Browse Source

files are now resources, file.c is thread-safe, the le_ vars are no longer shared,

but they are accessible thru "php_file_le_socket(), php_file_le_uploads()..."
i also updated the ftp, pdf and file-upload stuff to match the new requirements.
@- Cleaned up File-Module (Thies)
experimetnal/RETURN_REF_PATCH
Thies C. Arntzen 27 years ago
parent
commit
b5c3c7bfc9
  1. 11
      ext/ftp/php_ftp.c
  2. 24
      ext/pdf/pdf.c
  3. 1172
      ext/standard/file.c
  4. 3
      ext/standard/file.h
  5. 7
      ext/standard/fsock.c
  6. 2
      main/fopen_wrappers.h
  7. 3
      main/php.h
  8. 7
      main/rfc1867.c

11
ext/ftp/php_ftp.c

@ -132,16 +132,7 @@ PHP_MINIT_FUNCTION(ftp)
}
#define FILEP(fp, pval) { \
int id, type; \
int le_fp; \
le_fp = php3i_get_le_fp(); \
convert_to_long(pval); \
id = (pval)->value.lval; \
(fp) = php3_list_find(id, &type); \
if (!(fp) || type != le_fp) { \
php_error(E_WARNING, "Unable to find fp %d", id); \
RETURN_FALSE; \
} \
ZEND_FETCH_RESOURCE(fp, FILE *, &pval, -1, "File-Handle", php_file_le_fopen()); \
}
/* {{{ proto int ftp_connect(string host [, int port])

24
ext/pdf/pdf.c

@ -206,6 +206,7 @@ PHP_MSHUTDOWN_FUNCTION(pdf){
}
/* {{{ proto bool pdf_set_info_creator(int info, string creator)
Fills the creator field of the info structure */
PHP_FUNCTION(pdf_set_info_creator) {
pval *arg1, *arg2;
@ -231,9 +232,11 @@ PHP_FUNCTION(pdf_set_info_creator) {
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool pdf_set_info_title(int info, string title)
Fills the title field of the info structure */
PHP_FUNCTION(pdf_set_info_title) {
pval *arg1, *arg2;
@ -259,9 +262,11 @@ PHP_FUNCTION(pdf_set_info_title) {
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool pdf_set_info_subject(int info, string subject)
Fills the subject field of the info structure */
PHP_FUNCTION(pdf_set_info_subject) {
pval *arg1, *arg2;
@ -287,9 +292,11 @@ PHP_FUNCTION(pdf_set_info_subject) {
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool pdf_set_info_author(int info, string author)
Fills the author field of the info structure */
PHP_FUNCTION(pdf_set_info_author) {
pval *arg1, *arg2;
@ -315,9 +322,11 @@ PHP_FUNCTION(pdf_set_info_author) {
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool pdf_set_info_keywords(int info, string keywords)
Fills the keywords field of the info structure */
PHP_FUNCTION(pdf_set_info_keywords) {
pval *arg1, *arg2;
@ -343,30 +352,25 @@ PHP_FUNCTION(pdf_set_info_keywords) {
RETURN_TRUE;
}
/* }}} */
/* {{{ proto int pdf_open(int filedesc)
Opens a new pdf document */
PHP_FUNCTION(pdf_open) {
pval *file;
pval **file;
pval *info;
int id, type;
FILE *fp;
PDF *pdf;
PDF_TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &file) == FAILURE) {
if (ARG_COUNT(ht) != 1 || getParametersEx(1, &file) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(file);
id=file->value.lval;
fp = php3_list_find(id,&type);
if (!fp || type!=php3i_get_le_fp()) {
php3_error(E_WARNING,"Unable to find file identifier %d (type=%d)",id, type);
RETURN_FALSE;
}
ZEND_FETCH_RESOURCE(fp, FILE *, file, -1, "File-Handle", php_file_le_fopen());
/* XXX should do anzend_list_addref for <fp> here! */
pdf = PDF_new();
if (0 > PDF_open_fp(pdf, fp)) {

1172
ext/standard/file.c
File diff suppressed because it is too large
View File

3
ext/standard/file.h

@ -69,6 +69,9 @@ PHP_FUNCTION(get_meta_tags);
PHP_FUNCTION(flock);
PHPAPI int _php3_set_sock_blocking(int socketd, int block);
PHPAPI int php_file_le_fopen(void);
PHPAPI int php_file_le_socket(void);
PHPAPI int php_file_le_uploads(void);
#define phpext_file_ptr file_module_ptr
#endif /* _FILE_H */

7
ext/standard/fsock.c

@ -284,7 +284,8 @@ static void _php3_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
(void *) &sockp) == SUCCESS) {
FREE_SOCK;
*sock = *sockp;
RETURN_LONG(php3_list_insert(sock, le_socket));
ZEND_REGISTER_RESOURCE(return_value,sock,php_file_le_socket());
return;
}
if (portno) {
@ -361,8 +362,8 @@ static void _php3_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
key, strlen(key) + 1, NULL);
}
if(key) efree(key);
id = php3_list_insert(sock,le_socket);
RETURN_LONG(id);
ZEND_REGISTER_RESOURCE(return_value,sock,php_file_le_socket());
}
/* }}} */

2
main/fopen_wrappers.h

@ -66,8 +66,6 @@
#define IS_SOCKET 1
#define BAD_URL 2
extern int le_socket; /* a list for open sockets */
extern PHPAPI FILE *php3_fopen_wrapper(char *filename, char *mode, int options, int *issock, int *socketd);
PHPAPI FILE *php3_fopen_for_parser(void);

3
main/php.h

@ -307,9 +307,6 @@ int module_startup_modules(void);
int module_global_startup_modules(void);
int module_global_shutdown_modules(void);
/* needed for modules only */
extern PHPAPI int php3i_get_le_fp(void);
/*from basic functions*/
extern PHPAPI int _php_error_log(int opt_err,char *message,char *opt,char *headers);

7
main/rfc1867.c

@ -20,14 +20,11 @@
#include <stdio.h>
#include "php.h"
#include "ext/standard/php3_standard.h"
#include "ext/standard/file.h" /* for php_file_le_uploads() */
#include "zend_globals.h"
#include "php_globals.h"
#include "rfc1867.h"
#ifndef THREAD_SAFE
extern int le_uploads; /* "borrowed" from file.c */
extern HashTable list;
#endif
#define NEW_BOUNDARY_CHECK 1
#define SAFE_RETURN { if (namebuf) efree(namebuf); if (filenamebuf) efree(filenamebuf); if (lbuf) efree(lbuf); return; }
@ -220,7 +217,7 @@ void php_mime_split(char *buf, int cnt, char *boundary)
}
bytes = fwrite(ptr, 1, loc - ptr - 4, fp);
fclose(fp);
php3_list_insert(fn,le_uploads); /* Tell PHP about the file so the destructor can unlink it later */
php3_list_insert(fn,php_file_le_uploads()); /* Tell PHP about the file so the destructor can unlink it later */
if (bytes < (loc - ptr - 4)) {
php_error(E_WARNING, "Only %d bytes were written, expected to write %ld", bytes, loc - ptr - 4);
}

Loading…
Cancel
Save