phase two of string portability stuff:
[asterisk/asterisk.git] / cli.c
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * Standard Command Line Interface
5  * 
6  * Copyright (C) 1999 - 2005, Digium, Inc.
7  *
8  * Mark Spencer <markster@digium.com>
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License
12  */
13
14 #include <unistd.h>
15 #include <stdlib.h>
16 #include <sys/signal.h>
17 #include <stdio.h>
18 #include <signal.h>
19 #include <string.h>
20 #include <ctype.h>
21
22 #include "asterisk.h"
23
24 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
25
26 #include "asterisk/logger.h"
27 #include "asterisk/options.h"
28 #include "asterisk/cli.h"
29 #include "asterisk/module.h"
30 #include "asterisk/pbx.h"
31 #include "asterisk/channel.h"
32 #include "asterisk/manager.h"
33 #include "asterisk/utils.h"
34 #include "asterisk/lock.h"
35 /* For rl_filename_completion */
36 #include "editline/readline/readline.h"
37 /* For module directory */
38 #include "asterisk/version.h"
39 #include "asterisk/build.h"
40
41 #define VERSION_INFO "Asterisk " ASTERISK_VERSION " built by " BUILD_USER "@" BUILD_HOSTNAME \
42         " on a " BUILD_MACHINE " running " BUILD_OS " on " BUILD_DATE
43         
44 extern unsigned long global_fin, global_fout;
45         
46 void ast_cli(int fd, char *fmt, ...)
47 {
48         char *stuff;
49         int res = 0;
50         va_list ap;
51
52         va_start(ap, fmt);
53         res = vasprintf(&stuff, fmt, ap);
54         va_end(ap);
55         if (res == -1) {
56                 ast_log(LOG_ERROR, "Out of memory\n");
57         } else {
58                 ast_carefulwrite(fd, stuff, strlen(stuff), 100);
59                 free(stuff);
60         }
61 }
62
63 AST_MUTEX_DEFINE_STATIC(clilock);
64
65 struct ast_cli_entry *helpers = NULL;
66
67 static char load_help[] = 
68 "Usage: load <module name>\n"
69 "       Loads the specified module into Asterisk.\n";
70
71 static char unload_help[] = 
72 "Usage: unload [-f|-h] <module name>\n"
73 "       Unloads the specified module from Asterisk.  The -f\n"
74 "       option causes the module to be unloaded even if it is\n"
75 "       in use (may cause a crash) and the -h module causes the\n"
76 "       module to be unloaded even if the module says it cannot, \n"
77 "       which almost always will cause a crash.\n";
78
79 static char help_help[] =
80 "Usage: help [topic]\n"
81 "       When called with a topic as an argument, displays usage\n"
82 "       information on the given command.  If called without a\n"
83 "       topic, it provides a list of commands.\n";
84
85 static char chanlist_help[] = 
86 "Usage: show channels [concise]\n"
87 "       Lists currently defined channels and some information about\n"
88 "       them.  If 'concise' is specified, format is abridged and in\n"
89 "       a more easily machine parsable format\n";
90
91 static char reload_help[] = 
92 "Usage: reload [module ...]\n"
93 "       Reloads configuration files for all listed modules which support\n"
94 "       reloading, or for all supported modules if none are listed.\n";
95
96 static char set_verbose_help[] = 
97 "Usage: set verbose <level>\n"
98 "       Sets level of verbose messages to be displayed.  0 means\n"
99 "       no messages should be displayed. Equivalent to -v[v[v...]]\n"
100 "       on startup\n";
101
102 static char set_debug_help[] = 
103 "Usage: set debug <level>\n"
104 "       Sets level of core debug messages to be displayed.  0 means\n"
105 "       no messages should be displayed. Equivalent to -d[d[d...]]\n"
106 "       on startup.\n";
107
108 static char softhangup_help[] =
109 "Usage: soft hangup <channel>\n"
110 "       Request that a channel be hung up.  The hangup takes effect\n"
111 "       the next time the driver reads or writes from the channel\n";
112
113 static int handle_load(int fd, int argc, char *argv[])
114 {
115         if (argc != 2)
116                 return RESULT_SHOWUSAGE;
117         if (ast_load_resource(argv[1])) {
118                 ast_cli(fd, "Unable to load module %s\n", argv[1]);
119                 return RESULT_FAILURE;
120         }
121         return RESULT_SUCCESS;
122 }
123
124 static int handle_reload(int fd, int argc, char *argv[])
125 {
126         int x;
127         int res;
128         if (argc < 1)
129                 return RESULT_SHOWUSAGE;
130         if (argc > 1) { 
131                 for (x=1;x<argc;x++) {
132                         res = ast_module_reload(argv[x]);
133                         switch(res) {
134                         case 0:
135                                 ast_cli(fd, "No such module '%s'\n", argv[x]);
136                                 break;
137                         case 1:
138                                 ast_cli(fd, "Module '%s' does not support reload\n", argv[x]);
139                                 break;
140                         }
141                 }
142         } else
143                 ast_module_reload(NULL);
144         return RESULT_SUCCESS;
145 }
146
147 static int handle_set_verbose(int fd, int argc, char *argv[])
148 {
149         int val = 0;
150         int oldval = 0;
151
152         /* Has a hidden 'at least' argument */
153         if ((argc != 3) && (argc != 4))
154                 return RESULT_SHOWUSAGE;
155         if ((argc == 4) && strcasecmp(argv[2], "atleast"))
156                 return RESULT_SHOWUSAGE;
157         oldval = option_verbose;
158         if (argc == 3)
159                 option_verbose = atoi(argv[2]);
160         else {
161                 val = atoi(argv[3]);
162                 if (val > option_verbose)
163                         option_verbose = val;
164         }
165         if (oldval != option_verbose && option_verbose > 0)
166                 ast_cli(fd, "Verbosity was %d and is now %d\n", oldval, option_verbose);
167         else if (oldval > 0 && option_verbose > 0)
168                 ast_cli(fd, "Verbosity is at least %d\n", option_verbose);
169         else if (oldval > 0 && option_verbose == 0)
170                 ast_cli(fd, "Verbosity is now OFF\n");
171         return RESULT_SUCCESS;
172 }
173
174 static int handle_set_debug(int fd, int argc, char *argv[])
175 {
176         int val = 0;
177         int oldval = 0;
178         /* Has a hidden 'at least' argument */
179         if ((argc != 3) && (argc != 4))
180                 return RESULT_SHOWUSAGE;
181         if ((argc == 4) && strcasecmp(argv[2], "atleast"))
182                 return RESULT_SHOWUSAGE;
183         oldval = option_debug;
184         if (argc == 3)
185                 option_debug = atoi(argv[2]);
186         else {
187                 val = atoi(argv[3]);
188                 if (val > option_debug)
189                         option_debug = val;
190         }
191         if (oldval != option_debug && option_debug > 0)
192                 ast_cli(fd, "Core debug was %d and is now %d\n", oldval, option_debug);
193         else if (oldval > 0 && option_debug > 0)
194                 ast_cli(fd, "Core debug is at least %d\n", option_debug);
195         else if (oldval > 0 && option_debug == 0)
196                 ast_cli(fd, "Core debug is now OFF\n");
197         return RESULT_SUCCESS;
198 }
199
200 static int handle_unload(int fd, int argc, char *argv[])
201 {
202         int x;
203         int force=AST_FORCE_SOFT;
204         if (argc < 2)
205                 return RESULT_SHOWUSAGE;
206         for (x=1;x<argc;x++) {
207                 if (argv[x][0] == '-') {
208                         switch(argv[x][1]) {
209                         case 'f':
210                                 force = AST_FORCE_FIRM;
211                                 break;
212                         case 'h':
213                                 force = AST_FORCE_HARD;
214                                 break;
215                         default:
216                                 return RESULT_SHOWUSAGE;
217                         }
218                 } else if (x !=  argc - 1) 
219                         return RESULT_SHOWUSAGE;
220                 else if (ast_unload_resource(argv[x], force)) {
221                         ast_cli(fd, "Unable to unload resource %s\n", argv[x]);
222                         return RESULT_FAILURE;
223                 }
224         }
225         return RESULT_SUCCESS;
226 }
227
228 #define MODLIST_FORMAT  "%-30s %-40.40s %-10d\n"
229 #define MODLIST_FORMAT2 "%-30s %-40.40s %-10s\n"
230
231 AST_MUTEX_DEFINE_STATIC(climodentrylock);
232 static int climodentryfd = -1;
233
234 static int modlist_modentry(const char *module, const char *description, int usecnt, const char *like)
235 {
236         /* Comparing the like with the module */
237         if (strstr(module, like) != NULL) {
238                 ast_cli(climodentryfd, MODLIST_FORMAT, module, description, usecnt);
239                 return 1;
240         } 
241         return 0;
242 }
243
244 static char modlist_help[] =
245 "Usage: show modules [like keyword]\n"
246 "       Shows Asterisk modules currently in use, and usage statistics.\n";
247
248 static char version_help[] =
249 "Usage: show version\n"
250 "       Shows Asterisk version information.\n";
251
252 static char uptime_help[] =
253 "Usage: show uptime [seconds]\n"
254 "       Shows Asterisk uptime information.\n"
255 "       The seconds word returns the uptime in seconds only.\n";
256
257 static char *format_uptimestr(time_t timeval)
258 {
259         int years = 0, weeks = 0, days = 0, hours = 0, mins = 0, secs = 0;
260         char timestr[256]="";
261         int bytes = 0;
262         int maxbytes = 0;
263         int offset = 0;
264 #define SECOND (1)
265 #define MINUTE (SECOND*60)
266 #define HOUR (MINUTE*60)
267 #define DAY (HOUR*24)
268 #define WEEK (DAY*7)
269 #define YEAR (DAY*365)
270 #define ESS(x) ((x == 1) ? "" : "s")
271
272         maxbytes = sizeof(timestr);
273         if (timeval < 0)
274                 return NULL;
275         if (timeval > YEAR) {
276                 years = (timeval / YEAR);
277                 timeval -= (years * YEAR);
278                 if (years > 0) {
279                         snprintf(timestr + offset, maxbytes, "%d year%s, ", years, ESS(years));
280                         bytes = strlen(timestr + offset);
281                         offset += bytes;
282                         maxbytes -= bytes;
283                 }
284         }
285         if (timeval > WEEK) {
286                 weeks = (timeval / WEEK);
287                 timeval -= (weeks * WEEK);
288                 if (weeks > 0) {
289                         snprintf(timestr + offset, maxbytes, "%d week%s, ", weeks, ESS(weeks));
290                         bytes = strlen(timestr + offset);
291                         offset += bytes;
292                         maxbytes -= bytes;
293                 }
294         }
295         if (timeval > DAY) {
296                 days = (timeval / DAY);
297                 timeval -= (days * DAY);
298                 if (days > 0) {
299                         snprintf(timestr + offset, maxbytes, "%d day%s, ", days, ESS(days));
300                         bytes = strlen(timestr + offset);
301                         offset += bytes;
302                         maxbytes -= bytes;
303                 }
304         }
305         if (timeval > HOUR) {
306                 hours = (timeval / HOUR);
307                 timeval -= (hours * HOUR);
308                 if (hours > 0) {
309                         snprintf(timestr + offset, maxbytes, "%d hour%s, ", hours, ESS(hours));
310                         bytes = strlen(timestr + offset);
311                         offset += bytes;
312                         maxbytes -= bytes;
313                 }
314         }
315         if (timeval > MINUTE) {
316                 mins = (timeval / MINUTE);
317                 timeval -= (mins * MINUTE);
318                 if (mins > 0) {
319                         snprintf(timestr + offset, maxbytes, "%d minute%s, ", mins, ESS(mins));
320                         bytes = strlen(timestr + offset);
321                         offset += bytes;
322                         maxbytes -= bytes;
323                 }
324         }
325         secs = timeval;
326
327         if (secs > 0) {
328                 snprintf(timestr + offset, maxbytes, "%d second%s", secs, ESS(secs));
329         }
330
331         return timestr ? strdup(timestr) : NULL;
332 }
333
334 static int handle_showuptime(int fd, int argc, char *argv[])
335 {
336         time_t curtime, tmptime;
337         char *timestr;
338         int printsec;
339
340         printsec = ((argc == 3) && (!strcasecmp(argv[2],"seconds")));
341         if ((argc != 2) && (!printsec))
342                 return RESULT_SHOWUSAGE;
343
344         time(&curtime);
345         if (ast_startuptime) {
346                 tmptime = curtime - ast_startuptime;
347                 if (printsec) {
348                         ast_cli(fd, "System uptime: %lu\n",tmptime);
349                 } else {
350                         timestr = format_uptimestr(tmptime);
351                         if (timestr) {
352                                 ast_cli(fd, "System uptime: %s\n", timestr);
353                                 free(timestr);
354                         }
355                 }
356         }               
357         if (ast_lastreloadtime) {
358                 tmptime = curtime - ast_lastreloadtime;
359                 if (printsec) {
360                         ast_cli(fd, "Last reload: %lu\n", tmptime);
361                 } else {
362                         timestr = format_uptimestr(tmptime);
363                         if ((timestr) && (!printsec)) {
364                                 ast_cli(fd, "Last reload: %s\n", timestr);
365                                 free(timestr);
366                         } 
367                 }
368         }
369         return RESULT_SUCCESS;
370 }
371
372 static int handle_modlist(int fd, int argc, char *argv[])
373 {
374         char *like = "";
375         if (argc == 3)
376                 return RESULT_SHOWUSAGE;
377         else if (argc >= 4) {
378                 if (strcmp(argv[2],"like")) 
379                         return RESULT_SHOWUSAGE;
380                 like = argv[3];
381         }
382                 
383         ast_mutex_lock(&climodentrylock);
384         climodentryfd = fd;
385         ast_cli(fd, MODLIST_FORMAT2, "Module", "Description", "Use Count");
386         ast_cli(fd,"%d modules loaded\n", ast_update_module_list(modlist_modentry, like));
387         climodentryfd = -1;
388         ast_mutex_unlock(&climodentrylock);
389         return RESULT_SUCCESS;
390 }
391
392 static int handle_version(int fd, int argc, char *argv[])
393 {
394         if (argc != 2)
395                 return RESULT_SHOWUSAGE;
396         ast_cli(fd, "%s\n", VERSION_INFO);
397         return RESULT_SUCCESS;
398 }
399 static int handle_chanlist(int fd, int argc, char *argv[])
400 {
401 #define FORMAT_STRING  "%15s  (%-10s %-12s %-4d) %7s %-12s  %-15s\n"
402 #define FORMAT_STRING2 "%15s  (%-10s %-12s %-4s) %7s %-12s  %-15s\n"
403 #define CONCISE_FORMAT_STRING  "%s:%s:%s:%d:%s:%s:%s:%s:%s:%d\n"
404
405         struct ast_channel *c=NULL;
406         int numchans = 0;
407         int concise = 0;
408         if (argc < 2 || argc > 3)
409                 return RESULT_SHOWUSAGE;
410         
411         concise = (argc == 3 && (!strcasecmp(argv[2],"concise")));
412         if(!concise)
413                 ast_cli(fd, FORMAT_STRING2, "Channel", "Context", "Extension", "Pri", "State", "Appl.", "Data");
414         while ( (c = ast_channel_walk_locked(c)) != NULL) {
415                 if(concise)
416                         ast_cli(fd, CONCISE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
417                                         c->appl ? c->appl : "(None)", c->data ? ( !ast_strlen_zero(c->data) ? c->data : "" ): "",
418                                         (c->cid.cid_num && !ast_strlen_zero(c->cid.cid_num)) ? c->cid.cid_num : "",
419                                         (c->accountcode && !ast_strlen_zero(c->accountcode)) ? c->accountcode : "",c->amaflags);
420                 else
421                         ast_cli(fd, FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
422                                         c->appl ? c->appl : "(None)", c->data ? ( !ast_strlen_zero(c->data) ? c->data : "(Empty)" ): "(None)");
423
424                 numchans++;
425                 ast_mutex_unlock(&c->lock);
426         }
427         if(!concise) {
428                 ast_cli(fd, "%d active channel%s\n", numchans, (numchans!=1) ? "s" : "");
429                 if (option_maxcalls)
430                         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);
431                 else
432                         ast_cli(fd, "%d active call%s\n", ast_active_calls(), (ast_active_calls()!=1) ? "s" : "");
433         }
434         return RESULT_SUCCESS;
435 }
436
437 static char showchan_help[] = 
438 "Usage: show channel <channel>\n"
439 "       Shows lots of information about the specified channel.\n";
440
441 static char debugchan_help[] = 
442 "Usage: debug channel <channel>\n"
443 "       Enables debugging on a specific channel.\n";
444
445 static char debuglevel_help[] = 
446 "Usage: debug level <level> [filename]\n"
447 "       Set debug to specified level (0 to disable).  If filename\n"
448 "is specified, debugging will be limited to just that file.\n";
449
450 static char nodebugchan_help[] = 
451 "Usage: no debug channel <channel>\n"
452 "       Disables debugging on a specific channel.\n";
453
454 static char commandcomplete_help[] = 
455 "Usage: _command complete \"<line>\" text state\n"
456 "       This function is used internally to help with command completion and should.\n"
457 "       never be called by the user directly.\n";
458
459 static char commandnummatches_help[] = 
460 "Usage: _command nummatches \"<line>\" text \n"
461 "       This function is used internally to help with command completion and should.\n"
462 "       never be called by the user directly.\n";
463
464 static char commandmatchesarray_help[] = 
465 "Usage: _command matchesarray \"<line>\" text \n"
466 "       This function is used internally to help with command completion and should.\n"
467 "       never be called by the user directly.\n";
468
469 static int handle_softhangup(int fd, int argc, char *argv[])
470 {
471         struct ast_channel *c=NULL;
472         if (argc != 3)
473                 return RESULT_SHOWUSAGE;
474         c = ast_get_channel_by_name_locked(argv[2]);
475         if (c) {
476                 ast_cli(fd, "Requested Hangup on channel '%s'\n", c->name);
477                 ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
478                 ast_mutex_unlock(&c->lock);
479         } else
480                 ast_cli(fd, "%s is not a known channel\n", argv[2]);
481         return RESULT_SUCCESS;
482 }
483
484 static char *__ast_cli_generator(char *text, char *word, int state, int lock);
485
486 static int handle_commandmatchesarray(int fd, int argc, char *argv[])
487 {
488         char *buf, *obuf;
489         int buflen = 2048;
490         int len = 0;
491         char **matches;
492         int x, matchlen;
493
494         if (argc != 4)
495                 return RESULT_SHOWUSAGE;
496         buf = malloc(buflen);
497         if (!buf)
498                 return RESULT_FAILURE;
499         buf[len] = '\0';
500         matches = ast_cli_completion_matches(argv[2], argv[3]);
501         if (matches) {
502                 for (x=0; matches[x]; x++) {
503 #if 0
504                         printf("command matchesarray for '%s' %s got '%s'\n", argv[2], argv[3], matches[x]);
505 #endif
506                         matchlen = strlen(matches[x]) + 1;
507                         if (len + matchlen >= buflen) {
508                                 buflen += matchlen * 3;
509                                 obuf = buf;
510                                 buf = realloc(obuf, buflen);
511                                 if (!buf) 
512                                         /* Out of memory...  Just free old buffer and be done */
513                                         free(obuf);
514                         }
515                         if (buf)
516                                 len += sprintf( buf + len, "%s ", matches[x]);
517                         free(matches[x]);
518                         matches[x] = NULL;
519                 }
520                 free(matches);
521         }
522 #if 0
523         printf("array for '%s' %s got '%s'\n", argv[2], argv[3], buf);
524 #endif
525         
526         if (buf) {
527                 ast_cli(fd, "%s%s",buf, AST_CLI_COMPLETE_EOF);
528                 free(buf);
529         } else
530                 ast_cli(fd, "NULL\n");
531
532         return RESULT_SUCCESS;
533 }
534
535
536
537 static int handle_commandnummatches(int fd, int argc, char *argv[])
538 {
539         int matches = 0;
540
541         if (argc != 4)
542                 return RESULT_SHOWUSAGE;
543
544         matches = ast_cli_generatornummatches(argv[2], argv[3]);
545
546 #if 0
547         printf("Search for '%s' %s got '%d'\n", argv[2], argv[3], matches);
548 #endif
549         ast_cli(fd, "%d", matches);
550
551         return RESULT_SUCCESS;
552 }
553
554 static int handle_commandcomplete(int fd, int argc, char *argv[])
555 {
556         char *buf;
557 #if 0
558         printf("Search for %d args: '%s', '%s', '%s', '%s'\n", argc, argv[0], argv[1], argv[2], argv[3]);
559 #endif  
560         if (argc != 5)
561                 return RESULT_SHOWUSAGE;
562         buf = __ast_cli_generator(argv[2], argv[3], atoi(argv[4]), 0);
563 #if 0
564         printf("Search for '%s' %s %d got '%s'\n", argv[2], argv[3], atoi(argv[4]), buf);
565 #endif  
566         if (buf) {
567                 ast_cli(fd, buf);
568                 free(buf);
569         } else
570                 ast_cli(fd, "NULL\n");
571         return RESULT_SUCCESS;
572 }
573
574 static int handle_debuglevel(int fd, int argc, char *argv[])
575 {
576         int newlevel;
577         char *filename = "<any>";
578         if ((argc < 3) || (argc > 4))
579                 return RESULT_SHOWUSAGE;
580         if (sscanf(argv[2], "%d", &newlevel) != 1)
581                 return RESULT_SHOWUSAGE;
582         option_debug = newlevel;
583         if (argc == 4) {
584                 filename = argv[3];
585                 ast_copy_string(debug_filename, filename, sizeof(debug_filename));
586         } else {
587                 debug_filename[0] = '\0';
588         }
589         ast_cli(fd, "Debugging level set to %d, file '%s'\n", newlevel, filename);
590         return RESULT_SUCCESS;
591 }
592
593 #define DEBUGCHAN_FLAG  0x80000000
594 /* XXX todo: merge next two functions!!! */
595 static int handle_debugchan(int fd, int argc, char *argv[])
596 {
597         struct ast_channel *c=NULL;
598         int is_all;
599         if (argc != 3)
600                 return RESULT_SHOWUSAGE;
601
602         is_all = !strcasecmp("all", argv[2]);
603         if (is_all) {
604                 global_fin |= DEBUGCHAN_FLAG;
605                 global_fout |= DEBUGCHAN_FLAG;
606                 c = ast_channel_walk_locked(NULL);
607         } else {
608                 c = ast_get_channel_by_name_locked(argv[2]);
609                 if (c == NULL)
610                         ast_cli(fd, "No such channel %s\n", argv[2]);
611         }
612         while(c) {
613                 if (!(c->fin & DEBUGCHAN_FLAG) || !(c->fout & DEBUGCHAN_FLAG)) {
614                         c->fin |= DEBUGCHAN_FLAG;
615                         c->fout |= DEBUGCHAN_FLAG;
616                         ast_cli(fd, "Debugging enabled on channel %s\n", c->name);
617                 }
618                 ast_mutex_unlock(&c->lock);
619                 if (!is_all)
620                         break;
621                 c = ast_channel_walk_locked(c);
622         }
623         ast_cli(fd, "Debugging on new channels is enabled\n");
624         return RESULT_SUCCESS;
625 }
626
627 static int handle_nodebugchan(int fd, int argc, char *argv[])
628 {
629         struct ast_channel *c=NULL;
630         int is_all;
631         if (argc != 4)
632                 return RESULT_SHOWUSAGE;
633         is_all = !strcasecmp("all", argv[3]);
634         if (is_all) {
635                 global_fin &= ~DEBUGCHAN_FLAG;
636                 global_fout &= ~DEBUGCHAN_FLAG;
637                 c = ast_channel_walk_locked(NULL);
638         } else {
639                 c = ast_get_channel_by_name_locked(argv[3]);
640                 if (c == NULL)
641                         ast_cli(fd, "No such channel %s\n", argv[3]);
642     }
643         while(c) {
644                 if ((c->fin & DEBUGCHAN_FLAG) || (c->fout & DEBUGCHAN_FLAG)) {
645                         c->fin &= ~DEBUGCHAN_FLAG;
646                         c->fout &= ~DEBUGCHAN_FLAG;
647                         ast_cli(fd, "Debugging disabled on channel %s\n", c->name);
648                 }
649                 ast_mutex_unlock(&c->lock);
650                 if (!is_all)
651                         break;
652                 c = ast_channel_walk_locked(c);
653         }
654         ast_cli(fd, "Debugging on new channels is disabled\n");
655         return RESULT_SUCCESS;
656 }
657                 
658         
659
660 static int handle_showchan(int fd, int argc, char *argv[])
661 {
662         struct ast_channel *c=NULL;
663         struct timeval now;
664         char buf[2048];
665         char cdrtime[256];
666         long elapsed_seconds=0;
667         int hour=0, min=0, sec=0;
668         
669         if (argc != 3)
670                 return RESULT_SHOWUSAGE;
671         gettimeofday(&now, NULL);
672         c = ast_get_channel_by_name_locked(argv[2]);
673         if (!c) {
674                 ast_cli(fd, "%s is not a known channel\n", argv[2]);
675                 return RESULT_SUCCESS;
676         }
677         if(c->cdr) {
678                 elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
679                 hour = elapsed_seconds / 3600;
680                 min = (elapsed_seconds % 3600) / 60;
681                 sec = elapsed_seconds % 60;
682                 snprintf(cdrtime, sizeof(cdrtime), "%dh%dm%ds", hour, min, sec);
683         } else
684                 strcpy(cdrtime, "N/A");
685         ast_cli(fd, 
686                 " -- General --\n"
687                 "           Name: %s\n"
688                 "           Type: %s\n"
689                 "       UniqueID: %s\n"
690                 "      Caller ID: %s\n"
691                 " Caller ID Name: %s\n"
692                 "    DNID Digits: %s\n"
693                 "          State: %s (%d)\n"
694                 "          Rings: %d\n"
695                 "   NativeFormat: %d\n"
696                 "    WriteFormat: %d\n"
697                 "     ReadFormat: %d\n"
698                 "1st File Descriptor: %d\n"
699                 "      Frames in: %d%s\n"
700                 "     Frames out: %d%s\n"
701                 " Time to Hangup: %ld\n"
702                 "   Elapsed Time: %s\n"
703                 "  Direct Bridge: %s\n"
704                 "Indirect Bridge: %s\n"
705                 " --   PBX   --\n"
706                 "        Context: %s\n"
707                 "      Extension: %s\n"
708                 "       Priority: %d\n"
709                 "     Call Group: %d\n"
710                 "   Pickup Group: %d\n"
711                 "    Application: %s\n"
712                 "           Data: %s\n"
713                 "    Blocking in: %s\n",
714                 c->name, c->type, c->uniqueid,
715                 (c->cid.cid_num ? c->cid.cid_num : "(N/A)"),
716                 (c->cid.cid_name ? c->cid.cid_name : "(N/A)"),
717                 (c->cid.cid_dnid ? c->cid.cid_dnid : "(N/A)" ), ast_state2str(c->_state), c->_state, c->rings, c->nativeformats, c->writeformat, c->readformat,
718                 c->fds[0], c->fin & 0x7fffffff, (c->fin & 0x80000000) ? " (DEBUGGED)" : "",
719                 c->fout & 0x7fffffff, (c->fout & 0x80000000) ? " (DEBUGGED)" : "", (long)c->whentohangup,
720                 cdrtime, c->_bridge ? c->_bridge->name : "<none>", ast_bridged_channel(c) ? ast_bridged_channel(c)->name : "<none>", 
721                 c->context, c->exten, c->priority, c->callgroup, c->pickupgroup, ( c->appl ? c->appl : "(N/A)" ),
722                 ( c-> data ? (!ast_strlen_zero(c->data) ? c->data : "(Empty)") : "(None)"),
723                 (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
724         
725         if(pbx_builtin_serialize_variables(c,buf,sizeof(buf)))
726                 ast_cli(fd,"      Variables:\n%s\n",buf);
727         if(c->cdr && ast_cdr_serialize_variables(c->cdr,buf, sizeof(buf), '=', '\n', 1))
728                 ast_cli(fd,"  CDR Variables:\n%s\n",buf);
729         
730         ast_mutex_unlock(&c->lock);
731         return RESULT_SUCCESS;
732 }
733
734 static char *complete_ch_helper(char *line, char *word, int pos, int state, int rpos)
735 {
736         struct ast_channel *c = NULL;
737         int which=0;
738         char *ret = NULL;
739
740         if (pos != rpos)
741                 return NULL;
742         while ( (c = ast_channel_walk_locked(c)) != NULL) {
743                 if (!strncasecmp(word, c->name, strlen(word))) {
744                         if (++which > state) {
745                                 ret = strdup(c->name);
746                                 ast_mutex_unlock(&c->lock);
747                                 break;
748                         }
749                 }
750                 ast_mutex_unlock(&c->lock);
751         }
752         return ret;
753 }
754
755 static char *complete_ch_3(char *line, char *word, int pos, int state)
756 {
757         return complete_ch_helper(line, word, pos, state, 2);
758 }
759
760 static char *complete_ch_4(char *line, char *word, int pos, int state)
761 {
762         return complete_ch_helper(line, word, pos, state, 3);
763 }
764
765 static char *complete_mod_2(char *line, char *word, int pos, int state)
766 {
767         return ast_module_helper(line, word, pos, state, 1, 1);
768 }
769
770 static char *complete_mod_4(char *line, char *word, int pos, int state)
771 {
772         return ast_module_helper(line, word, pos, state, 3, 0);
773 }
774
775 static char *complete_fn(char *line, char *word, int pos, int state)
776 {
777         char *c;
778         char filename[256];
779         if (pos != 1)
780                 return NULL;
781         if (word[0] == '/')
782                 ast_copy_string(filename, word, sizeof(filename));
783         else
784                 snprintf(filename, sizeof(filename), "%s/%s", (char *)ast_config_AST_MODULE_DIR, word);
785         c = (char*)filename_completion_function(filename, state);
786         if (c && word[0] != '/')
787                 c += (strlen((char*)ast_config_AST_MODULE_DIR) + 1);
788         return c ? strdup(c) : c;
789 }
790
791 static int handle_help(int fd, int argc, char *argv[]);
792
793 static struct ast_cli_entry builtins[] = {
794         /* Keep alphabetized, with longer matches first (example: abcd before abc) */
795         { { "_command", "complete", NULL }, handle_commandcomplete, "Command complete", commandcomplete_help },
796         { { "_command", "nummatches", NULL }, handle_commandnummatches, "Returns number of command matches", commandnummatches_help },
797         { { "_command", "matchesarray", NULL }, handle_commandmatchesarray, "Returns command matches array", commandmatchesarray_help },
798         { { "debug", "channel", NULL }, handle_debugchan, "Enable debugging on a channel", debugchan_help, complete_ch_3 },
799         { { "debug", "level", NULL }, handle_debuglevel, "Set global debug level", debuglevel_help },
800         { { "help", NULL }, handle_help, "Display help list, or specific help on a command", help_help },
801         { { "load", NULL }, handle_load, "Load a dynamic module by name", load_help, complete_fn },
802         { { "no", "debug", "channel", NULL }, handle_nodebugchan, "Disable debugging on a channel", nodebugchan_help, complete_ch_4 },
803         { { "reload", NULL }, handle_reload, "Reload configuration", reload_help, complete_mod_2 },
804         { { "set", "debug", NULL }, handle_set_debug, "Set level of debug chattiness", set_debug_help },
805         { { "set", "verbose", NULL }, handle_set_verbose, "Set level of verboseness", set_verbose_help },
806         { { "show", "channel", NULL }, handle_showchan, "Display information on a specific channel", showchan_help, complete_ch_3 },
807         { { "show", "channels", NULL }, handle_chanlist, "Display information on channels", chanlist_help },
808         { { "show", "modules", NULL }, handle_modlist, "List modules and info", modlist_help },
809         { { "show", "modules", "like", NULL }, handle_modlist, "List modules and info", modlist_help, complete_mod_4 },
810         { { "show", "uptime", NULL }, handle_showuptime, "Show uptime information", uptime_help },
811         { { "show", "version", NULL }, handle_version, "Display version info", version_help },
812         { { "soft", "hangup", NULL }, handle_softhangup, "Request a hangup on a given channel", softhangup_help, complete_ch_3 },
813         { { "unload", NULL }, handle_unload, "Unload a dynamic module by name", unload_help, complete_fn },
814         { { NULL }, NULL, NULL, NULL }
815 };
816
817 static struct ast_cli_entry *find_cli(char *cmds[], int exact)
818 {
819         int x;
820         int y;
821         int match;
822         struct ast_cli_entry *e=NULL;
823
824         for (e=helpers;e;e=e->next) {
825                 match = 1;
826                 for (y=0;match && cmds[y]; y++) {
827                         if (!e->cmda[y] && !exact)
828                                 break;
829                         if (!e->cmda[y] || strcasecmp(e->cmda[y], cmds[y]))
830                                 match = 0;
831                 }
832                 if ((exact > -1) && e->cmda[y])
833                         match = 0;
834                 if (match)
835                         break;
836         }
837         if (e)
838                 return e;
839         for (x=0;builtins[x].cmda[0];x++) {
840                 /* start optimistic */
841                 match = 1;
842                 for (y=0;match && cmds[y]; y++) {
843                         /* If there are no more words in the candidate command, then we're
844                            there.  */
845                         if (!builtins[x].cmda[y] && !exact)
846                                 break;
847                         /* If there are no more words in the command (and we're looking for
848                            an exact match) or there is a difference between the two words,
849                            then this is not a match */
850                         if (!builtins[x].cmda[y] || strcasecmp(builtins[x].cmda[y], cmds[y]))
851                                 match = 0;
852                 }
853                 /* If more words are needed to complete the command then this is not
854                    a candidate (unless we're looking for a really inexact answer  */
855                 if ((exact > -1) && builtins[x].cmda[y])
856                         match = 0;
857                 if (match)
858                         return &builtins[x];
859         }
860         return NULL;
861 }
862
863 static void join(char *dest, size_t destsize, char *w[])
864 {
865         int x;
866         /* Join words into a string */
867         if (!dest || destsize < 1) {
868                 return;
869         }
870         dest[0] = '\0';
871         for (x=0;w[x];x++) {
872                 if (x)
873                         strncat(dest, " ", destsize - strlen(dest) - 1);
874                 strncat(dest, w[x], destsize - strlen(dest) - 1);
875         }
876 }
877
878 static void join2(char *dest, size_t destsize, char *w[])
879 {
880         int x;
881         /* Join words into a string */
882         if (!dest || destsize < 1) {
883                 return;
884         }
885         dest[0] = '\0';
886         for (x=0;w[x];x++) {
887                 strncat(dest, w[x], destsize - strlen(dest) - 1);
888         }
889 }
890
891 static char *find_best(char *argv[])
892 {
893         static char cmdline[80];
894         int x;
895         /* See how close we get, then print the  */
896         char *myargv[AST_MAX_CMD_LEN];
897         for (x=0;x<AST_MAX_CMD_LEN;x++)
898                 myargv[x]=NULL;
899         for (x=0;argv[x];x++) {
900                 myargv[x] = argv[x];
901                 if (!find_cli(myargv, -1))
902                         break;
903         }
904         join(cmdline, sizeof(cmdline), myargv);
905         return cmdline;
906 }
907
908 int ast_cli_unregister(struct ast_cli_entry *e)
909 {
910         struct ast_cli_entry *cur, *l=NULL;
911         ast_mutex_lock(&clilock);
912         cur = helpers;
913         while(cur) {
914                 if (e == cur) {
915                         if (e->inuse) {
916                                 ast_log(LOG_WARNING, "Can't remove command that is in use\n");
917                         } else {
918                                 /* Rewrite */
919                                 if (l)
920                                         l->next = e->next;
921                                 else
922                                         helpers = e->next;
923                                 e->next = NULL;
924                                 break;
925                         }
926                 }
927                 l = cur;
928                 cur = cur->next;
929         }
930         ast_mutex_unlock(&clilock);
931         return 0;
932 }
933
934 int ast_cli_register(struct ast_cli_entry *e)
935 {
936         struct ast_cli_entry *cur, *l=NULL;
937         char fulle[80] ="", fulltst[80] ="";
938         static int len;
939         ast_mutex_lock(&clilock);
940         join2(fulle, sizeof(fulle), e->cmda);
941         if (find_cli(e->cmda, -1)) {
942                 ast_mutex_unlock(&clilock);
943                 ast_log(LOG_WARNING, "Command '%s' already registered (or something close enough)\n", fulle);
944                 return -1;
945         }
946         cur = helpers;
947         while(cur) {
948                 join2(fulltst, sizeof(fulltst), cur->cmda);
949                 len = strlen(fulltst);
950                 if (strlen(fulle) < len)
951                         len = strlen(fulle);
952                 if (strncasecmp(fulle, fulltst, len) < 0) {
953                         if (l) {
954                                 e->next = l->next;
955                                 l->next = e;
956                         } else {
957                                 e->next = helpers;
958                                 helpers = e;
959                         }
960                         break;
961                 }
962                 l = cur;
963                 cur = cur->next;
964         }
965         if (!cur) {
966                 if (l)
967                         l->next = e;
968                 else
969                         helpers = e;
970                 e->next = NULL;
971         }
972         ast_mutex_unlock(&clilock);
973         return 0;
974 }
975
976 /*
977  * register/unregister an array of entries.
978  */
979 void ast_cli_register_multiple(struct ast_cli_entry *e, int len)
980 {
981         int i;
982
983         for (i=0; i < len; i++)
984                 ast_cli_register(e + i);
985 }
986
987 void ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
988 {
989         int i;
990
991         for (i=0; i < len; i++)
992                 ast_cli_unregister(e + i);
993 }
994
995 static int help_workhorse(int fd, char *match[])
996 {
997         char fullcmd1[80] = "";
998         char fullcmd2[80] = "";
999         char matchstr[80];
1000         char *fullcmd = NULL;
1001         struct ast_cli_entry *e, *e1, *e2;
1002         e1 = builtins;
1003         e2 = helpers;
1004         if (match)
1005                 join(matchstr, sizeof(matchstr), match);
1006         while(e1->cmda[0] || e2) {
1007                 if (e2)
1008                         join(fullcmd2, sizeof(fullcmd2), e2->cmda);
1009                 if (e1->cmda[0])
1010                         join(fullcmd1, sizeof(fullcmd1), e1->cmda);
1011                 if (!e1->cmda[0] || 
1012                                 (e2 && (strcmp(fullcmd2, fullcmd1) < 0))) {
1013                         /* Use e2 */
1014                         e = e2;
1015                         fullcmd = fullcmd2;
1016                         /* Increment by going to next */
1017                         e2 = e2->next;
1018                 } else {
1019                         /* Use e1 */
1020                         e = e1;
1021                         fullcmd = fullcmd1;
1022                         e1++;
1023                 }
1024                 /* Hide commands that start with '_' */
1025                 if (fullcmd[0] == '_')
1026                         continue;
1027                 if (match) {
1028                         if (strncasecmp(matchstr, fullcmd, strlen(matchstr))) {
1029                                 continue;
1030                         }
1031                 }
1032                 ast_cli(fd, "%25.25s  %s\n", fullcmd, e->summary);
1033         }
1034         return 0;
1035 }
1036
1037 static int handle_help(int fd, int argc, char *argv[]) {
1038         struct ast_cli_entry *e;
1039         char fullcmd[80];
1040         if ((argc < 1))
1041                 return RESULT_SHOWUSAGE;
1042         if (argc > 1) {
1043                 e = find_cli(argv + 1, 1);
1044                 if (e) {
1045                         if (e->usage)
1046                                 ast_cli(fd, e->usage);
1047                         else {
1048                                 join(fullcmd, sizeof(fullcmd), argv+1);
1049                                 ast_cli(fd, "No help text available for '%s'.\n", fullcmd);
1050                         }
1051                 } else {
1052                         if (find_cli(argv + 1, -1)) {
1053                                 return help_workhorse(fd, argv + 1);
1054                         } else {
1055                                 join(fullcmd, sizeof(fullcmd), argv+1);
1056                                 ast_cli(fd, "No such command '%s'.\n", fullcmd);
1057                         }
1058                 }
1059         } else {
1060                 return help_workhorse(fd, NULL);
1061         }
1062         return RESULT_SUCCESS;
1063 }
1064
1065 static char *parse_args(char *s, int *argc, char *argv[], int max)
1066 {
1067         char *dup, *cur;
1068         int x = 0;
1069         int quoted = 0;
1070         int escaped = 0;
1071         int whitespace = 1;
1072
1073         if (!(dup = strdup(s)))
1074                 return NULL;
1075
1076         cur = dup;
1077         while (*s) {
1078                 if ((*s == '"') && !escaped) {
1079                         quoted = !quoted;
1080                         if (quoted & whitespace) {
1081                                 /* If we're starting a quoted string, coming off white space, start a new argument */
1082                                 if (x >= (max - 1)) {
1083                                         ast_log(LOG_WARNING, "Too many arguments, truncating\n");
1084                                         break;
1085                                 }
1086                                 argv[x++] = cur;
1087                                 whitespace = 0;
1088                         }
1089                         escaped = 0;
1090                 } else if (((*s == ' ') || (*s == '\t')) && !(quoted || escaped)) {
1091                         /* If we are not already in whitespace, and not in a quoted string or
1092                            processing an escape sequence, and just entered whitespace, then
1093                            finalize the previous argument and remember that we are in whitespace
1094                         */
1095                         if (!whitespace) {
1096                                 *(cur++) = '\0';
1097                                 whitespace = 1;
1098                         }
1099                 } else if ((*s == '\\') && !escaped) {
1100                         escaped = 1;
1101                 } else {
1102                         if (whitespace) {
1103                                 /* If we are coming out of whitespace, start a new argument */
1104                                 if (x >= (max - 1)) {
1105                                         ast_log(LOG_WARNING, "Too many arguments, truncating\n");
1106                                         break;
1107                                 }
1108                                 argv[x++] = cur;
1109                                 whitespace = 0;
1110                         }
1111                         *(cur++) = *s;
1112                         escaped = 0;
1113                 }
1114                 s++;
1115         }
1116         /* Null terminate */
1117         *(cur++) = '\0';
1118         argv[x] = NULL;
1119         *argc = x;
1120
1121         return dup;
1122 }
1123
1124 /* This returns the number of unique matches for the generator */
1125 int ast_cli_generatornummatches(char *text, char *word)
1126 {
1127         int matches = 0, i = 0;
1128         char *buf = NULL, *oldbuf = NULL;
1129
1130         while ( (buf = ast_cli_generator(text, word, i)) ) {
1131                 if (++i > 1 && strcmp(buf,oldbuf) == 0)  {
1132                                 continue;
1133                 }
1134                 oldbuf = buf;
1135                 matches++;
1136         }
1137
1138         return matches;
1139 }
1140
1141 char **ast_cli_completion_matches(char *text, char *word)
1142 {
1143         char **match_list = NULL, *retstr, *prevstr;
1144         size_t match_list_len, max_equal, which, i;
1145         int matches = 0;
1146
1147         match_list_len = 1;
1148         while ((retstr = ast_cli_generator(text, word, matches)) != NULL) {
1149                 if (matches + 1 >= match_list_len) {
1150                         match_list_len <<= 1;
1151                         match_list = realloc(match_list, match_list_len * sizeof(char *));
1152                 }
1153                 match_list[++matches] = retstr;
1154         }
1155
1156         if (!match_list)
1157                 return (char **) NULL;
1158
1159         which = 2;
1160         prevstr = match_list[1];
1161         max_equal = strlen(prevstr);
1162         for (; which <= matches; which++) {
1163                 for (i = 0; i < max_equal && toupper(prevstr[i]) == toupper(match_list[which][i]); i++)
1164                         continue;
1165                 max_equal = i;
1166         }
1167
1168         retstr = malloc(max_equal + 1);
1169         (void) strncpy(retstr, match_list[1], max_equal);
1170         retstr[max_equal] = '\0';
1171         match_list[0] = retstr;
1172
1173         if (matches + 1 >= match_list_len)
1174                 match_list = realloc(match_list, (match_list_len + 1) * sizeof(char *));
1175         match_list[matches + 1] = (char *) NULL;
1176
1177         return (match_list);
1178 }
1179
1180 static char *__ast_cli_generator(char *text, char *word, int state, int lock)
1181 {
1182         char *argv[AST_MAX_ARGS];
1183         struct ast_cli_entry *e, *e1, *e2;
1184         int x;
1185         int matchnum=0;
1186         char *dup, *res;
1187         char fullcmd1[80] = "";
1188         char fullcmd2[80] = "";
1189         char matchstr[80];
1190         char *fullcmd = NULL;
1191
1192         if ((dup = parse_args(text, &x, argv, sizeof(argv) / sizeof(argv[0])))) {
1193                 join(matchstr, sizeof(matchstr), argv);
1194                 if (lock)
1195                         ast_mutex_lock(&clilock);
1196                 e1 = builtins;
1197                 e2 = helpers;
1198                 while(e1->cmda[0] || e2) {
1199                         if (e2)
1200                                 join(fullcmd2, sizeof(fullcmd2), e2->cmda);
1201                         if (e1->cmda[0])
1202                                 join(fullcmd1, sizeof(fullcmd1), e1->cmda);
1203                         if (!e1->cmda[0] || 
1204                                         (e2 && (strcmp(fullcmd2, fullcmd1) < 0))) {
1205                                 /* Use e2 */
1206                                 e = e2;
1207                                 fullcmd = fullcmd2;
1208                                 /* Increment by going to next */
1209                                 e2 = e2->next;
1210                         } else {
1211                                 /* Use e1 */
1212                                 e = e1;
1213                                 fullcmd = fullcmd1;
1214                                 e1++;
1215                         }
1216                         if ((fullcmd[0] != '_') && !strncasecmp(matchstr, fullcmd, strlen(matchstr))) {
1217                                 /* We contain the first part of one or more commands */
1218                                 /* Now, what we're supposed to return is the next word... */
1219                                 if (!ast_strlen_zero(word) && x>0) {
1220                                         res = e->cmda[x-1];
1221                                 } else {
1222                                         res = e->cmda[x];
1223                                 }
1224                                 if (res) {
1225                                         matchnum++;
1226                                         if (matchnum > state) {
1227                                                 if (lock)
1228                                                         ast_mutex_unlock(&clilock);
1229                                                 free(dup);
1230                                                 return strdup(res);
1231                                         }
1232                                 }
1233                         }
1234                         if (e->generator && !strncasecmp(matchstr, fullcmd, strlen(fullcmd))) {
1235                                 /* We have a command in its entirity within us -- theoretically only one
1236                                    command can have this occur */
1237                                 fullcmd = e->generator(matchstr, word, (!ast_strlen_zero(word) ? (x - 1) : (x)), state);
1238                                 if (fullcmd) {
1239                                         if (lock)
1240                                                 ast_mutex_unlock(&clilock);
1241                                         free(dup);
1242                                         return fullcmd;
1243                                 }
1244                         }
1245                         
1246                 }
1247                 if (lock)
1248                         ast_mutex_unlock(&clilock);
1249                 free(dup);
1250         }
1251         return NULL;
1252 }
1253
1254 char *ast_cli_generator(char *text, char *word, int state)
1255 {
1256         return __ast_cli_generator(text, word, state, 1);
1257 }
1258
1259 int ast_cli_command(int fd, char *s)
1260 {
1261         char *argv[AST_MAX_ARGS];
1262         struct ast_cli_entry *e;
1263         int x;
1264         char *dup;
1265
1266         if ((dup = parse_args(s, &x, argv, sizeof(argv) / sizeof(argv[0])))) {
1267                 /* We need at least one entry, or ignore */
1268                 if (x > 0) {
1269                         ast_mutex_lock(&clilock);
1270                         e = find_cli(argv, 0);
1271                         if (e)
1272                                 e->inuse++;
1273                         ast_mutex_unlock(&clilock);
1274                         if (e) {
1275                                 switch(e->handler(fd, x, argv)) {
1276                                 case RESULT_SHOWUSAGE:
1277                                         ast_cli(fd, e->usage);
1278                                         break;
1279                                 }
1280                         } else 
1281                                 ast_cli(fd, "No such command '%s' (type 'help' for help)\n", find_best(argv));
1282                         if (e) {
1283                                 ast_mutex_lock(&clilock);
1284                                 e->inuse--;
1285                                 ast_mutex_unlock(&clilock);
1286                         }
1287                 }
1288                 free(dup);
1289         } else {
1290                 ast_log(LOG_WARNING, "Out of memory\n");        
1291                 return -1;
1292         }
1293         return 0;
1294 }