FS-2936 stage 2 please test ASAP

This commit is contained in:
Anthony Minessale committed 2011-11-29 15:35:36 -06:00
1 parent 74ed2cef01
commit e794a6db21
18 files changed
+212 -249

No files matched your search

-1
View File
@@ -1,2 +1 @@
WANT_CURL=yes
include ../../../../build/modmake.rules
+39 -45
View File
@@ -188,9 +188,9 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
int fd = -1;
uint32_t cur_try;
long httpRes;
CURL *curl_handle = NULL;
struct curl_slist *headers = NULL;
struct curl_slist *slist = NULL;
switch_CURL *curl_handle = NULL;
switch_curl_slist_t *headers = NULL;
switch_curl_slist_t *slist = NULL;
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_status_t status = SWITCH_STATUS_FALSE;
int is_b;
@@ -260,10 +260,10 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
/* try to post it to the web server */
if (globals.url_count) {
char *destUrl = NULL;
curl_handle = curl_easy_init();
curl_handle = switch_curl_easy_init();
if (globals.encode == ENCODING_TEXTXML) {
headers = curl_slist_append(headers, "Content-Type: text/xml");
headers = switch_curl_slist_append(headers, "Content-Type: text/xml");
} else if (globals.encode) {
switch_size_t need_bytes = strlen(xml_text) * 3 + 1;
@@ -271,16 +271,16 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
switch_assert(xml_text_escaped);
memset(xml_text_escaped, 0, need_bytes);
if (globals.encode == ENCODING_DEFAULT) {
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
headers = switch_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-base64-encoded");
headers = switch_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");
headers = switch_curl_slist_append(headers, "Content-Type: application/x-www-form-plaintext");
}
if (globals.encode == ENCODING_TEXTXML) {
@@ -291,50 +291,50 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
}
if (!zstr(globals.cred)) {
curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, globals.auth_scheme);
curl_easy_setopt(curl_handle, CURLOPT_USERPWD, globals.cred);
switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, globals.auth_scheme);
switch_curl_easy_setopt(curl_handle, CURLOPT_USERPWD, globals.cred);
}
curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, curl_xml_text);
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-xml/1.0");
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, httpCallBack);
switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);
switch_curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
switch_curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
switch_curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, curl_xml_text);
switch_curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-xml/1.0");
switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, httpCallBack);
if (globals.disable100continue) {
slist = curl_slist_append(slist, "Expect:");
curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, slist);
slist = switch_curl_slist_append(slist, "Expect:");
switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, slist);
}
if (globals.ssl_cert_file) {
curl_easy_setopt(curl_handle, CURLOPT_SSLCERT, globals.ssl_cert_file);
switch_curl_easy_setopt(curl_handle, CURLOPT_SSLCERT, globals.ssl_cert_file);
}
if (globals.ssl_key_file) {
curl_easy_setopt(curl_handle, CURLOPT_SSLKEY, globals.ssl_key_file);
switch_curl_easy_setopt(curl_handle, CURLOPT_SSLKEY, globals.ssl_key_file);
}
if (globals.ssl_key_password) {
curl_easy_setopt(curl_handle, CURLOPT_SSLKEYPASSWD, globals.ssl_key_password);
switch_curl_easy_setopt(curl_handle, CURLOPT_SSLKEYPASSWD, globals.ssl_key_password);
}
if (globals.ssl_version) {
if (!strcasecmp(globals.ssl_version, "SSLv3")) {
curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, CURL_SSLVERSION_SSLv3);
switch_curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, CURL_SSLVERSION_SSLv3);
} else if (!strcasecmp(globals.ssl_version, "TLSv1")) {
curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
switch_curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
}
}
if (globals.ssl_cacert_file) {
curl_easy_setopt(curl_handle, CURLOPT_CAINFO, globals.ssl_cacert_file);
switch_curl_easy_setopt(curl_handle, CURLOPT_CAINFO, globals.ssl_cacert_file);
}
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, globals.timeout);
switch_curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, globals.timeout);
/* these were used for testing, optionally they may be enabled if someone desires
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1); // 302 recursion level
switch_curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1); // 302 recursion level
*/
for (cur_try = 0; cur_try < globals.retries; cur_try++) {
@@ -343,23 +343,23 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
}
destUrl = switch_mprintf("%s?uuid=%s%s", globals.urls[globals.url_index], a_prefix, switch_core_session_get_uuid(session));
curl_easy_setopt(curl_handle, CURLOPT_URL, destUrl);
switch_curl_easy_setopt(curl_handle, CURLOPT_URL, destUrl);
if (!strncasecmp(destUrl, "https", 5)) {
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
}
if (globals.enable_cacert_check) {
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, TRUE);
switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, TRUE);
}
if (globals.enable_ssl_verifyhost) {
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 2);
switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 2);
}
curl_easy_perform(curl_handle);
curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes);
switch_curl_easy_perform(curl_handle);
switch_curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes);
switch_safe_free(destUrl);
if (httpRes >= 200 && httpRes <= 299) {
goto success;
@@ -374,9 +374,9 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Retry will be with url [%s]\n", globals.urls[globals.url_index]);
}
}
curl_easy_cleanup(curl_handle);
curl_slist_free_all(headers);
curl_slist_free_all(slist);
switch_curl_easy_cleanup(curl_handle);
switch_curl_slist_free_all(headers);
switch_curl_slist_free_all(slist);
slist = NULL;
headers = NULL;
curl_handle = NULL;
@@ -415,13 +415,13 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
error:
if (curl_handle) {
curl_easy_cleanup(curl_handle);
switch_curl_easy_cleanup(curl_handle);
}
if (headers) {
curl_slist_free_all(headers);
switch_curl_slist_free_all(headers);
}
if (slist) {
curl_slist_free_all(slist);
switch_curl_slist_free_all(slist);
}
if (curl_xml_text != xml_text) {
switch_safe_free(curl_xml_text);
@@ -612,10 +612,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load)
switch_xml_free(xml);
if (status == SWITCH_STATUS_SUCCESS) {
switch_curl_init();
}
return status;
}
@@ -632,8 +628,6 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_xml_cdr_shutdown)
switch_thread_rwlock_destroy(globals.log_path_lock);
switch_curl_destroy();
return SWITCH_STATUS_SUCCESS;
}
-1
View File
@@ -1,2 +1 @@
WANT_CURL=yes
include ../../../../build/modmake.rules
+40 -42
View File
@@ -140,7 +140,7 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con
void *user_data)
{
char filename[512] = "";
CURL *curl_handle = NULL;
switch_CURL *curl_handle = NULL;
struct config_data config_data;
switch_xml_t xml = NULL;
char *data = NULL;
@@ -148,9 +148,9 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
xml_binding_t *binding = (xml_binding_t *) user_data;
char *file_url;
struct curl_slist *slist = NULL;
switch_curl_slist_t *slist = NULL;
long httpRes = 0;
struct curl_slist *headers = NULL;
switch_curl_slist_t *headers = NULL;
char hostname[256] = "";
char basic_data[512];
char *uri = NULL;
@@ -205,12 +205,12 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con
switch_uuid_format(uuid_str, &uuid);
switch_snprintf(filename, sizeof(filename), "%s%s.tmp.xml", SWITCH_GLOBAL_dirs.temp_dir, uuid_str);
curl_handle = curl_easy_init();
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
curl_handle = switch_curl_easy_init();
headers = switch_curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
if (!strncasecmp(binding->url, "https", 5)) {
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
}
memset(&config_data, 0, sizeof(config_data));
@@ -220,74 +220,74 @@ static switch_xml_t xml_url_fetch(const char *section, const char *tag_name, con
if ((config_data.fd = open(filename, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
if (!zstr(binding->cred)) {
curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, binding->auth_scheme);
curl_easy_setopt(curl_handle, CURLOPT_USERPWD, binding->cred);
switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, binding->auth_scheme);
switch_curl_easy_setopt(curl_handle, CURLOPT_USERPWD, binding->cred);
}
curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);
switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);
if (binding->method != NULL)
curl_easy_setopt(curl_handle, CURLOPT_CUSTOMREQUEST, binding->method);
curl_easy_setopt(curl_handle, CURLOPT_POST, !binding->use_get_style);
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 10);
switch_curl_easy_setopt(curl_handle, CURLOPT_CUSTOMREQUEST, binding->method);
switch_curl_easy_setopt(curl_handle, CURLOPT_POST, !binding->use_get_style);
switch_curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
switch_curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 10);
if (!binding->use_get_style)
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(curl_handle, CURLOPT_URL, binding->use_get_style ? uri : dynamic_url);
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, file_callback);
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) &config_data);
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-xml/1.0");
switch_curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, data);
switch_curl_easy_setopt(curl_handle, CURLOPT_URL, binding->use_get_style ? uri : dynamic_url);
switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, file_callback);
switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) &config_data);
switch_curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-xml/1.0");
if (binding->timeout) {
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, binding->timeout);
curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
switch_curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, binding->timeout);
switch_curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
}
if (binding->disable100continue) {
slist = curl_slist_append(slist, "Expect:");
curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, slist);
slist = switch_curl_slist_append(slist, "Expect:");
switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, slist);
}
if (binding->enable_cacert_check) {
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, TRUE);
switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, TRUE);
}
if (binding->ssl_cert_file) {
curl_easy_setopt(curl_handle, CURLOPT_SSLCERT, binding->ssl_cert_file);
switch_curl_easy_setopt(curl_handle, CURLOPT_SSLCERT, binding->ssl_cert_file);
}
if (binding->ssl_key_file) {
curl_easy_setopt(curl_handle, CURLOPT_SSLKEY, binding->ssl_key_file);
switch_curl_easy_setopt(curl_handle, CURLOPT_SSLKEY, binding->ssl_key_file);
}
if (binding->ssl_key_password) {
curl_easy_setopt(curl_handle, CURLOPT_SSLKEYPASSWD, binding->ssl_key_password);
switch_curl_easy_setopt(curl_handle, CURLOPT_SSLKEYPASSWD, binding->ssl_key_password);
}
if (binding->ssl_version) {
if (!strcasecmp(binding->ssl_version, "SSLv3")) {
curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, CURL_SSLVERSION_SSLv3);
switch_curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, CURL_SSLVERSION_SSLv3);
} else if (!strcasecmp(binding->ssl_version, "TLSv1")) {
curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
switch_curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
}
}
if (binding->ssl_cacert_file) {
curl_easy_setopt(curl_handle, CURLOPT_CAINFO, binding->ssl_cacert_file);
switch_curl_easy_setopt(curl_handle, CURLOPT_CAINFO, binding->ssl_cacert_file);
}
if (binding->enable_ssl_verifyhost) {
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 2);
switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 2);
}
if (binding->cookie_file) {
curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, binding->cookie_file);
curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, binding->cookie_file);
switch_curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, binding->cookie_file);
switch_curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, binding->cookie_file);
}
curl_easy_perform(curl_handle);
curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes);
curl_easy_cleanup(curl_handle);
curl_slist_free_all(headers);
curl_slist_free_all(slist);
switch_curl_easy_perform(curl_handle);
switch_curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes);
switch_curl_easy_cleanup(curl_handle);
switch_curl_slist_free_all(headers);
switch_curl_slist_free_all(slist);
close(config_data.fd);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening temp file!\n");
@@ -548,9 +548,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_xml_curl_load)
globals.hash_root = NULL;
globals.hash_tail = NULL;
if (do_config() == SWITCH_STATUS_SUCCESS) {
switch_curl_init();
} else {
if (do_config() != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
@@ -574,7 +572,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_xml_curl_shutdown)
}
switch_xml_unbind_search_function_ptr(xml_url_fetch);
switch_curl_destroy();
return SWITCH_STATUS_SUCCESS;
}