Asterisk - The Open Source Telephony Project GIT-master-6144b6b
Loading...
Searching...
No Matches
Macros | Functions | Variables
extension_state_autohints.c File Reference
#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/pbx.h"
#include "asterisk/stasis.h"
#include "asterisk/vector.h"
#include "pbx_private.h"
Include dependency graph for extension_state_autohints.c:

Go to the source code of this file.

Macros

#define AUTOHINT_CMP_CONTEXT_NAME(elem, name)   (!strcmp(ast_get_context_name(elem), name))
 

Functions

int ast_extension_state_autohints_init (void)
 
static void extension_state_autohints_cleanup (void)
 
static void extension_state_autohints_device_state_cb (void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
 
void pbx_extension_state_autohint_remove (struct ast_context *context, unsigned int forced)
 
void pbx_extension_state_autohint_set (struct ast_context *context)
 

Variables

static struct stasis_subscriptionautohints_subscription
 Subscription to receive updates so we can create hints as needed on autohint enabled contexts.
 
struct { 
 
   size_t   current 
 
   struct ast_context **   elems 
 
   size_t   max 
 
extension_state_autohints 
 Contexts which have autohints enabled.
 
static ast_mutex_t extension_state_autohints_lock = AST_MUTEX_INIT_VALUE
 Lock to protect the autohints vector.
 
static const char registrar [] = "autohints"
 The static registrar for the added dialplan hints.
 

Macro Definition Documentation

◆ AUTOHINT_CMP_CONTEXT_NAME

#define AUTOHINT_CMP_CONTEXT_NAME (   elem,
  name 
)    (!strcmp(ast_get_context_name(elem), name))

Definition at line 111 of file extension_state_autohints.c.

Function Documentation

◆ ast_extension_state_autohints_init()

int ast_extension_state_autohints_init ( void  )

Provided by extension_state_autohints.c

Definition at line 174 of file extension_state_autohints.c.

175{
176 /* Most likely there will be at most one context configured for autohints, or zero */
178 return -1;
179 }
180
182 return 0;
183}
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition clicompat.c:19
static struct @376 extension_state_autohints
Contexts which have autohints enabled.
static void extension_state_autohints_cleanup(void)
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition vector.h:124

References ast_register_cleanup(), AST_VECTOR_INIT, extension_state_autohints, and extension_state_autohints_cleanup().

Referenced by asterisk_daemon().

◆ extension_state_autohints_cleanup()

static void extension_state_autohints_cleanup ( void  )
static

Definition at line 163 of file extension_state_autohints.c.

164{
168 }
169 /* The vector just contains pointers so no need to free the individual items */
172}
static struct stasis_subscription * autohints_subscription
Subscription to receive updates so we can create hints as needed on autohint enabled contexts.
static ast_mutex_t extension_state_autohints_lock
Lock to protect the autohints vector.
#define ast_mutex_unlock(a)
Definition lock.h:197
#define ast_mutex_lock(a)
Definition lock.h:196
struct stasis_subscription * stasis_unsubscribe(struct stasis_subscription *subscription)
Cancel a subscription.
Definition stasis.c:1049
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition vector.h:185

References ast_mutex_lock, ast_mutex_unlock, AST_VECTOR_FREE, autohints_subscription, extension_state_autohints, extension_state_autohints_lock, and stasis_unsubscribe().

Referenced by ast_extension_state_autohints_init().

◆ extension_state_autohints_device_state_cb()

static void extension_state_autohints_device_state_cb ( void *  userdata,
struct stasis_subscription sub,
struct stasis_message msg 
)
static

Definition at line 50 of file extension_state_autohints.c.

52{
53 struct ast_device_state_message *device_state;
54 char *virtual_device, *type, *device_name;
55 int i;
56
58 return;
59 }
60
61 device_state = stasis_message_data(msg);
62
63 /* We only care about the aggregate state */
64 if (device_state->eid) {
65 return;
66 }
67
68 type = ast_strdupa(device_state->device);
69 if (ast_strlen_zero(type)) {
70 return;
71 }
72
73 /* Determine if this is a virtual/custom device or a real device */
74 virtual_device = strchr(type, ':');
75 device_name = strchr(type, '/');
76 if (virtual_device && (!device_name || (virtual_device < device_name))) {
77 device_name = virtual_device;
78 }
79
80 /* Invalid device state name - not a virtual/custom device and not a real device */
81 if (ast_strlen_zero(device_name)) {
82 return;
83 }
84 *device_name++ = '\0';
85
87
89 for (i = 0; i < AST_VECTOR_SIZE(&extension_state_autohints); i++) {
91 struct pbx_find_info q = { .stacklen = 0 };
92
93 if (pbx_find_extension(NULL, NULL, &q, ast_get_context_name(context), device_name,
94 PRIORITY_HINT, NULL, "", E_MATCH)) {
95 continue;
96 }
97
98 /* The device has no hint in the context referenced by this autohint so create one */
100 device_state->device, ast_strdup(device_state->device), ast_free_ptr, registrar);
101 }
103
105}
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298
void ast_free_ptr(void *ptr)
free() wrapper
Definition astmm.c:1739
static const char type[]
struct stasis_message_type * ast_device_state_message_type(void)
Get the Stasis message type for device state messages.
@ E_MATCH
Definition extconf.h:217
static const char registrar[]
The static registrar for the added dialplan hints.
int ast_add_extension(const char *context, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar)
Add and extension to an extension context.
Definition pbx.c:5206
int ast_wrlock_contexts(void)
Write locks the context list.
Definition pbx.c:6621
const char * ast_get_context_name(struct ast_context *con)
Definition ael_main.c:421
#define PRIORITY_HINT
Definition pbx.h:54
struct ast_exten * pbx_find_extension(struct ast_channel *chan, struct ast_context *bypass, struct pbx_find_info *q, const char *context, const char *exten, int priority, const char *label, const char *callerid, enum ext_match_t action)
Definition ael_main.c:152
int ast_unlock_contexts(void)
Unlocks contexts.
Definition pbx.c:6631
#define NULL
Definition resample.c:96
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
ast_context: An extension context
Definition pbx.c:254
The structure that contains device state.
const struct ast_eid * eid
The EID of the server where this message originated.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition vector.h:620
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition vector.h:691

References ast_add_extension(), ast_device_state_message_type(), ast_free_ptr(), ast_get_context_name(), ast_mutex_lock, ast_mutex_unlock, ast_strdup, ast_strdupa, ast_strlen_zero(), ast_unlock_contexts(), AST_VECTOR_GET, AST_VECTOR_SIZE, ast_wrlock_contexts(), ast_device_state_message::device, E_MATCH, ast_device_state_message::eid, extension_state_autohints, extension_state_autohints_lock, NULL, pbx_find_extension(), PRIORITY_HINT, registrar, pbx_find_info::stacklen, stasis_message_data(), and type.

Referenced by pbx_extension_state_autohint_set().

◆ pbx_extension_state_autohint_remove()

void pbx_extension_state_autohint_remove ( struct ast_context context,
unsigned int  forced 
)

Definition at line 133 of file extension_state_autohints.c.

134{
135 int removed;
136
138
140 if (!forced) {
143 } else {
146 }
147 if (removed) {
149 }
151 /* There's no more autohint enabled contexts, so unsubscribe */
153 }
155
157}
#define AUTOHINT_CMP_CONTEXT_NAME(elem, name)
int ast_context_destroy_by_name(const char *context, const char *registrar)
Destroy a context by name.
Definition pbx.c:6491
#define AST_VECTOR_ELEM_CLEANUP_NOOP(elem)
Vector element cleanup that does nothing.
Definition vector.h:582
#define AST_VECTOR_REMOVE_CMP_UNORDERED(vec, value, cmp, cleanup)
Remove an element from a vector that matches the given comparison.
Definition vector.h:499
#define AST_VECTOR_ELEM_DEFAULT_CMP(elem, value)
Default comparator for AST_VECTOR_REMOVE_ELEM_UNORDERED()
Definition vector.h:575

References ast_context_destroy_by_name(), ast_get_context_name(), ast_mutex_lock, ast_mutex_unlock, ast_unlock_contexts(), AST_VECTOR_ELEM_CLEANUP_NOOP, AST_VECTOR_ELEM_DEFAULT_CMP, AST_VECTOR_REMOVE_CMP_UNORDERED, AST_VECTOR_SIZE, ast_wrlock_contexts(), AUTOHINT_CMP_CONTEXT_NAME, autohints_subscription, extension_state_autohints, extension_state_autohints_lock, registrar, and stasis_unsubscribe().

Referenced by __ast_internal_context_destroy(), ast_context_set_autohints(), and context_promote().

◆ pbx_extension_state_autohint_set()

void pbx_extension_state_autohint_set ( struct ast_context context)

extension_state_autohints.c functions needed by pbx.c

Definition at line 113 of file extension_state_autohints.c.

114{
116
118
119 /* Since we store a pointer to the context we remove the old one by name and append the new one, easy */
123
125 /* We have at least one context enabled with autohints and no subscription, so subscribe */
127 }
129
131}
struct stasis_topic * ast_device_state_topic_all(void)
Get the Stasis topic for device state messages.
static void extension_state_autohints_device_state_cb(void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
int ast_rdlock_contexts(void)
Read locks the context list.
Definition pbx.c:6626
#define stasis_subscribe(topic, callback, data)
Definition stasis.h:649
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition vector.h:267

References ast_device_state_topic_all(), ast_get_context_name(), ast_mutex_lock, ast_mutex_unlock, ast_rdlock_contexts(), ast_unlock_contexts(), AST_VECTOR_APPEND, AST_VECTOR_ELEM_CLEANUP_NOOP, AST_VECTOR_REMOVE_CMP_UNORDERED, AST_VECTOR_SIZE, AUTOHINT_CMP_CONTEXT_NAME, autohints_subscription, extension_state_autohints, extension_state_autohints_device_state_cb(), extension_state_autohints_lock, NULL, and stasis_subscribe.

Referenced by ast_context_set_autohints(), context_merge(), and context_promote().

Variable Documentation

◆ autohints_subscription

struct stasis_subscription* autohints_subscription
static

Subscription to receive updates so we can create hints as needed on autohint enabled contexts.

Definition at line 37 of file extension_state_autohints.c.

Referenced by extension_state_autohints_cleanup(), pbx_extension_state_autohint_remove(), and pbx_extension_state_autohint_set().

◆ current

size_t current

Definition at line 34 of file extension_state_autohints.c.

◆ elems

struct ast_context* * elems

Definition at line 34 of file extension_state_autohints.c.

◆ [struct]

struct { ... } extension_state_autohints

◆ extension_state_autohints_lock

ast_mutex_t extension_state_autohints_lock = AST_MUTEX_INIT_VALUE
static

◆ max

size_t max

Definition at line 34 of file extension_state_autohints.c.

◆ registrar

const char registrar[] = "autohints"
static

The static registrar for the added dialplan hints.

Definition at line 40 of file extension_state_autohints.c.

Referenced by __ast_context_create(), __ast_context_destroy(), __ast_context_destroy(), ast_add_extension(), ast_add_extension2(), ast_add_extension2(), ast_add_extension2(), ast_add_extension2_lockopt(), ast_add_extension2_nolock(), ast_context_add_ignorepat(), ast_context_add_ignorepat2(), ast_context_add_ignorepat2(), ast_context_add_ignorepat2(), ast_context_add_include(), ast_context_add_include2(), ast_context_add_include2(), ast_context_add_switch(), ast_context_add_switch2(), ast_context_add_switch2(), ast_context_add_switch2(), ast_context_create(), ast_context_destroy(), ast_context_destroy_by_name(), ast_context_find_or_create(), ast_context_find_or_create(), ast_context_find_or_create(), ast_context_remove_extension(), ast_context_remove_extension2(), ast_context_remove_extension_callerid(), ast_context_remove_extension_callerid2(), ast_context_remove_ignorepat(), ast_context_remove_ignorepat2(), ast_context_remove_include(), ast_context_remove_include2(), ast_context_remove_switch(), ast_context_remove_switch2(), ast_merge_contexts_and_delete(), ast_merge_contexts_and_delete(), AST_TEST_DEFINE(), context_merge(), context_merge_incls_swits_igps_other_registrars(), extension_state_autohints_device_state_cb(), ignorepat_alloc(), include_alloc(), localized_add_extension2(), localized_context_add_ignorepat2(), localized_context_add_include2(), localized_context_add_switch2(), localized_context_destroy(), localized_context_find_or_create(), localized_merge_contexts_and_delete(), parking_add_extension(), parking_lot_cfg_create_extensions(), parking_lot_cfg_remove_extensions(), pbx_extension_state_autohint_remove(), and sw_alloc().