unixhttpurlinputstream.cpp

来自「IBM的解析xml的工具Xerces的源代码」· C++ 代码 · 共 497 行 · 第 1/2 页

CPP
497
字号
/* * Copyright 1999-2004 The Apache Software Foundation. *  * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 *  * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *//* * $Log: UnixHTTPURLInputStream.cpp,v $ * Revision 1.18  2004/09/08 13:56:35  peiyongz * Apache License Version 2.0 * * Revision 1.17  2004/05/11 13:39:35  amassari * The net accessor input source now can be used to get data using PUT or POST, as well as GET * * Revision 1.16  2004/02/11 12:42:22  cargilld * Fix for bug 25541. * * Revision 1.15  2004/01/29 11:51:20  cargilld * Code cleanup changes to get rid of various compiler diagnostic messages. * * Revision 1.14  2004/01/13 16:34:21  cargilld * Misc memory management changes. * * Revision 1.13  2003/12/24 15:24:13  cargilld * More updates to memory management so that the static memory manager. * * Revision 1.12  2003/05/17 05:54:18  knoaman * Update NetAccessors to use the memory manager. * * Revision 1.11  2003/05/16 14:03:28  knoaman * Pass memory manager to makeNewTranscoder. * * Revision 1.10  2003/02/25 21:22:36  tng * Modify UnixHTTPURLInputStream for it to work on ebcdic platform.  Patch from Steve Dulin * * Revision 1.9  2002/12/09 13:12:12  tng * Fix compilation error. * * Revision 1.8  2002/12/09 09:57:27  gareth * Fixed compile error by adding private member. Not very efficient. Should be looked at again. * * Revision 1.7  2002/12/06 16:43:33  tng * Fix the error messages thrown from net accessor module. * * Revision 1.6  2002/12/02 20:41:17  tng * [Bug 12490] Patches required to build Xerces-C++ on BeOS R5.  Patch from Andrew Bachmann. * * Revision 1.5  2002/11/04 15:11:38  tng * C++ Namespace Support. * * Revision 1.4  2002/05/29 14:30:50  peiyongz * Bug9489: Malformed HTTP GET Requests in UnixHTTPUrlInputStream , *                 patch from Gereon Steffens (gereon.steffens@web.de) * * Revision 1.3  2002/05/07 14:36:44  tng * [Bug 8852] UnixHTTPURLInputStream.cpp includes unneeded file. * * Revision 1.2  2002/03/11 21:08:23  peiyongz * Bug#7000: fix to corrupted URL, patch from kent@iastate.edu (Kent) * * Revision 1.1.1.1  2002/02/01 22:22:23  peiyongz * sane_include * * Revision 1.7  2001/09/04 17:53:09  peiyongz * Bugzilla# 3170: patch from Kevin Philips to handle Query in XMLURL. * * Revision 1.6  2001/06/25 16:27:04  tng * AS400 changes by Linda Swan. * * Revision 1.5  2000/07/21 03:31:41  andyh * Improved (but still weak) http access by the parser. * * Revision 1.4  2000/05/15 22:31:28  andyh * Replace #include<memory.h> with <string.h> everywhere. * * Revision 1.3  2000/03/24 01:30:32  rahulj * Connect to the port specified in the URL, rather than the default * one. * * Revision 1.2  2000/03/22 00:58:11  rahulj * Now we throw exceptions when errors occur. * Simplified code based on assumption that calling * function will allocate enough storage to store the * incoming data. * * Revision 1.1  2000/03/20 23:48:51  rahulj * Added Socket based NetAccessor. This will enable one to * use HTTP URL's for system id's. Default build options do * not use this NetAccessor. Specify the '-n socket' option * to 'runConfigure' to configure Xerces-C to use this new * feature. The code works under Solaris 2.6, Linux, AIX * and HPUX 11 with aCC. * Todo's: enable proper error handling. * */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <sys/types.h>#include <sys/socket.h>#if !defined(XML_BEOS)  #include <netinet/in.h>  #include <arpa/inet.h>#endif#include <netdb.h>#include <errno.h>#include <xercesc/util/XMLNetAccessor.hpp>#include <xercesc/util/NetAccessors/Socket/UnixHTTPURLInputStream.hpp>#include <xercesc/util/XMLString.hpp>#include <xercesc/util/XMLExceptMsgs.hpp>#include <xercesc/util/Janitor.hpp>#include <xercesc/util/XMLUniDefs.hpp>#include <xercesc/util/TransService.hpp>#include <xercesc/util/TranscodingException.hpp>#include <xercesc/util/PlatformUtils.hpp>XERCES_CPP_NAMESPACE_BEGINUnixHTTPURLInputStream::UnixHTTPURLInputStream(const XMLURL& urlSource, const XMLNetHTTPInfo* httpInfo/*=0*/)      : fSocket(0)      , fBytesProcessed(0)      , fMemoryManager(urlSource.getMemoryManager()){    //    //  Constants in ASCII to send/check in the HTTP request/response    //    const char GET[] =    {        chLatin_G, chLatin_E, chLatin_T, chSpace, chNull    };    const char PUT[] =    {        chLatin_P, chLatin_U, chLatin_T, chSpace, chNull    };    const char POST[] =    {        chLatin_P, chLatin_O, chLatin_S, chLatin_T, chSpace, chNull    };    const char HTTP[] =    {        chLatin_H, chLatin_T, chLatin_T, chLatin_P, chNull    };    const char HTTP10[] =    {        chSpace, chLatin_H, chLatin_T, chLatin_T, chLatin_P, chForwardSlash, chDigit_1, chPeriod, chDigit_0, chCR, chLF, chNull    };    const char CRLF[] =    {        chCR, chLF, chNull    };    const char CRLF2X[] =    {        chCR, chLF, chCR, chLF, chNull    };    const char LF2X[] =    {        chLF, chLF, chNull    };    const char HOST[] =    {        chLatin_H, chLatin_o, chLatin_s, chLatin_t, chColon, chSpace, chNull    };    const char COLON[] =    {        chColon, chNull    };    const char resp200 [] =    {        chSpace, chDigit_2, chDigit_0, chDigit_0, chSpace, chNull    };    unsigned int charsEaten;    unsigned int transSize;    XMLTransService::Codes failReason;    const unsigned int blockSize = 2048;    const unsigned int bufSize = 5;    static XMLCh portBuffer[bufSize+1];    //    // Pull all of the parts of the URL out of the urlSource object    //    const XMLCh*        hostName = urlSource.getHost();    const XMLCh*        path = urlSource.getPath();    const XMLCh*        fragment = urlSource.getFragment();    const XMLCh*        query = urlSource.getQuery();                            //    //  Convert the hostName to the platform's code page for gethostbyname and    //  inet_addr functions.    //    char*               hostNameAsCharStar = XMLString::transcode(hostName, fMemoryManager);    ArrayJanitor<char>  janBuf1(hostNameAsCharStar, fMemoryManager);    //    //  Convert all the parts of the urlSource object to ASCII so they can be    //  sent to the remote host in that format    //    transSize = XMLString::stringLen(hostName)+1;    char*               hostNameAsASCII = (char*) fMemoryManager->allocate    (        (transSize+1) * sizeof(char)    );//new char[transSize+1];    ArrayJanitor<char>  janBuf2(hostNameAsASCII, fMemoryManager);    XMLTranscoder* trans = XMLPlatformUtils::fgTransService->makeNewTranscoderFor("ISO8859-1", failReason, blockSize, fMemoryManager);    trans->transcodeTo(hostName, transSize, (unsigned char *) hostNameAsASCII, transSize, charsEaten, XMLTranscoder::UnRep_Throw);    char*               pathAsASCII = 0;    ArrayJanitor<char>  janBuf3(pathAsASCII, fMemoryManager);    if (path)    {        transSize = XMLString::stringLen(path)+1;        pathAsASCII = (char*) fMemoryManager->allocate        (            (transSize+1) * sizeof(char)        );//new char[transSize+1];                trans->transcodeTo(path, transSize, (unsigned char *) pathAsASCII, transSize, charsEaten, XMLTranscoder::UnRep_Throw);    }

⌨️ 快捷键说明

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