[asterisk-commits] branch oej/test-this-branch r15863 - in
/team/oej/test-this-branch: ./ apps/ ...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue Mar 28 17:00:30 MST 2006
Author: oej
Date: Tue Mar 28 18:00:22 2006
New Revision: 15863
URL: http://svn.digium.com/view/asterisk?rev=15863&view=rev
Log:
Resolve conflict, reset automerge, blame KLM
Modified:
team/oej/test-this-branch/ (props changed)
team/oej/test-this-branch/.cleancount
team/oej/test-this-branch/apps/app_meetme.c
team/oej/test-this-branch/asterisk.c
team/oej/test-this-branch/channels/chan_iax2.c
team/oej/test-this-branch/channels/chan_oss.c
team/oej/test-this-branch/channels/chan_sip.c
team/oej/test-this-branch/channels/chan_zap.c
team/oej/test-this-branch/channels/iax2-provision.c
team/oej/test-this-branch/cli.c
team/oej/test-this-branch/codecs/codec_a_mu.c
team/oej/test-this-branch/codecs/codec_adpcm.c
team/oej/test-this-branch/codecs/codec_alaw.c
team/oej/test-this-branch/codecs/codec_g723_1.c
team/oej/test-this-branch/codecs/codec_g726.c
team/oej/test-this-branch/codecs/codec_gsm.c
team/oej/test-this-branch/codecs/codec_ilbc.c
team/oej/test-this-branch/codecs/codec_lpc10.c
team/oej/test-this-branch/codecs/codec_speex.c
team/oej/test-this-branch/codecs/codec_ulaw.c
team/oej/test-this-branch/include/asterisk.h
team/oej/test-this-branch/include/asterisk/cli.h
team/oej/test-this-branch/include/asterisk/module.h
team/oej/test-this-branch/include/asterisk/pbx.h
team/oej/test-this-branch/loader.c
team/oej/test-this-branch/pbx.c
team/oej/test-this-branch/pbx/pbx_config.c
team/oej/test-this-branch/res/res_clioriginate.c
team/oej/test-this-branch/res/res_smdi.c
Propchange: team/oej/test-this-branch/
------------------------------------------------------------------------------
automerge = http://edvina.net/training/
Propchange: team/oej/test-this-branch/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Mar 28 18:00:22 2006
@@ -1,1 +1,1 @@
-/trunk:1-15783
+/trunk:1-15858
Modified: team/oej/test-this-branch/.cleancount
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/.cleancount?rev=15863&r1=15862&r2=15863&view=diff
==============================================================================
--- team/oej/test-this-branch/.cleancount (original)
+++ team/oej/test-this-branch/.cleancount Tue Mar 28 18:00:22 2006
@@ -1,1 +1,1 @@
-11
+12
Modified: team/oej/test-this-branch/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/apps/app_meetme.c?rev=15863&r1=15862&r2=15863&view=diff
==============================================================================
--- team/oej/test-this-branch/apps/app_meetme.c (original)
+++ team/oej/test-this-branch/apps/app_meetme.c Tue Mar 28 18:00:22 2006
@@ -685,42 +685,36 @@
return 0;
}
-static char *complete_confcmd(const char *line, const char *word, int pos, int state) {
-#define CONF_COMMANDS 6
- int which = 0, x = 0;
+static char *complete_confcmd(const char *line, const char *word, int pos, int state)
+{
+ static char *cmds[] = {"lock", "unlock", "mute", "unmute", "kick", "list", NULL};
+
+ int len = strlen(word);
+ int which = 0;
struct ast_conference *cnf = NULL;
struct ast_conf_user *usr = NULL;
char *confno = NULL;
char usrno[50] = "";
- char cmds[CONF_COMMANDS][20] = {"lock", "unlock", "mute", "unmute", "kick", "list"};
- char *myline;
+ char *myline, *ret = NULL;
- if (pos == 1) {
- /* Command */
- for (x = 0;x < CONF_COMMANDS; x++) {
- if (!strncasecmp(cmds[x], word, strlen(word))) {
- if (++which > state) {
- return strdup(cmds[x]);
- }
- }
- }
- } else if (pos == 2) {
- /* Conference Number */
+ if (pos == 1) { /* Command */
+ return ast_cli_complete(word, cmds, state);
+ } else if (pos == 2) { /* Conference Number */
AST_LIST_LOCK(&confs);
AST_LIST_TRAVERSE(&confs, cnf, list) {
- if (!strncasecmp(word, cnf->confno, strlen(word))) {
- if (++which > state)
- break;
- }
- }
+ if (!strncasecmp(word, cnf->confno, len) && ++which > state) {
+ ret = cnf->confno;
+ break;
+ }
+ }
+ ret = ast_strdup(ret); /* dup before releasing the lock */
AST_LIST_UNLOCK(&confs);
- return cnf ? strdup(cnf->confno) : NULL;
+ return ret;
} else if (pos == 3) {
/* User Number || Conf Command option*/
if (strstr(line, "mute") || strstr(line, "kick")) {
- if ((state == 0) && (strstr(line, "kick") || strstr(line,"mute")) && !(strncasecmp(word, "all", strlen(word)))) {
+ if (state == 0 && (strstr(line, "kick") || strstr(line,"mute")) && !strncasecmp(word, "all", len))
return strdup("all");
- }
which++;
AST_LIST_LOCK(&confs);
@@ -740,10 +734,8 @@
/* Search for the user */
for (usr = cnf->firstuser; usr; usr = usr->nextuser) {
snprintf(usrno, sizeof(usrno), "%d", usr->user_no);
- if (!strncasecmp(word, usrno, strlen(word))) {
- if (++which > state)
- break;
- }
+ if (!strncasecmp(word, usrno, len) && ++which > state)
+ break;
}
}
AST_LIST_UNLOCK(&confs);
Modified: team/oej/test-this-branch/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/asterisk.c?rev=15863&r1=15862&r2=15863&view=diff
==============================================================================
--- team/oej/test-this-branch/asterisk.c (original)
+++ team/oej/test-this-branch/asterisk.c Tue Mar 28 18:00:22 2006
@@ -2142,6 +2142,7 @@
ast_ulaw_init();
ast_alaw_init();
callerid_init();
+ ast_builtins_init();
ast_utils_init();
tdd_init();
/* When Asterisk restarts after it has dropped the root privileges,
Modified: team/oej/test-this-branch/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/channels/chan_iax2.c?rev=15863&r1=15862&r2=15863&view=diff
==============================================================================
--- team/oej/test-this-branch/channels/chan_iax2.c (original)
+++ team/oej/test-this-branch/channels/chan_iax2.c Tue Mar 28 18:00:22 2006
@@ -2128,11 +2128,9 @@
if (pos == 3) {
ast_mutex_lock(&peerl.lock);
for (p = peerl.peers ; p ; p = p->next) {
- if (!strncasecmp(p->name, word, wordlen)) {
- if (++which > state) {
- res = ast_strdup(p->name);
- break;
- }
+ if (!strncasecmp(p->name, word, wordlen) && ++which > state) {
+ res = ast_strdup(p->name);
+ break;
}
}
ast_mutex_unlock(&peerl.lock);
Modified: team/oej/test-this-branch/channels/chan_oss.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/channels/chan_oss.c?rev=15863&r1=15862&r2=15863&view=diff
==============================================================================
--- team/oej/test-this-branch/channels/chan_oss.c (original)
+++ team/oej/test-this-branch/channels/chan_oss.c Tue Mar 28 18:00:22 2006
@@ -1035,19 +1035,9 @@
static char *autoanswer_complete(const char *line, const char *word, int pos, int state)
{
- int l = strlen(word);
-
- switch(state) {
- case 0:
- if (l && !strncasecmp(word, "on", MIN(l, 2)))
- return ast_strdup("on");
- case 1:
- if (l && !strncasecmp(word, "off", MIN(l, 3)))
- return ast_strdup("off");
- default:
- return NULL;
- }
- return NULL;
+ static char *choices[] = { "on", "off", NULL };
+
+ return (pos != 1) ? NULL : ast_cli_complete(word, choices, state);
}
static char autoanswer_usage[] =
Modified: team/oej/test-this-branch/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/channels/chan_sip.c?rev=15863&r1=15862&r2=15863&view=diff
==============================================================================
--- team/oej/test-this-branch/channels/chan_sip.c (original)
+++ team/oej/test-this-branch/channels/chan_sip.c Tue Mar 28 18:00:22 2006
@@ -9290,7 +9290,8 @@
ast_cli(fd, FORMAT3, ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr),
S_OR(cur->username, S_OR(cur->cid_num, "(None)")),
cur->callid,
- cur->subscribed == MWI_NOTIFICATION ? "--" : cur->exten,
+ /* the 'complete' exten/context is hidden in the refer_to field for subscriptions */
+ cur->subscribed == MWI_NOTIFICATION ? "--" : cur->refer_to,
cur->subscribed == MWI_NOTIFICATION ? "<none>" : ast_extension_state2str(cur->laststate),
subscription_type2str(cur->subscribed),
cur->subscribed == MWI_NOTIFICATION ? (cur->relatedpeer ? cur->relatedpeer->mailbox : "<none>") : "<none>"
@@ -11821,7 +11822,6 @@
} else if (debug && ignore)
ast_verbose("Ignoring this SUBSCRIBE request\n");
-
/* Handle authentication if this is our first subscribe */
res = check_user_full(p, req, SIP_SUBSCRIBE, e, 0, sin, ignore, &authpeer);
if (res) {
@@ -11950,6 +11950,9 @@
transmit_response(p, "200 OK", req);
transmit_state_notify(p, firststate, 1); /* Send first notification */
append_history(p, "Subscribestatus", "%s", ast_extension_state2str(firststate));
+ /* hide the 'complete' exten/context in the refer_to field for later display */
+ ast_string_field_build(p, refer_to, "%s@%s", p->exten, p->context);
+
/* remove any old subscription from this peer for the same exten/context,
as the peer has obviously forgotten about it and it's wasteful to wait
for it to expire and send NOTIFY messages to the peer only to have them
Modified: team/oej/test-this-branch/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/channels/chan_zap.c?rev=15863&r1=15862&r2=15863&view=diff
==============================================================================
--- team/oej/test-this-branch/channels/chan_zap.c (original)
+++ team/oej/test-this-branch/channels/chan_zap.c Tue Mar 28 18:00:22 2006
@@ -120,7 +120,7 @@
static struct ast_jb_conf global_jbconf;
#endif /* AST_JB */
-#ifndef ZT_SIG_HARDHDLC
+#if !defined(ZT_SIG_EM_E1) || (defined(ZAPATA_PRI) && !defined(ZT_SIG_HARDHDLC))
#error "Your zaptel is too old. please update"
#endif
@@ -9547,20 +9547,19 @@
static char *complete_span_helper(const char *line, const char *word, int pos, int state, int rpos)
{
- int span=1;
- char tmp[50];
+ int which, span;
+ char *ret = NULL;
+
if (pos != rpos)
- return 0;
- while(span <= NUM_SPANS) {
- if (span > state && pris[span-1].pri)
+ return ret;
+
+ for (which = span = 0; span < NUM_SPANS; span++) {
+ if (pris[span].pri && ++which > state) {
+ asprintf(&ret, "%d", span + 1); /* user indexes start from 1 */
break;
- span++;
- }
- if (span <= NUM_SPANS) {
- snprintf(tmp, sizeof(tmp), "%d", span);
- return ast_strdup(tmp);
- } else
- return NULL;
+ }
+ }
+ return ret;
}
static char *complete_span_4(const char *line, const char *word, int pos, int state)
Modified: team/oej/test-this-branch/channels/iax2-provision.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/channels/iax2-provision.c?rev=15863&r1=15862&r2=15863&view=diff
==============================================================================
--- team/oej/test-this-branch/channels/iax2-provision.c (original)
+++ team/oej/test-this-branch/channels/iax2-provision.c Tue Mar 28 18:00:22 2006
@@ -165,11 +165,9 @@
ast_mutex_lock(&provlock);
for (c = templates; c; c = c->next) {
- if (!strncasecmp(word, c->name, wordlen)) {
- if (++which > state) {
- ret = strdup(c->name);
- break;
- }
+ if (!strncasecmp(word, c->name, wordlen) && ++which > state) {
+ ret = strdup(c->name);
+ break;
}
}
ast_mutex_unlock(&provlock);
Modified: team/oej/test-this-branch/cli.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/cli.c?rev=15863&r1=15862&r2=15863&view=diff
==============================================================================
--- team/oej/test-this-branch/cli.c (original)
+++ team/oej/test-this-branch/cli.c Tue Mar 28 18:00:22 2006
@@ -39,6 +39,7 @@
#include "asterisk/logger.h"
#include "asterisk/options.h"
#include "asterisk/cli.h"
+#include "asterisk/linkedlists.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/channel.h"
@@ -174,21 +175,19 @@
static int handle_set_verbose(int fd, int argc, char *argv[])
{
int val = 0;
- int oldval = 0;
-
- /* Has a hidden 'at least' argument */
- if ((argc != 3) && (argc != 4))
- return RESULT_SHOWUSAGE;
- if ((argc == 4) && strcasecmp(argv[2], "atleast"))
- return RESULT_SHOWUSAGE;
- oldval = option_verbose;
+ int oldval = option_verbose;
+
+ /* "set verbose [atleast] N" */
if (argc == 3)
option_verbose = atoi(argv[2]);
- else {
+ else if (argc == 4) {
+ if (strcasecmp(argv[2], "atleast"))
+ return RESULT_SHOWUSAGE;
val = atoi(argv[3]);
if (val > option_verbose)
option_verbose = val;
- }
+ } else
+ return RESULT_SHOWUSAGE;
if (oldval != option_verbose && option_verbose > 0)
ast_cli(fd, "Verbosity was %d and is now %d\n", oldval, option_verbose);
else if (oldval > 0 && option_verbose > 0)
@@ -201,20 +200,19 @@
static int handle_set_debug(int fd, int argc, char *argv[])
{
int val = 0;
- int oldval = 0;
- /* Has a hidden 'at least' argument */
- if ((argc != 3) && (argc != 4))
- return RESULT_SHOWUSAGE;
- if ((argc == 4) && strcasecmp(argv[2], "atleast"))
- return RESULT_SHOWUSAGE;
- oldval = option_debug;
+ int oldval = option_debug;
+
+ /* "set debug [atleast] N" */
if (argc == 3)
option_debug = atoi(argv[2]);
- else {
+ else if (argc == 4) {
+ if (strcasecmp(argv[2], "atleast"))
+ return RESULT_SHOWUSAGE;
val = atoi(argv[3]);
if (val > option_debug)
option_debug = val;
- }
+ } else
+ return RESULT_SHOWUSAGE;
if (oldval != option_debug && option_debug > 0)
ast_cli(fd, "Core debug was %d and is now %d\n", oldval, option_debug);
else if (oldval > 0 && option_debug > 0)
@@ -368,7 +366,7 @@
}
ast_mutex_lock(&climodentrylock);
- climodentryfd = fd;
+ climodentryfd = fd; /* global, protected by climodentrylock */
ast_cli(fd, MODLIST_FORMAT2, "Module", "Description", "Use Count");
ast_cli(fd,"%d modules loaded\n", ast_update_module_list(modlist_modentry, like));
climodentryfd = -1;
@@ -396,7 +394,7 @@
#define VERBOSE_FORMAT_STRING "%-20.20s %-20.20s %-16.16s %4d %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-20.20s\n"
#define VERBOSE_FORMAT_STRING2 "%-20.20s %-20.20s %-16.16s %-4.4s %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-20.20s\n"
- struct ast_channel *c = NULL, *bc = NULL;
+ struct ast_channel *c = NULL;
char durbuf[10] = "-";
char locbuf[40];
char appdata[40];
@@ -415,8 +413,9 @@
else if (verbose)
ast_cli(fd, VERBOSE_FORMAT_STRING2, "Channel", "Context", "Extension", "Priority", "State", "Application", "Data",
"CallerID", "Duration", "Accountcode", "BridgedTo");
+
while ((c = ast_channel_walk_locked(c)) != NULL) {
- bc = ast_bridged_channel(c);
+ struct ast_channel *bc = ast_bridged_channel(c);
if ((concise || verbose) && c->cdr && !ast_tvzero(c->cdr->start)) {
duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000);
if (verbose) {
@@ -446,22 +445,23 @@
snprintf(locbuf, sizeof(locbuf), "%s@%s:%d", c->exten, c->context, c->priority);
else
strcpy(locbuf, "(None)");
- if (c->appl) {
+ if (c->appl)
snprintf(appdata, sizeof(appdata), "%s(%s)", c->appl, c->data ? c->data : "");
- } else {
+ else
strcpy(appdata, "(None)");
- }
ast_cli(fd, FORMAT_STRING, c->name, locbuf, ast_state2str(c->_state), appdata);
}
numchans++;
ast_mutex_unlock(&c->lock);
}
if (!concise) {
- ast_cli(fd, "%d active channel%s\n", numchans, (numchans!=1) ? "s" : "");
+ ast_cli(fd, "%d active channel%s\n", numchans, ESS(numchans));
if (option_maxcalls)
- ast_cli(fd, "%d of %d max active call%s (%5.2f%% of capacity)\n", ast_active_calls(), option_maxcalls, (ast_active_calls()!=1) ? "s" : "", ((float)ast_active_calls() / (float)option_maxcalls) * 100.0);
+ ast_cli(fd, "%d of %d max active call%s (%5.2f%% of capacity)\n",
+ ast_active_calls(), option_maxcalls, ESS(ast_active_calls()),
+ ((double)ast_active_calls() / (double)option_maxcalls) * 100.0);
else
- ast_cli(fd, "%d active call%s\n", ast_active_calls(), (ast_active_calls()!=1) ? "s" : "");
+ ast_cli(fd, "%d active call%s\n", ast_active_calls(), ESS(ast_active_calls()));
}
return RESULT_SUCCESS;
@@ -537,9 +537,6 @@
matches = ast_cli_completion_matches(argv[2], argv[3]);
if (matches) {
for (x=0; matches[x]; x++) {
-#if 0
- printf("command matchesarray for '%s' %s got '%s'\n", argv[2], argv[3], matches[x]);
-#endif
matchlen = strlen(matches[x]) + 1;
if (len + matchlen >= buflen) {
buflen += matchlen * 3;
@@ -555,10 +552,7 @@
}
free(matches);
}
-#if 0
- printf("array for '%s' %s got '%s'\n", argv[2], argv[3], buf);
-#endif
-
+
if (buf) {
ast_cli(fd, "%s%s",buf, AST_CLI_COMPLETE_EOF);
free(buf);
@@ -579,9 +573,6 @@
matches = ast_cli_generatornummatches(argv[2], argv[3]);
-#if 0
- printf("Search for '%s' %s got '%d'\n", argv[2], argv[3], matches);
-#endif
ast_cli(fd, "%d", matches);
return RESULT_SUCCESS;
@@ -590,15 +581,10 @@
static int handle_commandcomplete(int fd, int argc, char *argv[])
{
char *buf;
-#if 0
- printf("Search for %d args: '%s', '%s', '%s', '%s'\n", argc, argv[0], argv[1], argv[2], argv[3]);
-#endif
+
if (argc != 5)
return RESULT_SHOWUSAGE;
buf = __ast_cli_generator(argv[2], argv[3], atoi(argv[4]), 0);
-#if 0
- printf("Search for '%s' %s %d got '%s'\n", argv[2], argv[3], atoi(argv[4]), buf);
-#endif
if (buf) {
ast_cli(fd, buf);
free(buf);
@@ -632,6 +618,8 @@
{
struct ast_channel *c=NULL;
int is_all;
+
+ /* 'debug channel {all|chan_id}' */
if (argc != 3)
return RESULT_SHOWUSAGE;
@@ -664,6 +652,7 @@
{
struct ast_channel *c=NULL;
int is_all;
+ /* 'no debug channel {all|chan_id}' */
if (argc != 4)
return RESULT_SHOWUSAGE;
is_all = !strcasecmp("all", argv[3]);
@@ -675,7 +664,7 @@
c = ast_get_channel_by_name_locked(argv[3]);
if (c == NULL)
ast_cli(fd, "No such channel %s\n", argv[3]);
- }
+ }
while(c) {
if ((c->fin & DEBUGCHAN_FLAG) || (c->fout & DEBUGCHAN_FLAG)) {
c->fin &= ~DEBUGCHAN_FLAG;
@@ -691,8 +680,6 @@
return RESULT_SUCCESS;
}
-
-
static int handle_showchan(int fd, int argc, char *argv[])
{
struct ast_channel *c=NULL;
@@ -776,27 +763,27 @@
return RESULT_SUCCESS;
}
+/*
+ * helper function to generate CLI matches from a fixed set of values.
+ * A NULL word is acceptable.
+ */
+char *ast_cli_complete(const char *word, char *const choices[], int state)
+{
+ int i, which = 0, len;
+ len = ast_strlen_zero(word) ? 0 : strlen(word);
+
+ for (i = 0; choices[i]; i++) {
+ if ((!len || !strncasecmp(word, choices[i], len)) && ++which > state)
+ return ast_strdup(choices[i]);
+ }
+ return NULL;
+}
+
static char *complete_show_channels(const char *line, const char *word, int pos, int state)
{
- static char *choices[] = { "concise", "verbose" };
- int match = 0;
- int x;
- int wordlen;
-
- if (pos != 2)
- return NULL;
-
- wordlen = strlen(word);
-
- for (x = 0; x < sizeof(choices) / sizeof(choices[0]); x++) {
- if (!strncasecmp(word, choices[x], wordlen)) {
- match++;
- if (match > state)
- return strdup(choices[x]);
- }
- }
-
- return NULL;
+ static char *choices[] = { "concise", "verbose", NULL };
+
+ return (pos != 2) ? NULL : ast_cli_complete(word, choices, state);
}
char *ast_complete_channels(const char *line, const char *word, int pos, int state, int rpos)
@@ -804,25 +791,20 @@
struct ast_channel *c = NULL;
int which = 0;
int wordlen;
- char *ret = NULL;
+ char notfound = '\0';
+ char *ret = ¬found; /* so NULL can break the loop */
if (pos != rpos)
return NULL;
wordlen = strlen(word);
- while ((c = ast_channel_walk_locked(c))) {
- if (!strncasecmp(word, c->name, wordlen)) {
- if (++which > state) {
- ret = strdup(c->name);
- ast_mutex_unlock(&c->lock);
- break;
- }
- }
+ while (ret == ¬found && (c = ast_channel_walk_locked(c))) {
+ if (!strncasecmp(word, c->name, wordlen) && ++which > state)
+ ret = ast_strdup(c->name);
ast_mutex_unlock(&c->lock);
}
-
- return ret;
+ return ret == ¬found ? NULL : ret;
}
static char *complete_ch_3(const char *line, const char *word, int pos, int state)
@@ -925,9 +907,8 @@
if (l > 5)
l = 5;
text += l;
-
/* XXX watch out, should stop to the non-generator parts */
- return __ast_cli_generator(text, word, state, 0); /* Don't lock as we are already locked */
+ return __ast_cli_generator(text, word, state, 0);
}
static struct ast_cli_entry builtins[] = {
@@ -956,87 +937,116 @@
{ { NULL }, NULL, NULL, NULL }
};
-static struct ast_cli_entry *find_cli(char *const cmds[], int exact)
-{
- int x;
- int y;
- int match;
- struct ast_cli_entry *e=NULL;
-
- AST_LIST_TRAVERSE(&helpers, e, list) {
- match = 1;
- for (y=0;match && cmds[y]; y++) {
- if (!e->cmda[y] && !exact)
+/*! \brief initialize the _full_cmd string in * each of the builtins. */
+void ast_builtins_init(void)
+{
+ struct ast_cli_entry *e;
+
+ for (e = builtins; e->cmda[0] != NULL; e++) {
+ char buf[80];
+ ast_join(buf, sizeof(buf), e->cmda);
+ e->_full_cmd = strdup(buf);
+ if (!e->_full_cmd)
+ ast_log(LOG_WARNING, "-- cannot allocate <%s>\n", buf);
+ }
+}
+
+/*
+ * We have two sets of commands: builtins are stored in a
+ * NULL-terminated array of ast_cli_entry, whereas external
+ * commands are in a list.
+ * When navigating, we need to keep two pointers and get
+ * the next one in lexicographic order. For the purpose,
+ * we use a structure.
+ */
+
+struct cli_iterator {
+ struct ast_cli_entry *builtins;
+ struct ast_cli_entry *helpers;
+};
+
+static struct ast_cli_entry *cli_next(struct cli_iterator *i)
+{
+ struct ast_cli_entry *e;
+
+ if (i->builtins == NULL && i->helpers == NULL) {
+ /* initialize */
+ i->builtins = builtins;
+ i->helpers = AST_LIST_FIRST(&helpers);
+ }
+ e = i->builtins; /* temporary */
+ if (!e->cmda[0] || (i->helpers &&
+ strcmp(i->helpers->_full_cmd, e->_full_cmd) < 0)) {
+ /* Use helpers */
+ e = i->helpers;
+ if (e)
+ i->helpers = AST_LIST_NEXT(e, list);
+ } else { /* use builtin. e is already set */
+ (i->builtins)++; /* move to next */
+ }
+ return e;
+}
+
+/*!
+ * \brief locate a cli command in the 'helpers' list (which must be locked).
+ * exact has 3 values:
+ * 0 returns if the search key is equal or longer than the entry.
+ * -1 true if the mismatch is on the last word XXX not true!
+ * 1 true only on complete, exact match.
+ */
+static struct ast_cli_entry *find_cli(char *const cmds[], int match_type)
+{
+ int matchlen = -1; /* length of longest match so far */
+ struct ast_cli_entry *cand = NULL, *e=NULL;
+ struct cli_iterator i = { NULL, NULL};
+
+ while( (e = cli_next(&i)) ) {
+ int y;
+ for (y = 0 ; cmds[y] && e->cmda[y]; y++) {
+ if (strcasecmp(e->cmda[y], cmds[y]))
break;
- if (!e->cmda[y] || strcasecmp(e->cmda[y], cmds[y]))
- match = 0;
- }
- if ((exact > -1) && e->cmda[y])
- match = 0;
- if (match)
- break;
- }
- if (e)
- return e;
- for (x=0;builtins[x].cmda[0];x++) {
- /* start optimistic */
- match = 1;
- for (y=0;match && cmds[y]; y++) {
- /* If there are no more words in the candidate command, then we're
- there. */
- if (!builtins[x].cmda[y] && !exact)
+ }
+ if (e->cmda[y] == NULL) { /* no more words in candidate */
+ if (cmds[y] == NULL) /* this is an exact match, cannot do better */
break;
- /* If there are no more words in the command (and we're looking for
- an exact match) or there is a difference between the two words,
- then this is not a match */
- if (!builtins[x].cmda[y] || strcasecmp(builtins[x].cmda[y], cmds[y]))
- match = 0;
- }
- /* If more words are needed to complete the command then this is not
- a candidate (unless we're looking for a really inexact answer */
- if ((exact > -1) && builtins[x].cmda[y])
- match = 0;
- if (match)
- return &builtins[x];
- }
- return NULL;
-}
-
-static void join(char *dest, size_t destsize, char *const w[], int tws)
-{
- ast_join(dest, destsize, w);
-
- if (tws && !ast_strlen_zero(dest))
- strncat(dest, " ", destsize - strlen(dest) - 1);
-}
-
-static void join2(char *dest, size_t destsize, char *const w[])
-{
- int x;
- /* Join words into a string */
- if (!dest || destsize < 1) {
- return;
- }
- dest[0] = '\0';
- for (x=0;w[x];x++) {
- strncat(dest, w[x], destsize - strlen(dest) - 1);
- }
+ /* here the search key is longer than the candidate */
+ if (match_type != 0) /* but we look for almost exact match... */
+ continue; /* so we skip this one. */
+ /* otherwise we like it (case 0) */
+ } else { /* still words in candidate */
+ if (cmds[y] == NULL) /* search key is shorter, not good */
+ continue;
+ /* if we get here, both words exist but there is a mismatch */
+ if (match_type == 0) /* not the one we look for */
+ continue;
+ if (match_type == 1) /* not the one we look for */
+ continue;
+ if (cmds[y+1] != NULL || e->cmda[y+1] != NULL) /* not the one we look for */
+ continue;
+ /* we are in case match_type == -1 and mismatch on last word */
+ }
+ if (cand == NULL || y > matchlen) /* remember the candidate */
+ cand = e;
+ }
+ return e ? e : cand;
}
static char *find_best(char *argv[])
{
static char cmdline[80];
int x;
- /* See how close we get, then print the */
+ /* See how close we get, then print the candidate */
char *myargv[AST_MAX_CMD_LEN];
for (x=0;x<AST_MAX_CMD_LEN;x++)
myargv[x]=NULL;
+ AST_LIST_LOCK(&helpers);
for (x=0;argv[x];x++) {
myargv[x] = argv[x];
if (!find_cli(myargv, -1))
break;
}
- join(cmdline, sizeof(cmdline), myargv, 0);
+ AST_LIST_UNLOCK(&helpers);
+ ast_join(cmdline, sizeof(cmdline), myargv);
return cmdline;
}
@@ -1055,24 +1065,26 @@
int ast_cli_register(struct ast_cli_entry *e)
{
struct ast_cli_entry *cur;
- char fulle[80] ="", fulltst[80] ="";
- static int len;
-
+ char fulle[80] ="";
+ int lf, ret = -1;
+
+ ast_join(fulle, sizeof(fulle), e->cmda);
AST_LIST_LOCK(&helpers);
- join2(fulle, sizeof(fulle), e->cmda);
-
- if (find_cli(e->cmda, -1)) {
+
+ if (find_cli(e->cmda, 1)) {
AST_LIST_UNLOCK(&helpers);
ast_log(LOG_WARNING, "Command '%s' already registered (or something close enough)\n", fulle);
- return -1;
- }
-
+ goto done;
+ }
+ e->_full_cmd = ast_strdup(fulle);
+ if (!e->_full_cmd)
+ goto done;
+ lf = strlen(fulle);
AST_LIST_TRAVERSE_SAFE_BEGIN(&helpers, cur, list) {
- join2(fulltst, sizeof(fulltst), cur->cmda);
- len = strlen(fulltst);
- if (strlen(fulle) < len)
- len = strlen(fulle);
- if (strncasecmp(fulle, fulltst, len) < 0) {
+ int len = strlen(cur->_full_cmd);
+ if (lf < len)
+ len = lf;
+ if (strncasecmp(fulle, cur->_full_cmd, len) < 0) {
AST_LIST_INSERT_BEFORE_CURRENT(&helpers, e, list);
break;
}
@@ -1081,10 +1093,12 @@
if (!cur)
AST_LIST_INSERT_TAIL(&helpers, e, list);
-
+ ret = 0; /* success */
+
+done:
AST_LIST_UNLOCK(&helpers);
- return 0;
+ return ret;
}
/*
@@ -1106,73 +1120,67 @@
ast_cli_unregister(e + i);
}
+
+/*! \brief helper for help_workhorse and final part of
+ * handle_help. if locked = 0 it's just help_workhorse,
+ * otherwise assume the list is already locked and print
+ * an error message if not found.
+ */
+static int help1(int fd, char *match[], int locked)
+{
+ char matchstr[80] = "";
+ struct ast_cli_entry *e;
+ int len = 0;
+ int found = 0;
+ struct cli_iterator i = { NULL, NULL};
+
+ if (match) {
+ ast_join(matchstr, sizeof(matchstr), match);
+ len = strlen(matchstr);
+ }
+ if (!locked)
+ AST_LIST_LOCK(&helpers);
+ while ( (e = cli_next(&i)) ) {
+ /* Hide commands that start with '_' */
+ if (e->_full_cmd[0] == '_')
+ continue;
+ if (match && strncasecmp(matchstr, e->_full_cmd, len))
+ continue;
+ ast_cli(fd, "%25.25s %s\n", e->_full_cmd, e->summary);
+ found++;
+ }
+ AST_LIST_UNLOCK(&helpers);
+ if (!locked && !found && matchstr[0])
+ ast_cli(fd, "No such command '%s'.\n", matchstr);
+ return 0;
+}
+
static int help_workhorse(int fd, char *match[])
{
- char fullcmd1[80] = "";
- char fullcmd2[80] = "";
- char matchstr[80];
- char *fullcmd = NULL;
- struct ast_cli_entry *e, *e1, *e2;
- e1 = builtins;
- e2 = AST_LIST_FIRST(&helpers);
- if (match)
- join(matchstr, sizeof(matchstr), match, 0);
- while(e1->cmda[0] || e2) {
- if (e2)
- join(fullcmd2, sizeof(fullcmd2), e2->cmda, 0);
- if (e1->cmda[0])
- join(fullcmd1, sizeof(fullcmd1), e1->cmda, 0);
- if (!e1->cmda[0] ||
- (e2 && (strcmp(fullcmd2, fullcmd1) < 0))) {
- /* Use e2 */
- e = e2;
- fullcmd = fullcmd2;
- /* Increment by going to next */
- e2 = AST_LIST_NEXT(e2, list);
- } else {
- /* Use e1 */
- e = e1;
- fullcmd = fullcmd1;
- e1++;
- }
- /* Hide commands that start with '_' */
- if (fullcmd[0] == '_')
- continue;
- if (match) {
- if (strncasecmp(matchstr, fullcmd, strlen(matchstr))) {
- continue;
- }
- }
- ast_cli(fd, "%25.25s %s\n", fullcmd, e->summary);
- }
- return 0;
-}
-
-static int handle_help(int fd, int argc, char *argv[]) {
+ return help1(fd, match, 0 /* do not print errors */);
+}
+
+static int handle_help(int fd, int argc, char *argv[])
+{
+ char fullcmd[80];
struct ast_cli_entry *e;
- char fullcmd[80];
- if ((argc < 1))
- return RESULT_SHOWUSAGE;
- if (argc > 1) {
- e = find_cli(argv + 1, 1);
- if (e) {
- if (e->usage)
- ast_cli(fd, "%s", e->usage);
- else {
- join(fullcmd, sizeof(fullcmd), argv+1, 0);
- ast_cli(fd, "No help text available for '%s'.\n", fullcmd);
- }
- } else {
- if (find_cli(argv + 1, -1)) {
- return help_workhorse(fd, argv + 1);
- } else {
- join(fullcmd, sizeof(fullcmd), argv+1, 0);
- ast_cli(fd, "No such command '%s'.\n", fullcmd);
- }
- }
- } else {
+
+ if (argc < 1)
+ return RESULT_SHOWUSAGE;
+ if (argc == 1)
return help_workhorse(fd, NULL);
- }
+
+ AST_LIST_LOCK(&helpers);
+ e = find_cli(argv + 1, 1); /* try exact match first */
+ if (!e)
+ return help1(fd, argv + 1, 1 /* locked */);
+ if (e->usage)
+ ast_cli(fd, "%s", e->usage);
+ else {
+ ast_join(fullcmd, sizeof(fullcmd), argv+1);
+ ast_cli(fd, "No help text available for '%s'.\n", fullcmd);
+ }
+ AST_LIST_UNLOCK(&helpers);
return RESULT_SUCCESS;
}
@@ -1185,58 +1193,60 @@
int whitespace = 1;
*trailingwhitespace = 0;
+ if (s == NULL) /* invalid, though! */
+ return NULL;
+ /* make a copy to store the parsed string */
if (!(dup = strdup(s)))
return NULL;
cur = dup;
- while (!ast_strlen_zero(s)) {
- if ((*s == '"') && !escaped) {
+ /* scan the original string copying into cur when needed */
+ for (; *s ; s++) {
+ if (x >= max - 1) {
+ ast_log(LOG_WARNING, "Too many arguments, truncating at %s\n", s);
+ break;
+ }
+ if (*s == '"' && !escaped) {
quoted = !quoted;
- if (quoted & whitespace) {
- /* If we're starting a quoted string, coming off white space, start a new argument */
- if (x >= (max - 1)) {
- ast_log(LOG_WARNING, "Too many arguments, truncating\n");
- break;
- }
+ if (quoted && whitespace) {
+ /* start a quoted string from previous whitespace: new argument */
argv[x++] = cur;
whitespace = 0;
}
- escaped = 0;
- } else if (((*s == ' ') || (*s == '\t')) && !(quoted || escaped)) {
+ } else if ((*s == ' ' || *s == '\t') && !(quoted || escaped)) {
/* If we are not already in whitespace, and not in a quoted string or
processing an escape sequence, and just entered whitespace, then
finalize the previous argument and remember that we are in whitespace
*/
if (!whitespace) {
- *(cur++) = '\0';
+ *cur++ = '\0';
whitespace = 1;
}
- } else if ((*s == '\\') && !escaped) {
+ } else if (*s == '\\' && !escaped) {
escaped = 1;
} else {
if (whitespace) {
- /* If we are coming out of whitespace, start a new argument */
- if (x >= (max - 1)) {
- ast_log(LOG_WARNING, "Too many arguments, truncating\n");
- break;
- }
+ /* we leave whitespace, and are not quoted. So it's a new argument */
argv[x++] = cur;
whitespace = 0;
}
- *(cur++) = *s;
+ *cur++ = *s;
escaped = 0;
}
- s++;
}
/* Null terminate */
- *(cur++) = '\0';
+ *cur++ = '\0';
+ /* XXX put a NULL in the last argument, because some functions that take
+ * the array may want a null-terminated array.
+ * argc still reflects the number of non-NULL entries.
+ */
argv[x] = NULL;
*argc = x;
*trailingwhitespace = whitespace;
return dup;
}
-/* This returns the number of unique matches for the generator */
+/*! \brief Return the number of unique matches for the generator */
int ast_cli_generatornummatches(const char *text, const char *word)
{
int matches = 0, i = 0;
@@ -1260,6 +1270,7 @@
size_t match_list_len, max_equal, which, i;
int matches = 0;
+ /* leave entry 0 free for the longest common substring */
match_list_len = 1;
while ((retstr = ast_cli_generator(text, word, matches)) != NULL) {
if (matches + 1 >= match_list_len) {
@@ -1271,12 +1282,14 @@
}
if (!match_list)
- return NULL;
-
- which = 2;
+ return match_list; /* NULL */
+
+ /* Find the longest substring that is common to all results
+ * (it is a candidate for completion), and store a copy in entry 0.
+ */
prevstr = match_list[1];
max_equal = strlen(prevstr);
- for (; which <= matches; which++) {
+ for (which = 2; which <= matches; which++) {
for (i = 0; i < max_equal && toupper(prevstr[i]) == toupper(match_list[which][i]); i++)
continue;
max_equal = i;
@@ -1289,6 +1302,7 @@
retstr[max_equal] = '\0';
match_list[0] = retstr;
+ /* ensure that the array is NULL terminated */
if (matches + 1 >= match_list_len) {
if (!(match_list = ast_realloc(match_list, (match_list_len + 1) * sizeof(*match_list))))
return NULL;
@@ -1301,77 +1315,42 @@
static char *__ast_cli_generator(const char *text, const char *word, int state, int lock)
{
char *argv[AST_MAX_ARGS];
- struct ast_cli_entry *e, *e1, *e2;
- int x;
+ struct ast_cli_entry *e;
+ struct cli_iterator i = { NULL, NULL };
+ int x = 0, argindex, matchlen;
int matchnum=0;
- char *dup, *res;
- char fullcmd1[80] = "";
- char fullcmd2[80] = "";
+ char *ret = NULL;
char matchstr[80] = "";
- char *fullcmd = NULL;
int tws;
-
- if ((dup = parse_args(text, &x, argv, sizeof(argv) / sizeof(argv[0]), &tws))) {
- join(matchstr, sizeof(matchstr), argv, tws);
- if (lock)
- AST_LIST_LOCK(&helpers);
- e1 = builtins;
- e2 = AST_LIST_FIRST(&helpers);
- while(e1->cmda[0] || e2) {
- if (e2)
- join(fullcmd2, sizeof(fullcmd2), e2->cmda, tws);
- if (e1->cmda[0])
- join(fullcmd1, sizeof(fullcmd1), e1->cmda, tws);
- if (!e1->cmda[0] ||
- (e2 && (strcmp(fullcmd2, fullcmd1) < 0))) {
- /* Use e2 */
- e = e2;
- fullcmd = fullcmd2;
- /* Increment by going to next */
- e2 = AST_LIST_NEXT(e2, list);
- } else {
- /* Use e1 */
- e = e1;
- fullcmd = fullcmd1;
- e1++;
- }
- if ((fullcmd[0] != '_') && !strncasecmp(matchstr, fullcmd, strlen(matchstr))) {
- /* We contain the first part of one or more commands */
- /* Now, what we're supposed to return is the next word... */
- if (!ast_strlen_zero(word) && x>0) {
- res = e->cmda[x-1];
- } else {
- res = e->cmda[x];
- }
- if (res) {
- matchnum++;
- if (matchnum > state) {
- if (lock)
- AST_LIST_UNLOCK(&helpers);
- free(dup);
- return strdup(res);
- }
- }
- }
- if (e->generator && !strncasecmp(matchstr, fullcmd, strlen(fullcmd)) &&
- (matchstr[strlen(fullcmd)] < 33)) {
- /* We have a command in its entirity within us -- theoretically only one
- command can have this occur */
- fullcmd = e->generator(matchstr, word, (!ast_strlen_zero(word) ? (x - 1) : (x)), state);
- if (fullcmd) {
- if (lock)
- AST_LIST_UNLOCK(&helpers);
- free(dup);
- return fullcmd;
- }
- }
-
- }
- if (lock)
- AST_LIST_UNLOCK(&helpers);
- free(dup);
- }
- return NULL;
+ char *dup = parse_args(text, &x, argv, sizeof(argv) / sizeof(argv[0]), &tws);
+
+ if (!dup) /* error */
+ return NULL;
+ argindex = (!ast_strlen_zero(word) && x>0) ? x-1 : x;
+ /* rebuild the command, ignore tws */
+ ast_join(matchstr, sizeof(matchstr)-1, argv);
+ if (tws)
+ strcat(matchstr, " "); /* XXX */
+ matchlen = strlen(matchstr);
+ if (lock)
+ AST_LIST_LOCK(&helpers);
+ while( !ret && (e = cli_next(&i)) ) {
+ int lc = strlen(e->_full_cmd);
+ if (e->_full_cmd[0] != '_' && lc > 0 && matchlen <= lc &&
+ !strncasecmp(matchstr, e->_full_cmd, matchlen)) {
+ /* Found initial part, return a copy of the next word... */
+ if (e->cmda[argindex] && ++matchnum > state)
+ ret = strdup(e->cmda[argindex]); /* we need a malloced string */
+ } else if (e->generator && !strncasecmp(matchstr, e->_full_cmd, lc) && matchstr[lc] < 33) {
+ /* We have a command in its entirity within us -- theoretically only one
+ command can have this occur */
+ ret = e->generator(matchstr, word, argindex, state);
+ }
+ }
+ if (lock)
+ AST_LIST_UNLOCK(&helpers);
+ free(dup);
+ return ret;
}
char *ast_cli_generator(const char *text, const char *word, int state)
@@ -1412,7 +1391,7 @@
ast_cli(fd, "No such command '%s' (type 'help' for help)\n", find_best(argv));
if (e) {
AST_LIST_LOCK(&helpers);
- e->inuse--;
+ e->inuse--; /* XXX here an atomic dec would suffice */
AST_LIST_UNLOCK(&helpers);
}
}
Modified: team/oej/test-this-branch/codecs/codec_a_mu.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/codecs/codec_a_mu.c?rev=15863&r1=15862&r2=15863&view=diff
==============================================================================
--- team/oej/test-this-branch/codecs/codec_a_mu.c (original)
+++ team/oej/test-this-branch/codecs/codec_a_mu.c Tue Mar 28 18:00:22 2006
@@ -316,7 +316,7 @@
int usecount(void)
{
int res;
- STANDARD_USECOUNT(res);
+ OLD_STANDARD_USECOUNT(res);
return res;
}
Modified: team/oej/test-this-branch/codecs/codec_adpcm.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/codecs/codec_adpcm.c?rev=15863&r1=15862&r2=15863&view=diff
==============================================================================
--- team/oej/test-this-branch/codecs/codec_adpcm.c (original)
+++ team/oej/test-this-branch/codecs/codec_adpcm.c Tue Mar 28 18:00:22 2006
@@ -616,7 +616,7 @@
int usecount(void)
{
int res;
- STANDARD_USECOUNT(res);
+ OLD_STANDARD_USECOUNT(res);
return res;
}
Modified: team/oej/test-this-branch/codecs/codec_alaw.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/codecs/codec_alaw.c?rev=15863&r1=15862&r2=15863&view=diff
==============================================================================
--- team/oej/test-this-branch/codecs/codec_alaw.c (original)
+++ team/oej/test-this-branch/codecs/codec_alaw.c Tue Mar 28 18:00:22 2006
@@ -416,7 +416,7 @@
int usecount(void)
{
int res;
- STANDARD_USECOUNT(res);
+ OLD_STANDARD_USECOUNT(res);
return res;
}
Modified: team/oej/test-this-branch/codecs/codec_g723_1.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/codecs/codec_g723_1.c?rev=15863&r1=15862&r2=15863&view=diff
==============================================================================
--- team/oej/test-this-branch/codecs/codec_g723_1.c (original)
+++ team/oej/test-this-branch/codecs/codec_g723_1.c Tue Mar 28 18:00:22 2006
@@ -407,7 +407,7 @@
int usecount(void)
{
int res;
- STANDARD_USECOUNT(res);
+ OLD_STANDARD_USECOUNT(res);
return res;
}
Modified: team/oej/test-this-branch/codecs/codec_g726.c
URL: http://svn.digium.com/view/asterisk/team/oej/test-this-branch/codecs/codec_g726.c?rev=15863&r1=15862&r2=15863&view=diff
==============================================================================
--- team/oej/test-this-branch/codecs/codec_g726.c (original)
[... 3472 lines stripped ...]
More information about the asterisk-commits
mailing list