Fixes and account stuff

FossilOrigin-Name: 91594d27f7c7ba14b8ca717fee8d3d826a02a03611676f3f841898bdfb91f38a
This commit is contained in:
me@ow.nekobit.net 2022-01-27 03:56:04 +00:00
parent 34e547cb90
commit b2535569fe
6 changed files with 49 additions and 5 deletions

View file

@ -21,4 +21,7 @@ struct mstdnt_account
int i;
};
int mstdnt_load_account_from_json(struct mstdnt_status* status, cJSON* js);
#endif /* MASTODONT_ACCOUNT */

View file

@ -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 */

25
src/account.c Normal file
View file

@ -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 <https://www.gnu.org/licenses/>.
*/
#include <mastodont_account.h>
int mstdnt_load_account_from_json(struct mstdnt_status* status, cJSON* js)
{
cJSON* v;
for (v = js; v; v->next)
{
/* TODO */
}
}

View file

@ -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;
}
}

View file

@ -15,6 +15,7 @@
#include <string.h>
#include <mastodont_status.h>
#include <mastodont_account.h>
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);
}
}
}

View file

@ -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");