Asterisk - The Open Source Telephony Project GIT-master-7e7a603
res_stasis_mailbox.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2014, Digium, Inc.
5 *
6 * Jonathan Rose <jrose@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*** MODULEINFO
20 <depend type="module">res_stasis</depend>
21 <depend type="module">res_mwi_external</depend>
22 <support_level>core</support_level>
23 ***/
24
25#include "asterisk.h"
26
27#include "asterisk/astdb.h"
28#include "asterisk/astobj2.h"
29#include "asterisk/module.h"
33
34/*! Number of hash buckets for mailboxes */
35#define MAILBOX_BUCKETS 37
36
38 const struct ast_mwi_mailbox_object *mailbox)
39{
40 return ast_json_pack("{s: s, s: i, s: i}",
43 "new_messages", ast_mwi_mailbox_get_msgs_new(mailbox));
44}
45
47 const char *name, struct ast_json **json)
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}
67
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}
100
102 const char *name, int old_messages, int new_messages)
103{
105 int res = 0;
106
108 if (!mailbox) {
109 return -1;
110 }
114 res = -1;
115 }
116
118
119 return res;
120}
121
123 const char *name)
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}
143
144static int load_module(void)
145{
147}
148
149static int unload_module(void)
150{
151 return 0;
152}
153
154AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Stasis application mailbox support",
155 .support_level = AST_MODULE_SUPPORT_CORE,
156 .load = load_module,
157 .unload = unload_module,
158 .requires = "res_stasis,res_mwi_external"
Persistent data storage (akin to *doze registry)
Asterisk main include file. File version handling, generic pbx functions.
#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 const char name[]
Definition: format_mp3.c:68
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_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:612
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
Definition: json.c:362
Asterisk module definitions.
@ AST_MODFLAG_GLOBAL_SYMBOLS
Definition: module.h:316
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:543
@ AST_MODULE_SUPPORT_CORE
Definition: module.h:121
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
static struct stasis_rest_handlers mailboxes
REST handler for /api-docs/mailboxes.json.
Core external MWI support.
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.
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.
const char * ast_mwi_mailbox_get_id(const struct ast_mwi_mailbox_object *mailbox)
Get mailbox id.
unsigned int ast_mwi_mailbox_get_msgs_old(const struct ast_mwi_mailbox_object *mailbox)
Get the number of old messages.
void ast_mwi_mailbox_set_msgs_new(struct ast_mwi_mailbox_object *mailbox, unsigned int num_msgs)
Set the number of new messages.
struct ao2_container * ast_mwi_mailbox_get_all(void)
Get all external MWI objects.
unsigned int ast_mwi_mailbox_get_msgs_new(const struct ast_mwi_mailbox_object *mailbox)
Get the number of new messages.
#define ast_mwi_mailbox_unref(mailbox)
Convenience unref function for mailbox object.
void ast_mwi_mailbox_set_msgs_old(struct ast_mwi_mailbox_object *mailbox, unsigned int num_msgs)
Set the number of old messages.
static struct ast_json * mailbox_to_json(const struct ast_mwi_mailbox_object *mailbox)
enum stasis_mailbox_result stasis_app_mailbox_delete(const char *name)
Delete a mailbox controlled by ARI.
enum stasis_mailbox_result stasis_app_mailbox_to_json(const char *name, struct ast_json **json)
Convert mailbox to JSON.
int stasis_app_mailbox_update(const char *name, int old_messages, int new_messages)
Changes the state of a mailbox.
struct ast_json * stasis_app_mailboxes_to_json()
Convert mailboxes to json array.
static int load_module(void)
static int unload_module(void)
#define NULL
Definition: resample.c:96
Backend API for implementing components of res_stasis.
Stasis Application Mailbox API. See StasisApplication API" for detailed documentation.
stasis_mailbox_result
@ STASIS_MAILBOX_MISSING
@ STASIS_MAILBOX_ERROR
@ STASIS_MAILBOX_OK
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
Abstract JSON element (object, array, string, int, ...).