Asterisk - The Open Source Telephony Project  GIT-master-a1fa8df
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 #include "asterisk/file.h"
35 #include "asterisk/channel.h"
36 #include "asterisk/pbx.h"
37 #include "asterisk/module.h"
38 #include "asterisk/lock.h"
39 #include "asterisk/app.h"
40 
41 /*** DOCUMENTATION
42  <application name="SoftHangup" language="en_US">
43  <synopsis>
44  Hangs up the requested channel.
45  </synopsis>
46  <syntax>
47  <parameter name="Technology/Resource" required="true" />
48  <parameter name="options">
49  <optionlist>
50  <option name="a">
51  <para>Hang up all channels on a specified device instead of a single resource</para>
52  </option>
53  </optionlist>
54  </parameter>
55  </syntax>
56  <description>
57  <para>Hangs up the requested channel. If there are no channels to
58  hangup, the application will report it.</para>
59  </description>
60  </application>
61 
62  ***/
63 
64 static char *app = "SoftHangup";
65 
66 enum {
67  OPTION_ALL = (1 << 0),
68 };
69 
72 });
73 
74 static int softhangup_exec(struct ast_channel *chan, const char *data)
75 {
76  struct ast_channel *c = NULL;
77  char *cut, *opts[0];
78  char name[AST_CHANNEL_NAME] = "", *parse;
79  struct ast_flags flags = {0};
80  int lenmatch;
82  AST_APP_ARG(channel);
84  );
85  struct ast_channel_iterator *iter;
86 
87  if (ast_strlen_zero(data)) {
88  ast_log(LOG_WARNING, "SoftHangup requires an argument (Technology/resource)\n");
89  return 0;
90  }
91 
92  parse = ast_strdupa(data);
94 
95  if (args.argc == 2)
96  ast_app_parse_options(app_opts, &flags, opts, args.options);
97  lenmatch = strlen(args.channel);
98 
99  if (!(iter = ast_channel_iterator_by_name_new(args.channel, lenmatch))) {
100  return -1;
101  }
102 
103  while ((c = ast_channel_iterator_next(iter))) {
104  ast_channel_lock(c);
105  ast_copy_string(name, ast_channel_name(c), sizeof(name));
106  if (ast_test_flag(&flags, OPTION_ALL)) {
107  /* CAPI is set up like CAPI[foo/bar]/clcnt */
108  if (!strcmp(ast_channel_tech(c)->type, "CAPI")) {
109  cut = strrchr(name, '/');
110  /* Basically everything else is Foo/Bar-Z */
111  } else {
112  /* use strrchr() because Foo/Bar-Z could actually be Foo/B-a-r-Z */
113  cut = strrchr(name,'-');
114  }
115  /* Get rid of what we've cut */
116  if (cut)
117  *cut = 0;
118  }
119  if (!strcasecmp(name, args.channel)) {
120  ast_verb(4, "Soft hanging %s up.\n", ast_channel_name(c));
122  if (!ast_test_flag(&flags, OPTION_ALL)) {
124  c = ast_channel_unref(c);
125  break;
126  }
127  }
129  c = ast_channel_unref(c);
130  }
131 
133 
134  return 0;
135 }
136 
137 static int unload_module(void)
138 {
140 }
141 
142 static int load_module(void)
143 {
145 }
146 
147 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Hangs up the requested channel");
static const char type[]
Definition: chan_ooh323.c:109
#define ast_channel_lock(chan)
Definition: channel.h:2913
Main Channel structure associated with a channel.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:567
static const char name[]
Definition: format_mp3.c:68
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:1418
Asterisk main include file. File version handling, generic pbx functions.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2949
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
#define LOG_WARNING
Definition: logger.h:274
static struct test_val c
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
const char * args
#define NULL
Definition: resample.c:96
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
#define ast_verb(level,...)
Definition: logger.h:455
static int softhangup_exec(struct ast_channel *chan, const char *data)
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
#define ast_log
Definition: astobj2.c:42
General Asterisk PBX channel definitions.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
int ast_softhangup(struct ast_channel *chan, int reason)
Softly hangup up a channel.
Definition: channel.c:2472
union ast_frame::@250 data
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
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: main/app.c:2846
Core PBX routines and definitions.
static const struct ast_app_option app_opts[128]
static int load_module(void)
#define ast_channel_unlock(chan)
Definition: channel.h:2914
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1844
#define AST_CHANNEL_NAME
Definition: channel.h:172
Structure used to handle boolean flags.
Definition: utils.h:199
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:1384
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:401
const char * ast_channel_name(const struct ast_channel *chan)
struct ast_channel_iterator * ast_channel_iterator_destroy(struct ast_channel_iterator *i)
Destroy a channel iterator.
Definition: channel.c:1356
static char * app
static struct test_options options
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Asterisk module definitions.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626
#define AST_APP_ARG(name)
Define an application argument.