1 <!-- Copyright (C) 2003 Red Hat, Inc. -->
2 <!-- This material may be distributed only subject to the terms -->
3 <!-- and conditions set forth in the Open Publication License, v1.0 -->
4 <!-- or later (the latest version is presently available at -->
5 <!-- http://www.opencontent.org/openpub/). -->
6 <!-- Distribution of the work or derivative of the work in any -->
7 <!-- standard (paper) book form is prohibited unless prior -->
8 <!-- permission is obtained from the copyright holder. -->
12 >Support Functions and Macros</TITLE
13 ><meta name="MSSmartTagsPreventParsing" content="TRUE">
16 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
19 TITLE="eCos Reference Manual"
20 HREF="ecos-ref.html"><LINK
22 TITLE="Embedded HTTP Server"
23 HREF="net-httpd-chapter.html"><LINK
25 TITLE="Server Configuration"
26 HREF="net-httpd-configuration.html"><LINK
28 TITLE="System Monitor"
29 HREF="net-httpd-monitor.html"></HEAD
40 SUMMARY="Header navigation table"
49 >eCos Reference Manual</TH
57 HREF="net-httpd-configuration.html"
65 >Chapter 48. Embedded HTTP Server</TD
71 HREF="net-httpd-monitor.html"
85 NAME="NET-HTTPD-HTML">Support Functions and Macros</H1
87 >The emphasis of this server is on dynamically generated content,
88 rather than fetching it from a filesystem. To do this the handler
89 functions make calls to <TT
96 >. Such handler functions would end up a
97 mass of print calls, with the actual structure of the HTML page hidden
98 in the format strings and arguments, making maintenance and debugging
99 very difficult. Such an approach would also result in the definition
100 of many, often only slightly different, format strings, leading to
101 unnecessary bloat.</P
103 >In an effort to expose the structure of the HTML in the structure of
104 the C code, and to maximize the sharing of string constants, the
107 >cyg/httpd/httpd.h</TT
108 > header file defines a set of
109 helper functions and macros. Most of these are wrappers for predefined
110 print calls on the <TT
115 > stream passed to the
116 hander function. For examples of their use, see the System Monitor
125 >All arguments to macros are pointers to strings, unless otherwise
126 stated. In general, wherever a function or macro has an
138 parameter, then the contents of this string will be inserted into the
139 tag being defined as HTML attributes. If it is a NULL or empty string
140 it will be ignored.</P
148 NAME="AEN15305">HTTP Support</H2
156 CLASS="PROGRAMLISTING"
157 >void cyg_http_start( FILE *client, char *content_type, int content_length );
158 void cyg_http_finish( FILE *client );
159 #define html_begin(__client)
160 #define html_end( __client )</PRE
167 >cyg_http_start()</TT
169 HTTP response header containing the value of
172 >CYGDAT_HTTPD_SERVER_ID</TT
173 > in the "Server" field, and the
185 > in the "Content-type"
186 and "Content-length" field respectively. The function
189 >cyg_http_finish()</TT
190 > just adds an extra newline to
191 the end of the output and then flushes it to force the data out to the
197 > generates an HTTP header
198 with a "text/html" content type followed by an opening
199 "<html>" tag. <TT
203 a closing "</html>" tag and calls
206 >cyg_http_finish()</TT
214 NAME="AEN15318">General HTML Support</H2
222 CLASS="PROGRAMLISTING"
223 >void cyg_html_tag_begin( FILE *client, char *tag, char *attr );
224 void cyg_html_tag_end( FILE *client, char *tag );
225 #define html_tag_begin( __client, __tag, __attr )
226 #define html_tag_end( __client, __tag )
227 #define html_head( __client, __title, __meta )
228 #define html_body_begin( __client, __attr )
229 #define html_body_end( __client )
230 #define html_heading( __client, __level, __heading )
231 #define html_para_begin( __client, __attr )
232 #define html_url( __client, __text, __link )
233 #define html_image( __client, __source, __alt, __attr )</PRE
240 >cyg_html_tag_begin()</TT
242 opening tag with the given name. The function
245 >cyg_html_tag_end()</TT
246 > generates a closing tag with
247 the given name. The macros <TT
249 >html_tag_begin()</TT
254 > are just wrappers for these functions.</P
259 > generates an HTML header
271 > argument defines any meta tags that will
272 be inserted into the header. <TT
274 >html_body_begin()</TT
279 > generate HTML body begin and end
285 > generates a complete HTML header
291 > is a numerical level, between 1
300 >html_para_begin()</TT
301 > generates a paragraph
307 > inserts a URL where
313 > is the displayed text and
319 > is the URL of the linked
323 > inserts an image tag where
329 > is the URL of the image to be
335 > is the alternative text for
336 when the image is not displayed.</P
343 NAME="AEN15344">Table Support</H2
351 CLASS="PROGRAMLISTING"
352 >#define html_table_begin( __client, __attr )
353 #define html_table_end( __client )
354 #define html_table_header( __client, __content, __attr )
355 #define html_table_row_begin( __client, __attr )
356 #define html_table_row_end( __client )
357 #define html_table_data_begin( __client, __attr )
358 #define html_table_data_end( __client ) </PRE
365 >html_table_begin()</TT
369 >html_table_end()</TT
373 >html_table_header()</TT
374 > generates a simple table
375 column header containg the string <TT
384 >html_table_row_begin()</TT
388 >html_table_row_end()</TT
389 > begin and end a table row,
392 >html_table_data_begin()</TT
396 >html_table_data_end()</TT
397 > begin and end a table
405 NAME="AEN15357">Forms Support</H2
413 CLASS="PROGRAMLISTING"
414 >#define html_form_begin( __client, __url, __attr )
415 #define html_form_end( __client )
416 #define html_form_input( __client, __type, __name, __value, __attr )
417 #define html_form_input_radio( __client, __name, __value, __checked )
418 #define html_form_input_checkbox( __client, __name, __value, __checked )
419 #define html_form_input_hidden( __client, __name, __value )
420 #define html_form_select_begin( __client, __name, __attr )
421 #define html_form_option( __client, __value, __label, __selected )
422 #define html_form_select_end( __client )
423 void cyg_formdata_parse( char *data, char *list[], int size );
424 char *cyg_formlist_find( char *list[], char *name );</PRE
431 >html_form_begin()</TT
438 > argument is the value for the
450 >html_form_input()</TT
451 > defines a general form input
452 element with the given type, name and
455 >html_form_input_radio</TT
456 > creates a radio button
457 with the given name and value; the <TT
463 argument is a boolean expression that is used to determine whether the
467 > attribute is added to the tag. Similarly
470 >html_form_input_checkbox()</TT
474 >html_form_input_hidden()</TT
476 form element with the given name and value.</P
480 >html_form_select_begin()</TT
481 > begins a multiple choice
482 menu with the given name. <TT
484 >html_form_select_end()</TT
488 >html_form_option()</TT
489 > defines a menu entry
490 with the given value and label; the <TT
496 argument is a boolean expression controlling whether the
500 > attribute is added to the tag.</P
504 >cyg_formdata_parse()</TT
505 > converts a form response
509 >-terminated array of
510 "name=value" entries. The <TT
516 argument is the string as passed to the handler function; note that
517 this string is not copied and will be updated in place to form the
523 > is a pointer to an array of
524 character pointers, and is <TT
532 >cyg_formlist_find()</TT
533 > searches a list generated by
536 >cyg_formdata_parse()</TT
537 > and returns a pointer to the
538 value part of the string whose name part matches
544 >; if there is no match it will return
555 NAME="AEN15388">Predefined Handlers</H2
563 CLASS="PROGRAMLISTING"
564 > int cyg_httpd_send_html( FILE *client, char *filename, char *request, void *arg );
569 cyg_uint32 content_length;
572 #define CYG_HTTPD_DATA( __name, __type, __length, __data )
574 int cyg_httpd_send_data( FILE *client, char *filename, char *request, void *arg ); </PRE
579 >The HTTP server defines a couple of predefined handers to make it
580 easier to deliver simple, static content.</P
584 >cyg_httpd_send_html()</TT
589 >-terminated string as the argument and sends it
590 to the client with an HTTP header indicating that it is HTML. The
591 following is an example of its use:</P
599 CLASS="PROGRAMLISTING"
600 > char cyg_html_message[] = "<head><title>Welcome</title></head>\n"
601 "<body><h2>Welcome to my Web Page</h2></body>\n"
603 CYG_HTTPD_TABLE_ENTRY( cyg_html_message_entry,
606 cyg_html_message ); </PRE
613 >cyg_httpd_send_data()</TT
614 > Sends arbitrary data to the
615 client. The argument is a pointer to a <SPAN
617 >cyg_httpd_data</SPAN
619 structure that defines the content type and length of the data, and a
620 pointer to the data itself. The <TT
622 >CYG_HTTPD_DATA()</TT
624 macro automates the definition of the structure. Here is a typical
625 example of its use:</P
633 CLASS="PROGRAMLISTING"
634 > static cyg_uint8 ecos_logo_gif[] = {
638 CYG_HTTPD_DATA( cyg_monitor_ecos_logo_data,
640 sizeof(ecos_logo_gif),
643 CYG_HTTPD_TABLE_ENTRY( cyg_monitor_ecos_logo,
646 &cyg_monitor_ecos_logo_data ); </PRE
657 SUMMARY="Footer navigation table"
668 HREF="net-httpd-configuration.html"
686 HREF="net-httpd-monitor.html"
696 >Server Configuration</TD
702 HREF="net-httpd-chapter.html"