Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
e794a6db
提交
e794a6db
authored
11月 29, 2011
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-2936 stage 2 please test ASAP
上级
74ed2cef
隐藏空白字符变更
内嵌
并排
正在显示
18 个修改的文件
包含
212 行增加
和
249 行删除
+212
-249
switch.h
src/include/switch.h
+1
-0
switch_curl.h
src/include/switch_curl.h
+17
-24
Makefile
src/mod/applications/mod_cidlookup/Makefile
+0
-1
mod_cidlookup.c
src/mod/applications/mod_cidlookup/mod_cidlookup.c
+22
-25
Makefile
src/mod/applications/mod_curl/Makefile
+0
-1
mod_curl.c
src/mod/applications/mod_curl/mod_curl.c
+8
-11
Makefile
src/mod/applications/mod_http_cache/Makefile
+0
-1
mod_http_cache.c
src/mod/applications/mod_http_cache/mod_http_cache.c
+27
-31
Makefile
src/mod/applications/mod_memcache/Makefile
+0
-2
Makefile
src/mod/event_handlers/mod_json_cdr/Makefile
+1
-1
mod_json_cdr.c
src/mod/event_handlers/mod_json_cdr/mod_json_cdr.c
+37
-39
Makefile
src/mod/formats/mod_shout/Makefile
+0
-2
mod_shout.c
src/mod/formats/mod_shout/mod_shout.c
+17
-20
Makefile
src/mod/xml_int/mod_xml_cdr/Makefile
+0
-1
mod_xml_cdr.c
src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c
+39
-45
Makefile
src/mod/xml_int/mod_xml_curl/Makefile
+0
-1
mod_xml_curl.c
src/mod/xml_int/mod_xml_curl/mod_xml_curl.c
+40
-42
switch_core.c
src/switch_core.c
+3
-2
没有找到文件。
src/include/switch.h
浏览文件 @
e794a6db
...
...
@@ -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"
...
...
src/include/switch_curl.h
浏览文件 @
e794a6db
...
...
@@ -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
...
...
src/mod/applications/mod_cidlookup/Makefile
浏览文件 @
e794a6db
WANT_CURL
=
yes
BASE
=
../../../..
include
$(BASE)/build/modmake.rules
src/mod/applications/mod_cidlookup/mod_cidlookup.c
浏览文件 @
e794a6db
...
...
@@ -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
,
s
truct
curl_slis
t
*
headers
,
int
timeout
)
s
witch_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
;
}
...
...
src/mod/applications/mod_curl/Makefile
浏览文件 @
e794a6db
json-c
=
json-c-0.9
BASE
=
../../../..
WANT_CURL
=
yes
JSON_DIR
=
$(switch_srcdir)
/libs/
$
(
json-c
)
JSON_BUILDDIR
=
$(switch_builddir)
/libs/
$
(
json-c
)
...
...
src/mod/applications/mod_curl/mod_curl.c
浏览文件 @
e794a6db
...
...
@@ -57,7 +57,7 @@ struct http_data_obj {
int
err
;
long
http_response_code
;
char
*
http_response
;
s
truct
curl_slis
t
*
headers
;
s
witch_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
;
s
truct
curl_slis
t
*
header
=
http_data
->
headers
;
s
witch_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
;
s
truct
curl_slis
t
*
slist
=
NULL
;
s
witch_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
;
s
truct
curl_slis
t
*
slist
=
NULL
;
s
witch_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
;
}
...
...
src/mod/applications/mod_http_cache/Makefile
浏览文件 @
e794a6db
BASE
=
../../../..
WANT_CURL
=
yes
include
$(BASE)/build/modmake.rules
src/mod/applications/mod_http_cache/mod_http_cache.c
浏览文件 @
e794a6db
...
...
@@ -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
);
...
...
src/mod/applications/mod_memcache/Makefile
浏览文件 @
e794a6db
MEMCACHED
=
libmemcached-0.32
BASE
=
../../../..
WANT_CURL
=
yes
MEMCACHED_DIR
=
$(switch_srcdir)
/libs/
$(MEMCACHED)
MEMCACHED_BUILDDIR
=
$(switch_builddir)
/libs/
$(MEMCACHED)
...
...
src/mod/event_handlers/mod_json_cdr/Makefile
浏览文件 @
e794a6db
json-c
=
json-c-0.9
BASE
=
../../../..
WANT_CURL
=
yes
JSON_DIR
=
$(switch_srcdir)
/libs/
$
(
json-c
)
JSON_BUILDDIR
=
$(switch_builddir)
/libs/
$
(
json-c
)
...
...
src/mod/event_handlers/mod_json_cdr/mod_json_cdr.c
浏览文件 @
e794a6db
...
...
@@ -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
;
s
truct
curl_slis
t
*
headers
=
NULL
;
s
truct
curl_slis
t
*
slist
=
NULL
;
s
witch_curl_slist_
t
*
headers
=
NULL
;
s
witch_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
++
)
{
...
...
src/mod/formats/mod_shout/Makefile
浏览文件 @
e794a6db
...
...
@@ -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)
...
...
src/mod/formats/mod_shout/mod_shout.c
浏览文件 @
e794a6db
...
...
@@ -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
;
}
...
...
src/mod/xml_int/mod_xml_cdr/Makefile
浏览文件 @
e794a6db
WANT_CURL
=
yes
include
../../../../build/modmake.rules
src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c
浏览文件 @
e794a6db
...
...
@@ -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
;
s
truct
curl_slis
t
*
headers
=
NULL
;
s
truct
curl_slis
t
*
slist
=
NULL
;
switch_
CURL
*
curl_handle
=
NULL
;
s
witch_curl_slist_
t
*
headers
=
NULL
;
s
witch_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
;
}
...
...
src/mod/xml_int/mod_xml_curl/Makefile
浏览文件 @
e794a6db
WANT_CURL
=
yes
include
../../../../build/modmake.rules
src/mod/xml_int/mod_xml_curl/mod_xml_curl.c
浏览文件 @
e794a6db
...
...
@@ -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
;
s
truct
curl_slis
t
*
slist
=
NULL
;
s
witch_curl_slist_
t
*
slist
=
NULL
;
long
httpRes
=
0
;
s
truct
curl_slis
t
*
headers
=
NULL
;
s
witch_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
;
}
...
...
src/switch_core.c
浏览文件 @
e794a6db
...
...
@@ -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
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论