00001 /* 00002 00003 Copyright (C) 2005-2007 by Peter Dimov. 00004 00005 This file is part of Calitko (http://www.calitko.org). 00006 00007 Calitko is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 Calitko is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with Calitko; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 00021 */ 00022 00023 #ifndef QUERY_H 00024 #define QUERY_H 00025 00026 #include "Packet.h" 00027 // \todo move to the cpp 00028 #include "Extensions/ExtensionBlock.h" 00029 00030 // Open containing namespaces: 00031 namespace Gnutella { 00032 namespace Packets { 00034 00036 00053 class Query : public Packet 00054 { 00055 public: 00056 static Query & castFrom (Packet & packet) { return dynamic_cast <Query &> (packet); } 00057 static const Query & castFrom (const Packet & packet) { return dynamic_cast <const Query &> (packet); } 00058 00059 Query (const QByteArray &rawHeader, const QByteArray &rawPayload); 00060 Query (const QString &searchCriteria = QString(), quint16 minimumSpeed = 0); 00061 ~Query(); 00062 00063 Query* copy() const { return new Query(*this); } 00064 00065 QString name() const { return QString ("Query"); } 00066 00067 quint16 minimumSpeed() const; 00068 QString searchCriteria() const; 00069 //QueryData queryData() const; 00070 00071 void setMinimumSpeed (const quint16 &minimumSpeed); 00072 void setSearchCriteria (const QString &searchCriteria); 00073 //void setQueryData (const QueryData &queryData); 00074 00075 protected: 00076 bool prepareReadPayload (const QByteArray &rawPayload); 00077 void readPayload (QDataStream &stream); 00078 int prepareWritePayload() const; 00079 void writePayload (QDataStream &stream) const; 00080 00081 private: 00082 00083 typedef Extensions::ExtensionBlock QueryData; 00084 00085 struct Data 00086 { 00087 quint16 minimumSpeed; 00088 QString searchCriteria; 00089 QueryData queryData; 00090 00091 mutable QByteArray rawSearchCriteria; 00092 } p; 00093 }; 00094 00095 // Close containing namespaces: 00096 } // namespace Packets 00097 } // namespace Gnutella 00099 00100 #endif // QUERY_H