Nut/OS  5.0.5
API Reference
Stream I/O
Collaboration diagram for Stream I/O:

Typedefs

typedef struct _HTTP_STREAM HTTP_STREAM
typedef void(* HTTP_CLIENT_HANDLER )(HTTP_STREAM *)

Functions

int StreamInit (void)
 Initialize the stream.
int StreamClientAccept (HTTP_CLIENT_HANDLER handler, const char *params)
 Accept stream clients.
int StreamReadUntilChars (HTTP_STREAM *sp, const char *delim, const char *ignore, char *buf, int siz)
 Read data from a stream until any of the specified characters appears.
int StreamReadUntilString (HTTP_STREAM *sp, const char *delim, char *buf, int siz)
 Read data from a stream until a specified string appears.
int s_write (const void *buf, size_t size, size_t count, HTTP_STREAM *sp)
 Write data items to a stream.
int s_puts (const char *str, HTTP_STREAM *sp)
 Write a string to a stream.
int s_vputs (HTTP_STREAM *sp,...)
 Write a variable number of strings to a stream.
int s_printf (HTTP_STREAM *sp, const char *fmt,...)
 Print formatted data to a stream.
int s_flush (HTTP_STREAM *sp)
 Flush a stream.
const char * StreamInfo (HTTP_STREAM *hs, int item)

Default environment variables

#define SITEM_REMOTE_ADDR   1
 The IP address of the host making this request.
#define SITEM_REMOTE_PORT   2
 The port number used by the remote host when making this request.
#define SITEM_SERVER_ADDR   3
 The IP address of the server for this URL.
#define SITEM_SERVER_NAME   4
 The servers host name, DNS alias or IP address.
#define SITEM_SERVER_PORT   5
 The port number on this server to which this request was directed.

Define Documentation

#define SITEM_REMOTE_ADDR   1

The IP address of the host making this request.

Referenced by ISC_LIST(), and StreamInfo().

#define SITEM_REMOTE_PORT   2

The port number used by the remote host when making this request.

Referenced by ISC_LIST(), and StreamInfo().

#define SITEM_SERVER_ADDR   3

The IP address of the server for this URL.

Referenced by ISC_LIST(), and StreamInfo().

#define SITEM_SERVER_NAME   4

The servers host name, DNS alias or IP address.

Referenced by ISC_LIST(), and StreamInfo().

#define SITEM_SERVER_PORT   5

The port number on this server to which this request was directed.

Referenced by ISC_LIST(), and StreamInfo().


Typedef Documentation

typedef struct _HTTP_STREAM HTTP_STREAM
typedef void(* HTTP_CLIENT_HANDLER)(HTTP_STREAM *)

Function Documentation

int StreamInit ( void  )

Initialize the stream.

This function must be called before before calling StreamClientAccept() and will initialize the platform dependent stream processing.

Returns:
0 on success or -1 on error.

$Id$

References printf.

int StreamClientAccept ( HTTP_CLIENT_HANDLER  handler,
const char *  params 
)

Accept stream clients.

If no error occurs, this function will never return.

Parameters:
handlerClient handler to be called when a client successfully connected.
paramsStream specific parameters. For TCP/IP connections this is currently used to specify the port number. If NULL, then the server will listen at default port 80.
Returns:
-1 on error.

References AF_INET, atoi(), calloc, _CLIENT_THREAD_PARAM::ctp_handler, _CLIENT_THREAD_PARAM::ctp_stream, free(), htonl, htons, HTTP_ASSERT, INADDR_ANY, IPPROTO_TCP, malloc(), memcpy(), memset(), NULL, NutTcpAccept(), NutTcpCloseSocket(), NutTcpCreateSocket(), NutTcpSetSockOpt(), rc, SO_RCVBUF, SO_RCVTIMEO, SOCK_STREAM, StreamClientThread(), _HTTP_STREAM::strm_caddr, _HTTP_STREAM::strm_csock, _HTTP_STREAM::strm_saddr, _HTTP_STREAM::strm_sock, _HTTP_STREAM::strm_ssock, and TCP_MAXSEG.

Here is the call graph for this function:

int StreamReadUntilChars ( HTTP_STREAM sp,
const char *  delim,
const char *  ignore,
char *  buf,
int  siz 
)

Read data from a stream until any of the specified characters appears.

Parameters:
spPointer to the stream's information structure.
delimThe function will return as soon as any of the characters in this string is read.
ignoreString of all characters that will be skipped.
bufPointer to the buffer that will receive the data read from the stream. Characters to ignore are not stored. The delimiter will be replaced by a string terminator (ASCII 0).
sizSize of the buffer, given in bytes.
Returns:
The number of bytes consumed from the stream, including any skipped characters and the delimiter. A return value of -1 indicates an error.

References HTTP_ASSERT, NULL, NutTcpReceive(), rc, strchr(), _HTTP_STREAM::strm_csock, _HTTP_STREAM::strm_ibuf, _HTTP_STREAM::strm_ilen, _HTTP_STREAM::strm_ipos, and _HTTP_STREAM::strm_sock.

Referenced by HttpArgReadNext(), HttpParseHeader(), and HttpParseMultipartHeader().

Here is the call graph for this function:

int StreamReadUntilString ( HTTP_STREAM sp,
const char *  delim,
char *  buf,
int  siz 
)

Read data from a stream until a specified string appears.

Parameters:
spPointer to the stream's information structure.
delimThe function will return as soon as this string appears.
ignoreString of all characters that will be skipped.
bufPointer to the buffer that will receive the data read from the stream. Characters to ignore are not stored. The searched string will be replaced by a string terminator (ASCII 0).
sizSize of the buffer, given in bytes.
Returns:
The number of bytes consumed from the stream, including any skipped characters and the delimiter. A return value of -1 indicates an error.

References HTTP_ASSERT, memcmp(), memcpy(), NULL, NutTcpReceive(), rc, strlen(), _HTTP_STREAM::strm_csock, _HTTP_STREAM::strm_ibuf, _HTTP_STREAM::strm_ilen, _HTTP_STREAM::strm_ipos, and _HTTP_STREAM::strm_sock.

Here is the call graph for this function:

int s_write ( const void *  buf,
size_t  size,
size_t  count,
HTTP_STREAM sp 
)

Write data items to a stream.

This function is similar to the standard function fwrite().

Parameters:
bufPointer to items to be written.
sizeItem size in bytes.
countNumber of items to write.
spPointer to the stream's information structure.
Returns:
The number of items written, which may be less than the specified number.

References HTTP_ASSERT, NULL, NutTcpDeviceWrite(), _HTTP_STREAM::strm_csock, and _HTTP_STREAM::strm_sock.

Referenced by HttpSsiProcessFile(), and MediaTypeHandlerBinary().

Here is the call graph for this function:

int s_puts ( const char *  str,
HTTP_STREAM sp 
)

Write a string to a stream.

This function is similar to the standard function fputs().

Parameters:
spPointer to the stream's information structure.
strString to write.
Returns:
A non-negative value if successful or EOF to indicate an error.

References HTTP_ASSERT, NULL, NutTcpDeviceWrite(), strlen(), _HTTP_STREAM::strm_csock, and _HTTP_STREAM::strm_sock.

Referenced by HttpSendHeaderBottom(), HttpSsiEchoHandler(), and HttpSsiHandler().

Here is the call graph for this function:

int s_vputs ( HTTP_STREAM sp,
  ... 
)

Write a variable number of strings to a stream.

Parameters:
spPointer to the stream's information structure.
Returns:
A non-negative value if successful or EOF to indicate an error.

References free(), HTTP_ASSERT, malloc(), NULL, NutTcpDeviceWrite(), rc, strcat(), strlen(), _HTTP_STREAM::strm_csock, and _HTTP_STREAM::strm_sock.

Referenced by HttpSendHeaderBottom(), HttpSendHeaderDate(), HttpSendHeaderTop(), HttpSendRedirection(), and HttpSsiHandler().

Here is the call graph for this function:

int s_printf ( HTTP_STREAM sp,
const char *  fmt,
  ... 
)

Print formatted data to a stream.

This function is similar to the standard function fprintf().

Parameters:
spPointer to the stream's information structure.
fmtFormat string containing conversion specifications.
Returns:
The number of characters written or a negative value to indicate an error.

References free(), HTTP_ASSERT, malloc(), NULL, NutTcpDeviceWrite(), rc, _HTTP_STREAM::strm_csock, _HTTP_STREAM::strm_sock, and vsprintf().

Referenced by HttpSendError(), HttpSendHeaderBottom(), HttpSendHeaderTop(), and HttpSendRedirection().

Here is the call graph for this function:

int s_flush ( HTTP_STREAM sp)

Flush a stream.

This function is similar to the standard function fflush().

The calling thread may be suspended until all buffered output data has been written.

Parameters:
spPointer to the stream's information structure.
Returns:
0 if the buffer was successfully flushed, EOF if an error occured.

References NULL, NutTcpDeviceWrite(), and _HTTP_STREAM::strm_sock.

Referenced by HttpSendError(), HttpSendRedirection(), HttpSsiProcessFile(), and MediaTypeHandlerBinary().

Here is the call graph for this function:

const char* StreamInfo ( HTTP_STREAM hs,
int  item 
)

References free(), inet_ntoa(), malloc(), NULL, SITEM_REMOTE_ADDR, SITEM_REMOTE_PORT, SITEM_SERVER_ADDR, SITEM_SERVER_NAME, SITEM_SERVER_PORT, sprintf, strdup(), _HTTP_STREAM::strm_caddr, and _HTTP_STREAM::strm_saddr.

Referenced by HttpStreamInfo().

Here is the call graph for this function: