Unify coding style
@sjaeckel integrated clang-format with formal coding style. Run his script and commit changes. There are pros and cons of this commit. Mixed coding style is a "broken window". A good single style simplifies reading and writing code. On the other hand, this is a big change which will lead to conflicts.
This commit is contained in:
@@ -18,14 +18,15 @@
|
||||
|
||||
#include "test.h"
|
||||
|
||||
#define fail_unless(expr) do { \
|
||||
int result = (expr); \
|
||||
if (!result) { \
|
||||
printf("%s:%d: Assertion failed: %s\n", \
|
||||
__FILE__, __LINE__, #expr); \
|
||||
exit(1); \
|
||||
} \
|
||||
} while (0)
|
||||
#define fail_unless(expr) \
|
||||
do { \
|
||||
int result = (expr); \
|
||||
if (!result) { \
|
||||
printf("%s:%d: Assertion failed: %s\n", __FILE__, __LINE__, \
|
||||
#expr); \
|
||||
exit(1); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static void create_destroy(void)
|
||||
{
|
||||
@@ -67,9 +68,7 @@ static void callbacks(void)
|
||||
int ret;
|
||||
|
||||
ctx = xmpp_ctx_new(NULL, NULL);
|
||||
parser = parser_new(ctx,
|
||||
cbtest_handle_start,
|
||||
cbtest_handle_end,
|
||||
parser = parser_new(ctx, cbtest_handle_start, cbtest_handle_end,
|
||||
cbtest_handle_stanza, NULL);
|
||||
|
||||
ret = parser_feed(parser, "<stream>", 8);
|
||||
|
||||
@@ -55,8 +55,8 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
domain = argv[1];
|
||||
snprintf(fulldomain, sizeof(fulldomain), "_%s._%s.%s",
|
||||
service, proto, domain);
|
||||
snprintf(fulldomain, sizeof(fulldomain), "_%s._%s.%s", service, proto,
|
||||
domain);
|
||||
errno = 0;
|
||||
len = res_query(fulldomain, C_IN, T_SRV, buf, sizeof(buf));
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
static uint8_t char_to_bin(char c)
|
||||
{
|
||||
return c <= '9' ? (uint8_t)(c - '0') :
|
||||
c <= 'Z' ? (uint8_t)(c - 'A' + 10) :
|
||||
(uint8_t)(c - 'a' + 10);
|
||||
return c <= '9'
|
||||
? (uint8_t)(c - '0')
|
||||
: c <= 'Z' ? (uint8_t)(c - 'A' + 10) : (uint8_t)(c - 'a' + 10);
|
||||
}
|
||||
|
||||
void test_hex_to_bin(const char *hex, uint8_t *bin, size_t *bin_len)
|
||||
|
||||
75
tests/test.h
75
tests/test.h
@@ -17,51 +17,48 @@
|
||||
#include <string.h>
|
||||
#include "ostypes.h"
|
||||
|
||||
#define TEST_MAIN \
|
||||
int main(int argc, char **argv) { \
|
||||
int num_failed; \
|
||||
Suite *s = parser_suite(); \
|
||||
SRunner *sr = srunner_create(s); \
|
||||
srunner_run_all(sr, CK_NORMAL); \
|
||||
num_failed = srunner_ntests_failed(sr); \
|
||||
srunner_free(sr); \
|
||||
return (num_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; \
|
||||
}
|
||||
#define TEST_MAIN \
|
||||
int main(int argc, char **argv) \
|
||||
{ \
|
||||
int num_failed; \
|
||||
Suite *s = parser_suite(); \
|
||||
SRunner *sr = srunner_create(s); \
|
||||
srunner_run_all(sr, CK_NORMAL); \
|
||||
num_failed = srunner_ntests_failed(sr); \
|
||||
srunner_free(sr); \
|
||||
return (num_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; \
|
||||
}
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
#endif
|
||||
|
||||
#define COMPARE(v1, v2) \
|
||||
do { \
|
||||
const char *__v1 = v1; \
|
||||
const char *__v2 = v2; \
|
||||
if (strcmp(__v1, __v2) != 0) { \
|
||||
printf("%s differs!\n" \
|
||||
"expected: %s\n" \
|
||||
"got: %s\n", \
|
||||
#v1, __v1, __v2); \
|
||||
exit(1); \
|
||||
} \
|
||||
} while (0)
|
||||
#define COMPARE(v1, v2) \
|
||||
do { \
|
||||
const char *__v1 = v1; \
|
||||
const char *__v2 = v2; \
|
||||
if (strcmp(__v1, __v2) != 0) { \
|
||||
printf("%s differs!\n" \
|
||||
"expected: %s\n" \
|
||||
"got: %s\n", \
|
||||
#v1, __v1, __v2); \
|
||||
exit(1); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define COMPARE_BUF(v1, len1, v2, len2) \
|
||||
do { \
|
||||
const uint8_t *__v1 = (uint8_t *)(v1); \
|
||||
const uint8_t *__v2 = (uint8_t *)(v2); \
|
||||
size_t __len1 = len1; \
|
||||
size_t __len2 = len2; \
|
||||
if (__len1 != __len2 || \
|
||||
memcmp(__v1, __v2, __len1) != 0) \
|
||||
{ \
|
||||
printf("%s differs!\n", #v1); \
|
||||
printf("expected: 0x%s\n", \
|
||||
test_bin_to_hex(__v1, __len1)); \
|
||||
printf("got: 0x%s\n", \
|
||||
test_bin_to_hex(__v2, __len2)); \
|
||||
exit(1); \
|
||||
} \
|
||||
} while (0)
|
||||
#define COMPARE_BUF(v1, len1, v2, len2) \
|
||||
do { \
|
||||
const uint8_t *__v1 = (uint8_t *)(v1); \
|
||||
const uint8_t *__v2 = (uint8_t *)(v2); \
|
||||
size_t __len1 = len1; \
|
||||
size_t __len2 = len2; \
|
||||
if (__len1 != __len2 || memcmp(__v1, __v2, __len1) != 0) { \
|
||||
printf("%s differs!\n", #v1); \
|
||||
printf("expected: 0x%s\n", test_bin_to_hex(__v1, __len1)); \
|
||||
printf("got: 0x%s\n", test_bin_to_hex(__v2, __len2)); \
|
||||
exit(1); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void test_hex_to_bin(const char *hex, uint8_t *bin, size_t *bin_len);
|
||||
const char *test_bin_to_hex(const uint8_t *bin, size_t len);
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
|
||||
#include "test.h"
|
||||
|
||||
static const unsigned char test_2_raw[] =
|
||||
{0x14, 0xfb, 0x9c, 0x03, 0xd9, 0x7e, 0x00};
|
||||
static const unsigned char test_4_raw[] =
|
||||
{0xd6, 0x2f, 0x27, 0x49, 0x7e, 0xdd, 0xf3, 0xd5,
|
||||
0x41, 0xbc, 0x1b, 0xe9, 0xdf, 0xe9, 0xb3, 0x08, 0x00};
|
||||
static const unsigned char test_2_raw[] = {0x14, 0xfb, 0x9c, 0x03,
|
||||
0xd9, 0x7e, 0x00};
|
||||
static const unsigned char test_4_raw[] = {0xd6, 0x2f, 0x27, 0x49, 0x7e, 0xdd,
|
||||
0xf3, 0xd5, 0x41, 0xbc, 0x1b, 0xe9,
|
||||
0xdf, 0xe9, 0xb3, 0x08, 0x00};
|
||||
|
||||
static const struct {
|
||||
char *raw;
|
||||
@@ -36,30 +36,26 @@ static const struct {
|
||||
.base64 = "FPucA9l+",
|
||||
},
|
||||
{
|
||||
.raw =
|
||||
"From rest and sleep, which but thy pictures be, "
|
||||
"Much pleasure; then from thee much more must flow, "
|
||||
"And soonest our best men with thee do go, "
|
||||
"Rest of their bones, and soul's delivery.",
|
||||
.base64 =
|
||||
"RnJvbSByZXN0IGFuZCBzbGVlcCwgd2hpY2ggYnV0IHRoeSBwaWN0dXJl"
|
||||
"cyBiZSwgTXVjaCBwbGVhc3VyZTsgdGhlbiBmcm9tIHRoZWUgbXVjaCBt"
|
||||
"b3JlIG11c3QgZmxvdywgQW5kIHNvb25lc3Qgb3VyIGJlc3QgbWVuIHdp"
|
||||
"dGggdGhlZSBkbyBnbywgUmVzdCBvZiB0aGVpciBib25lcywgYW5kIHNv"
|
||||
"dWwncyBkZWxpdmVyeS4=",
|
||||
.raw = "From rest and sleep, which but thy pictures be, "
|
||||
"Much pleasure; then from thee much more must flow, "
|
||||
"And soonest our best men with thee do go, "
|
||||
"Rest of their bones, and soul's delivery.",
|
||||
.base64 = "RnJvbSByZXN0IGFuZCBzbGVlcCwgd2hpY2ggYnV0IHRoeSBwaWN0dXJl"
|
||||
"cyBiZSwgTXVjaCBwbGVhc3VyZTsgdGhlbiBmcm9tIHRoZWUgbXVjaCBt"
|
||||
"b3JlIG11c3QgZmxvdywgQW5kIHNvb25lc3Qgb3VyIGJlc3QgbWVuIHdp"
|
||||
"dGggdGhlZSBkbyBnbywgUmVzdCBvZiB0aGVpciBib25lcywgYW5kIHNv"
|
||||
"dWwncyBkZWxpdmVyeS4=",
|
||||
},
|
||||
{
|
||||
.raw = (char *)test_4_raw,
|
||||
.base64 = "1i8nSX7d89VBvBvp3+mzCA==",
|
||||
},
|
||||
{
|
||||
.raw =
|
||||
"realm=\"chesspark.com\",nonce=\"b243c0d663257a9149999cef2f83"
|
||||
"a22116559e93\",qop=\"auth\",charset=utf-8,algorithm=md5-sess",
|
||||
.base64 =
|
||||
"cmVhbG09ImNoZXNzcGFyay5jb20iLG5vbmNlPSJiMjQzYzBkNjYzMjU3"
|
||||
"YTkxNDk5OTljZWYyZjgzYTIyMTE2NTU5ZTkzIixxb3A9ImF1dGgiLGNo"
|
||||
"YXJzZXQ9dXRmLTgsYWxnb3JpdGhtPW1kNS1zZXNz",
|
||||
.raw = "realm=\"chesspark.com\",nonce=\"b243c0d663257a9149999cef2f83"
|
||||
"a22116559e93\",qop=\"auth\",charset=utf-8,algorithm=md5-sess",
|
||||
.base64 = "cmVhbG09ImNoZXNzcGFyay5jb20iLG5vbmNlPSJiMjQzYzBkNjYzMjU3"
|
||||
"YTkxNDk5OTljZWYyZjgzYTIyMTE2NTU5ZTkzIixxb3A9ImF1dGgiLGNo"
|
||||
"YXJzZXQ9dXRmLTgsYWxnb3JpdGhtPW1kNS1zZXNz",
|
||||
},
|
||||
|
||||
/* RFC4648 test vectors */
|
||||
@@ -94,38 +90,27 @@ static const struct {
|
||||
};
|
||||
|
||||
static const unsigned char bin_data[] = {
|
||||
0xda, 0xa8, 0x81, 0x80, 0x00, 0x01, 0x00, 0x05,
|
||||
0x00, 0x00, 0x00, 0x00, 0x0c, 0x5f, 0x78, 0x6d,
|
||||
0x70, 0x70, 0x2d, 0x63, 0x6c, 0x69, 0x65, 0x6e,
|
||||
0x74, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x67,
|
||||
0x6d, 0x61, 0x69, 0x6c, 0x03, 0x63, 0x6f, 0x6d,
|
||||
0x00, 0x00, 0x21, 0x00, 0x01, 0xc0, 0x0c, 0x00,
|
||||
0x21, 0x00, 0x01, 0x00, 0x00, 0x02, 0x43, 0x00,
|
||||
0x1e, 0x00, 0x14, 0x00, 0x00, 0x14, 0x66, 0x04,
|
||||
0x61, 0x6c, 0x74, 0x31, 0x04, 0x78, 0x6d, 0x70,
|
||||
0x70, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f, 0x67,
|
||||
0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0xc0,
|
||||
0x0c, 0x00, 0x21, 0x00, 0x01, 0x00, 0x00, 0x02,
|
||||
0x43, 0x00, 0x1e, 0x00, 0x14, 0x00, 0x00, 0x14,
|
||||
0x66, 0x04, 0x61, 0x6c, 0x74, 0x34, 0x04, 0x78,
|
||||
0x6d, 0x70, 0x70, 0x01, 0x6c, 0x06, 0x67, 0x6f,
|
||||
0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d,
|
||||
0x00, 0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01, 0x00,
|
||||
0x00, 0x02, 0x43, 0x00, 0x1e, 0x00, 0x14, 0x00,
|
||||
0x00, 0x14, 0x66, 0x04, 0x61, 0x6c, 0x74, 0x32,
|
||||
0x04, 0x78, 0x6d, 0x70, 0x70, 0x01, 0x6c, 0x06,
|
||||
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63,
|
||||
0x6f, 0x6d, 0x00, 0xc0, 0x0c, 0x00, 0x21, 0x00,
|
||||
0x01, 0x00, 0x00, 0x02, 0x43, 0x00, 0x19, 0x00,
|
||||
0x05, 0x00, 0x00, 0x14, 0x66, 0x04, 0x78, 0x6d,
|
||||
0x70, 0x70, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f,
|
||||
0x67, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00,
|
||||
0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01, 0x00, 0x00,
|
||||
0x02, 0x43, 0x00, 0x1e, 0x00, 0x14, 0x00, 0x00,
|
||||
0x14, 0x66, 0x04, 0x61, 0x6c, 0x74, 0x33, 0x04,
|
||||
0x78, 0x6d, 0x70, 0x70, 0x01, 0x6c, 0x06, 0x67,
|
||||
0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63, 0x6f,
|
||||
0x6d, 0x00,
|
||||
0xda, 0xa8, 0x81, 0x80, 0x00, 0x01, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00,
|
||||
0x0c, 0x5f, 0x78, 0x6d, 0x70, 0x70, 0x2d, 0x63, 0x6c, 0x69, 0x65, 0x6e,
|
||||
0x74, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x67, 0x6d, 0x61, 0x69, 0x6c,
|
||||
0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x21, 0x00, 0x01, 0xc0, 0x0c, 0x00,
|
||||
0x21, 0x00, 0x01, 0x00, 0x00, 0x02, 0x43, 0x00, 0x1e, 0x00, 0x14, 0x00,
|
||||
0x00, 0x14, 0x66, 0x04, 0x61, 0x6c, 0x74, 0x31, 0x04, 0x78, 0x6d, 0x70,
|
||||
0x70, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63,
|
||||
0x6f, 0x6d, 0x00, 0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01, 0x00, 0x00, 0x02,
|
||||
0x43, 0x00, 0x1e, 0x00, 0x14, 0x00, 0x00, 0x14, 0x66, 0x04, 0x61, 0x6c,
|
||||
0x74, 0x34, 0x04, 0x78, 0x6d, 0x70, 0x70, 0x01, 0x6c, 0x06, 0x67, 0x6f,
|
||||
0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0xc0, 0x0c, 0x00,
|
||||
0x21, 0x00, 0x01, 0x00, 0x00, 0x02, 0x43, 0x00, 0x1e, 0x00, 0x14, 0x00,
|
||||
0x00, 0x14, 0x66, 0x04, 0x61, 0x6c, 0x74, 0x32, 0x04, 0x78, 0x6d, 0x70,
|
||||
0x70, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63,
|
||||
0x6f, 0x6d, 0x00, 0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01, 0x00, 0x00, 0x02,
|
||||
0x43, 0x00, 0x19, 0x00, 0x05, 0x00, 0x00, 0x14, 0x66, 0x04, 0x78, 0x6d,
|
||||
0x70, 0x70, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03,
|
||||
0x63, 0x6f, 0x6d, 0x00, 0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01, 0x00, 0x00,
|
||||
0x02, 0x43, 0x00, 0x1e, 0x00, 0x14, 0x00, 0x00, 0x14, 0x66, 0x04, 0x61,
|
||||
0x6c, 0x74, 0x33, 0x04, 0x78, 0x6d, 0x70, 0x70, 0x01, 0x6c, 0x06, 0x67,
|
||||
0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00,
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* test_ctx.c
|
||||
** libstrophe XMPP client library -- test routines for the library run-time context
|
||||
** libstrophe XMPP client library -- test routines for the library run-time
|
||||
*context
|
||||
**
|
||||
** Copyright (C) 2005-2009 Collecta, Inc.
|
||||
**
|
||||
@@ -21,30 +22,32 @@ static int mem_alloc_called = 0;
|
||||
static int mem_free_called = 0;
|
||||
static int mem_realloc_called = 0;
|
||||
|
||||
void *my_alloc(const size_t size, void * const userdata)
|
||||
void *my_alloc(const size_t size, void *const userdata)
|
||||
{
|
||||
mem_alloc_called++;
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void my_free(void *p, void * const userdata)
|
||||
void my_free(void *p, void *const userdata)
|
||||
{
|
||||
mem_free_called++;
|
||||
return free(p);
|
||||
}
|
||||
|
||||
void *my_realloc(void *p, const size_t size, void * const userdata)
|
||||
void *my_realloc(void *p, const size_t size, void *const userdata)
|
||||
{
|
||||
mem_realloc_called++;
|
||||
return realloc(p, size);
|
||||
}
|
||||
|
||||
void my_logger(void * const userdata, const xmpp_log_level_t level,
|
||||
const char * const area, const char * const msg)
|
||||
void my_logger(void *const userdata,
|
||||
const xmpp_log_level_t level,
|
||||
const char *const area,
|
||||
const char *const msg)
|
||||
{
|
||||
if (strcmp((char *)userdata, "asdf") == 0 && level == XMPP_LEVEL_DEBUG
|
||||
&& strcmp(area, "test") == 0 && strcmp(msg, "hello") == 0)
|
||||
log_called++;
|
||||
if (strcmp((char *)userdata, "asdf") == 0 && level == XMPP_LEVEL_DEBUG &&
|
||||
strcmp(area, "test") == 0 && strcmp(msg, "hello") == 0)
|
||||
log_called++;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@@ -56,7 +59,8 @@ int main(int argc, char **argv)
|
||||
void *testptr1, *testptr2;
|
||||
|
||||
ctx = xmpp_ctx_new(NULL, NULL);
|
||||
if (ctx == NULL) return 1;
|
||||
if (ctx == NULL)
|
||||
return 1;
|
||||
|
||||
/* destroy context */
|
||||
xmpp_ctx_free(ctx);
|
||||
@@ -75,15 +79,15 @@ int main(int argc, char **argv)
|
||||
|
||||
testptr1 = xmpp_alloc(ctx, 1024);
|
||||
if (testptr1 == NULL) {
|
||||
xmpp_ctx_free(ctx);
|
||||
return 1;
|
||||
xmpp_ctx_free(ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
testptr2 = xmpp_realloc(ctx, testptr1, 2048);
|
||||
if (testptr2 == NULL) {
|
||||
xmpp_free(ctx, testptr1);
|
||||
xmpp_ctx_free(ctx);
|
||||
return 1;
|
||||
xmpp_free(ctx, testptr1);
|
||||
xmpp_ctx_free(ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
xmpp_free(ctx, testptr2);
|
||||
@@ -92,8 +96,8 @@ int main(int argc, char **argv)
|
||||
|
||||
/* check for test failure */
|
||||
if (!(log_called && mem_alloc_called && mem_realloc_called &&
|
||||
mem_free_called))
|
||||
return 1;
|
||||
mem_free_called))
|
||||
return 1;
|
||||
if (mem_alloc_called != mem_free_called)
|
||||
return 1;
|
||||
|
||||
|
||||
@@ -22,12 +22,8 @@
|
||||
#define TESTSIZE 500
|
||||
|
||||
/* static test data */
|
||||
const char *keys[] = {
|
||||
"foo", "bar", "baz", "quux", "xyzzy"
|
||||
};
|
||||
const char *values[] = {
|
||||
"wuzzle", "mug", "canonical", "rosebud", "lottery"
|
||||
};
|
||||
const char *keys[] = {"foo", "bar", "baz", "quux", "xyzzy"};
|
||||
const char *values[] = {"wuzzle", "mug", "canonical", "rosebud", "lottery"};
|
||||
const int nkeys = ARRAY_SIZE(keys);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@@ -43,10 +39,10 @@ int main(int argc, char **argv)
|
||||
|
||||
/* initialize random numbers */
|
||||
if (argc > 2) {
|
||||
/* use a seed from the command line */
|
||||
seed = (unsigned int)atoi(argv[1]);
|
||||
/* use a seed from the command line */
|
||||
seed = (unsigned int)atoi(argv[1]);
|
||||
} else {
|
||||
seed = (unsigned int)clock();
|
||||
seed = (unsigned int)clock();
|
||||
}
|
||||
/* using random seed 'seed' */
|
||||
srand(seed);
|
||||
@@ -54,37 +50,42 @@ int main(int argc, char **argv)
|
||||
/* allocate a default context */
|
||||
ctx = xmpp_ctx_new(NULL, NULL);
|
||||
if (ctx == NULL) {
|
||||
/* ctx allocation failed! */
|
||||
return -1;
|
||||
/* ctx allocation failed! */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* allocate a hash table */
|
||||
table = hash_new(ctx, TABLESIZE, xmpp_free);
|
||||
if (table == NULL) {
|
||||
/* table allocation failed! */
|
||||
return 1;
|
||||
/* table allocation failed! */
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* test insertion */
|
||||
for (i = 0; i < nkeys; i++) {
|
||||
err = hash_add(table, keys[i], xmpp_strdup(ctx, values[i]));
|
||||
if (err) return err;
|
||||
err = hash_add(table, keys[i], xmpp_strdup(ctx, values[i]));
|
||||
if (err)
|
||||
return err;
|
||||
}
|
||||
|
||||
/* test key count */
|
||||
if (hash_num_keys(table) != nkeys) {
|
||||
/* wrong number of keys in table! */
|
||||
return 1;
|
||||
/* wrong number of keys in table! */
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* test replacing old values */
|
||||
for (i = 0; i < nkeys; i++) {
|
||||
err = hash_add(table, keys[0], xmpp_strdup(ctx, values[i]));
|
||||
if (err) return err;
|
||||
if (hash_num_keys(table) != nkeys) return 1;
|
||||
if (err)
|
||||
return err;
|
||||
if (hash_num_keys(table) != nkeys)
|
||||
return 1;
|
||||
result = hash_get(table, keys[0]);
|
||||
if (result == NULL) return 1;
|
||||
if (strcmp(result, values[i]) != 0) return 1;
|
||||
if (result == NULL)
|
||||
return 1;
|
||||
if (strcmp(result, values[i]) != 0)
|
||||
return 1;
|
||||
}
|
||||
/* restore value for the 1st key */
|
||||
hash_add(table, keys[0], xmpp_strdup(ctx, values[0]));
|
||||
@@ -94,36 +95,36 @@ int main(int argc, char **argv)
|
||||
|
||||
/* test lookup */
|
||||
for (i = 0; i < nkeys; i++) {
|
||||
result = hash_get(clone, keys[i]);
|
||||
if (result == NULL) {
|
||||
/* lookup failed! */
|
||||
return 1;
|
||||
}
|
||||
if (strcmp(values[i], result)) {
|
||||
/* lookup returned incorrect value! */
|
||||
return 1;
|
||||
}
|
||||
result = hash_get(clone, keys[i]);
|
||||
if (result == NULL) {
|
||||
/* lookup failed! */
|
||||
return 1;
|
||||
}
|
||||
if (strcmp(values[i], result)) {
|
||||
/* lookup returned incorrect value! */
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* test key iterator */
|
||||
iter = hash_iter_new(clone);
|
||||
if (iter == NULL) {
|
||||
/* iterator allocation failed! */
|
||||
return 1;
|
||||
/* iterator allocation failed! */
|
||||
return 1;
|
||||
}
|
||||
for (i = 0; i < nkeys; i++) {
|
||||
key = hash_iter_next(iter);
|
||||
printf("key: '%s'\n", key);
|
||||
key = hash_iter_next(iter);
|
||||
printf("key: '%s'\n", key);
|
||||
}
|
||||
key = hash_iter_next(iter);
|
||||
if (key != NULL) {
|
||||
/* extra keys returned! */
|
||||
return 1;
|
||||
/* extra keys returned! */
|
||||
return 1;
|
||||
}
|
||||
key = hash_iter_next(iter);
|
||||
if (key != NULL) {
|
||||
/* extra keys returned! */
|
||||
return 1;
|
||||
/* extra keys returned! */
|
||||
return 1;
|
||||
}
|
||||
hash_iter_release(iter);
|
||||
|
||||
@@ -132,14 +133,19 @@ int main(int argc, char **argv)
|
||||
|
||||
/* test drops */
|
||||
hash_drop(clone, keys[2]);
|
||||
if (hash_get(clone, keys[2]) != NULL) return 1;
|
||||
if (hash_get(clone, keys[2]) != NULL)
|
||||
return 1;
|
||||
hash_drop(clone, keys[1]);
|
||||
hash_drop(clone, keys[4]);
|
||||
if (hash_get(clone, keys[4]) != NULL) return 1;
|
||||
if (hash_get(clone, keys[1]) != NULL) return 1;
|
||||
if (hash_get(clone, keys[4]) != NULL)
|
||||
return 1;
|
||||
if (hash_get(clone, keys[1]) != NULL)
|
||||
return 1;
|
||||
/* keys 0,3 should still be available */
|
||||
if (hash_get(clone, keys[0]) == NULL) return 1;
|
||||
if (hash_get(clone, keys[3]) == NULL) return 1;
|
||||
if (hash_get(clone, keys[0]) == NULL)
|
||||
return 1;
|
||||
if (hash_get(clone, keys[3]) == NULL)
|
||||
return 1;
|
||||
|
||||
/* release our clone */
|
||||
hash_release(clone);
|
||||
|
||||
136
tests/test_jid.c
136
tests/test_jid.c
@@ -36,61 +36,93 @@ int test_jid(xmpp_ctx_t *ctx)
|
||||
node = xmpp_jid_node(ctx, jid1);
|
||||
domain = xmpp_jid_domain(ctx, jid1);
|
||||
resource = xmpp_jid_resource(ctx, jid1);
|
||||
printf("jid '%s' parsed to %s, %s, %s\n",
|
||||
jid1, _s(node), _s(domain), _s(resource));
|
||||
if (bare == NULL || strcmp(bare, "foo@bar.com")) return 1;
|
||||
if (node == NULL || strcmp(node, "foo")) return 1;
|
||||
if (domain == NULL || strcmp(domain, "bar.com")) return 1;
|
||||
if (resource != NULL) return 1;
|
||||
if (bare) xmpp_free(ctx, bare);
|
||||
if (node) xmpp_free(ctx, node);
|
||||
if (domain) xmpp_free(ctx, domain);
|
||||
if (resource) xmpp_free(ctx, resource);
|
||||
printf("jid '%s' parsed to %s, %s, %s\n", jid1, _s(node), _s(domain),
|
||||
_s(resource));
|
||||
if (bare == NULL || strcmp(bare, "foo@bar.com"))
|
||||
return 1;
|
||||
if (node == NULL || strcmp(node, "foo"))
|
||||
return 1;
|
||||
if (domain == NULL || strcmp(domain, "bar.com"))
|
||||
return 1;
|
||||
if (resource != NULL)
|
||||
return 1;
|
||||
if (bare)
|
||||
xmpp_free(ctx, bare);
|
||||
if (node)
|
||||
xmpp_free(ctx, node);
|
||||
if (domain)
|
||||
xmpp_free(ctx, domain);
|
||||
if (resource)
|
||||
xmpp_free(ctx, resource);
|
||||
|
||||
bare = xmpp_jid_bare(ctx, jid2);
|
||||
node = xmpp_jid_node(ctx, jid2);
|
||||
domain = xmpp_jid_domain(ctx, jid2);
|
||||
resource = xmpp_jid_resource(ctx, jid2);
|
||||
printf("jid '%s' parsed to %s, %s, %s\n",
|
||||
jid2, _s(node), _s(domain), _s(resource));
|
||||
if (bare == NULL || strcmp(bare, "anyone@example.com")) return 1;
|
||||
if (node == NULL || strcmp(node, "anyone")) return 1;
|
||||
if (domain == NULL || strcmp(domain, "example.com")) return 1;
|
||||
if (resource == NULL || strcmp(resource, "hullo")) return 1;
|
||||
if (bare) xmpp_free(ctx, bare);
|
||||
if (node) xmpp_free(ctx, node);
|
||||
if (domain) xmpp_free(ctx, domain);
|
||||
if (resource) xmpp_free(ctx, resource);
|
||||
printf("jid '%s' parsed to %s, %s, %s\n", jid2, _s(node), _s(domain),
|
||||
_s(resource));
|
||||
if (bare == NULL || strcmp(bare, "anyone@example.com"))
|
||||
return 1;
|
||||
if (node == NULL || strcmp(node, "anyone"))
|
||||
return 1;
|
||||
if (domain == NULL || strcmp(domain, "example.com"))
|
||||
return 1;
|
||||
if (resource == NULL || strcmp(resource, "hullo"))
|
||||
return 1;
|
||||
if (bare)
|
||||
xmpp_free(ctx, bare);
|
||||
if (node)
|
||||
xmpp_free(ctx, node);
|
||||
if (domain)
|
||||
xmpp_free(ctx, domain);
|
||||
if (resource)
|
||||
xmpp_free(ctx, resource);
|
||||
|
||||
bare = xmpp_jid_bare(ctx, jid3);
|
||||
node = xmpp_jid_node(ctx, jid3);
|
||||
domain = xmpp_jid_domain(ctx, jid3);
|
||||
resource = xmpp_jid_resource(ctx, jid3);
|
||||
printf("jid '%s' parsed to %s, %s, %s\n",
|
||||
jid3, _s(node), _s(domain), _s(resource));
|
||||
if (bare == NULL || strcmp(bare, "manic.porter@xyz.net")) return 1;
|
||||
if (node == NULL || strcmp(node, "manic.porter")) return 1;
|
||||
if (domain == NULL || strcmp(domain, "xyz.net")) return 1;
|
||||
if (resource == NULL || strcmp(resource, "frob")) return 1;
|
||||
if (bare) xmpp_free(ctx, bare);
|
||||
if (node) xmpp_free(ctx, node);
|
||||
if (domain) xmpp_free(ctx, domain);
|
||||
if (resource) xmpp_free(ctx, resource);
|
||||
printf("jid '%s' parsed to %s, %s, %s\n", jid3, _s(node), _s(domain),
|
||||
_s(resource));
|
||||
if (bare == NULL || strcmp(bare, "manic.porter@xyz.net"))
|
||||
return 1;
|
||||
if (node == NULL || strcmp(node, "manic.porter"))
|
||||
return 1;
|
||||
if (domain == NULL || strcmp(domain, "xyz.net"))
|
||||
return 1;
|
||||
if (resource == NULL || strcmp(resource, "frob"))
|
||||
return 1;
|
||||
if (bare)
|
||||
xmpp_free(ctx, bare);
|
||||
if (node)
|
||||
xmpp_free(ctx, node);
|
||||
if (domain)
|
||||
xmpp_free(ctx, domain);
|
||||
if (resource)
|
||||
xmpp_free(ctx, resource);
|
||||
|
||||
bare = xmpp_jid_bare(ctx, jid4);
|
||||
node = xmpp_jid_node(ctx, jid4);
|
||||
domain = xmpp_jid_domain(ctx, jid4);
|
||||
resource = xmpp_jid_resource(ctx, jid4);
|
||||
printf("jid '%s' parsed to %s, %s, %s\n",
|
||||
jid4, _s(node), _s(domain), _s(resource));
|
||||
if (bare == NULL || strcmp(bare, "domain.tld")) return 1;
|
||||
if (node != NULL) return 1;
|
||||
if (domain == NULL || strcmp(domain, "domain.tld")) return 1;
|
||||
if (resource != NULL) return 1;
|
||||
if (bare) xmpp_free(ctx, bare);
|
||||
if (node) xmpp_free(ctx, node);
|
||||
if (domain) xmpp_free(ctx, domain);
|
||||
if (resource) xmpp_free(ctx, resource);
|
||||
printf("jid '%s' parsed to %s, %s, %s\n", jid4, _s(node), _s(domain),
|
||||
_s(resource));
|
||||
if (bare == NULL || strcmp(bare, "domain.tld"))
|
||||
return 1;
|
||||
if (node != NULL)
|
||||
return 1;
|
||||
if (domain == NULL || strcmp(domain, "domain.tld"))
|
||||
return 1;
|
||||
if (resource != NULL)
|
||||
return 1;
|
||||
if (bare)
|
||||
xmpp_free(ctx, bare);
|
||||
if (node)
|
||||
xmpp_free(ctx, node);
|
||||
if (domain)
|
||||
xmpp_free(ctx, domain);
|
||||
if (resource)
|
||||
xmpp_free(ctx, resource);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -101,12 +133,14 @@ int test_jid_new(xmpp_ctx_t *ctx)
|
||||
|
||||
jid = xmpp_jid_new(ctx, "node", "domain", "resource");
|
||||
printf("new jid: '%s'\n", jid);
|
||||
if (strcmp(jid, "node@domain/resource")) return 1;
|
||||
if (strcmp(jid, "node@domain/resource"))
|
||||
return 1;
|
||||
xmpp_free(ctx, jid);
|
||||
|
||||
jid = xmpp_jid_new(ctx, "foo", "bar.com", NULL);
|
||||
printf("new jid: '%s'\n", jid);
|
||||
if (strcmp(jid, "foo@bar.com")) return 1;
|
||||
if (strcmp(jid, "foo@bar.com"))
|
||||
return 1;
|
||||
xmpp_free(ctx, jid);
|
||||
|
||||
return 0;
|
||||
@@ -119,20 +153,26 @@ int main(int argc, char *argv[])
|
||||
|
||||
printf("allocating context... ");
|
||||
ctx = xmpp_ctx_new(NULL, NULL);
|
||||
if (ctx == NULL) printf("failed to create context\n");
|
||||
if (ctx == NULL) return -1;
|
||||
if (ctx == NULL)
|
||||
printf("failed to create context\n");
|
||||
if (ctx == NULL)
|
||||
return -1;
|
||||
printf("ok.\n");
|
||||
|
||||
printf("testing jid routines...\n");
|
||||
ret = test_jid(ctx);
|
||||
if (ret) printf("testing jid routines... failed!\n");
|
||||
if (ret) return ret;
|
||||
if (ret)
|
||||
printf("testing jid routines... failed!\n");
|
||||
if (ret)
|
||||
return ret;
|
||||
printf("testing jid routines... ok.\n");
|
||||
|
||||
printf("testing jid new routines...\n");
|
||||
ret = test_jid_new(ctx);
|
||||
if (ret) printf("testing jid new routines... failed!\n");
|
||||
if (ret) return ret;
|
||||
if (ret)
|
||||
printf("testing jid new routines... failed!\n");
|
||||
if (ret)
|
||||
return ret;
|
||||
printf("testing jid new routines... ok.\n");
|
||||
|
||||
printf("freeing context... ");
|
||||
|
||||
@@ -21,14 +21,17 @@
|
||||
#include "rand.c"
|
||||
|
||||
/* stubs to build test without whole libstrophe */
|
||||
void *xmpp_alloc(const xmpp_ctx_t * const ctx, const size_t size) {
|
||||
void *xmpp_alloc(const xmpp_ctx_t *const ctx, const size_t size)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
void xmpp_free(const xmpp_ctx_t * const ctx, void *p) { }
|
||||
int xmpp_snprintf (char *str, size_t count, const char *fmt, ...) {
|
||||
void xmpp_free(const xmpp_ctx_t *const ctx, void *p) {}
|
||||
int xmpp_snprintf(char *str, size_t count, const char *fmt, ...)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
uint64_t time_stamp(void) {
|
||||
uint64_t time_stamp(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -121,8 +124,8 @@ int main()
|
||||
&entropy_input_len);
|
||||
test_hex_to_bin(test_vectors[i].nonce, nonce, &nonce_len);
|
||||
|
||||
Hash_DRBG_Instantiate(&ctx, entropy_input, entropy_input_len,
|
||||
nonce, nonce_len);
|
||||
Hash_DRBG_Instantiate(&ctx, entropy_input, entropy_input_len, nonce,
|
||||
nonce_len);
|
||||
COMPARE(test_vectors[i].V1, test_bin_to_hex(ctx.V, sizeof(ctx.V)));
|
||||
COMPARE(test_vectors[i].C1, test_bin_to_hex(ctx.C, sizeof(ctx.C)));
|
||||
assert(ctx.reseed_counter == 1);
|
||||
|
||||
@@ -19,117 +19,94 @@
|
||||
|
||||
/* res_query("_xmpp-client._tcp.jabber.kiev.ua", C_IN, T_SRV, ...) */
|
||||
static const unsigned char data1[] = {
|
||||
0x95, 0xf3, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01,
|
||||
0x00, 0x00, 0x00, 0x00, 0x0c, 0x5f, 0x78, 0x6d,
|
||||
0x70, 0x70, 0x2d, 0x63, 0x6c, 0x69, 0x65, 0x6e,
|
||||
0x74, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x06, 0x6a,
|
||||
0x61, 0x62, 0x62, 0x65, 0x72, 0x04, 0x6b, 0x69,
|
||||
0x65, 0x76, 0x02, 0x75, 0x61, 0x00, 0x00, 0x21,
|
||||
0x00, 0x01, 0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01,
|
||||
0x00, 0x00, 0x00, 0x3b, 0x00, 0x16, 0x00, 0x01,
|
||||
0x00, 0x00, 0x14, 0x66, 0x06, 0x6a, 0x61, 0x62,
|
||||
0x62, 0x65, 0x72, 0x04, 0x6b, 0x69, 0x65, 0x76,
|
||||
0x02, 0x75, 0x61, 0x00,
|
||||
0x95, 0xf3, 0x81, 0x80, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
|
||||
0x0c, 0x5f, 0x78, 0x6d, 0x70, 0x70, 0x2d, 0x63, 0x6c, 0x69, 0x65, 0x6e,
|
||||
0x74, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x06, 0x6a, 0x61, 0x62, 0x62, 0x65,
|
||||
0x72, 0x04, 0x6b, 0x69, 0x65, 0x76, 0x02, 0x75, 0x61, 0x00, 0x00, 0x21,
|
||||
0x00, 0x01, 0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3b,
|
||||
0x00, 0x16, 0x00, 0x01, 0x00, 0x00, 0x14, 0x66, 0x06, 0x6a, 0x61, 0x62,
|
||||
0x62, 0x65, 0x72, 0x04, 0x6b, 0x69, 0x65, 0x76, 0x02, 0x75, 0x61, 0x00,
|
||||
};
|
||||
/* res_query("_xmpp-client._tcp.jabber.org", C_IN, T_SRV, ...) */
|
||||
static const unsigned char data2[] = {
|
||||
0xf2, 0x98, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02,
|
||||
0x00, 0x00, 0x00, 0x00, 0x0c, 0x5f, 0x78, 0x6d,
|
||||
0x70, 0x70, 0x2d, 0x63, 0x6c, 0x69, 0x65, 0x6e,
|
||||
0x74, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x06, 0x6a,
|
||||
0x61, 0x62, 0x62, 0x65, 0x72, 0x03, 0x6f, 0x72,
|
||||
0x67, 0x00, 0x00, 0x21, 0x00, 0x01, 0xc0, 0x0c,
|
||||
0x00, 0x21, 0x00, 0x01, 0x00, 0x00, 0x03, 0x83,
|
||||
0x00, 0x1a, 0x00, 0x1e, 0x00, 0x1e, 0x14, 0x66,
|
||||
0x07, 0x68, 0x65, 0x72, 0x6d, 0x65, 0x73, 0x32,
|
||||
0x06, 0x6a, 0x61, 0x62, 0x62, 0x65, 0x72, 0x03,
|
||||
0x6f, 0x72, 0x67, 0x00, 0xc0, 0x0c, 0x00, 0x21,
|
||||
0x00, 0x01, 0x00, 0x00, 0x03, 0x83, 0x00, 0x1c,
|
||||
0x00, 0x1f, 0x00, 0x1e, 0x14, 0x66, 0x09, 0x68,
|
||||
0x65, 0x72, 0x6d, 0x65, 0x73, 0x32, 0x76, 0x36,
|
||||
0x06, 0x6a, 0x61, 0x62, 0x62, 0x65, 0x72, 0x03,
|
||||
0xf2, 0x98, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
|
||||
0x0c, 0x5f, 0x78, 0x6d, 0x70, 0x70, 0x2d, 0x63, 0x6c, 0x69, 0x65, 0x6e,
|
||||
0x74, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x06, 0x6a, 0x61, 0x62, 0x62, 0x65,
|
||||
0x72, 0x03, 0x6f, 0x72, 0x67, 0x00, 0x00, 0x21, 0x00, 0x01, 0xc0, 0x0c,
|
||||
0x00, 0x21, 0x00, 0x01, 0x00, 0x00, 0x03, 0x83, 0x00, 0x1a, 0x00, 0x1e,
|
||||
0x00, 0x1e, 0x14, 0x66, 0x07, 0x68, 0x65, 0x72, 0x6d, 0x65, 0x73, 0x32,
|
||||
0x06, 0x6a, 0x61, 0x62, 0x62, 0x65, 0x72, 0x03, 0x6f, 0x72, 0x67, 0x00,
|
||||
0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01, 0x00, 0x00, 0x03, 0x83, 0x00, 0x1c,
|
||||
0x00, 0x1f, 0x00, 0x1e, 0x14, 0x66, 0x09, 0x68, 0x65, 0x72, 0x6d, 0x65,
|
||||
0x73, 0x32, 0x76, 0x36, 0x06, 0x6a, 0x61, 0x62, 0x62, 0x65, 0x72, 0x03,
|
||||
0x6f, 0x72, 0x67, 0x00,
|
||||
};
|
||||
/* res_query("_xmpp-client._tcp.gmail.com", C_IN, T_SRV, ...) */
|
||||
static const unsigned char data3[] = {
|
||||
0xda, 0xa8, 0x81, 0x80, 0x00, 0x01, 0x00, 0x05,
|
||||
0x00, 0x00, 0x00, 0x00, 0x0c, 0x5f, 0x78, 0x6d,
|
||||
0x70, 0x70, 0x2d, 0x63, 0x6c, 0x69, 0x65, 0x6e,
|
||||
0x74, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x67,
|
||||
0x6d, 0x61, 0x69, 0x6c, 0x03, 0x63, 0x6f, 0x6d,
|
||||
0x00, 0x00, 0x21, 0x00, 0x01, 0xc0, 0x0c, 0x00,
|
||||
0x21, 0x00, 0x01, 0x00, 0x00, 0x02, 0x43, 0x00,
|
||||
0x1e, 0x00, 0x14, 0x00, 0x00, 0x14, 0x66, 0x04,
|
||||
0x61, 0x6c, 0x74, 0x31, 0x04, 0x78, 0x6d, 0x70,
|
||||
0x70, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f, 0x67,
|
||||
0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0xc0,
|
||||
0x0c, 0x00, 0x21, 0x00, 0x01, 0x00, 0x00, 0x02,
|
||||
0x43, 0x00, 0x1e, 0x00, 0x14, 0x00, 0x00, 0x14,
|
||||
0x66, 0x04, 0x61, 0x6c, 0x74, 0x34, 0x04, 0x78,
|
||||
0x6d, 0x70, 0x70, 0x01, 0x6c, 0x06, 0x67, 0x6f,
|
||||
0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d,
|
||||
0x00, 0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01, 0x00,
|
||||
0x00, 0x02, 0x43, 0x00, 0x1e, 0x00, 0x14, 0x00,
|
||||
0x00, 0x14, 0x66, 0x04, 0x61, 0x6c, 0x74, 0x32,
|
||||
0x04, 0x78, 0x6d, 0x70, 0x70, 0x01, 0x6c, 0x06,
|
||||
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63,
|
||||
0x6f, 0x6d, 0x00, 0xc0, 0x0c, 0x00, 0x21, 0x00,
|
||||
0x01, 0x00, 0x00, 0x02, 0x43, 0x00, 0x19, 0x00,
|
||||
0x05, 0x00, 0x00, 0x14, 0x66, 0x04, 0x78, 0x6d,
|
||||
0x70, 0x70, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f,
|
||||
0x67, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00,
|
||||
0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01, 0x00, 0x00,
|
||||
0x02, 0x43, 0x00, 0x1e, 0x00, 0x14, 0x00, 0x00,
|
||||
0x14, 0x66, 0x04, 0x61, 0x6c, 0x74, 0x33, 0x04,
|
||||
0x78, 0x6d, 0x70, 0x70, 0x01, 0x6c, 0x06, 0x67,
|
||||
0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63, 0x6f,
|
||||
0x6d, 0x00,
|
||||
0xda, 0xa8, 0x81, 0x80, 0x00, 0x01, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00,
|
||||
0x0c, 0x5f, 0x78, 0x6d, 0x70, 0x70, 0x2d, 0x63, 0x6c, 0x69, 0x65, 0x6e,
|
||||
0x74, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x05, 0x67, 0x6d, 0x61, 0x69, 0x6c,
|
||||
0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x21, 0x00, 0x01, 0xc0, 0x0c, 0x00,
|
||||
0x21, 0x00, 0x01, 0x00, 0x00, 0x02, 0x43, 0x00, 0x1e, 0x00, 0x14, 0x00,
|
||||
0x00, 0x14, 0x66, 0x04, 0x61, 0x6c, 0x74, 0x31, 0x04, 0x78, 0x6d, 0x70,
|
||||
0x70, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63,
|
||||
0x6f, 0x6d, 0x00, 0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01, 0x00, 0x00, 0x02,
|
||||
0x43, 0x00, 0x1e, 0x00, 0x14, 0x00, 0x00, 0x14, 0x66, 0x04, 0x61, 0x6c,
|
||||
0x74, 0x34, 0x04, 0x78, 0x6d, 0x70, 0x70, 0x01, 0x6c, 0x06, 0x67, 0x6f,
|
||||
0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0xc0, 0x0c, 0x00,
|
||||
0x21, 0x00, 0x01, 0x00, 0x00, 0x02, 0x43, 0x00, 0x1e, 0x00, 0x14, 0x00,
|
||||
0x00, 0x14, 0x66, 0x04, 0x61, 0x6c, 0x74, 0x32, 0x04, 0x78, 0x6d, 0x70,
|
||||
0x70, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63,
|
||||
0x6f, 0x6d, 0x00, 0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01, 0x00, 0x00, 0x02,
|
||||
0x43, 0x00, 0x19, 0x00, 0x05, 0x00, 0x00, 0x14, 0x66, 0x04, 0x78, 0x6d,
|
||||
0x70, 0x70, 0x01, 0x6c, 0x06, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03,
|
||||
0x63, 0x6f, 0x6d, 0x00, 0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01, 0x00, 0x00,
|
||||
0x02, 0x43, 0x00, 0x1e, 0x00, 0x14, 0x00, 0x00, 0x14, 0x66, 0x04, 0x61,
|
||||
0x6c, 0x74, 0x33, 0x04, 0x78, 0x6d, 0x70, 0x70, 0x01, 0x6c, 0x06, 0x67,
|
||||
0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00,
|
||||
};
|
||||
/* res_query("_xmpp-client._tcp.jabber.calyxinstitute.org", C_IN, T_SRV, ...) */
|
||||
static const unsigned char data4[] = {
|
||||
0x8d, 0x58, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, // .X........
|
||||
0x00, 0x00, 0x0c, 0x5f, 0x78, 0x6d, 0x70, 0x70, 0x2d, 0x63, // ..._xmpp-c
|
||||
0x6c, 0x69, 0x65, 0x6e, 0x74, 0x04, 0x5f, 0x74, 0x63, 0x70, // lient._tcp
|
||||
0x06, 0x6a, 0x61, 0x62, 0x62, 0x65, 0x72, 0x0e, 0x63, 0x61, // .jabber.ca
|
||||
0x6c, 0x79, 0x78, 0x69, 0x6e, 0x73, 0x74, 0x69, 0x74, 0x75, // lyxinstitu
|
||||
0x74, 0x65, 0x03, 0x6f, 0x72, 0x67, 0x00, 0x00, 0x21, 0x00, // te.org..!.
|
||||
0x01, 0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01, 0x00, 0x00, 0x03, // ....!.....
|
||||
0x83, 0x00, 0x1e, 0x00, 0x04, 0x00, 0x00, 0x14, 0x66, 0x10, // ........f.
|
||||
0x69, 0x6a, 0x65, 0x65, 0x79, 0x6e, 0x72, 0x63, 0x36, 0x78, // ijeeynrc6x
|
||||
0x32, 0x75, 0x79, 0x35, 0x6f, 0x62, 0x05, 0x6f, 0x6e, 0x69, // 2uy5ob.oni
|
||||
0x6f, 0x6e, 0x00, 0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01, 0x00, // on....!...
|
||||
0x00, 0x03, 0x83, 0x00, 0x21, 0x00, 0x05, 0x00, 0x01, 0x14, // ....!.....
|
||||
0x66, 0x06, 0x6a, 0x61, 0x62, 0x62, 0x65, 0x72, 0x0e, 0x63, // f.jabber.c
|
||||
0x61, 0x6c, 0x79, 0x78, 0x69, 0x6e, 0x73, 0x74, 0x69, 0x74, // alyxinstit
|
||||
0x75, 0x74, 0x65, 0x03, 0x6f, 0x72, 0x67, 0x00, // ute.org.
|
||||
0x8d, 0x58, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, // .X........
|
||||
0x00, 0x00, 0x0c, 0x5f, 0x78, 0x6d, 0x70, 0x70, 0x2d, 0x63, // ..._xmpp-c
|
||||
0x6c, 0x69, 0x65, 0x6e, 0x74, 0x04, 0x5f, 0x74, 0x63, 0x70, // lient._tcp
|
||||
0x06, 0x6a, 0x61, 0x62, 0x62, 0x65, 0x72, 0x0e, 0x63, 0x61, // .jabber.ca
|
||||
0x6c, 0x79, 0x78, 0x69, 0x6e, 0x73, 0x74, 0x69, 0x74, 0x75, // lyxinstitu
|
||||
0x74, 0x65, 0x03, 0x6f, 0x72, 0x67, 0x00, 0x00, 0x21, 0x00, // te.org..!.
|
||||
0x01, 0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01, 0x00, 0x00, 0x03, // ....!.....
|
||||
0x83, 0x00, 0x1e, 0x00, 0x04, 0x00, 0x00, 0x14, 0x66, 0x10, // ........f.
|
||||
0x69, 0x6a, 0x65, 0x65, 0x79, 0x6e, 0x72, 0x63, 0x36, 0x78, // ijeeynrc6x
|
||||
0x32, 0x75, 0x79, 0x35, 0x6f, 0x62, 0x05, 0x6f, 0x6e, 0x69, // 2uy5ob.oni
|
||||
0x6f, 0x6e, 0x00, 0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01, 0x00, // on....!...
|
||||
0x00, 0x03, 0x83, 0x00, 0x21, 0x00, 0x05, 0x00, 0x01, 0x14, // ....!.....
|
||||
0x66, 0x06, 0x6a, 0x61, 0x62, 0x62, 0x65, 0x72, 0x0e, 0x63, // f.jabber.c
|
||||
0x61, 0x6c, 0x79, 0x78, 0x69, 0x6e, 0x73, 0x74, 0x69, 0x74, // alyxinstit
|
||||
0x75, 0x74, 0x65, 0x03, 0x6f, 0x72, 0x67, 0x00, // ute.org.
|
||||
};
|
||||
/* res_query("_xmpp-client._tcp.jabber.org", C_IN, T_SRV, ...) with pointers */
|
||||
static const unsigned char data5[] = {
|
||||
0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, // ..........
|
||||
0x00, 0x00, 0x0c, 0x5f, 0x78, 0x6d, 0x70, 0x70, 0x2d, 0x63, // ..._xmpp-c
|
||||
0x6c, 0x69, 0x65, 0x6e, 0x74, 0x04, 0x5f, 0x74, 0x63, 0x70, // lient._tcp
|
||||
0x06, 0x6a, 0x61, 0x62, 0x62, 0x65, 0x72, 0x03, 0x6f, 0x72, // .jabber.or
|
||||
0x67, 0x00, 0x00, 0x21, 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x21, // g..!.....!
|
||||
0x00, 0x01, 0x00, 0x00, 0x01, 0x9e, 0x00, 0x12, 0x00, 0x1f, // ..........
|
||||
0x00, 0x1e, 0x14, 0x66, 0x09, 0x68, 0x65, 0x72, 0x6d, 0x65, // ...f.herme
|
||||
0x73, 0x32, 0x76, 0x36, 0xc0, 0x1e, 0xc0, 0x0c, 0x00, 0x21, // s2v6.....!
|
||||
0x00, 0x01, 0x00, 0x00, 0x01, 0x9e, 0x00, 0x10, 0x00, 0x1e, // ..........
|
||||
0x00, 0x1e, 0x14, 0x66, 0x07, 0x68, 0x65, 0x72, 0x6d, 0x65, // ...f.herme
|
||||
0x73, 0x32, 0xc0, 0x1e, // s2..
|
||||
0x00, 0x00, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, // ..........
|
||||
0x00, 0x00, 0x0c, 0x5f, 0x78, 0x6d, 0x70, 0x70, 0x2d, 0x63, // ..._xmpp-c
|
||||
0x6c, 0x69, 0x65, 0x6e, 0x74, 0x04, 0x5f, 0x74, 0x63, 0x70, // lient._tcp
|
||||
0x06, 0x6a, 0x61, 0x62, 0x62, 0x65, 0x72, 0x03, 0x6f, 0x72, // .jabber.or
|
||||
0x67, 0x00, 0x00, 0x21, 0x00, 0x01, 0xc0, 0x0c, 0x00, 0x21, // g..!.....!
|
||||
0x00, 0x01, 0x00, 0x00, 0x01, 0x9e, 0x00, 0x12, 0x00, 0x1f, // ..........
|
||||
0x00, 0x1e, 0x14, 0x66, 0x09, 0x68, 0x65, 0x72, 0x6d, 0x65, // ...f.herme
|
||||
0x73, 0x32, 0x76, 0x36, 0xc0, 0x1e, 0xc0, 0x0c, 0x00, 0x21, // s2v6.....!
|
||||
0x00, 0x01, 0x00, 0x00, 0x01, 0x9e, 0x00, 0x10, 0x00, 0x1e, // ..........
|
||||
0x00, 0x1e, 0x14, 0x66, 0x07, 0x68, 0x65, 0x72, 0x6d, 0x65, // ...f.herme
|
||||
0x73, 0x32, 0xc0, 0x1e, // s2..
|
||||
};
|
||||
/* hacked data2 with two empty-string targets. */
|
||||
static const unsigned char data6[] = {
|
||||
0xf2, 0x98, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02,
|
||||
0x00, 0x00, 0x00, 0x00, 0x0c, 0x5f, 0x78, 0x6d,
|
||||
0x70, 0x70, 0x2d, 0x63, 0x6c, 0x69, 0x65, 0x6e,
|
||||
0x74, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x06, 0x6a,
|
||||
0x61, 0x62, 0x62, 0x65, 0x72, 0x03, 0x6f, 0x72,
|
||||
0x67, 0x00, 0x00, 0x21, 0x00, 0x01, 0xc0, 0x0c,
|
||||
0x00, 0x21, 0x00, 0x01, 0x00, 0x00, 0x03, 0x83,
|
||||
0x00, 0x07, 0x00, 0x1e, 0x00, 0x1e, 0x14, 0x66,
|
||||
0x00, 0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01, 0x00,
|
||||
0x00, 0x03, 0x83, 0x00, 0x08, 0x00, 0x1f, 0x00,
|
||||
0x1e, 0x14, 0x66, 0xc0, 0x40,
|
||||
0xf2, 0x98, 0x81, 0x80, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00,
|
||||
0x00, 0x0c, 0x5f, 0x78, 0x6d, 0x70, 0x70, 0x2d, 0x63, 0x6c, 0x69,
|
||||
0x65, 0x6e, 0x74, 0x04, 0x5f, 0x74, 0x63, 0x70, 0x06, 0x6a, 0x61,
|
||||
0x62, 0x62, 0x65, 0x72, 0x03, 0x6f, 0x72, 0x67, 0x00, 0x00, 0x21,
|
||||
0x00, 0x01, 0xc0, 0x0c, 0x00, 0x21, 0x00, 0x01, 0x00, 0x00, 0x03,
|
||||
0x83, 0x00, 0x07, 0x00, 0x1e, 0x00, 0x1e, 0x14, 0x66, 0x00, 0xc0,
|
||||
0x0c, 0x00, 0x21, 0x00, 0x01, 0x00, 0x00, 0x03, 0x83, 0x00, 0x08,
|
||||
0x00, 0x1f, 0x00, 0x1e, 0x14, 0x66, 0xc0, 0x40,
|
||||
};
|
||||
|
||||
static const struct {
|
||||
@@ -187,7 +164,8 @@ static int srv_rr_list_len(resolver_srv_rr_t *list)
|
||||
{
|
||||
int nr;
|
||||
|
||||
for (nr = 0; list != NULL; ++nr, list = list->next);
|
||||
for (nr = 0; list != NULL; ++nr, list = list->next)
|
||||
;
|
||||
|
||||
return nr;
|
||||
}
|
||||
@@ -223,8 +201,8 @@ int main(int argc, char **argv)
|
||||
port = srv_rr_list->port;
|
||||
COMPARE(tests[i].target, domain);
|
||||
if (tests[i].port != port) {
|
||||
printf("fail! got port=%u, but should be %u\n",
|
||||
(unsigned)port, (unsigned)tests[i].port);
|
||||
printf("fail! got port=%u, but should be %u\n", (unsigned)port,
|
||||
(unsigned)tests[i].port);
|
||||
return 1;
|
||||
}
|
||||
printf("ok\n");
|
||||
|
||||
@@ -21,31 +21,31 @@ static const char password[] = "secret";
|
||||
static const char response_plain[] = "AGZvb0BiYXIuY29tAHNlY3JldA==";
|
||||
|
||||
static const char challenge_md5[] =
|
||||
"cmVhbG09InNvbWVyZWFsbSIsbm9uY2U9Ik9BNk1HOXRFUUdtMmhoIixxb3A9ImF1dGgi"
|
||||
"LGNoYXJzZXQ9dXRmLTgsYWxnb3JpdGhtPW1kNS1zZXNzCg==";
|
||||
"cmVhbG09InNvbWVyZWFsbSIsbm9uY2U9Ik9BNk1HOXRFUUdtMmhoIixxb3A9ImF1dGgi"
|
||||
"LGNoYXJzZXQ9dXRmLTgsYWxnb3JpdGhtPW1kNS1zZXNzCg==";
|
||||
static const char response_md5[] =
|
||||
"dXNlcm5hbWU9InNvbWVub2RlIixyZWFsbT0ic29tZXJlYWxtIixub25jZT0i"
|
||||
"T0E2TUc5dEVRR20yaGgiLGNub25jZT0iMDBERUFEQkVFRjAwIixuYz0wMDAw"
|
||||
"MDAwMSxxb3A9YXV0aCxkaWdlc3QtdXJpPSJ4bXBwL3NvbWVyZWFsbSIscmVz"
|
||||
"cG9uc2U9NGVhNmU4N2JjMDkzMzUwNzQzZGIyOGQ3MDIwOGNhZmIsY2hhcnNl"
|
||||
"dD11dGYtOA==";
|
||||
"dXNlcm5hbWU9InNvbWVub2RlIixyZWFsbT0ic29tZXJlYWxtIixub25jZT0i"
|
||||
"T0E2TUc5dEVRR20yaGgiLGNub25jZT0iMDBERUFEQkVFRjAwIixuYz0wMDAw"
|
||||
"MDAwMSxxb3A9YXV0aCxkaWdlc3QtdXJpPSJ4bXBwL3NvbWVyZWFsbSIscmVz"
|
||||
"cG9uc2U9NGVhNmU4N2JjMDkzMzUwNzQzZGIyOGQ3MDIwOGNhZmIsY2hhcnNl"
|
||||
"dD11dGYtOA==";
|
||||
static const char response_md5_rfc[] =
|
||||
"dXNlcm5hbWU9InNvbWVub2RlIixyZWFsbT0ic29tZXJlYWxtIixub25jZT0i"
|
||||
"T0E2TUc5dEVRR20yaGgiLGNub25jZT0iT0E2TUhYaDZWcVRyUmsiLG5jPTAw"
|
||||
"MDAwMDAxLHFvcD1hdXRoLGRpZ2VzdC11cmk9InhtcHAvZXhhbXBsZS5jb20i"
|
||||
"LHJlc3BvbnNlPWQzODhkYWQ5MGQ0YmJkNzYwYTE1MjMyMWYyMTQzYWY3LGNo"
|
||||
"YXJzZXQ9dXRmLTgK";
|
||||
"dXNlcm5hbWU9InNvbWVub2RlIixyZWFsbT0ic29tZXJlYWxtIixub25jZT0i"
|
||||
"T0E2TUc5dEVRR20yaGgiLGNub25jZT0iT0E2TUhYaDZWcVRyUmsiLG5jPTAw"
|
||||
"MDAwMDAxLHFvcD1hdXRoLGRpZ2VzdC11cmk9InhtcHAvZXhhbXBsZS5jb20i"
|
||||
"LHJlc3BvbnNlPWQzODhkYWQ5MGQ0YmJkNzYwYTE1MjMyMWYyMTQzYWY3LGNo"
|
||||
"YXJzZXQ9dXRmLTgK";
|
||||
|
||||
static const char challenge_md5_2[] =
|
||||
"cmVhbG09ImVsd29vZC5pbm5vc29mdC5jb20iLG5vbmNlPSJPQTZNRzl0"
|
||||
"RVFHbTJoaCIscW9wPSJhdXRoIixhbGdvcml0aG09bWQ1LXNlc3MsY2hh"
|
||||
"cnNldD11dGYtOA==";
|
||||
"cmVhbG09ImVsd29vZC5pbm5vc29mdC5jb20iLG5vbmNlPSJPQTZNRzl0"
|
||||
"RVFHbTJoaCIscW9wPSJhdXRoIixhbGdvcml0aG09bWQ1LXNlc3MsY2hh"
|
||||
"cnNldD11dGYtOA==";
|
||||
static const char response_md5_2[] =
|
||||
"Y2hhcnNldD11dGYtOCx1c2VybmFtZT0iY2hyaXMiLHJlYWxtPSJlbHdvb2"
|
||||
"QuaW5ub3NvZnQuY29tIixub25jZT0iT0E2TUc5dEVRR20yaGgiLG5jPTAw"
|
||||
"MDAwMDAxLGNub25jZT0iT0E2TUhYaDZWcVRyUmsiLGRpZ2VzdC11cmk9Im"
|
||||
"ltYXAvZWx3b29kLmlubm9zb2Z0LmNvbSIscmVzcG9uc2U9ZDM4OGRhZDkw"
|
||||
"ZDRiYmQ3NjBhMTUyMzIxZjIxNDNhZjcscW9wPWF1dGg=";
|
||||
"Y2hhcnNldD11dGYtOCx1c2VybmFtZT0iY2hyaXMiLHJlYWxtPSJlbHdvb2"
|
||||
"QuaW5ub3NvZnQuY29tIixub25jZT0iT0E2TUc5dEVRR20yaGgiLG5jPTAw"
|
||||
"MDAwMDAxLGNub25jZT0iT0E2TUhYaDZWcVRyUmsiLGRpZ2VzdC11cmk9Im"
|
||||
"ltYXAvZWx3b29kLmlubm9zb2Z0LmNvbSIscmVzcG9uc2U9ZDM4OGRhZDkw"
|
||||
"ZDRiYmQ3NjBhMTUyMzIxZjIxNDNhZjcscW9wPWF1dGg=";
|
||||
|
||||
int test_plain(xmpp_ctx_t *ctx)
|
||||
{
|
||||
@@ -53,12 +53,12 @@ int test_plain(xmpp_ctx_t *ctx)
|
||||
|
||||
result = sasl_plain(ctx, jid, password);
|
||||
if (result == NULL) {
|
||||
/* SASL PLAIN internal failure! */
|
||||
return 1;
|
||||
/* SASL PLAIN internal failure! */
|
||||
return 1;
|
||||
}
|
||||
if (strncmp(response_plain, result, strlen(response_plain))) {
|
||||
/* SASL PLAIN returned incorrect string! */
|
||||
return 2;
|
||||
/* SASL PLAIN returned incorrect string! */
|
||||
return 2;
|
||||
}
|
||||
xmpp_free(ctx, result);
|
||||
|
||||
@@ -69,12 +69,12 @@ int test_digest_md5(xmpp_ctx_t *ctx)
|
||||
{
|
||||
char *result;
|
||||
|
||||
result = sasl_digest_md5(ctx, challenge_md5,
|
||||
"somenode@somerealm", "secret");
|
||||
result =
|
||||
sasl_digest_md5(ctx, challenge_md5, "somenode@somerealm", "secret");
|
||||
printf("response:\n%s\n", result);
|
||||
if (strcmp(response_md5, result)) {
|
||||
/* generated incorrect response to challenge */
|
||||
return 1;
|
||||
/* generated incorrect response to challenge */
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -87,20 +87,26 @@ int main(int argc, char *argv[])
|
||||
|
||||
printf("allocating context... ");
|
||||
ctx = xmpp_ctx_new(NULL, NULL);
|
||||
if (ctx == NULL) printf("failed to create context\n");
|
||||
if (ctx == NULL) return -1;
|
||||
if (ctx == NULL)
|
||||
printf("failed to create context\n");
|
||||
if (ctx == NULL)
|
||||
return -1;
|
||||
printf("ok.\n");
|
||||
|
||||
printf("testing SASL PLAIN... ");
|
||||
ret = test_plain(ctx);
|
||||
if (ret) printf("failed!\n");
|
||||
if (ret) return ret;
|
||||
if (ret)
|
||||
printf("failed!\n");
|
||||
if (ret)
|
||||
return ret;
|
||||
printf("ok.\n");
|
||||
|
||||
printf("testing SASL DIGEST-MD5... ");
|
||||
ret = test_digest_md5(ctx);
|
||||
if (ret) printf("failed!\n");
|
||||
if (ret) return ret;
|
||||
if (ret)
|
||||
printf("failed!\n");
|
||||
if (ret)
|
||||
return ret;
|
||||
printf("ok.\n");
|
||||
|
||||
printf("freeing context... ");
|
||||
|
||||
@@ -25,12 +25,12 @@
|
||||
* Test vectors for derivation function (RFC6070).
|
||||
*/
|
||||
static const struct {
|
||||
char *P; /* text */
|
||||
char *S; /* salt */
|
||||
char *P; /* text */
|
||||
char *S; /* salt */
|
||||
size_t P_len;
|
||||
size_t S_len;
|
||||
uint32_t c; /* i */
|
||||
char *DK; /* resulting digest */
|
||||
uint32_t c; /* i */
|
||||
char *DK; /* resulting digest */
|
||||
} df_vectors[] = {
|
||||
{
|
||||
.P = "password",
|
||||
@@ -115,14 +115,13 @@ static void test_scram(void)
|
||||
printf("SCRAM_SHA1_ClientKey and SCRAM_SHA1_ClientSignature tests.\n");
|
||||
for (i = 0; i < ARRAY_SIZE(scram_vectors); ++i) {
|
||||
printf("Test #%d: ", (int)i + 1);
|
||||
snprintf(auth, sizeof(auth), "%s,%s,%s",
|
||||
scram_vectors[i].initial + 3, scram_vectors[i].challenge,
|
||||
scram_vectors[i].response);
|
||||
snprintf(auth, sizeof(auth), "%s,%s,%s", scram_vectors[i].initial + 3,
|
||||
scram_vectors[i].challenge, scram_vectors[i].response);
|
||||
test_hex_to_bin(scram_vectors[i].salt, salt, &salt_len);
|
||||
|
||||
SCRAM_SHA1_ClientKey((uint8_t *)scram_vectors[i].password,
|
||||
strlen(scram_vectors[i].password),
|
||||
salt, salt_len, scram_vectors[i].i, key);
|
||||
strlen(scram_vectors[i].password), salt, salt_len,
|
||||
scram_vectors[i].i, key);
|
||||
SCRAM_SHA1_ClientSignature(key, (uint8_t *)auth, strlen(auth), sign);
|
||||
for (j = 0; j < SHA1_DIGEST_SIZE; j++) {
|
||||
sign[j] ^= key[j];
|
||||
|
||||
@@ -12,25 +12,23 @@
|
||||
|
||||
/* Test Vectors (from FIPS PUB 180-1) */
|
||||
static char *test_data[] = {
|
||||
"abc",
|
||||
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
|
||||
"abc", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
|
||||
"A million repetitions of 'a'",
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"};
|
||||
static char *test_results[] = {
|
||||
"A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D",
|
||||
"84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1",
|
||||
"34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F",
|
||||
"AD5B3FDB CB526778 C2839D2F 151EA753 995E26A0"};
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"};
|
||||
static char *test_results[] = {"A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D",
|
||||
"84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1",
|
||||
"34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F",
|
||||
"AD5B3FDB CB526778 C2839D2F 151EA753 995E26A0"};
|
||||
|
||||
static void digest_to_hex(const uint8_t *digest, char *output)
|
||||
{
|
||||
int i,j;
|
||||
int i, j;
|
||||
char *c = output;
|
||||
|
||||
for (i = 0; i < SHA1_DIGEST_SIZE/4; i++) {
|
||||
for (i = 0; i < SHA1_DIGEST_SIZE / 4; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
sprintf(c,"%02X", digest[i*4+j]);
|
||||
sprintf(c, "%02X", digest[i * 4 + j]);
|
||||
c += 2;
|
||||
}
|
||||
sprintf(c, " ");
|
||||
@@ -39,7 +37,7 @@ static void digest_to_hex(const uint8_t *digest, char *output)
|
||||
*(c - 1) = '\0';
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
size_t k;
|
||||
SHA1_CTX context;
|
||||
@@ -49,23 +47,23 @@ int main(int argc, char** argv)
|
||||
|
||||
fprintf(stdout, "verifying SHA-1 implementation... ");
|
||||
|
||||
for (k = 0; k < ARRAY_SIZE(test_data); k++){
|
||||
for (k = 0; k < ARRAY_SIZE(test_data); k++) {
|
||||
if (k == 2) {
|
||||
/* this case will be checked below */
|
||||
continue;
|
||||
}
|
||||
copy = strdup(test_data[k]);
|
||||
crypto_SHA1_Init(&context);
|
||||
crypto_SHA1_Update(&context, (uint8_t*)test_data[k],
|
||||
crypto_SHA1_Update(&context, (uint8_t *)test_data[k],
|
||||
strlen(test_data[k]));
|
||||
crypto_SHA1_Final(&context, digest);
|
||||
digest_to_hex(digest, output);
|
||||
|
||||
if (strcmp(output, test_results[k])) {
|
||||
fprintf(stdout, "FAIL\n");
|
||||
fprintf(stderr,"* hash of \"%s\" incorrect:\n", test_data[k]);
|
||||
fprintf(stderr,"\t%s returned\n", output);
|
||||
fprintf(stderr,"\t%s is correct\n", test_results[k]);
|
||||
fprintf(stderr, "* hash of \"%s\" incorrect:\n", test_data[k]);
|
||||
fprintf(stderr, "\t%s returned\n", output);
|
||||
fprintf(stderr, "\t%s is correct\n", test_results[k]);
|
||||
return (1);
|
||||
}
|
||||
if (strcmp(copy, test_data[k])) {
|
||||
@@ -78,18 +76,18 @@ int main(int argc, char** argv)
|
||||
/* million 'a' vector we feed separately */
|
||||
crypto_SHA1_Init(&context);
|
||||
for (k = 0; k < 1000000; k++)
|
||||
crypto_SHA1_Update(&context, (uint8_t*)"a", 1);
|
||||
crypto_SHA1_Update(&context, (uint8_t *)"a", 1);
|
||||
crypto_SHA1_Final(&context, digest);
|
||||
digest_to_hex(digest, output);
|
||||
if (strcmp(output, test_results[2])) {
|
||||
fprintf(stdout, "FAIL\n");
|
||||
fprintf(stderr,"* hash of \"%s\" incorrect:\n", test_data[2]);
|
||||
fprintf(stderr,"\t%s returned\n", output);
|
||||
fprintf(stderr,"\t%s is correct\n", test_results[2]);
|
||||
fprintf(stderr, "* hash of \"%s\" incorrect:\n", test_data[2]);
|
||||
fprintf(stderr, "\t%s returned\n", output);
|
||||
fprintf(stderr, "\t%s is correct\n", test_results[2]);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* success */
|
||||
fprintf(stdout, "ok\n");
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -16,76 +16,50 @@
|
||||
#define LONG_STRING 1024
|
||||
#endif
|
||||
|
||||
int main (void)
|
||||
int main(void)
|
||||
{
|
||||
char buf1[LONG_STRING];
|
||||
char buf2[LONG_STRING];
|
||||
char *fp_fmt[] = {
|
||||
"%-1.5f",
|
||||
"%1.5f",
|
||||
"%123.9f",
|
||||
"%10.5f",
|
||||
"% 10.5f",
|
||||
"%+22.9f",
|
||||
"%+4.9f",
|
||||
"%01.3f",
|
||||
"%4f",
|
||||
"%3.1f",
|
||||
"%3.2f",
|
||||
"%.0f",
|
||||
"%.1f",
|
||||
NULL
|
||||
};
|
||||
double fp_nums[] = { -1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96, 0.996,
|
||||
0.9996, 1.996, 4.136, 0};
|
||||
char *int_fmt[] = {
|
||||
"%-1.5d",
|
||||
"%1.5d",
|
||||
"%123.9d",
|
||||
"%5.5d",
|
||||
"%10.5d",
|
||||
"% 10.5d",
|
||||
"%+22.33d",
|
||||
"%01.3d",
|
||||
"%4d",
|
||||
"0x%x",
|
||||
"0x%04x",
|
||||
NULL
|
||||
};
|
||||
long int_nums[] = { -1, 134, 91340, 341, 0203, 0x76543210, 0};
|
||||
int x, y;
|
||||
int fail = 0;
|
||||
int num = 0;
|
||||
char buf1[LONG_STRING];
|
||||
char buf2[LONG_STRING];
|
||||
char *fp_fmt[] = {"%-1.5f", "%1.5f", "%123.9f", "%10.5f", "% 10.5f",
|
||||
"%+22.9f", "%+4.9f", "%01.3f", "%4f", "%3.1f",
|
||||
"%3.2f", "%.0f", "%.1f", NULL};
|
||||
double fp_nums[] = {-1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96,
|
||||
0.996, 0.9996, 1.996, 4.136, 0};
|
||||
char *int_fmt[] = {"%-1.5d", "%1.5d", "%123.9d", "%5.5d",
|
||||
"%10.5d", "% 10.5d", "%+22.33d", "%01.3d",
|
||||
"%4d", "0x%x", "0x%04x", NULL};
|
||||
long int_nums[] = {-1, 134, 91340, 341, 0203, 0x76543210, 0};
|
||||
int x, y;
|
||||
int fail = 0;
|
||||
int num = 0;
|
||||
|
||||
printf ("Testing xmpp_snprintf format codes against system sprintf...\n");
|
||||
printf("Testing xmpp_snprintf format codes against system sprintf...\n");
|
||||
|
||||
for (x = 0; fp_fmt[x] != NULL ; x++)
|
||||
for (y = 0; fp_nums[y] != 0 ; y++)
|
||||
{
|
||||
xmpp_snprintf (buf1, sizeof (buf1), fp_fmt[x], fp_nums[y]);
|
||||
sprintf (buf2, fp_fmt[x], fp_nums[y]);
|
||||
if (strcmp (buf1, buf2))
|
||||
{
|
||||
printf("xmpp_snprintf doesn't match Format: %s\n\txmpp_snprintf = %s\n\tsprintf = %s\n",
|
||||
fp_fmt[x], buf1, buf2);
|
||||
fail++;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
for (x = 0; fp_fmt[x] != NULL; x++)
|
||||
for (y = 0; fp_nums[y] != 0; y++) {
|
||||
xmpp_snprintf(buf1, sizeof(buf1), fp_fmt[x], fp_nums[y]);
|
||||
sprintf(buf2, fp_fmt[x], fp_nums[y]);
|
||||
if (strcmp(buf1, buf2)) {
|
||||
printf("xmpp_snprintf doesn't match Format: "
|
||||
"%s\n\txmpp_snprintf = %s\n\tsprintf = %s\n",
|
||||
fp_fmt[x], buf1, buf2);
|
||||
fail++;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
|
||||
for (x = 0; int_fmt[x] != NULL ; x++)
|
||||
for (y = 0; int_nums[y] != 0 ; y++)
|
||||
{
|
||||
xmpp_snprintf (buf1, sizeof (buf1), int_fmt[x], int_nums[y]);
|
||||
sprintf (buf2, int_fmt[x], int_nums[y]);
|
||||
if (strcmp (buf1, buf2))
|
||||
{
|
||||
printf("xmpp_snprintf doesn't match Format: %s\n\txmpp_snprintf = %s\n\tsprintf = %s\n",
|
||||
int_fmt[x], buf1, buf2);
|
||||
fail++;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
printf ("%d tests failed out of %d.\n", fail, num);
|
||||
return fail != 0 ? 1 : 0;
|
||||
for (x = 0; int_fmt[x] != NULL; x++)
|
||||
for (y = 0; int_nums[y] != 0; y++) {
|
||||
xmpp_snprintf(buf1, sizeof(buf1), int_fmt[x], int_nums[y]);
|
||||
sprintf(buf2, int_fmt[x], int_nums[y]);
|
||||
if (strcmp(buf1, buf2)) {
|
||||
printf("xmpp_snprintf doesn't match Format: "
|
||||
"%s\n\txmpp_snprintf = %s\n\tsprintf = %s\n",
|
||||
int_fmt[x], buf1, buf2);
|
||||
fail++;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
printf("%d tests failed out of %d.\n", fail, num);
|
||||
return fail != 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
@@ -23,14 +23,19 @@ int wait_for_connect(sock_t sock)
|
||||
fd_set wfds, efds;
|
||||
int ret;
|
||||
|
||||
FD_ZERO(&wfds); FD_SET(sock, &wfds);
|
||||
FD_ZERO(&efds); FD_SET(sock, &efds);
|
||||
FD_ZERO(&wfds);
|
||||
FD_SET(sock, &wfds);
|
||||
FD_ZERO(&efds);
|
||||
FD_SET(sock, &efds);
|
||||
|
||||
ret = select(sock + 1, NULL, &wfds, &efds, NULL);
|
||||
if (ret <= 0) return -1;
|
||||
if (ret <= 0)
|
||||
return -1;
|
||||
|
||||
if (FD_ISSET(sock, &efds)) return 0;
|
||||
if (FD_ISSET(sock, &wfds)) return 1;
|
||||
if (FD_ISSET(sock, &efds))
|
||||
return 0;
|
||||
if (FD_ISSET(sock, &wfds))
|
||||
return 1;
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -45,15 +50,15 @@ int main(int argc, char **argv)
|
||||
sock = sock_connect("www.google.com", 80);
|
||||
|
||||
if (sock < 0) {
|
||||
sock_shutdown();
|
||||
return 1;
|
||||
sock_shutdown();
|
||||
return 1;
|
||||
}
|
||||
|
||||
err = wait_for_connect(sock);
|
||||
if (err < 0) {
|
||||
sock_close(sock);
|
||||
sock_shutdown();
|
||||
return 1;
|
||||
sock_close(sock);
|
||||
sock_shutdown();
|
||||
return 1;
|
||||
}
|
||||
|
||||
sock_close(sock);
|
||||
|
||||
@@ -23,11 +23,11 @@
|
||||
/* strtok_s() has appeared in visual studio 2005.
|
||||
Use own implementation for older versions. */
|
||||
#ifdef _MSC_VER
|
||||
# if (_MSC_VER >= 1400)
|
||||
# define strtok_r strtok_s
|
||||
# else
|
||||
# define strtok_r xmpp_strtok_r
|
||||
# endif
|
||||
#if (_MSC_VER >= 1400)
|
||||
#define strtok_r strtok_s
|
||||
#else
|
||||
#define strtok_r xmpp_strtok_r
|
||||
#endif
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
static int test_strtok_r(void)
|
||||
@@ -75,8 +75,8 @@ static int test_strdup_one(xmpp_ctx_t *ctx, const char *s)
|
||||
|
||||
if (!s1 || !s2 || strcmp(s1, s2) != 0) {
|
||||
rc = -1;
|
||||
printf("strdup: '%s', xmpp_strdup: '%s'\n",
|
||||
s1 ? s1 : "<NULL>", s2 ? s2 : "<NULL>");
|
||||
printf("strdup: '%s', xmpp_strdup: '%s'\n", s1 ? s1 : "<NULL>",
|
||||
s2 ? s2 : "<NULL>");
|
||||
}
|
||||
|
||||
free(s1);
|
||||
@@ -92,7 +92,7 @@ static int test_strdup(void)
|
||||
size_t i;
|
||||
int rc = 0;
|
||||
|
||||
static const char *tests[] = { "", "\0", "test", "s p a c e", "\n\r" };
|
||||
static const char *tests[] = {"", "\0", "test", "s p a c e", "\n\r"};
|
||||
|
||||
ctx = xmpp_ctx_new(NULL, NULL);
|
||||
assert(ctx != NULL);
|
||||
|
||||
Reference in New Issue
Block a user