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 InternAtom_H 19 #define InternAtom_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 INTERNATOM_ENABLE_CACHE 1 38 #define INTERNATOM_ENABLE_DATA 0 39 #define INTERNATOM_ENABLE_SPLIT 0 40 #define INTERNATOM_ENABLE_COMPRESS 0 41 42 #define INTERNATOM_DATA_LIMIT 80 43 #define INTERNATOM_DATA_OFFSET 8 44 45 #define INTERNATOM_CACHE_SLOTS 2000 46 #define INTERNATOM_CACHE_THRESHOLD 2 47 #define INTERNATOM_CACHE_LOWER_THRESHOLD 1 48 49 // 50 // The message class. 51 // 52 53 class InternAtomMessage : public Message 54 { 55 friend class InternAtomStore; 56 57 public: 58 InternAtomMessage()59 InternAtomMessage() 60 { 61 } 62 ~InternAtomMessage()63 ~InternAtomMessage() 64 { 65 } 66 67 // 68 // Put here the fields which constitute 69 // the 'identity' part of the message. 70 // 71 72 private: 73 74 unsigned char only_if_exists; 75 unsigned short name_length; 76 }; 77 78 class InternAtomStore : public MessageStore 79 { 80 // 81 // Constructors and destructors. 82 // 83 84 public: 85 InternAtomStore()86 InternAtomStore() : MessageStore() 87 { 88 enableCache = INTERNATOM_ENABLE_CACHE; 89 enableData = INTERNATOM_ENABLE_DATA; 90 enableSplit = INTERNATOM_ENABLE_SPLIT; 91 enableCompress = INTERNATOM_ENABLE_COMPRESS; 92 93 dataLimit = INTERNATOM_DATA_LIMIT; 94 dataOffset = INTERNATOM_DATA_OFFSET; 95 96 cacheSlots = INTERNATOM_CACHE_SLOTS; 97 cacheThreshold = INTERNATOM_CACHE_THRESHOLD; 98 cacheLowerThreshold = INTERNATOM_CACHE_LOWER_THRESHOLD; 99 100 messages_ -> resize(cacheSlots); 101 102 for (T_messages::iterator i = messages_ -> begin(); 103 i < messages_ -> end(); i++) 104 { 105 *i = NULL; 106 } 107 108 temporary_ = NULL; 109 } 110 ~InternAtomStore()111 virtual ~InternAtomStore() 112 { 113 for (T_messages::iterator i = messages_ -> begin(); 114 i < messages_ -> end(); i++) 115 { 116 destroy(*i); 117 } 118 119 destroy(temporary_); 120 } 121 name()122 virtual const char *name() const 123 { 124 return "InternAtom"; 125 } 126 opcode()127 virtual unsigned char opcode() const 128 { 129 return X_InternAtom; 130 } 131 storage()132 virtual unsigned int storage() const 133 { 134 return sizeof(InternAtomMessage); 135 } 136 137 // 138 // Message handling methods. 139 // 140 141 protected: 142 create()143 virtual Message *create() const 144 { 145 return new InternAtomMessage(); 146 } 147 create(const Message & message)148 virtual Message *create(const Message &message) const 149 { 150 return new InternAtomMessage((const InternAtomMessage &) message); 151 } 152 destroy(Message * message)153 virtual void destroy(Message *message) const 154 { 155 delete (InternAtomMessage *) message; 156 } 157 158 virtual int parseIdentity(Message *message, const unsigned char *buffer, 159 unsigned int size, int bigEndian) const; 160 161 virtual int unparseIdentity(const Message *message, unsigned char *buffer, 162 unsigned int size, int bigEndian) const; 163 164 virtual void identityChecksum(const Message *message, const unsigned char *buffer, 165 unsigned int size, int bigEndian) const; 166 167 virtual void dumpIdentity(const Message *message) const; 168 }; 169 170 #endif /* InternAtom_H */ 171