Skip to content
Snippets Groups Projects
pbx.c 107 KiB
Newer Older
  • Learn to ignore specific revisions
  • Mark Spencer's avatar
    Mark Spencer committed
    	}
    	
    	free(s);
    	return(ret);
    }
    
    static int pbx_builtin_gotoif(struct ast_channel *chan, void *data)
    {
    	char *condition,*branch1,*branch2,*branch;
    	char *s;
    	int rc;
    
    Mark Spencer's avatar
    Mark Spencer committed
    	char *stringp=NULL;
    
    Mark Spencer's avatar
    Mark Spencer committed
    
    	if (!data || !strlen(data)) {
    		ast_log(LOG_WARNING, "Ignoring, since there is no variable to set\n");
    		return 0;
    	}
    	
    	s=strdup(data);
    
    Mark Spencer's avatar
    Mark Spencer committed
    	stringp=s;
    	condition=strsep(&stringp,"?");
    	branch1=strsep(&stringp,":");
    	branch2=strsep(&stringp,"");
    
    Mark Spencer's avatar
    Mark Spencer committed
    	
    	if (pbx_checkcondition(condition)) {
    		branch=branch2;
    	} else {
    		branch=branch1;
    	}
    	
    	if ((branch==NULL) || (strlen(branch)==0)) {
    		ast_log(LOG_WARNING, "Not taking any branch\n");
    		return(0);
    	}
    	
    	rc=pbx_builtin_goto(chan,branch);
    	free(s);
    	return(rc);
    }           
    	
    
    Mark Spencer's avatar
    Mark Spencer committed
    int load_pbx(void)
    {
    	int x;
    	/* Initialize the PBX */
    	if (option_verbose) {
    		ast_verbose( "Asterisk PBX Core Initializing\n");
    		ast_verbose( "Registering builtin applications:\n");
    	}
    
    Mark Spencer's avatar
    Mark Spencer committed
    	ast_cli_register(&show_applications_cli);
    	ast_cli_register(&show_application_cli);
    	ast_cli_register(&show_dialplan_cli);
    	ast_cli_register(&show_switches_cli);
    
    Mark Spencer's avatar
    Mark Spencer committed
    	for (x=0;x<sizeof(builtins) / sizeof(struct pbx_builtin); x++) {
    		if (option_verbose)
    			ast_verbose( VERBOSE_PREFIX_1 "[%s]\n", builtins[x].name);
    
    Mark Spencer's avatar
    Mark Spencer committed
    		if (ast_register_application(builtins[x].name, builtins[x].execute, builtins[x].synopsis, builtins[x].description)) {
    
    Mark Spencer's avatar
    Mark Spencer committed
    			ast_log(LOG_ERROR, "Unable to register builtin application '%s'\n", builtins[x].name);
    			return -1;
    		}
    	}
    	return 0;
    }
    
    
    Mark Spencer's avatar
    Mark Spencer committed
    /*
     * Lock context list functions ...
     */
    int ast_lock_contexts()
    {
    	return ast_pthread_mutex_lock(&conlock);
    }
    
    int ast_unlock_contexts()
    {
    	return ast_pthread_mutex_unlock(&conlock);
    }
    
    /*
     * Lock context ...
     */
    int ast_lock_context(struct ast_context *con)
    {
    	return ast_pthread_mutex_lock(&con->lock);
    }
    
    int ast_unlock_context(struct ast_context *con)
    {
    	return ast_pthread_mutex_unlock(&con->lock);
    }
    
    /*
     * Name functions ...
     */
    char *ast_get_context_name(struct ast_context *con)
    {
    	return con ? con->name : NULL;
    }
    
    char *ast_get_extension_name(struct ast_exten *exten)
    {
    	return exten ? exten->exten : NULL;
    }
    
    char *ast_get_include_name(struct ast_include *inc)
    {
    	return inc ? inc->name : NULL;
    }
    
    char *ast_get_ignorepat_name(struct ast_ignorepat *ip)
    {
    	return ip ? ip->pattern : NULL;
    }
    
    int ast_get_extension_priority(struct ast_exten *exten)
    {
    	return exten ? exten->priority : -1;
    }
    
    /*
     * Registrar info functions ...
     */
    char *ast_get_context_registrar(struct ast_context *c)
    {
    	return c ? c->registrar : NULL;
    }
    
    char *ast_get_extension_registrar(struct ast_exten *e)
    {
    	return e ? e->registrar : NULL;
    }
    
    char *ast_get_include_registrar(struct ast_include *i)
    {
    	return i ? i->registrar : NULL;
    }
    
    char *ast_get_ignorepat_registrar(struct ast_ignorepat *ip)
    {
    	return ip ? ip->registrar : NULL;
    }
    
    char *ast_get_extension_app(struct ast_exten *e)
    {
    	return e ? e->app : NULL;
    }
    
    void *ast_get_extension_app_data(struct ast_exten *e)
    {
    	return e ? e->data : NULL;
    }
    
    char *ast_get_switch_name(struct ast_sw *sw)
    {
    	return sw ? sw->name : NULL;
    }
    
    char *ast_get_switch_data(struct ast_sw *sw)
    {
    	return sw ? sw->data : NULL;
    }
    
    char *ast_get_switch_registrar(struct ast_sw *sw)
    {
    	return sw ? sw->registrar : NULL;
    }
    
    /*
     * Walking functions ...
     */
    struct ast_context *ast_walk_contexts(struct ast_context *con)
    {
    	if (!con)
    		return contexts;
    	else
    		return con->next;
    }
    
    struct ast_exten *ast_walk_context_extensions(struct ast_context *con,
    	struct ast_exten *exten)
    {
    	if (!exten)
    		return con ? con->root : NULL;
    	else
    		return exten->next;
    }
    
    struct ast_sw *ast_walk_context_switches(struct ast_context *con,
    	struct ast_sw *sw)
    {
    	if (!sw)
    		return con ? con->alts : NULL;
    	else
    		return sw->next;
    }
    
    struct ast_exten *ast_walk_extension_priorities(struct ast_exten *exten,
    	struct ast_exten *priority)
    {
    	if (!priority)
    		return exten;
    	else
    		return priority->peer;
    }
    
    struct ast_include *ast_walk_context_includes(struct ast_context *con,
    	struct ast_include *inc)
    {
    	if (!inc)
    		return con ? con->includes : NULL;
    	else
    		return inc->next;
    }
    
    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;
    }