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-2008, 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 namespace Mode {
00039         class Desktop;
00040 }
00041 
00042 class Packet
00043 {
00044         friend class SocketZero;
00045         friend class Socket;
00046 
00047 protected:
00048         Data &m_send, &m_receive;
00049 
00050         Data& GetSend() { return m_send; }
00051         Data& GetReceive() { return m_receive; }
00052 
00053 public:
00054         Packet(Data &send, Data &receive)
00055                 : m_send(send), m_receive(receive)
00056                 {}
00057         virtual ~Packet() {}
00058 
00059         //////////////////////////////////
00060         // common response analysis
00061 
00062         unsigned int Command() const;   // throws Error if receive isn't big enough
00063 };
00064 
00065 //
00066 // ZeroPacket class
00067 //
00068 /// Provides an API for building and analyzing socket-0 protocol packets.
00069 /// This class relies on 2 external objects: a send and receive Data buffer.
00070 ///
00071 /// Note that the receive buffer may be modified
00072 /// during a packet send, and this DBPacket class provides API helpers
00073 /// to analyze the results.
00074 ///
00075 class ZeroPacket : public Packet
00076 {
00077         friend class Socket;
00078 
00079 public:
00080         ZeroPacket(Data &send, Data &receive);
00081         ~ZeroPacket();
00082 
00083         //////////////////////////////////
00084         // meta access
00085 
00086         //////////////////////////////////
00087         // packet building
00088 
00089         void GetAttribute(unsigned int object, unsigned int attribute);
00090 
00091 
00092         //////////////////////////////////
00093         // response analysis
00094 
00095         unsigned int ObjectID() const;
00096         unsigned int AttributeID() const;
00097         uint32_t ChallengeSeed() const;
00098         unsigned int RemainingTries() const;
00099         unsigned int SocketResponse() const;
00100         unsigned char SocketSequence() const;
00101 };
00102 
00103 
00104 //
00105 // DBPacket class
00106 //
00107 /// Provides an API for building and analyzing raw DB protocol packets.
00108 /// This class relies on 3 external objects: a Mode::Desktop object,
00109 /// a send Data buffer, and a receive data buffer.  Socket and
00110 /// connection details are retrieved on a readonly basis from the
00111 /// Mode::Desktop object, but both send and receive buffers can be
00112 /// modified.
00113 ///
00114 /// Note that the receive buffer may be modified
00115 /// during a packet send, and this DBPacket class provides API helpers
00116 /// to analyze the results.
00117 ///
00118 class DBPacket : public Packet
00119 {
00120         friend class Socket;
00121 
00122 private:
00123         Mode::Desktop &m_con;
00124         unsigned int m_last_dbop;       // last database operation
00125 
00126 protected:
00127 
00128 public:
00129         DBPacket(Mode::Desktop &con, Data &send, Data &receive);
00130         ~DBPacket();
00131 
00132         //////////////////////////////////
00133         // meta access
00134 
00135         //////////////////////////////////
00136         // packet building
00137 
00138         // commands that correspond to the DB operation
00139         // constants in protocol.h
00140         void ClearDatabase(unsigned int dbId);
00141         void GetDBDB();
00142         void GetRecordStateTable(unsigned int dbId);
00143         void SetRecordFlags(unsigned int dbId, unsigned int stateTableIndex, uint8_t flag1);
00144         void DeleteRecordByIndex(unsigned int dbId, unsigned int stateTableIndex);
00145         void GetRecordByIndex(unsigned int dbId, unsigned int stateTableIndex);
00146         bool SetRecordByIndex(unsigned int dbId, unsigned int stateTableIndex, Builder &build);
00147         void GetRecords(unsigned int dbId);
00148         bool SetRecord(unsigned int dbId, Builder &build);
00149 
00150 
00151         //////////////////////////////////
00152         // response analysis
00153 
00154         // DB command response functions
00155         unsigned int ReturnCode() const;        // throws FIXME if packet doesn't support it
00156         unsigned int DBOperation() const; // throws Error on size trouble
00157 
00158         bool Parse(Parser &parser);     // switches based on last m_send command
00159 
00160         // response parsers
00161 };
00162 
00163 } // namespace Barry
00164 
00165 #endif
00166 

Generated on Wed Sep 24 21:27:32 2008 for Barry by  doxygen 1.5.1