51 const char *
in =
"abcdefghijklmnopurstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 ~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/";
52 char out[256] = { 0 };
53 char small[4] = { 0 };
66 const char *decoded_output;
69 #define INIT_ENCODE_TEST(s, buffer, in, out, dec_out) do { \ 70 if (i < ARRAY_LEN(tests)) { \ 71 tests[i].spec_str = #s; \ 73 tests[i].buf = buffer; \ 74 tests[i].buflen = sizeof(buffer); \ 75 tests[i].input = in; \ 76 tests[i].output = out; \ 77 tests[i].decoded_output = dec_out; \ 80 ast_test_status_update(test, "error: 'tests' array too small\n"); \ 81 res = AST_TEST_FAIL; \ 86 "abcdefghijklmnopurstuvwxyz%20ABCDEFGHIJKLMNOPQRSTUVWXYZ%201234567890%20~%60!%40%23%24%25%5E%26*()_-%2B%3D%7B%5B%7D%5D%7C%5C%3A%3B%22'%3C%2C%3E.%3F%2F", in);
88 "abcdefghijklmnopurstuvwxyz+ABCDEFGHIJKLMNOPQRSTUVWXYZ+1234567890+~%60!%40%23%24%25%5E%26*()_-%2B%3D%7B%5B%7D%5D%7C%5C%3A%3B%22'%3C%2C%3E.%3F%2F", in);
90 "abcdefghijklmnopurstuvwxyz%20ABCDEFGHIJKLMNOPQRSTUVWXYZ%201234567890%20~%60!%40%23$%25%5E&*()_-+=%7B%5B%7D%5D%7C%5C%3A;%22'%3C,%3E.?/", in);
96 info->name =
"uri_encode_decode_test";
97 info->category =
"/main/utils/";
98 info->summary =
"encode and decode a hex escaped string";
99 info->description =
"encode a string, verify encoded string matches what we expect. Decode the encoded string, verify decoded string matches the original string.";
117 if (strcmp(
tests[i].decoded_output,
tests[i].buf)) {
132 const char *
in =
"a\"bcdefg\"hijkl\\mnopqrs tuv\twxyz";
133 char out[256] = { 0 };
134 char small[4] = { 0 };
144 "a\\\"bcdefg\\\"hijkl\\\\mnopqrs tuv\twxyz"},
150 tests[1].buf = small;
154 info->name =
"quoted_escape_test";
155 info->category =
"/main/utils/";
156 info->summary =
"escape a quoted string";
157 info->description =
"Escape a string to be quoted and check the result.";
179 static const struct {
181 const char *expected_output;
183 {
"apples",
"daeccf0ad3c1fc8c8015205c332f5b42" },
184 {
"bananas",
"ec121ff80513ae58ed478d5c5787075b" },
185 {
"reallylongstringaboutgoatcheese",
"0a2d9280d37e2e37545cfef6e7e4e890" },
192 info->name =
"md5_test";
193 info->category =
"/main/utils/";
194 info->summary =
"MD5 test";
196 "This test exercises MD5 calculations." 208 if (strcasecmp(md5_hash,
tests[i].expected_output)) {
210 "input: '%s' hash: '%s' expected hash: '%s'\n",
211 tests[i].input, md5_hash,
tests[i].expected_output);
221 static const struct {
223 const char *expected_output;
226 "fac8f1a31d2998734d6a5253e49876b8e6a08239" },
228 "1dfb21b7a4d35e90d943e3a16107ccbfabd064d5" },
229 {
"ParastratiosphecomyiaStratiosphecomyioides",
230 "58af4e8438676f2bd3c4d8df9e00ee7fe06945bb" },
237 info->name =
"sha1_test";
238 info->category =
"/main/utils/";
239 info->summary =
"SHA1 test";
241 "This test exercises SHA1 calculations." 253 if (strcasecmp(sha1_hash,
tests[i].expected_output)) {
255 "input: '%s' hash: '%s' expected hash: '%s'\n",
256 tests[i].input, sha1_hash,
tests[i].expected_output);
266 static const struct {
274 {
"ParastratiosphecomyiaStratiosphecomyioides",
275 "UGFyYXN0cmF0aW9zcGhlY29teWlhU3RyYXRpb3NwaGVjb215aW9pZGVz" },
282 info->name =
"base64_test";
283 info->category =
"/main/utils/";
284 info->summary =
"base64 test";
285 info->description =
"This test exercises the base64 conversions.";
295 if (strcasecmp(tmp,
tests[i].decoded)) {
297 "input: '%s' base64 output: '%s' expected base64 output: '%s'\n",
302 memset(tmp, 0,
sizeof(tmp));
304 if (strcasecmp(tmp,
tests[i].input)) {
306 "base64 input: '%s' output: '%s' expected output: '%s'\n",
319 info->name =
"crypto_loaded_test";
320 info->category =
"/res/crypto/";
321 info->summary =
"Crypto loaded into memory";
322 info->description =
"Verifies whether the crypto functions overrode the stubs";
337 info->name =
"adsi_loaded_test";
338 info->category =
"/res/adsi/";
339 info->summary =
"ADSI loaded into memory";
340 info->description =
"Verifies whether the adsi functions overrode the stubs";
374 info->name =
"agi_loaded_test";
375 info->category =
"/res/agi/";
376 info->summary =
"AGI loaded into memory";
377 info->description =
"Verifies whether the agi functions overrode the stubs";
388 #ifndef HAVE_NULLSAFE_PRINTF 406 char base_path[] =
"/tmp/safe_mkdir.XXXXXX";
413 info->name = __func__;
414 info->category =
"/main/utils/";
415 info->summary =
"Safe mkdir test";
417 "This test ensures that ast_safe_mkdir does what it is " 429 snprintf(path,
sizeof(path),
"%s/should_work", base_path);
431 ast_test_validate(
test, 0 == res);
432 res = stat(path, &actual);
433 ast_test_validate(
test, 0 == res);
434 ast_test_validate(
test, S_ISDIR(actual.st_mode));
436 snprintf(path,
sizeof(path),
"%s/should/also/work", base_path);
438 ast_test_validate(
test, 0 == res);
439 res = stat(path, &actual);
440 ast_test_validate(
test, 0 == res);
441 ast_test_validate(
test, S_ISDIR(actual.st_mode));
443 snprintf(path,
sizeof(path),
"%s/even/this/../should/work", base_path);
445 ast_test_validate(
test, 0 == res);
446 snprintf(path,
sizeof(path),
"%s/even/should/work", base_path);
447 res = stat(path, &actual);
448 ast_test_validate(
test, 0 == res);
449 ast_test_validate(
test, S_ISDIR(actual.st_mode));
451 snprintf(path,
sizeof(path),
452 "%s/surprisingly/this/should//////////////////work", base_path);
454 ast_test_validate(
test, 0 == res);
455 snprintf(path,
sizeof(path),
456 "%s/surprisingly/this/should/work", base_path);
457 res = stat(path, &actual);
458 ast_test_validate(
test, 0 == res);
459 ast_test_validate(
test, S_ISDIR(actual.st_mode));
461 snprintf(path,
sizeof(path),
"/should_not_work");
463 ast_test_validate(
test, 0 != res);
465 res = stat(path, &actual);
466 ast_test_validate(
test, 0 != res);
467 ast_test_validate(
test, ENOENT ==
errno);
469 snprintf(path,
sizeof(path),
"%s/../nor_should_this", base_path);
471 ast_test_validate(
test, 0 != res);
473 strncpy(path,
"/tmp/nor_should_this",
sizeof(path));
474 res = stat(path, &actual);
475 ast_test_validate(
test, 0 != res);
476 ast_test_validate(
test, ENOENT ==
errno);
478 snprintf(path,
sizeof(path),
479 "%s/this/especially/should/not/../../../../../work", base_path);
481 ast_test_validate(
test, 0 != res);
483 strncpy(path,
"/tmp/work",
sizeof(path));
484 res = stat(path, &actual);
485 ast_test_validate(
test, 0 != res);
486 ast_test_validate(
test, ENOENT ==
errno);
496 const char *not_a_password =
"not-a-password";
500 info->name =
"crypt_test";
501 info->category =
"/main/utils/";
502 info->summary =
"Test ast_crypt wrappers";
503 info->description =
"Verifies that the ast_crypt wrappers work as expected.";
510 ast_test_validate(
test,
NULL != password_crypted);
511 ast_test_validate(
test, 0 != strcmp(password, password_crypted));
513 ast_test_validate(
test,
517 ast_test_validate(
test,
NULL != blank_crypted);
518 ast_test_validate(
test, 0 != strcmp(blank_crypted,
""));
520 ast_test_validate(
test,
535 static const struct quote_set escape_sets[] = {
536 {
"\"string\"",
"\\\"string\\\""},
537 {
"\"string",
"\\\"string"},
538 {
"string\"",
"string\\\""},
539 {
"string",
"string"},
540 {
"str\"ing",
"str\\\"ing"},
542 {
"\\\"",
"\\\\\\\""},
548 info->name =
"quote_mutation";
549 info->category =
"/main/utils/";
550 info->summary =
"Test mutation of quotes in strings";
552 "This tests escaping and unescaping of quotes in strings to " 553 "verify that the original string is recovered.";
559 for (i = 0; i <
ARRAY_LEN(escape_sets); i++) {
562 if (strcmp(escaped, escape_sets[i].
output)) {
564 "Expected escaped string '%s' instead of '%s'\n",
565 escape_sets[i].output, escaped);
570 if (strcmp(escaped, escape_sets[i].input)) {
572 "Expected unescaped string '%s' instead of '%s'\n",
573 escape_sets[i].input, escaped);
583 static const struct quote_set escape_sets[] = {
584 {
"\"string\"",
"\"string\""},
585 {
"\\\"string\"",
"\"string\""},
586 {
"\"string\\\"",
"\"string\""},
587 {
"str\\ing",
"string"},
588 {
"string\\",
"string"},
589 {
"\\string",
"string"},
595 info->name =
"quote_unescaping";
596 info->category =
"/main/utils/";
597 info->summary =
"Test unescaping of off-nominal strings";
599 "This tests unescaping of strings which contain a mix of " 600 "escaped and unescaped sequences.";
606 for (i = 0; i <
ARRAY_LEN(escape_sets); i++) {
610 if (strcmp(escaped, escape_sets[i].
output)) {
612 "Expected unescaped string '%s' instead of '%s'\n",
613 escape_sets[i].output, escaped);
659 .requires =
"res_agi,res_crypto",
void ast_uri_decode(char *s, struct ast_flags spec)
Decode URI, URN, URL (overwrite string)
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
#define ast_channel_unref(c)
Decrease channel reference count.
AGI Extension interfaces - Asterisk Gateway Interface.
int AST_OPTIONAL_API_NAME() ast_agi_unregister(agi_command *cmd)
Provide cryptographic signature routines.
char * ast_uri_encode(const char *string, char *outbuf, int buflen, struct ast_flags spec)
Turn text string to URI-encoded XX version.
#define AST_TEST_REGISTER(cb)
static int load_module(void)
#define ast_strdup(str)
A wrapper for strdup()
ADSI Support (built upon Caller*ID)
static int input(yyscan_t yyscanner)
static struct ast_str * password
int ast_module_check(const char *name)
Check if module with the name given is loaded.
int ast_base64decode(unsigned char *dst, const char *src, int max)
Decode data from base64.
General Asterisk PBX channel definitions.
int AST_OPTIONAL_API_NAME() ast_agi_register(struct ast_module *mod, agi_command *cmd)
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ast_test_status_update(a, b, c...)
#define ast_dummy_channel_alloc()
Create a fake channel structure.
int AST_OPTIONAL_API_NAME() ast_crypto_loaded(void)
void ast_unescape_quoted(char *quote_str)
Unescape quotes in a string.
#define AST_OPTIONAL_API_UNAVAILABLE
A common value for optional API stub functions to return.
void ast_channel_adsicpe_set(struct ast_channel *chan, enum ast_channel_adsicpe value)
void ast_sha1_hash(char *output, const char *input)
Produces SHA1 hash based on input string.
#define INIT_ENCODE_TEST(s, buffer, in, out, dec_out)
AST_TEST_DEFINE(uri_encode_decode_test)
const struct ast_flags ast_uri_http_legacy
int ast_base64encode(char *dst, const unsigned char *src, int srclen, int max)
Encode data in base64.
char * mkdtemp(char *template_s)
#define AST_TEST_UNREGISTER(cb)
char * ast_escape_quoted(const char *string, char *outbuf, int buflen)
Escape characters found in a quoted string.
int ast_safe_mkdir(const char *base_path, const char *path, int mode)
Recursively create directory path, but only if it resolves within the given base_path.
Structure used to handle boolean flags.
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",)
int ast_adsi_available(struct ast_channel *chan)
Returns non-zero if Channel does or might support ADSI.
int ast_crypt_validate(const char *key, const char *expected)
Asterisk wrapper around crypt(3) for validating passwords.
const struct ast_flags ast_uri_sip_user
static int unload_module(void)
const struct ast_flags ast_uri_http
int AST_OPTIONAL_API_NAME() ast_agi_send(int fd, struct ast_channel *chan, char *fmt,...)
void ast_md5_hash(char *output, const char *input)
Produces MD5 hash based on input string.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
static int handle_noop(struct ast_channel *chan, AGI *agi, int arg, const char *const argv[])
char * ast_crypt_encrypt(const char *key)
Asterisk wrapper around crypt(3) for encrypting passwords.