diff --git a/include/mastodont_account.h b/include/mastodont_account.h index 7f9558a..13e3629 100644 --- a/include/mastodont_account.h +++ b/include/mastodont_account.h @@ -21,4 +21,7 @@ struct mstdnt_account int i; }; +int mstdnt_load_account_from_json(struct mstdnt_status* status, cJSON* js); + + #endif /* MASTODONT_ACCOUNT */ diff --git a/include/mastodont_timeline.h b/include/mastodont_timeline.h index 06026a7..1785496 100644 --- a/include/mastodont_timeline.h +++ b/include/mastodont_timeline.h @@ -31,6 +31,7 @@ struct mstdnt_timeline_public_args { int mastodont_timeline_public(mastodont_t* data, struct mstdnt_timeline_public_args* args, struct mstdnt_storage* storage, - struct mstdnt_status* response[]); + struct mstdnt_status* statuses[], + size_t* statuses_size); #endif /* MASTODONT_TIMELINE_H */ diff --git a/src/account.c b/src/account.c new file mode 100644 index 0000000..fe8a167 --- /dev/null +++ b/src/account.c @@ -0,0 +1,25 @@ +/* + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include + +int mstdnt_load_account_from_json(struct mstdnt_status* status, cJSON* js) +{ + cJSON* v; + for (v = js; v; v->next) + { + /* TODO */ + } +} diff --git a/src/mastodont.c b/src/mastodont.c index 2a27eab..15d6210 100644 --- a/src/mastodont.c +++ b/src/mastodont.c @@ -25,5 +25,9 @@ void mastodont_free(mastodont_t* data) void mastodont_storage_cleanup(struct mstdnt_storage* storage) { - cJSON_Delete(storage->root); + if (storage->needs_cleanup) + { + cJSON_Delete(storage->root); + storage->needs_cleanup = 0; + } } diff --git a/src/status.c b/src/status.c index 1e56398..d2c201e 100644 --- a/src/status.c +++ b/src/status.c @@ -15,6 +15,7 @@ #include #include +#include int mstdnt_load_status_from_json(struct mstdnt_status* status, cJSON* js) { @@ -46,5 +47,10 @@ int mstdnt_load_status_from_json(struct mstdnt_status* status, cJSON* js) if (strcmp("bookmarked", v->string) == 0) status->bookmarked = val; if (strcmp("pinned", v->string) == 0) status->pinned = val; } + else if (cJSON_IsObject(v)) + { + if (strcmp("account", v->string) == 0) + mstdnt_load_account_from_json(&(status->account), v->child); + } } } diff --git a/src/timeline.c b/src/timeline.c index ee12fac..8494c6e 100644 --- a/src/timeline.c +++ b/src/timeline.c @@ -21,7 +21,8 @@ int mastodont_timeline_public(mastodont_t* data, struct mstdnt_timeline_public_args* args, struct mstdnt_storage* storage, - struct mstdnt_status* statuses[]) + struct mstdnt_status* statuses[], + size_t* size) { int res; cJSON* root, *status_j_list; @@ -53,6 +54,7 @@ int mastodont_timeline_public(mastodont_t* data, fprintf(stderr, "cJSON_Parse: %s\n", jerror); goto cleanup; } + storage->root = root; storage->needs_cleanup = 1; if (!cJSON_IsArray(root)) @@ -61,8 +63,11 @@ int mastodont_timeline_public(mastodont_t* data, goto cleanup; } - /* malloc array */ - *statuses = malloc(cJSON_GetArraySize(root) * sizeof(struct mstdnt_status)); + if (size) *size = cJSON_GetArraySize(root); + + /* malloc array - cJSON does a loop to count, let's do it once preferably */ + *statuses = malloc((size ? *size : cJSON_GetArraySize(root)) + * sizeof(struct mstdnt_status)); if (*statuses == NULL) { perror("malloc");