aboutsummaryrefslogtreecommitdiffstats
path: root/example/hello.c
blob: 41ef753dabc87c966adbdce324570387bb0a9708 (plain)
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
#include <stdlib.h>
#include <string.h>
#include <sys/utsname.h>

#include <cJSON.h>
#include <curl/curl.h>

#include <dbs/event.h>
#include <dbs/log.h>
#include <dbs/util.h>

extern CURL *ws_handle;
char *app_id;

int hello(cJSON *data)
{
    print("hello: hello from userland!");

    return 0;
}
declare_event(HELLO, hello);

int ready(cJSON *data)
{
    print("hello: received ready event!");

    cJSON *app = cJSON_GetObjectItemCaseSensitive(data, "application");
    char *id = js_getStr(app, "id");
    app_id = malloc(strlen(id) + 1);
    strcpy(app_id, id);

    cJSON *user = cJSON_GetObjectItemCaseSensitive(data, "user");
    char *username = js_getStr(user, "username");
    print("hello: logged in! my name is %s (id %s)", username, app_id);

    return 0;
}
declare_event(READY, ready);