Asterisk - The Open Source Telephony Project  18.5.0
Functions
resource_mailboxes.c File Reference

/api-docs/mailboxes.{format} implementation- Mailboxes resources More...

#include "asterisk.h"
#include "asterisk/stasis_app_mailbox.h"
#include "resource_mailboxes.h"
Include dependency graph for resource_mailboxes.c:

Go to the source code of this file.

Functions

void ast_ari_mailboxes_delete (struct ast_variable *headers, struct ast_ari_mailboxes_delete_args *args, struct ast_ari_response *response)
 Destroy a mailbox. More...
 
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. More...
 
void ast_ari_mailboxes_list (struct ast_variable *headers, struct ast_ari_mailboxes_list_args *args, struct ast_ari_response *response)
 List all mailboxes. More...
 
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). More...
 

Detailed Description

/api-docs/mailboxes.{format} implementation- Mailboxes resources

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

Definition in file resource_mailboxes.c.

Function Documentation

◆ ast_ari_mailboxes_delete()

void ast_ari_mailboxes_delete ( struct ast_variable headers,
struct ast_ari_mailboxes_delete_args args,
struct ast_ari_response response 
)

Destroy a mailbox.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 79 of file resource_mailboxes.c.

References ast_ari_response_error(), ast_ari_response_no_content(), ast_ari_mailboxes_delete_args::mailbox_name, stasis_app_mailbox_delete(), STASIS_MAILBOX_ERROR, STASIS_MAILBOX_MISSING, and STASIS_MAILBOX_OK.

Referenced by ast_ari_mailboxes_delete_cb().

82 {
83  switch (stasis_app_mailbox_delete(args->mailbox_name)) {
85  ast_ari_response_error(response, 404,
86  "Not Found", "Mailbox does not exist");
87  return;
89  ast_ari_response_error(response, 500,
90  "INternal Server Error", "Failed to delete the mailbox");
91  return;
92  case STASIS_MAILBOX_OK:
94  }
95 }
enum stasis_mailbox_result stasis_app_mailbox_delete(const char *name)
Delete a mailbox controlled by ARI.
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
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284

◆ ast_ari_mailboxes_get()

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 49 of file resource_mailboxes.c.

References ast_ari_response_error(), ast_ari_response_ok(), ast_ari_mailboxes_get_args::mailbox_name, stasis_app_mailbox_to_json(), STASIS_MAILBOX_ERROR, STASIS_MAILBOX_MISSING, and STASIS_MAILBOX_OK.

Referenced by ast_ari_mailboxes_get_cb().

52 {
53  struct ast_json *json;
54 
55  switch (stasis_app_mailbox_to_json(args->mailbox_name, &json)) {
57  ast_ari_response_error(response, 404,
58  "Not Found", "Mailbox is does not exist");
59  return;
61  ast_ari_response_error(response, 500,
62  "Internal Server Error", "Error building response");
63  return;
64  case STASIS_MAILBOX_OK:
65  ast_ari_response_ok(response, json);
66  }
67 }
enum stasis_mailbox_result stasis_app_mailbox_to_json(const char *name, struct ast_json **json)
Convert mailbox to JSON.
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
Definition: res_ari.c:276
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
Abstract JSON element (object, array, string, int, ...).

◆ ast_ari_mailboxes_list()

void ast_ari_mailboxes_list ( struct ast_variable headers,
struct ast_ari_mailboxes_list_args args,
struct ast_ari_response response 
)

List all mailboxes.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 35 of file resource_mailboxes.c.

References ast_ari_response_error(), ast_ari_response_ok(), and stasis_app_mailboxes_to_json().

Referenced by ast_ari_mailboxes_list_cb().

38 {
39  struct ast_json *json;
40 
41  if (!(json = stasis_app_mailboxes_to_json())) {
42  ast_ari_response_error(response, 500,
43  "Internal Server Error", "Error building response");
44  return;
45  }
46 
47  ast_ari_response_ok(response, json);
48 }
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
Definition: res_ari.c:276
struct ast_json * stasis_app_mailboxes_to_json(void)
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
Abstract JSON element (object, array, string, int, ...).

◆ ast_ari_mailboxes_update()

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).

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 68 of file resource_mailboxes.c.

References ast_ari_response_error(), ast_ari_response_no_content(), ast_ari_mailboxes_update_args::mailbox_name, ast_ari_mailboxes_update_args::new_messages, ast_ari_mailboxes_update_args::old_messages, and stasis_app_mailbox_update().

Referenced by ast_ari_mailboxes_update_cb().

71 {
73  ast_ari_response_error(response, 500, "Internal Server Error", "Error updating mailbox");
74  return;
75  }
76 
78 }
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
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
int stasis_app_mailbox_update(const char *name, int old_messages, int new_messages)
Changes the state of a mailbox.