tcp_utils.c File Reference


Detailed Description

HTTP embedded server library Copyright (C) 2006-2007 Olivier Singla http://mihl.sourceforge.net/.

Definition in file tcp_utils.c.

Include dependency graph for tcp_utils.c:

Go to the source code of this file.

Defines

#define _GNU_SOURCE

Functions

int tcp_read (SOCKET sockfd, char *buffer, int maxlen)
 TBD.
int tcp_write (SOCKET sockfd, const char *buff, int buff_len)
 TBD.
void decode_keys_values (mihl_cnx_t *cnx, char *_request, int *nb_options, char *options_names[], char *options_values[], int maxnb_options, int *nb_variables, char *vars_names[], char *vars_values[], int maxnb_values)
 TBD.
int mihl_add (mihl_cnx_t *cnx, char const *fmt,...)
 Build HTML page for a given HTTP URL.
int mihl_send (mihl_cnx_t *cnx, char const *answer, char const *fmt_header,...)
 TBD.
static int filelength (int fd)
 TBD.
int read_file (char const *fname, char **file, int *length)
 Read en entire file in memory.


Define Documentation

#define _GNU_SOURCE

Definition at line 11 of file tcp_utils.c.


Function Documentation

int tcp_read ( SOCKET  sockfd,
char *  buffer,
int  maxlen 
)

TBD.

Parameters:
sockfd TBD
buffer TBD
maxlen TBD
Returns:
  • X
  • or -1 if an error occurred (errno is then set).

Definition at line 47 of file tcp_utils.c.

References ERRNO, and Sleep.

Referenced by got_data_for_active_connexion().

Here is the caller graph for this function:

int tcp_write ( SOCKET  sockfd,
const char *  buff,
int  buff_len 
)

TBD.

Parameters:
sockfd TBD
buff TBD
buff_len TBD
Returns:
  • X
  • or -1 if an error occurred (errno is then set).

Definition at line 104 of file tcp_utils.c.

References ERRNO, and Sleep.

Referenced by mihl_send(), and send_file().

Here is the caller graph for this function:

void decode_keys_values ( mihl_cnx_t cnx,
char *  _request,
int *  nb_options,
char *  options_names[],
char *  options_values[],
int  maxnb_options,
int *  nb_variables,
char *  vars_names[],
char *  vars_values[],
int  maxnb_values 
)

TBD.

Called by: got_data_for_active_connexion

Parameters:
cnx opaque context structure as returned by mihl_init()
_request TBD
[out] nb_options TBD
[out] options_names TBD
[out] options_values TBD
maxnb_options TBD
[out] nb_variables TBD
[out] vars_names TBD
[out] vars_values TBD
maxnb_values TBD

Definition at line 156 of file tcp_utils.c.

References mihl_cnx::authorization, mihl_cnxinfo_t::host, mihl_cnx::info, mihl_cnx::is_keep_alive, mihl_cnx::keep_alive, and mihl_cnxinfo_t::user_agent.

Referenced by got_data_for_active_connexion().

Here is the caller graph for this function:

int mihl_add ( mihl_cnx_t cnx,
char const *  fmt,
  ... 
)

Build HTML page for a given HTTP URL.

Used within a C handler function (such as one provide to mihl_handle_get or mihl_handle_post), to build a page content. Once the page will is finished, a call to mihl_add should be done.

Parameters:
cnx Opaque pointer, as provided to the C handler function (GET).
fmt printf like format and optional arguments to describe the data to add into the page (typically HTML content).
... Optional printf like format arguments
Returns:
  • 0 if the operation succeeded
  • or -1 if an error occurred (errno is then set).
Note:
mihl_add and mihl_send use a dynamic buffer, which is allocated when needed, but only released with mihl_end().

Definition at line 261 of file tcp_utils.c.

References mihl_cnx::html_buffer, mihl_cnx::html_buffer_len, and mihl_cnx::html_buffer_sz.

Referenced by http_data(), http_root(), and page_not_found().

Here is the caller graph for this function:

int mihl_send ( mihl_cnx_t cnx,
char const *  answer,
char const *  fmt_header,
  ... 
)

TBD.

Parameters:
cnx opaque context structure as returned by mihl_init()
[in] answer HTTP answer to send, If NULL, will send "HTTP/1.1 200 OK\r\n"
fmt_header TBD
... TBD
Returns:
  • X
  • or -1 if an error occurred (errno is then set).

Definition at line 289 of file tcp_utils.c.

References ERRNO, mihl_cnx::html_buffer, mihl_cnx::html_buffer_len, mihl_cnx::sockfd, and tcp_write().

Referenced by http_data(), http_root(), and page_not_found().

Here is the call graph for this function:

Here is the caller graph for this function:

static int filelength ( int  fd  )  [static]

TBD.

Parameters:
fd TBD
Returns:
  • X
  • or -1 if an error occurred (errno is then set).

Definition at line 333 of file tcp_utils.c.

Referenced by read_file().

Here is the caller graph for this function:

int read_file ( char const *  fname,
char **  file,
int *  length 
)

Read en entire file in memory.

The buffer is dynamically allocated (malloc).

Parameters:
fname TBD
file TBD
length TBD
Returns:
  • The length of the file
  • or -1 if an error occurred (errno is then set).

Definition at line 350 of file tcp_utils.c.

References filelength(), and O_BINARY.

Referenced by send_file().

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Mon May 26 18:06:29 2008 for milh-example_3 by  doxygen 1.5.6