Skip to content

Declare main constants in stubs - part 3 #9731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2121,9 +2121,6 @@ zend_result php_module_startup(sapi_module_struct *sf, zend_module_entry *additi
REGISTER_MAIN_STRINGL_CONSTANT("PHP_BINARY", "", 0, CONST_PERSISTENT | CONST_CS | CONST_NO_FILE_CACHE);
}

php_output_register_constants();
php_rfc1867_register_constants();

/* this will read in php.ini, set up the configuration parameters,
load zend extensions and register php function extensions
to be loaded later */
Expand Down
108 changes: 108 additions & 0 deletions main/main.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,111 @@
*/
const PHP_WINDOWS_NT_WORKSTATION = UNKNOWN;
#endif

/**
* @var int
* @cvalue PHP_OUTPUT_HANDLER_START
*/
const PHP_OUTPUT_HANDLER_START = UNKNOWN;
/**
* @var int
* @cvalue PHP_OUTPUT_HANDLER_WRITE
*/
const PHP_OUTPUT_HANDLER_WRITE = UNKNOWN;
/**
* @var int
* @cvalue PHP_OUTPUT_HANDLER_FLUSH
*/
const PHP_OUTPUT_HANDLER_FLUSH = UNKNOWN;
/**
* @var int
* @cvalue PHP_OUTPUT_HANDLER_CLEAN
*/
const PHP_OUTPUT_HANDLER_CLEAN = UNKNOWN;
/**
* @var int
* @cvalue PHP_OUTPUT_HANDLER_FINAL
*/
const PHP_OUTPUT_HANDLER_FINAL = UNKNOWN;
/**
* @var int
* @cvalue PHP_OUTPUT_HANDLER_WRITE
*/
const PHP_OUTPUT_HANDLER_CONT = UNKNOWN;
/**
* @var int
* @cvalue PHP_OUTPUT_HANDLER_FINAL
*/
const PHP_OUTPUT_HANDLER_END = UNKNOWN;

/**
* @var int
* @cvalue PHP_OUTPUT_HANDLER_CLEANABLE
*/
const PHP_OUTPUT_HANDLER_CLEANABLE = UNKNOWN;
/**
* @var int
* @cvalue PHP_OUTPUT_HANDLER_FLUSHABLE
*/
const PHP_OUTPUT_HANDLER_FLUSHABLE = UNKNOWN;
/**
* @var int
* @cvalue PHP_OUTPUT_HANDLER_REMOVABLE
*/
const PHP_OUTPUT_HANDLER_REMOVABLE = UNKNOWN;
/**
* @var int
* @cvalue PHP_OUTPUT_HANDLER_STDFLAGS
*/
const PHP_OUTPUT_HANDLER_STDFLAGS = UNKNOWN;
/**
* @var int
* @cvalue PHP_OUTPUT_HANDLER_STARTED
*/
const PHP_OUTPUT_HANDLER_STARTED = UNKNOWN;
/**
* @var int
* @cvalue PHP_OUTPUT_HANDLER_DISABLED
*/
const PHP_OUTPUT_HANDLER_DISABLED = UNKNOWN;

/**
* @var int
* @cvalue PHP_UPLOAD_ERROR_OK
*/
const UPLOAD_ERR_OK = UNKNOWN;
/**
* @var int
* @cvalue PHP_UPLOAD_ERROR_A
*/
const UPLOAD_ERR_INI_SIZE = UNKNOWN;
/**
* @var int
* @cvalue PHP_UPLOAD_ERROR_B
*/
const UPLOAD_ERR_FORM_SIZE = UNKNOWN;
/**
* @var int
* @cvalue PHP_UPLOAD_ERROR_C
*/
const UPLOAD_ERR_PARTIAL = UNKNOWN;
/**
* @var int
* @cvalue PHP_UPLOAD_ERROR_D
*/
const UPLOAD_ERR_NO_FILE = UNKNOWN;
/**
* @var int
* @cvalue PHP_UPLOAD_ERROR_E
*/
const UPLOAD_ERR_NO_TMP_DIR = UNKNOWN;
/**
* @var int
* @cvalue PHP_UPLOAD_ERROR_F
*/
const UPLOAD_ERR_CANT_WRITE = UNKNOWN;
/**
* @var int
* @cvalue PHP_UPLOAD_ERROR_X
*/
const UPLOAD_ERR_EXTENSION = UNKNOWN;
23 changes: 22 additions & 1 deletion main/main_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 0 additions & 20 deletions main/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,26 +202,6 @@ PHPAPI void php_output_deactivate(void)
}
/* }}} */

/* {{{ void php_output_register_constants() */
PHPAPI void php_output_register_constants(void)
{
REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_START", PHP_OUTPUT_HANDLER_START, CONST_CS | CONST_PERSISTENT);
REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_WRITE", PHP_OUTPUT_HANDLER_WRITE, CONST_CS | CONST_PERSISTENT);
REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_FLUSH", PHP_OUTPUT_HANDLER_FLUSH, CONST_CS | CONST_PERSISTENT);
REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_CLEAN", PHP_OUTPUT_HANDLER_CLEAN, CONST_CS | CONST_PERSISTENT);
REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_FINAL", PHP_OUTPUT_HANDLER_FINAL, CONST_CS | CONST_PERSISTENT);
REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_CONT", PHP_OUTPUT_HANDLER_WRITE, CONST_CS | CONST_PERSISTENT);
REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_END", PHP_OUTPUT_HANDLER_FINAL, CONST_CS | CONST_PERSISTENT);

REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_CLEANABLE", PHP_OUTPUT_HANDLER_CLEANABLE, CONST_CS | CONST_PERSISTENT);
REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_FLUSHABLE", PHP_OUTPUT_HANDLER_FLUSHABLE, CONST_CS | CONST_PERSISTENT);
REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_REMOVABLE", PHP_OUTPUT_HANDLER_REMOVABLE, CONST_CS | CONST_PERSISTENT);
REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_STDFLAGS", PHP_OUTPUT_HANDLER_STDFLAGS, CONST_CS | CONST_PERSISTENT);
REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_STARTED", PHP_OUTPUT_HANDLER_STARTED, CONST_CS | CONST_PERSISTENT);
REGISTER_MAIN_LONG_CONSTANT("PHP_OUTPUT_HANDLER_DISABLED", PHP_OUTPUT_HANDLER_DISABLED, CONST_CS | CONST_PERSISTENT);
}
/* }}} */

/* {{{ void php_output_set_status(int status)
* Used by SAPIs to disable output */
PHPAPI void php_output_set_status(int status)
Expand Down
2 changes: 0 additions & 2 deletions main/php_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ PHPAPI void php_output_startup(void);
/* MSHUTDOWN */
PHPAPI void php_output_shutdown(void);

PHPAPI void php_output_register_constants(void);

/* RINIT */
PHPAPI int php_output_activate(void);
/* RSHUTDOWN */
Expand Down
43 changes: 10 additions & 33 deletions main/rfc1867.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,6 @@ static void safe_php_register_variable(char *var, char *strval, size_t val_len,
/* The longest anonymous name */
#define MAX_SIZE_ANONNAME 33

/* Errors */
#define UPLOAD_ERROR_OK 0 /* File upload successful */
#define UPLOAD_ERROR_A 1 /* Uploaded file exceeded upload_max_filesize */
#define UPLOAD_ERROR_B 2 /* Uploaded file exceeded MAX_FILE_SIZE */
#define UPLOAD_ERROR_C 3 /* Partially uploaded */
#define UPLOAD_ERROR_D 4 /* No file uploaded */
#define UPLOAD_ERROR_E 6 /* Missing /tmp or similar directory */
#define UPLOAD_ERROR_F 7 /* Failed to write file to disk */
#define UPLOAD_ERROR_X 8 /* File upload stopped by extension */

void php_rfc1867_register_constants(void) /* {{{ */
{
REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_OK", UPLOAD_ERROR_OK, CONST_CS | CONST_PERSISTENT);
REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_INI_SIZE", UPLOAD_ERROR_A, CONST_CS | CONST_PERSISTENT);
REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_FORM_SIZE", UPLOAD_ERROR_B, CONST_CS | CONST_PERSISTENT);
REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_PARTIAL", UPLOAD_ERROR_C, CONST_CS | CONST_PERSISTENT);
REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_NO_FILE", UPLOAD_ERROR_D, CONST_CS | CONST_PERSISTENT);
REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_NO_TMP_DIR", UPLOAD_ERROR_E, CONST_CS | CONST_PERSISTENT);
REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_CANT_WRITE", UPLOAD_ERROR_F, CONST_CS | CONST_PERSISTENT);
REGISTER_MAIN_LONG_CONSTANT("UPLOAD_ERR_EXTENSION", UPLOAD_ERROR_X, CONST_CS | CONST_PERSISTENT);
}
/* }}} */

static void normalize_protected_variable(char *varname) /* {{{ */
{
char *s = varname, *index = NULL, *indexend = NULL, *p;
Expand Down Expand Up @@ -979,7 +956,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
#if DEBUG_FILE_UPLOAD
sapi_module.sapi_error(E_NOTICE, "No file uploaded");
#endif
cancel_upload = UPLOAD_ERROR_D;
cancel_upload = PHP_UPLOAD_ERROR_D;
}

offset = 0;
Expand All @@ -998,7 +975,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
upload_cnt--;
if (fd == -1) {
sapi_module.sapi_error(E_WARNING, "File upload error - unable to create a temporary file");
cancel_upload = UPLOAD_ERROR_E;
cancel_upload = PHP_UPLOAD_ERROR_E;
}
}
}
Expand All @@ -1014,7 +991,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
event_file_data.length = blen;
event_file_data.newlength = &blen;
if (php_rfc1867_callback(MULTIPART_EVENT_FILE_DATA, &event_file_data, &event_extra_data) == FAILURE) {
cancel_upload = UPLOAD_ERROR_X;
cancel_upload = PHP_UPLOAD_ERROR_X;
continue;
}
}
Expand All @@ -1023,12 +1000,12 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
#if DEBUG_FILE_UPLOAD
sapi_module.sapi_error(E_NOTICE, "upload_max_filesize of " ZEND_LONG_FMT " bytes exceeded - file [%s=%s] not saved", PG(upload_max_filesize), param, filename);
#endif
cancel_upload = UPLOAD_ERROR_A;
cancel_upload = PHP_UPLOAD_ERROR_A;
} else if (max_file_size && ((zend_long)(total_bytes+blen) > max_file_size)) {
#if DEBUG_FILE_UPLOAD
sapi_module.sapi_error(E_NOTICE, "MAX_FILE_SIZE of %" PRId64 " bytes exceeded - file [%s=%s] not saved", max_file_size, param, filename);
#endif
cancel_upload = UPLOAD_ERROR_B;
cancel_upload = PHP_UPLOAD_ERROR_B;
} else if (blen > 0) {
#ifdef PHP_WIN32
wlen = write(fd, buff, (unsigned int)blen);
Expand All @@ -1041,12 +1018,12 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
#if DEBUG_FILE_UPLOAD
sapi_module.sapi_error(E_NOTICE, "write() failed - %s", strerror(errno));
#endif
cancel_upload = UPLOAD_ERROR_F;
cancel_upload = PHP_UPLOAD_ERROR_F;
} else if (wlen < blen) {
#if DEBUG_FILE_UPLOAD
sapi_module.sapi_error(E_NOTICE, "Only %zd bytes were written, expected to write %zd", wlen, blen);
#endif
cancel_upload = UPLOAD_ERROR_F;
cancel_upload = PHP_UPLOAD_ERROR_F;
} else {
total_bytes += wlen;
}
Expand All @@ -1065,7 +1042,7 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
#if DEBUG_FILE_UPLOAD
sapi_module.sapi_error(E_NOTICE, "Missing mime boundary at the end of the data for file %s", filename[0] != '\0' ? filename : "");
#endif
cancel_upload = UPLOAD_ERROR_C;
cancel_upload = PHP_UPLOAD_ERROR_C;
}
#if DEBUG_FILE_UPLOAD
if (filename[0] != '\0' && total_bytes == 0 && !cancel_upload) {
Expand All @@ -1080,13 +1057,13 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
event_file_end.temp_filename = temp_filename ? ZSTR_VAL(temp_filename) : NULL;
event_file_end.cancel_upload = cancel_upload;
if (php_rfc1867_callback(MULTIPART_EVENT_FILE_END, &event_file_end, &event_extra_data) == FAILURE) {
cancel_upload = UPLOAD_ERROR_X;
cancel_upload = PHP_UPLOAD_ERROR_X;
}
}

if (cancel_upload) {
if (temp_filename) {
if (cancel_upload != UPLOAD_ERROR_E) { /* file creation failed */
if (cancel_upload != PHP_UPLOAD_ERROR_E) { /* file creation failed */
unlink(ZSTR_VAL(temp_filename));
}
zend_string_release_ex(temp_filename, 0);
Expand Down
11 changes: 10 additions & 1 deletion main/rfc1867.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
#define MULTIPART_EVENT_FILE_END 4
#define MULTIPART_EVENT_END 5

/* Errors */
#define PHP_UPLOAD_ERROR_OK 0 /* File upload successful */
#define PHP_UPLOAD_ERROR_A 1 /* Uploaded file exceeded upload_max_filesize */
#define PHP_UPLOAD_ERROR_B 2 /* Uploaded file exceeded MAX_FILE_SIZE */
#define PHP_UPLOAD_ERROR_C 3 /* Partially uploaded */
#define PHP_UPLOAD_ERROR_D 4 /* No file uploaded */
#define PHP_UPLOAD_ERROR_E 6 /* Missing /tmp or similar directory */
#define PHP_UPLOAD_ERROR_F 7 /* Failed to write file to disk */
#define PHP_UPLOAD_ERROR_X 8 /* File upload stopped by extension */

typedef struct _multipart_event_start {
size_t content_length;
} multipart_event_start;
Expand Down Expand Up @@ -73,7 +83,6 @@ typedef char* (*php_rfc1867_basename_t)(const zend_encoding *encoding, char *str
SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler);

PHPAPI void destroy_uploaded_files_hash(void);
void php_rfc1867_register_constants(void);
extern PHPAPI int (*php_rfc1867_callback)(unsigned int event, void *event_data, void **extra);

SAPI_API void php_rfc1867_set_multibyte_callbacks(
Expand Down