Skip to content
Snippets Groups Projects
Commit 28539278 authored by Arun Muthusamy's avatar Arun Muthusamy
Browse files

return json from xmltojson converter

parent dfce8441
No related branches found
No related tags found
No related merge requests found
......@@ -102,10 +102,10 @@ leave:
return NULL;
}
void xml_to_json(xmlNode *anode, json_object *jobj)
void xml_to_json(xmlNode *anode, struct json_object *jobj)
{
xmlNodePtr cur_node = NULL;
json_object *cur_jstr = NULL;
struct json_object *cur_jstr = NULL;
for (cur_node = anode; cur_node; cur_node = cur_node->next) {
debug_print("child address: %p\n", cur_node);
......@@ -127,21 +127,39 @@ void xml_to_json(xmlNode *anode, json_object *jobj)
}
}
void xml_to_json_converter(struct write_result *result)
//free memory...
struct json_object *xml_to_json_converter(struct write_result *result)
{
json_object *jobj;
struct json_object *jobj;
xmlDocPtr doc_ptr = NULL;
xmlNode *origin_node = NULL;
jobj = json_object_new_object();
doc_ptr = xmlParseMemory(result->data, result->pos);
origin_node = doc_ptr ? xmlDocGetRootElement(doc_ptr) : NULL;
if (!doc_ptr)
goto fail_doc_ptr;
origin_node = xmlDocGetRootElement(doc_ptr);
if (!origin_node)
goto fail_origin_node;
jobj = json_object_new_object();
xml_to_json(origin_node, jobj);
debug_print("The json object created: %s\n", json_object_to_json_string(jobj));
if (doc_ptr)
xmlFreeDoc(doc_ptr);
if (origin_node)
free (origin_node);
return jobj;
fail_origin_node:
if (doc_ptr)
xmlFreeDoc(doc_ptr);
fail_doc_ptr:
return NULL;
}
int isdigits(const char *pin)
......@@ -233,4 +251,4 @@ int check_response(struct json_object *response)
return 0;
fail:
return -1;
}
\ No newline at end of file
}
......@@ -23,8 +23,8 @@
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
//#include "libmobile_hilink.h"
#include "libmobile_zte.h"
#include "libmobile_hilink.h"
//#include "libmobile_zte.h"
extern int debug;
extern char *global_ip_addr;
......@@ -35,7 +35,7 @@ extern struct ubus_context *global_ctx;
if (debug) \
fprintf(stderr, __VA_ARGS__); \
} while (0)
/*
#define TAG_CONTENT_SIZE 100
struct write_result
......@@ -43,6 +43,7 @@ struct write_result
char *data;
int pos;
};
*/
char *get_ip(char *if_name);
/**
......@@ -76,7 +77,7 @@ int print_to_ubus(struct json_object *parsed_response, struct ubus_context *ctx,
struct blob_buf json_to_blob(struct json_object *response, struct blob_buf bb);
char *xml_parser(struct write_result *result, char *tag);
void xml_to_json_converter(struct write_result *result);
struct json_object *xml_to_json_converter(struct write_result *result);
int isdigits(const char *pin);
int validate_puk_format(char *puk);
int validate_pin_format(char *pin);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment