webradio/utils.c File Reference


Detailed Description

Utility routines.

 *
 * $Log$
 *
 * 

Definition in file utils.c.

Go to the source code of this file.

Defines

#define MAX_HEADERLINE_SIZE   255

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 TcpGetTag (TCPSOCKET *sock, char *tag, int size)
char * LocateAttributeString (CONST char *tag, CONST char *name)
int TcpGetLine (TCPSOCKET *sock, char *line, u_short size)
 Get line from TCP socket connection.
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.
void HttpSchemeRelease (HTTP_SCHEME *schm)
HTTP_SCHEMEHttpSchemeParse (CONST char *uri)
void Led0 (int on)
 Switch LED0 on or off.
char * strdup (CONST char *str)
 Create a copy of a string.


Define Documentation

#define MAX_HEADERLINE_SIZE   255

Definition at line 62 of file utils.c.

Referenced by TcpGetHeaderLines().


Function Documentation

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

Connect TCP host.

Definition at line 68 of file utils.c.

Referenced by OpenTcpStream(), ShoutCastGetPlayList(), and StationConnect().

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

Definition at line 92 of file utils.c.

Referenced by Service(), XmlCmdService(), and XmlRepoService().

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.

Referenced by ProcessMetaData().

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 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.

Referenced by ShoutCastGetPlayList(), and TcpGetHeaderLines().

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.

Referenced by ShoutCastGetPlayList(), and StationConnect().

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.

Referenced by StationConnect().

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.

Referenced by StationDisconnect().

void HttpSchemeRelease ( HTTP_SCHEME schm  ) 

Definition at line 442 of file utils.c.

Referenced by HttpSchemeParse(), ShoutCastAddStation(), ShoutCastGetGenreList(), ShoutCastGetPlayList(), ShoutCastGetStationList(), and StationConnect().

HTTP_SCHEME* HttpSchemeParse ( CONST char *  uri  ) 

Definition at line 453 of file utils.c.

Referenced by ShoutCastAddStation(), ShoutCastGetGenreList(), ShoutCastGetPlayList(), ShoutCastGetStationList(), and StationConnect().

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.

char* strdup ( CONST char *  str  ) 

Create a copy of a string.

Allocates sufficient memory from heap for a copy of the string does the copy.

Missing Nut/OS function.

Parameters:
str Pointer to the string to copy.
Returns:
A pointer to the new string or NULL if allocating memory failed.

Definition at line 541 of file utils.c.

Referenced by FavListCopy(), FavListLoad(), FavListSet(), HttpSchemeParse(), and ProcessMetaData().


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