httpd.sgml
来自「eCos操作系统源码」· SGML 代码 · 共 551 行 · 第 1/2 页
SGML
551 行
</para><note><para>All arguments to macros are pointers to strings, unless otherwisestated. In general, wherever a function or macro has an<parameter>attr</parameter> or <parameter>__attr</parameter>parameter, then the contents of this string will be inserted into thetag being defined as HTML attributes. If it is a NULL or empty stringit will be ignored.</para></note><sect2><title>HTTP Support</title><programlisting width=72>void cyg_http_start( FILE *client, char *content_type, int content_length );void cyg_http_finish( FILE *client );#define html_begin(__client)#define html_end( __client )</programlisting><para>The function <function>cyg_http_start()</function> generates a simpleHTTP response header containing the value of<literal>CYGDAT_HTTPD_SERVER_ID</literal> in the "Server" field, and thevalues of <parameter>content_type</parameter> and<parameter>content_length</parameter> in the "Content-type"and "Content-length" field respectively. The function<function>cyg_http_finish()</function> just adds an extra newline tothe end of the output and then flushes it to force the data out to theclient.</para><para>The macro <literal>html_begin()</literal> generates an HTTP headerwith a "text/html" content type followed by an opening"<html>" tag. <literal>html_end()</literal> generatesa closing "</html>" tag and calls<function>cyg_http_finish()</function>.</para></sect2><sect2><title>General HTML Support</title><programlisting width=72>void cyg_html_tag_begin( FILE *client, char *tag, char *attr );void cyg_html_tag_end( FILE *client, char *tag );#define html_tag_begin( __client, __tag, __attr )#define html_tag_end( __client, __tag )#define html_head( __client, __title, __meta )#define html_body_begin( __client, __attr )#define html_body_end( __client )#define html_heading( __client, __level, __heading )#define html_para_begin( __client, __attr )#define html_url( __client, __text, __link )#define html_image( __client, __source, __alt, __attr )</programlisting><para>The function <function>cyg_html_tag_begin()</function> generates anopening tag with the given name. The function<function>cyg_html_tag_end()</function> generates a closing tag withthe given name. The macros <literal>html_tag_begin()</literal> and<literal>html_tag_end</literal> are just wrappers for these functions.</para><para>The macro <literal>html_head()</literal> generates an HTML headersection with <parameter>__title</parameter> as the title. The<parameter>__meta</parameter> argument defines any meta tags that willbe inserted into the header. <literal>html_body_begin()</literal> and<literal>html_body_end</literal> generate HTML body begin and endtags.</para><para><literal>html_heading()</literal> generates a complete HTML headerwhere <parameter>__level</parameter> is a numerical level, between 1and 6, and <parameter>__heading</parameter> is the headingtext. <literal>html_para_begin()</literal> generates a paragraphbreak.</para><para><literal>html_url()</literal> inserts a URL where<parameter>__text</parameter> is the displayed text and<parameter>__link</parameter> is the URL of the linkedpage. <literal>html_image()</literal> inserts an image tag where<parameter>__source</parameter> is the URL of the image to beincluded and <parameter>__alt</parameter> is the alternative text forwhen the image is not displayed.</para></sect2><sect2><title>Table Support</title><programlisting width=72>#define html_table_begin( __client, __attr )#define html_table_end( __client )#define html_table_header( __client, __content, __attr ) #define html_table_row_begin( __client, __attr ) #define html_table_row_end( __client ) #define html_table_data_begin( __client, __attr ) #define html_table_data_end( __client ) </programlisting><para><literal>html_table_begin()</literal> starts a table and<literal>html_table_end()</literal> endit. <literal>html_table_header()</literal> generates a simple tablecolumn header containg the string <parameter>__content</parameter>. </para><para><literal>html_table_row_begin()</literal> and<literal>html_table_row_end()</literal> begin and end a table row,and similarly <literal>html_table_data_begin()</literal> and<literal>html_table_data_end()</literal> begin and end a tableentry. </para></sect2><sect2><title>Forms Support</title><programlisting width=72>#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 );</programlisting><para><literal>html_form_begin()</literal> begins a form, the<parameter>__url</parameter> argument is the value for the<literal>action</literal>attribute. <literal>html_form_end()</literal> ends the form.</para><para><literal>html_form_input()</literal> defines a general form inputelement with the given type, name andvalue. <literal>html_form_input_radio</literal> creates a radio buttonwith the given name and value; the <parameter>__checked</parameter>argument is a boolean expression that is used to determine whether the<literal>checked</literal> attribute is added to the tag. Similarly<literal>html_form_input_checkbox()</literal> defines a checkboxelement. <literal>html_form_input_hidden()</literal> defines a hiddenform element with the given name and value.</para><para><literal>html_form_select_begin()</literal> begins a multiple choicemenu with the given name. <literal>html_form_select_end()</literal>end it. <literal>html_form_option()</literal> defines a menu entrywith the given value and label; the <parameter>__selected</parameter>argument is a boolean expression controlling whether the<literal>selected</literal> attribute is added to the tag.</para><para><function>cyg_formdata_parse()</function> converts a form responsestring into an <literal>NULL</literal>-terminated array of"name=value" entries. The <parameter>data</parameter>argument is the string as passed to the handler function; note thatthis string is not copied and will be updated in place to form thelist entries. <parameter>list</parameter> is a pointer to an array ofcharacter pointers, and is <parameter>size</parameter> elements long.<function>cyg_formlist_find()</function> searches a list generated by<function>cyg_formdata_parse()</function> and returns a pointer to thevalue part of the string whose name part matches<parameter>name</parameter>; if there is no match it will return<literal>NULL</literal>.</para></sect2><sect2><title>Predefined Handlers</title><programlisting width=72>cyg_bool 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 )cyg_bool cyg_httpd_send_data( FILE *client, char *filename, char *request, void *arg );</programlisting><para>The HTTP server defines a couple of predefined handers to make iteasier to deliver simple, static content.</para><para><function>cyg_httpd_send_html()</function> takes a<literal>NULL</literal>-terminated string as the argument and sends itto the client with an HTTP header indicating that it is HTML. Thefollowing is an example of its use:</para><programlisting width=72>char cyg_html_message[] = "<head><title>Welcome</title></head>\n" "<body><h2>Welcome to my Web Page</h2></body>\n"CYG_HTTPD_TABLE_ENTRY( cyg_html_message_entry, "/message.html", cyg_httpd_send_html, cyg_html_message );</programlisting><para><function>cyg_httpd_send_data()</function> Sends arbitrary data to theclient. The argument is a pointer to a <type>cyg_httpd_data</type>structure that defines the content type and length of the data, and apointer to the data itself. The <literal>CYG_HTTPD_DATA()</literal>macro automates the definition of the structure. Here is a typicalexample of its use:</para><programlisting width=72>static cyg_uint8 ecos_logo_gif[] = { ...};CYG_HTTPD_DATA( cyg_monitor_ecos_logo_data, "image/gif", sizeof(ecos_logo_gif), ecos_logo_gif );CYG_HTTPD_TABLE_ENTRY( cyg_monitor_ecos_logo, "/monitor/ecos.gif", cyg_httpd_send_data, &cyg_monitor_ecos_logo_data );</programlisting></sect2></sect1><!-- =============================================================== --><sect1 id="net-httpd-monitor"><title>System Monitor</title><para>Included in the HTTPD package is a simple System Monitor that isintended to act as a test and an example of how to produce servers.It is also hoped that it might be of some use in and of itself.</para><para>The System Monitor is intended to work in the background of anyapplication. Adding the network stack and the HTTPD package to anyconfiguration will enable the monitor by default. It may be disabledby disabling the <literal>CYGPKG_HTTPD_MONITOR</literal> option.</para><para>The monitor is intended to be simple and self-explanatory in use. Itconsists of four main pages. The thread monitor page presents a tableof all current threads showing such things as id, state, priority,name and stack dimensions. Clicking on the thread ID will link to athread edit page where the thread's state and priority may bemanipulated. The interrupt monitor just shows a table of the currentinterrupts and indicates which are active. The memory monitor shows a256 byte page of memory, with controls to change the base address anddisplay element size. Note: Accessing invalid memory locations can causememory exceptions and the program to crash. The network monitor page showsinformation extracted from the active network interfaces andprotocols. Finally, if kernel instrumentation is enabled, theinstrumentation page provides some controls over the instrumentationmechanism, and displays the instrumentation buffer.</para></sect1><!-- =============================================================== --></chapter></part>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?