Now also parse new diffs
[handlerosm.git] / handler_osm_delete.c
blob1bcae0d90c514a997f0ffb47d4128ad2fc8ed4f8
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 ret_t
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;
16 char *token;
18 while (state != OSM_DELETE_DONE && (token = (char *) strsep( &string , "/")) != NULL) {
19 if (*token == '\0')
20 continue;
22 switch (state) {
23 case OSM_DELETE_FIRST:
24 switch (token[0]) {
25 case 'n':
26 state = OSM_DELETE_NODE_ID;
27 break;
28 case 'w':
29 state = OSM_DELETE_WAY_ID;
30 break;
31 case 'r':
32 state = OSM_DELETE_RELATION_ID;
33 break;
35 break;
37 case OSM_DELETE_NODE_ID:
38 case OSM_DELETE_WAY_ID:
39 case OSM_DELETE_RELATION_ID: {
40 unsigned long id = 0;
41 id = strtoul(token, (char **) NULL, 10);
42 if (errno != ERANGE) {
43 state++;
44 ret = delete_object_by_id(hdl, id, state);
45 } else
46 state = OSM_DELETE_DONE;
47 break;
49 default:
50 ret = ret_error;
54 return ret;
57 ret_t
58 delete_object_by_id(cherokee_handler_osm_t *hdl, unsigned long int id, osm_state_delete_t state) {
59 ret_t ret;
60 cherokee_buffer_t sql = CHEROKEE_BUF_INIT;
61 switch (state) {
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);
65 break;
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);
70 break;
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);
75 break;
76 default:
77 ret = ret_error;
79 cherokee_buffer_mrproper(&sql);
80 return ret;