Sat Nov 1 06:31:10 2008

Asterisk developer's documentation


pbx_config.c File Reference

Populate and remember extensions from static config file. More...

#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include "asterisk.h"
#include "asterisk/pbx.h"
#include "asterisk/config.h"
#include "asterisk/options.h"
#include "asterisk/module.h"
#include "asterisk/logger.h"
#include "asterisk/cli.h"
#include "asterisk/callerid.h"

Include dependency graph for pbx_config.c:

Go to the source code of this file.

Defines

#define BROKEN_READLINE   1
#define FREE   free

Functions

 AST_MUTEX_DEFINE_STATIC (save_dialplan_lock)
static char * complete_context_add_extension (char *line, char *word, int pos, int state)
static char * complete_context_add_ignorepat (char *line, char *word, int pos, int state)
static char * complete_context_add_include (char *line, char *word, int pos, int state)
static char * complete_context_dont_include (char *line, char *word, int pos, int state)
static char * complete_context_remove_extension (char *line, char *word, int pos, int state)
static char * complete_context_remove_ignorepat (char *line, char *word, int pos, int state)
char * description (void)
 Provides a description of the module.
static int fix_complete_args (char *line, char **word, int *pos)
static int handle_context_add_extension (int fd, int argc, char *argv[])
 ADD EXTENSION command stuff.
static int handle_context_add_ignorepat (int fd, int argc, char *argv[])
static int handle_context_add_include (int fd, int argc, char *argv[])
static int handle_context_dont_include (int fd, int argc, char *argv[])
static int handle_context_remove_extension (int fd, int argc, char *argv[])
static int handle_context_remove_ignorepat (int fd, int argc, char *argv[])
static int handle_reload_extensions (int fd, int argc, char *argv[])
static int handle_save_dialplan (int fd, int argc, char *argv[])
 'save dialplan' CLI command implementation functions ...
char * key (void)
 Returns the ASTERISK_GPL_KEY.
int load_module (void)
 Initialize the module.
static int pbx_load_module (void)
int reload (void)
 Reload stuff.
int unload_module (void)
 Cleanup all module structures, sockets, etc.
int usecount (void)
 Provides a usecount.

Variables

static int autofallthrough_config = 0
static int clearglobalvars_config = 0
static char * config = "extensions.conf"
static struct ast_cli_entry context_add_extension_cli
static char context_add_extension_help []
static struct ast_cli_entry context_add_ignorepat_cli
static char context_add_ignorepat_help []
static struct ast_cli_entry context_add_include_cli
static char context_add_include_help []
static struct ast_cli_entry context_dont_include_cli
static char context_dont_include_help []
static struct ast_cli_entry context_remove_extension_cli
static char context_remove_extension_help []
static struct ast_cli_entry context_remove_ignorepat_cli
static char context_remove_ignorepat_help []
static char * dtext = "Text Extension Configuration"
static struct ast_contextlocal_contexts = NULL
static char * registrar = "pbx_config"
static struct ast_cli_entry reload_extensions_cli
static char reload_extensions_help []
static struct ast_cli_entry save_dialplan_cli
static char save_dialplan_help []
static int static_config = 0
static int write_protect_config = 1


Detailed Description

Populate and remember extensions from static config file.

Definition in file pbx_config.c.


Define Documentation

#define BROKEN_READLINE   1

Definition at line 437 of file pbx_config.c.

#define FREE   free

Definition at line 51 of file pbx_config.c.


Function Documentation

AST_MUTEX_DEFINE_STATIC ( save_dialplan_lock   ) 

static char* complete_context_add_extension ( char *  line,
char *  word,
int  pos,
int  state 
) [static]

add extension 6123,1,Dial,IAX/212.71.138.13/6123 into local

Definition at line 1255 of file pbx_config.c.

References ast_get_context_name(), ast_lock_contexts(), ast_log(), ast_unlock_contexts(), ast_walk_contexts(), LOG_WARNING, and strdup.

01257 {
01258    int which = 0;
01259 
01260    /* complete 'into' word ... */
01261    if (pos == 3) {
01262       if (state == 0) return strdup("into");
01263       return NULL;
01264    }
01265 
01266    /* complete context */
01267    if (pos == 4) {
01268       struct ast_context *c;
01269 
01270       /* try to lock contexts list ... */
01271       if (ast_lock_contexts()) {
01272          ast_log(LOG_WARNING, "Failed to lock contexts list\n");
01273          return NULL;
01274       }
01275 
01276       /* walk through all contexts */
01277       c = ast_walk_contexts(NULL);
01278       while (c) {
01279          /* matching context? */
01280          if (!strncmp(ast_get_context_name(c), word, strlen(word))) {
01281             if (++which > state) {
01282                char *res = strdup(ast_get_context_name(c));
01283                ast_unlock_contexts();
01284                return res;
01285             }
01286          }
01287          c = ast_walk_contexts(c);
01288       }
01289 
01290       ast_unlock_contexts();
01291       return NULL;
01292    }
01293 
01294    if (pos == 5) return state == 0 ? strdup("replace") : NULL;
01295 
01296    return NULL;
01297 }

static char* complete_context_add_ignorepat ( char *  line,
char *  word,
int  pos,
int  state 
) [static]

Definition at line 1338 of file pbx_config.c.

References ast_get_context_name(), ast_get_ignorepat_name(), ast_lock_context(), ast_lock_contexts(), ast_log(), ast_unlock_context(), ast_unlock_contexts(), ast_walk_context_ignorepats(), ast_walk_contexts(), context, free, LOG_ERROR, strdup, and strsep().

01340 {
01341    if (pos == 3) return state == 0 ? strdup("into") : NULL;
01342 
01343    if (pos == 4) {
01344       struct ast_context *c;
01345       int which = 0;
01346       char *dupline, *duplinet, *ignorepat = NULL;
01347 
01348       dupline = strdup(line);
01349       duplinet = dupline;
01350 
01351       if (duplinet) {
01352          strsep(&duplinet, " "); /* skip 'add' */
01353          strsep(&duplinet, " "); /* skip 'ignorepat' */
01354          ignorepat = strsep(&duplinet, " ");
01355       }
01356 
01357       if (ast_lock_contexts()) {
01358          ast_log(LOG_ERROR, "Failed to lock contexts list\n");
01359          return NULL;
01360       }
01361 
01362       c = ast_walk_contexts(NULL);
01363       while (c) {
01364          if (!strncmp(ast_get_context_name(c), word, strlen(word))) {
01365             int serve_context = 1;
01366             if (ignorepat) {
01367                if (!ast_lock_context(c)) {
01368                   struct ast_ignorepat *ip;
01369                   ip = ast_walk_context_ignorepats(c, NULL);
01370                   while (ip && serve_context) {
01371                      if (!strcmp(ast_get_ignorepat_name(ip), ignorepat))
01372                         serve_context = 0;
01373                      ip = ast_walk_context_ignorepats(c, ip);
01374                   }
01375                   ast_unlock_context(c);
01376                }
01377             }
01378             if (serve_context) {
01379                if (++which > state) {
01380                   char *context = strdup(ast_get_context_name(c));
01381                   if (dupline) free(dupline);
01382                   ast_unlock_contexts();
01383                   return context;
01384                }
01385             }
01386          }
01387          c = ast_walk_contexts(c);
01388       }
01389 
01390       if (dupline) free(dupline);
01391       ast_unlock_contexts();
01392       return NULL;
01393    }
01394 
01395    return NULL;
01396 }

static char* complete_context_add_include ( char *  line,
char *  word,
int  pos,
int  state 
) [static]

Definition at line 748 of file pbx_config.c.

References ast_get_context_name(), ast_get_include_name(), ast_lock_context(), ast_lock_contexts(), ast_log(), ast_unlock_context(), ast_unlock_contexts(), ast_walk_context_includes(), ast_walk_contexts(), context, free, LOG_ERROR, strdup, and strsep().

00750 {
00751    struct ast_context *c;
00752    int which = 0;
00753 
00754    /* server context for inclusion ... */
00755    if (pos == 1)
00756    {
00757       if (ast_lock_contexts()) {
00758          ast_log(LOG_ERROR, "Failed to lock context list\n");
00759          return NULL;
00760       }
00761 
00762       /* server all contexts */ 
00763       c = ast_walk_contexts(NULL); 
00764       while (c) {
00765          if ((!strlen(word) || 
00766              !strncmp(ast_get_context_name(c), word, strlen(word))) &&
00767             ++which > state)
00768          {
00769             char *context = strdup(ast_get_context_name(c));
00770             ast_unlock_contexts();
00771             return context;
00772          }
00773          c = ast_walk_contexts(c);
00774       }
00775 
00776       ast_unlock_contexts();
00777    }
00778 
00779    /* complete 'in' only if context exist ... */
00780    if (pos == 2)
00781    {
00782       char *context, *dupline, *duplinet;
00783 
00784       if (state != 0) return NULL;
00785 
00786       /* parse context from line ... */
00787       if (!(dupline = strdup(line))) {
00788          ast_log(LOG_ERROR, "Out of free memory\n");
00789          if (state == 0) return strdup("in");
00790          return NULL;
00791       }
00792 
00793       duplinet = dupline;
00794 
00795       strsep(&duplinet, " ");
00796       context = strsep(&duplinet, " ");
00797       if (context) {
00798          struct ast_context *c;
00799          int context_existence = 0;
00800 
00801          /* check for context existence ... */
00802          if (ast_lock_contexts()) {
00803             ast_log(LOG_ERROR, "Failed to lock context list\n");
00804             free(dupline);
00805             /* our fault, we can't check, so complete 'in' ... */
00806             return strdup("in");
00807          }
00808 
00809          c = ast_walk_contexts(NULL);
00810          while (c && !context_existence) {
00811             if (!strcmp(context, ast_get_context_name(c))) {
00812                context_existence = 1;
00813                continue;
00814             }
00815             c = ast_walk_contexts(c);
00816          }
00817 
00818          /* if context exists, return 'into' ... */
00819          if (context_existence) {
00820             free(dupline);
00821             ast_unlock_contexts();
00822             return strdup("into");
00823          }
00824 
00825          ast_unlock_contexts();
00826       }  
00827 
00828       free(dupline);
00829       return NULL;
00830    }
00831 
00832    /* serve context into which we include another context */
00833    if (pos == 3)
00834    {
00835       char *context, *dupline, *duplinet, *in;
00836       int context_existence = 0;
00837 
00838       if (!(dupline = strdup(line))) {
00839          ast_log(LOG_ERROR, "Out of free memory\n");
00840          return NULL;
00841       }
00842 
00843       duplinet = dupline;
00844 
00845       strsep(&duplinet, " "); /* skip 'include' */
00846       context = strsep(&duplinet, " ");
00847       in = strsep(&duplinet, " ");
00848 
00849       /* given some context and third word is in? */
00850       if (!strlen(context) || strcmp(in, "in")) {
00851          free(dupline);
00852          return NULL;
00853       }
00854 
00855       if (ast_lock_contexts()) {
00856          ast_log(LOG_ERROR, "Failed to lock context list\n");
00857          free(dupline);
00858          return NULL;
00859       }
00860 
00861       /* check for context existence ... */
00862       c = ast_walk_contexts(NULL);
00863       while (c && !context_existence) {
00864          if (!strcmp(context, ast_get_context_name(c))) {
00865             context_existence = 1;
00866             continue;
00867          }
00868          c = ast_walk_contexts(c);
00869       }
00870 
00871       if (!context_existence) {
00872          free(dupline);
00873          ast_unlock_contexts();
00874          return NULL;
00875       }
00876 
00877       /* go through all contexts ... */
00878       c = ast_walk_contexts(NULL);
00879       while (c) {
00880          /* must be different contexts ... */
00881          if (strcmp(context, ast_get_context_name(c))) {
00882             if (!ast_lock_context(c)) {
00883                struct ast_include *i;
00884                int included = 0;
00885 
00886                /* check for duplicity inclusion ... */
00887                i = ast_walk_context_includes(c, NULL);
00888                while (i && !included) {
00889                   if (!strcmp(ast_get_include_name(i), context))
00890                      included = 1;
00891                   i = ast_walk_context_includes(c, i);
00892                }
00893                ast_unlock_context(c);
00894 
00895                /* not included yet, so show possibility ... */
00896                if (!included &&
00897                   !strncmp(ast_get_context_name(c), word, strlen(word))){
00898                   
00899                   if (++which > state) {
00900                      char *res = strdup(ast_get_context_name(c));
00901                      free(dupline);
00902                      ast_unlock_contexts();
00903                      return res;
00904                   }
00905                }  
00906             }
00907          }
00908          c = ast_walk_contexts(c);
00909       }
00910 
00911       ast_unlock_contexts();
00912       free(dupline);
00913       return NULL;
00914    }
00915 
00916    return NULL;
00917 }

static char* complete_context_dont_include ( char *  line,
char *  word,
int  pos,
int  state 
) [static]

Definition at line 146 of file pbx_config.c.

References ast_get_context_name(), ast_get_include_name(), ast_lock_context(), ast_lock_contexts(), ast_log(), ast_unlock_context(), ast_unlock_contexts(), ast_walk_context_includes(), ast_walk_contexts(), context, free, LOG_ERROR, LOG_WARNING, strdup, and strsep().

00148 {
00149    int which = 0;
00150 
00151    /*
00152     * Context completion ...
00153     */
00154    if (pos == 2) {
00155       struct ast_context *c;
00156 
00157       if (ast_lock_contexts()) {
00158          ast_log(LOG_ERROR, "Failed to lock context list\n");
00159          return NULL;
00160       }
00161 
00162       /* walk pbx_get_contexts ... */
00163       c = ast_walk_contexts(NULL); 
00164       while (c) {
00165          struct ast_include *i;
00166 
00167          if (ast_lock_context(c)) {
00168             c = ast_walk_contexts(c);
00169             continue;
00170          }
00171 
00172          i = ast_walk_context_includes(c, NULL);
00173          while (i) {
00174             if (!strlen(word) ||
00175                !strncmp(ast_get_include_name(i), word, strlen(word))) {
00176                struct ast_context *nc;
00177                int already_served = 0;
00178 
00179                /* check if this include is already served or not */
00180 
00181                /* go through all contexts again till we reach actuall
00182                 * context or already_served = 1
00183                 */
00184                nc = ast_walk_contexts(NULL);
00185                while (nc && nc != c && !already_served) {
00186                   if (!ast_lock_context(nc)) {
00187                      struct ast_include *ni;
00188 
00189                      ni = ast_walk_context_includes(nc, NULL);
00190                      while (ni && !already_served) {
00191                         if (!strcmp(ast_get_include_name(i),
00192                            ast_get_include_name(ni)))
00193                            already_served = 1;
00194                         ni = ast_walk_context_includes(nc, ni);
00195                      }  
00196                      
00197                      ast_unlock_context(nc);
00198                   }
00199                   nc = ast_walk_contexts(nc);
00200                }
00201 
00202                if (!already_served) {
00203                   if (++which > state) {
00204                      char *res =
00205                         strdup(ast_get_include_name(i));
00206                      ast_unlock_context(c);
00207                      ast_unlock_contexts();
00208                      return res;
00209                   }
00210                }
00211             }
00212             i = ast_walk_context_includes(c, i);
00213          }
00214 
00215          ast_unlock_context(c);
00216          c = ast_walk_contexts(c);
00217       }
00218 
00219       ast_unlock_contexts();
00220       return NULL;
00221    }
00222 
00223    /*
00224     * 'in' completion ... (complete only if previous context is really
00225     * included somewhere)
00226     */
00227    if (pos == 3) {
00228       struct ast_context *c;
00229       char *context, *dupline, *duplinet;
00230 
00231       if (state > 0) return NULL;
00232 
00233       /* take 'context' from line ... */
00234       if (!(dupline = strdup(line))) {
00235          ast_log(LOG_ERROR, "Out of free memory\n");
00236          return NULL;
00237       }
00238 
00239       duplinet = dupline;
00240       strsep(&duplinet, " "); /* skip 'dont' */
00241       strsep(&duplinet, " "); /* skip 'include' */
00242       context = strsep(&duplinet, " ");
00243 
00244       if (!context) {
00245          free(dupline);
00246          return NULL;
00247       }
00248 
00249       if (ast_lock_contexts()) {
00250          ast_log(LOG_WARNING, "Failed to lock contexts list\n");
00251          free(dupline);
00252          return NULL;
00253       }
00254 
00255       /* go through all contexts and check if is included ... */
00256       c = ast_walk_contexts(NULL);
00257       while (c) {
00258          struct ast_include *i;
00259          if (ast_lock_context(c)) {
00260             free(dupline);
00261             ast_unlock_contexts();
00262             return NULL;
00263          }
00264 
00265          i = ast_walk_context_includes(c, NULL);
00266          while (i) {
00267             /* is it our context? */
00268             if (!strcmp(ast_get_include_name(i), context)) {
00269                /* yes, it is, context is really included, so
00270                 * complete "in" command
00271                 */
00272                free(dupline);
00273                ast_unlock_context(c);
00274                ast_unlock_contexts();
00275                return strdup("in");
00276             }
00277             i = ast_walk_context_includes(c, i);
00278          }
00279          ast_unlock_context(c);
00280          c = ast_walk_contexts(c);
00281       }
00282       free(dupline);
00283       ast_unlock_contexts();
00284       return NULL;
00285    }
00286 
00287    /*
00288     * Context from which we removing include ... 
00289     */
00290    if (pos == 4) {
00291       struct ast_context *c;
00292       char *context, *dupline, *duplinet, *in;
00293 
00294       if (!(dupline = strdup(line))) {
00295          ast_log(LOG_ERROR, "Out of free memory\n");
00296          return NULL;
00297       }
00298 
00299       duplinet = dupline;
00300 
00301       strsep(&duplinet, " "); /* skip 'dont' */
00302       strsep(&duplinet, " "); /* skip 'include' */
00303 
00304       if (!(context = strsep(&duplinet, " "))) {
00305          free(dupline);
00306          return NULL;
00307       }
00308 
00309       /* third word must be in */
00310       in = strsep(&duplinet, " ");
00311       if (!in ||
00312          strcmp(in, "in")) {
00313          free(dupline);
00314          return NULL;
00315       }
00316 
00317       if (ast_lock_contexts()) {
00318          ast_log(LOG_ERROR, "Failed to lock context list\n");
00319          free(dupline);
00320          return NULL;
00321       }
00322 
00323       /* walk through all contexts ... */
00324       c = ast_walk_contexts(NULL);
00325       while (c) {
00326          struct ast_include *i;
00327          if (ast_lock_context(c)) {
00328             free(dupline);
00329             return NULL;
00330          }
00331    
00332          /* walk through all includes and check if it is our context */ 
00333          i = ast_walk_context_includes(c, NULL);
00334          while (i) {
00335             /* is in this context included another on which we want to
00336              * remove?
00337              */
00338             if (!strcmp(context, ast_get_include_name(i))) {
00339                /* yes, it's included, is matching our word too? */
00340                if (!strncmp(ast_get_context_name(c),
00341                      word, strlen(word))) {
00342                   /* check state for completion */
00343                   if (++which > state) {
00344                      char *res = strdup(ast_get_context_name(c));
00345                      free(dupline);
00346                      ast_unlock_context(c);
00347                      ast_unlock_contexts();
00348                      return res;
00349                   }
00350                }
00351                break;
00352             }
00353             i = ast_walk_context_includes(c, i);
00354          }  
00355          ast_unlock_context(c);
00356          c = ast_walk_contexts(c);
00357       }
00358 
00359       free(dupline);
00360       ast_unlock_contexts();
00361       return NULL;
00362    }
00363 
00364    return NULL;
00365 }

static char* complete_context_remove_extension ( char *  line,
char *  word,
int  pos,
int  state 
) [static]

Definition at line 484 of file pbx_config.c.

References ast_get_context_name(), ast_get_extension_name(), ast_get_extension_priority(), ast_lock_contexts(), ast_log(), ast_unlock_contexts(), ast_walk_context_extensions(), ast_walk_contexts(), ast_walk_extension_priorities(), context, exten, fix_complete_args(), free, LOG_ERROR, malloc, ast_exten::priority, strdup, and strsep().

00486 {
00487    char *ret = NULL;
00488    int which = 0;
00489 
00490 #ifdef BROKEN_READLINE
00491    /*
00492     * Fix arguments, *word is a new allocated structure, REMEMBER to
00493     * free *word when you want to return from this function ...
00494     */
00495    if (fix_complete_args(line, &word, &pos)) {
00496       ast_log(LOG_ERROR, "Out of free memory\n");
00497       return NULL;
00498    }
00499 #endif
00500 
00501    /*
00502     * exten@context completion ... 
00503     */
00504    if (pos == 2) {
00505       struct ast_context *c;
00506       struct ast_exten *e;
00507       char *context = NULL, *exten = NULL, *delim = NULL;
00508 
00509       /* now, parse values from word = exten@context */
00510       if ((delim = strchr(word, (int)'@'))) {
00511          /* check for duplicity ... */
00512          if (delim != strrchr(word, (int)'@')) {
00513 #ifdef BROKEN_READLINE
00514             free(word);
00515 #endif
00516             return NULL;
00517          }
00518 
00519          *delim = '\0';
00520          exten = strdup(word);
00521          context = strdup(delim + 1);
00522          *delim = '@';
00523       } else {
00524          exten = strdup(word);
00525       }
00526 #ifdef BROKEN_READLINE
00527       free(word);
00528 #endif
00529 
00530       if (ast_lock_contexts()) {
00531          ast_log(LOG_ERROR, "Failed to lock context list\n");
00532          free(context); free(exten);
00533          return NULL;
00534       }
00535 
00536       /* find our context ... */
00537       c = ast_walk_contexts(NULL); 
00538       while (c) {
00539          /* our context? */
00540          if ( (!context || !strlen(context)) ||                            /* if no input, all contexts ... */
00541              (context && !strncmp(ast_get_context_name(c),
00542                           context, strlen(context))) ) {                  /* if input, compare ... */
00543             /* try to complete extensions ... */
00544             e = ast_walk_context_extensions(c, NULL);
00545             while (e) {
00546                /* our extension? */
00547                if ( (!exten || !strlen(exten)) ||                           /* if not input, all extensions ... */
00548                    (exten && !strncmp(ast_get_extension_name(e), exten,
00549                                       strlen(exten))) ) { /* if input, compare ... */
00550                   if (++which > state) {
00551                      /* If there is an extension then return
00552                       * exten@context.
00553                       */
00554                      if (exten) {
00555                         ret = malloc(strlen(ast_get_extension_name(e)) +
00556                            strlen(ast_get_context_name(c)) + 2);
00557                         if (ret)
00558                            sprintf(ret, "%s@%s", ast_get_extension_name(e),
00559                               ast_get_context_name(c));
00560                      }
00561                      free(exten); free(context);
00562 
00563                      ast_unlock_contexts();
00564    
00565                      return ret;
00566                   }
00567                }
00568                e = ast_walk_context_extensions(c, e);
00569             }
00570          }
00571          c = ast_walk_contexts(c);
00572       }
00573 
00574       ast_unlock_contexts();
00575 
00576       free(exten); free(context);
00577 
00578       return NULL;
00579    }
00580 
00581    /*
00582     * Complete priority ...
00583     */
00584    if (pos == 3) {
00585       char *delim, *exten, *context, *dupline, *duplinet, *ec;
00586       struct ast_context *c;
00587 
00588       dupline = strdup(line);
00589       if (!dupline) {
00590 #ifdef BROKEN_READLINE
00591          free(word);
00592 #endif
00593          return NULL;
00594       }
00595       duplinet = dupline;
00596 
00597       strsep(&duplinet, " "); /* skip 'remove' */
00598       strsep(&duplinet, " "); /* skip 'extension */
00599 
00600       if (!(ec = strsep(&duplinet, " "))) {
00601          free(dupline);
00602 #ifdef BROKEN_READLINE
00603          free(word);
00604 #endif
00605          return NULL;
00606       }
00607 
00608       /* wrong exten@context format? */
00609       if (!(delim = strchr(ec, (int)'@')) ||
00610          (strchr(ec, (int)'@') != strrchr(ec, (int)'@'))) {
00611 #ifdef BROKEN_READLINE
00612          free(word);
00613 #endif
00614          free(dupline);
00615          return NULL;
00616       }
00617 
00618       /* check if there is exten and context too ... */
00619       *delim = '\0';
00620       if ((!strlen(ec)) || (!strlen(delim + 1))) {
00621 #ifdef BROKEN_READLINE
00622          free(word);
00623 #endif
00624          free(dupline);
00625          return NULL;
00626       }
00627 
00628       exten = strdup(ec);
00629       context = strdup(delim + 1);
00630       free(dupline);
00631 
00632       if (ast_lock_contexts()) {
00633          ast_log(LOG_ERROR, "Failed to lock context list\n");
00634 #ifdef BROKEN_READLINE
00635          free(word);
00636 #endif
00637          free(exten); free(context);
00638          return NULL;
00639       }
00640 
00641       /* walk contexts */
00642       c = ast_walk_contexts(NULL); 
00643       while (c) {
00644          if (!strcmp(ast_get_context_name(c), context)) {
00645             struct ast_exten *e;
00646 
00647             /* walk extensions */
00648             free(context);
00649             e = ast_walk_context_extensions(c, NULL); 
00650             while (e) {
00651                if (!strcmp(ast_get_extension_name(e), exten)) {
00652                   struct ast_exten *priority;
00653                   char buffer[10];
00654                
00655                   free(exten);
00656                   priority = ast_walk_extension_priorities(e, NULL);
00657                   /* serve priorities */
00658                   do {
00659                      snprintf(buffer, 10, "%u",
00660                         ast_get_extension_priority(priority));
00661                      if (!strncmp(word, buffer, strlen(word))) {
00662                         if (++which > state) {
00663 #ifdef BROKEN_READLINE
00664                            free(word);
00665 #endif
00666                            ast_unlock_contexts();
00667                            return strdup(buffer);
00668                         }
00669                      }
00670                      priority = ast_walk_extension_priorities(e,
00671                         priority);
00672                   } while (priority);
00673 
00674 #ifdef BROKEN_READLINE
00675                   free(word);
00676 #endif
00677                   ast_unlock_contexts();
00678                   return NULL;         
00679                }
00680                e = ast_walk_context_extensions(c, e);
00681             }
00682 #ifdef BROKEN_READLINE
00683             free(word);
00684 #endif
00685             free(exten);
00686             ast_unlock_contexts();
00687             return NULL;
00688          }
00689          c = ast_walk_contexts(c);
00690       }
00691 
00692 #ifdef BROKEN_READLINE
00693       free(word);
00694 #endif
00695       free(exten); free(context);
00696 
00697       ast_unlock_contexts();
00698       return NULL;
00699    }
00700 
00701 #ifdef BROKEN_READLINE
00702    free(word);
00703 #endif
00704    return NULL; 
00705 }

static char* complete_context_remove_ignorepat ( char *  line,
char *  word,
int  pos,
int  state 
) [static]

Definition at line 1441 of file pbx_config.c.

References ast_get_context_name(), ast_get_ignorepat_name(), ast_lock_context(), ast_lock_contexts(), ast_log(), ast_unlock_context(), ast_unlock_contexts(), ast_walk_context_ignorepats(), ast_walk_contexts(), free, LOG_WARNING, strdup, and strsep().

01443 {
01444    struct ast_context *c;
01445    int which = 0;
01446 
01447    if (pos == 2) {
01448       if (ast_lock_contexts()) {
01449          ast_log(LOG_WARNING, "Failed to lock contexts list\n");
01450          return NULL;
01451       }
01452 
01453       c = ast_walk_contexts(NULL);
01454       while (c) {
01455          if (!ast_lock_context(c)) {
01456             struct ast_ignorepat *ip;
01457          
01458             ip = ast_walk_context_ignorepats(c, NULL);
01459             while (ip) {
01460                if (!strncmp(ast_get_ignorepat_name(ip), word, strlen(word))) {
01461                   if (which + 1 > state) {
01462                      struct ast_context *cw;
01463                      int already_served = 0;
01464                      cw = ast_walk_contexts(NULL);
01465                      while (cw && cw != c && !already_served) {
01466                         if (!ast_lock_context(cw)) {
01467                            struct ast_ignorepat *ipw;
01468                            ipw = ast_walk_context_ignorepats(cw, NULL);
01469                            while (ipw) {
01470                               if (!strcmp(ast_get_ignorepat_name(ipw),
01471                                  ast_get_ignorepat_name(ip))) already_served = 1;
01472                               ipw = ast_walk_context_ignorepats(cw, ipw);
01473                            }
01474                            ast_unlock_context(cw);
01475                         }
01476                         cw = ast_walk_contexts(cw);
01477                      }
01478                      if (!already_served) {
01479                         char *ret = strdup(ast_get_ignorepat_name(ip));
01480                         ast_unlock_context(c);
01481                         ast_unlock_contexts();
01482                         return ret;
01483                      }
01484                   } else
01485                      which++;
01486                }
01487                ip = ast_walk_context_ignorepats(c, ip);
01488             }
01489 
01490             ast_unlock_context(c);
01491          }
01492          c = ast_walk_contexts(c);
01493       }
01494 
01495       ast_unlock_contexts();
01496       return NULL;
01497    }
01498  
01499    if (pos == 3) return state == 0 ? strdup("from") : NULL;
01500 
01501    if (pos == 4) {
01502       char *dupline, *duplinet, *ignorepat;
01503 
01504       dupline = strdup(line);
01505       if (!dupline) {
01506          ast_log(LOG_WARNING, "Out of free memory\n");
01507          return NULL;
01508       }
01509 
01510       duplinet = dupline;
01511       strsep(&duplinet, " ");
01512       strsep(&duplinet, " ");
01513       ignorepat = strsep(&duplinet, " ");
01514 
01515       if (!ignorepat) {
01516          free(dupline);
01517          return NULL;
01518       }
01519 
01520       if (ast_lock_contexts()) {
01521          ast_log(LOG_WARNING, "Failed to lock contexts list\n");
01522          free(dupline);
01523          return NULL;
01524       }
01525 
01526       c = ast_walk_contexts(NULL);
01527       while (c) {
01528          if (!ast_lock_context(c)) {
01529             struct ast_ignorepat *ip;
01530             ip = ast_walk_context_ignorepats(c, NULL);
01531             while (ip) {
01532                if (!strcmp(ast_get_ignorepat_name(ip), ignorepat)) {
01533                   if (!strncmp(ast_get_context_name(c), word, strlen(word))) {
01534                      if (++which > state) {
01535                         char *ret = strdup(ast_get_context_name(c));
01536                         free(dupline);
01537                         ast_unlock_context(c);
01538                         ast_unlock_contexts();
01539                         return ret;
01540                      }
01541                   }
01542                }
01543                ip = ast_walk_context_ignorepats(c, ip);
01544             }
01545 
01546             ast_unlock_context(c);
01547          }
01548          c = ast_walk_contexts(c);
01549       }
01550 
01551       free(dupline);
01552       ast_unlock_contexts();
01553       return NULL;
01554    }
01555 
01556    return NULL;
01557 }

char* description ( void   ) 

Provides a description of the module.

Returns:
a short description of your module

Definition at line 1837 of file pbx_config.c.

01838 {
01839    return dtext;
01840 }

static int fix_complete_args ( char *  line,
char **  word,
int *  pos 
) [static]

Definition at line 452 of file pbx_config.c.

References free, strdup, and strsep().

Referenced by complete_context_remove_extension().

00453 {
00454    char *_line, *_strsep_line, *_previous_word = NULL, *_word = NULL;
00455    int words = 0;
00456 
00457    _line = strdup(line);
00458 
00459    _strsep_line = _line;
00460    while (_strsep_line) {
00461       _previous_word = _word;
00462       _word = strsep(&_strsep_line, " ");
00463 
00464       if (_word && strlen(_word)) words++;
00465    }
00466 
00467 
00468    if (_word || _previous_word) {
00469       if (_word) {
00470          if (!strlen(_word)) words++;
00471          *word = strdup(_word);
00472       } else
00473          *word = strdup(_previous_word);
00474       *pos = words - 1;
00475       free(_line);
00476       return 0;
00477    }
00478 
00479    free(_line);
00480    return -1;
00481 }

static int handle_context_add_extension ( int  fd,
int  argc,
char *  argv[] 
) [static]

ADD EXTENSION command stuff.

Definition at line 1169 of file pbx_config.c.

References app, ast_add_extension(), ast_cli(), ast_process_quotes_and_slashes(), ast_exten::cidmatch, exten, free, PRIORITY_HINT, RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, strdup, and strsep().

01170 {
01171    char *whole_exten;
01172    char *exten, *prior;
01173    int iprior = -2;
01174    char *cidmatch, *app, *app_data;
01175    char *start, *end;
01176 
01177    /* check for arguments at first */
01178    if (argc != 5 && argc != 6) return RESULT_SHOWUSAGE;
01179    if (strcmp(argv[3], "into")) return RESULT_SHOWUSAGE;
01180    if (argc == 6) if (strcmp(argv[5], "replace")) return RESULT_SHOWUSAGE;
01181 
01182    whole_exten = argv[2];
01183    exten       = strsep(&whole_exten,",");
01184    if (strchr(exten, '/')) {
01185       cidmatch = exten;
01186       strsep(&cidmatch,"/");
01187    } else {
01188       cidmatch = NULL;
01189    }
01190    prior       = strsep(&whole_exten,",");
01191    if (prior) {
01192       if (!strcmp(prior, "hint")) {
01193          iprior = PRIORITY_HINT;
01194       } else {
01195          if (sscanf(prior, "%d", &iprior) != 1) {
01196             ast_cli(fd, "'%s' is not a valid priority\n", prior);
01197             prior = NULL;
01198          }
01199       }
01200    }
01201    app = whole_exte