Wed Jan 8 2020 09:50:13

Asterisk developer's documentation


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"

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)
 
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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static 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

static void __reg_module ( void  )
static

Definition at line 150 of file func_extstate.c.

static void __unreg_module ( void  )
static

Definition at line 150 of file func_extstate.c.

static const char* ast_extstate_str ( int  state)
static

Definition at line 66 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().

67 {
68  const char *res = "UNKNOWN";
69 
70  switch (state) {
72  res = "NOT_INUSE";
73  break;
75  res = "INUSE";
76  break;
77  case AST_EXTENSION_BUSY:
78  res = "BUSY";
79  break;
81  res = "UNAVAILABLE";
82  break;
84  res = "RINGING";
85  break;
87  res = "RINGINUSE";
88  break;
90  res = "HOLDINUSE";
91  break;
93  res = "ONHOLD";
94  break;
95  }
96 
97  return res;
98 }
static int extstate_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 100 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().

102 {
103  char *exten, *context;
104 
105  if (ast_strlen_zero(data)) {
106  ast_log(LOG_WARNING, "EXTENSION_STATE requires an extension\n");
107  return -1;
108  }
109 
110  context = exten = data;
111  strsep(&context, "@");
112  if (ast_strlen_zero(context))
113  context = "default";
114 
115  if (ast_strlen_zero(exten)) {
116  ast_log(LOG_WARNING, "EXTENSION_STATE requires an extension\n");
117  return -1;
118  }
119 
120  ast_copy_string(buf,
121  ast_extstate_str(ast_extension_state(chan, context, exten)), len);
122 
123  return 0;
124 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
char * strsep(char **str, const char *delims)
#define LOG_WARNING
Definition: logger.h:144
static const char * ast_extstate_str(int state)
Definition: func_extstate.c:66
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
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
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
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:4914
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
static int load_module ( void  )
static

Definition at line 141 of file func_extstate.c.

References ast_custom_function_register, AST_MODULE_LOAD_DECLINE, and AST_MODULE_LOAD_SUCCESS.

142 {
143  int res;
144 
146 
148 }
static struct ast_custom_function extstate_function
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1164
static int unload_module ( void  )
static

Definition at line 132 of file func_extstate.c.

References ast_custom_function_unregister().

133 {
134  int res;
135 
137 
138  return res;
139 }
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Definition: pbx.c:3814
static struct ast_custom_function extstate_function

Variable Documentation

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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 150 of file func_extstate.c.

Definition at line 150 of file func_extstate.c.

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 at line 126 of file func_extstate.c.