[PHP-CVS] svn: /php/php-src/trunk/main/ SAPI.c main.c rfc1867.c snprintf.c streams/glob_wrapper.c

2010-08-17 Thread Kalle Sommer Nielsen
kalleTue, 17 Aug 2010 12:49:19 +

Revision: http://svn.php.net/viewvc?view=revision&revision=302387

Log:
Fixed compiler warnings in main/

Changed paths:
U   php/php-src/trunk/main/SAPI.c
U   php/php-src/trunk/main/main.c
U   php/php-src/trunk/main/rfc1867.c
U   php/php-src/trunk/main/snprintf.c
U   php/php-src/trunk/main/streams/glob_wrapper.c

Modified: php/php-src/trunk/main/SAPI.c
===
--- php/php-src/trunk/main/SAPI.c   2010-08-17 12:17:28 UTC (rev 302386)
+++ php/php-src/trunk/main/SAPI.c   2010-08-17 12:49:19 UTC (rev 302387)
@@ -570,7 +570,6 @@

 SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
 {
-   int retval;
sapi_header_struct sapi_header;
char *colon_offset;
long myuid = 0L;

Modified: php/php-src/trunk/main/main.c
===
--- php/php-src/trunk/main/main.c   2010-08-17 12:17:28 UTC (rev 302386)
+++ php/php-src/trunk/main/main.c   2010-08-17 12:49:19 UTC (rev 302387)
@@ -1621,7 +1621,7 @@
zend_bool send_buffer = SG(request_info).headers_only ? 0 : 1;

if (CG(unclean_shutdown) && PG(last_error_type) == E_ERROR &&
-   PG(memory_limit) < zend_memory_usage(1 TSRMLS_CC)
+   (size_t)PG(memory_limit) < zend_memory_usage(1 
TSRMLS_CC)
) {
send_buffer = 0;
}

Modified: php/php-src/trunk/main/rfc1867.c
===
--- php/php-src/trunk/main/rfc1867.c2010-08-17 12:17:28 UTC (rev 302386)
+++ php/php-src/trunk/main/rfc1867.c2010-08-17 12:49:19 UTC (rev 302387)
@@ -769,7 +769,7 @@
int fd = -1;
zend_llist header;
void *event_extra_data = NULL;
-   int llen = 0;
+   unsigned int llen = 0;
int upload_cnt = INI_INT("max_file_uploads");

if (SG(post_max_size) > 0 && SG(request_info).content_length > 
SG(post_max_size)) {
@@ -1066,12 +1066,12 @@
}
}

-   if (PG(upload_max_filesize) > 0 && 
(total_bytes+blen) > PG(upload_max_filesize)) {
+   if (PG(upload_max_filesize) > 0 && 
(long)(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);
 #endif
cancel_upload = UPLOAD_ERROR_A;
-   } else if (max_file_size && ((total_bytes+blen) 
> max_file_size)) {
+   } else if (max_file_size && 
((long)(total_bytes+blen) > max_file_size)) {
 #if DEBUG_FILE_UPLOAD
sapi_module.sapi_error(E_NOTICE, 
"MAX_FILE_SIZE of %ld bytes exceeded - file [%s=%s] not saved", max_file_size, 
param, filename);
 #endif

Modified: php/php-src/trunk/main/snprintf.c
===
--- php/php-src/trunk/main/snprintf.c   2010-08-17 12:17:28 UTC (rev 302386)
+++ php/php-src/trunk/main/snprintf.c   2010-08-17 12:49:19 UTC (rev 302387)
@@ -1220,7 +1220,7 @@

 PHPAPI int ap_php_slprintf(char *buf, size_t len, const char *format,...) /* 
{{{ */
 {
-   int cc;
+   unsigned int cc;
va_list ap;

va_start(ap, format);
@@ -1236,7 +1236,7 @@

 PHPAPI int ap_php_vslprintf(char *buf, size_t len, const char *format, va_list 
ap) /* {{{ */
 {
-   int cc;
+   unsigned int cc;

strx_printv(&cc, buf, len, format, ap);
if (cc >= len) {

Modified: php/php-src/trunk/main/streams/glob_wrapper.c
===
--- php/php-src/trunk/main/streams/glob_wrapper.c   2010-08-17 12:17:28 UTC 
(rev 302386)
+++ php/php-src/trunk/main/streams/glob_wrapper.c   2010-08-17 12:49:19 UTC 
(rev 302387)
@@ -144,7 +144,7 @@

/* avoid problems if someone mis-uses the stream */
if (count == sizeof(php_stream_dirent) && pglob) {
-   if (pglob->index < pglob->glob.gl_pathc) {
+   if (pglob->index < (size_t)pglob->glob.gl_pathc) {
php_glob_stream_path_split(pglob, 
pglob->glob.gl_pathv[pglob->index++], pglob->flags & GLOB_APPEND, &path 
TSRMLS_CC);
PHP_STRLCPY(ent->d_name, path, sizeof(ent->d_name), 
strlen(path));
return sizeof(php_stream_dirent);

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

[PHP-CVS] svn: /php/php-src/trunk/main/ SAPI.c main.c

2010-07-14 Thread Dmitry Stogov
dmitry   Wed, 14 Jul 2010 15:20:44 +

Revision: http://svn.php.net/viewvc?view=revision&revision=301263

Log:
Optimized defaut Content-Type HTTP header processing

Changed paths:
U   php/php-src/trunk/main/SAPI.c
U   php/php-src/trunk/main/main.c

Modified: php/php-src/trunk/main/SAPI.c
===
--- php/php-src/trunk/main/SAPI.c   2010-07-14 10:27:08 UTC (rev 301262)
+++ php/php-src/trunk/main/SAPI.c   2010-07-14 15:20:44 UTC (rev 301263)
@@ -224,35 +224,61 @@
 }


-SAPI_API char *sapi_get_default_content_type(TSRMLS_D)
+static inline char *get_default_content_type(uint prefix_len, uint *len 
TSRMLS_DC)
 {
char *mimetype, *charset, *content_type;
+   uint mimetype_len, charset_len;

-   mimetype = SG(default_mimetype) ? SG(default_mimetype) : 
SAPI_DEFAULT_MIMETYPE;
-   charset = SG(default_charset) ? SG(default_charset) : 
SAPI_DEFAULT_CHARSET;
+   if (SG(default_mimetype)) {
+   mimetype = SG(default_mimetype);
+   mimetype_len = strlen(SG(default_mimetype));
+   } else {
+   mimetype = SAPI_DEFAULT_MIMETYPE;
+   mimetype_len = sizeof(SAPI_DEFAULT_MIMETYPE) - 1;
+   }
+   if (SG(default_charset)) {
+   charset = SG(default_charset);
+   charset_len = strlen(SG(default_charset));
+   } else {
+   charset = SAPI_DEFAULT_CHARSET;
+   charset_len = sizeof(SAPI_DEFAULT_CHARSET) - 1;
+   }

-   if (strncasecmp(mimetype, "text/", 5) == 0 && *charset) {
-   int len = strlen(mimetype) + sizeof("; charset=") + 
strlen(charset); /* sizeof() includes \0 */
-   content_type = emalloc(len);
-   snprintf(content_type, len, "%s; charset=%s", mimetype, 
charset);
+   if (*charset && strncasecmp(mimetype, "text/", 5) == 0) {
+   char *p;
+
+   *len = prefix_len + mimetype_len + sizeof("; charset=") - 1 + 
charset_len;
+   content_type = (char*)emalloc(*len + 1);
+   p = content_type + prefix_len;
+   memcpy(p, mimetype, mimetype_len);
+   p += mimetype_len;
+   memcpy(p, "; charset=", sizeof("; charset=") - 1);
+   p += sizeof("; charset=") - 1;
+   memcpy(p, charset, charset_len + 1);
} else {
-   content_type = estrdup(mimetype);
+   *len = prefix_len + mimetype_len;
+   content_type = (char*)emalloc(*len + 1);
+   memcpy(content_type + prefix_len, mimetype, mimetype_len + 1);
}
return content_type;
 }


+SAPI_API char *sapi_get_default_content_type(TSRMLS_D)
+{
+   uint len;
+
+   return get_default_content_type(0, &len TSRMLS_CC);
+}
+
+
 SAPI_API void sapi_get_default_content_type_header(sapi_header_struct 
*default_header TSRMLS_DC)
 {
-   char *default_content_type = sapi_get_default_content_type(TSRMLS_C);
-   int default_content_type_len = strlen(default_content_type);
+uint len;

-   default_header->header_len = (sizeof("Content-type: ")-1) + 
default_content_type_len;
-   default_header->header = emalloc(default_header->header_len+1);
-   memcpy(default_header->header, "Content-type: ", sizeof("Content-type: 
"));
-   memcpy(default_header->header+sizeof("Content-type: ")-1, 
default_content_type, default_content_type_len);
-   default_header->header[default_header->header_len] = 0;
-   efree(default_content_type);
+   default_header->header = get_default_content_type(sizeof("Content-type: 
")-1, &len TSRMLS_CC);
+   default_header->header_len = len;
+   memcpy(default_header->header, "Content-type: ", sizeof("Content-type: 
") - 1);
 }

 /*
@@ -521,6 +547,27 @@
return r;
 }

+static void sapi_header_add_op(sapi_header_op_enum op, sapi_header_struct 
*sapi_header TSRMLS_DC)
+{
+   if (!sapi_module.header_handler ||
+   (SAPI_HEADER_ADD & sapi_module.header_handler(sapi_header, op, 
&SG(sapi_headers) TSRMLS_CC))) {
+   if (op == SAPI_HEADER_REPLACE) {
+   char *colon_offset = strchr(sapi_header->header, ':');
+
+   if (colon_offset) {
+   char sav = *colon_offset;
+
+   *colon_offset = 0;
+   
zend_llist_del_element(&SG(sapi_headers).headers, sapi_header->header, 
(int(*)(void*, void*))sapi_find_matching_header);
+   *colon_offset = sav;
+   }
+   }
+   zend_llist_add_element(&SG(sapi_headers).headers, (void *) 
sapi_header);
+   } else {
+   sapi_free_header(sapi_header);
+   }
+}
+
 SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg TSRMLS_DC)
 {
int retval;
@@ -577,8 +624,12 @@
header_line = estrndup(header_line, h