add headers
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5824 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
7962945c39
commit
b82cb961dd
|
@ -191,6 +191,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_get(switch_xml_t xml,...);
|
|||
///\param xml the xml node
|
||||
///\return the xml text string
|
||||
SWITCH_DECLARE(char *) switch_xml_toxml(switch_xml_t xml);
|
||||
SWITCH_DECLARE(char *) switch_xml_toxml_buf(switch_xml_t xml, char *buf, switch_size_t buflen, switch_size_t offset);
|
||||
|
||||
///\brief returns a NULL terminated array of processing instructions for the given
|
||||
///\ target
|
||||
|
|
|
@ -75,7 +75,6 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
|
|||
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||
|
||||
if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
|
||||
|
||||
/* build the XML */
|
||||
if (!(xml_text = switch_xml_toxml(cdr))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
|
||||
|
@ -108,6 +107,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
|
|||
|
||||
/* try to post it to the web server */
|
||||
if (!switch_strlen_zero(globals.url)) {
|
||||
struct curl_slist *headers = NULL;
|
||||
curl_handle = curl_easy_init();
|
||||
|
||||
if (globals.encode) {
|
||||
|
@ -117,13 +117,17 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
|
|||
assert(xml_text_escaped);
|
||||
memset(xml_text_escaped, 0, sizeof(xml_text_escaped));
|
||||
if (globals.encode == 1) {
|
||||
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
|
||||
switch_url_encode(xml_text, xml_text_escaped, need_bytes - 1);
|
||||
} else {
|
||||
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-base64-encoded");
|
||||
switch_b64_encode((unsigned char *)xml_text, need_bytes / 3, (unsigned char *)xml_text_escaped, need_bytes);
|
||||
}
|
||||
switch_safe_free(xml_text);
|
||||
xml_text = xml_text_escaped;
|
||||
}
|
||||
} else {
|
||||
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-plaintext");
|
||||
}
|
||||
|
||||
if (!(curl_xml_text = switch_mprintf("cdr=%s", xml_text))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
|
||||
|
@ -135,12 +139,13 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
|
|||
curl_easy_setopt(curl_handle, CURLOPT_USERPWD, globals.cred);
|
||||
}
|
||||
|
||||
curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, curl_xml_text);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, globals.url);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-xml/1.0");
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, httpCallBack);
|
||||
|
||||
|
||||
if (globals.ignore_cacert_check) {
|
||||
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
}
|
||||
|
@ -164,6 +169,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
|
|||
|
||||
}
|
||||
curl_easy_cleanup(curl_handle);
|
||||
curl_slist_free_all(headers);
|
||||
curl_handle = NULL;
|
||||
|
||||
/* if we are here the web post failed for some reason */
|
||||
|
|
|
@ -1509,21 +1509,29 @@ static char *switch_xml_toxml_r(switch_xml_t xml, char **s, switch_size_t *len,
|
|||
}
|
||||
}
|
||||
|
||||
SWITCH_DECLARE(char *) switch_xml_toxml(switch_xml_t xml)
|
||||
{
|
||||
char *s;
|
||||
s = malloc(SWITCH_XML_BUFSIZE);
|
||||
return switch_xml_toxml_buf(xml, s, SWITCH_XML_BUFSIZE, 0);
|
||||
}
|
||||
|
||||
// converts an switch_xml structure back to xml, returning a string of xml date that
|
||||
// must be freed
|
||||
SWITCH_DECLARE(char *) switch_xml_toxml(switch_xml_t xml)
|
||||
SWITCH_DECLARE(char *) switch_xml_toxml_buf(switch_xml_t xml, char *buf, switch_size_t buflen, switch_size_t offset)
|
||||
{
|
||||
switch_xml_t p = (xml) ? xml->parent : NULL, o = (xml) ? xml->ordered : NULL;
|
||||
switch_xml_root_t root = (switch_xml_root_t) xml;
|
||||
switch_size_t len = 0, max = SWITCH_XML_BUFSIZE;
|
||||
switch_size_t len = 0, max = buflen;
|
||||
char *s, *t, *n, *r;
|
||||
int i, j, k;
|
||||
uint32_t count = 0;
|
||||
|
||||
s = malloc(max);
|
||||
s = buf;
|
||||
assert(s != NULL);
|
||||
memset(s, 0, max);
|
||||
len = sprintf(s, "<?xml version=\"1.0\"?>\n");
|
||||
len += offset;
|
||||
len += sprintf(s + len, "<?xml version=\"1.0\"?>\n");
|
||||
|
||||
|
||||
if (!xml || !xml->name) {
|
||||
|
|
Loading…
Reference in New Issue