Browse Source

Requests create JSON instead

Complementary files still need to be updated

FossilOrigin-Name: 10b62909af66babc3e1b09c364c3ccc8b37d75b7d0727c34bb67dc96169efcf1
master
nekobit 3 months ago
parent
commit
c0c8a93606
  1. 6
      .fossil-settings/ignore-glob
  2. 3
      include/mastodont_error.h
  3. 4
      include/mastodont_request.h
  4. 9
      src/error.c
  5. 2
      src/json_helper.c
  6. 16
      src/request.c
  7. 11
      src/status.c

6
.gitignore → .fossil-settings/ignore-glob

@ -1,5 +1,5 @@
**/*.o
**/*.a
*.o
src/*.o
*.a
docs/html/
docs/latex/

3
include/mastodont_error.h

@ -18,7 +18,6 @@
#include <mastodont_types.h>
#include <mastodont_fetch.h>
int mstdnt_check_error(struct mstdnt_fetch_results* result,
struct mstdnt_storage* storage);
int mstdnt_check_error(struct mstdnt_storage* storage);
#endif /* MASTODONT_ERROR_H */

4
include/mastodont_request.h

@ -29,9 +29,7 @@ struct mastodont_request_args
size_t params_post_len;
CURLoption request_type;
void* args;
int (*callback)(struct mstdnt_fetch_results* results,
struct mstdnt_storage* storage,
void*);
int (*callback)(void*);
};
int mastodont_request(mastodont_t* data, struct mastodont_request_args* args);

9
src/error.c

@ -28,13 +28,10 @@ static void _mstdnt_val_errors_call(cJSON* v, void* _type)
}
}
int mstdnt_check_error(struct mstdnt_fetch_results* results,
struct mstdnt_storage* storage)
int mstdnt_check_error(struct mstdnt_storage* storage)
{
int res = 0;
cJSON* root, *v;
if (_mstdnt_json_init(&root, results, storage))
return 1;
cJSON* v;
/* Make sure empty */
storage->error = NULL;
@ -49,6 +46,8 @@ int mstdnt_check_error(struct mstdnt_fetch_results* results,
for (v = root->child; v; v = v->next)
if (_mstdnt_key_val_ref(v, refs, _mstdnt_arr_len(refs)) == 0)
{
res = 1;
}
return res;
}

2
src/json_helper.c

@ -26,9 +26,9 @@ int _mstdnt_json_init(cJSON** root,
struct mstdnt_storage* storage)
{
*root = cJSON_ParseWithLength(results->response, results->size);
storage->root = *root;
if (*root == NULL)
return 1;
storage->root = *root;
storage->needs_cleanup = 1;
return 0;
}

16
src/request.c

@ -74,6 +74,7 @@ int mastodont_request(mastodont_t* data, struct mastodont_request_args* args)
int res = 0, curlerror = 0;
struct mstdnt_storage* storage = args->storage;
struct mstdnt_fetch_results results = { 0 };
cJSON* root;
curl_mime* mime = NULL;
char* post;
// TODO debug me
@ -115,19 +116,14 @@ int mastodont_request(mastodont_t* data, struct mastodont_request_args* args)
goto cleanup;
}
if (mstdnt_check_error(&results, storage))
// Create json structure
if (_mstdnt_json_init(&root, &results, storage) &&
mstdnt_check_error(&results, storage))
{
res = 1;
goto cleanup_res;
/* Optional */
if (args->callback) res = args->callback(args->args);
}
storage->needs_cleanup = 1;
/* Optional */
if (args->callback) res = args->callback(&results, storage, args->args);
cleanup_res:
mastodont_fetch_results_cleanup(&results);
cleanup:
if (args->params_post && args->request_type == CURLOPT_POST) free(post);

11
src/status.c

@ -123,20 +123,13 @@ int mstdnt_statuses_from_result(struct mstdnt_storage* storage,
struct mstdnt_status* statuses[],
size_t* size)
{
cJSON* root, *status_j_list;
if (_mstdnt_json_init(&root, results, storage) &&
!cJSON_IsArray(root))
return 1;
return mstdnt_statuses_json(statuses, size, root);
return mstdnt_statuses_json(statuses, size, storage->root);
}
// GENERATE mstdnt_statuses_json
GENERATE_JSON_ARRAY_FUNC(mstdnt_statuses_json, struct mstdnt_status, mstdnt_status_from_json)
int _mstdnt_statuses_result_callback(struct mstdnt_fetch_results* results,
struct mstdnt_storage* storage,
void* _args)
int mstdnt_statuses_json_callback(void* _args)
{
struct _mstdnt_statuses_cb_args* args = _args;
return mstdnt_statuses_from_result(storage, results, args->statuses, args->size);

Loading…
Cancel
Save