1 /**************************************************************************/
2 /*                                                                        */
3 /* Copyright (c) 2001, 2010 NoMachine, http://www.nomachine.com/.         */
4 /*                                                                        */
5 /* NXCOMP, NX protocol compression and NX extensions to this software     */
6 /* are copyright of NoMachine. Redistribution and use of the present      */
7 /* software is allowed according to terms specified in the file LICENSE   */
8 /* which comes in the source distribution.                                */
9 /*                                                                        */
10 /* Check http://www.nomachine.com/licensing.html for applicability.       */
11 /*                                                                        */
12 /* NX and NoMachine are trademarks of Medialogic S.p.A.                   */
13 /*                                                                        */
14 /* All rights reserved.                                                   */
15 /*                                                                        */
16 /**************************************************************************/
17 
18 #ifndef GenericReply_H
19 #define GenericReply_H
20 
21 #include "Message.h"
22 
23 //
24 // Set the verbosity level.
25 //
26 
27 #define PANIC
28 #define WARNING
29 #undef  TEST
30 #undef  DEBUG
31 #undef  DUMP
32 
33 //
34 // Set default values.
35 //
36 
37 #define GENERICREPLY_ENABLE_CACHE                       1
38 #define GENERICREPLY_ENABLE_DATA                        1
39 #define GENERICREPLY_ENABLE_SPLIT                       0
40 #define GENERICREPLY_ENABLE_COMPRESS                    1
41 
42 #define GENERICREPLY_DATA_LIMIT                         1048576 - 32
43 #define GENERICREPLY_DATA_OFFSET                        32
44 
45 #define GENERICREPLY_CACHE_SLOTS                        400
46 #define GENERICREPLY_CACHE_THRESHOLD                    5
47 #define GENERICREPLY_CACHE_LOWER_THRESHOLD              1
48 
49 #define GENERICREPLY_ENABLE_COMPRESS_IF_PROTO_STEP_7    0
50 
51 //
52 // The message class.
53 //
54 
55 class GenericReplyMessage : public Message
56 {
57   friend class GenericReplyStore;
58 
59   public:
60 
GenericReplyMessage()61   GenericReplyMessage()
62   {
63   }
64 
~GenericReplyMessage()65   ~GenericReplyMessage()
66   {
67   }
68 
69   //
70   // Put here the fields which constitute the
71   // 'identity' part of the message. Starting
72   // from protocol level 3 we use short data
73   // to increase cache efficiency.
74   //
75 
76   private:
77 
78   unsigned char  byte_data;
79   unsigned int   int_data[6];
80   unsigned short short_data[12];
81 };
82 
83 class GenericReplyStore : public MessageStore
84 {
85   public:
86 
87   GenericReplyStore(StaticCompressor *compressor);
88 
89   virtual ~GenericReplyStore();
90 
name()91   virtual const char *name() const
92   {
93     return "GenericReply";
94   }
95 
opcode()96   virtual unsigned char opcode() const
97   {
98     return X_NXInternalGenericReply;
99   }
100 
storage()101   virtual unsigned int storage() const
102   {
103     return sizeof(GenericReplyMessage);
104   }
105 
106   //
107   // Message handling methods.
108   //
109 
110   protected:
111 
create()112   virtual Message *create() const
113   {
114     return new GenericReplyMessage();
115   }
116 
create(const Message & message)117   virtual Message *create(const Message &message) const
118   {
119     return new GenericReplyMessage((const GenericReplyMessage &) message);
120   }
121 
destroy(Message * message)122   virtual void destroy(Message *message) const
123   {
124     delete (GenericReplyMessage *) message;
125   }
126 
127   virtual int encodeIdentity(EncodeBuffer &encodeBuffer, const unsigned char *buffer,
128                                  const unsigned int size, int bigEndian,
129                                      ChannelCache *channelCache) const;
130 
131   virtual int decodeIdentity(DecodeBuffer &decodeBuffer, unsigned char *&buffer,
132                                  unsigned int &size, int bigEndian, WriteBuffer *writeBuffer,
133                                      ChannelCache *channelCache) const;
134 
135   virtual int parseIdentity(Message *message, const unsigned char *buffer,
136                                 unsigned int size, int bigEndian) const;
137 
138   virtual int unparseIdentity(const Message *message, unsigned char *buffer,
139                                   unsigned int size, int bigEndian) const;
140 
141   virtual void updateIdentity(EncodeBuffer &encodeBuffer, const Message *message,
142                                   const Message *cachedMessage,
143                                       ChannelCache *channelCache) const;
144 
145   virtual void updateIdentity(DecodeBuffer &decodeBuffer, const Message *message,
146                                   ChannelCache *channelCache) const;
147 
148   virtual void identityChecksum(const Message *message, const unsigned char *buffer,
149                                     unsigned int size, int bigEndian) const;
150 
151   virtual void dumpIdentity(const Message *message) const;
152 };
153 
154 #endif /* GenericReply_H */
155