nanohttp-stream.h File Reference

Go to the source code of this file.

Classes

struct  http_input_stream_t
struct  http_output_stream_t

Defines

#define STREAM_ERROR   1200
#define STREAM_ERROR_INVALID_TYPE   (STREAM_ERROR + 1)
#define STREAM_ERROR_SOCKET_ERROR   (STREAM_ERROR + 2)
#define STREAM_ERROR_NO_CHUNK_SIZE   (STREAM_ERROR + 3)
#define STREAM_ERROR_WRONG_CHUNK_SIZE   (STREAM_ERROR + 4)

Typedefs

typedef enum http_transfer_type http_transfer_type_t

Enumerations

enum  http_transfer_type { HTTP_TRANSFER_CONTENT_LENGTH, HTTP_TRANSFER_CHUNKED, HTTP_TRANSFER_CONNECTION_CLOSE, HTTP_TRANSFER_FILE }

Functions

http_input_stream_thttp_input_stream_new (struct hsocket_t *sock, hpair_t *header)
http_input_stream_thttp_input_stream_new_from_file (const char *filename)
void http_input_stream_free (struct http_input_stream_t *stream)
int http_input_stream_is_ready (struct http_input_stream_t *stream)
int http_input_stream_read (struct http_input_stream_t *stream, unsigned char *dest, int size)
http_output_stream_thttp_output_stream_new (struct hsocket_t *sock, hpair_t *header)
void http_output_stream_free (struct http_output_stream_t *stream)
herror_t http_output_stream_write (struct http_output_stream_t *stream, const unsigned char *bytes, int size)
herror_t http_output_stream_write_string (struct http_output_stream_t *stream, const char *str)
herror_t http_output_stream_flush (struct http_output_stream_t *stream)


Detailed Description

Stream modul

nanoHTTP supports 2 different streams:
  1. http_input_stream_t
  2. http_output_stream_t

These are not regular streams. They will care about transfer styles while sending/receiving data.

Supported transfer styles are

A stream will set its transfer style from the header information, which must be given while creating a stream.

A stream will start sending/receiving data "after" sending/receiving header information. (After <CF><CF>)"

Definition in file nanohttp-stream.h.


Typedef Documentation

typedef enum http_transfer_type http_transfer_type_t
 

Transfer types supported while sending/receiving data.


Enumeration Type Documentation

enum http_transfer_type
 

Transfer types supported while sending/receiving data.

Enumerator:
HTTP_TRANSFER_CONTENT_LENGTH  The stream cares about Content-length
HTTP_TRANSFER_CHUNKED  The stream sends/receives chunked data
HTTP_TRANSFER_CONNECTION_CLOSE  The stream sends/receives data until connection is closed
HTTP_TRANSFER_FILE  This transfer style will be used by MIME support and for debug purposes.

Definition at line 76 of file nanohttp-stream.h.


Function Documentation

void http_input_stream_free struct http_input_stream_t stream  ) 
 

Free input stream. Note that the socket will not be closed by this functions.

Parameters:
stream the input stream to free.

Definition at line 162 of file nanohttp-stream.c.

References http_input_stream_t::deleteOnExit, http_input_stream_t::fd, http_input_stream_t::filename, HTTP_TRANSFER_FILE, log_info2, and http_input_stream_t::type.

Referenced by hrequest_free(), hresponse_free(), and hresponse_new_from_socket().

int http_input_stream_is_ready struct http_input_stream_t stream  ) 
 

Returns the actual status of the stream.

Definition at line 422 of file nanohttp-stream.c.

References http_input_stream_t::err, H_OK, HTTP_TRANSFER_CHUNKED, HTTP_TRANSFER_CONNECTION_CLOSE, HTTP_TRANSFER_CONTENT_LENGTH, HTTP_TRANSFER_FILE, and http_input_stream_t::type.

Referenced by mime_streamreader_function().

struct http_input_stream_t* http_input_stream_new struct hsocket_t sock,
hpair_t header
 

Creates a new input stream.

Definition at line 84 of file nanohttp-stream.c.

References http_input_stream_t::chunk_size, http_input_stream_t::connection_closed, http_input_stream_t::content_length, http_input_stream_t::err, H_OK, HEADER_CONTENT_LENGTH, hpairnode_dump_deep(), hpairnode_get_ignore_case(), HTTP_TRANSFER_CHUNKED, HTTP_TRANSFER_CONNECTION_CLOSE, HTTP_TRANSFER_CONTENT_LENGTH, log_error2, log_verbose1, http_input_stream_t::received, http_input_stream_t::sock, and http_input_stream_t::type.

Referenced by hresponse_new_from_socket().

struct http_input_stream_t* http_input_stream_new_from_file const char *  filename  ) 
 

Creates a new input stream from file. This function was added for MIME messages and for debugging.

Definition at line 134 of file nanohttp-stream.c.

References http_input_stream_t::deleteOnExit, http_input_stream_t::fd, http_input_stream_t::filename, HTTP_TRANSFER_FILE, log_error2, and http_input_stream_t::type.

Referenced by hresponse_new_from_socket().

int http_input_stream_read struct http_input_stream_t stream,
unsigned char *  dest,
int  size
 

Returns the actual read bytes <0 on error

Definition at line 452 of file nanohttp-stream.c.

References http_input_stream_t::err, H_OK, herror_new(), HTTP_TRANSFER_CHUNKED, HTTP_TRANSFER_CONNECTION_CLOSE, HTTP_TRANSFER_CONTENT_LENGTH, HTTP_TRANSFER_FILE, STREAM_ERROR_INVALID_TYPE, and http_input_stream_t::type.

Referenced by httpd_get_postdata(), and mime_streamreader_function().

herror_t http_output_stream_flush struct http_output_stream_t stream  ) 
 

Sends finish flags if nesseccary (like in chunked transport). Call always this function before closing the connections.

Parameters:
stream the stream to send post data.
Returns:
H_OK on success. One of the followings otherwise
  • HSOCKET_ERROR_NOT_INITIALIZED
  • HSOCKET_ERROR_SEND

Definition at line 605 of file nanohttp-stream.c.

References H_OK, hsocket_send_string(), HTTP_TRANSFER_CHUNKED, http_output_stream_t::sock, and http_output_stream_t::type.

Referenced by httpc_mime_end(), httpc_post_end(), and httpd_mime_end().

void http_output_stream_free struct http_output_stream_t stream  ) 
 

Free output stream

Definition at line 552 of file nanohttp-stream.c.

Referenced by httpc_free(), and httpd_free().

struct http_output_stream_t* http_output_stream_new struct hsocket_t sock,
hpair_t header
 

Creates a new output stream. Transfer code will be found from header.

Definition at line 503 of file nanohttp-stream.c.

References http_output_stream_t::content_length, HEADER_CONTENT_LENGTH, hpairnode_get_ignore_case(), HTTP_TRANSFER_CHUNKED, HTTP_TRANSFER_CONNECTION_CLOSE, HTTP_TRANSFER_CONTENT_LENGTH, log_error2, log_verbose1, http_output_stream_t::sent, http_output_stream_t::sock, and http_output_stream_t::type.

Referenced by httpc_post_begin(), and httpd_send_header().

herror_t http_output_stream_write struct http_output_stream_t stream,
const unsigned char *  bytes,
int  size
 

Writes 'size' bytes of 'bytes' into stream. Returns socket error flags or H_OK.

Definition at line 564 of file nanohttp-stream.c.

References H_OK, hsocket_send(), hsocket_send_string(), HTTP_TRANSFER_CHUNKED, http_output_stream_t::sock, and http_output_stream_t::type.

Referenced by http_output_stream_write_string(), httpc_mime_end(), httpc_mime_next(), httpc_mime_send_file(), httpd_mime_end(), httpd_mime_next(), and httpd_mime_send_file().

herror_t http_output_stream_write_string struct http_output_stream_t stream,
const char *  str
 

Writes 'strlen()' bytes of 'str' into stream. Returns socket error flags or H_OK.

Definition at line 597 of file nanohttp-stream.c.

References http_output_stream_write().


Generated on Thu Jan 25 23:36:04 2007 for csoap by  doxygen 1.4.6