diff options
Diffstat (limited to 'include/asterisk')
-rw-r--r-- | include/asterisk/ari.h | 3 | ||||
-rw-r--r-- | include/asterisk/astmm.h | 26 | ||||
-rw-r--r-- | include/asterisk/astobj2.h | 27 | ||||
-rw-r--r-- | include/asterisk/autoconfig.h.in | 29 | ||||
-rw-r--r-- | include/asterisk/calendar.h | 1 | ||||
-rw-r--r-- | include/asterisk/channel.h | 6 | ||||
-rw-r--r-- | include/asterisk/chanvars.h | 2 | ||||
-rw-r--r-- | include/asterisk/config.h | 2 | ||||
-rw-r--r-- | include/asterisk/format_cache.h | 5 | ||||
-rw-r--r-- | include/asterisk/hashtab.h | 14 | ||||
-rw-r--r-- | include/asterisk/heap.h | 4 | ||||
-rw-r--r-- | include/asterisk/http.h | 1 | ||||
-rw-r--r-- | include/asterisk/inline_api.h | 6 | ||||
-rw-r--r-- | include/asterisk/io.h | 10 | ||||
-rw-r--r-- | include/asterisk/lock.h | 34 | ||||
-rw-r--r-- | include/asterisk/named_locks.h | 10 | ||||
-rw-r--r-- | include/asterisk/opus.h | 51 | ||||
-rw-r--r-- | include/asterisk/res_fax.h | 22 | ||||
-rw-r--r-- | include/asterisk/res_pjsip.h | 62 | ||||
-rw-r--r-- | include/asterisk/sdp_srtp.h | 95 | ||||
-rw-r--r-- | include/asterisk/sorcery.h | 20 | ||||
-rw-r--r-- | include/asterisk/strings.h | 6 | ||||
-rw-r--r-- | include/asterisk/taskprocessor.h | 32 | ||||
-rw-r--r-- | include/asterisk/utils.h | 223 | ||||
-rw-r--r-- | include/asterisk/vector.h | 54 |
25 files changed, 521 insertions, 224 deletions
diff --git a/include/asterisk/ari.h b/include/asterisk/ari.h index 79b9516eb..4019e94e3 100644 --- a/include/asterisk/ari.h +++ b/include/asterisk/ari.h @@ -146,10 +146,11 @@ void ast_ari_invoke(struct ast_tcptls_session_instance *ser, * for unit testing. * * \param uri Requested URI, relative to the docs path. + * \param prefix prefix that prefixes all http requests * \param headers HTTP headers. * \param[out] response RESTful HTTP response. */ -void ast_ari_get_docs(const char *uri, struct ast_variable *headers, struct ast_ari_response *response); +void ast_ari_get_docs(const char *uri, const char *prefix, struct ast_variable *headers, struct ast_ari_response *response); /*! \brief Abstraction for reading/writing JSON to a WebSocket */ struct ast_ari_websocket_session; diff --git a/include/asterisk/astmm.h b/include/asterisk/astmm.h index 83c34bed3..e129dc034 100644 --- a/include/asterisk/astmm.h +++ b/include/asterisk/astmm.h @@ -174,35 +174,11 @@ void __ast_mm_init_phase_2(void); #endif -/* Provide our own definitions */ - -#define ast_calloc(a,b) \ - __ast_calloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) - -#define ast_calloc_cache(a,b) \ - __ast_calloc_cache(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) - -#define ast_malloc(a) \ - __ast_malloc(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) +/* Provide our own definition for ast_free */ #define ast_free(a) \ __ast_free(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) -#define ast_realloc(a,b) \ - __ast_realloc(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) - -#define ast_strdup(a) \ - __ast_strdup(a,__FILE__, __LINE__, __PRETTY_FUNCTION__) - -#define ast_strndup(a,b) \ - __ast_strndup(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) - -#define ast_asprintf(a, b, c...) \ - __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, a, b, c) - -#define ast_vasprintf(a,b,c) \ - __ast_vasprintf(a,b,c,__FILE__, __LINE__, __PRETTY_FUNCTION__) - #endif /* !STANDALONE */ #else diff --git a/include/asterisk/astobj2.h b/include/asterisk/astobj2.h index 0472c1b37..28ae73e87 100644 --- a/include/asterisk/astobj2.h +++ b/include/asterisk/astobj2.h @@ -368,6 +368,13 @@ enum ao2_alloc_opts { AO2_ALLOC_OPT_LOCK_NOLOCK = (2 << 0), /*! The ao2 object locking option field mask. */ AO2_ALLOC_OPT_LOCK_MASK = (3 << 0), + /*! + * \internal The ao2 object uses a separate object for locking. + * + * \note This option is used internally by ao2_alloc_with_lockobj and + * should never be passed directly to ao2_alloc. + */ + AO2_ALLOC_OPT_LOCK_OBJ = AO2_ALLOC_OPT_LOCK_MASK, }; /*! @@ -408,6 +415,26 @@ void *__ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn, unsigned in /*! @} */ +/*! + * \since 14.1.0 + * \brief Allocate and initialize an object with separate locking. + * + * \param data_size The sizeof() of the user-defined structure. + * \param destructor_fn The destructor function (can be NULL) + * \param lockobj A separate ao2 object that will provide locking. + * \param debug_msg An ao2 object debug tracing message. + * \return A pointer to user-data. + * + * \see \ref ao2_alloc for additional details. + * + * \note lockobj must be a valid AO2 object. + */ +#define ao2_alloc_with_lockobj(data_size, destructor_fn, lockobj, tag) \ + __ao2_alloc_with_lockobj((data_size), (destructor_fn), (lockobj), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__) + +void *__ao2_alloc_with_lockobj(size_t data_size, ao2_destructor_fn destructor_fn, void *lockobj, + const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result; + /*! \brief * Reference/unreference an object and return the old refcount. * diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in index b48257ec0..7a11ba3e4 100644 --- a/include/asterisk/autoconfig.h.in +++ b/include/asterisk/autoconfig.h.in @@ -145,6 +145,9 @@ /* Define to 1 if you have the `closefrom' function. */ #undef HAVE_CLOSEFROM +/* Define to 1 if you have the Codec 2 Audio Decoder/Encoder library. */ +#undef HAVE_CODEC2 + /* Define to 1 if you have the Corosync library. */ #undef HAVE_COROSYNC @@ -583,28 +586,36 @@ /* Define if your system has PJPROJECT_BUNDLED */ #undef HAVE_PJPROJECT_BUNDLED -/* Define if your system has pjsip_dlg_create_uas_and_inc_lock declared. */ +/* Define to 1 if PJPROJECT has the PJSIP Dialog Create UAS with Incremented + Lock feature. */ #undef HAVE_PJSIP_DLG_CREATE_UAS_AND_INC_LOCK -/* Define if your system has PJSIP_EVSUB_GRP_LOCK */ +/* Define to 1 if PJPROJECT has the PJSIP EVSUB Group Lock support feature. */ #undef HAVE_PJSIP_EVSUB_GRP_LOCK -/* Define if your system has pjsip_endpt_set_ext_resolver declared. */ +/* Define to 1 if PJPROJECT has the PJSIP External Resolver Support feature. + */ #undef HAVE_PJSIP_EXTERNAL_RESOLVER -/* Define if your system has pjsip_get_dest_info declared. */ +/* Define to 1 if PJPROJECT has the pjsip_get_dest_info support feature. */ #undef HAVE_PJSIP_GET_DEST_INFO +/* Define to 1 if PJPROJECT has the PJSIP INVITE Session Reference Count + support feature. */ +#undef HAVE_PJSIP_INV_SESSION_REF + /* Define if your system has the PJSIP_REPLACE_MEDIA_STREAM headers. */ #undef HAVE_PJSIP_REPLACE_MEDIA_STREAM /* Define if your system has the PJSIP_TLS_TRANSPORT_PROTO headers. */ #undef HAVE_PJSIP_TLS_TRANSPORT_PROTO -/* Define if your system has pj_ssl_cert_load_from_files2 declared. */ +/* Define to 1 if PJPROJECT has the pj_ssl_cert_load_from_files2 support + feature. */ #undef HAVE_PJ_SSL_CERT_LOAD_FROM_FILES2 -/* Define if your system has pjsip_tsx_create_uac2 declared. */ +/* Define to 1 if PJPROJECT has the PJSIP Transaction Group Lock Support + feature. */ #undef HAVE_PJ_TRANSACTION_GRP_LOCK /* Define to 1 if your system defines IP_PKTINFO. */ @@ -1021,6 +1032,9 @@ /* Define to 1 if you have the <syslog.h> header file. */ #undef HAVE_SYSLOG_H +/* Define if your system has the SYSTEMD libraries. */ +#undef HAVE_SYSTEMD + /* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'. */ #undef HAVE_SYS_DIR_H @@ -1108,6 +1122,9 @@ /* Define to 1 if you have the unbound library. */ #undef HAVE_UNBOUND +/* Define if your system has UNBOUND_VERSION_MAJOR declared. */ +#undef HAVE_UNBOUND_CONST_PARAMS + /* Define to 1 if you have the <unistd.h> header file. */ #undef HAVE_UNISTD_H diff --git a/include/asterisk/calendar.h b/include/asterisk/calendar.h index da4af01ef..e9dcd8809 100644 --- a/include/asterisk/calendar.h +++ b/include/asterisk/calendar.h @@ -129,6 +129,7 @@ struct ast_calendar { int autoreminder; /*!< If set, override any calendar_tech specific notification times and use this time (in mins) */ int notify_waittime; /*!< Maxiumum time to allow for a notification attempt */ int refresh; /*!< When to refresh the calendar events */ + int fetch_again_at_reload; /*!< To reload the calendar content when the module is reloaded */ int timeframe; /*!< Span (in mins) of calendar data to pull with each request */ pthread_t thread; /*!< The thread that the calendar is loaded/updated in */ ast_cond_t unload; diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h index 94f72b879..df752c902 100644 --- a/include/asterisk/channel.h +++ b/include/asterisk/channel.h @@ -2559,7 +2559,11 @@ static inline int ast_fdisset(struct pollfd *pfds, int fd, int maximum, int *sta return 0; } -/*! \brief Retrieves the current T38 state of a channel */ +/*! + * \brief Retrieves the current T38 state of a channel + * + * \note Absolutely _NO_ channel locks should be held before calling this function. + */ static inline enum ast_t38_state ast_channel_get_t38_state(struct ast_channel *chan) { enum ast_t38_state state = T38_STATE_UNAVAILABLE; diff --git a/include/asterisk/chanvars.h b/include/asterisk/chanvars.h index 3693e2a3a..2040c7b65 100644 --- a/include/asterisk/chanvars.h +++ b/include/asterisk/chanvars.h @@ -35,7 +35,7 @@ AST_LIST_HEAD_NOLOCK(varshead, ast_var_t); struct varshead *ast_var_list_create(void); void ast_var_list_destroy(struct varshead *head); -#ifdef MALLOC_DEBUG +#ifdef __AST_DEBUG_MALLOC struct ast_var_t *_ast_var_assign(const char *name, const char *value, const char *file, int lineno, const char *function); #define ast_var_assign(a,b) _ast_var_assign(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__) #else diff --git a/include/asterisk/config.h b/include/asterisk/config.h index 287635a8e..4944a3af2 100644 --- a/include/asterisk/config.h +++ b/include/asterisk/config.h @@ -907,7 +907,7 @@ void ast_category_destroy(struct ast_category *cat); struct ast_variable *ast_category_detach_variables(struct ast_category *cat); void ast_category_rename(struct ast_category *cat, const char *name); -#ifdef MALLOC_DEBUG +#ifdef __AST_DEBUG_MALLOC struct ast_variable *_ast_variable_new(const char *name, const char *value, const char *filename, const char *file, const char *function, int lineno); #define ast_variable_new(name, value, filename) _ast_variable_new(name, value, filename, __FILE__, __PRETTY_FUNCTION__, __LINE__) #else diff --git a/include/asterisk/format_cache.h b/include/asterisk/format_cache.h index 3894ad21b..6099c59ea 100644 --- a/include/asterisk/format_cache.h +++ b/include/asterisk/format_cache.h @@ -209,6 +209,11 @@ extern struct ast_format *ast_format_siren7; extern struct ast_format *ast_format_opus; /*! + * \brief Built-in cached Codec 2 format. + */ +extern struct ast_format *ast_format_codec2; + +/*! * \brief Built-in cached t140 format. */ extern struct ast_format *ast_format_t140; diff --git a/include/asterisk/hashtab.h b/include/asterisk/hashtab.h index 17eff7048..cfe035b28 100644 --- a/include/asterisk/hashtab.h +++ b/include/asterisk/hashtab.h @@ -251,7 +251,7 @@ unsigned int ast_hashtab_hash_short(const short num); * \param hash a func ptr to do the hashing * \param do_locking use locks to guarantee safety of iterators/insertion/deletion -- real simpleminded right now */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC struct ast_hashtab * _ast_hashtab_create(int initial_buckets, int (*compare)(const void *a, const void *b), int (*resize)(struct ast_hashtab *), @@ -294,7 +294,7 @@ void ast_hashtab_destroy( struct ast_hashtab *tab, void (*objdestroyfunc)(void * * \retval 1 on success * \retval 0 if there's a problem */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC int _ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj, const char *file, int lineno, const char *func); #define ast_hashtab_insert_immediate(a,b) _ast_hashtab_insert_immediate(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__) #else @@ -311,7 +311,7 @@ int ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj); * \retval 1 on success * \retval 0 if there's a problem */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC int _ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj, unsigned int h, const char *file, int lineno, const char *func); #define ast_hashtab_insert_immediate_bucket(a,b,c) _ast_hashtab_insert_immediate_bucket(a, b, c, __FILE__, __LINE__, __PRETTY_FUNCTION__) #else @@ -324,7 +324,7 @@ int ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj * \retval 1 on success * \retval 0 if there's a problem, or it's already there. */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC int _ast_hashtab_insert_safe(struct ast_hashtab *tab, const void *obj, const char *file, int lineno, const char *func); #define ast_hashtab_insert_safe(a,b) _ast_hashtab_insert_safe(a,b,__FILE__, __LINE__, __PRETTY_FUNCTION__) #else @@ -362,7 +362,7 @@ int ast_hashtab_size( struct ast_hashtab *tab); int ast_hashtab_capacity( struct ast_hashtab *tab); /*! \brief Return a copy of the hash table */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC struct ast_hashtab *_ast_hashtab_dup(struct ast_hashtab *tab, void *(*obj_dup_func)(const void *obj), const char *file, int lineno, const char *func); #define ast_hashtab_dup(a,b) _ast_hashtab_dup(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__) #else @@ -370,7 +370,7 @@ struct ast_hashtab *ast_hashtab_dup(struct ast_hashtab *tab, void *(*obj_dup_fun #endif /*! \brief Gives an iterator to hastable */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC struct ast_hashtab_iter *_ast_hashtab_start_traversal(struct ast_hashtab *tab, const char *file, int lineno, const char *func); #define ast_hashtab_start_traversal(a) _ast_hashtab_start_traversal(a,__FILE__,__LINE__,__PRETTY_FUNCTION__) #else @@ -395,7 +395,7 @@ void *ast_hashtab_remove_this_object(struct ast_hashtab *tab, void *obj); /* ------------------ */ /*! \brief Gives an iterator to hastable */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC struct ast_hashtab_iter *_ast_hashtab_start_write_traversal(struct ast_hashtab *tab, const char *file, int lineno, const char *func); #define ast_hashtab_start_write_traversal(a) _ast_hashtab_start_write_traversal(a,__FILE__,__LINE__,__PRETTY_FUNCTION__) #else diff --git a/include/asterisk/heap.h b/include/asterisk/heap.h index a868ac589..728327936 100644 --- a/include/asterisk/heap.h +++ b/include/asterisk/heap.h @@ -97,7 +97,7 @@ typedef int (*ast_heap_cmp_fn)(void *elm1, void *elm2); * \return An instance of a max heap * \since 1.6.1 */ -#ifdef MALLOC_DEBUG +#ifdef __AST_DEBUG_MALLOC struct ast_heap *_ast_heap_create(unsigned int init_height, ast_heap_cmp_fn cmp_fn, ssize_t index_offset, const char *file, int lineno, const char *func); #define ast_heap_create(a,b,c) _ast_heap_create(a,b,c,__FILE__,__LINE__,__PRETTY_FUNCTION__) @@ -126,7 +126,7 @@ struct ast_heap *ast_heap_destroy(struct ast_heap *h); * \retval non-zero failure * \since 1.6.1 */ -#ifdef MALLOC_DEBUG +#ifdef __AST_DEBUG_MALLOC int _ast_heap_push(struct ast_heap *h, void *elm, const char *file, int lineno, const char *func); #define ast_heap_push(a,b) _ast_heap_push(a,b,__FILE__,__LINE__,__PRETTY_FUNCTION__) #else diff --git a/include/asterisk/http.h b/include/asterisk/http.h index bb8973dce..d5f54cc65 100644 --- a/include/asterisk/http.h +++ b/include/asterisk/http.h @@ -101,6 +101,7 @@ struct ast_http_uri { AST_LIST_ENTRY(ast_http_uri) entry; const char *description; const char *uri; + const char *prefix; ast_http_callback callback; unsigned int has_subtree:1; /*! Structure is malloc'd */ diff --git a/include/asterisk/inline_api.h b/include/asterisk/inline_api.h index 291a83828..5f7a43bdc 100644 --- a/include/asterisk/inline_api.h +++ b/include/asterisk/inline_api.h @@ -33,7 +33,7 @@ copies of the function body are not built in different modules. However, since this doesn't work for clang, we go with 'static' anyway and hope for the best! - - when LOW_MEMORY is defined, inlining should be disabled + - when DISABLE_INLINE is defined, inlining should be disabled completely, even if the compiler is configured to support it The AST_INLINE_API macro allows this to happen automatically, when @@ -45,7 +45,7 @@ including the header file */ -#if !defined(LOW_MEMORY) && !defined(DISABLE_INLINE) +#if !defined(DISABLE_INLINE) #if !defined(AST_API_MODULE) #if defined(__clang__) || defined(__GNUC_STDC_INLINE__) @@ -57,7 +57,7 @@ #define AST_INLINE_API(hdr, body) hdr; hdr body #endif -#else /* defined(LOW_MEMORY) */ +#else /* defined(DISABLE_INLINE) */ #if !defined(AST_API_MODULE) #define AST_INLINE_API(hdr, body) hdr; diff --git a/include/asterisk/io.h b/include/asterisk/io.h index 2bddd3780..6ee8450bd 100644 --- a/include/asterisk/io.h +++ b/include/asterisk/io.h @@ -139,6 +139,16 @@ int ast_restore_tty(int fd, int oldstatus); int ast_get_termcols(int fd); +/*! + * \brief a wrapper for sd_notify(): notify systemd of any state changes. + * \param state a string that states the changes. See sd_notify(3). + * The wrapper does nothing if systemd ('s development headers) was not + * detected on the system. + * \returns >=0 on success, negative value on error. + */ +int ast_sd_notify(const char *state); + + #if defined(__cplusplus) || defined(c_plusplus) } #endif diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h index 35a244b5b..5b6817f6b 100644 --- a/include/asterisk/lock.h +++ b/include/asterisk/lock.h @@ -113,7 +113,7 @@ struct ast_lock_track { int lineno[AST_MAX_REENTRANCY]; int reentrancy; const char *func[AST_MAX_REENTRANCY]; - pthread_t thread[AST_MAX_REENTRANCY]; + pthread_t thread_id[AST_MAX_REENTRANCY]; #ifdef HAVE_BKTR struct ast_bt backtrace[AST_MAX_REENTRANCY]; #endif @@ -240,7 +240,6 @@ enum ast_lock_type { * lock info struct. The lock is marked as pending as the thread is waiting * on the lock. ast_mark_lock_acquired() will mark it as held by this thread. */ -#if !defined(LOW_MEMORY) #ifdef HAVE_BKTR void ast_store_lock_info(enum ast_lock_type type, const char *filename, int line_num, const char *func, const char *lock_name, void *lock_addr, struct ast_bt *bt); @@ -249,32 +248,15 @@ void ast_store_lock_info(enum ast_lock_type type, const char *filename, int line_num, const char *func, const char *lock_name, void *lock_addr); #endif /* HAVE_BKTR */ -#else - -#ifdef HAVE_BKTR -#define ast_store_lock_info(I,DONT,CARE,ABOUT,THE,PARAMETERS,BUD) -#else -#define ast_store_lock_info(I,DONT,CARE,ABOUT,THE,PARAMETERS) -#endif /* HAVE_BKTR */ -#endif /* !defined(LOW_MEMORY) */ - /*! * \brief Mark the last lock as acquired */ -#if !defined(LOW_MEMORY) void ast_mark_lock_acquired(void *lock_addr); -#else -#define ast_mark_lock_acquired(ignore) -#endif /*! * \brief Mark the last lock as failed (trylock) */ -#if !defined(LOW_MEMORY) void ast_mark_lock_failed(void *lock_addr); -#else -#define ast_mark_lock_failed(ignore) -#endif /*! * \brief remove lock info for the current thread @@ -282,7 +264,6 @@ void ast_mark_lock_failed(void *lock_addr); * this gets called by ast_mutex_unlock so that information on the lock can * be removed from the current thread's lock info struct. */ -#if !defined(LOW_MEMORY) #ifdef HAVE_BKTR void ast_remove_lock_info(void *lock_addr, struct ast_bt *bt); #else @@ -290,15 +271,6 @@ void ast_remove_lock_info(void *lock_addr); #endif /* HAVE_BKTR */ void ast_suspend_lock_info(void *lock_addr); void ast_restore_lock_info(void *lock_addr); -#else -#ifdef HAVE_BKTR -#define ast_remove_lock_info(ignore,me) -#else -#define ast_remove_lock_info(ignore) -#endif /* HAVE_BKTR */ -#define ast_suspend_lock_info(ignore); -#define ast_restore_lock_info(ignore); -#endif /* !defined(LOW_MEMORY) */ /*! * \brief log info for the current lock with ast_log(). @@ -333,11 +305,7 @@ struct ast_str *ast_dump_locks(void); * this gets called during deadlock avoidance, so that the information may * be preserved as to what location originally acquired the lock. */ -#if !defined(LOW_MEMORY) int ast_find_lock_info(void *lock_addr, char *filename, size_t filename_size, int *lineno, char *func, size_t func_size, char *mutex_name, size_t mutex_name_size); -#else -#define ast_find_lock_info(a,b,c,d,e,f,g,h) -1 -#endif /*! * \brief Unlock a lock briefly diff --git a/include/asterisk/named_locks.h b/include/asterisk/named_locks.h index 0fe07d992..1959841d0 100644 --- a/include/asterisk/named_locks.h +++ b/include/asterisk/named_locks.h @@ -48,7 +48,7 @@ * To use a named lock: * Call ast_named_lock_get with the appropriate keyspace and key. * Use the standard ao2 lock/unlock functions as needed. - * Call ast_named_lock_put when you're finished with it. + * Call ao2_cleanup when you're finished with it. */ /*! @@ -66,9 +66,6 @@ struct ast_named_lock; struct ast_named_lock *__ast_named_lock_get(const char *filename, int lineno, const char *func, enum ast_named_lock_type lock_type, const char *keyspace, const char *key); -int __ast_named_lock_put(const char *filename, int lineno, const char *func, - struct ast_named_lock *lock); - /*! * \brief Geta named lock handle * \since 13.9.0 @@ -92,11 +89,8 @@ int __ast_named_lock_put(const char *filename, int lineno, const char *func, * \since 13.9.0 * * \param lock The pointer to the ast_named_lock structure returned by ast_named_lock_get - * \retval 0 Success - * \retval -1 Failure */ -#define ast_named_lock_put(lock) \ - __ast_named_lock_put(__FILE__, __LINE__, __PRETTY_FUNCTION__, lock) +#define ast_named_lock_put(lock) ao2_cleanup(lock) /*! * @} diff --git a/include/asterisk/opus.h b/include/asterisk/opus.h index 0fbcfa10e..6d2cdcf8c 100644 --- a/include/asterisk/opus.h +++ b/include/asterisk/opus.h @@ -18,24 +18,47 @@ /*! * \file - * \brief Opus Format Attributes (http://tools.ietf.org/html/draft-ietf-payload-rtp-opus) + * \brief Codec opus externals and format attributes * - * \author Lorenzo Miniero <lorenzo@meetecho.com> + * RFC - https://tools.ietf.org/rfc/rfc7587.txt */ #ifndef _AST_FORMAT_OPUS_H_ #define _AST_FORMAT_OPUS_H_ -/*! Opus format attribute key value pairs, all are accessible through ast_format_get_value()*/ -enum opus_attr_keys { - OPUS_ATTR_KEY_MAX_BITRATE, /*! value is an int (6000-510000 in spec). */ - OPUS_ATTR_KEY_MAX_PLAYRATE, /*! value is an int (8000-48000), maximum output rate the receiver can render. */ - OPUS_ATTR_KEY_MINPTIME, /*! value is an int (3-120 in spec, 10-60 in format.c), decoder's minimum length of time in milliseconds. */ - OPUS_ATTR_KEY_STEREO, /*! value is an int, 1 prefer receiving stereo, 0 prefer mono. */ - OPUS_ATTR_KEY_CBR, /*! value is an int, 1 use constant bitrate, 0 use variable bitrate. */ - OPUS_ATTR_KEY_FEC, /*! value is an int, 1 encode with FEC, 0 do not use FEC. */ - OPUS_ATTR_KEY_DTX, /*! value is an int, 1 dtx is enabled, 0 dtx not enabled. */ - OPUS_ATTR_KEY_SPROP_CAPTURE_RATE, /*! value is an int (8000-48000), likely input rate we're going to produce. */ - OPUS_ATTR_KEY_SPROP_STEREO, /*! value is an int, 1 likely to send stereo, 0 likely to send mono. */ -}; +/*! \brief Maximum sampling rate an endpoint is capable of receiving */ +#define CODEC_OPUS_ATTR_MAX_PLAYBACK_RATE "maxplaybackrate" +/*! \brief An alias for maxplaybackrate (used in older versions) */ +#define CODEC_OPUS_ATTR_MAX_CODED_AUDIO_BANDWIDTH "maxcodedaudiobandwidth" +/*! \brief Maximum sampling rate an endpoint is capable of sending */ +#define CODEC_OPUS_ATTR_SPROP_MAX_CAPTURE_RATE "sprop-maxcapturerate" +/*! \brief Maximum duration of packet (in milliseconds) */ +#define CODEC_OPUS_ATTR_MAX_PTIME "maxptime" +/*! \brief Duration of packet (in milliseconds) */ +#define CODEC_OPUS_ATTR_PTIME "ptime" +/*! \brief Maximum average received bit rate (in bits per second) */ +#define CODEC_OPUS_ATTR_MAX_AVERAGE_BITRATE "maxaveragebitrate" +/*! \brief Decode stereo (1) vs mono (0) */ +#define CODEC_OPUS_ATTR_STEREO "stereo" +/*! \brief Likeliness of sender producing stereo (1) vs mono (0) */ +#define CODEC_OPUS_ATTR_SPROP_STEREO "sprop-stereo" +/*! \brief Decoder prefers a constant (1) vs variable (0) bitrate */ +#define CODEC_OPUS_ATTR_CBR "cbr" +/*! \brief Use forward error correction (1) or not (0) */ +#define CODEC_OPUS_ATTR_FEC "useinbandfec" +/*! \brief Use discontinuous transmission (1) or not (0) */ +#define CODEC_OPUS_ATTR_DTX "usedtx" +/*! \brief Custom data object */ +#define CODEC_OPUS_ATTR_DATA "data" + +/*! \brief Default attribute values */ +#define CODEC_OPUS_DEFAULT_SAMPLE_RATE 48000 +#define CODEC_OPUS_DEFAULT_MAX_PLAYBACK_RATE 48000 +#define CODEC_OPUS_DEFAULT_MAX_PTIME 120 +#define CODEC_OPUS_DEFAULT_PTIME 20 +#define CODEC_OPUS_DEFAULT_BITRATE -1000 /* OPUS_AUTO */ +#define CODEC_OPUS_DEFAULT_CBR 0 +#define CODEC_OPUS_DEFAULT_FEC 0 +#define CODEC_OPUS_DEFAULT_DTX 0 +#define CODEC_OPUS_DEFAULT_STEREO 0 #endif /* _AST_FORMAT_OPUS_H */ diff --git a/include/asterisk/res_fax.h b/include/asterisk/res_fax.h index 5119bfa6c..e88d8002f 100644 --- a/include/asterisk/res_fax.h +++ b/include/asterisk/res_fax.h @@ -20,16 +20,16 @@ #ifndef _ASTERISK_RES_FAX_H #define _ASTERISK_RES_FAX_H -#include <asterisk.h> -#include <asterisk/lock.h> -#include <asterisk/linkedlists.h> -#include <asterisk/module.h> -#include <asterisk/utils.h> -#include <asterisk/options.h> -#include <asterisk/frame.h> -#include <asterisk/cli.h> -#include <asterisk/stringfields.h> -#include <asterisk/manager.h> +#include "asterisk.h" +#include "asterisk/lock.h" +#include "asterisk/linkedlists.h" +#include "asterisk/module.h" +#include "asterisk/utils.h" +#include "asterisk/options.h" +#include "asterisk/frame.h" +#include "asterisk/cli.h" +#include "asterisk/stringfields.h" +#include "asterisk/manager.h" /*! \brief capabilities for res_fax to locate a fax technology module */ enum ast_fax_capabilities { @@ -187,6 +187,8 @@ struct ast_fax_session_details { int faxdetect_timeout; /*! flags used for fax detection */ int faxdetect_flags; + /*! Non-zero if T.38 is negotiated */ + int is_t38_negotiated; }; struct ast_fax_tech; diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h index 9bb2a82c5..92bdabb66 100644 --- a/include/asterisk/res_pjsip.h +++ b/include/asterisk/res_pjsip.h @@ -755,6 +755,10 @@ struct ast_sip_endpoint { struct ast_acl_list *contact_acl; /*! The number of seconds into call to disable fax detection. (0 = disabled) */ unsigned int faxdetect_timeout; + /*! Override the user on the outgoing Contact header with this value. */ + char *contact_user; + /*! Whether to response SDP offer with single most preferred codec. */ + unsigned int preferred_codec_only; }; /*! @@ -2417,6 +2421,64 @@ int ast_sip_register_supplement(struct ast_sip_supplement *supplement); void ast_sip_unregister_supplement(struct ast_sip_supplement *supplement); /*! + * \brief Retrieve the global MWI taskprocessor high water alert trigger level. + * + * \since 13.12.0 + * + * \retval the system MWI taskprocessor high water alert trigger level + */ +unsigned int ast_sip_get_mwi_tps_queue_high(void); + +/*! + * \brief Retrieve the global MWI taskprocessor low water clear alert level. + * + * \since 13.12.0 + * + * \retval the system MWI taskprocessor low water clear alert level + */ +int ast_sip_get_mwi_tps_queue_low(void); + +/*! + * \brief Retrieve the global setting 'disable sending unsolicited mwi on startup'. + * \since 13.12.0 + * + * \retval non zero if disable. + */ +unsigned int ast_sip_get_mwi_disable_initial_unsolicited(void); + +/*! + * \brief Retrieve the global setting 'ignore_uri_user_options'. + * \since 13.12.0 + * + * \retval non zero if ignore the user field options. + */ +unsigned int ast_sip_get_ignore_uri_user_options(void); + +/*! + * \brief Truncate the URI user field options string if enabled. + * \since 13.12.0 + * + * \param str URI user field string to truncate if enabled + * + * \details + * We need to be able to handle URI's looking like + * "sip:1235557890;phone-context=national@x.x.x.x;user=phone" + * + * Where the URI user field is: + * "1235557890;phone-context=national" + * + * When truncated the string will become: + * "1235557890" + */ +#define AST_SIP_USER_OPTIONS_TRUNCATE_CHECK(str) \ + do { \ + char *__semi = strchr((str), ';'); \ + if (__semi && ast_sip_get_ignore_uri_user_options()) { \ + *__semi = '\0'; \ + } \ + } while (0) + +/*! * \brief Retrieve the system debug setting (yes|no|host). * * \note returned string needs to be de-allocated by caller. diff --git a/include/asterisk/sdp_srtp.h b/include/asterisk/sdp_srtp.h index 5d8f0e7d1..cf89fa9e0 100644 --- a/include/asterisk/sdp_srtp.h +++ b/include/asterisk/sdp_srtp.h @@ -63,6 +63,100 @@ struct ast_sdp_srtp *ast_sdp_srtp_alloc(void); */ void ast_sdp_srtp_destroy(struct ast_sdp_srtp *srtp); +/*! \brief Destroy a previously allocated ast_sdp_crypto struct */ +typedef void (*sdp_crypto_destroy_cb)(struct ast_sdp_crypto *crypto); + +/*! + * \brief Initialize and return an ast_sdp_crypto struct + * + * \details + * This function allocates a new ast_sdp_crypto struct and initializes its values + * + * \retval NULL on failure + * \retval a pointer to a new ast_sdp_crypto structure + */ +typedef struct ast_sdp_crypto *(*sdp_crypto_alloc_cb)(void); + +/*! + * \brief Generate an SRTP a=crypto offer + * + * \details + * The offer is stored on the ast_sdp_crypto struct in a_crypto + * + * \param crypto A valid ast_sdp_crypto struct + * \param taglen Length + * + * \retval 0 success + * \retval nonzero failure + */ +typedef int (*sdp_crypto_build_offer_cb)(struct ast_sdp_crypto *crypto, int taglen); + +/*! + * \brief Parse the a=crypto line from SDP and set appropriate values on the + * ast_sdp_crypto struct. + * + * The attribute line should already have "a=crypto:" removed. + * + * \param p A valid ast_sdp_crypto struct + * \param attr the a:crypto line from SDP + * \param rtp The rtp instance associated with the SDP being parsed + * \param srtp SRTP structure + * + * \retval 0 success + * \retval nonzero failure + */ +typedef int (*sdp_crypto_parse_offer_cb)(struct ast_rtp_instance *rtp, struct ast_sdp_srtp *srtp, const char *attr); + +/*! + * \brief Get the crypto attribute line for the srtp structure + * + * \details + * The attribute line does not contain the initial "a=crypto:" and does + * not terminate with "\r\n". + * + * \param srtp The ast_sdp_srtp structure for which to get an attribute line + * \param dtls_enabled Whether this connection is encrypted with datagram TLS + * \param default_taglen_32 Whether to default to a tag length of 32 instead of 80 + * + * \retval An attribute line containing cryptographic information + * \retval NULL if the srtp structure does not require an attribute line containing crypto information + */ +typedef const char *(*sdp_srtp_get_attr_cb)(struct ast_sdp_srtp *srtp, int dtls_enabled, int default_taglen_32); + +struct ast_sdp_crypto_api { + /*! Destroy a crypto struct */ + sdp_crypto_destroy_cb dtor; + /*! Allocate a crypto struct */ + sdp_crypto_alloc_cb alloc; + /*! Build a SDP a=crypto offer line parameter string */ + sdp_crypto_build_offer_cb build_offer; + /*! Parse a SDP a=crypto offer line parameter string */ + sdp_crypto_parse_offer_cb parse_offer; + /*! Get the SDP a=crypto offer line parameter string */ + sdp_srtp_get_attr_cb get_attr; +}; + +/*! + * \brief Register SDP SRTP crypto processing routines. + * \since 14.0.0 + * + * \param api Callbacks to register. + * + * \retval 0 on success. + * \retval -1 on error. + */ +int ast_sdp_crypto_register(struct ast_sdp_crypto_api *api); + +/*! + * \brief Unregister SDP SRTP crypto processing routines. + * \since 14.0.0 + * + * \param api Callbacks to unregister. + * + * \return Nothing + */ +void ast_sdp_crypto_unregister(struct ast_sdp_crypto_api *api); + /*! \brief Initialize an return an ast_sdp_crypto struct * * \details @@ -104,7 +198,6 @@ int ast_sdp_crypto_process(struct ast_rtp_instance *rtp, struct ast_sdp_srtp *sr */ int ast_sdp_crypto_build_offer(struct ast_sdp_crypto *p, int taglen); - /*! \brief Get the crypto attribute line for the srtp structure * * The attribute line does not contain the initial "a=crypto:" and does diff --git a/include/asterisk/sorcery.h b/include/asterisk/sorcery.h index 23219ec41..896633816 100644 --- a/include/asterisk/sorcery.h +++ b/include/asterisk/sorcery.h @@ -988,10 +988,30 @@ int ast_sorcery_changeset_create(const struct ast_variable *original, const stru * * \retval non-NULL success * \retval NULL failure + * + * \note The returned object does not support AO2 locking. */ void *ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor); /*! + * \since 14.1.0 + * \brief Allocate a generic sorcery capable object with locking. + * + * \details Sorcery objects may be replaced with new allocations during reloads. + * If locking is required on sorcery objects it must be shared between the old + * object and the new one. lockobj can be any AO2 object with locking enabled, + * but in most cases named locks should be used to provide stable locking. + * + * \param size Size of the object + * \param destructor Optional destructor function + * \param lockobj An AO2 object that will provide locking. + * + * \retval non-NULL success + * \retval NULL failure + */ +void *ast_sorcery_lockable_alloc(size_t size, ao2_destructor_fn destructor, void *lockobj); + +/*! * \brief Allocate an object * * \param sorcery Pointer to a sorcery structure diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h index 2ca75a69c..eb5b4e43c 100644 --- a/include/asterisk/strings.h +++ b/include/asterisk/strings.h @@ -616,7 +616,7 @@ int ast_regex_string_to_regex_pattern(const char *regex_string, struct ast_str * * \note The result of this function is dynamically allocated memory, and must * be free()'d after it is no longer needed. */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC #define ast_str_create(a) _ast_str_create(a,__FILE__,__LINE__,__PRETTY_FUNCTION__) AST_INLINE_API( struct ast_str * attribute_malloc _ast_str_create(size_t init_len, @@ -771,7 +771,7 @@ char *ast_str_truncate(struct ast_str *buf, ssize_t len), /*! * Make space in a new string (e.g. to read in data from a file) */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC AST_INLINE_API( int _ast_str_make_space(struct ast_str **buf, size_t new_len, const char *file, int lineno, const char *function), { @@ -964,7 +964,7 @@ enum { * through calling one of the other functions or macros defined in this * file. */ -#if (defined(MALLOC_DEBUG) && !defined(STANDALONE)) +#ifdef __AST_DEBUG_MALLOC int __attribute__((format(printf, 4, 0))) __ast_debug_str_helper(struct ast_str **buf, ssize_t max_len, int append, const char *fmt, va_list ap, const char *file, int lineno, const char *func); #define __ast_str_helper(a,b,c,d,e) __ast_debug_str_helper(a,b,c,d,e,__FILE__,__LINE__,__PRETTY_FUNCTION__) diff --git a/include/asterisk/taskprocessor.h b/include/asterisk/taskprocessor.h index e51122269..7c79036b3 100644 --- a/include/asterisk/taskprocessor.h +++ b/include/asterisk/taskprocessor.h @@ -242,6 +242,38 @@ int ast_taskprocessor_push_local(struct ast_taskprocessor *tps, int (*task_exe)(struct ast_taskprocessor_local *local), void *datap); /*! + * \brief Indicate the taskprocessor is suspended. + * + * \since 13.12.0 + * + * \param tps Task processor. + * \retval 0 success + * \retval -1 failure + */ +int ast_taskprocessor_suspend(struct ast_taskprocessor *tps); + +/*! + * \brief Indicate the taskprocessor is unsuspended. + * + * \since 13.12.0 + * + * \param tps Task processor. + * \retval 0 success + * \retval -1 failure + */ +int ast_taskprocessor_unsuspend(struct ast_taskprocessor *tps); + +/*! + * \brief Get the task processor suspend status + * + * \since 13.12.0 + * + * \param tps Task processor. + * \retval non-zero if the task processor is suspended + */ +int ast_taskprocessor_is_suspended(struct ast_taskprocessor *tps); + +/*! * \brief Pop a task off the taskprocessor and execute it. * * \since 12.0.0 diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h index c311e9cd5..2378c6971 100644 --- a/include/asterisk/utils.h +++ b/include/asterisk/utils.h @@ -423,13 +423,12 @@ int ast_careful_fwrite(FILE *f, int fd, const char *s, size_t len, int timeoutms * Thread management support (should be moved to lock.h or a different header) */ -#define AST_STACKSIZE (((sizeof(void *) * 8 * 8) - 16) * 1024) +#define AST_STACKSIZE (((sizeof(void *) * 8 * 8) - 16) * 1024) +#define AST_STACKSIZE_LOW (((sizeof(void *) * 8 * 2) - 16) * 1024) -#if defined(LOW_MEMORY) -#define AST_BACKGROUND_STACKSIZE (((sizeof(void *) * 8 * 2) - 16) * 1024) -#else -#define AST_BACKGROUND_STACKSIZE AST_STACKSIZE -#endif +int ast_background_stacksize(void); + +#define AST_BACKGROUND_STACKSIZE ast_background_stacksize() void ast_register_thread(char *name); void ast_unregister_thread(void *id); @@ -533,19 +532,8 @@ long int ast_random(void); ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file) #endif -/*! - * \brief A wrapper for malloc() - * - * ast_malloc() is a wrapper for malloc() that will generate an Asterisk log - * message in the case that the allocation fails. - * - * The argument and return value are the same as malloc() - */ -#define ast_malloc(len) \ - _ast_malloc((len), __FILE__, __LINE__, __PRETTY_FUNCTION__) - AST_INLINE_API( -void * attribute_malloc _ast_malloc(size_t len, const char *file, int lineno, const char *func), +void * attribute_malloc __ast_malloc(size_t len, const char *file, int lineno, const char *func), { void *p; @@ -559,19 +547,8 @@ void * attribute_malloc _ast_malloc(size_t len, const char *file, int lineno, co } ) -/*! - * \brief A wrapper for calloc() - * - * ast_calloc() is a wrapper for calloc() that will generate an Asterisk log - * message in the case that the allocation fails. - * - * The arguments and return value are the same as calloc() - */ -#define ast_calloc(num, len) \ - _ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) - AST_INLINE_API( -void * attribute_malloc _ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func), +void * attribute_malloc __ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func), { void *p; @@ -585,6 +562,98 @@ void * attribute_malloc _ast_calloc(size_t num, size_t len, const char *file, in } ) +AST_INLINE_API( +void * attribute_malloc __ast_realloc(void *p, size_t len, const char *file, int lineno, const char *func), +{ + void *newp; + + DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL); + + if (!(newp = realloc(p, len))) { + MALLOC_FAILURE_MSG; + } + + return newp; +} +) + +AST_INLINE_API( +char * attribute_malloc __ast_strdup(const char *str, const char *file, int lineno, const char *func), +{ + char *newstr = NULL; + + DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL); + + if (str) { + if (!(newstr = strdup(str))) { + MALLOC_FAILURE_MSG; + } + } + + return newstr; +} +) + +AST_INLINE_API( +char * attribute_malloc __ast_strndup(const char *str, size_t len, const char *file, int lineno, const char *func), +{ + char *newstr = NULL; + + DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL); + + if (str) { + if (!(newstr = strndup(str, len))) { + MALLOC_FAILURE_MSG; + } + } + + return newstr; +} +) + +int __attribute__((format(printf, 5, 6))) + __ast_asprintf(const char *file, int lineno, const char *func, char **ret, const char *fmt, ...); + +AST_INLINE_API( +__attribute__((format(printf, 2, 0))) +int __ast_vasprintf(char **ret, const char *fmt, va_list ap, const char *file, int lineno, const char *func), +{ + int res; + + DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1); + + if ((res = vasprintf(ret, fmt, ap)) == -1) { + MALLOC_FAILURE_MSG; + } + + return res; +} +) + +#endif /* AST_DEBUG_MALLOC */ + +/*! + * \brief A wrapper for malloc() + * + * ast_malloc() is a wrapper for malloc() that will generate an Asterisk log + * message in the case that the allocation fails. + * + * The argument and return value are the same as malloc() + */ +#define ast_malloc(len) \ + __ast_malloc((len), __FILE__, __LINE__, __PRETTY_FUNCTION__) + +/*! + * \brief A wrapper for calloc() + * + * ast_calloc() is a wrapper for calloc() that will generate an Asterisk log + * message in the case that the allocation fails. + * + * The arguments and return value are the same as calloc() + */ +#define ast_calloc(num, len) \ + __ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) + /*! * \brief A wrapper for calloc() for use in cache pools * @@ -596,7 +665,7 @@ void * attribute_malloc _ast_calloc(size_t num, size_t len, const char *file, in * The arguments and return value are the same as calloc() */ #define ast_calloc_cache(num, len) \ - _ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) + __ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) /*! * \brief A wrapper for realloc() @@ -607,22 +676,7 @@ void * attribute_malloc _ast_calloc(size_t num, size_t len, const char *file, in * The arguments and return value are the same as realloc() */ #define ast_realloc(p, len) \ - _ast_realloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) - -AST_INLINE_API( -void * attribute_malloc _ast_realloc(void *p, size_t len, const char *file, int lineno, const char *func), -{ - void *newp; - - DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL); - - if (!(newp = realloc(p, len))) { - MALLOC_FAILURE_MSG; - } - - return newp; -} -) + __ast_realloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) /*! * \brief A wrapper for strdup() @@ -637,24 +691,7 @@ void * attribute_malloc _ast_realloc(void *p, size_t len, const char *file, int * The argument and return value are the same as strdup() */ #define ast_strdup(str) \ - _ast_strdup((str), __FILE__, __LINE__, __PRETTY_FUNCTION__) - -AST_INLINE_API( -char * attribute_malloc _ast_strdup(const char *str, const char *file, int lineno, const char *func), -{ - char *newstr = NULL; - - DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL); - - if (str) { - if (!(newstr = strdup(str))) { - MALLOC_FAILURE_MSG; - } - } - - return newstr; -} -) + __ast_strdup((str), __FILE__, __LINE__, __PRETTY_FUNCTION__) /*! * \brief A wrapper for strndup() @@ -669,24 +706,7 @@ char * attribute_malloc _ast_strdup(const char *str, const char *file, int linen * The arguments and return value are the same as strndup() */ #define ast_strndup(str, len) \ - _ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) - -AST_INLINE_API( -char * attribute_malloc _ast_strndup(const char *str, size_t len, const char *file, int lineno, const char *func), -{ - char *newstr = NULL; - - DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, NULL); - - if (str) { - if (!(newstr = strndup(str, len))) { - MALLOC_FAILURE_MSG; - } - } - - return newstr; -} -) + __ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__) /*! * \brief A wrapper for asprintf() @@ -697,10 +717,7 @@ char * attribute_malloc _ast_strndup(const char *str, size_t len, const char *fi * The arguments and return value are the same as asprintf() */ #define ast_asprintf(ret, fmt, ...) \ - _ast_asprintf((ret), __FILE__, __LINE__, __PRETTY_FUNCTION__, fmt, __VA_ARGS__) - -int __attribute__((format(printf, 5, 6))) - _ast_asprintf(char **ret, const char *file, int lineno, const char *func, const char *fmt, ...); + __ast_asprintf(__FILE__, __LINE__, __PRETTY_FUNCTION__, (ret), (fmt), __VA_ARGS__) /*! * \brief A wrapper for vasprintf() @@ -711,25 +728,7 @@ int __attribute__((format(printf, 5, 6))) * The arguments and return value are the same as vasprintf() */ #define ast_vasprintf(ret, fmt, ap) \ - _ast_vasprintf((ret), __FILE__, __LINE__, __PRETTY_FUNCTION__, (fmt), (ap)) - -AST_INLINE_API( -__attribute__((format(printf, 5, 0))) -int _ast_vasprintf(char **ret, const char *file, int lineno, const char *func, const char *fmt, va_list ap), -{ - int res; - - DEBUG_CHAOS_RETURN(DEBUG_CHAOS_ALLOC_CHANCE, -1); - - if ((res = vasprintf(ret, fmt, ap)) == -1) { - MALLOC_FAILURE_MSG; - } - - return res; -} -) - -#endif /* AST_DEBUG_MALLOC */ + __ast_vasprintf((ret), (fmt), (ap), __FILE__, __LINE__, __PRETTY_FUNCTION__) /*! \brief call __builtin_alloca to ensure we get gcc builtin semantics @@ -849,8 +848,10 @@ int ast_parse_digest(const char *digest, struct ast_http_digest *d, int request, #define DO_CRASH_NORETURN #endif +void DO_CRASH_NORETURN __ast_assert_failed(int condition, const char *condition_str, + const char *file, int line, const char *function); + #ifdef AST_DEVMODE -void DO_CRASH_NORETURN __ast_assert_failed(int condition, const char *condition_str, const char *file, int line, const char *function); #define ast_assert(a) _ast_assert(a, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__) static void force_inline _ast_assert(int condition, const char *condition_str, const char *file, int line, const char *function) { @@ -973,6 +974,14 @@ int ast_str_to_eid(struct ast_eid *eid, const char *s); int ast_eid_cmp(const struct ast_eid *eid1, const struct ast_eid *eid2); /*! + * \brief Check if EID is empty + * + * \return 1 if the EID is empty, zero otherwise + * \since 13.12.0 + */ +int ast_eid_is_empty(const struct ast_eid *eid); + +/*! * \brief Get current thread ID * \return the ID if platform is supported, else -1 */ diff --git a/include/asterisk/vector.h b/include/asterisk/vector.h index be9091272..c74f0a89b 100644 --- a/include/asterisk/vector.h +++ b/include/asterisk/vector.h @@ -354,6 +354,32 @@ AST_VECTOR_REMOVE(vec, idx, 1) /*! + * \brief Remove all elements from a vector that matches the given comparison + * + * \param vec Vector to remove from. + * \param value Value to pass into comparator. + * \param cmp Comparator function/macros (called as \c cmp(elem, value)) + * \param cleanup How to cleanup a removed element macro/function. + * + * \return the number of deleted elements. + */ +#define AST_VECTOR_REMOVE_ALL_CMP_UNORDERED(vec, value, cmp, cleanup) ({ \ + int count = 0; \ + size_t idx; \ + typeof(value) __value = (value); \ + for (idx = 0; idx < (vec)->current; ) { \ + if (cmp((vec)->elems[idx], __value)) { \ + cleanup((vec)->elems[idx]); \ + AST_VECTOR_REMOVE_UNORDERED((vec), idx); \ + ++count; \ + } else { \ + ++idx; \ + } \ + } \ + count; \ +}) + +/*! * \brief Remove an element from a vector that matches the given comparison * * \param vec Vector to remove from. @@ -380,6 +406,32 @@ }) /*! + * \brief Remove all elements from a vector that matches the given comparison while maintaining order + * + * \param vec Vector to remove from. + * \param value Value to pass into comparator. + * \param cmp Comparator function/macros (called as \c cmp(elem, value)) + * \param cleanup How to cleanup a removed element macro/function. + * + * \return the number of deleted elements. + */ +#define AST_VECTOR_REMOVE_ALL_CMP_ORDERED(vec, value, cmp, cleanup) ({ \ + int count = 0; \ + size_t idx; \ + typeof(value) __value = (value); \ + for (idx = 0; idx < (vec)->current; ) { \ + if (cmp((vec)->elems[idx], __value)) { \ + cleanup((vec)->elems[idx]); \ + AST_VECTOR_REMOVE_ORDERED((vec), idx); \ + ++count; \ + } else { \ + ++idx; \ + } \ + } \ + count; \ +}) + +/*! * \brief Remove an element from a vector that matches the given comparison while maintaining order * * \param vec Vector to remove from. @@ -397,7 +449,7 @@ for (idx = 0; idx < (vec)->current; ++idx) { \ if (cmp((vec)->elems[idx], __value)) { \ cleanup((vec)->elems[idx]); \ - AST_VECTOR_REMOVE_ORDERED((vec), idx); \ + AST_VECTOR_REMOVE_ORDERED((vec), idx); \ res = 0; \ break; \ } \ |