From: Wez Furlong Date: Sat, 16 Mar 2002 01:34:52 +0000 (+0000) Subject: * formatting, plus remove some old fopen wrappers X-Git-Tag: php-4.3.0dev-ZendEngine2-Preview1~1372 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a184f5d1d361f699bab9cc9483c815302dd61be7;p=php * formatting, plus remove some old fopen wrappers --- diff --git a/ext/standard/file.c b/ext/standard/file.c index 30cbf8346d..593d943a19 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -379,7 +379,7 @@ PHP_FUNCTION(file) int target_len, len; zend_bool use_include_path = 0; zend_bool reached_eof = 0; - php_stream * stream; + php_stream *stream; /* Parse arguments */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", @@ -471,7 +471,7 @@ PHP_FUNCTION(tempnam) Create a temporary file that will be deleted automatically after use */ PHP_NAMED_FUNCTION(php_if_tmpfile) { - php_stream * stream; + php_stream *stream; if (ZEND_NUM_ARGS() != 0) { WRONG_PARAM_COUNT; @@ -493,7 +493,7 @@ PHP_NAMED_FUNCTION(php_if_tmpfile) PHP_FUNCTION(fgetwrapperdata) { zval **arg1; - php_stream * stream; + php_stream *stream; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { WRONG_PARAM_COUNT; @@ -517,7 +517,7 @@ PHP_NAMED_FUNCTION(php_if_fopen) { zval **arg1, **arg2, **arg3; int use_include_path = 0; - php_stream * stream; + php_stream *stream; switch(ZEND_NUM_ARGS()) { case 2: @@ -579,7 +579,7 @@ PHP_FUNCTION(popen) FILE *fp; char *p, *tmp = NULL; char *b, buf[1024]; - php_stream * stream; + php_stream *stream; if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; @@ -815,7 +815,7 @@ PHP_FUNCTION(socket_get_status) if (php_stream_is((php_stream*)what, PHP_STREAM_IS_SOCKET)) { - php_netstream_data_t * sock = PHP_NETSTREAM_DATA_FROM_STREAM((php_stream*)what); + php_netstream_data_t *sock = PHP_NETSTREAM_DATA_FROM_STREAM((php_stream*)what); add_assoc_bool(return_value, "timed_out", sock->timeout_event); add_assoc_bool(return_value, "blocked", sock->is_blocked); @@ -1109,7 +1109,7 @@ PHP_FUNCTION(set_file_buffer) { zval **arg1, **arg2; int ret, type, buff; - php_stream * stream; + php_stream *stream; FILE * fp; switch (ZEND_NUM_ARGS()) { @@ -1279,7 +1279,7 @@ PHP_FUNCTION(rmdir) /* }}} */ /* {{{ php_passthru_stream */ -static size_t php_passthru_stream(php_stream * stream TSRMLS_DC) +static size_t php_passthru_stream(php_stream *stream TSRMLS_DC) { size_t bcount = 0; int ready = 0; @@ -1332,7 +1332,7 @@ PHP_FUNCTION(readfile) zval **arg1, **arg2; int size=0; int use_include_path=0; - php_stream * stream; + php_stream *stream; /* check args */ switch (ZEND_NUM_ARGS()) { @@ -1644,7 +1644,7 @@ PHP_FUNCTION(copy) */ PHPAPI int php_copy_file(char *src, char *dest TSRMLS_DC) { - php_stream * srcstream = NULL, * deststream = NULL; + php_stream *srcstream = NULL, *deststream = NULL; int ret = FAILURE; srcstream = php_stream_open_wrapper(src, "rb", @@ -1673,7 +1673,7 @@ PHP_FUNCTION(fread) { zval **arg1, **arg2; int len, type; - php_stream * stream; + php_stream *stream; if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { WRONG_PARAM_COUNT; @@ -1715,7 +1715,7 @@ PHP_FUNCTION(fgetcsv) zval **fd, **bytes, **p_delim; int len, type; char *buf; - php_stream * stream; + php_stream *stream; switch(ZEND_NUM_ARGS()) { case 2: diff --git a/ext/standard/file.h b/ext/standard/file.h index eee46a9de9..13185513d9 100644 --- a/ext/standard/file.h +++ b/ext/standard/file.h @@ -90,7 +90,7 @@ typedef enum _php_meta_tags_token { } php_meta_tags_token; typedef struct _php_meta_tags_data { - php_stream * stream; + php_stream *stream; int ulc; int lc; char *input_buffer; diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c index b672e0087c..dfadc5e0fd 100644 --- a/ext/standard/fsock.c +++ b/ext/standard/fsock.c @@ -120,15 +120,15 @@ PHPAPI int php_lookup_hostname(const char *addr, struct in_addr *in) static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent) { - char * host; + char *host; int host_len; int port = -1; - zval * zerrno = NULL, * zerrstr = NULL; + zval *zerrno = NULL, *zerrstr = NULL; double timeout = 60; unsigned long conv; struct timeval tv; - char * hashkey = NULL; - php_stream * stream = NULL; + char *hashkey = NULL; + php_stream *stream = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|lzzd", &host, &host_len, &port, &zerrno, &zerrstr, &timeout) == FAILURE) { RETURN_FALSE; @@ -163,7 +163,7 @@ static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent) enum php_sslflags_t { php_ssl_none, php_ssl_v23, php_ssl_tls }; enum php_sslflags_t ssl_flags; struct { - char * proto; + char *proto; int protolen; int socktype; enum php_sslflags_t ssl_flags; diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c index 4c4b0543b1..ade1e86f36 100644 --- a/ext/standard/ftp_fopen_wrapper.c +++ b/ext/standard/ftp_fopen_wrapper.c @@ -66,7 +66,7 @@ #include "php_fopen_wrappers.h" -static int php_get_ftp_result(php_stream * stream) +static int php_get_ftp_result(php_stream *stream) { char tmp_line[513]; @@ -85,7 +85,7 @@ php_stream_wrapper php_stream_ftp_wrapper = { /* {{{ php_fopen_url_wrap_ftp */ -php_stream * php_stream_url_wrap_ftp(char * path, char * mode, int options, char ** opened_path TSRMLS_DC) +php_stream * php_stream_url_wrap_ftp(char *path, char *mode, int options, char **opened_path TSRMLS_DC) { php_stream *stream=NULL; php_url *resource=NULL; diff --git a/ext/standard/html.c b/ext/standard/html.c index 7cf5a25de3..09c6f537a4 100644 --- a/ext/standard/html.c +++ b/ext/standard/html.c @@ -37,7 +37,7 @@ enum entity_charset { cs_terminator, cs_8859_1, cs_cp1252, cs_8859_15, cs_utf_8, cs_big5, cs_gb2312, cs_big5hkscs, cs_sjis, cs_eucjp}; -typedef const char * entity_table_t; +typedef const char *entity_table_t; /* codepage 1252 is a Windows extension to iso-8859-1. */ static entity_table_t ent_cp_1252[] = { @@ -88,7 +88,7 @@ struct html_entity_map { enum entity_charset charset; /* charset identifier */ unsigned short basechar; /* char code at start of table */ unsigned short endchar; /* last char code in the table */ - entity_table_t * table; /* the table of mappings */ + entity_table_t *table; /* the table of mappings */ }; static const struct html_entity_map entity_map[] = { @@ -106,7 +106,7 @@ static const struct html_entity_map entity_map[] = { }; static const struct { - const char * codeset; + const char *codeset; enum entity_charset charset; } charset_map[] = { { "ISO-8859-1", cs_8859_1 }, @@ -125,7 +125,7 @@ static const struct { static const struct { unsigned short charcode; - char * entity; + char *entity; int entitylen; int flags; } basic_entities[] = { @@ -141,10 +141,10 @@ static const struct { /* {{{ get_next_char */ inline static unsigned short get_next_char(enum entity_charset charset, - unsigned char * str, - int * newpos, - unsigned char * mbseq, - int * mbseqlen + unsigned char *str, + int *newpos, + unsigned char *mbseq, + int *mbseqlen ) { int pos = *newpos; @@ -341,7 +341,7 @@ inline static unsigned short get_next_char(enum entity_charset charset, /* {{{ entity_charset determine_charset * returns the charset identifier based on current locale or a hint. * defaults to iso-8859-1 */ -static enum entity_charset determine_charset(char * charset_hint) +static enum entity_charset determine_charset(char *charset_hint) { int i; enum entity_charset charset = cs_8859_1; @@ -360,8 +360,8 @@ static enum entity_charset determine_charset(char * charset_hint) if (charset_hint == NULL) { /* try to figure out the charset from the locale */ - char * localename; - char * dot, * at; + char *localename; + char *dot, *at; /* lang[_territory][.codeset][@modifier] */ localename = setlocale(LC_CTYPE, NULL); @@ -501,7 +501,7 @@ PHPAPI char *php_escape_html_entities(unsigned char *old, int oldlen, int *newle if (all) { /* look for a match in the maps for this charset */ - unsigned char * rep; + unsigned char *rep; for (j=0; entity_map[j].charset != cs_terminator; j++) { diff --git a/ext/standard/html.h b/ext/standard/html.h index 5f122cbc6e..0f264328e9 100644 --- a/ext/standard/html.h +++ b/ext/standard/html.h @@ -36,6 +36,6 @@ PHP_FUNCTION(htmlentities); PHP_FUNCTION(html_entity_decode); PHP_FUNCTION(get_html_translation_table); -PHPAPI char *php_escape_html_entities(unsigned char *old, int oldlen, int *newlen, int all, int quote_style, char * hint_charset); +PHPAPI char *php_escape_html_entities(unsigned char *old, int oldlen, int *newlen, int all, int quote_style, char *hint_charset); #endif /* HTML_H */ diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c index 41ee9d7d54..9cada1fb52 100644 --- a/ext/standard/http_fopen_wrapper.c +++ b/ext/standard/http_fopen_wrapper.c @@ -70,21 +70,20 @@ #define HTTP_HEADER_BLOCK_SIZE 1024 -#if HAVE_PHP_STREAM -php_stream * php_stream_url_wrap_http(char * path, char * mode, int options, char ** opened_path TSRMLS_DC) +php_stream *php_stream_url_wrap_http(char *path, char *mode, int options, char **opened_path TSRMLS_DC) { - php_stream * stream = NULL; - php_url * resource = NULL; + php_stream *stream = NULL; + php_url *resource = NULL; int use_ssl; - char * scratch = NULL; - char * tmp = NULL; + char *scratch = NULL; + char *tmp = NULL; int scratch_len = 0; int body = 0; char location[HTTP_HEADER_BLOCK_SIZE]; - zval * response_header = NULL; + zval *response_header = NULL; int reqok = 0; - char * http_header_line = NULL; + char *http_header_line = NULL; char tmp_line[128]; resource = php_url_parse(path); @@ -180,7 +179,7 @@ php_stream * php_stream_url_wrap_http(char * path, char * mode, int options, cha /* get response header */ if (php_stream_gets(stream, tmp_line, sizeof(tmp_line)-1) != NULL) { - zval * http_response; + zval *http_response; MAKE_STD_ZVAL(http_response); if (strncmp(tmp_line + 8, " 200 ", 5) == 0) @@ -207,7 +206,7 @@ php_stream * php_stream_url_wrap_http(char * path, char * mode, int options, cha while (!body && !php_stream_eof(stream)) { if (php_stream_gets(stream, http_header_line, HTTP_HEADER_BLOCK_SIZE-1) != NULL) { - char * p; + char *p; int found_eol = 0; int http_header_line_length; @@ -231,7 +230,7 @@ php_stream * php_stream_url_wrap_http(char * path, char * mode, int options, cha if (http_header_line[0] == '\0') body = 1; else { - zval * http_header; + zval *http_header; MAKE_STD_ZVAL(http_header); @@ -299,7 +298,7 @@ out: stream->wrapperdata = response_header; if (response_header) { - zval * sym; + zval *sym; MAKE_STD_ZVAL(sym); *sym = *response_header; zval_copy_ctor(sym); @@ -315,265 +314,6 @@ php_stream_wrapper php_stream_http_wrapper = { NULL }; -#else - - - -/* {{{ php_fopen_url_wrap_http - */ -FILE *php_fopen_url_wrap_http(const char *path, char *mode, int options, int *issock, int *socketd, char **opened_path TSRMLS_DC) -{ - FILE *fp=NULL; - php_url *resource=NULL; - char tmp_line[128]; - char location[512]; - char hdr_line[8192]; - int body = 0; - char *scratch; - unsigned char *tmp; - int len; - int reqok = 0; - zval *response_header; - char *http_header_line; - int http_header_line_length, http_header_line_size; - - resource = php_url_parse((char *) path); - if (resource == NULL) { - php_error(E_WARNING, "Invalid URL specified, %s", path); - *issock = BAD_URL; - return NULL; - } - /* use port 80 if one wasn't specified */ - if (resource->port == 0) { - resource->port = 80; - } - - *socketd = php_hostconnect(resource->host, resource->port, SOCK_STREAM, 0); - if (*socketd == -1) { - SOCK_FCLOSE(*socketd); - *socketd = 0; - php_url_free(resource); - return NULL; - } -#if 0 - if ((fp = fdopen(*socketd, "r+")) == NULL) { - php_url_free(resource); - return NULL; - } -#ifdef HAVE_SETVBUF - if ((setvbuf(fp, NULL, _IONBF, 0)) != 0) { - php_url_free(resource); - return NULL; - } -#endif -#endif /*win32 */ - - strcpy(hdr_line, "GET "); - - /* tell remote http which file to get */ - if (resource->path != NULL && *resource->path) { - strlcat(hdr_line, resource->path, sizeof(hdr_line)); - } else { - strlcat(hdr_line, "/", sizeof(hdr_line)); - } - /* append the query string, if any */ - if (resource->query != NULL) { - strlcat(hdr_line, "?", sizeof(hdr_line)); - strlcat(hdr_line, resource->query, sizeof(hdr_line)); - } - strlcat(hdr_line, " HTTP/1.0\r\n", sizeof(hdr_line)); - SOCK_WRITE(hdr_line, *socketd); - - /* send authorization header if we have user/pass */ - if (resource->user != NULL && resource->pass != NULL) { - scratch = (char *) emalloc(strlen(resource->user) + strlen(resource->pass) + 2); - if (!scratch) { - php_url_free(resource); - return NULL; - } - strcpy(scratch, resource->user); - strcat(scratch, ":"); - strcat(scratch, resource->pass); - tmp = php_base64_encode((unsigned char *)scratch, strlen(scratch), NULL); - - if (snprintf(hdr_line, sizeof(hdr_line), - "Authorization: Basic %s\r\n", tmp) > 0) { - SOCK_WRITE(hdr_line, *socketd); - } - - efree(scratch); - efree(tmp); - } - /* if the user has configured who they are, send a From: line */ - if (cfg_get_string("from", &scratch) == SUCCESS) { - if (snprintf(hdr_line, sizeof(hdr_line), - "From: %s\r\n", scratch) > 0) { - SOCK_WRITE(hdr_line, *socketd); - } - - } - /* send a Host: header so name-based virtual hosts work */ - if (resource->port != 80) { - len = snprintf(hdr_line, sizeof(hdr_line), - "Host: %s:%i\r\n", resource->host, resource->port); - } else { - len = snprintf(hdr_line, sizeof(hdr_line), - "Host: %s\r\n", resource->host); - } - if(len > sizeof(hdr_line) - 1) { - len = sizeof(hdr_line) - 1; - } - if (len > 0) { - SOCK_WRITE(hdr_line, *socketd); - } - - /* identify ourselves and end the headers */ - SOCK_WRITE("User-Agent: PHP/" PHP_VERSION "\r\n\r\n", *socketd); - - body = 0; - location[0] = '\0'; - - MAKE_STD_ZVAL(response_header); - array_init(response_header); - - if (!SOCK_FEOF(*socketd)) { - /* get response header */ - if (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, *socketd) != NULL) { - zval *http_response; - - MAKE_STD_ZVAL(http_response); - if (strncmp(tmp_line + 8, " 200 ", 5) == 0) { - reqok = 1; - } - Z_STRLEN_P(http_response) = strlen(tmp_line); - Z_STRVAL_P(http_response) = estrndup(tmp_line, Z_STRLEN_P(http_response)); - if (Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=='\n') { - Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=0; - Z_STRLEN_P(http_response)--; - if (Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=='\r') { - Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=0; - Z_STRLEN_P(http_response)--; - } - } - Z_TYPE_P(http_response) = IS_STRING; - zend_hash_next_index_insert(Z_ARRVAL_P(response_header), &http_response, sizeof(zval *), NULL); - } - } - - - /* Read past HTTP headers */ - while (!body && !SOCK_FEOF(*socketd)) { - http_header_line = emalloc(HTTP_HEADER_BLOCK_SIZE); - http_header_line_size = HTTP_HEADER_BLOCK_SIZE; - http_header_line_length = 0; - if (SOCK_FGETS(http_header_line, HTTP_HEADER_BLOCK_SIZE-1, *socketd) != NULL) { - char *p; - zend_bool found_eol=0; - zval *http_header; - - http_header_line[HTTP_HEADER_BLOCK_SIZE-1] = '\0'; - - do { - p = http_header_line+http_header_line_length; - while (*p) { - while (*p == '\n' || *p == '\r') { - *p = '\0'; - p--; - found_eol=1; - } - if (found_eol) { - break; - } - p++; - } - if (!found_eol) { - http_header_line_size += HTTP_HEADER_BLOCK_SIZE; - http_header_line_length += HTTP_HEADER_BLOCK_SIZE-1; - http_header_line = erealloc(http_header_line, http_header_line_size); - if (SOCK_FGETS(http_header_line+http_header_line_length, HTTP_HEADER_BLOCK_SIZE-1, *socketd)==NULL) { - http_header_line[http_header_line_length] = 0; - break; - } - } else { - http_header_line_length = p-http_header_line+1; - } - } while (!found_eol); - - if (!strncasecmp(http_header_line, "Location: ", 10)) { - strlcpy(location, http_header_line + 10, sizeof(location)); - } - - if (http_header_line[0] == '\0') { - body = 1; - } - - if (http_header_line_length>0) { - MAKE_STD_ZVAL(http_header); - Z_STRVAL_P(http_header) = http_header_line; - Z_STRLEN_P(http_header) = http_header_line_length; - Z_TYPE_P(http_header) = IS_STRING; - zend_hash_next_index_insert(Z_ARRVAL_P(response_header), &http_header, sizeof(zval *), NULL); - } else { - efree(http_header_line); - } - } - } - - if (!reqok) { - SOCK_FCLOSE(*socketd); - *socketd = 0; - if (location[0] != '\0') { - zval **response_header_new, *entry, **entryp; - char new_path[512]; - - *new_path='\0'; - if (strlen(location)<8 || strncasecmp(location, "http://", 7)) { - strcpy(new_path, "http://"); - strlcat(new_path, resource->host, sizeof(new_path)); - if (resource->port != 80) { - snprintf(new_path+strlen(new_path), sizeof(new_path)-strlen(new_path)-1, ":%d", resource->port); - } - if (*location != '/') { - php_dirname(resource->path, strlen(resource->path)); - snprintf (new_path+strlen(new_path), sizeof(new_path)-strlen(new_path)-1, "%s/", resource->path); - } - strlcat(new_path, location, sizeof(new_path)); - } - else { - strlcpy(new_path, location, sizeof(new_path)); - } - php_url_free(resource); - fp = php_fopen_url_wrap_http(new_path, mode, options, issock, socketd, opened_path TSRMLS_CC); - if (zend_hash_find(EG(active_symbol_table), "http_response_header", sizeof("http_response_header"), (void **) &response_header_new) == SUCCESS) { - entryp = &entry; - MAKE_STD_ZVAL(entry); - ZVAL_EMPTY_STRING(entry); - zend_hash_next_index_insert(Z_ARRVAL_P(response_header), entryp, sizeof(zval *), NULL); - zend_hash_internal_pointer_reset(Z_ARRVAL_PP(response_header_new)); - while (zend_hash_get_current_data(Z_ARRVAL_PP(response_header_new), (void **)&entryp) == SUCCESS) { - zval_add_ref(entryp); - zend_hash_next_index_insert(Z_ARRVAL_P(response_header), entryp, sizeof(zval *), NULL); - zend_hash_move_forward(Z_ARRVAL_PP(response_header_new)); - } - } - goto out; - } else { - php_url_free(resource); - fp = NULL; - goto out; - } - } - php_url_free(resource); - *issock = 1; - out: - { - ZEND_SET_SYMBOL(EG(active_symbol_table), "http_response_header", response_header); - } - return (fp); -} -/* }}} */ - -#endif /* * Local variables: diff --git a/ext/standard/php_fopen_wrappers.h b/ext/standard/php_fopen_wrappers.h index 1cad9777c9..0d235b945d 100644 --- a/ext/standard/php_fopen_wrappers.h +++ b/ext/standard/php_fopen_wrappers.h @@ -23,8 +23,8 @@ #ifndef PHP_FOPEN_WRAPPERS_H #define PHP_FOPEN_WRAPPERS_H -php_stream * php_stream_url_wrap_http(char * path, char * mode, int options, char ** opened_path TSRMLS_DC); -php_stream * php_stream_url_wrap_ftp(char * path, char * mode, int options, char ** opened_path TSRMLS_DC); +php_stream *php_stream_url_wrap_http(char *path, char *mode, int options, char **opened_path TSRMLS_DC); +php_stream *php_stream_url_wrap_ftp(char *path, char *mode, int options, char **opened_path TSRMLS_DC); php_stream_wrapper php_stream_http_wrapper; php_stream_wrapper php_stream_ftp_wrapper; php_stream_wrapper php_stream_php_wrapper; diff --git a/ext/standard/php_image.h b/ext/standard/php_image.h index 3046c8cd62..3b54fdc1c3 100644 --- a/ext/standard/php_image.h +++ b/ext/standard/php_image.h @@ -45,6 +45,6 @@ typedef enum } image_filetype; /* }}} */ -extern int php_getimagetype(php_stream * stream, char *filetype); +extern int php_getimagetype(php_stream *stream, char *filetype); #endif /* PHP_IMAGE_H */