|
|
|
@ -936,6 +936,16 @@ static struct api_data *api_add_data_full(struct api_data *root, char *name, enu
@@ -936,6 +936,16 @@ static struct api_data *api_add_data_full(struct api_data *root, char *name, enu
|
|
|
|
|
api_data->data = (void *)malloc(strlen((char *)data) + 1); |
|
|
|
|
strcpy((char*)(api_data->data), (char *)data); |
|
|
|
|
break; |
|
|
|
|
case API_UINT8: |
|
|
|
|
/* Most OSs won't really alloc less than 4 */ |
|
|
|
|
api_data->data = malloc(4); |
|
|
|
|
*(uint8_t *)api_data->data = *(uint8_t *)data; |
|
|
|
|
break; |
|
|
|
|
case API_UINT16: |
|
|
|
|
/* Most OSs won't really alloc less than 4 */ |
|
|
|
|
api_data->data = malloc(4); |
|
|
|
|
*(uint16_t *)api_data->data = *(uint16_t *)data; |
|
|
|
|
break; |
|
|
|
|
case API_INT: |
|
|
|
|
api_data->data = (void *)malloc(sizeof(int)); |
|
|
|
|
*((int *)(api_data->data)) = *((int *)data); |
|
|
|
@ -1007,6 +1017,16 @@ struct api_data *api_add_const(struct api_data *root, char *name, const char *da
@@ -1007,6 +1017,16 @@ struct api_data *api_add_const(struct api_data *root, char *name, const char *da
|
|
|
|
|
return api_add_data_full(root, name, API_CONST, (void *)data, copy_data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct api_data *api_add_uint8(struct api_data *root, char *name, uint8_t *data, bool copy_data) |
|
|
|
|
{ |
|
|
|
|
return api_add_data_full(root, name, API_UINT8, (void *)data, copy_data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct api_data *api_add_uint16(struct api_data *root, char *name, uint16_t *data, bool copy_data) |
|
|
|
|
{ |
|
|
|
|
return api_add_data_full(root, name, API_UINT16, (void *)data, copy_data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct api_data *api_add_int(struct api_data *root, char *name, int *data, bool copy_data) |
|
|
|
|
{ |
|
|
|
|
return api_add_data_full(root, name, API_INT, (void *)data, copy_data); |
|
|
|
@ -1140,6 +1160,12 @@ static struct api_data *print_data(struct api_data *root, char *buf, bool isjson
@@ -1140,6 +1160,12 @@ static struct api_data *print_data(struct api_data *root, char *buf, bool isjson
|
|
|
|
|
if (escape != original) |
|
|
|
|
free(escape); |
|
|
|
|
break; |
|
|
|
|
case API_UINT8: |
|
|
|
|
sprintf(buf, "%u", *(uint8_t *)root->data); |
|
|
|
|
break; |
|
|
|
|
case API_UINT16: |
|
|
|
|
sprintf(buf, "%u", *(uint16_t *)root->data); |
|
|
|
|
break; |
|
|
|
|
case API_INT: |
|
|
|
|
sprintf(buf, "%d", *((int *)(root->data))); |
|
|
|
|
break; |
|
|
|
|