aboutsummaryrefslogtreecommitdiffstats
path: root/funcs
diff options
context:
space:
mode:
authorbweschke <bweschke@f38db490-d61c-443f-a65b-d21fe96a405b>2006-09-03 19:07:58 +0000
committerbweschke <bweschke@f38db490-d61c-443f-a65b-d21fe96a405b>2006-09-03 19:07:58 +0000
commitc1f28d707c88f3e51c968350a835e740921eb043 (patch)
tree11dd3debab06741088a0ffb8ab968abc55f6d2e4 /funcs
parentac50d00d9164da286ba7ea788b8d8b6539f3a1c3 (diff)
Some changes/fixes for func_curl. curl_global_init is only supposed to be called once, and if it returns non-zero, we need to give up on further executions with that instance. Additionally, let's set absolute timeout values for the CURL connections to try and prevent possible Zap (and possibly other channel tech) channel lockouts.
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@41900 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs')
-rw-r--r--funcs/func_curl.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/funcs/func_curl.c b/funcs/func_curl.c
index fc5ad79cb..f6091d025 100644
--- a/funcs/func_curl.c
+++ b/funcs/func_curl.c
@@ -57,6 +57,7 @@ struct MemoryStruct {
size_t size;
};
+
static void *myrealloc(void *ptr, size_t size)
{
/* There might be a realloc() out there that doesn't like reallocing
@@ -85,13 +86,16 @@ static int curl_internal(struct MemoryStruct *chunk, char *url, char *post)
{
CURL *curl;
- curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (!curl) {
return -1;
}
+ curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
+ curl_easy_setopt(curl, CURLOPT_TIMEOUT, 180);
+ curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1);
+ curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 1);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)chunk);
@@ -126,7 +130,7 @@ static int acf_curl_exec(struct ast_channel *chan, char *cmd, char *info, char *
u = ast_module_user_add(chan);
AST_STANDARD_APP_ARGS(args, info);
-
+
if (!curl_internal(&chunk, args.url, args.postdata)) {
if (chunk.memory) {
chunk.memory[chunk.size] = '\0';
@@ -162,6 +166,8 @@ static int unload_module(void)
res = ast_custom_function_unregister(&acf_curl);
ast_module_user_hangup_all();
+
+ curl_global_cleanup();
return res;
}
@@ -170,6 +176,11 @@ static int load_module(void)
{
int res;
+ if (curl_global_init(CURL_GLOBAL_ALL)) {
+ ast_log(LOG_ERROR, "Unable to initialize the CURL library. Cannot load func_curl\n");
+ return AST_MODULE_LOAD_DECLINE;
+ }
+
res = ast_custom_function_register(&acf_curl);
return res;