Asterisk - The Open Source Telephony Project  18.5.0
pbx_switch.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2016, CFWare, LLC
5  *
6  * Corey Farrell <[email protected]>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  *
21  * \brief PBX switch routines.
22  *
23  * \author Corey Farrell <[email protected]>
24  */
25 
26 /*** MODULEINFO
27  <support_level>core</support_level>
28  ***/
29 
30 #include "asterisk.h"
31 
32 #include "asterisk/_private.h"
33 #include "asterisk/cli.h"
34 #include "asterisk/linkedlists.h"
35 #include "asterisk/pbx.h"
36 #include "pbx_private.h"
37 
39 
40 struct ast_switch *pbx_findswitch(const char *sw)
41 {
42  struct ast_switch *asw;
43 
46  if (!strcasecmp(asw->name, sw))
47  break;
48  }
50 
51  return asw;
52 }
53 
54 /*
55  * Append to the list. We don't have a tail pointer because we need
56  * to scan the list anyways to check for duplicates during insertion.
57  */
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 }
75 
77 {
81 }
82 
83 /*! \brief handle_show_switches: CLI support for listing registered dial plan switches */
84 static char *handle_show_switches(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
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 }
115 
116 static struct ast_cli_entry sw_cli[] = {
117  AST_CLI_DEFINE(handle_show_switches, "Show alternative switches"),
118 };
119 
120 static void unload_pbx_switch(void)
121 {
122  ast_cli_unregister_multiple(sw_cli, ARRAY_LEN(sw_cli));
123 }
124 
126 {
127  ast_cli_register_multiple(sw_cli, ARRAY_LEN(sw_cli));
129 
130  return 0;
131 }
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
#define AST_CLI_DEFINE(fn, txt,...)
Definition: cli.h:197
Asterisk main include file. File version handling, generic pbx functions.
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
Private include file for pbx.
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized...
Definition: linkedlists.h:332
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
descriptor for a cli entry.
Definition: cli.h:171
#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
Definition: cli.h:152
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
int ast_register_switch(struct ast_switch *sw)
Register an alternative dialplan switch.
Definition: pbx_switch.c:58
const char * name
Definition: pbx.h:162
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
#define ast_log
Definition: astobj2.c:42
void ast_unregister_switch(struct ast_switch *sw)
Unregister an alternative switch.
Definition: pbx_switch.c:76
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
const int fd
Definition: cli.h:159
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
static struct ast_cli_entry sw_cli[]
Definition: pbx_switch.c:116
A set of macros to manage forward-linked lists.
Core PBX routines and definitions.
#define AST_RWLIST_EMPTY
Definition: linkedlists.h:451
char * command
Definition: cli.h:186
Prototypes for public functions only of internal interest,.
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:740
Standard Command Line Interface.
struct ast_switch * pbx_findswitch(const char *sw)
Definition: pbx_switch.c:40
int load_pbx_switch(void)
Definition: pbx_switch.c:125
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:884
struct ast_switch::@278 list
static void unload_pbx_switch(void)
Definition: pbx_switch.c:120
const char * description
Definition: pbx.h:163
static struct test_val a