mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 05:15:04 +00:00
Backported from xs.
This commit is contained in:
parent
424557fcb8
commit
d86f6ee27f
4 changed files with 17 additions and 17 deletions
|
@ -256,7 +256,7 @@ void process_message(snac *snac, char *msg, char *req)
|
|||
char *object, *utype;
|
||||
|
||||
object = xs_dict_get(msg, "object");
|
||||
if (object != NULL && xs_type(object) == XSTYPE_SOD)
|
||||
if (object != NULL && xs_type(object) == XSTYPE_DICT)
|
||||
utype = xs_dict_get(object, "type");
|
||||
else
|
||||
utype = "(null)";
|
||||
|
|
|
@ -82,7 +82,7 @@ int webfinger_request(char *qs, char **actor, char **user)
|
|||
char *v;
|
||||
|
||||
while (xs_list_iter(&list, &v)) {
|
||||
if (xs_type(v) == XSTYPE_SOD) {
|
||||
if (xs_type(v) == XSTYPE_DICT) {
|
||||
char *type = xs_dict_get(v, "type");
|
||||
|
||||
if (type && strcmp(type, "application/activity+json") == 0) {
|
||||
|
|
24
xs.h
24
xs.h
|
@ -17,10 +17,10 @@ typedef enum {
|
|||
XSTYPE_NULL = 0x18,
|
||||
XSTYPE_TRUE = 0x06,
|
||||
XSTYPE_FALSE = 0x15,
|
||||
XSTYPE_SOL = 0x11,
|
||||
XSTYPE_LIST = 0x11,
|
||||
XSTYPE_LITEM = 0x1f,
|
||||
XSTYPE_EOL = 0x12,
|
||||
XSTYPE_SOD = 0x13,
|
||||
XSTYPE_DICT = 0x13,
|
||||
XSTYPE_DITEM = 0x1e,
|
||||
XSTYPE_EOD = 0x14,
|
||||
XSTYPE_NUMBER = 0x17,
|
||||
|
@ -103,9 +103,9 @@ xstype xs_type(const char *data)
|
|||
case XSTYPE_NULL:
|
||||
case XSTYPE_TRUE:
|
||||
case XSTYPE_FALSE:
|
||||
case XSTYPE_SOL:
|
||||
case XSTYPE_LIST:
|
||||
case XSTYPE_EOL:
|
||||
case XSTYPE_SOD:
|
||||
case XSTYPE_DICT:
|
||||
case XSTYPE_EOD:
|
||||
case XSTYPE_LITEM:
|
||||
case XSTYPE_DITEM:
|
||||
|
@ -136,19 +136,19 @@ int xs_size(const char *data)
|
|||
len = strlen(data) + 1;
|
||||
break;
|
||||
|
||||
case XSTYPE_SOL:
|
||||
case XSTYPE_LIST:
|
||||
/* look for a balanced EOL */
|
||||
do {
|
||||
c += data[len] == XSTYPE_SOL ? 1 : data[len] == XSTYPE_EOL ? -1 : 0;
|
||||
c += data[len] == XSTYPE_LIST ? 1 : data[len] == XSTYPE_EOL ? -1 : 0;
|
||||
len++;
|
||||
} while (c);
|
||||
|
||||
break;
|
||||
|
||||
case XSTYPE_SOD:
|
||||
case XSTYPE_DICT:
|
||||
/* look for a balanced EOD */
|
||||
do {
|
||||
c += data[len] == XSTYPE_SOD ? 1 : data[len] == XSTYPE_EOD ? -1 : 0;
|
||||
c += data[len] == XSTYPE_DICT ? 1 : data[len] == XSTYPE_EOD ? -1 : 0;
|
||||
len++;
|
||||
} while (c);
|
||||
|
||||
|
@ -397,7 +397,7 @@ d_char *xs_list_new(void)
|
|||
d_char *list;
|
||||
|
||||
list = malloc(_xs_blk_size(2));
|
||||
list[0] = XSTYPE_SOL;
|
||||
list[0] = XSTYPE_LIST;
|
||||
list[1] = XSTYPE_EOL;
|
||||
|
||||
return list;
|
||||
|
@ -429,7 +429,7 @@ int xs_list_iter(char **list, char **value)
|
|||
p = *list;
|
||||
|
||||
/* skip a possible start of the list */
|
||||
if (*p == XSTYPE_SOL)
|
||||
if (*p == XSTYPE_LIST)
|
||||
p++;
|
||||
|
||||
/* an element? */
|
||||
|
@ -572,7 +572,7 @@ d_char *xs_dict_new(void)
|
|||
d_char *dict;
|
||||
|
||||
dict = malloc(_xs_blk_size(2));
|
||||
dict[0] = XSTYPE_SOD;
|
||||
dict[0] = XSTYPE_DICT;
|
||||
dict[1] = XSTYPE_EOD;
|
||||
|
||||
return dict;
|
||||
|
@ -606,7 +606,7 @@ int xs_dict_iter(char **dict, char **key, char **value)
|
|||
p = *dict;
|
||||
|
||||
/* skip a possible start of the list */
|
||||
if (*p == XSTYPE_SOD)
|
||||
if (*p == XSTYPE_DICT)
|
||||
p++;
|
||||
|
||||
/* an element? */
|
||||
|
|
|
@ -111,7 +111,7 @@ d_char *_xs_json_dumps(d_char *s, char *data, int level, int indent)
|
|||
}
|
||||
break;
|
||||
|
||||
case XSTYPE_SOL:
|
||||
case XSTYPE_LIST:
|
||||
s = xs_str_cat(s, "[");
|
||||
|
||||
while (xs_list_iter(&data, &v)) {
|
||||
|
@ -129,7 +129,7 @@ d_char *_xs_json_dumps(d_char *s, char *data, int level, int indent)
|
|||
|
||||
break;
|
||||
|
||||
case XSTYPE_SOD:
|
||||
case XSTYPE_DICT:
|
||||
s = xs_str_cat(s, "{");
|
||||
|
||||
while (xs_dict_iter(&data, &k, &v)) {
|
||||
|
@ -171,7 +171,7 @@ d_char *xs_json_dumps_pp(char *data, int indent)
|
|||
xstype t = xs_type(data);
|
||||
d_char *s = NULL;
|
||||
|
||||
if (t == XSTYPE_SOL || t == XSTYPE_SOD) {
|
||||
if (t == XSTYPE_LIST || t == XSTYPE_DICT) {
|
||||
s = xs_str_new(NULL);
|
||||
s = _xs_json_dumps(s, data, 0, indent);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue