Asterisk - The Open Source Telephony Project  21.4.1
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"

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 = "da6642af068ee5e6490c5b1d2cc1d238" , .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.
 
static struct stasis_rest_handlers mailboxes_mailboxName
 REST handler for /api-docs/mailboxes.json.
 

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.

Function Documentation

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.

References ast_ari_mailboxes_delete(), ast_ari_response_error(), ast_ari_validate_void(), ast_ari_mailboxes_delete_args::mailbox_name, ast_ari_response::message, ast_variable::name, ast_variable::next, ast_ari_response::response_code, and ast_variable::value.

269 {
270  struct ast_ari_mailboxes_delete_args args = {};
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 
313 fin: __attribute__((unused))
314  return;
315 }
struct ast_variable * next
void ast_ari_mailboxes_delete(struct ast_variable *headers, struct ast_ari_mailboxes_delete_args *args, struct ast_ari_response *response)
Destroy a mailbox.
Structure for variables, used for configurations and for channel variables.
int ast_ari_validate_void(struct ast_json *json)
Validator for native Swagger void.
Definition: res_ari_model.c:91
int response_code
Definition: ari.h:99
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
struct ast_json * message
Definition: ari.h:94
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.

References ast_ari_mailboxes_get(), ast_ari_response_error(), ast_ari_validate_mailbox(), ast_ari_mailboxes_get_args::mailbox_name, ast_ari_response::message, ast_variable::name, ast_variable::next, ast_ari_response::response_code, and ast_variable::value.

119 {
120  struct ast_ari_mailboxes_get_args args = {};
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 
163 fin: __attribute__((unused))
164  return;
165 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
int response_code
Definition: ari.h:99
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
struct ast_json * message
Definition: ari.h:94
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.
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.

References ast_ari_mailboxes_list(), ast_ari_response_error(), ast_ari_validate_list(), ast_ari_validate_mailbox_fn(), ast_ari_response::message, and ast_ari_response::response_code.

67 {
68  struct ast_ari_mailboxes_list_args args = {};
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 
103 fin: __attribute__((unused))
104  return;
105 }
ari_validator ast_ari_validate_mailbox_fn(void)
Function pointer to ast_ari_validate_mailbox().
int response_code
Definition: ari.h:99
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
struct ast_json * message
Definition: ari.h:94
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.
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.

References ast_ari_mailboxes_update(), ast_ari_mailboxes_update_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_void(), ast_ari_mailboxes_update_args::mailbox_name, ast_ari_response::message, ast_variable::name, ast_ari_mailboxes_update_args::new_messages, ast_variable::next, ast_ari_mailboxes_update_args::old_messages, ast_ari_response::response_code, and ast_variable::value.

196 {
197  struct ast_ari_mailboxes_update_args args = {};
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  }
219  if (ast_ari_mailboxes_update_parse_body(body, &args)) {
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 
253 fin: __attribute__((unused))
254  return;
255 }
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).
struct ast_variable * next
int ast_ari_mailboxes_update_parse_body(struct ast_json *body, struct ast_ari_mailboxes_update_args *args)
Body parsing function for /mailboxes/{mailboxName}.
Structure for variables, used for configurations and for channel variables.
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_validate_void(struct ast_json *json)
Validator for native Swagger void.
Definition: res_ari_model.c:91
int response_code
Definition: ari.h:99
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
struct ast_json * message
Definition: ari.h:94
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.

References ast_json_integer_get(), ast_json_object_get(), ast_ari_mailboxes_update_args::new_messages, and ast_ari_mailboxes_update_args::old_messages.

Referenced by ast_ari_mailboxes_update_cb().

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
Abstract JSON element (object, array, string, int, ...).
intmax_t ast_json_integer_get(const struct ast_json *integer)
Get the value from a JSON integer.
Definition: json.c:332