Copyright ©

Mongoose OS Forum


json_rpc_server with frozen parser


I am using "json_rpc_server" example to receive http request from client which contains json body. It was working fine. Now I need to parse the json data received. So searching web, I have identifed that CESANTA has got beautiful and simple json parser called "frozen". I have tried to integrate the json parser on receiving the http event in the following way:

static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
  struct http_message *hm = (struct http_message *) ev_data;
  static const char *methods[] = { "sum", NULL };
  static mg_rpc_handler_t handlers[] = { rpc_sum, NULL };
  char buf[100];  
  switch (ev) {
        printf("Inside MG_EV_HTTP_REQUEST with count: %d\n", cnt);
        printf("Received Data: %s\n", hm->body.p);
        char b[100];
        json_scanf(hm->body.p, strlen(hm->body.p), "{keyId: %s}", &b);
      mg_rpc_dispatch(hm->body.p, hm->body.len, buf, sizeof(buf),
                      methods, handlers);
      mg_printf(nc, "HTTP/1.0 200 OK\r\nContent-Length: %d\r\n"
                "Content-Type: application/json\r\n\r\n%s",
                (int) strlen(buf), buf);
      nc->flags |= MG_F_SEND_AND_CLOSE;

Also I have included frozen.h header file. But while compiling I am getting lot of duplication errors.

frozen.h:34:3: error: redeclaration of enumerator ‘JSON_TYPE_STRING’
mongoose.h:528:3: note: previous definition of ‘JSON_TYPE_STRING’ was here
frozen.h:35:3: error: redeclaration of enumerator ‘JSON_TYPE_NUMBER’
mongoose.h:529:3: note: previous definition of ‘JSON_TYPE_NUMBER’ was here
frozen.h:36:3: error: redeclaration of enumerator ‘JSON_TYPE_TRUE’
mongoose.h:531:3: note: previous definition of ‘JSON_TYPE_TRUE’ was here
frozen.h:37:3: error: redeclaration of enumerator ‘JSON_TYPE_FALSE’
mongoose.h:532:3: note: previous definition of ‘JSON_TYPE_FALSE’ was here
frozen.h:38:3: error: redeclaration of enumerator ‘JSON_TYPE_NULL’
mongoose.h:533:3: note: previous definition of ‘JSON_TYPE_NULL’ was here
frozen.h:52:8: error: redefinition of ‘struct json_token’
mongoose.h:537:8: note: originally defined here

If I try to change the enum names in frozen.h header file, other errors are coming.

I would like to know how do I integrate the frozen parser in to json rpc server. Please let me know

Thanks in advance


Sign In or Register to comment.