Mercurial > ecos
changeset 1053:657f409c5dfe
* src/httpd.c: Fixed a problem with closing the client socket --
it was being done twice.
Tidied up the formatting a little.
* src/monitor.c: Fixed some compiler warnings.
| author | nickg |
|---|---|
| date | Sat, 14 Jun 2003 18:04:55 +0000 |
| parents | ee5b3444e088 |
| children | c706e0d163d7 |
| files | packages/net/httpd/current/ChangeLog packages/net/httpd/current/src/httpd.c packages/net/httpd/current/src/monitor.c |
| diffstat | 3 files changed, 98 insertions(+), 93 deletions(-) [+] |
line wrap: on
line diff
--- a/packages/net/httpd/current/ChangeLog +++ b/packages/net/httpd/current/ChangeLog @@ -1,3 +1,11 @@ +2003-06-09 Nick Garnett <nickg@balti.calivar.com> + + * src/httpd.c: Fixed a problem with closing the client socket -- + it was being done twice. + Tidied up the formatting a little. + + * src/monitor.c: Fixed some compiler warnings. + 2003-05-11 Andrew Lunn <andrew.lunn@ascom.ch> * src/monitor.c (cyg_monitor_network): Added IPv6 information to
--- a/packages/net/httpd/current/src/httpd.c +++ b/packages/net/httpd/current/src/httpd.c @@ -154,104 +154,105 @@ static cyg_bool match( char *name, char /* */ /* Reads the HTTP header, look it up in the table and calls the */ /* handler. */ -static void cyg_httpd_process( int client_socket, struct sockaddr *client_address ) { - - int calen = sizeof(*client_address); - int nlc = 0; - char request[CYGNUM_HTTPD_SERVER_BUFFER_SIZE]; - FILE *client; - cyg_httpd_table_entry *entry = cyg_httpd_table; - char *filename; - char *formdata = NULL; - char *p; - cyg_bool success = false; - char name[64]; - char port[10]; + +static void cyg_httpd_process( int client_socket, struct sockaddr *client_address ) +{ + int calen = sizeof(*client_address); + int nlc = 0; + char request[CYGNUM_HTTPD_SERVER_BUFFER_SIZE]; + FILE *client; + cyg_httpd_table_entry *entry = cyg_httpd_table; + char *filename; + char *formdata = NULL; + char *p; + cyg_bool success = false; + char name[64]; + char port[10]; - getnameinfo(client_address, calen, name, sizeof(name), - port, sizeof(port), NI_NUMERICHOST|NI_NUMERICSERV); - HTTPD_DIAG("Connection from %s[%s]\n",name,port); + getnameinfo(client_address, calen, name, sizeof(name), + port, sizeof(port), NI_NUMERICHOST|NI_NUMERICSERV); + HTTPD_DIAG("Connection from %s[%s]\n",name,port); - /* Convert the file descriptor to a C library FILE object so - * we can use fprintf() and friends on it. - */ - client = fdopen( client_socket, "r+"); + /* Convert the file descriptor to a C library FILE object so + * we can use fprintf() and friends on it. + */ + client = fdopen( client_socket, "r+"); - /* We are really only interested in the first line. - */ - fgets( request, sizeof(request), client ); + /* We are really only interested in the first line. + */ + fgets( request, sizeof(request), client ); - HTTPD_DIAG("Request >%s<\n", request ); + HTTPD_DIAG("Request >%s<\n", request ); - /* Absorb the rest of the header. We nibble it away a - * character at a time like this to avoid having to define - * another buffer to read lines into. If we ever need to take - * more interest in the header fields, we will need to be a - * lot more sophisticated than this. - */ - do{ - int c = getc( client ); - HTTPD_DIAG("%c",c); - if( c == '\n' ) - nlc++; - else if( c != '\r' ) - nlc = 0; - } while(nlc < 2); + /* Absorb the rest of the header. We nibble it away a + * character at a time like this to avoid having to define + * another buffer to read lines into. If we ever need to take + * more interest in the header fields, we will need to be a + * lot more sophisticated than this. + */ + do{ + int c = getc( client ); + HTTPD_DIAG("%c",c); + if( c == '\n' ) + nlc++; + else if( c != '\r' ) + nlc = 0; + } while(nlc < 2); - /* Extract the filename and any form data being returned. - * We know that the "GET " request takes 4 bytes. - * TODO: handle POST type requests as well as GET's. - */ + /* Extract the filename and any form data being returned. + * We know that the "GET " request takes 4 bytes. + * TODO: handle POST type requests as well as GET's. + */ - filename = p = request+4; + filename = p = request+4; - /* Now scan the filename until we hit a space or a '?'. If we - * end on a '?' then the rest is a form request. Put NULs at - * the end of each string. - */ - while( *p != ' ' && *p != '?' ) - p++; - if( *p == '?' ) - formdata = p+1; - *p = 0; + /* Now scan the filename until we hit a space or a '?'. If we + * end on a '?' then the rest is a form request. Put NULs at + * the end of each string. + */ + while( *p != ' ' && *p != '?' ) + p++; + if( *p == '?' ) + formdata = p+1; + *p = 0; - if( formdata != NULL ) + if( formdata != NULL ) { - while( *p != ' ' ) - p++; - *p = 0; + while( *p != ' ' ) + p++; + *p = 0; } - HTTPD_DIAG("Request filename >%s< formdata >%s<\n",filename,formdata?formdata:"-NULL-"); + HTTPD_DIAG("Request filename >%s< formdata >%s<\n",filename,formdata?formdata:"-NULL-"); - HTTPD_DIAG("table: %08x...%08x\n",cyg_httpd_table, cyg_httpd_table_end); + HTTPD_DIAG("table: %08x...%08x\n",cyg_httpd_table, cyg_httpd_table_end); - /* Now scan the table for a matching entry. If we find one - * call the handler routine. If that returns true then we - * terminate the scan, otherwise we keep looking. - */ - while( entry != cyg_httpd_table_end ) + /* Now scan the table for a matching entry. If we find one + * call the handler routine. If that returns true then we + * terminate the scan, otherwise we keep looking. + */ + while( entry != cyg_httpd_table_end ) { - HTTPD_DIAG("try %08x: %s\n", entry, entry->pattern); + HTTPD_DIAG("try %08x: %s\n", entry, entry->pattern); - if( match( filename, entry->pattern ) ) + if( match( filename, entry->pattern ) ) { - if( (success = entry->handler( client, filename, formdata, entry->arg )) ) - break; + if( (success = entry->handler( client, filename, formdata, entry->arg )) ) + break; } - entry++; + entry++; } - /* If we failed to find a match in the table, send a "not - * found" response. - * TODO: add an optional fallback to go look for files in - * some filesystem, somewhere. - */ - if( !success ) - cyg_httpd_send_html( client, NULL, NULL, cyg_httpd_not_found ); + /* If we failed to find a match in the table, send a "not + * found" response. + * TODO: add an optional fallback to go look for files in + * some filesystem, somewhere. + */ + if( !success ) + cyg_httpd_send_html( client, NULL, NULL, cyg_httpd_not_found ); - fclose(client); + fclose(client); } /* ================================================================= */ @@ -285,15 +286,11 @@ static void cyg_httpd_server( cyg_addrwo if (FD_ISSET(server_socket, &readfds)) { client_socket = accept( server_socket, &client_address, &calen ); cyg_httpd_process(client_socket, &client_address); - err = close( client_socket ); - CYG_ASSERT( err == 0, "fclose() returned error"); } #ifdef CYGPKG_NET_INET6 if (FD_ISSET(server_socket6, &readfds)) { client_socket = accept( server_socket6, &client_address, &calen ); cyg_httpd_process(client_socket, &client_address); - err = close( client_socket ); - CYG_ASSERT( err == 0, "fclose(AF_INET6) returned error"); } #endif } while(1);
--- a/packages/net/httpd/current/src/monitor.c +++ b/packages/net/httpd/current/src/monitor.c @@ -170,8 +170,8 @@ static void draw_navbar( FILE *client ) */ static char monitor_index_blurb[] = -"<p>This is the eCos System Monitor. It presents a simple web monitor -and control interface for eCos systems.\n" +"<p>This is the eCos System Monitor. It presents a simple web monitor" +"and control interface for eCos systems.\n" "<p>Use the navigation bar at the bottom of each page to explore." ; @@ -321,15 +321,15 @@ CYG_HTTPD_TABLE_ENTRY( cyg_monitor_show_ */ static char thread_edit_blurb[] = -"<p>This table contains an entry for each property of the thread -that you can edit. The properties are:\n" -"<p><b>State:</b> Change thread's state. The <em>Suspend</em> button -will suspend the thread. The <em>Run</em> button will undo any previous -suspends. The <em>Release</em> button will release the thread out of -any sleep it is currently in.\n" +"<p>This table contains an entry for each property of the thread" +"that you can edit. The properties are:\n" +"<p><b>State:</b> Change thread's state. The <em>Suspend</em> button" +"will suspend the thread. The <em>Run</em> button will undo any previous" +"suspends. The <em>Release</em> button will release the thread out of" +"any sleep it is currently in.\n" "<p><b>Priority:</b> Change the thread's priority.\n" -"<p>Once the new state has been selected, press the <em>Submit</em> -button to make the change, or <em>Reset</em> to clear it." +"<p>Once the new state has been selected, press the <em>Submit</em>" +"button to make the change, or <em>Reset</em> to clear it." ; static cyg_bool cyg_monitor_thread_edit( FILE * client, char *filename, @@ -1180,9 +1180,9 @@ static cyg_uint32 instrument_flags[(CYG_ #endif static char cyg_monitor_instrument_blurb1[] = -"<p>Use the checkboxes to enable the events to be recorded. Click -the <em>Submit</em> button to start recording. Click the <em>Clear</em> -button to clear all instrumentation and to stop recording." +"<p>Use the checkboxes to enable the events to be recorded. Click" +"the <em>Submit</em> button to start recording. Click the <em>Clear</em>" +"button to clear all instrumentation and to stop recording." ; static cyg_bool cyg_monitor_instrument( FILE * client, char *filename,
