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

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

No files matched your search

@@ -1,4 +1,3 @@
WANT_CURL=yes
BASE=../../../..
include $(BASE)/build/modmake.rules
@@ -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;
}
-1
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)
+9 -10
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;
}
@@ -1,5 +1,4 @@
BASE=../../../..
WANT_CURL=yes
include $(BASE)/build/modmake.rules
@@ -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;
}
@@ -1,8 +1,6 @@
MEMCACHED=libmemcached-0.32
BASE=../../../..
WANT_CURL=yes
MEMCACHED_DIR=$(switch_srcdir)/libs/$(MEMCACHED)
MEMCACHED_BUILDDIR=$(switch_builddir)/libs/$(MEMCACHED)