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

refactor print_list to stupid code

parent c1956bf5
Branches
No related tags found
No related merge requests found
...@@ -454,61 +454,56 @@ fail: ...@@ -454,61 +454,56 @@ fail:
return ipv4_addr; return ipv4_addr;
} }
int list_to_blob(void) int list_to_blob(struct blob_buf *bb)
{ {
struct device *net_dev; struct device *net_dev;
struct blob_buf bb;
void *arr, *table; void *arr, *table;
int rv; int rv;
memset(&bb, 0, sizeof(bb)); memset(bb, 0, sizeof(*bb));
rv = blob_buf_init(&bb, 0); rv = blob_buf_init(bb, 0);
if (rv != 0) if (rv != 0)
goto fail; goto fail;
arr = blobmsg_open_array(&bb, "network_devices"); arr = blobmsg_open_array(bb, "network_devices");
if (!arr) if (!arr)
goto fail_arr; goto fail_arr;
list_for_each_entry(net_dev, &devices, list) list_for_each_entry(net_dev, &devices, list) {
{ table = blobmsg_open_table(bb, "");
table = blobmsg_open_table(&bb, "");
if (!table) if (!table)
goto fail_table; goto fail_table;
rv = blobmsg_add_string(&bb, "product", net_dev->usb.product); rv = blobmsg_add_string(bb, "product", net_dev->usb.product);
if (rv < 0) if (rv < 0)
goto fail_string; goto fail_string;
rv = blobmsg_add_string(&bb, "interface_name", net_dev->usb.if_name); rv = blobmsg_add_string(bb, "interface_name", net_dev->usb.if_name);
if (rv < 0) if (rv < 0)
goto fail_string; goto fail_string;
rv = blobmsg_add_string(&bb, "idproduct", net_dev->usb.product_id); rv = blobmsg_add_string(bb, "idproduct", net_dev->usb.product_id);
if (rv < 0) if (rv < 0)
goto fail_string; goto fail_string;
rv = blobmsg_add_string(&bb, "idvendor", net_dev->usb.vendor_id); rv = blobmsg_add_string(bb, "idvendor", net_dev->usb.vendor_id);
if (rv < 0) if (rv < 0)
goto fail_string; goto fail_string;
if (net_dev->ip) if (net_dev->ip)
{ {
rv = blobmsg_add_string(&bb, "ip", net_dev->ip); rv = blobmsg_add_string(bb, "ip", net_dev->ip);
if (rv < 0) if (rv < 0)
goto fail_string; goto fail_string;
} }
blobmsg_close_table(&bb, table); blobmsg_close_table(bb, table);
} }
blobmsg_close_array(&bb, arr); blobmsg_close_array(bb, arr);
ubus_send_reply(ctx, req, bb.head);
blob_buf_free(&bb);
return 0; return 0;
fail_string: fail_string:
fail_table: fail_table:
fail_arr: fail_arr:
blob_buf_free(&bb);
fail: fail:
return UBUS_STATUS_UNKNOWN_ERROR; return UBUS_STATUS_UNKNOWN_ERROR;
} }
...@@ -517,7 +512,18 @@ int print_list(struct ubus_context *ctx, struct ubus_object *obj, ...@@ -517,7 +512,18 @@ int print_list(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method, struct ubus_request_data *req, const char *method,
struct blob_attr *msg) struct blob_attr *msg)
{ {
return list_to_blob(); struct blob_buf bb;
int rv;
rv = list_to_blob(&bb);
if (rv == 0)
goto fail;
ubus_send_reply(ctx, req, bb.head);
fail:
blob_buf_free(&bb);
return rv;
} }
int clear(struct ubus_context *ctx, struct ubus_object *obj, int clear(struct ubus_context *ctx, struct ubus_object *obj,
......
...@@ -34,7 +34,7 @@ void remove_newline(char *input); ...@@ -34,7 +34,7 @@ void remove_newline(char *input);
char *get_usb_stat(char *path, char *dir, char *stat); char *get_usb_stat(char *path, char *dir, char *stat);
char *get_device_name(char *dir_name); char *get_device_name(char *dir_name);
char *get_device_ip(char *device_name); char *get_device_ip(char *device_name);
int list_to_blob(void); int list_to_blob(struct blob_buf *bb);
int print_list(struct ubus_context *ctx, struct ubus_object *obj, int print_list(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method, struct ubus_request_data *req, const char *method,
struct blob_attr *msg); struct blob_attr *msg);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment