diff --git a/src/search.c b/src/search.c
index 6790b06..3fad595 100644
--- a/src/search.c
+++ b/src/search.c
@@ -13,10 +13,13 @@
* along with this program. If not, see .
*/
+#include
#include
#include
#include
#include
+#include
+#include
static const char* type_to_string(enum mstdnt_search_type type)
{
@@ -29,6 +32,43 @@ static const char* type_to_string(enum mstdnt_search_type type)
}
}
+int mstdnt_search_from_result(struct mstdnt_storage* storage,
+ struct mstdnt_fetch_results* results,
+ struct mstdnt_search_results* search_results)
+{
+ size_t i = 0;
+ size_t arr_len = 0;
+ size_t size = 0;
+ cJSON* root, *item;
+ if (_mstdnt_json_init(&root, results, storage))
+ return 1;
+
+ // Not many items here, just use cJSON_GetObjectItemCaseSensitive() instead
+ cJSON* statuses = cJSON_GetObjectItemCaseSensitive(root, "statuses");
+ cJSON* accounts = cJSON_GetObjectItemCaseSensitive(root, "accounts");
+ cJSON* hashtags = cJSON_GetObjectItemCaseSensitive(root, "hashtags");
+
+ // Statuses
+ if (statuses && cJSON_IsArray(statuses) && (size = cJSON_GetArraySize(statuses)))
+ {
+ search_results->statuses = calloc(1, size * sizeof(struct mstdnt_status));
+ search_results->statuses_len = size;
+ cJSON_ArrayForEach(item, statuses)
+ {
+ mstdnt_status_from_json(search_results->statuses + arr_len++, item->child);
+ }
+ }
+
+ return 0;
+}
+
+int _mstdnt_search_result_callback(struct mstdnt_fetch_results* results,
+ struct mstdnt_storage* storage,
+ void* _args)
+{
+ return mstdnt_search_from_result(storage, results, _args);
+}
+
int mastodont_search(mastodont_t* data,
char* query,
struct mstdnt_storage* storage,
@@ -41,7 +81,7 @@ int mastodont_search(mastodont_t* data,
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
{ _MSTDNT_QUERY_STRING, "q", { .s = query } },
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
- { _MSTDNT_QUERY_STRING, "type", { .s = type_to_string(args->type) } },
+ { _MSTDNT_QUERY_STRING, "type", { .s = (char*)type_to_string(args->type) } },
{ _MSTDNT_QUERY_INT, "resolve", { .i = args->resolve } },
{ _MSTDNT_QUERY_INT, "following", { .i = args->following } },
{ _MSTDNT_QUERY_INT, "with_relationships", { .i = args->with_relationships } },
@@ -56,8 +96,7 @@ int mastodont_search(mastodont_t* data,
NULL, 0,
CURLOPT_HTTPGET,
results,
- /* _mstdnt_search_result_callback, */
- NULL
+ _mstdnt_search_result_callback
};
return mastodont_request(data, &req_args);