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