Wed Jan 8 2020 09:49:40

Asterisk developer's documentation


app_softhangup.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.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 SoftHangup application
22  *
23  * \author Mark Spencer <markster@digium.com>
24  *
25  * \ingroup applications
26  */
27 
28 /*** MODULEINFO
29  <support_level>core</support_level>
30  ***/
31 
32 #include "asterisk.h"
33 
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
35 
36 #include "asterisk/file.h"
37 #include "asterisk/channel.h"
38 #include "asterisk/pbx.h"
39 #include "asterisk/module.h"
40 #include "asterisk/lock.h"
41 #include "asterisk/app.h"
42 
43 /*** DOCUMENTATION
44  <application name="SoftHangup" language="en_US">
45  <synopsis>
46  Hangs up the requested channel.
47  </synopsis>
48  <syntax>
49  <parameter name="Technology/Resource" required="true" />
50  <parameter name="options">
51  <optionlist>
52  <option name="a">
53  <para>Hang up all channels on a specified device instead of a single resource</para>
54  </option>
55  </optionlist>
56  </parameter>
57  </syntax>
58  <description>
59  <para>Hangs up the requested channel. If there are no channels to
60  hangup, the application will report it.</para>
61  </description>
62  </application>
63 
64  ***/
65 
66 static char *app = "SoftHangup";
67 
68 enum {
69  OPTION_ALL = (1 << 0),
70 };
71 
74 });
75 
76 static int softhangup_exec(struct ast_channel *chan, const char *data)
77 {
78  struct ast_channel *c = NULL;
79  char *cut, *opts[0];
80  char name[AST_CHANNEL_NAME] = "", *parse;
81  struct ast_flags flags = {0};
82  int lenmatch;
84  AST_APP_ARG(channel);
85  AST_APP_ARG(options);
86  );
87  struct ast_channel_iterator *iter;
88 
89  if (ast_strlen_zero(data)) {
90  ast_log(LOG_WARNING, "SoftHangup requires an argument (Technology/resource)\n");
91  return 0;
92  }
93 
94  parse = ast_strdupa(data);
96 
97  if (args.argc == 2)
98  ast_app_parse_options(app_opts, &flags, opts, args.options);
99  lenmatch = strlen(args.channel);
100 
101  if (!(iter = ast_channel_iterator_by_name_new(args.channel, lenmatch))) {
102  return -1;
103  }
104 
105  while ((c = ast_channel_iterator_next(iter))) {
106  ast_channel_lock(c);
107  ast_copy_string(name, c->name, sizeof(name));
108  if (ast_test_flag(&flags, OPTION_ALL)) {
109  /* CAPI is set up like CAPI[foo/bar]/clcnt */
110  if (!strcmp(c->tech->type, "CAPI")) {
111  cut = strrchr(name, '/');
112  /* Basically everything else is Foo/Bar-Z */
113  } else {
114  /* use strrchr() because Foo/Bar-Z could actually be Foo/B-a-r-Z */
115  cut = strrchr(name,'-');
116  }
117  /* Get rid of what we've cut */
118  if (cut)
119  *cut = 0;
120  }
121  if (!strcasecmp(name, args.channel)) {
122  ast_log(LOG_WARNING, "Soft hanging %s up.\n", c->name);
124  if (!ast_test_flag(&flags, OPTION_ALL)) {
126  c = ast_channel_unref(c);
127  break;
128  }
129  }
131  c = ast_channel_unref(c);
132  }
133 
135 
136  return 0;
137 }
138 
139 static int unload_module(void)
140 {
141  return ast_unregister_application(app);
142 }
143 
144 static int load_module(void)
145 {
147 }
148 
149 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Hangs up the requested channel");
#define ast_channel_lock(chan)
Definition: channel.h:2466
Main Channel structure associated with a channel.
Definition: channel.h:742
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
const char *const type
Definition: channel.h:508
Asterisk locking-related definitions:
struct ast_channel * ast_channel_iterator_next(struct ast_channel_iterator *i)
Get the next channel for a channel iterator.
Definition: channel.c:1715
Asterisk main include file. File version handling, generic pbx functions.
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
Definition: app.h:712
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2502
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define LOG_WARNING
Definition: logger.h:144
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: app.c:2101
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
static int softhangup_exec(struct ast_channel *chan, const char *data)
General Asterisk PBX channel definitions.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
int ast_softhangup(struct ast_channel *chan, int reason)
Softly hangup up a channel.
Definition: channel.c:2746
Core PBX routines and definitions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static int load_module(void)
static struct @350 args
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_channel_unlock(chan)
Definition: channel.h:2467
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
static const char name[]
#define AST_CHANNEL_NAME
Definition: channel.h:137
Structure used to handle boolean flags.
Definition: utils.h:200
struct ast_channel_iterator * ast_channel_iterator_by_name_new(const char *name, size_t name_len)
Create a new channel iterator based on name.
Definition: channel.c:1696
static int unload_module(void)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
struct ast_channel_iterator * ast_channel_iterator_destroy(struct ast_channel_iterator *i)
Destroy a channel iterator.
Definition: channel.c:1649
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
static char * app
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
Asterisk module definitions.
union ast_frame::@172 data
struct ast_channel_tech * tech
Definition: channel.h:743
static struct ast_app_option app_opts[128]
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
Definition: app.h:721