forked from Mirrors/freeswitch
FS-2936 stage 2 please test ASAP
This commit is contained in:
parent
74ed2cef01
commit
e794a6db21
@ -109,6 +109,7 @@
|
||||
#include "switch_platform.h"
|
||||
#include "switch_types.h"
|
||||
#include "switch_apr.h"
|
||||
#include "switch_curl.h"
|
||||
#include "switch_mprintf.h"
|
||||
#include "switch_core_db.h"
|
||||
#include "switch_dso.h"
|
||||
|
@ -30,34 +30,27 @@
|
||||
|
||||
#ifndef __SWITCH_CURL_H
|
||||
#define __SWITCH_CURL_H
|
||||
#include "curl/curl.h"
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <switch_ssl.h>
|
||||
|
||||
static inline void switch_curl_init(void)
|
||||
{
|
||||
int curl_count = switch_core_curl_count(NULL);
|
||||
typedef void switch_CURL;
|
||||
typedef struct curl_slist switch_curl_slist_t;
|
||||
typedef int switch_CURLINFO;
|
||||
typedef int switch_CURLcode;
|
||||
typedef int switch_CURLoption;
|
||||
|
||||
if (curl_count == 0) {
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
}
|
||||
|
||||
curl_count++;
|
||||
switch_core_curl_count(&curl_count);
|
||||
}
|
||||
|
||||
static inline void switch_curl_destroy()
|
||||
{
|
||||
int curl_count = switch_core_curl_count(NULL);
|
||||
|
||||
curl_count--;
|
||||
|
||||
if (curl_count == 0) {
|
||||
curl_global_cleanup();
|
||||
}
|
||||
switch_core_curl_count(&curl_count);
|
||||
}
|
||||
SWITCH_DECLARE(switch_CURL *) switch_curl_easy_init(void);
|
||||
SWITCH_DECLARE(switch_CURLcode) switch_curl_easy_perform(switch_CURL *handle);
|
||||
SWITCH_DECLARE(switch_CURLcode) switch_curl_easy_getinfo(switch_CURL *curl, switch_CURLINFO info, ... );
|
||||
SWITCH_DECLARE(void) switch_curl_easy_cleanup(switch_CURL *handle);
|
||||
SWITCH_DECLARE(switch_curl_slist_t *) switch_curl_slist_append(switch_curl_slist_t * list, const char * string );
|
||||
SWITCH_DECLARE(void) switch_curl_slist_free_all(switch_curl_slist_t * list);
|
||||
SWITCH_DECLARE(switch_CURLcode) switch_curl_easy_setopt(CURL *handle, switch_CURLoption option, ...);
|
||||
SWITCH_DECLARE(const char *) switch_curl_easy_strerror(switch_CURLcode errornum );
|
||||
SWITCH_DECLARE(void) switch_curl_init(void);
|
||||
SWITCH_DECLARE(void) switch_curl_destroy(void);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
WANT_CURL=yes
|
||||
BASE=../../../..
|
||||
include $(BASE)/build/modmake.rules
|
||||
|
||||
|
@ -360,7 +360,7 @@ static size_t file_callback(void *ptr, size_t size, size_t nmemb, void *data)
|
||||
}
|
||||
|
||||
static long do_lookup_url(switch_memory_pool_t *pool, switch_event_t *event, char **response, const char *query, struct curl_httppost *post,
|
||||
struct curl_slist *headers, int timeout)
|
||||
switch_curl_slist_t *headers, int timeout)
|
||||
{
|
||||
switch_time_t start_time = switch_micro_time_now();
|
||||
switch_time_t time_diff = 0;
|
||||
@ -375,49 +375,49 @@ static long do_lookup_url(switch_memory_pool_t *pool, switch_event_t *event, cha
|
||||
SWITCH_STANDARD_STREAM(http_data.stream);
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "url: %s\n", query);
|
||||
curl_handle = curl_easy_init();
|
||||
curl_handle = switch_curl_easy_init();
|
||||
|
||||
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 0);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 0);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
|
||||
|
||||
if (!strncasecmp(query, "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 (post) {
|
||||
curl_easy_setopt(curl_handle, CURLOPT_HTTPPOST, post);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPPOST, post);
|
||||
} else {
|
||||
curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 1);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 1);
|
||||
}
|
||||
if (headers) {
|
||||
curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);
|
||||
}
|
||||
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 10);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 10);
|
||||
/*
|
||||
TIMEOUT_MS is introduced in 7.16.2, we have 7.16.0 in tree
|
||||
*/
|
||||
#ifdef CURLOPT_TIMEOUT_MS
|
||||
if (timeout > 0) {
|
||||
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT_MS, timeout);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT_MS, timeout);
|
||||
} else {
|
||||
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT_MS, globals.curl_timeout);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT_MS, globals.curl_timeout);
|
||||
}
|
||||
#else
|
||||
if (timeout > 0) {
|
||||
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, timeout);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, timeout);
|
||||
} else {
|
||||
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, globals.curl_timeout / 1000);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, globals.curl_timeout / 1000);
|
||||
}
|
||||
#endif
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, query);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, file_callback);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) &http_data);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-cidlookup/1.0");
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_URL, query);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, file_callback);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) &http_data);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-cidlookup/1.0");
|
||||
|
||||
curl_easy_perform(curl_handle);
|
||||
curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes);
|
||||
curl_easy_cleanup(curl_handle);
|
||||
switch_curl_easy_perform(curl_handle);
|
||||
switch_curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes);
|
||||
switch_curl_easy_cleanup(curl_handle);
|
||||
|
||||
if (http_data.stream.data && !zstr((char *) http_data.stream.data) && strcmp(" ", http_data.stream.data)) {
|
||||
|
||||
@ -839,8 +839,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_cidlookup_load)
|
||||
return SWITCH_STATUS_TERM;
|
||||
}
|
||||
|
||||
switch_curl_init();
|
||||
|
||||
SWITCH_ADD_API(api_interface, "cidlookup", "cidlookup API", cidlookup_function, SYNTAX);
|
||||
SWITCH_ADD_APP(app_interface, "cidlookup", "Perform a CID lookup", "Perform a CID lookup",
|
||||
cidlookup_app_function, "[number [skipurl]]", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
|
||||
@ -854,7 +852,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_cidlookup_load)
|
||||
Macro expands to: switch_status_t mod_cidlookup_shutdown() */
|
||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cidlookup_shutdown)
|
||||
{
|
||||
switch_curl_destroy();
|
||||
switch_event_unbind(&reload_xml_event);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
json-c=json-c-0.9
|
||||
BASE=../../../..
|
||||
WANT_CURL=yes
|
||||
|
||||
JSON_DIR=$(switch_srcdir)/libs/$(json-c)
|
||||
JSON_BUILDDIR=$(switch_builddir)/libs/$(json-c)
|
||||
|
@ -57,7 +57,7 @@ struct http_data_obj {
|
||||
int err;
|
||||
long http_response_code;
|
||||
char *http_response;
|
||||
struct curl_slist *headers;
|
||||
switch_curl_slist_t *headers;
|
||||
};
|
||||
typedef struct http_data_obj http_data_t;
|
||||
|
||||
@ -94,7 +94,7 @@ static size_t header_callback(void *ptr, size_t size, size_t nmemb, void *data)
|
||||
switch_copy_string(header, ptr, realsize);
|
||||
header[realsize] = '\0';
|
||||
|
||||
http_data->headers = curl_slist_append(http_data->headers, header);
|
||||
http_data->headers = switch_curl_slist_append(http_data->headers, header);
|
||||
|
||||
return realsize;
|
||||
}
|
||||
@ -102,7 +102,7 @@ static size_t header_callback(void *ptr, size_t size, size_t nmemb, void *data)
|
||||
static http_data_t *do_lookup_url(switch_memory_pool_t *pool, const char *url, const char *method, const char *data)
|
||||
{
|
||||
|
||||
CURL *curl_handle = NULL;
|
||||
switch_CURL *curl_handle = NULL;
|
||||
long httpRes = 0;
|
||||
|
||||
http_data_t *http_data = NULL;
|
||||
@ -165,7 +165,7 @@ static char *print_json(switch_memory_pool_t *pool, http_data_t *http_data)
|
||||
struct json_object *top = NULL;
|
||||
struct json_object *headers = NULL;
|
||||
char *data = NULL;
|
||||
struct curl_slist *header = http_data->headers;
|
||||
switch_curl_slist_t *header = http_data->headers;
|
||||
|
||||
top = json_object_new_object();
|
||||
headers = json_object_new_array();
|
||||
@ -240,7 +240,7 @@ SWITCH_STANDARD_APP(curl_app_function)
|
||||
switch_bool_t do_headers = SWITCH_FALSE;
|
||||
switch_bool_t do_json = SWITCH_FALSE;
|
||||
http_data_t *http_data = NULL;
|
||||
struct curl_slist *slist = NULL;
|
||||
switch_curl_slist_t *slist = NULL;
|
||||
switch_stream_handle_t stream = { 0 };
|
||||
int i = 0;
|
||||
|
||||
@ -308,7 +308,7 @@ SWITCH_STANDARD_APP(curl_app_function)
|
||||
done:
|
||||
switch_safe_free(stream.data);
|
||||
if (http_data && http_data->headers) {
|
||||
curl_slist_free_all(http_data->headers);
|
||||
switch_curl_slist_free_all(http_data->headers);
|
||||
}
|
||||
if (!session && pool) {
|
||||
switch_core_destroy_memory_pool(&pool);
|
||||
@ -326,7 +326,7 @@ SWITCH_STANDARD_API(curl_function)
|
||||
char *postdata = NULL;
|
||||
switch_bool_t do_headers = SWITCH_FALSE;
|
||||
switch_bool_t do_json = SWITCH_FALSE;
|
||||
struct curl_slist *slist = NULL;
|
||||
switch_curl_slist_t *slist = NULL;
|
||||
http_data_t *http_data = NULL;
|
||||
int i = 0;
|
||||
|
||||
@ -391,7 +391,7 @@ SWITCH_STANDARD_API(curl_function)
|
||||
|
||||
done:
|
||||
if (http_data && http_data->headers) {
|
||||
curl_slist_free_all(http_data->headers);
|
||||
switch_curl_slist_free_all(http_data->headers);
|
||||
}
|
||||
switch_safe_free(mydata);
|
||||
if (!session && pool) {
|
||||
@ -412,8 +412,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_curl_load)
|
||||
|
||||
globals.pool = pool;
|
||||
|
||||
switch_curl_init();
|
||||
|
||||
SWITCH_ADD_API(api_interface, "curl", "curl API", curl_function, SYNTAX);
|
||||
SWITCH_ADD_APP(app_interface, "curl", "Perform a http request", "Perform a http request",
|
||||
curl_app_function, SYNTAX, SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
|
||||
@ -428,7 +426,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_curl_load)
|
||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_curl_shutdown)
|
||||
{
|
||||
/* Cleanup dynamically allocated config settings */
|
||||
switch_curl_destroy();
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
BASE=../../../..
|
||||
WANT_CURL=yes
|
||||
|
||||
include $(BASE)/build/modmake.rules
|
||||
|
||||
|
@ -197,24 +197,24 @@ static switch_status_t http_put(switch_core_session_t *session, const char *url,
|
||||
goto done;
|
||||
}
|
||||
|
||||
curl_handle = curl_easy_init();
|
||||
curl_handle = switch_curl_easy_init();
|
||||
if (!curl_handle) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "curl_easy_init() failure\n");
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "switch_curl_easy_init() failure\n");
|
||||
status = SWITCH_STATUS_FALSE;
|
||||
goto done;
|
||||
}
|
||||
curl_easy_setopt(curl_handle, CURLOPT_UPLOAD, 1);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_PUT, 1);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, url);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_READDATA, file_to_put);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 10);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-http-cache/1.0");
|
||||
curl_easy_perform(curl_handle);
|
||||
curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes);
|
||||
curl_easy_cleanup(curl_handle);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_UPLOAD, 1);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_PUT, 1);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_URL, url);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_READDATA, file_to_put);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 10);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-http-cache/1.0");
|
||||
switch_curl_easy_perform(curl_handle);
|
||||
switch_curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes);
|
||||
switch_curl_easy_cleanup(curl_handle);
|
||||
|
||||
if (httpRes == 200 || httpRes == 201 || httpRes == 204) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s saved to %s\n", filename, url);
|
||||
@ -704,7 +704,7 @@ static void cached_url_destroy(cached_url_t *url, switch_memory_pool_t *pool)
|
||||
static switch_status_t http_get(cached_url_t *url, switch_core_session_t *session)
|
||||
{
|
||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
CURL *curl_handle = NULL;
|
||||
switch_CURL *curl_handle = NULL;
|
||||
http_get_data_t get_data = {0};
|
||||
long httpRes = 0;
|
||||
int start_time_ms = switch_time_now() / 1000;
|
||||
@ -713,20 +713,20 @@ static switch_status_t http_get(cached_url_t *url, switch_core_session_t *sessio
|
||||
get_data.fd = 0;
|
||||
get_data.url = url;
|
||||
|
||||
curl_handle = curl_easy_init();
|
||||
curl_handle = switch_curl_easy_init();
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "opening %s for URL cache\n", get_data.url->filename);
|
||||
if ((get_data.fd = open(get_data.url->filename, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
|
||||
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 10);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, get_data.url->url);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, get_file_callback);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) &get_data);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_HEADERFUNCTION, get_header_callback);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, (void *) url);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-http-cache/1.0");
|
||||
curl_easy_perform(curl_handle);
|
||||
curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes);
|
||||
curl_easy_cleanup(curl_handle);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 10);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_URL, get_data.url->url);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, get_file_callback);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) &get_data);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_HEADERFUNCTION, get_header_callback);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, (void *) url);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-http-cache/1.0");
|
||||
switch_curl_easy_perform(curl_handle);
|
||||
switch_curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes);
|
||||
switch_curl_easy_cleanup(curl_handle);
|
||||
close(get_data.fd);
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "open() error: %s\n", strerror(errno));
|
||||
@ -1011,9 +1011,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_http_cache_load)
|
||||
|
||||
setup_dir(&gcache);
|
||||
|
||||
/* init CURL */
|
||||
switch_curl_init();
|
||||
|
||||
/* indicate that the module should continue to be loaded */
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
@ -1023,7 +1020,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_http_cache_load)
|
||||
*/
|
||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_http_cache_shutdown)
|
||||
{
|
||||
switch_curl_destroy();
|
||||
url_cache_clear(&gcache, NULL);
|
||||
switch_core_hash_destroy(&gcache.map);
|
||||
switch_mutex_destroy(gcache.mutex);
|
||||
|
@ -1,8 +1,6 @@
|
||||
MEMCACHED=libmemcached-0.32
|
||||
BASE=../../../..
|
||||
|
||||
WANT_CURL=yes
|
||||
|
||||
MEMCACHED_DIR=$(switch_srcdir)/libs/$(MEMCACHED)
|
||||
MEMCACHED_BUILDDIR=$(switch_builddir)/libs/$(MEMCACHED)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
json-c=json-c-0.9
|
||||
BASE=../../../..
|
||||
WANT_CURL=yes
|
||||
|
||||
|
||||
JSON_DIR=$(switch_srcdir)/libs/$(json-c)
|
||||
JSON_BUILDDIR=$(switch_builddir)/libs/$(json-c)
|
||||
|
@ -614,8 +614,8 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
|
||||
uint32_t cur_try;
|
||||
long httpRes;
|
||||
CURL *curl_handle = NULL;
|
||||
struct curl_slist *headers = NULL;
|
||||
struct curl_slist *slist = 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;
|
||||
@ -688,7 +688,7 @@ 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) {
|
||||
switch_size_t need_bytes = strlen(json_text) * 3;
|
||||
@ -697,10 +697,10 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
|
||||
switch_assert(json_text_escaped);
|
||||
memset(json_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(json_text, json_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 *) json_text, need_bytes / 3, (unsigned char *) json_text_escaped, need_bytes);
|
||||
}
|
||||
|
||||
@ -712,55 +712,55 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
|
||||
}
|
||||
|
||||
} else {
|
||||
headers = curl_slist_append(headers, "Content-Type: application/json");
|
||||
headers = switch_curl_slist_append(headers, "Content-Type: application/json");
|
||||
curl_json_text = (char *)json_text;
|
||||
}
|
||||
|
||||
|
||||
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_json_text);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-json/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_json_text);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-json/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);
|
||||
}
|
||||
|
||||
/* these were used for testing, optionally they may be enabled if someone desires
|
||||
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 120); // tcp timeout
|
||||
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1); // 302 recursion level
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 120); // tcp timeout
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1); // 302 recursion level
|
||||
*/
|
||||
|
||||
for (cur_try = 0; cur_try < globals.retries; cur_try++) {
|
||||
@ -769,23 +769,23 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
|
||||
}
|
||||
|
||||
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);
|
||||
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) {
|
||||
goto success;
|
||||
@ -800,9 +800,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;
|
||||
@ -848,13 +848,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_json_text != json_text) {
|
||||
switch_safe_free(curl_json_text);
|
||||
@ -1041,7 +1041,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_json_cdr_load)
|
||||
|
||||
globals.retries++;
|
||||
|
||||
switch_curl_init();
|
||||
set_json_cdr_log_dirs();
|
||||
|
||||
switch_xml_free(xml);
|
||||
@ -1054,7 +1053,6 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_json_cdr_shutdown)
|
||||
|
||||
globals.shutdown = 1;
|
||||
|
||||
switch_curl_destroy();
|
||||
switch_safe_free(globals.log_dir);
|
||||
|
||||
for (;err_dir_index < globals.err_dir_count; err_dir_index++) {
|
||||
|
@ -3,8 +3,6 @@ SHOUT=libshout-2.2.2
|
||||
MPG123=mpg123-1.13.2
|
||||
BASE=../../../..
|
||||
|
||||
WANT_CURL=yes
|
||||
|
||||
LAME_DIR=$(switch_srcdir)/libs/$(LAME)
|
||||
SHOUT_DIR=$(switch_srcdir)/libs/$(SHOUT)
|
||||
MPG123_DIR=$(switch_srcdir)/libs/$(MPG123)
|
||||
|
@ -445,30 +445,30 @@ static size_t stream_callback(void *ptr, size_t size, size_t nmemb, void *data)
|
||||
#define MY_BLOCK_SIZE MY_BUF_LEN
|
||||
static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void *obj)
|
||||
{
|
||||
CURL *curl_handle = NULL;
|
||||
CURLcode cc;
|
||||
switch_CURL *curl_handle = NULL;
|
||||
switch_CURLcode cc;
|
||||
shout_context_t *context = (shout_context_t *) obj;
|
||||
|
||||
switch_thread_rwlock_rdlock(context->rwlock);
|
||||
|
||||
curl_handle = curl_easy_init();
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, context->stream_url);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 10);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, stream_callback);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) context);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "FreeSWITCH(mod_shout)/1.0");
|
||||
curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 30); /* eventually timeout connect */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_LOW_SPEED_LIMIT, 100); /* handle trickle connections */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_LOW_SPEED_TIME, 30);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_ERRORBUFFER, context->curl_error_buff);
|
||||
cc = curl_easy_perform(curl_handle);
|
||||
curl_handle = switch_curl_easy_init();
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_URL, context->stream_url);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 10);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, stream_callback);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) context);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "FreeSWITCH(mod_shout)/1.0");
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 30); /* eventually timeout connect */
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_LOW_SPEED_LIMIT, 100); /* handle trickle connections */
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_LOW_SPEED_TIME, 30);
|
||||
switch_curl_easy_setopt(curl_handle, CURLOPT_ERRORBUFFER, context->curl_error_buff);
|
||||
cc = switch_curl_easy_perform(curl_handle);
|
||||
if (cc && cc != CURLE_WRITE_ERROR) { /* write error is ok, we just exited from callback early */
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "CURL returned error:[%d] %s : %s [%s]\n", cc, curl_easy_strerror(cc),
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "CURL returned error:[%d] %s : %s [%s]\n", cc, switch_curl_easy_strerror(cc),
|
||||
context->curl_error_buff, context->stream_url);
|
||||
}
|
||||
curl_easy_cleanup(curl_handle);
|
||||
switch_curl_easy_cleanup(curl_handle);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Read Thread Done\n");
|
||||
|
||||
context->eof++;
|
||||
@ -1550,8 +1550,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_shout_load)
|
||||
supported_formats[0] = "shout";
|
||||
supported_formats[1] = "mp3";
|
||||
|
||||
switch_curl_init();
|
||||
|
||||
/* connect my internal structure to the blank pointer passed to me */
|
||||
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
||||
file_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_FILE_INTERFACE);
|
||||
@ -1577,7 +1575,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_shout_load)
|
||||
|
||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_shout_shutdown)
|
||||
{
|
||||
switch_curl_destroy();
|
||||
mpg123_exit();
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
@ -1,2 +1 @@
|
||||
WANT_CURL=yes
|
||||
include ../../../../build/modmake.rules
|
||||
|
@ -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,2 +1 @@
|
||||
WANT_CURL=yes
|
||||
include ../../../../build/modmake.rules
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -1377,8 +1377,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
|
||||
memset(&runtime, 0, sizeof(runtime));
|
||||
gethostname(runtime.hostname, sizeof(runtime.hostname));
|
||||
|
||||
switch_ssl_init_ssl_locks();
|
||||
|
||||
runtime.max_db_handles = 50;
|
||||
runtime.db_handle_timeout = 5000000;;
|
||||
|
||||
@ -1455,6 +1453,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
|
||||
runtime.console = stdout;
|
||||
}
|
||||
|
||||
switch_ssl_init_ssl_locks();
|
||||
switch_curl_init();
|
||||
|
||||
switch_core_set_variable("hostname", runtime.hostname);
|
||||
switch_find_local_ip(guess_ip, sizeof(guess_ip), &mask, AF_INET);
|
||||
switch_core_set_variable("local_ip_v4", guess_ip);
|
||||
|
Loading…
Reference in New Issue
Block a user