Forms support, Predefined handlers – Comtrol eCos User Manual

Page 637

Advertising
background image

Chapter 48. Embedded HTTP Server

Forms Support

#define html_form_begin( __client, __url, __attr )

#define html_form_end( __client )

#define html_form_input( __client, __type, __name, __value, __attr )

#define html_form_input_radio( __client, __name, __value, __checked )

#define html_form_input_checkbox( __client, __name, __value, __checked )

#define html_form_input_hidden( __client, __name, __value )

#define html_form_select_begin( __client, __name, __attr )

#define html_form_option( __client, __value, __label, __selected )

#define html_form_select_end( __client )

void cyg_formdata_parse( char *data, char *list[], int size );

char *cyg_formlist_find( char *list[], char *name );

html_form_begin()

begins a form, the

__url

argument is the value for the

action

attribute.

html_form_end()

ends the form.

html_form_input()

defines a general form input element with the given type, name and value.

html_form_input_radio

creates a radio button with the given name and value; the

__checked

argument

is a boolean expression that is used to determine whether the

checked

attribute is added to the tag. Similarly

html_form_input_checkbox()

defines a checkbox element.

html_form_input_hidden()

defines a hidden

form element with the given name and value.

html_form_select_begin()

begins a multiple choice menu with the given name.

html_form_select_end()

end it.

html_form_option()

defines a menu entry with the given value and label; the

__selected

argument is

a boolean expression controlling whether the

selected

attribute is added to the tag.

cyg_formdata_parse()

converts a form response string into an

NULL

-terminated array of "name=value" entries.

The

data

argument is the string as passed to the handler function; note that this string is not copied and will be

updated in place to form the list entries.

list

is a pointer to an array of character pointers, and is

size

elements

long.

cyg_formlist_find()

searches a list generated by

cyg_formdata_parse()

and returns a pointer to the

value part of the string whose name part matches

name

; if there is no match it will return

NULL

.

Predefined Handlers

int cyg_httpd_send_html( FILE *client, char *filename, char *request, void *arg );

typedef struct

{

char

*content_type;

cyg_uint32

content_length;

cyg_uint8

*data;

} cyg_httpd_data;

#define CYG_HTTPD_DATA( __name, __type, __length, __data )

int cyg_httpd_send_data( FILE *client, char *filename, char *request, void *arg );

The HTTP server defines a couple of predefined handers to make it easier to deliver simple, static content.

cyg_httpd_send_html()

takes a

NULL

-terminated string as the argument and sends it to the client with an HTTP

header indicating that it is HTML. The following is an example of its use:

533

Advertising