JSON uint function
FossilOrigin-Name: f540905360811fec24e363a46b75ff56f770aa43bcca22d7768cb827864ba9b9
This commit is contained in:
parent
196931b7d2
commit
1a7a0cbc48
4 changed files with 35 additions and 21 deletions
|
@ -34,6 +34,7 @@ int _mstdnt_key_val_ref(cJSON* v, struct _mstdnt_val_ref* refs,
|
|||
|
||||
void _mstdnt_val_string_call(cJSON* v, void* _type);
|
||||
void _mstdnt_val_bool_call(cJSON* v, void* _type);
|
||||
void _mstdnt_val_uint_call(cJSON* v, void* _type);
|
||||
|
||||
/* DEPRECATED */
|
||||
struct _mstdnt_str_val
|
||||
|
|
|
@ -61,30 +61,29 @@ cleanup:
|
|||
int mstdnt_load_account_from_json(struct mstdnt_account* acct, cJSON* js)
|
||||
{
|
||||
cJSON* v;
|
||||
struct _mstdnt_str_val strings[] = {
|
||||
{ "id", &(acct->id) },
|
||||
{ "username", &(acct->username) },
|
||||
{ "acct", &(acct->acct) },
|
||||
{ "display_name", &(acct->display_name) },
|
||||
{ "created_at", &(acct->created_at) },
|
||||
{ "note", &(acct->note) },
|
||||
{ "url", &(acct->url) },
|
||||
{ "avatar", &(acct->avatar) },
|
||||
{ "avatar_static", &(acct->avatar_static) },
|
||||
{ "header", &(acct->header) },
|
||||
{ "header_static", &(acct->header_static) },
|
||||
{ "last_status_at", &(acct->last_status_at) },
|
||||
{ "mute_expires_at", &(acct->mute_expires_at) }
|
||||
};
|
||||
|
||||
struct _mstdnt_bool_val bools[] = {
|
||||
{ "locked", &(acct->locked) },
|
||||
{ "bot", &(acct->bot) }
|
||||
struct _mstdnt_val_ref refs[] = {
|
||||
{ "id", &(acct->id), _mstdnt_val_string_call },
|
||||
{ "username", &(acct->username), _mstdnt_val_string_call },
|
||||
{ "acct", &(acct->acct), _mstdnt_val_string_call },
|
||||
{ "display_name", &(acct->display_name), _mstdnt_val_string_call },
|
||||
{ "created_at", &(acct->created_at), _mstdnt_val_string_call },
|
||||
{ "note", &(acct->note), _mstdnt_val_string_call },
|
||||
{ "url", &(acct->url), _mstdnt_val_string_call },
|
||||
{ "avatar", &(acct->avatar), _mstdnt_val_string_call },
|
||||
{ "avatar_static", &(acct->avatar_static), _mstdnt_val_string_call },
|
||||
{ "header", &(acct->header), _mstdnt_val_string_call },
|
||||
{ "header_static", &(acct->header_static), _mstdnt_val_string_call },
|
||||
{ "last_status_at", &(acct->last_status_at), _mstdnt_val_string_call },
|
||||
{ "mute_expires_at", &(acct->mute_expires_at), _mstdnt_val_string_call },
|
||||
{ "locked", &(acct->locked), _mstdnt_val_bool_call },
|
||||
{ "bot", &(acct->bot), _mstdnt_val_bool_call },
|
||||
{ "statuses_count", &(acct->statuses_count), _mstdnt_val_uint_call },
|
||||
{ "followers_count", &(acct->followers_count), _mstdnt_val_uint_call },
|
||||
{ "following_count", &(acct->following_count), _mstdnt_val_uint_call },
|
||||
};
|
||||
|
||||
for (v = js; v; v = v->next)
|
||||
{
|
||||
_mstdnt_key_val_iter(v, strings, _mstdnt_arr_len(strings),
|
||||
bools, _mstdnt_arr_len(bools));
|
||||
_mstdnt_key_val_ref(v, refs, _mstdnt_arr_len(refs));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,6 +64,17 @@ void _mstdnt_val_bool_call(cJSON* v, void* _type)
|
|||
*type = cJSON_IsTrue(v);
|
||||
}
|
||||
|
||||
void _mstdnt_val_uint_call(cJSON* v, void* _type)
|
||||
{
|
||||
unsigned* type = _type;
|
||||
if (!cJSON_IsNumber(v))
|
||||
{
|
||||
*type = 0;
|
||||
return;
|
||||
}
|
||||
*type = v->valueint;
|
||||
}
|
||||
|
||||
int _mstdnt_key_val_iter(cJSON* v,
|
||||
struct _mstdnt_str_val* str,
|
||||
size_t str_len,
|
||||
|
|
|
@ -40,6 +40,9 @@ int mstdnt_load_status_from_json(struct mstdnt_status* status, cJSON* js)
|
|||
{ "muted", &(status->muted), _mstdnt_val_bool_call, NULL },
|
||||
{ "bookmarked", &(status->bookmarked), _mstdnt_val_bool_call, NULL },
|
||||
{ "pinned", &(status->pinned), _mstdnt_val_bool_call, NULL },
|
||||
{ "reblogs_count", &(status->reblogs_count), _mstdnt_val_uint_call, NULL },
|
||||
{ "favourites_count", &(status->favourites_count), _mstdnt_val_uint_call, NULL },
|
||||
{ "replies_count", &(status->replies_count), _mstdnt_val_uint_call, NULL },
|
||||
};
|
||||
|
||||
for (v = js; v; v = v->next)
|
||||
|
|
Loading…
Reference in a new issue