Asterisk - The Open Source Telephony Project  18.5.0
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.

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().

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_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define LOG_WARNING
Definition: logger.h:274
static int tmp()
Definition: bt_open.c:389
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
const char * name
Definition: pbx.h:162
#define ast_log
Definition: astobj2.c:42
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:740
struct ast_switch::@278 list

◆ ast_unregister_switch()

void ast_unregister_switch ( struct ast_switch sw)

Unregister an alternative switch.

Parameters
swswitch to unregister

Unregisters a switch from asterisk.

Returns
nothing

Definition at line 76 of file pbx_switch.c.

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

Referenced by __unload_module(), and unload_module().

77 {
81 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:884
struct ast_switch::@278 list

◆ 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.

References 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_cli_args::fd, ast_switch::list, ast_switch::name, NULL, and ast_cli_entry::usage.

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 
101  if (AST_RWLIST_EMPTY(&switches)) {
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 AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
Definition: cli.h:152
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
const char * name
Definition: pbx.h:162
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
const int fd
Definition: cli.h:159
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
#define AST_RWLIST_EMPTY
Definition: linkedlists.h:451
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
struct ast_switch::@278 list
const char * description
Definition: pbx.h:163

◆ load_pbx_switch()

int load_pbx_switch ( void  )

Provided by pbx_switch.c

Definition at line 125 of file pbx_switch.c.

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

Referenced by asterisk_daemon().

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

◆ 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.

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

Referenced by ast_check_timing(), and pbx_find_extension().

41 {
42  struct ast_switch *asw;
43 
46  if (!strcasecmp(asw->name, sw))
47  break;
48  }
50 
51  return asw;
52 }
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
const char * name
Definition: pbx.h:162
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
struct ast_switch::@278 list

◆ unload_pbx_switch()

static void unload_pbx_switch ( void  )
static

Definition at line 120 of file pbx_switch.c.

References ARRAY_LEN, and ast_cli_unregister_multiple().

Referenced by load_pbx_switch().

121 {
123 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
static struct ast_cli_entry sw_cli[]
Definition: pbx_switch.c:116

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.

◆ switches

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