⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 http.h

📁 pwlib源码库
💻 H
📖 第 1 页 / 共 5 页
字号:
/* * http.h * * HyperText Transport Protocol classes. * * Portable Windows Library * * Copyright (c) 1993-2002 Equivalence Pty. Ltd. * * The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. * * The Original Code is Portable Windows Library. * * The Initial Developer of the Original Code is Equivalence Pty. Ltd. * * Contributor(s): ______________________________________. * * $Log: http.h,v $ * Revision 1.59  2005/01/03 12:48:41  csoutheren * Added new configure options and ability to disable/enable modules * * Revision 1.58  2004/10/23 11:34:59  ykiryanov * Added ifdef _WIN32_WCE for PocketPC 2003 SDK port * * Revision 1.57  2002/12/03 22:37:36  robertj * Removed get document that just returns a content length as the chunked *   transfer encoding makes this very dangerous. * Added GetTextDocument() to get a URL content into a PString. * Added a version pf PostData() that gets the reponse content into a PString. * Added ReadContentBody() that takes a PString, not just PBYTEArray. * * Revision 1.56  2002/11/06 22:47:23  robertj * Fixed header comment (copyright etc) * * Revision 1.55  2002/10/10 04:43:43  robertj * VxWorks port, thanks Martijn Roest * * Revision 1.54  2002/10/02 08:54:34  craigs * Added support for XMLRPC server * * Revision 1.53  2002/09/16 01:08:59  robertj * Added #define so can select if #pragma interface/implementation is used on *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. * * Revision 1.52  2002/05/08 05:38:53  robertj * Added PHTTPTailFile resource to do a unix 'tail -f' of a file. * * Revision 1.51  2001/10/31 01:34:47  robertj * Added extra const for constant HTTP tag name strings. * Changes to support HTTP v1.1 chunked transfer encoding. * * Revision 1.50  2001/10/03 00:26:34  robertj * Upgraded client to HTTP/1.1 and for chunked mode entity bodies. * * Revision 1.49  2001/09/28 08:55:15  robertj * More changes to support restartable PHTTPClient * * Revision 1.48  2001/09/28 00:42:54  robertj * Added automatic setting of some outward MIME fields. * Added "user agent" string field for automatic inclusion. * Added function to read the contents of the HTTP request. * * Revision 1.47  2001/08/28 06:44:30  craigs * Added ability to override PHTTPServer creation * * Revision 1.46  2001/03/14 01:49:54  craigs * Added ability to handle multi-part form POST commands * * Revision 1.45  2001/02/22 05:26:47  robertj * Added "nicer" version of GetDocument in HTTP client class. * * Revision 1.44  2001/01/15 06:16:53  robertj * Set HTTP resource members to private to assure are not modified by *   dscendents in non-threadsafe manner. * * Revision 1.43  2000/09/04 03:57:58  robertj * Added ability to change the persistent connection parameters (timeout etc). * * Revision 1.42  2000/05/02 08:28:10  craigs * Removed "memory leaks" caused by brain-dead GNU linker * * Revision 1.41  1999/09/17 01:11:14  robertj * Fixed some documentation typos. * * Revision 1.40  1999/05/13 04:04:04  robertj * Fixed problem of initialised commandName in ConnectionInfo. * * Revision 1.39  1999/05/04 15:26:01  robertj * Improved HTTP/1.1 compatibility (pass through user commands). * Fixed problems with quicktime installer. * * Revision 1.38  1999/04/21 01:58:08  robertj * Fixed problem with reading data for request using second form of PHTTPRequestInfo constructor. * * Revision 1.37  1999/03/09 08:01:46  robertj * Changed comments for doc++ support (more to come). * * Revision 1.36  1999/02/16 08:07:10  robertj * MSVC 6.0 compatibility changes. * * Revision 1.35  1998/11/30 02:50:47  robertj * New directory structure * * Revision 1.34  1998/10/31 12:49:21  robertj * Added read/write mutex to the HTTP space variable to avoid thread crashes. * * Revision 1.33  1998/10/25 01:00:46  craigs * Added ability to specify per-directory authorisation for PHTTPDirectory * * Revision 1.32  1998/09/23 06:19:29  robertj * Added open source copyright license. * * Revision 1.31  1998/07/24 06:58:42  robertj * Changed PostData function so just has string for data instead of dictionary. * * Revision 1.30  1998/06/16 03:33:33  robertj * Changed TCP connection shutdown to be parameterised. * Propagated persistence and proxy flags in new connection info instances. * * Revision 1.29  1998/04/14 03:42:59  robertj * Fixed error code propagation in HTTP client. * * Revision 1.28  1998/02/03 06:29:38  robertj * Added local address and port to PHTTPRequest. * * Revision 1.27  1998/01/26 00:24:24  robertj * Added more information to PHTTPConnectionInfo. * Added function to allow HTTPClient to automatically connect if URL has hostname. * * Revision 1.26  1997/10/30 10:22:52  robertj * Added multiple user basic authorisation scheme. * * Revision 1.25  1997/10/03 13:30:15  craigs * Added ability to access client socket from within HTTP resources * * Revision 1.24  1997/03/28 04:40:22  robertj * Added tags for cookies. * * Revision 1.23  1997/01/12 04:15:19  robertj * Globalised MIME tag strings. * * Revision 1.22  1996/10/26 03:31:05  robertj * Changed OnError so can pass in full HTML page as parameter. * * Revision 1.21  1996/09/14 13:09:10  robertj * Major upgrade: *   rearranged sockets to help support IPX. *   added indirect channel class and moved all protocols to descend from it, *   separating the protocol from the low level byte transport. * * Revision 1.20  1996/08/22 13:20:55  robertj * Fixed bug in authorisation, missing virtual prevented polymorphism. * * Revision 1.19  1996/08/19 13:44:06  robertj * Fixed authorisation so if have no user/password on basic authentication, does not require it. * * Revision 1.18  1996/06/28 13:15:23  robertj * Modified HTTPAuthority so gets PHTTPReqest (mainly for URL) passed in. * Moved HTTP form resource to another compilation module. * * Revision 1.17  1996/06/07 13:52:20  robertj * Added PUT to HTTP proxy FTP. Necessitating redisign of entity body processing. * * Revision 1.16  1996/05/23 10:00:52  robertj * Added common function for GET and HEAD commands. * Fixed status codes to be the actual status code instead of sequential enum. * This fixed some problems with proxy pass through of status codes. * * Revision 1.14  1996/03/31 08:46:51  robertj * HTTP 1.1 upgrade. * * Revision 1.13  1996/03/17 05:41:57  robertj * Added hit count to PHTTPResource. * * Revision 1.12  1996/03/16 04:39:55  robertj * Added ParseReponse() for splitting reponse line into code and info. * Added client side support for HTTP socket. * Added hooks for proxy support in HTTP socket. * * Revision 1.11  1996/03/10 13:15:23  robertj * Redesign to make resources thread safe. * * Revision 1.10  1996/03/02 03:12:55  robertj * Added radio button and selection boxes to HTTP form resource. * * Revision 1.9  1996/02/25 11:14:21  robertj * Radio button support for forms. * * Revision 1.8  1996/02/25 02:57:48  robertj * Removed pass through HTTP resource. * * Revision 1.7  1996/02/19 13:25:43  robertj * Added overwrite option to AddResource(). * Added get/set string to PHTTPString resource. * Moved nested classes from PHTTPForm. * * Revision 1.6  1996/02/13 13:09:16  robertj * Added extra parameters to callback function in PHTTPResources, required *   by descendants to make informed decisions on data being loaded. * * Revision 1.5  1996/02/08 12:04:19  robertj * Redesign of resource object callback virtuals. * Added HTML form resource type. * * Revision 1.4  1996/02/03 11:03:32  robertj * Added ismodified since and expires time checking. * Added PHTTPString that defaults to empty string. * * Revision 1.3  1996/01/28 14:15:38  robertj * Changed PCharArray in OnLoadData to PString for convenience in mangling data. * Beginning of pass through resource type. * * Revision 1.2  1996/01/26 02:24:26  robertj * Further implemetation. * * Revision 1.1  1996/01/23 13:04:20  robertj * Initial revision * */#ifndef _PHTTP#define _PHTTP#ifdef P_USE_PRAGMA#pragma interface#endif#include <ptclib/inetprot.h>#include <ptclib/mime.h>#include <ptclib/url.h>#include <ptlib/ipsock.h>#ifdef P_HTTPSVC#include <ptclib/html.h>//////////////////////////////////////////////////////////////////////////////// PHTTPSpaceclass PHTTPResource;/** This class describes a name space that a Universal Resource Locator operates   in. Each section of the hierarchy field of the URL points to a leg in the   tree specified by this class. */class PHTTPSpace : public PContainer{  PCONTAINERINFO(PHTTPSpace, PContainer)  public:    /// Constructor for HTTP URL Name Space    PHTTPSpace();  // New functions for class.    enum AddOptions {      /// Generate error if resource already exists      ErrorOnExist,      /// Overwrite the existing resource at URL location      Overwrite    };    /** Add a new resource to the URL space. If there is already a resource at       the location in the tree, or that location in the tree is already in       the path to another resource then the function will fail.       The <CODE>overwrite</CODE> flag can be used to replace an existing       resource. The function will still fail if the resource is on a partial       path to another resource but not if it is a leaf node.       @return       TRUE if resource added, FALSE if failed.     */    BOOL AddResource(      PHTTPResource * resource, /// Resource to add to the name space.      AddOptions overwrite = ErrorOnExist        /// Flag to overwrite an existing resource if it already exists.    );    /** Delete an existing resource to the URL space. If there is not a resource       at the location in the tree, or that location in the tree is in the       path to another resource then the function will fail.       @return       TRUE if resource deleted, FALSE if failed.     */    BOOL DelResource(      const PURL & url          /// URL to search for in the name space.    );    /** Locate the resource specified by the URL in the URL name space.       @return       The resource found or NULL if no resource at that position in hiearchy.     */    PHTTPResource * FindResource(      const PURL & url   /// URL to search for in the name space.    );    /** This function attempts to acquire the mutex for reading.     */    void StartRead() const      { mutex->StartRead(); }    /** This function attempts to release the mutex for reading.     */    void EndRead() const      { mutex->EndRead(); }    /** This function attempts to acquire the mutex for writing.     */    void StartWrite() const      { mutex->StartWrite(); }    /** This function attempts to release the mutex for writing.     */    void EndWrite() const      { mutex->EndWrite(); }  protected:    PReadWriteMutex * mutex;    class Node;    PSORTED_LIST(ChildList, Node);    class Node : public PString    {      PCLASSINFO(Node, PString)      public:        Node(const PString & name, Node * parentNode);        ~Node();        Node          * parent;        ChildList       children;        PHTTPResource * resource;    } * root;  private:    BOOL SetSize(PINDEX) { return FALSE; }};#endif // P_HTTPSVC#ifdef _WIN32_WCE#undef TRACE#endif//////////////////////////////////////////////////////////////////////////////// PHTTP/** A common base class for TCP/IP socket for the HyperText Transfer Protocolversion 1.0 client and server. */class PHTTP : public PInternetProtocol{  PCLASSINFO(PHTTP, PInternetProtocol)  public:  // New functions for class.    enum Commands {      // HTTP/1.0 commands      GET, HEAD, POST,      // HTTP/1.1 commands      PUT, DELETE, TRACE, OPTIONS,      // HTTPS command      CONNECT,      NumCommands    };    enum StatusCode {      Continue = 100,              // 100 - Continue      SwitchingProtocols,          // 101 - upgrade allowed      RequestOK = 200,             // 200 - request has succeeded

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -