Backported from xs.

This commit is contained in:
default 2022-09-25 22:57:18 +02:00
parent 424557fcb8
commit d86f6ee27f
4 changed files with 17 additions and 17 deletions

View file

@ -256,7 +256,7 @@ void process_message(snac *snac, char *msg, char *req)
char *object, *utype; char *object, *utype;
object = xs_dict_get(msg, "object"); 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"); utype = xs_dict_get(object, "type");
else else
utype = "(null)"; utype = "(null)";

View file

@ -82,7 +82,7 @@ int webfinger_request(char *qs, char **actor, char **user)
char *v; char *v;
while (xs_list_iter(&list, &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"); char *type = xs_dict_get(v, "type");
if (type && strcmp(type, "application/activity+json") == 0) { if (type && strcmp(type, "application/activity+json") == 0) {

24
xs.h
View file

@ -17,10 +17,10 @@ typedef enum {
XSTYPE_NULL = 0x18, XSTYPE_NULL = 0x18,
XSTYPE_TRUE = 0x06, XSTYPE_TRUE = 0x06,
XSTYPE_FALSE = 0x15, XSTYPE_FALSE = 0x15,
XSTYPE_SOL = 0x11, XSTYPE_LIST = 0x11,
XSTYPE_LITEM = 0x1f, XSTYPE_LITEM = 0x1f,
XSTYPE_EOL = 0x12, XSTYPE_EOL = 0x12,
XSTYPE_SOD = 0x13, XSTYPE_DICT = 0x13,
XSTYPE_DITEM = 0x1e, XSTYPE_DITEM = 0x1e,
XSTYPE_EOD = 0x14, XSTYPE_EOD = 0x14,
XSTYPE_NUMBER = 0x17, XSTYPE_NUMBER = 0x17,
@ -103,9 +103,9 @@ xstype xs_type(const char *data)
case XSTYPE_NULL: case XSTYPE_NULL:
case XSTYPE_TRUE: case XSTYPE_TRUE:
case XSTYPE_FALSE: case XSTYPE_FALSE:
case XSTYPE_SOL: case XSTYPE_LIST:
case XSTYPE_EOL: case XSTYPE_EOL:
case XSTYPE_SOD: case XSTYPE_DICT:
case XSTYPE_EOD: case XSTYPE_EOD:
case XSTYPE_LITEM: case XSTYPE_LITEM:
case XSTYPE_DITEM: case XSTYPE_DITEM:
@ -136,19 +136,19 @@ int xs_size(const char *data)
len = strlen(data) + 1; len = strlen(data) + 1;
break; break;
case XSTYPE_SOL: case XSTYPE_LIST:
/* look for a balanced EOL */ /* look for a balanced EOL */
do { 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++; len++;
} while (c); } while (c);
break; break;
case XSTYPE_SOD: case XSTYPE_DICT:
/* look for a balanced EOD */ /* look for a balanced EOD */
do { 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++; len++;
} while (c); } while (c);
@ -397,7 +397,7 @@ d_char *xs_list_new(void)
d_char *list; d_char *list;
list = malloc(_xs_blk_size(2)); list = malloc(_xs_blk_size(2));
list[0] = XSTYPE_SOL; list[0] = XSTYPE_LIST;
list[1] = XSTYPE_EOL; list[1] = XSTYPE_EOL;
return list; return list;
@ -429,7 +429,7 @@ int xs_list_iter(char **list, char **value)
p = *list; p = *list;
/* skip a possible start of the list */ /* skip a possible start of the list */
if (*p == XSTYPE_SOL) if (*p == XSTYPE_LIST)
p++; p++;
/* an element? */ /* an element? */
@ -572,7 +572,7 @@ d_char *xs_dict_new(void)
d_char *dict; d_char *dict;
dict = malloc(_xs_blk_size(2)); dict = malloc(_xs_blk_size(2));
dict[0] = XSTYPE_SOD; dict[0] = XSTYPE_DICT;
dict[1] = XSTYPE_EOD; dict[1] = XSTYPE_EOD;
return dict; return dict;
@ -606,7 +606,7 @@ int xs_dict_iter(char **dict, char **key, char **value)
p = *dict; p = *dict;
/* skip a possible start of the list */ /* skip a possible start of the list */
if (*p == XSTYPE_SOD) if (*p == XSTYPE_DICT)
p++; p++;
/* an element? */ /* an element? */

View file

@ -111,7 +111,7 @@ d_char *_xs_json_dumps(d_char *s, char *data, int level, int indent)
} }
break; break;
case XSTYPE_SOL: case XSTYPE_LIST:
s = xs_str_cat(s, "["); s = xs_str_cat(s, "[");
while (xs_list_iter(&data, &v)) { 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; break;
case XSTYPE_SOD: case XSTYPE_DICT:
s = xs_str_cat(s, "{"); s = xs_str_cat(s, "{");
while (xs_dict_iter(&data, &k, &v)) { 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); xstype t = xs_type(data);
d_char *s = NULL; 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_str_new(NULL);
s = _xs_json_dumps(s, data, 0, indent); s = _xs_json_dumps(s, data, 0, indent);
} }