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 PROTOCOLS__HTTP__HEADER_BASE_H 00024 #define PROTOCOLS__HTTP__HEADER_BASE_H 00025 00026 #include "Imports.h" 00027 00028 namespace Protocols { 00029 namespace Http { 00030 00032 00048 class HeaderBase : public DataBase 00049 { 00050 public: 00051 // Interface DataBase implementation: 00052 auto_ptr <DataBase> copy() const; 00053 QByteArray toRawBytes() const; 00054 00055 // Own interface: 00056 HeaderBase(); 00057 virtual ~HeaderBase(); 00058 00059 bool operator== (const HeaderBase &) const; 00060 bool operator!= (const HeaderBase &) const; 00061 00062 bool parse (const QByteArray &rawBytes); 00063 00064 QList <QByteArray> fields() const; 00065 bool hasField (const QByteArray &key) const; 00066 00067 QByteArray fieldValue (const QByteArray &fieldName) const; 00068 QList <QByteArray> fieldValues(const QByteArray &fieldName) const; 00069 00070 void setFieldValue (const QByteArray &fieldName, 00071 const QByteArray &fieldValue); 00072 void addFieldValue (const QByteArray &fieldName, 00073 const QByteArray &fieldValue); 00074 void addFieldValues (const QByteArray &fieldName, 00075 const QList <QByteArray> &fieldValues); 00076 void removeField (const QByteArray &fieldName); 00077 00078 protected: 00079 class Data; // Forward declaration needed for the ctor: 00080 HeaderBase (Data *d); 00081 virtual bool parseStartLine (const QByteArray &startLine); 00082 virtual QByteArray rawStartLine() const; 00083 00084 class Data : public SharedData 00085 { 00086 public: 00087 Q_SHARED_DATA_COPY (Data); 00088 00089 QMap <QByteArray, QList <QByteArray> > fieldValues; 00090 QMap <QByteArray, QByteArray> originalCaseFieldNames; 00091 QList <QByteArray> orderedFieldList; 00092 }; 00093 00095 SharedDataPointer d_ptr; 00096 00097 private: 00098 Q_DECLARE_SHARED_DATA (Data); 00099 00100 bool doParse (const QByteArray &rawBytes); 00101 static QList <QByteArray> splitStringIntoLines (const QByteArray &str); 00102 bool parseAllLines (const QList <QByteArray> &lines); 00103 bool parseHeaderLine (const QByteArray &line); 00104 QByteArray rawHeaderLine (const QByteArray &name) const; 00105 }; 00106 00107 } // namespace Http 00108 } // namespace Protocols 00109 00110 #endif // PROTOCOLS__HTTP__HEADER_BASE_H