c3281a5c486e21fe6039cfca737b2e234a9fbb33
[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 typedef struct _citxmpp {                       /* Information about the current session */
20         XML_Parser xp;                  /* XML parser instance for incoming client stream */
21         char server_name[256];          /* who they think we are */
22         char *chardata;
23         int chardata_len;
24         int chardata_alloc;
25         char client_jid[256];           /* "full JID" of the client */
26         int last_event_processed;
27
28         char iq_type[256];              /* for <iq> stanzas */
29         char iq_id[256];
30         char iq_from[256];
31         char iq_to[256];
32         char iq_client_username[256];   /* username requested by the client (NON SASL ONLY) */
33         char iq_client_password[256];   /* password requested by the client (NON SASL ONLY) */
34         char iq_client_resource[256];   /* resource name requested by the client */
35         int iq_session;                 /* nonzero == client is requesting a session */
36         char iq_query_xmlns[256];       /* Namespace of <query> */
37
38         char sasl_auth_mech[32];        /* SASL auth mechanism requested by the client */
39
40         char message_to[256];
41         char *message_body;             /* Message body in transit */
42         int html_tag_level;             /* <html> tag nesting level */
43
44         int bind_requested;             /* In this stanza, client is asking server to bind a resource. */
45         int ping_requested;             /* In this stanza, client is pinging the server. */
46 } citxmpp;
47
48 #define XMPP ((citxmpp *)CC->session_specific_data)
49
50 struct xmpp_event {
51         struct xmpp_event *next;
52         int event_seq;
53         time_t event_time;
54         int event_type;
55         char event_jid[256];
56         int session_which_generated_this_event;
57 };
58
59 extern struct xmpp_event *xmpp_queue;
60 extern int queue_event_seq;
61
62 enum {
63         XMPP_EVT_LOGIN,
64         XMPP_EVT_LOGOUT
65 };
66
67 void xmpp_cleanup_function(void);
68 void xmpp_greeting(void);
69 void xmpp_command_loop(void);
70 void xmpp_async_loop(void);
71 void xmpp_sasl_auth(char *, char *);
72 void xmpp_output_auth_mechs(void);
73 void xmpp_query_namespace(char *, char *, char *, char *);
74 void xmpp_wholist_presence_dump(void);
75 void xmpp_output_incoming_messages(void);
76 void xmpp_queue_event(int, char *);
77 void xmpp_process_events(void);
78 void xmpp_presence_notify(char *, int);
79 void xmpp_roster_item(struct CitContext *);
80 void xmpp_send_message(char *, char *);
81 void xmpp_non_sasl_authenticate(char *, char *, char *, char *);
82 void xmpp_massacre_roster(void);
83 void xmpp_delete_old_buddies_who_no_longer_exist_from_the_client_roster(void);
84 int xmpp_is_visible(struct CitContext *from, struct CitContext *to_whom);
85 char *xmlesc(char *buf, char *str, int bufsiz);
86
87 extern int XMPPSrvDebugEnable;
88
89 #define DBGLOG(LEVEL) if ((LEVEL != LOG_DEBUG) || (XMPPSrvDebugEnable != 0))
90
91 #define XMPP_syslog(LEVEL, FORMAT, ...)                         \
92         DBGLOG(LEVEL) syslog(LEVEL,                             \
93                              "XMPP: " FORMAT, __VA_ARGS__)
94
95 #define XMPPM_syslog(LEVEL, FORMAT)             \
96         DBGLOG(LEVEL) syslog(LEVEL,             \
97                              "XMPP: " FORMAT);
98