ipprequest.h
00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License version 2 as published by the Free Software Foundation. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Library General Public License 00015 * along with this library; see the file COPYING.LIB. If not, write to 00016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, USA. 00018 **/ 00019 00020 #ifndef IPPREQUEST_H 00021 #define IPPREQUEST_H 00022 00023 #include <tqstring.h> 00024 #include <tqstringlist.h> 00025 #include <tqtextstream.h> 00026 #include <tqmap.h> 00027 00028 #include <cups/ipp.h> 00029 00030 #include "config.h" 00031 00032 class IppRequest 00033 { 00034 public: 00035 IppRequest(); 00036 ~IppRequest(); 00037 00038 void init(); // re-initializes the request 00039 00040 // request building functions 00041 void addMime(int group, const TQString& name, const TQString& mime); 00042 void addKeyword(int group, const TQString& name, const TQString& key); 00043 void addKeyword(int group, const TQString& name, const TQStringList& keys); 00044 void addURI(int group, const TQString& name, const TQString& uri); 00045 void addURI(int group, const TQString& name, const TQStringList& uris); 00046 void addText(int group, const TQString& name, const TQString& txt); 00047 void addText(int group, const TQString& name, const TQStringList& txts); 00048 void addName(int group, const TQString& name, const TQString& nm); 00049 void addName(int group, const TQString& name, const TQStringList& nms); 00050 void addInteger(int group, const TQString& name, int value); 00051 void addInteger(int group, const TQString& name, const TQValueList<int>& values); 00052 void addEnum(int group, const TQString& name, int value); 00053 void addEnum(int group, const TQString& name, const TQValueList<int>& values); 00054 void addBoolean(int group, const TQString& name, bool value); 00055 void addBoolean(int group, const TQString& name, const TQValueList<bool>& values); 00056 00057 void setOperation(int op); 00058 void setHost(const TQString& host); 00059 void setPort(int p); 00060 00061 // request answer functions 00062 int status(); 00063 TQString statusMessage(); 00064 bool integer(const TQString& name, int& value); 00065 bool boolean(const TQString& name, bool& value); 00066 bool enumvalue(const TQString& name, int& value); 00067 bool name(const TQString& name, TQString& value); 00068 bool name(const TQString& name, TQStringList& value); 00069 bool text(const TQString& name, TQString& value); 00070 bool text(const TQString& name, TQStringList& value); 00071 bool uri(const TQString& name, TQString& value); 00072 bool uri(const TQString& name, TQStringList& value); 00073 bool keyword(const TQString& name, TQString& value); 00074 bool keyword(const TQString& name, TQStringList& value); 00075 bool mime(const TQString& name, TQString& value); 00076 ipp_attribute_t* first(); 00077 #ifndef HAVE_CUPS_1_6 00078 ipp_attribute_t* last(); 00079 #endif // HAVE_CUPS_1_6 00080 ipp_t* request(); 00081 TQMap<TQString,TQString> toMap(int group = -1); 00082 void setMap(const TQMap<TQString,TQString>& opts); 00083 00084 // processing functions 00085 bool doRequest(const TQString& res); 00086 bool doFileRequest(const TQString& res, const TQString& filename = TQString::null); 00087 00088 // report functions 00089 bool htmlReport(int group, TQTextStream& output); 00090 00091 // debug function 00092 void dump(int state); 00093 00094 protected: 00095 void addString_p(int group, int type, const TQString& name, const TQString& value); 00096 void addStringList_p(int group, int type, const TQString& name, const TQStringList& values); 00097 void addInteger_p(int group, int type, const TQString& name, int value); 00098 void addIntegerList_p(int group, int type, const TQString& name, const TQValueList<int>& values); 00099 bool stringValue_p(const TQString& name, TQString& value, int type); 00100 bool stringListValue_p(const TQString& name, TQStringList& values, int type); 00101 bool integerValue_p(const TQString& name, int& value, int type); 00102 00103 private: 00104 ipp_t *request_; 00105 QString host_; 00106 int port_; 00107 bool connect_; 00108 int dump_; 00109 }; 00110 00111 inline void IppRequest::addMime(int group, const TQString& name, const TQString& mime) 00112 { addString_p(group, IPP_TAG_MIMETYPE, name, mime); } 00113 00114 inline void IppRequest::addKeyword(int group, const TQString& name, const TQString& key) 00115 { addString_p(group, IPP_TAG_KEYWORD, name, key); } 00116 00117 inline void IppRequest::addKeyword(int group, const TQString& name, const TQStringList& keys) 00118 { addStringList_p(group, IPP_TAG_KEYWORD, name, keys); } 00119 00120 inline void IppRequest::addURI(int group, const TQString& name, const TQString& uri) 00121 { addString_p(group, IPP_TAG_URI, name, uri); } 00122 00123 inline void IppRequest::addURI(int group, const TQString& name, const TQStringList& uris) 00124 { addStringList_p(group, IPP_TAG_URI, name, uris); } 00125 00126 inline void IppRequest::addText(int group, const TQString& name, const TQString& txt) 00127 { addString_p(group, IPP_TAG_TEXT, name, txt); } 00128 00129 inline void IppRequest::addText(int group, const TQString& name, const TQStringList& txts) 00130 { addStringList_p(group, IPP_TAG_TEXT, name, txts); } 00131 00132 inline void IppRequest::addName(int group, const TQString& name, const TQString& nm) 00133 { addString_p(group, IPP_TAG_NAME, name, nm); } 00134 00135 inline void IppRequest::addName(int group, const TQString& name, const TQStringList& nms) 00136 { addStringList_p(group, IPP_TAG_NAME, name, nms); } 00137 00138 inline void IppRequest::addInteger(int group, const TQString& name, int value) 00139 { addInteger_p(group, IPP_TAG_INTEGER, name, value); } 00140 00141 inline void IppRequest::addInteger(int group, const TQString& name, const TQValueList<int>& values) 00142 { addIntegerList_p(group, IPP_TAG_INTEGER, name, values); } 00143 00144 inline void IppRequest::addEnum(int group, const TQString& name, int value) 00145 { addInteger_p(group, IPP_TAG_ENUM, name, value); } 00146 00147 inline void IppRequest::addEnum(int group, const TQString& name, const TQValueList<int>& values) 00148 { addIntegerList_p(group, IPP_TAG_ENUM, name, values); } 00149 00150 inline bool IppRequest::integer(const TQString& name, int& value) 00151 { return integerValue_p(name, value, IPP_TAG_INTEGER); } 00152 00153 inline bool IppRequest::enumvalue(const TQString& name, int& value) 00154 { return integerValue_p(name, value, IPP_TAG_ENUM); } 00155 00156 inline bool IppRequest::name(const TQString& name, TQString& value) 00157 { return stringValue_p(name, value, IPP_TAG_NAME); } 00158 00159 inline bool IppRequest::name(const TQString& name, TQStringList& values) 00160 { return stringListValue_p(name, values, IPP_TAG_NAME); } 00161 00162 inline bool IppRequest::text(const TQString& name, TQString& value) 00163 { return stringValue_p(name, value, IPP_TAG_TEXT); } 00164 00165 inline bool IppRequest::text(const TQString& name, TQStringList& values) 00166 { return stringListValue_p(name, values, IPP_TAG_TEXT); } 00167 00168 inline bool IppRequest::uri(const TQString& name, TQString& value) 00169 { return stringValue_p(name, value, IPP_TAG_URI); } 00170 00171 inline bool IppRequest::uri(const TQString& name, TQStringList& values) 00172 { return stringListValue_p(name, values, IPP_TAG_URI); } 00173 00174 inline bool IppRequest::keyword(const TQString& name, TQString& value) 00175 { return stringValue_p(name, value, IPP_TAG_KEYWORD); } 00176 00177 inline bool IppRequest::keyword(const TQString& name, TQStringList& values) 00178 { return stringListValue_p(name, values, IPP_TAG_KEYWORD); } 00179 00180 inline bool IppRequest::mime(const TQString& name, TQString& value) 00181 { return stringValue_p(name, value, IPP_TAG_MIMETYPE); } 00182 00183 inline bool IppRequest::doRequest(const TQString& res) 00184 { return doFileRequest(res); } 00185 00186 #ifndef HAVE_CUPS_1_6 00187 inline ipp_attribute_t* IppRequest::last() 00188 { return (request_ ? request_->last : NULL); } 00189 #endif // HAVE_CUPS_1_6 00190 00191 inline void IppRequest::setHost(const TQString& host) 00192 { host_ = host; } 00193 00194 inline void IppRequest::setPort(int p) 00195 { port_ = p; } 00196 00197 inline void IppRequest::dump(int state) 00198 { dump_ = state; } 00199 00200 inline ipp_t* IppRequest::request() 00201 { return request_; } 00202 00203 #endif