Skip to content

Commit

Permalink
Populate the rcode pval in rest get/post methods before returning error
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarrod Baumann authored and liviuchircu committed Apr 24, 2015
1 parent a6ece8d commit fa37b3d
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions modules/rest_client/rest_methods.c
Expand Up @@ -93,6 +93,20 @@ int rest_get_method(struct sip_msg *msg, char *url,
w_curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L);

rc = curl_easy_perform(handle);

if (code_pv) {
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &http_rc);
LM_DBG("Last response code: %ld\n", http_rc);

pv_val.flags = PV_VAL_INT|PV_TYPE_INT;
pv_val.ri = (int)http_rc;

if (pv_set_value(msg, code_pv, 0, &pv_val) != 0) {
LM_ERR("Set code pv value failed!\n");
goto error;
}
}

if (rc != CURLE_OK) {
LM_ERR("Error [%i] while performing curl operation\n", rc);
LM_ERR("[%s]\n", err_buff);
Expand Down Expand Up @@ -123,19 +137,6 @@ int rest_get_method(struct sip_msg *msg, char *url,
}
}

if (code_pv) {
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &http_rc);
LM_DBG("Last response code: %ld\n", http_rc);

pv_val.flags = PV_VAL_INT|PV_TYPE_INT;
pv_val.ri = (int)http_rc;

if (pv_set_value(msg, code_pv, 0, &pv_val) != 0) {
LM_ERR("Set code pv value failed!\n");
goto error;
}
}

curl_easy_cleanup(handle);
return 1;

Expand Down Expand Up @@ -206,6 +207,19 @@ int rest_post_method(struct sip_msg *msg, char *url, char *ctype, char *body,
w_curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L);

rc = curl_easy_perform(handle);
if (code_pv) {
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &http_rc);
LM_DBG("Last response code: %ld\n", http_rc);

pv_val.flags = PV_VAL_INT|PV_TYPE_INT;
pv_val.ri = (int)http_rc;

if (pv_set_value(msg, code_pv, 0, &pv_val) != 0) {
LM_ERR("Set code pv value failed!\n");
goto error;
}
}

curl_slist_free_all(list);

if (rc != CURLE_OK) {
Expand Down Expand Up @@ -238,19 +252,6 @@ int rest_post_method(struct sip_msg *msg, char *url, char *ctype, char *body,
}
}

if (code_pv) {
curl_easy_getinfo(handle, CURLINFO_RESPONSE_CODE, &http_rc);
LM_DBG("Last response code: %ld\n", http_rc);

pv_val.flags = PV_VAL_INT|PV_TYPE_INT;
pv_val.ri = (int)http_rc;

if (pv_set_value(msg, code_pv, 0, &pv_val) != 0) {
LM_ERR("Set code pv value failed!\n");
goto error;
}
}

curl_easy_cleanup(handle);
return 1;

Expand Down

0 comments on commit fa37b3d

Please sign in to comment.