Skip to content
Snippets Groups Projects
pbx.c 165 KiB
Newer Older
  • Learn to ignore specific revisions
  • Mark Spencer's avatar
    Mark Spencer committed
    
    struct ast_ignorepat *ast_walk_context_ignorepats(struct ast_context *con,
    	struct ast_ignorepat *ip)
    {
    	if (!ip)
    		return con ? con->ignorepats : NULL;
    	else
    		return ip->next;
    }
    
    
    int ast_context_verify_includes(struct ast_context *con)
    {
    
    Russell Bryant's avatar
    Russell Bryant committed
    	struct ast_include *inc = NULL;
    
    Russell Bryant's avatar
    Russell Bryant committed
    	while ( (inc = ast_walk_context_includes(con, inc)) )
    
    		if (!ast_context_find(inc->rname)) {
    			res = -1;
    
    			ast_log(LOG_WARNING, "Context '%s' tries includes nonexistent context '%s'\n",
    
    					ast_get_context_name(con), inc->rname);
    		}
    	return res;
    }
    
    static int __ast_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority, int async) 
    
    	int (*goto_func)(struct ast_channel *chan, const char *context, const char *exten, int priority);
    
    	goto_func = (async) ? ast_async_goto : ast_explicit_goto;
    	if (ast_exists_extension(chan, context ? context : chan->context,
    				 exten ? exten : chan->exten, priority,
    				 chan->cid.cid_num))
    		return goto_func(chan, context ? context : chan->context,
    				 exten ? exten : chan->exten, priority);
    	else 
    		return -3;
    
    int ast_goto_if_exists(struct ast_channel *chan, const char* context, const char *exten, int priority) {
    
    	return __ast_goto_if_exists(chan, context, exten, priority, 0);
    }
    
    
    int ast_async_goto_if_exists(struct ast_channel *chan, const char * context, const char *exten, int priority) {
    
    	return __ast_goto_if_exists(chan, context, exten, priority, 1);
    }
    
    
    int ast_parseable_goto(struct ast_channel *chan, const char *goto_string) 
    {
    	char *s;
    	char *exten, *pri, *context;
    	char *stringp=NULL;
    	int ipri;
    	int mode = 0;
    
    
    	if (ast_strlen_zero(goto_string)) {
    
    		ast_log(LOG_WARNING, "Goto requires an argument (optional context|optional extension|priority)\n");
    		return -1;
    	}
    
    	context = strsep(&stringp, "|");
    	exten = strsep(&stringp, "|");
    	if (!exten) {
    		/* Only a priority in this one */
    		pri = context;
    		exten = NULL;
    		context = NULL;
    	} else {
    		pri = strsep(&stringp, "|");
    		if (!pri) {
    			/* Only an extension and priority in this one */
    			pri = exten;
    			exten = context;
    			context = NULL;
    		}
    	}
    	if (*pri == '+') {
    		mode = 1;
    		pri++;
    	} else if (*pri == '-') {
    		mode = -1;
    		pri++;
    	}
    
    		if ((ipri = ast_findlabel_extension(chan, context ? context : chan->context, (exten && strcasecmp(exten, "BYEXTENSION")) ? exten : chan->exten, 
    			pri, chan->cid.cid_num)) < 1) {
    			ast_log(LOG_WARNING, "Priority '%s' must be a number > 0, or valid label\n", pri);
    			return -1;
    		} else
    			mode = 0;
    	} 
    	/* At this point we have a priority and maybe an extension and a context */
    
    	if (exten && !strcasecmp(exten, "BYEXTENSION"))
    		exten = NULL;
    
    	if (mode) 
    		ipri = chan->priority + (ipri * mode);
    
    
    	ast_explicit_goto(chan, context, exten, ipri);
    
    	ast_cdr_update(chan);
    	return 0;
    
    }