packet.h

Go to the documentation of this file.
00001 ///
00002 /// \file       packet.h
00003 ///             Low level protocol packet builder class.
00004 ///             Has knowledge of specific protocol commands in order
00005 ///             to hide protocol details behind an API.
00006 ///
00007 
00008 /*
00009     Copyright (C) 2005-2009, Net Direct Inc. (http://www.netdirect.ca/)
00010 
00011     This program is free software; you can redistribute it and/or modify
00012     it under the terms of the GNU General Public License as published by
00013     the Free Software Foundation; either version 2 of the License, or
00014     (at your option) any later version.
00015 
00016     This program is distributed in the hope that it will be useful,
00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00019 
00020     See the GNU General Public License in the COPYING file at the
00021     root directory of this project for more details.
00022 */
00023 
00024 #ifndef __BARRY_PACKET_H__
00025 #define __BARRY_PACKET_H__
00026 
00027 #include <stdint.h>
00028 
00029 namespace Barry { class Data; }
00030 
00031 namespace Barry {
00032 
00033 // forward declarations
00034 class Parser;
00035 class Builder;
00036 class SocketZero;
00037 class Socket;
00038 class IConverter;
00039 namespace Mode {
00040         class Desktop;
00041 }
00042 
00043 class Packet
00044 {
00045         friend class SocketZero;
00046         friend class Socket;
00047 
00048 protected:
00049         Data &m_send, &m_receive;
00050 
00051         Data& GetSend() { return m_send; }
00052         Data& GetReceive() { return m_receive; }
00053 
00054 public:
00055         Packet(Data &send, Data &receive)
00056                 : m_send(send), m_receive(receive)
00057                 {}
00058         virtual ~Packet() {}
00059 
00060         //////////////////////////////////
00061         // common response analysis
00062 
00063         unsigned int Command() const;   // throws Error if receive isn't big enough
00064 };
00065 
00066 //
00067 // ZeroPacket class
00068 //
00069 /// Provides an API for building and analyzing socket-0 protocol packets.
00070 /// This class relies on 2 external objects: a send and receive Data buffer.
00071 ///
00072 /// Note that the receive buffer may be modified
00073 /// during a packet send, and this DBPacket class provides API helpers
00074 /// to analyze the results.
00075 ///
00076 class ZeroPacket : public Packet
00077 {
00078         friend class Socket;
00079 
00080 public:
00081         ZeroPacket(Data &send, Data &receive);
00082         ~ZeroPacket();
00083 
00084         //////////////////////////////////
00085         // meta access
00086 
00087         //////////////////////////////////
00088         // packet building
00089 
00090         void GetAttribute(unsigned int object, unsigned int attribute);
00091 
00092 
00093         //////////////////////////////////
00094         // response analysis
00095 
00096         unsigned int ObjectID() const;
00097         unsigned int AttributeID() const;
00098         uint32_t ChallengeSeed() const;
00099         unsigned int RemainingTries() const;
00100         unsigned int SocketResponse() const;
00101         unsigned char SocketSequence() const;
00102 };
00103 
00104 
00105 //
00106 // DBPacket class
00107 //
00108 /// Provides an API for building and analyzing raw DB protocol packets.
00109 /// This class relies on 3 external objects: a Mode::Desktop object,
00110 /// a send Data buffer, and a receive data buffer.  Socket and
00111 /// connection details are retrieved on a readonly basis from the
00112 /// Mode::Desktop object, but both send and receive buffers can be
00113 /// modified.
00114 ///
00115 /// Note that the receive buffer may be modified
00116 /// during a packet send, and this DBPacket class provides API helpers
00117 /// to analyze the results.
00118 ///
00119 class DBPacket : public Packet
00120 {
00121         friend class Socket;
00122 
00123 private:
00124         Mode::Desktop &m_con;
00125         unsigned int m_last_dbop;       // last database operation
00126 
00127 protected:
00128 
00129 public:
00130         DBPacket(Mode::Desktop &con, Data &send, Data &receive);
00131         ~DBPacket();
00132 
00133         //////////////////////////////////
00134         // meta access
00135 
00136         //////////////////////////////////
00137         // packet building
00138 
00139         // commands that correspond to the DB operation
00140         // constants in protocol.h
00141         void ClearDatabase(unsigned int dbId);
00142         void GetDBDB();
00143         void GetRecordStateTable(unsigned int dbId);
00144         void SetRecordFlags(unsigned int dbId, unsigned int stateTableIndex, uint8_t flag1);
00145         void DeleteRecordByIndex(unsigned int dbId, unsigned int stateTableIndex);
00146         void GetRecordByIndex(unsigned int dbId, unsigned int stateTableIndex);
00147         bool SetRecordByIndex(unsigned int dbId, unsigned int stateTableIndex, Builder &build, const IConverter *ic);
00148         void GetRecords(unsigned int dbId);
00149         bool SetRecord(unsigned int dbId, Builder &build, const IConverter *ic);
00150 
00151 
00152         //////////////////////////////////
00153         // response analysis
00154 
00155         // DB command response functions
00156         unsigned int ReturnCode() const;        // throws FIXME if packet doesn't support it
00157         unsigned int DBOperation() const; // throws Error on size trouble
00158 
00159         bool Parse(Parser &parser, const IConverter *ic); // switches based on last m_send command
00160 
00161         // response parsers
00162 };
00163 
00164 } // namespace Barry
00165 
00166 #endif
00167 

Generated on Mon Jan 12 10:51:13 2009 for Barry by  doxygen 1.5.7.1