Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4b05cf156 | ||
|
|
06da6d5125 | ||
|
|
1bcf77608d | ||
|
|
aab0cc3e3e | ||
|
|
822f95071a | ||
|
|
27f613bc84 | ||
|
|
af1ef3855b | ||
|
|
7ede9c6d03 | ||
|
|
20c6f225b9 | ||
|
|
5b204b0938 | ||
|
|
6e6093ee7b | ||
|
|
f12d43989f | ||
|
|
032e8ec89d | ||
|
|
d0644c5e95 |
@@ -8,6 +8,9 @@
|
|||||||
userdata
|
userdata
|
||||||
- System handlers are deleted on xmpp_conn_t reconnection. Old system
|
- System handlers are deleted on xmpp_conn_t reconnection. Old system
|
||||||
handlers could cause problems
|
handlers could cause problems
|
||||||
|
- Default timeout for xmpp_run() is increased from 1 millisecond to 1
|
||||||
|
second in order to reduce CPU consumption
|
||||||
|
- Reduced memory usage in expat module
|
||||||
- New functions:
|
- New functions:
|
||||||
- xmpp_ctx_set_timeout()
|
- xmpp_ctx_set_timeout()
|
||||||
- xmpp_sha1_digest()
|
- xmpp_sha1_digest()
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ SSL_LIBS = @openssl_LIBS@
|
|||||||
|
|
||||||
RESOLV_LIBS = @RESOLV_LIBS@
|
RESOLV_LIBS = @RESOLV_LIBS@
|
||||||
|
|
||||||
STROPHE_FLAGS = -I$(top_srcdir) -Wall -Wextra -Werror -Wno-unused-parameter
|
STROPHE_FLAGS = -I$(top_srcdir) -Wall -Wextra -Wno-unused-parameter
|
||||||
STROPHE_LIBS = libstrophe.la
|
STROPHE_LIBS = libstrophe.la
|
||||||
|
|
||||||
## Main build targets
|
## Main build targets
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
AC_INIT([libstrophe], [0.9.1], [jack@metajack.im])
|
AC_INIT([libstrophe], [0.9.2], [jack@metajack.im])
|
||||||
AC_CONFIG_MACRO_DIR([m4])
|
AC_CONFIG_MACRO_DIR([m4])
|
||||||
AM_INIT_AUTOMAKE([foreign])
|
AM_INIT_AUTOMAKE([foreign])
|
||||||
LT_INIT([dlopen])
|
LT_INIT([dlopen])
|
||||||
|
|||||||
@@ -73,6 +73,15 @@ static int _conn_connect(xmpp_conn_t * const conn,
|
|||||||
xmpp_conn_handler callback,
|
xmpp_conn_handler callback,
|
||||||
void * const userdata);
|
void * const userdata);
|
||||||
|
|
||||||
|
void xmpp_send_error(xmpp_conn_t * const conn, xmpp_error_type_t const type, char * const text)
|
||||||
|
{
|
||||||
|
xmpp_stanza_t *error = xmpp_error_new(conn->ctx, type, text);
|
||||||
|
|
||||||
|
xmpp_send(conn, error);
|
||||||
|
|
||||||
|
xmpp_stanza_release(error);
|
||||||
|
}
|
||||||
|
|
||||||
/** Create a new Strophe connection object.
|
/** Create a new Strophe connection object.
|
||||||
*
|
*
|
||||||
* @param ctx a Strophe context object
|
* @param ctx a Strophe context object
|
||||||
|
|||||||
26
src/crypto.c
26
src/crypto.c
@@ -61,7 +61,7 @@ static char *digest_to_string_alloc(xmpp_ctx_t *ctx, const uint8_t *digest)
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute SHA1 message digest
|
/** Compute SHA1 message digest.
|
||||||
* Returns an allocated string which represents SHA1 message digest in
|
* Returns an allocated string which represents SHA1 message digest in
|
||||||
* hexadecimal notation. The string must be freed with xmpp_free().
|
* hexadecimal notation. The string must be freed with xmpp_free().
|
||||||
*
|
*
|
||||||
@@ -81,7 +81,7 @@ char *xmpp_sha1(xmpp_ctx_t *ctx, const unsigned char *data, size_t len)
|
|||||||
return digest_to_string_alloc(ctx, digest);
|
return digest_to_string_alloc(ctx, digest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compute SHA1 message digest
|
/** Compute SHA1 message digest.
|
||||||
* Stores digest in user's buffer which must be at least XMPP_SHA1_DIGEST_SIZE
|
* Stores digest in user's buffer which must be at least XMPP_SHA1_DIGEST_SIZE
|
||||||
* bytes long.
|
* bytes long.
|
||||||
*
|
*
|
||||||
@@ -97,7 +97,7 @@ void xmpp_sha1_digest(const unsigned char *data, size_t len,
|
|||||||
crypto_SHA1((const uint8_t *)data, len, digest);
|
crypto_SHA1((const uint8_t *)data, len, digest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create new SHA1 object
|
/** Create new SHA1 object.
|
||||||
* SHA1 object is used to compute SHA1 digest of a buffer that is split
|
* SHA1 object is used to compute SHA1 digest of a buffer that is split
|
||||||
* in multiple chunks or provided in stream mode. A single buffer can be
|
* in multiple chunks or provided in stream mode. A single buffer can be
|
||||||
* processed by short functions xmpp_sha1() and xmpp_sha1_digest().
|
* processed by short functions xmpp_sha1() and xmpp_sha1_digest().
|
||||||
@@ -111,7 +111,7 @@ void xmpp_sha1_digest(const unsigned char *data, size_t len,
|
|||||||
* xmpp_sha1_free(sha1);
|
* xmpp_sha1_free(sha1);
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* @param ctx a Strophe context onject
|
* @param ctx a Strophe context object
|
||||||
*
|
*
|
||||||
* @return new SHA1 object
|
* @return new SHA1 object
|
||||||
*
|
*
|
||||||
@@ -130,7 +130,7 @@ xmpp_sha1_t *xmpp_sha1_new(xmpp_ctx_t *ctx)
|
|||||||
return sha1;
|
return sha1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Destroy SHA1 object
|
/** Destroy SHA1 object.
|
||||||
*
|
*
|
||||||
* @param sha1 a SHA1 object
|
* @param sha1 a SHA1 object
|
||||||
*
|
*
|
||||||
@@ -141,7 +141,7 @@ void xmpp_sha1_free(xmpp_sha1_t *sha1)
|
|||||||
xmpp_free(sha1->xmpp_ctx, sha1);
|
xmpp_free(sha1->xmpp_ctx, sha1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Update SHA1 context with the next portion of data
|
/** Update SHA1 context with the next portion of data.
|
||||||
* Can be called repeatedly.
|
* Can be called repeatedly.
|
||||||
*
|
*
|
||||||
* @param sha1 a SHA1 object
|
* @param sha1 a SHA1 object
|
||||||
@@ -155,7 +155,7 @@ void xmpp_sha1_update(xmpp_sha1_t *sha1, const unsigned char *data, size_t len)
|
|||||||
crypto_SHA1_Update(&sha1->ctx, data, len);
|
crypto_SHA1_Update(&sha1->ctx, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Finish SHA1 computation
|
/** Finish SHA1 computation.
|
||||||
* Don't call xmpp_sha1_update() after this function. Retrieve resulting
|
* Don't call xmpp_sha1_update() after this function. Retrieve resulting
|
||||||
* message digest with xmpp_sha1_to_string() or xmpp_sha1_to_digest().
|
* message digest with xmpp_sha1_to_string() or xmpp_sha1_to_digest().
|
||||||
*
|
*
|
||||||
@@ -168,7 +168,7 @@ void xmpp_sha1_final(xmpp_sha1_t *sha1)
|
|||||||
crypto_SHA1_Final(&sha1->ctx, sha1->digest);
|
crypto_SHA1_Final(&sha1->ctx, sha1->digest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return message digest rendered as a string
|
/** Return message digest rendered as a string.
|
||||||
* Stores the string to a user's buffer and returns the buffer. Call this
|
* Stores the string to a user's buffer and returns the buffer. Call this
|
||||||
* function after xmpp_sha1_final().
|
* function after xmpp_sha1_final().
|
||||||
*
|
*
|
||||||
@@ -185,7 +185,7 @@ char *xmpp_sha1_to_string(xmpp_sha1_t *sha1, char *s, size_t slen)
|
|||||||
return digest_to_string(sha1->digest, s, slen);
|
return digest_to_string(sha1->digest, s, slen);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return message digest rendered as a string
|
/** Return message digest rendered as a string.
|
||||||
* Returns an allocated string. Free the string using the Strophe context
|
* Returns an allocated string. Free the string using the Strophe context
|
||||||
* which is passed to xmpp_sha1_new(). Call this function after
|
* which is passed to xmpp_sha1_new(). Call this function after
|
||||||
* xmpp_sha1_final().
|
* xmpp_sha1_final().
|
||||||
@@ -201,7 +201,7 @@ char *xmpp_sha1_to_string_alloc(xmpp_sha1_t *sha1)
|
|||||||
return digest_to_string_alloc(sha1->xmpp_ctx, sha1->digest);
|
return digest_to_string_alloc(sha1->xmpp_ctx, sha1->digest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Stores message digest to a user's buffer
|
/** Stores message digest to a user's buffer.
|
||||||
*
|
*
|
||||||
* @param sha1 a SHA1 object
|
* @param sha1 a SHA1 object
|
||||||
* @param digest output buffer of XMPP_SHA1_DIGEST_SIZE bytes
|
* @param digest output buffer of XMPP_SHA1_DIGEST_SIZE bytes
|
||||||
@@ -419,7 +419,7 @@ _base64_error:
|
|||||||
*outlen = 0;
|
*outlen = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Base64 encoding routine
|
/** Base64 encoding routine.
|
||||||
* Returns an allocated string which must be freed with xmpp_free().
|
* Returns an allocated string which must be freed with xmpp_free().
|
||||||
*
|
*
|
||||||
* @param ctx a Strophe context
|
* @param ctx a Strophe context
|
||||||
@@ -435,7 +435,7 @@ char *xmpp_base64_encode(xmpp_ctx_t *ctx, const unsigned char *data, size_t len)
|
|||||||
return base64_encode(ctx, data, len);
|
return base64_encode(ctx, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Base64 decoding routine
|
/** Base64 decoding routine.
|
||||||
* Returns an allocated string which must be freed with xmpp_free(). User
|
* Returns an allocated string which must be freed with xmpp_free(). User
|
||||||
* calls this function when the result must be a string. When decoded buffer
|
* calls this function when the result must be a string. When decoded buffer
|
||||||
* contains '\0' NULL is returned.
|
* contains '\0' NULL is returned.
|
||||||
@@ -471,7 +471,7 @@ char *xmpp_base64_decode_str(xmpp_ctx_t *ctx, const char *base64, size_t len)
|
|||||||
return (char *)buf;
|
return (char *)buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Base64 decoding routine
|
/** Base64 decoding routine.
|
||||||
* Returns an allocated buffer which must be freed with xmpp_free().
|
* Returns an allocated buffer which must be freed with xmpp_free().
|
||||||
*
|
*
|
||||||
* @param ctx a Strophe context
|
* @param ctx a Strophe context
|
||||||
|
|||||||
@@ -262,10 +262,8 @@ void xmpp_run_once(xmpp_ctx_t *ctx, const unsigned long timeout)
|
|||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
ret = parser_feed(conn->parser, buf, ret);
|
ret = parser_feed(conn->parser, buf, ret);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
/* parse error, we need to shut down */
|
xmpp_debug(ctx, "xmpp", "parse error [%s]", buf);
|
||||||
/* FIXME */
|
xmpp_send_error(conn, XMPP_SE_INVALID_XML, "parse error");
|
||||||
xmpp_debug(ctx, "xmpp", "parse error, disconnecting");
|
|
||||||
conn_disconnect(conn);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (conn->tls) {
|
if (conn->tls) {
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ void hash_iter_release(hash_iterator_t *iter)
|
|||||||
|
|
||||||
iter->ref--;
|
iter->ref--;
|
||||||
|
|
||||||
if (iter->ref <= 0) {
|
if (iter->ref == 0) { // ref is unsigned!!!
|
||||||
hash_release(iter->table);
|
hash_release(iter->table);
|
||||||
xmpp_free(ctx, iter);
|
xmpp_free(ctx, iter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -249,6 +249,8 @@ void parser_free(parser_t *parser)
|
|||||||
{
|
{
|
||||||
if (parser->xmlctx)
|
if (parser->xmlctx)
|
||||||
xmlFreeParserCtxt(parser->xmlctx);
|
xmlFreeParserCtxt(parser->xmlctx);
|
||||||
|
if (parser->stanza)
|
||||||
|
xmpp_stanza_release(parser->stanza);
|
||||||
xmpp_free(parser->ctx, parser);
|
xmpp_free(parser->ctx, parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,18 +259,16 @@ int parser_reset(parser_t *parser)
|
|||||||
{
|
{
|
||||||
if (parser->xmlctx)
|
if (parser->xmlctx)
|
||||||
xmlFreeParserCtxt(parser->xmlctx);
|
xmlFreeParserCtxt(parser->xmlctx);
|
||||||
|
|
||||||
if (parser->stanza)
|
if (parser->stanza)
|
||||||
xmpp_stanza_release(parser->stanza);
|
xmpp_stanza_release(parser->stanza);
|
||||||
|
|
||||||
|
parser->stanza = NULL;
|
||||||
|
parser->depth = 0;
|
||||||
|
|
||||||
parser->xmlctx = xmlCreatePushParserCtxt(&parser->handlers,
|
parser->xmlctx = xmlCreatePushParserCtxt(&parser->handlers,
|
||||||
parser, NULL, 0, NULL);
|
parser, NULL, 0, NULL);
|
||||||
if (!parser->xmlctx) return 0;
|
|
||||||
|
|
||||||
parser->depth = 0;
|
return parser->xmlctx ? 1 : 0;
|
||||||
parser->stanza = NULL;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* feed a chunk of data to the parser */
|
/* feed a chunk of data to the parser */
|
||||||
|
|||||||
@@ -517,7 +517,7 @@ static int resolver_win32_srv_query(const char *fulldomain,
|
|||||||
unsigned char *buf, size_t len)
|
unsigned char *buf, size_t len)
|
||||||
{
|
{
|
||||||
int set = 0;
|
int set = 0;
|
||||||
int insize;
|
int insize = 0;
|
||||||
|
|
||||||
/* if dnsapi didn't work/isn't there, try querying the dns server manually */
|
/* if dnsapi didn't work/isn't there, try querying the dns server manually */
|
||||||
if (!set)
|
if (!set)
|
||||||
@@ -550,7 +550,7 @@ static int resolver_win32_srv_query(const char *fulldomain,
|
|||||||
char buffer[65535];
|
char buffer[65535];
|
||||||
|
|
||||||
len = 65535;
|
len = 65535;
|
||||||
fi = buffer;
|
fi = (FIXED_INFO *)buffer;
|
||||||
|
|
||||||
if ((error = pGetNetworkParams(fi, &len)) == ERROR_SUCCESS)
|
if ((error = pGetNetworkParams(fi, &len)) == ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -264,6 +264,7 @@ char *sasl_digest_md5(xmpp_ctx_t *ctx, const char *challenge,
|
|||||||
xmpp_rand_nonce(ctx->rand, cnonce, sizeof(cnonce));
|
xmpp_rand_nonce(ctx->rand, cnonce, sizeof(cnonce));
|
||||||
hash_add(table, "cnonce", xmpp_strdup(ctx, cnonce));
|
hash_add(table, "cnonce", xmpp_strdup(ctx, cnonce));
|
||||||
hash_add(table, "nc", xmpp_strdup(ctx, "00000001"));
|
hash_add(table, "nc", xmpp_strdup(ctx, "00000001"));
|
||||||
|
if (hash_get(table, "qop") == NULL)
|
||||||
hash_add(table, "qop", xmpp_strdup(ctx, "auth"));
|
hash_add(table, "qop", xmpp_strdup(ctx, "auth"));
|
||||||
value = xmpp_alloc(ctx, 5 + strlen(domain) + 1);
|
value = xmpp_alloc(ctx, 5 + strlen(domain) + 1);
|
||||||
memcpy(value, "xmpp/", 5);
|
memcpy(value, "xmpp/", 5);
|
||||||
|
|||||||
119
src/stanza.c
119
src/stanza.c
@@ -1218,3 +1218,122 @@ xmpp_stanza_t *xmpp_presence_new(xmpp_ctx_t *ctx)
|
|||||||
{
|
{
|
||||||
return _stanza_new_with_attrs(ctx, "presence", NULL, NULL, NULL);
|
return _stanza_new_with_attrs(ctx, "presence", NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Create an <stream:error/> stanza object with given type and error text.
|
||||||
|
* The error text is optional and may be NULL.
|
||||||
|
*
|
||||||
|
* @param ctx a Strophe context object
|
||||||
|
* @param type enum of xmpp_error_type_t
|
||||||
|
* @param text content of a 'text'
|
||||||
|
*
|
||||||
|
* @return a new Strophe stanza object
|
||||||
|
*
|
||||||
|
* @todo Handle errors in this function
|
||||||
|
*
|
||||||
|
* @ingroup Stanza
|
||||||
|
*/
|
||||||
|
xmpp_stanza_t *xmpp_error_new(xmpp_ctx_t *ctx, xmpp_error_type_t const type,
|
||||||
|
const char * const text)
|
||||||
|
{
|
||||||
|
xmpp_stanza_t *error = _stanza_new_with_attrs(ctx, "stream:error", NULL, NULL, NULL);
|
||||||
|
xmpp_stanza_t *error_type = xmpp_stanza_new(ctx);
|
||||||
|
|
||||||
|
switch(type) {
|
||||||
|
case XMPP_SE_BAD_FORMAT:
|
||||||
|
xmpp_stanza_set_name(error_type, "bad-format");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_BAD_NS_PREFIX:
|
||||||
|
xmpp_stanza_set_name(error_type, "bad-namespace-prefix");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_CONFLICT:
|
||||||
|
xmpp_stanza_set_name(error_type, "conflict");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_CONN_TIMEOUT:
|
||||||
|
xmpp_stanza_set_name(error_type, "connection-timeout");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_HOST_GONE:
|
||||||
|
xmpp_stanza_set_name(error_type, "host-gone");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_HOST_UNKNOWN:
|
||||||
|
xmpp_stanza_set_name(error_type, "host-unknown");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_IMPROPER_ADDR:
|
||||||
|
xmpp_stanza_set_name(error_type, "improper-addressing");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_INTERNAL_SERVER_ERROR:
|
||||||
|
xmpp_stanza_set_name(error_type, "internal-server-error");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_INVALID_FROM:
|
||||||
|
xmpp_stanza_set_name(error_type, "invalid-from");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_INVALID_ID:
|
||||||
|
xmpp_stanza_set_name(error_type, "invalid-id");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_INVALID_NS:
|
||||||
|
xmpp_stanza_set_name(error_type, "invalid-namespace");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_INVALID_XML:
|
||||||
|
xmpp_stanza_set_name(error_type, "invalid-xml");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_NOT_AUTHORIZED:
|
||||||
|
xmpp_stanza_set_name(error_type, "not-authorized");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_POLICY_VIOLATION:
|
||||||
|
xmpp_stanza_set_name(error_type, "policy-violation");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_REMOTE_CONN_FAILED:
|
||||||
|
xmpp_stanza_set_name(error_type, "remote-connection-failed");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_RESOURCE_CONSTRAINT:
|
||||||
|
xmpp_stanza_set_name(error_type, "resource-constraint");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_RESTRICTED_XML:
|
||||||
|
xmpp_stanza_set_name(error_type, "restricted-xml");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_SEE_OTHER_HOST:
|
||||||
|
xmpp_stanza_set_name(error_type, "see-other-host");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_SYSTEM_SHUTDOWN:
|
||||||
|
xmpp_stanza_set_name(error_type, "system-shutdown");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_UNDEFINED_CONDITION:
|
||||||
|
xmpp_stanza_set_name(error_type, "undefined-condition");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_UNSUPPORTED_ENCODING:
|
||||||
|
xmpp_stanza_set_name(error_type, "unsupported-encoding");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_UNSUPPORTED_STANZA_TYPE:
|
||||||
|
xmpp_stanza_set_name(error_type, "unsupported-stanza-type");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_UNSUPPORTED_VERSION:
|
||||||
|
xmpp_stanza_set_name(error_type, "unsupported-version");
|
||||||
|
break;
|
||||||
|
case XMPP_SE_XML_NOT_WELL_FORMED:
|
||||||
|
xmpp_stanza_set_name(error_type, "xml-not-well-formed");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
xmpp_stanza_set_name(error_type, "internal-server-error");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
xmpp_stanza_set_ns(error_type, XMPP_NS_STREAMS_IETF);
|
||||||
|
xmpp_stanza_add_child(error, error_type);
|
||||||
|
xmpp_stanza_release(error_type);
|
||||||
|
|
||||||
|
if (text) {
|
||||||
|
xmpp_stanza_t *error_text = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_t *content = xmpp_stanza_new(ctx);
|
||||||
|
|
||||||
|
xmpp_stanza_set_name(error_text, "text");
|
||||||
|
xmpp_stanza_set_ns(error_text, XMPP_NS_STREAMS_IETF);
|
||||||
|
|
||||||
|
xmpp_stanza_set_text(content, text);
|
||||||
|
xmpp_stanza_add_child(error_text, content);
|
||||||
|
xmpp_stanza_release(content);
|
||||||
|
|
||||||
|
xmpp_stanza_add_child(error, error_text);
|
||||||
|
xmpp_stanza_release(error_text);
|
||||||
|
}
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|||||||
@@ -209,6 +209,14 @@ int tls_stop(tls_t *tls)
|
|||||||
}
|
}
|
||||||
_tls_sock_wait(tls, error);
|
_tls_sock_wait(tls, error);
|
||||||
}
|
}
|
||||||
|
if (error == SSL_ERROR_SYSCALL && errno == 0) {
|
||||||
|
/*
|
||||||
|
* Handle special case when peer closes connection instead of
|
||||||
|
* proper shutdown.
|
||||||
|
*/
|
||||||
|
error = 0;
|
||||||
|
ret = 1;
|
||||||
|
}
|
||||||
_tls_set_error(tls, error);
|
_tls_set_error(tls, error);
|
||||||
|
|
||||||
return ret <= 0 ? 0 : 1;
|
return ret <= 0 ? 0 : 1;
|
||||||
@@ -260,6 +268,8 @@ static void _tls_sock_wait(tls_t *tls, int error)
|
|||||||
int nfds;
|
int nfds;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if (error == SSL_ERROR_NONE) return;
|
||||||
|
|
||||||
FD_ZERO(&rfds);
|
FD_ZERO(&rfds);
|
||||||
FD_ZERO(&wfds);
|
FD_ZERO(&wfds);
|
||||||
if (error == SSL_ERROR_WANT_READ)
|
if (error == SSL_ERROR_WANT_READ)
|
||||||
@@ -278,6 +288,7 @@ static void _tls_sock_wait(tls_t *tls, int error)
|
|||||||
static void _tls_set_error(tls_t *tls, int error)
|
static void _tls_set_error(tls_t *tls, int error)
|
||||||
{
|
{
|
||||||
if (error != 0 && !tls_is_recoverable(error)) {
|
if (error != 0 && !tls_is_recoverable(error)) {
|
||||||
|
xmpp_debug(tls->ctx, "tls", "error=%d errno=%d", error, errno);
|
||||||
_tls_log_error(tls->ctx);
|
_tls_log_error(tls->ctx);
|
||||||
}
|
}
|
||||||
tls->lasterror = error;
|
tls->lasterror = error;
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ typedef void (*xmpp_conn_handler)(xmpp_conn_t * const conn,
|
|||||||
xmpp_stream_error_t * const stream_error,
|
xmpp_stream_error_t * const stream_error,
|
||||||
void * const userdata);
|
void * const userdata);
|
||||||
|
|
||||||
|
void xmpp_send_error(xmpp_conn_t * const conn, xmpp_error_type_t const type, char * const text);
|
||||||
xmpp_conn_t *xmpp_conn_new(xmpp_ctx_t * const ctx);
|
xmpp_conn_t *xmpp_conn_new(xmpp_ctx_t * const ctx);
|
||||||
xmpp_conn_t *xmpp_conn_clone(xmpp_conn_t * const conn);
|
xmpp_conn_t *xmpp_conn_clone(xmpp_conn_t * const conn);
|
||||||
int xmpp_conn_release(xmpp_conn_t * const conn);
|
int xmpp_conn_release(xmpp_conn_t * const conn);
|
||||||
@@ -381,6 +382,8 @@ int xmpp_message_set_body(xmpp_stanza_t *msg, const char * const text);
|
|||||||
xmpp_stanza_t *xmpp_iq_new(xmpp_ctx_t *ctx, const char * const type,
|
xmpp_stanza_t *xmpp_iq_new(xmpp_ctx_t *ctx, const char * const type,
|
||||||
const char * const id);
|
const char * const id);
|
||||||
xmpp_stanza_t *xmpp_presence_new(xmpp_ctx_t *ctx);
|
xmpp_stanza_t *xmpp_presence_new(xmpp_ctx_t *ctx);
|
||||||
|
xmpp_stanza_t *xmpp_error_new(xmpp_ctx_t *ctx, xmpp_error_type_t const type,
|
||||||
|
const char * const text);
|
||||||
|
|
||||||
/* jid */
|
/* jid */
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,16 @@
|
|||||||
|
|
||||||
#include "test.h" /* ARRAY_SIZE */
|
#include "test.h" /* ARRAY_SIZE */
|
||||||
|
|
||||||
|
/* 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
|
||||||
|
#endif /* _MSC_VER */
|
||||||
|
|
||||||
static int test_strtok_r(void)
|
static int test_strtok_r(void)
|
||||||
{
|
{
|
||||||
const char *test = "-abc-=-def--";
|
const char *test = "-abc-=-def--";
|
||||||
|
|||||||
Reference in New Issue
Block a user