Some progress

FossilOrigin-Name: 5b2ae52971b08d103cc7eccdff1614bcc4e0fa9f3d6f2ce3b13fcfb84720c99a
This commit is contained in:
nekobit 2022-11-07 00:11:46 +00:00
parent 5687929253
commit e561cb1847
7 changed files with 34 additions and 32 deletions

View file

@ -31,7 +31,7 @@ struct mstdnt_request_args
CURLoption request_type;
char* request_type_custom;
void* args;
int (*callback)(cJSON*, void**);
int (*callback)(cJSON*, void*, mstdnt_request_cb_data*);
};
/**

View file

@ -109,7 +109,7 @@ struct mstdnt_status_args
// Cleanup
void mstdnt_cleanup_statuses(struct mstdnt_status* statuses, size_t s);
void mstdnt_cleanup_status(struct mstdnt_status* status);
void mstdnt_cleanup_status(struct mstdnt_status* status, size_t unused);
int mstdnt_status_json(struct mstdnt_status* status, cJSON* js);
int mstdnt_status_emoji_react(mastodont_t* api,
@ -126,8 +126,8 @@ int mstdnt_statuses_json(struct mstdnt_status* statuses[],
size_t* size,
cJSON* js);
void _mstdnt_val_status_call(cJSON* v, void* args, mstdnt_request_cb_data* data);
void _mstdnt_val_malloc_status_call(cJSON* v, void* args, mstdnt_request_cb_data* data);
void _mstdnt_val_status_call(cJSON* v, void* args);
void _mstdnt_val_malloc_status_call(cJSON* v, void* args);
int mstdnt_status_context_json(struct mstdnt_status* statuses_before[],
struct mstdnt_status* statuses_after[],
@ -289,8 +289,8 @@ int mstdnt_get_favourites(mastodont_t* data,
struct mstdnt_status* statuses[],
size_t* size);
int mstdnt_statuses_json_callback(cJSON* json, void** _args);
int mstdnt_statuses_json_callback(cJSON* json, void* args, mstdnt_request_cb_data* data);
int mstdnt_status_json_callback(cJSON* json, void* args, mstdnt_request_cb_data* results);
int mstdnt_status_context_json_callback(cJSON* json, void** _args);
int mstdnt_status_context_json_callback(cJSON* json, void* args, mstdnt_request_cb_data* results);
#endif /* MASTODONT_STATUS */

View file

@ -31,12 +31,13 @@ typedef int8_t mstdnt_bool;
struct mstdnt_storage;
// Only god knows
typedef void (*data_free_cb_t)(void*, size_t);
typedef void (*mstdnt_request_cb_t)(void* data, void* args);
typedef struct mstdnt_request_cb_data {
struct mstdnt_storage* storage;
void* data;
void (*data_free_cb)(void*);
data_free_cb_t data_free_cb;
} mstdnt_request_cb_data;
typedef void (*mstdnt_request_cb_t)(void* data, void* args);
#define MSTDNT_CB_DATA(_data) (_data->data)
#define MSTDNT_FLAG_NO_URI_SANITIZE (1<<0)

View file

@ -118,7 +118,6 @@ int mstdnt_fetch_curl_async(mastodont_t* mstdnt,
return -1;
}
/* int running; */
/* res = curl_multi_perform(mstdnt->curl, &running); */
/* if (res != CURLM_OK) */
@ -190,7 +189,7 @@ int mstdnt_await(mastodont_t* mstdnt,
if (data->json_cb)
res = data->json_cb(storage.root, data->json_args, &results);
data->callback(NULL, data->callback_args);
data->callback(&(results), data->callback_args);
cleanup_res:
// Cleanup

View file

@ -27,7 +27,7 @@ void mstdnt_cleanup(mastodont_t* data)
void mstdnt_storage_cleanup(struct mstdnt_storage* storage)
{
if (storage->needs_cleanup)
if (storage && storage->needs_cleanup)
{
cJSON_Delete(storage->root);
storage->needs_cleanup = 0;
@ -37,7 +37,6 @@ void mstdnt_storage_cleanup(struct mstdnt_storage* storage)
void mstdnt_request_cb_cleanup(mstdnt_request_cb_data* data)
{
mstdnt_storage_cleanup(data->storage);
free(data->storage);
data->data_free_cb(data->data);
free(data);
//data->data_free_cb(data->data, 0);
/* free(data); */
}

View file

@ -252,7 +252,7 @@ void mstdnt_cleanup_notification(struct mstdnt_notification* notif)
}
if (notif->status)
{
mstdnt_cleanup_status(notif->status);
mstdnt_cleanup_status(notif->status, 0);
mstdnt_free(notif->status);
}
mstdnt_free(notif->pleroma);

View file

@ -134,9 +134,12 @@ int mstdnt_status_json(struct mstdnt_status* status, cJSON* js)
int mstdnt_status_json_callback(cJSON* json, void* args, mstdnt_request_cb_data* data)
{
// No arguments passed for statuses
(void)_args;
// Unused
(void)args;
struct mstdnt_status* status = malloc(sizeof(struct mstdnt_status));
data->data = status;
data->data_free_cb = (data_free_cb_t)mstdnt_cleanup_status;
return mstdnt_status_json(status, json->child);
}
@ -145,7 +148,6 @@ GENERATE_JSON_ARRAY_FUNC(mstdnt_statuses_json, struct mstdnt_status, mstdnt_stat
int mstdnt_statuses_json_callback(cJSON* json, void* args, mstdnt_request_cb_data* data)
{
// TODO
struct mstdnt_statuses* statuses = malloc(sizeof(struct mstdnt_statuses));
return mstdnt_statuses_json(&(statuses->statuses), &(statuses->len), json);
}
@ -250,7 +252,7 @@ static int mstdnt_status_action(mastodont_t* data,
status,
mstdnt_status_json_callback
};
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
}
@ -396,10 +398,10 @@ int mstdnt_status_context_json(struct mstdnt_status* statuses_before[],
return 0;
}
int mstdnt_status_context_json_callback(cJSON* json, void** _args)
int mstdnt_status_context_json_callback(cJSON* json, void* args, mstdnt_request_cb_data* data)
{
struct mstdnt_status_context* ctx = malloc(sizeof(struct mstdnt_status_context));
*_args = ctx;
data->data = ctx;
return mstdnt_status_context_json(&(ctx->before.statuses),
&(ctx->after.statuses),
&(ctx->before.len),
@ -454,6 +456,7 @@ int mstdnt_status_favourited_by(mastodont_t* data,
accounts,
accts_len,
};
char url[MSTDNT_URLSIZE];
snprintf(url, MSTDNT_URLSIZE, "api/v1/statuses/%s/favourited_by", id);
@ -566,13 +569,13 @@ void* cb_args,
}
int mstdnt_status_emoji_react(mastodont_t* api,
struct mstdnt_args* m_args,
mstdnt_request_cb_t cb_request,
void* cb_args,
char* id,
char* emoji,
struct mstdnt_storage* storage,
struct mstdnt_status* status)
struct mstdnt_args* m_args,
mstdnt_request_cb_t cb_request,
void* cb_args,
char* id,
char* emoji,
struct mstdnt_storage* storage,
struct mstdnt_status* status)
{
char url[MSTDNT_URLSIZE];
snprintf(url, MSTDNT_URLSIZE, "api/v1/pleroma/statuses/%s/reactions/%s", id, emoji);
@ -588,10 +591,10 @@ void* cb_args,
mstdnt_status_json_callback
};
return mstdnt_request(api, m_args, &req_args, cb_request, cb_args);
return mstdnt_request(api, m_args, cb_request, cb_args, &req_args);
}
void mstdnt_cleanup_status(struct mstdnt_status* status)
void mstdnt_cleanup_status(struct mstdnt_status* status, size_t unused)
{
mstdnt_cleanup_attachments(status->media_attachments);
mstdnt_cleanup_account(&(status->account));
@ -599,7 +602,7 @@ void mstdnt_cleanup_status(struct mstdnt_status* status)
mstdnt_cleanup_emojis(status->emojis);
if (status->reblog)
{
mstdnt_cleanup_status(status->reblog);
mstdnt_cleanup_status(status->reblog, 0);
mstdnt_free(status->reblog);
}
mstdnt_free(status->application);
@ -611,7 +614,7 @@ void mstdnt_cleanup_statuses(struct mstdnt_status* statuses, size_t s)
if (!statuses) return;
for (i = 0; i < s; ++i)
{
mstdnt_cleanup_status(statuses + i);
mstdnt_cleanup_status(statuses + i, 0);
}
mstdnt_free(statuses);
}