22#include "../../sysdep.h"
38#include <libcitadel.h>
39#include "../../citadel_defs.h"
40#include "../../server.h"
41#include "../../citserver.h"
42#include "../../support.h"
43#include "../../config.h"
44#include "../../internet_addressing.h"
45#include "../../ctdl_module.h"
56 syslog(LOG_DEBUG,
"xmpp: indicating presence of <%s> to <%s>", presence_jid,
XMPP->client_jid);
57 cprintf(
"<presence from=\"%s\" ",
xmlesc(xmlbuf, presence_jid,
sizeof xmlbuf));
58 cprintf(
"to=\"%s\"></presence>",
xmlesc(xmlbuf,
XMPP->client_jid,
sizeof xmlbuf));
94 for (i=0; i<nContexts; i++) {
108 static int unsolicited_id = 1;
112 if (!presence_jid)
return;
114 if (!
XMPP->client_jid)
return;
117 cprintf(
"<presence type=\"unavailable\" from=\"%s\" to=\"%s\"></presence>",
118 xmlesc(xmlbuf1, presence_jid,
sizeof xmlbuf1),
119 xmlesc(xmlbuf2,
XMPP->client_jid,
sizeof xmlbuf2)
129 cprintf(
"<presence type=\"unsubscribed\" from=\"%s\" to=\"%s\"></presence>",
130 xmlesc(xmlbuf1, presence_jid,
sizeof xmlbuf1),
131 xmlesc(xmlbuf2,
XMPP->client_jid,
sizeof xmlbuf2)
138 cprintf(
"<iq from=\"%s\" to=\"%s\" id=\"unbuddy_%x\" type=\"result\">",
139 xmlesc(xmlbuf1,
CC->cs_principal_id,
sizeof xmlbuf1),
140 xmlesc(xmlbuf2,
XMPP->client_jid,
sizeof xmlbuf2),
143 cprintf(
"<query xmlns=\"jabber:iq:roster\">");
144 cprintf(
"<item jid=\"%s\" subscription=\"remove\">",
xmlesc(xmlbuf1, presence_jid,
sizeof xmlbuf1));
159 static int unsolicited_id = 12345;
160 int visible_sessions = 0;
162 int which_cptr_is_relevant = (-1);
164 if (IsEmptyStr(presence_jid))
return;
165 if (
CC->kill_me)
return;
173 for (i=0; i<nContexts; i++) {
178 which_cptr_is_relevant = i;
182 syslog(LOG_DEBUG,
"xmpp: %d sessions for <%s> are now visible to session %d", visible_sessions, presence_jid,
CC->cs_pid);
184 if ( (event_type ==
XMPP_EVT_LOGIN) && (visible_sessions == 1) ) {
186 syslog(LOG_DEBUG,
"xmpp: telling session %d that <%s> logged in",
CC->cs_pid, presence_jid);
189 assert(which_cptr_is_relevant >= 0);
190 cprintf(
"<iq id=\"unsolicited_%x\" type=\"result\">", ++unsolicited_id);
191 cprintf(
"<query xmlns=\"jabber:iq:roster\">");
199 if (visible_sessions == 0) {
200 syslog(LOG_DEBUG,
"xmpp: telling session %d that <%s> logged out",
CC->cs_pid, presence_jid);
209 HashList *mortuary = (HashList *) userdata;
235 ptr = strtok_r(ptr,
"\n", &lasts);
236 while (ptr != NULL) {
237 char *pch = strdup(ptr);
238 Put(mortuary, pch, strlen(pch), pch, NULL);
239 ptr = strtok_r(NULL,
"\n", &lasts);
252 HashList *mortuary = NewHash(1, NULL);
254 syslog(LOG_ALERT,
"xmpp: NewHash() failed!");
280 themsg = NewStrBuf();
281 StrBufPrintf(themsg,
"Content-type: " XMPPMORTUARY
"\n"
282 "Content-transfer-encoding: 7bit\n"
286 HashPos = GetNewHashPos(mortuary, 0);
287 while (GetNextHashPos(mortuary, HashPos, &len, &Key, &Value) != 0) {
288 StrBufAppendPrintf(themsg,
"%s\n", (
char *)Value);
290 DeleteHashPos(&HashPos);
315 for (i=0; i<nContexts; i++) {
319 Put(mortuary, buddy, strlen(buddy), buddy, NULL);
328 DeleteHash(&mortuary);
351 HashPos *HashPos = GetNewHashPos(mortuary, 0);
357 while (GetNextHashPos(mortuary, HashPos, &len, &Key, &Value) != 0)
361 if (cptr)
for (i=0; i<nContexts; i++) {
374 DeleteHashPos(&HashPos);
375 DeleteHash(&mortuary);
char * CtdlGetConfigStr(char *key)
CitContext * CtdlGetContextArray(int *count)
int CtdlGetRoom(struct ctdlroom *qrbuf, const char *room_name)
void CM_Free(struct CtdlMessage *msg)
int CtdlForEachMessage(int mode, long ref, char *search_string, char *content_type, struct CtdlMessage *compare, ForEachMsgCallback CallBack, void *userdata)
struct CtdlMessage * CtdlFetchMessage(long msgnum, int with_body)
int CtdlDeleteMessages(const char *room_name, long *dmsgnums, int num_dmsgnums, char *content_type)
long quickie_message(char *from, char *fromaddr, char *to, char *room, char *text, int format_type, char *subject)
char * xmlesc(char *buf, char *str, int bufsiz)
void xmpp_roster_item(struct CitContext *)
char cs_principal_id[256]
void cprintf(const char *format,...)
void xmpp_fetch_mortuary_backend(long msgnum, void *userdata)
int xmpp_is_visible(struct CitContext *cptr, struct CitContext *to_whom)
void xmpp_indicate_presence(char *presence_jid)
void xmpp_presence_notify(char *presence_jid, int event_type)
void xmpp_delete_old_buddies_who_no_longer_exist_from_the_client_roster(void)
void xmpp_store_mortuary(HashList *mortuary)
void xmpp_wholist_presence_dump(void)
void xmpp_massacre_roster(void)
HashList * xmpp_fetch_mortuary(void)
void xmpp_destroy_buddy(char *presence_jid, int aggressively)