• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeioslave/http
 

tdeioslave/http

  • tdeioslave
  • http
http.h
1 /*
2  Copyright (C) 2000,2001 Dawit Alemayehu <adawit@kde.org>
3  Copyright (C) 2000,2001 Waldo Bastian <bastian@kde.org>
4  Copyright (C) 2000,2001 George Staikos <staikos@kde.org>
5  Copyright (C) 2001,2002 Hamish Rodda <rodda@kde.org>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #ifndef HTTP_H_
24 #define HTTP_H_
25 
26 
27 #include <netinet/in.h>
28 #include <arpa/inet.h>
29 #include <string.h>
30 #include <stdio.h>
31 #include <time.h>
32 
33 #include <tqptrlist.h>
34 #include <tqstrlist.h>
35 #include <tqstringlist.h>
36 
37 #include <kurl.h>
38 #include "tdeio/tcpslavebase.h"
39 #include "tdeio/http.h"
40 
41 class DCOPClient;
42 class TQDomElement;
43 class TQDomNodeList;
44 
45 namespace TDEIO {
46  class AuthInfo;
47 }
48 
49 class HTTPProtocol : public TQObject, public TDEIO::TCPSlaveBase
50 {
51  TQ_OBJECT
52 public:
53  HTTPProtocol( const TQCString &protocol, const TQCString &pool,
54  const TQCString &app );
55  virtual ~HTTPProtocol();
56 
58  enum HTTP_REV {HTTP_None, HTTP_Unknown, HTTP_10, HTTP_11, SHOUTCAST};
59 
61  enum HTTP_AUTH {AUTH_None, AUTH_Basic, AUTH_NTLM, AUTH_Digest, AUTH_Negotiate};
62 
64  // Removed to interfaces/tdeio/http.h
65  //enum HTTP_METHOD {HTTP_GET, HTTP_PUT, HTTP_POST, HTTP_HEAD, HTTP_DELETE,
66  // HTTP_OPTIONS, DAV_PROPFIND, DAV_PROPPATCH, DAV_MKCOL,
67  // DAV_COPY, DAV_MOVE, DAV_LOCK, DAV_UNLOCK, DAV_SEARCH };
68 
70  struct HTTPState
71  {
72  HTTPState ()
73  {
74  port = 0;
75  doProxy = false;
76  }
77 
78  TQString hostname;
79  TQString encoded_hostname;
80  short unsigned int port;
81  TQString user;
82  TQString passwd;
83  bool doProxy;
84  };
85 
87  struct DAVRequest
88  {
89  DAVRequest ()
90  {
91  overwrite = false;
92  depth = 0;
93  }
94 
95  TQString desturl;
96  bool overwrite;
97  int depth;
98  };
99 
101  struct HTTPRequest
102  {
103  HTTPRequest ()
104  {
105  port = 0;
106  method = TDEIO::HTTP_UNKNOWN;
107  offset = 0;
108  doProxy = false;
109  allowCompressedPage = false;
110  disablePassDlg = false;
111  bNoAuth = false;
112  bUseCache = false;
113  bCachedRead = false;
114  bCachedWrite = false;
115  fcache = 0;
116  bMustRevalidate = false;
117  cacheExpireDateOffset = 0;
118  bErrorPage = false;
119  bUseCookiejar = false;
120  expireDate = 0;
121  creationDate = 0;
122  }
123 
124  TQString hostname;
125  TQString encoded_hostname;
126  short unsigned int port;
127  TQString user;
128  TQString passwd;
129  TQString path;
130  TQString query;
131  TDEIO::HTTP_METHOD method;
132  TDEIO::CacheControl cache;
133  TDEIO::filesize_t offset;
134  bool doProxy;
135  KURL url;
136  TQString window; // Window Id this request is related to.
137  TQString referrer;
138  TQString charsets;
139  TQString languages;
140  bool allowCompressedPage;
141  bool disablePassDlg;
142  TQString userAgent;
143  TQString id;
144  DAVRequest davData;
145 
146  bool bNoAuth; // Do not authenticate
147 
148  // Cache related
149  TQString cef; // Cache Entry File belonging to this URL.
150  bool bUseCache; // Whether the cache is active
151  bool bCachedRead; // Whether the file is to be read from m_fcache.
152  bool bCachedWrite; // Whether the file is to be written to m_fcache.
153  FILE* fcache; // File stream of a cache entry
154  TQString etag; // ETag header.
155  TQString lastModified; // Last modified.
156  bool bMustRevalidate; // Cache entry is expired.
157  long cacheExpireDateOffset; // Position in the cache entry where the
158  // 16 byte expire date is stored.
159  time_t expireDate; // Date when the cache entry will expire
160  time_t creationDate; // Date when the cache entry was created
161  TQString strCharset; // Charset
162 
163  // Indicates whether an error-page or error-msg should is preferred.
164  bool bErrorPage;
165 
166  // Cookie flags
167  bool bUseCookiejar;
168  enum { CookiesAuto, CookiesManual, CookiesNone } cookieMode;
169  };
170 
171  struct DigestAuthInfo
172  {
173  TQCString nc;
174  TQCString qop;
175  TQCString realm;
176  TQCString nonce;
177  TQCString method;
178  TQCString cnonce;
179  TQCString username;
180  TQCString password;
181  TQStrList digestURI;
182  TQCString algorithm;
183  TQCString entityBody;
184  };
185 
186 //---------------------- Re-implemented methods ----------------
187  virtual void setHost(const TQString& host, int port, const TQString& user,
188  const TQString& pass);
189 
190  virtual void slave_status();
191 
192  virtual void get( const KURL& url );
193  virtual void put( const KURL& url, int permissions, bool overwrite,
194  bool resume );
195 
196 //----------------- Re-implemented methods for WebDAV -----------
197  virtual void listDir( const KURL& url );
198  virtual void mkdir( const KURL& url, int permissions );
199 
200  virtual void rename( const KURL& src, const KURL& dest, bool overwrite );
201  virtual void copy( const KURL& src, const KURL& dest, int permissions, bool overwrite );
202  virtual void del( const KURL& url, bool isfile );
203 
204  // ask the host whether it supports WebDAV & cache this info
205  bool davHostOk();
206 
207  // send generic DAV request
208  void davGeneric( const KURL& url, TDEIO::HTTP_METHOD method );
209 
210  // Send requests to lock and unlock resources
211  void davLock( const KURL& url, const TQString& scope,
212  const TQString& type, const TQString& owner );
213  void davUnlock( const KURL& url );
214 
215  // Calls httpClose() and finished()
216  void davFinished();
217 
218  // Handle error conditions
219  TQString davError( int code = -1, TQString url = TQString::null );
220 //---------------------------- End WebDAV -----------------------
221 
231  virtual void special( const TQByteArray &data );
232 
233  virtual void mimetype( const KURL& url);
234 
235  virtual void stat( const KURL& url );
236 
237  virtual void reparseConfiguration();
238 
239  virtual void closeConnection(); // Forced close of connection
240 
241  void post( const KURL& url );
242  void multiGet(const TQByteArray &data);
243  bool checkRequestURL( const KURL& );
244  void cacheUpdate( const KURL &url, bool nocache, time_t expireDate);
245 
246  void httpError(); // Generate error message based on response code
247 
248  bool isOffline(const KURL &url); // Check network status
249 
250 protected slots:
251  void slotData(const TQByteArray &);
252  void error( int _errid, const TQString &_text );
253 
254 protected:
255  int readChunked(); // Read a chunk
256  int readLimited(); // Read maximum m_iSize bytes.
257  int readUnlimited(); // Read as much as possible.
258 
265  ssize_t write(const void *buf, size_t nbytes);
266 
272  ssize_t read (void *b, size_t nbytes);
273 
274  char *gets (char *str, int size);
275 
276  void setRewindMarker();
277  void rewind();
278 
284  void addEncoding(TQString, TQStringList &);
285 
286  void configAuth( char *, bool );
287 
288  bool httpOpen(); // Open transfer
289  void httpClose(bool keepAlive); // Close transfer
290 
291  bool httpOpenConnection(); // Open connection
292  void httpCloseConnection(); // Close connection
293  void httpCheckConnection(); // Check whether to keep connection.
294 
295  void forwardHttpResponseHeader();
296 
297  bool readHeader();
298 
299  bool sendBody();
300 
301  // where dataInternal == true, the content is to be made available
302  // to an internal function.
303  bool readBody( bool dataInternal = false );
304 
308  void davSetRequest( const TQCString& requestXML );
309  void davStatList( const KURL& url, bool stat = true );
310  void davParsePropstats( const TQDomNodeList& propstats, TDEIO::UDSEntry& entry );
311  void davParseActiveLocks( const TQDomNodeList& activeLocks,
312  uint& lockCount );
313 
317  long parseDateTime( const TQString& input, const TQString& type );
318 
322  int codeFromResponse( const TQString& response );
323 
328  TQString davProcessLocks();
329 
333  void addCookies( const TQString &url, const TQCString &cookieHeader);
334 
338  TQString findCookies( const TQString &url);
339 
351  FILE *checkCacheEntry(bool readWrite = false);
352 
358  void createCacheEntry(const TQString &mimetype, time_t expireDate);
359 
365  void writeCacheEntry( const char *buffer, int nbytes);
366 
370  void closeCacheEntry();
371 
375  void updateExpireDate(time_t expireDate, bool updateCreationDate=false);
376 
380  void cleanCache();
381 
385  // where dataInternal == true, the content is to be made available
386  // to an internal function.
387  void retrieveContent( bool dataInternal = false );
388 
392  bool retrieveHeader(bool close_connection = true);
393 
397  void resetSessionSettings();
398 
402  void resetResponseSettings();
403 
410  void resetConnectionSettings();
411 
416  TQString proxyAuthenticationHeader();
417 
421  bool getAuthorization();
422 
426  void saveAuthorization();
427 
431  TQString createBasicAuth( bool isForProxy = false );
432 
436  TQString createDigestAuth( bool isForProxy = false );
437 
441  TQString createNTLMAuth( bool isForProxy = false );
442 
446  TQString createNegotiateAuth();
447 
451  TQCString gssError( int major_status, int minor_status );
452 
456  void calculateResponse( DigestAuthInfo &info, TQCString &Response );
457 
461  bool retryPrompt();
462 
466  void promptInfo( TDEIO::AuthInfo& info );
467 
468 protected:
469  HTTPState m_state;
470  HTTPRequest m_request;
471  TQPtrList<HTTPRequest> m_requestQueue;
472 
473  bool m_bBusy; // Busy handling request queue.
474  bool m_bEOF;
475  bool m_bEOD;
476 
477 //--- Settings related to a single response only
478  TQStringList m_responseHeader; // All headers
479  KURL m_redirectLocation;
480  bool m_bRedirect; // Indicates current request is a redirection
481 
482  // Processing related
483  bool m_bChunked; // Chunked tranfer encoding
484  TDEIO::filesize_t m_iSize; // Expected size of message
485  TDEIO::filesize_t m_iBytesLeft; // # of bytes left to receive in this message.
486  TDEIO::filesize_t m_iContentLeft; // # of content bytes left
487  TQByteArray m_bufReceive; // Receive buffer
488  bool m_dataInternal; // Data is for internal consumption
489  char m_lineBuf[1024];
490  char m_rewindBuf[8192];
491  size_t m_rewindCount;
492  char *m_linePtr;
493  size_t m_lineCount;
494  char *m_lineBufUnget;
495  char *m_linePtrUnget;
496  size_t m_lineCountUnget;
497 
498  // Mimetype determination
499  bool m_cpMimeBuffer;
500  TQByteArray m_mimeTypeBuffer;
501 
502  // Language/Encoding related
503  TQStringList m_qTransferEncodings;
504  TQStringList m_qContentEncodings;
505  TQString m_sContentMD5;
506  TQString m_strMimeType;
507 
508 
509 //--- WebDAV
510  // Data structure to hold data which will be passed to an internal func.
511  TQByteArray m_bufWebDavData;
512  TQStringList m_davCapabilities;
513 
514  bool m_davHostOk;
515  bool m_davHostUnsupported;
516 //----------
517 
518  // Holds the POST data so it won't get lost on if we
519  // happend to get a 401/407 response when submitting,
520  // a form.
521  TQByteArray m_bufPOST;
522 
523  // Cache related
524  int m_maxCacheAge; // Maximum age of a cache entry.
525  long m_maxCacheSize; // Maximum cache size in Kb.
526  TQString m_strCacheDir; // Location of the cache.
527 
528 
529 
530 //--- Proxy related members
531  bool m_bUseProxy;
532  bool m_bNeedTunnel; // Whether we need to make a SSL tunnel
533  bool m_bIsTunneled; // Whether we have an active SSL tunnel
534  bool m_bProxyAuthValid;
535  int m_iProxyPort;
536  KURL m_proxyURL;
537  TQString m_strProxyRealm;
538 
539  // Operation mode
540  TQCString m_protocol;
541 
542  // Authentication
543  TQString m_strRealm;
544  TQString m_strAuthorization;
545  TQString m_strProxyAuthorization;
546  HTTP_AUTH Authentication;
547  HTTP_AUTH ProxyAuthentication;
548  bool m_bUnauthorized;
549  short unsigned int m_iProxyAuthCount;
550  short unsigned int m_iWWWAuthCount;
551 
552  // First request on a connection
553  bool m_bFirstRequest;
554 
555  // Persistent connections
556  bool m_bKeepAlive;
557  int m_keepAliveTimeout; // Timeout in seconds.
558 
559  // Persistent proxy connections
560  bool m_bPersistentProxyConnection;
561 
562 
563  // Indicates whether there was some connection error.
564  bool m_bError;
565 
566  // Previous and current response codes
567  unsigned int m_responseCode;
568  unsigned int m_prevResponseCode;
569 
570  // Values that determine the remote connection timeouts.
571  int m_proxyConnTimeout;
572  int m_remoteConnTimeout;
573  int m_remoteRespTimeout;
574 
575  int m_pid;
576 };
577 #endif
HTTPProtocol::DAVRequest
DAV-specific request elements for the current connection.
Definition: http.h:88
HTTPProtocol::HTTPRequest
The request for the current connection.
Definition: http.h:102
HTTPProtocol::HTTPState
HTTP / DAV method.
Definition: http.h:71

tdeioslave/http

Skip menu "tdeioslave/http"
  • Main Page
  • Alphabetical List
  • Class List
  • File List

tdeioslave/http

Skip menu "tdeioslave/http"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeioslave/http by doxygen 1.9.1
This website is maintained by Timothy Pearson.