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"
10 static ret_t
delete_object_by_id(cherokee_handler_osm_t
*hdl
, unsigned long int id
, osm_state_delete_t state
);
13 cherokee_handler_osm_init_delete (cherokee_handler_osm_t
*hdl
) {
14 ret_t ret
= ret_error
;
15 osm_state_delete_t state
= OSM_DELETE_FIRST
;
16 cherokee_connection_t
*conn
= HANDLER_CONN(hdl
);
17 char *string
= conn
->request
.buf
;
20 while (state
!= OSM_DELETE_DONE
&& (token
= (char *) strsep( &string
, "/")) != NULL
) {
25 case OSM_DELETE_FIRST
:
28 state
= OSM_DELETE_NODE_ID
;
31 state
= OSM_DELETE_WAY_ID
;
34 state
= OSM_DELETE_RELATION_ID
;
39 case OSM_DELETE_NODE_ID
:
40 case OSM_DELETE_WAY_ID
:
41 case OSM_DELETE_RELATION_ID
: {
43 id
= strtoul(token
, (char **) NULL
, 10);
44 if (errno
!= ERANGE
) {
46 ret
= delete_object_by_id(hdl
, id
, state
);
48 state
= OSM_DELETE_DONE
;
60 delete_object_by_id(cherokee_handler_osm_t
*hdl
, unsigned long int id
, osm_state_delete_t state
) {
62 cherokee_buffer_t sql
= CHEROKEE_BUF_INIT
;
64 case OSM_DELETE_NODE_COMMAND
:
65 cherokee_buffer_add_va (&sql
, SQL_DELETE_NODE_BY_ID
, id
);
66 ret
= run_sql(hdl
, &sql
, NULL
, NULL
);
69 case OSM_DELETE_WAY_COMMAND
:
70 cherokee_buffer_add_va (&sql
, SQL_DELETE_WAY_BY_ID
, id
);
71 ret
= run_sql(hdl
, &sql
, NULL
, NULL
);
74 case OSM_DELETE_RELATION_COMMAND
:
75 cherokee_buffer_add_va (&sql
, SQL_DELETE_RELATION_BY_ID
, id
);
76 ret
= run_sql(hdl
, &sql
, NULL
, NULL
);
81 cherokee_buffer_mrproper(&sql
);