#include <curl/curl.h>
#define MAX_URLS 20
+#define ENCODING_NONE 0
+#define ENCODING_DEFAULT 1
+#define ENCODING_BASE64 2
+#define ENCODING_TEXTXML 2
+
static struct {
char *cred;
char *urls[MAX_URLS+1];
/* try to post it to the web server */
if (globals.url_count) {
+ char* destUrl = NULL;
curl_handle = curl_easy_init();
- if (globals.encode) {
+ if (globals.encode == ENCODING_TEXTXML) {
+ headers = curl_slist_append(headers, "Content-Type: text/xml");
+ } else if (globals.encode) {
switch_size_t need_bytes = strlen(xml_text) * 3;
xml_text_escaped = malloc(need_bytes);
switch_assert(xml_text_escaped);
memset(xml_text_escaped, 0, need_bytes);
- if (globals.encode == 1) {
+ if (globals.encode == ENCODING_DEFAULT) {
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
switch_url_encode(xml_text, xml_text_escaped, need_bytes);
} else {
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-plaintext");
}
- if (!(curl_xml_text = switch_mprintf("cdr=%s", xml_text))) {
+ if (globals.encode == ENCODING_TEXTXML) {
+ curl_xml_text = xml_text;
+ } else if (!(curl_xml_text = switch_mprintf("cdr=%s", xml_text))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
goto error;
}
switch_yield(globals.delay * 1000000);
}
- curl_easy_setopt(curl_handle, CURLOPT_URL, globals.urls[globals.url_index]);
+ destUrl = switch_mprintf("%s?uuid=%s", globals.urls[globals.url_index], switch_core_session_get_uuid(session));
+ curl_easy_setopt(curl_handle, CURLOPT_URL, destUrl);
- if (!strncasecmp(globals.urls[globals.url_index], "https", 5)) {
+ if (!strncasecmp(destUrl, "https", 5)) {
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
}
curl_easy_perform(curl_handle);
curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes);
+ switch_safe_free(destUrl);
if (httpRes == 200) {
goto success;
} else {
if (slist) {
curl_slist_free_all(slist);
}
- switch_safe_free(curl_xml_text);
+ if (curl_xml_text != xml_text) {
+ switch_safe_free(curl_xml_text);
+ }
switch_safe_free(xml_text);
switch_safe_free(path);
switch_xml_free(cdr);
globals.disable100continue = 1;
} else if (!strcasecmp(var, "encode") && !zstr(val)) {
if (!strcasecmp(val, "base64")) {
- globals.encode = 2;
+ globals.encode = ENCODING_BASE64;
+ } else if (!strcasecmp(val, "textxml")) {
+ globals.encode = ENCODING_TEXTXML;
} else {
- globals.encode = switch_true(val) ? 1 : 0;
+ globals.encode = switch_true(val) ? ENCODING_DEFAULT : ENCODING_NONE;
}
} else if (!strcasecmp(var, "retries") && !zstr(val)) {
globals.retries = (uint32_t) atoi(val);