Cherokee added a cryptor.h and we wanted to have the pcre.h also to be working.
[handlerosm.git] / handler_osm_delete.c
blobe53db6e9b881b24700cd870e107f8c63cdc0209a
1 #include <cherokee/common-internal.h>
2 #include <cherokee/cherokee.h>
3 #include <Mapi.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);
12 ret_t
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;
18 char *token;
20 while (state != OSM_DELETE_DONE && (token = (char *) strsep( &string , "/")) != NULL) {
21 if (*token == '\0')
22 continue;
24 switch (state) {
25 case OSM_DELETE_FIRST:
26 switch (token[0]) {
27 case 'n':
28 state = OSM_DELETE_NODE_ID;
29 break;
30 case 'w':
31 state = OSM_DELETE_WAY_ID;
32 break;
33 case 'r':
34 state = OSM_DELETE_RELATION_ID;
35 break;
37 break;
39 case OSM_DELETE_NODE_ID:
40 case OSM_DELETE_WAY_ID:
41 case OSM_DELETE_RELATION_ID: {
42 unsigned long id = 0;
43 id = strtoul(token, (char **) NULL, 10);
44 if (errno != ERANGE) {
45 state++;
46 ret = delete_object_by_id(hdl, id, state);
47 } else
48 state = OSM_DELETE_DONE;
49 break;
51 default:
52 ret = ret_error;
56 return ret;
59 static ret_t
60 delete_object_by_id(cherokee_handler_osm_t *hdl, unsigned long int id, osm_state_delete_t state) {
61 ret_t ret;
62 cherokee_buffer_t sql = CHEROKEE_BUF_INIT;
63 switch (state) {
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);
67 break;
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);
72 break;
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);
77 break;
78 default:
79 ret = ret_error;
81 cherokee_buffer_mrproper(&sql);
82 return ret;