Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions
res_mwi_external.h File Reference

Core external MWI support. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ast_mwi_mailbox_unref(mailbox)   ao2_ref((struct ast_mwi_mailbox_object *) mailbox, -1)
 Convienience unref function for mailbox object. More...
 

Functions

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...
 

Detailed Description

Core external MWI support.

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.h.

Macro Definition Documentation

◆ ast_mwi_mailbox_unref

#define ast_mwi_mailbox_unref (   mailbox)    ao2_ref((struct ast_mwi_mailbox_object *) mailbox, -1)

Function Documentation

◆ 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.
Return values
objecton success. The object is an ao2 object.
NULLon error.

Definition at line 196 of file res_mwi_external.c.

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

Referenced by mwi_mailbox_update(), and stasis_app_mailbox_update().

197 {
198  if (ast_strlen_zero(mailbox_id)) {
199  return NULL;
200  }
201 
202  return ast_sorcery_alloc(mwi_sorcery, MWI_MAILBOX_TYPE, mailbox_id);
203 }
static struct ast_sorcery * mwi_sorcery
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define MWI_MAILBOX_TYPE
void * ast_sorcery_alloc(const struct ast_sorcery *sorcery, const char *type, const char *id)
Allocate an object.
Definition: sorcery.c:1744

◆ 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.
Return values
copyon success. The object is an ao2 object.
NULLon error.

Definition at line 205 of file res_mwi_external.c.

References ast_sorcery_copy().

206 {
207  return ast_sorcery_copy(mwi_sorcery, mailbox);
208 }
static struct ast_sorcery * mwi_sorcery
void * ast_sorcery_copy(const struct ast_sorcery *sorcery, const void *object)
Create a copy of an object.
Definition: sorcery.c:1778

◆ 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 310 of file res_mwi_external.c.

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

Referenced by mwi_mailbox_delete(), and stasis_app_mailbox_delete().

311 {
312  const struct ast_mwi_mailbox_object *mailbox;
313 
314  if (ast_strlen_zero(mailbox_id)) {
315  return -1;
316  }
317 
318  mailbox = ast_mwi_mailbox_get(mailbox_id);
319  if (mailbox) {
320  mwi_mailbox_delete((struct ast_mwi_mailbox_object *) mailbox);
321  ast_mwi_mailbox_unref(mailbox);
322  }
323  return 0;
324 }
const struct ast_mwi_mailbox_object * ast_mwi_mailbox_get(const char *mailbox_id)
Get matching external MWI object.
#define ast_strlen_zero(foo)
Definition: strings.h:52
static char mailbox[AST_MAX_MAILBOX_UNIQUEID]
Definition: chan_mgcp.c:204
static void mwi_mailbox_delete(struct ast_mwi_mailbox_object *mailbox)
#define ast_mwi_mailbox_unref(mailbox)
Convienience unref function for mailbox object.

◆ 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 286 of file res_mwi_external.c.

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

287 {
288  struct ao2_container *mailboxes;
289 
290  mailboxes = ast_mwi_mailbox_get_all();
291  if (mailboxes) {
292  mwi_mailbox_delete_all(mailboxes);
293  ao2_ref(mailboxes, -1);
294  }
295  return 0;
296 }
static void mwi_mailbox_delete_all(struct ao2_container *mailboxes)
static struct stasis_rest_handlers mailboxes
REST handler for /api-docs/mailboxes.json.
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ao2_container * ast_mwi_mailbox_get_all(void)
Get all external MWI objects.
Generic container type.

◆ 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 298 of file res_mwi_external.c.

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

Referenced by mwi_mailbox_delete().

299 {
300  struct ao2_container *mailboxes;
301 
302  mailboxes = ast_mwi_mailbox_get_by_regex(regex);
303  if (mailboxes) {
304  mwi_mailbox_delete_all(mailboxes);
305  ao2_ref(mailboxes, -1);
306  }
307  return 0;
308 }
static void mwi_mailbox_delete_all(struct ao2_container *mailboxes)
static struct stasis_rest_handlers mailboxes
REST handler for /api-docs/mailboxes.json.
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:948
struct ao2_container * ast_mwi_mailbox_get_by_regex(const char *regex)
Get all external MWI objects selected by the regular expression.
Generic container type.

◆ 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.
Return values
requestedmailbox on success. The object is an ao2 object.
NULLon error or no mailbox.
Note
The object must be treated as read-only.

Definition at line 187 of file res_mwi_external.c.

References ast_sorcery_retrieve_by_id(), ast_strlen_zero, MWI_MAILBOX_TYPE, 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().

188 {
189  if (ast_strlen_zero(mailbox_id)) {
190  return NULL;
191  }
192 
194 }
static struct ast_sorcery * mwi_sorcery
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
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
#define MWI_MAILBOX_TYPE

◆ ast_mwi_mailbox_get_all()

struct ao2_container* ast_mwi_mailbox_get_all ( void  )

Get all external MWI objects.

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

Definition at line 176 of file res_mwi_external.c.

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

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

177 {
180 }
Perform no matching, return all objects.
Definition: sorcery.h:123
static struct ast_sorcery * mwi_sorcery
Return all matching objects.
Definition: sorcery.h:120
#define NULL
Definition: resample.c:96
#define MWI_MAILBOX_TYPE
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

◆ 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.
Return values
containerof struct ast_mwi_mailbox_object on success.
NULLon error.
Note
The objects in the container must be treated as read-only.

Definition at line 182 of file res_mwi_external.c.

References ast_sorcery_retrieve_by_regex(), and MWI_MAILBOX_TYPE.

Referenced by ast_mwi_mailbox_delete_by_regex(), and mwi_mailbox_get().

183 {
185 }
static struct ast_sorcery * mwi_sorcery
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:1949
#define MWI_MAILBOX_TYPE
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:948

◆ 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 210 of file res_mwi_external.c.

References ast_sorcery_object_get_id().

Referenced by mailbox_to_json(), and mwi_mailbox_get().

211 {
212  return ast_sorcery_object_get_id(mailbox);
213 }
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312

◆ 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 215 of file res_mwi_external.c.

References ast_mwi_mailbox_object::msgs_new.

Referenced by mailbox_to_json(), and mwi_mailbox_get().

216 {
217  return mailbox->msgs_new;
218 }

◆ 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 220 of file res_mwi_external.c.

References ast_mwi_mailbox_object::msgs_old.

Referenced by mailbox_to_json(), and mwi_mailbox_get().

221 {
222  return mailbox->msgs_old;
223 }

◆ 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.
Returns
Nothing

Definition at line 225 of file res_mwi_external.c.

References ast_mwi_mailbox_object::msgs_new.

Referenced by mwi_mailbox_update(), and stasis_app_mailbox_update().

226 {
227  mailbox->msgs_new = num_msgs;
228 }

◆ 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.
Returns
Nothing

Definition at line 230 of file res_mwi_external.c.

References ast_mwi_mailbox_object::msgs_old.

Referenced by mwi_mailbox_update(), and stasis_app_mailbox_update().

231 {
232  mailbox->msgs_old = num_msgs;
233 }

◆ 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 235 of file res_mwi_external.c.

References ast_mwi_mailbox_unref, ast_sorcery_create(), ast_sorcery_object_get_id(), ast_sorcery_retrieve_by_id(), ast_sorcery_update(), exists(), and MWI_MAILBOX_TYPE.

Referenced by mwi_mailbox_update(), and stasis_app_mailbox_update().

236 {
237  const struct ast_mwi_mailbox_object *exists;
238  int res;
239 
241  ast_sorcery_object_get_id(mailbox));
242  if (exists) {
243  res = ast_sorcery_update(mwi_sorcery, mailbox);
244  ast_mwi_mailbox_unref(exists);
245  } else {
246  res = ast_sorcery_create(mwi_sorcery, mailbox);
247  }
248  return res;
249 }
static int exists(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
Definition: func_logic.c:124
static struct ast_sorcery * mwi_sorcery
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
int ast_sorcery_create(const struct ast_sorcery *sorcery, void *object)
Create and potentially persist an object using an available wizard.
Definition: sorcery.c:2057
#define MWI_MAILBOX_TYPE
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2312
#define ast_mwi_mailbox_unref(mailbox)
Convienience unref function for mailbox object.
int ast_sorcery_update(const struct ast_sorcery *sorcery, void *object)
Update an object.
Definition: sorcery.c:2145