Allocate application
FossilOrigin-Name: a9e1b008096f688eebc3f91c25a37fe717aa2c9420a8459b157a6e4ee1f3cb36
This commit is contained in:
parent
6576135c81
commit
c61371a34f
4 changed files with 22 additions and 9 deletions
|
@ -68,6 +68,6 @@ int mastodont_obtain_oauth_token(mastodont_t* data,
|
|||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_oauth_token* app);
|
||||
|
||||
void _mstdnt_val_application_call(cJSON* v, void* _type);
|
||||
void _mstdnt_val_malloc_application_call(cJSON* v, void* _type);
|
||||
|
||||
#endif /* MASTODONT_ACCOUNT */
|
||||
|
|
|
@ -43,7 +43,7 @@ struct mstdnt_status
|
|||
char* spoiler_text;
|
||||
struct mstdnt_attachment* media_attachments;
|
||||
size_t media_attachments_len;
|
||||
struct mstdnt_app application;
|
||||
struct mstdnt_app* application;
|
||||
struct mstdnt_status_pleroma pleroma;
|
||||
|
||||
/* Rendering attributes */
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
static int mstdnt_app_json(cJSON* json, struct mstdnt_app* app)
|
||||
{
|
||||
if (!json) return 1;
|
||||
/* Zero out */
|
||||
memset(app, 0, sizeof(struct mstdnt_app));
|
||||
|
||||
|
@ -35,7 +36,7 @@ static int mstdnt_app_json(cJSON* json, struct mstdnt_app* app)
|
|||
{ "vapid_key", &(app->vapid_key), _mstdnt_val_string_call },
|
||||
};
|
||||
|
||||
for (cJSON* v = json->child; v; v = v->next)
|
||||
for (cJSON* v = json; v; v = v->next)
|
||||
if (_mstdnt_key_val_ref(v, refs, _mstdnt_arr_len(refs)))
|
||||
return 1;
|
||||
|
||||
|
@ -58,8 +59,7 @@ static int mstdnt_token_json(cJSON* json, struct mstdnt_oauth_token* app)
|
|||
};
|
||||
|
||||
for (cJSON* v = json; v; v = v->next)
|
||||
if (_mstdnt_key_val_ref(v->child, refs, _mstdnt_arr_len(refs)) == 1)
|
||||
return 1;
|
||||
_mstdnt_key_val_ref(v, refs, _mstdnt_arr_len(refs));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -69,10 +69,22 @@ static int mstdnt_token_json_callback(cJSON* json, void* args)
|
|||
return mstdnt_token_json(json, args);
|
||||
}
|
||||
|
||||
void _mstdnt_val_application_call(cJSON* v, void* _type)
|
||||
void _mstdnt_val_malloc_application_call(cJSON* v, void* _type)
|
||||
{
|
||||
struct mstdnt_app* type = _type;
|
||||
mstdnt_app_json(type, v->child);
|
||||
struct mstdnt_app** type = _type;
|
||||
// We can skip an array size check by just seeing
|
||||
// if the first value of the child is not zero
|
||||
if (!(v->child && !cJSON_IsInvalid(v->child)))
|
||||
{
|
||||
*type = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
*type = calloc(1, sizeof(struct mstdnt_app));
|
||||
|
||||
if (*type)
|
||||
mstdnt_app_json(v->child, *type);
|
||||
}
|
||||
|
||||
int mastodont_register_app(mastodont_t* data,
|
||||
|
|
|
@ -115,7 +115,7 @@ int mstdnt_status_json(struct mstdnt_status* status, cJSON* js)
|
|||
{ "bookmarked", &(status->bookmarked), _mstdnt_val_bool_call },
|
||||
{ "pinned", &(status->pinned), _mstdnt_val_bool_call },
|
||||
{ "reblogs_count", &(status->reblogs_count), _mstdnt_val_uint_call },
|
||||
{ "application", &(status->application), _mstdnt_val_application_call },
|
||||
{ "application", &(status->application), _mstdnt_val_malloc_application_call },
|
||||
{ "favourites_count", &(status->favourites_count), _mstdnt_val_uint_call },
|
||||
{ "replies_count", &(status->replies_count), _mstdnt_val_uint_call },
|
||||
{ "media_attachments", &att_args, _mstdnt_val_attachments_call },
|
||||
|
@ -571,6 +571,7 @@ void mstdnt_cleanup_status(struct mstdnt_status* status)
|
|||
mstdnt_cleanup_status(status->reblog);
|
||||
free(status->reblog);
|
||||
}
|
||||
free(status->application);
|
||||
}
|
||||
|
||||
void mstdnt_cleanup_statuses(struct mstdnt_status* statuses, size_t s)
|
||||
|
|
Loading…
Reference in a new issue