Compare commits
73 commits
Author | SHA1 | Date | |
---|---|---|---|
536226e3ab | |||
cc06a401a4 | |||
61f9697250 | |||
8e28c5679a | |||
f5271f9189 | |||
ac18ecb86d | |||
ec186e9a18 | |||
04626f9e3f | |||
aa44b9cc3f | |||
e95a6ae246 | |||
bcdfb621b7 | |||
18e8814cf6 | |||
d212252b08 | |||
6394aeec89 | |||
6360a8167e | |||
f004d06316 | |||
1a52d1f23b | |||
05af07a450 | |||
8c40a4c3c5 | |||
6330408c6e | |||
119f681fc2 | |||
53461b6fc3 | |||
7606545a27 | |||
d979621621 | |||
839a226729 | |||
7cda5f605e | |||
0e269a0eeb | |||
5aa8e03d7e | |||
b073520076 | |||
0ef61ba959 | |||
317ea5514b | |||
1c5ee031c9 | |||
98cc03f303 | |||
861433eab8 | |||
0b87c70d33 | |||
44b1e64c67 | |||
ac44b17fe4 | |||
4f21fb33c2 | |||
c0ddc1bf5e | |||
1bb9dafe39 | |||
d47cedfe63 | |||
d4041fc030 | |||
f11802fc98 | |||
9c72241040 | |||
c1c3dd59f6 | |||
266acad80e | |||
eb0ab23094 | |||
64c4c502c3 | |||
9ec2abb288 | |||
a14f78903c | |||
0228cdd97c | |||
fc688c303d | |||
1814abfe10 | |||
b17d3af171 | |||
ac4529348d | |||
e561cb1847 | |||
5687929253 | |||
38de5f2392 | |||
9f82057f99 | |||
ce0cf6d3e4 | |||
b42d23ca02 | |||
0908b2979a | |||
949876fc7f | |||
dfb0a2e230 | |||
b8a2395248 | |||
3357bd476e | |||
a54e0cf0b3 | |||
740fd220a0 | |||
6e07fc0b96 | |||
90393af306 | |||
81116dccdf | |||
4fd79f5fd5 | |||
9df1e54cdf |
|
@ -3,3 +3,7 @@ src/*.o
|
|||
*.a
|
||||
docs/html/
|
||||
docs/latex/
|
||||
build/
|
||||
obj/
|
||||
mastodont.make
|
||||
Makefile
|
||||
|
|
181
LICENSE
181
LICENSE
|
@ -1,165 +1,26 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
Copyright (c) 2023, Nekobit
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
0. Additional Definitions.
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
|
23
Makefile
23
Makefile
|
@ -1,23 +0,0 @@
|
|||
CC ?= cc
|
||||
CFLAGS = -g -std=c99 -Wall -Werror=implicit-function-declaration -Wno-unused-variable -I ./libs/ -I ./include/ $(shell pkg-config --cflags libcurl)
|
||||
SRC = $(wildcard src/*.c) libs/cjson/cJSON.c
|
||||
OBJ = $(patsubst %.c,%.o,$(SRC))
|
||||
TARGET = libmastodont.a # shared
|
||||
AR = ar
|
||||
|
||||
all: static
|
||||
|
||||
docs:
|
||||
doxygen Doxyfile
|
||||
|
||||
static: $(OBJ)
|
||||
$(AR) rcs $(TARGET) $(OBJ)
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET)
|
||||
rm -f $(OBJ)
|
||||
|
||||
.PHONY: clean docs all test
|
27
README.md
Normal file
27
README.md
Normal file
|
@ -0,0 +1,27 @@
|
|||
# Mastodont-c
|
||||
|
||||
- *NOTE:* API is not stable yet. Please be patient.
|
||||
|
||||
Mastodont-c is a C library to access the Mastodon API and it's variants
|
||||
(Pleroma, Akkoma, Soapbox).
|
||||
|
||||
It was written in C due to it's portability. It's designed to be used in
|
||||
Treebird, but it can be used in other programs as well. In fact, there are
|
||||
tests specifically designed to showcase it's power
|
||||
|
||||
# Build system
|
||||
|
||||
Mastodont-c uses a pretty quirky build system called Premake5 mainly just
|
||||
to make me happy and for portability. I plan on writing some neat little
|
||||
Java bindings for this library someday to see if I can expand it onto other
|
||||
platforms :-)
|
||||
|
||||
#### On UNIX-like systems...
|
||||
|
||||
$ premake5 gmake
|
||||
|
||||
(Silly systems can use `--os bsd` to force it)
|
||||
|
||||
# Documentation
|
||||
|
||||
Documentation is essentially non-existant, but this will improve over time.
|
|
@ -1,62 +1,55 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_H
|
||||
#define MASTODONT_H
|
||||
#include <mastodont_hooks.h>
|
||||
#include <mastodont_types.h>
|
||||
#include <mastodont_timeline.h>
|
||||
#include <mastodont_list.h>
|
||||
#include <mastodont_notification.h>
|
||||
#include <mastodont_status.h>
|
||||
#include <mastodont_relationship.h>
|
||||
#include <mastodont_account.h>
|
||||
#include <mastodont_attachment.h>
|
||||
#include <mastodont_scrobbles.h>
|
||||
#include <mastodont_search.h>
|
||||
#include <mastodont_announcement.h>
|
||||
#include <mastodont_static.h>
|
||||
#include <mastodont_chats.h>
|
||||
#include "mastodont_hooks.h"
|
||||
#include "mastodont_types.h"
|
||||
#include "mastodont_timeline.h"
|
||||
#include "mastodont_list.h"
|
||||
#include "mastodont_notification.h"
|
||||
#include "mastodont_status.h"
|
||||
#include "mastodont_relationship.h"
|
||||
#include "mastodont_account.h"
|
||||
#include "mastodont_attachment.h"
|
||||
#include "mastodont_scrobbles.h"
|
||||
#include "mastodont_search.h"
|
||||
#include "mastodont_announcement.h"
|
||||
#include "mastodont_chats.h"
|
||||
|
||||
//! Initializes libcurl
|
||||
void mstdnt_global_curl_init();
|
||||
//! Cleans up libcurl
|
||||
void mstdnt_global_curl_cleanup();
|
||||
/// Initializes libcurl
|
||||
void
|
||||
mstdnt_global_curl_init(void);
|
||||
/// Cleans up libcurl
|
||||
void
|
||||
mstdnt_global_curl_cleanup(void);
|
||||
|
||||
/*!
|
||||
/**
|
||||
* Initializes a mstdnt struct
|
||||
*
|
||||
* \param data Pointer to struct to fill in
|
||||
* \return Value of curl_easy_init(); either Zero or non-zero
|
||||
*/
|
||||
int mstdnt_init(mastodont_t* data);
|
||||
int
|
||||
mstdnt_init(mastodont_t* data);
|
||||
|
||||
/*!
|
||||
/**
|
||||
* Cleans up the mstdnt struct
|
||||
*
|
||||
* \param data Pointer to the mstdnt data
|
||||
*/
|
||||
void mstdnt_cleanup(mastodont_t* data);
|
||||
void
|
||||
mstdnt_cleanup(mastodont_t* data);
|
||||
|
||||
/*!
|
||||
/**
|
||||
* Cleans up a storage struct.
|
||||
*
|
||||
* This contains information such as JSON information and errors.
|
||||
*
|
||||
* \param storage The storage block to cleanup
|
||||
*/
|
||||
void mstdnt_storage_cleanup(struct mstdnt_storage* storage);
|
||||
void
|
||||
mstdnt_storage_cleanup(struct mstdnt_storage *storage);
|
||||
|
||||
#endif /* MASTODONT_H */
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_ACCOUNT
|
||||
|
@ -24,13 +13,20 @@
|
|||
#define MSTDNT_LOOKUP_ACCT 0
|
||||
#define MSTDNT_LOOKUP_ID 1
|
||||
|
||||
// DEPRECATED
|
||||
struct _mstdnt_accounts_args
|
||||
{
|
||||
struct mstdnt_account** acct;
|
||||
size_t* size;
|
||||
};
|
||||
|
||||
struct mstdnt_account
|
||||
typedef struct mstdnt_accounts
|
||||
{
|
||||
struct mstdnt_account* accts;
|
||||
size_t len;
|
||||
} mstdnt_accounts;
|
||||
|
||||
typedef struct mstdnt_account
|
||||
{
|
||||
char* id;
|
||||
char* username;
|
||||
|
@ -64,7 +60,7 @@ struct mstdnt_account
|
|||
/* struct mstdnt_source* source */
|
||||
mstdnt_bool suspended;
|
||||
char* mute_expires_at;
|
||||
};
|
||||
} mstdnt_account;
|
||||
|
||||
struct mstdnt_account_args
|
||||
{
|
||||
|
@ -76,20 +72,33 @@ struct mstdnt_account_args
|
|||
int with_relationships; // mstdnt_get_mutes
|
||||
};
|
||||
|
||||
int mstdnt_account_action(mastodont_t* data,
|
||||
struct mstdnt_args* args,
|
||||
char* id,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_relationship* rel,
|
||||
char* url_str);
|
||||
int
|
||||
mstdnt_account_action(mastodont_t* data,
|
||||
struct mstdnt_args* args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
char* url_str);
|
||||
|
||||
int mstdnt_accounts_json(struct mstdnt_account* accounts[],
|
||||
size_t* size,
|
||||
cJSON* js);
|
||||
int
|
||||
mstdnt_accounts_json(struct mstdnt_account* accounts[],
|
||||
size_t* size,
|
||||
cJSON* js);
|
||||
|
||||
#define MSTDNT_ACCOUNT_ACTION_DECL(type) int mstdnt_##type##_account(mastodont_t* data, struct mstdnt_args* args, char* id, struct mstdnt_storage* storage, struct mstdnt_relationship* relationship)
|
||||
#define MSTDNT_ACCOUNT_ACTION_FUNC_URL(action) { \
|
||||
return mstdnt_account_action(data, args, id, storage, relationship, "api/v1/accounts/%s/" action); \
|
||||
#define MSTDNT_ACCOUNT_ACTION_DECL(type) \
|
||||
int mstdnt_##type##_account(mastodont_t* data, \
|
||||
struct mstdnt_args* args, \
|
||||
mstdnt_request_cb_t cb_request, \
|
||||
void* cb_args, \
|
||||
char* id)
|
||||
|
||||
#define MSTDNT_ACCOUNT_ACTION_FUNC_URL(action) { \
|
||||
return mstdnt_account_action(data, \
|
||||
args, \
|
||||
cb_request, \
|
||||
cb_args, \
|
||||
id, \
|
||||
"api/v1/accounts/%s/" action); \
|
||||
}
|
||||
|
||||
MSTDNT_ACCOUNT_ACTION_DECL(follow);
|
||||
|
@ -101,56 +110,67 @@ MSTDNT_ACCOUNT_ACTION_DECL(unblock);
|
|||
MSTDNT_ACCOUNT_ACTION_DECL(subscribe);
|
||||
MSTDNT_ACCOUNT_ACTION_DECL(unsubscribe);
|
||||
|
||||
int mstdnt_verify_credentials(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_account* acct,
|
||||
struct mstdnt_storage* storage);
|
||||
|
||||
int mstdnt_get_account(mastodont_t* data,
|
||||
int
|
||||
mstdnt_verify_credentials(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
int lookup_type,
|
||||
char* id,
|
||||
struct mstdnt_account* acct,
|
||||
struct mstdnt_storage* storage);
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args);
|
||||
|
||||
int mstdnt_get_blocks(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_account_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_account* accts[],
|
||||
size_t* accts_len);
|
||||
int
|
||||
mstdnt_get_account(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
int lookup_type,
|
||||
char* id);
|
||||
|
||||
int mstdnt_get_mutes(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_account_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_account* accts[],
|
||||
size_t* accts_len);
|
||||
int
|
||||
mstdnt_get_blocks(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_account_args args);
|
||||
|
||||
int mstdnt_get_followers(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_account_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_account* accts[],
|
||||
size_t* accts_len);
|
||||
int
|
||||
mstdnt_get_mutes(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_account_args args);
|
||||
|
||||
int mstdnt_get_following(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_account_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_account* accts[],
|
||||
size_t* accts_len);
|
||||
int
|
||||
mstdnt_get_followers(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
struct mstdnt_account_args args);
|
||||
|
||||
int mstdnt_account_json(struct mstdnt_account* acct, cJSON* js);
|
||||
int mstdnt_account_json_callback(cJSON* json, void* _args);
|
||||
int mstdnt_accounts_json_callback(cJSON* json, void* _args);
|
||||
int
|
||||
mstdnt_get_following(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
struct mstdnt_account_args args);
|
||||
|
||||
int
|
||||
mstdnt_account_json(struct mstdnt_account* acct,
|
||||
cJSON* js);
|
||||
|
||||
int
|
||||
mstdnt_account_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data);
|
||||
int
|
||||
mstdnt_accounts_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data);
|
||||
void _mstdnt_val_account_call(cJSON* v, void* _type);
|
||||
void _mstdnt_val_malloc_account_call(cJSON* v, void* _type);
|
||||
|
||||
// Cleanup
|
||||
void mstdnt_cleanup_account(struct mstdnt_account* acct);
|
||||
void mstdnt_cleanup_accounts(struct mstdnt_account* accts, size_t len);
|
||||
void mstdnt_cleanup_accounts(struct mstdnt_accounts* accts);
|
||||
|
||||
#endif /* MASTODONT_ACCOUNT */
|
||||
|
|
|
@ -1,22 +1,11 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_ANNOUNCEMENT_H
|
||||
#define MASTODONT_ANNOUNCEMENT_H
|
||||
#include <mastodont_types.h>
|
||||
|
||||
#include "mastodont_types.h"
|
||||
|
||||
// TODO
|
||||
|
||||
#endif /* MASTODONT_ANNOUNCEMENT_H */
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_APPLICATION
|
||||
|
@ -56,17 +45,19 @@ struct mstdnt_application_args
|
|||
char* website;
|
||||
};
|
||||
|
||||
int mstdnt_register_app(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_application_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_app* app);
|
||||
int
|
||||
mstdnt_register_app(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_application_args args);
|
||||
|
||||
int mstdnt_obtain_oauth_token(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_application_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_oauth_token* app);
|
||||
int
|
||||
mstdnt_obtain_oauth_token(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_application_args args);
|
||||
|
||||
void _mstdnt_val_malloc_application_call(cJSON* v, void* _type);
|
||||
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_ATTACHMENT
|
||||
|
@ -47,17 +36,24 @@ struct mstdnt_upload_media_args
|
|||
/* TODO focus */
|
||||
};
|
||||
|
||||
int mstdnt_attachment_json(cJSON* att_json, struct mstdnt_attachment* att);
|
||||
int
|
||||
mstdnt_attachment_json(cJSON* att_json, struct mstdnt_attachment* att);
|
||||
|
||||
void _mstdnt_val_attachments_call(cJSON* v, void* _type);
|
||||
void
|
||||
_mstdnt_val_attachments_call(cJSON* v, void* _type);
|
||||
|
||||
int mstdnt_upload_media(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_upload_media_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_attachment* attachment);
|
||||
int
|
||||
mstdnt_upload_media(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_upload_media_args args);
|
||||
|
||||
void
|
||||
mstdnt_cleanup_attachments(struct mstdnt_attachment* attachment);
|
||||
|
||||
void
|
||||
_mstdnt_val_attachments_call(cJSON* v, void* _type);
|
||||
|
||||
void mstdnt_cleanup_attachments(struct mstdnt_attachment* attachment);
|
||||
void _mstdnt_val_attachments_call(cJSON* v, void* _type);
|
||||
|
||||
#endif /* MASTODONT_ATTACHMENT */
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_CHATS_H
|
||||
|
@ -40,6 +29,12 @@ struct mstdnt_message
|
|||
mstdnt_bool unread;
|
||||
};
|
||||
|
||||
struct mstdnt_chats
|
||||
{
|
||||
struct mstdnt_chat* chats;
|
||||
size_t len;
|
||||
};
|
||||
|
||||
struct mstdnt_chats_args
|
||||
{
|
||||
mstdnt_bool with_muted;
|
||||
|
@ -50,37 +45,54 @@ struct mstdnt_chats_args
|
|||
int limit;
|
||||
};
|
||||
|
||||
int mstdnt_chat_json(struct mstdnt_chat* chat, cJSON* js);
|
||||
int mstdnt_chats_json(struct mstdnt_chat* statuses[],
|
||||
size_t* size,
|
||||
cJSON* js);
|
||||
int mstdnt_message_json(struct mstdnt_message* message, cJSON* js);
|
||||
int mstdnt_message_json_callback(cJSON* json, void* chat);
|
||||
int mstdnt_messages_json(struct mstdnt_message* message[], size_t* size, cJSON* js);
|
||||
int
|
||||
mstdnt_chat_json(struct mstdnt_chat* chat, cJSON* js);
|
||||
|
||||
int mstdnt_get_chats_v2(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_chats_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_chat* chats[],
|
||||
size_t* chats_len);
|
||||
int
|
||||
mstdnt_chats_json(struct mstdnt_chat* statuses[],
|
||||
size_t* size,
|
||||
cJSON* js);
|
||||
int
|
||||
mstdnt_message_json(struct mstdnt_message* message, cJSON* js);
|
||||
|
||||
int mstdnt_get_chat_messages(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* chat_id,
|
||||
struct mstdnt_chats_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_message* chats[],
|
||||
size_t* size);
|
||||
int
|
||||
mstdnt_message_json_callback(cJSON* json,
|
||||
void* chat,
|
||||
mstdnt_request_cb_data* data);
|
||||
|
||||
int mstdnt_get_chat(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* chat_id,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_chat* chat);
|
||||
int
|
||||
mstdnt_chat_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data);
|
||||
|
||||
int mstdnt_messages_json(struct mstdnt_message* message[],
|
||||
size_t* size,
|
||||
cJSON* js);
|
||||
|
||||
int
|
||||
mstdnt_get_chats_v2(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_chats_args args);
|
||||
|
||||
int
|
||||
mstdnt_get_chat_messages(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* chat_id,
|
||||
struct mstdnt_chats_args args);
|
||||
|
||||
int
|
||||
mstdnt_get_chat(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* chat_id);
|
||||
|
||||
void mstdnt_cleanup_chat(struct mstdnt_chat* chat);
|
||||
void mstdnt_cleanup_chats(struct mstdnt_chat* chats, size_t len);
|
||||
void mstdnt_cleanup_messages(struct mstdnt_message* chats);
|
||||
void mstdnt_cleanup_chats(struct mstdnt_chats* chats);
|
||||
void mstdnt_cleanup_message(struct mstdnt_message* chats);
|
||||
|
||||
#endif // MASTODONT_CHATS_H
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_CODES_H
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_EMOJI
|
||||
|
|
|
@ -1,22 +1,11 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_ERROR_H
|
||||
#define MASTODONT_ERROR_H
|
||||
#include <mastodont_types.h>
|
||||
#include <mastodont_fetch.h>
|
||||
#include "mastodont_types.h"
|
||||
#include "mastodont_fetch.h"
|
||||
|
||||
int mstdnt_check_error(struct mstdnt_storage* storage);
|
||||
|
||||
|
|
|
@ -1,38 +1,114 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_FETCH_H
|
||||
#define MASTODONT_FETCH_H
|
||||
#include <cjson/cJSON.h>
|
||||
#include <mastodont_types.h>
|
||||
#include <curl/curl.h>
|
||||
#include "mastodont_types.h"
|
||||
|
||||
struct mstdnt_fetch_results
|
||||
/** Used to store the response from CURL */
|
||||
struct mstdnt_fetch_data
|
||||
{
|
||||
char* response;
|
||||
size_t size;
|
||||
|
||||
// Callback from user
|
||||
mstdnt_request_cb_t callback;
|
||||
void* callback_args;
|
||||
int (*json_cb)(cJSON*, void*, mstdnt_request_cb_data*);
|
||||
void* json_args;
|
||||
};
|
||||
|
||||
struct mstdnt_fd
|
||||
{
|
||||
int fd;
|
||||
short events;
|
||||
short revents;
|
||||
};
|
||||
|
||||
/* Note: Don't quite rely on these values being equal to curl's! */
|
||||
enum mstdnt_fds_events
|
||||
{
|
||||
MSTDNT_POLLIN = CURL_WAIT_POLLIN,
|
||||
MSTDNT_POLLPRI = CURL_WAIT_POLLPRI,
|
||||
MSTDNT_POLLOUT = CURL_WAIT_POLLOUT,
|
||||
};
|
||||
|
||||
enum mstdnt_fetch_await
|
||||
{
|
||||
MSTDNT_AWAIT_ALL,
|
||||
MSTDNT_AWAIT_ONCE,
|
||||
};
|
||||
|
||||
size_t mstdnt_curl_write_callback(char* ptr, size_t _size, size_t nmemb, void* _content);
|
||||
void mstdnt_fetch_results_cleanup(struct mstdnt_fetch_results* res);
|
||||
int mstdnt_fetch_curl(mastodont_t* mstdnt,
|
||||
CURL* curl,
|
||||
struct mstdnt_args* args,
|
||||
char* url,
|
||||
struct mstdnt_fetch_results* results,
|
||||
CURLoption request_t,
|
||||
char* request_t_custom);
|
||||
void mstdnt_fetch_data_cleanup(struct mstdnt_fetch_data* res);
|
||||
|
||||
/**
|
||||
* @brief Attempts to fetch, async or blocking.
|
||||
*
|
||||
* @param mstdnt Mastodont struct
|
||||
* @param curl curl API
|
||||
* @param args Mastodont General args passed
|
||||
* @param url URL of request
|
||||
* @param results Results from response
|
||||
* @return Number of connections in progress, or -1 on error
|
||||
*/
|
||||
int mstdnt_fetch_curl_async(mastodont_t* mstdnt,
|
||||
CURL* curl,
|
||||
struct mstdnt_args* args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
int (*json_cb)(cJSON*, void*, mstdnt_request_cb_data*),
|
||||
void* json_args,
|
||||
char* url,
|
||||
CURLoption request_t,
|
||||
char* request_t_custom);
|
||||
|
||||
/**
|
||||
* \brief Blocks until a transfer is complete.
|
||||
*
|
||||
* You can also check curl's socket, but mastodont offers ways to do that
|
||||
* in case of change
|
||||
*
|
||||
* \param mstdnt Mastodont struct
|
||||
* \param opt Option, MSTDNT_AWAIT_ALL means it will keep going until
|
||||
* there are no more transfers. MSTDNT_AWAIT_ONCE will run
|
||||
* \param extra_fds Set of file descriptors to poll alongside
|
||||
* the mastodont data.
|
||||
* \param nfds Length of extra_fds
|
||||
* \return 1 on error
|
||||
*/
|
||||
int mstdnt_await(mastodont_t* mstdnt,
|
||||
enum mstdnt_fetch_await opt,
|
||||
struct mstdnt_fd extra_fds[],
|
||||
size_t nfds);
|
||||
|
||||
|
||||
/**
|
||||
* Returns a array of file descriptors to network sockets (if any)
|
||||
*
|
||||
* These file descriptors only notify when ready to read.
|
||||
*
|
||||
* \remark If you need the write-ready sockets available, poke at CURLM*
|
||||
directly
|
||||
* \remark Usually required if you want to interface Mastodont with
|
||||
* application event loops (i.e. GTK, QT, EFL)
|
||||
*
|
||||
* \param read Reference ptr to read set
|
||||
* \param write Reference ptr to write set
|
||||
* \param error Reference ptr to error set
|
||||
* \param nfds Number of file descriptors to check for reading.
|
||||
* \return 0 on success, 1 on error
|
||||
*/
|
||||
int
|
||||
mstdnt_get_fds(mastodont_t* mstdnt,
|
||||
fd_set* read,
|
||||
fd_set* write,
|
||||
fd_set* error,
|
||||
int* nfds);
|
||||
|
||||
void mstdnt_request_cb_cleanup(mstdnt_request_cb_data* data);
|
||||
|
||||
#endif /* MASTODONT_FETCH_H */
|
||||
|
|
|
@ -30,8 +30,8 @@
|
|||
\
|
||||
if (!arr_len) \
|
||||
return 0; \
|
||||
\
|
||||
*array = calloc(1, arr_len * sizeof(type)); \
|
||||
\
|
||||
*array = calloc(arr_len, sizeof(type)); \
|
||||
\
|
||||
if (*array == NULL) \
|
||||
return 1; \
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_HISTORY
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_HOOKS_H
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_INSTANCE_H
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_JSON_HELPER_H
|
||||
|
@ -32,7 +21,7 @@ struct _mstdnt_val_ref
|
|||
};
|
||||
|
||||
int _mstdnt_json_init(cJSON** root,
|
||||
struct mstdnt_fetch_results* results,
|
||||
struct mstdnt_fetch_data* results,
|
||||
struct mstdnt_storage* storage);
|
||||
|
||||
int _mstdnt_key_val_ref(cJSON* v, struct _mstdnt_val_ref* refs,
|
||||
|
|
|
@ -1,24 +1,13 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_LIST_H
|
||||
#define MASTODONT_LIST_H
|
||||
#include <mastodont_types.h>
|
||||
#include "mastodont_types.h"
|
||||
#include <cjson/cJSON.h>
|
||||
#include <mastodont_fetch.h>
|
||||
#include <mastodont_account.h>
|
||||
#include "mastodont_fetch.h"
|
||||
#include "mastodont_account.h"
|
||||
|
||||
enum mstdnt_list_replies_policy
|
||||
{
|
||||
|
@ -30,12 +19,18 @@ enum mstdnt_list_replies_policy
|
|||
MSTDNT_LIST_REPLIES_POLICY_FOLLOWED
|
||||
};
|
||||
|
||||
struct mstdnt_list
|
||||
typedef struct mstdnt_list
|
||||
{
|
||||
char* id;
|
||||
char* title;
|
||||
enum mstdnt_list_replies_policy replies_policy;
|
||||
};
|
||||
} mstdnt_list;
|
||||
|
||||
typedef struct mstdnt_lists
|
||||
{
|
||||
struct mstdnt_list* lists;
|
||||
size_t len;
|
||||
} mstdnt_lists;
|
||||
|
||||
struct mstdnt_list_args
|
||||
{
|
||||
|
@ -43,65 +38,77 @@ struct mstdnt_list_args
|
|||
enum mstdnt_list_replies_policy replies_policy;
|
||||
};
|
||||
|
||||
int mstdnt_list_json(struct mstdnt_list* list, cJSON* js);
|
||||
int
|
||||
mstdnt_list_json(struct mstdnt_list* list,
|
||||
cJSON* js);
|
||||
|
||||
int mstdnt_lists_json(struct mstdnt_list* lists[],
|
||||
size_t* size,
|
||||
cJSON* json);
|
||||
int
|
||||
mstdnt_lists_json(struct mstdnt_list* lists[],
|
||||
size_t* size,
|
||||
cJSON* json);
|
||||
|
||||
int mstdnt_get_lists(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_list* lists[],
|
||||
size_t* size);
|
||||
int
|
||||
mstdnt_get_lists(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args);
|
||||
|
||||
int mstdnt_get_list(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_list* lists);
|
||||
int
|
||||
mstdnt_get_list(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id);
|
||||
|
||||
int mstdnt_create_list(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_list_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_list* list);
|
||||
int
|
||||
mstdnt_create_list(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_list_args args);
|
||||
|
||||
int mstdnt_update_list(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_list_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_list* list);
|
||||
int
|
||||
mstdnt_update_list(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
struct mstdnt_list_args args);
|
||||
|
||||
int mstdnt_delete_list(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_storage* storage);
|
||||
int
|
||||
mstdnt_delete_list(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id);
|
||||
|
||||
int mstdnt_list_get_accounts(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_account_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_account* accts[],
|
||||
size_t* accts_len);
|
||||
int
|
||||
mstdnt_list_get_accounts(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
struct mstdnt_account_args args);
|
||||
|
||||
int mstdnt_list_add_accounts(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
char** account_ids,
|
||||
size_t account_ids_len,
|
||||
struct mstdnt_storage* storage);
|
||||
int
|
||||
mstdnt_list_add_accounts(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
char** account_ids,
|
||||
size_t account_ids_len);
|
||||
|
||||
int mstdnt_list_remove_accounts(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
char** account_ids,
|
||||
size_t account_ids_len,
|
||||
struct mstdnt_storage* storage);
|
||||
int
|
||||
mstdnt_list_remove_accounts(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
char** account_ids,
|
||||
size_t account_ids_len);
|
||||
|
||||
// Cleanup
|
||||
void mstdnt_cleanup_lists(struct mstdnt_list* lists);
|
||||
void mstdnt_cleanup_lists(struct mstdnt_lists* lists);
|
||||
|
||||
#endif /* MASTODONT_LIST_H */
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_MENTION
|
||||
|
|
|
@ -1,22 +1,10 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_NODEINFO_H
|
||||
#define MASTODONT_NODEINFO_H
|
||||
#include <mastodont_types.h>
|
||||
|
||||
#include "mastodont_types.h"
|
||||
|
||||
struct mstdnt_nodeinfo_metadata
|
||||
{
|
||||
|
@ -41,10 +29,13 @@ int mstdnt_nodeinfo_json(struct mstdnt_nodeinfo* nodeinfo, cJSON* js);
|
|||
|
||||
int mstdnt_nodeinfo_json_callback(cJSON* json, void* nodeinfo);
|
||||
|
||||
int mstdnt_get_nodeinfo(mastodont_t* api, struct mstdnt_args* args,
|
||||
char* version,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_nodeinfo* nodeinfo);
|
||||
int mstdnt_get_nodeinfo(mastodont_t* api,
|
||||
struct mstdnt_args* args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* version,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_nodeinfo* nodeinfo);
|
||||
|
||||
void mstdnt_cleanup_nodeinfo(struct mstdnt_nodeinfo* nodeinfo);
|
||||
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_NOTIF_TYPES
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_NOTIFICATION
|
||||
|
@ -40,6 +29,12 @@ struct mstdnt_notification
|
|||
mstdnt_notification_t type;
|
||||
};
|
||||
|
||||
struct mstdnt_notifications
|
||||
{
|
||||
struct mstdnt_notification* notifs;
|
||||
size_t len;
|
||||
};
|
||||
|
||||
struct mstdnt_notifications_args
|
||||
{
|
||||
/* Bitmask */
|
||||
|
@ -65,35 +60,50 @@ struct _mstdnt_notifications_result_cb_args
|
|||
};
|
||||
|
||||
// Callback helpers
|
||||
int mstdnt_notification_json_callback(cJSON* json, void* notif);
|
||||
int mstdnt_notifications_json_callback(cJSON* json, void* _args);
|
||||
int
|
||||
mstdnt_notification_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data);
|
||||
|
||||
int mstdnt_notification_json(struct mstdnt_notification* notif, cJSON* js);
|
||||
int mstdnt_notification_pleroma_json(struct mstdnt_notification_pleroma* notif, cJSON* js);
|
||||
int
|
||||
mstdnt_notifications_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data);
|
||||
|
||||
int mstdnt_get_notifications(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_notifications_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_notification** notifs,
|
||||
size_t* size);
|
||||
int
|
||||
mstdnt_notification_json(struct mstdnt_notification* notif, cJSON* js);
|
||||
|
||||
int mstdnt_notifications_clear(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_storage* storage);
|
||||
int
|
||||
mstdnt_notification_pleroma_json(struct mstdnt_notification_pleroma* notif, cJSON* js);
|
||||
|
||||
int mstdnt_notifications_read(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_notifications_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_notification* notification);
|
||||
int
|
||||
mstdnt_get_notifications(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_notifications_args args);
|
||||
|
||||
int mstdnt_notification_dismiss(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_storage* storage,
|
||||
char* id);
|
||||
int
|
||||
mstdnt_notifications_clear(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args);
|
||||
|
||||
void mstdnt_cleanup_notifications(struct mstdnt_notification* notif, size_t notif_len);
|
||||
int
|
||||
mstdnt_notifications_read(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_notifications_args args);
|
||||
|
||||
int
|
||||
mstdnt_notification_dismiss(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id);
|
||||
|
||||
void mstdnt_cleanup_notifications(struct mstdnt_notifications* notif);
|
||||
void mstdnt_cleanup_notification(struct mstdnt_notification* notif);
|
||||
|
||||
#endif /* MASTODONT_NOTIFICATION */
|
||||
|
|
|
@ -1,24 +1,13 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
|
||||
// TODO Move me to statuses
|
||||
#ifndef MASTODONT_PLEROMA
|
||||
#define MASTODONT_PLEROMA
|
||||
#include <mastodont_types.h>
|
||||
#include <mastodont_emoji.h>
|
||||
#include "mastodont_types.h"
|
||||
#include "mastodont_emoji.h"
|
||||
|
||||
struct mstdnt_status_pleroma
|
||||
{
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_QUERY_H
|
||||
|
|
|
@ -1,24 +1,13 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_RELATIONSHIP_H
|
||||
#define MASTODONT_RELATIONSHIP_H
|
||||
#include <stdint.h>
|
||||
#include <cjson/cJSON.h>
|
||||
#include <mastodont_types.h>
|
||||
#include <mastodont_request.h>
|
||||
#include "mastodont_types.h"
|
||||
#include "mastodont_request.h"
|
||||
|
||||
typedef uint16_t mstdnt_relationship_flag_t;
|
||||
|
||||
|
@ -35,14 +24,23 @@ typedef uint16_t mstdnt_relationship_flag_t;
|
|||
#define MSTDNT_RELATIONSHIP_DOMAIN_BLOCKING (1<<9)
|
||||
#define MSTDNT_RELATIONSHIP_BLOCKED_BY (1<<10)
|
||||
|
||||
struct mstdnt_relationship
|
||||
typedef struct mstdnt_relationship
|
||||
{
|
||||
char* id;
|
||||
mstdnt_relationship_flag_t flags;
|
||||
char* note;
|
||||
};
|
||||
} mstdnt_relationship;
|
||||
|
||||
int mstdnt_relationship_json_callback(cJSON* json, void* _args);
|
||||
typedef struct mstdnt_relationships
|
||||
{
|
||||
mstdnt_relationship* relationships;
|
||||
size_t len;
|
||||
} mstdnt_relationships;
|
||||
|
||||
int
|
||||
mstdnt_relationship_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data);
|
||||
|
||||
int mstdnt_relationship_json(struct mstdnt_relationship* relationship, cJSON* js);
|
||||
|
||||
|
@ -50,16 +48,20 @@ int mstdnt_relationships_json(struct mstdnt_relationship* relationships[],
|
|||
size_t* size,
|
||||
cJSON* json);
|
||||
|
||||
int mstdnt_relationships_json_callback(cJSON* json, void* _args);
|
||||
int
|
||||
mstdnt_relationships_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data);
|
||||
|
||||
int mstdnt_get_relationships(mastodont_t* data, struct mstdnt_args* args,
|
||||
char** ids,
|
||||
size_t ids_len,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_relationship* relationships[],
|
||||
size_t* size);
|
||||
int
|
||||
mstdnt_get_relationships(mastodont_t* data,
|
||||
struct mstdnt_args* args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char** ids,
|
||||
size_t ids_len);
|
||||
|
||||
void mstdnt_cleanup_relationships(struct mstdnt_relationship* rels);
|
||||
void mstdnt_cleanup_relationships(struct mstdnt_relationships* rels);
|
||||
|
||||
|
||||
#endif /* MASTODONT_RELATIONSHIP_H */
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_REQUEST_H
|
||||
|
@ -31,11 +20,22 @@ struct mstdnt_request_args
|
|||
CURLoption request_type;
|
||||
char* request_type_custom;
|
||||
void* args;
|
||||
int (*callback)(cJSON*, void*);
|
||||
int (*callback)(cJSON*, void*, mstdnt_request_cb_data*);
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends a mastoAPI request to an HTTP server.
|
||||
*
|
||||
* @param data Mastodont struct
|
||||
* @param m_args Mastodont general args pointer
|
||||
* @param cb_request Callback pointer associated with this request
|
||||
* @param cb_args Args passed into cb_request
|
||||
* @param args Propagated arguments to request to the server
|
||||
*/
|
||||
int mstdnt_request(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_request_args* args);
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_request_args* args);
|
||||
|
||||
#endif /* MASTODONT_REQUEST_H */
|
||||
|
|
|
@ -1,26 +1,14 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_SCROBBLES_H
|
||||
#define MASTODONT_SCROBBLES_H
|
||||
#include <stddef.h>
|
||||
#include <mastodont.h>
|
||||
#include <mastodont_types.h>
|
||||
#include <mastodont_account.h>
|
||||
#include "mastodont_types.h"
|
||||
#include "mastodont_account.h"
|
||||
|
||||
struct mstdnt_scrobble
|
||||
typedef struct mstdnt_scrobble
|
||||
{
|
||||
struct mstdnt_account account;
|
||||
char* album;
|
||||
|
@ -29,7 +17,13 @@ struct mstdnt_scrobble
|
|||
char* id;
|
||||
int length;
|
||||
char* title;
|
||||
};
|
||||
} mstdnt_scrobble;
|
||||
|
||||
typedef struct mstdnt_scrobbles
|
||||
{
|
||||
mstdnt_scrobble* scrobbles;
|
||||
size_t len;
|
||||
} mstdnt_scrobbles;
|
||||
|
||||
struct mstdnt_get_scrobbles_args
|
||||
{
|
||||
|
@ -40,27 +34,38 @@ struct mstdnt_get_scrobbles_args
|
|||
int limit;
|
||||
};
|
||||
|
||||
// DEPRECATED
|
||||
struct _mstdnt_scrobbles_cb_args
|
||||
{
|
||||
struct mstdnt_scrobble** scrobbles;
|
||||
size_t* size;
|
||||
};
|
||||
|
||||
int mstdnt_get_scrobbles(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_get_scrobbles_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_scrobble* scrobbles[],
|
||||
size_t* size);
|
||||
int
|
||||
mstdnt_get_scrobbles(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
struct mstdnt_get_scrobbles_args args);
|
||||
|
||||
int mstdnt_scrobbles_json(struct mstdnt_scrobble* scrobbles[],
|
||||
size_t* size,
|
||||
cJSON* json);
|
||||
int
|
||||
mstdnt_scrobbles_json(struct mstdnt_scrobble* scrobbles[],
|
||||
size_t* size,
|
||||
cJSON* json);
|
||||
|
||||
int mstdnt_scrobbles_json_callback(cJSON* json,
|
||||
void* arg);
|
||||
int
|
||||
mstdnt_scrobbles_json_callback(cJSON* json,
|
||||
void* arg,
|
||||
mstdnt_request_cb_data* data);
|
||||
|
||||
int mstdnt_scrobble_json(struct mstdnt_scrobble* scrobble, cJSON* js);
|
||||
int
|
||||
mstdnt_scrobble_json(struct mstdnt_scrobble* scrobble, cJSON* js);
|
||||
|
||||
void
|
||||
mstdnt_cleanup_scrobble(mstdnt_scrobble* scrobble);
|
||||
|
||||
void
|
||||
mstdnt_cleanup_scrobbles(mstdnt_scrobbles* scrobbles);
|
||||
|
||||
#endif /* MASTODONT_SCROBBLES_H */
|
||||
|
|
|
@ -1,21 +1,9 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_SEARCH_H
|
||||
#define MASTODONT_SEARCH_H
|
||||
#include "mastodont.h"
|
||||
#include "mastodont_types.h"
|
||||
|
||||
enum mstdnt_search_type
|
||||
|
@ -42,24 +30,26 @@ struct mstdnt_search_args
|
|||
|
||||
struct mstdnt_search_results
|
||||
{
|
||||
struct mstdnt_account* accts;
|
||||
size_t accts_len;
|
||||
struct mstdnt_status* statuses;
|
||||
size_t statuses_len;
|
||||
struct mstdnt_tag* tags;
|
||||
size_t tags_len;
|
||||
struct mstdnt_accounts* accts;
|
||||
struct mstdnt_statuses* statuses;
|
||||
struct mstdnt_tags* tags;
|
||||
};
|
||||
|
||||
int mstdnt_search_json_callback(cJSON* json, void* _args);
|
||||
int
|
||||
mstdnt_search_json_callback(cJSON* json,
|
||||
void* _args,
|
||||
mstdnt_request_cb_data* data);
|
||||
|
||||
int mstdnt_search_json(struct mstdnt_search_results* search_results, cJSON* json);
|
||||
int
|
||||
mstdnt_search_json(struct mstdnt_search_results* search_results, cJSON* json);
|
||||
|
||||
int mstdnt_search(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* query,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_search_args* args,
|
||||
struct mstdnt_search_results* results);
|
||||
int
|
||||
mstdnt_search(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* query,
|
||||
struct mstdnt_search_args args);
|
||||
|
||||
void mstdnt_cleanup_search_results(struct mstdnt_search_results* res);
|
||||
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* 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 mstdnt_instance_panel(mastodont_t* api,
|
||||
struct mstdnt_args* args,
|
||||
struct mstdnt_fetch_results* html);
|
||||
|
||||
int mstdnt_terms_of_service(mastodont_t* api,
|
||||
struct mstdnt_args* args,
|
||||
struct mstdnt_fetch_results* html);
|
||||
|
||||
#endif /* MSTDNT_STATIC_H */
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_STATUS
|
||||
|
@ -29,7 +18,6 @@
|
|||
#include "mastodont_pleroma.h"
|
||||
#include "mastodont_account.h"
|
||||
#include "mastodont_visibility_types.h"
|
||||
/* Status: Complete, not implemented */
|
||||
|
||||
struct mstdnt_status
|
||||
{
|
||||
|
@ -108,77 +96,94 @@ struct mstdnt_status_args
|
|||
int media_ids_len;
|
||||
};
|
||||
|
||||
// Cleanup
|
||||
void mstdnt_cleanup_statuses(struct mstdnt_status* statuses, size_t s);
|
||||
void mstdnt_cleanup_status(struct mstdnt_status* status);
|
||||
int
|
||||
mstdnt_status_json(struct mstdnt_status* status, cJSON* js);
|
||||
|
||||
int mstdnt_status_json(struct mstdnt_status* status, cJSON* js);
|
||||
int mstdnt_status_emoji_react(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
char* emoji,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* status);
|
||||
int
|
||||
mstdnt_status_emoji_react(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
char* emoji);
|
||||
|
||||
// Generated function
|
||||
int mstdnt_statuses_json(struct mstdnt_status* statuses[],
|
||||
size_t* size,
|
||||
cJSON* js);
|
||||
int
|
||||
mstdnt_statuses_json(struct mstdnt_status* statuses[],
|
||||
size_t* size,
|
||||
cJSON* js);
|
||||
|
||||
void _mstdnt_val_status_call(cJSON* v, void* _type);
|
||||
void _mstdnt_val_malloc_status_call(cJSON* v, void* _type);
|
||||
void
|
||||
_mstdnt_val_status_call(cJSON* v, void* args);
|
||||
|
||||
int mstdnt_status_context_json(struct mstdnt_status* statuses_before[],
|
||||
struct mstdnt_status* statuses_after[],
|
||||
size_t* size_before,
|
||||
size_t* size_after,
|
||||
cJSON* js);
|
||||
void
|
||||
_mstdnt_val_malloc_status_call(cJSON* v, void* args);
|
||||
|
||||
int mstdnt_get_account_statuses(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_account_statuses_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses[],
|
||||
size_t* size);
|
||||
int
|
||||
mstdnt_status_context_json(struct mstdnt_status* statuses_before[],
|
||||
struct mstdnt_status* statuses_after[],
|
||||
size_t* size_before,
|
||||
size_t* size_after,
|
||||
cJSON* js);
|
||||
|
||||
int mstdnt_get_status(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* status);
|
||||
|
||||
int mstdnt_get_status_context(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses_before[],
|
||||
struct mstdnt_status* statuses_after[],
|
||||
size_t* size_before,
|
||||
size_t* size_after);
|
||||
|
||||
int mstdnt_status_favourited_by(mastodont_t* data, struct mstdnt_args* args,
|
||||
char* id,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_account* accounts[],
|
||||
size_t* accts);
|
||||
|
||||
int mstdnt_status_reblogged_by(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_account* accounts[],
|
||||
size_t* accts);
|
||||
|
||||
int mstdnt_create_status(mastodont_t* data,
|
||||
int
|
||||
mstdnt_get_account_statuses(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_status_args* args,
|
||||
struct mstdnt_storage* storage);
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
struct mstdnt_account_statuses_args args);
|
||||
|
||||
int
|
||||
mstdnt_get_status(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id);
|
||||
|
||||
int
|
||||
mstdnt_get_status_context(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id);
|
||||
|
||||
int
|
||||
mstdnt_status_favourited_by(mastodont_t* data,
|
||||
struct mstdnt_args* args,
|
||||
mstdnt_request_cb_t cb_reqest,
|
||||
void* cb_args,
|
||||
char* id);
|
||||
|
||||
int
|
||||
mstdnt_status_reblogged_by(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id);
|
||||
|
||||
int
|
||||
mstdnt_create_status(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_status_args args);
|
||||
|
||||
/* Generates do and undo functions */
|
||||
#define MSTDNT_STATUS_ACTION_DECL(type) int mstdnt_##type##_status(mastodont_t* data, struct mstdnt_args* m_args, char* id, struct mstdnt_storage* storage, struct mstdnt_status* status)
|
||||
#define MSTDNT_STATUS_ACTION_FUNC_URL(action) { \
|
||||
return mstdnt_status_action(data, m_args, id, storage, status, "api/v1/statuses/%s/" action); \
|
||||
#define MSTDNT_STATUS_ACTION_DECL(type) \
|
||||
int mstdnt_##type##_status(mastodont_t* data, \
|
||||
struct mstdnt_args* m_args, \
|
||||
mstdnt_request_cb_t cb_request, \
|
||||
void* cb_args, \
|
||||
char* id)
|
||||
|
||||
#define MSTDNT_STATUS_ACTION_FUNC_URL(action) { \
|
||||
return mstdnt_status_action(data, \
|
||||
m_args, \
|
||||
cb_request, \
|
||||
cb_args, \
|
||||
id, \
|
||||
"api/v1/statuses/%s/" action); \
|
||||
}
|
||||
|
||||
MSTDNT_STATUS_ACTION_DECL(favourite);
|
||||
|
@ -191,27 +196,46 @@ MSTDNT_STATUS_ACTION_DECL(bookmark);
|
|||
MSTDNT_STATUS_ACTION_DECL(unbookmark);
|
||||
MSTDNT_STATUS_ACTION_DECL(delete);
|
||||
|
||||
int mstdnt_mute_conversation(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* status);
|
||||
int
|
||||
mstdnt_mute_conversation(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id);
|
||||
|
||||
int mstdnt_unmute_conversation(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* status);
|
||||
int
|
||||
mstdnt_unmute_conversation(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id);
|
||||
|
||||
|
||||
struct mstdnt_statuses
|
||||
{
|
||||
struct mstdnt_status* statuses;
|
||||
size_t len;
|
||||
};
|
||||
|
||||
/* Callbacks */
|
||||
struct mstdnt_status_context
|
||||
{
|
||||
struct mstdnt_statuses before;
|
||||
struct mstdnt_statuses after;
|
||||
};
|
||||
|
||||
|
||||
// DEPRECATED
|
||||
struct _mstdnt_statuses_cb_args
|
||||
{
|
||||
struct mstdnt_status** statuses;
|
||||
size_t* size;
|
||||
};
|
||||
|
||||
// DEPRECATED
|
||||
struct _mstdnt_status_context_result_cb_args
|
||||
{
|
||||
|
||||
struct mstdnt_status** statuses_before;
|
||||
struct mstdnt_status** statuses_after;
|
||||
size_t* size_before;
|
||||
|
@ -233,22 +257,29 @@ struct mstdnt_favourites_args
|
|||
int limit;
|
||||
};
|
||||
|
||||
int mstdnt_get_bookmarks(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_bookmarks_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses[],
|
||||
size_t* size);
|
||||
int
|
||||
mstdnt_get_bookmarks(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_bookmarks_args args);
|
||||
|
||||
int mstdnt_get_favourites(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_favourites_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses[],
|
||||
size_t* size);
|
||||
int
|
||||
mstdnt_get_favourites(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_favourites_args args);
|
||||
|
||||
int mstdnt_statuses_json_callback(cJSON* json, void* _args);
|
||||
int mstdnt_status_json_callback(cJSON* json, void* status);
|
||||
int mstdnt_status_context_json_callback(cJSON* json, void* _args);
|
||||
int mstdnt_statuses_json_callback(cJSON* json, void* args, mstdnt_request_cb_data* data);
|
||||
int mstdnt_status_json_callback(cJSON* json, void* args, mstdnt_request_cb_data* results);
|
||||
int mstdnt_status_context_json_callback(cJSON* json, void* args, mstdnt_request_cb_data* results);
|
||||
|
||||
// Cleanup
|
||||
void
|
||||
mstdnt_cleanup_statuses(struct mstdnt_statuses* statuses);
|
||||
|
||||
void
|
||||
mstdnt_cleanup_status(struct mstdnt_status* status);
|
||||
|
||||
#endif /* MASTODONT_STATUS */
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_TAG
|
||||
|
|
|
@ -1,22 +1,11 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_TIMELINE_H
|
||||
#define MASTODONT_TIMELINE_H
|
||||
#include <mastodont_types.h>
|
||||
#include <mastodont_status.h>
|
||||
#include "mastodont_types.h"
|
||||
#include "mastodont_status.h"
|
||||
|
||||
enum mstdnt_reply_visibility
|
||||
{
|
||||
|
@ -40,41 +29,41 @@ struct mstdnt_timeline_args
|
|||
int with_muted;
|
||||
};
|
||||
|
||||
int mstdnt_timeline_home(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_timeline_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses[],
|
||||
size_t* size);
|
||||
int
|
||||
mstdnt_timeline_home(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_timeline_args args);
|
||||
|
||||
int mstdnt_timeline_list(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* list_id,
|
||||
struct mstdnt_timeline_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses[],
|
||||
size_t* size);
|
||||
int
|
||||
mstdnt_timeline_list(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* list_id,
|
||||
struct mstdnt_timeline_args args);
|
||||
|
||||
int mstdnt_timeline_public(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_timeline_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses[],
|
||||
size_t* statuses_size);
|
||||
int
|
||||
mstdnt_timeline_public(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_timeline_args args);
|
||||
|
||||
int mstdnt_timeline_direct(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_timeline_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses[],
|
||||
size_t* statuses_size);
|
||||
int
|
||||
mstdnt_timeline_direct(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_timeline_args args);
|
||||
|
||||
int mstdnt_timeline_tag(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* hashtag,
|
||||
struct mstdnt_timeline_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses[],
|
||||
size_t* size);
|
||||
int
|
||||
mstdnt_timeline_tag(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* hashtag,
|
||||
struct mstdnt_timeline_args args);
|
||||
|
||||
#endif /* MASTODONT_TIMELINE_H */
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_TYPES_H
|
||||
|
@ -23,13 +12,23 @@
|
|||
#define MSTDNT_URLSIZE 2048
|
||||
#define MSTDNT_URISIZE 512
|
||||
typedef int8_t mstdnt_bool;
|
||||
// Don't be fooled!
|
||||
#define MSTDNT_TRUE 2
|
||||
#define MSTDNT_FALSE 1
|
||||
#define MSTDNT_BOOL_UNSET 0
|
||||
|
||||
// It's more logical to not sanitize than to sanitize data
|
||||
// Return types for mstdnt_request_cb_t, specifies
|
||||
// what we want to do with the data
|
||||
typedef enum mstdnt_enum_req
|
||||
{
|
||||
MSTDNT_REQUEST_DONE = 0,
|
||||
MSTDNT_REQUEST_DATA_NOCLEANUP = 1,
|
||||
} mstdnt_enum_req;
|
||||
|
||||
#define MSTDNT_CB_DATA(_data) (_data->data)
|
||||
#define MSTDNT_FLAG_NO_URI_SANITIZE (1<<0)
|
||||
#define MSTDNT_FLAG_SSL_UNVERIFIED (1<<1)
|
||||
#define MSTDNT_FLAG_SYNC (1<<2)
|
||||
#define MSTDNT_FLAG_ISSET(flags, flag) (((flags) & (flag)) == (flag))
|
||||
#define MSTDNT_T_FLAG_ISSET(flag_ref, flag) (((flag_ref->flags) & (flag)) == (flag))
|
||||
|
||||
|
@ -53,6 +52,21 @@ struct mstdnt_args
|
|||
uint8_t flags;
|
||||
};
|
||||
|
||||
struct mstdnt_storage;
|
||||
|
||||
typedef void (*mstdnt_data_free_cb_t)(void*);
|
||||
|
||||
typedef struct mstdnt_request_cb_data {
|
||||
struct mstdnt_storage storage;
|
||||
cJSON* root;
|
||||
struct mstdnt_fetch_data* fetch_data;
|
||||
|
||||
void* data;
|
||||
mstdnt_data_free_cb_t data_free_cb;
|
||||
} mstdnt_request_cb_data;
|
||||
|
||||
typedef int (*mstdnt_request_cb_t)(mstdnt_request_cb_data* data, void* args);
|
||||
|
||||
struct mstdnt_file
|
||||
{
|
||||
char* file;
|
||||
|
|
|
@ -1,21 +1,10 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_URI_H
|
||||
#define MASTODONT_URI_H
|
||||
#include <mastodont_types.h>
|
||||
#include "mastodont_types.h"
|
||||
#include <stddef.h>
|
||||
|
||||
struct mstdnt_uri
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#ifndef MASTODONT_VISIBILITY_TYPES_H
|
||||
|
|
11
mastodont.pc
Normal file
11
mastodont.pc
Normal file
|
@ -0,0 +1,11 @@
|
|||
prefix=/usr/local
|
||||
exec_prefix=${prefix}
|
||||
includedir=${prefix}/include
|
||||
libdir=${exec_prefix}/lib
|
||||
|
||||
Name: mastodont
|
||||
Description: The mastodont library
|
||||
Version: 0.0.1
|
||||
Requires: libcjson libcurl
|
||||
Cflags: -I${includedir}/mastodont
|
||||
Libs: -L${libdir} -lmastodont
|
40
premake4.lua
Normal file
40
premake4.lua
Normal file
|
@ -0,0 +1,40 @@
|
|||
solution "mastodont-c";
|
||||
configurations { "Debug", "Release" };
|
||||
|
||||
-- BEGIN Mastodont project
|
||||
project("mastodont");
|
||||
kind("StaticLib");
|
||||
language("C");
|
||||
files { "include/*.h", "src/*.c" };
|
||||
includedirs { "include/" };
|
||||
|
||||
configuration { "linux", "bsd", "gmake" };
|
||||
linkoptions { "`curl-config --libs`" };
|
||||
linkoptions { "`pkg-config --libs cjson`" };
|
||||
|
||||
|
||||
configuration { "Debug" };
|
||||
defines { "DEBUG" };
|
||||
flags("Symbols");
|
||||
|
||||
configuration { "Release" };
|
||||
defines { "NDEBUG" };
|
||||
flags("Optimize");
|
||||
-- END Mastodont-c
|
||||
|
||||
local prefix = os.getenv("PREFIX") or "/usr/local";
|
||||
local pkgconfig_path = os.getenv("PKG_CONFIG_PATH") or
|
||||
(os.isdir(prefix .. "/pkgconfig") and prefix .. "/pkgconfig") or
|
||||
prefix .. "/share/pkgconfig";
|
||||
|
||||
newaction {
|
||||
trigger = "install",
|
||||
description = "install the library",
|
||||
execute = function()
|
||||
os.copyfile("libmastodont.a", prefix .. "/lib");
|
||||
os.execute("install -d include/ " .. prefix .. "/include");
|
||||
os.execute("cp -r include/ " .. prefix .. "/include/mastodont");
|
||||
os.mkdir(pkgconfig_path);
|
||||
os.copyfile("mastodont.pc", pkgconfig_path .. "/mastodont.pc");
|
||||
end
|
||||
}
|
252
src/account.c
252
src/account.c
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -22,14 +11,16 @@
|
|||
#include <mastodont_json_helper.h>
|
||||
#include <mastodont_generate.h>
|
||||
|
||||
void _mstdnt_val_account_call(cJSON* v, void* _type)
|
||||
void
|
||||
_mstdnt_val_account_call(cJSON* v, void* _type)
|
||||
{
|
||||
struct mstdnt_account* type = _type;
|
||||
|
||||
mstdnt_account_json(type, v->child);
|
||||
}
|
||||
|
||||
void _mstdnt_val_malloc_account_call(cJSON* v, void* _type)
|
||||
void
|
||||
_mstdnt_val_malloc_account_call(cJSON* v, void* _type)
|
||||
{
|
||||
struct mstdnt_account** type = _type;
|
||||
|
||||
|
@ -42,104 +33,132 @@ void _mstdnt_val_malloc_account_call(cJSON* v, void* _type)
|
|||
// GENERATE mstdnt_statuses_json
|
||||
GENERATE_JSON_ARRAY_FUNC(mstdnt_accounts_json, struct mstdnt_account, mstdnt_account_json)
|
||||
|
||||
int mstdnt_account_json_callback(cJSON* json, void* _args)
|
||||
int
|
||||
mstdnt_account_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data)
|
||||
{
|
||||
(void)args;
|
||||
struct mstdnt_account* acct = malloc(sizeof(struct mstdnt_account));
|
||||
data->data = acct;
|
||||
data->data_free_cb = (mstdnt_data_free_cb_t)mstdnt_cleanup_account;
|
||||
// Not sure why it expects it to be in the child
|
||||
return mstdnt_account_json(_args, json->child);
|
||||
return mstdnt_account_json(acct, json->child);
|
||||
}
|
||||
|
||||
int mstdnt_accounts_json_callback(cJSON* json, void* _args)
|
||||
int
|
||||
mstdnt_accounts_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data)
|
||||
{
|
||||
struct _mstdnt_accounts_args* args = _args;
|
||||
return mstdnt_accounts_json(args->acct, args->size, json);
|
||||
(void)args;
|
||||
struct mstdnt_accounts* accts = malloc(sizeof(struct mstdnt_accounts));
|
||||
data->data = accts;
|
||||
data->data_free_cb = (mstdnt_data_free_cb_t)mstdnt_cleanup_accounts;
|
||||
return mstdnt_accounts_json(&(accts->accts), &(accts->len), json);
|
||||
}
|
||||
|
||||
static int mstdnt_get_accounts_query(char* url,
|
||||
mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_account_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_account* accts[],
|
||||
size_t* accts_len)
|
||||
static int
|
||||
mstdnt_get_accounts_query(char* url,
|
||||
mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_account_args args)
|
||||
{
|
||||
struct _mstdnt_accounts_args _args = {
|
||||
accts,
|
||||
accts_len,
|
||||
};
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args->offset } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
{ _MSTDNT_QUERY_INT, "with_relationships", { .i = args->with_relationships } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args.since_id } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args.offset } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args.limit } },
|
||||
{ _MSTDNT_QUERY_INT, "with_relationships", { .i = args.with_relationships } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
params, _mstdnt_arr_len(params),
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
&_args,
|
||||
mstdnt_accounts_json_callback,
|
||||
.url = url,
|
||||
.params_query = params,
|
||||
.params_query_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_accounts_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_get_followers(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_account_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_account* accts[],
|
||||
size_t* accts_len)
|
||||
int
|
||||
mstdnt_get_followers(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
struct mstdnt_account_args args)
|
||||
{
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/accounts/%s/followers", id);
|
||||
return mstdnt_get_accounts_query(url, data, m_args, args, storage, accts, accts_len);
|
||||
return mstdnt_get_accounts_query(url,
|
||||
data,
|
||||
m_args,
|
||||
cb_request,
|
||||
cb_args,
|
||||
args);
|
||||
}
|
||||
|
||||
int mstdnt_get_following(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_account_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_account* accts[],
|
||||
size_t* accts_len)
|
||||
int
|
||||
mstdnt_get_following(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
struct mstdnt_account_args args)
|
||||
{
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/accounts/%s/following", id);
|
||||
return mstdnt_get_accounts_query(url, data, m_args, args, storage, accts, accts_len);
|
||||
return mstdnt_get_accounts_query(url,
|
||||
data,
|
||||
m_args,
|
||||
cb_request,
|
||||
cb_args,
|
||||
args);
|
||||
}
|
||||
|
||||
int mstdnt_get_blocks(mastodont_t* data, struct mstdnt_args* m_args,
|
||||
struct mstdnt_account_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_account* accts[],
|
||||
size_t* accts_len)
|
||||
int
|
||||
mstdnt_get_blocks(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_account_args args)
|
||||
{
|
||||
return mstdnt_get_accounts_query("api/v1/blocks", data, m_args, args, storage, accts, accts_len);
|
||||
return mstdnt_get_accounts_query("api/v1/blocks",
|
||||
data,
|
||||
m_args,
|
||||
cb_request,
|
||||
cb_args,
|
||||
args);
|
||||
}
|
||||
|
||||
int mstdnt_get_mutes(mastodont_t* data, struct mstdnt_args* m_args,
|
||||
struct mstdnt_account_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_account* accts[],
|
||||
size_t* accts_len)
|
||||
int
|
||||
mstdnt_get_mutes(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_account_args args)
|
||||
{
|
||||
return mstdnt_get_accounts_query("api/v1/mutes", data, m_args, args, storage, accts, accts_len);
|
||||
return mstdnt_get_accounts_query("api/v1/mutes",
|
||||
data,
|
||||
m_args,
|
||||
cb_request,
|
||||
cb_args,
|
||||
args);
|
||||
}
|
||||
|
||||
int mstdnt_get_account(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
int lookup, /* TODO move into separate function for consistancy? */
|
||||
char* id,
|
||||
struct mstdnt_account* acct,
|
||||
struct mstdnt_storage* storage)
|
||||
int
|
||||
mstdnt_get_account(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
int lookup,
|
||||
char* id)
|
||||
{
|
||||
/* Url */
|
||||
char url[MSTDNT_URLSIZE];
|
||||
|
@ -148,39 +167,31 @@ int mstdnt_get_account(mastodont_t* data,
|
|||
id);
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
NULL, 0,
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
acct, /* args */
|
||||
mstdnt_account_json_callback, /* callback */
|
||||
.url = url,
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_account_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_verify_credentials(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_account* acct,
|
||||
struct mstdnt_storage* storage)
|
||||
int
|
||||
mstdnt_verify_credentials(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args)
|
||||
{
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
"api/v1/accounts/verify_credentials",
|
||||
NULL, 0,
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
acct, /* args */
|
||||
mstdnt_account_json_callback, /* callback */
|
||||
.url = "api/v1/accounts/verify_credentials",
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_account_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_account_json(struct mstdnt_account* acct, cJSON* js)
|
||||
int
|
||||
mstdnt_account_json(struct mstdnt_account* acct, cJSON* js)
|
||||
{
|
||||
cJSON* v;
|
||||
|
||||
|
@ -223,28 +234,24 @@ int mstdnt_account_json(struct mstdnt_account* acct, cJSON* js)
|
|||
}
|
||||
|
||||
|
||||
int mstdnt_account_action(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_relationship* rel,
|
||||
char* url_str)
|
||||
int
|
||||
mstdnt_account_action(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
char* url_str)
|
||||
{
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, url_str, id);
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
NULL, 0,
|
||||
NULL, 0,
|
||||
CURLOPT_POST,
|
||||
NULL,
|
||||
rel,
|
||||
mstdnt_relationship_json_callback
|
||||
.url = url,
|
||||
.request_type = CURLOPT_POST,
|
||||
.callback = mstdnt_relationship_json_callback
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
/* These are all the same */
|
||||
|
@ -278,11 +285,12 @@ void mstdnt_cleanup_account(struct mstdnt_account* acct)
|
|||
mstdnt_cleanup_emojis(acct->emojis);
|
||||
}
|
||||
|
||||
void mstdnt_cleanup_accounts(struct mstdnt_account* accts, size_t len)
|
||||
void mstdnt_cleanup_accounts(struct mstdnt_accounts* accts)
|
||||
{
|
||||
if (!accts) return;
|
||||
for (int i = 0; i < len; ++i)
|
||||
mstdnt_cleanup_account(accts + i);
|
||||
mstdnt_free(accts);
|
||||
for (size_t i = 0; i < accts->len; ++i)
|
||||
mstdnt_cleanup_account(accts->accts + i);
|
||||
|
||||
mstdnt_free(accts->accts);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
@ -21,7 +10,8 @@
|
|||
#include <mastodont_query.h>
|
||||
#include <mastodont_request.h>
|
||||
|
||||
static int mstdnt_app_json(cJSON* json, struct mstdnt_app* app)
|
||||
static int
|
||||
mstdnt_app_json(cJSON* json, struct mstdnt_app* app)
|
||||
{
|
||||
if (!json) return 1;
|
||||
/* Zero out */
|
||||
|
@ -43,12 +33,19 @@ static int mstdnt_app_json(cJSON* json, struct mstdnt_app* app)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int mstdnt_app_json_callback(cJSON* json, void* args)
|
||||
static int
|
||||
mstdnt_app_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data)
|
||||
{
|
||||
return mstdnt_app_json(json->child, args);
|
||||
(void)args;
|
||||
struct mstdnt_app* app = malloc(sizeof(struct mstdnt_app));
|
||||
data->data = app;
|
||||
return mstdnt_app_json(json->child, app);
|
||||
}
|
||||
|
||||
static int mstdnt_token_json(cJSON* json, struct mstdnt_oauth_token* app)
|
||||
static int
|
||||
mstdnt_token_json(cJSON* json, struct mstdnt_oauth_token* app)
|
||||
{
|
||||
struct _mstdnt_val_ref refs[] = {
|
||||
{ "access_token", &(app->access_token), _mstdnt_val_string_call },
|
||||
|
@ -64,12 +61,21 @@ static int mstdnt_token_json(cJSON* json, struct mstdnt_oauth_token* app)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int mstdnt_token_json_callback(cJSON* json, void* args)
|
||||
static int
|
||||
mstdnt_token_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data)
|
||||
{
|
||||
return mstdnt_token_json(json->child, args);
|
||||
(void)args;
|
||||
struct mstdnt_oauth_token* oauth_token = malloc(sizeof(struct mstdnt_oauth_token));
|
||||
data->data = oauth_token;
|
||||
data->data_free_cb = NULL;
|
||||
// TODO this is correct?
|
||||
return mstdnt_token_json(json->child, oauth_token);
|
||||
}
|
||||
|
||||
void _mstdnt_val_malloc_application_call(cJSON* v, void* _type)
|
||||
void
|
||||
_mstdnt_val_malloc_application_call(cJSON* v, void* _type)
|
||||
{
|
||||
struct mstdnt_app** type = _type;
|
||||
// We can skip an array size check by just seeing
|
||||
|
@ -87,63 +93,57 @@ void _mstdnt_val_malloc_application_call(cJSON* v, void* _type)
|
|||
mstdnt_app_json(v->child, *type);
|
||||
}
|
||||
|
||||
int mstdnt_register_app(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_application_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_app* app)
|
||||
int
|
||||
mstdnt_register_app(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_application_args args)
|
||||
{
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "client_name", { .s = args->client_name } },
|
||||
{ _MSTDNT_QUERY_STRING, "redirect_uris", { .s = args->redirect_uris } },
|
||||
{ _MSTDNT_QUERY_STRING, "scopes", { .s = args->scopes } },
|
||||
{ _MSTDNT_QUERY_STRING, "website", { .s = args->website } },
|
||||
{ _MSTDNT_QUERY_STRING, "client_name", { .s = args.client_name } },
|
||||
{ _MSTDNT_QUERY_STRING, "redirect_uris", { .s = args.redirect_uris } },
|
||||
{ _MSTDNT_QUERY_STRING, "scopes", { .s = args.scopes } },
|
||||
{ _MSTDNT_QUERY_STRING, "website", { .s = args.website } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
"api/v1/apps",
|
||||
NULL, 0,
|
||||
params, _mstdnt_arr_len(params),
|
||||
CURLOPT_POST,
|
||||
NULL,
|
||||
app,
|
||||
mstdnt_app_json_callback
|
||||
.url = "api/v1/apps",
|
||||
.params_post = params,
|
||||
.params_post_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_POST,
|
||||
.callback = mstdnt_app_json_callback
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_obtain_oauth_token(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_application_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_oauth_token* token)
|
||||
int
|
||||
mstdnt_obtain_oauth_token(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_application_args args)
|
||||
{
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "grant_type", { .s = args->grant_type } },
|
||||
{ _MSTDNT_QUERY_STRING, "client_id", { .s = args->client_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "client_secret", { .s = args->client_secret } },
|
||||
{ _MSTDNT_QUERY_STRING, "redirect_uri", { .s = args->redirect_uri } },
|
||||
{ _MSTDNT_QUERY_STRING, "scope", { .s = args->scope } },
|
||||
{ _MSTDNT_QUERY_STRING, "code", { .s = args->code } },
|
||||
{ _MSTDNT_QUERY_STRING, "username", { .s = args->username } },
|
||||
{ _MSTDNT_QUERY_STRING, "password", { .s = args->password } },
|
||||
{ _MSTDNT_QUERY_STRING, "grant_type", { .s = args.grant_type } },
|
||||
{ _MSTDNT_QUERY_STRING, "client_id", { .s = args.client_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "client_secret", { .s = args.client_secret } },
|
||||
{ _MSTDNT_QUERY_STRING, "redirect_uri", { .s = args.redirect_uri } },
|
||||
{ _MSTDNT_QUERY_STRING, "scope", { .s = args.scope } },
|
||||
{ _MSTDNT_QUERY_STRING, "code", { .s = args.code } },
|
||||
{ _MSTDNT_QUERY_STRING, "username", { .s = args.username } },
|
||||
{ _MSTDNT_QUERY_STRING, "password", { .s = args.password } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
"oauth/token",
|
||||
NULL,
|
||||
0,
|
||||
params,
|
||||
_mstdnt_arr_len(params),
|
||||
CURLOPT_POST,
|
||||
NULL,
|
||||
token,
|
||||
mstdnt_token_json_callback
|
||||
.url = "oauth/token",
|
||||
.params_post = params,
|
||||
.params_post_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_POST,
|
||||
.callback = mstdnt_token_json_callback
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
@ -21,7 +10,8 @@
|
|||
#include <mastodont_request.h>
|
||||
#include <mastodont_query.h>
|
||||
|
||||
void _mstdnt_val_attachment_type_call(cJSON* v, void* _type)
|
||||
void
|
||||
_mstdnt_val_attachment_type_call(cJSON* v, void* _type)
|
||||
{
|
||||
enum mstdnt_attachment_type* type = _type;
|
||||
if (!cJSON_IsString(v))
|
||||
|
@ -42,7 +32,9 @@ void _mstdnt_val_attachment_type_call(cJSON* v, void* _type)
|
|||
*type = MSTDNT_ATTACHMENT_AUDIO;
|
||||
}
|
||||
|
||||
int mstdnt_attachment_json(cJSON* att_json, struct mstdnt_attachment* att)
|
||||
int
|
||||
mstdnt_attachment_json(cJSON* att_json,
|
||||
struct mstdnt_attachment* att)
|
||||
{
|
||||
if (!att) return 1;
|
||||
|
||||
|
@ -66,7 +58,8 @@ int mstdnt_attachment_json(cJSON* att_json, struct mstdnt_attachment* att)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void _mstdnt_val_attachments_call(cJSON* v, void* _type)
|
||||
void
|
||||
_mstdnt_val_attachments_call(cJSON* v, void* _type)
|
||||
{
|
||||
struct _mstdnt_generic_args* args = _type;
|
||||
struct mstdnt_attachment** attachments = args->arg;
|
||||
|
@ -94,37 +87,45 @@ void _mstdnt_val_attachments_call(cJSON* v, void* _type)
|
|||
}
|
||||
}
|
||||
|
||||
static int mstdnt_attachment_json_callback(cJSON* json, void* _args)
|
||||
static int
|
||||
mstdnt_attachment_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data)
|
||||
{
|
||||
return mstdnt_attachment_json(json, _args);
|
||||
(void)args;
|
||||
|
||||
struct mstdnt_attachment* attachment = malloc(sizeof(struct mstdnt_attachment));
|
||||
data->data = attachment;
|
||||
// Intentionally not set
|
||||
//data->data_free_cb
|
||||
return mstdnt_attachment_json(json, attachment);
|
||||
}
|
||||
|
||||
int mstdnt_upload_media(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_upload_media_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_attachment* attachment)
|
||||
int
|
||||
mstdnt_upload_media(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_upload_media_args args)
|
||||
{
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_FILE, "file", { .f = &(args->file) } },
|
||||
{ _MSTDNT_QUERY_FILE, "thumbnail", { .f = args->thumbnail } }
|
||||
{ _MSTDNT_QUERY_FILE, "file", { .f = &(args.file) } },
|
||||
{ _MSTDNT_QUERY_FILE, "thumbnail", { .f = args.thumbnail } }
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
"api/v1/media",
|
||||
NULL, 0,
|
||||
params, _mstdnt_arr_len(params),
|
||||
CURLOPT_MIMEPOST,
|
||||
NULL,
|
||||
attachment,
|
||||
mstdnt_attachment_json_callback,
|
||||
.url = "api/v1/media",
|
||||
.params_post = params,
|
||||
.params_post_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_MIMEPOST,
|
||||
.callback = mstdnt_attachment_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(api, m_args, &req_args);
|
||||
return mstdnt_request(api, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
void mstdnt_cleanup_attachments(struct mstdnt_attachment* attachment)
|
||||
void
|
||||
mstdnt_cleanup_attachments(struct mstdnt_attachment* attachment)
|
||||
{
|
||||
if (attachment) mstdnt_free(attachment);
|
||||
}
|
||||
|
|
139
src/chats.c
139
src/chats.c
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
@ -36,7 +25,8 @@ struct _mstdnt_messages_cb_args
|
|||
size_t* messages_len;
|
||||
};
|
||||
|
||||
int mstdnt_chat_json(struct mstdnt_chat* chat, cJSON* js)
|
||||
int
|
||||
mstdnt_chat_json(struct mstdnt_chat* chat, cJSON* js)
|
||||
{
|
||||
memset(chat, 0, sizeof(struct mstdnt_chat));
|
||||
|
||||
|
@ -52,7 +42,8 @@ int mstdnt_chat_json(struct mstdnt_chat* chat, cJSON* js)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int mstdnt_message_json(struct mstdnt_message* message, cJSON* js)
|
||||
int
|
||||
mstdnt_message_json(struct mstdnt_message* message, cJSON* js)
|
||||
{
|
||||
memset(message, 0, sizeof(struct mstdnt_message));
|
||||
|
||||
|
@ -77,13 +68,25 @@ int mstdnt_message_json(struct mstdnt_message* message, cJSON* js)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int mstdnt_message_json_callback(cJSON* json, void* chat)
|
||||
int
|
||||
mstdnt_message_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data)
|
||||
{
|
||||
return mstdnt_message_json(chat, json->child);
|
||||
struct mstdnt_message* msg = malloc(sizeof(struct mstdnt_message));
|
||||
data->data = msg;
|
||||
data->data_free_cb = (mstdnt_request_cb_t)mstdnt_cleanup_message;
|
||||
return mstdnt_message_json(msg, json->child);
|
||||
}
|
||||
|
||||
int mstdnt_chat_json_callback(cJSON* json, void* chat)
|
||||
int
|
||||
mstdnt_chat_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data)
|
||||
{
|
||||
struct mstdnt_chat* chat = malloc(sizeof(struct mstdnt_chat));
|
||||
data->data = chat;
|
||||
data->data_free_cb = (mstdnt_request_cb_t)mstdnt_cleanup_chats;
|
||||
return mstdnt_chat_json(chat, json->child);
|
||||
}
|
||||
|
||||
|
@ -93,111 +96,95 @@ GENERATE_JSON_ARRAY_FUNC(mstdnt_chats_json, struct mstdnt_chat, mstdnt_chat_json
|
|||
// GENERATE mstdnt_messages_json
|
||||
GENERATE_JSON_ARRAY_FUNC(mstdnt_messages_json, struct mstdnt_message, mstdnt_message_json)
|
||||
|
||||
static int mstdnt_chats_json_callback(cJSON* json, void* _args)
|
||||
static int
|
||||
mstdnt_chats_json_callback(cJSON* json, void* _args)
|
||||
{
|
||||
struct _mstdnt_chats_cb_args* args = _args;
|
||||
return mstdnt_chats_json(args->chats, args->chats_len, json);
|
||||
}
|
||||
|
||||
static int mstdnt_messages_json_callback(cJSON* json, void* _args)
|
||||
static int
|
||||
mstdnt_messages_json_callback(cJSON* json, void* _args)
|
||||
{
|
||||
struct _mstdnt_messages_cb_args* args = _args;
|
||||
return mstdnt_messages_json(args->messages, args->messages_len, json);
|
||||
}
|
||||
|
||||
int mstdnt_get_chats_v2(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_chats_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_chat* chats[],
|
||||
size_t* size)
|
||||
int
|
||||
mstdnt_get_chats_v2(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_chats_args args)
|
||||
{
|
||||
struct _mstdnt_chats_cb_args cb_args = { chats, size };
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_BOOL, "with_muted", { .b = args->with_muted } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args->offset } },
|
||||
{ _MSTDNT_QUERY_BOOL, "with_muted", { .b = args.with_muted } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args.since_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args.limit } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args.offset } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
.storage = storage,
|
||||
.url = "api/v2/pleroma/chats",
|
||||
.params_query = params,
|
||||
.params_query_len = _mstdnt_arr_len(params),
|
||||
.params_post = NULL,
|
||||
.params_post_len = 0,
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.request_type_custom = NULL,
|
||||
.args = &cb_args,
|
||||
.callback = mstdnt_chats_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_get_chat_messages(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* chat_id,
|
||||
struct mstdnt_chats_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_message* messages[],
|
||||
size_t* size)
|
||||
int
|
||||
mstdnt_get_chat_messages(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* chat_id,
|
||||
struct mstdnt_chats_args args)
|
||||
{
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/pleroma/chats/%s/messages", chat_id);
|
||||
struct _mstdnt_messages_cb_args cb_args = { messages, size };
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_BOOL, "with_muted", { .b = args->with_muted } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args->offset } },
|
||||
{ _MSTDNT_QUERY_BOOL, "with_muted", { .b = args.with_muted } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args.since_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args.limit } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args.offset } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
.storage = storage,
|
||||
.url = url,
|
||||
.params_query = params,
|
||||
.params_query_len = _mstdnt_arr_len(params),
|
||||
.params_post = NULL,
|
||||
.params_post_len = 0,
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.request_type_custom = NULL,
|
||||
.args = &cb_args,
|
||||
.callback = mstdnt_messages_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_get_chat(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* chat_id,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_chat* chat)
|
||||
int
|
||||
mstdnt_get_chat(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* chat_id)
|
||||
{
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/pleroma/chats/%s", chat_id);
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
.storage = storage,
|
||||
.url = url,
|
||||
.params_query = NULL,
|
||||
.params_query_len = 0,
|
||||
.params_post = NULL,
|
||||
.params_post_len = 0,
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.request_type_custom = NULL,
|
||||
.args = chat,
|
||||
.callback = mstdnt_chat_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
void mstdnt_cleanup_chat(struct mstdnt_chat* chat)
|
||||
|
@ -206,15 +193,15 @@ void mstdnt_cleanup_chat(struct mstdnt_chat* chat)
|
|||
}
|
||||
|
||||
|
||||
void mstdnt_cleanup_chats(struct mstdnt_chat* chats, size_t len)
|
||||
void mstdnt_cleanup_chats(struct mstdnt_chats* chats)
|
||||
{
|
||||
if (!chats) return;
|
||||
for (size_t i = 0; i < len; ++i)
|
||||
mstdnt_cleanup_chat(chats + i);
|
||||
mstdnt_free(chats);
|
||||
for (size_t i = 0; i < chats->len; ++i)
|
||||
mstdnt_cleanup_chat(chats->chats + i);
|
||||
mstdnt_free(chats->chats);
|
||||
}
|
||||
|
||||
void mstdnt_cleanup_messages(struct mstdnt_message* messages)
|
||||
void mstdnt_cleanup_message(struct mstdnt_message* messages)
|
||||
{
|
||||
if (!messages) return;
|
||||
mstdnt_cleanup_emojis(messages->emojis);
|
||||
|
|
19
src/emoji.c
19
src/emoji.c
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
@ -19,7 +8,8 @@
|
|||
#include <mastodont_json_helper.h>
|
||||
#include <mastodont_emoji.h>
|
||||
|
||||
void load_emoji_from_json(struct mstdnt_emoji* emo, cJSON* emo_json)
|
||||
void
|
||||
load_emoji_from_json(struct mstdnt_emoji* emo, cJSON* emo_json)
|
||||
{
|
||||
cJSON* it;
|
||||
|
||||
|
@ -38,7 +28,8 @@ void load_emoji_from_json(struct mstdnt_emoji* emo, cJSON* emo_json)
|
|||
_mstdnt_key_val_ref(it, refs, _mstdnt_arr_len(refs));
|
||||
}
|
||||
|
||||
void load_emoji_react_from_json(struct mstdnt_emoji_reaction* emo, cJSON* emo_json)
|
||||
void
|
||||
load_emoji_react_from_json(struct mstdnt_emoji_reaction* emo, cJSON* emo_json)
|
||||
{
|
||||
cJSON* it;
|
||||
|
||||
|
|
13
src/error.c
13
src/error.c
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <mastodont_query.h>
|
||||
|
|
288
src/fetch.c
288
src/fetch.c
|
@ -1,29 +1,22 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <sys/select.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <mastodont_hooks.h>
|
||||
#include <mastodont_fetch.h>
|
||||
#include <mastodont_json_helper.h>
|
||||
#include <mastodont_error.h>
|
||||
|
||||
/* For use with libcurl */
|
||||
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 */
|
||||
struct mstdnt_fetch_data* res = _content; /* Cast */
|
||||
char* data;
|
||||
|
||||
if ((data = mstdnt_realloc(res->response, res->size + size + 1)) == NULL)
|
||||
|
@ -40,34 +33,30 @@ size_t mstdnt_curl_write_callback(char* ptr, size_t _size, size_t nmemb, void* _
|
|||
return size;
|
||||
}
|
||||
|
||||
void mstdnt_fetch_results_cleanup(struct mstdnt_fetch_results* res)
|
||||
{
|
||||
mstdnt_free(res->response);
|
||||
}
|
||||
|
||||
#define TOKEN_STR_SIZE 512
|
||||
int mstdnt_fetch_curl(mastodont_t* mstdnt,
|
||||
CURL* curl,
|
||||
struct mstdnt_args* m_args,
|
||||
char* _url,
|
||||
struct mstdnt_fetch_results* results,
|
||||
CURLoption request_t,
|
||||
char* request_t_custom)
|
||||
int mstdnt_fetch_curl_async(mastodont_t* mstdnt,
|
||||
CURL* curl,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
int (*json_cb)(cJSON*, void*, mstdnt_request_cb_data*),
|
||||
void* json_args,
|
||||
char* _url,
|
||||
CURLoption request_t,
|
||||
char* request_t_custom)
|
||||
{
|
||||
#define is_custom request_t_custom && request_t == CURLOPT_CUSTOMREQUEST
|
||||
CURLMcode res = 3;
|
||||
int status = 0;
|
||||
CURLMsg* msg;
|
||||
int running = 1;
|
||||
struct mstdnt_fetch_data* results = NULL;
|
||||
CURLMcode res = 0;
|
||||
char token[TOKEN_STR_SIZE] = { 0 };
|
||||
struct curl_slist* list = NULL;
|
||||
|
||||
/* Setup URL */
|
||||
// Setup URL
|
||||
char url[MSTDNT_URLSIZE] = { 0 };
|
||||
strncpy(url, m_args->url, MSTDNT_URLSIZE-1);
|
||||
strncat(url, _url, MSTDNT_URLSIZE-1);
|
||||
|
||||
/* Setup token */
|
||||
// Setup token
|
||||
if (m_args->token)
|
||||
{
|
||||
snprintf(token, TOKEN_STR_SIZE, "Authorization: Bearer %s",
|
||||
|
@ -76,81 +65,196 @@ int mstdnt_fetch_curl(mastodont_t* mstdnt,
|
|||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, list);
|
||||
}
|
||||
|
||||
/* Set options */
|
||||
// Setup data to pass into results
|
||||
results = calloc(1, sizeof(struct mstdnt_fetch_data));
|
||||
if (!results)
|
||||
{
|
||||
perror("calloc");
|
||||
return -1;
|
||||
}
|
||||
results->callback = cb_request;
|
||||
results->callback_args = cb_args;
|
||||
|
||||
results->json_cb = json_cb;
|
||||
results->json_args = json_args;
|
||||
|
||||
// Set options
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, mstdnt_curl_write_callback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, results);
|
||||
/* Copy into private pointer value
|
||||
* A little stupid, but we can let CURL hold our values for us.
|
||||
* Curl won't let us get the WRITEDATA opt pointer back sadly, so this has to be done */
|
||||
curl_easy_setopt(curl, CURLOPT_PRIVATE, results);
|
||||
/* Should we verify the peer's SSL cert? */
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER,
|
||||
!MSTDNT_T_FLAG_ISSET(m_args, MSTDNT_FLAG_SSL_UNVERIFIED));
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST,
|
||||
!MSTDNT_T_FLAG_ISSET(m_args, MSTDNT_FLAG_SSL_UNVERIFIED));
|
||||
/* PUT, POST, GET, Custom */
|
||||
/* Mimes are expected to be set beforehand manually */
|
||||
// PUT, POST, GET, Custom
|
||||
// Mimes are expected to be set beforehand manually
|
||||
if (is_custom)
|
||||
curl_easy_setopt(curl, request_t, request_t_custom);
|
||||
else if (request_t != CURLOPT_MIMEPOST)
|
||||
curl_easy_setopt(curl, request_t, 1);
|
||||
|
||||
// Add curl handle to multi, then run and block
|
||||
#ifndef THREAD_UNSAFE
|
||||
static pthread_mutex_t multi_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
#endif
|
||||
|
||||
#ifndef THREAD_UNSAFE
|
||||
pthread_mutex_lock(&multi_mutex);
|
||||
#endif
|
||||
curl_multi_add_handle(mstdnt->curl, curl);
|
||||
#ifndef THREAD_UNSAFE
|
||||
pthread_mutex_unlock(&multi_mutex);
|
||||
#endif
|
||||
|
||||
int msgs_left;
|
||||
while (running)
|
||||
// Add curl handle to multi, then run
|
||||
res = curl_multi_add_handle(mstdnt->curl, curl);
|
||||
if (res != CURLM_OK)
|
||||
{
|
||||
#ifndef THREAD_UNSAFE
|
||||
pthread_mutex_lock(&multi_mutex);
|
||||
#endif
|
||||
res = curl_multi_perform(mstdnt->curl, &running);
|
||||
#ifndef THREAD_UNSAFE
|
||||
pthread_mutex_unlock(&multi_mutex);
|
||||
#endif
|
||||
|
||||
if (running)
|
||||
res = curl_multi_poll(mstdnt->curl, NULL, 0, 1000, NULL);
|
||||
|
||||
// Check if our socket is done
|
||||
#ifndef THREAD_UNSAEF
|
||||
pthread_mutex_lock(&multi_mutex);
|
||||
#endif
|
||||
while ((msg = curl_multi_info_read(mstdnt->curl, &msgs_left)))
|
||||
{
|
||||
if (msg->msg == CURLMSG_DONE && msg->easy_handle == curl)
|
||||
{
|
||||
status = msg->data.result;
|
||||
#ifndef THREAD_UNSAFE
|
||||
pthread_mutex_unlock(&multi_mutex);
|
||||
#endif
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
#ifndef THREAD_UNSAFE
|
||||
pthread_mutex_unlock(&multi_mutex);
|
||||
#endif
|
||||
|
||||
if (res) break;
|
||||
printf("error %s\n", curl_multi_strerror(res));
|
||||
return -1;
|
||||
}
|
||||
|
||||
out:
|
||||
#ifndef THREAD_UNSAFE
|
||||
pthread_mutex_lock(&multi_mutex);
|
||||
#endif
|
||||
// Looks like we're done here
|
||||
curl_multi_remove_handle(mstdnt->curl, curl);
|
||||
#ifndef THREAD_UNSAFE
|
||||
pthread_mutex_unlock(&multi_mutex);
|
||||
#endif
|
||||
|
||||
if (list) curl_slist_free_all(list);
|
||||
return status;
|
||||
// TODO add option to "queue" and not perform a request
|
||||
// Get her running...
|
||||
int running;
|
||||
res = curl_multi_perform(mstdnt->curl, &running);
|
||||
/* if (res != CURLM_OK) */
|
||||
/* { */
|
||||
/* printf("error %s\n", curl_multi_strerror(res)); */
|
||||
/* return -1; */
|
||||
/* } */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
mstdnt_get_fds(mastodont_t* mstdnt,
|
||||
fd_set* read_set,
|
||||
fd_set* write_set,
|
||||
fd_set* error_set,
|
||||
int* nfds)
|
||||
{
|
||||
assert(mstdnt && nfds);
|
||||
|
||||
return curl_multi_fdset(mstdnt->curl,
|
||||
read_set,
|
||||
write_set,
|
||||
error_set,
|
||||
nfds) != CURLM_OK;
|
||||
}
|
||||
|
||||
int mstdnt_await(mastodont_t* mstdnt,
|
||||
enum mstdnt_fetch_await opt,
|
||||
struct mstdnt_fd extra_fds[],
|
||||
size_t nfds)
|
||||
{
|
||||
CURLMsg* msg;
|
||||
int msgs_left = 1;
|
||||
int res;
|
||||
struct curl_waitfd* fds = NULL;
|
||||
|
||||
// Any other fds can go here
|
||||
if (extra_fds)
|
||||
{
|
||||
fds = calloc(nfds, sizeof(struct curl_waitfd));
|
||||
for (int i = 0; i < nfds; ++i)
|
||||
{
|
||||
fds[i].fd = extra_fds[i].fd;
|
||||
fds[i].events = extra_fds[i].events;
|
||||
fds[i].revents = extra_fds[i].revents;
|
||||
}
|
||||
}
|
||||
|
||||
int numfds;
|
||||
int running;
|
||||
// Data used with response, must keep it with request
|
||||
struct mstdnt_fetch_data* data;
|
||||
// Data that the user will work with
|
||||
|
||||
// Check if our socket is done
|
||||
// BUG: Reusing data structures if multiple transfers in place
|
||||
do
|
||||
{
|
||||
// TODO error check
|
||||
res = curl_multi_perform(mstdnt->curl, &running);
|
||||
|
||||
if (running || nfds)
|
||||
res = curl_multi_poll(mstdnt->curl, fds, nfds, 1000, &numfds);
|
||||
|
||||
if (res) break;
|
||||
}
|
||||
while (/* opt == MSTDNT_AWAIT_ALL && msgs_left */ running);
|
||||
|
||||
while ((msg = curl_multi_info_read(mstdnt->curl, &msgs_left)) != NULL)
|
||||
{
|
||||
if (msg->msg == CURLMSG_DONE)
|
||||
{
|
||||
// Get easy info
|
||||
curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &data);
|
||||
// Setup
|
||||
mstdnt_request_cb_data* results = calloc(1, sizeof(mstdnt_request_cb_data));
|
||||
|
||||
results->fetch_data = data; // So we can clean it up
|
||||
results->storage.needs_cleanup = 0;
|
||||
|
||||
// Get json
|
||||
if (_mstdnt_json_init(&(results->root),
|
||||
data,
|
||||
&(results->storage)))
|
||||
{
|
||||
res = 1;
|
||||
goto cleanup_res;
|
||||
}
|
||||
|
||||
if (!mstdnt_check_error(&results->storage))
|
||||
{
|
||||
// Pass data to json callback, so it can store it's data
|
||||
if (data->json_cb)
|
||||
res = data->json_cb(results->storage.root,
|
||||
data->json_args,
|
||||
results);
|
||||
}
|
||||
|
||||
// Call the actual callback, regardless of error
|
||||
if (data->callback)
|
||||
res = data->callback(results, data->callback_args);
|
||||
else
|
||||
res = MSTDNT_REQUEST_DONE;
|
||||
|
||||
cleanup_res:
|
||||
/* The response of the callback is important!
|
||||
* If the user returns the below response, then the request
|
||||
* must be cleaned up manually by them */
|
||||
if (res != MSTDNT_REQUEST_DATA_NOCLEANUP)
|
||||
{
|
||||
// Will cleanup fetch too
|
||||
mstdnt_request_cb_cleanup(results);
|
||||
}
|
||||
// We can clean the handle up though
|
||||
curl_multi_remove_handle(mstdnt->curl, msg->easy_handle);
|
||||
curl_easy_cleanup(msg->easy_handle);
|
||||
}
|
||||
}
|
||||
|
||||
// Put revents back for callee
|
||||
if (extra_fds)
|
||||
for (int i = 0; i < nfds; ++i)
|
||||
extra_fds[i].revents = fds[i].revents;
|
||||
|
||||
free(fds);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void mstdnt_storage_cleanup(struct mstdnt_storage* storage);// ?
|
||||
|
||||
void mstdnt_fetch_data_cleanup(struct mstdnt_fetch_data* res)
|
||||
{
|
||||
mstdnt_free(res->response);
|
||||
// Free ourself
|
||||
mstdnt_free(res);
|
||||
}
|
||||
|
||||
void
|
||||
mstdnt_request_cb_cleanup(mstdnt_request_cb_data* data)
|
||||
{
|
||||
mstdnt_storage_cleanup(&(data->storage));
|
||||
if (data->data_free_cb)
|
||||
data->data_free_cb(data->data);
|
||||
// Cleanup
|
||||
mstdnt_fetch_data_cleanup(data->fetch_data);
|
||||
// Free ourself
|
||||
mstdnt_free(data);
|
||||
}
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
|
13
src/hooks.c
13
src/hooks.c
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <mastodont_instance.h>
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE
|
||||
|
@ -24,7 +13,7 @@
|
|||
#define TIMESTAMP_LEN 16
|
||||
|
||||
int _mstdnt_json_init(cJSON** root,
|
||||
struct mstdnt_fetch_results* results,
|
||||
struct mstdnt_fetch_data* results,
|
||||
struct mstdnt_storage* storage)
|
||||
{
|
||||
*root = cJSON_ParseWithLengthOpts(results->response, results->size, NULL, 0);
|
||||
|
@ -66,17 +55,38 @@ void _mstdnt_val_string_unix_call(cJSON* v, void* _type)
|
|||
*type = v->valuestring != endptr ? conv : 0;
|
||||
}
|
||||
|
||||
static time_t
|
||||
time_to_seconds(struct tm* time)
|
||||
{
|
||||
int const mday = time->tm_mday + 1;
|
||||
int const ly = (mday % 4 == 0 && mday % 100 != 0) || mday % 400 == 0 ? 28 : 29;
|
||||
int const days_past_per_month[] = {
|
||||
31,
|
||||
31+ly,
|
||||
31+ly+31,
|
||||
31+ly+31+30,
|
||||
31+ly+31+30+31, /* >-\ */
|
||||
31+ly+31+30+31+30, /* :( */
|
||||
31+ly+31+30+31+30+31,
|
||||
31+ly+31+30+31+30+31+31,
|
||||
31+ly+31+30+31+30+31+31+30,
|
||||
31+ly+31+30+31+30+31+31+30+31,
|
||||
31+ly+31+30+31+30+31+31+30+31+30,
|
||||
31+ly+31+30+31+30+31+31+30+31+30+31, /* >->-O */
|
||||
};
|
||||
return (time->tm_year * 60 * 60 * 24 * 365) +
|
||||
(days_past_per_month[time->tm_mon] * 60 * 60 * 24) +
|
||||
(time->tm_mday * 60 * 60 * 24) +
|
||||
(time->tm_hour * 60 * 60) +
|
||||
(time->tm_min * 60) +
|
||||
time->tm_sec;
|
||||
}
|
||||
|
||||
void _mstdnt_val_datetime_unix_call(cJSON* v, void* _type)
|
||||
{
|
||||
// First, assure correct time properties like DST
|
||||
time_t loc_time = time(NULL);
|
||||
struct tm* conv_time_cpy = gmtime(&loc_time);
|
||||
struct tm conv_time;
|
||||
// Copy over for use
|
||||
memcpy(&conv_time, conv_time_cpy, sizeof(struct tm));
|
||||
|
||||
time_t* type = _type;
|
||||
|
||||
if (sscanf(v->valuestring, "%d-%d-%dT%d:%d:%d.000Z",
|
||||
&conv_time.tm_year,
|
||||
&conv_time.tm_mon,
|
||||
|
@ -85,12 +95,11 @@ void _mstdnt_val_datetime_unix_call(cJSON* v, void* _type)
|
|||
&conv_time.tm_min,
|
||||
&conv_time.tm_sec) == 6)
|
||||
{
|
||||
conv_time.tm_year -= 1900;
|
||||
conv_time.tm_mon -= 1;
|
||||
*type = mktime(&conv_time) - timezone;
|
||||
conv_time.tm_year -= 1970;
|
||||
*type = time_to_seconds(&conv_time);
|
||||
}
|
||||
else
|
||||
*type = 0; // 70's, baby!
|
||||
*type = 0; // Non-conforming server. Shouldn't really happen
|
||||
}
|
||||
|
||||
// Fuck you Gargron
|
||||
|
@ -105,7 +114,7 @@ void _mstdnt_val_string_uint_call(cJSON* v, void* _type)
|
|||
return;
|
||||
}
|
||||
|
||||
// Convert string to long
|
||||
// Convert his string garbage to long
|
||||
conv = strtol(v->valuestring, &endptr, 10);
|
||||
*type = v->valuestring != endptr ? conv : 0;
|
||||
}
|
||||
|
|
289
src/list.c
289
src/list.c
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
@ -27,7 +16,8 @@ struct mstdnt_get_lists_args {
|
|||
size_t* size;
|
||||
};
|
||||
|
||||
static void _mstdnt_val_replies_policy_call(cJSON* v, void* _type)
|
||||
static void
|
||||
_mstdnt_val_replies_policy_call(cJSON* v, void* _type)
|
||||
{
|
||||
enum mstdnt_list_replies_policy* type = _type;
|
||||
|
||||
|
@ -39,7 +29,8 @@ static void _mstdnt_val_replies_policy_call(cJSON* v, void* _type)
|
|||
*type = MSTDNT_LIST_REPLIES_POLICY_FOLLOWED;
|
||||
}
|
||||
|
||||
int mstdnt_list_json(struct mstdnt_list* list, cJSON* js)
|
||||
int
|
||||
mstdnt_list_json(mstdnt_list* list, cJSON* js)
|
||||
{
|
||||
if (!list) return 1;
|
||||
cJSON* v;
|
||||
|
@ -62,66 +53,65 @@ int mstdnt_list_json(struct mstdnt_list* list, cJSON* js)
|
|||
|
||||
GENERATE_JSON_ARRAY_FUNC(mstdnt_lists_json, struct mstdnt_list, mstdnt_list_json);
|
||||
|
||||
static int mstdnt_list_json_callback(cJSON* json, void* _args)
|
||||
static int
|
||||
mstdnt_list_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data)
|
||||
{
|
||||
return mstdnt_list_json(_args, json);
|
||||
(void)args;
|
||||
mstdnt_list* list = mstdnt_malloc(sizeof(mstdnt_list));
|
||||
data->data = list;
|
||||
return mstdnt_list_json(list, json);
|
||||
}
|
||||
|
||||
static int mstdnt_lists_json_callback(cJSON* json, void* _args)
|
||||
static int
|
||||
mstdnt_lists_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data)
|
||||
{
|
||||
struct mstdnt_get_lists_args* args = _args;
|
||||
return mstdnt_lists_json(args->lists, args->size, json);
|
||||
(void)args;
|
||||
mstdnt_lists* lists = mstdnt_malloc(sizeof(mstdnt_lists));
|
||||
data->data = lists;
|
||||
data->data_free_cb = (mstdnt_data_free_cb_t)mstdnt_cleanup_lists;
|
||||
return mstdnt_lists_json(&(lists->lists), &(lists->len), json);
|
||||
}
|
||||
|
||||
int mstdnt_get_lists(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_list* lists[],
|
||||
size_t* size)
|
||||
int
|
||||
mstdnt_get_lists(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args)
|
||||
{
|
||||
struct mstdnt_get_lists_args args = {
|
||||
lists,
|
||||
size
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
"api/v1/lists",
|
||||
NULL, 0,
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
&args,
|
||||
mstdnt_lists_json_callback
|
||||
.url = "api/v1/lists",
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_lists_json_callback
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_get_list(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_list* list)
|
||||
int
|
||||
mstdnt_get_list(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id)
|
||||
{
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/lists/%s", id);
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
NULL, 0,
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
list,
|
||||
mstdnt_list_json_callback
|
||||
.url = url,
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_list_json_callback
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
static const char* replies_policy_str(enum mstdnt_list_replies_policy pol)
|
||||
static const char*
|
||||
replies_policy_str(enum mstdnt_list_replies_policy pol)
|
||||
{
|
||||
switch (pol)
|
||||
{
|
||||
|
@ -135,87 +125,84 @@ static const char* replies_policy_str(enum mstdnt_list_replies_policy pol)
|
|||
}
|
||||
}
|
||||
|
||||
int mstdnt_create_list(mastodont_t* data, struct mstdnt_args* m_args,
|
||||
struct mstdnt_list_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_list* list)
|
||||
int
|
||||
mstdnt_create_list(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_list_args args)
|
||||
{
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "title", { .s = args->title } },
|
||||
{ _MSTDNT_QUERY_STRING, "replies_policy", { .s = (char*)replies_policy_str(args->replies_policy) } },
|
||||
{ _MSTDNT_QUERY_STRING, "title", { .s = args.title } },
|
||||
{ _MSTDNT_QUERY_STRING, "replies_policy", { .s = replies_policy_str(args.replies_policy) } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
"api/v1/lists",
|
||||
NULL, 0,
|
||||
params, _mstdnt_arr_len(params),
|
||||
CURLOPT_POST,
|
||||
NULL,
|
||||
list,
|
||||
mstdnt_list_json_callback
|
||||
.url = "api/v1/lists",
|
||||
.params_post = params,
|
||||
.params_post_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_POST,
|
||||
.callback = mstdnt_list_json_callback
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args,&req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_update_list(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_list_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_list* list)
|
||||
int
|
||||
mstdnt_update_list(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
struct mstdnt_list_args args)
|
||||
{
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/lists/%s", id);
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "title", { .s = args->title } },
|
||||
{ _MSTDNT_QUERY_STRING, "replies_policy", { .s = (char*)replies_policy_str(args->replies_policy) } },
|
||||
{ _MSTDNT_QUERY_STRING, "title", { .s = args.title } },
|
||||
{ _MSTDNT_QUERY_STRING, "replies_policy", { .s = (char*)replies_policy_str(args.replies_policy) } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
NULL, 0,
|
||||
params, _mstdnt_arr_len(params),
|
||||
CURLOPT_CUSTOMREQUEST,
|
||||
"PUT",
|
||||
list,
|
||||
mstdnt_list_json_callback
|
||||
.url = url,
|
||||
.params_post = params,
|
||||
.params_post_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_CUSTOMREQUEST,
|
||||
.request_type_custom = "PUT",
|
||||
.callback = mstdnt_list_json_callback
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_delete_list(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_storage* storage)
|
||||
int
|
||||
mstdnt_delete_list(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id)
|
||||
{
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/lists/%s", id);
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
NULL, 0,
|
||||
NULL, 0,
|
||||
CURLOPT_CUSTOMREQUEST,
|
||||
"DELETE",
|
||||
NULL,
|
||||
NULL,
|
||||
.url = url,
|
||||
.request_type = CURLOPT_CUSTOMREQUEST,
|
||||
.request_type_custom = "DELETE",
|
||||
};
|
||||
|
||||
return mstdnt_request(api, m_args, &req_args);
|
||||
return mstdnt_request(api, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_list_add_accounts(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
char** account_ids,
|
||||
size_t account_ids_len,
|
||||
struct mstdnt_storage* storage)
|
||||
int
|
||||
mstdnt_list_add_accounts(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
char** account_ids,
|
||||
size_t account_ids_len)
|
||||
{
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/lists/%s/accounts", id);
|
||||
|
@ -230,25 +217,23 @@ int mstdnt_list_add_accounts(mastodont_t* api,
|
|||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
NULL, 0,
|
||||
params, _mstdnt_arr_len(params),
|
||||
CURLOPT_POST,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
.url = url,
|
||||
.params_post = params,
|
||||
.params_post_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_POST,
|
||||
};
|
||||
|
||||
return mstdnt_request(api, m_args, &req_args);
|
||||
return mstdnt_request(api, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_list_remove_accounts(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
char** account_ids,
|
||||
size_t account_ids_len,
|
||||
struct mstdnt_storage* storage)
|
||||
int
|
||||
mstdnt_list_remove_accounts(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
char** account_ids,
|
||||
size_t account_ids_len)
|
||||
{
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/lists/%s/accounts", id);
|
||||
|
@ -263,58 +248,48 @@ int mstdnt_list_remove_accounts(mastodont_t* api,
|
|||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
NULL, 0,
|
||||
params, _mstdnt_arr_len(params),
|
||||
CURLOPT_CUSTOMREQUEST,
|
||||
"DELETE",
|
||||
NULL,
|
||||
NULL,
|
||||
.url = url,
|
||||
.params_post = params,
|
||||
.params_post_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_CUSTOMREQUEST,
|
||||
.request_type_custom = "DELETE",
|
||||
};
|
||||
|
||||
return mstdnt_request(api, m_args, &req_args);
|
||||
return mstdnt_request(api, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_list_get_accounts(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_account_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_account* accts[],
|
||||
size_t* accts_len)
|
||||
int
|
||||
mstdnt_list_get_accounts(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
struct mstdnt_account_args args)
|
||||
{
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/lists/%s/accounts", id);
|
||||
struct _mstdnt_accounts_args _args = {
|
||||
accts,
|
||||
accts_len,
|
||||
};
|
||||
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args->offset } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
{ _MSTDNT_QUERY_INT, "with_relationships", { .i = args->with_relationships } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args.since_id } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args.offset } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args.limit } },
|
||||
{ _MSTDNT_QUERY_INT, "with_relationships", { .i = args.with_relationships } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
params, _mstdnt_arr_len(params),
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
&_args,
|
||||
mstdnt_accounts_json_callback,
|
||||
.url = url,
|
||||
.params_query = params,
|
||||
.params_query_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_accounts_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
void mstdnt_cleanup_lists(struct mstdnt_list* lists)
|
||||
void mstdnt_cleanup_lists(struct mstdnt_lists* lists)
|
||||
{
|
||||
mstdnt_free(lists);
|
||||
mstdnt_free(lists->lists);
|
||||
}
|
||||
|
|
|
@ -3,31 +3,36 @@
|
|||
#include <mastodont.h>
|
||||
#include <curl/curl.h>
|
||||
|
||||
void mstdnt_global_curl_init()
|
||||
void
|
||||
mstdnt_global_curl_init(void)
|
||||
{
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
}
|
||||
|
||||
void mstdnt_global_curl_cleanup()
|
||||
void
|
||||
mstdnt_global_curl_cleanup(void)
|
||||
{
|
||||
curl_global_cleanup();
|
||||
}
|
||||
|
||||
// Curl multi can still be used with single context's
|
||||
int mstdnt_init(mastodont_t* data)
|
||||
int
|
||||
mstdnt_init(mastodont_t* data)
|
||||
{
|
||||
data->curl = curl_multi_init();
|
||||
return data->curl == NULL;
|
||||
}
|
||||
|
||||
void mstdnt_cleanup(mastodont_t* data)
|
||||
void
|
||||
mstdnt_cleanup(mastodont_t* data)
|
||||
{
|
||||
curl_multi_cleanup(data->curl);
|
||||
}
|
||||
|
||||
void mstdnt_storage_cleanup(struct mstdnt_storage* storage)
|
||||
void
|
||||
mstdnt_storage_cleanup(struct mstdnt_storage* storage)
|
||||
{
|
||||
if (storage->needs_cleanup)
|
||||
if (storage && storage->needs_cleanup)
|
||||
{
|
||||
cJSON_Delete(storage->root);
|
||||
storage->needs_cleanup = 0;
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -97,6 +86,8 @@ int mstdnt_nodeinfo_json_callback(cJSON* json, void* nodeinfo)
|
|||
|
||||
int mstdnt_get_nodeinfo(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* version,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_nodeinfo* nodeinfo)
|
||||
|
@ -115,7 +106,7 @@ int mstdnt_get_nodeinfo(mastodont_t* api,
|
|||
mstdnt_nodeinfo_json_callback
|
||||
};
|
||||
|
||||
return mstdnt_request(api, m_args, &req_args);
|
||||
return mstdnt_request(api, m_args, &req_args, cb_request, cb_args);
|
||||
}
|
||||
|
||||
void mstdnt_cleanup_nodeinfo(struct mstdnt_nodeinfo* nodeinfo)
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -23,7 +12,8 @@
|
|||
#include <mastodont_request.h>
|
||||
#include <mastodont_generate.h>
|
||||
|
||||
static void _mstdnt_val_notif_type_call(cJSON* v, void* _type)
|
||||
static void
|
||||
_mstdnt_val_notif_type_call(cJSON* v, void* _type)
|
||||
{
|
||||
mstdnt_notification_t* type = _type;
|
||||
|
||||
|
@ -46,7 +36,8 @@ static void _mstdnt_val_notif_type_call(cJSON* v, void* _type)
|
|||
else if (strcmp(v->valuestring, "pleroma:report") == 0) *type = MSTDNT_NOTIFICATION_REPORT;
|
||||
}
|
||||
|
||||
static void _mstdnt_val_malloc_notification_pleroma_call(cJSON* v, void* _type)
|
||||
static void
|
||||
_mstdnt_val_malloc_notification_pleroma_call(cJSON* v, void* _type)
|
||||
{
|
||||
struct mstdnt_notification_pleroma** type = _type;
|
||||
|
||||
|
@ -56,7 +47,8 @@ static void _mstdnt_val_malloc_notification_pleroma_call(cJSON* v, void* _type)
|
|||
mstdnt_notification_pleroma_json(*type, v->child);
|
||||
}
|
||||
|
||||
int mstdnt_notification_json(struct mstdnt_notification* notif, cJSON* js)
|
||||
int
|
||||
mstdnt_notification_json(struct mstdnt_notification* notif, cJSON* js)
|
||||
{
|
||||
cJSON* v;
|
||||
|
||||
|
@ -81,7 +73,8 @@ int mstdnt_notification_json(struct mstdnt_notification* notif, cJSON* js)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int mstdnt_notification_pleroma_json(struct mstdnt_notification_pleroma* notif, cJSON* js)
|
||||
int
|
||||
mstdnt_notification_pleroma_json(struct mstdnt_notification_pleroma* notif, cJSON* js)
|
||||
{
|
||||
cJSON* v;
|
||||
|
||||
|
@ -101,141 +94,129 @@ int mstdnt_notification_pleroma_json(struct mstdnt_notification_pleroma* notif,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int mstdnt_notification_json_callback(cJSON* json, void* notif)
|
||||
int
|
||||
mstdnt_notification_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data)
|
||||
{
|
||||
(void)args;
|
||||
struct mstdnt_notification* notif = malloc(sizeof(struct mstdnt_notification));
|
||||
data->data = notif;
|
||||
data->data_free_cb = (mstdnt_data_free_cb_t)mstdnt_cleanup_notification;
|
||||
return mstdnt_notification_json(notif, json->child);
|
||||
}
|
||||
|
||||
GENERATE_JSON_ARRAY_FUNC(mstdnt_notifications_json, struct mstdnt_notification, mstdnt_notification_json)
|
||||
|
||||
int mstdnt_notifications_json_callback(cJSON* json, void* _args)
|
||||
int
|
||||
mstdnt_notifications_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data)
|
||||
{
|
||||
struct _mstdnt_notifications_result_cb_args* args = _args;
|
||||
return mstdnt_notifications_json(args->notif, args->size, json);
|
||||
(void)args;
|
||||
struct mstdnt_notifications* notifs = malloc(sizeof(struct mstdnt_notifications));
|
||||
data->data = notifs;
|
||||
data->data_free_cb = (mstdnt_data_free_cb_t)mstdnt_cleanup_notifications;
|
||||
return mstdnt_notifications_json(&(notifs->notifs), &(notifs->len), json);
|
||||
}
|
||||
|
||||
int mstdnt_get_notifications(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_notifications_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_notification** notifs,
|
||||
size_t* size)
|
||||
int
|
||||
mstdnt_get_notifications(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_notifications_args args)
|
||||
{
|
||||
struct _mstdnt_notifications_result_cb_args cb_args = { notifs, size };
|
||||
|
||||
union param_value u_exclude_types, u_account_id, u_exclude_visibilities,
|
||||
u_include_types, u_with_muted, u_max_id, u_min_id,
|
||||
u_since_id, u_offset, u_limit;
|
||||
/* TODO Arrays of excludes, includes */
|
||||
u_account_id.s = args->account_id;
|
||||
u_with_muted.i = args->with_muted;
|
||||
u_max_id.s = args->max_id;
|
||||
u_since_id.s = args->since_id;
|
||||
u_min_id.s = args->min_id;
|
||||
u_offset.i = args->offset;
|
||||
u_limit.i = args->limit;
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "account_id", u_account_id },
|
||||
{ _MSTDNT_QUERY_INT, "with_muted", u_with_muted },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", u_max_id },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", u_since_id },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", u_min_id },
|
||||
{ _MSTDNT_QUERY_INT, "offset", u_offset },
|
||||
{ _MSTDNT_QUERY_INT, "limit", u_limit },
|
||||
{ _MSTDNT_QUERY_STRING, "account_id", { .s = args.account_id } },
|
||||
{ _MSTDNT_QUERY_INT, "with_muted", { .i = args.with_muted } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args.since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args.offset } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args.limit } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
"api/v1/notifications",
|
||||
params, _mstdnt_arr_len(params),
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
&cb_args,
|
||||
mstdnt_notifications_json_callback,
|
||||
.url = "api/v1/notifications",
|
||||
.params_query = params,
|
||||
.params_query_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_notifications_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_notification_dismiss(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_storage* storage,
|
||||
char* id)
|
||||
int
|
||||
mstdnt_notification_dismiss(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id)
|
||||
{
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/notifications/%s/dismiss", id);
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
NULL, 0,
|
||||
NULL, 0,
|
||||
CURLOPT_POST,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
.url = url,
|
||||
.request_type = CURLOPT_POST,
|
||||
// TODO?
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_notifications_clear(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_storage* storage)
|
||||
int
|
||||
mstdnt_notifications_clear(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args)
|
||||
{
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
"api/v1/notifications/clear",
|
||||
NULL, 0,
|
||||
NULL, 0,
|
||||
CURLOPT_POST,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
.url = "api/v1/notifications/clear",
|
||||
.request_type = CURLOPT_POST,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_notifications_read(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_notifications_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_notification* notification)
|
||||
int
|
||||
mstdnt_notifications_read(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_notifications_args args)
|
||||
{
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "id", { .s = args ? args->id : NULL } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args ? args->max_id : NULL } },
|
||||
{ _MSTDNT_QUERY_STRING, "id", { .s = args.id } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
"api/v1/pleroma/notifications/read",
|
||||
NULL, 0,
|
||||
params, _mstdnt_arr_len(params),
|
||||
CURLOPT_POST,
|
||||
NULL,
|
||||
notification,
|
||||
mstdnt_notification_json_callback,
|
||||
.url = "api/v1/pleroma/notifications/read",
|
||||
.params_post = params,
|
||||
.params_post_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_POST,
|
||||
.callback = mstdnt_notification_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
|
||||
void mstdnt_cleanup_notifications(struct mstdnt_notification* notifs, size_t notifs_len)
|
||||
void
|
||||
mstdnt_cleanup_notifications(struct mstdnt_notifications* notifs)
|
||||
{
|
||||
size_t i;
|
||||
if (!notifs) return;
|
||||
for (i = 0; i < notifs_len; ++i)
|
||||
mstdnt_cleanup_notification(notifs + i);
|
||||
for (i = 0; i < notifs->len; ++i)
|
||||
mstdnt_cleanup_notification(notifs->notifs + i);
|
||||
|
||||
mstdnt_free(notifs);
|
||||
mstdnt_free(notifs->notifs);
|
||||
}
|
||||
|
||||
void mstdnt_cleanup_notification(struct mstdnt_notification* notif)
|
||||
void
|
||||
mstdnt_cleanup_notification(struct mstdnt_notification* notif)
|
||||
{
|
||||
if (notif->account)
|
||||
{
|
||||
|
@ -250,7 +231,8 @@ void mstdnt_cleanup_notification(struct mstdnt_notification* notif)
|
|||
mstdnt_free(notif->pleroma);
|
||||
}
|
||||
|
||||
const char* mstdnt_notification_t_to_str(mstdnt_notification_t type)
|
||||
const char*
|
||||
mstdnt_notification_t_to_str(mstdnt_notification_t type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
|
13
src/query.c
13
src/query.c
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
|
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -34,14 +23,16 @@ struct _mstdnt_relationship_flags_args
|
|||
mstdnt_relationship_flag_t flag;
|
||||
};
|
||||
|
||||
static void _mstdnt_val_relationship_flag_call(cJSON* v, void* _type)
|
||||
static void
|
||||
_mstdnt_val_relationship_flag_call(cJSON* v, void* _type)
|
||||
{
|
||||
struct _mstdnt_relationship_flags_args* arg = _type;
|
||||
if (cJSON_IsTrue(v))
|
||||
*(arg->flags) |= arg->flag;
|
||||
}
|
||||
|
||||
int mstdnt_relationship_json(struct mstdnt_relationship* relationship, cJSON* js)
|
||||
int
|
||||
mstdnt_relationship_json(struct mstdnt_relationship* relationship, cJSON* js)
|
||||
{
|
||||
cJSON* v;
|
||||
|
||||
|
@ -86,25 +77,37 @@ int mstdnt_relationship_json(struct mstdnt_relationship* relationship, cJSON* js
|
|||
// GENERATE mstdnt_statuses_json
|
||||
GENERATE_JSON_ARRAY_FUNC(mstdnt_relationships_json, struct mstdnt_relationship, mstdnt_relationship_json)
|
||||
|
||||
int mstdnt_relationship_json_callback(cJSON* json, void* _args)
|
||||
int
|
||||
mstdnt_relationship_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data)
|
||||
{
|
||||
return mstdnt_relationship_json((struct mstdnt_relationship*)_args, json);
|
||||
(void)args;
|
||||
mstdnt_relationship* rel = malloc(sizeof(mstdnt_relationship));
|
||||
data->data = rel;
|
||||
return mstdnt_relationship_json(rel, json);
|
||||
}
|
||||
|
||||
int mstdnt_relationships_json_callback(cJSON* json, void* _args)
|
||||
int
|
||||
mstdnt_relationships_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data)
|
||||
{
|
||||
struct _mstdnt_relationships_cb_args* args = _args;
|
||||
return mstdnt_relationships_json(args->relationships, args->size, json);
|
||||
(void)args;
|
||||
mstdnt_relationships* rels = malloc(sizeof(mstdnt_relationship));
|
||||
data->data = rels;
|
||||
data->data_free_cb = (mstdnt_data_free_cb_t)mstdnt_cleanup_relationships;
|
||||
return mstdnt_relationships_json(&(rels->relationships), &(rels->len), json);
|
||||
}
|
||||
|
||||
int mstdnt_get_relationships(mastodont_t* data, struct mstdnt_args* m_args,
|
||||
char** ids,
|
||||
size_t ids_len,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_relationship* relationships[],
|
||||
size_t* size)
|
||||
int
|
||||
mstdnt_get_relationships(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char** ids,
|
||||
size_t ids_len)
|
||||
{
|
||||
struct _mstdnt_relationships_cb_args cb_args = { relationships, size };
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_ARRAY, "id",
|
||||
{
|
||||
|
@ -115,21 +118,19 @@ int mstdnt_get_relationships(mastodont_t* data, struct mstdnt_args* m_args,
|
|||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
"api/v1/accounts/relationships",
|
||||
params, _mstdnt_arr_len(params),
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
&cb_args,
|
||||
mstdnt_relationships_json_callback
|
||||
.url = "api/v1/accounts/relationships",
|
||||
.params_query = params,
|
||||
.params_query_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_relationships_json_callback
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args,&req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
void mstdnt_cleanup_relationships(struct mstdnt_relationship* rels)
|
||||
void
|
||||
mstdnt_cleanup_relationships(struct mstdnt_relationships* rels)
|
||||
{
|
||||
if (!rels) return;
|
||||
mstdnt_free(rels);
|
||||
mstdnt_free(rels->relationships);
|
||||
}
|
||||
|
|
113
src/request.c
113
src/request.c
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -71,17 +60,49 @@ static void mime_params_post(curl_mime* mime,
|
|||
|
||||
}
|
||||
|
||||
// TODO
|
||||
#if 0
|
||||
static int mstdnt_sync_request(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_request_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
CURL* curl,
|
||||
char* url_query)
|
||||
{
|
||||
|
||||
int res = 0, curlerror = 0;
|
||||
cJSON* root;
|
||||
struct mstdnt_fetch_data results = { 0 };
|
||||
curlerror = mstdnt_fetch_curl_async(data,
|
||||
curl,
|
||||
m_args,
|
||||
url_query,
|
||||
&results,
|
||||
args->request_type,
|
||||
args->request_type_custom);
|
||||
|
||||
if (curlerror != CURLE_OK)
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
int mstdnt_request(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_request_args* args)
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_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
|
||||
char* url_query = args->params_query ?
|
||||
_mstdnt_query_string(data, m_args, args->url, args->params_query, args->params_query_len) :
|
||||
args->url;
|
||||
|
@ -89,10 +110,6 @@ int mstdnt_request(mastodont_t* data,
|
|||
// Create cURL single handle, we will run this later and then block
|
||||
CURL* curl = curl_easy_init();
|
||||
|
||||
/* Zero out */
|
||||
memset(storage, 0, sizeof(struct mstdnt_storage));
|
||||
storage->needs_cleanup = 0;
|
||||
|
||||
if (args->params_post &&
|
||||
(args->request_type == CURLOPT_POST ||
|
||||
args->request_type == CURLOPT_CUSTOMREQUEST))
|
||||
|
@ -114,47 +131,27 @@ int mstdnt_request(mastodont_t* data,
|
|||
else if (args->request_type == CURLOPT_POST)
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "");
|
||||
|
||||
curlerror = mstdnt_fetch_curl(data,
|
||||
curl,
|
||||
m_args,
|
||||
url_query,
|
||||
&results,
|
||||
args->request_type,
|
||||
args->request_type_custom);
|
||||
curlerror = mstdnt_fetch_curl_async(
|
||||
data,
|
||||
curl,
|
||||
m_args,
|
||||
cb_request,
|
||||
cb_args,
|
||||
args->callback,
|
||||
args->args,
|
||||
url_query,
|
||||
args->request_type,
|
||||
args->request_type_custom);
|
||||
|
||||
if (mime) curl_mime_free(mime);
|
||||
// Mime already used, free it early
|
||||
//if (mime) curl_mime_free(mime);
|
||||
|
||||
if (curlerror != CURLE_OK)
|
||||
{
|
||||
res = 1;
|
||||
storage->error = (char*)curl_easy_strerror(curlerror);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// Create json structure
|
||||
if (_mstdnt_json_init(&root, &results, storage))
|
||||
{
|
||||
res = 1;
|
||||
goto cleanup_res;
|
||||
}
|
||||
|
||||
// Make sure there is no error
|
||||
if (!mstdnt_check_error(storage))
|
||||
{
|
||||
/* Call our callback and do the large work */
|
||||
if (args->callback) res = args->callback(storage->root, args->args);
|
||||
}
|
||||
else
|
||||
res = 1;
|
||||
|
||||
cleanup_res:
|
||||
mstdnt_fetch_results_cleanup(&results);
|
||||
cleanup:
|
||||
// Note: the fetch removed the handle from our multi handle
|
||||
curl_easy_cleanup(curl);
|
||||
/* if (args->params_post && args->request_type == CURLOPT_POST) */
|
||||
/* mstdnt_free(post); */
|
||||
|
||||
if (args->params_post && args->request_type == CURLOPT_POST) mstdnt_free(post);
|
||||
/* Only free if params_query set */
|
||||
if (args->params_query) mstdnt_free(url_query);
|
||||
return res;
|
||||
/* /\* Only free if params_query set *\/ */
|
||||
/* if (args->params_query) mstdnt_free(url_query); */
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -1,27 +1,18 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <mastodont_hooks.h>
|
||||
#include <mastodont_scrobbles.h>
|
||||
#include <mastodont_json_helper.h>
|
||||
#include <mastodont_query.h>
|
||||
#include <mastodont_request.h>
|
||||
#include <mastodont_generate.h>
|
||||
|
||||
int mstdnt_scrobble_json(struct mstdnt_scrobble* scrobble, cJSON* js)
|
||||
int
|
||||
mstdnt_scrobble_json(struct mstdnt_scrobble* scrobble, cJSON* js)
|
||||
{
|
||||
cJSON* v;
|
||||
|
||||
|
@ -36,6 +27,7 @@ int mstdnt_scrobble_json(struct mstdnt_scrobble* scrobble, cJSON* js)
|
|||
{ "id", &(scrobble->id), _mstdnt_val_string_call },
|
||||
{ "length", &(scrobble->length), _mstdnt_val_uint_call },
|
||||
{ "title", &(scrobble->title), _mstdnt_val_string_call }
|
||||
|
||||
};
|
||||
|
||||
for (v = js; v; v = v->next)
|
||||
|
@ -46,43 +38,60 @@ int mstdnt_scrobble_json(struct mstdnt_scrobble* scrobble, cJSON* js)
|
|||
|
||||
GENERATE_JSON_ARRAY_FUNC(mstdnt_scrobbles_json, struct mstdnt_scrobble, mstdnt_scrobble_json)
|
||||
|
||||
int mstdnt_scrobbles_json_callback(cJSON* json, void* _args)
|
||||
int
|
||||
mstdnt_scrobbles_json_callback(cJSON* json,
|
||||
void* _args,
|
||||
mstdnt_request_cb_data* data)
|
||||
{
|
||||
struct _mstdnt_scrobbles_cb_args* args = _args;
|
||||
return mstdnt_scrobbles_json(args->scrobbles, args->size, json);
|
||||
mstdnt_scrobbles* scrobbles = mstdnt_malloc(sizeof(mstdnt_scrobbles));
|
||||
data->data = scrobbles;
|
||||
data->data_free_cb = (mstdnt_data_free_cb_t)mstdnt_cleanup_scrobbles;
|
||||
return mstdnt_scrobbles_json(&(scrobbles->scrobbles), &(scrobbles->len), json);
|
||||
}
|
||||
|
||||
int mstdnt_get_scrobbles(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_get_scrobbles_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_scrobble* scrobbles[],
|
||||
size_t* size)
|
||||
int
|
||||
mstdnt_get_scrobbles(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
struct mstdnt_get_scrobbles_args args)
|
||||
{
|
||||
struct _mstdnt_scrobbles_cb_args cb_args = { scrobbles, size };
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/pleroma/accounts/%s/scrobbles", id);
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args->offset } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args.since_id } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args.offset } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args.limit } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
params, _mstdnt_arr_len(params),
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
&cb_args,
|
||||
mstdnt_scrobbles_json_callback
|
||||
.url = url,
|
||||
.params_query = params,
|
||||
.params_query_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_scrobbles_json_callback
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
void
|
||||
mstdnt_cleanup_scrobble(mstdnt_scrobble* scrobble)
|
||||
{
|
||||
mstdnt_cleanup_account(&(scrobble->account));
|
||||
}
|
||||
|
||||
void
|
||||
mstdnt_cleanup_scrobbles(mstdnt_scrobbles* scrobbles)
|
||||
{
|
||||
if (!scrobbles) return;
|
||||
for (size_t i = 0; i < scrobbles->len; ++i)
|
||||
{
|
||||
mstdnt_cleanup_scrobble(scrobbles->scrobbles + i);
|
||||
}
|
||||
mstdnt_free(scrobbles->scrobbles);
|
||||
}
|
||||
|
|
105
src/search.c
105
src/search.c
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -22,7 +11,8 @@
|
|||
#include <mastodont_account.h>
|
||||
#include <mastodont_tag.h>
|
||||
|
||||
static const char* type_to_string(enum mstdnt_search_type type)
|
||||
static const char*
|
||||
type_to_string(enum mstdnt_search_type type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
|
@ -33,7 +23,9 @@ static const char* type_to_string(enum mstdnt_search_type type)
|
|||
}
|
||||
}
|
||||
|
||||
int mstdnt_search_json(struct mstdnt_search_results* search_results, cJSON* root)
|
||||
int
|
||||
mstdnt_search_json(struct mstdnt_search_results* search_results,
|
||||
cJSON* root)
|
||||
{
|
||||
// Not many items here, just use cJSON_GetObjectItemCaseSensitive() instead
|
||||
cJSON* statuses = cJSON_GetObjectItemCaseSensitive(root, "statuses");
|
||||
|
@ -41,65 +33,72 @@ int mstdnt_search_json(struct mstdnt_search_results* search_results, cJSON* root
|
|||
cJSON* hashtags = cJSON_GetObjectItemCaseSensitive(root, "hashtags");
|
||||
|
||||
// Statuses
|
||||
mstdnt_statuses_json(&(search_results->statuses),
|
||||
&(search_results->statuses_len),
|
||||
mstdnt_statuses_json(&(search_results->statuses->statuses),
|
||||
&(search_results->statuses->len),
|
||||
statuses);
|
||||
|
||||
mstdnt_accounts_json(&(search_results->accts),
|
||||
&(search_results->accts_len),
|
||||
mstdnt_accounts_json(&(search_results->accts->accts),
|
||||
&(search_results->accts->len),
|
||||
accounts);
|
||||
|
||||
mstdnt_tags_json(&(search_results->tags),
|
||||
&(search_results->tags_len),
|
||||
hashtags);
|
||||
// TODO finish tags
|
||||
/* mstdnt_tags_json(&(search_results->tags->tags), */
|
||||
/* &(search_results->tags->len), */
|
||||
/* hashtags); */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mstdnt_search_json_callback(cJSON* json, void* _args)
|
||||
int
|
||||
mstdnt_search_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data)
|
||||
{
|
||||
return mstdnt_search_json(_args, json);
|
||||
struct mstdnt_search_results* results = malloc(sizeof(struct mstdnt_search_results));
|
||||
data->data = results;
|
||||
data->data_free_cb = (mstdnt_data_free_cb_t)mstdnt_cleanup_search_results;
|
||||
return mstdnt_search_json(results, json);
|
||||
}
|
||||
|
||||
int mstdnt_search(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* query,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_search_args* args,
|
||||
struct mstdnt_search_results* results)
|
||||
int
|
||||
mstdnt_search(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* query,
|
||||
struct mstdnt_search_args args)
|
||||
{
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } },
|
||||
{ _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 = (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 } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args->offset } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } },
|
||||
{ _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 } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args.limit } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args.offset } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
"api/v2/search",
|
||||
params, _mstdnt_arr_len(params),
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
results,
|
||||
mstdnt_search_json_callback
|
||||
.url = "api/v2/search",
|
||||
.params_query = params,
|
||||
.params_query_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_search_json_callback
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
void mstdnt_cleanup_search_results(struct mstdnt_search_results* res)
|
||||
void
|
||||
mstdnt_cleanup_search_results(struct mstdnt_search_results* res)
|
||||
{
|
||||
if (!res) return;
|
||||
mstdnt_cleanup_accounts(res->accts, res->accts_len);
|
||||
mstdnt_cleanup_statuses(res->statuses, res->statuses_len);
|
||||
mstdnt_cleanup_tags(res->tags, res->tags_len);
|
||||
mstdnt_cleanup_accounts(res->accts);
|
||||
mstdnt_cleanup_statuses(res->statuses);
|
||||
// TODO
|
||||
//mstdnt_cleanup_tags(res->tags, res->tags_len);
|
||||
}
|
||||
|
|
49
src/static.c
49
src/static.c
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* 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 mstdnt_instance_panel(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_fetch_results* html)
|
||||
{
|
||||
CURL* curl = curl_easy_init();
|
||||
int status = mstdnt_fetch_curl(api,
|
||||
curl,
|
||||
m_args,
|
||||
"instance/panel.html",
|
||||
html,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL);
|
||||
curl_easy_cleanup(curl);
|
||||
return status;
|
||||
}
|
||||
|
||||
int mstdnt_terms_of_service(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_fetch_results* html)
|
||||
{
|
||||
CURL* curl = curl_easy_init();
|
||||
int status = mstdnt_fetch_curl(api,
|
||||
curl,
|
||||
m_args,
|
||||
"static/terms-of-service.html",
|
||||
html,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL);
|
||||
curl_easy_cleanup(curl);
|
||||
return status;
|
||||
}
|
512
src/status.c
512
src/status.c
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
@ -24,7 +13,8 @@
|
|||
#include <mastodont_request.h>
|
||||
#include <mastodont_generate.h>
|
||||
|
||||
void _mstdnt_val_status_call(cJSON* v, void* _type)
|
||||
void
|
||||
_mstdnt_val_status_call(cJSON* v, void* _type)
|
||||
{
|
||||
struct mstdnt_status* type = _type;
|
||||
|
||||
|
@ -32,7 +22,8 @@ void _mstdnt_val_status_call(cJSON* v, void* _type)
|
|||
}
|
||||
|
||||
|
||||
void _mstdnt_val_malloc_status_call(cJSON* v, void* _type)
|
||||
void
|
||||
_mstdnt_val_malloc_status_call(cJSON* v, void* _type)
|
||||
{
|
||||
struct mstdnt_status** type = _type;
|
||||
|
||||
|
@ -47,7 +38,8 @@ void _mstdnt_val_malloc_status_call(cJSON* v, void* _type)
|
|||
}
|
||||
|
||||
// Consider moving to mstdnt_visibility_types?
|
||||
static void _mstdnt_val_visibility_call(cJSON* v, void* _type)
|
||||
static void
|
||||
_mstdnt_val_visibility_call(cJSON* v, void* _type)
|
||||
{
|
||||
enum mstdnt_visibility_type* type = _type;
|
||||
|
||||
|
@ -75,7 +67,8 @@ static void _mstdnt_val_visibility_call(cJSON* v, void* _type)
|
|||
*type = MSTDNT_VISIBILITY_UNKNOWN;
|
||||
}
|
||||
|
||||
int mstdnt_status_json(struct mstdnt_status* status, cJSON* js)
|
||||
int
|
||||
mstdnt_status_json(struct mstdnt_status* status, cJSON* js)
|
||||
{
|
||||
cJSON* v;
|
||||
|
||||
|
@ -131,141 +124,157 @@ int mstdnt_status_json(struct mstdnt_status* status, cJSON* js)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int mstdnt_status_json_callback(cJSON* json, void* status)
|
||||
int
|
||||
mstdnt_status_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data)
|
||||
{
|
||||
return mstdnt_status_json((struct mstdnt_status*)status, json->child);
|
||||
// Unused
|
||||
(void)args;
|
||||
|
||||
struct mstdnt_status* status = malloc(sizeof(struct mstdnt_status));
|
||||
data->data = status;
|
||||
data->data_free_cb = (mstdnt_data_free_cb_t)mstdnt_cleanup_status;
|
||||
return mstdnt_status_json(status, json->child);
|
||||
}
|
||||
|
||||
// GENERATE mstdnt_statuses_json
|
||||
GENERATE_JSON_ARRAY_FUNC(mstdnt_statuses_json, struct mstdnt_status, mstdnt_status_json)
|
||||
|
||||
int mstdnt_statuses_json_callback(cJSON* json, void* _args)
|
||||
int
|
||||
mstdnt_statuses_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data)
|
||||
{
|
||||
struct _mstdnt_statuses_cb_args* args = _args;
|
||||
return mstdnt_statuses_json(args->statuses, args->size, json);
|
||||
struct mstdnt_statuses* statuses = malloc(sizeof(struct mstdnt_statuses));
|
||||
data->data = statuses;
|
||||
data->data_free_cb = (mstdnt_data_free_cb_t)mstdnt_cleanup_statuses;
|
||||
return mstdnt_statuses_json(&(statuses->statuses), &(statuses->len), json);
|
||||
}
|
||||
|
||||
int mstdnt_get_account_statuses(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_account_statuses_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses[],
|
||||
size_t* size)
|
||||
int
|
||||
mstdnt_get_account_statuses(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
struct mstdnt_account_statuses_args args)
|
||||
{
|
||||
char url[MSTDNT_URLSIZE];
|
||||
struct _mstdnt_statuses_cb_args cb_args = { statuses, size };
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/accounts/%s/statuses", id);
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_INT, "pinned", { .i = args->pinned } },
|
||||
{ _MSTDNT_QUERY_STRING, "tagged", { .s = args->tagged } },
|
||||
{ _MSTDNT_QUERY_INT, "only_media", { .i = args->only_media } },
|
||||
{ _MSTDNT_QUERY_INT, "with_muted", { .i = args->with_muted } },
|
||||
{ _MSTDNT_QUERY_INT, "exclude_reblogs", { .i = args->exclude_reblogs } },
|
||||
{ _MSTDNT_QUERY_INT, "exclude_replies", { .i = args->exclude_replies } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args->offset } },
|
||||
{ _MSTDNT_QUERY_INT, "pinned", { .i = args.pinned } },
|
||||
{ _MSTDNT_QUERY_STRING, "tagged", { .s = args.tagged } },
|
||||
{ _MSTDNT_QUERY_INT, "only_media", { .i = args.only_media } },
|
||||
{ _MSTDNT_QUERY_INT, "with_muted", { .i = args.with_muted } },
|
||||
{ _MSTDNT_QUERY_INT, "exclude_reblogs", { .i = args.exclude_reblogs } },
|
||||
{ _MSTDNT_QUERY_INT, "exclude_replies", { .i = args.exclude_replies } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args.since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args.limit } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args.offset } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
params, _mstdnt_arr_len(params),
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
&cb_args,
|
||||
mstdnt_statuses_json_callback
|
||||
.url = url,
|
||||
.params_query = params,
|
||||
.params_query_len = _mstdnt_arr_len(params),
|
||||
.params_post = NULL,
|
||||
.params_post_len = 0,
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.args = NULL,
|
||||
.callback = mstdnt_statuses_json_callback
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
/* TODO Populate the arguments! */
|
||||
int mstdnt_create_status(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_status_args* args,
|
||||
struct mstdnt_storage* storage)
|
||||
int
|
||||
mstdnt_create_status(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_status_args args)
|
||||
{
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "in_reply_to_id", { .s = args->in_reply_to_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "content_type", { .s = args->content_type } },
|
||||
{ _MSTDNT_QUERY_STRING, "status", { .s = args->status } },
|
||||
{ _MSTDNT_QUERY_STRING, "visibility", { .s = args->visibility } },
|
||||
{ _MSTDNT_QUERY_STRING, "in_reply_to_id", { .s = args.in_reply_to_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "content_type", { .s = args.content_type } },
|
||||
{ _MSTDNT_QUERY_STRING, "status", { .s = args.status } },
|
||||
{ _MSTDNT_QUERY_STRING, "visibility", { .s = args.visibility } },
|
||||
{ _MSTDNT_QUERY_ARRAY, "media_ids",
|
||||
{
|
||||
.a.arr = args->media_ids,
|
||||
.a.arr_len = args->media_ids_len
|
||||
.a.arr = args.media_ids,
|
||||
.a.arr_len = args.media_ids_len
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
"api/v1/statuses",
|
||||
NULL, 0,
|
||||
params, _mstdnt_arr_len(params),
|
||||
CURLOPT_POST,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, /* TODO populate the status back?
|
||||
* (not sure if the api returns it or not) */
|
||||
.url = "api/v1/statuses",
|
||||
.params_query = NULL,
|
||||
.params_query_len = 0,
|
||||
.params_post = params,
|
||||
.params_post_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_POST,
|
||||
.request_type_custom = NULL,
|
||||
.args = NULL,
|
||||
.callback = NULL, /* TODO populate the status back?
|
||||
* (not sure if the api returns it or not (it does)) */
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
static int mstdnt_status_action(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* status,
|
||||
char* url_str)
|
||||
static int
|
||||
mstdnt_status_action(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
char* url_str)
|
||||
{
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, url_str, id);
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
NULL, 0,
|
||||
NULL, 0,
|
||||
CURLOPT_POST,
|
||||
NULL,
|
||||
status,
|
||||
mstdnt_status_json_callback
|
||||
.url = url,
|
||||
.params_query = NULL,
|
||||
.params_query_len = 0,
|
||||
.params_post = NULL,
|
||||
.params_post_len = 0,
|
||||
.request_type = CURLOPT_POST,
|
||||
.args = NULL,
|
||||
.callback = mstdnt_status_json_callback
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
/* These are all the same */
|
||||
MSTDNT_STATUS_ACTION_DECL(favourite)
|
||||
MSTDNT_STATUS_ACTION_FUNC_URL("favourite")
|
||||
MSTDNT_STATUS_ACTION_FUNC_URL("favourite")
|
||||
|
||||
MSTDNT_STATUS_ACTION_DECL(unfavourite)
|
||||
MSTDNT_STATUS_ACTION_FUNC_URL("unfavourite")
|
||||
MSTDNT_STATUS_ACTION_DECL(unfavourite)
|
||||
MSTDNT_STATUS_ACTION_FUNC_URL("unfavourite")
|
||||
|
||||
MSTDNT_STATUS_ACTION_DECL(reblog)
|
||||
MSTDNT_STATUS_ACTION_FUNC_URL("reblog")
|
||||
MSTDNT_STATUS_ACTION_DECL(reblog)
|
||||
MSTDNT_STATUS_ACTION_FUNC_URL("reblog")
|
||||
|
||||
MSTDNT_STATUS_ACTION_DECL(unreblog)
|
||||
MSTDNT_STATUS_ACTION_FUNC_URL("unreblog")
|
||||
MSTDNT_STATUS_ACTION_DECL(unreblog)
|
||||
MSTDNT_STATUS_ACTION_FUNC_URL("unreblog")
|
||||
|
||||
MSTDNT_STATUS_ACTION_DECL(pin)
|
||||
MSTDNT_STATUS_ACTION_FUNC_URL("pin")
|
||||
MSTDNT_STATUS_ACTION_DECL(pin)
|
||||
MSTDNT_STATUS_ACTION_FUNC_URL("pin")
|
||||
|
||||
MSTDNT_STATUS_ACTION_DECL(unpin)
|
||||
MSTDNT_STATUS_ACTION_FUNC_URL("unpin")
|
||||
MSTDNT_STATUS_ACTION_DECL(unpin)
|
||||
MSTDNT_STATUS_ACTION_FUNC_URL("unpin")
|
||||
|
||||
MSTDNT_STATUS_ACTION_DECL(bookmark)
|
||||
MSTDNT_STATUS_ACTION_FUNC_URL("bookmark")
|
||||
MSTDNT_STATUS_ACTION_DECL(bookmark)
|
||||
MSTDNT_STATUS_ACTION_FUNC_URL("bookmark")
|
||||
|
||||
MSTDNT_STATUS_ACTION_DECL(unbookmark)
|
||||
MSTDNT_STATUS_ACTION_DECL(unbookmark)
|
||||
MSTDNT_STATUS_ACTION_FUNC_URL("unbookmark")
|
||||
|
||||
// Delete's use a delete method
|
||||
|
@ -275,66 +284,72 @@ MSTDNT_STATUS_ACTION_DECL(delete)
|
|||
snprintf(url, MSTDNT_URLSIZE, "api/v1/statuses/%s", id);
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
NULL, 0,
|
||||
NULL, 0,
|
||||
CURLOPT_CUSTOMREQUEST,
|
||||
"DELETE",
|
||||
status,
|
||||
mstdnt_status_json_callback
|
||||
.url = url,
|
||||
.params_query = NULL,
|
||||
.params_query_len = 0,
|
||||
.params_post = NULL,
|
||||
.params_post_len = 0,
|
||||
.request_type = CURLOPT_CUSTOMREQUEST,
|
||||
.request_type_custom = "DELETE",
|
||||
.args = NULL,
|
||||
.callback = mstdnt_status_json_callback
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
/* TODO Mutes can be timed */
|
||||
int mstdnt_mute_conversation(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* status)
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id)
|
||||
{
|
||||
return mstdnt_status_action(data, m_args, id, storage, status, "api/v1/statuses/%s/mute");
|
||||
return mstdnt_status_action(data,
|
||||
m_args,
|
||||
cb_request,
|
||||
cb_args,
|
||||
id,
|
||||
"api/v1/statuses/%s/mute");
|
||||
}
|
||||
|
||||
int mstdnt_unmute_conversation(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* status)
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id)
|
||||
{
|
||||
return mstdnt_status_action(data, m_args, id, storage, status, "api/v1/statuses/%s/unmute");
|
||||
return mstdnt_status_action(data,
|
||||
m_args,
|
||||
cb_request, cb_args,
|
||||
id,
|
||||
"api/v1/statuses/%s/unmute");
|
||||
}
|
||||
|
||||
int mstdnt_get_status(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* status)
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id)
|
||||
{
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/statuses/%s", id);
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
NULL, 0,
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
status,
|
||||
mstdnt_status_json_callback,
|
||||
.url = url,
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_status_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_status_context_json(struct mstdnt_status* statuses_before[],
|
||||
struct mstdnt_status* statuses_after[],
|
||||
size_t* size_before,
|
||||
size_t* size_after,
|
||||
cJSON* root)
|
||||
int
|
||||
mstdnt_status_context_json(struct mstdnt_status* statuses_before[],
|
||||
struct mstdnt_status* statuses_after[],
|
||||
size_t* size_before,
|
||||
size_t* size_after,
|
||||
cJSON* root)
|
||||
{
|
||||
cJSON* v, *status_item;
|
||||
size_t* size_ptr = NULL;
|
||||
|
@ -379,189 +394,151 @@ int mstdnt_status_context_json(struct mstdnt_status* statuses_before[],
|
|||
return 0;
|
||||
}
|
||||
|
||||
int mstdnt_status_context_json_callback(cJSON* json, void* _args)
|
||||
int
|
||||
mstdnt_status_context_json_callback(cJSON* json,
|
||||
void* args,
|
||||
mstdnt_request_cb_data* data)
|
||||
{
|
||||
struct _mstdnt_status_context_result_cb_args* args = _args;
|
||||
return mstdnt_status_context_json(args->statuses_before,
|
||||
args->statuses_after,
|
||||
args->size_before,
|
||||
args->size_after,
|
||||
struct mstdnt_status_context* ctx = malloc(sizeof(struct mstdnt_status_context));
|
||||
data->data = ctx;
|
||||
// TODO URGENT
|
||||
data->data_free_cb = NULL;
|
||||
return mstdnt_status_context_json(&(ctx->before.statuses),
|
||||
&(ctx->after.statuses),
|
||||
&(ctx->before.len),
|
||||
&(ctx->after.len),
|
||||
json);
|
||||
}
|
||||
|
||||
int mstdnt_get_status_context(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses_before[],
|
||||
struct mstdnt_status* statuses_after[],
|
||||
size_t* size_before,
|
||||
size_t* size_after)
|
||||
int
|
||||
mstdnt_get_status_context(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id)
|
||||
{
|
||||
struct _mstdnt_status_context_result_cb_args args = {
|
||||
statuses_before,
|
||||
statuses_after,
|
||||
size_before,
|
||||
size_after,
|
||||
};
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/statuses/%s/context", id);
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
NULL, 0,
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
&args,
|
||||
mstdnt_status_context_json_callback,
|
||||
.url = url,
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_status_context_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_status_favourited_by(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_account* accounts[],
|
||||
size_t* accts_len)
|
||||
int
|
||||
mstdnt_status_favourited_by(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id)
|
||||
{
|
||||
struct _mstdnt_accounts_args args = {
|
||||
accounts,
|
||||
accts_len,
|
||||
};
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/statuses/%s/favourited_by", id);
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
NULL, 0,
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
&args,
|
||||
mstdnt_accounts_json_callback,
|
||||
.url = url,
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_accounts_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_status_reblogged_by(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_account* accounts[],
|
||||
size_t* accts_len)
|
||||
int
|
||||
mstdnt_status_reblogged_by(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id)
|
||||
{
|
||||
struct _mstdnt_accounts_args args = {
|
||||
accounts,
|
||||
accts_len,
|
||||
};
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/statuses/%s/reblogged_by", id);
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
NULL, 0,
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
&args,
|
||||
mstdnt_accounts_json_callback,
|
||||
.url = url,
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_accounts_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
|
||||
int mstdnt_get_bookmarks(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_bookmarks_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses[],
|
||||
size_t* size)
|
||||
int
|
||||
mstdnt_get_bookmarks(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_bookmarks_args args)
|
||||
{
|
||||
struct _mstdnt_statuses_cb_args cb_args = { statuses, size };
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args.since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args.limit } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
"api/v1/bookmarks",
|
||||
params, _mstdnt_arr_len(params),
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
&cb_args,
|
||||
mstdnt_statuses_json_callback,
|
||||
.url = "api/v1/bookmarks",
|
||||
.params_query = params,
|
||||
.params_query_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_statuses_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_get_favourites(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_favourites_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses[],
|
||||
size_t* size)
|
||||
int
|
||||
mstdnt_get_favourites(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_favourites_args args)
|
||||
{
|
||||
struct _mstdnt_statuses_cb_args cb_args = { statuses, size };
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args.limit } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
"api/v1/favourites",
|
||||
params, _mstdnt_arr_len(params),
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
&cb_args,
|
||||
mstdnt_statuses_json_callback,
|
||||
.url = "api/v1/favourites",
|
||||
.params_query = params,
|
||||
.params_query_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_statuses_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_status_emoji_react(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
char* id,
|
||||
char* emoji,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* status)
|
||||
int
|
||||
mstdnt_status_emoji_react(mastodont_t* api,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* id,
|
||||
char* emoji)
|
||||
{
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/pleroma/statuses/%s/reactions/%s", id, emoji);
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
NULL, 0,
|
||||
NULL, 0,
|
||||
CURLOPT_PUT,
|
||||
NULL,
|
||||
status,
|
||||
mstdnt_status_json_callback
|
||||
.url = url,
|
||||
.request_type = CURLOPT_PUT,
|
||||
.callback = mstdnt_status_json_callback
|
||||
};
|
||||
|
||||
return mstdnt_request(api, m_args, &req_args);
|
||||
return mstdnt_request(api, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
void mstdnt_cleanup_status(struct mstdnt_status* status)
|
||||
void
|
||||
mstdnt_cleanup_status(struct mstdnt_status* status)
|
||||
{
|
||||
mstdnt_cleanup_attachments(status->media_attachments);
|
||||
mstdnt_cleanup_account(&(status->account));
|
||||
|
@ -575,13 +552,12 @@ void mstdnt_cleanup_status(struct mstdnt_status* status)
|
|||
mstdnt_free(status->application);
|
||||
}
|
||||
|
||||
void mstdnt_cleanup_statuses(struct mstdnt_status* statuses, size_t s)
|
||||
void
|
||||
mstdnt_cleanup_statuses(struct mstdnt_statuses* statuses)
|
||||
{
|
||||
size_t i;
|
||||
if (!statuses) return;
|
||||
for (i = 0; i < s; ++i)
|
||||
{
|
||||
mstdnt_cleanup_status(statuses + i);
|
||||
}
|
||||
mstdnt_free(statuses);
|
||||
for (size_t i = 0; i < statuses->len; ++i)
|
||||
mstdnt_cleanup_status(statuses->statuses + i);
|
||||
|
||||
mstdnt_free(statuses->statuses);
|
||||
}
|
||||
|
|
13
src/tag.c
13
src/tag.c
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
|
258
src/timeline.c
258
src/timeline.c
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
@ -20,88 +9,81 @@
|
|||
#include <mastodont_query.h>
|
||||
#include <mastodont_request.h>
|
||||
|
||||
int mstdnt_timeline_list(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* list_id,
|
||||
struct mstdnt_timeline_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses[],
|
||||
size_t* size)
|
||||
int
|
||||
mstdnt_timeline_list(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* list_id,
|
||||
struct mstdnt_timeline_args args)
|
||||
{
|
||||
struct _mstdnt_statuses_cb_args cb_args = { statuses, size };
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/timelines/list/%s", list_id);
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_BOOL, "local", { .b = args->local } },
|
||||
{ _MSTDNT_QUERY_BOOL, "remote", { .b = args->remote } },
|
||||
{ _MSTDNT_QUERY_BOOL, "only_media", { .b = args->only_media } },
|
||||
{ _MSTDNT_QUERY_BOOL, "with_muted", { .b = args->with_muted } },
|
||||
/* { _MSTDNT_QUERY_INT, "exclude_visibilities", { .i = args->only_media } }, */
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args->offset } },
|
||||
{ _MSTDNT_QUERY_BOOL, "local", { .b = args.local } },
|
||||
{ _MSTDNT_QUERY_BOOL, "remote", { .b = args.remote } },
|
||||
{ _MSTDNT_QUERY_BOOL, "only_media", { .b = args.only_media } },
|
||||
{ _MSTDNT_QUERY_BOOL, "with_muted", { .b = args.with_muted } },
|
||||
/* { _MSTDNT_QUERY_INT, "exclude_visibilities", { .i = args.only_media } }, */
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args.since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args.limit } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args.offset } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
params, _mstdnt_arr_len(params),
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
&cb_args,
|
||||
mstdnt_statuses_json_callback,
|
||||
.url = url,
|
||||
.params_query = params,
|
||||
.params_query_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_statuses_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
int mstdnt_timeline_tag(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
char* hashtag,
|
||||
struct mstdnt_timeline_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses[],
|
||||
size_t* size)
|
||||
int
|
||||
mstdnt_timeline_tag(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
char* hashtag,
|
||||
struct mstdnt_timeline_args args)
|
||||
{
|
||||
struct _mstdnt_statuses_cb_args cb_args = { statuses, size };
|
||||
char url[MSTDNT_URLSIZE];
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/timelines/tag/%s", hashtag);
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args.since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } },
|
||||
// TODO ANY
|
||||
// TODO ALL
|
||||
// TODO NONE
|
||||
// TODO exclude_visibilities
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args->offset } },
|
||||
{ _MSTDNT_QUERY_BOOL, "local", { .b = args->local } },
|
||||
{ _MSTDNT_QUERY_BOOL, "remote", { .b = args->remote } },
|
||||
{ _MSTDNT_QUERY_BOOL, "only_media", { .b = args->only_media } },
|
||||
{ _MSTDNT_QUERY_BOOL, "with_muted", { .b = args->with_muted } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args.limit } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args.offset } },
|
||||
{ _MSTDNT_QUERY_BOOL, "local", { .b = args.local } },
|
||||
{ _MSTDNT_QUERY_BOOL, "remote", { .b = args.remote } },
|
||||
{ _MSTDNT_QUERY_BOOL, "only_media", { .b = args.only_media } },
|
||||
{ _MSTDNT_QUERY_BOOL, "with_muted", { .b = args.with_muted } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
url,
|
||||
params, _mstdnt_arr_len(params),
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
&cb_args,
|
||||
mstdnt_statuses_json_callback,
|
||||
.url = url,
|
||||
.params_query = params,
|
||||
.params_query_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_statuses_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
static const char* reply_visibility_str(enum mstdnt_reply_visibility vis)
|
||||
static const char*
|
||||
reply_visibility_str(enum mstdnt_reply_visibility vis)
|
||||
{
|
||||
switch (vis)
|
||||
{
|
||||
|
@ -115,110 +97,96 @@ static const char* reply_visibility_str(enum mstdnt_reply_visibility vis)
|
|||
}
|
||||
}
|
||||
|
||||
int mstdnt_timeline_public(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_timeline_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses[],
|
||||
size_t* size)
|
||||
int
|
||||
mstdnt_timeline_public(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_timeline_args args)
|
||||
{
|
||||
struct _mstdnt_statuses_cb_args cb_args = { statuses, size };
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_BOOL, "local", { .b = args->local } },
|
||||
{ _MSTDNT_QUERY_STRING, "instance", { .s = args->instance } },
|
||||
{ _MSTDNT_QUERY_BOOL, "with_muted", { .b = args->with_muted } },
|
||||
{ _MSTDNT_QUERY_STRING, "reply_visibility", { .s = (char*)reply_visibility_str(args->reply_visibility) } },
|
||||
{ _MSTDNT_QUERY_BOOL, "remote", { .b = args->remote } },
|
||||
{ _MSTDNT_QUERY_BOOL, "only_media", { .b = args->only_media } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args->offset } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
{ _MSTDNT_QUERY_BOOL, "local", { .b = args.local } },
|
||||
{ _MSTDNT_QUERY_STRING, "instance", { .s = args.instance } },
|
||||
{ _MSTDNT_QUERY_BOOL, "with_muted", { .b = args.with_muted } },
|
||||
{ _MSTDNT_QUERY_STRING, "reply_visibility", { .s = (char*)reply_visibility_str(args.reply_visibility) } },
|
||||
{ _MSTDNT_QUERY_BOOL, "remote", { .b = args.remote } },
|
||||
{ _MSTDNT_QUERY_BOOL, "only_media", { .b = args.only_media } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args.since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args.offset } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args.limit } },
|
||||
};
|
||||
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
"api/v1/timelines/public",
|
||||
params, _mstdnt_arr_len(params),
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
&cb_args,
|
||||
mstdnt_statuses_json_callback,
|
||||
.url = "api/v1/timelines/public",
|
||||
.params_query = params,
|
||||
.params_query_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_statuses_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
|
||||
int mstdnt_timeline_direct(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_timeline_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses[],
|
||||
size_t* size)
|
||||
int
|
||||
mstdnt_timeline_direct(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_timeline_args args)
|
||||
{
|
||||
struct _mstdnt_statuses_cb_args cb_args = { statuses, size };
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args->offset } },
|
||||
{ _MSTDNT_QUERY_BOOL, "with_muted", { .b = args->with_muted } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args.since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args.limit } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args.offset } },
|
||||
{ _MSTDNT_QUERY_BOOL, "with_muted", { .b = args.with_muted } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
"api/v1/timelines/direct",
|
||||
params, _mstdnt_arr_len(params),
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
&cb_args,
|
||||
mstdnt_statuses_json_callback,
|
||||
.url = "api/v1/timelines/direct",
|
||||
.params_query = params,
|
||||
.params_query_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_statuses_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
|
||||
int mstdnt_timeline_home(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
struct mstdnt_timeline_args* args,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses[],
|
||||
size_t* size)
|
||||
int
|
||||
mstdnt_timeline_home(mastodont_t* data,
|
||||
struct mstdnt_args* m_args,
|
||||
mstdnt_request_cb_t cb_request,
|
||||
void* cb_args,
|
||||
struct mstdnt_timeline_args args)
|
||||
{
|
||||
struct _mstdnt_statuses_cb_args cb_args = { statuses, size };
|
||||
|
||||
struct _mstdnt_query_param params[] = {
|
||||
{ _MSTDNT_QUERY_BOOL, "local", { .b = args->local } },
|
||||
{ _MSTDNT_QUERY_BOOL, "remote", { .b = args->remote } },
|
||||
{ _MSTDNT_QUERY_INT, "only_media", { .i = args->only_media } },
|
||||
{ _MSTDNT_QUERY_INT, "with_muted", { .i = args->with_muted } },
|
||||
/* { _MSTDNT_QUERY_INT, "exclude_visibilities", { .i = args->with_muted } }, */
|
||||
{ _MSTDNT_QUERY_STRING, "reply_visibility", { .s = (char*)reply_visibility_str(args->reply_visibility) } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args->max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args->since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args->min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args->limit } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args->offset } },
|
||||
{ _MSTDNT_QUERY_BOOL, "local", { .b = args.local } },
|
||||
{ _MSTDNT_QUERY_BOOL, "remote", { .b = args.remote } },
|
||||
{ _MSTDNT_QUERY_INT, "only_media", { .i = args.only_media } },
|
||||
{ _MSTDNT_QUERY_INT, "with_muted", { .i = args.with_muted } },
|
||||
/* { _MSTDNT_QUERY_INT, "exclude_visibilities", { .i = args.with_muted } }, */
|
||||
{ _MSTDNT_QUERY_STRING, "reply_visibility", { .s = (char*)reply_visibility_str(args.reply_visibility) } },
|
||||
{ _MSTDNT_QUERY_STRING, "max_id", { .s = args.max_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "since_id", { .s = args.since_id } },
|
||||
{ _MSTDNT_QUERY_STRING, "min_id", { .s = args.min_id } },
|
||||
{ _MSTDNT_QUERY_INT, "limit", { .i = args.limit } },
|
||||
{ _MSTDNT_QUERY_INT, "offset", { .i = args.offset } },
|
||||
};
|
||||
|
||||
struct mstdnt_request_args req_args = {
|
||||
storage,
|
||||
"api/v1/timelines/home",
|
||||
params, _mstdnt_arr_len(params),
|
||||
NULL, 0,
|
||||
CURLOPT_HTTPGET,
|
||||
NULL,
|
||||
&cb_args,
|
||||
mstdnt_statuses_json_callback,
|
||||
.url = "api/v1/timelines/home",
|
||||
.params_query = params,
|
||||
.params_query_len = _mstdnt_arr_len(params),
|
||||
.request_type = CURLOPT_HTTPGET,
|
||||
.callback = mstdnt_statuses_json_callback,
|
||||
};
|
||||
|
||||
return mstdnt_request(data, m_args, &req_args);
|
||||
return mstdnt_request(data, m_args, cb_request, cb_args, &req_args);
|
||||
}
|
||||
|
||||
|
|
13
src/uri.c
13
src/uri.c
|
@ -1,16 +1,5 @@
|
|||
/*
|
||||
* 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/>.
|
||||
* Licensed under BSD 3-Clause License
|
||||
*/
|
||||
|
||||
#include <mastodont_uri.h>
|
||||
|
|
90
tests/get_feed.c
Normal file
90
tests/get_feed.c
Normal file
|
@ -0,0 +1,90 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <mastodont.h>
|
||||
|
||||
char* get_line(char const* prompt)
|
||||
{
|
||||
char* result = NULL;
|
||||
#define GL_BUF_SIZE 255
|
||||
char buffer[GL_BUF_SIZE];
|
||||
|
||||
if (prompt)
|
||||
{
|
||||
fputs(prompt, stdout);
|
||||
fputs(": ", stdout);
|
||||
}
|
||||
|
||||
fgets(buffer, GL_BUF_SIZE, stdin);
|
||||
int buffer_len = strlen(buffer);
|
||||
result = realloc(result, buffer_len+1);
|
||||
memcpy(result, buffer, buffer_len);
|
||||
result[buffer_len-1] = '\0';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static char const*
|
||||
itob(int i)
|
||||
{
|
||||
return i ? "true" : "false";
|
||||
}
|
||||
|
||||
int
|
||||
tl_callback(mstdnt_request_cb_data* cb_data, void* args)
|
||||
{
|
||||
struct mstdnt_statuses* statuses = MSTDNT_CB_DATA(cb_data);
|
||||
|
||||
for (int i = 0; i < statuses->len; ++i)
|
||||
{
|
||||
struct mstdnt_status* status = statuses->statuses + i;
|
||||
puts("---------------- BEGIN STATUS ----------------");
|
||||
printf(" Author: %s\n", status->account.username);
|
||||
printf(" id: %s\n", status->id);
|
||||
printf(" R/F/REPLIES: %u %u %u\n", status->reblogs_count,
|
||||
status->favourites_count,
|
||||
status->replies_count);
|
||||
printf(" Is Reply? %s\n", itob(status->in_reply_to_id != NULL));
|
||||
printf(" Contains emojos? %s\n", itob(status->emojis_len > 0));
|
||||
printf(" Has attachments? %s\n", itob(status->media_attachments_len > 0));
|
||||
|
||||
puts("----------------- END STATUS -----------------");
|
||||
}
|
||||
|
||||
return MSTDNT_REQUEST_DONE;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
mstdnt_global_curl_init();
|
||||
|
||||
mastodont_t data;
|
||||
|
||||
if (mstdnt_init(&data) != 0)
|
||||
{
|
||||
fputs("Couldn't initialize Mastodont-c!", stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char* instance = get_line("Instance");
|
||||
|
||||
struct mstdnt_args m_args = {
|
||||
.url = instance,
|
||||
.token = NULL,
|
||||
.flags = 0,
|
||||
};
|
||||
|
||||
mstdnt_timeline_public(&data, &m_args, tl_callback, NULL, (struct mstdnt_timeline_args){.limit=20});
|
||||
|
||||
mstdnt_await(&data, 0, NULL, 0);
|
||||
|
||||
// Cleanup
|
||||
free(instance);
|
||||
mstdnt_cleanup(&data);
|
||||
mstdnt_global_curl_cleanup();
|
||||
|
||||
return 1;
|
||||
}
|
198
tests/get_feed_efl.c
Normal file
198
tests/get_feed_efl.c
Normal file
|
@ -0,0 +1,198 @@
|
|||
#define _POSIX_C_SOURCE 200112L
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <mastodont.h>
|
||||
|
||||
#include <signal.h>
|
||||
#define EFL_BETA_API_SUPPORT 1
|
||||
|
||||
#include <Efl_Ui.h>
|
||||
|
||||
void update_mstdnt_fds(void);
|
||||
|
||||
Eo* textbox_instance;
|
||||
Eo* fd;
|
||||
Eo* posts;
|
||||
Eo* fake_list;
|
||||
mastodont_t mstdnt;
|
||||
|
||||
static void
|
||||
gui_quit_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
|
||||
{
|
||||
mstdnt_cleanup(&mstdnt);
|
||||
mstdnt_global_curl_cleanup();
|
||||
efl_exit(0);
|
||||
}
|
||||
|
||||
static Eo*
|
||||
gui_create_status(struct mstdnt_status* status)
|
||||
{
|
||||
Eo* root = efl_add(EFL_UI_BOX_CLASS, fake_list,
|
||||
efl_gfx_hint_margin_set(efl_added, 5, 5, 5, 0),
|
||||
efl_gfx_color_set(efl_part(efl_added, "background"), 84, 84, 84, 150)
|
||||
);
|
||||
|
||||
Eo* header = efl_add(EFL_UI_BOX_CLASS, root,
|
||||
efl_ui_layout_orientation_set(efl_added, EFL_UI_LAYOUT_ORIENTATION_HORIZONTAL),
|
||||
efl_gfx_hint_fill_set(efl_added, EINA_FALSE, EINA_FALSE),
|
||||
efl_gfx_hint_align_set(efl_added, 0.0, 0.0),
|
||||
efl_pack(root, efl_added));
|
||||
|
||||
efl_add(EFL_UI_TEXTBOX_CLASS, header,
|
||||
efl_text_set(efl_added, status->account.display_name),
|
||||
efl_gfx_hint_margin_set(efl_added, 0, 5, 0, 0),
|
||||
efl_pack(header, efl_added));
|
||||
|
||||
efl_add(EFL_UI_TEXTBOX_CLASS, header,
|
||||
efl_text_set(efl_added, status->account.acct),
|
||||
efl_text_font_weight_set(efl_added, EFL_TEXT_FONT_WEIGHT_BOLD),
|
||||
efl_pack(header, efl_added));
|
||||
|
||||
Eo* content = efl_add(EFL_UI_TEXTBOX_CLASS, root,
|
||||
efl_text_interactive_selection_allowed_set(efl_added, EINA_FALSE),
|
||||
efl_text_wrap_set(efl_added, EINA_TRUE),
|
||||
efl_gfx_hint_fill_set(efl_added, EINA_TRUE, EINA_FALSE),
|
||||
efl_text_markup_set(efl_added, status->content),
|
||||
efl_text_interactive_editable_set(efl_added, EINA_FALSE),
|
||||
efl_gfx_color_set(efl_part(efl_added, "background"), 84, 84, 84, 150),
|
||||
efl_gfx_hint_margin_set(efl_added, 0, 0, 0, 5),
|
||||
efl_pack(root, efl_added));
|
||||
efl_pack_layout_update(fake_list);
|
||||
return root;
|
||||
}
|
||||
|
||||
static void
|
||||
gui_add_status(struct mstdnt_status* status)
|
||||
{
|
||||
efl_pack_end(fake_list, gui_create_status(status));
|
||||
}
|
||||
|
||||
int
|
||||
tl_callback(mstdnt_request_cb_data* cb_data, void* args)
|
||||
{
|
||||
struct mstdnt_statuses* statuses = MSTDNT_CB_DATA(cb_data);
|
||||
|
||||
for (int i = 0; i < statuses->len; ++i)
|
||||
{
|
||||
struct mstdnt_status* status = statuses->statuses + i;
|
||||
gui_add_status(status);
|
||||
}
|
||||
|
||||
return MSTDNT_REQUEST_DONE;
|
||||
}
|
||||
|
||||
static void
|
||||
gui_fetch_posts(void* data EINA_UNUSED, const Efl_Event* event EINA_UNUSED)
|
||||
{
|
||||
printf("Got %s...\n", efl_text_get(textbox_instance));
|
||||
|
||||
struct mstdnt_args m_args = {
|
||||
.url = efl_text_get(textbox_instance),
|
||||
.token = NULL,
|
||||
.flags = 0,
|
||||
};
|
||||
|
||||
mstdnt_timeline_public(&mstdnt, &m_args, tl_callback, NULL,
|
||||
(struct mstdnt_timeline_args){.limit=20});
|
||||
|
||||
update_mstdnt_fds();
|
||||
}
|
||||
|
||||
static void
|
||||
mstdnt_results_cb(void* _data EINA_UNUSED, const Efl_Event* event EINA_UNUSED)
|
||||
{
|
||||
Eo* data = _data;
|
||||
mstdnt_await(&mstdnt, 0, NULL, 0);
|
||||
}
|
||||
|
||||
void
|
||||
update_mstdnt_fds()
|
||||
{
|
||||
int nfds;
|
||||
// Get
|
||||
fd_set read;
|
||||
fd_set write;
|
||||
fd_set error;
|
||||
FD_ZERO(&read);
|
||||
FD_ZERO(&write);
|
||||
FD_ZERO(&error);
|
||||
|
||||
mstdnt_get_fds(&mstdnt, &read, &write, &error, &nfds);
|
||||
|
||||
for (int i = 0; i <= nfds; ++i)
|
||||
{
|
||||
printf("FD_ISSET: %i\n", i);
|
||||
if (FD_ISSET(i, &read))
|
||||
{
|
||||
efl_add(EFL_LOOP_FD_CLASS,
|
||||
efl_main_loop_get(),
|
||||
efl_loop_fd_set(efl_added, i),
|
||||
efl_event_callback_add(efl_added, EFL_LOOP_FD_EVENT_READ, mstdnt_results_cb, efl_added));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gui_setup(void)
|
||||
{
|
||||
Eo *win, *box;
|
||||
|
||||
win = efl_add(EFL_UI_WIN_CLASS,
|
||||
efl_main_loop_get(),
|
||||
efl_ui_win_type_set(efl_added, EFL_UI_WIN_TYPE_BASIC),
|
||||
efl_text_set(efl_added, "mastodont-c test"),
|
||||
efl_ui_win_autodel_set(efl_added, EINA_TRUE),
|
||||
efl_event_callback_add(efl_added,
|
||||
EFL_UI_WIN_EVENT_DELETE_REQUEST,
|
||||
gui_quit_cb,
|
||||
NULL));
|
||||
|
||||
box = efl_add(EFL_UI_BOX_CLASS,
|
||||
win,
|
||||
efl_content_set(win, efl_added),
|
||||
efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(300, 440)));
|
||||
|
||||
posts = efl_add(EFL_UI_SCROLLER_CLASS,
|
||||
box,
|
||||
//efl_text_interactive_selection_allowed_set(efl_added, EINA_FALSE),
|
||||
//efl_gfx_hint_weight_set(efl_added, 1.0, 0.9),
|
||||
//efl_gfx_hint_align_set(efl_added, 0.5, 0.5),
|
||||
efl_pack(box, efl_added));
|
||||
|
||||
fake_list = efl_add(EFL_UI_BOX_CLASS,
|
||||
posts,
|
||||
efl_content_set(posts, efl_added));
|
||||
|
||||
textbox_instance = efl_add(EFL_UI_TEXTBOX_CLASS,
|
||||
box,
|
||||
efl_gfx_hint_weight_set(efl_added, 1.0, 0.1),
|
||||
efl_gfx_color_set(efl_added, 0, 255, 0, 255),
|
||||
efl_pack(box, efl_added));
|
||||
|
||||
efl_add(EFL_UI_BUTTON_CLASS,
|
||||
box,
|
||||
efl_text_set(efl_added, "Fetch posts asynchronously"),
|
||||
efl_gfx_hint_weight_set(efl_added, 1.0, 0.2),
|
||||
efl_pack(box, efl_added),
|
||||
efl_event_callback_add(efl_added, EFL_INPUT_EVENT_CLICKED,
|
||||
gui_fetch_posts, NULL));
|
||||
}
|
||||
|
||||
EAPI_MAIN void
|
||||
efl_main(void *edata EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
|
||||
{
|
||||
// Initialize Mastodont library
|
||||
mstdnt_global_curl_init();
|
||||
|
||||
if (mstdnt_init(&mstdnt) != 0)
|
||||
{
|
||||
fputs("Couldn't initialize Mastodont-c!", stderr);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
gui_setup();
|
||||
}
|
||||
EFL_MAIN()
|
||||
|
Loading…
Reference in a new issue