Asterisk - The Open Source Telephony Project GIT-master-a358458
Macros | Functions | Variables
res_ari_mailboxes.c File Reference

Mailboxes resources. More...

#include "asterisk.h"
#include "asterisk/app.h"
#include "asterisk/module.h"
#include "asterisk/stasis_app.h"
#include "ari/resource_mailboxes.h"
Include dependency graph for res_ari_mailboxes.c:

Go to the source code of this file.

Macros

#define MAX_VALS   128
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static void ast_ari_mailboxes_delete_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /mailboxes/{mailboxName}. More...
 
static void ast_ari_mailboxes_get_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /mailboxes/{mailboxName}. More...
 
static void ast_ari_mailboxes_list_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /mailboxes. More...
 
static void ast_ari_mailboxes_update_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /mailboxes/{mailboxName}. More...
 
int ast_ari_mailboxes_update_parse_body (struct ast_json *body, struct ast_ari_mailboxes_update_args *args)
 Body parsing function for /mailboxes/{mailboxName}. More...
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "RESTful API module - Mailboxes resources" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_ari,res_ari_model,res_stasis,res_stasis_mailbox", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct stasis_rest_handlers mailboxes
 REST handler for /api-docs/mailboxes.json. More...
 
static struct stasis_rest_handlers mailboxes_mailboxName
 REST handler for /api-docs/mailboxes.json. More...
 

Detailed Description

Mailboxes resources.

Author
Jonathan Rose jrose.nosp@m.@dig.nosp@m.ium.c.nosp@m.om

Definition in file res_ari_mailboxes.c.

Macro Definition Documentation

◆ MAX_VALS

#define MAX_VALS   128

Definition at line 52 of file res_ari_mailboxes.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 364 of file res_ari_mailboxes.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 364 of file res_ari_mailboxes.c.

◆ ast_ari_mailboxes_delete_cb()

static void ast_ari_mailboxes_delete_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /mailboxes/{mailboxName}.

Parameters
serTCP/TLS session object
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
body
[out]responseResponse to the HTTP request.

Definition at line 265 of file res_ari_mailboxes.c.

269{
271 struct ast_variable *i;
272#if defined(AST_DEVMODE)
273 int is_valid;
274 int code;
275#endif /* AST_DEVMODE */
276
277 for (i = path_vars; i; i = i->next) {
278 if (strcmp(i->name, "mailboxName") == 0) {
279 args.mailbox_name = (i->value);
280 } else
281 {}
282 }
283 ast_ari_mailboxes_delete(headers, &args, response);
284#if defined(AST_DEVMODE)
285 code = response->response_code;
286
287 switch (code) {
288 case 0: /* Implementation is still a stub, or the code wasn't set */
289 is_valid = response->message == NULL;
290 break;
291 case 500: /* Internal Server Error */
292 case 501: /* Not Implemented */
293 case 404: /* Mailbox not found */
294 is_valid = 1;
295 break;
296 default:
297 if (200 <= code && code <= 299) {
298 is_valid = ast_ari_validate_void(
299 response->message);
300 } else {
301 ast_log(LOG_ERROR, "Invalid error response %d for /mailboxes/{mailboxName}\n", code);
302 is_valid = 0;
303 }
304 }
305
306 if (!is_valid) {
307 ast_log(LOG_ERROR, "Response validation failed for /mailboxes/{mailboxName}\n");
308 ast_ari_response_error(response, 500,
309 "Internal Server Error", "Response validation failed");
310 }
311#endif /* AST_DEVMODE */
312
313fin: __attribute__((unused))
314 return;
315}
void ast_ari_response_error(struct ast_ari_response *response, int response_code, const char *response_text, const char *message_fmt,...)
Fill in an error ast_ari_response.
Definition: res_ari.c:259
int ast_ari_validate_void(struct ast_json *json)
Validator for native Swagger void.
Definition: res_ari_model.c:91
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
#define NULL
Definition: resample.c:96
void ast_ari_mailboxes_delete(struct ast_variable *headers, struct ast_ari_mailboxes_delete_args *args, struct ast_ari_response *response)
Destroy a mailbox.
struct ast_json * message
Definition: ari.h:94
int response_code
Definition: ari.h:99
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
const char * args

References args, ast_ari_mailboxes_delete(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

◆ ast_ari_mailboxes_get_cb()

static void ast_ari_mailboxes_get_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /mailboxes/{mailboxName}.

Parameters
serTCP/TLS session object
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
body
[out]responseResponse to the HTTP request.

Definition at line 115 of file res_ari_mailboxes.c.

119{
121 struct ast_variable *i;
122#if defined(AST_DEVMODE)
123 int is_valid;
124 int code;
125#endif /* AST_DEVMODE */
126
127 for (i = path_vars; i; i = i->next) {
128 if (strcmp(i->name, "mailboxName") == 0) {
129 args.mailbox_name = (i->value);
130 } else
131 {}
132 }
133 ast_ari_mailboxes_get(headers, &args, response);
134#if defined(AST_DEVMODE)
135 code = response->response_code;
136
137 switch (code) {
138 case 0: /* Implementation is still a stub, or the code wasn't set */
139 is_valid = response->message == NULL;
140 break;
141 case 500: /* Internal Server Error */
142 case 501: /* Not Implemented */
143 case 404: /* Mailbox not found */
144 is_valid = 1;
145 break;
146 default:
147 if (200 <= code && code <= 299) {
148 is_valid = ast_ari_validate_mailbox(
149 response->message);
150 } else {
151 ast_log(LOG_ERROR, "Invalid error response %d for /mailboxes/{mailboxName}\n", code);
152 is_valid = 0;
153 }
154 }
155
156 if (!is_valid) {
157 ast_log(LOG_ERROR, "Response validation failed for /mailboxes/{mailboxName}\n");
158 ast_ari_response_error(response, 500,
159 "Internal Server Error", "Response validation failed");
160 }
161#endif /* AST_DEVMODE */
162
163fin: __attribute__((unused))
164 return;
165}
int ast_ari_validate_mailbox(struct ast_json *json)
Validator for Mailbox.
void ast_ari_mailboxes_get(struct ast_variable *headers, struct ast_ari_mailboxes_get_args *args, struct ast_ari_response *response)
Retrieve the current state of a mailbox.

References args, ast_ari_mailboxes_get(), ast_ari_response_error(), ast_ari_validate_mailbox(), ast_log, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

◆ ast_ari_mailboxes_list_cb()

static void ast_ari_mailboxes_list_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /mailboxes.

Parameters
serTCP/TLS session object
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
body
[out]responseResponse to the HTTP request.

Definition at line 63 of file res_ari_mailboxes.c.

67{
69#if defined(AST_DEVMODE)
70 int is_valid;
71 int code;
72#endif /* AST_DEVMODE */
73
74 ast_ari_mailboxes_list(headers, &args, response);
75#if defined(AST_DEVMODE)
76 code = response->response_code;
77
78 switch (code) {
79 case 0: /* Implementation is still a stub, or the code wasn't set */
80 is_valid = response->message == NULL;
81 break;
82 case 500: /* Internal Server Error */
83 case 501: /* Not Implemented */
84 is_valid = 1;
85 break;
86 default:
87 if (200 <= code && code <= 299) {
88 is_valid = ast_ari_validate_list(response->message,
90 } else {
91 ast_log(LOG_ERROR, "Invalid error response %d for /mailboxes\n", code);
92 is_valid = 0;
93 }
94 }
95
96 if (!is_valid) {
97 ast_log(LOG_ERROR, "Response validation failed for /mailboxes\n");
98 ast_ari_response_error(response, 500,
99 "Internal Server Error", "Response validation failed");
100 }
101#endif /* AST_DEVMODE */
102
103fin: __attribute__((unused))
104 return;
105}
ari_validator ast_ari_validate_mailbox_fn(void)
Function pointer to ast_ari_validate_mailbox().
int ast_ari_validate_list(struct ast_json *json, int(*fn)(struct ast_json *))
Validator for a Swagger List[]/JSON array.
void ast_ari_mailboxes_list(struct ast_variable *headers, struct ast_ari_mailboxes_list_args *args, struct ast_ari_response *response)
List all mailboxes.

References args, ast_ari_mailboxes_list(), ast_ari_response_error(), ast_ari_validate_list(), ast_ari_validate_mailbox_fn(), ast_log, LOG_ERROR, ast_ari_response::message, NULL, and ast_ari_response::response_code.

◆ ast_ari_mailboxes_update_cb()

static void ast_ari_mailboxes_update_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /mailboxes/{mailboxName}.

Parameters
serTCP/TLS session object
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
body
[out]responseResponse to the HTTP request.

Definition at line 192 of file res_ari_mailboxes.c.

196{
198 struct ast_variable *i;
199#if defined(AST_DEVMODE)
200 int is_valid;
201 int code;
202#endif /* AST_DEVMODE */
203
204 for (i = get_params; i; i = i->next) {
205 if (strcmp(i->name, "oldMessages") == 0) {
206 args.old_messages = atoi(i->value);
207 } else
208 if (strcmp(i->name, "newMessages") == 0) {
209 args.new_messages = atoi(i->value);
210 } else
211 {}
212 }
213 for (i = path_vars; i; i = i->next) {
214 if (strcmp(i->name, "mailboxName") == 0) {
215 args.mailbox_name = (i->value);
216 } else
217 {}
218 }
221 goto fin;
222 }
223 ast_ari_mailboxes_update(headers, &args, response);
224#if defined(AST_DEVMODE)
225 code = response->response_code;
226
227 switch (code) {
228 case 0: /* Implementation is still a stub, or the code wasn't set */
229 is_valid = response->message == NULL;
230 break;
231 case 500: /* Internal Server Error */
232 case 501: /* Not Implemented */
233 case 404: /* Mailbox not found */
234 is_valid = 1;
235 break;
236 default:
237 if (200 <= code && code <= 299) {
238 is_valid = ast_ari_validate_void(
239 response->message);
240 } else {
241 ast_log(LOG_ERROR, "Invalid error response %d for /mailboxes/{mailboxName}\n", code);
242 is_valid = 0;
243 }
244 }
245
246 if (!is_valid) {
247 ast_log(LOG_ERROR, "Response validation failed for /mailboxes/{mailboxName}\n");
248 ast_ari_response_error(response, 500,
249 "Internal Server Error", "Response validation failed");
250 }
251#endif /* AST_DEVMODE */
252
253fin: __attribute__((unused))
254 return;
255}
void ast_ari_response_alloc_failed(struct ast_ari_response *response)
Fill in response with a 500 message for allocation failures.
Definition: res_ari.c:298
int ast_ari_mailboxes_update_parse_body(struct ast_json *body, struct ast_ari_mailboxes_update_args *args)
Body parsing function for /mailboxes/{mailboxName}.
void ast_ari_mailboxes_update(struct ast_variable *headers, struct ast_ari_mailboxes_update_args *args, struct ast_ari_response *response)
Change the state of a mailbox. (Note - implicitly creates the mailbox).

References args, ast_ari_mailboxes_update(), ast_ari_mailboxes_update_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

◆ ast_ari_mailboxes_update_parse_body()

int ast_ari_mailboxes_update_parse_body ( struct ast_json body,
struct ast_ari_mailboxes_update_args args 
)

Body parsing function for /mailboxes/{mailboxName}.

Parameters
bodyThe JSON body from which to parse parameters.
[out]argsThe args structure to parse into.
Return values
zeroon success
non-zeroon failure

Definition at line 166 of file res_ari_mailboxes.c.

169{
170 struct ast_json *field;
171 /* Parse query parameters out of it */
172 field = ast_json_object_get(body, "oldMessages");
173 if (field) {
174 args->old_messages = ast_json_integer_get(field);
175 }
176 field = ast_json_object_get(body, "newMessages");
177 if (field) {
178 args->new_messages = ast_json_integer_get(field);
179 }
180 return 0;
181}
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:407
intmax_t ast_json_integer_get(const struct ast_json *integer)
Get the value from a JSON integer.
Definition: json.c:332
Abstract JSON element (object, array, string, int, ...).

References args, ast_json_integer_get(), and ast_json_object_get().

Referenced by ast_ari_mailboxes_update_cb().

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 364 of file res_ari_mailboxes.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 345 of file res_ari_mailboxes.c.

346{
347 int res = 0;
348
349
351 if (res) {
354 }
355
357}
int ast_ari_add_handler(struct stasis_rest_handlers *handler)
Definition: res_ari.c:179
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static struct stasis_rest_handlers mailboxes
REST handler for /api-docs/mailboxes.json.
static int unload_module(void)

References ast_ari_add_handler(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, mailboxes, and unload_module().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 339 of file res_ari_mailboxes.c.

340{
342 return 0;
343}
int ast_ari_remove_handler(struct stasis_rest_handlers *handler)
Definition: res_ari.c:202

References ast_ari_remove_handler(), and mailboxes.

Referenced by load_module().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "RESTful API module - Mailboxes resources" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_ari,res_ari_model,res_stasis,res_stasis_mailbox", }
static

Definition at line 364 of file res_ari_mailboxes.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 364 of file res_ari_mailboxes.c.

◆ mailboxes

struct stasis_rest_handlers mailboxes
static

◆ mailboxes_mailboxName

struct stasis_rest_handlers mailboxes_mailboxName
static

REST handler for /api-docs/mailboxes.json.

Definition at line 318 of file res_ari_mailboxes.c.