Asterisk - The Open Source Telephony Project GIT-master-f36a736
Data Structures | Macros | Enumerations | Functions | Variables
res_mwi_external.c File Reference

Core external MWI support. More...

#include "asterisk.h"
#include "asterisk/app.h"
#include "asterisk/mwi.h"
#include "asterisk/module.h"
#include "asterisk/res_mwi_external.h"
#include "asterisk/sorcery.h"
#include "asterisk/cli.h"
Include dependency graph for res_mwi_external.c:

Go to the source code of this file.

Data Structures

struct  ast_mwi_mailbox_object
 

Macros

#define FORMAT_MAILBOX_HDR   "%6s %6s %s\n"
 
#define FORMAT_MAILBOX_ROW   "%6u %6u %s\n"
 
#define MWI_ASTDB_PREFIX   "mwi_external"
 
#define MWI_MAILBOX_TYPE   "mailboxes"
 

Enumerations

enum  folder_map { FOLDER_INVALID = 0 , FOLDER_INBOX = 1 , FOLDER_OLD = 2 }
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
struct ast_mwi_mailbox_objectast_mwi_mailbox_alloc (const char *mailbox_id)
 Allocate an external MWI object. More...
 
struct ast_mwi_mailbox_objectast_mwi_mailbox_copy (const struct ast_mwi_mailbox_object *mailbox)
 Copy the external MWI counts object. More...
 
int ast_mwi_mailbox_delete (const char *mailbox_id)
 Delete matching external MWI object. More...
 
int ast_mwi_mailbox_delete_all (void)
 Delete all external MWI objects. More...
 
int ast_mwi_mailbox_delete_by_regex (const char *regex)
 Delete all external MWI objects selected by the regular expression. More...
 
const struct ast_mwi_mailbox_objectast_mwi_mailbox_get (const char *mailbox_id)
 Get matching external MWI object. More...
 
struct ao2_containerast_mwi_mailbox_get_all (void)
 Get all external MWI objects. More...
 
struct ao2_containerast_mwi_mailbox_get_by_regex (const char *regex)
 Get all external MWI objects selected by the regular expression. More...
 
const char * ast_mwi_mailbox_get_id (const struct ast_mwi_mailbox_object *mailbox)
 Get mailbox id. More...
 
unsigned int ast_mwi_mailbox_get_msgs_new (const struct ast_mwi_mailbox_object *mailbox)
 Get the number of new messages. More...
 
unsigned int ast_mwi_mailbox_get_msgs_old (const struct ast_mwi_mailbox_object *mailbox)
 Get the number of old messages. More...
 
void ast_mwi_mailbox_set_msgs_new (struct ast_mwi_mailbox_object *mailbox, unsigned int num_msgs)
 Set the number of new messages. More...
 
void ast_mwi_mailbox_set_msgs_old (struct ast_mwi_mailbox_object *mailbox, unsigned int num_msgs)
 Set the number of old messages. More...
 
int ast_mwi_mailbox_update (struct ast_mwi_mailbox_object *mailbox)
 Update the external MWI counts with the given object. More...
 
static int load_module (void)
 
static enum folder_map mwi_folder_map (const char *folder)
 
static int mwi_has_voicemail (const char *mailboxes, const char *folder)
 
static int mwi_inboxcount (const char *mailboxes, int *newmsgs, int *oldmsgs)
 
static int mwi_inboxcount2 (const char *mailboxes, int *urgentmsgs, int *newmsgs, int *oldmsgs)
 
static void mwi_initial_events (void)
 
static void mwi_mailbox_delete (struct ast_mwi_mailbox_object *mailbox)
 
static void mwi_mailbox_delete_all (struct ao2_container *mailboxes)
 
static int mwi_messagecount (const char *mailbox_id, const char *folder)
 
static void mwi_observe_delete (const void *obj)
 
static void mwi_observe_update (const void *obj)
 
static void mwi_post_event (const struct ast_mwi_mailbox_object *mailbox)
 
static int mwi_sorcery_init (void)
 
static void * mwi_sorcery_object_alloc (const char *id)
 Internal function to allocate a mwi object. More...
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Core external MWI resource" , .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, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DEPEND - 5, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static const struct ast_sorcery_observer mwi_observers
 
static struct ast_sorcerymwi_sorcery
 
static const struct ast_vm_functions vm_table
 

Detailed Description

Core external MWI support.

The module manages the persistent message counts cache and supplies an API to allow the protocol specific modules to control the counts or a subset.

Author
Richard Mudgett rmudg.nosp@m.ett@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

See Also:

Definition in file res_mwi_external.c.

Macro Definition Documentation

◆ FORMAT_MAILBOX_HDR

#define FORMAT_MAILBOX_HDR   "%6s %6s %s\n"

Definition at line 642 of file res_mwi_external.c.

◆ FORMAT_MAILBOX_ROW

#define FORMAT_MAILBOX_ROW   "%6u %6u %s\n"

Definition at line 643 of file res_mwi_external.c.

◆ MWI_ASTDB_PREFIX

#define MWI_ASTDB_PREFIX   "mwi_external"

Define to include CLI commands to manipulate the external MWI mailboxes. Useful for testing the module functionality.

Definition at line 72 of file res_mwi_external.c.

◆ MWI_MAILBOX_TYPE

#define MWI_MAILBOX_TYPE   "mailboxes"

Definition at line 73 of file res_mwi_external.c.

Enumeration Type Documentation

◆ folder_map

enum folder_map
Enumerator
FOLDER_INVALID 
FOLDER_INBOX 
FOLDER_OLD 

Definition at line 318 of file res_mwi_external.c.

318 {
319 FOLDER_INVALID = 0,
320 FOLDER_INBOX = 1,
321 FOLDER_OLD = 2,
322};
@ FOLDER_INVALID
@ FOLDER_OLD
@ FOLDER_INBOX

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 943 of file res_mwi_external.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 943 of file res_mwi_external.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 943 of file res_mwi_external.c.

◆ ast_mwi_mailbox_alloc()

struct ast_mwi_mailbox_object * ast_mwi_mailbox_alloc ( const char *  mailbox_id)

Allocate an external MWI object.

Since
12.1.0
Parameters
mailbox_idName of mailbox.
Returns
object on success. The object is an ao2 object.
Return values
NULLon error.

Definition at line 192 of file res_mwi_external.c.

193{
194 if (ast_strlen_zero(mailbox_id)) {
195 return NULL;
196 }
197
199}
#define MWI_MAILBOX_TYPE
static struct ast_sorcery * mwi_sorcery
#define NULL
Definition: resample.c:96
void * ast_sorcery_alloc(const struct ast_sorcery *sorcery, const char *type, const char *id)
Allocate an object.
Definition: sorcery.c:1744
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65

References ast_sorcery_alloc(), ast_strlen_zero(), MWI_MAILBOX_TYPE, mwi_sorcery, and NULL.

Referenced by mwi_mailbox_update(), and stasis_app_mailbox_update().

◆ ast_mwi_mailbox_copy()

struct ast_mwi_mailbox_object * ast_mwi_mailbox_copy ( const struct ast_mwi_mailbox_object mailbox)

Copy the external MWI counts object.

Since
12.1.0
Parameters
mailboxWhat to copy.
Returns
copy on success. The object is an ao2 object.
Return values
NULLon error.

Definition at line 201 of file res_mwi_external.c.

202{
204}
void * ast_sorcery_copy(const struct ast_sorcery *sorcery, const void *object)
Create a copy of an object.
Definition: sorcery.c:1778

References ast_sorcery_copy(), voicemailpwcheck::mailbox, and mwi_sorcery.

◆ ast_mwi_mailbox_delete()

int ast_mwi_mailbox_delete ( const char *  mailbox_id)

Delete matching external MWI object.

Since
12.1.0
Parameters
mailbox_idName of mailbox to delete.
Return values
0on success.
-1on error.

Definition at line 302 of file res_mwi_external.c.

303{
304 const struct ast_mwi_mailbox_object *mailbox;
305
306 if (ast_strlen_zero(mailbox_id)) {
307 return -1;
308 }
309
310 mailbox = ast_mwi_mailbox_get(mailbox_id);
311 if (mailbox) {
314 }
315 return 0;
316}
const struct ast_mwi_mailbox_object * ast_mwi_mailbox_get(const char *mailbox_id)
Get matching external MWI object.
static void mwi_mailbox_delete(struct ast_mwi_mailbox_object *mailbox)
#define ast_mwi_mailbox_unref(mailbox)
Convenience unref function for mailbox object.

References ast_mwi_mailbox_get(), ast_mwi_mailbox_unref, ast_strlen_zero(), voicemailpwcheck::mailbox, and mwi_mailbox_delete().

Referenced by mwi_mailbox_delete(), and stasis_app_mailbox_delete().

◆ ast_mwi_mailbox_delete_all()

int ast_mwi_mailbox_delete_all ( void  )

Delete all external MWI objects.

Since
12.1.0
Return values
0on success.
-1on error.

Definition at line 278 of file res_mwi_external.c.

279{
280 struct ao2_container *mailboxes;
281
283 if (mailboxes) {
285 ao2_ref(mailboxes, -1);
286 }
287 return 0;
288}
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
static struct stasis_rest_handlers mailboxes
REST handler for /api-docs/mailboxes.json.
static void mwi_mailbox_delete_all(struct ao2_container *mailboxes)
struct ao2_container * ast_mwi_mailbox_get_all(void)
Get all external MWI objects.
Generic container type.

References ao2_ref, ast_mwi_mailbox_get_all(), mailboxes, and mwi_mailbox_delete_all().

◆ ast_mwi_mailbox_delete_by_regex()

int ast_mwi_mailbox_delete_by_regex ( const char *  regex)

Delete all external MWI objects selected by the regular expression.

Since
12.1.0
Parameters
regexRegular expression in extended syntax. (NULL is same as "")
Note
The provided regex is treated as extended case sensitive.
Return values
0on success.
-1on error.

Definition at line 290 of file res_mwi_external.c.

291{
292 struct ao2_container *mailboxes;
293
295 if (mailboxes) {
297 ao2_ref(mailboxes, -1);
298 }
299 return 0;
300}
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
struct ao2_container * ast_mwi_mailbox_get_by_regex(const char *regex)
Get all external MWI objects selected by the regular expression.

References ao2_ref, ast_mwi_mailbox_get_by_regex(), mailboxes, mwi_mailbox_delete_all(), and regex().

Referenced by mwi_mailbox_delete().

◆ ast_mwi_mailbox_get()

const struct ast_mwi_mailbox_object * ast_mwi_mailbox_get ( const char *  mailbox_id)

Get matching external MWI object.

Since
12.1.0
Parameters
mailbox_idName of mailbox to retrieve.
Returns
requested mailbox on success. The object is an ao2 object.
Return values
NULLon error or no mailbox.
Note
The object must be treated as read-only.

Definition at line 183 of file res_mwi_external.c.

184{
185 if (ast_strlen_zero(mailbox_id)) {
186 return NULL;
187 }
188
190}
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition: sorcery.c:1853

References ast_sorcery_retrieve_by_id(), ast_strlen_zero(), MWI_MAILBOX_TYPE, mwi_sorcery, and NULL.

Referenced by ast_mwi_mailbox_delete(), mwi_has_voicemail(), mwi_inboxcount(), mwi_mailbox_get(), mwi_messagecount(), stasis_app_mailbox_delete(), and stasis_app_mailbox_to_json().

◆ ast_mwi_mailbox_get_all()

struct ao2_container * ast_mwi_mailbox_get_all ( void  )

Get all external MWI objects.

Since
12.1.0
Returns
container of struct ast_mwi_mailbox_object on success.
Return values
NULLon error.
Note
The objects in the container must be treated as read-only.

Definition at line 172 of file res_mwi_external.c.

173{
176}
@ AST_RETRIEVE_FLAG_MULTIPLE
Return all matching objects.
Definition: sorcery.h:120
@ AST_RETRIEVE_FLAG_ALL
Perform no matching, return all objects.
Definition: sorcery.h:123
void * ast_sorcery_retrieve_by_fields(const struct ast_sorcery *sorcery, const char *type, unsigned int flags, struct ast_variable *fields)
Retrieve an object or multiple objects using specific fields.
Definition: sorcery.c:1897

References AST_RETRIEVE_FLAG_ALL, AST_RETRIEVE_FLAG_MULTIPLE, ast_sorcery_retrieve_by_fields(), MWI_MAILBOX_TYPE, mwi_sorcery, and NULL.

Referenced by ast_mwi_mailbox_delete_all(), mwi_initial_events(), and stasis_app_mailboxes_to_json().

◆ ast_mwi_mailbox_get_by_regex()

struct ao2_container * ast_mwi_mailbox_get_by_regex ( const char *  regex)

Get all external MWI objects selected by the regular expression.

Since
12.1.0
Parameters
regexRegular expression in extended syntax. (NULL is same as "")
Note
The provided regex is treated as extended case sensitive.
Returns
container of struct ast_mwi_mailbox_object on success.
Return values
NULLon error.
Note
The objects in the container must be treated as read-only.

Definition at line 178 of file res_mwi_external.c.

179{
181}
struct ao2_container * ast_sorcery_retrieve_by_regex(const struct ast_sorcery *sorcery, const char *type, const char *regex)
Retrieve multiple objects using a regular expression on their id.
Definition: sorcery.c:1954

References ast_sorcery_retrieve_by_regex(), MWI_MAILBOX_TYPE, mwi_sorcery, and regex().

Referenced by ast_mwi_mailbox_delete_by_regex(), and mwi_mailbox_get().

◆ ast_mwi_mailbox_get_id()

const char * ast_mwi_mailbox_get_id ( const struct ast_mwi_mailbox_object mailbox)

Get mailbox id.

Since
12.1.0
Parameters
mailboxObject to get id.
Returns
mailbox_id of the object.
Note
This should never return NULL unless there is a bug in sorcery.

Definition at line 206 of file res_mwi_external.c.

207{
209}
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2317

References ast_sorcery_object_get_id(), and voicemailpwcheck::mailbox.

Referenced by mailbox_to_json(), and mwi_mailbox_get().

◆ ast_mwi_mailbox_get_msgs_new()

unsigned int ast_mwi_mailbox_get_msgs_new ( const struct ast_mwi_mailbox_object mailbox)

Get the number of new messages.

Since
12.1.0
Parameters
mailboxObject to get number of new messages.
Returns
Number of new messages.

Definition at line 211 of file res_mwi_external.c.

212{
213 return mailbox->msgs_new;
214}

References voicemailpwcheck::mailbox.

Referenced by mailbox_to_json(), and mwi_mailbox_get().

◆ ast_mwi_mailbox_get_msgs_old()

unsigned int ast_mwi_mailbox_get_msgs_old ( const struct ast_mwi_mailbox_object mailbox)

Get the number of old messages.

Since
12.1.0
Parameters
mailboxObject to get number of old messages.
Returns
Number of old messages.

Definition at line 216 of file res_mwi_external.c.

217{
218 return mailbox->msgs_old;
219}

References voicemailpwcheck::mailbox.

Referenced by mailbox_to_json(), and mwi_mailbox_get().

◆ ast_mwi_mailbox_set_msgs_new()

void ast_mwi_mailbox_set_msgs_new ( struct ast_mwi_mailbox_object mailbox,
unsigned int  num_msgs 
)

Set the number of new messages.

Since
12.1.0
Parameters
mailboxObject to set number of new messages.
num_msgsNumber of messages to set.

Definition at line 221 of file res_mwi_external.c.

222{
223 mailbox->msgs_new = num_msgs;
224}

References voicemailpwcheck::mailbox.

Referenced by mwi_mailbox_update(), and stasis_app_mailbox_update().

◆ ast_mwi_mailbox_set_msgs_old()

void ast_mwi_mailbox_set_msgs_old ( struct ast_mwi_mailbox_object mailbox,
unsigned int  num_msgs 
)

Set the number of old messages.

Since
12.1.0
Parameters
mailboxObject to set number of old messages.
num_msgsNumber of messages to set.

Definition at line 226 of file res_mwi_external.c.

227{
228 mailbox->msgs_old = num_msgs;
229}

References voicemailpwcheck::mailbox.

Referenced by mwi_mailbox_update(), and stasis_app_mailbox_update().

◆ ast_mwi_mailbox_update()

int ast_mwi_mailbox_update ( struct ast_mwi_mailbox_object mailbox)

Update the external MWI counts with the given object.

Since
12.1.0
Parameters
mailboxWhat to update.
Return values
0on success.
-1on error.

Definition at line 231 of file res_mwi_external.c.

232{
233 const struct ast_mwi_mailbox_object *exists;
234 int res;
235
238 if (exists) {
241 } else {
243 }
244 return res;
245}
static int exists(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_logic.c:157
int ast_sorcery_create(const struct ast_sorcery *sorcery, void *object)
Create and potentially persist an object using an available wizard.
Definition: sorcery.c:2062
int ast_sorcery_update(const struct ast_sorcery *sorcery, void *object)
Update an object.
Definition: sorcery.c:2150

References ast_mwi_mailbox_unref, ast_sorcery_create(), ast_sorcery_object_get_id(), ast_sorcery_retrieve_by_id(), ast_sorcery_update(), exists(), voicemailpwcheck::mailbox, MWI_MAILBOX_TYPE, and mwi_sorcery.

Referenced by mwi_mailbox_update(), and stasis_app_mailbox_update().

◆ load_module()

static int load_module ( void  )
static

Definition at line 910 of file res_mwi_external.c.

911{
912 int res;
913
914 if (mwi_sorcery_init()
916#if defined(MWI_DEBUG_CLI)
917 || ast_cli_register_multiple(mwi_cli, ARRAY_LEN(mwi_cli))
918#endif /* defined(MWI_DEBUG_CLI) */
919 ) {
922 }
923
924 /* ast_vm_register may return DECLINE if another module registered for vm */
926 if (res) {
927 ast_log(LOG_ERROR, "Failure registering as a voicemail provider\n");
930 }
931
932 /* Post initial MWI count events. */
934
936}
#define ast_log
Definition: astobj2.c:42
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
#define ast_vm_register(vm_table)
See __ast_vm_register()
#define LOG_ERROR
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static const struct ast_vm_functions vm_table
static void mwi_initial_events(void)
static const struct ast_sorcery_observer mwi_observers
static int unload_module(void)
static int mwi_sorcery_init(void)
int ast_sorcery_observer_add(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Add an observer to a specific object type.
Definition: sorcery.c:2391
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, ast_cli_register_multiple, ast_log, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_sorcery_observer_add(), ast_vm_register, LOG_ERROR, mwi_initial_events(), MWI_MAILBOX_TYPE, mwi_observers, mwi_sorcery, mwi_sorcery_init(), unload_module(), and vm_table.

◆ mwi_folder_map()

static enum folder_map mwi_folder_map ( const char *  folder)
static

Definition at line 333 of file res_mwi_external.c.

334{
335 enum folder_map which_folder;
336
337 if (ast_strlen_zero(folder) || !strcasecmp(folder, "INBOX")) {
338 which_folder = FOLDER_INBOX;
339 } else if (!strcasecmp(folder, "Old")) {
340 which_folder = FOLDER_OLD;
341 } else {
342 which_folder = FOLDER_INVALID;
343 }
344 return which_folder;
345}
folder_map

References ast_strlen_zero(), FOLDER_INBOX, FOLDER_INVALID, and FOLDER_OLD.

Referenced by mwi_has_voicemail(), and mwi_messagecount().

◆ mwi_has_voicemail()

static int mwi_has_voicemail ( const char *  mailboxes,
const char *  folder 
)
static

Definition at line 399 of file res_mwi_external.c.

400{
401 char *parse;
402 char *mailbox_id;
403 enum folder_map which_folder;
404
405 which_folder = mwi_folder_map(folder);
406 if (which_folder == FOLDER_INVALID) {
407 return 0;
408 }
409
410 /* For each mailbox in the list. */
411 parse = ast_strdupa(mailboxes);
412 while ((mailbox_id = strsep(&parse, ",&"))) {
413 const struct ast_mwi_mailbox_object *mailbox;
414 int num_msgs;
415
416 /* Get the specified mailbox. */
417 mailbox = ast_mwi_mailbox_get(mailbox_id);
418 if (!mailbox) {
419 continue;
420 }
421
422 /* Done if the found mailbox has any messages. */
423 num_msgs = 0;
424 switch (which_folder) {
425 case FOLDER_INVALID:
426 break;
427 case FOLDER_INBOX:
428 num_msgs = mailbox->msgs_new;
429 break;
430 case FOLDER_OLD:
431 num_msgs = mailbox->msgs_old;
432 break;
433 }
435 if (num_msgs) {
436 return 1;
437 }
438 }
439
440 return 0;
441}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
char * strsep(char **str, const char *delims)
static enum folder_map mwi_folder_map(const char *folder)

References ast_mwi_mailbox_get(), ast_mwi_mailbox_unref, ast_strdupa, FOLDER_INBOX, FOLDER_INVALID, FOLDER_OLD, voicemailpwcheck::mailbox, mailboxes, mwi_folder_map(), and strsep().

◆ mwi_inboxcount()

static int mwi_inboxcount ( const char *  mailboxes,
int *  newmsgs,
int *  oldmsgs 
)
static

Definition at line 459 of file res_mwi_external.c.

460{
461 char *parse;
462 char *mailbox_id;
463
464 if (!newmsgs && !oldmsgs) {
465 /* Nowhere to accumulate counts */
466 return 0;
467 }
468
469 /* For each mailbox in the list. */
470 parse = ast_strdupa(mailboxes);
471 while ((mailbox_id = strsep(&parse, ", "))) {
472 const struct ast_mwi_mailbox_object *mailbox;
473
474 /* Get the specified mailbox. */
475 mailbox = ast_mwi_mailbox_get(mailbox_id);
476 if (!mailbox) {
477 continue;
478 }
479
480 /* Accumulate the counts. */
481 if (newmsgs) {
482 *newmsgs += mailbox->msgs_new;
483 }
484 if (oldmsgs) {
485 *oldmsgs += mailbox->msgs_old;
486 }
487
489 }
490
491 return 0;
492}

References ast_mwi_mailbox_get(), ast_mwi_mailbox_unref, ast_strdupa, voicemailpwcheck::mailbox, mailboxes, and strsep().

Referenced by mwi_inboxcount2().

◆ mwi_inboxcount2()

static int mwi_inboxcount2 ( const char *  mailboxes,
int *  urgentmsgs,
int *  newmsgs,
int *  oldmsgs 
)
static

Definition at line 512 of file res_mwi_external.c.

513{
514 /*
515 * This module does not support urgentmsgs. Just ignore them.
516 * The global API call has already set the count to zero.
517 */
518 return mwi_inboxcount(mailboxes, newmsgs, oldmsgs);
519}
static int mwi_inboxcount(const char *mailboxes, int *newmsgs, int *oldmsgs)

References mailboxes, and mwi_inboxcount().

◆ mwi_initial_events()

static void mwi_initial_events ( void  )
static

Definition at line 874 of file res_mwi_external.c.

875{
876 struct ao2_container *mailboxes;
877 const struct ast_mwi_mailbox_object *mailbox;
878 struct ao2_iterator iter;
879
880 /* Get all mailbox counts. */
882 if (!mailboxes) {
883 return;
884 }
885
886 /* Post all mailbox counts. */
890 }
892
893 ao2_ref(mailboxes, -1);
894}
#define ao2_iterator_next(iter)
Definition: astobj2.h:1911
@ AO2_ITERATOR_UNLINK
Definition: astobj2.h:1863
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
static void mwi_post_event(const struct ast_mwi_mailbox_object *mailbox)
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1821

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, AO2_ITERATOR_UNLINK, ao2_ref, ast_mwi_mailbox_get_all(), ast_mwi_mailbox_unref, voicemailpwcheck::mailbox, mailboxes, and mwi_post_event().

Referenced by load_module().

◆ mwi_mailbox_delete()

static void mwi_mailbox_delete ( struct ast_mwi_mailbox_object mailbox)
static

Definition at line 254 of file res_mwi_external.c.

255{
257}
int ast_sorcery_delete(const struct ast_sorcery *sorcery, void *object)
Delete an object.
Definition: sorcery.c:2238

References ast_sorcery_delete(), voicemailpwcheck::mailbox, and mwi_sorcery.

Referenced by ast_mwi_mailbox_delete(), and mwi_mailbox_delete_all().

◆ mwi_mailbox_delete_all()

static void mwi_mailbox_delete_all ( struct ao2_container mailboxes)
static

◆ mwi_messagecount()

static int mwi_messagecount ( const char *  mailbox_id,
const char *  folder 
)
static

Definition at line 357 of file res_mwi_external.c.

358{
359 const struct ast_mwi_mailbox_object *mailbox;
360 int num_msgs;
361 enum folder_map which_folder;
362
363 which_folder = mwi_folder_map(folder);
364 if (which_folder == FOLDER_INVALID) {
365 return 0;
366 }
367
368 mailbox = ast_mwi_mailbox_get(mailbox_id);
369 if (!mailbox) {
370 return 0;
371 }
372 num_msgs = 0;
373 switch (which_folder) {
374 case FOLDER_INVALID:
375 break;
376 case FOLDER_INBOX:
377 num_msgs = mailbox->msgs_new;
378 break;
379 case FOLDER_OLD:
380 num_msgs = mailbox->msgs_old;
381 break;
382 }
384
385 return num_msgs;
386}

References ast_mwi_mailbox_get(), ast_mwi_mailbox_unref, FOLDER_INBOX, FOLDER_INVALID, FOLDER_OLD, voicemailpwcheck::mailbox, and mwi_folder_map().

◆ mwi_observe_delete()

static void mwi_observe_delete ( const void *  obj)
static

Definition at line 106 of file res_mwi_external.c.

107{
108 const struct ast_mwi_mailbox_object *mailbox = obj;
109
110 if (mailbox->msgs_new || mailbox->msgs_old) {
111 /* Post a count clearing event. */
113 }
114
115 /* Post a cache remove event. */
117}
#define ast_delete_mwi_state(mailbox, context)
Delete MWI state cached by stasis.
Definition: mwi.h:431
#define ast_publish_mwi_state(mailbox, context, new_msgs, old_msgs)
Publish a MWI state update via stasis.
Definition: mwi.h:378

References ast_delete_mwi_state, ast_publish_mwi_state, ast_sorcery_object_get_id(), voicemailpwcheck::mailbox, and NULL.

◆ mwi_observe_update()

static void mwi_observe_update ( const void *  obj)
static

Definition at line 96 of file res_mwi_external.c.

97{
98 mwi_post_event(obj);
99}

References mwi_post_event().

◆ mwi_post_event()

static void mwi_post_event ( const struct ast_mwi_mailbox_object mailbox)
static

◆ mwi_sorcery_init()

static int mwi_sorcery_init ( void  )
static

Definition at line 139 of file res_mwi_external.c.

140{
141 int res;
142
144 if (!mwi_sorcery) {
145 ast_log(LOG_ERROR, "MWI external: Sorcery failed to open.\n");
146 return -1;
147 }
148
149 /* Map the external MWI wizards. */
152 ast_log(LOG_ERROR, "MWI external: Sorcery could not setup wizards.\n");
153 return -1;
154 }
155
158 if (res) {
159 ast_log(LOG_ERROR, "MWI external: Sorcery could not register object type '%s'.\n",
161 return -1;
162 }
163
164 /* Define the MWI_MAILBOX_TYPE object fields. */
166 "msgs_new", "0", OPT_UINT_T, 0, FLDSET(struct ast_mwi_mailbox_object, msgs_new));
168 "msgs_old", "0", OPT_UINT_T, 0, FLDSET(struct ast_mwi_mailbox_object, msgs_old));
169 return res ? -1 : 0;
170}
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
@ OPT_UINT_T
Type for default option handler for unsigned integers.
#define MWI_ASTDB_PREFIX
static void * mwi_sorcery_object_alloc(const char *id)
Internal function to allocate a mwi object.
#define ast_sorcery_object_field_register_nodoc(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object without documentation.
Definition: sorcery.h:987
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
Definition: sorcery.h:837
#define ast_sorcery_apply_default(sorcery, type, name, data)
Definition: sorcery.h:476
#define ast_sorcery_open()
Open a new sorcery structure.
Definition: sorcery.h:406
@ AST_SORCERY_APPLY_FAIL
Definition: sorcery.h:425

References ast_log, ast_sorcery_apply_default, AST_SORCERY_APPLY_FAIL, ast_sorcery_object_field_register_nodoc, ast_sorcery_object_register, ast_sorcery_open, FLDSET, LOG_ERROR, MWI_ASTDB_PREFIX, MWI_MAILBOX_TYPE, mwi_sorcery, mwi_sorcery_object_alloc(), NULL, and OPT_UINT_T.

Referenced by load_module().

◆ mwi_sorcery_object_alloc()

static void * mwi_sorcery_object_alloc ( const char *  id)
static

Internal function to allocate a mwi object.

Definition at line 126 of file res_mwi_external.c.

127{
129}
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
Definition: sorcery.c:1728

References ast_sorcery_generic_alloc(), and NULL.

Referenced by mwi_sorcery_init().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 896 of file res_mwi_external.c.

897{
899#if defined(MWI_DEBUG_CLI)
900 ast_cli_unregister_multiple(mwi_cli, ARRAY_LEN(mwi_cli));
901#endif /* defined(MWI_DEBUG_CLI) */
903
906
907 return 0;
908}
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
void ast_vm_unregister(const char *module_name)
Unregister the specified voicemail provider.
Definition: main/app.c:400
#define ast_sorcery_unref(sorcery)
Decrease the reference count of a sorcery structure.
Definition: sorcery.h:1500
void ast_sorcery_observer_remove(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Remove an observer from a specific object type.
Definition: sorcery.c:2423
const char * module_name
The name of the module that provides the voicemail functionality.

References ARRAY_LEN, ast_cli_unregister_multiple(), ast_sorcery_observer_remove(), ast_sorcery_unref, ast_vm_unregister(), ast_vm_functions::module_name, MWI_MAILBOX_TYPE, mwi_observers, mwi_sorcery, NULL, and vm_table.

Referenced by load_module().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Core external MWI resource" , .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, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DEPEND - 5, }
static

Definition at line 943 of file res_mwi_external.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 943 of file res_mwi_external.c.

◆ mwi_observers

const struct ast_sorcery_observer mwi_observers
static
Initial value:
= {
.created = mwi_observe_update,
.updated = mwi_observe_update,
.deleted = mwi_observe_delete,
}
static void mwi_observe_update(const void *obj)
static void mwi_observe_delete(const void *obj)

Definition at line 119 of file res_mwi_external.c.

Referenced by load_module(), and unload_module().

◆ mwi_sorcery

struct ast_sorcery* mwi_sorcery
static

◆ vm_table

const struct ast_vm_functions vm_table
static

Definition at line 521 of file res_mwi_external.c.

Referenced by load_module(), and unload_module().