diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/Makefile | 2 | ||||
-rw-r--r-- | main/asterisk.c | 54 | ||||
-rw-r--r-- | main/bridge.c | 102 | ||||
-rw-r--r-- | main/channel.c | 10 | ||||
-rw-r--r-- | main/config.c | 21 | ||||
-rw-r--r-- | main/config_options.c | 79 | ||||
-rw-r--r-- | main/manager.c | 46 | ||||
-rw-r--r-- | main/named_acl.c | 22 | ||||
-rw-r--r-- | main/plc.c | 9 | ||||
-rw-r--r-- | main/sounds.c | 32 | ||||
-rw-r--r-- | main/stringfields.c | 34 | ||||
-rw-r--r-- | main/taskprocessor.c | 17 | ||||
-rw-r--r-- | main/test.c | 68 | ||||
-rw-r--r-- | main/translate.c | 18 |
14 files changed, 254 insertions, 260 deletions
diff --git a/main/Makefile b/main/Makefile index cd5c08c02..fb985b9b8 100644 --- a/main/Makefile +++ b/main/Makefile @@ -294,7 +294,7 @@ ASTPJ_LIB:=libasteriskpj.dylib # /lib or /usr/lib $(ASTPJ_LIB): _ASTLDFLAGS+=-dynamiclib -install_name $(ASTLIBDIR)/$(ASTPJ_LIB) $(PJ_LDFLAGS) $(ASTPJ_LIB): _ASTCFLAGS+=-fPIC -DAST_MODULE=\"asteriskpj\" $(PJ_CFLAGS) -DAST_NOT_MODULE -$(ASTPJ_LIB): LIBS+=$(PJPROJECT_LIBS) $(OPENSSL_LIB) $(UUID_LIB) -lm -lpthread $(RT_LIB) +$(ASTPJ_LIB): LIBS+=$(PJPROJECT_LIB) $(OPENSSL_LIB) $(UUID_LIB) -lm -lpthread $(RT_LIB) $(ASTPJ_LIB): SOLINK=$(DYLINK) # Special rules for building a shared library (not a dynamically loadable module) diff --git a/main/asterisk.c b/main/asterisk.c index 2a7e30166..36b1b54a1 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -599,6 +599,7 @@ static char *handle_show_settings(struct ast_cli_entry *e, int cmd, struct ast_c ast_cli(a->fd, " Transcode via SLIN: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSCODE_VIA_SLIN) ? "Enabled" : "Disabled"); ast_cli(a->fd, " Transmit silence during rec: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSMIT_SILENCE) ? "Enabled" : "Disabled"); ast_cli(a->fd, " Generic PLC: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_GENERIC_PLC) ? "Enabled" : "Disabled"); + ast_cli(a->fd, " Generic PLC on equal codecs: %s\n", ast_test_flag(&ast_options, AST_OPT_FLAG_GENERIC_PLC_ON_EQUAL_CODECS) ? "Enabled" : "Disabled"); ast_cli(a->fd, " Min DTMF duration:: %u\n", option_dtmfminduration); #if !defined(LOW_MEMORY) ast_cli(a->fd, " Cache media frames: %s\n", ast_opt_cache_media_frames ? "Enabled" : "Disabled"); @@ -2725,10 +2726,14 @@ static void send_rasterisk_connect_commands(void) } #ifdef HAVE_LIBEDIT_IS_UNICODE -static int ast_el_read_char(EditLine *editline, wchar_t *cp) +#define CHAR_T_LIBEDIT wchar_t +#define CHAR_TO_LIBEDIT(c) btowc(c) #else -static int ast_el_read_char(EditLine *editline, char *cp) +#define CHAR_T_LIBEDIT char +#define CHAR_TO_LIBEDIT(c) c #endif + +static int ast_el_read_char(EditLine *editline, CHAR_T_LIBEDIT *cp) { int num_read = 0; int lastpos = 0; @@ -2749,28 +2754,29 @@ static int ast_el_read_char(EditLine *editline, char *cp) } res = ast_poll(fds, max, -1); if (res < 0) { - if (sig_flags.need_quit || sig_flags.need_quit_handler) + if (sig_flags.need_quit || sig_flags.need_quit_handler) { break; - if (errno == EINTR) + } + if (errno == EINTR) { continue; + } fprintf(stderr, "poll failed: %s\n", strerror(errno)); break; } if (!ast_opt_exec && fds[1].revents) { char c = '\0'; + num_read = read(STDIN_FILENO, &c, 1); if (num_read < 1) { break; - } else { -#ifdef HAVE_LIBEDIT_IS_UNICODE - *cp = btowc(c); -#else - *cp = c; -#endif - return (num_read); } + + *cp = CHAR_TO_LIBEDIT(c); + + return num_read; } + if (fds[0].revents) { res = read(ast_consock, buf, sizeof(buf) - 1); /* if the remote side disappears exit */ @@ -2781,6 +2787,7 @@ static int ast_el_read_char(EditLine *editline, char *cp) } else { int tries; int reconnects_per_second = 20; + fprintf(stderr, "Attempting to reconnect for 30 seconds\n"); for (tries = 0; tries < 30 * reconnects_per_second; tries++) { if (ast_tryconnect()) { @@ -2789,8 +2796,9 @@ static int ast_el_read_char(EditLine *editline, char *cp) WELCOME_MESSAGE; send_rasterisk_connect_commands(); break; - } else - usleep(1000000 / reconnects_per_second); + } + + usleep(1000000 / reconnects_per_second); } if (tries >= 30 * reconnects_per_second) { fprintf(stderr, "Failed to reconnect for 30 seconds. Quitting.\n"); @@ -2811,25 +2819,17 @@ static int ast_el_read_char(EditLine *editline, char *cp) console_print(buf); if ((res < EL_BUF_SIZE - 1) && ((buf[res-1] == '\n') || (res >= 2 && buf[res-2] == '\n'))) { -#ifdef HAVE_LIBEDIT_IS_UNICODE - *cp = btowc(CC_REFRESH); -#else - *cp = CC_REFRESH; -#endif - return(1); - } else { - lastpos = 1; + *cp = CHAR_TO_LIBEDIT(CC_REFRESH); + + return 1; } + lastpos = 1; } } -#ifdef HAVE_LIBEDIT_IS_UNICODE - *cp = btowc('\0'); -#else - *cp = '\0'; -#endif + *cp = CHAR_TO_LIBEDIT('\0'); - return (0); + return 0; } static struct ast_str *prompt = NULL; diff --git a/main/bridge.c b/main/bridge.c index 4f79852cb..1109c4b76 100644 --- a/main/bridge.c +++ b/main/bridge.c @@ -5027,46 +5027,29 @@ struct ast_bridge *ast_bridge_find_by_id(const char *bridge_id) return ao2_find(bridges, bridge_id, OBJ_SEARCH_KEY); } -struct bridge_complete { - /*! Nth match to return. */ - int state; - /*! Which match currently on. */ - int which; -}; - -static int complete_bridge_live_search(void *obj, void *arg, void *data, int flags) +static int complete_bridge_live_search(void *obj, void *arg, int flags) { - struct bridge_complete *search = data; + struct ast_bridge *bridge = obj; - if (++search->which > search->state) { - return CMP_MATCH; + if (ast_cli_completion_add(ast_strdup(bridge->uniqueid))) { + return CMP_STOP; } + return 0; } -static char *complete_bridge_live(const char *word, int state) +static char *complete_bridge_live(const char *word) { - char *ret; - struct ast_bridge *bridge; - struct bridge_complete search = { - .state = state, - }; + ao2_callback(bridges, ast_strlen_zero(word) ? 0 : OBJ_PARTIAL_KEY, + complete_bridge_live_search, (char *) word); - bridge = ao2_callback_data(bridges, ast_strlen_zero(word) ? 0 : OBJ_PARTIAL_KEY, - complete_bridge_live_search, (char *) word, &search); - if (!bridge) { - return NULL; - } - ret = ast_strdup(bridge->uniqueid); - ao2_ref(bridge, -1); - return ret; + return NULL; } -static char *complete_bridge_stasis(const char *word, int state) +static char *complete_bridge_stasis(const char *word) { - char *ret = NULL; - int wordlen = strlen(word), which = 0; - RAII_VAR(struct ao2_container *, cached_bridges, NULL, ao2_cleanup); + int wordlen = strlen(word); + struct ao2_container *cached_bridges; struct ao2_iterator iter; struct stasis_message *msg; @@ -5079,15 +5062,17 @@ static char *complete_bridge_stasis(const char *word, int state) for (; (msg = ao2_iterator_next(&iter)); ao2_ref(msg, -1)) { struct ast_bridge_snapshot *snapshot = stasis_message_data(msg); - if (!strncasecmp(word, snapshot->uniqueid, wordlen) && (++which > state)) { - ret = ast_strdup(snapshot->uniqueid); - ao2_ref(msg, -1); - break; + if (!strncasecmp(word, snapshot->uniqueid, wordlen)) { + if (ast_cli_completion_add(ast_strdup(snapshot->uniqueid))) { + ao2_ref(msg, -1); + break; + } } } ao2_iterator_destroy(&iter); + ao2_ref(cached_bridges, -1); - return ret; + return NULL; } static char *handle_bridge_show_all(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) @@ -5168,7 +5153,7 @@ static char *handle_bridge_show_specific(struct ast_cli_entry *e, int cmd, struc return NULL; case CLI_GENERATE: if (a->pos == 2) { - return complete_bridge_stasis(a->word, a->n); + return complete_bridge_stasis(a->word); } return NULL; } @@ -5207,7 +5192,7 @@ static char *handle_bridge_destroy_specific(struct ast_cli_entry *e, int cmd, st return NULL; case CLI_GENERATE: if (a->pos == 2) { - return complete_bridge_live(a->word, a->n); + return complete_bridge_live(a->word); } return NULL; } @@ -5229,11 +5214,10 @@ static char *handle_bridge_destroy_specific(struct ast_cli_entry *e, int cmd, st } #endif -static char *complete_bridge_participant(const char *bridge_name, const char *line, const char *word, int pos, int state) +static char *complete_bridge_participant(const char *bridge_name, const char *word) { struct ast_bridge *bridge; struct ast_bridge_channel *bridge_channel; - int which; int wordlen; bridge = ast_bridge_find_by_id(bridge_name); @@ -5241,19 +5225,17 @@ static char *complete_bridge_participant(const char *bridge_name, const char *li return NULL; } - { - SCOPED_LOCK(bridge_lock, bridge, ast_bridge_lock, ast_bridge_unlock); + wordlen = strlen(word); - which = 0; - wordlen = strlen(word); - AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) { - if (!strncasecmp(ast_channel_name(bridge_channel->chan), word, wordlen) - && ++which > state) { - ao2_ref(bridge, -1); - return ast_strdup(ast_channel_name(bridge_channel->chan)); + ast_bridge_lock(bridge); + AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) { + if (!strncasecmp(ast_channel_name(bridge_channel->chan), word, wordlen)) { + if (ast_cli_completion_add(ast_strdup(ast_channel_name(bridge_channel->chan)))) { + break; } } } + ast_bridge_unlock(bridge); ao2_ref(bridge, -1); @@ -5263,7 +5245,6 @@ static char *complete_bridge_participant(const char *bridge_name, const char *li static char *handle_bridge_kick_channel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { static const char * const completions[] = { "all", NULL }; - char *complete; struct ast_bridge *bridge; switch (cmd) { @@ -5277,14 +5258,11 @@ static char *handle_bridge_kick_channel(struct ast_cli_entry *e, int cmd, struct return NULL; case CLI_GENERATE: if (a->pos == 2) { - return complete_bridge_live(a->word, a->n); + return complete_bridge_live(a->word); } if (a->pos == 3) { - complete = ast_cli_complete(a->word, completions, a->n); - if (!complete) { - complete = complete_bridge_participant(a->argv[2], a->line, a->word, a->pos, a->n - 1); - } - return complete; + ast_cli_complete(a->word, completions, -1); + return complete_bridge_participant(a->argv[2], a->word); } return NULL; } @@ -5385,24 +5363,22 @@ static char *handle_bridge_technology_show(struct ast_cli_entry *e, int cmd, str #undef FORMAT } -static char *complete_bridge_technology(const char *word, int state) +static char *complete_bridge_technology(const char *word) { struct ast_bridge_technology *cur; - char *res; - int which; int wordlen; - which = 0; wordlen = strlen(word); AST_RWLIST_RDLOCK(&bridge_technologies); AST_RWLIST_TRAVERSE(&bridge_technologies, cur, entry) { - if (!strncasecmp(cur->name, word, wordlen) && ++which > state) { - res = ast_strdup(cur->name); - AST_RWLIST_UNLOCK(&bridge_technologies); - return res; + if (!strncasecmp(cur->name, word, wordlen)) { + if (ast_cli_completion_add(ast_strdup(cur->name))) { + break; + } } } AST_RWLIST_UNLOCK(&bridge_technologies); + return NULL; } @@ -5421,7 +5397,7 @@ static char *handle_bridge_technology_suspend(struct ast_cli_entry *e, int cmd, return NULL; case CLI_GENERATE: if (a->pos == 3) { - return complete_bridge_technology(a->word, a->n); + return complete_bridge_technology(a->word); } return NULL; } diff --git a/main/channel.c b/main/channel.c index 34991ff2b..869b29f5e 100644 --- a/main/channel.c +++ b/main/channel.c @@ -6463,11 +6463,15 @@ static int ast_channel_make_compatible_helper(struct ast_channel *from, struct a * to use SLINEAR between channels, but only if there is * no direct conversion available. If generic PLC is * desired, then transcoding via SLINEAR is a requirement + * even if the formats are the same. */ - if (ast_format_cmp(best_dst_fmt, best_src_fmt) == AST_FORMAT_CMP_NOT_EQUAL - && (ast_opt_generic_plc || ast_opt_transcode_via_slin)) { + if (ast_opt_generic_plc_on_equal_codecs + || (ast_format_cmp(best_dst_fmt, best_src_fmt) == AST_FORMAT_CMP_NOT_EQUAL + && (ast_opt_generic_plc || ast_opt_transcode_via_slin))) { + int use_slin = (ast_format_cache_is_slinear(best_src_fmt) - || ast_format_cache_is_slinear(best_dst_fmt)) ? 1 : 0; + || ast_format_cache_is_slinear(best_dst_fmt)) + ? 1 : ast_opt_generic_plc_on_equal_codecs; if (use_slin || ast_translate_path_steps(best_dst_fmt, best_src_fmt) != 1) { int best_sample_rate = (ast_format_get_sample_rate(best_src_fmt) > ast_format_get_sample_rate(best_dst_fmt)) ? diff --git a/main/config.c b/main/config.c index f2c336049..f7f0d7be1 100644 --- a/main/config.c +++ b/main/config.c @@ -3925,8 +3925,8 @@ static char *handle_cli_core_show_config_mappings(struct ast_cli_entry *e, int c static char *handle_cli_config_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct cache_file_mtime *cfmtime; - char *prev = "", *completion_value = NULL; - int wordlen, which = 0; + char *prev = ""; + int wordlen; switch (cmd) { case CLI_INIT: @@ -3944,19 +3944,20 @@ static char *handle_cli_config_reload(struct ast_cli_entry *e, int cmd, struct a AST_LIST_LOCK(&cfmtime_head); AST_LIST_TRAVERSE(&cfmtime_head, cfmtime, list) { - /* Skip duplicates - this only works because the list is sorted by filename */ - if (strcmp(cfmtime->filename, prev) == 0) { + /* Core configs cannot be reloaded */ + if (ast_strlen_zero(cfmtime->who_asked)) { continue; } - /* Core configs cannot be reloaded */ - if (ast_strlen_zero(cfmtime->who_asked)) { + /* Skip duplicates - this only works because the list is sorted by filename */ + if (!strcmp(cfmtime->filename, prev)) { continue; } - if (++which > a->n && strncmp(cfmtime->filename, a->word, wordlen) == 0) { - completion_value = ast_strdup(cfmtime->filename); - break; + if (!strncmp(cfmtime->filename, a->word, wordlen)) { + if (ast_cli_completion_add(ast_strdup(cfmtime->filename))) { + break; + } } /* Otherwise save that we've seen this filename */ @@ -3964,7 +3965,7 @@ static char *handle_cli_config_reload(struct ast_cli_entry *e, int cmd, struct a } AST_LIST_UNLOCK(&cfmtime_head); - return completion_value; + return NULL; } if (a->argc != 3) { diff --git a/main/config_options.c b/main/config_options.c index 3aa00f921..41c8b222c 100644 --- a/main/config_options.c +++ b/main/config_options.c @@ -958,88 +958,79 @@ int aco_set_defaults(struct aco_type *type, const char *category, void *obj) /*! \internal * \brief Complete the name of the module the user is looking for */ -static char *complete_config_module(const char *word, int pos, int state) +static char *complete_config_module(const char *word) { - char *c = NULL; size_t wordlen = strlen(word); - int which = 0; struct ao2_iterator i; struct ast_xml_doc_item *cur; - if (pos != 3) { - return NULL; - } - i = ao2_iterator_init(xmldocs, 0); while ((cur = ao2_iterator_next(&i))) { - if (!strncasecmp(word, cur->name, wordlen) && ++which > state) { - c = ast_strdup(cur->name); - ao2_ref(cur, -1); - break; + if (!strncasecmp(word, cur->name, wordlen)) { + if (ast_cli_completion_add(ast_strdup(cur->name))) { + ao2_ref(cur, -1); + break; + } } ao2_ref(cur, -1); } ao2_iterator_destroy(&i); - return c; + return NULL; } /*! \internal * \brief Complete the name of the configuration type the user is looking for */ -static char *complete_config_type(const char *module, const char *word, int pos, int state) +static char *complete_config_type(const char *module, const char *word) { - char *c = NULL; size_t wordlen = strlen(word); - int which = 0; - RAII_VAR(struct ast_xml_doc_item *, info, NULL, ao2_cleanup); + struct ast_xml_doc_item *info; struct ast_xml_doc_item *cur; - if (pos != 4) { - return NULL; - } - - if (!(info = ao2_find(xmldocs, module, OBJ_KEY))) { + info = ao2_find(xmldocs, module, OBJ_KEY); + if (!info) { return NULL; } cur = info; while ((cur = AST_LIST_NEXT(cur, next))) { - if (!strcasecmp(cur->type, "configObject") && !strncasecmp(word, cur->name, wordlen) && ++which > state) { - c = ast_strdup(cur->name); - break; + if (!strcasecmp(cur->type, "configObject") && !strncasecmp(word, cur->name, wordlen)) { + if (ast_cli_completion_add(ast_strdup(cur->name))) { + break; + } } } - return c; + ao2_ref(info, -1); + + return NULL; } /*! \internal * \brief Complete the name of the configuration option the user is looking for */ -static char *complete_config_option(const char *module, const char *option, const char *word, int pos, int state) +static char *complete_config_option(const char *module, const char *option, const char *word) { - char *c = NULL; size_t wordlen = strlen(word); - int which = 0; - RAII_VAR(struct ast_xml_doc_item *, info, NULL, ao2_cleanup); + struct ast_xml_doc_item *info; struct ast_xml_doc_item *cur; - if (pos != 5) { - return NULL; - } - - if (!(info = ao2_find(xmldocs, module, OBJ_KEY))) { + info = ao2_find(xmldocs, module, OBJ_KEY); + if (!info) { return NULL; } cur = info; while ((cur = AST_LIST_NEXT(cur, next))) { - if (!strcasecmp(cur->type, "configOption") && !strcasecmp(cur->ref, option) && !strncasecmp(word, cur->name, wordlen) && ++which > state) { - c = ast_strdup(cur->name); - break; + if (!strcasecmp(cur->type, "configOption") && !strcasecmp(cur->ref, option) && !strncasecmp(word, cur->name, wordlen)) { + if (ast_cli_completion_add(ast_strdup(cur->name))) { + break; + } } } - return c; + ao2_ref(info, -1); + + return NULL; } /* Define as 0 if we want to allow configurations to be registered without @@ -1340,10 +1331,14 @@ static char *cli_show_help(struct ast_cli_entry *e, int cmd, struct ast_cli_args return NULL; case CLI_GENERATE: switch(a->pos) { - case 3: return complete_config_module(a->word, a->pos, a->n); - case 4: return complete_config_type(a->argv[3], a->word, a->pos, a->n); - case 5: return complete_config_option(a->argv[3], a->argv[4], a->word, a->pos, a->n); - default: return NULL; + case 3: + return complete_config_module(a->word); + case 4: + return complete_config_type(a->argv[3], a->word); + case 5: + return complete_config_option(a->argv[3], a->argv[4], a->word); + default: + return NULL; } } diff --git a/main/manager.c b/main/manager.c index 64b07d319..577c7f928 100644 --- a/main/manager.c +++ b/main/manager.c @@ -2325,9 +2325,9 @@ static char *handle_showmancmd(struct ast_cli_entry *e, int cmd, struct ast_cli_ { struct manager_action *cur; struct ast_str *authority; - int num, l, which; + int num; + int l; const char *auth_str; - char *ret = NULL; #ifdef AST_XML_DOCS char syntax_title[64], description_title[64], synopsis_title[64], seealso_title[64]; char arguments_title[64], privilege_title[64], final_response_title[64], list_responses_title[64]; @@ -2342,16 +2342,16 @@ static char *handle_showmancmd(struct ast_cli_entry *e, int cmd, struct ast_cli_ return NULL; case CLI_GENERATE: l = strlen(a->word); - which = 0; AST_RWLIST_RDLOCK(&actions); AST_RWLIST_TRAVERSE(&actions, cur, list) { - if (!strncasecmp(a->word, cur->action, l) && ++which > a->n) { - ret = ast_strdup(cur->action); - break; /* make sure we exit even if ast_strdup() returns NULL */ + if (!strncasecmp(a->word, cur->action, l)) { + if (ast_cli_completion_add(ast_strdup(cur->action))) { + break; + } } } AST_RWLIST_UNLOCK(&actions); - return ret; + return NULL; } if (a->argc < 4) { return CLI_SHOWUSAGE; @@ -2481,8 +2481,7 @@ static char *handle_mandebug(struct ast_cli_entry *e, int cmd, struct ast_cli_ar static char *handle_showmanager(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct ast_manager_user *user = NULL; - int l, which; - char *ret = NULL; + int l; struct ast_str *rauthority = ast_str_alloca(MAX_AUTH_PERM_STRING); struct ast_str *wauthority = ast_str_alloca(MAX_AUTH_PERM_STRING); struct ast_variable *v; @@ -2496,19 +2495,19 @@ static char *handle_showmanager(struct ast_cli_entry *e, int cmd, struct ast_cli return NULL; case CLI_GENERATE: l = strlen(a->word); - which = 0; if (a->pos != 3) { return NULL; } AST_RWLIST_RDLOCK(&users); AST_RWLIST_TRAVERSE(&users, user, list) { - if ( !strncasecmp(a->word, user->username, l) && ++which > a->n ) { - ret = ast_strdup(user->username); - break; + if (!strncasecmp(a->word, user->username, l)) { + if (ast_cli_completion_add(ast_strdup(user->username))) { + break; + } } } AST_RWLIST_UNLOCK(&users); - return ret; + return NULL; } if (a->argc != 4) { @@ -8645,8 +8644,6 @@ static char *handle_manager_show_event(struct ast_cli_entry *e, int cmd, struct struct ao2_iterator it_events; struct ast_xml_doc_item *item, *temp; int length; - int which; - char *match = NULL; if (cmd == CLI_INIT) { e->command = "manager show event"; @@ -8663,19 +8660,24 @@ static char *handle_manager_show_event(struct ast_cli_entry *e, int cmd, struct } if (cmd == CLI_GENERATE) { + if (a->pos != 3) { + return NULL; + } + length = strlen(a->word); - which = 0; it_events = ao2_iterator_init(events, 0); while ((item = ao2_iterator_next(&it_events))) { - if (!strncasecmp(a->word, item->name, length) && ++which > a->n) { - match = ast_strdup(item->name); - ao2_ref(item, -1); - break; + if (!strncasecmp(a->word, item->name, length)) { + if (ast_cli_completion_add(ast_strdup(item->name))) { + ao2_ref(item, -1); + break; + } } ao2_ref(item, -1); } ao2_iterator_destroy(&it_events); - return match; + + return NULL; } if (a->argc != 4) { diff --git a/main/named_acl.c b/main/named_acl.c index 4f2069a75..c4628216f 100644 --- a/main/named_acl.c +++ b/main/named_acl.c @@ -475,12 +475,10 @@ static void cli_display_named_acl_list(int fd) /* \brief ACL command show <name> */ static char *handle_show_named_acl_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { - RAII_VAR(struct named_acl_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup); + struct named_acl_config *cfg; int length; - int which; struct ao2_iterator i; struct named_acl *named_acl; - char *match = NULL; switch (cmd) { case CLI_INIT: @@ -490,23 +488,29 @@ static char *handle_show_named_acl_cmd(struct ast_cli_entry *e, int cmd, struct " Shows a list of named ACLs or lists all entries in a given named ACL.\n"; return NULL; case CLI_GENERATE: + if (a->pos != 2) { + return NULL; + } + + cfg = ao2_global_obj_ref(globals); if (!cfg) { return NULL; } length = strlen(a->word); - which = 0; i = ao2_iterator_init(cfg->named_acl_list, 0); while ((named_acl = ao2_iterator_next(&i))) { - if (!strncasecmp(a->word, named_acl->name, length) && ++which > a->n) { - match = ast_strdup(named_acl->name); - ao2_ref(named_acl, -1); - break; + if (!strncasecmp(a->word, named_acl->name, length)) { + if (ast_cli_completion_add(ast_strdup(named_acl->name))) { + ao2_ref(named_acl, -1); + break; + } } ao2_ref(named_acl, -1); } ao2_iterator_destroy(&i); - return match; + ao2_ref(cfg, -1); + return NULL; } if (a->argc == 2) { diff --git a/main/plc.c b/main/plc.c index 847ce65b0..369d285a5 100644 --- a/main/plc.c +++ b/main/plc.c @@ -262,10 +262,19 @@ static int reload_module(void) for (var = ast_variable_browse(cfg, "plc"); var; var = var->next) { if (!strcasecmp(var->name, "genericplc")) { ast_set2_flag(&ast_options, ast_true(var->value), AST_OPT_FLAG_GENERIC_PLC); + } else if (!strcasecmp(var->name, "genericplc_on_equal_codecs")) { + ast_set2_flag(&ast_options, ast_true(var->value), AST_OPT_FLAG_GENERIC_PLC_ON_EQUAL_CODECS); } } ast_config_destroy(cfg); + /* + * Force on_equal_codecs to false if generic_plc is false. + */ + if (!ast_opt_generic_plc) { + ast_set2_flag(&ast_options, 0, AST_OPT_FLAG_GENERIC_PLC_ON_EQUAL_CODECS); + } + return 0; } diff --git a/main/sounds.c b/main/sounds.c index 08e29275e..745b62805 100644 --- a/main/sounds.c +++ b/main/sounds.c @@ -219,6 +219,11 @@ static char *handle_cli_sounds_show(struct ast_cli_entry *e, int cmd, struct ast /*! \brief Show details about a sound available in the system */ static char *handle_cli_sound_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { + int length; + struct ao2_iterator it_sounds; + char *filename; + struct ao2_container *sound_files; + switch (cmd) { case CLI_INIT: e->command = "core show sound"; @@ -227,29 +232,30 @@ static char *handle_cli_sound_show(struct ast_cli_entry *e, int cmd, struct ast_ " Shows information about the specified sound.\n"; return NULL; case CLI_GENERATE: - { - int length = strlen(a->word); - int which = 0; - struct ao2_iterator it_sounds; - char *match = NULL; - char *filename; - RAII_VAR(struct ao2_container *, sound_files, ast_media_get_media(sounds_index), ao2_cleanup); + if (a->pos != 3) { + return NULL; + } + + sound_files = ast_media_get_media(sounds_index); if (!sound_files) { return NULL; } + length = strlen(a->word); it_sounds = ao2_iterator_init(sound_files, 0); while ((filename = ao2_iterator_next(&it_sounds))) { - if (!strncasecmp(a->word, filename, length) && ++which > a->n) { - match = ast_strdup(filename); - ao2_ref(filename, -1); - break; + if (!strncasecmp(a->word, filename, length)) { + if (ast_cli_completion_add(ast_strdup(filename))) { + ao2_ref(filename, -1); + break; + } } ao2_ref(filename, -1); } ao2_iterator_destroy(&it_sounds); - return match; - } + ao2_ref(sound_files, -1); + + return NULL; } if (a->argc == 4) { diff --git a/main/stringfields.c b/main/stringfields.c index 30aa8cddd..0a9e59903 100644 --- a/main/stringfields.c +++ b/main/stringfields.c @@ -179,11 +179,6 @@ int __ast_string_field_init(struct ast_string_field_mgr *mgr, struct ast_string_ } mgr->last_alloc = NULL; - /* v-- MALLOC_DEBUG information */ - mgr->owner_file = file; - mgr->owner_func = func; - mgr->owner_line = lineno; - /* ^-- MALLOC_DEBUG information */ if (AST_VECTOR_INIT(&mgr->string_fields, initial_vector_size)) { return -1; @@ -205,7 +200,8 @@ int __ast_string_field_init(struct ast_string_field_mgr *mgr, struct ast_string_ } ast_string_field __ast_string_field_alloc_space(struct ast_string_field_mgr *mgr, - struct ast_string_field_pool **pool_head, size_t needed) + struct ast_string_field_pool **pool_head, size_t needed, + const char *file, int lineno, const char *func) { char *result = NULL; size_t space = (*pool_head)->size - (*pool_head)->used; @@ -222,8 +218,7 @@ ast_string_field __ast_string_field_alloc_space(struct ast_string_field_mgr *mgr new_size *= 2; } - if (add_string_pool(mgr, pool_head, new_size, - mgr->owner_file, mgr->owner_line, mgr->owner_func)) { + if (add_string_pool(mgr, pool_head, new_size, file, lineno, func)) { return NULL; } } @@ -290,7 +285,8 @@ void __ast_string_field_release_active(struct ast_string_field_pool *pool_head, void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, ast_string_field *ptr, - const char *format, va_list ap) + const char *format, va_list ap, + const char *file, int lineno, const char *func) { size_t needed; size_t available; @@ -342,7 +338,8 @@ void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr, (if it has one), or the space available in the pool (if it does not). allocate space for it, adding a new string pool if necessary. */ - if (!(target = (char *) __ast_string_field_alloc_space(mgr, pool_head, needed))) { + target = (char *) __ast_string_field_alloc_space(mgr, pool_head, needed, file, lineno, func); + if (!target) { return; } vsprintf(target, format, ap); @@ -369,13 +366,14 @@ void __ast_string_field_ptr_build_va(struct ast_string_field_mgr *mgr, } } -void __ast_string_field_ptr_build(struct ast_string_field_mgr *mgr, +void __ast_string_field_ptr_build(const char *file, int lineno, const char *func, + struct ast_string_field_mgr *mgr, struct ast_string_field_pool **pool_head, ast_string_field *ptr, const char *format, ...) { va_list ap; va_start(ap, format); - __ast_string_field_ptr_build_va(mgr, pool_head, ptr, format, ap); + __ast_string_field_ptr_build_va(mgr, pool_head, ptr, format, ap, file, lineno, func); va_end(ap); } @@ -419,11 +417,6 @@ void *__ast_calloc_with_stringfields(unsigned int num_structs, size_t struct_siz mgr->embedded_pool = pool; *pool_head = pool; pool->size = size_to_alloc - struct_size - sizeof(*pool); - /* v-- MALLOC_DEBUG information */ - mgr->owner_file = file; - mgr->owner_func = func; - mgr->owner_line = lineno; - /* ^-- MALLOC_DEBUG information */ return allocation; } @@ -446,7 +439,8 @@ int __ast_string_fields_cmp(struct ast_string_field_vector *left, } int __ast_string_fields_copy(struct ast_string_field_pool *copy_pool, - struct ast_string_field_mgr *copy_mgr, struct ast_string_field_mgr *orig_mgr) + struct ast_string_field_mgr *copy_mgr, struct ast_string_field_mgr *orig_mgr, + const char *file, int lineno, const char *func) { int i; struct ast_string_field_vector *dest = &(copy_mgr->string_fields); @@ -460,8 +454,8 @@ int __ast_string_fields_copy(struct ast_string_field_pool *copy_pool, } for (i = 0; i < AST_VECTOR_SIZE(dest); i++) { - if (ast_string_field_ptr_set_by_fields(copy_pool, *copy_mgr, AST_VECTOR_GET(dest, i), - *AST_VECTOR_GET(src, i))) { + if (__ast_string_field_ptr_set_by_fields(copy_pool, *copy_mgr, AST_VECTOR_GET(dest, i), + *AST_VECTOR_GET(src, i), file, lineno, func)) { return -1; } } diff --git a/main/taskprocessor.c b/main/taskprocessor.c index cf82efff2..91eb7d993 100644 --- a/main/taskprocessor.c +++ b/main/taskprocessor.c @@ -341,26 +341,27 @@ static void *tps_task_free(struct tps_task *task) static char *tps_taskprocessor_tab_complete(struct ast_cli_args *a) { int tklen; - int wordnum = 0; struct ast_taskprocessor *p; - char *name = NULL; struct ao2_iterator i; - if (a->pos != 3) + if (a->pos != 3) { return NULL; + } tklen = strlen(a->word); i = ao2_iterator_init(tps_singletons, 0); while ((p = ao2_iterator_next(&i))) { - if (!strncasecmp(a->word, p->name, tklen) && ++wordnum > a->n) { - name = ast_strdup(p->name); - ast_taskprocessor_unreference(p); - break; + if (!strncasecmp(a->word, p->name, tklen)) { + if (ast_cli_completion_add(ast_strdup(p->name))) { + ast_taskprocessor_unreference(p); + break; + } } ast_taskprocessor_unreference(p); } ao2_iterator_destroy(&i); - return name; + + return NULL; } /* ping task handling function */ diff --git a/main/test.c b/main/test.c index f45ad9b62..b117c0814 100644 --- a/main/test.c +++ b/main/test.c @@ -691,40 +691,40 @@ static struct ast_test *test_alloc(ast_test_cb_t *cb) return test; } -static char *complete_test_category(const char *line, const char *word, int pos, int state) +static char *complete_test_category(const char *word) { - int which = 0; int wordlen = strlen(word); - char *ret = NULL; struct ast_test *test; AST_LIST_LOCK(&tests); AST_LIST_TRAVERSE(&tests, test, entry) { - if (!strncasecmp(word, test->info.category, wordlen) && ++which > state) { - ret = ast_strdup(test->info.category); - break; + if (!strncasecmp(word, test->info.category, wordlen)) { + if (ast_cli_completion_add(ast_strdup(test->info.category))) { + break; + } } } AST_LIST_UNLOCK(&tests); - return ret; + + return NULL; } -static char *complete_test_name(const char *line, const char *word, int pos, int state, const char *category) +static char *complete_test_name(const char *word, const char *category) { - int which = 0; int wordlen = strlen(word); - char *ret = NULL; struct ast_test *test; AST_LIST_LOCK(&tests); AST_LIST_TRAVERSE(&tests, test, entry) { - if (!test_cat_cmp(test->info.category, category) && (!strncasecmp(word, test->info.name, wordlen) && ++which > state)) { - ret = ast_strdup(test->info.name); - break; + if (!test_cat_cmp(test->info.category, category) && !strncasecmp(word, test->info.name, wordlen)) { + if (ast_cli_completion_add(ast_strdup(test->info.name))) { + break; + } } } AST_LIST_UNLOCK(&tests); - return ret; + + return NULL; } /* CLI commands */ @@ -749,22 +749,22 @@ static char *test_cli_show_registered(struct ast_cli_entry *e, int cmd, struct a return NULL; case CLI_GENERATE: if (a->pos == 3) { - return ast_cli_complete(a->word, option1, a->n); + return ast_cli_complete(a->word, option1, -1); } - if (a->pos == 4) { - return complete_test_category(a->line, a->word, a->pos, a->n); + if (a->pos == 4 && !strcasecmp(a->argv[3], "category")) { + return complete_test_category(a->word); } if (a->pos == 5) { - return ast_cli_complete(a->word, option2, a->n); + return ast_cli_complete(a->word, option2, -1); } if (a->pos == 6) { - return complete_test_name(a->line, a->word, a->pos, a->n, a->argv[3]); + return complete_test_name(a->word, a->argv[4]); } return NULL; case CLI_HANDLER: if ((a->argc < 4) || (a->argc == 6) || (a->argc > 7) || - ((a->argc == 4) && strcmp(a->argv[3], "all")) || - ((a->argc == 7) && strcmp(a->argv[5], "name"))) { + ((a->argc == 4) && strcasecmp(a->argv[3], "all")) || + ((a->argc == 7) && strcasecmp(a->argv[5], "name"))) { return CLI_SHOWUSAGE; } ast_cli(a->fd, FORMAT, "Category", "Name", "Summary", "Test Result"); @@ -808,16 +808,16 @@ static char *test_cli_execute_registered(struct ast_cli_entry *e, int cmd, struc return NULL; case CLI_GENERATE: if (a->pos == 2) { - return ast_cli_complete(a->word, option1, a->n); + return ast_cli_complete(a->word, option1, -1); } - if (a->pos == 3) { - return complete_test_category(a->line, a->word, a->pos, a->n); + if (a->pos == 3 && !strcasecmp(a->argv[2], "category")) { + return complete_test_category(a->word); } if (a->pos == 4) { - return ast_cli_complete(a->word, option2, a->n); + return ast_cli_complete(a->word, option2, -1); } if (a->pos == 5) { - return complete_test_name(a->line, a->word, a->pos, a->n, a->argv[3]); + return complete_test_name(a->word, a->argv[3]); } return NULL; case CLI_HANDLER: @@ -826,7 +826,7 @@ static char *test_cli_execute_registered(struct ast_cli_entry *e, int cmd, struc return CLI_SHOWUSAGE; } - if ((a->argc == 3) && !strcmp(a->argv[2], "all")) { /* run all registered tests */ + if ((a->argc == 3) && !strcasecmp(a->argv[2], "all")) { /* run all registered tests */ ast_cli(a->fd, "Running all available tests...\n\n"); test_execute_multiple(NULL, NULL, a); } else if (a->argc == 4) { /* run only tests within a category */ @@ -877,7 +877,7 @@ static char *test_cli_show_results(struct ast_cli_entry *e, int cmd, struct ast_ return NULL; case CLI_GENERATE: if (a->pos == 3) { - return ast_cli_complete(a->word, option1, a->n); + return ast_cli_complete(a->word, option1, -1); } return NULL; case CLI_HANDLER: @@ -885,11 +885,11 @@ static char *test_cli_show_results(struct ast_cli_entry *e, int cmd, struct ast_ /* verify input */ if (a->argc != 4) { return CLI_SHOWUSAGE; - } else if (!strcmp(a->argv[3], "passed")) { + } else if (!strcasecmp(a->argv[3], "passed")) { mode = 2; - } else if (!strcmp(a->argv[3], "failed")) { + } else if (!strcasecmp(a->argv[3], "failed")) { mode = 1; - } else if (!strcmp(a->argv[3], "all")) { + } else if (!strcasecmp(a->argv[3], "all")) { mode = 0; } else { return CLI_SHOWUSAGE; @@ -950,7 +950,7 @@ static char *test_cli_generate_results(struct ast_cli_entry *e, int cmd, struct return NULL; case CLI_GENERATE: if (a->pos == 3) { - return ast_cli_complete(a->word, option, a->n); + return ast_cli_complete(a->word, option, -1); } return NULL; case CLI_HANDLER: @@ -958,10 +958,10 @@ static char *test_cli_generate_results(struct ast_cli_entry *e, int cmd, struct /* verify input */ if (a->argc < 4 || a->argc > 5) { return CLI_SHOWUSAGE; - } else if (!strcmp(a->argv[3], "xml")) { + } else if (!strcasecmp(a->argv[3], "xml")) { type = "xml"; isxml = 1; - } else if (!strcmp(a->argv[3], "txt")) { + } else if (!strcasecmp(a->argv[3], "txt")) { type = "txt"; } else { return CLI_SHOWUSAGE; diff --git a/main/translate.c b/main/translate.c index 226d0985d..396c5522e 100644 --- a/main/translate.c +++ b/main/translate.c @@ -900,9 +900,9 @@ const char *ast_translate_path_to_str(struct ast_trans_pvt *p, struct ast_str ** return ast_str_buffer(*str); } -static char *complete_trans_path_choice(const char *line, const char *word, int pos, int state) +static char *complete_trans_path_choice(const char *word) { - int i = 1, which = 0; + int i = 1; int wordlen = strlen(word); struct ast_codec *codec; @@ -912,13 +912,15 @@ static char *complete_trans_path_choice(const char *line, const char *word, int ao2_ref(codec, -1); continue; } - if (!strncasecmp(word, codec->name, wordlen) && ++which > state) { - char *res = ast_strdup(codec->name); - ao2_ref(codec, -1); - return res; + if (!strncasecmp(word, codec->name, wordlen)) { + if (ast_cli_completion_add(ast_strdup(codec->name))) { + ao2_ref(codec, -1); + break; + } } ao2_ref(codec, -1); } + return NULL; } @@ -1138,10 +1140,10 @@ static char *handle_cli_core_show_translation(struct ast_cli_entry *e, int cmd, return NULL; case CLI_GENERATE: if (a->pos == 3) { - return ast_cli_complete(a->word, option, a->n); + return ast_cli_complete(a->word, option, -1); } if (a->pos == 4 && !strcasecmp(a->argv[3], option[1])) { - return complete_trans_path_choice(a->line, a->word, a->pos, a->n); + return complete_trans_path_choice(a->word); } /* BUGBUG - add tab completion for sample rates */ return NULL; |