Asterisk - The Open Source Telephony Project GIT-master-a358458
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 <git@cfware.com>
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 <git@cfware.com>
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"
35#include "asterisk/pbx.h"
36#include "pbx_private.h"
37
39
40struct 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 */
84static 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
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
116static struct ast_cli_entry sw_cli[] = {
117 AST_CLI_DEFINE(handle_show_switches, "Show alternative switches"),
118};
119
120static void unload_pbx_switch(void)
121{
123}
124
126{
129
130 return 0;
131}
Prototypes for public functions only of internal interest,.
Asterisk main include file. File version handling, generic pbx functions.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
#define ast_log
Definition: astobj2.c:42
static int tmp()
Definition: bt_open.c:389
Standard Command Line Interface.
#define CLI_SUCCESS
Definition: cli.h:44
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
#define AST_CLI_DEFINE(fn, txt,...)
Definition: cli.h:197
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_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
#define LOG_WARNING
A set of macros to manage forward-linked lists.
#define AST_RWLIST_EMPTY
Definition: linkedlists.h:452
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:78
#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_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized.
Definition: linkedlists.h:333
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:885
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:494
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:741
Core PBX routines and definitions.
Private include file for pbx.
static void unload_pbx_switch(void)
Definition: pbx_switch.c:120
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
static struct ast_cli_entry sw_cli[]
Definition: pbx_switch.c:116
struct ast_switch * pbx_findswitch(const char *sw)
Definition: pbx_switch.c:40
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 load_pbx_switch(void)
Definition: pbx_switch.c:125
#define NULL
Definition: resample.c:96
descriptor for a cli entry.
Definition: cli.h:171
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
struct ast_switch::@241 list
const char * description
Definition: pbx.h:163
const char * name
Definition: pbx.h:162
static struct test_val a
#define ARRAY_LEN(a)
Definition: utils.h:666