Skip to content
Snippets Groups Projects
Commit e255c5af authored by Jakob Olsson's avatar Jakob Olsson
Browse files

combine common files, solve merge conflicts

parent f7018b25
No related branches found
No related tags found
No related merge requests found
......@@ -21,10 +21,10 @@ libmobile1_hilink: ${HLOBJS}
libmobile2_hilink: ${HLOBJS}
${CC} ${HLOBJS} -shared -o libmobile_hilink.so
HOBJS = common_hilink.o
HSRCS = common_hilink.c
common_hilink: ${HOBJS}
${CC} -c ${CFLAGS} ${HSRCS} -o ${HOBJS}
COBJS = common.o
CSRCS = common.c
common: ${COBJS}
${CC} -c ${CFLAGS} ${CSRCS} -o ${COBJS}
STOBJS = stack_operations.o
STSRCS = stack_operations.c
......@@ -34,7 +34,7 @@ stack_operations: ${STOBJS}
DIOBJS = dongle_infrastructure.o
DISRCS = dongle_infrastructure.c
dongle_infrastructure: ${DIOBJS}
${CC} -c ${CWFLAGS} ${DISRCS} ${ZCOBJS} ${STOBJS} -o ${DIOBJS} -L . ${LIBS}
${CC} -c ${CWFLAGS} ${DISRCS} ${STOBJS} ${COBJS} -o ${DIOBJS} -L . ${LIBS}
dongle: dongle.o
${CC} ${CWFLAGS} dongle.o ${ZCOBJS} ${DIOBJS} ${STOBJS} -o dongle -L . ${LIBS}
......
#include "common_hilink.h"
#include "common.h"
int print_to_ubus(struct json_object *parsed_response, struct ubus_context *ctx, struct ubus_request_data *req)
{
struct blob_buf bb;
memset(&bb, 0, sizeof(bb));
blob_buf_init(&bb, 0);
bb = json_to_blob(parsed_response, bb);
ubus_send_reply(ctx, req, bb.head);
blob_buf_free(&bb);
json_object_put(parsed_response);
return 0;
}
struct blob_buf json_to_blob(struct json_object *response, struct blob_buf bb)
{
void *arr, *obj;
int i;
json_object_object_foreach(response, key, val) {
int val_type = json_object_get_type(val);
switch (val_type) {
case json_type_int:
blobmsg_add_u32(&bb, key, json_object_get_int(val));
break;
case json_type_double:
blobmsg_add_double(&bb, key, json_object_get_double(val));
break;
case json_type_string:
blobmsg_add_string(&bb, key, json_object_get_string(val));
break;
case json_type_array:
arr = blobmsg_open_array(&bb, key);
for (i = 0; i < json_object_array_length(val); i++) {
// add open table
bb = json_to_blob(json_object_array_get_idx(val, i), bb);
// add close table
}
blobmsg_close_array(&bb, arr);
break;
case json_type_object:
obj = blobmsg_open_table(&bb, key);
bb = json_to_blob(val, bb);
blobmsg_close_table(&bb, obj);
break;
}
}
return bb;
}
//need to free tag content..
char *xml_parser(struct write_result *result, char *tag)
......@@ -17,23 +69,25 @@ char *xml_parser(struct write_result *result, char *tag)
xpathctx_ptr = doc_ptr ? xmlXPathNewContext(doc_ptr) : NULL;
xpathobj_ptr = xpathctx_ptr ? xmlXPathEvalExpression((xmlChar *)tag, xpathctx_ptr) : NULL;
if (xpathobj_ptr) {
if (xpathobj_ptr)
{
int n;
xmlNodeSetPtr nodeset_ptr = xpathobj_ptr->nodesetval;
for (n = 0; nodeset_ptr && n < xmlXPathNodeSetGetLength(nodeset_ptr); n++) {
for (n = 0; nodeset_ptr && n < xmlXPathNodeSetGetLength(nodeset_ptr); n++)
{
//if (DEBUG)
//printf("n value: %d\n", n);
xmlNodePtr node_ptr = nodeset_ptr->nodeTab[n];
if (node_ptr->type != XML_ATTRIBUTE_NODE && node_ptr->type != XML_ELEMENT_NODE && node_ptr->type != XML_CDATA_SECTION_NODE)
continue;
if (node_ptr->children) {
if (node_ptr->children)
{
//tag_content = (char*) node_ptr->children->content;
strcpy(tag_content, (char *)node_ptr->children->content);
if (DEBUG)
printf("tag content: %s\n", tag_content);
break;
}
}
}
......@@ -48,7 +102,6 @@ char *xml_parser(struct write_result *result, char *tag)
leave:
return NULL;
}
void xml_to_json(xmlNode *anode, json_object *jobj)
......@@ -56,19 +109,24 @@ void xml_to_json(xmlNode *anode, json_object *jobj)
xmlNodePtr cur_node = NULL;
json_object *cur_jstr = NULL;
for (cur_node = anode; cur_node; cur_node = cur_node->next) {
if (DEBUG_COMMON) {
for (cur_node = anode; cur_node; cur_node = cur_node->next)
{
if (DEBUG_COMMON)
{
printf("child address: %p\n", cur_node);
printf("next addres: %p\n", cur_node->next);
printf("root child content: %s\n", (uint8_t *)xmlNodeGetContent(cur_node));
}
if (cur_node->type == XML_ELEMENT_NODE) {
if (xmlChildElementCount(cur_node) == 0) {
if (cur_node->type == XML_ELEMENT_NODE)
{
if (xmlChildElementCount(cur_node) == 0)
{
cur_jstr = json_object_new_string((char *)xmlNodeGetContent(cur_node));
if (DEBUG_COMMON) {
printf ("xmlNodeGet name: %sn", (char *)cur_node->name);
printf ("xmlNodeGetContent: %sn", (char *)xmlNodeGetContent(cur_node));
if (DEBUG_COMMON)
{
printf("xmlNodeGet name: %sn", (char *)cur_node->name);
printf("xmlNodeGetContent: %sn", (char *)xmlNodeGetContent(cur_node));
}
json_object_object_add(jobj, (char *)cur_node->name, cur_jstr);
......@@ -79,8 +137,6 @@ void xml_to_json(xmlNode *anode, json_object *jobj)
}
}
void xml_to_json_converter(struct write_result *result)
{
json_object *jobj;
......@@ -94,11 +150,8 @@ void xml_to_json_converter(struct write_result *result)
jobj = json_object_new_object();
xml_to_json(origin_node, jobj);
if (DEBUG_COMMON) {
printf ("The json object created: %s\n",json_object_to_json_string(jobj));
if (DEBUG_COMMON)
{
printf("The json object created: %s\n", json_object_to_json_string(jobj));
}
}
......@@ -14,15 +14,20 @@
#include <libubox/list.h>
#include <libubox/uloop.h>
#include <ctype.h>
#include "libmobile_zte.h"
#include <json-c/json.h>
#include <string.h>
#include <libubox/blobmsg.h>
#include <libubox/blobmsg_json.h>
#include <libubus.h>
#include <libxml2/libxml/parser.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include "libmobile_hilink.h"
#include "libmobile_zte.h"
extern int debug;
extern char *ip_addr;
extern struct ubus_context *global_ctx;
#define debug_print(...) \
......@@ -61,4 +66,7 @@ int print_to_ubus(struct json_object *parsed_response, struct ubus_context *ctx,
* Blob buffer containing the replicated json_object.
*/
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);
#endif
#ifndef COMMON_HILINK_H
#define COMMON_HILINK_H
#include "libmobile_hilink.h"
#include <libxml2/libxml/parser.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include <json-c/json.h>
#define DEBUG_COMMON 0
char *xml_parser(struct write_result *result, char *tag);
void xml_to_json_converter(struct write_result *result);
#endif
#include "common_zte.h"
int print_to_ubus(struct json_object *parsed_response, struct ubus_context *ctx, struct ubus_request_data *req)
{
struct blob_buf bb;
memset(&bb, 0, sizeof(bb));
blob_buf_init(&bb, 0);
bb = json_to_blob(parsed_response, bb);
ubus_send_reply(ctx, req, bb.head);
blob_buf_free(&bb);
json_object_put(parsed_response);
return 0;
}
struct blob_buf json_to_blob(struct json_object *response, struct blob_buf bb)
{
void *arr, *obj;
int i;
json_object_object_foreach(response, key, val) {
int val_type = json_object_get_type(val);
switch (val_type) {
case json_type_int:
blobmsg_add_u32(&bb, key, json_object_get_int(val));
break;
case json_type_double:
blobmsg_add_double(&bb, key, json_object_get_double(val));
break;
case json_type_string:
blobmsg_add_string(&bb, key, json_object_get_string(val));
break;
case json_type_array:
arr = blobmsg_open_array(&bb, key);
for (i = 0; i < json_object_array_length(val); i++) {
// add open table
bb = json_to_blob(json_object_array_get_idx(val, i), bb);
// add close table
}
blobmsg_close_array(&bb, arr);
break;
case json_type_object:
obj = blobmsg_open_table(&bb, key);
bb = json_to_blob(val, bb);
blobmsg_close_table(&bb, obj);
break;
}
}
return bb;
}
#include <getopt.h>
#include "common_zte.h"
#include "common.h"
#include "dongle_infrastructure.h"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment