Main Page | Modules | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

XSECBinHTTPURIInputStream.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2002-2004 The Apache Software Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * imitations under the License.
00015  */
00016 
00017 /*
00018  * XSEC
00019  *
00020  * XSECBinHTTPURIInputStream := Re-implementation of the Xerces
00021  *                              BinHTTPURLInputStream.  Allows us to make
00022  *                              some small changes to support the requirements
00023  *                              of XMLDSIG (notably re-directs)
00024  *
00025  * NOTE: Much code taken from Xerces, and the cross platform interfacing is
00026  * no-where near as nice.
00027  *
00028  * Author(s): Berin Lautenbach
00029  *
00030  * $Id: XSECBinHTTPURIInputStream.hpp,v 1.4 2004/02/08 10:25:40 blautenb Exp $
00031  *
00032  * $Log: XSECBinHTTPURIInputStream.hpp,v $
00033  * Revision 1.4  2004/02/08 10:25:40  blautenb
00034  * Convert to Apache 2.0 license
00035  *
00036  * Revision 1.3  2003/09/11 11:11:05  blautenb
00037  * Cleaned up usage of Xerces namespace - no longer inject into global namespace in headers
00038  *
00039  * Revision 1.2  2003/07/05 10:30:38  blautenb
00040  * Copyright update
00041  *
00042  * Revision 1.1  2003/02/12 09:45:29  blautenb
00043  * Win32 Re-implementation of Xerces URIResolver to support re-directs
00044  *
00045  *
00046  */
00047 
00048 
00049 #ifndef XSECBINHTTPURIINPUTSTREAM_HEADER
00050 #define XSECBINHTTPURIINPUTSTREAM_HEADER
00051 
00052 #include <xsec/framework/XSECDefs.hpp>
00053 
00054 #include <xercesc/util/XMLUri.hpp>
00055 #include <xercesc/util/XMLExceptMsgs.hpp>
00056 #include <xercesc/util/BinInputStream.hpp>
00057 #include <xercesc/util/Mutexes.hpp>
00058 
00059 //
00060 // This class implements the BinInputStream interface specified by the XML
00061 // parser.
00062 //
00063 
00064 struct hostent;
00065 struct sockaddr;
00066 
00067 
00068 class DSIG_EXPORT XSECBinHTTPURIInputStream : public XERCES_CPP_NAMESPACE_QUALIFIER BinInputStream
00069 {
00070 public :
00071 
00072     XSECBinHTTPURIInputStream(const XERCES_CPP_NAMESPACE_QUALIFIER XMLUri&  urlSource);
00073     ~XSECBinHTTPURIInputStream();
00074 
00075     unsigned int curPos() const;
00076     unsigned int readBytes(XMLByte* const  toFill, const unsigned int    maxToRead);
00077 
00078     static void Cleanup();
00079 
00080 
00081 private :
00082     // -----------------------------------------------------------------------
00083     //  Private data members
00084     //
00085     //  fSocketHandle
00086     //      The socket representing the connection to the remote file.
00087     //      We deliberately did not define the type to be SOCKET, so as to
00088     //      avoid bringing in any Windows header into this file.
00089     //  fBytesProcessed
00090     //      Its a rolling count of the number of bytes processed off this
00091     //      input stream.
00092     //  fBuffer
00093     //      Holds the http header, plus the first part of the actual
00094     //      data.  Filled at the time the stream is opened, data goes
00095     //      out to user in response to readBytes().
00096     //  fBufferPos, fBufferEnd
00097     //      Pointers into fBuffer, showing start and end+1 of content
00098     //      that readBytes must return.
00099     // -----------------------------------------------------------------------
00100 
00101     unsigned int        fSocketHandle;
00102     unsigned int        fBytesProcessed;
00103     char                fBuffer[4000];
00104     char *              fBufferEnd;
00105     char *              fBufferPos;
00106     static bool         fInitialized;
00107     static XERCES_CPP_NAMESPACE_QUALIFIER XMLMutex*    fInitMutex;
00108 
00109     static void Initialize();
00110     unsigned int getSocketHandle(const XERCES_CPP_NAMESPACE_QUALIFIER XMLUri&  urlSource);
00111 
00112     inline static hostent* gethostbyname(const char* name);
00113     inline static unsigned long inet_addr(const char* cp);
00114     inline static hostent* gethostbyaddr(const char* addr,int len,int type);
00115     inline static unsigned short htons(unsigned short hostshort);
00116     inline static unsigned short socket(int af,int type,int protocol);
00117     inline static int connect(unsigned short s,const sockaddr* name,int namelen);
00118     inline static int send(unsigned short s,const char* buf,int len,int flags);
00119     inline static int recv(unsigned short s,char* buf,int len,int flags);
00120     inline static int shutdown(unsigned int s,int how);
00121     inline static int closesocket(unsigned int socket);
00122 };
00123 
00124 
00125 inline unsigned int XSECBinHTTPURIInputStream::curPos() const
00126 {
00127     return fBytesProcessed;
00128 }
00129 
00130 
00131 #endif // XSECBINHTTPURIINPUTSTREAM_HEADER

Generated on Sun Mar 14 21:35:32 2004 for XML-Security-C by doxygen 1.3.2