Asterisk - The Open Source Telephony Project GIT-master-f36a736
Enumerations | Functions
stasis_app_mailbox.h File Reference

Stasis Application Mailbox API. See StasisApplication API" for detailed documentation. More...

#include "asterisk/app.h"
#include "asterisk/stasis_app.h"
Include dependency graph for stasis_app_mailbox.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  stasis_mailbox_result { STASIS_MAILBOX_OK , STASIS_MAILBOX_MISSING , STASIS_MAILBOX_ERROR }
 

Functions

enum stasis_mailbox_result stasis_app_mailbox_delete (const char *name)
 Delete a mailbox controlled by ARI. More...
 
enum stasis_mailbox_result stasis_app_mailbox_to_json (const char *name, struct ast_json **json)
 Convert mailbox to JSON. More...
 
int stasis_app_mailbox_update (const char *name, int old_messages, int new_messages)
 Changes the state of a mailbox. More...
 
struct ast_jsonstasis_app_mailboxes_to_json (void)
 Convert mailboxes to json array. More...
 

Detailed Description

Stasis Application Mailbox API. See StasisApplication API" for detailed documentation.

Author
Jonathan Rose kharw.nosp@m.ell@.nosp@m.digiu.nosp@m.m.co.nosp@m.m
Since
12

Definition in file stasis_app_mailbox.h.

Enumeration Type Documentation

◆ stasis_mailbox_result

Stasis mailbox operation result codes

Enumerator
STASIS_MAILBOX_OK 

Mailbox operation completed successfully

STASIS_MAILBOX_MISSING 

Mailbox of the requested name does not exist

STASIS_MAILBOX_ERROR 

Mailbox operation failed internally

Definition at line 35 of file stasis_app_mailbox.h.

35 {
36 /*! Mailbox operation completed successfully */
38 /*! Mailbox of the requested name does not exist */
40 /*! Mailbox operation failed internally */
42};
@ STASIS_MAILBOX_MISSING
@ STASIS_MAILBOX_ERROR
@ STASIS_MAILBOX_OK

Function Documentation

◆ stasis_app_mailbox_delete()

enum stasis_mailbox_result stasis_app_mailbox_delete ( const char *  name)

Delete a mailbox controlled by ARI.

Parameters
namethe name of the ARI controlled mailbox
Returns
a stasis mailbox application result

Definition at line 122 of file res_stasis_mailbox.c.

124{
125 const struct ast_mwi_mailbox_object *mailbox;
126
127 /* Make sure the mailbox actually exists before we delete it */
129 if (!mailbox) {
131 }
132
134 mailbox = NULL;
135
136 /* Now delete the mailbox */
139 }
140
141 return STASIS_MAILBOX_OK;
142}
static const char name[]
Definition: format_mp3.c:68
int ast_mwi_mailbox_delete(const char *mailbox_id)
Delete matching external MWI object.
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.
#define NULL
Definition: resample.c:96

References ast_mwi_mailbox_delete(), ast_mwi_mailbox_get(), ast_mwi_mailbox_unref, voicemailpwcheck::mailbox, name, NULL, STASIS_MAILBOX_ERROR, STASIS_MAILBOX_MISSING, and STASIS_MAILBOX_OK.

Referenced by ast_ari_mailboxes_delete().

◆ stasis_app_mailbox_to_json()

enum stasis_mailbox_result stasis_app_mailbox_to_json ( const char *  name,
struct ast_json **  json 
)

Convert mailbox to JSON.

Parameters
namethe name of the mailbox
jsonIf the query is successful, this pointer at this address will be set to the JSON representation of the mailbox
Returns
stasis mailbox result code indicating success or failure and cause
Return values
NULLon error.

Definition at line 46 of file res_stasis_mailbox.c.

48{
49 struct ast_json *mailbox_json;
50 const struct ast_mwi_mailbox_object *mailbox;
51
53 if (!mailbox) {
55 }
56
57 mailbox_json = mailbox_to_json(mailbox);
58 if (!mailbox_json) {
61 }
62
63 *json = mailbox_json;
64
65 return STASIS_MAILBOX_OK;
66}
static struct ast_json * mailbox_to_json(const struct ast_mwi_mailbox_object *mailbox)
Abstract JSON element (object, array, string, int, ...).

References ast_mwi_mailbox_get(), ast_mwi_mailbox_unref, voicemailpwcheck::mailbox, mailbox_to_json(), name, STASIS_MAILBOX_ERROR, STASIS_MAILBOX_MISSING, and STASIS_MAILBOX_OK.

Referenced by ast_ari_mailboxes_get().

◆ stasis_app_mailbox_update()

int stasis_app_mailbox_update ( const char *  name,
int  old_messages,
int  new_messages 
)

Changes the state of a mailbox.

Note
Implicitly creates the mailbox.
Parameters
nameThe name of the ARI controlled mailbox
old_messagescount of old (read) messages in the mailbox
new_messagescount of new (unread) messages in the mailbox
Return values
0if successful
-1on internal error.

Definition at line 101 of file res_stasis_mailbox.c.

103{
105 int res = 0;
106
108 if (!mailbox) {
109 return -1;
110 }
114 res = -1;
115 }
116
118
119 return res;
120}
int ast_mwi_mailbox_update(struct ast_mwi_mailbox_object *mailbox)
Update the external MWI counts with the given object.
struct ast_mwi_mailbox_object * ast_mwi_mailbox_alloc(const char *mailbox_id)
Allocate an external MWI object.
void ast_mwi_mailbox_set_msgs_new(struct ast_mwi_mailbox_object *mailbox, unsigned int num_msgs)
Set the number of new messages.
void ast_mwi_mailbox_set_msgs_old(struct ast_mwi_mailbox_object *mailbox, unsigned int num_msgs)
Set the number of old messages.

References ast_mwi_mailbox_alloc(), ast_mwi_mailbox_set_msgs_new(), ast_mwi_mailbox_set_msgs_old(), ast_mwi_mailbox_unref, ast_mwi_mailbox_update(), voicemailpwcheck::mailbox, and name.

Referenced by ast_ari_mailboxes_update().

◆ stasis_app_mailboxes_to_json()

struct ast_json * stasis_app_mailboxes_to_json ( void  )

Convert mailboxes to json array.

Returns
JSON representation of the mailboxes
Return values
NULLon error.

Definition at line 68 of file res_stasis_mailbox.c.

69{
72 struct ao2_iterator iter;
73 const struct ast_mwi_mailbox_object *mailbox;
74
75 if (!array) {
76 return NULL;
77 }
78
80 if (!mailboxes) {
82 return NULL;
83 }
84
87 struct ast_json *appending = mailbox_to_json(mailbox);
88 if (!appending || ast_json_array_append(array, appending)) {
89 /* Failed to append individual mailbox to the array. Abort. */
91 array = NULL;
92 break;
93 }
94 }
96 ao2_ref(mailboxes, -1);
97
98 return array;
99}
#define ao2_iterator_next(iter)
Definition: astobj2.h:1911
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
static int array(struct ast_channel *chan, const char *cmd, char *var, const char *value)
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
Definition: json.c:378
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
Definition: json.c:362
static struct stasis_rest_handlers mailboxes
REST handler for /api-docs/mailboxes.json.
struct ao2_container * ast_mwi_mailbox_get_all(void)
Get all external MWI objects.
Generic container type.
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_ref, array(), ast_json_array_append(), ast_json_array_create(), ast_json_unref(), ast_mwi_mailbox_get_all(), ast_mwi_mailbox_unref, voicemailpwcheck::mailbox, mailbox_to_json(), mailboxes, and NULL.

Referenced by ast_ari_mailboxes_list().