Browse Source

Add the ability to add uint8 and uint16 entities to api data.

nfactor-troky
Con Kolivas 11 years ago
parent
commit
25d4f16727
  1. 26
      api.c
  2. 4
      miner.h

26
api.c

@ -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;

4
miner.h

@ -1539,6 +1539,8 @@ enum api_data_type { @@ -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 { @@ -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);

Loading…
Cancel
Save