Asterisk - The Open Source Telephony Project GIT-master-f36a736
Data Structures | Functions | Variables
pbx_switch.c File Reference

PBX switch routines. More...

#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/cli.h"
#include "asterisk/linkedlists.h"
#include "asterisk/pbx.h"
#include "pbx_private.h"
Include dependency graph for pbx_switch.c:

Go to the source code of this file.

Data Structures

struct  switches
 

Functions

int ast_register_switch (struct ast_switch *sw)
 Register an alternative dialplan switch. More...
 
void ast_unregister_switch (struct ast_switch *sw)
 Unregister an alternative switch. More...
 
static char * handle_show_switches (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 handle_show_switches: CLI support for listing registered dial plan switches More...
 
int load_pbx_switch (void)
 
struct ast_switchpbx_findswitch (const char *sw)
 
static void unload_pbx_switch (void)
 

Variables

static struct ast_cli_entry sw_cli []
 
static struct switches switches = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 

Detailed Description

PBX switch routines.

Author
Corey Farrell git@c.nosp@m.fwar.nosp@m.e.com

Definition in file pbx_switch.c.

Function Documentation

◆ ast_register_switch()

int ast_register_switch ( struct ast_switch sw)

Register an alternative dialplan switch.

Parameters
swswitch to register

This function registers a populated ast_switch structure with the asterisk switching architecture.

Return values
0success
non-zerofailure

Definition at line 58 of file pbx_switch.c.

59{
60 struct ast_switch *tmp;
61
64 if (!strcasecmp(tmp->name, sw->name)) {
66 ast_log(LOG_WARNING, "Switch '%s' already found\n", sw->name);
67 return -1;
68 }
69 }
72
73 return 0;
74}
#define ast_log
Definition: astobj2.c:42
static int tmp()
Definition: bt_open.c:389
#define LOG_WARNING
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:494
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:741
struct ast_switch::@241 list
const char * name
Definition: pbx.h:162

References ast_log, AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_switch::list, LOG_WARNING, ast_switch::name, and tmp().

Referenced by load_module().

◆ ast_unregister_switch()

void ast_unregister_switch ( struct ast_switch sw)

Unregister an alternative switch.

Parameters
swswitch to unregister

Unregisters a switch from asterisk.

Definition at line 76 of file pbx_switch.c.

77{
79 AST_RWLIST_REMOVE(&switches, sw, list);
81}
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:885

References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and ast_switch::list.

Referenced by __unload_module(), and unload_module().

◆ handle_show_switches()

static char * handle_show_switches ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

handle_show_switches: CLI support for listing registered dial plan switches

Definition at line 84 of file pbx_switch.c.

85{
86 struct ast_switch *sw;
87
88 switch (cmd) {
89 case CLI_INIT:
90 e->command = "core show switches";
91 e->usage =
92 "Usage: core show switches\n"
93 " List registered switches\n";
94 return NULL;
95 case CLI_GENERATE:
96 return NULL;
97 }
98
100
103 ast_cli(a->fd, "There are no registered alternative switches\n");
104 return CLI_SUCCESS;
105 }
106
107 ast_cli(a->fd, "\n -= Registered Asterisk Alternative Switches =-\n");
109 ast_cli(a->fd, "%s: %s\n", sw->name, sw->description);
110
112
113 return CLI_SUCCESS;
114}
#define CLI_SUCCESS
Definition: cli.h:44
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
@ CLI_INIT
Definition: cli.h:152
@ CLI_GENERATE
Definition: cli.h:153
#define AST_RWLIST_EMPTY
Definition: linkedlists.h:452
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:78
#define NULL
Definition: resample.c:96
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
const char * description
Definition: pbx.h:163
static struct test_val a

References a, ast_cli(), AST_RWLIST_EMPTY, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_switch::description, ast_switch::list, ast_switch::name, NULL, and ast_cli_entry::usage.

◆ load_pbx_switch()

int load_pbx_switch ( void  )

Provided by pbx_switch.c

Definition at line 125 of file pbx_switch.c.

126{
129
130 return 0;
131}
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
static void unload_pbx_switch(void)
Definition: pbx_switch.c:120
static struct ast_cli_entry sw_cli[]
Definition: pbx_switch.c:116
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, ast_cli_register_multiple, ast_register_cleanup(), sw_cli, and unload_pbx_switch().

Referenced by asterisk_daemon().

◆ pbx_findswitch()

struct ast_switch * pbx_findswitch ( const char *  sw)

pbx_switch.c functions needed by pbx.c

Definition at line 40 of file pbx_switch.c.

41{
42 struct ast_switch *asw;
43
46 if (!strcasecmp(asw->name, sw))
47 break;
48 }
50
51 return asw;
52}

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_switch::list, and ast_switch::name.

Referenced by pbx_find_extension().

◆ unload_pbx_switch()

static void unload_pbx_switch ( void  )
static

Definition at line 120 of file pbx_switch.c.

121{
123}
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30

References ARRAY_LEN, ast_cli_unregister_multiple(), and sw_cli.

Referenced by load_pbx_switch().

Variable Documentation

◆ sw_cli

struct ast_cli_entry sw_cli[]
static
Initial value:
= {
{ .handler = handle_show_switches , .summary = "Show alternative switches" ,},
}
static char * handle_show_switches(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
handle_show_switches: CLI support for listing registered dial plan switches
Definition: pbx_switch.c:84

Definition at line 116 of file pbx_switch.c.

Referenced by load_pbx_switch(), and unload_pbx_switch().

◆ switches

struct switches switches = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
static