Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
Utility functions. More...
#include "asterisk/network.h"
#include <time.h>
#include <unistd.h>
#include <string.h>
#include "asterisk/lock.h"
#include "asterisk/logger.h"
#include "asterisk/localtime.h"
#include "asterisk/stringfields.h"
#include "asterisk/strings.h"
Go to the source code of this file.
Data Structures | |
struct | ast_eid |
An Entity ID is essentially a MAC address, brief and unique. More... | |
struct | ast_flags |
Structure used to handle boolean flags. More... | |
struct | ast_flags64 |
Structure used to handle a large number of boolean flags == used only in app_dial? More... | |
struct | ast_hostent |
struct | ast_http_digest |
Macros | |
#define | ARRAY_IN_BOUNDS(v, a) IN_BOUNDS((int) (v), 0, ARRAY_LEN(a) - 1) |
Checks to see if value is within the bounds of the given array. More... | |
#define | ARRAY_LEN(a) (size_t) (sizeof(a) / sizeof(0[a])) |
#define | ast_align_for(offset, type) (((offset + __alignof__(type) - 1) / __alignof__(type)) * __alignof__(type)) |
Increase offset so it is a multiple of the required alignment of type. More... | |
#define | ast_alignof(type) __alignof__(type) |
Return the number of bytes used in the alignment of type. More... | |
#define | ast_assert(a) |
#define | ast_assert_return(a, ...) |
#define | AST_BACKGROUND_STACKSIZE ast_background_stacksize() |
#define | ast_clear_flag(p, flag) |
#define | ast_clear_flag64(p, flag) |
#define | ast_clear_flag_nonstd(p, flag) |
#define | ast_copy_flags(dest, src, flagz) |
#define | ast_copy_flags64(dest, src, flagz) |
#define | ast_copy_flags_nonstd(dest, src, flagz) |
#define | ast_fd_clear_flags(fd, flags) __ast_fd_set_flags((fd), (flags), AST_FD_FLAG_CLEAR, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
Clear flags on the given file descriptor. More... | |
#define | ast_fd_set_flags(fd, flags) __ast_fd_set_flags((fd), (flags), AST_FD_FLAG_SET, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
Set flags on the given file descriptor. More... | |
#define | AST_FLAGS_ALL UINT_MAX |
#define | ast_make_room_for(offset, type) (((offset + (2 * __alignof__(type) - 1)) / __alignof__(type)) * __alignof__(type)) |
Increase offset by the required alignment of type and make sure it is a multiple of said alignment. More... | |
#define | ast_pipe_nonblock(filedes) pipe2((filedes), O_NONBLOCK) |
Create a non-blocking pipe. More... | |
#define | ast_pthread_create(a, b, c, d) |
#define | ast_pthread_create_background(a, b, c, d) |
#define | ast_pthread_create_detached(a, b, c, d) |
#define | ast_pthread_create_detached_background(a, b, c, d) |
#define | ast_random_double() (((double)ast_random()) / RAND_MAX) |
Returns a random number between 0.0 and 1.0, inclusive. More... | |
#define | ast_set2_flag(p, value, flag) |
#define | ast_set2_flag64(p, value, flag) |
#define | ast_set2_flag_nonstd(p, value, flag) |
#define | ast_set_flag(p, flag) |
#define | ast_set_flag64(p, flag) |
#define | ast_set_flag_nonstd(p, flag) |
#define | ast_set_flags_to(p, flag, value) |
#define | ast_set_flags_to64(p, flag, value) |
#define | ast_socket_nonblock(domain, type, protocol) socket((domain), (type) | SOCK_NONBLOCK, (protocol)) |
Create a non-blocking socket. More... | |
#define | AST_STACKSIZE (((sizeof(void *) * 8 * 8) - 16) * 1024) |
#define | AST_STACKSIZE_LOW (((sizeof(void *) * 8 * 2) - 16) * 1024) |
#define | ast_test_flag(p, flag) |
#define | ast_test_flag64(p, flag) |
#define | ast_test_flag_nonstd(p, flag) ((p)->flags & (flag)) |
#define | AST_URI_ALPHANUM (1 << 0) |
#define | AST_URI_LEGACY_SPACE (1 << 2) |
#define | AST_URI_MARK (1 << 1) |
#define | AST_URI_SIP_USER_UNRESERVED (1 << 20) |
#define | AST_URI_UNRESERVED (AST_URI_ALPHANUM | AST_URI_MARK) |
#define | DO_CRASH_NORETURN |
#define | IN_BOUNDS(v, min, max) ((v) >= (min)) && ((v) <= (max)) |
Checks to see if value is within the given bounds. More... | |
#define | localtime_r __dont_use_localtime_r_use_ast_localtime_instead__ |
#define | MAX(a, b) ({ typeof(a) __a = (a); typeof(b) __b = (b); ((__a < __b) ? __b : __a);}) |
#define | MIN(a, b) ({ typeof(a) __a = (a); typeof(b) __b = (b); ((__a > __b) ? __b : __a);}) |
#define | RAII_VAR(vartype, varname, initval, dtor) |
Declare a variable that will call a destructor function when it goes out of scope. More... | |
#define | SWAP(a, b) do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) |
Enumerations | |
enum | ast_fd_flag_operation { AST_FD_FLAG_SET , AST_FD_FLAG_CLEAR } |
Functions | |
void DO_CRASH_NORETURN | __ast_assert_failed (int condition, const char *condition_str, const char *file, int line, const char *function) |
int | __ast_fd_set_flags (int fd, int flags, enum ast_fd_flag_operation op, const char *file, int lineno, const char *function) |
int | ast_background_stacksize (void) |
int | ast_base64_encode_file (FILE *inputfile, FILE *outputfile, const char *endl) |
Performs a base 64 encode algorithm on the contents of a File. More... | |
int | ast_base64_encode_file_path (const char *filename, FILE *outputfile, const char *endl) |
Performs a base 64 encode algorithm on the contents of a File. More... | |
int | ast_base64decode (unsigned char *dst, const char *src, int max) |
Decode data from base64. More... | |
char * | ast_base64decode_string (const char *src) |
Same as ast_base64decode, but does the math for you and returns a decoded string. More... | |
int | ast_base64encode (char *dst, const unsigned char *src, int srclen, int max) |
Encode data in base64. More... | |
int | ast_base64encode_full (char *dst, const unsigned char *src, int srclen, int max, int linebreaks) |
encode text to BASE64 coding More... | |
char * | ast_base64encode_string (const char *src) |
Same as ast_base64encode, but does hte math for you and returns an encoded string. More... | |
int | ast_base64url_decode (unsigned char *dst, const char *src, int max) |
Decode data from base64 URL. More... | |
char * | ast_base64url_decode_string (const char *src) |
Decode string from base64 URL. More... | |
int | ast_base64url_encode (char *dst, const unsigned char *src, int srclen, int max) |
Encode data in base64 URL. More... | |
int | ast_base64url_encode_full (char *dst, const unsigned char *src, int srclen, int max, int linebreaks) |
Same as ast_base64encode_full but for base64 URL. More... | |
char * | ast_base64url_encode_string (const char *src) |
Encode string in base64 URL. More... | |
int | ast_careful_fwrite (FILE *f, int fd, const char *s, size_t len, int timeoutms) |
Write data to a file stream with a timeout. More... | |
int | ast_carefulwrite (int fd, char *s, int len, int timeoutms) |
Try to write string, but wait no more than ms milliseconds before timing out. More... | |
int | ast_check_command_in_path (const char *cmd) |
Test for the presence of an executable command in $PATH. More... | |
int | ast_check_ipv6 (void) |
Test that an OS supports IPv6 Networking. More... | |
int | ast_compare_versions (const char *version1, const char *version2) |
Compare 2 major.minor.patch.extra version strings. More... | |
char * | ast_crypt (const char *key, const char *salt) |
Asterisk wrapper around crypt(3). More... | |
char * | ast_crypt_encrypt (const char *key) |
Asterisk wrapper around crypt(3) for encrypting passwords. More... | |
int | ast_crypt_validate (const char *key, const char *expected) |
Asterisk wrapper around crypt(3) for validating passwords. More... | |
void DO_CRASH_NORETURN | ast_do_crash (void) |
Force a crash if DO_CRASH is defined. More... | |
int | ast_eid_cmp (const struct ast_eid *eid1, const struct ast_eid *eid2) |
Compare two EIDs. More... | |
int | ast_eid_is_empty (const struct ast_eid *eid) |
Check if EID is empty. More... | |
char * | ast_eid_to_str (char *s, int maxlen, struct ast_eid *eid) |
Convert an EID to a string. More... | |
void | ast_enable_packet_fragmentation (int sock) |
Disable PMTU discovery on a socket. More... | |
char * | ast_escape_quoted (const char *string, char *outbuf, int buflen) |
Escape characters found in a quoted string. More... | |
char * | ast_escape_semicolons (const char *string, char *outbuf, int buflen) |
Escape semicolons found in a string. More... | |
int | ast_file_is_readable (const char *filename) |
Test that a file exists and is readable by the effective user. More... | |
int | ast_get_tid (void) |
Get current thread ID. More... | |
struct hostent * | ast_gethostbyname (const char *host, struct ast_hostent *hp) |
Thread-safe gethostbyname function to use in Asterisk. More... | |
void | ast_md5_hash (char *output, const char *input) |
Produces MD5 hash based on input string. More... | |
int | ast_mkdir (const char *path, int mode) |
Recursively create directory path. More... | |
int | ast_parse_digest (const char *digest, struct ast_http_digest *d, int request, int pedantic) |
Parse digest authorization header. More... | |
char * | ast_process_quotes_and_slashes (char *start, char find, char replace_with) |
Process a string to find and replace characters. More... | |
int | ast_pthread_create_detached_stack (pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *data, size_t stacksize, const char *file, const char *caller, int line, const char *start_fn) |
int | ast_pthread_create_stack (pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *data, size_t stacksize, const char *file, const char *caller, int line, const char *start_fn) |
long int | ast_random (void) |
void | ast_register_thread (char *name) |
void | ast_replace_subargument_delimiter (char *s) |
Replace '^' in a string with ','. More... | |
int | ast_safe_mkdir (const char *base_path, const char *path, int mode) |
Recursively create directory path, but only if it resolves within the given base_path. More... | |
void | ast_set_default_eid (struct ast_eid *eid) |
Fill in an ast_eid with the default eid of this machine. More... | |
void | ast_sha1_hash (char *output, const char *input) |
Produces SHA1 hash based on input string. More... | |
void | ast_sha1_hash_uint (uint8_t *digest, const char *input) |
Produces SHA1 hash based on input string, stored in uint8_t array. More... | |
static force_inline void | ast_slinear_saturated_add (short *input, short *value) |
static force_inline void | ast_slinear_saturated_divide (short *input, short *value) |
static force_inline void | ast_slinear_saturated_divide_float (short *input, float *value) |
static force_inline void | ast_slinear_saturated_multiply (short *input, short *value) |
static force_inline void | ast_slinear_saturated_multiply_float (short *input, float *value) |
static force_inline void | ast_slinear_saturated_subtract (short *input, short *value) |
int | ast_str_to_eid (struct ast_eid *eid, const char *s) |
Convert a string into an EID. More... | |
int | ast_thread_is_user_interface (void) |
Indicates whether the current thread is a user interface. More... | |
int | ast_thread_user_interface_set (int is_user_interface) |
Set the current thread's user interface status. More... | |
void | ast_unescape_quoted (char *quote_str) |
Unescape quotes in a string. More... | |
void | ast_unregister_thread (void *id) |
void | ast_uri_decode (char *s, struct ast_flags spec) |
Decode URI, URN, URL (overwrite string) More... | |
char * | ast_uri_encode (const char *string, char *outbuf, int buflen, struct ast_flags spec) |
Turn text string to URI-encoded XX version. More... | |
int | ast_utils_init (void) |
char * | ast_utils_which (const char *binary, char *fullpath, size_t fullpath_size) |
Resolve a binary to a full pathname. More... | |
int | ast_wait_for_input (int fd, int ms) |
int | ast_wait_for_output (int fd, int ms) |
int | ast_xml_escape (const char *string, char *outbuf, size_t buflen) |
Escape reserved characters for use in XML. More... | |
Variables | |
unsigned int | __unsigned_int_flags_dummy |
uint64_t | __unsigned_int_flags_dummy64 |
struct ast_eid | ast_eid_default |
Global EID. More... | |
const struct ast_flags | ast_uri_http |
const struct ast_flags | ast_uri_http_legacy |
const struct ast_flags | ast_uri_sip_user |
Utility functions.
Definition in file utils.h.
#define ast_align_for | ( | offset, | |
type | |||
) | (((offset + __alignof__(type) - 1) / __alignof__(type)) * __alignof__(type)) |
Increase offset so it is a multiple of the required alignment of type.
offset | The value that should be increased. |
type | The data type that offset should be aligned to. |
Many systems prefer integers to be stored on aligned on memory locations. This macro will increase an offset so a value of the supplied type can be safely be stored on such a memory location.
Examples: ast_align_for(0x17, int64_t) ==> 0x18 ast_align_for(0x18, int64_t) ==> 0x18 ast_align_for(0x19, int64_t) ==> 0x20
Don't mind the ugliness, the compiler will optimize it.
#define ast_assert_return | ( | a, | |
... | |||
) |
#define AST_BACKGROUND_STACKSIZE ast_background_stacksize() |
#define ast_clear_flag_nonstd | ( | p, | |
flag | |||
) |
#define ast_copy_flags_nonstd | ( | dest, | |
src, | |||
flagz | |||
) |
#define ast_fd_clear_flags | ( | fd, | |
flags | |||
) | __ast_fd_set_flags((fd), (flags), AST_FD_FLAG_CLEAR, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
#define ast_fd_set_flags | ( | fd, | |
flags | |||
) | __ast_fd_set_flags((fd), (flags), AST_FD_FLAG_SET, __FILE__, __LINE__, __PRETTY_FUNCTION__) |
#define ast_make_room_for | ( | offset, | |
type | |||
) | (((offset + (2 * __alignof__(type) - 1)) / __alignof__(type)) * __alignof__(type)) |
Increase offset by the required alignment of type and make sure it is a multiple of said alignment.
offset | The value that should be increased. |
type | The data type that room should be reserved for. |
A use case for this is when prepending length fields of type int to a buffer. If you keep the offset a multiple of the alignment of the integer type, a next block of length+buffer will have the length field automatically aligned.
Examples: ast_make_room_for(0x17, int64_t) ==> 0x20 ast_make_room_for(0x18, int64_t) ==> 0x20 ast_make_room_for(0x19, int64_t) ==> 0x28
Don't mind the ugliness, the compiler will optimize it.
#define ast_pipe_nonblock | ( | filedes | ) | pipe2((filedes), O_NONBLOCK) |
#define ast_random_double | ( | ) | (((double)ast_random()) / RAND_MAX) |
#define ast_set_flag_nonstd | ( | p, | |
flag | |||
) |
#define AST_STACKSIZE (((sizeof(void *) * 8 * 8) - 16) * 1024) |
#define AST_STACKSIZE_LOW (((sizeof(void *) * 8 * 2) - 16) * 1024) |
#define ast_test_flag | ( | p, | |
flag | |||
) |
#define AST_URI_UNRESERVED (AST_URI_ALPHANUM | AST_URI_MARK) |
#define localtime_r __dont_use_localtime_r_use_ast_localtime_instead__ |
#define RAII_VAR | ( | vartype, | |
varname, | |||
initval, | |||
dtor | |||
) |
Declare a variable that will call a destructor function when it goes out of scope.
Resource Allocation Is Initialization (RAII) variable declaration.
vartype | The type of the variable |
varname | The name of the variable |
initval | The initial value of the variable |
dtor | The destructor function of type' void func(vartype *)' |
Enumerator | |
---|---|
AST_FD_FLAG_SET | |
AST_FD_FLAG_CLEAR |
void DO_CRASH_NORETURN __ast_assert_failed | ( | int | condition, |
const char * | condition_str, | ||
const char * | file, | ||
int | line, | ||
const char * | function | ||
) |
Definition at line 2816 of file utils.c.
References __LOG_ERROR, ast_do_crash(), ast_log, ast_log_backtrace(), and make_ari_stubs::file.
Referenced by __ao2_container_clone(), __ao2_iterator_next(), __ao2_link(), __ao2_ref(), internal_ao2_traverse(), and log_bad_ao2().
int __ast_fd_set_flags | ( | int | fd, |
int | flags, | ||
enum ast_fd_flag_operation | op, | ||
const char * | file, | ||
int | lineno, | ||
const char * | function | ||
) |
Definition at line 3150 of file utils.c.
References __LOG_ERROR, ast_assert, AST_FD_FLAG_CLEAR, AST_FD_FLAG_SET, ast_log, errno, and make_ari_stubs::file.
int ast_background_stacksize | ( | void | ) |
Definition at line 1616 of file utils.c.
References AST_STACKSIZE, and AST_STACKSIZE_LOW.
int ast_base64_encode_file | ( | FILE * | inputfile, |
FILE * | outputfile, | ||
const char * | endl | ||
) |
Performs a base 64 encode algorithm on the contents of a File.
inputfile | A FILE handle to the input file to be encoded. Must be readable. This handle is not automatically closed. |
outputfile | A FILE handle to the output file to receive the base 64 encoded contents of the input file, identified by filename. |
endl | The line ending to use (e.g. either "\n" or "\r\n") |
Definition at line 648 of file utils.c.
References BASEMAXINLINE, c, inchar(), baseio::iocp, and ochar().
Referenced by ast_base64_encode_file_path().
int ast_base64_encode_file_path | ( | const char * | filename, |
FILE * | outputfile, | ||
const char * | endl | ||
) |
Performs a base 64 encode algorithm on the contents of a File.
filename | The path to the file to be encoded. Must be readable, file is opened in read mode. |
outputfile | A FILE handle to the output file to receive the base 64 encoded contents of the input file, identified by filename. |
endl | The line ending to use (e.g. either "\n" or "\r\n") |
Definition at line 702 of file utils.c.
References ast_base64_encode_file(), ast_log, AST_LOG_WARNING, and errno.
Referenced by add_email_attachment(), and sendmail().
int ast_base64decode | ( | unsigned char * | dst, |
const char * | src, | ||
int | max | ||
) |
Decode data from base64.
dst | the destination buffer |
src | the source buffer |
max | The maximum number of bytes to write into the destination buffer. Note that this function will not ensure that the destination buffer is NULL terminated. So, in general, this parameter should be sizeof(dst) - 1. |
Decode data from base64.
Definition at line 296 of file utils.c.
Referenced by action_messagesend(), aes_helper(), ast_base64decode_string(), ast_check_signature(), ast_http_get_auth(), AST_TEST_DEFINE(), base64_helper(), crypto_init_keys(), custom_presence_callback(), presence_write(), and res_sdp_crypto_parse_offer().
char * ast_base64decode_string | ( | const char * | src | ) |
Same as ast_base64decode, but does the math for you and returns a decoded string.
src | The source buffer |
NULL | on failure |
Same as ast_base64decode, but does the math for you and returns a decoded string.
Definition at line 323 of file utils.c.
References ast_base64decode(), ast_malloc, ast_strlen_zero(), and NULL.
int ast_base64encode | ( | char * | dst, |
const unsigned char * | src, | ||
int | srclen, | ||
int | max | ||
) |
Encode data in base64.
dst | the destination buffer |
src | the source data to be encoded |
srclen | the number of bytes present in the source buffer |
max | the maximum number of bytes to write into the destination buffer, including the terminating NULL character. |
Definition at line 406 of file utils.c.
References ast_base64encode_full(), and max.
Referenced by aes_helper(), ast_base64encode_string(), ast_sign(), AST_TEST_DEFINE(), base64_helper(), build_secret(), crypto_init_keys(), presence_read(), websocket_client_create_key(), websocket_combine_key(), and xmpp_client_authenticate_sasl().
int ast_base64encode_full | ( | char * | dst, |
const unsigned char * | src, | ||
int | srclen, | ||
int | max, | ||
int | linebreaks | ||
) |
encode text to BASE64 coding
Definition at line 355 of file utils.c.
Referenced by ast_base64encode().
char * ast_base64encode_string | ( | const char * | src | ) |
Same as ast_base64encode, but does hte math for you and returns an encoded string.
src | The source buffer |
NULL | on failure |
Same as ast_base64encode, but does hte math for you and returns an encoded string.
Definition at line 412 of file utils.c.
References ast_base64encode(), ast_calloc, ast_strlen_zero(), and NULL.
int ast_base64url_decode | ( | unsigned char * | dst, |
const char * | src, | ||
int | max | ||
) |
Decode data from base64 URL.
dst | The destination buffer |
src | The source buffer |
max | The maximum number of bytes to write into the destination buffer. Note that this function will not ensure that the destination buffer is NULL terminated. So, in general, this parameter should be sizeof(dst) - 1 |
Definition at line 429 of file utils.c.
Referenced by ast_base64url_decode_string().
char * ast_base64url_decode_string | ( | const char * | src | ) |
Decode string from base64 URL.
src | The source buffer |
NULL | on failure |
Definition at line 450 of file utils.c.
References ast_base64url_decode(), ast_malloc, ast_strlen_zero(), and NULL.
int ast_base64url_encode | ( | char * | dst, |
const unsigned char * | src, | ||
int | srclen, | ||
int | max | ||
) |
Encode data in base64 URL.
dst | The destination buffer |
src | The source data to be encoded |
srclen | The number of bytes present in the source buffer |
max | The maximum number of bytes to write into the destination buffer, including the terminating NULL character |
Definition at line 518 of file utils.c.
References ast_base64url_encode_full(), and max.
Referenced by ast_base64url_encode_string().
int ast_base64url_encode_full | ( | char * | dst, |
const unsigned char * | src, | ||
int | srclen, | ||
int | max, | ||
int | linebreaks | ||
) |
Same as ast_base64encode_full but for base64 URL.
dst | The destination buffer |
src | The source buffer |
srclen | The number of bytes present in the source buffer |
max | The maximum number of bytes to write into the destination buffer, including the terminating NULL character. |
linebreaks | Set to 1 if there should be linebreaks inserted in the result |
Definition at line 471 of file utils.c.
References base64url, and max.
Referenced by ast_base64url_encode().
char * ast_base64url_encode_string | ( | const char * | src | ) |
Encode string in base64 URL.
src | The source data to be encoded |
NULL | on failure |
Definition at line 523 of file utils.c.
References ast_base64url_encode(), ast_malloc, ast_strlen_zero(), and NULL.
int ast_careful_fwrite | ( | FILE * | f, |
int | fd, | ||
const char * | s, | ||
size_t | len, | ||
int | timeoutms | ||
) |
Write data to a file stream with a timeout.
f | the file stream to write to |
fd | the file description to poll on to know when the file stream can be written to without blocking. |
s | the buffer to write from |
len | the number of bytes to write |
timeoutms | The maximum amount of time to block in this function trying to write, specified in milliseconds. |
0 | success |
-1 | error |
int ast_carefulwrite | ( | int | fd, |
char * | s, | ||
int | len, | ||
int | timeoutms | ||
) |
Try to write string, but wait no more than ms milliseconds before timing out.
Try to write string, but wait no more than ms milliseconds before timing out.
Definition at line 1771 of file utils.c.
References ast_debug, ast_log, ast_tvdiff_ms(), ast_tvnow(), errno, len(), LOG_ERROR, and wait_for_output().
Referenced by ast_agi_send(), ast_cli(), and cleanup_module().
int ast_check_command_in_path | ( | const char * | cmd | ) |
Test for the presence of an executable command in $PATH.
cmd | Name of command to locate. |
True | (non-zero) if command is in $PATH. |
False | (zero) command not found. |
Definition at line 3263 of file utils.c.
References ast_free, ast_log, ast_strdup, len(), LOG_WARNING, NULL, and PATH_MAX.
Referenced by AST_TEST_DEFINE().
int ast_check_ipv6 | ( | void | ) |
Test that an OS supports IPv6 Networking.
True | (non-zero) if the IPv6 supported. |
False | (zero) if the OS doesn't support IPv6. |
Definition at line 2792 of file utils.c.
Referenced by load_module().
int ast_compare_versions | ( | const char * | version1, |
const char * | version2 | ||
) |
Compare 2 major.minor.patch.extra version strings.
version1 | |
version2 |
negative | if version 1 < version 2. |
0 | if version 1 = version 2. |
positive | if version 1 > version 2. |
Definition at line 3124 of file utils.c.
Referenced by transport_apply().
char * ast_crypt | ( | const char * | key, |
const char * | salt | ||
) |
Asterisk wrapper around crypt(3).
The interpretation of the salt (which determines the password hashing algorithm) is system specific. Application code should prefer to use ast_crypt_encrypt() or ast_crypt_validate().
The returned string is heap allocated, and should be freed with ast_free().
key | User's password to crypt. |
salt | Salt to crypt with. |
NULL | on error. |
Definition at line 121 of file crypt.c.
References ast_begins_with(), ast_strdup, and NULL.
Referenced by ast_crypt_encrypt().
char * ast_crypt_encrypt | ( | const char * | key | ) |
Asterisk wrapper around crypt(3) for encrypting passwords.
This function will generate a random salt and encrypt the given password.
The returned string is heap allocated, and should be freed with ast_free().
key | User's password to crypt. |
NULL | on error. |
Definition at line 190 of file crypt.c.
References ast_crypt(), gen_salt(), MAX_SALT_LEN, and NULL.
Referenced by ari_mkpasswd(), and AST_TEST_DEFINE().
int ast_crypt_validate | ( | const char * | key, |
const char * | expected | ||
) |
Asterisk wrapper around crypt(3) for validating passwords.
key | User's password to validate. |
expected | Expected result from crypt. |
True | (non-zero) if key matches expected. |
False | (zero) if key doesn't match. |
Definition at line 136 of file crypt.c.
Referenced by ast_ari_config_validate_user(), and AST_TEST_DEFINE().
void DO_CRASH_NORETURN ast_do_crash | ( | void | ) |
Force a crash if DO_CRASH is defined.
Definition at line 2804 of file utils.c.
Referenced by __ast_assert_failed().
Compare two EIDs.
0 | if the two are the same |
non-zero | otherwise |
Definition at line 3094 of file utils.c.
Referenced by AST_TEST_DEFINE(), asterisk_publisher_devstate_cb(), asterisk_publisher_mwistate_cb(), build_peer(), build_transactions(), cache_entry_by_eid(), cache_entry_create(), cache_remove(), cache_update(), clear_node_cache(), cpg_deliver_cb(), destroy_trans(), dundi_answer_entity(), dundi_answer_query(), dundi_ie_append_eid_appropriately(), dundi_lookup_internal(), dundi_prop_precache(), dundi_query_thread(), find_peer(), handle_command_response(), optimize_transactions(), publish_cluster_discovery_to_stasis(), publish_to_corosync(), register_request(), state_find_and_remove_eid(), state_find_or_add_eid(), xmpp_pubsub_devstate_cb(), xmpp_pubsub_handle_event(), and xmpp_pubsub_mwi_cb().
int ast_eid_is_empty | ( | const struct ast_eid * | eid | ) |
Check if EID is empty.
1 | if the EID is empty |
0 | otherwise |
Definition at line 3099 of file utils.c.
References ast_eid::eid, and empty_eid.
Referenced by load_module(), and set_config().
char * ast_eid_to_str | ( | char * | s, |
int | maxlen, | ||
struct ast_eid * | eid | ||
) |
Convert an EID to a string.
Definition at line 2839 of file utils.c.
References ast_eid::eid.
Referenced by app_send(), append_transaction(), ast_ari_asterisk_get_info(), ast_ari_asterisk_ping(), ast_set_default_eid(), ast_str_retrieve_variable(), AST_TEST_DEFINE(), asterisk_publication_send_refresh(), asterisk_publisher_devstate_cb(), asterisk_publisher_mwistate_cb(), bridges_scrape_cb(), build_peer(), build_transactions(), cache_lookup(), cache_lookup_internal(), channels_scrape_cb(), check_key(), complete_peer_helper(), cpg_deliver_cb(), destroy_trans(), do_autokill(), do_register(), do_register_expire(), dump_answer(), dump_eid(), dundi_answer_entity(), dundi_lookup_internal(), dundi_lookup_local(), dundi_lookup_thread(), dundi_precache_thread(), dundi_prop_precache(), dundi_query_thread(), dundi_send(), dundi_show_cache(), dundi_show_entityid(), dundi_show_hints(), dundi_show_peer(), dundi_show_peers(), dundi_show_requests(), endpoints_scrape_cb(), handle_command_response(), handle_show_settings(), populate_addr(), prometheus_config_post_apply(), publish_cluster_discovery_to_stasis_full(), publish_device_state_to_stasis(), publish_mwi_to_stasis(), publish_to_corosync(), register_request(), update_key(), xmpp_pubsub_publish_device_state(), and xmpp_pubsub_publish_mwi().
void ast_enable_packet_fragmentation | ( | int | sock | ) |
Disable PMTU discovery on a socket.
sock | The socket to manipulate |
On Linux, UDP sockets default to sending packets with the Dont Fragment (DF) bit set. This is supposedly done to allow the application to do PMTU discovery, but Asterisk does not do this.
Because of this, UDP packets sent by Asterisk that are larger than the MTU of any hop in the path will be lost. This function can be called on a socket to ensure that the DF bit will not be set.
Definition at line 2469 of file utils.c.
References ast_log, and LOG_WARNING.
Referenced by ast_netsock_bindaddr().
char * ast_escape_quoted | ( | const char * | string, |
char * | outbuf, | ||
int | buflen | ||
) |
Escape characters found in a quoted string.
string | string to be escaped |
outbuf | resulting escaped string |
buflen | size of output buffer |
Definition at line 781 of file utils.c.
Referenced by ast_callerid_merge(), ast_sip_modify_id_header(), AST_TEST_DEFINE(), channel_read_pjsip(), create_new_id_hdr(), print_escaped_uri(), and refer_send().
char * ast_escape_semicolons | ( | const char * | string, |
char * | outbuf, | ||
int | buflen | ||
) |
Escape semicolons found in a string.
string | string to be escaped |
outbuf | resulting escaped string |
buflen | size of output buffer |
Definition at line 811 of file utils.c.
References ast_assert, NULL, out, and string.
Referenced by ast_config_text_file_save2(), handle_cli_dialplan_save(), and test_semi().
int ast_file_is_readable | ( | const char * | filename | ) |
Test that a file exists and is readable by the effective user.
filename | File to test. |
True | (non-zero) if the file exists and is readable. |
False | (zero) if the file either doesn't exists or is not readable. |
Definition at line 3107 of file utils.c.
Referenced by add_email_attachment(), as_check_common_config(), ast_media_cache_retrieve(), ast_rtp_dtls_cfg_parse(), retrieve_cert_from_cache(), transport_tls_file_handler(), and vs_check_common_config().
int ast_get_tid | ( | void | ) |
Get current thread ID.
Definition at line 2752 of file utils.c.
Referenced by __ao2_ref(), ast_hangup(), ast_register_thread(), dummy_start(), format_log_message_ap(), and internal_ao2_alloc().
struct hostent * ast_gethostbyname | ( | const char * | host, |
struct ast_hostent * | hp | ||
) |
Thread-safe gethostbyname function to use in Asterisk.
ast_sockaddr_resolve()
and ast_sockaddr_resolve_first_af()
Thread-safe gethostbyname function to use in Asterisk.
Definition at line 199 of file utils.c.
References ast_hostent::buf, ast_hostent::hp, NULL, and result.
void ast_md5_hash | ( | char * | output, |
const char * | input | ||
) |
Produces MD5 hash based on input string.
Produces MD5 hash based on input string.
Definition at line 250 of file utils.c.
References input(), md5(), MD5Final(), MD5Init(), and MD5Update().
Referenced by __init_manager(), ast_sip_location_create_contact(), AST_TEST_DEFINE(), auth_exec(), auth_http_callback(), build_nonce(), md5(), and permanent_uri_handler().
int ast_mkdir | ( | const char * | path, |
int | mode | ||
) |
Recursively create directory path.
path | The directory path to create |
mode | The permissions with which to try to create the directory |
0 | on success |
Creates a directory path, creating parent directories as needed.
Definition at line 2479 of file utils.c.
References ast_alloca, ast_strdupa, errno, len(), and tmp().
Referenced by ast_file_fdtemp(), ast_logger_rotate_channel(), conf_rec_name(), conf_run(), create_destination_directory(), create_dirpath(), dictate_exec(), filename_parse(), init_logger(), load_module(), reload_logger(), remove_from_queue(), setup_privacy_args(), sms_nextoutgoing(), sms_writefile(), test_vm_api_create_voicemail_folder(), testclient_exec(), testserver_exec(), and write_history().
int ast_parse_digest | ( | const char * | digest, |
struct ast_http_digest * | d, | ||
int | request, | ||
int | pedantic | ||
) |
Parse digest authorization header.
Definition at line 2638 of file utils.c.
References ast_free, ast_log, ast_skip_blanks(), ast_str_buffer(), ast_str_create, ast_str_set(), ast_string_field_ptr_set, ast_string_field_set, ast_strlen_zero(), ast_unescape_c(), c, d, LOG_WARNING, NULL, request(), str, and strsep().
Referenced by auth_http_callback().
char * ast_process_quotes_and_slashes | ( | char * | start, |
char | find, | ||
char | replace_with | ||
) |
Process a string to find and replace characters.
start | The string to analyze |
find | The character to find |
replace_with | The character that will replace the one we are looking for |
Definition at line 2352 of file utils.c.
int ast_pthread_create_detached_stack | ( | pthread_t * | thread, |
pthread_attr_t * | attr, | ||
void *(*)(void *) | start_routine, | ||
void * | data, | ||
size_t | stacksize, | ||
const char * | file, | ||
const char * | caller, | ||
int | line, | ||
const char * | start_fn | ||
) |
Definition at line 1673 of file utils.c.
References ast_alloca, ast_log, ast_pthread_create_stack(), thr_arg::data, errno, make_ari_stubs::file, LOG_WARNING, thr_arg::start_routine, and thread.
int ast_pthread_create_stack | ( | pthread_t * | thread, |
pthread_attr_t * | attr, | ||
void *(*)(void *) | start_routine, | ||
void * | data, | ||
size_t | stacksize, | ||
const char * | file, | ||
const char * | caller, | ||
int | line, | ||
const char * | start_fn | ||
) |
Definition at line 1625 of file utils.c.
References a, ast_alloca, ast_asprintf, ast_log, ast_malloc, AST_STACKSIZE, thr_arg::data, dummy_start(), errno, make_ari_stubs::file, LOG_WARNING, test_val::name, NULL, pthread_create, thr_arg::start_routine, and thread.
Referenced by ast_pthread_create_detached_stack().
long int ast_random | ( | void | ) |
Definition at line 2312 of file utils.c.
References ast_mutex_lock, ast_mutex_unlock, dev_urandom_fd, and randomlock.
Referenced by acf_rand_exec(), action_challenge(), agi_handle_command(), app_exec(), ast_generate_random_string(), ast_lock_path_lockfile(), ast_moh_files_next(), ast_rtp_change_source(), ast_rtp_new(), AST_TEST_DEFINE(), ast_udptl_new_with_bindaddr(), astobj2_test_1_helper(), auth_http_callback(), authenticate_request(), build_iv(), build_rand_pad(), calc_metric(), calc_rxstamp(), caldav_write_event(), create_channel_name(), create_local_sdp(), dns_srv_sort(), generate_parked_user(), generate_random_string(), generic_http_callback(), get_trans_id(), get_unused_callno(), handle_cli_sched_bench(), iax2_key_rotate(), jingle_add_ice_udp_candidates_to_transport(), jingle_alloc(), jingle_new(), load_module(), make_email_file(), mbl_new(), moh_files_alloc(), multicast_rtp_new(), ogg_vorbis_rewrite(), page_exec(), process_weights(), registry_authrequest(), reschedule_reinvite(), rtp_allocate_transport(), say_periodic_announcement(), sendmail(), sip_outbound_registration_perform(), socket_read(), sorcery_memory_cache_thrash_retrieve(), sorcery_memory_cache_thrash_update(), stun_req_id(), test_ao2_find_w_no_flags(), test_ao2_find_w_OBJ_KEY(), test_ao2_find_w_OBJ_PARTIAL_KEY(), test_ao2_find_w_OBJ_POINTER(), test_files_get_one(), try_firmware(), websocket_client_create_key(), and websocket_mask_payload().
void ast_register_thread | ( | char * | name | ) |
Definition at line 414 of file asterisk.c.
References ast_assert, ast_calloc, ast_get_tid(), AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, multi_thread_safe, and name.
Referenced by dummy_start().
void ast_replace_subargument_delimiter | ( | char * | s | ) |
Replace '^' in a string with ','.
s | String within which to replace characters |
Definition at line 2343 of file utils.c.
Referenced by app_exec(), ast_bridge_set_after_go_on(), dial_exec_full(), originate_exec(), page_exec(), and queue_exec().
int ast_safe_mkdir | ( | const char * | base_path, |
const char * | path, | ||
int | mode | ||
) |
Recursively create directory path, but only if it resolves within the given base_path.
If base_path does not exist, it will not be created and this function returns EPERM
.
base_path | |
path | The directory path to create |
mode | The permissions with which to try to create the directory |
0 | on success |
Definition at line 2584 of file utils.c.
References ast_free, ast_std_free(), ast_strdup, errno, NULL, RAII_VAR, and safe_mkdir().
Referenced by AST_TEST_DEFINE(), stasis_app_control_record(), and stasis_app_stored_recording_copy().
void ast_set_default_eid | ( | struct ast_eid * | eid | ) |
Fill in an ast_eid with the default eid of this machine.
Definition at line 3001 of file utils.c.
References ast_debug, ast_eid_to_str(), ast_free, ast_log, ast_malloc, buf, if(), LOG_WARNING, and NULL.
Referenced by load_asterisk_conf().
void ast_sha1_hash | ( | char * | output, |
const char * | input | ||
) |
Produces SHA1 hash based on input string.
Produces SHA1 hash based on input string.
Definition at line 266 of file utils.c.
References input(), SHA1Input(), SHA1Reset(), and SHA1Result().
Referenced by ast_tcptls_server_start(), AST_TEST_DEFINE(), ctx_populate(), handle_call_token(), media_cache_item_sync_to_astdb(), sha1(), xmpp_client_authenticate_digest(), and xmpp_component_authenticate().
void ast_sha1_hash_uint | ( | uint8_t * | digest, |
const char * | input | ||
) |
Produces SHA1 hash based on input string, stored in uint8_t array.
Produces SHA1 hash based on input string, stored in uint8_t array.
Definition at line 284 of file utils.c.
References input(), SHA1Input(), SHA1Reset(), and SHA1Result().
Referenced by websocket_combine_key().
|
static |
Definition at line 450 of file utils.h.
References input(), and value.
Referenced by ast_frame_slinear_sum(), audio_audiohook_write_list(), audiohook_read_frame_both(), binaural_mixing(), softmix_mixing_loop(), and spy_generate().
|
static |
Definition at line 502 of file utils.h.
References input(), and value.
Referenced by ast_frame_adjust_volume(), and audiohook_read_frame_both().
|
static |
|
static |
Definition at line 476 of file utils.h.
References input(), and value.
Referenced by ast_frame_adjust_volume(), and audiohook_read_frame_both().
|
static |
|
static |
Definition at line 463 of file utils.h.
References input(), and value.
Referenced by softmix_process_write_audio(), and softmix_process_write_binaural_audio().
int ast_str_to_eid | ( | struct ast_eid * | eid, |
const char * | s | ||
) |
Convert a string into an EID.
This function expects an EID in the format: 00:11:22:33:44:55
0 | success |
non-zero | failure |
Definition at line 3077 of file utils.c.
References ast_eid::eid.
Referenced by asterisk_publication_devicestate_state_change(), asterisk_publication_mwi_state_change(), build_peer(), dundi_do_query(), load_asterisk_conf(), set_config(), and xmpp_pubsub_handle_event().
int ast_thread_is_user_interface | ( | void | ) |
Indicates whether the current thread is a user interface.
True | (non-zero) if thread is a user interface. |
False | (zero) if thread is not a user interface. |
Definition at line 3248 of file utils.c.
References ast_log, ast_threadstorage_get(), LOG_ERROR, NULL, and thread_user_interface_tl.
Referenced by ast_autoservice_start(), and ast_autoservice_stop().
int ast_thread_user_interface_set | ( | int | is_user_interface | ) |
Set the current thread's user interface status.
is_user_interface | Non-zero to mark the thread as a user interface. |
True | (non-zero) if marking current thread failed. |
False | (zero) if successfuly marked current thread. |
Definition at line 3233 of file utils.c.
References ast_log, ast_threadstorage_get(), LOG_ERROR, NULL, and thread_user_interface_tl.
Referenced by handle_tcptls_connection().
void ast_unescape_quoted | ( | char * | quote_str | ) |
Unescape quotes in a string.
quote_str | The string with quotes to be unescaped |
Definition at line 842 of file utils.c.
Referenced by ast_callerid_parse(), ast_strsep(), ast_strsep_quoted(), and AST_TEST_DEFINE().
void ast_unregister_thread | ( | void * | id | ) |
Definition at line 430 of file asterisk.c.
References ast_free, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.
Referenced by dummy_start().
void ast_uri_decode | ( | char * | s, |
struct ast_flags | spec | ||
) |
Decode URI, URN, URL (overwrite string)
s | string to be decoded |
spec | flags describing how the decoding should be performed |
Definition at line 762 of file utils.c.
References ast_test_flag, AST_URI_LEGACY_SPACE, and tmp().
Referenced by acf_curl_helper(), ast_ari_invoke(), ast_http_get_post_vars(), AST_TEST_DEFINE(), config_curl(), handle_uri(), realtime_curl(), realtime_multi_curl(), and uridecode().
char * ast_uri_encode | ( | const char * | string, |
char * | outbuf, | ||
int | buflen, | ||
struct ast_flags | spec | ||
) |
Turn text string to URI-encoded XX version.
This function encodes characters according to the rules presented in RFC 2396 and/or RFC 3261 section 19.1.2 and section 25.1.
Outbuf needs to have more memory allocated than the instring to have room for the expansion. Every byte that is converted is replaced by three ASCII characters.
string | string to be converted |
outbuf | resulting encoded string |
buflen | size of output buffer |
spec | flags describing how the encoding should be performed |
Definition at line 723 of file utils.c.
References ast_test_flag, AST_URI_ALPHANUM, AST_URI_LEGACY_SPACE, AST_URI_MARK, AST_URI_SIP_USER_UNRESERVED, out, and string.
Referenced by ast_ari_bridges_record(), ast_ari_channels_record(), AST_TEST_DEFINE(), config_curl(), destroy_curl(), launch_asyncagi(), realtime_curl(), realtime_multi_curl(), require_curl(), store_curl(), update2_curl(), update_curl(), and uriencode().
int ast_utils_init | ( | void | ) |
Definition at line 2617 of file utils.c.
References ARRAY_LEN, ast_cli_register_multiple, ast_register_cleanup(), base64_init(), dev_urandom_fd, and utils_shutdown().
Referenced by asterisk_daemon().
char * ast_utils_which | ( | const char * | binary, |
char * | fullpath, | ||
size_t | fullpath_size | ||
) |
Resolve a binary to a full pathname.
binary | Name of the executable to resolve |
fullpath | Buffer to hold the complete pathname |
fullpath_size | Size of fullpath |
NULL | binary was not found or the environment variable PATH is not set |
Definition at line 2774 of file utils.c.
References ast_strdupa, NULL, and strsep().
int ast_wait_for_input | ( | int | fd, |
int | ms | ||
) |
Definition at line 1698 of file utils.c.
References ast_poll.
Referenced by action_waitevent(), ast_ari_websocket_session_read(), ast_iostream_wait_for_input(), ast_iostream_write(), ast_tcptls_server_root(), dahdi_test_timer(), get_input(), iostream_read(), moh_class_destructor(), and unbound_resolver_thread().
int ast_wait_for_output | ( | int | fd, |
int | ms | ||
) |
Definition at line 1708 of file utils.c.
References ast_poll.
Referenced by ast_iostream_write(), iostream_read(), and socket_connect().
int ast_xml_escape | ( | const char * | string, |
char * | outbuf, | ||
size_t | buflen | ||
) |
Escape reserved characters for use in XML.
ast_xml_escape
If outbuf is too short, the output string will be truncated. Regardless, the output will always be null terminated.
string | String to be converted |
outbuf | Resulting encoded string |
buflen | Size of output buffer |
0 | for success |
-1 | if buflen is too short. |
Definition at line 864 of file utils.c.
References ast_assert, end, len(), NULL, and string.
Referenced by ast_http_create_response(), and test_xml().
|
extern |
Note: It is very important to use only unsigned variables to hold bit flags, as otherwise you can fall prey to the compiler's sign-extension antics if you try to use the top two bits in your variable. The flag macros below use a set of compiler tricks to verify that the caller is using an "unsigned int" variable to hold the flags, and nothing else. If the caller uses any other type of variable, a warning message similar to this: warning: comparison of distinct pointer types lacks cast will be generated. The "dummy" variable below is used to make these comparisons. Also note that at -O2 or above, this type-safety checking does _not_ produce any additional object code at all.
|
extern |
|
extern |
Global EID.
This is set in asterisk.conf, or determined automatically by taking the mac address of an Ethernet interface on the system.
Definition at line 93 of file options.c.
Referenced by app_send(), ast_ari_asterisk_get_info(), ast_ari_asterisk_ping(), ast_delete_mwi_state_full(), ast_device_state_clear_cache(), ast_event_append_eid(), ast_str_retrieve_variable(), AST_TEST_DEFINE(), asterisk_publication_send_refresh(), asterisk_publisher_devstate_cb(), asterisk_publisher_mwistate_cb(), bridges_scrape_cb(), cache_entry_by_eid(), cache_entry_create(), cache_remove(), cache_test_message_create(), cache_update(), channels_scrape_cb(), clear_node_cache(), cpg_confchg_cb(), cpg_deliver_cb(), endpoints_scrape_cb(), handle_show_settings(), load_asterisk_conf(), load_module(), mwi_state_create_message(), prometheus_config_post_apply(), publish_cluster_discovery_to_stasis(), publish_to_corosync(), set_config(), stasis_cache_dump(), stasis_cache_get(), stasis_message_create(), state_find_and_remove_eid(), state_find_or_add_eid(), xmpp_pubsub_devstate_cb(), xmpp_pubsub_handle_event(), xmpp_pubsub_mwi_cb(), xmpp_pubsub_publish_device_state(), and xmpp_pubsub_publish_mwi().
|
extern |
Definition at line 719 of file utils.c.
Referenced by acf_curl_helper(), ast_ari_bridges_record(), ast_ari_channels_record(), AST_TEST_DEFINE(), config_curl(), destroy_curl(), launch_asyncagi(), realtime_curl(), realtime_multi_curl(), require_curl(), store_curl(), update2_curl(), update_curl(), uridecode(), and uriencode().
|
extern |
Definition at line 720 of file utils.c.
Referenced by acf_curl_helper(), ast_ari_invoke(), ast_http_get_post_vars(), AST_TEST_DEFINE(), and handle_uri().
|
extern |
Definition at line 721 of file utils.c.
Referenced by AST_TEST_DEFINE().