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

📄 ncbicgi.hpp

📁 ncbi源码
💻 HPP
📖 第 1 页 / 共 3 页
字号:
/* * =========================================================================== * PRODUCTION $Log: ncbicgi.hpp,v $ * PRODUCTION Revision 1000.1  2003/11/18 15:42:41  gouriano * PRODUCTION PRODUCTION: UPGRADED [ORIGINAL] Dev-tree R1.63 * PRODUCTION * =========================================================================== */#ifndef NCBICGI__HPP#define NCBICGI__HPP/*  $Id: ncbicgi.hpp,v 1000.1 2003/11/18 15:42:41 gouriano Exp $* ===========================================================================**                            PUBLIC DOMAIN NOTICE*               National Center for Biotechnology Information**  This software/database is a "United States Government Work" under the*  terms of the United States Copyright Act.  It was written as part of*  the author's official duties as a United States Government employee and*  thus cannot be copyrighted.  This software/database is freely available*  to the public for use. The National Library of Medicine and the U.S.*  Government have not placed any restriction on its use or reproduction.**  Although all reasonable efforts have been taken to ensure the accuracy*  and reliability of the software and data, the NLM and the U.S.*  Government do not and cannot warrant the performance or results that*  may be obtained by using this software or data. The NLM and the U.S.*  Government disclaim all warranties, express or implied, including*  warranties of performance, merchantability or fitness for any particular*  purpose.**  Please cite the author in any work or product based on this material.** ===========================================================================** Author:  Denis Vakatov** File Description:*   NCBI C++ CGI API:*      CCgiCookie    -- one CGI cookie*      CCgiCookies   -- set of CGI cookies*      CCgiRequest   -- full CGI request*/#include <corelib/ncbistd.hpp>#include <corelib/ncbiobj.hpp>#include <list>#include <map>#include <set>#include <memory>#include <time.h>/** @addtogroup CGIReqRes * * @{ */#define HTTP_EOL "\r\n"BEGIN_NCBI_SCOPEclass CTime;///////////////////////////////////////////////////////////  CCgiCookie:://// The CGI send-cookie class//class NCBI_XCGI_EXPORT CCgiCookie{public:    // Copy constructor    CCgiCookie(const CCgiCookie& cookie);    // Throw the "invalid_argument" if "name" or "value" have invalid format    //  - the "name" must not be empty; it must not contain '='    //  - "name", "value", "domain" -- must consist of printable ASCII    //    characters, and not: semicolons(;), commas(,), or space characters.    //  - "path" -- can have space characters.    CCgiCookie(const string& name, const string& value,               const string& domain = NcbiEmptyString,               const string& path   = NcbiEmptyString);    // The cookie name cannot be changed during its whole timelife    const string& GetName(void) const;    // Compose and write to output stream "os":    //   "Set-Cookie: name=value; expires=date; path=val_path; domain=dom_name;    //    secure\n"    // Here, only "name=value" is mandatory, and other parts are optional    CNcbiOstream& Write(CNcbiOstream& os) const;    // Reset everything(but name!) to default state like CCgiCookie(m_Name, "")    void Reset(void);    // Set all attribute values(but name!) to those from "cookie"    void CopyAttributes(const CCgiCookie& cookie);    // All SetXXX(const string&) methods beneath:    //  - set the property to "str" if "str" has valid format    //  - throw the "invalid_argument" if "str" has invalid format    void SetValue  (const string& str);    void SetDomain (const string& str);    // not spec'd by default    void SetPath   (const string& str);    // not spec'd by default    void SetExpDate(const tm& exp_date);   // GMT time (infinite if all zeros)    void SetExpTime(const CTime& exp_time);// GMT time (infinite if all zeros)    void SetSecure (bool secure);          // "false" by default    // All "const string& GetXXX(...)" methods beneath return reference    // to "NcbiEmptyString" if the requested attributre is not set    const string& GetValue  (void) const;    const string& GetDomain (void) const;    const string& GetPath   (void) const;    // Day, dd-Mon-yyyy hh:mm:ss GMT  (return empty string if not set)    string        GetExpDate(void) const;    // If exp.date is not set then return "false" and dont assign "*exp_date"    bool GetExpDate(tm* exp_date) const;    bool GetSecure(void)          const;    // Compare two cookies    bool operator< (const CCgiCookie& cookie) const;    // Predicate for the cookie comparison    typedef const CCgiCookie* TCPtr;    struct PLessCPtr {        bool operator() (const TCPtr& c1, const TCPtr& c2) const {            return (*c1 < *c2);        }    };private:    string m_Name;    string m_Value;    string m_Domain;    string m_Path;    tm     m_Expires;  // GMT time zone    bool   m_Secure;    static void x_CheckField(const string& str, const char* banned_symbols);    static bool x_GetString(string* str, const string& val);    // prohibit default assignment    CCgiCookie& operator= (const CCgiCookie&);};  // CCgiCookie/* @} */inline CNcbiOstream& operator<< (CNcbiOstream& os, const CCgiCookie& cookie){    return cookie.Write(os);}/** @addtogroup CGIReqRes * * @{ *////////////////////////////////////////////////////////////  CCgiCookies:://// Set of CGI send-cookies////  The cookie is uniquely identified by {name, domain, path}.//  "name" is mandatory and non-empty;  "domain" and "path" are optional.//  "name" and "domain" are not case-sensitive;  "path" is case-sensitive.//class NCBI_XCGI_EXPORT CCgiCookies{public:    typedef set<CCgiCookie*, CCgiCookie::PLessCPtr>  TSet;    typedef TSet::iterator         TIter;    typedef TSet::const_iterator   TCIter;    typedef pair<TIter,  TIter>    TRange;    typedef pair<TCIter, TCIter>   TCRange;    // Empty set of cookies    CCgiCookies(void);    // Format of the string:  "name1=value1; name2=value2; ..."    CCgiCookies(const string& str);    // Destructor    ~CCgiCookies(void);    // Return "true" if this set contains no cookies    bool Empty(void) const;    // All Add() functions:    // if the added cookie has the same {name, domain, path} as an already    // existing one then the new cookie will override the old one    CCgiCookie* Add(const string& name, const string& value,                    const string& domain = NcbiEmptyString,                    const string& path   = NcbiEmptyString);    CCgiCookie* Add(const CCgiCookie& cookie);  // add a copy of "cookie"    void Add(const CCgiCookies& cookies);  // update by a set of cookies    void Add(const string& str); // "name1=value1; name2=value2; ..."    // Return NULL if cannot find this exact cookie    CCgiCookie*       Find(const string& name,                           const string& domain, const string& path);    const CCgiCookie* Find(const string& name,                           const string& domain, const string& path) const;    // Return the first matched cookie with name "name", or NULL if    // there is no such cookie(s).    // Also, if "range" is non-NULL then assign its "first" and    // "second" fields to the beginning and the end of the range    // of cookies matching the name "name".    // NOTE:  if there is a cookie with empty domain and path then    //        this cookie is guaranteed to be returned.    CCgiCookie*       Find(const string& name, TRange*  range=0);    const CCgiCookie* Find(const string& name, TCRange* range=0) const;    // Remove "cookie" from this set;  deallocate it if "destroy" is true    // Return "false" if can not find "cookie" in this set    bool Remove(CCgiCookie* cookie, bool destroy=true);    // Remove (and destroy if "destroy" is true) all cookies belonging    // to range "range".  Return # of found and removed cookies.    size_t Remove(TRange& range, bool destroy=true);    // Remove (and destroy if "destroy" is true) all cookies with the    // given "name".  Return # of found and removed cookies.    size_t Remove(const string& name, bool destroy=true);    // Remove all stored cookies    void Clear(void);    // Printout all cookies into the stream "os" (see also CCgiCookie::Write())    CNcbiOstream& Write(CNcbiOstream& os) const;private:    TSet m_Cookies;    // prohibit default initialization and assignment    CCgiCookies(const CCgiCookies&);    CCgiCookies& operator= (const CCgiCookies&);};  // CCgiCookies/* @} */inline CNcbiOstream& operator<< (CNcbiOstream& os, const CCgiCookies& cookies){    return cookies.Write(os);}/** @addtogroup CGIReqRes * * @{ *////////////////////////////////////////////////////////////  CCgiRequest:://// The CGI request class//// Set of "standard" HTTP request propertiesenum ECgiProp {    // server properties    eCgi_ServerSoftware = 0,    eCgi_ServerName,    eCgi_GatewayInterface,    eCgi_ServerProtocol,    eCgi_ServerPort,        // see also "GetServerPort()"    // client properties    eCgi_RemoteHost,    eCgi_RemoteAddr,        // see also "GetRemoteAddr()"    // client data properties    eCgi_ContentType,    eCgi_ContentLength,     // see also "GetContentLength()"    // request properties    eCgi_RequestMethod,    eCgi_PathInfo,    eCgi_PathTranslated,    eCgi_ScriptName,    eCgi_QueryString,    // authentication info    eCgi_AuthType,    eCgi_RemoteUser,    eCgi_RemoteIdent,    // semi-standard properties(from HTTP header)    eCgi_HttpAccept,    eCgi_HttpCookie,    eCgi_HttpIfModifiedSince,    eCgi_HttpReferer,    eCgi_HttpUserAgent,    // # of CCgiRequest-supported standard properties    // for internal use only!    eCgi_NProperties};  // ECgiPropclass NCBI_XCGI_EXPORT CCgiEntry // copy-on-write semantics{private:    struct SData : public CObject    {        SData(const string& value, const string& filename,

⌨️ 快捷键说明

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