6 * Copyright (c) 2007 by Art Cancro
7 * This code is released under the terms of the GNU General Public License.
19 #include <sys/types.h>
21 #if TIME_WITH_SYS_TIME
22 # include <sys/time.h>
26 # include <sys/time.h>
36 #include <libcitadel.h>
39 #include "citserver.h"
42 #include "internet_addressing.h"
44 #include "ctdl_module.h"
48 #include "serv_xmpp.h"
52 void xmpp_queue_event(int event_type, char *email_addr) {
55 struct xmpp_event *xptr = NULL;
56 struct xmpp_event *new_event = NULL;
57 struct xmpp_event *last = NULL;
58 int purged_something = 0;
59 struct CitContext *cptr;
61 lprintf(CTDL_DEBUG, "xmpp_queue_event(%d, %s)\n", event_type, email_addr);
63 /* Purge events more than a minute old */
64 begin_critical_section(S_XMPP_QUEUE);
67 if (xmpp_queue != NULL) {
68 if ((time(NULL) - xmpp_queue->event_time) > 60) {
69 xptr = xmpp_queue->next;
75 } while(purged_something);
76 end_critical_section(S_XMPP_QUEUE);
78 /* Create a new event */
79 new_event = (struct xmpp_event *) malloc(sizeof(struct xmpp_event));
80 new_event->next = NULL;
81 new_event->event_time = time(NULL);
82 new_event->event_seq = ++seq;
83 new_event->event_type = event_type;
84 safestrncpy(new_event->event_jid, email_addr, sizeof new_event->event_jid);
86 /* Add it to the list */
87 begin_critical_section(S_XMPP_QUEUE);
88 if (xmpp_queue == NULL) {
89 xmpp_queue = new_event;
92 for (xptr = xmpp_queue; xptr != NULL; xptr = xptr->next) {
93 if (xptr->next == NULL) {
97 last->next = new_event;
99 end_critical_section(S_XMPP_QUEUE);
101 /* Tell the sessions that something is happening */
102 for (cptr = ContextList; cptr != NULL; cptr = cptr->next) {
103 if (cptr->h_async_function == xmpp_async_loop) {
104 cptr->async_waiting = 1;
111 * Are we interested in anything from the queue? (Called in async loop)
113 void xmpp_process_events(void) {
114 struct xmpp_event *xptr = NULL;
115 int highest_event = 0;
117 for (xptr=xmpp_queue; xptr!=NULL; xptr=xptr->next) {
118 if (xptr->event_seq > XMPP->last_event_processed) {
120 /* FIXME do something */
122 if (xptr->event_seq > highest_event) {
123 highest_event = xptr->event_seq;
128 XMPP->last_event_processed = highest_event;
132 #endif /* HAVE_EXPAT */