3 /// Low level protocol packet builder class.
4 /// Has knowledge of specific protocol commands in order
5 /// to hide protocol details behind an API.
9 Copyright (C) 2005-2008, Net Direct Inc. (http://www.netdirect.ca/)
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 See the GNU General Public License in the COPYING file at the
21 root directory of this project for more details.
24 #ifndef __BARRY_PACKET_H__
25 #define __BARRY_PACKET_H__
29 namespace Barry
{ class Data
; }
33 // forward declarations
44 friend class SocketZero
;
48 Data
&m_send
, &m_receive
;
50 Data
& GetSend() { return m_send
; }
51 Data
& GetReceive() { return m_receive
; }
54 Packet(Data
&send
, Data
&receive
)
55 : m_send(send
), m_receive(receive
)
59 //////////////////////////////////
60 // common response analysis
62 unsigned int Command() const; // throws Error if receive isn't big enough
68 /// Provides an API for building and analyzing socket-0 protocol packets.
69 /// This class relies on 2 external objects: a send and receive Data buffer.
71 /// Note that the receive buffer may be modified
72 /// during a packet send, and this DBPacket class provides API helpers
73 /// to analyze the results.
75 class ZeroPacket
: public Packet
80 ZeroPacket(Data
&send
, Data
&receive
);
83 //////////////////////////////////
86 //////////////////////////////////
89 void GetAttribute(unsigned int object
, unsigned int attribute
);
92 //////////////////////////////////
95 unsigned int ObjectID() const;
96 unsigned int AttributeID() const;
97 uint32_t ChallengeSeed() const;
98 unsigned int RemainingTries() const;
99 unsigned int SocketResponse() const;
100 unsigned char SocketSequence() const;
107 /// Provides an API for building and analyzing raw DB protocol packets.
108 /// This class relies on 3 external objects: a Mode::Desktop object,
109 /// a send Data buffer, and a receive data buffer. Socket and
110 /// connection details are retrieved on a readonly basis from the
111 /// Mode::Desktop object, but both send and receive buffers can be
114 /// Note that the receive buffer may be modified
115 /// during a packet send, and this DBPacket class provides API helpers
116 /// to analyze the results.
118 class DBPacket
: public Packet
123 Mode::Desktop
&m_con
;
124 unsigned int m_last_dbop
; // last database operation
129 DBPacket(Mode::Desktop
&con
, Data
&send
, Data
&receive
);
132 //////////////////////////////////
135 //////////////////////////////////
138 // commands that correspond to the DB operation
139 // constants in protocol.h
140 void ClearDatabase(unsigned int dbId
);
142 void GetRecordStateTable(unsigned int dbId
);
143 void SetRecordFlags(unsigned int dbId
, unsigned int stateTableIndex
, uint8_t flag1
);
144 void DeleteRecordByIndex(unsigned int dbId
, unsigned int stateTableIndex
);
145 void GetRecordByIndex(unsigned int dbId
, unsigned int stateTableIndex
);
146 bool SetRecordByIndex(unsigned int dbId
, unsigned int stateTableIndex
, Builder
&build
);
147 void GetRecords(unsigned int dbId
);
148 bool SetRecord(unsigned int dbId
, Builder
&build
);
151 //////////////////////////////////
154 // DB command response functions
155 unsigned int ReturnCode() const; // throws FIXME if packet doesn't support it
156 unsigned int DBOperation() const; // throws Error on size trouble
158 bool Parse(Parser
&parser
); // switches based on last m_send command