mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-25 14:35:04 +00:00
Some prototype update.
This commit is contained in:
parent
33f1f915db
commit
125317ac47
2 changed files with 29 additions and 29 deletions
44
data.c
44
data.c
|
@ -32,7 +32,7 @@ int srv_open(char *basedir, int auto_upgrade)
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
xs *cfg_file = NULL;
|
xs *cfg_file = NULL;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
d_char *error = NULL;
|
xs_str *error = NULL;
|
||||||
|
|
||||||
pthread_mutex_init(&data_mutex, NULL);
|
pthread_mutex_init(&data_mutex, NULL);
|
||||||
|
|
||||||
|
@ -485,7 +485,7 @@ int index_len(const char *fn)
|
||||||
xs_list *index_list(const char *fn, int max)
|
xs_list *index_list(const char *fn, int max)
|
||||||
/* returns an index as a list */
|
/* returns an index as a list */
|
||||||
{
|
{
|
||||||
d_char *list = NULL;
|
xs_list *list = NULL;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
|
@ -511,7 +511,7 @@ xs_list *index_list(const char *fn, int max)
|
||||||
xs_list *index_list_desc(const char *fn, int skip, int show)
|
xs_list *index_list_desc(const char *fn, int skip, int show)
|
||||||
/* returns an index as a list, in reverse order */
|
/* returns an index as a list, in reverse order */
|
||||||
{
|
{
|
||||||
d_char *list = NULL;
|
xs_list *list = NULL;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
|
@ -543,7 +543,7 @@ xs_list *index_list_desc(const char *fn, int skip, int show)
|
||||||
|
|
||||||
/** objects **/
|
/** objects **/
|
||||||
|
|
||||||
d_char *_object_fn_by_md5(const char *md5)
|
xs_str *_object_fn_by_md5(const char *md5)
|
||||||
{
|
{
|
||||||
xs *bfn = xs_fmt("%s/object/%c%c", srv_basedir, md5[0], md5[1]);
|
xs *bfn = xs_fmt("%s/object/%c%c", srv_basedir, md5[0], md5[1]);
|
||||||
|
|
||||||
|
@ -553,14 +553,14 @@ d_char *_object_fn_by_md5(const char *md5)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
d_char *_object_fn(const char *id)
|
xs_str *_object_fn(const char *id)
|
||||||
{
|
{
|
||||||
xs *md5 = xs_md5_hex(id, strlen(id));
|
xs *md5 = xs_md5_hex(id, strlen(id));
|
||||||
return _object_fn_by_md5(md5);
|
return _object_fn_by_md5(md5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int object_here_by_md5(char *id)
|
int object_here_by_md5(const char *id)
|
||||||
/* checks if an object is already downloaded */
|
/* checks if an object is already downloaded */
|
||||||
{
|
{
|
||||||
xs *fn = _object_fn_by_md5(id);
|
xs *fn = _object_fn_by_md5(id);
|
||||||
|
@ -568,7 +568,7 @@ int object_here_by_md5(char *id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int object_here(char *id)
|
int object_here(const char *id)
|
||||||
/* checks if an object is already downloaded */
|
/* checks if an object is already downloaded */
|
||||||
{
|
{
|
||||||
xs *fn = _object_fn(id);
|
xs *fn = _object_fn(id);
|
||||||
|
@ -609,7 +609,7 @@ int object_get(const char *id, xs_dict **obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int _object_add(const char *id, d_char *obj, int ow)
|
int _object_add(const char *id, const xs_dict *obj, int ow)
|
||||||
/* stores an object */
|
/* stores an object */
|
||||||
{
|
{
|
||||||
int status = 201; /* Created */
|
int status = 201; /* Created */
|
||||||
|
@ -666,14 +666,14 @@ int _object_add(const char *id, d_char *obj, int ow)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int object_add(const char *id, d_char *obj)
|
int object_add(const char *id, const xs_dict *obj)
|
||||||
/* stores an object */
|
/* stores an object */
|
||||||
{
|
{
|
||||||
return _object_add(id, obj, 0);
|
return _object_add(id, obj, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int object_add_ow(const char *id, d_char *obj)
|
int object_add_ow(const char *id, const xs_dict *obj)
|
||||||
/* stores an object (overwriting allowed) */
|
/* stores an object (overwriting allowed) */
|
||||||
{
|
{
|
||||||
return _object_add(id, obj, 1);
|
return _object_add(id, obj, 1);
|
||||||
|
@ -744,10 +744,10 @@ double object_ctime(const char *id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
d_char *_object_index_fn(const char *id, const char *idxsfx)
|
xs_str *_object_index_fn(const char *id, const char *idxsfx)
|
||||||
/* returns the filename of an object's index */
|
/* returns the filename of an object's index */
|
||||||
{
|
{
|
||||||
d_char *fn = _object_fn(id);
|
xs_str *fn = _object_fn(id);
|
||||||
return xs_replace_i(fn, ".json", idxsfx);
|
return xs_replace_i(fn, ".json", idxsfx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -879,7 +879,7 @@ int object_user_cache_in(snac *snac, const char *id, const char *cachedir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
d_char *object_user_cache_list(snac *snac, const char *cachedir, int max)
|
xs_list *object_user_cache_list(snac *snac, const char *cachedir, int max)
|
||||||
/* returns the objects in a cache as a list */
|
/* returns the objects in a cache as a list */
|
||||||
{
|
{
|
||||||
xs *idx = xs_fmt("%s/%s.idx", snac->basedir, cachedir);
|
xs *idx = xs_fmt("%s/%s.idx", snac->basedir, cachedir);
|
||||||
|
@ -920,11 +920,11 @@ int follower_check(snac *snac, const char *actor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
d_char *follower_list(snac *snac)
|
xs_list *follower_list(snac *snac)
|
||||||
/* returns the list of followers */
|
/* returns the list of followers */
|
||||||
{
|
{
|
||||||
xs *list = object_user_cache_list(snac, "followers", XS_ALL);
|
xs *list = object_user_cache_list(snac, "followers", XS_ALL);
|
||||||
d_char *fwers = xs_list_new();
|
xs_list *fwers = xs_list_new();
|
||||||
char *p, *v;
|
char *p, *v;
|
||||||
|
|
||||||
/* resolve the list of md5 to be a list of actors */
|
/* resolve the list of md5 to be a list of actors */
|
||||||
|
@ -1150,7 +1150,7 @@ xs_list *timeline_instance_list(int skip, int show)
|
||||||
with a link to a cached author, because we need the Follow object
|
with a link to a cached author, because we need the Follow object
|
||||||
in case we need to unfollow (Undo + original Follow) */
|
in case we need to unfollow (Undo + original Follow) */
|
||||||
|
|
||||||
d_char *_following_fn(snac *snac, const char *actor)
|
xs_str *_following_fn(snac *snac, const char *actor)
|
||||||
{
|
{
|
||||||
xs *md5 = xs_md5_hex(actor, strlen(actor));
|
xs *md5 = xs_md5_hex(actor, strlen(actor));
|
||||||
return xs_fmt("%s/following/%s.json", snac->basedir, md5);
|
return xs_fmt("%s/following/%s.json", snac->basedir, md5);
|
||||||
|
@ -1201,7 +1201,7 @@ int following_check(snac *snac, const char *actor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int following_get(snac *snac, const char *actor, d_char **data)
|
int following_get(snac *snac, const char *actor, xs_dict **data)
|
||||||
/* returns the 'Follow' object */
|
/* returns the 'Follow' object */
|
||||||
{
|
{
|
||||||
xs *fn = _following_fn(snac, actor);
|
xs *fn = _following_fn(snac, actor);
|
||||||
|
@ -1262,7 +1262,7 @@ xs_list *following_list(snac *snac)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
d_char *_muted_fn(snac *snac, const char *actor)
|
xs_str *_muted_fn(snac *snac, const char *actor)
|
||||||
{
|
{
|
||||||
xs *md5 = xs_md5_hex(actor, strlen(actor));
|
xs *md5 = xs_md5_hex(actor, strlen(actor));
|
||||||
return xs_fmt("%s/muted/%s", snac->basedir, md5);
|
return xs_fmt("%s/muted/%s", snac->basedir, md5);
|
||||||
|
@ -1304,7 +1304,7 @@ int is_muted(snac *snac, const char *actor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
d_char *_hidden_fn(snac *snac, const char *id)
|
xs_str *_hidden_fn(snac *snac, const char *id)
|
||||||
{
|
{
|
||||||
xs *md5 = xs_md5_hex(id, strlen(id));
|
xs *md5 = xs_md5_hex(id, strlen(id));
|
||||||
return xs_fmt("%s/hidden/%s", snac->basedir, md5);
|
return xs_fmt("%s/hidden/%s", snac->basedir, md5);
|
||||||
|
@ -1424,7 +1424,7 @@ int actor_get(snac *snac1, const char *actor, xs_dict **data)
|
||||||
|
|
||||||
/** static data **/
|
/** static data **/
|
||||||
|
|
||||||
d_char *_static_fn(snac *snac, const char *id)
|
xs_str *_static_fn(snac *snac, const char *id)
|
||||||
/* gets the filename for a static file */
|
/* gets the filename for a static file */
|
||||||
{
|
{
|
||||||
if (strchr(id, '/'))
|
if (strchr(id, '/'))
|
||||||
|
@ -1434,7 +1434,7 @@ d_char *_static_fn(snac *snac, const char *id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int static_get(snac *snac, const char *id, d_char **data, int *size)
|
int static_get(snac *snac, const char *id, xs_val **data, int *size)
|
||||||
/* returns static content */
|
/* returns static content */
|
||||||
{
|
{
|
||||||
xs *fn = _static_fn(snac, id);
|
xs *fn = _static_fn(snac, id);
|
||||||
|
|
14
snac.h
14
snac.h
|
@ -73,10 +73,10 @@ int index_len(const char *fn);
|
||||||
xs_list *index_list(const char *fn, int max);
|
xs_list *index_list(const char *fn, int max);
|
||||||
xs_list *index_list_desc(const char *fn, int skip, int show);
|
xs_list *index_list_desc(const char *fn, int skip, int show);
|
||||||
|
|
||||||
int object_add(const char *id, d_char *obj);
|
int object_add(const char *id, const xs_dict *obj);
|
||||||
int object_add_ow(const char *id, d_char *obj);
|
int object_add_ow(const char *id, const xs_dict *obj);
|
||||||
int object_here_by_md5(char *id);
|
int object_here_by_md5(const char *id);
|
||||||
int object_here(char *id);
|
int object_here(const char *id);
|
||||||
int object_get_by_md5(const char *md5, xs_dict **obj);
|
int object_get_by_md5(const char *md5, xs_dict **obj);
|
||||||
int object_get(const char *id, xs_dict **obj);
|
int object_get(const char *id, xs_dict **obj);
|
||||||
int object_del(const char *id);
|
int object_del(const char *id);
|
||||||
|
@ -100,7 +100,7 @@ int object_user_cache_del(snac *snac, const char *id, const char *cachedir);
|
||||||
int follower_add(snac *snac, const char *actor);
|
int follower_add(snac *snac, const char *actor);
|
||||||
int follower_del(snac *snac, const char *actor);
|
int follower_del(snac *snac, const char *actor);
|
||||||
int follower_check(snac *snac, const char *actor);
|
int follower_check(snac *snac, const char *actor);
|
||||||
d_char *follower_list(snac *snac);
|
xs_list *follower_list(snac *snac);
|
||||||
|
|
||||||
double timeline_mtime(snac *snac);
|
double timeline_mtime(snac *snac);
|
||||||
int timeline_touch(snac *snac);
|
int timeline_touch(snac *snac);
|
||||||
|
@ -119,7 +119,7 @@ xs_list *timeline_instance_list(int skip, int show);
|
||||||
int following_add(snac *snac, const char *actor, const xs_dict *msg);
|
int following_add(snac *snac, const char *actor, const xs_dict *msg);
|
||||||
int following_del(snac *snac, const char *actor);
|
int following_del(snac *snac, const char *actor);
|
||||||
int following_check(snac *snac, const char *actor);
|
int following_check(snac *snac, const char *actor);
|
||||||
int following_get(snac *snac, const char *actor, d_char **data);
|
int following_get(snac *snac, const char *actor, xs_dict **data);
|
||||||
xs_list *following_list(snac *snac);
|
xs_list *following_list(snac *snac);
|
||||||
|
|
||||||
void mute(snac *snac, const char *actor);
|
void mute(snac *snac, const char *actor);
|
||||||
|
@ -132,7 +132,7 @@ int is_hidden(snac *snac, const char *id);
|
||||||
int actor_add(const char *actor, xs_dict *msg);
|
int actor_add(const char *actor, xs_dict *msg);
|
||||||
int actor_get(snac *snac, const char *actor, xs_dict **data);
|
int actor_get(snac *snac, const char *actor, xs_dict **data);
|
||||||
|
|
||||||
int static_get(snac *snac, const char *id, d_char **data, int *size);
|
int static_get(snac *snac, const char *id, xs_val **data, int *size);
|
||||||
void static_put(snac *snac, const char *id, const char *data, int size);
|
void static_put(snac *snac, const char *id, const char *data, int size);
|
||||||
void static_put_meta(snac *snac, const char *id, const char *str);
|
void static_put_meta(snac *snac, const char *id, const char *str);
|
||||||
xs_str *static_get_meta(snac *snac, const char *id);
|
xs_str *static_get_meta(snac *snac, const char *id);
|
||||||
|
|
Loading…
Reference in a new issue