X-Git-Url: https://code.citadel.org/?p=citadel.git;a=blobdiff_plain;f=citadel%2Fmodules%2Fxmpp%2Fserv_xmpp.c;h=d62bcfe468ee99ced792b01fde6632897838bbb7;hp=3248a11cb39bbbf98b1281ec78082c10d3da3774;hb=2976b35710982e72d499db16d648eee7b2cfaa94;hpb=7e8e24791e16e0a94ed346c6a11595a40d3a31b1 diff --git a/citadel/modules/xmpp/serv_xmpp.c b/citadel/modules/xmpp/serv_xmpp.c index 3248a11cb..d62bcfe46 100644 --- a/citadel/modules/xmpp/serv_xmpp.c +++ b/citadel/modules/xmpp/serv_xmpp.c @@ -1,6 +1,6 @@ /* * XMPP (Jabber) service for the Citadel system - * Copyright (c) 2007-2017 by Art Cancro and citadel.org + * Copyright (c) 2007-2018 by Art Cancro and citadel.org * * This program is open source software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -57,6 +57,9 @@ #include "ctdl_module.h" #include "serv_xmpp.h" +/* uncomment for more verbosity - it will log all received XML tags */ +#define XMPP_XML_DEBUG + /* XML_StopParser is present in expat 2.x */ #if XML_MAJOR_VERSION > 1 #define HAVE_XML_STOPPARSER @@ -65,8 +68,6 @@ struct xmpp_event *xmpp_queue = NULL; - - #ifdef HAVE_XML_STOPPARSER /* Stop the parser if an entity declaration is hit. */ static void xmpp_entity_declaration(void *userData, const XML_Char *entityName, @@ -81,7 +82,6 @@ static void xmpp_entity_declaration(void *userData, const XML_Char *entityName, #endif - /* * Given a source string and a target buffer, returns the string * properly escaped for insertion into an XML stream. Returns a @@ -106,6 +106,7 @@ static inline int Ctdl_GetUtf8SequenceLength(const char *CharS, const char *Char return n; } + char *xmlesc(char *buf, char *str, int bufsiz) { int IsUtf8Sequence; @@ -238,12 +239,12 @@ void xmpp_xml_start(void *data, const char *supplied_el, const char **attr) { strcpy(el, ++sep); } - /* +#ifdef XMPP_XML_DEBUG syslog(LOG_DEBUG, "xmpp: ELEMENT START: <%s>", el); for (i=0; attr[i] != NULL; i+=2) { syslog(LOG_DEBUG, "xmpp: Attribute '%s' = '%s'", attr[i], attr[i+1]); } - uncomment for more verbosity */ +#endif if (!strcasecmp(el, "stream")) { xmpp_stream_start(data, supplied_el, attr); @@ -310,33 +311,30 @@ void xmpp_xml_end(void *data, const char *supplied_el) { strcpy(el, ++sep); } - /* +#ifdef XMPP_XML_DEBUG syslog(LOG_DEBUG, "xmpp: ELEMENT END : <%s>", el); if (XMPP->chardata_len > 0) { syslog(LOG_DEBUG, "xmpp: chardata: %s", XMPP->chardata); } - uncomment for more verbosity */ +#endif if (!strcasecmp(el, "resource")) { if (XMPP->chardata_len > 0) { - safestrncpy(XMPP->iq_client_resource, XMPP->chardata, - sizeof XMPP->iq_client_resource); + safestrncpy(XMPP->iq_client_resource, XMPP->chardata, sizeof XMPP->iq_client_resource); striplt(XMPP->iq_client_resource); } } else if (!strcasecmp(el, "username")) { /* NON SASL ONLY */ if (XMPP->chardata_len > 0) { - safestrncpy(XMPP->iq_client_username, XMPP->chardata, - sizeof XMPP->iq_client_username); + safestrncpy(XMPP->iq_client_username, XMPP->chardata, sizeof XMPP->iq_client_username); striplt(XMPP->iq_client_username); } } else if (!strcasecmp(el, "password")) { /* NON SASL ONLY */ if (XMPP->chardata_len > 0) { - safestrncpy(XMPP->iq_client_password, XMPP->chardata, - sizeof XMPP->iq_client_password); + safestrncpy(XMPP->iq_client_password, XMPP->chardata, sizeof XMPP->iq_client_password); striplt(XMPP->iq_client_password); } } @@ -352,8 +350,7 @@ void xmpp_xml_end(void *data, const char *supplied_el) { * Query on a namespace */ if (!IsEmptyStr(XMPP->iq_query_xmlns)) { - xmpp_query_namespace(XMPP->iq_id, XMPP->iq_from, - XMPP->iq_to, XMPP->iq_query_xmlns); + xmpp_query_namespace(XMPP->iq_id, XMPP->iq_from, XMPP->iq_to, XMPP->iq_query_xmlns); } /* @@ -395,8 +392,7 @@ void xmpp_xml_end(void *data, const char *supplied_el) { xmpp_non_sasl_authenticate( XMPP->iq_id, XMPP->iq_client_username, - XMPP->iq_client_password, - XMPP->iq_client_resource + XMPP->iq_client_password ); } @@ -406,17 +402,17 @@ void xmpp_xml_end(void *data, const char *supplied_el) { else if ( (XMPP->bind_requested) && (!IsEmptyStr(XMPP->iq_id)) - && (!IsEmptyStr(XMPP->iq_client_resource)) && (CC->logged_in) - ) { + ) { - /* Generate the "full JID" of the client resource */ + /* If the client has not specified a client resource, generate one */ - snprintf(XMPP->client_jid, sizeof XMPP->client_jid, - "%s/%s", - CC->cs_inet_email, - XMPP->iq_client_resource - ); + if (IsEmptyStr(XMPP->iq_client_resource)) { + snprintf(XMPP->iq_client_resource, sizeof XMPP->iq_client_resource, "%d", CC->cs_pid); + } + + /* Generate the "full JID" of the client resource */ + snprintf(XMPP->client_jid, sizeof XMPP->client_jid, "%s/%s", CC->cs_inet_email, XMPP->iq_client_resource); /* Tell the client what its JID is */ @@ -434,8 +430,9 @@ void xmpp_xml_end(void *data, const char *supplied_el) { else { cprintf("", xmlesc(xmlbuf, XMPP->iq_id, sizeof xmlbuf)); - cprintf("Don't know howto do '%s'!", xmlesc(xmlbuf, XMPP->iq_type, sizeof xmlbuf)); + cprintf("Don't know how to do '%s'!", xmlesc(xmlbuf, XMPP->iq_type, sizeof xmlbuf)); cprintf(""); + syslog(LOG_DEBUG, "XMPP: don't know how to do iq_type='%s' with iq_query_xmlns='%s'", XMPP->iq_type, XMPP->iq_query_xmlns); } /* Now clear these fields out so they don't get used by a future stanza */ @@ -571,7 +568,6 @@ void xmpp_cleanup_function(void) { } - /* * Here's where our XMPP session begins its happy day. */