trg_response *dispatch(TrgClient * tc, JsonNode * req) { gchar *serialized = trg_serialize(req); json_node_free(req); #ifdef DEBUG if (g_getenv("TRG_SHOW_OUTGOING")) g_debug("=>(OUTgoing)=>: %s", serialized); #endif return dispatch_str(tc, serialized); }
trg_response *dispatch(TrgClient * tc, trg_request *req) { trg_response *response = g_new0(trg_response, 1); GError *decode_error = NULL; JsonNode *result; if (req->node && !req->body) req->body = trg_serialize(req->node); #ifdef DEBUG if (g_getenv("TRG_SHOW_OUTGOING")) g_message("=>(OUTgoing)=>: %s", req->body); #endif trg_http_perform(tc, req, response); if (response->status == CURLE_OK) response->obj = trg_deserialize(response, &decode_error); g_free(response->raw); response->raw = NULL; if (response->status != CURLE_OK) return response; if (decode_error) { g_error("JSON decoding error: %s", decode_error->message); g_error_free(decode_error); response->status = FAIL_JSON_DECODE; return response; } result = json_object_get_member(response->obj, FIELD_RESULT); if (!result || g_strcmp0(json_node_get_string(result), FIELD_SUCCESS)) response->status = FAIL_RESPONSE_UNSUCCESSFUL; return response; }