1 /* $Id: connection.h 2851 2010-03-06 18:16:56Z kuhlmann $ */
2 
3 #ifndef CLIMM_UTIL_CONNECTION_H
4 #define CLIMM_UTIL_CONNECTION_H
5 
6 #include "util_opts.h"
7 #if ENABLE_XMPP
8 #include <iksemel.h>
9 #endif
10 #include "util_io.h"
11 
12 typedef void (jump_conn_f)(Connection *conn);
13 typedef struct Dispatcher_s Dispatcher;
14 
15 struct Connection_s
16 {
17     Server   *serv;           /* parent session               */
18     UWORD     type;           /* connection type - TYPE_*                 */
19     UBYTE     version;        /* protocol version in this session         */
20 
21     Contact  *cont;           /* the user this connection is for          */
22     char     *server;         /* the remote server name                   */
23     UDWORD    port;           /* the port the server is listening on      */
24     UDWORD    ip;             /* the remote ip (host byte order)          */
25     UDWORD    our_local_ip;   /* LAN-internal IP (host byte order)        */
26     UDWORD    our_outside_ip; /* the IP address the server sees from us   */
27     SOK_T     sok;            /* socket for connection to server          */
28     UWORD     connect;        /* connection setup status                  */
29     Packet   *incoming;       /* packet we're receiving                   */
30 
31     Dispatcher *dispatcher;   /* pointer to extra data for dispatching    */
32 
33     ssl_status_t ssl_status;  /* SSL status (INIT,OK,FAILED,...)          */
34 
35     Connection       *oscar_file;  /* associated file saving session           */
36     UDWORD    oscar_our_session;    /* session ID                               */
37     UDWORD    oscar_file_len;            /* used for file transfer                   */
38     UDWORD    oscar_file_done;           /* used for file transfer                   */
39     UWORD     oscar_dc_seq;
40 
41     void *xmpp_file_private;   /* XMPP file transfer private */
42 #define xmpp_file oscar_file
43 #define xmpp_file_len    oscar_file_len            /* used for file transfer                   */
44 #define xmpp_file_done   oscar_file_done           /* used for file transfer                   */
45 
46     jump_conn_f *dispatch;     /* function to call on select()    */
47 
48     UDWORD    stat_pak_sent;
49     UDWORD    stat_pak_rcvd;
50 };
51 
52 struct Server_s
53 {
54     UWORD     type;           /* connection type - TYPE_*                 */
55     UBYTE     pref_version;        /* protocol version in this session         */
56     Connection            *oscar_dc;  /* associated session           */
57 
58     char     *screen;
59     status_t  status;         /* own status                               */
60     UBYTE     flags;          /* connection flags                         */
61     status_t  pref_status;
62     char     *pref_server;
63     UDWORD    pref_port;
64     char     *pref_passwd;
65     char     *passwd;         /* the password for this user               */
66     SOK_T     logfd;
67     ContactGroup *contacts;   /* The contacts for this connection         */
68     Connection            *conn;   /* main I/O connection          */
69     UDWORD    nativestatus;   /* own ICQ extended status                  */
70     idleflag_t idle_flag;     /* the idle status                          */
71     Opt       copts;
72 
73 #if ENABLE_XMPP
74     UWORD     xmpp_sequence;
75     iksparser*xmpp_parser;
76     char     *xmpp_stamp;
77     iksid    *xmpp_id;
78     iksfilter*xmpp_filter;
79     char     *xmpp_privacy_list;
80     char     *xmpp_privacy_items;
81 
82     char     *xmpp_gmail_new_newertid;
83     char     *xmpp_gmail_newertid;
84     char     *xmpp_gmail_query;
85     int64_t   xmpp_gmail_new_newer;
86     int64_t   xmpp_gmail_newer;
87 #endif
88 
89     void     *oscar_tlv;            /* temporary during v8 connect              */
90     UDWORD    oscar_uin;            /* the uin of this server connection        */
91     UWORD     oscar_type2_seq;     /* sequence number for dc and type-2        */
92     UWORD     oscar_snac_seq;       /* current secondary sequence number        */
93 #define xmpp_file_seq oscar_snac_seq
94     UDWORD    oscar_icq_seq;       /* current old-ICQ sequence number          */
95     UWORD     oscar_seq;        /* current primary sequence number          */
96     UWORD     oscar_privacy_tag;         /* F*cking ICQ needs to change the value */
97     UBYTE     oscar_privacy_value;       /* when switching between visible and invisible */
98 };
99 
100 #define CONNECT_MASK       0x00ff
101 #define CONNECT_OK         0x0080
102 #define CONNECT_FAIL       0x0100
103 #define CONNECT_SELECT_A   0x1000
104 #define CONNECT_SELECT_R   0x2000
105 #define CONNECT_SELECT_W   0x4000
106 #define CONNECT_SELECT_X   0x8000
107 
108 
109 Server        *ServerC           (UWORD type DEBUGPARAM);
110 void           ServerD           (Server *serv DEBUGPARAM);
111 Server        *ServerNr          (int i);
112 UDWORD         ServerFindNr      (const Server *serv);
113 Server        *ServerFindScreen  (UWORD type, const char *screen);
114 Connection    *ServerChild       (Server *serv, Contact *cont, UWORD type DEBUGPARAM);
115 Connection    *ServerFindChild   (const Server *parent, const Contact *cont, UWORD type);
116 const char    *ServerStrType     (Server *conn);
117 val_t          ServerPrefVal     (Server *conn, UDWORD flag);
118 const char    *ServerPrefStr     (Server *conn, UDWORD flag);
119 
120 Connection    *ConnectionC       (UWORD type DEBUGPARAM);
121 void           ConnectionD       (Connection *conn DEBUGPARAM);
122 Connection    *ConnectionNr      (int i);
123 const char    *ConnectionStrType (Connection *conn);
124 const char    *ConnectionServerType  (UWORD type);
125 UWORD          ConnectionServerNType (const char *type, char del);
126 
127 #define ConnectionC(t)       ConnectionC (t DEBUGARGS)
128 #define ConnectionD(c)       ConnectionD (c DEBUGARGS)
129 #define ServerC(t)           ServerC (t DEBUGARGS)
130 #define ServerD(c)           ServerD (c DEBUGARGS)
131 #define ServerChild(s,f,t)   ServerChild (s,f,t DEBUGARGS)
132 
133 /*
134                             TYPE_SERVER
135                            ^ |  ^ ^ ^ ^
136                          p/ dc  | | | p\
137                          /   V  | | |   \
138                  TYPE_MSGLISTEN | | | TYPE_FILELISTEN
139                                 | | |
140                                p| | |p
141                                 | | |
142               TYPE_MSGDIRECT(uin) | TYPE_FILEDIRECT(uin)
143                                   |   |
144                                   |   |file
145                                   |   V
146                                  TYPE_FILE(uin)
147 
148 */
149 
150 
151 #define TYPEF_ANY_SERVER    1  /* any server connection  */
152 #define TYPEF_OSCAR         4  /* ICQ server connection  */
153 #define TYPEF_ANY_PEER      8  /* any peer connection    */
154 #define TYPEF_ANY_DIRECT   16  /* " && established       */
155 #define TYPEF_ANY_LISTEN   32  /* " && listening         */
156 #define TYPEF_ANY_MSG      64  /* " && for messages      */
157 #define TYPEF_ANY_FILE    128  /* " && for file transfer */
158 #define TYPEF_ANY_CHAT    256  /* " && for chat          */
159 #define TYPEF_FILE        512  /* any file io            */
160 #define TYPEF_REMOTE     1024  /* remote control (socket)*/
161 #define TYPEF_MSN        2048  /* MSN: connection        */
162 #define TYPEF_MSN_CHAT   4096  /* MSN: chat connection   */
163 #define TYPEF_XMPP       8192  /* XMPP(Jabber) connection*/
164 #define TYPEF_HAVEUIN   16384  /* server session uses numeric UINs */
165 
166 /* any conn->type may be only any of those values:
167  * do not use the flags above unless you _really_ REALLY know what you're doing
168  */
169 #define TYPE_SERVER        (TYPEF_ANY_SERVER | TYPEF_OSCAR | TYPEF_HAVEUIN)
170 #define TYPE_XMPP_SERVER   (TYPEF_ANY_SERVER | TYPEF_XMPP)
171 #define TYPE_MSN_SERVER    (TYPEF_ANY_SERVER | TYPEF_MSN)
172 
173 #define TYPE_MSGLISTEN     (TYPEF_ANY_PEER | TYPEF_ANY_MSG  | TYPEF_ANY_LISTEN)
174 #define TYPE_MSGDIRECT     (TYPEF_ANY_PEER | TYPEF_ANY_MSG  | TYPEF_ANY_DIRECT)
175 #define TYPE_FILELISTEN    (TYPEF_ANY_PEER | TYPEF_ANY_FILE | TYPEF_ANY_LISTEN)
176 #define TYPE_FILEDIRECT    (TYPEF_ANY_PEER | TYPEF_ANY_FILE | TYPEF_ANY_DIRECT)
177 #define TYPE_CHATLISTEN    (TYPEF_ANY_PEER | TYPEF_ANY_CHAT | TYPEF_ANY_LISTEN)
178 #define TYPE_CHATDIRECT    (TYPEF_ANY_PEER | TYPEF_ANY_CHAT | TYPEF_ANY_DIRECT)
179 #define TYPE_XMPPDIRECT    (TYPEF_ANY_PEER | TYPEF_ANY_FILE | TYPEF_XMPP)
180 #define TYPE_FILE          (TYPEF_FILE | TYPEF_OSCAR)
181 #define TYPE_FILEXMPP      (TYPEF_FILE | TYPEF_XMPP)
182 #define TYPE_REMOTE        TYPEF_REMOTE
183 #define TYPE_MSN_TEMP      (TYPEF_ANY_PEER | TYPEF_MSN)
184 #define TYPE_MSN_CHAT      (TYPEF_MSN | TYPEF_MSN_CHAT)
185 
186 #define ASSERT_SERVER(s)      { Server *__s = (s); assert (__s); assert (__s->type == TYPE_SERVER); }
187 #define ASSERT_SERVER_CONN(c) { Connection *__c = (c); assert (__c); ASSERT_SERVER (__c->serv); }
188 
189 #define CONN_AUTOLOGIN   1
190 #define CONN_WIZARD      2
191 #define CONN_INITWP      8
192 
193 #endif /* CLIMM_UTIL_CONNECTION_H */
194