Debugging support.
This commit is contained in:
@@ -18,6 +18,7 @@ struct cosmo {
|
|||||||
json_t *subscriptions;
|
json_t *subscriptions;
|
||||||
uint64_t next_delay_ms;
|
uint64_t next_delay_ms;
|
||||||
unsigned int seedp;
|
unsigned int seedp;
|
||||||
|
bool debug;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
INITIAL_CONNECT,
|
INITIAL_CONNECT,
|
||||||
|
|||||||
@@ -247,6 +247,9 @@ static json_t *cosmo_send_rpc(cosmo *instance, json_t *commands, json_t *ack) {
|
|||||||
json_array_extend(int_commands, commands);
|
json_array_extend(int_commands, commands);
|
||||||
|
|
||||||
char *request = cosmo_build_rpc(instance, int_commands);
|
char *request = cosmo_build_rpc(instance, int_commands);
|
||||||
|
if (instance->debug) {
|
||||||
|
fprintf(stderr, "--> %s\n", request);
|
||||||
|
}
|
||||||
|
|
||||||
char *response = cosmo_send_http(instance, request);
|
char *response = cosmo_send_http(instance, request);
|
||||||
json_decref(int_commands);
|
json_decref(int_commands);
|
||||||
@@ -254,6 +257,10 @@ static json_t *cosmo_send_rpc(cosmo *instance, json_t *commands, json_t *ack) {
|
|||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (instance->debug) {
|
||||||
|
fprintf(stderr, "<-- %s\n", response);
|
||||||
|
}
|
||||||
|
|
||||||
json_error_t error;
|
json_error_t error;
|
||||||
json_t *received = json_loads(response, 0, &error);
|
json_t *received = json_loads(response, 0, &error);
|
||||||
if (!received) {
|
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->seedp = (unsigned int) time(NULL);
|
||||||
|
|
||||||
|
instance->debug = false;
|
||||||
|
|
||||||
strcpy(instance->client_id, client_id);
|
strcpy(instance->client_id, client_id);
|
||||||
cosmo_uuid(instance->instance_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_PROTOCOLS, CURLPROTO_HTTPS));
|
||||||
assert(!curl_easy_setopt(instance->curl, CURLOPT_REDIR_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_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_POST, 1L));
|
||||||
assert(!curl_easy_setopt(instance->curl, CURLOPT_READFUNCTION, cosmo_read_callback));
|
assert(!curl_easy_setopt(instance->curl, CURLOPT_READFUNCTION, cosmo_read_callback));
|
||||||
assert(!curl_easy_setopt(instance->curl, CURLOPT_WRITEFUNCTION, cosmo_write_callback));
|
assert(!curl_easy_setopt(instance->curl, CURLOPT_WRITEFUNCTION, cosmo_write_callback));
|
||||||
|
|||||||
@@ -126,7 +126,9 @@ cosmo *create_client(test_state *state) {
|
|||||||
.message = on_message,
|
.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) {
|
json_t *random_subject(const char *readable_only_by, const char *writeable_only_by) {
|
||||||
|
|||||||
Reference in New Issue
Block a user