Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2006, Digium, Inc.
5 *
6 * Mark Spencer <markster@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*! \file
20 * \brief Utility functions
21 */
22
23#ifndef _ASTERISK_UTILS_H
24#define _ASTERISK_UTILS_H
25
26#include "asterisk/network.h"
27
28#include <time.h> /* we want to override localtime_r */
29#include <unistd.h>
30#include <string.h>
31#include <endian.h>
32
33#include "asterisk/lock.h"
34#include "asterisk/time.h"
35#include "asterisk/logger.h"
36#include "asterisk/localtime.h"
38
39/*!
40\note \verbatim
41 Note:
42 It is very important to use only unsigned variables to hold
43 bit flags, as otherwise you can fall prey to the compiler's
44 sign-extension antics if you try to use the top two bits in
45 your variable.
46
47 The flag macros below use a set of compiler tricks to verify
48 that the caller is using an "unsigned int" variable to hold
49 the flags, and nothing else. If the caller uses any other
50 type of variable, a warning message similar to this:
51
52 warning: comparison of distinct pointer types lacks cast
53 will be generated.
54
55 The "dummy" variable below is used to make these comparisons.
56
57 Also note that at -O2 or above, this type-safety checking
58 does _not_ produce any additional object code at all.
59 \endverbatim
60*/
61
62extern unsigned int __unsigned_int_flags_dummy;
63
64#define ast_test_flag(p,flag) ({ \
65 typeof ((p)->flags) __p = (p)->flags; \
66 typeof (__unsigned_int_flags_dummy) __x = 0; \
67 (void) (&__p == &__x); \
68 ((p)->flags & (flag)); \
69 })
70
71#define ast_set_flag(p,flag) do { \
72 typeof ((p)->flags) __p = (p)->flags; \
73 typeof (__unsigned_int_flags_dummy) __x = 0; \
74 (void) (&__p == &__x); \
75 ((p)->flags |= (flag)); \
76 } while(0)
77
78#define ast_clear_flag(p,flag) do { \
79 typeof ((p)->flags) __p = (p)->flags; \
80 typeof (__unsigned_int_flags_dummy) __x = 0; \
81 (void) (&__p == &__x); \
82 ((p)->flags &= ~(flag)); \
83 } while(0)
84
85#define ast_copy_flags(dest,src,flagz) do { \
86 typeof ((dest)->flags) __d = (dest)->flags; \
87 typeof ((src)->flags) __s = (src)->flags; \
88 typeof (__unsigned_int_flags_dummy) __x = 0; \
89 (void) (&__d == &__x); \
90 (void) (&__s == &__x); \
91 (dest)->flags &= ~(flagz); \
92 (dest)->flags |= ((src)->flags & (flagz)); \
93 } while (0)
94
95#define ast_set2_flag(p,value,flag) do { \
96 typeof ((p)->flags) __p = (p)->flags; \
97 typeof (__unsigned_int_flags_dummy) __x = 0; \
98 (void) (&__p == &__x); \
99 if (value) \
100 (p)->flags |= (flag); \
101 else \
102 (p)->flags &= ~(flag); \
103 } while (0)
104
105#define ast_set_flags_to(p,flag,value) do { \
106 typeof ((p)->flags) __p = (p)->flags; \
107 typeof (__unsigned_int_flags_dummy) __x = 0; \
108 (void) (&__p == &__x); \
109 (p)->flags &= ~(flag); \
110 (p)->flags |= (value); \
111 } while (0)
112
113
114/*!
115 * \brief Swap the upper and lower 32 bits of a big-endian 64-bit integer
116 *
117 * This macro is needed to preserve ABI compatability on big-endian systems
118 * after changing from a 32 bit flags to a 64 bit flags. It ensures that a
119 * new 64-bit flag field will still work with a function that expects a
120 * 32-bit flag field. On a little-endian system, nothing is needed, since
121 * the 64-bit flags are already in the correct order.
122 *
123 * \note This macro is different than a standard byte swap, as it
124 * doesn't reverse the byte order, it just swaps the upper 4 bytes with
125 * the lower 4 bytes.
126 *
127 * \param flags The 64-bit flags to swap
128 * \retval The flags with the upper and lower 32 bits swapped if the system is big-endian,
129 */
130#if defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN)
131#define SWAP64_32(flags) (((uint64_t)flags << 32) | ((uint64_t)flags >> 32))
132#elif defined(BYTE_ORDER) && (BYTE_ORDER == LITTLE_ENDIAN)
133#define SWAP64_32(flags) (flags)
134#else
135#error "Endianness not known - endian.h broken?"
136#endif
137
138extern uint64_t __unsigned_int_flags_dummy64;
139
140#define ast_test_flag64(p,flag) ({ \
141 typeof ((p)->flags) __p = (p)->flags; \
142 typeof (__unsigned_int_flags_dummy64) __x = 0; \
143 (void) (&__p == &__x); \
144 ((p)->flags & SWAP64_32(flag)); \
145 })
146
147#define ast_set_flag64(p,flag) do { \
148 typeof ((p)->flags) __p = (p)->flags; \
149 typeof (__unsigned_int_flags_dummy64) __x = 0; \
150 (void) (&__p == &__x); \
151 ((p)->flags |= SWAP64_32(flag)); \
152 } while(0)
153
154#define ast_clear_flag64(p,flag) do { \
155 typeof ((p)->flags) __p = (p)->flags; \
156 typeof (__unsigned_int_flags_dummy64) __x = 0; \
157 (void) (&__p == &__x); \
158 ((p)->flags &= ~SWAP64_32(flag)); \
159 } while(0)
160
161#define ast_copy_flags64(dest,src,flagz) do { \
162 typeof ((dest)->flags) __d = (dest)->flags; \
163 typeof ((src)->flags) __s = (src)->flags; \
164 typeof (__unsigned_int_flags_dummy64) __x = 0; \
165 (void) (&__d == &__x); \
166 (void) (&__s == &__x); \
167 (dest)->flags &= ~SWAP64_32(flagz); \
168 (dest)->flags |= ((src)->flags & SWAP64_32(flagz)); \
169 } while (0)
170
171#define ast_set2_flag64(p,value,flag) do { \
172 typeof ((p)->flags) __p = (p)->flags; \
173 typeof (__unsigned_int_flags_dummy64) __x = 0; \
174 (void) (&__p == &__x); \
175 if (value) \
176 (p)->flags |= SWAP64_32(flag); \
177 else \
178 (p)->flags &= ~SWAP64_32(flag); \
179 } while (0)
180
181#define ast_set_flags_to64(p,flag,value) do { \
182 typeof ((p)->flags) __p = (p)->flags; \
183 typeof (__unsigned_int_flags_dummy64) __x = 0; \
184 (void) (&__p == &__x); \
185 (p)->flags &= ~SWAP64_32(flag); \
186 (p)->flags |= SWAP64_32(value); \
187 } while (0)
188
189#define AST_FLAGS64_ALL ULONG_MAX
190
191/* Non-type checking variations for non-unsigned int flags. You
192 should only use non-unsigned int flags where required by
193 protocol etc and if you know what you're doing :) */
194#define ast_test_flag_nonstd(p,flag) \
195 ((p)->flags & (flag))
196
197#define ast_set_flag_nonstd(p,flag) do { \
198 ((p)->flags |= (flag)); \
199 } while(0)
200
201#define ast_clear_flag_nonstd(p,flag) do { \
202 ((p)->flags &= ~(flag)); \
203 } while(0)
204
205#define ast_copy_flags_nonstd(dest,src,flagz) do { \
206 (dest)->flags &= ~(flagz); \
207 (dest)->flags |= ((src)->flags & (flagz)); \
208 } while (0)
209
210#define ast_set2_flag_nonstd(p,value,flag) do { \
211 if (value) \
212 (p)->flags |= (flag); \
213 else \
214 (p)->flags &= ~(flag); \
215 } while (0)
216
217#define AST_FLAGS_ALL UINT_MAX
218
219/*! \brief Structure used to handle boolean flags */
220struct ast_flags {
221 unsigned int flags;
222};
223
224/*! \brief Structure used to handle a large number of boolean flags == used only in app_dial? */
226 uint64_t flags;
227};
228
230 struct hostent hp;
231 char buf[1024];
232};
233
234/*!
235 * \brief Thread-safe gethostbyname function to use in Asterisk
236 *
237 * \deprecated Replaced by \c ast_sockaddr_resolve() and \c ast_sockaddr_resolve_first_af()
238 * \note To be removed in Asterisk 23.
239 */
240struct hostent *ast_gethostbyname(const char *host, struct ast_hostent *hp);
241
242/*! \brief Produces MD5 hash based on input string */
243void ast_md5_hash(char *output, const char *input);
244/*! \brief Produces SHA1 hash based on input string */
245void ast_sha1_hash(char *output, const char *input);
246/*! \brief Produces SHA1 hash based on input string, stored in uint8_t array */
247void ast_sha1_hash_uint(uint8_t *digest, const char *input);
248
249int ast_base64encode_full(char *dst, const unsigned char *src, int srclen, int max, int linebreaks);
250
251#undef MIN
252#define MIN(a, b) ({ typeof(a) __a = (a); typeof(b) __b = (b); ((__a > __b) ? __b : __a);})
253#undef MAX
254#define MAX(a, b) ({ typeof(a) __a = (a); typeof(b) __b = (b); ((__a < __b) ? __b : __a);})
255
256#define SWAP(a,b) do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
257
258/*!
259 * \brief Encode data in base64
260 * \param dst the destination buffer
261 * \param src the source data to be encoded
262 * \param srclen the number of bytes present in the source buffer
263 * \param max the maximum number of bytes to write into the destination
264 * buffer, *including* the terminating NULL character.
265 */
266int ast_base64encode(char *dst, const unsigned char *src, int srclen, int max);
267
268/*!
269 * \brief Same as ast_base64encode, but does hte math for you and returns
270 * an encoded string
271 *
272 * \note The returned string will need to be freed later
273 *
274 * \param src The source buffer
275 *
276 * \retval NULL on failure
277 * \return Encoded string on success
278 */
279char *ast_base64encode_string(const char *src);
280
281/*!
282 * \brief Decode data from base64
283 * \param dst the destination buffer
284 * \param src the source buffer
285 * \param max The maximum number of bytes to write into the destination
286 * buffer. Note that this function will not ensure that the
287 * destination buffer is NULL terminated. So, in general,
288 * this parameter should be sizeof(dst) - 1.
289 */
290int ast_base64decode(unsigned char *dst, const char *src, int max);
291
292/*!
293 * \brief Same as ast_base64decode, but does the math for you and returns
294 * a decoded string
295 *
296 * \note The returned string will need to be freed later and IS NULL terminated
297 *
298 * \param src The source buffer
299 *
300 * \retval NULL on failure
301 * \return Decoded string on success
302 */
303char *ast_base64decode_string(const char *src);
304
305/*!
306 * \brief Decode data from base64 URL
307 *
308 * \param dst The destination buffer
309 * \param src The source buffer
310 * \param max The maximum number of bytes to write into the destination
311 * buffer. Note that this function will not ensure that the
312 * destination buffer is NULL terminated. So, in general,
313 * this parameter should be sizeof(dst) - 1
314 */
315int ast_base64url_decode(unsigned char *dst, const char *src, int max);
316
317/*!
318 * \brief Same as ast_base64encode_full but for base64 URL
319 *
320 * \param dst The destination buffer
321 * \param src The source buffer
322 * \param srclen The number of bytes present in the source buffer
323 * \param max The maximum number of bytes to write into the destination
324 * buffer, *including* the terminating NULL character.
325 * \param linebreaks Set to 1 if there should be linebreaks inserted
326 * in the result
327 */
328int ast_base64url_encode_full(char *dst, const unsigned char *src, int srclen, int max, int linebreaks);
329
330/*!
331 * \brief Encode data in base64 URL
332 *
333 * \param dst The destination buffer
334 * \param src The source data to be encoded
335 * \param srclen The number of bytes present in the source buffer
336 * \param max The maximum number of bytes to write into the destination
337 * buffer, including the terminating NULL character
338 */
339int ast_base64url_encode(char *dst, const unsigned char *src, int srclen, int max);
340
341/*!
342 * \brief Decode string from base64 URL
343 *
344 * \note The returned string will need to be freed later
345 *
346 * \param src The source buffer
347 *
348 * \retval NULL on failure
349 * \return Decoded string on success
350 */
351char *ast_base64url_decode_string(const char *src);
352
353/*!
354 * \brief Encode string in base64 URL
355 *
356 * \note The returned string will need to be freed later
357 *
358 * \param src The source data to be encoded
359 *
360 * \retval NULL on failure
361 * \return Encoded string on success
362 */
363char *ast_base64url_encode_string(const char *src);
364
365/*!
366 * \brief Performs a base 64 encode algorithm on the contents of a File
367 * \param inputfile A FILE handle to the input file to be encoded. Must be readable. This handle is not automatically closed.
368 * \param outputfile A FILE handle to the output file to receive the base 64 encoded contents of the input file, identified by filename.
369 * \param endl The line ending to use (e.g. either "\n" or "\r\n")
370 *
371 * \return zero on success, -1 on error.
372 */
373int ast_base64_encode_file(FILE *inputfile, FILE *outputfile, const char *endl);
374
375/*!
376 * \brief Performs a base 64 encode algorithm on the contents of a File
377 * \param filename The path to the file to be encoded. Must be readable, file is opened in read mode.
378 * \param outputfile A FILE handle to the output file to receive the base 64 encoded contents of the input file, identified by filename.
379 * \param endl The line ending to use (e.g. either "\n" or "\r\n")
380 *
381 * \return zero on success, -1 on error.
382 */
383int ast_base64_encode_file_path(const char *filename, FILE *outputfile, const char *endl);
384
385#define AST_URI_ALPHANUM (1 << 0)
386#define AST_URI_MARK (1 << 1)
387#define AST_URI_UNRESERVED (AST_URI_ALPHANUM | AST_URI_MARK)
388#define AST_URI_LEGACY_SPACE (1 << 2)
389
390#define AST_URI_SIP_USER_UNRESERVED (1 << 20)
391
392extern const struct ast_flags ast_uri_http;
393extern const struct ast_flags ast_uri_http_legacy;
394extern const struct ast_flags ast_uri_sip_user;
395
396/*!
397 * \brief Turn text string to URI-encoded %XX version
398 *
399 * This function encodes characters according to the rules presented in RFC
400 * 2396 and/or RFC 3261 section 19.1.2 and section 25.1.
401 *
402 * Outbuf needs to have more memory allocated than the instring to have room
403 * for the expansion. Every byte that is converted is replaced by three ASCII
404 * characters.
405 *
406 * \param string string to be converted
407 * \param outbuf resulting encoded string
408 * \param buflen size of output buffer
409 * \param spec flags describing how the encoding should be performed
410 * \return a pointer to the uri encoded string
411 */
412char *ast_uri_encode(const char *string, char *outbuf, int buflen, struct ast_flags spec);
413
414/*!
415 * \brief Decode URI, URN, URL (overwrite string)
416 *
417 * \note The ast_uri_http_legacy decode spec flag will cause this function to
418 * decode '+' as ' '.
419 *
420 * \param s string to be decoded
421 * \param spec flags describing how the decoding should be performed
422 */
423void ast_uri_decode(char *s, struct ast_flags spec);
424
425/*!
426 * \brief Verify if a string is valid as a URI component
427 *
428 * This function checks if the string either doesn't need encoding
429 * or is already properly URI encoded.
430 * Valid characters are 'a-zA-Z0-9.+_-' and '%xx' escape sequences.
431 *
432 * \param string String to be checked
433 * \retval 1 if the string is valid
434 * \retval 0 if the string is not valid
435 */
436int ast_uri_verify_encoded(const char *string);
437
438/*! ast_xml_escape
439 \brief Escape reserved characters for use in XML.
440
441 If \a outbuf is too short, the output string will be truncated.
442 Regardless, the output will always be null terminated.
443
444 \param string String to be converted
445 \param outbuf Resulting encoded string
446 \param buflen Size of output buffer
447 \retval 0 for success
448 \retval -1 if buflen is too short.
449 */
450int ast_xml_escape(const char *string, char *outbuf, size_t buflen);
451
452/*!
453 * \brief Escape characters found in a quoted string.
454 *
455 * \note This function escapes quoted characters based on the 'qdtext' set of
456 * allowed characters from RFC 3261 section 25.1.
457 *
458 * \param string string to be escaped
459 * \param outbuf resulting escaped string
460 * \param buflen size of output buffer
461 * \return a pointer to the escaped string
462 */
463char *ast_escape_quoted(const char *string, char *outbuf, int buflen);
464
465/*!
466 * \brief Escape semicolons found in a string.
467 *
468 * \param string string to be escaped
469 * \param outbuf resulting escaped string
470 * \param buflen size of output buffer
471 * \return a pointer to the escaped string
472 */
473char *ast_escape_semicolons(const char *string, char *outbuf, int buflen);
474
475/*!
476 * \brief Unescape quotes in a string
477 *
478 * \param quote_str The string with quotes to be unescaped
479 *
480 * \note This function mutates the passed-in string.
481 */
482void ast_unescape_quoted(char *quote_str);
483
484static force_inline void ast_slinear_saturated_add(short *input, short *value)
485{
486 int res;
487
488 res = (int) *input + *value;
489 if (res > 32767)
490 *input = 32767;
491 else if (res < -32768)
492 *input = -32768;
493 else
494 *input = (short) res;
495}
496
497static force_inline void ast_slinear_saturated_subtract(short *input, short *value)
498{
499 int res;
500
501 res = (int) *input - *value;
502 if (res > 32767)
503 *input = 32767;
504 else if (res < -32768)
505 *input = -32768;
506 else
507 *input = (short) res;
508}
509
510static force_inline void ast_slinear_saturated_multiply(short *input, short *value)
511{
512 int res;
513
514 res = (int) *input * *value;
515 if (res > 32767)
516 *input = 32767;
517 else if (res < -32768)
518 *input = -32768;
519 else
520 *input = (short) res;
521}
522
524{
525 float res;
526
527 res = (float) *input * *value;
528 if (res > 32767)
529 *input = 32767;
530 else if (res < -32768)
531 *input = -32768;
532 else if (res > 0)
533 *input = (short) (res + 0.5);
534 else
535 *input = (short) (res - 0.5);
536
537}
538
539static force_inline void ast_slinear_saturated_divide(short *input, short *value)
540{
541 *input /= *value;
542}
543
545{
546 float res = (float) *input / *value;
547 if (res > 32767)
548 *input = 32767;
549 else if (res < -32768)
550 *input = -32768;
551 else if (res > 0)
552 *input = (short) (res + 0.5);
553 else
554 *input = (short) (res - 0.5);
555
556}
557
558#ifdef localtime_r
559#undef localtime_r
560#endif
561#define localtime_r __dont_use_localtime_r_use_ast_localtime_instead__
562
563int ast_utils_init(void);
564int ast_wait_for_input(int fd, int ms);
565int ast_wait_for_output(int fd, int ms);
566
567/*!
568 * \brief Try to write string, but wait no more than ms milliseconds
569 * before timing out.
570 *
571 * \note If you are calling ast_carefulwrite, it is assumed that you are calling
572 * it on a file descriptor that _DOES_ have NONBLOCK set. This way,
573 * there is only one system call made to do a write, unless we actually
574 * have a need to wait. This way, we get better performance.
575 */
576int ast_carefulwrite(int fd, char *s, int len, int timeoutms);
577
578/*!
579 * \brief Write data to a file stream with a timeout
580 *
581 * \param f the file stream to write to
582 * \param fd the file description to poll on to know when the file stream can
583 * be written to without blocking.
584 * \param s the buffer to write from
585 * \param len the number of bytes to write
586 * \param timeoutms The maximum amount of time to block in this function trying
587 * to write, specified in milliseconds.
588 *
589 * \note This function assumes that the associated file stream has been set up
590 * as non-blocking.
591 *
592 * \retval 0 success
593 * \retval -1 error
594 */
595int ast_careful_fwrite(FILE *f, int fd, const char *s, size_t len, int timeoutms);
596
597/*
598 * Thread management support (should be moved to lock.h or a different header)
599 */
600
601#if defined(PTHREAD_STACK_MIN)
602# define AST_STACKSIZE MAX((((sizeof(void *) * 8 * 8) - 16) * 1024), PTHREAD_STACK_MIN)
603# define AST_STACKSIZE_LOW MAX((((sizeof(void *) * 8 * 2) - 16) * 1024), PTHREAD_STACK_MIN)
604#else
605# define AST_STACKSIZE (((sizeof(void *) * 8 * 8) - 16) * 1024)
606# define AST_STACKSIZE_LOW (((sizeof(void *) * 8 * 2) - 16) * 1024)
607#endif
608
610
611#define AST_BACKGROUND_STACKSIZE ast_background_stacksize()
612
613void ast_register_thread(char *name);
614void ast_unregister_thread(void *id);
615
616int ast_pthread_create_stack(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *),
617 void *data, size_t stacksize, const char *file, const char *caller,
618 int line, const char *start_fn);
619
620int ast_pthread_create_detached_stack(pthread_t *thread, pthread_attr_t *attr, void*(*start_routine)(void *),
621 void *data, size_t stacksize, const char *file, const char *caller,
622 int line, const char *start_fn);
623
624#define ast_pthread_create(a, b, c, d) \
625 ast_pthread_create_stack(a, b, c, d, \
626 0, __FILE__, __FUNCTION__, __LINE__, #c)
627
628#define ast_pthread_create_detached(a, b, c, d) \
629 ast_pthread_create_detached_stack(a, b, c, d, \
630 0, __FILE__, __FUNCTION__, __LINE__, #c)
631
632#define ast_pthread_create_background(a, b, c, d) \
633 ast_pthread_create_stack(a, b, c, d, \
634 AST_BACKGROUND_STACKSIZE, \
635 __FILE__, __FUNCTION__, __LINE__, #c)
636
637#define ast_pthread_create_detached_background(a, b, c, d) \
638 ast_pthread_create_detached_stack(a, b, c, d, \
639 AST_BACKGROUND_STACKSIZE, \
640 __FILE__, __FUNCTION__, __LINE__, #c)
641
642/* End of thread management support */
643
644/*!
645 * \brief Replace '^' in a string with ','
646 * \param s String within which to replace characters
647 */
649
650/*!
651 * \brief Process a string to find and replace characters
652 * \param start The string to analyze
653 * \param find The character to find
654 * \param replace_with The character that will replace the one we are looking for
655 */
656char *ast_process_quotes_and_slashes(char *start, char find, char replace_with);
657
658long int ast_random(void);
659
660/*!
661 * \brief Returns a random number between 0.0 and 1.0, inclusive.
662 * \since 12
663 */
664#define ast_random_double() (((double)ast_random()) / RAND_MAX)
665
666/*!
667 * \brief Disable PMTU discovery on a socket
668 * \param sock The socket to manipulate
669 *
670 * On Linux, UDP sockets default to sending packets with the Dont Fragment (DF)
671 * bit set. This is supposedly done to allow the application to do PMTU
672 * discovery, but Asterisk does not do this.
673 *
674 * Because of this, UDP packets sent by Asterisk that are larger than the MTU
675 * of any hop in the path will be lost. This function can be called on a socket
676 * to ensure that the DF bit will not be set.
677 */
679
680/*!
681 * \brief Recursively create directory path
682 * \param path The directory path to create
683 * \param mode The permissions with which to try to create the directory
684 * \retval 0 on success
685 * \return error code otherwise
686 *
687 * Creates a directory path, creating parent directories as needed.
688 */
689int ast_mkdir(const char *path, int mode);
690
691/*!
692 * \brief Recursively create directory path, but only if it resolves within
693 * the given \a base_path.
694 *
695 * If \a base_path does not exist, it will not be created and this function
696 * returns \c EPERM.
697 *
698 * \param base_path
699 * \param path The directory path to create
700 * \param mode The permissions with which to try to create the directory
701 * \retval 0 on success
702 * \return an error code otherwise
703 */
704int ast_safe_mkdir(const char *base_path, const char *path, int mode);
705
706#define ARRAY_LEN(a) (size_t) (sizeof(a) / sizeof(0[a]))
707
708/*!
709 * \brief Checks to see if value is within the given bounds
710 *
711 * \param v the value to check
712 * \param min minimum lower bound (inclusive)
713 * \param max maximum upper bound (inclusive)
714 * \retval 0 if value out of bounds
715 * \retval non-zero otherwise
716 */
717#define IN_BOUNDS(v, min, max) ((v) >= (min)) && ((v) <= (max))
718
719/*!
720 * \brief Checks to see if value is within the bounds of the given array
721 *
722 * \param v the value to check
723 * \param a the array to bound check
724 * \retval 0 if value out of bounds
725 * \retval non-zero otherwise
726 */
727#define ARRAY_IN_BOUNDS(v, a) IN_BOUNDS((int) (v), 0, ARRAY_LEN(a) - 1)
728
729/* Definition for Digest authorization */
744
745/*!
746 * \brief Parse digest authorization header.
747 * \return -1 if we have no auth or something wrong with digest.
748 * \note This function may be used for Digest request and responce header.
749 * request arg is set to nonzero, if we parse Digest Request.
750 * pedantic arg can be set to nonzero if we need to do addition Digest check.
751 */
752int ast_parse_digest(const char *digest, struct ast_http_digest *d, int request, int pedantic);
753
754#ifdef DO_CRASH
755#define DO_CRASH_NORETURN attribute_noreturn
756#else
757#define DO_CRASH_NORETURN
758#endif
759
760void DO_CRASH_NORETURN __ast_assert_failed(int condition, const char *condition_str,
761 const char *file, int line, const char *function);
762
763#ifdef AST_DEVMODE
764#define ast_assert(a) _ast_assert(a, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
765#define ast_assert_return(a, ...) \
766({ \
767 if (__builtin_expect(!(a), 1)) { \
768 _ast_assert(0, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
769 return __VA_ARGS__; \
770 }\
771})
772static void force_inline _ast_assert(int condition, const char *condition_str, const char *file, int line, const char *function)
773{
774 if (__builtin_expect(!condition, 1)) {
775 __ast_assert_failed(condition, condition_str, file, line, function);
776 }
777}
778#else
779#define ast_assert(a)
780#define ast_assert_return(a, ...) \
781({ \
782 if (__builtin_expect(!(a), 1)) { \
783 return __VA_ARGS__; \
784 }\
785})
786#endif
787
788/*!
789 * \brief Force a crash if DO_CRASH is defined.
790 *
791 * \note If DO_CRASH is not defined then the function returns.
792 */
794
795#include "asterisk/strings.h"
796
797/*!
798 * \brief Return the number of bytes used in the alignment of type.
799 * \param type
800 * \return The number of bytes required for alignment.
801 *
802 * This is really just __alignof__(), but tucked away in this header so we
803 * don't have to look at the nasty underscores in the source.
804 */
805#define ast_alignof(type) __alignof__(type)
806
807/*!
808 * \brief Increase offset so it is a multiple of the required alignment of type.
809 * \param offset The value that should be increased.
810 * \param type The data type that offset should be aligned to.
811 * \return The smallest multiple of alignof(type) larger than or equal to offset.
812 * \see ast_make_room_for()
813 *
814 * Many systems prefer integers to be stored on aligned on memory locations.
815 * This macro will increase an offset so a value of the supplied type can be
816 * safely be stored on such a memory location.
817 *
818 * Examples:
819 * ast_align_for(0x17, int64_t) ==> 0x18
820 * ast_align_for(0x18, int64_t) ==> 0x18
821 * ast_align_for(0x19, int64_t) ==> 0x20
822 *
823 * Don't mind the ugliness, the compiler will optimize it.
824 */
825#define ast_align_for(offset, type) (((offset + __alignof__(type) - 1) / __alignof__(type)) * __alignof__(type))
826
827/*!
828 * \brief Increase offset by the required alignment of type and make sure it is
829 * a multiple of said alignment.
830 * \param offset The value that should be increased.
831 * \param type The data type that room should be reserved for.
832 * \return The smallest multiple of alignof(type) larger than or equal to offset
833 * plus alignof(type).
834 * \see ast_align_for()
835 *
836 * A use case for this is when prepending length fields of type int to a buffer.
837 * If you keep the offset a multiple of the alignment of the integer type,
838 * a next block of length+buffer will have the length field automatically
839 * aligned.
840 *
841 * Examples:
842 * ast_make_room_for(0x17, int64_t) ==> 0x20
843 * ast_make_room_for(0x18, int64_t) ==> 0x20
844 * ast_make_room_for(0x19, int64_t) ==> 0x28
845 *
846 * Don't mind the ugliness, the compiler will optimize it.
847 */
848#define ast_make_room_for(offset, type) (((offset + (2 * __alignof__(type) - 1)) / __alignof__(type)) * __alignof__(type))
849
850/*!
851 * \brief An Entity ID is essentially a MAC address, brief and unique
852 */
853struct ast_eid {
854 unsigned char eid[6];
855} __attribute__((__packed__));
856
857/*!
858 * \brief Global EID
859 *
860 * This is set in asterisk.conf, or determined automatically by taking the mac
861 * address of an Ethernet interface on the system.
862 */
863extern struct ast_eid ast_eid_default;
864
865/*!
866 * \brief Fill in an ast_eid with the default eid of this machine
867 * \since 1.6.1
868 */
869void ast_set_default_eid(struct ast_eid *eid);
870
871/*!
872 * \brief Convert an EID to a string
873 * \since 1.6.1
874 */
875char *ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid);
876
877/*!
878 * \brief Convert a string into an EID
879 *
880 * This function expects an EID in the format:
881 * 00:11:22:33:44:55
882 *
883 * \retval 0 success
884 * \retval non-zero failure
885 * \since 1.6.1
886 */
887int ast_str_to_eid(struct ast_eid *eid, const char *s);
888
889/*!
890 * \brief Compare two EIDs
891 *
892 * \retval 0 if the two are the same
893 * \retval non-zero otherwise
894 * \since 1.6.1
895 */
896int ast_eid_cmp(const struct ast_eid *eid1, const struct ast_eid *eid2);
897
898/*!
899 * \brief Check if EID is empty
900 *
901 * \retval 1 if the EID is empty
902 * \retval 0 otherwise
903 * \since 13.12.0
904 */
905int ast_eid_is_empty(const struct ast_eid *eid);
906
907/*!
908 * \brief Get current thread ID
909 * \return the ID if platform is supported, else -1
910 */
911int ast_get_tid(void);
912
913/*!
914 * \brief Resolve a binary to a full pathname
915 * \param binary Name of the executable to resolve
916 * \param fullpath Buffer to hold the complete pathname
917 * \param fullpath_size Size of \a fullpath
918 * \retval NULL \a binary was not found or the environment variable PATH is not set
919 * \return \a fullpath
920 */
921char *ast_utils_which(const char *binary, char *fullpath, size_t fullpath_size);
922
923/*!
924 * \brief Declare a variable that will call a destructor function when it goes out of scope.
925 *
926 * Resource Allocation Is Initialization (RAII) variable declaration.
927 *
928 * \since 11.0
929 * \param vartype The type of the variable
930 * \param varname The name of the variable
931 * \param initval The initial value of the variable
932 * \param dtor The destructor function of type' void func(vartype *)'
933 *
934 * \code
935 * void mything_cleanup(struct mything *t)
936 * {
937 * if (t) {
938 * ast_free(t->stuff);
939 * }
940 * }
941 *
942 * void do_stuff(const char *name)
943 * {
944 * RAII_VAR(struct mything *, thing, mything_alloc(name), mything_cleanup);
945 * ...
946 * }
947 * \endcode
948 *
949 * \note This macro is especially useful for working with ao2 objects. A common idiom
950 * would be a function that needed to look up an ao2 object and might have several error
951 * conditions after the allocation that would normally need to unref the ao2 object.
952 * With RAII_VAR, it is possible to just return and leave the cleanup to the destructor
953 * function. For example:
954 *
955 * \code
956 * void do_stuff(const char *name)
957 * {
958 * RAII_VAR(struct mything *, thing, find_mything(name), ao2_cleanup);
959 * if (!thing) {
960 * return;
961 * }
962 * if (error) {
963 * return;
964 * }
965 * do_stuff_with_thing(thing);
966 * }
967 * \endcode
968 */
969
970#if defined(__clang__)
971typedef void (^_raii_cleanup_block_t)(void);
972static inline void _raii_cleanup_block(_raii_cleanup_block_t *b) { (*b)(); }
973
974#define RAII_VAR(vartype, varname, initval, dtor) \
975 __block vartype varname = initval; \
976 _raii_cleanup_block_t _raii_cleanup_ ## varname __attribute__((cleanup(_raii_cleanup_block),unused)) = \
977 ^{ {(void)dtor(varname);} };
978
979#elif defined(__GNUC__)
980
981#define RAII_VAR(vartype, varname, initval, dtor) \
982 auto void _dtor_ ## varname (vartype * v); \
983 void _dtor_ ## varname (vartype * v) { dtor(*v); } \
984 vartype varname __attribute__((cleanup(_dtor_ ## varname))) = (initval)
985
986#else
987 #error "Cannot compile Asterisk: unknown and unsupported compiler."
988#endif /* #if __GNUC__ */
989
990/*!
991 * \brief Asterisk wrapper around crypt(3).
992 *
993 * The interpretation of the salt (which determines the password hashing
994 * algorithm) is system specific. Application code should prefer to use
995 * ast_crypt_encrypt() or ast_crypt_validate().
996 *
997 * The returned string is heap allocated, and should be freed with ast_free().
998 *
999 * \param key User's password to crypt.
1000 * \param salt Salt to crypt with.
1001 * \return Crypted password.
1002 * \retval NULL on error.
1003 */
1004char *ast_crypt(const char *key, const char *salt);
1005
1006/*!
1007 * \brief Asterisk wrapper around crypt(3) for encrypting passwords.
1008 *
1009 * This function will generate a random salt and encrypt the given password.
1010 *
1011 * The returned string is heap allocated, and should be freed with ast_free().
1012 *
1013 * \param key User's password to crypt.
1014 * \return Crypted password.
1015 * \retval NULL on error.
1016 */
1017char *ast_crypt_encrypt(const char *key);
1018
1019/*!
1020 * \brief Asterisk wrapper around crypt(3) for validating passwords.
1021 *
1022 * \param key User's password to validate.
1023 * \param expected Expected result from crypt.
1024 * \retval True (non-zero) if \a key matches \a expected.
1025 * \retval False (zero) if \a key doesn't match.
1026 */
1027int ast_crypt_validate(const char *key, const char *expected);
1028
1029/*!
1030 * \brief Test that a file exists and is readable by the effective user.
1031 * \since 13.7.0
1032 *
1033 * \param filename File to test.
1034 * \retval True (non-zero) if the file exists and is readable.
1035 * \retval False (zero) if the file either doesn't exists or is not readable.
1036 */
1037int ast_file_is_readable(const char *filename);
1038
1039/*!
1040 * \brief Compare 2 major.minor.patch.extra version strings.
1041 * \since 13.7.0
1042 *
1043 * \param version1
1044 * \param version2
1045 *
1046 * \retval negative if version 1 < version 2.
1047 * \retval 0 if version 1 = version 2.
1048 * \retval positive if version 1 > version 2.
1049 */
1050int ast_compare_versions(const char *version1, const char *version2);
1051
1052/*!
1053 * \brief Test that an OS supports IPv6 Networking.
1054 * \since 13.14.0
1055 *
1056 * \retval True (non-zero) if the IPv6 supported.
1057 * \retval False (zero) if the OS doesn't support IPv6.
1058 */
1059int ast_check_ipv6(void);
1060
1065
1066/*!
1067 * \brief Set flags on the given file descriptor
1068 * \since 13.19
1069 *
1070 * If getting or setting flags of the given file descriptor fails, logs an
1071 * error message.
1072 *
1073 * \param fd File descriptor to set flags on
1074 * \param flags The flag(s) to set
1075 *
1076 * \retval -1 on error
1077 * \retval 0 if successful
1078 */
1079#define ast_fd_set_flags(fd, flags) \
1080 __ast_fd_set_flags((fd), (flags), AST_FD_FLAG_SET, __FILE__, __LINE__, __PRETTY_FUNCTION__)
1081
1082/*!
1083 * \brief Clear flags on the given file descriptor
1084 * \since 13.19
1085 *
1086 * If getting or setting flags of the given file descriptor fails, logs an
1087 * error message.
1088 *
1089 * \param fd File descriptor to clear flags on
1090 * \param flags The flag(s) to clear
1091 *
1092 * \retval -1 on error
1093 * \retval 0 if successful
1094 */
1095#define ast_fd_clear_flags(fd, flags) \
1096 __ast_fd_set_flags((fd), (flags), AST_FD_FLAG_CLEAR, __FILE__, __LINE__, __PRETTY_FUNCTION__)
1097
1098int __ast_fd_set_flags(int fd, int flags, enum ast_fd_flag_operation op,
1099 const char *file, int lineno, const char *function);
1100
1101/*!
1102 * \brief Create a non-blocking socket
1103 * \since 13.25
1104 *
1105 * Wrapper around socket(2) that sets the O_NONBLOCK flag on the resulting
1106 * socket.
1107 *
1108 * \details
1109 * For parameter and return information, see the man page for
1110 * socket(2).
1111 */
1112#ifdef HAVE_SOCK_NONBLOCK
1113# define ast_socket_nonblock(domain, type, protocol) socket((domain), (type) | SOCK_NONBLOCK, (protocol))
1114#else
1115int ast_socket_nonblock(int domain, int type, int protocol);
1116#endif
1117
1118/*!
1119 * \brief Create a non-blocking pipe
1120 * \since 13.25
1121 *
1122 * Wrapper around pipe(2) that sets the O_NONBLOCK flag on the resulting
1123 * file descriptors.
1124 *
1125 * \details
1126 * For parameter and return information, see the man page for
1127 * pipe(2).
1128 */
1129#ifdef HAVE_PIPE2
1130# define ast_pipe_nonblock(filedes) pipe2((filedes), O_NONBLOCK)
1131#else
1132int ast_pipe_nonblock(int filedes[2]);
1133#endif
1134
1135/*!
1136 * \brief Set the current thread's user interface status.
1137 *
1138 * \param is_user_interface Non-zero to mark the thread as a user interface.
1139 *
1140 * \retval True (non-zero) if marking current thread failed.
1141 * \retval False (zero) if successfuly marked current thread.
1142 */
1143int ast_thread_user_interface_set(int is_user_interface);
1144
1145/*!
1146 * \brief Indicates whether the current thread is a user interface
1147 *
1148 * \retval True (non-zero) if thread is a user interface.
1149 * \retval False (zero) if thread is not a user interface.
1150 */
1152
1153/*!
1154 * \brief Test for the presence of an executable command in $PATH
1155 *
1156 * \param cmd Name of command to locate.
1157 *
1158 * \retval True (non-zero) if command is in $PATH.
1159 * \retval False (zero) command not found.
1160 */
1161int ast_check_command_in_path(const char *cmd);
1162
1163#endif /* _ASTERISK_UTILS_H */
pthread_t thread
Definition app_sla.c:335
static const char type[]
static int request(void *obj)
#define force_inline
Definition compiler.h:29
Asterisk architecture endianess compatibility definitions.
#define max(a, b)
Definition f2c.h:198
static const char name[]
Definition format_mp3.c:68
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
Support for logging to various files, console and syslog Configuration in file logger....
Custom localtime functions for multiple timezones.
Asterisk locking-related definitions:
Wrapper for network related headers, masking differences between various operating systems....
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define AST_STRING_FIELD(name)
Declare a string field.
String manipulation functions.
An Entity ID is essentially a MAC address, brief and unique.
Definition utils.h:853
unsigned char eid[6]
Definition utils.h:854
Structure used to handle a large number of boolean flags == used only in app_dial?
Definition utils.h:225
uint64_t flags
Definition utils.h:226
Structure used to handle boolean flags.
Definition utils.h:220
unsigned int flags
Definition utils.h:221
char buf[1024]
Definition utils.h:231
struct hostent hp
Definition utils.h:230
const ast_string_field response
Definition utils.h:741
const ast_string_field uri
Definition utils.h:741
const ast_string_field domain
Definition utils.h:741
const ast_string_field opaque
Definition utils.h:741
const ast_string_field cnonce
Definition utils.h:741
const ast_string_field nonce
Definition utils.h:741
const ast_string_field username
Definition utils.h:741
const ast_string_field realm
Definition utils.h:741
const ast_string_field nc
Definition utils.h:741
int value
Definition syslog.c:37
static struct test_val b
static struct test_val d
Time-related functions and macros.
int ast_thread_is_user_interface(void)
Indicates whether the current thread is a user interface.
Definition utils.c:3284
void ast_unescape_quoted(char *quote_str)
Unescape quotes in a string.
Definition utils.c:878
static force_inline void ast_slinear_saturated_divide_float(short *input, float *value)
Definition utils.h:544
static force_inline void ast_slinear_saturated_subtract(short *input, short *value)
Definition utils.h:497
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.
Definition utils.c:471
int ast_base64_encode_file(FILE *inputfile, FILE *outputfile, const char *endl)
Performs a base 64 encode algorithm on the contents of a File.
Definition utils.c:648
int ast_base64decode(unsigned char *dst, const char *src, int max)
Decode data from base64.
Definition utils.c:296
int ast_check_command_in_path(const char *cmd)
Test for the presence of an executable command in $PATH.
Definition utils.c:3299
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.
Definition utils.c:2620
unsigned int __unsigned_int_flags_dummy
char * ast_base64url_encode_string(const char *src)
Encode string in base64 URL.
Definition utils.c:523
int ast_file_is_readable(const char *filename)
Test that a file exists and is readable by the effective user.
Definition utils.c:3143
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.
Definition utils.c:1807
#define DO_CRASH_NORETURN
Definition utils.h:757
ast_fd_flag_operation
Definition utils.h:1061
@ AST_FD_FLAG_SET
Definition utils.h:1062
@ AST_FD_FLAG_CLEAR
Definition utils.h:1063
int __ast_fd_set_flags(int fd, int flags, enum ast_fd_flag_operation op, const char *file, int lineno, const char *function)
Definition utils.c:3186
int ast_background_stacksize(void)
Definition utils.c:1652
static force_inline void ast_slinear_saturated_multiply_float(short *input, float *value)
Definition utils.h:523
char * ast_utils_which(const char *binary, char *fullpath, size_t fullpath_size)
Resolve a binary to a full pathname.
Definition utils.c:2810
char * ast_uri_encode(const char *string, char *outbuf, int buflen, struct ast_flags spec)
Turn text string to URI-encoded XX version.
Definition utils.c:723
#define ast_socket_nonblock(domain, type, protocol)
Create a non-blocking socket.
Definition utils.h:1113
void ast_set_default_eid(struct ast_eid *eid)
Fill in an ast_eid with the default eid of this machine.
Definition utils.c:3037
int ast_thread_user_interface_set(int is_user_interface)
Set the current thread's user interface status.
Definition utils.c:3269
int ast_eid_cmp(const struct ast_eid *eid1, const struct ast_eid *eid2)
Compare two EIDs.
Definition utils.c:3130
char * ast_escape_quoted(const char *string, char *outbuf, int buflen)
Escape characters found in a quoted string.
Definition utils.c:817
int ast_base64encode(char *dst, const unsigned char *src, int srclen, int max)
Encode data in base64.
Definition utils.c:406
static force_inline void ast_slinear_saturated_multiply(short *input, short *value)
Definition utils.h:510
int ast_wait_for_input(int fd, int ms)
Definition utils.c:1734
int ast_parse_digest(const char *digest, struct ast_http_digest *d, int request, int pedantic)
Parse digest authorization header.
Definition utils.c:2674
char * ast_base64decode_string(const char *src)
Same as ast_base64decode, but does the math for you and returns a decoded string.
Definition utils.c:323
int ast_crypt_validate(const char *key, const char *expected)
Asterisk wrapper around crypt(3) for validating passwords.
Definition crypt.c:136
char * ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
Convert an EID to a string.
Definition utils.c:2875
char * ast_base64encode_string(const char *src)
Same as ast_base64encode, but does hte math for you and returns an encoded string.
Definition utils.c:412
uint64_t __unsigned_int_flags_dummy64
Swap the upper and lower 32 bits of a big-endian 64-bit integer.
int ast_get_tid(void)
Get current thread ID.
Definition utils.c:2788
long int ast_random(void)
Definition utils.c:2348
int ast_mkdir(const char *path, int mode)
Recursively create directory path.
Definition utils.c:2515
const struct ast_flags ast_uri_http
Definition utils.c:719
int ast_utils_init(void)
Definition utils.c:2653
int ast_wait_for_output(int fd, int ms)
Definition utils.c:1744
char * ast_crypt(const char *key, const char *salt)
Asterisk wrapper around crypt(3).
Definition crypt.c:121
static force_inline void ast_slinear_saturated_add(short *input, short *value)
Definition utils.h:484
void ast_enable_packet_fragmentation(int sock)
Disable PMTU discovery on a socket.
Definition utils.c:2505
int ast_xml_escape(const char *string, char *outbuf, size_t buflen)
Escape reserved characters for use in XML.
Definition utils.c:900
int ast_base64url_decode(unsigned char *dst, const char *src, int max)
Decode data from base64 URL.
Definition utils.c:429
int ast_compare_versions(const char *version1, const char *version2)
Compare 2 major.minor.patch.extra version strings.
Definition utils.c:3160
void ast_register_thread(char *name)
Definition asterisk.c:421
int ast_eid_is_empty(const struct ast_eid *eid)
Check if EID is empty.
Definition utils.c:3135
int ast_base64url_encode(char *dst, const unsigned char *src, int srclen, int max)
Encode data in base64 URL.
Definition utils.c:518
void ast_unregister_thread(void *id)
Definition asterisk.c:437
void DO_CRASH_NORETURN ast_do_crash(void)
Force a crash if DO_CRASH is defined.
Definition utils.c:2840
char * ast_process_quotes_and_slashes(char *start, char find, char replace_with)
Process a string to find and replace characters.
Definition utils.c:2388
#define ast_pipe_nonblock(filedes)
Create a non-blocking pipe.
Definition utils.h:1130
char * ast_escape_semicolons(const char *string, char *outbuf, int buflen)
Escape semicolons found in a string.
Definition utils.c:847
int ast_base64encode_full(char *dst, const unsigned char *src, int srclen, int max, int linebreaks)
encode text to BASE64 coding
Definition utils.c:355
void ast_sha1_hash_uint(uint8_t *digest, const char *input)
Produces SHA1 hash based on input string, stored in uint8_t array.
Definition utils.c:284
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.
int ast_uri_verify_encoded(const char *string)
Verify if a string is valid as a URI component.
Definition utils.c:781
int ast_check_ipv6(void)
Test that an OS supports IPv6 Networking.
Definition utils.c:2828
char * ast_base64url_decode_string(const char *src)
Decode string from base64 URL.
Definition utils.c:450
struct ast_eid ast_eid_default
Global EID.
Definition options.c:94
int ast_str_to_eid(struct ast_eid *eid, const char *s)
Convert a string into an EID.
Definition utils.c:3113
void ast_uri_decode(char *s, struct ast_flags spec)
Decode URI, URN, URL (overwrite string)
Definition utils.c:762
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.
Definition utils.c:702
struct hostent * ast_gethostbyname(const char *host, struct ast_hostent *hp)
Thread-safe gethostbyname function to use in Asterisk.
Definition utils.c:199
void ast_replace_subargument_delimiter(char *s)
Replace '^' in a string with ','.
Definition utils.c:2379
void DO_CRASH_NORETURN __ast_assert_failed(int condition, const char *condition_str, const char *file, int line, const char *function)
Definition utils.c:2852
const struct ast_flags ast_uri_sip_user
Definition utils.c:721
void ast_md5_hash(char *output, const char *input)
Produces MD5 hash based on input string.
Definition utils.c:250
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)
Definition utils.c:1709
void ast_sha1_hash(char *output, const char *input)
Produces SHA1 hash based on input string.
Definition utils.c:266
static force_inline void ast_slinear_saturated_divide(short *input, short *value)
Definition utils.h:539
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)
Definition utils.c:1661
const struct ast_flags ast_uri_http_legacy
Definition utils.c:720
char * ast_crypt_encrypt(const char *key)
Asterisk wrapper around crypt(3) for encrypting passwords.
Definition crypt.c:190