mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-17 17:22:21 +00:00
FS-4714 --resolve patch applied
This commit is contained in:
parent
090cdaa9d3
commit
cd7d1efc2a
@ -43,7 +43,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_curl_load);
|
|||||||
*/
|
*/
|
||||||
SWITCH_MODULE_DEFINITION(mod_curl, mod_curl_load, mod_curl_shutdown, NULL);
|
SWITCH_MODULE_DEFINITION(mod_curl, mod_curl_load, mod_curl_shutdown, NULL);
|
||||||
|
|
||||||
static char *SYNTAX = "curl url [headers|json] [get|head|post [url_encoded_data]]";
|
static char *SYNTAX = "curl url [headers|json|content-type <mime-type>] [get|head|post [post_data]]";
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
switch_memory_pool_t *pool;
|
switch_memory_pool_t *pool;
|
||||||
@ -99,13 +99,12 @@ static size_t header_callback(void *ptr, size_t size, size_t nmemb, void *data)
|
|||||||
return realsize;
|
return realsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static http_data_t *do_lookup_url(switch_memory_pool_t *pool, const char *url, const char *method, const char *data)
|
static http_data_t *do_lookup_url(switch_memory_pool_t *pool, const char *url, const char *method, const char *data, const char *content_type)
|
||||||
{
|
{
|
||||||
|
|
||||||
switch_CURL *curl_handle = NULL;
|
switch_CURL *curl_handle = NULL;
|
||||||
long httpRes = 0;
|
long httpRes = 0;
|
||||||
|
|
||||||
http_data_t *http_data = NULL;
|
http_data_t *http_data = NULL;
|
||||||
|
switch_curl_slist_t *headers = NULL;
|
||||||
|
|
||||||
http_data = switch_core_alloc(pool, sizeof(http_data_t));
|
http_data = switch_core_alloc(pool, sizeof(http_data_t));
|
||||||
memset(http_data, 0, sizeof(http_data_t));
|
memset(http_data, 0, sizeof(http_data_t));
|
||||||
@ -118,35 +117,42 @@ static http_data_t *do_lookup_url(switch_memory_pool_t *pool, const char *url, c
|
|||||||
method = "get";
|
method = "get";
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "method: %s, url: %s\n", method, url);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "method: %s, url: %s, content-type: %s\n", method, url, content_type);
|
||||||
curl_handle = curl_easy_init();
|
curl_handle = switch_curl_easy_init();
|
||||||
|
|
||||||
if (!strncasecmp(url, "https", 5)) {
|
if (!strncasecmp(url, "https", 5)) {
|
||||||
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
|
switch_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_VERIFYHOST, 0);
|
||||||
}
|
}
|
||||||
if (!strcasecmp(method, "head")) {
|
if (!strcasecmp(method, "head")) {
|
||||||
curl_easy_setopt(curl_handle, CURLOPT_NOBODY, 1);
|
switch_curl_easy_setopt(curl_handle, CURLOPT_NOBODY, 1);
|
||||||
} else if (!strcasecmp(method, "post")) {
|
} else if (!strcasecmp(method, "post")) {
|
||||||
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDSIZE, strlen(data));
|
switch_curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDSIZE, strlen(data));
|
||||||
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, (void *) data);
|
switch_curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, (void *) data);
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Post data: %s\n", data);
|
if (content_type) {
|
||||||
} else {
|
char *ct = switch_mprintf("Content-Type: %s", content_type);
|
||||||
curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 1);
|
headers = switch_curl_slist_append(headers, ct);
|
||||||
|
switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers);
|
||||||
|
switch_safe_free(ct);
|
||||||
}
|
}
|
||||||
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Post data: %s\n", data);
|
||||||
curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 15);
|
} else {
|
||||||
curl_easy_setopt(curl_handle, CURLOPT_URL, url);
|
switch_curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 1);
|
||||||
curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
|
}
|
||||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, file_callback);
|
switch_curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
|
||||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) http_data);
|
switch_curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS, 15);
|
||||||
curl_easy_setopt(curl_handle, CURLOPT_HEADERFUNCTION, header_callback);
|
switch_curl_easy_setopt(curl_handle, CURLOPT_URL, url);
|
||||||
curl_easy_setopt(curl_handle, CURLOPT_HEADERDATA, (void *) http_data);
|
switch_curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
|
||||||
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-curl/1.0");
|
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_HEADERFUNCTION, header_callback);
|
||||||
|
switch_curl_easy_setopt(curl_handle, CURLOPT_HEADERDATA, (void *) http_data);
|
||||||
|
switch_curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "freeswitch-curl/1.0");
|
||||||
|
|
||||||
curl_easy_perform(curl_handle);
|
switch_curl_easy_perform(curl_handle);
|
||||||
curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes);
|
switch_curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &httpRes);
|
||||||
curl_easy_cleanup(curl_handle);
|
switch_curl_easy_cleanup(curl_handle);
|
||||||
|
switch_curl_slist_free_all(headers);
|
||||||
|
|
||||||
if (http_data->stream.data && !zstr((char *) http_data->stream.data) && strcmp(" ", http_data->stream.data)) {
|
if (http_data->stream.data && !zstr((char *) http_data->stream.data) && strcmp(" ", http_data->stream.data)) {
|
||||||
|
|
||||||
@ -237,6 +243,7 @@ SWITCH_STANDARD_APP(curl_app_function)
|
|||||||
char *url = NULL;
|
char *url = NULL;
|
||||||
char *method = NULL;
|
char *method = NULL;
|
||||||
char *postdata = NULL;
|
char *postdata = NULL;
|
||||||
|
char *content_type = NULL;
|
||||||
switch_bool_t do_headers = SWITCH_FALSE;
|
switch_bool_t do_headers = SWITCH_FALSE;
|
||||||
switch_bool_t do_json = SWITCH_FALSE;
|
switch_bool_t do_json = SWITCH_FALSE;
|
||||||
http_data_t *http_data = NULL;
|
http_data_t *http_data = NULL;
|
||||||
@ -244,7 +251,6 @@ SWITCH_STANDARD_APP(curl_app_function)
|
|||||||
switch_stream_handle_t stream = { 0 };
|
switch_stream_handle_t stream = { 0 };
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
|
|
||||||
if (session) {
|
if (session) {
|
||||||
pool = switch_core_session_get_pool(session);
|
pool = switch_core_session_get_pool(session);
|
||||||
} else {
|
} else {
|
||||||
@ -276,11 +282,15 @@ SWITCH_STANDARD_APP(curl_app_function)
|
|||||||
} else {
|
} else {
|
||||||
postdata = "";
|
postdata = "";
|
||||||
}
|
}
|
||||||
|
} else if (!strcasecmp("content-type", argv[i])) {
|
||||||
|
if (++i < argc) {
|
||||||
|
content_type = switch_core_strdup(pool, argv[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
http_data = do_lookup_url(pool, url, method, postdata);
|
http_data = do_lookup_url(pool, url, method, postdata, content_type);
|
||||||
if (do_json) {
|
if (do_json) {
|
||||||
switch_channel_set_variable(channel, "curl_response_data", print_json(pool, http_data));
|
switch_channel_set_variable(channel, "curl_response_data", print_json(pool, http_data));
|
||||||
} else {
|
} else {
|
||||||
@ -324,6 +334,7 @@ SWITCH_STANDARD_API(curl_function)
|
|||||||
char *url = NULL;
|
char *url = NULL;
|
||||||
char *method = NULL;
|
char *method = NULL;
|
||||||
char *postdata = NULL;
|
char *postdata = NULL;
|
||||||
|
char *content_type = NULL;
|
||||||
switch_bool_t do_headers = SWITCH_FALSE;
|
switch_bool_t do_headers = SWITCH_FALSE;
|
||||||
switch_bool_t do_json = SWITCH_FALSE;
|
switch_bool_t do_json = SWITCH_FALSE;
|
||||||
switch_curl_slist_t *slist = NULL;
|
switch_curl_slist_t *slist = NULL;
|
||||||
@ -361,14 +372,17 @@ SWITCH_STANDARD_API(curl_function)
|
|||||||
method = "post";
|
method = "post";
|
||||||
if (++i < argc) {
|
if (++i < argc) {
|
||||||
postdata = switch_core_strdup(pool, argv[i]);
|
postdata = switch_core_strdup(pool, argv[i]);
|
||||||
switch_url_decode(postdata);
|
|
||||||
} else {
|
} else {
|
||||||
postdata = "";
|
postdata = "";
|
||||||
}
|
}
|
||||||
|
} else if (!strcasecmp("content-type", argv[i])) {
|
||||||
|
if (++i < argc) {
|
||||||
|
content_type = switch_core_strdup(pool, argv[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
http_data = do_lookup_url(pool, url, method, postdata);
|
http_data = do_lookup_url(pool, url, method, postdata, content_type);
|
||||||
if (do_json) {
|
if (do_json) {
|
||||||
stream->write_function(stream, "%s", print_json(pool, http_data));
|
stream->write_function(stream, "%s", print_json(pool, http_data));
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user