76 for (; get_params !=
NULL; get_params = get_params->
next) {
80 for (; path_vars !=
NULL; path_vars = path_vars->
next) {
84 for (; headers !=
NULL; headers = headers->
next) {
97 #define HANDLER(name, response_code) \ 98 static void name(struct ast_tcptls_session_instance *ser, \ 99 struct ast_variable *get_params, \ 100 struct ast_variable *path_vars, \ 101 struct ast_variable *headers, \ 102 struct ast_json *body, \ 103 struct ast_ari_response *response) \ 105 handler(#name, response_code, get_params, path_vars, headers, body, response); \ 140 .children = { &
bang }
206 const char *basePath;
210 info->name = __func__;
211 info->category =
"/res/ari/";
212 info->summary =
"Test simple API get.";
213 info->description =
"Test ARI binding logic.";
222 ast_test_validate(
test, 200 == response->response_code);
226 ast_test_validate(
test,
NULL != basePathJson);
228 ast_test_validate(
test, 0 == strcmp(
"http://stasis.asterisk.org/ari", basePath));
241 info->name = __func__;
242 info->category =
"/res/ari/";
243 info->summary =
"Test API get without a Host header";
244 info->description =
"Test ARI binding logic.";
252 ast_test_validate(
test, 200 == response->response_code);
256 ast_test_validate(
test,
NULL == basePathJson);
268 info->name = __func__;
269 info->category =
"/res/ari/";
270 info->summary =
"Test API get for invalid resource";
271 info->description =
"Test ARI binding logic.";
279 ast_test_validate(
test, 404 == response->response_code);
291 info->name = __func__;
292 info->category =
"/res/ari/";
293 info->summary =
"Test API get for a file outside the rest-api path";
294 info->description =
"Test ARI binding logic.";
302 ast_test_validate(
test, 404 == response->response_code);
317 info->name = __func__;
318 info->category =
"/res/ari/";
319 info->summary =
"Test simple GET of an HTTP resource.";
320 info->description =
"Test ARI binding logic.";
338 expected =
ast_json_pack(
"{s: s, s: {s: s, s: s}, s: {s: s, s: s}, s: {}}",
352 ast_test_validate(
test, 200 == response->response_code);
368 info->name = __func__;
369 info->category =
"/res/ari/";
370 info->summary =
"Test GET of a wildcard resource.";
371 info->description =
"Test ARI binding logic.";
390 ast_test_validate(
test, 200 == response->response_code);
406 info->name = __func__;
407 info->category =
"/res/ari/";
408 info->summary =
"Test DELETE of an HTTP resource.";
409 info->description =
"Test ARI binding logic.";
418 "name",
"bang_delete",
428 ast_test_validate(
test, 204 == response->response_code);
444 info->name = __func__;
445 info->category =
"/res/ari/";
446 info->summary =
"Test POST of an HTTP resource.";
447 info->description =
"Test ARI binding logic.";
465 expected =
ast_json_pack(
"{s: s, s: {s: s, s: s}, s: {s: s, s: s}, s: {}}",
479 ast_test_validate(
test, 200 == response->response_code);
494 info->name = __func__;
495 info->category =
"/res/ari/";
496 info->summary =
"Test POST on a resource that doesn't support it.";
497 info->description =
"Test ARI binding logic.";
509 ast_test_validate(
test, 405 == response->response_code);
523 info->name = __func__;
524 info->category =
"/res/ari/";
525 info->summary =
"Test GET on a resource that does not exist.";
526 info->description =
"Test ARI binding logic.";
538 ast_test_validate(
test, 404 == response->response_code);
577 .requires =
"res_ari",
struct ast_variable * next
static int unload_module(void)
Asterisk main include file. File version handling, generic pbx functions.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
void ast_ari_get_docs(const char *uri, const char *prefix, struct ast_variable *headers, struct ast_ari_response *response)
static struct ast_ari_response * response_alloc(void)
Structure for variables, used for configurations and for channel variables.
static struct stasis_rest_handlers bar
#define AST_TEST_REGISTER(cb)
#define HANDLER(name, response_code)
Asterisk RESTful API hooks.
static void tear_down_invocation_test(void *ignore)
void ast_ari_invoke(struct ast_tcptls_session_instance *ser, const char *uri, enum ast_http_method method, struct ast_variable *get_params, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
struct ast_json * ast_json_null(void)
Get the JSON null value.
static void * setup_invocation_test(void)
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
#define ast_variable_new(name, value, filename)
static int load_module(void)
int ast_ari_add_handler(struct stasis_rest_handlers *handler)
#define AST_TEST_UNREGISTER(cb)
static void response_free(struct ast_ari_response *resp)
static struct stasis_rest_handlers bang
def ignore(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
int ast_ari_remove_handler(struct stasis_rest_handlers *handler)
#define ast_calloc(num, len)
A wrapper for calloc()
static int invocation_count
static struct stasis_rest_handlers test_root
struct ast_json * message
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
AST_TEST_DEFINE(get_docs)
const char * path_segment
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
int ast_json_equal(const struct ast_json *lhs, const struct ast_json *rhs)
Compare two JSON objects.
static void handler(const char *name, int response_code, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Abstract JSON element (object, array, string, int, ...).
static struct stasis_rest_handlers bam
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
Handler for a single RESTful path segment.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.