Skip to content

Commit 9fb816f

Browse files
author
George Wang
committed
made lsapi_main.c compatible with PHP7/phpng .
1 parent 98b2286 commit 9fb816f

File tree

1 file changed

+92
-26
lines changed

1 file changed

+92
-26
lines changed

sapi/litespeed/lsapi_main.c

Lines changed: 92 additions & 26 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 )
158+
static void sapi_lsapi_flush( void * server_context TSRMLS_DC )
159159
{
160160
if ( lsapi_mode ) {
161161
if ( LSAPI_Flush() == -1) {
@@ -200,7 +200,12 @@ 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-
int filter_arg = (arg == PG(http_globals)[TRACK_VARS_ENV])?PARSE_ENV:PARSE_SERVER;
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
204209
char * new_val = (char *) pValue;
205210
unsigned int new_val_len;
206211

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

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
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
245250
) {
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);
251+
zval_dtor(array_ptr);
252+
ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_ENV]);
250253
return;
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
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
255257
) {
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);
258+
zval_dtor(array_ptr);
259+
ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_SERVER]);
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
262285

263286
for (env = environ; env != NULL && *env != NULL; env++) {
264287
p = strchr(*env, '=');
@@ -592,6 +615,9 @@ static int lsapi_module_main(int show_source TSRMLS_DC)
592615
static int alter_ini( const char * pKey, int keyLen, const char * pValue, int valLen,
593616
void * arg )
594617
{
618+
#if PHP_MAJOR_VERSION >= 7
619+
zend_string * psKey;
620+
#endif
595621
int type = ZEND_INI_PERDIR;
596622
if ( '\001' == *pKey ) {
597623
++pKey;
@@ -606,9 +632,19 @@ static int alter_ini( const char * pKey, int keyLen, const char * pValue, int va
606632
engine = 0;
607633
}
608634
else
609-
zend_alter_ini_entry((char *)pKey, keyLen,
635+
{
636+
#if PHP_MAJOR_VERSION >= 7
637+
psKey = STR_INIT( pKey, keyLen, 1 );
638+
zend_alter_ini_entry(psKey,
610639
(char *)pValue, valLen,
611640
type, PHP_INI_STAGE_ACTIVATE);
641+
STR_RELEASE( psKey );
642+
#else
643+
zend_alter_ini_entry((char *)pKey, keyLen,
644+
(char *)pValue, valLen,
645+
type, PHP_INI_STAGE_ACTIVATE);
646+
#endif
647+
}
612648
}
613649
return 1;
614650
}
@@ -749,6 +785,9 @@ static int cli_main( int argc, char * argv[] )
749785
char ** argend= &argv[argc];
750786
int ret = -1;
751787
int c;
788+
#if PHP_MAJOR_VERSION >= 7
789+
zend_string * psKey;
790+
#endif
752791
lsapi_mode = 0; /* enter CLI mode */
753792

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

764803
zend_uv.html_errors = 0; /* tell the engine we're in non-html mode */
765804
CG(in_compilation) = 0; /* not initialized but needed for several options */
805+
#if PHP_MAJOR_VERSION < 7
766806
EG(uninitialized_zval_ptr) = NULL;
767-
807+
#endif
768808
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
769816
zend_alter_ini_entry( (char *)*ini, strlen( *ini )+1,
770817
(char *)*(ini+1), strlen( *(ini+1) ),
771818
PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE);
819+
#endif
772820
}
773821

774822
while (( p < argend )&&(**p == '-' )) {
@@ -1148,7 +1196,11 @@ zend_module_entry litespeed_module_entry = {
11481196
static int add_associate_array( const char * pKey, int keyLen, const char * pValue, int valLen,
11491197
void * arg )
11501198
{
1151-
add_assoc_string_ex( (zval *)arg, (char *)pKey, keyLen+1, (char *)pValue, 1 );
1199+
add_assoc_string_ex( (zval *)arg, (char *)pKey, keyLen+1, (char *)pValue
1200+
#if PHP_MAJOR_VERSION < 7
1201+
, 1
1202+
#endif
1203+
);
11521204
return 1;
11531205
}
11541206

@@ -1202,7 +1254,11 @@ PHP_FUNCTION(litespeed_response_headers)
12021254
headerBuf[len] = 0;
12031255
if ( len ) {
12041256
while( isspace(*++p));
1205-
add_assoc_string_ex(return_value, headerBuf, len+1, p, 1 );
1257+
add_assoc_string_ex(return_value, headerBuf, len+1, p
1258+
#if PHP_MAJOR_VERSION < 7
1259+
, 1
1260+
#endif
1261+
);
12061262
}
12071263
}
12081264
}
@@ -1217,15 +1273,25 @@ PHP_FUNCTION(litespeed_response_headers)
12171273
Fetch all loaded module names */
12181274
PHP_FUNCTION(apache_get_modules)
12191275
{
1276+
static const char * mod_names[] =
1277+
{
1278+
"mod_rewrite", "mod_mime", "mod_headers", "mod_expires", NULL
1279+
};
1280+
const char **name = mod_names;
12201281
/* TODO: */
12211282
if (ZEND_NUM_ARGS() > 0) {
12221283
WRONG_PARAM_COUNT;
12231284
}
12241285
array_init(return_value);
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);
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+
}
12291295
}
12301296
/* }}} */
12311297

0 commit comments

Comments
 (0)