URI Functions, account lookup
FossilOrigin-Name: 11852ad563b470e8ffa2c89b05982a5078c88e0957712e8738e6b4e2360537d0
This commit is contained in:
parent
3b80eeac09
commit
a9692464ad
5 changed files with 83 additions and 1 deletions
|
@ -18,6 +18,9 @@
|
|||
#include "mastodont_types.h"
|
||||
#include <cjson/cJSON.h>
|
||||
|
||||
#define MSTDNT_LOOKUP_ACCT 0
|
||||
#define MSTDNT_LOOPUP_ID 1
|
||||
|
||||
struct mstdnt_account
|
||||
{
|
||||
char* id;
|
||||
|
@ -52,6 +55,7 @@ struct mstdnt_account
|
|||
};
|
||||
|
||||
int mastodont_account(mastodont_t* data,
|
||||
int lookup_type,
|
||||
char* id,
|
||||
struct mstdnt_account* acct,
|
||||
struct mstdnt_storage* storage,
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <cjson/cJSON.h>
|
||||
|
||||
#define MSTDNT_URLSIZE 2048
|
||||
#define MSTDNT_URISIZE 512
|
||||
typedef unsigned char mstdnt_bool;
|
||||
|
||||
typedef struct mastodont
|
||||
|
|
30
include/mastodont_uri.h
Normal file
30
include/mastodont_uri.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* 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 MASTODONT_URI_H
|
||||
#define MASTODONT_URI_H
|
||||
#include <mastodont_types.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct mstdnt_uri
|
||||
{
|
||||
char* user;
|
||||
char* domain;
|
||||
char storage[MSTDNT_URISIZE];
|
||||
};
|
||||
|
||||
struct mstdnt_uri mastodont_uristr_to_uri(char* uri, size_t len);
|
||||
|
||||
#endif /* MASTODONT_URI_H */
|
|
@ -19,6 +19,7 @@
|
|||
#include "mastodont_fetch.h"
|
||||
|
||||
int mastodont_account(mastodont_t* data,
|
||||
int lookup,
|
||||
char* id,
|
||||
struct mstdnt_account* acct,
|
||||
struct mstdnt_storage* storage,
|
||||
|
@ -28,7 +29,9 @@ int mastodont_account(mastodont_t* data,
|
|||
cJSON* root;
|
||||
char url[MSTDNT_URLSIZE];
|
||||
struct mstdnt_fetch_results results = { 0 };
|
||||
snprintf(url, MSTDNT_URLSIZE, "api/v1/accounts/%s", id);
|
||||
snprintf(url, MSTDNT_URLSIZE,
|
||||
lookup ? "/api/v1/accounts/%s" : "/api/v1/accounts/lookup?acct=%s",
|
||||
id);
|
||||
storage->needs_cleanup = 0;
|
||||
|
||||
res = mastodont_fetch_curl(data, url, &results);
|
||||
|
|
44
src/uri.c
Normal file
44
src/uri.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* 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_uri.h>
|
||||
#include <string.h>
|
||||
|
||||
struct mstdnt_uri mastodont_uristr_to_uri(char* uri, size_t len)
|
||||
{
|
||||
int i;
|
||||
struct mstdnt_uri ret;
|
||||
if (len <= 0)
|
||||
len = strlen(uri);
|
||||
|
||||
ret.user = ret.storage;
|
||||
/* Copy information over */
|
||||
for (i = 0; i < len; ++i)
|
||||
{
|
||||
switch (uri[i])
|
||||
{
|
||||
case '@':
|
||||
ret.storage[i] = '\0';
|
||||
ret.domain = ret.storage + i + 1;
|
||||
break;
|
||||
default:
|
||||
ret.storage[i] = uri[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret.storage[i] = '\0';
|
||||
return ret;
|
||||
}
|
Loading…
Reference in a new issue