97264ff30a5f6dfd435c76a5c99bc464e72a7212
[citadel.git] / citadel / modules / xmpp / serv_xmpp.h
1 /*
2  * Copyright (c) 2007-2009 by Art Cancro
3  *
4  *  This program is open source software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License version 3.
6  *  
7  *  
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  *  
16  *  
17  */
18
19 #include "xmpp_xmacros.h"
20 #include "xmpp_util.h"
21
22
23 typedef struct _citxmpp {                       /* Information about the current session */
24         StrBuf *OutBuf;
25         XML_Parser xp;                  /* XML parser instance for incoming client stream */
26         char server_name[256];          /* who they think we are */
27         char *chardata;
28         int chardata_len;
29         int chardata_alloc;
30         char client_jid[256];           /* "full JID" of the client */
31         int last_event_processed;
32
33         TheToken_iq IQ;
34         TheToken_message Message;
35
36         char iq_client_username[256];   /* username requested by the client (NON SASL ONLY) */
37         char iq_client_password[256];   /* password requested by the client (NON SASL ONLY) */
38         char iq_client_resource[256];   /* resource name requested by the client */
39         int iq_session;                 /* nonzero == client is requesting a session */
40         char iq_query_xmlns[256];       /* Namespace of <query> */
41
42         char sasl_auth_mech[32];        /* SASL auth mechanism requested by the client */
43
44         char message_to[256];
45         char *message_body;             /* Message body in transit */
46         int html_tag_level;             /* <html> tag nesting level */
47
48         int bind_requested;             /* In this stanza, client is asking server to bind a resource. */
49         int ping_requested;             /* In this stanza, client is pinging the server. */
50 } citxmpp;
51
52 #define XMPP ((citxmpp *)CC->session_specific_data)
53
54 struct xmpp_event {
55         struct xmpp_event *next;
56         int event_seq;
57         time_t event_time;
58         int event_type;
59         char event_jid[256];
60         int session_which_generated_this_event;
61 };
62
63 extern int queue_event_seq;
64
65 enum {
66         XMPP_EVT_LOGIN,
67         XMPP_EVT_LOGOUT
68 };
69
70
71 typedef void (*xmpp_handler_func)(void *data, const char *supplied_el, const char **attr);
72
73 typedef struct __xmpp_handler {
74         int               Flags;
75         xmpp_handler_func Handler;
76 }xmpp_handler;
77
78
79 void xmpp_cleanup_function(void);
80 void xmpp_greeting(void);
81 void xmpp_command_loop(void);
82 void xmpp_async_loop(void);
83 void xmpp_sasl_auth(char *, char *);
84 void xmpp_output_auth_mechs(void);
85 void xmpp_query_namespace(TheToken_iq *iq, char *);
86 void xmpp_output_incoming_messages(void);
87 void xmpp_queue_event(int, char *);
88 void xmpp_process_events(void);
89 void xmpp_presence_notify(char *, int);
90 void xmpp_roster_item(struct CitContext *);
91 void xmpp_send_message(char *, char *);
92 void xmpp_non_sasl_authenticate(StrBuf *IQ_id, char *, char *, char *);
93 void xmpp_massacre_roster(void);
94 void xmpp_delete_old_buddies_who_no_longer_exist_from_the_client_roster(void);
95 int xmpp_is_visible(struct CitContext *from, struct CitContext *to_whom);
96 char *xmlesc(char *buf, char *str, int bufsiz);
97
98 extern int XMPPSrvDebugEnable;
99
100 #define DBGLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (XMPPSrvDebugEnable != 0))
101
102 #define XMPP_syslog(LEVEL, FORMAT, ...)                         \
103         DBGLOG(LEVEL) syslog(LEVEL,                             \
104                              "XMPP: " FORMAT, __VA_ARGS__)
105
106 #define XMPPM_syslog(LEVEL, FORMAT)             \
107         DBGLOG(LEVEL) syslog(LEVEL,             \
108                              "XMPP: " FORMAT);
109
110
111 void AddXMPPStartHandler(const char *key,
112                          long len,
113                          xmpp_handler_func Handler,
114                          int Flags);
115
116 void AddXMPPEndHandler(const char *key,
117                        long len,
118                        xmpp_handler_func Handler,
119                        int Flags);
120
121
122
123