Add the ability to add uint8 and uint16 entities to api data.
1 2 3 4 5 6 7 8 9 10 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 63 64 65 66 67 68 69 70 71 72 73
diff --git a/api.c b/api.c
index 55f42ea..65e6682 100644
--- a/api.c
+++ b/api.c
@@ -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
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
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;
diff --git a/miner.h b/miner.h
index 0bb2042..f39a7d7 100644
--- a/miner.h
+++ b/miner.h
@@ -1539,6 +1539,8 @@ enum api_data_type {
API_ESCAPE,
API_STRING,
API_CONST,
+ API_UINT8,
+ API_UINT16,
API_INT,
API_UINT,
API_UINT32,
@@ -1571,6 +1573,8 @@ struct api_data {
extern struct api_data *api_add_escape(struct api_data *root, char *name, char *data, bool copy_data);
extern struct api_data *api_add_string(struct api_data *root, char *name, char *data, bool copy_data);
extern struct api_data *api_add_const(struct api_data *root, char *name, const char *data, bool copy_data);
+extern struct api_data *api_add_uint8(struct api_data *root, char *name, uint8_t *data, bool copy_data);
+extern struct api_data *api_add_uint16(struct api_data *root, char *name, uint16_t *data, bool copy_data);
extern struct api_data *api_add_int(struct api_data *root, char *name, int *data, bool copy_data);
extern struct api_data *api_add_uint(struct api_data *root, char *name, unsigned int *data, bool copy_data);
extern struct api_data *api_add_uint32(struct api_data *root, char *name, uint32_t *data, bool copy_data);