| Asterisk - The Open Source Telephony Project GIT-master-27fb039
    | 
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"#include "asterisk/test.h"
Go to the source code of this file.
| Data Structures | |
| struct | curl_args | 
| struct | curl_settings | 
| struct | curl_write_callback_data | 
| Callback data passed to WriteMemoryCallback.  More... | |
| struct | global_curl_info | 
| Macros | |
| #define | CURLOPT_SPECIAL_FAILURE_CODE 999 | 
| #define | CURLOPT_SPECIAL_HASHCOMPAT ((CURLoption) -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 | hashcompat { HASHCOMPAT_NO = 0 , HASHCOMPAT_YES , HASHCOMPAT_LEGACY } | 
| enum | optiontype { OT_BOOLEAN , OT_INTEGER , OT_INTEGER_MS , OT_STRING , OT_ENUM } | 
| Functions | |
| static void | __reg_module (void) | 
| static void | __unreg_module (void) | 
| static int | acf_curl_exec (struct ast_channel *chan, const char *cmd, char *info, struct ast_str **buf, ssize_t len) | 
| static int | acf_curl_helper (struct ast_channel *chan, struct curl_args *args) | 
| static int | acf_curl_write (struct ast_channel *chan, const char *cmd, char *name, const char *value) | 
| 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) | 
| struct ast_module * | AST_MODULE_SELF_SYM (void) | 
| AST_THREADSTORAGE_CUSTOM_SCOPE (curl_instance, curl_instance_init, curl_instance_cleanup, static) | |
| AST_THREADSTORAGE_CUSTOM_SCOPE (thread_escapebuf, NULL, ast_free_ptr, static) | |
| 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 int | url_is_vulnerable (const char *url) | 
| Check for potential HTTP injection risk. | |
| 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 = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_REALTIME_DEPEND2, .requires = "res_curl", } | 
| static struct ast_custom_function | acf_curl | 
| static struct ast_custom_function | acf_curlopt | 
| static const struct ast_module_info * | ast_module_info = &__mod_info | 
| static const struct ast_datastore_info | curl_info | 
| struct global_curl_info | global_curl_info = AST_LIST_HEAD_INIT_VALUE | 
Curl - Load a URL.
Definition in file func_curl.c.
| #define CURLOPT_SPECIAL_FAILURE_CODE 999 | 
Definition at line 267 of file func_curl.c.
| #define CURLOPT_SPECIAL_HASHCOMPAT ((CURLoption) -500) | 
Definition at line 265 of file func_curl.c.
| #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)))) | 
Definition at line 262 of file func_curl.c.
| enum hashcompat | 
| Enumerator | |
|---|---|
| HASHCOMPAT_NO | |
| HASHCOMPAT_YES | |
| HASHCOMPAT_LEGACY | |
Definition at line 306 of file func_curl.c.
| enum optiontype | 
| Enumerator | |
|---|---|
| OT_BOOLEAN | |
| OT_INTEGER | |
| OT_INTEGER_MS | |
| OT_STRING | |
| OT_ENUM | |
Definition at line 298 of file func_curl.c.
| 
 | static | 
Definition at line 1097 of file func_curl.c.
| 
 | static | 
Definition at line 1097 of file func_curl.c.
| 
 | static | 
Definition at line 935 of file func_curl.c.
References acf_curl_helper(), args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_free, ast_log, AST_STANDARD_APP_ARGS, ast_str_buffer(), ast_str_create, ast_str_set(), ast_strlen_zero(), buf, curl_args::cb_data, len(), LOG_WARNING, curl_args::postdata, curl_write_callback_data::str, curl_args::url, and url.
| 
 | static | 
Definition at line 774 of file func_curl.c.
References args, ast_autoservice_start(), ast_autoservice_stop(), ast_channel_datastore_find(), ast_channel_lock, ast_channel_name(), ast_channel_unlock, ast_debug, ast_free, AST_LIST_HEAD, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log, ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_set(), ast_str_set_escapecommas(), ast_str_strlen(), ast_str_thread_get(), ast_str_trim_blanks(), ast_threadstorage_get(), ast_uri_decode(), ast_uri_http, ast_uri_http_legacy, AST_VECTOR_APPEND, AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_INIT, AST_VECTOR_SIZE, curl_info, CURLOPT_SPECIAL_FAILURE_CODE, CURLOPT_SPECIAL_HASHCOMPAT, ast_datastore::data, HASHCOMPAT_LEGACY, curl_settings::key, LOG_ERROR, LOG_NOTICE, LOG_WARNING, name, NULL, pbx_builtin_setvar_helper(), S_OR, strsep(), url_is_vulnerable(), and curl_settings::value.
Referenced by acf_curl_exec(), and acf_curl_write().
| 
 | static | 
Definition at line 966 of file func_curl.c.
References acf_curl_helper(), args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), curl_args::cb_data, errno, LOG_WARNING, name, curl_write_callback_data::out_file, curl_args::url, and value.
| 
 | static | 
Definition at line 566 of file func_curl.c.
References ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_debug, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log, ast_str_set(), buf, curl_info, CURLOPT_SPECIAL_HASHCOMPAT, ast_datastore::data, HASHCOMPAT_LEGACY, HASHCOMPAT_NO, HASHCOMPAT_YES, curl_settings::key, len(), curl_settings::list, LOG_ERROR, NULL, 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().
| 
 | static | 
Definition at line 681 of file func_curl.c.
References acf_curlopt_helper(), buf, len(), and NULL.
| 
 | static | 
Definition at line 686 of file func_curl.c.
References acf_curlopt_helper(), buf, len(), and NULL.
| 
 | static | 
Definition at line 417 of file func_curl.c.
References ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_channel_lock, ast_channel_unlock, ast_datastore_alloc, ast_datastore_free(), ast_debug, ast_free, 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_strdupa, ast_true(), curl_info, CURLOPT_SPECIAL_HASHCOMPAT, ast_datastore::data, HASHCOMPAT_LEGACY, HASHCOMPAT_NO, HASHCOMPAT_YES, curl_settings::key, curl_settings::list, LOG_ERROR, LOG_WARNING, name, NULL, OT_BOOLEAN, OT_ENUM, OT_INTEGER, OT_INTEGER_MS, OT_STRING, parse_curlopt_key(), strsep(), and value.
| struct ast_module * AST_MODULE_SELF_SYM | ( | void | ) | 
Definition at line 1097 of file func_curl.c.
| AST_THREADSTORAGE_CUSTOM_SCOPE | ( | curl_instance | , | 
| curl_instance_init | , | ||
| curl_instance_cleanup | , | ||
| static | |||
| ) | 
| AST_THREADSTORAGE_CUSTOM_SCOPE | ( | thread_escapebuf | , | 
| NULL | , | ||
| ast_free_ptr | , | ||
| static | |||
| ) | 
| 
 | static | 
Definition at line 731 of file func_curl.c.
References ast_free.
| 
 | static | 
Definition at line 716 of file func_curl.c.
References AST_CURL_USER_AGENT, and WriteMemoryCallback().
| 
 | static | 
Definition at line 284 of file func_curl.c.
References ast_free, AST_LIST_HEAD, AST_LIST_HEAD_DESTROY, AST_LIST_REMOVE_HEAD, and curl_settings::list.
| 
 | static | 
Definition at line 1079 of file func_curl.c.
References acf_curl, acf_curlopt, AST_CFE_WRITE, ast_custom_function_register, ast_custom_function_register_escalating, and AST_TEST_REGISTER.
| 
 | static | 
Definition at line 312 of file func_curl.c.
References CURLOPT_SPECIAL_FAILURE_CODE, CURLOPT_SPECIAL_HASHCOMPAT, curl_settings::key, name, OT_BOOLEAN, OT_ENUM, OT_INTEGER, OT_INTEGER_MS, and OT_STRING.
Referenced by acf_curlopt_helper(), and acf_curlopt_write().
| 
 | static | 
Definition at line 1067 of file func_curl.c.
References acf_curl, acf_curlopt, ast_custom_function_unregister(), and AST_TEST_UNREGISTER.
| 
 | static | 
Check for potential HTTP injection risk.
CVE-2014-8150 brought up the fact that HTTP proxies are subject to injection attacks. An HTTP URL sent to a proxy contains a carriage-return linefeed combination, followed by a complete HTTP request. Proxies will handle this as two separate HTTP requests rather than as a malformed URL.
libcURL patched this vulnerability in version 7.40.0, but we have no guarantee that Asterisk systems will be using an up-to-date cURL library. Therefore, we implement the same fix as libcURL for determining if a URL is vulnerable to an injection attack.
| url | The URL to check for vulnerability | 
| 0 | The URL is not vulnerable | 
| 1 | The URL is vulnerable. | 
Definition at line 759 of file func_curl.c.
References url.
Referenced by acf_curl_helper().
| 
 | static | 
Definition at line 701 of file func_curl.c.
References ast_str_append_substr(), curl_write_callback_data::out_file, and curl_write_callback_data::str.
Referenced by curl_instance_init().
| 
 | static | 
Definition at line 1097 of file func_curl.c.
| 
 | static | 
Definition at line 1004 of file func_curl.c.
Referenced by load_module(), and unload_module().
| 
 | static | 
Definition at line 1010 of file func_curl.c.
Referenced by load_module(), and unload_module().
| 
 | static | 
Definition at line 1097 of file func_curl.c.
| 
 | static | 
Definition at line 271 of file func_curl.c.
Referenced by acf_curl_helper(), acf_curlopt_helper(), and acf_curlopt_write().