Move the xmpp library to its new name.
This commit is contained in:
151
tests/test_base64.c
Normal file
151
tests/test_base64.c
Normal file
@@ -0,0 +1,151 @@
|
||||
/* test_base64.c
|
||||
** XMPP client library -- test routines for the base64 codec
|
||||
**
|
||||
** Copyright (C) 2005 OGG, LCC. All rights reserved.
|
||||
**
|
||||
** This software is provided AS-IS with no warranty, either express
|
||||
** or implied.
|
||||
**
|
||||
** This software is distributed under license and may not be copied,
|
||||
** modified or distributed except as expressly authorized under the
|
||||
** terms of the license contained in the file LICENSE.txt in this
|
||||
** distribution.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "xmpp.h"
|
||||
#include "common.h"
|
||||
#include "sasl.h"
|
||||
|
||||
static const unsigned char text_1[] = "How now brown cow?";
|
||||
static const char base64_1[] = "SG93IG5vdyBicm93biBjb3c/";
|
||||
static const unsigned char text_2[] = {0x14,0xfb,0x9c,0x03,0xd9,0x7e,0x00};
|
||||
static const char base64_2[] = "FPucA9l+";
|
||||
static const unsigned char text_3[] =
|
||||
"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.";
|
||||
static const char base64_3[] =
|
||||
"RnJvbSByZXN0IGFuZCBzbGVlcCwgd2hpY2ggYnV0IHRoeSBwaWN0dXJl"
|
||||
"cyBiZSwgTXVjaCBwbGVhc3VyZTsgdGhlbiBmcm9tIHRoZWUgbXVjaCBt"
|
||||
"b3JlIG11c3QgZmxvdywgQW5kIHNvb25lc3Qgb3VyIGJlc3QgbWVuIHdp"
|
||||
"dGggdGhlZSBkbyBnbywgUmVzdCBvZiB0aGVpciBib25lcywgYW5kIHNv"
|
||||
"dWwncyBkZWxpdmVyeS4=";
|
||||
static const unsigned char text_4[] =
|
||||
{0xd6, 0x2f, 0x27, 0x49, 0x7e, 0xdd, 0xf3, 0xd5,
|
||||
0x41, 0xbc, 0x1b, 0xe9, 0xdf, 0xe9, 0xb3, 0x08, 0x00};
|
||||
static const char base64_4[] = "1i8nSX7d89VBvBvp3+mzCA==";
|
||||
static const char text_5[] =
|
||||
"realm=\"chesspark.com\",nonce=\"b243c0d663257a9149999cef2f83a22116559e93\",qop=\"auth\",charset=utf-8,algorithm=md5-sess";
|
||||
static const char base64_5[] =
|
||||
"cmVhbG09ImNoZXNzcGFyay5jb20iLG5vbmNlPSJiMjQzYzBkNjYzMjU3"
|
||||
"YTkxNDk5OTljZWYyZjgzYTIyMTE2NTU5ZTkzIixxb3A9ImF1dGgiLGNo"
|
||||
"YXJzZXQ9dXRmLTgsYWxnb3JpdGhtPW1kNS1zZXNz";
|
||||
|
||||
int test_encode(xmpp_ctx_t *ctx)
|
||||
{
|
||||
char *result;
|
||||
result = base64_encode(ctx, text_1, strlen(text_1));
|
||||
if (result == NULL) return 2;
|
||||
if (strlen(result) != strlen(base64_1)) return 1;
|
||||
if (strncmp(base64_1, result, strlen(base64_1))) return 1;
|
||||
xmpp_free(ctx,result);
|
||||
|
||||
result = base64_encode(ctx, text_2, strlen(text_2));
|
||||
if (result == NULL) return 2;
|
||||
if (strlen(result) != strlen(base64_2)) return 1;
|
||||
if (strncmp(base64_2, result, strlen(base64_2))) return 1;
|
||||
xmpp_free(ctx,result);
|
||||
|
||||
result = base64_encode(ctx, text_3, strlen(text_3));
|
||||
if (result == NULL) return 2;
|
||||
if (strlen(result) != strlen(base64_3)) return 1;
|
||||
if (strncmp(base64_3, result, strlen(base64_3))) return 1;
|
||||
xmpp_free(ctx,result);
|
||||
|
||||
result = base64_encode(ctx, text_4, strlen(text_4));
|
||||
if (result == NULL) return 2;
|
||||
if (strlen(result) != strlen(base64_4)) return 1;
|
||||
if (strncmp(base64_4, result, strlen(base64_4))) return 1;
|
||||
xmpp_free(ctx,result);
|
||||
|
||||
result = base64_encode(ctx, text_5, strlen(text_5));
|
||||
if (result == NULL) return 2;
|
||||
if (strlen(result) != strlen(base64_5)) return 1;
|
||||
if (strncmp(base64_5, result, strlen(base64_5))) return 1;
|
||||
xmpp_free(ctx,result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int test_decode(xmpp_ctx_t *ctx)
|
||||
{
|
||||
unsigned char *result;
|
||||
|
||||
result = base64_decode(ctx, base64_1, strlen(base64_1));
|
||||
if (result == NULL) return 2;
|
||||
if (strlen(result) != strlen(text_1)) return 1;
|
||||
if (strncmp(text_1, result, strlen(text_1))) return 1;
|
||||
xmpp_free(ctx,result);
|
||||
|
||||
result = base64_decode(ctx, base64_2, strlen(base64_2));
|
||||
if (result == NULL) return 2;
|
||||
if (strlen(result) != strlen(text_2)) return 1;
|
||||
if (strncmp(text_2, result, strlen(text_2))) return 1;
|
||||
xmpp_free(ctx,result);
|
||||
|
||||
result = base64_decode(ctx, base64_3, strlen(base64_3));
|
||||
if (result == NULL) return 2;
|
||||
if (strlen(result) != strlen(text_3)) return 1;
|
||||
if (strncmp(text_3, result, strlen(text_3))) return 1;
|
||||
xmpp_free(ctx,result);
|
||||
|
||||
result = base64_decode(ctx, base64_4, strlen(base64_4));
|
||||
if (result == NULL) return 2;
|
||||
if (strlen(result) != strlen(text_4)) return 1;
|
||||
if (strncmp(text_4, result, strlen(text_4))) return 1;
|
||||
xmpp_free(ctx,result);
|
||||
|
||||
result = base64_decode(ctx, base64_5, strlen(base64_5));
|
||||
if (result == NULL) return 2;
|
||||
if (strlen(result) != strlen(text_5)) return 1;
|
||||
if (strncmp(text_5, result, strlen(text_5))) return 1;
|
||||
xmpp_free(ctx,result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
xmpp_ctx_t *ctx;
|
||||
int ret;
|
||||
|
||||
printf("allocating context... ");
|
||||
ctx = xmpp_ctx_new(NULL, NULL);
|
||||
if (ctx == NULL) printf("failed to create context\n");
|
||||
if (ctx == NULL) return -1;
|
||||
printf("ok.\n");
|
||||
|
||||
printf("testing encode... ");
|
||||
ret = test_encode(ctx);
|
||||
if (ret) printf("base64_encode failed!\n");
|
||||
if (ret) return ret;
|
||||
printf("ok.\n");
|
||||
|
||||
printf("testing decode... ");
|
||||
ret = test_decode(ctx);
|
||||
if (ret) printf("base64_decode failed!\n");
|
||||
if (ret) return ret;
|
||||
printf("ok.\n");
|
||||
|
||||
printf("freeing context... ");
|
||||
xmpp_ctx_free(ctx);
|
||||
printf("ok.\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
102
tests/test_ctx.c
Normal file
102
tests/test_ctx.c
Normal file
@@ -0,0 +1,102 @@
|
||||
/* test_ctx.c
|
||||
** XMPP client library -- test routines for the library run-time context
|
||||
**
|
||||
** Copyright (C) 2005 OGG, LCC. All rights reserved.
|
||||
**
|
||||
** This software is provided AS-IS with no warranty, either express
|
||||
** or implied.
|
||||
**
|
||||
** This software is distributed under license and may not be copied,
|
||||
** modified or distributed except as expressly authorized under the
|
||||
** terms of the license contained in the file LICENSE.txt in this
|
||||
** distribution.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "xmpp.h"
|
||||
#include "common.h"
|
||||
|
||||
static int log_called = 0;
|
||||
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)
|
||||
{
|
||||
mem_alloc_called++;
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void my_free(void *p)
|
||||
{
|
||||
mem_free_called++;
|
||||
return free(p);
|
||||
}
|
||||
|
||||
void *my_realloc(void *p, const size_t size)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
xmpp_ctx_t *ctx;
|
||||
xmpp_mem_t mymem;
|
||||
xmpp_log_t mylog;
|
||||
char my_str[5] = "asdf";
|
||||
void *testptr1, *testptr2;
|
||||
|
||||
ctx = xmpp_ctx_new(NULL, NULL);
|
||||
if (ctx == NULL) return 1;
|
||||
|
||||
/* destroy context */
|
||||
xmpp_ctx_free(ctx);
|
||||
|
||||
/* setup our memory handler */
|
||||
mymem.alloc = my_alloc;
|
||||
mymem.free = my_free;
|
||||
mymem.realloc = my_realloc;
|
||||
|
||||
/* setup our logger */
|
||||
mylog.handler = my_logger;
|
||||
mylog.userdata = my_str;
|
||||
|
||||
ctx = xmpp_ctx_new(&mymem, &mylog);
|
||||
xmpp_debug(ctx, "test", "hello");
|
||||
|
||||
testptr1 = xmpp_alloc(ctx, 1024);
|
||||
if (testptr1 == NULL) {
|
||||
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, testptr2);
|
||||
|
||||
xmpp_ctx_free(ctx);
|
||||
|
||||
/* check for test failure */
|
||||
if (!(log_called && mem_alloc_called && mem_realloc_called &&
|
||||
mem_free_called))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
141
tests/test_hash.c
Normal file
141
tests/test_hash.c
Normal file
@@ -0,0 +1,141 @@
|
||||
/* test_hash.c
|
||||
** XMPP client library -- self-test for the hash-table implementation
|
||||
**
|
||||
** Copyright (C) 2005 OGG, LCC. All rights reserved.
|
||||
**
|
||||
** This software is provided AS-IS with no warranty, either express
|
||||
** or implied.
|
||||
**
|
||||
** This software is distributed under license and may not be copied,
|
||||
** modified or distributed except as expressly authorized under the
|
||||
** terms of the license contained in the file LICENSE.txt in this
|
||||
** distribution.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "xmpp.h"
|
||||
#include "common.h"
|
||||
#include "hash.h"
|
||||
|
||||
#define TABLESIZE 100
|
||||
#define TESTSIZE 500
|
||||
|
||||
/* static test data */
|
||||
const int nkeys = 5;
|
||||
const char *keys[] = {
|
||||
"foo", "bar", "baz", "quux", "xyzzy"
|
||||
};
|
||||
const char *values[] = {
|
||||
"wuzzle", "mug", "canonical", "rosebud", "lottery"
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
xmpp_ctx_t *ctx;
|
||||
hash_t *table, *clone;
|
||||
hash_iterator_t *iter;
|
||||
unsigned int seed;
|
||||
const char *key;
|
||||
char *result;
|
||||
int err = 0;
|
||||
int i;
|
||||
|
||||
/* initialize random numbers */
|
||||
if (argc > 2) {
|
||||
/* use a seed from the command line */
|
||||
seed = (unsigned int)atoi(argv[1]);
|
||||
} else {
|
||||
seed = (unsigned int)clock();
|
||||
}
|
||||
/* using random seed 'seed' */
|
||||
srand(seed);
|
||||
|
||||
/* allocate a default context */
|
||||
ctx = xmpp_ctx_new(NULL, NULL);
|
||||
if (ctx == NULL) {
|
||||
/* ctx allocation failed! */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* allocate a hash table */
|
||||
table = hash_new(ctx, TABLESIZE, NULL);
|
||||
if (table == NULL) {
|
||||
/* table allocation failed! */
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* test insertion */
|
||||
for (i = 0; i < nkeys; i++) {
|
||||
err = hash_add(table, keys[i], (void*)values[i]);
|
||||
if (err) return err;
|
||||
}
|
||||
|
||||
/* test key count */
|
||||
if (hash_num_keys(table) != nkeys) {
|
||||
/* wrong number of keys in table! */
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* test cloning */
|
||||
clone = hash_clone(table);
|
||||
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
|
||||
/* test key iterator */
|
||||
iter = hash_iter_new(clone);
|
||||
if (iter == NULL) {
|
||||
/* 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);
|
||||
if (key != NULL) {
|
||||
/* extra keys returned! */
|
||||
return 1;
|
||||
}
|
||||
key = hash_iter_next(iter);
|
||||
if (key != NULL) {
|
||||
/* extra keys returned! */
|
||||
return 1;
|
||||
}
|
||||
hash_iter_release(iter);
|
||||
|
||||
/* release the hash table */
|
||||
hash_release(table);
|
||||
|
||||
/* test drops */
|
||||
hash_drop(clone, keys[2]);
|
||||
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;
|
||||
/* 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;
|
||||
|
||||
/* release our clone */
|
||||
hash_release(clone);
|
||||
|
||||
/* release our library context */
|
||||
xmpp_ctx_free(ctx);
|
||||
|
||||
return err;
|
||||
}
|
||||
128
tests/test_jid.c
Normal file
128
tests/test_jid.c
Normal file
@@ -0,0 +1,128 @@
|
||||
/* test_base64.c
|
||||
** XMPP client library -- test routines for the jid utils
|
||||
**
|
||||
** Copyright (C) 2005 OGG, LCC. All rights reserved.
|
||||
**
|
||||
** This software is provided AS-IS with no warranty, either express
|
||||
** or implied.
|
||||
**
|
||||
** This software is distributed under license and may not be copied,
|
||||
** modified or distributed except as expressly authorized under the
|
||||
** terms of the license contained in the file LICENSE.txt in this
|
||||
** distribution.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "xmpp.h"
|
||||
#include "common.h"
|
||||
|
||||
static const char jid1[] = "foo@bar.com";
|
||||
static const char jid2[] = "anyone@example.com/hullo";
|
||||
static const char jid3[] = "manic.porter@xyz.net/frob";
|
||||
static const char jid4[] = "domain.tld";
|
||||
|
||||
int test_jid(xmpp_ctx_t *ctx)
|
||||
{
|
||||
char *node;
|
||||
char *domain;
|
||||
char *resource;
|
||||
|
||||
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, node, domain, resource);
|
||||
if (strcmp(node, "foo")) return 1;
|
||||
if (strcmp(domain, "bar.com")) return 1;
|
||||
if (resource != NULL) return 1;
|
||||
if (node) xmpp_free(ctx, node);
|
||||
if (domain) xmpp_free(ctx, domain);
|
||||
if (resource) xmpp_free(ctx, resource);
|
||||
|
||||
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, node, domain, resource);
|
||||
if (strcmp(node, "anyone")) return 1;
|
||||
if (strcmp(domain, "example.com")) return 1;
|
||||
if (strcmp(resource, "hullo")) return 1;
|
||||
if (node) xmpp_free(ctx, node);
|
||||
if (domain) xmpp_free(ctx, domain);
|
||||
if (resource) xmpp_free(ctx, resource);
|
||||
|
||||
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, node, domain, resource);
|
||||
if (strcmp(node, "manic.porter")) return 1;
|
||||
if (strcmp(domain, "xyz.net")) return 1;
|
||||
if (strcmp(resource, "frob")) return 1;
|
||||
if (node) xmpp_free(ctx, node);
|
||||
if (domain) xmpp_free(ctx, domain);
|
||||
if (resource) xmpp_free(ctx, resource);
|
||||
|
||||
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, node, domain, resource);
|
||||
if (node != NULL) return 1;
|
||||
if (strcmp(domain, "domain.tld")) return 1;
|
||||
if (resource != NULL) return 1;
|
||||
if (node) xmpp_free(ctx, node);
|
||||
if (domain) xmpp_free(ctx, domain);
|
||||
if (resource) xmpp_free(ctx, resource);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_jid_new(xmpp_ctx_t *ctx)
|
||||
{
|
||||
char *jid;
|
||||
|
||||
jid = xmpp_jid_new(ctx, "node", "domain", "resource");
|
||||
printf("new jid: '%s'\n", jid);
|
||||
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;
|
||||
xmpp_free(ctx, jid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
xmpp_ctx_t *ctx;
|
||||
int ret;
|
||||
|
||||
printf("allocating context... ");
|
||||
ctx = xmpp_ctx_new(NULL, NULL);
|
||||
if (ctx == NULL) printf("failed to create context\n");
|
||||
if (ctx == NULL) return -1;
|
||||
printf("ok.\n");
|
||||
|
||||
printf("testing jid routines... ");
|
||||
ret = test_jid(ctx);
|
||||
if (ret) printf("failed!\n");
|
||||
if (ret) return ret;
|
||||
printf("ok.\n");
|
||||
|
||||
printf("testing jid new routines... ");
|
||||
ret = test_jid_new(ctx);
|
||||
if (ret) printf("failed!\n");
|
||||
if (ret) return ret;
|
||||
printf("ok.\n");
|
||||
|
||||
printf("freeing context... ");
|
||||
xmpp_ctx_free(ctx);
|
||||
printf("ok.\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
114
tests/test_sasl.c
Normal file
114
tests/test_sasl.c
Normal file
@@ -0,0 +1,114 @@
|
||||
/* test_sasl.c
|
||||
** XMPP client library -- test routines for the SASL implementation
|
||||
**
|
||||
** Copyright (C) 2005 OGG, LCC. All rights reserved.
|
||||
**
|
||||
** This software is provided AS-IS with no warranty, either express
|
||||
** or implied.
|
||||
**
|
||||
** This software is distributed under license and may not be copied,
|
||||
** modified or distributed except as expressly authorized under the
|
||||
** terms of the license contained in the file LICENSE.txt in this
|
||||
** distribution.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "xmpp.h"
|
||||
#include "common.h"
|
||||
#include "sasl.h"
|
||||
|
||||
static const unsigned char jid[] = "foo@bar.com";
|
||||
static const char password[] = "secret";
|
||||
static const char response_plain[] = "AGZvb0BiYXIuY29tAHNlY3JldA==";
|
||||
|
||||
static const char challenge_md5[] =
|
||||
"cmVhbG09InNvbWVyZWFsbSIsbm9uY2U9Ik9BNk1HOXRFUUdtMmhoIixxb3A9ImF1dGgi"
|
||||
"LGNoYXJzZXQ9dXRmLTgsYWxnb3JpdGhtPW1kNS1zZXNzCg==";
|
||||
static const char response_md5[] =
|
||||
"dXNlcm5hbWU9InNvbWVub2RlIixyZWFsbT0ic29tZXJlYWxtIixub25jZT0i"
|
||||
"T0E2TUc5dEVRR20yaGgiLGNub25jZT0iMDBERUFEQkVFRjAwIixuYz0wMDAw"
|
||||
"MDAwMSxxb3A9YXV0aCxkaWdlc3QtdXJpPSJ4bXBwL3NvbWVyZWFsbSIscmVz"
|
||||
"cG9uc2U9NGVhNmU4N2JjMDkzMzUwNzQzZGIyOGQ3MDIwOGNhZmIsY2hhcnNl"
|
||||
"dD11dGYtOA==";
|
||||
static const char response_md5_rfc[] =
|
||||
"dXNlcm5hbWU9InNvbWVub2RlIixyZWFsbT0ic29tZXJlYWxtIixub25jZT0i"
|
||||
"T0E2TUc5dEVRR20yaGgiLGNub25jZT0iT0E2TUhYaDZWcVRyUmsiLG5jPTAw"
|
||||
"MDAwMDAxLHFvcD1hdXRoLGRpZ2VzdC11cmk9InhtcHAvZXhhbXBsZS5jb20i"
|
||||
"LHJlc3BvbnNlPWQzODhkYWQ5MGQ0YmJkNzYwYTE1MjMyMWYyMTQzYWY3LGNo"
|
||||
"YXJzZXQ9dXRmLTgK";
|
||||
|
||||
static const char challenge_md5_2[] =
|
||||
"cmVhbG09ImVsd29vZC5pbm5vc29mdC5jb20iLG5vbmNlPSJPQTZNRzl0"
|
||||
"RVFHbTJoaCIscW9wPSJhdXRoIixhbGdvcml0aG09bWQ1LXNlc3MsY2hh"
|
||||
"cnNldD11dGYtOA==";
|
||||
static const char response_md5_2[] =
|
||||
"Y2hhcnNldD11dGYtOCx1c2VybmFtZT0iY2hyaXMiLHJlYWxtPSJlbHdvb2"
|
||||
"QuaW5ub3NvZnQuY29tIixub25jZT0iT0E2TUc5dEVRR20yaGgiLG5jPTAw"
|
||||
"MDAwMDAxLGNub25jZT0iT0E2TUhYaDZWcVRyUmsiLGRpZ2VzdC11cmk9Im"
|
||||
"ltYXAvZWx3b29kLmlubm9zb2Z0LmNvbSIscmVzcG9uc2U9ZDM4OGRhZDkw"
|
||||
"ZDRiYmQ3NjBhMTUyMzIxZjIxNDNhZjcscW9wPWF1dGg=";
|
||||
|
||||
int test_plain(xmpp_ctx_t *ctx)
|
||||
{
|
||||
char *result;
|
||||
|
||||
result = sasl_plain(ctx, jid, password);
|
||||
if (result == NULL) {
|
||||
/* SASL PLAIN internal failure! */
|
||||
return 1;
|
||||
}
|
||||
if (strncmp(response_plain, result, strlen(response_plain))) {
|
||||
/* SASL PLAIN returned incorrect string! */
|
||||
return 2;
|
||||
}
|
||||
xmpp_free(ctx, result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_digest_md5(xmpp_ctx_t *ctx)
|
||||
{
|
||||
char *result;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
xmpp_ctx_t *ctx;
|
||||
int ret;
|
||||
|
||||
printf("allocating context... ");
|
||||
ctx = xmpp_ctx_new(NULL, NULL);
|
||||
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;
|
||||
printf("ok.\n");
|
||||
|
||||
printf("testing SASL DIGEST-MD5... ");
|
||||
ret = test_digest_md5(ctx);
|
||||
if (ret) printf("failed!\n");
|
||||
if (ret) return ret;
|
||||
printf("ok.\n");
|
||||
|
||||
printf("freeing context... ");
|
||||
xmpp_ctx_free(ctx);
|
||||
printf("ok.\n");
|
||||
|
||||
return ret;
|
||||
}
|
||||
64
tests/test_sock.c
Normal file
64
tests/test_sock.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/* test_sock.c
|
||||
** XMPP client library -- test routines for the socket abstraction
|
||||
**
|
||||
** Copyright (C) 2005 OGG, LCC. All rights reserved.
|
||||
**
|
||||
** This software is provided AS-IS with no warranty, either express
|
||||
** or implied.
|
||||
**
|
||||
** This software is distributed under license and may not be copied,
|
||||
** modified or distributed except as expressly authorized under the
|
||||
** terms of the license contained in the file LICENSE.txt in this
|
||||
** distribution.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#include "sock.h"
|
||||
|
||||
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);
|
||||
|
||||
ret = select(sock + 1, NULL, &wfds, &efds, NULL);
|
||||
if (ret <= 0) return -1;
|
||||
|
||||
if (FD_ISSET(sock, &efds)) return 0;
|
||||
if (FD_ISSET(sock, &wfds)) return 1;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
sock_t sock;
|
||||
int err;
|
||||
|
||||
sock_initialize();
|
||||
|
||||
sock = sock_connect("www.google.com", 80);
|
||||
|
||||
if (sock < 0) {
|
||||
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 0;
|
||||
}
|
||||
Reference in New Issue
Block a user