Wed Jan 8 2020 09:49:55

Asterisk developer's documentation


app_softhangup.c File Reference

SoftHangup application. More...

#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/app.h"

Go to the source code of this file.

Enumerations

enum  { OPTION_ALL = (1 << 0) }
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static int load_module (void)
 
static int softhangup_exec (struct ast_channel *chan, const char *data)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Hangs up the requested channel" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static char * app = "SoftHangup"
 
static struct ast_app_option app_opts [128] = { [ 'a' ] = { .flag = OPTION_ALL }, }
 
static struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

SoftHangup application.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file app_softhangup.c.

Enumeration Type Documentation

anonymous enum
Enumerator
OPTION_ALL 

Definition at line 68 of file app_softhangup.c.

68  {
69  OPTION_ALL = (1 << 0),
70 };

Function Documentation

static void __reg_module ( void  )
static

Definition at line 149 of file app_softhangup.c.

static void __unreg_module ( void  )
static

Definition at line 149 of file app_softhangup.c.

static int load_module ( void  )
static

Definition at line 144 of file app_softhangup.c.

References ast_register_application_xml, and softhangup_exec().

145 {
147 }
static int softhangup_exec(struct ast_channel *chan, const char *data)
static char * app
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
static int softhangup_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 76 of file app_softhangup.c.

References app_opts, args, AST_APP_ARG, ast_app_parse_options(), ast_channel_iterator_by_name_new(), ast_channel_iterator_destroy(), ast_channel_iterator_next(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_unlock, ast_channel_unref, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_log(), ast_softhangup(), AST_SOFTHANGUP_EXPLICIT, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_test_flag, LOG_WARNING, name, ast_channel::name, OPTION_ALL, parse(), ast_channel::tech, and ast_channel_tech::type.

Referenced by load_module().

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 }
#define ast_channel_lock(chan)
Definition: channel.h:2466
Main Channel structure associated with a channel.
Definition: channel.h:742
const char *const type
Definition: channel.h:508
struct ast_channel * ast_channel_iterator_next(struct ast_channel_iterator *i)
Get the next channel for a channel iterator.
Definition: channel.c:1715
#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
unsigned int flags
Definition: utils.h:201
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
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
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
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
#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
struct ast_channel_tech * tech
Definition: channel.h:743
static struct ast_app_option app_opts[128]
static int unload_module ( void  )
static

Definition at line 139 of file app_softhangup.c.

References ast_unregister_application().

140 {
142 }
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
static char * app

Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Hangs up the requested channel" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 149 of file app_softhangup.c.

char* app = "SoftHangup"
static

Definition at line 66 of file app_softhangup.c.

struct ast_app_option app_opts[128] = { [ 'a' ] = { .flag = OPTION_ALL }, }
static

Definition at line 74 of file app_softhangup.c.

Referenced by softhangup_exec().

Definition at line 149 of file app_softhangup.c.