Skip to content

Commit 96cde18

Browse files
committed
Revert "made lsapi_main.c compatible with PHP7/phpng ."
This reverts commit 9fb816f. Not a security-related fix.
1 parent 9fb816f commit 96cde18

File tree

1 file changed

+26
-92
lines changed

1 file changed

+26
-92
lines changed

sapi/litespeed/lsapi_main.c

Lines changed: 26 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static int sapi_lsapi_ub_write(const char *str, uint str_length TSRMLS_DC)
155155

156156
/* {{{ sapi_lsapi_flush
157157
*/
158-
static void sapi_lsapi_flush( void * server_context TSRMLS_DC )
158+
static void sapi_lsapi_flush( void * server_context )
159159
{
160160
if ( lsapi_mode ) {
161161
if ( LSAPI_Flush() == -1) {
@@ -200,12 +200,7 @@ static char *sapi_lsapi_getenv( char * name, size_t name_len TSRMLS_DC )
200200
static int add_variable( const char * pKey, int keyLen, const char * pValue, int valLen,
201201
void * arg )
202202
{
203-
#if PHP_MAJOR_VERSION >= 7
204-
int filter_arg = (Z_ARR_P((zval *)arg) == Z_ARR(PG(http_globals)[TRACK_VARS_ENV]))
205-
? PARSE_ENV : PARSE_SERVER;
206-
#else
207-
int filter_arg = (arg == PG(http_globals)[TRACK_VARS_ENV])?PARSE_ENV:PARSE_SERVER;
208-
#endif
203+
int filter_arg = (arg == PG(http_globals)[TRACK_VARS_ENV])?PARSE_ENV:PARSE_SERVER;
209204
char * new_val = (char *) pValue;
210205
unsigned int new_val_len;
211206

@@ -243,45 +238,27 @@ static void litespeed_php_import_environment_variables(zval *array_ptr TSRMLS_DC
243238
size_t alloc_size = sizeof(buf);
244239
unsigned long nlen; /* ptrdiff_t is not portable */
245240

246-
#if PHP_MAJOR_VERSION >= 7
247-
if (Z_TYPE(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY &&
248-
Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_ENV]) &&
249-
zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_ENV])) > 0
241+
if (PG(http_globals)[TRACK_VARS_ENV] &&
242+
array_ptr != PG(http_globals)[TRACK_VARS_ENV] &&
243+
Z_TYPE_P(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY &&
244+
zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_ENV])) > 0
250245
) {
251-
zval_dtor(array_ptr);
252-
ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_ENV]);
246+
zval_dtor(array_ptr);
247+
*array_ptr = *PG(http_globals)[TRACK_VARS_ENV];
248+
INIT_PZVAL(array_ptr);
249+
zval_copy_ctor(array_ptr);
253250
return;
254-
} else if (Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY &&
255-
Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_SERVER]) &&
256-
zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER])) > 0
251+
} else if (PG(http_globals)[TRACK_VARS_SERVER] &&
252+
array_ptr != PG(http_globals)[TRACK_VARS_SERVER] &&
253+
Z_TYPE_P(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY &&
254+
zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])) > 0
257255
) {
258-
zval_dtor(array_ptr);
259-
ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_SERVER]);
256+
zval_dtor(array_ptr);
257+
*array_ptr = *PG(http_globals)[TRACK_VARS_SERVER];
258+
INIT_PZVAL(array_ptr);
259+
zval_copy_ctor(array_ptr);
260260
return;
261261
}
262-
#else
263-
if (PG(http_globals)[TRACK_VARS_ENV] &&
264-
array_ptr != PG(http_globals)[TRACK_VARS_ENV] &&
265-
Z_TYPE_P(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY &&
266-
zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_ENV])) > 0
267-
) {
268-
zval_dtor(array_ptr);
269-
*array_ptr = *PG(http_globals)[TRACK_VARS_ENV];
270-
INIT_PZVAL(array_ptr);
271-
zval_copy_ctor(array_ptr);
272-
return;
273-
} else if (PG(http_globals)[TRACK_VARS_SERVER] &&
274-
array_ptr != PG(http_globals)[TRACK_VARS_SERVER] &&
275-
Z_TYPE_P(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY &&
276-
zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])) > 0
277-
) {
278-
zval_dtor(array_ptr);
279-
*array_ptr = *PG(http_globals)[TRACK_VARS_SERVER];
280-
INIT_PZVAL(array_ptr);
281-
zval_copy_ctor(array_ptr);
282-
return;
283-
}
284-
#endif
285262

286263
for (env = environ; env != NULL && *env != NULL; env++) {
287264
p = strchr(*env, '=');
@@ -615,9 +592,6 @@ static int lsapi_module_main(int show_source TSRMLS_DC)
615592
static int alter_ini( const char * pKey, int keyLen, const char * pValue, int valLen,
616593
void * arg )
617594
{
618-
#if PHP_MAJOR_VERSION >= 7
619-
zend_string * psKey;
620-
#endif
621595
int type = ZEND_INI_PERDIR;
622596
if ( '\001' == *pKey ) {
623597
++pKey;
@@ -632,19 +606,9 @@ static int alter_ini( const char * pKey, int keyLen, const char * pValue, int va
632606
engine = 0;
633607
}
634608
else
635-
{
636-
#if PHP_MAJOR_VERSION >= 7
637-
psKey = STR_INIT( pKey, keyLen, 1 );
638-
zend_alter_ini_entry(psKey,
639-
(char *)pValue, valLen,
640-
type, PHP_INI_STAGE_ACTIVATE);
641-
STR_RELEASE( psKey );
642-
#else
643609
zend_alter_ini_entry((char *)pKey, keyLen,
644610
(char *)pValue, valLen,
645-
type, PHP_INI_STAGE_ACTIVATE);
646-
#endif
647-
}
611+
type, PHP_INI_STAGE_ACTIVATE);
648612
}
649613
return 1;
650614
}
@@ -785,9 +749,6 @@ static int cli_main( int argc, char * argv[] )
785749
char ** argend= &argv[argc];
786750
int ret = -1;
787751
int c;
788-
#if PHP_MAJOR_VERSION >= 7
789-
zend_string * psKey;
790-
#endif
791752
lsapi_mode = 0; /* enter CLI mode */
792753

793754
#ifdef PHP_WIN32
@@ -802,21 +763,12 @@ static int cli_main( int argc, char * argv[] )
802763

803764
zend_uv.html_errors = 0; /* tell the engine we're in non-html mode */
804765
CG(in_compilation) = 0; /* not initialized but needed for several options */
805-
#if PHP_MAJOR_VERSION < 7
806766
EG(uninitialized_zval_ptr) = NULL;
807-
#endif
767+
808768
for( ini = ini_defaults; *ini; ini+=2 ) {
809-
#if PHP_MAJOR_VERSION >= 7
810-
psKey = STR_INIT( *ini, strlen( *ini ), 1 );
811-
zend_alter_ini_entry( psKey,
812-
(char *)*(ini+1), strlen( *(ini+1) ),
813-
PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
814-
STR_RELEASE( psKey );
815-
#else
816769
zend_alter_ini_entry( (char *)*ini, strlen( *ini )+1,
817770
(char *)*(ini+1), strlen( *(ini+1) ),
818771
PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
819-
#endif
820772
}
821773

822774
while (( p < argend )&&(**p == '-' )) {
@@ -1196,11 +1148,7 @@ zend_module_entry litespeed_module_entry = {
11961148
static int add_associate_array( const char * pKey, int keyLen, const char * pValue, int valLen,
11971149
void * arg )
11981150
{
1199-
add_assoc_string_ex( (zval *)arg, (char *)pKey, keyLen+1, (char *)pValue
1200-
#if PHP_MAJOR_VERSION < 7
1201-
, 1
1202-
#endif
1203-
);
1151+
add_assoc_string_ex( (zval *)arg, (char *)pKey, keyLen+1, (char *)pValue, 1 );
12041152
return 1;
12051153
}
12061154

@@ -1254,11 +1202,7 @@ PHP_FUNCTION(litespeed_response_headers)
12541202
headerBuf[len] = 0;
12551203
if ( len ) {
12561204
while( isspace(*++p));
1257-
add_assoc_string_ex(return_value, headerBuf, len+1, p
1258-
#if PHP_MAJOR_VERSION < 7
1259-
, 1
1260-
#endif
1261-
);
1205+
add_assoc_string_ex(return_value, headerBuf, len+1, p, 1 );
12621206
}
12631207
}
12641208
}
@@ -1273,25 +1217,15 @@ PHP_FUNCTION(litespeed_response_headers)
12731217
Fetch all loaded module names */
12741218
PHP_FUNCTION(apache_get_modules)
12751219
{
1276-
static const char * mod_names[] =
1277-
{
1278-
"mod_rewrite", "mod_mime", "mod_headers", "mod_expires", NULL
1279-
};
1280-
const char **name = mod_names;
12811220
/* TODO: */
12821221
if (ZEND_NUM_ARGS() > 0) {
12831222
WRONG_PARAM_COUNT;
12841223
}
12851224
array_init(return_value);
1286-
while( *name )
1287-
{
1288-
add_next_index_string(return_value, *name
1289-
#if PHP_MAJOR_VERSION < 7
1290-
, 1
1291-
#endif
1292-
);
1293-
++name;
1294-
}
1225+
add_next_index_string(return_value, "mod_rewrite", 1);
1226+
add_next_index_string(return_value, "mod_mime", 1);
1227+
add_next_index_string(return_value, "mod_headers", 1);
1228+
add_next_index_string(return_value, "mod_expires", 1);
12951229
}
12961230
/* }}} */
12971231

0 commit comments

Comments
 (0)