72 #define MWI_ASTDB_PREFIX "mwi_external" 73 #define MWI_MAILBOX_TYPE "mailboxes" 163 ast_log(
LOG_ERROR,
"MWI external: Sorcery could not register object type '%s'.\n",
347 }
else if (!strcasecmp(folder,
"Old")) {
381 switch (which_folder) {
420 while ((mailbox_id =
strsep(&parse,
",&"))) {
432 switch (which_folder) {
472 if (!newmsgs && !oldmsgs) {
479 while ((mailbox_id =
strsep(&parse,
", "))) {
539 #if defined(MWI_DEBUG_CLI) 540 static char *complete_mailbox(
const char *
word,
int state)
543 int wordlen = strlen(
word);
551 sprintf(regex,
"^%s",
word);
560 if (++which > state) {
572 #if defined(MWI_DEBUG_CLI) 579 "Usage: mwi delete all\n" 580 " Delete all external MWI mailboxes.\n";
587 ast_cli(a->
fd,
"Deleted all external MWI mailboxes.\n");
592 #if defined(MWI_DEBUG_CLI) 599 e->
command =
"mwi delete like";
601 "Usage: mwi delete like <pattern>\n" 602 " Delete external MWI mailboxes matching a regular expression.\n";
614 ast_cli(a->
fd,
"Deleted external MWI mailboxes matching '%s'.\n", regex);
619 #if defined(MWI_DEBUG_CLI) 622 const char *mailbox_id;
626 e->
command =
"mwi delete mailbox";
628 "Usage: mwi delete mailbox <mailbox_id>\n" 629 " Delete a specific external MWI mailbox.\n";
633 return complete_mailbox(a->
word, a->
n);
641 mailbox_id = a->
argv[3];
644 ast_cli(a->
fd,
"Deleted external MWI mailbox '%s'.\n", mailbox_id);
650 #define FORMAT_MAILBOX_HDR "%6s %6s %s\n" 651 #define FORMAT_MAILBOX_ROW "%6u %6u %s\n" 653 #if defined(MWI_DEBUG_CLI) 671 #if defined(MWI_DEBUG_CLI) 691 mwi_cli_print_mailbox(cli_fd, mailbox);
697 #undef FORMAT_MAILBOX_HDR 698 #undef FORMAT_MAILBOX_ROW 700 #if defined(MWI_DEBUG_CLI) 709 "Usage: mwi list all\n" 710 " List all external MWI mailboxes.\n";
718 ast_cli(a->
fd,
"Failed to retrieve external MWI mailboxes.\n");
721 mwi_cli_list_mailboxes(a->
fd, mailboxes);
727 #if defined(MWI_DEBUG_CLI) 737 "Usage: mwi list like <pattern>\n" 738 " List external MWI mailboxes matching a regular expression.\n";
751 ast_cli(a->
fd,
"Failed to retrieve external MWI mailboxes.\n");
754 mwi_cli_list_mailboxes(a->
fd, mailboxes);
760 #if defined(MWI_DEBUG_CLI) 764 const char *mailbox_id;
768 e->
command =
"mwi show mailbox";
770 "Usage: mwi show mailbox <mailbox_id>\n" 771 " Show a specific external MWI mailbox.\n";
775 return complete_mailbox(a->
word, a->
n);
783 mailbox_id = a->
argv[3];
797 ast_cli(a->
fd,
"External MWI mailbox '%s' not found.\n", mailbox_id);
804 #if defined(MWI_DEBUG_CLI) 808 const char *mailbox_id;
809 unsigned int num_new;
810 unsigned int num_old;
814 e->
command =
"mwi update mailbox";
816 "Usage: mwi update mailbox <mailbox_id> [<new> [<old>]]\n" 817 " Update a specific external MWI mailbox.\n";
821 return complete_mailbox(a->
word, a->
n);
829 mailbox_id = a->
argv[3];
833 const char *count_new = a->
argv[4];
835 if (sscanf(count_new,
"%u", &num_new) != 1) {
836 ast_cli(a->
fd,
"Invalid NewMessages: '%s'.\n", count_new);
843 const char *count_old = a->
argv[5];
845 if (sscanf(count_old,
"%u", &num_old) != 1) {
846 ast_cli(a->
fd,
"Invalid OldMessages: '%s'.\n", count_old);
856 ast_cli(a->
fd,
"Could not update mailbox %s.\n",
869 #if defined(MWI_DEBUG_CLI) 871 AST_CLI_DEFINE(handle_mwi_delete_all,
"Delete all external MWI mailboxes"),
872 AST_CLI_DEFINE(handle_mwi_delete_like,
"Delete external MWI mailboxes matching regex"),
873 AST_CLI_DEFINE(handle_mwi_delete_mailbox,
"Delete a specific external MWI mailbox"),
874 AST_CLI_DEFINE(handle_mwi_list_all,
"List all external MWI mailboxes"),
875 AST_CLI_DEFINE(handle_mwi_list_like,
"List external MWI mailboxes matching regex"),
876 AST_CLI_DEFINE(handle_mwi_show_mailbox,
"Show a specific external MWI mailbox"),
877 AST_CLI_DEFINE(handle_mwi_update_mailbox,
"Update a specific external MWI mailbox"),
913 #if defined(MWI_DEBUG_CLI) 930 #
if defined(MWI_DEBUG_CLI)
#define AST_CLI_DEFINE(fn, txt,...)
#define ast_sorcery_object_field_register_nodoc(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object without documentation.
Asterisk main include file. File version handling, generic pbx functions.
static int unload_module(void)
static int mwi_has_voicemail(const char *mailboxes, const char *folder)
static int mwi_inboxcount(const char *mailboxes, int *newmsgs, int *oldmsgs)
static void mwi_observe_delete(const void *obj)
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
static int exists(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int mwi_sorcery_init(void)
static void mwi_mailbox_delete_all(struct ao2_container *mailboxes)
descriptor for a cli entry.
#define FORMAT_MAILBOX_HDR
static struct stasis_rest_handlers mailboxes
REST handler for /api-docs/mailboxes.json.
void(* created)(const void *object)
Callback for when an object is created.
int ast_mwi_mailbox_update(struct ast_mwi_mailbox_object *mailbox)
Update the external MWI counts with the given object.
Perform no matching, return all objects.
static void mwi_post_event(const struct ast_mwi_mailbox_object *mailbox)
Full structure for sorcery.
const struct ast_mwi_mailbox_object * ast_mwi_mailbox_get(const char *mailbox_id)
Get matching external MWI object.
static struct ast_sorcery * mwi_sorcery
#define ast_cli_register_multiple(e, len)
Register multiple commands.
void ast_vm_unregister(const char *module_name)
Unregister the specified voicemail provider.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
Return all matching objects.
void ast_mwi_mailbox_set_msgs_old(struct ast_mwi_mailbox_object *mailbox, unsigned int num_msgs)
Set the number of old messages.
#define ast_strdup(str)
A wrapper for strdup()
Core external MWI support.
void ast_cli(int fd, const char *fmt,...)
#define ast_publish_mwi_state(mailbox, context, new_msgs, old_msgs)
Publish a MWI state update via stasis.
#define FORMAT_MAILBOX_ROW
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.
#define ast_strlen_zero(foo)
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
#define ast_sorcery_unref(sorcery)
Decrease the reference count of a sorcery structure.
static char mailbox[AST_MAX_MAILBOX_UNIQUEID]
int ast_sorcery_create(const struct ast_sorcery *sorcery, void *object)
Create and potentially persist an object using an available wizard.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Type for default option handler for unsigned integers.
int ast_mwi_mailbox_delete(const char *mailbox_id)
Delete matching external MWI object.
#define ao2_ref(o, delta)
#define VM_MODULE_VERSION
static int mwi_messagecount(const char *mailbox_id, const char *folder)
#define ast_strdupa(s)
duplicate a string in memory from the stack
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
static const struct ast_vm_functions vm_table
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
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.
struct ast_mwi_mailbox_object * ast_mwi_mailbox_alloc(const char *mailbox_id)
Allocate an external MWI object.
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
#define ast_vm_register(vm_table)
See __ast_vm_register()
int ast_sorcery_delete(const struct ast_sorcery *sorcery, void *object)
Delete an object.
void ast_mwi_mailbox_set_msgs_new(struct ast_mwi_mailbox_object *mailbox, unsigned int num_msgs)
Set the number of new messages.
Interface for a sorcery object type observer.
struct ao2_container * ast_mwi_mailbox_get_all(void)
Get all external MWI objects.
#define ast_sorcery_apply_default(sorcery, type, name, data)
static enum folder_map mwi_folder_map(const char *folder)
static void mwi_observe_update(const void *obj)
const char * ast_mwi_mailbox_get_id(const struct ast_mwi_mailbox_object *mailbox)
Get mailbox id.
#define ao2_iterator_next(iter)
static void mwi_mailbox_delete(struct ast_mwi_mailbox_object *mailbox)
unsigned int ast_mwi_mailbox_get_msgs_new(const struct ast_mwi_mailbox_object *mailbox)
Get the number of new messages.
void * ast_sorcery_alloc(const struct ast_sorcery *sorcery, const char *type, const char *id)
Allocate an object.
#define ast_delete_mwi_state(mailbox, context)
Delete MWI state cached by stasis.
static void parse(struct mgcp_request *req)
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
#define ast_mwi_mailbox_unref(mailbox)
Convienience unref function for mailbox object.
static const struct ast_sorcery_observer mwi_observers
Module has failed to load, may be in an inconsistent state.
int ast_mwi_mailbox_delete_by_regex(const char *regex)
Delete all external MWI objects selected by the regular expression.
struct ao2_container * ast_mwi_mailbox_get_by_regex(const char *regex)
Get all external MWI objects selected by the regular expression.
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
unsigned int ast_mwi_mailbox_get_msgs_old(const struct ast_mwi_mailbox_object *mailbox)
Get the number of old messages.
struct ast_mwi_mailbox_object * ast_mwi_mailbox_copy(const struct ast_mwi_mailbox_object *mailbox)
Copy the external MWI counts object.
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.
const char * module_name
The name of the module that provides the voicemail functionality.
static void * mwi_sorcery_object_alloc(const char *id)
Internal function to allocate a mwi object.
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.
static void mwi_initial_events(void)
char * strsep(char **str, const char *delims)
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Standard Command Line Interface.
void * ast_sorcery_copy(const struct ast_sorcery *sorcery, const void *object)
Create a copy of an object.
int ast_mwi_mailbox_delete_all(void)
Delete all external MWI objects.
#define ast_sorcery_open()
unsigned int module_version
The version of this function table.
static int load_module(void)
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
Voicemail function table definition.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
static int mwi_inboxcount2(const char *mailboxes, int *urgentmsgs, int *newmsgs, int *oldmsgs)
Sorcery Data Access Layer API.
int ast_sorcery_update(const struct ast_sorcery *sorcery, void *object)
Update an object.