Generate a synthetic user@host for XMPP JID if the user does not have an Internet...
[citadel.git] / citadel / modules / xmpp / serv_xmpp.c
index 20f2089e33aab30f55098115fb890e41874b2c5a..e0b61af64413e38b7978d4b42d0f5388cd2ef71a 100644 (file)
@@ -403,17 +403,27 @@ 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)
-                       ) {
+               ) {
+
+                       /* If the client has not specified a client resource, generate one */
+
+                       if (IsEmptyStr(XMPP->iq_client_resource)) {
+                               generate_uuid(XMPP->iq_client_resource);
+                       }
 
                        /* 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
-                       );
+                       if (IsEmptyStr(CC->cs_inet_email)) {                            // synthetic user@host if no email is set
+                               snprintf(XMPP->client_jid, sizeof XMPP->client_jid,
+                                       "%ld@%s/%s", CC->user.usernum, CtdlGetConfigStr("c_fqdn"), XMPP->iq_client_resource
+                               );
+                       }
+                       else {                                                          // use the email address if we have it
+                               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 */