diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | apps/app_voicemail.c | 2 | ||||
-rw-r--r-- | channels/sip/config_parser.c | 7 | ||||
-rw-r--r-- | channels/sip/reqresp_parser.c | 23 | ||||
-rw-r--r-- | funcs/func_curl.c | 2 | ||||
-rw-r--r-- | include/asterisk/pbx.h | 10 | ||||
-rw-r--r-- | main/pbx.c | 186 | ||||
-rw-r--r-- | main/pbx_ignorepat.c | 82 | ||||
-rw-r--r-- | main/pbx_private.h | 7 | ||||
-rw-r--r-- | pbx/pbx_config.c | 32 | ||||
-rw-r--r-- | res/ael/pval.c | 2 | ||||
-rw-r--r-- | res/res_pjsip.c | 2 | ||||
-rw-r--r-- | res/res_pjsip_mwi.c | 28 | ||||
-rw-r--r-- | res/res_rtp_asterisk.c | 2 | ||||
-rw-r--r-- | utils/conf2ael.c | 6 | ||||
-rw-r--r-- | utils/extconf.c | 25 |
16 files changed, 269 insertions, 149 deletions
@@ -824,7 +824,7 @@ install-logrotate: rm -f contrib/scripts/asterisk.logrotate.tmp config: - if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then \ + @if [ -f /etc/redhat-release -o -f /etc/fedora-release ]; then \ ./build_tools/install_subst contrib/init.d/rc.redhat.asterisk "$(DESTDIR)/etc/rc.d/init.d/asterisk"; \ if [ ! -f "$(DESTDIR)/etc/sysconfig/asterisk" ] ; then \ $(INSTALL) -m 644 contrib/init.d/etc_default_asterisk "$(DESTDIR)/etc/sysconfig/asterisk" ; \ diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index 6607f529e..894038bdb 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -12307,6 +12307,7 @@ static int append_mailbox(const char *context, const char *box, const char *data return 0; } +#ifdef TEST_FRAMEWORK AST_TEST_DEFINE(test_voicemail_vmuser) { int res = 0; @@ -12494,6 +12495,7 @@ AST_TEST_DEFINE(test_voicemail_vmuser) free_user(vmu); return res ? AST_TEST_FAIL : AST_TEST_PASS; } +#endif static int vm_box_exists(struct ast_channel *chan, const char *data) { diff --git a/channels/sip/config_parser.c b/channels/sip/config_parser.c index 56d04b260..036f7f7d2 100644 --- a/channels/sip/config_parser.c +++ b/channels/sip/config_parser.c @@ -274,6 +274,7 @@ int sip_parse_register_line(struct sip_registry *reg, int default_expiry, const return 0; } +#ifdef TEST_FRAMEWORK AST_TEST_DEFINE(sip_parse_register_line_test) { int res = AST_TEST_PASS; @@ -643,6 +644,7 @@ alloc_fail: ast_test_status_update(test, "Out of memory. \n"); return res; } +#endif int sip_parse_host(char *line, int lineno, char **hostname, int *portnum, enum ast_transport *transport) { @@ -708,6 +710,7 @@ int sip_parse_host(char *line, int lineno, char **hostname, int *portnum, enum a return 0; } +#ifdef TEST_FRAMEWORK AST_TEST_DEFINE(sip_parse_host_line_test) { int res = AST_TEST_PASS; @@ -787,6 +790,7 @@ AST_TEST_DEFINE(sip_parse_host_line_test) return res; } +#endif /*! \brief Parse the comma-separated nat= option values */ void sip_parse_nat_option(const char *value, struct ast_flags *mask, struct ast_flags *flags) @@ -834,6 +838,7 @@ void sip_parse_nat_option(const char *value, struct ast_flags *mask, struct ast_ } } +#ifdef TEST_FRAMEWORK #define TEST_FORCE_RPORT 1 << 0 #define TEST_COMEDIA 1 << 1 #define TEST_AUTO_FORCE_RPORT 1 << 2 @@ -904,6 +909,8 @@ AST_TEST_DEFINE(sip_parse_nat_test) return res; } +#endif + /*! \brief SIP test registration */ void sip_config_parser_register_tests(void) { diff --git a/channels/sip/reqresp_parser.c b/channels/sip/reqresp_parser.c index 298b8cb95..358d6e568 100644 --- a/channels/sip/reqresp_parser.c +++ b/channels/sip/reqresp_parser.c @@ -258,7 +258,7 @@ int parse_uri_full(char *uri, const char *scheme, char **user, char **pass, return error; } - +#ifdef TEST_FRAMEWORK AST_TEST_DEFINE(sip_parse_uri_full_test) { int res = AST_TEST_PASS; @@ -514,7 +514,7 @@ AST_TEST_DEFINE(sip_parse_uri_full_test) return res; } - +#endif int parse_uri(char *uri, const char *scheme, char **user, char **pass, char **hostport, char **transport) { @@ -530,6 +530,7 @@ int parse_uri(char *uri, const char *scheme, char **user, char **pass, return ret; } +#ifdef TEST_FRAMEWORK AST_TEST_DEFINE(sip_parse_uri_test) { int res = AST_TEST_PASS; @@ -687,6 +688,7 @@ AST_TEST_DEFINE(sip_parse_uri_test) return res; } +#endif /*! \brief Get caller id name from SIP headers, copy into output buffer * @@ -817,6 +819,7 @@ const char *get_calleridname(const char *input, char *output, size_t outputsize) return input; } +#ifdef TEST_FRAMEWORK AST_TEST_DEFINE(get_calleridname_test) { int res = AST_TEST_PASS; @@ -899,6 +902,7 @@ AST_TEST_DEFINE(get_calleridname_test) return res; } +#endif int get_name_and_number(const char *hdr, char **name, char **number) { @@ -940,6 +944,7 @@ int get_name_and_number(const char *hdr, char **name, char **number) return 0; } +#ifdef TEST_FRAMEWORK AST_TEST_DEFINE(get_name_and_number_test) { int res = AST_TEST_PASS; @@ -1044,6 +1049,7 @@ AST_TEST_DEFINE(get_name_and_number_test) return res; } +#endif int get_in_brackets_const(const char *src,const char **start,int *length) { @@ -1176,6 +1182,7 @@ char *get_in_brackets(char *tmp) return out; } +#ifdef TEST_FRAMEWORK AST_TEST_DEFINE(get_in_brackets_test) { int res = AST_TEST_PASS; @@ -1252,7 +1259,7 @@ AST_TEST_DEFINE(get_in_brackets_test) return res; } - +#endif int parse_name_andor_addr(char *uri, const char *scheme, char **name, char **user, char **pass, char **hostport, @@ -1298,6 +1305,7 @@ int parse_name_andor_addr(char *uri, const char *scheme, char **name, return parse_uri_full(uri, scheme, user, pass, hostport, params, headers, residue2); } +#ifdef TEST_FRAMEWORK AST_TEST_DEFINE(parse_name_andor_addr_test) { int res = AST_TEST_PASS; @@ -1427,6 +1435,7 @@ AST_TEST_DEFINE(parse_name_andor_addr_test) return res; } +#endif int get_comma(char *in, char **out) { @@ -1523,6 +1532,7 @@ int parse_contact_header(char *contactheader, struct contactliststruct *contactl return last; } +#ifdef TEST_FRAMEWORK AST_TEST_DEFINE(parse_contact_header_test) { int res = AST_TEST_PASS; @@ -1668,6 +1678,7 @@ AST_TEST_DEFINE(parse_contact_header_test) return res; } +#endif /*! * \brief Parse supported header in incoming packet @@ -1755,6 +1766,7 @@ unsigned int parse_sip_options(const char *options, char *unsupported, size_t un return profile; } +#ifdef TEST_FRAMEWORK AST_TEST_DEFINE(sip_parse_options_test) { int res = AST_TEST_PASS; @@ -1892,6 +1904,7 @@ AST_TEST_DEFINE(sip_parse_options_test) return res; } +#endif /*! \brief helper routine for sip_uri_cmp to compare URI parameters * @@ -2246,6 +2259,7 @@ int sip_uri_cmp(const char *input1, const char *input2) #define URI_CMP_MATCH 0 #define URI_CMP_NOMATCH 1 +#ifdef TEST_FRAMEWORK AST_TEST_DEFINE(sip_uri_cmp_test) { static const struct { @@ -2362,6 +2376,7 @@ AST_TEST_DEFINE(sip_uri_cmp_test) return test_res; } +#endif void free_via(struct sip_via *v) { @@ -2448,6 +2463,7 @@ struct sip_via *parse_via(const char *header) return v; } +#ifdef TEST_FRAMEWORK AST_TEST_DEFINE(parse_via_test) { int res = AST_TEST_PASS; @@ -2625,6 +2641,7 @@ AST_TEST_DEFINE(parse_via_test) } return res; } +#endif void sip_request_parser_register_tests(void) { diff --git a/funcs/func_curl.c b/funcs/func_curl.c index 6a8c36767..8ec1032a7 100644 --- a/funcs/func_curl.c +++ b/funcs/func_curl.c @@ -856,6 +856,7 @@ static struct ast_custom_function acf_curlopt = { .write = acf_curlopt_write, }; +#ifdef TEST_FRAMEWORK AST_TEST_DEFINE(vulnerable_url) { const char *bad_urls [] = { @@ -903,6 +904,7 @@ AST_TEST_DEFINE(vulnerable_url) return res; } +#endif static int unload_module(void) { diff --git a/include/asterisk/pbx.h b/include/asterisk/pbx.h index 378bb556d..67cdccf90 100644 --- a/include/asterisk/pbx.h +++ b/include/asterisk/pbx.h @@ -1228,7 +1228,7 @@ const char *ast_get_context_name(struct ast_context *con); const char *ast_get_extension_name(struct ast_exten *exten); struct ast_context *ast_get_extension_context(struct ast_exten *exten); const char *ast_get_include_name(const struct ast_include *include); -const char *ast_get_ignorepat_name(struct ast_ignorepat *ip); +const char *ast_get_ignorepat_name(const struct ast_ignorepat *ip); const char *ast_get_switch_name(struct ast_sw *sw); const char *ast_get_switch_data(struct ast_sw *sw); int ast_get_switch_eval(struct ast_sw *sw); @@ -1250,7 +1250,7 @@ void *ast_get_extension_app_data(struct ast_exten *e); const char *ast_get_context_registrar(struct ast_context *c); const char *ast_get_extension_registrar(struct ast_exten *e); const char *ast_get_include_registrar(const struct ast_include *i); -const char *ast_get_ignorepat_registrar(struct ast_ignorepat *ip); +const char *ast_get_ignorepat_registrar(const struct ast_ignorepat *ip); const char *ast_get_switch_registrar(struct ast_sw *sw); /*! @} */ @@ -1263,8 +1263,8 @@ struct ast_exten *ast_walk_extension_priorities(struct ast_exten *exten, struct ast_exten *priority); const struct ast_include *ast_walk_context_includes(const struct ast_context *con, const struct ast_include *inc); -struct ast_ignorepat *ast_walk_context_ignorepats(struct ast_context *con, - struct ast_ignorepat *ip); +const struct ast_ignorepat *ast_walk_context_ignorepats(const struct ast_context *con, + const struct ast_ignorepat *ip); struct ast_sw *ast_walk_context_switches(struct ast_context *con, struct ast_sw *sw); /*! @} */ @@ -1272,6 +1272,8 @@ struct ast_sw *ast_walk_context_switches(struct ast_context *con, struct ast_sw /*! @{ */ int ast_context_includes_count(const struct ast_context *con); const struct ast_include *ast_context_includes_get(const struct ast_context *con, int idx); +int ast_context_ignorepats_count(const struct ast_context *con); +const struct ast_ignorepat *ast_context_ignorepats_get(const struct ast_context *con, int idx); /*! @} */ /*! diff --git a/main/pbx.c b/main/pbx.c index f6768bb54..eb395eba4 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -265,13 +265,6 @@ struct ast_sw { char stuff[0]; }; -/*! \brief ast_ignorepat: Ignore patterns in dial plan */ -struct ast_ignorepat { - const char *registrar; - struct ast_ignorepat *next; - const char pattern[0]; -}; - /*! \brief match_char: forms a syntax tree for quick matching of extension patterns */ struct match_char { @@ -303,7 +296,7 @@ struct ast_context { struct match_char *pattern_tree; /*!< A tree to speed up extension pattern matching */ struct ast_context *next; /*!< Link them together */ struct ast_includes includes; /*!< Include other contexts */ - struct ast_ignorepat *ignorepats; /*!< Patterns for which to continue playing dialtone */ + struct ast_ignorepats ignorepats; /*!< Patterns for which to continue playing dialtone */ char *registrar; /*!< Registrar -- make sure you malloc this, as the registrar may have to survive module unloads */ int refcount; /*!< each module that would have created this context should inc/dec this as appropriate */ int autohints; /*!< Whether autohints support is enabled or not */ @@ -2381,7 +2374,7 @@ struct fake_context /* this struct is purely for matching in the hashtab */ struct match_char *pattern_tree; struct ast_context *next; struct ast_includes includes; - struct ast_ignorepat *ignorepats; + struct ast_ignorepats ignorepats; const char *registrar; int refcount; int autohints; @@ -5394,7 +5387,6 @@ static int show_dialplan_helper(int fd, const char *context, const char *exten, while ( (c = ast_walk_contexts(c)) ) { int idx; struct ast_exten *e; - struct ast_ignorepat *ip; #ifndef LOW_MEMORY char buf[1024], buf2[1024]; #else @@ -5512,10 +5504,11 @@ static int show_dialplan_helper(int fd, const char *context, const char *exten, } /* walk ignore patterns and write info ... */ - ip = NULL; - while ( (ip = ast_walk_context_ignorepats(c, ip)) ) { + for (idx = 0; idx < ast_context_ignorepats_count(c); idx++) { + const struct ast_ignorepat *ip = ast_context_ignorepats_get(c, idx); const char *ipname = ast_get_ignorepat_name(ip); char ignorepat[AST_MAX_EXTENSION]; + snprintf(buf, sizeof(buf), "'%s'", ipname); snprintf(ignorepat, sizeof(ignorepat), "_%s.", ipname); if (!exten || ast_extension_match(ignorepat, exten)) { @@ -5758,7 +5751,6 @@ static int manager_show_dialplan_helper(struct mansession *s, const struct messa while ( (c = ast_walk_contexts(c)) ) { int idx; struct ast_exten *e; - struct ast_ignorepat *ip; if (context && strcmp(ast_get_context_name(c), context) != 0) continue; /* not the name we want */ @@ -5829,8 +5821,8 @@ static int manager_show_dialplan_helper(struct mansession *s, const struct messa } } - ip = NULL; /* walk ignore patterns and write info ... */ - while ( (ip = ast_walk_context_ignorepats(c, ip)) ) { + for (idx = 0; idx < ast_context_ignorepats_count(c); idx++) { + const struct ast_ignorepat *ip = ast_context_ignorepats_get(c, idx); const char *ipname = ast_get_ignorepat_name(ip); char ignorepat[AST_MAX_EXTENSION]; @@ -6094,7 +6086,7 @@ struct ast_context *ast_context_find_or_create(struct ast_context **extcontexts, tmp->root_table = NULL; tmp->registrar = ast_strdup(registrar); AST_VECTOR_INIT(&tmp->includes, 0); - tmp->ignorepats = NULL; + AST_VECTOR_INIT(&tmp->ignorepats, 0); tmp->refcount = 1; } else { ast_log(LOG_ERROR, "Danger! We failed to allocate a context for %s!\n", name); @@ -6146,7 +6138,6 @@ AST_LIST_HEAD_NOLOCK(store_hints, store_hint); static void context_merge_incls_swits_igps_other_registrars(struct ast_context *new, struct ast_context *old, const char *registrar) { int idx; - struct ast_ignorepat *ip; struct ast_sw *sw; ast_verb(3, "merging incls/swits/igpats from old(%s) to new(%s) context, registrar = %s\n", ast_get_context_name(old), ast_get_context_name(new), registrar); @@ -6169,9 +6160,12 @@ static void context_merge_incls_swits_igps_other_registrars(struct ast_context * } /* walk thru ignorepats ... */ - for (ip = NULL; (ip = ast_walk_context_ignorepats(old, ip)); ) { - if (strcmp(ast_get_ignorepat_registrar(ip), registrar) == 0) + for (idx = 0; idx < ast_context_ignorepats_count(old); idx++) { + const struct ast_ignorepat *ip = ast_context_ignorepats_get(old, idx); + + if (strcmp(ast_get_ignorepat_registrar(ip), registrar) == 0) { continue; /* not mine */ + } ast_context_add_ignorepat2(new, ast_get_ignorepat_name(ip), ast_get_ignorepat_registrar(ip)); } } @@ -6700,24 +6694,20 @@ int ast_context_remove_ignorepat(const char *context, const char *ignorepat, con int ast_context_remove_ignorepat2(struct ast_context *con, const char *ignorepat, const char *registrar) { - struct ast_ignorepat *ip, *ipl = NULL; + int idx; ast_wrlock_context(con); - for (ip = con->ignorepats; ip; ip = ip->next) { - if (!strcmp(ip->pattern, ignorepat) && - (!registrar || (registrar == ip->registrar))) { - if (ipl) { - ipl->next = ip->next; - ast_free(ip); - } else { - con->ignorepats = ip->next; - ast_free(ip); - } + for (idx = 0; idx < ast_context_ignorepats_count(con); idx++) { + struct ast_ignorepat *ip = AST_VECTOR_GET(&con->ignorepats, idx); + + if (!strcmp(ast_get_ignorepat_name(ip), ignorepat) && + (!registrar || (registrar == ast_get_ignorepat_registrar(ip)))) { + AST_VECTOR_REMOVE_ORDERED(&con->ignorepats, idx); + ignorepat_free(ip); ast_unlock_context(con); return 0; } - ipl = ip; } ast_unlock_context(con); @@ -6744,41 +6734,29 @@ int ast_context_add_ignorepat(const char *context, const char *value, const char int ast_context_add_ignorepat2(struct ast_context *con, const char *value, const char *registrar) { - struct ast_ignorepat *ignorepat, *ignorepatc, *ignorepatl = NULL; - int length; - char *pattern; - length = sizeof(struct ast_ignorepat); - length += strlen(value) + 1; - if (!(ignorepat = ast_calloc(1, length))) + struct ast_ignorepat *ignorepat = ignorepat_alloc(value, registrar); + int idx; + + if (!ignorepat) { return -1; - /* The cast to char * is because we need to write the initial value. - * The field is not supposed to be modified otherwise. Also, gcc 4.2 - * sees the cast as dereferencing a type-punned pointer and warns about - * it. This is the workaround (we're telling gcc, yes, that's really - * what we wanted to do). - */ - pattern = (char *) ignorepat->pattern; - strcpy(pattern, value); - ignorepat->next = NULL; - ignorepat->registrar = registrar; + } + ast_wrlock_context(con); - for (ignorepatc = con->ignorepats; ignorepatc; ignorepatc = ignorepatc->next) { - ignorepatl = ignorepatc; - if (!strcasecmp(ignorepatc->pattern, value)) { + for (idx = 0; idx < ast_context_ignorepats_count(con); idx++) { + const struct ast_ignorepat *i = ast_context_ignorepats_get(con, idx); + + if (!strcasecmp(ast_get_ignorepat_name(i), value)) { /* Already there */ ast_unlock_context(con); - ast_free(ignorepat); + ignorepat_free(ignorepat); errno = EEXIST; return -1; } } - if (ignorepatl) - ignorepatl->next = ignorepat; - else - con->ignorepats = ignorepat; + AST_VECTOR_APPEND(&con->ignorepats, ignorepat); ast_unlock_context(con); - return 0; + return 0; } int ast_ignore_pattern(const char *context, const char *pattern) @@ -6789,10 +6767,12 @@ int ast_ignore_pattern(const char *context, const char *pattern) ast_rdlock_contexts(); con = ast_context_find(context); if (con) { - struct ast_ignorepat *pat; + int idx; - for (pat = con->ignorepats; pat; pat = pat->next) { - if (ast_extension_match(pat->pattern, pattern)) { + for (idx = 0; idx < ast_context_ignorepats_count(con); idx++) { + const struct ast_ignorepat *pat = ast_context_ignorepats_get(con, idx); + + if (ast_extension_match(ast_get_ignorepat_name(pat), pattern)) { ret = 1; break; } @@ -7797,18 +7777,16 @@ static void __ast_internal_context_destroy( struct ast_context *con) { struct ast_sw *sw; struct ast_exten *e, *el, *en; - struct ast_ignorepat *ipi; struct ast_context *tmp = con; /* Free includes */ AST_VECTOR_CALLBACK_VOID(&tmp->includes, include_free); AST_VECTOR_FREE(&tmp->includes); - for (ipi = tmp->ignorepats; ipi; ) { /* Free ignorepats */ - struct ast_ignorepat *ipl = ipi; - ipi = ipi->next; - ast_free(ipl); - } + /* Free ignorepats */ + AST_VECTOR_CALLBACK_VOID(&tmp->ignorepats, ignorepat_free); + AST_VECTOR_FREE(&tmp->ignorepats); + if (tmp->registrar) ast_free(tmp->registrar); @@ -7868,25 +7846,17 @@ void __ast_context_destroy(struct ast_context *list, struct ast_hashtab *context /* then search thru and remove any extens that match registrar. */ struct ast_hashtab_iter *exten_iter; struct ast_hashtab_iter *prio_iter; - struct ast_ignorepat *ip, *ipl = NULL, *ipn = NULL; struct ast_sw *sw = NULL; int idx; /* remove any ignorepats whose registrar matches */ - for (ip = tmp->ignorepats; ip; ip = ipn) { - ipn = ip->next; - if (!strcmp(ip->registrar, registrar)) { - if (ipl) { - ipl->next = ip->next; - ast_free(ip); - continue; /* don't change ipl */ - } else { - tmp->ignorepats = ip->next; - ast_free(ip); - continue; /* don't change ipl */ - } + for (idx = ast_context_ignorepats_count(tmp) - 1; idx >= 0; idx--) { + struct ast_ignorepat *ip = AST_VECTOR_GET(&tmp->ignorepats, idx); + + if (!strcmp(ast_get_ignorepat_registrar(ip), registrar)) { + AST_VECTOR_REMOVE_ORDERED(&tmp->ignorepats, idx); + ignorepat_free(ip); } - ipl = ip; } /* remove any includes whose registrar matches */ for (idx = ast_context_includes_count(tmp) - 1; idx >= 0; idx--) { @@ -7955,7 +7925,7 @@ void __ast_context_destroy(struct ast_context *list, struct ast_hashtab *context /* delete the context if it's registrar matches, is empty, has refcount of 1, */ /* it's not empty, if it has includes, ignorepats, or switches that are registered from another registrar. It's not empty if there are any extensions */ - if (strcmp(tmp->registrar, registrar) == 0 && tmp->refcount < 2 && !tmp->root && !tmp->ignorepats && !ast_context_includes_count(tmp) && AST_LIST_EMPTY(&tmp->alts)) { + if (strcmp(tmp->registrar, registrar) == 0 && tmp->refcount < 2 && !tmp->root && !ast_context_ignorepats_count(tmp) && !ast_context_includes_count(tmp) && AST_LIST_EMPTY(&tmp->alts)) { ast_debug(1, "delete ctx %s %s\n", tmp->name, tmp->registrar); ast_hashtab_remove_this_object(contexttab, tmp); @@ -8356,11 +8326,6 @@ const char *ast_get_extension_label(struct ast_exten *exten) return exten ? exten->label : NULL; } -const char *ast_get_ignorepat_name(struct ast_ignorepat *ip) -{ - return ip ? ip->pattern : NULL; -} - int ast_get_extension_priority(struct ast_exten *exten) { return exten ? exten->priority : -1; @@ -8379,11 +8344,6 @@ const char *ast_get_extension_registrar(struct ast_exten *e) return e ? e->registrar : NULL; } -const char *ast_get_ignorepat_registrar(struct ast_ignorepat *ip) -{ - return ip ? ip->registrar : NULL; -} - int ast_get_extension_matchcid(struct ast_exten *e) { return e ? e->matchcid : 0; @@ -8495,13 +8455,47 @@ const struct ast_include *ast_context_includes_get(const struct ast_context *con return AST_VECTOR_GET(&con->includes, idx); } -struct ast_ignorepat *ast_walk_context_ignorepats(struct ast_context *con, - struct ast_ignorepat *ip) +const struct ast_ignorepat *ast_walk_context_ignorepats(const struct ast_context *con, + const struct ast_ignorepat *ip) { - if (!ip) - return con ? con->ignorepats : NULL; - else - return ip->next; + if (!con) { + return NULL; + } + + if (ip) { + int idx; + int next = 0; + + for (idx = 0; idx < ast_context_ignorepats_count(con); idx++) { + const struct ast_ignorepat *i = ast_context_ignorepats_get(con, idx); + + if (next) { + return i; + } + + if (ip == i) { + next = 1; + } + } + + return NULL; + } + + if (!ast_context_ignorepats_count(con)) { + return NULL; + } + + return ast_context_ignorepats_get(con, 0); +} + +int ast_context_ignorepats_count(const struct ast_context *con) +{ + return AST_VECTOR_SIZE(&con->ignorepats); +} + +const struct ast_ignorepat *ast_context_ignorepats_get(const struct ast_context *con, int idx) +{ + return AST_VECTOR_GET(&con->ignorepats, idx); } int ast_context_verify_includes(struct ast_context *con) diff --git a/main/pbx_ignorepat.c b/main/pbx_ignorepat.c new file mode 100644 index 000000000..1a2232c57 --- /dev/null +++ b/main/pbx_ignorepat.c @@ -0,0 +1,82 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2016, CFWare, LLC + * + * Corey Farrell <git@cfware.com> + * + * See http://www.asterisk.org for more information about + * the Asterisk project. Please do not directly contact + * any of the maintainers of this project for assistance; + * the project provides a web site, mailing lists and IRC + * channels for your use. + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. + */ + +/*! \file + * + * \brief Dialplan context ignorepat routines. + * + * \author Corey Farrell <git@cfware.com> + */ + +/*** MODULEINFO + <support_level>core</support_level> + ***/ + +#include "asterisk.h" + +ASTERISK_REGISTER_FILE() + +#include "asterisk/_private.h" +#include "asterisk/pbx.h" +#include "pbx_private.h" + +/*! \brief ast_ignorepat: Ignore patterns in dial plan */ +struct ast_ignorepat { + const char *registrar; + const char pattern[0]; +}; + +const char *ast_get_ignorepat_name(const struct ast_ignorepat *ip) +{ + return ip ? ip->pattern : NULL; +} + +const char *ast_get_ignorepat_registrar(const struct ast_ignorepat *ip) +{ + return ip ? ip->registrar : NULL; +} + +struct ast_ignorepat *ignorepat_alloc(const char *value, const char *registrar) +{ + struct ast_ignorepat *ignorepat; + int length = strlen(value) + 1; + char *pattern; + + /* allocate new include structure ... */ + ignorepat = ast_calloc(1, sizeof(*ignorepat) + length); + if (!ignorepat) { + return NULL; + } + + /* The cast to char * is because we need to write the initial value. + * The field is not supposed to be modified otherwise. Also, gcc 4.2 + * sees the cast as dereferencing a type-punned pointer and warns about + * it. This is the workaround (we're telling gcc, yes, that's really + * what we wanted to do). + */ + pattern = (char *) ignorepat->pattern; + strcpy(pattern, value); + ignorepat->registrar = registrar; + + return ignorepat; +} + +void ignorepat_free(struct ast_ignorepat *ip) +{ + ast_free(ip); +} diff --git a/main/pbx_private.h b/main/pbx_private.h index 22d454ad0..2b7d9828b 100644 --- a/main/pbx_private.h +++ b/main/pbx_private.h @@ -31,6 +31,13 @@ void set_ext_pri(struct ast_channel *c, const char *exten, int pri); /*! pbx.c function needed by pbx_app.c */ void unreference_cached_app(struct ast_app *app); +/*! pbx_ignorepat.c */ +struct ast_ignorepat; +AST_VECTOR(ast_ignorepats, struct ast_ignorepat *); + +struct ast_ignorepat *ignorepat_alloc(const char *value, const char *registrar); +void ignorepat_free(struct ast_ignorepat *ip); + /*! pbx_includes.c */ struct ast_include; AST_VECTOR(ast_includes, struct ast_include *); diff --git a/pbx/pbx_config.c b/pbx/pbx_config.c index 478c0a321..cb7e03a3e 100644 --- a/pbx/pbx_config.c +++ b/pbx/pbx_config.c @@ -213,15 +213,25 @@ static int lookup_ci(struct ast_context *c, const char *name) /*! \brief return true if 'name' is in the ignorepats for context c */ static int lookup_c_ip(struct ast_context *c, const char *name) { - struct ast_ignorepat *ip = NULL; + int idx; + int ret = 0; - if (ast_rdlock_context(c)) /* error, skip */ + if (ast_rdlock_context(c)) { + /* error, skip */ return 0; - while ( (ip = ast_walk_context_ignorepats(c, ip)) ) - if (!strcmp(name, ast_get_ignorepat_name(ip))) + } + + for (idx = 0; idx < ast_context_ignorepats_count(c); idx++) { + const struct ast_ignorepat *ip = ast_context_ignorepats_get(c, idx); + + if (!strcmp(name, ast_get_ignorepat_name(ip))) { + ret = -1; break; + } + } ast_unlock_context(c); - return ip ? -1 /* success */ : 0; + + return ret; } /*! \brief moves to the n-th word in the string, or empty string if none */ @@ -918,7 +928,6 @@ static char *handle_cli_dialplan_save(struct ast_cli_entry *e, int cmd, struct a int context_header_written = 0; struct ast_exten *ext, *last_written_e = NULL; int idx; - struct ast_ignorepat *ip; struct ast_sw *sw; /* try to lock context and fireout all info */ @@ -1019,7 +1028,9 @@ static char *handle_cli_dialplan_save(struct ast_cli_entry *e, int cmd, struct a fprintf(output, "\n"); /* fireout ignorepats ... */ - for (ip = NULL; (ip = ast_walk_context_ignorepats(c, ip)); ) { + for (idx = 0; idx < ast_context_ignorepats_count(c); idx++) { + const struct ast_ignorepat *ip = ast_context_ignorepats_get(c, idx); + if (strcmp(ast_get_ignorepat_registrar(ip), registrar) != 0) continue; /* not mine */ PUT_CTX_HDR; @@ -1486,12 +1497,13 @@ static char *complete_dialplan_remove_ignorepat(struct ast_cli_args *a) } for (c = NULL; !ret && (c = ast_walk_contexts(c));) { - struct ast_ignorepat *ip; + int idx; if (ast_rdlock_context(c)) /* error, skip it */ continue; - - for (ip = NULL; !ret && (ip = ast_walk_context_ignorepats(c, ip));) { + for (idx = 0; idx < ast_context_ignorepats_count(c); idx++) { + const struct ast_ignorepat *ip = ast_context_ignorepats_get(c, idx); + if (partial_match(ast_get_ignorepat_name(ip), a->word, len) && ++which > a->n) { /* n-th match */ struct ast_context *cw = NULL; diff --git a/res/ael/pval.c b/res/ael/pval.c index 8b6760f99..2941365c9 100644 --- a/res/ael/pval.c +++ b/res/ael/pval.c @@ -4410,7 +4410,7 @@ static int context_used(struct ael_extension *exten_list, struct ast_context *co { struct ael_extension *exten; /* Check the simple elements first */ - if (ast_walk_context_extensions(context, NULL) || ast_context_includes_count(context) || ast_walk_context_ignorepats(context, NULL) || ast_walk_context_switches(context, NULL)) { + if (ast_walk_context_extensions(context, NULL) || ast_context_includes_count(context) || ast_context_ignorepats_count(context) || ast_walk_context_switches(context, NULL)) { return 1; } for (exten = exten_list; exten; exten = exten->next_exten) { diff --git a/res/res_pjsip.c b/res/res_pjsip.c index af2f93749..882f57876 100644 --- a/res/res_pjsip.c +++ b/res/res_pjsip.c @@ -4154,6 +4154,7 @@ long ast_sip_threadpool_queue_size(void) return ast_threadpool_queue_size(sip_threadpool); } +#ifdef TEST_FRAMEWORK AST_TEST_DEFINE(xml_sanitization_end_null) { char sanitized[8]; @@ -4204,6 +4205,7 @@ AST_TEST_DEFINE(xml_sanitization_exceeds_buffer) return AST_TEST_PASS; } +#endif /*! * \internal diff --git a/res/res_pjsip_mwi.c b/res/res_pjsip_mwi.c index 9eba335b5..d86c96c74 100644 --- a/res/res_pjsip_mwi.c +++ b/res/res_pjsip_mwi.c @@ -976,38 +976,12 @@ static int create_mwi_subscriptions_for_endpoint(void *obj, void *arg, int flags { RAII_VAR(struct mwi_subscription *, aggregate_sub, NULL, ao2_cleanup); struct ast_sip_endpoint *endpoint = obj; - char *endpoint_aors, *aor_name, *mailboxes, *mailbox; - struct ao2_container *contacts = NULL; + char *mailboxes, *mailbox; if (ast_strlen_zero(endpoint->subscription.mwi.mailboxes)) { return 0; } - endpoint_aors = ast_strdupa(endpoint->aors); - - while ((aor_name = ast_strip(strsep(&endpoint_aors, ",")))) { - RAII_VAR(struct ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup); - - if (!aor) { - continue; - } - - contacts = ast_sip_location_retrieve_aor_contacts(aor); - if (!contacts || (ao2_container_count(contacts) == 0)) { - ao2_cleanup(contacts); - contacts = NULL; - continue; - } - - break; - } - - if (!contacts) { - return 0; - } - - ao2_ref(contacts, -1); - if (endpoint->subscription.mwi.aggregate) { aggregate_sub = mwi_subscription_alloc(endpoint, 0, NULL); if (!aggregate_sub) { diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c index c8d7f4630..6cf69ef0d 100644 --- a/res/res_rtp_asterisk.c +++ b/res/res_rtp_asterisk.c @@ -2592,7 +2592,7 @@ static int ast_rtp_new(struct ast_rtp_instance *instance, /* Set default parameters on the newly created RTP structure */ rtp->ssrc = ast_random(); - rtp->seqno = ast_random() & 0xffff; + rtp->seqno = ast_random() & 0x7fff; rtp->strict_rtp_state = (strictrtp ? STRICT_RTP_LEARN : STRICT_RTP_OPEN); if (strictrtp) { rtp_learning_seq_init(&rtp->rtp_source_learn, (uint16_t)rtp->seqno); diff --git a/utils/conf2ael.c b/utils/conf2ael.c index 8b2043082..f0cb83f30 100644 --- a/utils/conf2ael.c +++ b/utils/conf2ael.c @@ -670,12 +670,6 @@ const struct ast_include *ast_walk_context_includes(const struct ast_context *co return NULL; } -struct ast_ignorepat *ast_walk_context_ignorepats(struct ast_context *con, struct ast_ignorepat *ip); -struct ast_ignorepat *ast_walk_context_ignorepats(struct ast_context *con, struct ast_ignorepat *ip) -{ - return NULL; -} - struct ast_sw *ast_walk_context_switches(struct ast_context *con, struct ast_sw *sw); struct ast_sw *ast_walk_context_switches(struct ast_context *con, struct ast_sw *sw) { diff --git a/utils/extconf.c b/utils/extconf.c index 3a0b2e97c..049882334 100644 --- a/utils/extconf.c +++ b/utils/extconf.c @@ -4402,6 +4402,31 @@ struct ast_include *localized_walk_context_includes(struct ast_context *con, return ast_walk_context_includes(con, inc); } +static struct ast_ignorepat *ast_walk_context_ignorepats(struct ast_context *con, + struct ast_ignorepat *ip); + +static struct ast_ignorepat *ast_walk_context_ignorepats(struct ast_context *con, + struct ast_ignorepat *ip) +{ + if (!ip) + return con ? con->ignorepats : NULL; + else + return ip->next; +} + +int ast_context_ignorepats_count(struct ast_context *con); +int ast_context_ignorepats_count(struct ast_context *con) +{ + int c = 0; + struct ast_ignorepat *ip = NULL; + + while ((ip = ast_walk_context_ignorepats(con, ip))) { + c++; + } + + return c; +} + static struct ast_sw *ast_walk_context_switches(struct ast_context *con, struct ast_sw *sw); |