citadel
About: Citadel is an advanced messaging and collaboration system for groupware and BBS applications (preferred OS: Linux).
  Fossies Dox: citadel.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

xmpp_queue.c
Go to the documentation of this file.
1/*
2 * XMPP event queue
3 *
4 * Copyright (c) 2007-2021 by Art Cancro
5 *
6 * This program is open source software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include "sysdep.h"
16#include <stdlib.h>
17#include <unistd.h>
18#include <stdio.h>
19#include <fcntl.h>
20#include <signal.h>
21#include <pwd.h>
22#include <errno.h>
23#include <sys/types.h>
24#include <time.h>
25#include <sys/wait.h>
26#include <string.h>
27#include <limits.h>
28#include <ctype.h>
29#include <expat.h>
30#include <libcitadel.h>
31#include "citadel.h"
32#include "server.h"
33#include "citserver.h"
34#include "support.h"
35#include "config.h"
36#include "internet_addressing.h"
37#include "ctdl_module.h"
38#include "serv_xmpp.h"
39
41
42void xmpp_queue_event(int event_type, char *email_addr) {
43
44 struct xmpp_event *xptr = NULL;
45 struct xmpp_event *new_event = NULL;
46 struct xmpp_event *last = NULL;
47 int purged_something = 0;
48 struct CitContext *cptr;
49
50 syslog(LOG_DEBUG, "xmpp: xmpp_queue_event(%d, %s)", event_type, email_addr);
51
52 /* Purge events more than a minute old */
54 do {
55 purged_something = 0;
56 if (xmpp_queue != NULL) {
57 if ((time(NULL) - xmpp_queue->event_time) > 60) {
58 xptr = xmpp_queue->next;
60 xmpp_queue = xptr;
61 purged_something = 1;
62 }
63 }
64 } while(purged_something);
66
67 /* Create a new event */
68 new_event = (struct xmpp_event *) malloc(sizeof(struct xmpp_event));
69 new_event->next = NULL;
70 new_event->event_time = time(NULL);
71 new_event->event_seq = ++queue_event_seq;
72 new_event->event_type = event_type;
73 new_event->session_which_generated_this_event = CC->cs_pid;
74 safestrncpy(new_event->event_jid, email_addr, sizeof new_event->event_jid);
75
76 /* Add it to the list */
78 if (xmpp_queue == NULL) {
79 xmpp_queue = new_event;
80 }
81 else {
82 for (xptr = xmpp_queue; xptr != NULL; xptr = xptr->next) {
83 if (xptr->next == NULL) {
84 last = xptr;
85 }
86 }
87 last->next = new_event;
88 }
90
91 /* Tell the sessions that something is happening */
93 for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
94 if ((cptr->logged_in) && (cptr->h_async_function == xmpp_async_loop)) {
96 }
97 }
99}
100
101
102/*
103 * Are we interested in anything from the queue? (Called in async loop)
104 */
106 struct xmpp_event *xptr = NULL;
107 int highest_event = 0;
108
109 for (xptr=xmpp_queue; xptr!=NULL; xptr=xptr->next) {
110 if (xptr->event_seq > XMPP->last_event_processed) {
111
112 switch(xptr->event_type) {
113
114 case XMPP_EVT_LOGIN:
115 case XMPP_EVT_LOGOUT:
116 if (xptr->session_which_generated_this_event != CC->cs_pid) {
118 }
119 break;
120 }
121
122 if (xptr->event_seq > highest_event) {
123 highest_event = xptr->event_seq;
124 }
125 }
126 }
127
128 XMPP->last_event_processed = highest_event;
129}
CitContext * ContextList
Definition: context.c:22
void set_async_waiting(struct CitContext *ccptr)
Definition: context.c:704
#define CC
Definition: context.h:140
void * malloc(size_t)
void free(void *)
void xmpp_async_loop(void)
Definition: serv_xmpp.c:631
struct xmpp_event * xmpp_queue
Definition: serv_xmpp.c:56
@ XMPP_EVT_LOGOUT
Definition: serv_xmpp.h:59
@ XMPP_EVT_LOGIN
Definition: serv_xmpp.h:58
#define XMPP
Definition: serv_xmpp.h:43
void xmpp_presence_notify(char *, int)
@ S_SESSION_TABLE
Definition: server.h:137
@ S_XMPP_QUEUE
Definition: server.h:153
int logged_in
Definition: context.h:70
CitContext * next
Definition: context.h:42
void(* h_async_function)(void)
Definition: context.h:131
char event_jid[256]
Definition: serv_xmpp.h:50
int session_which_generated_this_event
Definition: serv_xmpp.h:51
int event_type
Definition: serv_xmpp.h:49
time_t event_time
Definition: serv_xmpp.h:48
int event_seq
Definition: serv_xmpp.h:47
struct xmpp_event * next
Definition: serv_xmpp.h:46
void begin_critical_section(int which_one)
Definition: threads.c:67
void end_critical_section(int which_one)
Definition: threads.c:85
void xmpp_queue_event(int event_type, char *email_addr)
Definition: xmpp_queue.c:42
void xmpp_process_events(void)
Definition: xmpp_queue.c:105
int queue_event_seq
Definition: xmpp_queue.c:40