webradio/utils.h File Reference


Detailed Description

Useful utility routines.

 *
 * $Log$
 *
 * 

Definition in file utils.h.

Go to the source code of this file.

Data Structures

struct  HTTP_SCHEME

Functions

int TcpHostConnect (TCPSOCKET *sock, CONST char *rhost, u_short port)
 Connect TCP host.
FILE * TcpStreamAccept (TCPSOCKET *sock, u_short port, char *mode)
int TcpGetBuffer (TCPSOCKET *sock, char *buff, u_int size, u_int *status)
 Get a specified number of characters from TCP socket connection.
int TcpGetLine (TCPSOCKET *sock, char *line, u_short size)
 Get line from TCP socket connection.
int TcpGetTag (TCPSOCKET *sock, char *tag, int size)
char * LocateAttributeString (CONST char *tag, CONST char *name)
int TcpPutString (TCPSOCKET *sock, char *str)
 Send complete string via TCP.
int TcpGetHeaderLines (TCPSOCKET *sock, char ***array)
 Get header line array from TCP socket connection.
void TcpReleaseHeaderLines (char **array)
 Release previously allocated memory for the header lines.
HTTP_SCHEMEHttpSchemeParse (CONST char *uri)
void HttpSchemeRelease (HTTP_SCHEME *schm)
void Led0 (int on)
 Switch LED0 on or off.


Function Documentation

int TcpHostConnect ( TCPSOCKET *  sock,
CONST char *  rhost,
u_short  port 
)

Connect TCP host.

Definition at line 68 of file utils.c.

References LOG_WARN, LogMsg(), proxy, HTTP_PROXY::proxy_host, and HTTP_PROXY::proxy_port.

Here is the call graph for this function:

LogMsg

FILE* TcpStreamAccept ( TCPSOCKET *  sock,
u_short  port,
char *  mode 
)

Definition at line 92 of file utils.c.

References LOG_WARN, and LogMsg().

Here is the call graph for this function:

LogMsg

int TcpGetBuffer ( TCPSOCKET *  sock,
char *  buff,
u_int  size,
u_int *  status 
)

Get a specified number of characters from TCP socket connection.

The low level NutTcpReceive() routine may return less than the number of bytes specified. This routine makes sure, that the complete buffer is filled. However, an additional pointer to a status is passed to this routine. If the status changes, the routine will be aborted.

Any TCP receive timeout is ignored, but required in order to detect status changes.

Parameters:
sock Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket(). In addition a connection must have been established by calling NutTcpConnect() or NutTcpAccept().
buff Pointer to the buffer.
size Size of the buffer.
status Pointer to a status.
Returns:
0 if the buffer is filled. Otherwise -1 is returned.

Definition at line 143 of file utils.c.

int TcpGetLine ( TCPSOCKET *  sock,
char *  line,
u_short  size 
)

Get line from TCP socket connection.

ASCII codes below 32 or above 127 are discarded.

Parameters:
sock Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket(). In addition a connection must have been established by calling NutTcpConnect() or NutTcpAccept().
line Pointer to the buffer that receives the string.
size Size of the buffer. If the received line doesn't fit, then remaining characters will be discarded.
Returns:
Number of characters stored in the line buffer or -1 in case of an error or timeout.

Definition at line 261 of file utils.c.

int TcpGetTag ( TCPSOCKET *  sock,
char *  tag,
int  size 
)

Definition at line 159 of file utils.c.

char* LocateAttributeString ( CONST char *  tag,
CONST char *  name 
)

Definition at line 209 of file utils.c.

int TcpPutString ( TCPSOCKET *  sock,
char *  str 
)

Send complete string via TCP.

The low level NutTcpSend() routine limits the number of bytes to the maximum segment size of the connection. This routine makes sure, that the complete string is transmitted.

Parameters:
sock Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket(). In addition a connection must have been established by calling NutTcpConnect() or NutTcpAccept().
str Pointer to a buffer containing the string to send.
Returns:
0 on success. Otherwise -1 is returned.

Definition at line 301 of file utils.c.

int TcpGetHeaderLines ( TCPSOCKET *  sock,
char ***  array 
)

Get header line array from TCP socket connection.

Receives lines from a TCP stream until the first empty line appears and stores all lines in an array of strings. The empty line is not stored, but the last pointer of the array is set to NULL.

The routine allocates the array and all string. The caller should use TcpReleaseHeaderLines() to release all allocated memory.

Parameters:
sock Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket(). In addition a connection must have been established by calling NutTcpConnect() or NutTcpAccept().
array Pointer to a string array pointer, which receives the address of the newly allocated string array. If no non-empty lines were received or if an error occured, then the string array pointer will be set to NULL.
Returns:
The number of header lines stored. In case of an error, the function result is -1 instead.

Definition at line 338 of file utils.c.

References MAX_HEADERLINE_SIZE, and TcpGetLine().

Here is the call graph for this function:

TcpGetLine

void TcpReleaseHeaderLines ( char **  array  ) 

Release previously allocated memory for the header lines.

Should be called to release all memory allocated by TcpGetHeaderLines().

Parameters:
array String array to be released.

Definition at line 428 of file utils.c.

HTTP_SCHEME* HttpSchemeParse ( CONST char *  uri  ) 

Definition at line 453 of file utils.c.

References HttpSchemeRelease(), HTTP_SCHEME::schm_host, HTTP_SCHEME::schm_pass, HTTP_SCHEME::schm_path, HTTP_SCHEME::schm_port, HTTP_SCHEME::schm_portnum, HTTP_SCHEME::schm_uri, HTTP_SCHEME::schm_user, and strdup().

Here is the call graph for this function:

HttpSchemeReleasestrdup

void HttpSchemeRelease ( HTTP_SCHEME schm  ) 

Definition at line 442 of file utils.c.

References HTTP_SCHEME::schm_uri.

void Led0 ( int  on  ) 

Switch LED0 on or off.

On the SAM7X-EK the LED labeled DS4 is used.

On the SAM9260-EK we use the only one user LED.

Parameters:
on If 0, then the LED will be switched off. Otherwise it will be lit.

Definition at line 506 of file utils.c.


© 2008 by egnite GmbH - visit www.ethernut.de