jani            Sat May 23 18:46:10 2009 UTC

  Modified files:              
    /php-src/main       rfc1867.c 
  Log:
  ws
  
http://cvs.php.net/viewvc.cgi/php-src/main/rfc1867.c?r1=1.212&r2=1.213&diff_format=u
Index: php-src/main/rfc1867.c
diff -u php-src/main/rfc1867.c:1.212 php-src/main/rfc1867.c:1.213
--- php-src/main/rfc1867.c:1.212        Sat May 23 18:42:54 2009
+++ php-src/main/rfc1867.c      Sat May 23 18:46:10 2009
@@ -17,13 +17,13 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: rfc1867.c,v 1.212 2009/05/23 18:42:54 jani Exp $ */
+/* $Id: rfc1867.c,v 1.213 2009/05/23 18:46:10 jani Exp $ */
 
 /*
  *  This product includes software developed by the Apache Group
  *  for use in the Apache HTTP server project (http://www.apache.org/).
  *
- */   
+ */
 
 #include <stdio.h>
 #include "php.h"
@@ -76,14 +76,12 @@
        REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_EXTENSION",  UPLOAD_ERROR_X,  
CONST_CS | CONST_PERSISTENT);
 }
 
-
 static int unlink_filename(char **filename TSRMLS_DC)
 {
        VCWD_UNLINK(*filename);
        return 0;
 }
 
-
 void destroy_uploaded_files_hash(TSRMLS_D)
 {
        zend_hash_apply(SG(rfc1867_uploaded_files), (apply_func_t) 
unlink_filename TSRMLS_CC);
@@ -113,13 +111,11 @@
 
 } multipart_buffer;
 
-
 typedef struct {
        char *key;
        char *value;
 } mime_header_entry;
 
-
 /*
   fill up the buffer with client data.
   returns number of bytes added to buffer.
@@ -166,7 +162,6 @@
        return total_read;
 }
 
-
 /* eof if we are out of bytes, or if we hit the final boundary */
 static int multipart_buffer_eof(multipart_buffer *self TSRMLS_DC)
 {
@@ -177,7 +172,6 @@
        }
 }
 
-
 /* create new multipart_buffer structure */
 static multipart_buffer *multipart_buffer_new(char *boundary, int boundary_len)
 {
@@ -190,7 +184,7 @@
        self->bufsize = minsize;
 
        spprintf(&self->boundary, 0, "--%s", boundary);
-       
+
        self->boundary_next_len = spprintf(&self->boundary_next, 0, "\n--%s", 
boundary);
 
        self->buf_begin = self->buffer;
@@ -199,7 +193,6 @@
        return self;
 }
 
-
 /*
   gets the next CRLF terminated line from the input buffer.
   if it doesn't find a CRLF, and the buffer isn't completely full, returns
@@ -229,7 +222,7 @@
                /* bump the pointer */
                self->buf_begin = ptr + 1;
                self->bytes_in_buffer -= (self->buf_begin - line);
-       
+
        } else {        /* no LF found */
 
                /* buffer isn't completely full, fail */
@@ -245,7 +238,6 @@
        return line;
 }
 
-
 /* returns the next CRLF terminated line from the client */
 static char *get_line(multipart_buffer *self TSRMLS_DC)
 {
@@ -259,7 +251,6 @@
        return ptr;
 }
 
-
 /* Free header entry */
 static void php_free_hdr_entry(mime_header_entry *h)
 {
@@ -271,7 +262,6 @@
        }
 }
 
-
 /* finds a boundary */
 static int find_boundary(multipart_buffer *self, char *boundary TSRMLS_DC)
 {
@@ -290,14 +280,13 @@
        return 0;
 }
 
-
 /* parse headers */
 static int multipart_buffer_headers(multipart_buffer *self, zend_llist *header 
TSRMLS_DC)
 {
        char *line;
        mime_header_entry prev_entry, entry;
        int prev_len, cur_len;
-       
+
        /* didn't find boundary, abort */
        if (!find_boundary(self, self->boundary TSRMLS_CC)) {
                return 0;
@@ -308,10 +297,9 @@
        while( (line = get_line(self TSRMLS_CC)) && strlen(line) > 0 )
        {
                /* add header to table */
-               
                char *key = line;
                char *value = NULL;
-               
+
                /* space in the beginning means same header */
                if (!isspace(line[0])) {
                        value = strchr(line, ':');
@@ -335,7 +323,7 @@
                        entry.value[cur_len + prev_len] = '\0';
 
                        entry.key = estrdup(prev_entry.key);
-                       
+
                        zend_llist_remove_tail(header);
                } else {
                        continue;
@@ -348,7 +336,6 @@
        return 1;
 }
 
-
 static char *php_mime_get_hdr_value(zend_llist header, char *key)
 {
        mime_header_entry *entry;
@@ -356,7 +343,7 @@
        if (key == NULL) {
                return NULL;
        }
-       
+
        entry = zend_llist_get_first(&header);
        while (entry) {
                if (!strcasecmp(entry->key, key)) {
@@ -364,19 +351,17 @@
                }
                entry = zend_llist_get_next(&header);
        }
-       
+
        return NULL;
 }
 
-
-
 static char *php_ap_getword(char **line, char stop)
 {
        char *pos = *line, quote;
        char *res;
 
        while (*pos && *pos != stop) {
-               
+
                if ((quote = *pos) == '"' || quote == '\'') {
                        ++pos;
                        while (*pos && *pos != quote) {
@@ -390,7 +375,7 @@
                                ++pos;
                        }
                } else ++pos;
-               
+
        }
        if (*pos == '\0') {
                res = estrdup(*line);
@@ -408,8 +393,6 @@
        return res;
 }
 
-
-
 static char *substring_conf(char *start, int len, char quote TSRMLS_DC)
 {
        char *result = emalloc(len + 2);
@@ -428,7 +411,6 @@
        return result;
 }
 
-
 static char *php_ap_getword_conf(char **line TSRMLS_DC)
 {
        char *str = *line, *strend, *res, quote;
@@ -483,7 +465,6 @@
        return res;
 }
 
-
 /*
   search for a string in a fixed-length byte string.
   if partial is true, partial matches are allowed at the end of the buffer.
@@ -512,7 +493,6 @@
        return ptr;
 }
 
-
 /* read until a boundary condition */
 static int multipart_buffer_read(multipart_buffer *self, char *buf, int bytes, 
int *end TSRMLS_DC)
 {
@@ -556,7 +536,6 @@
        return len;
 }
 
-
 /*
   XXX: this is horrible memory-usage-wise, but we only expect
   to do this on small pieces of form data.
@@ -572,7 +551,9 @@
                total_bytes += read_bytes;
        }
 
-       if (out) out[total_bytes] = '\0';
+       if (out) {
+               out[total_bytes] = '\0';
+       }
        *len = total_bytes;
 
        return out;
@@ -580,7 +561,7 @@
 
 static void register_raw_var_ex(char *var, zval *value, HashTable *array)
 {
-       zend_hash_update(array, var, strlen(var)+1, &value, sizeof(zval *), 
NULL);
+       zend_hash_update(array, var, strlen(var) + 1, &value, sizeof(zval *), 
NULL);
 }
 
 static void register_raw_var(char *var, char *str, int str_len, HashTable 
*array)
@@ -590,9 +571,7 @@
 
        /* Prepare value */
        MAKE_STD_ZVAL(new_entry);
-       Z_STRLEN_P(new_entry) = str_len;
-       Z_STRVAL_P(new_entry) = estrndup(str, Z_STRLEN_P(new_entry));
-       Z_TYPE_P(new_entry) = IS_STRING;
+       ZVAL_STRINGL(new_entry, str, str_len, 1);
 
        register_raw_var_ex(var, new_entry, array);
 }
@@ -634,7 +613,7 @@
        if (boundary[0] == '"') {
                boundary++;
                boundary_end = strchr(boundary, '"');
-               if (!boundary_end) { 
+               if (!boundary_end) {
                        sapi_module.sapi_error(E_WARNING, "Invalid boundary in 
multipart/form-data POST data");
                        return;
                }
@@ -676,12 +655,11 @@
                }
        }
 
-
        while (!multipart_buffer_eof(mbuff TSRMLS_CC))
        {
                char buff[FILLUNIT];
-               char *cd=NULL,*param=NULL,*filename=NULL, *tmp=NULL;
-               size_t blen=0, wlen=0;
+               char *cd = NULL, *param = NULL, *filename = NULL, *tmp = NULL;
+               size_t blen = 0, wlen = 0;
                off_t offset;
 
                zend_llist_clean(&header);
@@ -691,16 +669,16 @@
                }
 
                if ((cd = php_mime_get_hdr_value(header, 
"Content-Disposition"))) {
-                       char *pair=NULL;
-                       int end=0;
-                       
+                       char *pair = NULL;
+                       int end = 0;
+
                        while (isspace(*cd)) {
                                ++cd;
                        }
 
                        while (*cd && (pair = php_ap_getword(&cd, ';')))
                        {
-                               char *key=NULL, *word = pair;
+                               char *key = NULL, *word = pair;
 
                                while (isspace(*cd)) {
                                        ++cd;
@@ -729,7 +707,7 @@
 
                        /* Normal form variable, safe to read all data into 
memory */
                        if (!filename && param) {
-                               unsigned int value_len; 
+                               unsigned int value_len;
                                char *value = multipart_buffer_read_body(mbuff, 
&value_len TSRMLS_CC);
 
                                if (!value) {
@@ -797,7 +775,7 @@
                                                skip_upload = 1;
                                                break;
                                        }
-                                       tmp++;                          
+                                       tmp++;
                                }
                        }
 
@@ -811,7 +789,7 @@
                                        cancel_upload = UPLOAD_ERROR_E;
                                }
                        }
-                       
+
                        if (!skip_upload && php_rfc1867_callback != NULL) {
                                multipart_event_file_start event_file_start;
 
@@ -833,14 +811,13 @@
                                }
                        }
 
-                       
                        if (skip_upload) {
                                efree(param);
                                efree(filename);
                                continue;
-                       }       
+                       }
 
-                       if(strlen(filename) == 0) {
+                       if (strlen(filename) == 0) {
 #if DEBUG_FILE_UPLOAD
                                sapi_module.sapi_error(E_NOTICE, "No file 
uploaded");
 #endif
@@ -864,8 +841,7 @@
                                                continue;
                                        }
                                }
-                               
-                       
+
                                if (PG(upload_max_filesize) > 0 && 
(total_bytes+blen) > PG(upload_max_filesize)) {
 #if DEBUG_FILE_UPLOAD
                                        sapi_module.sapi_error(E_NOTICE, 
"upload_max_filesize of %ld bytes exceeded - file [%s=%s] not saved", 
PG(upload_max_filesize), param, filename);
@@ -878,7 +854,7 @@
                                        cancel_upload = UPLOAD_ERROR_B;
                                } else if (blen > 0) {
                                        wlen = write(fd, buff, blen);
-                       
+
                                        if (wlen == -1) {
                                                /* write failed */
 #if DEBUG_FILE_UPLOAD
@@ -893,9 +869,8 @@
                                        } else {
                                                total_bytes += wlen;
                                        }
-                                       
                                        offset += wlen;
-                               } 
+                               }
                        }
                        if (fd!=-1) { /* may not be initialized if file could 
not be created */
                                close(fd);
@@ -907,12 +882,11 @@
                                cancel_upload = UPLOAD_ERROR_C;
                        }
 #if DEBUG_FILE_UPLOAD
-                       if(strlen(filename) > 0 && total_bytes == 0 && 
!cancel_upload) {
+                       if (strlen(filename) > 0 && total_bytes == 0 && 
!cancel_upload) {
                                sapi_module.sapi_error(E_WARNING, "Uploaded 
file size 0 - file [%s=%s] not saved", param, filename);
                                cancel_upload = 5;
                        }
-#endif         
-
+#endif
                        if (php_rfc1867_callback != NULL) {
                                multipart_event_file_end event_file_end;
 
@@ -947,7 +921,7 @@
                                if (array_index) {
                                        efree(array_index);
                                }
-                               array_index = estrndup(start_arr+1, 
array_len-2);   
+                               array_index = estrndup(start_arr + 1, array_len 
- 2);
                        }
 
                        /* Add $foo_name */
@@ -960,7 +934,7 @@
                        /* The \ check should technically be needed for win32 
systems only where
                         * it is a valid path separator. However, IE in all 
it's wisdom always sends
                         * the full path of the file on the user's filesystem, 
which means that unless
-                        * the user does basename() they get a bogus file name. 
Until IE's user base drops 
+                        * the user does basename() they get a bogus file name. 
Until IE's user base drops
                         * to nill or problem is fixed this code must remain 
enabled for all systems.
                         */
                        s = strrchr(filename, '\\');
@@ -985,7 +959,7 @@
                        /* Possible Content-Type: */
                        if (cancel_upload || !(cd = 
php_mime_get_hdr_value(header, "Content-Type"))) {
                                cd = "";
-                       } else { 
+                       } else {
                                /* fix for Opera 6.01 */
                                s = strchr(cd, ';');
                                if (s != NULL) {
@@ -1028,7 +1002,7 @@
                                        ZVAL_LONG(file_size, 0);
                                } else {
                                        ZVAL_LONG(file_size, total_bytes);
-                               }       
+                               }
 
                                if (is_arr_upload) {
                                        snprintf(lbuf, llen, "%s[error][%s]", 
abuf, array_index);
@@ -1050,10 +1024,9 @@
        }
 
 fileupload_done:
-
        if (php_rfc1867_callback != NULL) {
                multipart_event_end event_end;
-               
+
                event_end.post_bytes_processed = SG(read_post_bytes);
                php_rfc1867_callback(MULTIPART_EVENT_END, &event_end, 
&event_extra_data TSRMLS_CC);
        }

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to