ncbicgi.cpp

来自「ncbi源码」· C++ 代码 · 共 1,506 行 · 第 1/4 页

CPP
1,506
字号
        "0",   "1",   "2",   "3",   "4",   "5",   "6",   "7",        "8",   "9",   "%3A", "%3B", "%3C", "%3D", "%3E", "%3F",        "%40", "A",   "B",   "C",   "D",   "E",   "F",   "G",        "H",   "I",   "J",   "K",   "L",   "M",   "N",   "O",        "P",   "Q",   "R",   "S",   "T",   "U",   "V",   "W",        "X",   "Y",   "Z",   "%5B", "%5C", "%5D", "%5E", "_",        "%60", "a",   "b",   "c",   "d",   "e",   "f",   "g",        "h",   "i",   "j",   "k",   "l",   "m",   "n",   "o",        "p",   "q",   "r",   "s",   "t",   "u",   "v",   "w",        "x",   "y",   "z",   "%7B", "%7C", "%7D", "%7E", "%7F",        "%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87",        "%88", "%89", "%8A", "%8B", "%8C", "%8D", "%8E", "%8F",        "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97",        "%98", "%99", "%9A", "%9B", "%9C", "%9D", "%9E", "%9F",        "%A0", "%A1", "%A2", "%A3", "%A4", "%A5", "%A6", "%A7",        "%A8", "%A9", "%AA", "%AB", "%AC", "%AD", "%AE", "%AF",        "%B0", "%B1", "%B2", "%B3", "%B4", "%B5", "%B6", "%B7",        "%B8", "%B9", "%BA", "%BB", "%BC", "%BD", "%BE", "%BF",        "%C0", "%C1", "%C2", "%C3", "%C4", "%C5", "%C6", "%C7",        "%C8", "%C9", "%CA", "%CB", "%CC", "%CD", "%CE", "%CF",        "%D0", "%D1", "%D2", "%D3", "%D4", "%D5", "%D6", "%D7",        "%D8", "%D9", "%DA", "%DB", "%DC", "%DD", "%DE", "%DF",        "%E0", "%E1", "%E2", "%E3", "%E4", "%E5", "%E6", "%E7",        "%E8", "%E9", "%EA", "%EB", "%EC", "%ED", "%EE", "%EF",        "%F0", "%F1", "%F2", "%F3", "%F4", "%F5", "%F6", "%F7",        "%F8", "%F9", "%FA", "%FB", "%FC", "%FD", "%FE", "%FF"    };    static const char s_EncodeMarkChars[256][4] = {        "%00", "%01", "%02", "%03", "%04", "%05", "%06", "%07",        "%08", "%09", "%0A", "%0B", "%0C", "%0D", "%0E", "%0F",        "%10", "%11", "%12", "%13", "%14", "%15", "%16", "%17",        "%18", "%19", "%1A", "%1B", "%1C", "%1D", "%1E", "%1F",        "+",   "%21", "%22", "%23", "%24", "%25", "%26", "%27",        "%28", "%29", "%2A", "%2B", "%2C", "%2D", "%2E", "%2F",        "0",   "1",   "2",   "3",   "4",   "5",   "6",   "7",        "8",   "9",   "%3A", "%3B", "%3C", "%3D", "%3E", "%3F",        "%40", "A",   "B",   "C",   "D",   "E",   "F",   "G",        "H",   "I",   "J",   "K",   "L",   "M",   "N",   "O",        "P",   "Q",   "R",   "S",   "T",   "U",   "V",   "W",        "X",   "Y",   "Z",   "%5B", "%5C", "%5D", "%5E", "%5F",        "%60", "a",   "b",   "c",   "d",   "e",   "f",   "g",        "h",   "i",   "j",   "k",   "l",   "m",   "n",   "o",        "p",   "q",   "r",   "s",   "t",   "u",   "v",   "w",        "x",   "y",   "z",   "%7B", "%7C", "%7D", "%7E", "%7F",        "%80", "%81", "%82", "%83", "%84", "%85", "%86", "%87",        "%88", "%89", "%8A", "%8B", "%8C", "%8D", "%8E", "%8F",        "%90", "%91", "%92", "%93", "%94", "%95", "%96", "%97",        "%98", "%99", "%9A", "%9B", "%9C", "%9D", "%9E", "%9F",        "%A0", "%A1", "%A2", "%A3", "%A4", "%A5", "%A6", "%A7",        "%A8", "%A9", "%AA", "%AB", "%AC", "%AD", "%AE", "%AF",        "%B0", "%B1", "%B2", "%B3", "%B4", "%B5", "%B6", "%B7",        "%B8", "%B9", "%BA", "%BB", "%BC", "%BD", "%BE", "%BF",        "%C0", "%C1", "%C2", "%C3", "%C4", "%C5", "%C6", "%C7",        "%C8", "%C9", "%CA", "%CB", "%CC", "%CD", "%CE", "%CF",        "%D0", "%D1", "%D2", "%D3", "%D4", "%D5", "%D6", "%D7",        "%D8", "%D9", "%DA", "%DB", "%DC", "%DD", "%DE", "%DF",        "%E0", "%E1", "%E2", "%E3", "%E4", "%E5", "%E6", "%E7",        "%E8", "%E9", "%EA", "%EB", "%EC", "%ED", "%EE", "%EF",        "%F0", "%F1", "%F2", "%F3", "%F4", "%F5", "%F6", "%F7",        "%F8", "%F9", "%FA", "%FB", "%FC", "%FD", "%FE", "%FF"    };    string url_str;    SIZE_TYPE len = str.length();    if ( !len )        return url_str;    const char (*encode_table)[4] =        encode_mark_chars == eUrlEncode_SkipMarkChars        ? s_Encode : s_EncodeMarkChars;    SIZE_TYPE pos;    SIZE_TYPE url_len = len;    const unsigned char* cstr = (const unsigned char*)str.c_str();    for (pos = 0;  pos < len;  pos++) {        if (encode_table[cstr[pos]][0] == '%')            url_len += 2;    }    url_str.reserve(url_len + 1);    url_str.resize(url_len);    SIZE_TYPE p = 0;    for (pos = 0;  pos < len;  pos++, p++) {        const char* subst = encode_table[cstr[pos]];        if (*subst != '%') {            url_str[p] = *subst;        } else {            url_str[  p] = '%';            url_str[++p] = *(++subst);            url_str[++p] = *(++subst);        }    }    _ASSERT( p == url_len );    url_str[url_len] = '\0';    return url_str;}END_NCBI_SCOPE/** ===========================================================================* $Log: ncbicgi.cpp,v $* Revision 1000.2  2004/06/01 18:39:19  gouriano* PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.76** Revision 1.76  2004/05/17 20:56:50  gorelenk* Added include of PCH ncbi_pch.hpp** Revision 1.75  2003/11/24 18:14:58  ucko* CCgiRequest::ParseEntries: Swallow "amp;" (case-insensitive) after &* for the sake of some older browsers that misparse HREF attributes.** Revision 1.74  2003/10/15 17:06:02  ucko* CCgiRequest::x_Init: truncate str properly in the case of unexpected EOF.** Revision 1.73  2003/08/20 19:41:34  ucko* CCgiRequest::ParseEntries: handle unencoded = signs in values.** Revision 1.72  2003/07/14 20:28:46  vakatov* CCgiCookie::GetExpDate() -- date format to conform with RFC1123** Revision 1.71  2003/07/08 19:04:12  ivanov* Added optional parameter to the URL_Encode() to enable mark charactres* encoding** Revision 1.70  2003/06/04 00:22:53  ucko* Improve diagnostics in CCgiRequest::x_Init.** Revision 1.69  2003/04/16 21:48:19  vakatov* Slightly improved logging format, and some minor coding style fixes.** Revision 1.68  2003/03/12 16:10:23  kuznets* iterate -> ITERATE** Revision 1.67  2003/03/11 19:17:31  kuznets* Improved error diagnostics in CCgiRequest** Revision 1.66  2003/02/24 20:01:54  gouriano* use template-based exceptions instead of errno and parse exceptions** Revision 1.65  2003/02/19 17:50:47  kuznets* Added function AddExpTime to CCgiCookie class** Revision 1.64  2002/09/17 19:57:50  ucko* Add position field to CGI entries; minor reformatting.** Revision 1.63  2002/08/08 19:26:04  ucko* When parsing multipart forms, allow (but ignore) data after the* trailing boundary.** Revision 1.62  2002/07/19 14:50:23  ucko* Substitute NStr::Compare for uses of string::compare added in last revision.** Revision 1.61  2002/07/18 21:15:24  ucko* Rewrite multipart/form-data parser; the old line-by-line approach was* somewhat clumsy and inefficient.** Revision 1.60  2002/07/18 20:18:09  lebedev* NCBI_OS_MAC: STDIN_FILENO define added** Revision 1.59  2002/07/17 17:02:26  ucko* Reinstate more lost changes from R1.56.** Revision 1.58  2002/07/11 17:39:56  gouriano* corrected wrong merge of v1.56 and v1.57** Revision 1.57  2002/07/11 14:22:59  gouriano* exceptions replaced by CNcbiException-type ones** Revision 1.56  2002/07/10 18:40:21  ucko* Made CCgiEntry-based functions the only version; kept "Ex" names as* temporary synonyms, to go away in a few days.** Revision 1.55  2002/07/05 20:45:46  ucko* Add a couple of missing calls to the extended version of s_AddEntry.** Revision 1.54  2002/07/03 20:24:31  ucko* Extend to support learning uploaded files' names; move CVS logs to end.** Revision 1.53  2002/04/26 21:18:31  lavr* Do not enforce the last line of the form to have HTTP_EOL (but just EOF)** Revision 1.52  2002/01/10 23:48:55  vakatov* s_ParseMultipartEntries() -- allow for empty parts** Revision 1.51  2001/12/06 00:19:55  vakatov* CCgiRequest::ParseEntries() -- allow leading '&' in the query string (temp.)** Revision 1.50  2001/10/04 18:17:53  ucko* Accept additional query parameters for more flexible diagnostics.* Support checking the readiness of CGI input and output streams.** Revision 1.49  2001/06/19 20:08:30  vakatov* CCgiRequest::{Set,Get}InputStream()  -- to provide safe access to the* requests' content body** Revision 1.48  2001/06/13 21:04:37  vakatov* Formal improvements and general beautifications of the CGI lib sources.** Revision 1.47  2001/05/17 15:01:49  lavr* Typos corrected** Revision 1.46  2001/02/02 20:55:13  vakatov* CCgiRequest::GetEntry() -- "const"** Revision 1.45  2001/01/30 23:17:31  vakatov* + CCgiRequest::GetEntry()** Revision 1.44  2000/11/01 20:36:31  vasilche* Added HTTP_EOL string macro.** Revision 1.43  2000/06/26 16:34:27  vakatov* CCgiCookies::Add(const string&) -- maimed to workaround MS IE bug* (it sent empty cookies w/o "=" in versions prior to 5.5)** Revision 1.42  2000/05/04 16:29:12  vakatov* s_ParsePostQuery():  do not throw on an unknown Content-Type** Revision 1.41  2000/05/02 16:10:07  vasilche* CGI: Fixed URL parsing when Content-Length header is missing.** Revision 1.40  2000/05/01 16:58:18  vasilche* Allow missing Content-Length and Content-Type headers.** Revision 1.39  2000/02/15 19:25:33  vakatov* CCgiRequest::ParseEntries() -- fixed UMR** Revision 1.38  2000/02/01 22:19:57  vakatov* CCgiRequest::GetRandomProperty() -- allow to retrieve value of* properties whose names are not prefixed by "HTTP_" (optional).* Get rid of the aux.methods GetServerPort() and GetRemoteAddr() which* are obviously not widely used (but add to the volume of API).** Revision 1.37  2000/02/01 16:53:29  vakatov* CCgiRequest::x_Init() -- parse "$QUERY_STRING"(or cmd.-line arg) even* in the case of "POST" method, in order to catch possible "ACTION" args.** Revision 1.36  2000/01/20 17:52:07  vakatov* Two CCgiRequest:: constructors:  one using raw "argc", "argv", "envp",* and another using auxiliary classes "CNcbiArguments" and "CNcbiEnvironment".* + constructor flag CCgiRequest::fOwnEnvironment to take ownership over* the passed "CNcbiEnvironment" object.** Revision 1.35  1999/12/30 22:11:17  vakatov* CCgiCookie::GetExpDate() -- use a more standard time string format.* CCgiCookie::CCgiCookie() -- check the validity of passed cookie attributes** Revision 1.34  1999/11/22 19:07:47  vakatov* CCgiRequest::CCgiRequest() -- check for the NULL "query_string"** Revision 1.33  1999/11/02 22:15:50  vakatov* const CCgiCookie* CCgiCookies::Find() -- forgot to cast to non-const "this"** Revision 1.32  1999/11/02 20:35:42  vakatov* Redesigned of CCgiCookie and CCgiCookies to make them closer to the* cookie standard, smarter, and easier in use** Revision 1.31  1999/06/21 16:04:17  vakatov* CCgiRequest::CCgiRequest() -- the last(optional) arg is of type* "TFlags" rather than the former "bool"** Revision 1.30  1999/05/11 03:11:51  vakatov* Moved the CGI API(along with the relevant tests) from "corelib/" to "cgi/"** Revision 1.29  1999/05/04 16:14:45  vasilche* Fixed problems with program environment.* Added class CNcbiEnvironment for cached access to C environment.** Revision 1.28  1999/05/04 00:03:12  vakatov* Removed the redundant severity arg from macro ERR_POST()** Revision 1.27  1999/05/03 20:32:29  vakatov* Use the (newly introduced) macro from <corelib/ncbidbg.h>:*   RETHROW_TRACE,*   THROW0_TRACE(exception_class),*   THROW1_TRACE(exception_class, exception_arg),*   THROW_TRACE(exception_class, exception_args)* instead of the former (now obsolete) macro _TRACE_THROW.** Revision 1.26  1999/04/30 19:21:03  vakatov* Added more details and more control on the diagnostics* See #ERR_POST, EDiagPostFlag, and ***DiagPostFlag()** Revision 1.25  1999/04/28 16:54:42  vasilche* Implemented stream input processing for FastCGI applications.* Fixed POST request parsing** Revision 1.24  1999/04/14 21:01:22  vakatov* s_HexChar():  get rid of "::tolower()"** Revision 1.23  1999/04/14 20:11:56  vakatov* + <stdio.h>* Changed all "str.compare(...)" to "NStr::Compare(str, ...)"** Revision 1.22  1999/04/14 17:28:58  vasilche* Added parsing of CGI parameters from IMAGE input tag like "cmd.x=1&cmd.y=2"* As a result special parameter is added with empty name: "=cmd"** Revision 1.21  1999/03/01 21:02:22  vasilche* Added parsing of 'form-data' requests.** Revision 1.20  1999/01/07 22:03:42  vakatov* s_URL_Decode():  typo fixed** Revision 1.19  1999/01/07 21:15:22  vakatov* Changed prototypes for URL_DecodeString() and URL_EncodeString()** Revision 1.18  1999/01/07 20:06:04  vakatov* + URL_DecodeString()* + URL_EncodeString()** Revision 1.17  1998/12/28 17:56:36  vakatov* New CVS and development tree structure for the NCBI C++ projects** Revision 1.16  1998/12/04 23:38:35  vakatov* Workaround SunPro's "buggy const"(see "BW_01")* Renamed "CCgiCookies::Erase()" method to "...Clear()"** Revision 1.15  1998/12/01 00:27:19  vakatov* Made CCgiRequest::ParseEntries() to read ISINDEX data, too.* Got rid of now redundant CCgiRequest::ParseIndexesAsEntries()** Revision 1.14  1998/11/30 21:23:19  vakatov* CCgiRequest:: - by default, interprete ISINDEX data as regular FORM entries* + CCgiRequest::ParseIndexesAsEntries()* Allow FORM entry in format "name1&name2....." (no '=' necessary after name)** Revision 1.13  1998/11/27 20:55:21  vakatov* CCgiRequest::  made the input stream arg. be optional(std.input by default)** Revision 1.12  1998/11/27 19:44:34  vakatov* CCgiRequest::  Engage cmd.-line args if "$REQUEST_METHOD" is undefined** Revision 1.11  1998/11/27 15:54:05  vakatov* Cosmetics in the ParseEntries() diagnostics** Revision 1.10  1998/11/26 00:29:53  vakatov* Finished NCBI CGI API;  successfully tested on MSVC++ and SunPro C++ 5.0** Revision 1.9  1998/11/24 23:07:30  vakatov* Draft(almost untested) version of CCgiRequest API** Revision 1.8  1998/11/24 21:31:32  vakatov* Updated with the ISINDEX-related code for CCgiRequest::* TCgiEntries, ParseIndexes(), GetIndexes(), etc.** Revision 1.7  1998/11/24 17:52:17  vakatov* Starting to implement CCgiRequest::* Fully implemented CCgiRequest::ParseEntries() static function** Revision 1.6  1998/11/20 22:36:40  vakatov* Added destructor to CCgiCookies:: class* + Save the works on CCgiRequest:: class in a "compilable" state** Revision 1.4  1998/11/19 23:41:12  vakatov* Tested version of "CCgiCookie::" and "CCgiCookies::"** Revision 1.3  1998/11/19 20:02:51  vakatov* Logic typo:  actually, the cookie string does not contain "Cookie: "** Revision 1.2  1998/11/19 19:50:03  vakatov* Implemented "CCgiCookies::"* Slightly changed "CCgiCookie::" API** Revision 1.1  1998/11/18 21:47:53  vakatov* Draft version of CCgiCookie::* ==========================================================================*/

⌨️ 快捷键说明

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