diff --git a/include/mastodont_application.h b/include/mastodont_application.h index 6dbede7..9405e6c 100644 --- a/include/mastodont_application.h +++ b/include/mastodont_application.h @@ -48,14 +48,6 @@ struct mstdnt_oauth_token time_t time; }; -int mstdnt_app_result(struct mstdnt_fetch_results* results, - struct mstdnt_storage* storage, - struct mstdnt_app* app); - -int mstdnt_token_result(struct mstdnt_fetch_results* results, - struct mstdnt_storage* storage, - struct mstdnt_oauth_token* app); - int mastodont_register_app(mastodont_t* data, struct mstdnt_args* args, struct mstdnt_storage* storage, diff --git a/include/mastodont_attachment.h b/include/mastodont_attachment.h index 8f7bbbf..d93d377 100644 --- a/include/mastodont_attachment.h +++ b/include/mastodont_attachment.h @@ -47,19 +47,16 @@ struct mstdnt_upload_media_args /* TODO focus */ }; -int mstdnt_attachment_result(struct mstdnt_fetch_results* results, - struct mstdnt_storage* storage, - struct mstdnt_attachment* att); +int mstdnt_attachment_json(cJSON* att_json, struct mstdnt_attachment* att); void _mstdnt_val_attachments_call(cJSON* v, void* _type); -void load_attachment_from_json(struct mstdnt_attachment* att, cJSON* att_json); int mastodont_upload_media(mastodont_t* api, struct mstdnt_upload_media_args* args, struct mstdnt_storage* storage, struct mstdnt_attachment* attachment); -void cleanup_attachments(struct mstdnt_attachment* attachment); +void mstdnt_cleanup_attachments(struct mstdnt_attachment* attachment); void _mstdnt_val_attachments_call(cJSON* v, void* _type); #endif /* MASTODONT_ATTACHMENT */ diff --git a/src/application.c b/src/application.c index 173838a..02dd53a 100644 --- a/src/application.c +++ b/src/application.c @@ -20,19 +20,11 @@ #include #include -int mstdnt_app_result(struct mstdnt_fetch_results* results, - struct mstdnt_storage* storage, - struct mstdnt_app* app) +static int mstdnt_app_json(cJSON* json, struct mstdnt_app* app) { - cJSON* root, *v; - /* Zero out */ - memset(storage, 0, sizeof(struct mstdnt_storage)); memset(app, 0, sizeof(struct mstdnt_app)); - if (_mstdnt_json_init(&root, results, storage)) - return 1; - struct _mstdnt_val_ref refs[] = { { "id", &(app->id), _mstdnt_val_string_call }, { "name", &(app->name), _mstdnt_val_string_call }, @@ -43,31 +35,20 @@ int mstdnt_app_result(struct mstdnt_fetch_results* results, { "vapid_key", &(app->vapid_key), _mstdnt_val_string_call }, }; - for (v = root->child; v; v = v->next) - { + for (cJSON* v = json->child; v; v = v->next) if (_mstdnt_key_val_ref(v, refs, _mstdnt_arr_len(refs))) - { return 1; - } - } + return 0; } -static int mstdnt_app_result_callback(struct mstdnt_fetch_results* results, - struct mstdnt_storage* storage, - void* args) +static int mstdnt_app_json_callback(cJSON* json, void* args) { - return mstdnt_app_result(results, storage, args); + return mstdnt_app_json(json, args); } -int mstdnt_token_result(struct mstdnt_fetch_results* results, - struct mstdnt_storage* storage, - struct mstdnt_oauth_token* app) +static int mstdnt_token_json(cJSON* json, struct mstdnt_oauth_token* app) { - cJSON* root, *v; - if (_mstdnt_json_init(&root, results, storage)) - return 1; - struct _mstdnt_val_ref refs[] = { { "access_token", &(app->access_token), _mstdnt_val_string_call }, { "token_type", &(app->token_type), _mstdnt_val_string_call }, @@ -76,22 +57,16 @@ int mstdnt_token_result(struct mstdnt_fetch_results* results, { "me", &(app->me), _mstdnt_val_string_call }, }; - for (v = root; v; v = v->next) - { + for (cJSON* v = json; v; v = v->next) if (_mstdnt_key_val_ref(v->child, refs, _mstdnt_arr_len(refs)) == 1) - { return 1; - } - } - + return 0; } -static int mstdnt_token_result_callback(struct mstdnt_fetch_results* results, - struct mstdnt_storage* storage, - void* args) +static int mstdnt_token_json_callback(cJSON* json, void* args) { - return mstdnt_token_result(results, storage, args); + return mstdnt_token_json(json, args); } int mastodont_register_app(mastodont_t* data, @@ -113,7 +88,7 @@ int mastodont_register_app(mastodont_t* data, params, _mstdnt_arr_len(params), CURLOPT_POST, app, - mstdnt_app_result_callback + mstdnt_app_json_callback }; return mastodont_request(data, &req_args); @@ -145,7 +120,7 @@ int mastodont_obtain_oauth_token(mastodont_t* data, _mstdnt_arr_len(params), CURLOPT_POST, token, - mstdnt_token_result_callback + mstdnt_token_json_callback }; return mastodont_request(data, &req_args); diff --git a/src/attachment.c b/src/attachment.c index e279c8e..96d3b9d 100644 --- a/src/attachment.c +++ b/src/attachment.c @@ -20,10 +20,10 @@ #include #include -void load_attachment_from_json(struct mstdnt_attachment* att, cJSON* att_json) +int mstdnt_attachment_json(struct mstdnt_attachment* att, cJSON* att_json) { - cJSON* it; - + if (!att) return 1; + /* Zero out */ memset(att, 0, sizeof(struct mstdnt_attachment)); @@ -38,25 +38,9 @@ void load_attachment_from_json(struct mstdnt_attachment* att, cJSON* att_json) { "blurhash", &(att->blurhash), _mstdnt_val_string_call }, }; - for (it = att_json; it; it = it->next) - { + for (cJSON* it = att_json; it; it = it->next) _mstdnt_key_val_ref(it, refs, _mstdnt_arr_len(refs)); - } -} -int mstdnt_attachment_result(struct mstdnt_fetch_results* results, - struct mstdnt_storage* storage, - struct mstdnt_attachment* att) -{ - /* Can be null sometimes */ - if (!att) return 0; - - cJSON* root; - if (_mstdnt_json_init(&root, results, storage) || - !cJSON_IsObject(root)) - return 1; - - load_attachment_from_json(att, root->child); return 0; } @@ -84,15 +68,13 @@ void _mstdnt_val_attachments_call(cJSON* v, void* _type) int i; for (it = v_array, i = 0; it; (++i, it = it->next)) { - load_attachment_from_json((*attachments) + i, it->child); + mstdnt_attachment_json(it->child, (*attachments) + i); } } -static int mstdnt_attachment_callback(struct mstdnt_fetch_results* results, - struct mstdnt_storage* storage, - void* _args) +static int mstdnt_attachment_json_callback(cJSON* json, void* _args) { - return mstdnt_attachment_result(results, storage, _args); + return mstdnt_attachment_result(json, _args); } int mastodont_upload_media(mastodont_t* api,