Fix examples to use new API and lots of compiler warnings.
This commit is contained in:
@@ -12,6 +12,10 @@
|
||||
** distribution.
|
||||
*/
|
||||
|
||||
/** @file
|
||||
* Internally used functions and structures.
|
||||
*/
|
||||
|
||||
#ifndef __LIBSTROPHE_COMMON_H__
|
||||
#define __LIBSTROPHE_COMMON_H__
|
||||
|
||||
|
||||
@@ -32,6 +32,13 @@
|
||||
#include "strophe.h"
|
||||
#include "common.h"
|
||||
|
||||
/* do any of the immediate children have namespaces that match? */
|
||||
static int _match_children(xmpp_stanza_t * const stanza,
|
||||
const char * const ns)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Fire off all stanza handlers that match.
|
||||
* This function is called internally by the event loop whenever stanzas
|
||||
* are received from the XMPP server.
|
||||
@@ -99,7 +106,8 @@ void handler_fire_stanza(xmpp_conn_t * const conn,
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((!item->ns || (ns && strcmp(ns, item->ns) == 0)) &&
|
||||
if ((!item->ns || (ns && strcmp(ns, item->ns) == 0) ||
|
||||
_match_children(stanza, item->ns)) &&
|
||||
(!item->name || (name && strcmp(name, item->name) == 0)) &&
|
||||
(!item->type || (type && strcmp(type, item->type) == 0)))
|
||||
if (!((xmpp_handler)(item->handler))(conn, stanza, item->userdata)) {
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
** distribution.
|
||||
*/
|
||||
|
||||
/** @file
|
||||
* Hash table API.
|
||||
*/
|
||||
|
||||
#ifndef __LIBSTROPHE_HASH_H__
|
||||
#define __LIBSTROPHE_HASH_H__
|
||||
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
** This code is in the Public Domain.
|
||||
*/
|
||||
|
||||
/** @file
|
||||
* MD5 hash API.
|
||||
*/
|
||||
|
||||
#ifndef MD5_H
|
||||
#define MD5_H
|
||||
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
** distribution.
|
||||
*/
|
||||
|
||||
/** @file
|
||||
* Type definitions for platforms without stdint.h.
|
||||
*/
|
||||
|
||||
#ifndef __LIBSTROPHE_OSTYPES_H__
|
||||
#define __LIBSTROPHE_OSTYPES_H__
|
||||
|
||||
|
||||
78
src/sasl.c
78
src/sasl.c
@@ -56,7 +56,7 @@ char *sasl_plain(xmpp_ctx_t *ctx, const char *authid, const char *password) {
|
||||
memcpy(msg+1, authid, idlen);
|
||||
msg[1+idlen] = '\0';
|
||||
memcpy(msg+1+idlen+1, password, passlen);
|
||||
result = base64_encode(ctx, msg, 2 + idlen + passlen);
|
||||
result = base64_encode(ctx, (unsigned char *)msg, 2 + idlen + passlen);
|
||||
xmpp_free(ctx, msg);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ char *sasl_plain(xmpp_ctx_t *ctx, const char *authid, const char *password) {
|
||||
/** helpers for digest auth */
|
||||
|
||||
/* create a new, null-terminated string from a substring */
|
||||
static char *_make_string(xmpp_ctx_t *ctx, const char *s, const int len)
|
||||
static char *_make_string(xmpp_ctx_t *ctx, const char *s, const unsigned len)
|
||||
{
|
||||
char *result;
|
||||
|
||||
@@ -98,9 +98,9 @@ static char *_make_quoted(xmpp_ctx_t *ctx, const char *s)
|
||||
static hash_t *_parse_digest_challenge(xmpp_ctx_t *ctx, const char *msg)
|
||||
{
|
||||
hash_t *result;
|
||||
char *text;
|
||||
unsigned char *text;
|
||||
char *key, *value;
|
||||
char *s, *t;
|
||||
unsigned char *s, *t;
|
||||
|
||||
text = base64_decode(ctx, msg, strlen(msg));
|
||||
if (text == NULL) {
|
||||
@@ -118,7 +118,7 @@ static hash_t *_parse_digest_challenge(xmpp_ctx_t *ctx, const char *msg)
|
||||
t = s;
|
||||
while ((*t != '=') && (*t != '\0')) t++;
|
||||
if (*t == '\0') break; /* bad string */
|
||||
key = _make_string(ctx, s, (t-s));
|
||||
key = _make_string(ctx, (char *)s, (t-s));
|
||||
if (key == NULL) break;
|
||||
/* advance our start pointer past the key */
|
||||
s = t + 1;
|
||||
@@ -129,16 +129,16 @@ static hash_t *_parse_digest_challenge(xmpp_ctx_t *ctx, const char *msg)
|
||||
while ((*t != *s) && (*t != '\0'))
|
||||
t++;
|
||||
if (*t == *s) {
|
||||
value = _make_string(ctx, s+1, (t-s-2));
|
||||
value = _make_string(ctx, (char *)s+1, (t-s-2));
|
||||
s = t + 1;
|
||||
} else {
|
||||
value = _make_string(ctx, s+1, (t-s-1));
|
||||
value = _make_string(ctx, (char *)s+1, (t-s-1));
|
||||
s = t;
|
||||
}
|
||||
/* otherwise, accumulate a value ending in ',' or '\0' */
|
||||
} else {
|
||||
while ((*t != ',') && (*t != '\0')) t++;
|
||||
value = _make_string(ctx, s, (t-s));
|
||||
value = _make_string(ctx, (char *)s, (t-s));
|
||||
s = t;
|
||||
}
|
||||
if (value == NULL) {
|
||||
@@ -268,21 +268,21 @@ char *sasl_digest_md5(xmpp_ctx_t *ctx, const char *challenge,
|
||||
|
||||
/* construct MD5(A1) */
|
||||
MD5Init(&MD5);
|
||||
MD5Update(&MD5, node, strlen(node));
|
||||
MD5Update(&MD5, ":", 1);
|
||||
MD5Update(&MD5, domain, strlen(domain));
|
||||
MD5Update(&MD5, ":", 1);
|
||||
MD5Update(&MD5, password, strlen(password));
|
||||
MD5Update(&MD5, (unsigned char *)node, strlen(node));
|
||||
MD5Update(&MD5, (unsigned char *)":", 1);
|
||||
MD5Update(&MD5, (unsigned char *)domain, strlen(domain));
|
||||
MD5Update(&MD5, (unsigned char *)":", 1);
|
||||
MD5Update(&MD5, (unsigned char *)password, strlen(password));
|
||||
MD5Final(digest, &MD5);
|
||||
|
||||
MD5Init(&MD5);
|
||||
MD5Update(&MD5, digest, 16);
|
||||
MD5Update(&MD5, ":", 1);
|
||||
MD5Update(&MD5, (unsigned char *)digest, 16);
|
||||
MD5Update(&MD5, (unsigned char *)":", 1);
|
||||
value = hash_get(table, "nonce");
|
||||
MD5Update(&MD5, value, strlen(value));
|
||||
MD5Update(&MD5, ":", 1);
|
||||
MD5Update(&MD5, (unsigned char *)value, strlen(value));
|
||||
MD5Update(&MD5, (unsigned char *)":", 1);
|
||||
value = hash_get(table, "cnonce");
|
||||
MD5Update(&MD5, value, strlen(value));
|
||||
MD5Update(&MD5, (unsigned char *)value, strlen(value));
|
||||
MD5Final(digest, &MD5);
|
||||
|
||||
A1 = xmpp_alloc(ctx, 16);
|
||||
@@ -290,9 +290,9 @@ char *sasl_digest_md5(xmpp_ctx_t *ctx, const char *challenge,
|
||||
|
||||
/* construct MD5(A2) */
|
||||
MD5Init(&MD5);
|
||||
MD5Update(&MD5, "AUTHENTICATE:", 13);
|
||||
MD5Update(&MD5, (unsigned char *)"AUTHENTICATE:", 13);
|
||||
value = hash_get(table, "digest-uri");
|
||||
MD5Update(&MD5, value, strlen(value));
|
||||
MD5Update(&MD5, (unsigned char *)value, strlen(value));
|
||||
MD5Final(digest, &MD5);
|
||||
|
||||
A2 = xmpp_alloc(ctx, 16);
|
||||
@@ -300,26 +300,26 @@ char *sasl_digest_md5(xmpp_ctx_t *ctx, const char *challenge,
|
||||
|
||||
/* construct response */
|
||||
MD5Init(&MD5);
|
||||
_digest_to_hex(A1, hex);
|
||||
MD5Update(&MD5, hex, 32);
|
||||
MD5Update(&MD5, ":", 1);
|
||||
_digest_to_hex((char *)A1, hex);
|
||||
MD5Update(&MD5, (unsigned char *)hex, 32);
|
||||
MD5Update(&MD5, (unsigned char *)":", 1);
|
||||
value = hash_get(table, "nonce");
|
||||
MD5Update(&MD5, value, strlen(value));
|
||||
MD5Update(&MD5, ":", 1);
|
||||
MD5Update(&MD5, "00000001", 8);
|
||||
MD5Update(&MD5, ":", 1);
|
||||
MD5Update(&MD5, (unsigned char *)value, strlen(value));
|
||||
MD5Update(&MD5, (unsigned char *)":", 1);
|
||||
MD5Update(&MD5, (unsigned char *)"00000001", 8);
|
||||
MD5Update(&MD5, (unsigned char *)":", 1);
|
||||
value = hash_get(table, "cnonce");
|
||||
MD5Update(&MD5, value, strlen(value));
|
||||
MD5Update(&MD5, ":", 1);
|
||||
MD5Update(&MD5, (unsigned char *)value, strlen(value));
|
||||
MD5Update(&MD5, (unsigned char *)":", 1);
|
||||
value = hash_get(table, "qop");
|
||||
MD5Update(&MD5, value, strlen(value));
|
||||
MD5Update(&MD5, ":", 1);
|
||||
_digest_to_hex(A2, hex);
|
||||
MD5Update(&MD5, hex, 32);
|
||||
MD5Update(&MD5, (unsigned char *)value, strlen(value));
|
||||
MD5Update(&MD5, (unsigned char *)":", 1);
|
||||
_digest_to_hex((char *)A2, hex);
|
||||
MD5Update(&MD5, (unsigned char *)hex, 32);
|
||||
MD5Final(digest, &MD5);
|
||||
|
||||
response = xmpp_alloc(ctx, 32+1);
|
||||
_digest_to_hex(digest, hex);
|
||||
_digest_to_hex((char *)digest, hex);
|
||||
memcpy(response, hex, 32);
|
||||
response[32] = '\0';
|
||||
hash_add(table, "response", response);
|
||||
@@ -345,7 +345,7 @@ char *sasl_digest_md5(xmpp_ctx_t *ctx, const char *challenge,
|
||||
hash_release(table); /* also frees value strings */
|
||||
|
||||
/* reuse response for the base64 encode of our result */
|
||||
response = base64_encode(ctx, result, strlen(result));
|
||||
response = base64_encode(ctx, (unsigned char *)result, strlen(result));
|
||||
xmpp_free(ctx, result);
|
||||
|
||||
return response;
|
||||
@@ -389,14 +389,14 @@ static const char _base64_charmap[65] = {
|
||||
'='
|
||||
};
|
||||
|
||||
int base64_encoded_len(xmpp_ctx_t *ctx, const int len)
|
||||
int base64_encoded_len(xmpp_ctx_t *ctx, const unsigned len)
|
||||
{
|
||||
/* encoded steam is 4 bytes for every three, rounded up */
|
||||
return ((len + 2)/3) << 2;
|
||||
}
|
||||
|
||||
char *base64_encode(xmpp_ctx_t *ctx,
|
||||
const unsigned char * const buffer, const int len)
|
||||
const unsigned char * const buffer, const unsigned len)
|
||||
{
|
||||
int clen;
|
||||
char *cbuf, *c;
|
||||
@@ -450,7 +450,7 @@ char *base64_encode(xmpp_ctx_t *ctx,
|
||||
}
|
||||
|
||||
int base64_decoded_len(xmpp_ctx_t *ctx,
|
||||
const char * const buffer, const int len)
|
||||
const char * const buffer, const unsigned len)
|
||||
{
|
||||
int nudge;
|
||||
int c;
|
||||
@@ -474,7 +474,7 @@ int base64_decoded_len(xmpp_ctx_t *ctx,
|
||||
}
|
||||
|
||||
unsigned char *base64_decode(xmpp_ctx_t *ctx,
|
||||
const char * const buffer, const int len)
|
||||
const char * const buffer, const unsigned len)
|
||||
{
|
||||
int dlen;
|
||||
unsigned char *dbuf, *d;
|
||||
|
||||
12
src/sasl.h
12
src/sasl.h
@@ -12,6 +12,10 @@
|
||||
** distribution.
|
||||
*/
|
||||
|
||||
/** @file
|
||||
* SASL authentication helpers.
|
||||
*/
|
||||
|
||||
#ifndef __LIBSTROPHE_SASL_H__
|
||||
#define __LIBSTROPHE_SASL_H__
|
||||
|
||||
@@ -26,15 +30,15 @@ char *sasl_digest_md5(xmpp_ctx_t *ctx, const char *challenge,
|
||||
|
||||
/** Base64 encoding routines. Implemented according to RFC 3548 */
|
||||
|
||||
int base64_encoded_len(xmpp_ctx_t *ctx, const int len);
|
||||
int base64_encoded_len(xmpp_ctx_t *ctx, const unsigned len);
|
||||
|
||||
char *base64_encode(xmpp_ctx_t *ctx,
|
||||
const unsigned char * const buffer, const int len);
|
||||
const unsigned char * const buffer, const unsigned len);
|
||||
|
||||
int base64_decoded_len(xmpp_ctx_t *ctx,
|
||||
const char * const buffer, const int len);
|
||||
const char * const buffer, const unsigned len);
|
||||
|
||||
unsigned char *base64_decode(xmpp_ctx_t *ctx,
|
||||
const char * const buffer, const int len);
|
||||
const char * const buffer, const unsigned len);
|
||||
|
||||
#endif /* _LIBXMPP_SASL_H__ */
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
/* public api for steve reid's public domain SHA-1 implementation */
|
||||
/* this file is in the public domain */
|
||||
|
||||
/** @file
|
||||
* SHA-1 hash API.
|
||||
*/
|
||||
|
||||
#ifndef __SHA1_H
|
||||
#define __SHA1_H
|
||||
|
||||
|
||||
14
src/sock.c
14
src/sock.c
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
@@ -161,7 +162,7 @@ int sock_is_recoverable(const int error)
|
||||
int sock_connect_error(const sock_t sock)
|
||||
{
|
||||
struct sockaddr sa;
|
||||
int len;
|
||||
unsigned len;
|
||||
char temp;
|
||||
|
||||
sa.sa_family = AF_INET;
|
||||
@@ -285,13 +286,14 @@ void netbuf_get_16bitnum(unsigned char *buf, int buflen, int *offset, unsigned s
|
||||
*offset += 2;
|
||||
}
|
||||
|
||||
void netbuf_add_domain_name(unsigned char *buf, int buflen, int *offset, char *name)
|
||||
void netbuf_add_domain_name(unsigned char *buf, int buflen, int *offset,
|
||||
char *name)
|
||||
{
|
||||
unsigned char *start = buf + *offset;
|
||||
unsigned char *p = start;
|
||||
unsigned char *wordstart, *wordend;
|
||||
|
||||
wordstart = name;
|
||||
wordstart = (unsigned char *)name;
|
||||
|
||||
while (*wordstart)
|
||||
{
|
||||
@@ -388,7 +390,6 @@ void netbuf_get_domain_name(unsigned char *buf, int buflen, int *offset, char **
|
||||
{
|
||||
unsigned char *start = buf + *offset;
|
||||
unsigned char *p = start;
|
||||
char *p2;
|
||||
int *curroffset = offset;
|
||||
|
||||
*name = malloc(sizeof(**name) * (calc_domain_name_size(buf, buflen, *offset) + 1));
|
||||
@@ -417,7 +418,7 @@ void netbuf_get_domain_name(unsigned char *buf, int buflen, int *offset, char **
|
||||
strcat(*name, ".");
|
||||
}
|
||||
|
||||
strncat(*name, p + 1, *p);
|
||||
strncat(*name, (char *)p + 1, *p);
|
||||
p += *p + 1;
|
||||
}
|
||||
}
|
||||
@@ -597,7 +598,6 @@ void netbuf_get_dnsquery_resourcerecord(unsigned char *buf, int buflen, int *off
|
||||
|
||||
char **SeparateStringByDots(char *string)
|
||||
{
|
||||
FILE *fp;
|
||||
char **result;
|
||||
char *p = string;
|
||||
char **ps;
|
||||
@@ -947,8 +947,6 @@ int sock_srv_lookup(const char *service, const char *proto, const char *domain,
|
||||
|
||||
if (offset > 0)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
int len = offset;
|
||||
int i;
|
||||
struct dnsquery_header header;
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
** distribution.
|
||||
*/
|
||||
|
||||
/** @file
|
||||
* Socket abstraction API.
|
||||
*/
|
||||
|
||||
#ifndef __LIBSTROPHE_SOCK_H__
|
||||
#define __LIBSTROPHE_SOCK_H__
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
*/
|
||||
|
||||
/** @file
|
||||
* XMPP stanza creation and manipulation.
|
||||
* Stanza creation and manipulation.
|
||||
*/
|
||||
|
||||
/** @defgroup Stanza Stanza creation and manipulation
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
** distribution.
|
||||
*/
|
||||
|
||||
/** @file
|
||||
* Threading abstraction API.
|
||||
*/
|
||||
|
||||
#ifndef __LIBSTROPHE_THREAD_H__
|
||||
#define __LIBSTROPHE_THREAD_H__
|
||||
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
** distribution.
|
||||
*/
|
||||
|
||||
/** @file
|
||||
* TLS abstraction API.
|
||||
*/
|
||||
|
||||
#ifndef __LIBSTROPHE_TLS_H__
|
||||
#define __LIBSTROPHE_TLS_H__
|
||||
|
||||
@@ -36,4 +40,7 @@ int tls_error(tls_t *tls);
|
||||
int tls_read(tls_t *tls, void * const buff, const size_t len);
|
||||
int tls_write(tls_t *tls, const void * const buff, const size_t len);
|
||||
|
||||
int tls_clear_pending_write(tls_t *tls);
|
||||
int tls_is_recoverable(int error);
|
||||
|
||||
#endif /* __LIBSTROPHE_TLS_H__ */
|
||||
|
||||
@@ -44,7 +44,7 @@ tls_t *tls_new(xmpp_ctx_t *ctx, sock_t sock)
|
||||
|
||||
void tls_free(tls_t *tls)
|
||||
{
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
int tls_set_credentials(tls_t *tls, const char *cafilename)
|
||||
@@ -77,3 +77,13 @@ int tls_write(tls_t *tls, const void * const buff, const size_t len)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int tls_clear_pending_write(tls_t *tls)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int tls_is_recoverable(int error)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
** distribution.
|
||||
*/
|
||||
|
||||
/** @file
|
||||
* Internally used utility functions.
|
||||
*/
|
||||
|
||||
#ifndef __LIBSTROPHE_UTIL_H__
|
||||
#define __LIBSTROPHE_UTIL_H__
|
||||
|
||||
|
||||
Reference in New Issue
Block a user