Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

URLStream Class Reference

A URL processing version of TCPStream. C++ url processing stream class. More...

#include <url.h>

Inheritance diagram for URLStream:

TCPStream Socket List of all members.

Public Types

enum  Error {
  errSuccess = 0, errUnreachable, errMissing, errDenied,
  errInvalid, errForbidden, errUnauthorized, errRelocated,
  errFailure, errTimeout, errInterface
}
 Return error for url fetch. More...
enum  Authentication { authAnonymous = 0, authBasic }
 Type of authentication. More...
enum  Encoding { encodingBinary = 0, encodingChunked }
 Encoding used in transfer. More...
enum  Method {
  methodHttpGet, methodHttpPut, methodHttpPost, methodFtpGet,
  methodFtpPut, methodFileGet, methodFilePut
}
 Type of fetch. More...
enum  Protocol { protocolHttp1_0, protocolHttp1_1 }
 http protocol version More...

Public Member Functions

 URLStream (Family family=IPV4, timeout_t to=0)
 Construct an instance of URL stream.
URLStreamgetline (char *buffer, size_t len)
 Line parsing with conversion.
Error get (const char *url, int buffer=512)
 Get URL data from a named stream of a known buffer size.
Error get (int buffer=512)
 Get URL data from a named stream of a known buffer size.
Error submit (const char *url, const char **vars, int buffer=512)
 Submit URL with vars passed as argument array.
Error post (const char *url, const char **vars, int buffer=512)
 Post URL vars with post method.
Error head (const char *url, int buffer=512)
 Used to fetch header information for a resource.
void close ()
 Close the URL stream for a new connection.
void setReferer (const char *str)
 Set the referer url.
void setHost (const char *str)
 Set the host for the url.
void setAddress (const char *str)
 Set the address for the url.
void setCookie (const char *str)
 Set the cookie to pass.
void setUser (const char *str)
 Set user id for the url.
void setPassword (const char *str)
 Set password for the url.
void setAuthentication (Authentication a, const char *str=NULL)
 Set authentication type for the url.
void setProxyUser (const char *str)
 Set proxy user id for the url.
void setProxyPassword (const char *str)
 Set proxy password for the url.
void setProxyAuthentication (Authentication a, const char *str=NULL)
 Set proxy authentication type for the url.
void setPragma (const char *str)
 Set the pragmas.
void setProxy (const char *host, tpport_t port)
 Set the proxy server used.
void setAgent (const char *str)
 Set the agent.
Method getMethod (void)
 Get url method (and protocol) employed.
void setTimeout (timeout_t to)
 Set socket timeout characteristics for processing URL requests.
void setFollow (bool enable)
 Specify url following.
void setProtocol (Protocol pro)
 Specify http protocol level being used.
void setLocalInterface (const char *intf)
 Specify local interface to use.

Protected Member Functions

Error sendHTTPHeader (const char *url, const char **vars, int bufsize)
int underflow (void)
virtual int aRead (char *buffer, size_t len, timeout_t timer)
virtual int aWrite (char *buffer, size_t len, timeout_t timer)
virtual void httpHeader (const char *header, const char *value)
 Derived method to receive and parse http "headers".
virtual char ** extraHeader (void)
 A virtual to insert additional header info into the request.

Protected Attributes

ost::String m_host
ost::String m_address

Related Functions

(Note that these are not member functions.)

__EXPORT char * urlDecode (char *source, char *dest=NULL)
 Decode an url parameter (ie "\%20" -> " ").
__EXPORT char * urlEncode (const char *source, char *dest, unsigned size)
 Encode an url parameter (ie " " -> "+").
__EXPORT char * b64Decode (char *src, char *dest=NULL)
 Decode a string using base64 coding.
__EXPORT char * b64Encode (const char *source, char *dest, unsigned size)
 Encode a string using base64 coding.
__EXPORT size_t b64Encode (const unsigned char *src, size_t srcsize, char *dst, size_t dstsize)
 Encode a octet stream using base64 coding.
__EXPORT size_t b64Decode (const char *src, unsigned char *dst, size_t dstsize)
 Decode a string using base64 coding.
__EXPORT String b64Encode (const String &src)
 Encode a STL string using base64 coding into a STL string.
__EXPORT String b64Decode (const String &src)
 Decode a STL string using base64 coding into an STL String.
__EXPORT String b64Encode (const unsigned char *src, size_t srcsize)
 Encode a octet stream using base64 coding into a STL string.
__EXPORT size_t b64Decode (const String &src, unsigned char *dst, size_t dstsize)
 Decode a string using base64 coding.

Detailed Description

A URL processing version of TCPStream. C++ url processing stream class.

Author:
David Sugar <dyfet@ostel.com>
Examples:

urlfetch.cpp, and xmlfetch.cpp.


Member Enumeration Documentation

enum URLStream::Authentication
 

Type of authentication.

Enumeration values:
authAnonymous 
authBasic 

enum URLStream::Encoding
 

Encoding used in transfer.

Enumeration values:
encodingBinary 
encodingChunked 

enum URLStream::Error
 

Return error for url fetch.

Enumeration values:
errSuccess 
errUnreachable 
errMissing 
errDenied 
errInvalid 
errForbidden 
errUnauthorized 
errRelocated 
errFailure 
errTimeout 
errInterface 

Reimplemented from Socket.

enum URLStream::Method
 

Type of fetch.

Enumeration values:
methodHttpGet 
methodHttpPut 
methodHttpPost 
methodFtpGet 
methodFtpPut 
methodFileGet 
methodFilePut 

enum URLStream::Protocol
 

http protocol version

Enumeration values:
protocolHttp1_0 
protocolHttp1_1 


Constructor & Destructor Documentation

URLStream::URLStream Family  family = IPV4,
timeout_t  to = 0
 

Construct an instance of URL stream.

Parameters:
to default timeout.


Member Function Documentation

virtual int URLStream::aRead char *  buffer,
size_t  len,
timeout_t  timer
[inline, protected, virtual]
 

virtual int URLStream::aWrite char *  buffer,
size_t  len,
timeout_t  timer
[inline, protected, virtual]
 

void URLStream::close  ) 
 

Close the URL stream for a new connection.

Examples:
xmlfetch.cpp.

virtual char** URLStream::extraHeader void   )  [inline, protected, virtual]
 

A virtual to insert additional header info into the request.

Returns:
array of header attributes to add.

Error URLStream::get int  buffer = 512  ) 
 

Get URL data from a named stream of a known buffer size.

Requesting URL defined in previous calls of setAddress() and setHost() functions.

Returns:
url error code.
Parameters:
buffer size of buffer.

Error URLStream::get const char *  url,
int  buffer = 512
 

Get URL data from a named stream of a known buffer size.

Returns:
url error code.
Parameters:
url name of resource.
buffer size of buffer.

URLStream& URLStream::getline char *  buffer,
size_t  len
 

Line parsing with conversion.

Returns:
URLStream object.
Parameters:
buffer to store.
len maximum buffer size.

Method URLStream::getMethod void   )  [inline]
 

Get url method (and protocol) employed.

Returns:
url method in effect.

Error URLStream::head const char *  url,
int  buffer = 512
 

Used to fetch header information for a resource.

Returns:
url error code.
Parameters:
url name of resource.
buffer size of buffer.

virtual void URLStream::httpHeader const char *  header,
const char *  value
[inline, protected, virtual]
 

Derived method to receive and parse http "headers".

Parameters:
header keyword.
value header keyword value.

Error URLStream::post const char *  url,
const char **  vars,
int  buffer = 512
 

Post URL vars with post method.

Returns:
url error code.
Parameters:
url name of resource.
vars to set.
buffer size of buffer.

Error URLStream::sendHTTPHeader const char *  url,
const char **  vars,
int  bufsize
[protected]
 

void URLStream::setAddress const char *  str  )  [inline]
 

Set the address for the url.

Parameters:
str address in the URL.

void URLStream::setAgent const char *  str  )  [inline]
 

Set the agent.

Parameters:
str agent value.

void URLStream::setAuthentication Authentication  a,
const char *  str = NULL
 

Set authentication type for the url.

Parameters:
a authentication.
str string.

void URLStream::setCookie const char *  str  )  [inline]
 

Set the cookie to pass.

Parameters:
str cookie string.

void URLStream::setFollow bool  enable  )  [inline]
 

Specify url following.

Set to false to disable following of relocation requests.

Parameters:
enable true to enable following.

void URLStream::setHost const char *  str  )  [inline]
 

Set the host for the url.

Parameters:
str host address.

void URLStream::setLocalInterface const char *  intf  )  [inline]
 

Specify local interface to use.

Parameters:
intf Local interface name

void URLStream::setPassword const char *  str  )  [inline]
 

Set password for the url.

Parameters:
str password.

void URLStream::setPragma const char *  str  )  [inline]
 

Set the pragmas.

Parameters:
str pragma setting.

void URLStream::setProtocol Protocol  pro  )  [inline]
 

Specify http protocol level being used.

Parameters:
pro protocol level.

void URLStream::setProxy const char *  host,
tpport_t  port
 

Set the proxy server used.

Parameters:
host proxy host.
port proxy port.

void URLStream::setProxyAuthentication Authentication  a,
const char *  str = NULL
 

Set proxy authentication type for the url.

Parameters:
a authentication.
str string.

void URLStream::setProxyPassword const char *  str  )  [inline]
 

Set proxy password for the url.

Parameters:
str password.

void URLStream::setProxyUser const char *  str  )  [inline]
 

Set proxy user id for the url.

Parameters:
str user id.

void URLStream::setReferer const char *  str  ) 
 

Set the referer url.

Parameters:
str referer string.

void URLStream::setTimeout timeout_t  to  )  [inline]
 

Set socket timeout characteristics for processing URL requests.

Set to 0 for no default timeouts.

Parameters:
to timeout to set.

Reimplemented from TCPStream.

void URLStream::setUser const char *  str  )  [inline]
 

Set user id for the url.

Parameters:
str user id.

Error URLStream::submit const char *  url,
const char **  vars,
int  buffer = 512
 

Submit URL with vars passed as argument array.

This submit assumes "GET" method. Use "post" member to perform post.

Returns:
url error code.
Parameters:
url name of resource.
vars to set.
buffer size of buffer.

int URLStream::underflow void   )  [protected]
 

Reimplemented from TCPStream.


Friends And Related Function Documentation

__EXPORT size_t b64Decode const String src,
unsigned char *  dst,
size_t  dstsize
[related]
 

Decode a string using base64 coding.

Destination size should be at least strlen(src)/4*3. Destination are not string terminated (It's just a octet stream).

Returns:
number of octets written into destination buffer
Parameters:
src source string
dst destination octet buffer
dstsize destination buffer size

__EXPORT String b64Decode const String src  )  [related]
 

Decode a STL string using base64 coding into an STL String.

Destination size should be at least strlen(src)/4*3. Destination are not string terminated (It's just a octet stream).

Returns:
decoded string
Parameters:
src source string

__EXPORT size_t b64Decode const char *  src,
unsigned char *  dst,
size_t  dstsize
[related]
 

Decode a string using base64 coding.

Destination size should be at least strlen(src)/4*3. Destination are not string terminated (It's just a octet stream).

Returns:
number of octets written into destination buffer
Parameters:
src source string
dst destination octet buffer
dstsize destination buffer size

__EXPORT char * b64Decode char *  src,
char *  dest = NULL
[related]
 

Decode a string using base64 coding.

Destination size should be at least strlen(src)+1. Destination will be a string, so is always terminated . This function is deprecated, base64 can use binary source, not only string use overloaded b64Decode.

Returns:
string coded
Parameters:
src source buffer
dest destination buffer. If NULL src is used

__EXPORT String b64Encode const unsigned char *  src,
size_t  srcsize
[related]
 

Encode a octet stream using base64 coding into a STL string.

Returns:
base 64 encoded string
Parameters:
src source buffer
srcsize source buffer size

__EXPORT String b64Encode const String src  )  [related]
 

Encode a STL string using base64 coding into a STL string.

Returns:
base 64 encoded string
Parameters:
src source string

__EXPORT size_t b64Encode const unsigned char *  src,
size_t  srcsize,
char *  dst,
size_t  dstsize
[related]
 

Encode a octet stream using base64 coding.

Destination size should be at least (srcsize+2)/3*4+1. Destination will be a string, so is always terminated (unless you pass dstsize == 0).

Returns:
size of string written not counting terminator
Parameters:
src source buffer
srcsize source buffer size
dst destination buffer
dstsize destination buffer size

__EXPORT char * b64Encode const char *  source,
char *  dest,
unsigned  size
[related]
 

Encode a string using base64 coding.

Destination size should be at least strlen(src)/4*3+1. Destination is string terminated. This function is deprecated, coded stream can contain terminator character use overloaded b64Encode instead.

Returns:
destination buffer
Parameters:
source source string
dest destination octet buffer
size destination buffer size

__EXPORT char * urlDecode char *  source,
char *  dest = NULL
[related]
 

Decode an url parameter (ie "\%20" -> " ").

Parameters:
source string
dest destination buffer. If NULL source is used

__EXPORT char * urlEncode const char *  source,
char *  dest,
unsigned  size
[related]
 

Encode an url parameter (ie " " -> "+").

Parameters:
source string
dest destination buffer. Do not overlap with source
size destination buffer size.


Member Data Documentation

ost::String URLStream::m_address [protected]
 

ost::String URLStream::m_host [protected]
 


The documentation for this class was generated from the following file:
Generated on Tue Jan 18 14:32:39 2005 for GNU CommonC++ by  doxygen 1.3.9.1