Asterisk - The Open Source Telephony Project  GIT-master-9ed6387
Enumerations | Functions | Variables
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)
 
struct ast_moduleAST_MODULE_SELF_SYM (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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static char * app = "SoftHangup"
 
static const struct ast_app_option app_opts [128] = { [ 'a' ] = { .flag = OPTION_ALL }, }
 
static const 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

anonymous enum
Enumerator
OPTION_ALL 

Definition at line 66 of file app_softhangup.c.

66  {
67  OPTION_ALL = (1 << 0),
68 };

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 147 of file app_softhangup.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 147 of file app_softhangup.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 147 of file app_softhangup.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 142 of file app_softhangup.c.

References app, ast_register_application_xml, and softhangup_exec().

143 {
145 }
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:626

◆ softhangup_exec()

static int softhangup_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 74 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_name(), ast_channel_tech(), 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, ast_verb, c, LOG_WARNING, name, NULL, OPTION_ALL, options, parse(), and type.

Referenced by load_module().

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;
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 }
static const char type[]
Definition: chan_ooh323.c:109
#define ast_channel_lock(chan)
Definition: channel.h:2837
Main Channel structure associated with a channel.
struct ast_channel * ast_channel_iterator_next(struct ast_channel_iterator *i)
Get the next channel for a channel iterator.
Definition: channel.c:1407
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2873
#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
unsigned int flags
Definition: utils.h:200
static struct test_val c
Definition: muted.c:95
const char * args
#define NULL
Definition: resample.c:96
#define ast_verb(level,...)
Definition: logger.h:455
#define ast_log
Definition: astobj2.c:42
int ast_softhangup(struct ast_channel *chan, int reason)
Softly hangup up a channel.
Definition: channel.c:2451
#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:2829
static const struct ast_app_option app_opts[128]
#define ast_strlen_zero(a)
Definition: muted.c:73
#define ast_channel_unlock(chan)
Definition: channel.h:2838
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1872
static const char name[]
Definition: cdr_mysql.c:74
#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:1373
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:1345
static struct test_options options
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)
#define AST_APP_ARG(name)
Define an application argument.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 137 of file app_softhangup.c.

References app, and ast_unregister_application().

138 {
140 }
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
static char * app

Variable Documentation

◆ __mod_info

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 = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 147 of file app_softhangup.c.

◆ app

char* app = "SoftHangup"
static

Definition at line 64 of file app_softhangup.c.

Referenced by load_module(), and unload_module().

◆ app_opts

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

Definition at line 72 of file app_softhangup.c.

Referenced by softhangup_exec().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 147 of file app_softhangup.c.