[aadk-commits] kpfleming: uClinux/trunk r279 - /uClinux/trunk/uClinux-dist/user/mini_httpd/

aadk-commits at lists.digium.com aadk-commits at lists.digium.com
Thu Mar 29 12:00:35 MST 2007


Author: kpfleming
Date: Thu Mar 29 14:00:35 2007
New Revision: 279

URL: http://svn.digium.com/view/aadk?view=rev&rev=279
Log:
add POST-to-file support

Modified:
    uClinux/trunk/uClinux-dist/user/mini_httpd/mini_httpd.c

Modified: uClinux/trunk/uClinux-dist/user/mini_httpd/mini_httpd.c
URL: http://svn.digium.com/view/aadk/uClinux/trunk/uClinux-dist/user/mini_httpd/mini_httpd.c?view=diff&rev=279&r1=278&r2=279
==============================================================================
--- uClinux/trunk/uClinux-dist/user/mini_httpd/mini_httpd.c (original)
+++ uClinux/trunk/uClinux-dist/user/mini_httpd/mini_httpd.c Thu Mar 29 14:00:35 2007
@@ -840,7 +840,6 @@
     int fd;
     void* ptr;
 
-    /* Check authorization for this directory. */
     (void) strncpy( buf, file, sizeof(buf) );
     cp = strrchr( buf, '/' );
     if ( cp == (char*) 0 )
@@ -861,35 +860,55 @@
 	return;
 	}
 
-    fd = open( file, O_RDONLY );
-    if ( fd < 0 )
-	send_error( 403, "Forbidden", (char*) 0, "File is protected." );
-    type = get_mime_type( file );
-    (void) snprintf( fixed_type, sizeof(fixed_type), type, charset );
-    if ( if_modified_since != (time_t) -1 &&
-	 if_modified_since >= sb.st_mtime )
-	{
-	add_headers(
-	    304, "Not Modified", (char*) 0, fixed_type, sb.st_size,
-	    sb.st_mtime );
-	send_response();
-	return;
-	}
-    add_headers( 200, "Ok", (char*) 0, fixed_type, sb.st_size, sb.st_mtime );
-    send_response();
-    if ( method == METHOD_HEAD )
-	return;
-    if ( sb.st_size > 0 )	/* avoid zero-length mmap */
-	{
-	ptr = mmap( 0, sb.st_size, PROT_READ, MAP_SHARED, fd, 0 );
-	if ( ptr != (void*) -1 )
-	    {
-	    (void) my_write( ptr, sb.st_size );
-	    (void) munmap( ptr, sb.st_size );
-	    }
-	}
-    (void) close( fd );
-    }
+    switch (method) {
+    case METHOD_GET:
+    case METHOD_HEAD:
+	    fd = open( file, O_RDONLY );
+	    if ( fd < 0 )
+		    send_error( 403, "Forbidden", (char*) 0, "File is protected." );
+	    type = get_mime_type( file );
+	    (void) snprintf( fixed_type, sizeof(fixed_type), type, charset );
+	    if ( if_modified_since != (time_t) -1 &&
+		 if_modified_since >= sb.st_mtime )
+	    {
+		    add_headers(
+			    304, "Not Modified", (char*) 0, fixed_type, sb.st_size,
+			    sb.st_mtime );
+		    send_response();
+		    return;
+	    }
+	    add_headers( 200, "Ok", (char*) 0, fixed_type, sb.st_size, sb.st_mtime );
+	    send_response();
+	    if ( method == METHOD_HEAD )
+		    return;
+	    if ( sb.st_size > 0 )	/* avoid zero-length mmap */
+	    {
+		    ptr = mmap( 0, sb.st_size, PROT_READ, MAP_SHARED, fd, 0 );
+		    if ( ptr != (void*) -1 )
+		    {
+			    (void) my_write( ptr, sb.st_size );
+			    (void) munmap( ptr, sb.st_size );
+		    }
+	    }
+	    (void) close( fd );
+	    break;
+    case METHOD_POST:
+	    fd = open( file, O_WRONLY | O_CREAT | O_TRUNC );
+	    if ( fd < 0 )
+		    send_error( 403, "Forbidden", (char*) 0, "File is protected." );
+	    /* dump the request body out to the file */
+	    cgi_interpose_input( fd );
+	    (void) close( fd );
+	    stat( file, &sb );
+	    type = get_mime_type( file );
+	    (void) snprintf( fixed_type, sizeof(fixed_type), type, charset );
+	    add_headers( 200, "Ok", (char*) 0, fixed_type, sb.st_size, sb.st_mtime );
+	    send_response();
+	    break;
+    }
+
+    return;
+}
 
 
 static void



More information about the aadk-commits mailing list