forked from necrosis/slack-libpurple
-
Notifications
You must be signed in to change notification settings - Fork 41
/
slack-json.h
49 lines (40 loc) · 1.63 KB
/
slack-json.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef _PURPLE_SLACK_JSON_H
#define _PURPLE_SLACK_JSON_H
#include <glib.h>
#include "json.h"
#define json_get_selector(JSON, TYPE, SELECTOR, DEFAULT) ({ \
__typeof__(JSON) _val = (JSON); \
_val && _val->type == json_##TYPE ? SELECTOR : DEFAULT; \
})
#define json_get_type(JSON, TYPE) \
json_get_selector(JSON, TYPE, _val, NULL)
#define json_get_strptr(JSON) \
json_get_selector(JSON, string, _val->u.string.ptr, NULL)
#define json_get_strptr1(JSON) ({ \
char *_str = json_get_strptr(JSON); \
_str && *_str ? _str : NULL; \
})
#define json_get_val(JSON, TYPE, DEF) \
json_get_selector(JSON, TYPE, _val->u.TYPE, DEF)
#define json_get_boolean(JSON, DEF) \
json_get_val(JSON, boolean, DEF)
json_value *json_get_prop(json_value *val, const char *prop) __attribute__((pure));
#define json_get_prop_type(JSON, PROP, TYPE) \
json_get_type(json_get_prop(JSON, PROP), TYPE)
#define json_get_prop_strptr(JSON, PROP) \
json_get_strptr(json_get_prop(JSON, PROP))
#define json_get_prop_strptr1(JSON, PROP) \
json_get_strptr1(json_get_prop(JSON, PROP))
#define json_get_prop_val(JSON, PROP, TYPE, DEF) \
json_get_val(json_get_prop(JSON, PROP), TYPE, DEF)
#define json_get_prop_boolean(JSON, PROP, DEF) \
json_get_boolean(json_get_prop(JSON, PROP), DEF)
/* Add an escaped, quoted json string to a GString */
GString *append_json_string(GString *str, const char *s);
time_t slack_parse_time_str(const char *str);
time_t slack_parse_time(json_value *val);
static inline int slack_ts_cmp(const char *a, const char *b) {
/* at least for the next few hundred years, these should be fixed length, so just treat them as such */
return g_strcmp0(a, b);
}
#endif