Merge branch 'master' of ssh://git.freeswitch.org:222/freeswitch

This commit is contained in:
Di-Shi Sun 2011-11-30 15:19:34 +08:00
commit fafcc46a97
33 changed files with 385 additions and 285 deletions

View File

@ -106,6 +106,7 @@ CORE_CFLAGS += -I$(switch_srcdir)/libs/spandsp/src -I$(switch_srcdir)/libs/tiff-
CORE_LIBS = libs/apr-util/libaprutil-1.la libs/apr/libapr-1.la
CORE_LIBS += libs/sqlite/libsqlite3.la libs/pcre/libpcre.la libs/speex/libspeex/libspeexdsp.la
if ENABLE_SRTP
CORE_CFLAGS += -DENABLE_SRTP
CORE_LIBS += libs/srtp/libsrtp.la
@ -128,6 +129,10 @@ if ENABLE_TIMERFD_WRAPPER
CORE_CFLAGS += -DTIMERFD_WRAP
endif
if CURL_BUILTIN
CORE_LIBS += libs/curl/lib/libcurl.la
endif
##
## libfreeswitch
##
@ -244,6 +249,7 @@ libfreeswitch_la_SOURCES = \
src/switch_pcm.c \
src/switch_profile.c \
src/switch_json.c \
src/switch_curl.c \
libs/stfu/stfu.c \
libs/libteletone/src/libteletone_detect.c \
libs/libteletone/src/libteletone_generate.c \
@ -430,6 +436,10 @@ src/include/switch_version.h: src/include/switch_version.h.in .version $(libfree
libs/libedit/src/.libs/libedit.a:
cd libs/libedit && $(MAKE)
libs/curl/lib/libcurl.la: libs/curl
@cd libs/curl && $(MAKE)
@$(TOUCH_TARGET)
libs/apr/libapr-1.la: libs/apr libs/apr/.update
@cd libs/apr && $(MAKE)
@$(TOUCH_TARGET)

View File

@ -80,20 +80,18 @@ TOUCH_TARGET=@TOUCH_TARGET@
MAKE_OPTS = `test -n "$(VERBOSE)" || echo -s`
RECURSE_MODNAME=`pwd | sed -e 's|^.*/||'`
RECURSE_SOURCEFILE=`if test -f "$$modname.cpp" -o -f "$(MODDIR)/$$modname.cpp"; then echo "$$modname.cpp"; else echo "$$modname.c"; fi`
RECURSE_OUR_DEPS=`test -z "$(WANT_CURL)" || if test ! -z "$(LIBCURL_DEPS)"; then echo $(CURLLA); fi `
RECURSE_OUR_CFLAGS=`test -z "$(WANT_CURL)" || echo $(LIBCURL_CPPFLAGS) ; $(LOCAL_INSERT_CFLAGS) `
RECURSE_OUR_LDFLAGS=`test -z "$(WANT_CURL)" || echo $(LIBCURL) ; $(LOCAL_INSERT_LDFLAGS) `
RECURSE_OUR_CFLAGS=` $(LOCAL_INSERT_CFLAGS) `
RECURSE_OUR_LDFLAGS=` $(LOCAL_INSERT_LDFLAGS) `
RECURSE_MODDIR=`if test -z $(MODDIR); then pwd | sed -e 's|$(switch_builddir)|$(switch_srcdir)|'; else echo $(MODDIR); fi`
RECURSE_MAKE=+modname="$(RECURSE_MODNAME)" ; \
sourcefile="$(RECURSE_SOURCEFILE)" ; \
osarch=`uname -s` ; \
ourdefs="$(RECURSE_OUR_DEPS)" ; \
ourcflags="$(RECURSE_OUR_CFLAGS)" ; \
ourldflags="$(RECURSE_OUR_LDFLAGS)" ; \
insertobjs="`$(LOCAL_INSERT_OBJS)`" ; \
moddir="$(RECURSE_MODDIR)" ; \
$(MAKE) $(MAKE_OPTS) MODNAME="$$modname" SOURCEFILE="$$sourcefile" MODDIR="$$moddir" \
OUR_DEPS="$$ourdefs" OUR_CFLAGS="$$ourcflags" OUR_LDFLAGS="$$ourldflags" OUR_OBJS="$$insertobjs"
OUR_CFLAGS="$$ourcflags" OUR_LDFLAGS="$$ourldflags" OUR_OBJS="$$insertobjs"
all: Makefile
@$(RECURSE_MAKE) all-modules || exit 1
@ -136,7 +134,7 @@ LINK_OUTPUT_REDIR=> .libs/$(MODNAME).log || error="yes" ; \
exit 1 ;\
fi
$(MODNAME).$(LIBTOOL_LIB_EXTEN): $(LIBS) $(LOCAL_LIBADD) $(OUR_DEPS) $(LOCAL_OBJS) $(OUR_OBJS) $(MODDIR)/$(SOURCEFILE) $(MODNAME).lo
$(MODNAME).$(LIBTOOL_LIB_EXTEN): $(LIBS) $(LOCAL_LIBADD) $(LOCAL_OBJS) $(OUR_OBJS) $(MODDIR)/$(SOURCEFILE) $(MODNAME).lo
@echo Creating $@...
@test -d .libs || mkdir .libs
@error="";\

View File

@ -807,8 +807,15 @@ if test "$ac_cv_use_system_curl" != "yes" ; then
LIBCURL_DEPS='${switch_builddir}/libs/curl/lib/libcurl.la'
LIBCURL='${switch_builddir}/libs/curl/lib/libcurl.la'
LIBCURL_CPPFLAGS='-I${switch_srcdir}/libs/curl/include'
else
SWITCH_AM_LDFLAGS="$LIBCURL $SWITCH_AM_LDFLAGS"
fi
SWITCH_AM_CFLAGS="$LIBCURL_CPPFLAGS $SWITCH_AM_CFLAGS"
SWITCH_AM_CXXFLAGS="$LIBCURL_CPPFLAGS $SWITCH_AM_CXXFLAGS"
AM_CONDITIONAL([CURL_BUILTIN],[test "${ac_cv_use_system_curl}" != "yes"])
AC_SUBST(LIBCURL_DEPS)

View File

@ -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"

View File

@ -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

View File

@ -1,4 +1,3 @@
WANT_CURL=yes
BASE=../../../..
include $(BASE)/build/modmake.rules

View File

@ -30,7 +30,7 @@
*/
#include <switch.h>
#include <curl/curl.h>
#include <switch_curl.h>
#define SWITCH_REWIND_STREAM(s) s.end = s.data
@ -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)) {
@ -852,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_event_unbind(&reload_xml_event);
return SWITCH_STATUS_SUCCESS;
}

View File

@ -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)

View File

@ -30,7 +30,7 @@
*/
#include <switch.h>
#include <curl/curl.h>
#include <switch_curl.h>
#include <json.h>
/* Prototypes */
@ -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) {
@ -426,7 +426,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_curl_load)
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_curl_shutdown)
{
/* Cleanup dynamically allocated config settings */
return SWITCH_STATUS_SUCCESS;
}

View File

@ -1,5 +1,4 @@
BASE=../../../..
WANT_CURL=yes
include $(BASE)/build/modmake.rules

View File

@ -30,7 +30,7 @@
*
*/
#include <switch.h>
#include <curl/curl.h>
#include <switch_curl.h>
/* Defines module interface to FreeSWITCH */
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_http_cache_shutdown);
@ -197,23 +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_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);
@ -703,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;
@ -712,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));
@ -1010,9 +1011,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_http_cache_load)
setup_dir(&gcache);
/* init CURL */
curl_global_init(CURL_GLOBAL_ALL);
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}

View File

@ -1,8 +1,6 @@
MEMCACHED=libmemcached-0.32
BASE=../../../..
WANT_CURL=yes
MEMCACHED_DIR=$(switch_srcdir)/libs/$(MEMCACHED)
MEMCACHED_BUILDDIR=$(switch_builddir)/libs/$(MEMCACHED)

View File

@ -1932,24 +1932,39 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
}
case SWITCH_MESSAGE_INDICATE_INFO:
{
char *headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_INFO_HEADER_PREFIX);
char *ct = "freeswitch/data";
const char *pl = NULL;
int ok = 0;
if (!zstr(msg->string_array_arg[0]) && !zstr(msg->string_array_arg[1])) {
ct = switch_core_session_sprintf(session, "%s/%s", msg->string_array_arg[0], msg->string_array_arg[1]);
ok = 1;
}
if (!zstr(msg->string_array_arg[2])) {
pl = msg->string_array_arg[2];
if (switch_stristr("send_info", tech_pvt->x_freeswitch_support_remote)) {
ok = 1;
}
nua_info(tech_pvt->nh,
SIPTAG_CONTENT_TYPE_STR(ct),
TAG_IF(!zstr(headers), SIPTAG_HEADER_STR(headers)),
TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
TAG_IF(pl, SIPTAG_PAYLOAD_STR(pl)),
TAG_END());
if (switch_true(switch_channel_get_variable(channel, "fs_send_unspported_info"))) {
ok = 1;
}
if (ok) {
char *headers = sofia_glue_get_extra_headers(channel, SOFIA_SIP_INFO_HEADER_PREFIX);
const char *pl = NULL;
if (!zstr(msg->string_array_arg[2])) {
pl = msg->string_array_arg[2];
}
nua_info(tech_pvt->nh,
SIPTAG_CONTENT_TYPE_STR(ct),
TAG_IF(!zstr(headers), SIPTAG_HEADER_STR(headers)),
TAG_IF(!zstr(tech_pvt->user_via), SIPTAG_VIA_STR(tech_pvt->user_via)),
TAG_IF(pl, SIPTAG_PAYLOAD_STR(pl)),
TAG_END());
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s send_info is not supported.\n", switch_channel_get_name(channel));
}
}
break;
case SWITCH_MESSAGE_INDICATE_SIMPLIFY:

View File

@ -111,7 +111,7 @@ typedef struct private_object private_object_t;
#define SOFIA_SECURE_MEDIA_CONFIRMED_VARIABLE "sip_secure_media_confirmed"
#define SOFIA_HAS_CRYPTO_VARIABLE "sip_has_crypto"
#define SOFIA_CRYPTO_MANDATORY_VARIABLE "sip_crypto_mandatory"
#define FREESWITCH_SUPPORT "update_display"
#define FREESWITCH_SUPPORT "update_display,send_info"
#include <switch_stun.h>
#include <sofia-sip/nua.h>

View File

@ -475,7 +475,7 @@ void sofia_handle_sip_i_notify(switch_core_session_t *session, int status,
/* dispatch freeswitch event */
if (switch_event_create(&s_event, SWITCH_EVENT_NOTIFY_IN) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "event", sip->sip_event->o_type);
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "pl_data", sip->sip_payload->pl_data);
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "pl_data", sip->sip_payload ? sip->sip_payload->pl_data : "");
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "sip_content_type", sip->sip_content_type->c_type);
switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "port", "%d", sofia_private->gateway->profile->sip_port);
switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "module_name", "mod_sofia");
@ -6967,31 +6967,37 @@ void sofia_handle_sip_i_info(nua_t *nua, sofia_profile_t *profile, nua_handle_t
sofia_glue_set_extra_headers(session, sip, SOFIA_SIP_INFO_HEADER_PREFIX);
if (!(vval = switch_channel_get_variable(channel, "sip_copy_custom_headers")) || switch_true(vval)) {
switch_core_session_t *nsession = NULL;
switch_core_session_get_partner(session, &nsession);
if (sip && sip->sip_content_type && sip->sip_content_type->c_type && !strcasecmp(sip->sip_content_type->c_type, "freeswitch/data")) {
char *data = NULL;
if (nsession) {
switch_core_session_message_t *msg;
if (sip->sip_payload && sip->sip_payload->pl_data) {
data = sip->sip_payload->pl_data;
}
if ((vval = switch_channel_get_variable(channel, "sip_copy_custom_headers")) && switch_true(vval)) {
switch_core_session_t *nsession = NULL;
switch_ivr_transfer_variable(session, nsession, SOFIA_SIP_INFO_HEADER_PREFIX_T);
msg = switch_core_session_alloc(nsession, sizeof(*msg));
MESSAGE_STAMP_FFL(msg);
msg->message_id = SWITCH_MESSAGE_INDICATE_INFO;
switch_core_session_get_partner(session, &nsession);
if (nsession) {
switch_core_session_message_t *msg;
if (sip && sip->sip_content_type && sip->sip_content_type->c_type && sip->sip_content_type->c_subtype &&
sip->sip_payload && sip->sip_payload->pl_data) {
msg->string_array_arg[0] = switch_core_session_strdup(nsession, sip->sip_content_type->c_type);
msg->string_array_arg[1] = switch_core_session_strdup(nsession, sip->sip_content_type->c_subtype);
msg->string_array_arg[0] = switch_core_session_strdup(nsession, sip->sip_payload->pl_data);
}
msg->from = __FILE__;
switch_core_session_queue_message(nsession, msg);
switch_ivr_transfer_variable(session, nsession, SOFIA_SIP_INFO_HEADER_PREFIX_T);
msg = switch_core_session_alloc(nsession, sizeof(*msg));
MESSAGE_STAMP_FFL(msg);
msg->message_id = SWITCH_MESSAGE_INDICATE_INFO;
msg->string_array_arg[2] = switch_core_session_strdup(nsession, data);
msg->from = __FILE__;
switch_core_session_queue_message(nsession, msg);
switch_core_session_rwunlock(nsession);
switch_core_session_rwunlock(nsession);
}
}
}
}
if (sip && sip->sip_content_type && sip->sip_content_type->c_subtype && sip->sip_content_type->c_type &&
!strncasecmp(sip->sip_content_type->c_type, "message", 7) &&

View File

@ -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)

View File

@ -32,7 +32,7 @@
*/
#include <sys/stat.h>
#include <switch.h>
#include <curl/curl.h>
#include <switch_curl.h>
#include <json.h>
#define MAX_URLS 20
@ -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,54 +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_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++) {
@ -768,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;
@ -799,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;
@ -847,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);

View File

@ -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)

View File

@ -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;
}

View File

@ -1797,8 +1797,8 @@ public class freeswitch {
return ret;
}
public static SWIGTYPE_p_HashElem switch_hash_first(string depricate_me, SWIGTYPE_p_switch_hash hash) {
IntPtr cPtr = freeswitchPINVOKE.switch_hash_first(depricate_me, SWIGTYPE_p_switch_hash.getCPtr(hash));
public static SWIGTYPE_p_HashElem switch_hash_first(string deprecate_me, SWIGTYPE_p_switch_hash hash) {
IntPtr cPtr = freeswitchPINVOKE.switch_hash_first(deprecate_me, SWIGTYPE_p_switch_hash.getCPtr(hash));
SWIGTYPE_p_HashElem ret = (cPtr == IntPtr.Zero) ? null : new SWIGTYPE_p_HashElem(cPtr, false);
return ret;
}
@ -24680,6 +24680,7 @@ public enum switch_core_session_message_types_t {
SWITCH_MESSAGE_INDICATE_JITTER_BUFFER,
SWITCH_MESSAGE_INDICATE_RECOVERY_REFRESH,
SWITCH_MESSAGE_INDICATE_SIGNAL_DATA,
SWITCH_MESSAGE_INDICATE_INFO,
SWITCH_MESSAGE_INVALID
}

View File

@ -2520,6 +2520,7 @@ static JSBool js_fetchurl_hash(JSContext * cx, JSObject * obj, uintN argc, jsval
}
curl_easy_setopt(curl_handle, CURLOPT_URL, url);
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 10);
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, hash_callback);
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) &config_data);

View File

@ -183,6 +183,7 @@ static JSBool curl_run(JSContext * cx, JSObject * obj, uintN argc, jsval * argv,
method, url_p, data, switch_str_nil(cred), co->function ? "yes" : "no");
curl_easy_setopt(co->curl_handle, CURLOPT_URL, url_p);
curl_easy_setopt(co->curl_handle, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(co->curl_handle, CURLOPT_WRITEFUNCTION, file_callback);
curl_easy_setopt(co->curl_handle, CURLOPT_WRITEDATA, (void *) co);

View File

@ -1,2 +1 @@
WANT_CURL=yes
include ../../../../build/modmake.rules

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,49 +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_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++) {
@ -342,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;
@ -373,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;
@ -414,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);
@ -611,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;
}
@ -631,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;
}

View File

@ -1,2 +1 @@
WANT_CURL=yes
include ../../../../build/modmake.rules

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;
}

View File

@ -1453,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);
@ -1512,7 +1515,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc
switch_uuid_get(&uuid);
switch_uuid_format(runtime.uuid_str, &uuid);
switch_ssl_init_ssl_locks();
return SWITCH_STATUS_SUCCESS;
}

76
src/switch_curl.c Normal file
View File

@ -0,0 +1,76 @@
#include <switch.h>
#include <curl/curl.h>
CURLcode Curl_setopt(switch_CURL *curl, CURLoption option, va_list arg);
SWITCH_DECLARE(switch_CURL *) switch_curl_easy_init(void)
{
return curl_easy_init();
}
SWITCH_DECLARE(switch_CURLcode) switch_curl_easy_perform(switch_CURL *handle)
{
return curl_easy_perform((CURL *)handle);
}
SWITCH_DECLARE(switch_CURLcode) switch_curl_easy_getinfo(switch_CURL *curl, switch_CURLINFO info, ... )
{
va_list ap;
switch_CURLcode code;
va_start(ap, info);
code = curl_easy_getinfo(curl, info, va_arg(ap, void *));
va_end(ap);
return code;
}
SWITCH_DECLARE(void) switch_curl_easy_cleanup(switch_CURL *handle)
{
curl_easy_cleanup((CURL *)handle);
}
SWITCH_DECLARE(switch_curl_slist_t *) switch_curl_slist_append(switch_curl_slist_t * list, const char * string )
{
return (switch_curl_slist_t *) curl_slist_append((struct curl_slist *)list, string);
}
SWITCH_DECLARE(void) switch_curl_slist_free_all(switch_curl_slist_t * list)
{
curl_slist_free_all((struct curl_slist *) list);
}
SWITCH_DECLARE(switch_CURLcode) switch_curl_easy_setopt(CURL *handle, switch_CURLoption option, ...)
{
va_list ap;
switch_CURLcode code;
va_start(ap, option);
code = Curl_setopt(handle, option, ap);
va_end(ap);
return code;
}
SWITCH_DECLARE(const char *) switch_curl_easy_strerror(switch_CURLcode errornum )
{
return curl_easy_strerror(errornum);
}
SWITCH_DECLARE(void) switch_curl_init(void)
{
curl_global_init(CURL_GLOBAL_ALL);
}
SWITCH_DECLARE(void) switch_curl_destroy(void)
{
curl_global_cleanup();
}

View File

@ -1180,8 +1180,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_multi_threaded_bridge(switch_core_ses
const char *app, *data;
if (switch_channel_get_state(peer_channel) == CS_CONSUME_MEDIA) {
switch_channel_set_state(peer_channel, CS_RESET);
switch_channel_wait_for_state(peer_channel, caller_channel, CS_RESET);
switch_channel_set_state(peer_channel, CS_HIBERNATE);
switch_channel_wait_for_state(peer_channel, caller_channel, CS_HIBERNATE);
}
if (!switch_channel_ready(caller_channel)) {

View File

@ -3511,8 +3511,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
switch_channel_t *bchan = switch_core_session_get_channel(*bleg);
if (switch_channel_get_state(bchan) == CS_CONSUME_MEDIA) {
switch_channel_set_state(bchan, CS_RESET);
switch_channel_wait_for_state(bchan, caller_channel, CS_RESET);
switch_channel_set_state(bchan, CS_HIBERNATE);
switch_channel_wait_for_state(bchan, caller_channel, CS_HIBERNATE);
}
if (session && caller_channel) {

View File

@ -374,6 +374,7 @@ if not exist "$(OutDir)htdocs" xcopy "$(SolutionDir)htdocs\*.*" "$(OutDir)htdocs
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\..\src\switch_curl.c" />
<ClCompile Include="..\..\src\switch_dso.c" />
<ClCompile Include="..\..\src\switch_event.c" />
<ClCompile Include="..\..\src\switch_ivr.c" />
@ -788,6 +789,9 @@ if not exist "$(OutDir)htdocs" xcopy "$(SolutionDir)htdocs\*.*" "$(OutDir)htdocs
<LinkLibraryDependencies>true</LinkLibraryDependencies>
<UseLibraryDependencyInputs>false</UseLibraryDependencyInputs>
</ProjectReference>
<ProjectReference Include="..\..\libs\win32\curl\curllib.2010.vcxproj">
<Project>{87ee9da4-de1e-4448-8324-183c98dca588}</Project>
</ProjectReference>
<ProjectReference Include="..\..\libs\win32\pcre\libpcre.2010.vcxproj">
<Project>{8d04b550-d240-4a44-8a18-35da3f7038d9}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>

View File

@ -199,6 +199,9 @@
<ClCompile Include="..\..\libs\miniupnpc\upnpreplyparse.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\switch_curl.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\libs\miniupnpc\declspec.h">

View File

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets">
<Import Project="curl.props" />
</ImportGroup>
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<_PropertySheetDisplayName>Freeswitch Core Windows Libraries</_PropertySheetDisplayName>