55
55
ERROR_TEMP_BANNED = 32,
56
56
ERROR_PROTOCOL_GENERIC = 40,
57
57
ERROR_PROTOCOL_UNSUPPORTED = 41,
58
ERROR_INF_MISSING = 42,
60
ERROR_FEATURE_MISSING = 44,
58
ERROR_CONNECT_FAILED = 42,
59
ERROR_INF_MISSING = 43,
61
ERROR_FEATURE_MISSING = 45,
62
63
ERROR_TRANSFER_GENERIC = 50,
63
64
ERROR_FILE_NOT_AVAILABLE = 51,
64
65
ERROR_FILE_PART_NOT_AVAILABLE = 52,
74
75
static const char TYPE_BROADCAST = 'B';
75
76
static const char TYPE_CLIENT = 'C';
76
77
static const char TYPE_DIRECT = 'D';
78
static const char TYPE_ECHO = 'E';
77
79
static const char TYPE_FEATURE = 'F';
78
80
static const char TYPE_INFO = 'I';
79
81
static const char TYPE_HUB = 'H';
80
82
static const char TYPE_UDP = 'U';
82
#if defined(_WIN32) || defined(__i386__) || defined(__x86_64__) || defined(__alpha) // Little-endian
83
#define C(n, a, b, c) static const u_int32_t CMD_##n = (((u_int32_t)a) | (((u_int32_t)b)<<8) | (((u_int32_t)c)<<16)); typedef Type<CMD_##n> n
85
#define C(n, a, b, c) static const u_int32_t CMD_##n = ((((u_int32_t)a)<<24) | (((u_int32_t)b)<<16) | (((u_int32_t)c)<<8)); typedef Type<CMD_##n> n
84
#if defined(_WIN32) || defined(__i386__) || defined(__x86_64__) || defined(__alpha)
85
#define C(n, a, b, c) static const uint32_t CMD_##n = (((uint32_t)a) | (((uint32_t)b)<<8) | (((uint32_t)c)<<16)); typedef Type<CMD_##n> n
87
#define C(n, a, b, c) static const uint32_t CMD_##n = ((((uint32_t)a)<<24) | (((uint32_t)b)<<16) | (((uint32_t)c)<<8)); typedef Type<CMD_##n> n
88
90
C(SUP, 'S','U','P');
105
106
C(CMD, 'C','M','D');
108
static const u_int32_t HUB_SID = 0x41414141; // AAAA in base32
109
static const uint32_t HUB_SID = 0x41414141; // AAAA in base32
110
explicit AdcCommand(u_int32_t aCmd, char aType = TYPE_CLIENT);
111
explicit AdcCommand(u_int32_t aCmd, const u_int32_t aTarget);
111
explicit AdcCommand(uint32_t aCmd, char aType = TYPE_CLIENT);
112
explicit AdcCommand(uint32_t aCmd, const uint32_t aTarget, char aType);
112
113
explicit AdcCommand(Severity sev, Error err, const string& desc, char aType = TYPE_CLIENT);
113
114
explicit AdcCommand(const string& aLine, bool nmdc = false) throw(ParseException);
114
115
void parse(const string& aLine, bool nmdc = false) throw(ParseException);
116
u_int32_t getCommand() const { return cmdInt; }
117
uint32_t getCommand() const { return cmdInt; }
117
118
char getType() const { return type; }
118
119
void setType(char t) { type = t; }
120
121
AdcCommand& setFeatures(const string& feat) { features = feat; return *this; }
122
123
StringList& getParameters() { return parameters; }
123
124
const StringList& getParameters() const { return parameters; }
125
126
string toString(const CID& aCID) const;
126
string toString(u_int32_t sid, bool nmdc = false) const;
127
string toString(uint32_t sid, bool nmdc = false) const;
128
129
AdcCommand& addParam(const string& name, const string& value) {
129
130
parameters.push_back(name);
140
141
/** Return a named parameter where the name is a two-letter code */
141
142
bool getParam(const char* name, size_t start, string& ret) const;
142
143
bool hasFlag(const char* name, size_t start) const;
143
static u_int16_t toCode(const char* x) { return *((u_int16_t*)x); }
144
static uint16_t toCode(const char* x) { return *((uint16_t*)x); }
145
bool operator==(u_int32_t aCmd) { return cmdInt == aCmd; }
146
bool operator==(uint32_t aCmd) { return cmdInt == aCmd; }
147
148
static string escape(const string& str, bool old);
148
u_int32_t getTo() const { return to; }
149
AdcCommand& setTo(const u_int32_t sid) { to = sid; return *this; }
150
u_int32_t getFrom() const { return from; }
149
uint32_t getTo() const { return to; }
150
AdcCommand& setTo(const uint32_t sid) { to = sid; return *this; }
151
uint32_t getFrom() const { return from; }
152
static u_int32_t toSID(const string& aSID) { return *reinterpret_cast<const u_int32_t*>(aSID.data()); }
153
static string fromSID(const u_int32_t aSID) { return string(reinterpret_cast<const char*>(&aSID), sizeof(aSID)); }
153
static uint32_t toSID(const string& aSID) { return *reinterpret_cast<const uint32_t*>(aSID.data()); }
154
static string fromSID(const uint32_t aSID) { return string(reinterpret_cast<const char*>(&aSID), sizeof(aSID)); }
155
156
string getHeaderString(const CID& cid) const;
156
string getHeaderString(u_int32_t sid, bool nmdc) const;
157
string getHeaderString(uint32_t sid, bool nmdc) const;
157
158
string getParamString(bool nmdc) const;
158
159
StringList parameters;