36 #include "asterisk/uri.h"
38 #define CATEGORY "/main/uri/"
40 static const char *scenarios[][7] = {
41 {
"http://name:pass@localhost",
"http",
"name:pass",
"localhost", NULL, NULL, NULL},
42 {
"http://localhost",
"http", NULL,
"localhost", NULL, NULL, NULL},
43 {
"http://localhost:80",
"http", NULL,
"localhost",
"80", NULL, NULL},
44 {
"http://localhost/path/",
"http", NULL,
"localhost", NULL,
"path/", NULL},
45 {
"http://localhost/?query",
"http", NULL,
"localhost", NULL,
"",
"query"},
46 {
"http://localhost:80/path",
"http", NULL,
"localhost",
"80",
"path", NULL},
47 {
"http://localhost:80/?query",
"http", NULL,
"localhost",
"80",
"",
"query"},
48 {
"http://localhost:80/path?query",
"http", NULL,
"localhost",
"80",
"path",
"query"},
53 #define VALIDATE(value, expected_value) \
54 do { ast_test_validate(test, \
55 (value == expected_value) || \
56 (value && expected_value && \
57 !strcmp(value, expected_value))); \
64 info->name = __func__;
66 info->summary =
"Uri parsing scenarios";
67 info->description =
"For each scenario validate result(s)";
68 return AST_TEST_NOT_RUN;
72 for (i = 0; i < ARRAY_LEN(scenarios); ++i) {
74 const char **scenario = scenarios[i];
76 ast_test_validate(
test, (uri = ast_uri_parse(scenario[0])));
77 VALIDATE(ast_uri_scheme(uri), scenario[1]);
78 VALIDATE(ast_uri_user_info(uri), scenario[2]);
79 VALIDATE(ast_uri_host(uri), scenario[3]);
80 VALIDATE(ast_uri_port(uri), scenario[4]);
81 VALIDATE(ast_uri_path(uri), scenario[5]);
82 VALIDATE(ast_uri_query(uri), scenario[6]);
94 info->name = __func__;
96 info->summary =
"parse an http uri with host only";
97 info->description = info->summary;
98 return AST_TEST_NOT_RUN;
103 ast_test_validate(
test, (uri = ast_uri_parse_http(
"localhost")));
104 ast_test_validate(
test, !strcmp(ast_uri_scheme(uri),
"http"));
105 ast_test_validate(
test, !strcmp(ast_uri_host(uri),
"localhost"));
106 ast_test_validate(
test, !strcmp(ast_uri_port(uri),
"80"));
107 ast_test_validate(
test, !ast_uri_is_secure(uri));
109 return AST_TEST_PASS;
118 info->name = __func__;
120 info->summary =
"parse an https uri with host only";
121 info->description = info->summary;
122 return AST_TEST_NOT_RUN;
127 ast_test_validate(
test, (uri = ast_uri_parse_http(
"https://localhost")));
128 ast_test_validate(
test, !strcmp(ast_uri_scheme(uri),
"https"));
129 ast_test_validate(
test, !strcmp(ast_uri_host(uri),
"localhost"));
130 ast_test_validate(
test, !strcmp(ast_uri_port(uri),
"443"));
131 ast_test_validate(
test, ast_uri_is_secure(uri));
133 return AST_TEST_PASS;
136 static int load_module(
void)
138 AST_TEST_REGISTER(uri_parse);
139 AST_TEST_REGISTER(uri_default_http);
140 AST_TEST_REGISTER(uri_default_http_secure);
144 static int unload_module(
void)
146 AST_TEST_UNREGISTER(uri_default_http_secure);
147 AST_TEST_UNREGISTER(uri_default_http);
148 AST_TEST_UNREGISTER(uri_parse);
Asterisk main include file. File version handling, generic pbx functions.
Stores parsed uri information.
#define AST_TEST_DEFINE(hdr)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.