1 #include <cherokee/common-internal.h>
2 #include <cherokee/cherokee.h>
5 #include "handler_osm.h"
6 #include "handler_osm_db.h"
7 #include "handler_osm_delete.h"
8 #include "handler_osm_sql.h"
11 cherokee_handler_osm_init_delete (cherokee_handler_osm_t
*hdl
) {
12 ret_t ret
= ret_error
;
13 osm_state_delete_t state
= OSM_DELETE_FIRST
;
14 cherokee_connection_t
*conn
= HANDLER_CONN(hdl
);
15 char *string
= conn
->request
.buf
;
18 while (state
!= OSM_DELETE_DONE
&& (token
= (char *) strsep( &string
, "/")) != NULL
) {
23 case OSM_DELETE_FIRST
:
26 state
= OSM_DELETE_NODE_ID
;
29 state
= OSM_DELETE_WAY_ID
;
32 state
= OSM_DELETE_RELATION_ID
;
37 case OSM_DELETE_NODE_ID
:
38 case OSM_DELETE_WAY_ID
:
39 case OSM_DELETE_RELATION_ID
: {
41 id
= strtoul(token
, (char **) NULL
, 10);
42 if (errno
!= ERANGE
) {
44 ret
= delete_object_by_id(hdl
, id
, state
);
46 state
= OSM_DELETE_DONE
;
58 delete_object_by_id(cherokee_handler_osm_t
*hdl
, unsigned long int id
, osm_state_delete_t state
) {
60 cherokee_buffer_t sql
= CHEROKEE_BUF_INIT
;
62 case OSM_DELETE_NODE_COMMAND
:
63 cherokee_buffer_add_va (&sql
, SQL_DELETE_NODE_BY_ID
, id
);
64 ret
= run_sql(hdl
, &sql
, NULL
, NULL
);
67 case OSM_DELETE_WAY_COMMAND
:
68 cherokee_buffer_add_va (&sql
, SQL_DELETE_WAY_BY_ID
, id
);
69 ret
= run_sql(hdl
, &sql
, NULL
, NULL
);
72 case OSM_DELETE_RELATION_COMMAND
:
73 cherokee_buffer_add_va (&sql
, SQL_DELETE_RELATION_BY_ID
, id
);
74 ret
= run_sql(hdl
, &sql
, NULL
, NULL
);
79 cherokee_buffer_mrproper(&sql
);