This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
HTTPD: A few minor fixes
- From: Nick Garnett <nickg at ecoscentric dot com>
- To: ecos-patches at sources dot redhat dot com
- Date: 14 Jun 2003 19:09:43 +0100
- Subject: HTTPD: A few minor fixes
Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/httpd/current/ChangeLog,v
retrieving revision 1.6
diff -u -5 -r1.6 ChangeLog
--- ChangeLog 12 May 2003 10:24:23 -0000 1.6
+++ ChangeLog 14 Jun 2003 18:03:56 -0000
@@ -1,5 +1,13 @@
+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
the display of network information.
* tests/httpd1.c: New file: Simple program to actually run the
Index: src/httpd.c
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/httpd/current/src/httpd.c,v
retrieving revision 1.2
diff -u -5 -r1.2 httpd.c
--- src/httpd.c 12 May 2003 10:24:23 -0000 1.2
+++ src/httpd.c 14 Jun 2003 18:03:57 -0000
@@ -152,108 +152,109 @@
/* ================================================================= */
/* Main processing function */
/* */
/* 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];
-
- 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+");
-
- /* We are really only interested in the first line.
- */
- fgets( request, sizeof(request), client );
-
- 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);
-
- /* 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;
-
- /* 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;
+
+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);
+
+ /* 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 );
+
+ 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);
+
+ /* 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;
+
+ /* 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);
}
/* ================================================================= */
/* Main HTTP server
*
@@ -283,19 +284,15 @@
#endif
select(n,&readfds,NULL,NULL,NULL);
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);
}
Index: src/monitor.c
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/httpd/current/src/monitor.c,v
retrieving revision 1.3
diff -u -5 -r1.3 monitor.c
--- src/monitor.c 12 May 2003 10:24:23 -0000 1.3
+++ src/monitor.c 14 Jun 2003 18:04:00 -0000
@@ -168,12 +168,12 @@
* A simple introductory page matching "/monitor" and
* "/monitor/index.html".
*/
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."
;
static cyg_bool cyg_monitor_index( FILE * client, char *filename,
char *formdata, void *arg )
@@ -319,19 +319,19 @@
* A page on which the thread's state may be edited. This tests forms
* handling.
*/
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,
char *formdata, void *arg )
{
@@ -1178,13 +1178,13 @@
static cyg_uint32 instrument_flags[(CYG_INSTRUMENT_CLASS_MAX>>8)+1];
#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,
char *formdata, void *arg )
{
--
Nick Garnett eCos Kernel Architect
http://www.ecoscentric.com/ The eCos and RedBoot experts