1 /* $Id: packet.h 2770 2009-04-01 16:26:43Z kuhlmann $ */
2 
3 #ifndef CLIMM_PACKET_H
4 #define CLIMM_PACKET_H
5 
6 #define PacketMaxData 1024 * 8
7 
8 struct Packet_s
9 {
10     UDWORD   id;
11     UWORD    len;
12     UBYTE    ver;
13     UDWORD   cmd;
14     UDWORD   ref;
15     UDWORD   flags;
16 
17     UWORD    rpos, wpos, tpos;
18     UBYTE    data[PacketMaxData];
19 };
20 
21 struct Cap_s
22 {
23     UBYTE id;
24     UBYTE len;
25     const char *cap;
26     const char *name;
27     char *var;
28 };
29 
30 typedef enum {
31   CAP_NONE = 0, CAP_AIM_VOICE, CAP_AIM_SFILE, CAP_REVCONNREQ, CAP_AIM_IMIMAGE,
32   CAP_AIM_BUDICON, CAP_AIM_STOCKS, CAP_AIM_GETFILE, CAP_SRVRELAY, CAP_AIM_GAMES,
33   CAP_AIM_SBUD, CAP_AIM_INTER, CAP_AVATAR,
34   CAP_UTF8, CAP_RTFMSGS, CAP_IS_2001, CAP_STR_2001,
35   CAP_STR_2002, CAP_AIM_CHAT, CAP_TYPING, CAP_XTRAZ,
36   CAP_TRILL_CRYPT, CAP_TRILL_2, CAP_LICQ, CAP_LICQNEW, CAP_SIM, CAP_SIMNEW,
37   CAP_MACICQ, CAP_CLIMM, CAP_MICQ, CAP_KXICQ, CAP_KOPETE,
38   CAP_IMSECURE, CAP_ARQ, CAP_MIRANDA, CAP_QIP, CAP_IM2,
39   CAP_UTF8ii,
40   CAP_WIERD1, CAP_WIERD3, CAP_WIERD4, CAP_WIERD5, CAP_WIERD7,
41   CAP_11, CAP_12,
42   CAP_MAX = 63
43 } cap_id_t;
44 
45 #define CAP_GID_UTF8    "{0946134E-4C7F-11D1-8222-444553540000}"
46 
47 #define HAS_CAP(caps,cap) (((caps)[(cap) / 32]) & (1UL << ((cap) % 32)))
48 #define SET_CAP(caps,cap) ((caps)[(cap) / 32]) |= (1UL << ((cap) % 32))
49 #define CLR_CAP(caps,cap) ((caps)[(cap) / 32]) &= ~(1UL << ((cap) % 32))
50 
51 Packet *PacketC        (DEBUG0PARAM);
52 Packet *PacketCreate   (str_t str DEBUGPARAM);
53 Packet *PacketClone    (const Packet *pak DEBUGPARAM);
54 void    PacketD        (Packet *pak DEBUGPARAM);
55 
56 #define PacketC()       PacketC(DEBUG0ARGS)
57 #define PacketCreate(s) PacketCreate(s DEBUGARGS)
58 #define PacketClone(p)  PacketClone(p DEBUGARGS)
59 #define PacketD(p)      PacketD(p DEBUGARGS)
60 
61 void        PacketWrite1      (      Packet *pak,           UBYTE  data);
62 void        PacketWrite2      (      Packet *pak,           UWORD  data);
63 void        PacketWriteB2     (      Packet *pak,           UWORD  data);
64 void        PacketWrite4      (      Packet *pak,           UDWORD data);
65 void        PacketWriteB4     (      Packet *pak,           UDWORD data);
66 void        PacketWriteCap    (      Packet *pak,           Cap *cap);
67 void        PacketWriteCapID  (      Packet *pak,           UBYTE id);
68 void        PacketWriteData   (      Packet *pak,           const char *data, UWORD len);
69 void        PacketWriteStr    (      Packet *pak,           const char *data);
70 void        PacketWriteLNTS   (      Packet *pak,           const char *data);
71 void        PacketWriteLNTS2  (      Packet *pak,           str_t data);
72 void        PacketWriteDLStr  (      Packet *pak,           const char *data);
73 void        PacketWriteLLNTS  (      Packet *pak,           const char *data);
74 void        PacketWriteCont   (      Packet *pak, Contact *cont);
75 void        PacketWriteTLV    (      Packet *pak, UDWORD type);
76 void        PacketWriteTLVDone(      Packet *pak);
77 void        PacketWriteLen    (      Packet *pak);
78 void        PacketWriteLenDone(      Packet *pak);
79 void        PacketWriteBLenDone(     Packet *pak);
80 void        PacketWriteLen4   (      Packet *pak);
81 void        PacketWriteLen4Done(     Packet *pak);
82 
83 void        PacketWriteAt1    (      Packet *pak, UWORD at, UBYTE  data);
84 void        PacketWriteAt2    (      Packet *pak, UWORD at, UWORD  data);
85 void        PacketWriteAtB2   (      Packet *pak, UWORD at, UWORD  data);
86 void        PacketWriteAt4    (      Packet *pak, UWORD at, UDWORD data);
87 void        PacketWriteAtB4   (      Packet *pak, UWORD at, UDWORD data);
88 
89 UBYTE       PacketRead1       (      Packet *pak);
90 UWORD       PacketRead2       (      Packet *pak);
91 UWORD       PacketReadB2      (      Packet *pak);
92 UDWORD      PacketRead4       (      Packet *pak);
93 UDWORD      PacketReadB4      (      Packet *pak);
94 Cap        *PacketReadCap     (      Packet *pak);
95 void        PacketReadData    (      Packet *pak, str_t str, UWORD len);
96 strc_t      PacketReadB2Str   (      Packet *pak, str_t str);
97 strc_t      PacketReadL2Str   (      Packet *pak, str_t str);
98 strc_t      PacketReadL4Str   (      Packet *pak, str_t str);
99 strc_t      PacketReadUIN     (      Packet *pak);
100 Contact    *PacketReadCont    (      Packet *pak, Server *serv);
101 
102 UBYTE       PacketReadAt1     (const Packet *pak, UWORD at);
103 UWORD       PacketReadAt2     (const Packet *pak, UWORD at);
104 UWORD       PacketReadAtB2    (const Packet *pak, UWORD at);
105 UDWORD      PacketReadAt4     (const Packet *pak, UWORD at);
106 UDWORD      PacketReadAtB4    (const Packet *pak, UWORD at);
107 void        PacketReadAtData  (const Packet *pak, UWORD at, str_t str, UWORD len);
108 strc_t      PacketReadAtL2Str (const Packet *pak, UWORD at, str_t str);
109 
110 UWORD       PacketWritePos    (const Packet *pak);
111 UWORD       PacketReadPos     (const Packet *pak);
112 int         PacketReadLeft    (const Packet *pak);
113 
114 Cap        *PacketCap         (UBYTE id);
115 
116 #define PacketWriteTLV2(pak,tlv,data)        do { PacketWriteB2 (pak, tlv); PacketWriteB2   (pak, 2);   PacketWriteB2 (pak, data);        } while (0)
117 #define PacketWriteTLV4(pak,tlv,data)        do { PacketWriteB2 (pak, tlv); PacketWriteB2   (pak, 4);   PacketWriteB4 (pak, data);        } while (0)
118 #define PacketWriteTLVData(pak,tlv,data,len) do { PacketWriteB2 (pak, tlv); PacketWriteB2   (pak, len); PacketWriteData (pak, data, len); } while (0)
119 #define PacketWriteTLVStr(pak,tlv,data)      do { PacketWriteTLV (pak, tlv); PacketWriteStr (pak, data);PacketWriteTLVDone (pak);         } while (0)
120 #define PacketWriteStrB(pak,str)             do { PacketWriteB2 (pak, strlen (str)); PacketWriteStr (pak, str);                           } while (0)
121 #define PacketWriteBLen(pak) PacketWriteLen(pak)
122 
123 #endif /* CLIMM_PACKET_H */
124