Static pages

FossilOrigin-Name: ff47d1ce28f661cc68c5ad6f314bdc0f02b84cc440cbde38642aadf5b54c4ca0
This commit is contained in:
nekobit 2022-05-21 17:03:08 +00:00
parent f60e5088c1
commit 988b495a35
6 changed files with 68 additions and 4 deletions

View file

@ -26,6 +26,7 @@
#include <mastodont_scrobbles.h>
#include <mastodont_search.h>
#include <mastodont_announcement.h>
#include <mastodont_static.h>
/* 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);

View file

@ -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,

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
#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 */

View file

@ -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,

View file

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

29
src/static.c Normal file
View file

@ -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 <https://www.gnu.org/licenses/>.
*/
#include <mastodont_static.h>
#include <mastodont_fetch.h>
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);
}