diff --git a/include/mastodont_application.h b/include/mastodont_application.h index da55c7c..13317a4 100644 --- a/include/mastodont_application.h +++ b/include/mastodont_application.h @@ -15,6 +15,9 @@ #ifndef MASTODONT_APPLICATION #define MASTODONT_APPLICATION +#include "mastodont_types.h" +#include +#include /* Status: Complete */ @@ -25,4 +28,16 @@ struct mstdnt_application char* vapid_key; }; +struct mstdnt_app_register_args +{ + char* client_name; + char* redirect_uris; + char* scopes; + char* website; +}; + +int mastodont_register_app(mastodont_t* data, + struct mstdnt_app_register_args* args, + struct mstdnt_storage* storage); + #endif /* MASTODONT_ACCOUNT */ diff --git a/include/mastodont_query.h b/include/mastodont_query.h new file mode 100644 index 0000000..eb12e42 --- /dev/null +++ b/include/mastodont_query.h @@ -0,0 +1,41 @@ +/* + * 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 . + */ + +#ifndef MASTODONT_QUERY_H +#define MASTODONT_QUERY_H +#include +#include "mastodont_types.h" + +enum _mstdnt_query_type +{ + _MSTDNT_QUERY_STRING, + _MSTDNT_QUERY_INT +} + +struct _mstdnt_query_param +{ + enum _mstdnt_query_type type; + char* key; + union { + char* s; + int i; + } value; +}; + +char* _mstdnt_query_string(char* src, + struct _mstdnt_query_param* params, + size_t param_len); + +#endif /* MASTODONT_QUERY_H */ diff --git a/src/application.c b/src/application.c new file mode 100644 index 0000000..dcc80e5 --- /dev/null +++ b/src/application.c @@ -0,0 +1,49 @@ +/* + * 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 mastodont_register_app(mastodont_t* data, + struct mstdnt_app_register_args* args, + struct mstdnt_storage* storage) +{ + int res; + struct mstdnt_fetch_results results = { 0 }; + + /* Default args */ + struct mstdnt_timeline_public_args _args; + if (args == NULL) + { + _args.local = 0; /* Defaults to false */ + _args.remote = 0; + _args.only_media = 0; + _args.max_id = NULL; + _args.since_id = NULL; + _args.min_id = NULL; + _args.limit = 20; + args = &_args; + } + storage->needs_cleanup = 0; + + if (mastodont_fetch_curl(data, "api/v1/apps", &results) != CURLE_OK) + return 1; + + res = mstdnt_load_statuses_from_result(statuses, storage, &results, size); + + mastodont_fetch_results_cleanup(&results); + + return res; +} + diff --git a/src/query.c b/src/query.c new file mode 100644 index 0000000..faa56dc --- /dev/null +++ b/src/query.c @@ -0,0 +1,72 @@ +/* + * 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 +#include +#include + +#define CONV_SIZE 64 + +char* _mstdnt_query_string(char* src, + struct _mstdnt_query_param* params, + size_t param_len) +{ + size_t i; + int res_prev; + /* If value type is an int, convert it with int->str */ + char conv_val[CONV_SIZE]; + size_t src_l = strlen(src); + + /* Result */ + size_t res_len = src_l+1; + char* result = malloc(res_len); + strncpy(result, src, res_len); + + /* We'll call them res to represent the query parameters */ + int res_count = 0; + + for (i = 0; i < param_len; ++i) + { + if (params[i].key) + { + if (res_count++ == 0) + { + result = realloc(result, ++res_len); + result[res_len-1] = '?'; + } + + /* Convert value */ + if (params[i].type == _MSTDNT_QUERY_INT) + snprintf(conv_val, CONV_SIZE, "%d", params[i].value.i); + else /* Point to it */ + conv_val = params[i].value.s; + + res_prev = res_len; + /* |v| & character |v| account for '=' */ + res_len += 1 + strlen(params[i].key) + 1 + strlen(conv_val); + + + result = realloc(result, res_len + 1); + if (res_count) result[res_prev] = '&'; + + if (res_count) result[res_len-2] = '\0'; + else result[res_len-1] = '\0'; + + /* TODO */ + } + } + + return result; +}