Release tarball for barry-0.9
[barry.git] / src / packet.h
blob215872c14544c7edea2e9186ce414ff039edd48c
1 ///
2 /// \file packet.h
3 /// Low level protocol packet builder class.
4 /// Has knowledge of specific protocol commands in order
5 /// to hide protocol details behind an API.
6 ///
8 /*
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__
27 #include <stdint.h>
29 namespace Barry { class Data; }
31 namespace Barry {
33 // forward declarations
34 class Parser;
35 class Builder;
36 class Socket;
37 class Controller;
39 class Packet
41 friend class Socket;
43 protected:
44 Data &m_send, &m_receive;
46 Data& GetSend() { return m_send; }
47 Data& GetReceive() { return m_receive; }
49 public:
50 Packet(Data &send, Data &receive)
51 : m_send(send), m_receive(receive)
53 virtual ~Packet() {}
55 //////////////////////////////////
56 // common response analysis
58 unsigned int Command() const; // throws Error if receive isn't big enough
62 // ZeroPacket class
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.
66 ///
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.
70 ///
71 class ZeroPacket : public Packet
73 friend class Socket;
75 public:
76 ZeroPacket(Data &send, Data &receive);
77 ~ZeroPacket();
79 //////////////////////////////////
80 // meta access
82 //////////////////////////////////
83 // packet building
85 void GetAttribute(unsigned int object, unsigned int attribute);
88 //////////////////////////////////
89 // response analysis
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;
101 // DBPacket class
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
108 /// modified.
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
116 friend class Socket;
118 private:
119 Controller &m_con;
120 unsigned int m_last_dbop; // last database operation
122 protected:
124 public:
125 DBPacket(Controller &con, Data &send, Data &receive);
126 ~DBPacket();
128 //////////////////////////////////
129 // meta access
131 //////////////////////////////////
132 // packet building
134 // commands that correspond to the DB operation
135 // constants in protocol.h
136 void ClearDatabase(unsigned int dbId);
137 void GetDBDB();
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 //////////////////////////////////
148 // response analysis
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
156 // response parsers
159 } // namespace Barry
161 #endif