diff options
-rw-r--r-- | example/hello.c | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/example/hello.c b/example/hello.c index f192a52..fe208d5 100644 --- a/example/hello.c +++ b/example/hello.c @@ -1,16 +1,40 @@ #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> +extern CURL *ws_handle; + int hello(cJSON *data) { - char *string = cJSON_Print(data); - print("hello, world!"); - print("hello data: %s", string); - free(string); + cJSON *ev_payload = cJSON_CreateObject(); + cJSON *ev_data = cJSON_CreateObject(); + cJSON_AddNumberToObject(ev_payload, "op", 2); + cJSON_AddItemToObject(ev_payload, "d", ev_data); + + cJSON_AddStringToObject(ev_data, "token", getenv("TOKEN")); + cJSON_AddNumberToObject(ev_data, "intents", 0); + + cJSON *properties = cJSON_CreateObject(); + cJSON_AddItemToObject(ev_data, "properties", properties); + cJSON_AddStringToObject(properties, "browser", "DBS"); + cJSON_AddStringToObject(properties, "device", "DBS"); + + struct utsname unamed; + uname(&unamed); + cJSON_AddStringToObject(properties, "os", unamed.sysname); + + char *msg = cJSON_PrintUnformatted(ev_payload); + size_t sent; + curl_ws_send(ws_handle, msg, strlen(msg), &sent, 0, CURLWS_TEXT); + free(msg); + cJSON_Delete(ev_payload); + print("hello: sent IDENT"); return 0; } |