diff --git a/include/mastodont.h b/include/mastodont.h index 7fa3e1a..058e906 100644 --- a/include/mastodont.h +++ b/include/mastodont.h @@ -26,6 +26,7 @@ #include #include #include +#include /* Functions required form curl */ void mastodont_global_curl_init(); @@ -33,7 +34,8 @@ void mastodont_global_curl_cleanup(); int mastodont_init(mastodont_t* data, uint16_t flags); int mastodont_set_token(mastodont_t* data, char* token); -void mastodont_free(mastodont_t* data); +void mastodont_cleanup(mastodont_t* data); +void mastodont_free(void*); void mastodont_storage_cleanup(struct mstdnt_storage* storage); diff --git a/include/mastodont_fetch.h b/include/mastodont_fetch.h index 123a029..1b6b900 100644 --- a/include/mastodont_fetch.h +++ b/include/mastodont_fetch.h @@ -25,6 +25,7 @@ struct mstdnt_fetch_results size_t size; }; +size_t mstdnt_curl_write_callback(char* ptr, size_t _size, size_t nmemb, void* _content); void mastodont_fetch_results_cleanup(struct mstdnt_fetch_results* res); int mastodont_fetch_curl(mastodont_t* mstdnt, char* url, diff --git a/include/mastodont_static.h b/include/mastodont_static.h new file mode 100644 index 0000000..c3ee481 --- /dev/null +++ b/include/mastodont_static.h @@ -0,0 +1,27 @@ +/* + * 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 MSTDNT_STATIC_H +#define MSTDNT_STATIC_H +#include "mastodont_types.h" +#include "mastodont_fetch.h" + +int mastodont_instance_panel(mastodont_t* api, + struct mstdnt_fetch_results* html); + +int mastodont_terms_of_service(mastodont_t* api, + struct mstdnt_fetch_results* html); + +#endif /* MSTDNT_STATIC_H */ diff --git a/src/fetch.c b/src/fetch.c index 45ed2be..3434c5a 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -18,7 +18,7 @@ #include "mastodont_fetch.h" /* For use with libcurl */ -static size_t write_callback(char* ptr, size_t _size, size_t nmemb, void* _content) +size_t mstdnt_curl_write_callback(char* ptr, size_t _size, size_t nmemb, void* _content) { size_t size = nmemb * _size; /* Mostly pointless, but portable */ struct mstdnt_fetch_results* res = _content; /* Cast */ @@ -69,7 +69,7 @@ int mastodont_fetch_curl(mastodont_t* mstdnt, /* Set options */ curl_easy_setopt(mstdnt->curl, CURLOPT_URL, url); - curl_easy_setopt(mstdnt->curl, CURLOPT_WRITEFUNCTION, write_callback); + curl_easy_setopt(mstdnt->curl, CURLOPT_WRITEFUNCTION, mstdnt_curl_write_callback); curl_easy_setopt(mstdnt->curl, CURLOPT_WRITEDATA, results); /* Should we verify the peer's SSL cert? */ curl_easy_setopt(mstdnt->curl, CURLOPT_SSL_VERIFYPEER, diff --git a/src/mastodont.c b/src/mastodont.c index 56ecf40..55ecb79 100644 --- a/src/mastodont.c +++ b/src/mastodont.c @@ -33,13 +33,18 @@ int mastodont_set_token(mastodont_t* data, char* token) return 0; } -void mastodont_free(mastodont_t* data) +void mastodont_cleanup(mastodont_t* data) { curl_easy_cleanup(data->curl); if (data->token_heap) free(data->token); } +void mastodont_free(void* ptr) +{ + free(ptr); +} + void mastodont_storage_cleanup(struct mstdnt_storage* storage) { if (storage->needs_cleanup) diff --git a/src/static.c b/src/static.c new file mode 100644 index 0000000..1836f35 --- /dev/null +++ b/src/static.c @@ -0,0 +1,29 @@ +/* + * 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 + +int mastodont_instance_panel(mastodont_t* api, + struct mstdnt_fetch_results* html) +{ + return mastodont_fetch_curl(api, "instance/panel.html", html, CURLOPT_HTTPGET); +} + +int mastodont_terms_of_service(mastodont_t* api, + struct mstdnt_fetch_results* html) +{ + return mastodont_fetch_curl(api, "static/terms-of-service.html", html, CURLOPT_HTTPGET); +}