~ubuntu-branches/debian/lenny/linuxdcpp/lenny

« back to all changes in this revision

Viewing changes to client/AdcCommand.h

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2006-12-08 15:50:58 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20061208155058-tgl4tv9qhurow54z
Tags: 0.0.1.cvs20061208-1
* New upstream release
* Dropped patch for tightening linking, a solution has been implemented
  upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
class AdcCommand {
34
34
public:
35
 
        template<u_int32_t T>
 
35
        template<uint32_t T>
36
36
        struct Type {
37
37
                enum { CMD = T };
38
38
        };
55
55
                ERROR_TEMP_BANNED = 32,
56
56
                ERROR_PROTOCOL_GENERIC = 40,
57
57
                ERROR_PROTOCOL_UNSUPPORTED = 41,
58
 
                ERROR_INF_MISSING = 42,
59
 
                ERROR_BAD_STATE = 43,
60
 
                ERROR_FEATURE_MISSING = 44,
61
 
                ERROR_BAD_IP = 45,
 
58
                ERROR_CONNECT_FAILED = 42,
 
59
                ERROR_INF_MISSING = 43,
 
60
                ERROR_BAD_STATE = 44,
 
61
                ERROR_FEATURE_MISSING = 45,
 
62
                ERROR_BAD_IP = 46,
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';
81
83
 
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
84
 
#else // Big-endian
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
 
86
#else
 
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
86
88
#endif
87
89
        // Base commands
88
90
        C(SUP, 'S','U','P');
96
98
        C(GPA, 'G','P','A');
97
99
        C(PAS, 'P','A','S');
98
100
        C(QUI, 'Q','U','I');
99
 
        C(DSC, 'D','S','C');
100
101
        C(GET, 'G','E','T');
101
102
        C(GFI, 'G','F','I');
102
103
        C(SND, 'S','N','D');
105
106
        C(CMD, 'C','M','D');
106
107
#undef C
107
108
 
108
 
        static const u_int32_t HUB_SID = 0x41414141;            // AAAA in base32
 
109
        static const uint32_t HUB_SID = 0x41414141;             // AAAA in base32
109
110
 
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);
115
116
 
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; }
119
 
        
 
120
 
120
121
        AdcCommand& setFeatures(const string& feat) { features = feat; return *this; }
121
122
 
122
123
        StringList& getParameters() { return parameters; }
123
124
        const StringList& getParameters() const { return parameters; }
124
125
 
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;
127
128
 
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); }
144
145
 
145
 
        bool operator==(u_int32_t aCmd) { return cmdInt == aCmd; }
 
146
        bool operator==(uint32_t aCmd) { return cmdInt == aCmd; }
146
147
 
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; }
151
152
 
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)); }
154
155
private:
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;
159
160
        string features;
160
161
        union {
161
162
                char cmdChar[4];
162
 
                u_int8_t cmd[4];
163
 
                u_int32_t cmdInt;
 
163
                uint8_t cmd[4];
 
164
                uint32_t cmdInt;
164
165
        };
165
 
        u_int32_t from;
166
 
        u_int32_t to;
 
166
        uint32_t from;
 
167
        uint32_t to;
167
168
        char type;
168
169
 
169
170
};
188
189
                                C(GPA);
189
190
                                C(PAS);
190
191
                                C(QUI);
191
 
                                C(DSC);
192
192
                                C(GET);
193
193
                                C(GFI);
194
194
                                C(SND);
195
195
                                C(SID);
196
196
                                C(CMD);
197
 
                        default: 
 
197
                        default:
198
198
                                dcdebug("Unknown ADC command: %.50s\n", aLine.c_str());
199
199
                                break;
200
200
#undef C