From 65c118ce6cdd6246215f643a82d0598e722358fe Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Fri, 19 Jun 2015 22:57:11 +0000 Subject: [PATCH] Debugging support. --- clients/c/cosmopolite-int.h | 1 + clients/c/cosmopolite.c | 11 ++++++++++- clients/c/test.c | 4 +++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/clients/c/cosmopolite-int.h b/clients/c/cosmopolite-int.h index c6dbb87..b7dbc58 100644 --- a/clients/c/cosmopolite-int.h +++ b/clients/c/cosmopolite-int.h @@ -18,6 +18,7 @@ struct cosmo { json_t *subscriptions; uint64_t next_delay_ms; unsigned int seedp; + bool debug; enum { INITIAL_CONNECT, diff --git a/clients/c/cosmopolite.c b/clients/c/cosmopolite.c index d6a3015..daf47ee 100644 --- a/clients/c/cosmopolite.c +++ b/clients/c/cosmopolite.c @@ -247,6 +247,9 @@ static json_t *cosmo_send_rpc(cosmo *instance, json_t *commands, json_t *ack) { json_array_extend(int_commands, commands); char *request = cosmo_build_rpc(instance, int_commands); + if (instance->debug) { + fprintf(stderr, "--> %s\n", request); + } char *response = cosmo_send_http(instance, request); json_decref(int_commands); @@ -254,6 +257,10 @@ static json_t *cosmo_send_rpc(cosmo *instance, json_t *commands, json_t *ack) { return commands; } + if (instance->debug) { + fprintf(stderr, "<-- %s\n", response); + } + json_error_t error; json_t *received = json_loads(response, 0, &error); if (!received) { @@ -524,6 +531,8 @@ cosmo *cosmo_create(const char *base_url, const char *client_id, const cosmo_cal instance->seedp = (unsigned int) time(NULL); + instance->debug = false; + strcpy(instance->client_id, client_id); cosmo_uuid(instance->instance_id); @@ -541,7 +550,7 @@ cosmo *cosmo_create(const char *base_url, const char *client_id, const cosmo_cal assert(!curl_easy_setopt(instance->curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS)); assert(!curl_easy_setopt(instance->curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS)); assert(!curl_easy_setopt(instance->curl, CURLOPT_SSL_CIPHER_LIST, "ECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH")); - assert(!curl_easy_setopt(instance->curl, CURLOPT_TIMEOUT, CYCLE_MS / MS_PER_S)); + assert(!curl_easy_setopt(instance->curl, CURLOPT_TIMEOUT_MS, CYCLE_MS)); assert(!curl_easy_setopt(instance->curl, CURLOPT_POST, 1L)); assert(!curl_easy_setopt(instance->curl, CURLOPT_READFUNCTION, cosmo_read_callback)); assert(!curl_easy_setopt(instance->curl, CURLOPT_WRITEFUNCTION, cosmo_write_callback)); diff --git a/clients/c/test.c b/clients/c/test.c index ce7335c..70b5936 100644 --- a/clients/c/test.c +++ b/clients/c/test.c @@ -126,7 +126,9 @@ cosmo *create_client(test_state *state) { .message = on_message, }; - return cosmo_create("https://playground.cosmopolite.org/cosmopolite", client_id, &callbacks, state); + cosmo *ret = cosmo_create("https://playground.cosmopolite.org/cosmopolite", client_id, &callbacks, state); + // ret->debug = true; + return ret; } json_t *random_subject(const char *readable_only_by, const char *writeable_only_by) {