updated comments
[barrytmp.git] / src / packet.h
blobadd51b2d608c291351fcf5528ca43b7d987b09c5
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-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__
27 #include <stdint.h>
29 namespace Barry { class Data; }
31 namespace Barry {
33 // forward declarations
34 class Parser;
35 class Builder;
36 class SocketZero;
37 class Socket;
38 namespace Mode {
39 class Desktop;
42 class Packet
44 friend class SocketZero;
45 friend class Socket;
47 protected:
48 Data &m_send, &m_receive;
50 Data& GetSend() { return m_send; }
51 Data& GetReceive() { return m_receive; }
53 public:
54 Packet(Data &send, Data &receive)
55 : m_send(send), m_receive(receive)
57 virtual ~Packet() {}
59 //////////////////////////////////
60 // common response analysis
62 unsigned int Command() const; // throws Error if receive isn't big enough
66 // ZeroPacket class
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.
70 ///
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.
74 ///
75 class ZeroPacket : public Packet
77 friend class Socket;
79 public:
80 ZeroPacket(Data &send, Data &receive);
81 ~ZeroPacket();
83 //////////////////////////////////
84 // meta access
86 //////////////////////////////////
87 // packet building
89 void GetAttribute(unsigned int object, unsigned int attribute);
92 //////////////////////////////////
93 // response analysis
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;
105 // DBPacket class
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
112 /// modified.
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
120 friend class Socket;
122 private:
123 Mode::Desktop &m_con;
124 unsigned int m_last_dbop; // last database operation
126 protected:
128 public:
129 DBPacket(Mode::Desktop &con, Data &send, Data &receive);
130 ~DBPacket();
132 //////////////////////////////////
133 // meta access
135 //////////////////////////////////
136 // packet building
138 // commands that correspond to the DB operation
139 // constants in protocol.h
140 void ClearDatabase(unsigned int dbId);
141 void GetDBDB();
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 //////////////////////////////////
152 // response analysis
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
160 // response parsers
163 } // namespace Barry
165 #endif