Newer
Older
#ifndef COMMON_H
#define COMMON_H
#define DEBUG(message, ...) \
do \
{ \
fprintf(stdout, "\n(DEBUG)\t"); \
fprintf(stdout, message, ##__VA_ARGS__);\
} while (0)
Jakob Olsson
committed
#include "libtrace.h"
#include <libmobile.h>
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <json-c/json.h>
#include <string.h>
#include <libubox/blobmsg.h>
#include <libubus.h>
/**
* Function: parse_and_print
*
* Parses a string to its corresponding JSON format, if available, then writes it on ubus through <write_to_ubus>.
*
* IMPORTANT NOTE
* Will free the input string!
*
* Parameters:
* dongle_response - A string of JSON format that should be printed on ubus.
* ctx - Ubus context containing connection.
* req - Information for from the ubus request.
*
* Returns:
* 0 On success.
* -1 On failure.
*/
int parse_and_print(char *dongle_response, struct ubus_context *ctx, struct ubus_request_data *req);
/**
* Function: write_to_ubus
*
* Prints a json_object pointer's json structure to ubus.
*
* Parameters:
* parsed_response - A struct json_object pointer to json structure to be printed to ubus.
* ctx - Ubus context containing connection.
* req - Information for from the ubus request.
*
* Returns:
* 0 On success.
* -1 On failure.
*/
int write_to_ubus(struct json_object *parsed_response, struct ubus_context *ctx, struct ubus_request_data *req);
/**
* Function: json_to_blob
*
* Parses a json_object pointer to a corresponding blob buffer.
*
* Parameters:
* response - json_object pointer to be replicated in a blob buffer.
* bb - The blob buffer to hold the results.
*
* Returns:
* Blob buffer containing the replicated json_object.
*/
struct blob_buf json_to_blob(struct json_object *response, struct blob_buf bb);