Upstream tarball 9756
[amule.git] / cocoa-mule / EC.h
blob5dba2e617b458227248293fce60f5462574ef07e
1 #import <Cocoa/Cocoa.h>
3 #include "ECCodes.h"
4 #include "ECTagTypes.h"
6 @interface ECTag : NSObject {
7 ECTagTypes m_type;
8 ECTagNames m_name;
10 int m_size;
12 NSMutableArray *m_subtags;
15 + (id)tagFromBuffer:(uint8_t **) buffer withLenght:(int) length;
16 + (NSMutableArray *)readSubtags:(uint8_t **) buffer withLenght:(int) length;
18 - (void)initSubtags;
19 - (void)writeToSocket:(NSOutputStream *) socket;
20 - (void)writeSubtagsToSocket:(NSOutputStream *) socket;
22 - (int)getSize;
23 - (int)tagCount;
25 - (id)tagByName:(ECTagNames) tagname;
27 - (uint64_t)tagInt64ByName:(ECTagNames) tagname;
29 @property (readonly) ECTagTypes tagType;
30 @property (readonly) ECTagNames tagName;
32 // needed for fast enumeration of subtags in data updates
33 @property (readonly) NSMutableArray *subtags;
35 @end
37 @interface ECTagInt8 : ECTag {
38 uint8_t m_val;
41 + (id)tagFromInt8:(uint8_t) value withName:(ECTagNames) name;
42 + (id)tagFromBuffer:(uint8_t **) buffer;
44 @property (readonly)uint8_t uint8Value;
46 @end
48 @interface ECTagInt16 : ECTag {
49 uint16_t m_val;
52 + (id)tagFromInt16:(uint16_t) value withName:(ECTagNames) name;
53 + (id)tagFromBuffer:(uint8_t **) buffer;
55 @property (readonly)uint16_t uint16Value;
57 @end
59 @interface ECTagInt32 : ECTag {
60 uint32_t m_val;
63 + (id)tagFromInt32:(uint32_t) value withName:(ECTagNames) name;
64 + (id)tagFromBuffer:(uint8_t **) buffer;
66 @property (readonly)uint32_t uint32Value;
68 @end
70 @interface ECTagInt64 : ECTag {
71 uint64_t m_val;
74 + (id)tagFromInt64:(uint64_t) value withName:(ECTagNames) name;
75 + (id)tagFromBuffer:(uint8_t **) buffer;
77 @property (readonly)uint64_t uint64Value;
79 @end
81 @interface ECTagData : ECTag {
82 NSData *m_data;
85 - (void)writeToSocket:(NSOutputStream *) socket;
86 + (id)tagFromBuffer:(uint8_t **) buffer withLenght:(int) length;
88 @end
90 typedef struct {
91 uint64_t lo, hi;
92 } MD5Data;
94 @interface ECTagMD5 : ECTagData {
95 // contain either raw data (in case of hashed string) or 2 64-bit words (in case of tag coming from ec)
96 MD5Data m_val;
99 + (id)tagFromString:(NSString *) string withName:(ECTagNames) name;
100 + (id)tagFromBuffer:(uint8_t **) buffer;
102 - (MD5Data)getMD5Data;
103 - (NSString *)stringKey;
105 @end
107 @interface ECTagString : ECTagData {
108 // string
109 NSString *m_val;
112 + tagFromString:(NSString *) string withName:(ECTagNames) name;
113 + (id)tagFromBuffer:(uint8_t **) buffer;
115 @property (readonly) NSString * stringValue;
117 @end
119 @interface ECPacket : ECTag {
120 ec_opcode_t m_opcode;
121 uint32_t m_flags;
124 + (id)packetWithOpcode:(ec_opcode_t) opcode;
125 + (id)packetFromBuffer:(uint8_t *) buffer withLength:(int)length;
127 - (void)initWithOpcode:(ec_opcode_t) opcode;
129 - (void)writeToSocket:(NSOutputStream *) socket;
131 @property (readonly) ec_opcode_t opcode;
133 @end
135 @interface ECLoginAuthPacket : ECPacket {
138 + (id)loginPacket:(NSString *) password withSalt:(uint64_t) salt;
140 - (NSString *)getMD5_Str:(NSString *) str;
142 @end
144 @interface ECLoginRequestPacket : ECPacket
148 + (id)loginPacket:(NSString *) version;
151 @end
153 @class ECRemoteConnection;
155 @interface amuleLoginHandler : NSObject {
156 enum LOGIN_REQUEST_STATE {
157 LOGIN_IDLE,
158 LOGIN_REQUEST_SENT,
159 LOGIN_PASS_SENT,
160 LOGIN_OK
161 } m_state;
163 ECRemoteConnection *m_connection;
165 NSString *m_pass;
168 + (id)initWithConnection:(ECRemoteConnection *) connection;
170 - (void)handlePacket:(ECPacket *) packet;
172 - (void)usePass:(NSString *) pass;
174 - (void)reset;
175 - (bool)loginOK;
177 @end
180 @interface NSObject (ECRemoteConnection)
181 - (void)handlePacket:(ECPacket *) packet;
182 @end
184 @interface ECRemoteConnection : NSObject {
185 NSInputStream *m_istream;
186 NSOutputStream *m_ostream;
188 NSMutableData *m_rxbuf;
190 int m_rx_size;
191 int m_remaining_size;
194 NSData *m_txbuf;
195 int m_tx_ptr;
196 int m_tx_size;
198 amuleLoginHandler *m_login_handler;
200 id delegate;
202 bool m_error;
205 + (id)remoteConnection;
207 - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode;
209 - (void)connectToAddress:(NSString *) hostname withPort:(int)trgport;
210 - (void)sendLogin:(NSString *) password;
212 - (void)sendPacket:(ECPacket *) packet;
214 @property (readonly) bool error;
216 - (void)setDelegate:(id) val;
217 - (id)delegate;
219 @end