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

Core external MWI support. More...

Go to the source code of this file.

Macros

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

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.

Function Documentation

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.

References ast_sorcery_alloc().

Referenced by stasis_app_mailbox_update().

193 {
194  if (ast_strlen_zero(mailbox_id)) {
195  return NULL;
196  }
197 
198  return ast_sorcery_alloc(mwi_sorcery, MWI_MAILBOX_TYPE, mailbox_id);
199 }
void * ast_sorcery_alloc(const struct ast_sorcery *sorcery, const char *type, const char *id)
Allocate an object.
Definition: sorcery.c:1744
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.

References ast_sorcery_copy().

202 {
203  return ast_sorcery_copy(mwi_sorcery, mailbox);
204 }
void * ast_sorcery_copy(const struct ast_sorcery *sorcery, const void *object)
Create a copy of an object.
Definition: sorcery.c:1778
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.

References ast_mwi_mailbox_get(), and ast_mwi_mailbox_unref.

Referenced by stasis_app_mailbox_delete().

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) {
312  mwi_mailbox_delete((struct ast_mwi_mailbox_object *) mailbox);
313  ast_mwi_mailbox_unref(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.
#define ast_mwi_mailbox_unref(mailbox)
Convenience unref function for mailbox object.
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.

References ao2_ref, ast_mwi_mailbox_get_all(), and mailboxes.

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

References ao2_ref, ast_mwi_mailbox_get_by_regex(), and mailboxes.

291 {
292  struct ao2_container *mailboxes;
293 
294  mailboxes = ast_mwi_mailbox_get_by_regex(regex);
295  if (mailboxes) {
296  mwi_mailbox_delete_all(mailboxes);
297  ao2_ref(mailboxes, -1);
298  }
299  return 0;
300 }
static struct stasis_rest_handlers mailboxes
REST handler for /api-docs/mailboxes.json.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
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.
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.

References ast_sorcery_retrieve_by_id().

Referenced by ast_mwi_mailbox_delete(), stasis_app_mailbox_delete(), and stasis_app_mailbox_to_json().

184 {
185  if (ast_strlen_zero(mailbox_id)) {
186  return NULL;
187  }
188 
189  return ast_sorcery_retrieve_by_id(mwi_sorcery, MWI_MAILBOX_TYPE, mailbox_id);
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
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.

References AST_RETRIEVE_FLAG_ALL, AST_RETRIEVE_FLAG_MULTIPLE, and ast_sorcery_retrieve_by_fields().

Referenced by ast_mwi_mailbox_delete_all(), and stasis_app_mailboxes_to_json().

173 {
174  return ast_sorcery_retrieve_by_fields(mwi_sorcery, MWI_MAILBOX_TYPE,
176 }
Perform no matching, return all objects.
Definition: sorcery.h:123
Return all matching objects.
Definition: sorcery.h:120
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
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.

References ast_sorcery_retrieve_by_regex().

Referenced by ast_mwi_mailbox_delete_by_regex().

179 {
180  return ast_sorcery_retrieve_by_regex(mwi_sorcery, MWI_MAILBOX_TYPE, regex ?: "");
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
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.

References ast_sorcery_object_get_id().

207 {
208  return ast_sorcery_object_get_id(mailbox);
209 }
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2317
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.

References ast_mwi_mailbox_object::msgs_new.

212 {
213  return mailbox->msgs_new;
214 }
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.

References ast_mwi_mailbox_object::msgs_old.

217 {
218  return mailbox->msgs_old;
219 }
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.

References ast_mwi_mailbox_object::msgs_new.

Referenced by stasis_app_mailbox_update().

222 {
223  mailbox->msgs_new = num_msgs;
224 }
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.

References ast_mwi_mailbox_object::msgs_old.

Referenced by stasis_app_mailbox_update().

227 {
228  mailbox->msgs_old = num_msgs;
229 }
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.

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

Referenced by stasis_app_mailbox_update().

232 {
233  const struct ast_mwi_mailbox_object *exists;
234  int res;
235 
236  exists = ast_sorcery_retrieve_by_id(mwi_sorcery, MWI_MAILBOX_TYPE,
237  ast_sorcery_object_get_id(mailbox));
238  if (exists) {
239  res = ast_sorcery_update(mwi_sorcery, mailbox);
240  ast_mwi_mailbox_unref(exists);
241  } else {
242  res = ast_sorcery_create(mwi_sorcery, mailbox);
243  }
244  return res;
245 }
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:2062
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition: sorcery.c:2317
#define ast_mwi_mailbox_unref(mailbox)
Convenience unref function for mailbox object.
int ast_sorcery_update(const struct ast_sorcery *sorcery, void *object)
Update an object.
Definition: sorcery.c:2150