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-2007, 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 Data
&m_send
, &m_receive
;
46 Data
& GetSend() { return m_send
; }
47 Data
& GetReceive() { return m_receive
; }
50 Packet(Data
&send
, Data
&receive
)
51 : m_send(send
), m_receive(receive
)
55 //////////////////////////////////
56 // common response analysis
58 unsigned int Command() const; // throws Error if receive isn't big enough
64 /// Provides an API for building and analyzing socket-0 protocol packets.
65 /// This class relies on 2 external objects: a send and receive Data buffer.
67 /// Note that the receive buffer may be modified
68 /// during a packet send, and this DBPacket class provides API helpers
69 /// to analyze the results.
71 class ZeroPacket
: public Packet
76 ZeroPacket(Data
&send
, Data
&receive
);
79 //////////////////////////////////
82 //////////////////////////////////
85 void GetAttribute(unsigned int object
, unsigned int attribute
);
88 //////////////////////////////////
91 unsigned int ObjectID() const;
92 unsigned int AttributeID() const;
93 uint32_t ChallengeSeed() const;
94 unsigned int RemainingTries() const;
95 unsigned int SocketResponse() const;
96 unsigned char SocketSequence() const;
103 /// Provides an API for building and analyzing raw DB protocol packets.
104 /// This class relies on 3 external objects: a Controller object,
105 /// a send Data buffer, and a receive data buffer. Socket and
106 /// connection details are retrieved on a readonly basis from the
107 /// Controller object, but both send and receive buffers can be
110 /// Note that the receive buffer may be modified
111 /// during a packet send, and this DBPacket class provides API helpers
112 /// to analyze the results.
114 class DBPacket
: public Packet
120 unsigned int m_last_dbop
; // last database operation
125 DBPacket(Controller
&con
, Data
&send
, Data
&receive
);
128 //////////////////////////////////
131 //////////////////////////////////
134 // commands that correspond to the DB operation
135 // constants in protocol.h
136 void ClearDatabase(unsigned int dbId
);
138 void GetRecordStateTable(unsigned int dbId
);
139 void SetRecordFlags(unsigned int dbId
, unsigned int stateTableIndex
, uint8_t flag1
);
140 void DeleteRecordByIndex(unsigned int dbId
, unsigned int stateTableIndex
);
141 void GetRecordByIndex(unsigned int dbId
, unsigned int stateTableIndex
);
142 bool SetRecordByIndex(unsigned int dbId
, unsigned int stateTableIndex
, Builder
&build
);
143 void GetRecords(unsigned int dbId
);
144 bool SetRecord(unsigned int dbId
, Builder
&build
);
147 //////////////////////////////////
150 // DB command response functions
151 unsigned int ReturnCode() const; // throws FIXME if packet doesn't support it
152 unsigned int DBOperation() const; // throws Error on size trouble
154 bool Parse(Parser
&parser
); // switches based on last m_send command