Asterisk - The Open Source Telephony Project  18.5.0
Functions | Variables
func_extstate.c File Reference

Get the state of a hinted extension for dialplan control. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/devicestate.h"
Include dependency graph for func_extstate.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static const char * ast_extstate_str (int state)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int extstate_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Gets an extension's state in the dialplan" , .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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_custom_function extstate_function
 

Detailed Description

Get the state of a hinted extension for dialplan control.

Author
Adam Gundy adam@.nosp@m.star.nosp@m.silk..nosp@m.net

Definition in file func_extstate.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 148 of file func_extstate.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 148 of file func_extstate.c.

◆ ast_extstate_str()

static const char* ast_extstate_str ( int  state)
static

Definition at line 64 of file func_extstate.c.

References AST_EXTENSION_BUSY, AST_EXTENSION_INUSE, AST_EXTENSION_NOT_INUSE, AST_EXTENSION_ONHOLD, AST_EXTENSION_RINGING, and AST_EXTENSION_UNAVAILABLE.

Referenced by extstate_read().

65 {
66  const char *res = "UNKNOWN";
67 
68  switch (state) {
70  res = "NOT_INUSE";
71  break;
73  res = "INUSE";
74  break;
75  case AST_EXTENSION_BUSY:
76  res = "BUSY";
77  break;
79  res = "UNAVAILABLE";
80  break;
82  res = "RINGING";
83  break;
85  res = "RINGINUSE";
86  break;
88  res = "HOLDINUSE";
89  break;
91  res = "ONHOLD";
92  break;
93  }
94 
95  return res;
96 }

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 148 of file func_extstate.c.

◆ extstate_read()

static int extstate_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 98 of file func_extstate.c.

References ast_copy_string(), ast_extension_state(), ast_extstate_str(), ast_log, ast_strlen_zero, context, exten, LOG_WARNING, and strsep().

100 {
101  char *exten, *context;
102 
103  if (ast_strlen_zero(data)) {
104  ast_log(LOG_WARNING, "EXTENSION_STATE requires an extension\n");
105  return -1;
106  }
107 
108  context = exten = data;
109  strsep(&context, "@");
110  if (ast_strlen_zero(context))
111  context = "default";
112 
113  if (ast_strlen_zero(exten)) {
114  ast_log(LOG_WARNING, "EXTENSION_STATE requires an extension\n");
115  return -1;
116  }
117 
119  ast_extstate_str(ast_extension_state(chan, context, exten)), len);
120 
121  return 0;
122 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define LOG_WARNING
Definition: logger.h:274
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
static const char * ast_extstate_str(int state)
Definition: func_extstate.c:64
const char * data
Definition: extconf.h:241
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char * strsep(char **str, const char *delims)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
int ast_extension_state(struct ast_channel *c, const char *context, const char *exten)
Uses hint and devicestate callback to get the state of an extension.
Definition: pbx.c:3170
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

◆ load_module()

static int load_module ( void  )
static

Definition at line 139 of file func_extstate.c.

References ast_custom_function_register, AST_MODULE_LOAD_DECLINE, and AST_MODULE_LOAD_SUCCESS.

140 {
141  int res;
142 
144 
146 }
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static struct ast_custom_function extstate_function
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1508

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 130 of file func_extstate.c.

References ast_custom_function_unregister().

131 {
132  int res;
133 
135 
136  return res;
137 }
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
static struct ast_custom_function extstate_function

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Gets an extension's state in the dialplan" , .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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 148 of file func_extstate.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 148 of file func_extstate.c.

◆ extstate_function

struct ast_custom_function extstate_function
static
Initial value:
= {
.name = "EXTENSION_STATE",
.read = extstate_read,
.read_max = 12,
}
static int extstate_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_extstate.c:98

Definition at line 124 of file func_extstate.c.