Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
Macros | Functions | Variables
pbx_loopback.c File Reference

Loopback PBX Module. More...

#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/frame.h"
#include "asterisk/cli.h"
#include "asterisk/lock.h"
#include "asterisk/md5.h"
#include "asterisk/linkedlists.h"
#include "asterisk/chanvars.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
#include "asterisk/utils.h"
#include "asterisk/astdb.h"
Include dependency graph for pbx_loopback.c:

Go to the source code of this file.

Macros

#define LOOPBACK_COMMON
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static int loopback_canmatch (struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
 
static int loopback_exec (struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
 
static int loopback_exists (struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
 
static int loopback_matchmore (struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
 
static void loopback_parse (char **newexten, char **newcontext, int *priority, char **newpattern, char *buf)
 
static char * loopback_subst (char *buf, int buflen, const char *exten, const char *context, int priority, const char *data)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Loopback Switch" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_switch loopback_switch
 

Detailed Description

Loopback PBX Module.

Definition in file pbx_loopback.c.

Macro Definition Documentation

◆ LOOPBACK_COMMON

#define LOOPBACK_COMMON

Definition at line 73 of file pbx_loopback.c.

84{
85 struct ast_var_t *newvariable;
86 struct varshead headp;
87 char tmp[80];
88
89 snprintf(tmp, sizeof(tmp), "%d", priority);
91 if ((newvariable = ast_var_assign("EXTEN", exten))) {
92 AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
93 }
94 if ((newvariable = ast_var_assign("CONTEXT", context))) {
95 AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
96 }
97 if ((newvariable = ast_var_assign("PRIORITY", tmp))) {
98 AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
99 }
100 /* Substitute variables */
101 pbx_substitute_variables_varshead(&headp, data, buf, buflen);
102 /* free the list */
103 while ((newvariable = AST_LIST_REMOVE_HEAD(&headp, entries)))
104 ast_var_delete(newvariable);
105 return buf;
106}
107
108static void loopback_parse(char **newexten, char **newcontext, int *priority, char **newpattern, char *buf)
109{
110 char *con;
111 char *pri;
112 *newpattern = strchr(buf, '/');
113 if (*newpattern)
114 *(*newpattern)++ = '\0';
115 con = strchr(buf, '@');
116 if (con) {
117 *con++ = '\0';
118 pri = strchr(con, ':');
119 } else
120 pri = strchr(buf, ':');
121 if (!ast_strlen_zero(buf))
122 *newexten = buf;
123 if (!ast_strlen_zero(con))
124 *newcontext = con;
125 if (!ast_strlen_zero(pri))
126 sscanf(pri, "%30d", priority);
127}
128
129static int loopback_exists(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
130{
132 if (newpattern && !ast_extension_match(newpattern, exten))
133 res = 0;
134 else
135 res = ast_exists_extension(chan, newcontext, newexten, newpriority, callerid);
136 return res;
137}
138
139static int loopback_canmatch(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
140{
142 if (newpattern && !ast_extension_match(newpattern, exten))
143 res = 0;
144 else
145 res = ast_canmatch_extension(chan, newcontext, newexten, newpriority, callerid);
146 return res;
147}
148
149static int loopback_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
150{
151 int found;
153 res = ast_spawn_extension(chan, newcontext, newexten, newpriority, callerid, &found, 0);
154 return res;
155}
156
157static int loopback_matchmore(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
158{
160 if (newpattern && !ast_extension_match(newpattern, exten))
161 res = 0;
162 else
163 res = ast_matchmore_extension(chan, newcontext, newexten, newpriority, callerid);
164 return res;
165}
166
167static struct ast_switch loopback_switch =
168{
169 .name = "Loopback",
170 .description = "Loopback Dialplan Switch",
171 .exists = loopback_exists,
172 .canmatch = loopback_canmatch,
173 .exec = loopback_exec,
174 .matchmore = loopback_matchmore,
175};
176
177static int unload_module(void)
178{
180 return 0;
181}
182
183static int load_module(void)
184{
188}
189
static int priority
#define ast_var_assign(name, value)
Definition chanvars.h:40
void ast_var_delete(struct ast_var_t *var)
Definition extconf.c:2469
char buf[BUFSIZE]
Definition eagi_proxy.c:66
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition module.h:581
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition module.h:46
@ AST_MODULE_LOAD_FAILURE
Module could not be loaded properly.
Definition module.h:102
@ AST_MODULE_LOAD_SUCCESS
Definition module.h:70
void pbx_substitute_variables_varshead(struct varshead *headp, const char *cp1, char *cp2, int count)
void ast_unregister_switch(struct ast_switch *sw)
Unregister an alternative switch.
Definition pbx_switch.c:76
int ast_register_switch(struct ast_switch *sw)
Register an alternative dialplan switch.
Definition pbx_switch.c:58
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition pbx.c:4196
int ast_canmatch_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Looks for a valid matching extension.
Definition pbx.c:4211
int ast_spawn_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid, int *found, int combined_find_spawn)
Launch a new extension (i.e. new stack)
Definition pbx.c:4221
int ast_extension_match(const char *pattern, const char *extension)
Determine if a given extension matches a given pattern (in NXX format)
Definition extconf.c:4293
int ast_matchmore_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Looks to see if adding anything to this extension might match something. (exists ^ canmatch)
Definition pbx.c:4216
static void loopback_parse(char **newexten, char **newcontext, int *priority, char **newpattern, char *buf)
static int loopback_exists(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
static struct ast_switch loopback_switch
static int loopback_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
#define LOOPBACK_COMMON
static int loopback_matchmore(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
static int load_module(void)
static int unload_module(void)
static int loopback_canmatch(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
Main Channel structure associated with a channel.
const char * name
Definition pbx.h:163

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 191 of file pbx_loopback.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 191 of file pbx_loopback.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 191 of file pbx_loopback.c.

◆ load_module()

static int load_module ( void  )
static

◆ loopback_canmatch()

static int loopback_canmatch ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority,
const char *  callerid,
const char *  data 
)
static

Definition at line 140 of file pbx_loopback.c.

141{
143 if (newpattern && !ast_extension_match(newpattern, exten))
144 res = 0;
145 else
146 res = ast_canmatch_extension(chan, newcontext, newexten, newpriority, callerid);
147 return res;
148}

References ast_canmatch_extension(), ast_extension_match(), and LOOPBACK_COMMON.

◆ loopback_exec()

static int loopback_exec ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority,
const char *  callerid,
const char *  data 
)
static

Definition at line 150 of file pbx_loopback.c.

151{
152 int found;
154 res = ast_spawn_extension(chan, newcontext, newexten, newpriority, callerid, &found, 0);
155 return res;
156}

References ast_spawn_extension(), and LOOPBACK_COMMON.

◆ loopback_exists()

static int loopback_exists ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority,
const char *  callerid,
const char *  data 
)
static

Definition at line 130 of file pbx_loopback.c.

131{
133 if (newpattern && !ast_extension_match(newpattern, exten))
134 res = 0;
135 else
136 res = ast_exists_extension(chan, newcontext, newexten, newpriority, callerid);
137 return res;
138}

References ast_exists_extension(), ast_extension_match(), and LOOPBACK_COMMON.

◆ loopback_matchmore()

static int loopback_matchmore ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority,
const char *  callerid,
const char *  data 
)
static

Definition at line 158 of file pbx_loopback.c.

159{
161 if (newpattern && !ast_extension_match(newpattern, exten))
162 res = 0;
163 else
164 res = ast_matchmore_extension(chan, newcontext, newexten, newpriority, callerid);
165 return res;
166}

References ast_extension_match(), ast_matchmore_extension(), and LOOPBACK_COMMON.

◆ loopback_parse()

static void loopback_parse ( char **  newexten,
char **  newcontext,
int *  priority,
char **  newpattern,
char *  buf 
)
static

Definition at line 109 of file pbx_loopback.c.

110{
111 char *con;
112 char *pri;
113 *newpattern = strchr(buf, '/');
114 if (*newpattern)
115 *(*newpattern)++ = '\0';
116 con = strchr(buf, '@');
117 if (con) {
118 *con++ = '\0';
119 pri = strchr(con, ':');
120 } else
121 pri = strchr(buf, ':');
122 if (!ast_strlen_zero(buf))
123 *newexten = buf;
124 if (!ast_strlen_zero(con))
125 *newcontext = con;
126 if (!ast_strlen_zero(pri))
127 sscanf(pri, "%30d", priority);
128}

References ast_strlen_zero(), buf, and priority.

◆ loopback_subst()

static char * loopback_subst ( char *  buf,
int  buflen,
const char *  exten,
const char *  context,
int  priority,
const char *  data 
)
static

Definition at line 84 of file pbx_loopback.c.

85{
86 struct ast_var_t *newvariable;
87 struct varshead headp;
88 char tmp[80];
89
90 snprintf(tmp, sizeof(tmp), "%d", priority);
92 if ((newvariable = ast_var_assign("EXTEN", exten))) {
93 AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
94 }
95 if ((newvariable = ast_var_assign("CONTEXT", context))) {
96 AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
97 }
98 if ((newvariable = ast_var_assign("PRIORITY", tmp))) {
99 AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
100 }
101 /* Substitute variables */
102 pbx_substitute_variables_varshead(&headp, data, buf, buflen);
103 /* free the list */
104 while ((newvariable = AST_LIST_REMOVE_HEAD(&headp, entries)))
105 ast_var_delete(newvariable);
106 return buf;
107}

References AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_HEAD, AST_LIST_REMOVE_HEAD, ast_var_assign, ast_var_delete(), buf, pbx_substitute_variables_varshead(), and priority.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 178 of file pbx_loopback.c.

179{
181 return 0;
182}

References ast_unregister_switch(), and loopback_switch.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Loopback Switch" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 191 of file pbx_loopback.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 191 of file pbx_loopback.c.

◆ loopback_switch

struct ast_switch loopback_switch
static

Definition at line 168 of file pbx_loopback.c.

169{
170 .name = "Loopback",
171 .description = "Loopback Dialplan Switch",
172 .exists = loopback_exists,
173 .canmatch = loopback_canmatch,
174 .exec = loopback_exec,
175 .matchmore = loopback_matchmore,
176};

Referenced by load_module(), and unload_module().