Mon Jun 27 16:51:14 2011

Asterisk developer's documentation


func_curl.c File Reference

Curl - Load a URL. More...

#include "asterisk.h"
#include <curl/curl.h>
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/cli.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
#include "asterisk/utils.h"
#include "asterisk/threadstorage.h"

Go to the source code of this file.

Data Structures

struct  curl_settings
struct  global_curl_info

Defines

#define CURLOPT_SPECIAL_HASHCOMPAT   -500
#define CURLVERSION_ATLEAST(a, b, c)   ((LIBCURL_VERSION_MAJOR > (a)) || ((LIBCURL_VERSION_MAJOR == (a)) && (LIBCURL_VERSION_MINOR > (b))) || ((LIBCURL_VERSION_MAJOR == (a)) && (LIBCURL_VERSION_MINOR == (b)) && (LIBCURL_VERSION_PATCH >= (c))))

Enumerations

enum  optiontype {
  OT_BOOLEAN, OT_INTEGER, OT_INTEGER_MS, OT_STRING,
  OT_ENUM
}

Functions

static void __init_curl_instance (void)
static void __reg_module (void)
static void __unreg_module (void)
static int acf_curl2_exec (struct ast_channel *chan, const char *cmd, char *info, struct ast_str **buf, ssize_t len)
static int acf_curl_exec (struct ast_channel *chan, const char *cmd, char *info, char *buf, size_t len)
static int acf_curl_helper (struct ast_channel *chan, const char *cmd, char *info, char *buf, struct ast_str **input_str, ssize_t len)
static int acf_curlopt_helper (struct ast_channel *chan, const char *cmd, char *data, char *buf, struct ast_str **bufstr, ssize_t len)
static int acf_curlopt_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int acf_curlopt_read2 (struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
static int acf_curlopt_write (struct ast_channel *chan, const char *cmd, char *name, const char *value)
static void curl_instance_cleanup (void *data)
static int curl_instance_init (void *data)
static void curlds_free (void *data)
static int load_module (void)
static int parse_curlopt_key (const char *name, CURLoption *key, enum optiontype *ot)
static int unload_module (void)
static size_t WriteMemoryCallback (void *ptr, size_t size, size_t nmemb, void *data)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Load external URL" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_REALTIME_DEPEND2, }
static struct ast_custom_function acf_curl
static struct ast_custom_function acf_curlopt
static struct ast_module_infoast_module_info = &__mod_info
static struct ast_datastore_info curl_info
static struct ast_threadstorage curl_instance = { .once = PTHREAD_ONCE_INIT , .key_init = __init_curl_instance , .custom_init = curl_instance_init , }
static const char *const global_useragent = "asterisk-libcurl-agent/1.0"


Detailed Description

Curl - Load a URL.

Author:
Tilghman Lesher <curl-20050919@the-tilghman.com>
Note:
Brian Wilkins <bwilkins@cfl.rr.com> (Added POST option)
ExtRef:
Depends on the CURL library - http://curl.haxx.se/

Definition in file func_curl.c.


Define Documentation

#define CURLOPT_SPECIAL_HASHCOMPAT   -500

Definition at line 56 of file func_curl.c.

Referenced by acf_curl_helper(), and parse_curlopt_key().

#define CURLVERSION_ATLEAST ( a,
b,
 )     ((LIBCURL_VERSION_MAJOR > (a)) || ((LIBCURL_VERSION_MAJOR == (a)) && (LIBCURL_VERSION_MINOR > (b))) || ((LIBCURL_VERSION_MAJOR == (a)) && (LIBCURL_VERSION_MINOR == (b)) && (LIBCURL_VERSION_PATCH >= (c))))

Definition at line 53 of file func_curl.c.


Enumeration Type Documentation

enum optiontype

Enumerator:
OT_BOOLEAN 
OT_INTEGER 
OT_INTEGER_MS 
OT_STRING 
OT_ENUM 

Definition at line 86 of file func_curl.c.

00086                 {
00087    OT_BOOLEAN,
00088    OT_INTEGER,
00089    OT_INTEGER_MS,
00090    OT_STRING,
00091    OT_ENUM,
00092 };


Function Documentation

static void __init_curl_instance ( void   )  [static]

Definition at line 445 of file func_curl.c.

00448 {

static void __reg_module ( void   )  [static]

Definition at line 648 of file func_curl.c.

static void __unreg_module ( void   )  [static]

Definition at line 648 of file func_curl.c.

static int acf_curl2_exec ( struct ast_channel chan,
const char *  cmd,
char *  info,
struct ast_str **  buf,
ssize_t  len 
) [static]

Definition at line 573 of file func_curl.c.

References acf_curl_helper().

00574 {
00575    return acf_curl_helper(chan, cmd, info, NULL, buf, len);
00576 }

static int acf_curl_exec ( struct ast_channel chan,
const char *  cmd,
char *  info,
char *  buf,
size_t  len 
) [static]

Definition at line 568 of file func_curl.c.

References acf_curl_helper().

00569 {
00570    return acf_curl_helper(chan, cmd, info, buf, NULL, len);
00571 }

static int acf_curl_helper ( struct ast_channel chan,
const char *  cmd,
char *  info,
char *  buf,
struct ast_str **  input_str,
ssize_t  len 
) [static]

Definition at line 447 of file func_curl.c.

References args, AST_APP_ARG, ast_autoservice_start(), ast_autoservice_stop(), ast_channel_datastore_find(), ast_copy_string(), ast_debug, AST_DECLARE_APP_ARGS, ast_free, AST_LIST_HEAD, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), AST_STANDARD_APP_ARGS, ast_str_append(), ast_str_buffer(), ast_str_create(), ast_str_set(), ast_str_strlen(), ast_str_trim_blanks(), ast_strlen_zero(), ast_threadstorage_get(), ast_uri_decode(), curl_info, curl_instance, CURLOPT_SPECIAL_HASHCOMPAT, ast_datastore::data, curl_settings::key, curl_settings::list, LOG_ERROR, LOG_WARNING, name, pbx_builtin_setvar_helper(), str, strsep(), url, and curl_settings::value.

Referenced by acf_curl2_exec(), and acf_curl_exec().

00448 {
00449    struct ast_str *str = ast_str_create(16);
00450    int ret = -1;
00451    AST_DECLARE_APP_ARGS(args,
00452       AST_APP_ARG(url);
00453       AST_APP_ARG(postdata);
00454    );
00455    CURL **curl;
00456    struct curl_settings *cur;
00457    struct ast_datastore *store = NULL;
00458    int hashcompat = 0;
00459    AST_LIST_HEAD(global_curl_info, curl_settings) *list = NULL;
00460 
00461    if (buf) {
00462       *buf = '\0';
00463    }
00464 
00465    if (ast_strlen_zero(info)) {
00466       ast_log(LOG_WARNING, "CURL requires an argument (URL)\n");
00467       ast_free(str);
00468       return -1;
00469    }
00470 
00471    AST_STANDARD_APP_ARGS(args, info);
00472 
00473    if (chan) {
00474       ast_autoservice_start(chan);
00475    }
00476 
00477    if (!(curl = ast_threadstorage_get(&curl_instance, sizeof(*curl)))) {
00478       ast_log(LOG_ERROR, "Cannot allocate curl structure\n");
00479       return -1;
00480    }
00481 
00482    AST_LIST_LOCK(&global_curl_info);
00483    AST_LIST_TRAVERSE(&global_curl_info, cur, list) {
00484       if (cur->key == CURLOPT_SPECIAL_HASHCOMPAT) {
00485          hashcompat = (cur->value != NULL) ? 1 : 0;
00486       } else {
00487          curl_easy_setopt(*curl, cur->key, cur->value);
00488       }
00489    }
00490 
00491    if (chan && (store = ast_channel_datastore_find(chan, &curl_info, NULL))) {
00492       list = store->data;
00493       AST_LIST_LOCK(list);
00494       AST_LIST_TRAVERSE(list, cur, list) {
00495          if (cur->key == CURLOPT_SPECIAL_HASHCOMPAT) {
00496             hashcompat = (cur->value != NULL) ? 1 : 0;
00497          } else {
00498             curl_easy_setopt(*curl, cur->key, cur->value);
00499          }
00500       }
00501    }
00502 
00503    curl_easy_setopt(*curl, CURLOPT_URL, args.url);
00504    curl_easy_setopt(*curl, CURLOPT_FILE, (void *) &str);
00505 
00506    if (args.postdata) {
00507       curl_easy_setopt(*curl, CURLOPT_POST, 1);
00508       curl_easy_setopt(*curl, CURLOPT_POSTFIELDS, args.postdata);
00509    }
00510 
00511    curl_easy_perform(*curl);
00512 
00513    if (store) {
00514       AST_LIST_UNLOCK(list);
00515    }
00516    AST_LIST_UNLOCK(&global_curl_info);
00517 
00518    if (args.postdata) {
00519       curl_easy_setopt(*curl, CURLOPT_POST, 0);
00520    }
00521 
00522    if (ast_str_strlen(str)) {
00523       ast_str_trim_blanks(str);
00524 
00525       ast_debug(3, "str='%s'\n", ast_str_buffer(str));
00526       if (hashcompat) {
00527          char *remainder = ast_str_buffer(str);
00528          char *piece;
00529          struct ast_str *fields = ast_str_create(ast_str_strlen(str) / 2);
00530          struct ast_str *values = ast_str_create(ast_str_strlen(str) / 2);
00531          int rowcount = 0;
00532          while (fields && values && (piece = strsep(&remainder, "&"))) {
00533             char *name = strsep(&piece, "=");
00534             if (!piece) {
00535                piece = "";
00536             }
00537             ast_uri_decode(piece);
00538             ast_uri_decode(name);
00539             ast_str_append(&fields, 0, "%s%s", rowcount ? "," : "", name);
00540             ast_str_append(&values, 0, "%s%s", rowcount ? "," : "", piece);
00541             rowcount++;
00542          }
00543          pbx_builtin_setvar_helper(chan, "~ODBCFIELDS~", ast_str_buffer(fields));
00544          if (buf) {
00545             ast_copy_string(buf, ast_str_buffer(values), len);
00546          } else {
00547             ast_str_set(input_str, len, "%s", ast_str_buffer(values));
00548          }
00549          ast_free(fields);
00550          ast_free(values);
00551       } else {
00552          if (buf) {
00553             ast_copy_string(buf, ast_str_buffer(str), len);
00554          } else {
00555             ast_str_set(input_str, len, "%s", ast_str_buffer(str));
00556          }
00557       }
00558       ret = 0;
00559    }
00560    ast_free(str);
00561 
00562    if (chan)
00563       ast_autoservice_stop(chan);
00564 
00565    return ret;
00566 }

static int acf_curlopt_helper ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
struct ast_str **  bufstr,
ssize_t  len 
) [static]

Definition at line 282 of file func_curl.c.

References ast_channel_datastore_find(), ast_copy_string(), ast_debug, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_str_set(), curl_info, ast_datastore::data, curl_settings::key, curl_settings::list, LOG_ERROR, OT_BOOLEAN, OT_INTEGER, OT_INTEGER_MS, OT_STRING, parse_curlopt_key(), and curl_settings::value.

Referenced by acf_curlopt_read(), and acf_curlopt_read2().

00283 {
00284    struct ast_datastore *store;
00285    struct global_curl_info *list[2] = { &global_curl_info, NULL };
00286    struct curl_settings *cur = NULL;
00287    CURLoption key;
00288    enum optiontype ot;
00289    int i;
00290 
00291    if (parse_curlopt_key(data, &key, &ot)) {
00292       ast_log(LOG_ERROR, "Unrecognized option: '%s'\n", data);
00293       return -1;
00294    }
00295 
00296    if (chan && (store = ast_channel_datastore_find(chan, &curl_info, NULL))) {
00297       list[0] = store->data;
00298       list[1] = &global_curl_info;
00299    }
00300 
00301    for (i = 0; i < 2; i++) {
00302       if (!list[i]) {
00303          break;
00304       }
00305       AST_LIST_LOCK(list[i]);
00306       AST_LIST_TRAVERSE(list[i], cur, list) {
00307          if (cur->key == key) {
00308             if (ot == OT_BOOLEAN || ot == OT_INTEGER) {
00309                if (buf) {
00310                   snprintf(buf, len, "%ld", (long) cur->value);
00311                } else {
00312                   ast_str_set(bufstr, len, "%ld", (long) cur->value);
00313                }
00314             } else if (ot == OT_INTEGER_MS) {
00315                if ((long) cur->value % 1000 == 0) {
00316                   if (buf) {
00317                      snprintf(buf, len, "%ld", (long)cur->value / 1000);
00318                   } else {
00319                      ast_str_set(bufstr, len, "%ld", (long) cur->value / 1000);
00320                   }
00321                } else {
00322                   if (buf) {
00323                      snprintf(buf, len, "%.3f", (double) ((long) cur->value) / 1000.0);
00324                   } else {
00325                      ast_str_set(bufstr, len, "%.3f", (double) ((long) cur->value) / 1000.0);
00326                   }
00327                }
00328             } else if (ot == OT_STRING) {
00329                ast_debug(1, "Found entry %p, with key %d and value %p\n", cur, cur->key, cur->value);
00330                if (buf) {
00331                   ast_copy_string(buf, cur->value, len);
00332                } else {
00333                   ast_str_set(bufstr, 0, "%s", (char *) cur->value);
00334                }
00335             } else if (key == CURLOPT_PROXYTYPE) {
00336                if (0) {
00337 #if CURLVERSION_ATLEAST(7,15,2)
00338                } else if ((long)cur->value == CURLPROXY_SOCKS4) {
00339                   if (buf) {
00340                      ast_copy_string(buf, "socks4", len);
00341                   } else {
00342                      ast_str_set(bufstr, 0, "socks4");
00343                   }
00344 #endif
00345 #if CURLVERSION_ATLEAST(7,18,0)
00346                } else if ((long)cur->value == CURLPROXY_SOCKS4A) {
00347                   if (buf) {
00348                      ast_copy_string(buf, "socks4a", len);
00349                   } else {
00350                      ast_str_set(bufstr, 0, "socks4a");
00351                   }
00352 #endif
00353                } else if ((long)cur->value == CURLPROXY_SOCKS5) {
00354                   if (buf) {
00355                      ast_copy_string(buf, "socks5", len);
00356                   } else {
00357                      ast_str_set(bufstr, 0, "socks5");
00358                   }
00359 #if CURLVERSION_ATLEAST(7,18,0)
00360                } else if ((long)cur->value == CURLPROXY_SOCKS5_HOSTNAME) {
00361                   if (buf) {
00362                      ast_copy_string(buf, "socks5hostname", len);
00363                   } else {
00364                      ast_str_set(bufstr, 0, "socks5hostname");
00365                   }
00366 #endif
00367 #if CURLVERSION_ATLEAST(7,10,0)
00368                } else if ((long)cur->value == CURLPROXY_HTTP) {
00369                   if (buf) {
00370                      ast_copy_string(buf, "http", len);
00371                   } else {
00372                      ast_str_set(bufstr, 0, "http");
00373                   }
00374 #endif
00375                } else {
00376                   if (buf) {
00377                      ast_copy_string(buf, "unknown", len);
00378                   } else {
00379                      ast_str_set(bufstr, 0, "unknown");
00380                   }
00381                }
00382             }
00383             break;
00384          }
00385       }
00386       AST_LIST_UNLOCK(list[i]);
00387       if (cur) {
00388          break;
00389       }
00390    }
00391 
00392    return cur ? 0 : -1;
00393 }

static int acf_curlopt_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
) [static]

Definition at line 395 of file func_curl.c.

References acf_curlopt_helper().

00396 {
00397    return acf_curlopt_helper(chan, cmd, data, buf, NULL, len);
00398 }

static int acf_curlopt_read2 ( struct ast_channel chan,
const char *  cmd,
char *  data,
struct ast_str **  buf,
ssize_t  len 
) [static]

Definition at line 400 of file func_curl.c.

References acf_curlopt_helper().

00401 {
00402    return acf_curlopt_helper(chan, cmd, data, NULL, buf, len);
00403 }

static int acf_curlopt_write ( struct ast_channel chan,
const char *  cmd,
char *  name,
const char *  value 
) [static]

Definition at line 163 of file func_curl.c.

References ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_datastore_alloc, ast_datastore_free(), ast_debug, AST_LIST_HEAD_INIT, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log(), ast_true(), curl_info, ast_datastore::data, free, curl_settings::key, curl_settings::list, LOG_ERROR, OT_BOOLEAN, OT_ENUM, OT_INTEGER, OT_INTEGER_MS, OT_STRING, and parse_curlopt_key().

00164 {
00165    struct ast_datastore *store;
00166    struct global_curl_info *list;
00167    struct curl_settings *cur, *new = NULL;
00168    CURLoption key;
00169    enum optiontype ot;
00170 
00171    if (chan) {
00172       if (!(store = ast_channel_datastore_find(chan, &curl_info, NULL))) {
00173          /* Create a new datastore */
00174          if (!(store = ast_datastore_alloc(&curl_info, NULL))) {
00175             ast_log(LOG_ERROR, "Unable to allocate new datastore.  Cannot set any CURL options\n");
00176             return -1;
00177          }
00178 
00179          if (!(list = ast_calloc(1, sizeof(*list)))) {
00180             ast_log(LOG_ERROR, "Unable to allocate list head.  Cannot set any CURL options\n");
00181             ast_datastore_free(store);
00182          }
00183 
00184          store->data = list;
00185          AST_LIST_HEAD_INIT(list);
00186          ast_channel_datastore_add(chan, store);
00187       } else {
00188          list = store->data;
00189       }
00190    } else {
00191       /* Populate the global structure */
00192       list = &global_curl_info;
00193    }
00194 
00195    if (!parse_curlopt_key(name, &key, &ot)) {
00196       if (ot == OT_BOOLEAN) {
00197          if ((new = ast_calloc(1, sizeof(*new)))) {
00198             new->value = (void *)((long) ast_true(value));
00199          }
00200       } else if (ot == OT_INTEGER) {
00201          long tmp = atol(value);
00202          if ((new = ast_calloc(1, sizeof(*new)))) {
00203             new->value = (void *)tmp;
00204          }
00205       } else if (ot == OT_INTEGER_MS) {
00206          long tmp = atof(value) * 1000.0;
00207          if ((new = ast_calloc(1, sizeof(*new)))) {
00208             new->value = (void *)tmp;
00209          }
00210       } else if (ot == OT_STRING) {
00211          if ((new = ast_calloc(1, sizeof(*new) + strlen(value) + 1))) {
00212             new->value = (char *)new + sizeof(*new);
00213             strcpy(new->value, value);
00214          }
00215       } else if (ot == OT_ENUM) {
00216          if (key == CURLOPT_PROXYTYPE) {
00217             long ptype =
00218 #if CURLVERSION_ATLEAST(7,10,0)
00219                CURLPROXY_HTTP;
00220 #else
00221                CURLPROXY_SOCKS5;
00222 #endif
00223             if (0) {
00224 #if CURLVERSION_ATLEAST(7,15,2)
00225             } else if (!strcasecmp(value, "socks4")) {
00226                ptype = CURLPROXY_SOCKS4;
00227 #endif
00228 #if CURLVERSION_ATLEAST(7,18,0)
00229             } else if (!strcasecmp(value, "socks4a")) {
00230                ptype = CURLPROXY_SOCKS4A;
00231 #endif
00232 #if CURLVERSION_ATLEAST(7,18,0)
00233             } else if (!strcasecmp(value, "socks5")) {
00234                ptype = CURLPROXY_SOCKS5;
00235 #endif
00236 #if CURLVERSION_ATLEAST(7,18,0)
00237             } else if (!strncasecmp(value, "socks5", 6)) {
00238                ptype = CURLPROXY_SOCKS5_HOSTNAME;
00239 #endif
00240             }
00241 
00242             if ((new = ast_calloc(1, sizeof(*new)))) {
00243                new->value = (void *)ptype;
00244             }
00245          } else {
00246             /* Highly unlikely */
00247             goto yuck;
00248          }
00249       }
00250 
00251       /* Memory allocation error */
00252       if (!new) {
00253          return -1;
00254       }
00255 
00256       new->key = key;
00257    } else {
00258 yuck:
00259       ast_log(LOG_ERROR, "Unrecognized option: %s\n", name);
00260       return -1;
00261    }
00262 
00263    /* Remove any existing entry */
00264    AST_LIST_LOCK(list);
00265    AST_LIST_TRAVERSE_SAFE_BEGIN(list, cur, list) {
00266       if (cur->key == new->key) {
00267          AST_LIST_REMOVE_CURRENT(list);
00268          free(cur);
00269          break;
00270       }
00271    }
00272    AST_LIST_TRAVERSE_SAFE_END
00273 
00274    /* Insert new entry */
00275    ast_debug(1, "Inserting entry %p with key %d and value %p\n", new, new->key, new->value);
00276    AST_LIST_INSERT_TAIL(list, new, list);
00277    AST_LIST_UNLOCK(list);
00278 
00279    return 0;
00280 }

static void curl_instance_cleanup ( void *  data  )  [static]

Definition at line 436 of file func_curl.c.

References ast_free.

00437 {
00438    CURL **curl = data;
00439 
00440    curl_easy_cleanup(*curl);
00441 
00442    ast_free(data);
00443 }

static int curl_instance_init ( void *  data  )  [static]

Definition at line 421 of file func_curl.c.

References global_useragent, and WriteMemoryCallback().

00422 {
00423    CURL **curl = data;
00424 
00425    if (!(*curl = curl_easy_init()))
00426       return -1;
00427 
00428    curl_easy_setopt(*curl, CURLOPT_NOSIGNAL, 1);
00429    curl_easy_setopt(*curl, CURLOPT_TIMEOUT, 180);
00430    curl_easy_setopt(*curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
00431    curl_easy_setopt(*curl, CURLOPT_USERAGENT, global_useragent);
00432 
00433    return 0;
00434 }

static void curlds_free ( void *  data  )  [static]

Definition at line 73 of file func_curl.c.

References AST_LIST_HEAD, AST_LIST_HEAD_DESTROY, AST_LIST_REMOVE_HEAD, free, and curl_settings::list.

00074 {
00075    AST_LIST_HEAD(global_curl_info, curl_settings) *list = data;
00076    struct curl_settings *setting;
00077    if (!list) {
00078       return;
00079    }
00080    while ((setting = AST_LIST_REMOVE_HEAD(list, list))) {
00081       free(setting);
00082    }
00083    AST_LIST_HEAD_DESTROY(list);
00084 }

static int load_module ( void   )  [static]

Definition at line 627 of file func_curl.c.

References acf_curl, acf_curlopt, ast_custom_function_register, ast_load_resource(), ast_log(), ast_module_check(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, and LOG_ERROR.

00628 {
00629    int res;
00630 
00631    if (!ast_module_check("res_curl.so")) {
00632       if (ast_load_resource("res_curl.so") != AST_MODULE_LOAD_SUCCESS) {
00633          ast_log(LOG_ERROR, "Cannot load res_curl, so func_curl cannot be loaded\n");
00634          return AST_MODULE_LOAD_DECLINE;
00635       }
00636    }
00637 
00638    res = ast_custom_function_register(&acf_curl);
00639    res |= ast_custom_function_register(&acf_curlopt);
00640 
00641    return res;
00642 }

static int parse_curlopt_key ( const char *  name,
CURLoption *  key,
enum optiontype ot 
) [static]

Definition at line 94 of file func_curl.c.

References CURLOPT_SPECIAL_HASHCOMPAT, OT_BOOLEAN, OT_ENUM, OT_INTEGER, OT_INTEGER_MS, and OT_STRING.

Referenced by acf_curlopt_helper(), and acf_curlopt_write().

00095 {
00096    if (!strcasecmp(name, "header")) {
00097       *key = CURLOPT_HEADER;
00098       *ot = OT_BOOLEAN;
00099    } else if (!strcasecmp(name, "proxy")) {
00100       *key = CURLOPT_PROXY;
00101       *ot = OT_STRING;
00102    } else if (!strcasecmp(name, "proxyport")) {
00103       *key = CURLOPT_PROXYPORT;
00104       *ot = OT_INTEGER;
00105    } else if (!strcasecmp(name, "proxytype")) {
00106       *key = CURLOPT_PROXYTYPE;
00107       *ot = OT_ENUM;
00108    } else if (!strcasecmp(name, "dnstimeout")) {
00109       *key = CURLOPT_DNS_CACHE_TIMEOUT;
00110       *ot = OT_INTEGER;
00111    } else if (!strcasecmp(name, "userpwd")) {
00112       *key = CURLOPT_USERPWD;
00113       *ot = OT_STRING;
00114    } else if (!strcasecmp(name, "proxyuserpwd")) {
00115       *key = CURLOPT_PROXYUSERPWD;
00116       *ot = OT_STRING;
00117    } else if (!strcasecmp(name, "maxredirs")) {
00118       *key = CURLOPT_MAXREDIRS;
00119       *ot = OT_INTEGER;
00120    } else if (!strcasecmp(name, "referer")) {
00121       *key = CURLOPT_REFERER;
00122       *ot = OT_STRING;
00123    } else if (!strcasecmp(name, "useragent")) {
00124       *key = CURLOPT_USERAGENT;
00125       *ot = OT_STRING;
00126    } else if (!strcasecmp(name, "cookie")) {
00127       *key = CURLOPT_COOKIE;
00128       *ot = OT_STRING;
00129    } else if (!strcasecmp(name, "ftptimeout")) {
00130       *key = CURLOPT_FTP_RESPONSE_TIMEOUT;
00131       *ot = OT_INTEGER;
00132    } else if (!strcasecmp(name, "httptimeout")) {
00133 #if CURLVERSION_ATLEAST(7,16,2)
00134       *key = CURLOPT_TIMEOUT_MS;
00135       *ot = OT_INTEGER_MS;
00136 #else
00137       *key = CURLOPT_TIMEOUT;
00138       *ot = OT_INTEGER;
00139 #endif
00140    } else if (!strcasecmp(name, "conntimeout")) {
00141 #if CURLVERSION_ATLEAST(7,16,2)
00142       *key = CURLOPT_CONNECTTIMEOUT_MS;
00143       *ot = OT_INTEGER_MS;
00144 #else
00145       *key = CURLOPT_CONNECTTIMEOUT;
00146       *ot = OT_INTEGER;
00147 #endif
00148    } else if (!strcasecmp(name, "ftptext")) {
00149       *key = CURLOPT_TRANSFERTEXT;
00150       *ot = OT_BOOLEAN;
00151    } else if (!strcasecmp(name, "ssl_verifypeer")) {
00152       *key = CURLOPT_SSL_VERIFYPEER;
00153       *ot = OT_BOOLEAN;
00154    } else if (!strcasecmp(name, "hashcompat")) {
00155       *key = CURLOPT_SPECIAL_HASHCOMPAT;
00156       *ot = OT_BOOLEAN;
00157    } else {
00158       return -1;
00159    }
00160    return 0;
00161 }

static int unload_module ( void   )  [static]

Definition at line 617 of file func_curl.c.

References acf_curl, acf_curlopt, and ast_custom_function_unregister().

00618 {
00619    int res;
00620 
00621    res = ast_custom_function_unregister(&acf_curl);
00622    res |= ast_custom_function_unregister(&acf_curlopt);
00623 
00624    return res;
00625 }

static size_t WriteMemoryCallback ( void *  ptr,
size_t  size,
size_t  nmemb,
void *  data 
) [static]

Definition at line 405 of file func_curl.c.

References ast_debug, ast_str_append_substr(), ast_str_size(), and ast_str_strlen().

Referenced by curl_instance_init().

00406 {
00407    register int realsize = size * nmemb;
00408    struct ast_str **pstr = (struct ast_str **)data;
00409 
00410    ast_debug(3, "Called with data=%p, str=%p, realsize=%d, len=%zu, used=%zu\n", data, *pstr, realsize, ast_str_size(*pstr), ast_str_strlen(*pstr));
00411 
00412    ast_str_append_substr(pstr, 0, ptr, realsize);
00413 
00414    ast_debug(3, "Now, len=%zu, used=%zu\n", ast_str_size(*pstr), ast_str_strlen(*pstr));
00415 
00416    return realsize;
00417 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Load external URL" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_REALTIME_DEPEND2, } [static]

Definition at line 648 of file func_curl.c.

struct ast_custom_function acf_curl [static]

Definition at line 578 of file func_curl.c.

Referenced by load_module(), and unload_module().

struct ast_custom_function acf_curlopt [static]

Definition at line 589 of file func_curl.c.

Referenced by load_module(), and unload_module().

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 648 of file func_curl.c.

struct ast_datastore_info curl_info [static]

Initial value:

 {
   .type = "CURL",
   .destroy = curlds_free,
}

Definition at line 60 of file func_curl.c.

Referenced by acf_curl_helper(), acf_curlopt_helper(), and acf_curlopt_write().

struct ast_threadstorage curl_instance = { .once = PTHREAD_ONCE_INIT , .key_init = __init_curl_instance , .custom_init = curl_instance_init , } [static]

Definition at line 445 of file func_curl.c.

Referenced by acf_curl_helper().

const char* const global_useragent = "asterisk-libcurl-agent/1.0" [static]

Definition at line 419 of file func_curl.c.


Generated on Mon Jun 27 16:51:14 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7