Beispiel #1
0
/**
 * Gets the global zval into PG macro
 */
int zephir_get_global(zval *arr, const char *global, unsigned int global_length)
{
	zval *gv;
	zend_bool jit_initialization = PG(auto_globals_jit);
	zend_string *str = zend_string_init(global, global_length, 0);

	if (jit_initialization) {
		zend_is_auto_global(str);
	}

	zval_ptr_dtor(arr);
	ZVAL_UNDEF(arr);

	if (&EG(symbol_table)) {
		if ((gv = zend_hash_find(&EG(symbol_table), str)) != NULL) {
			if (Z_TYPE_P(gv) == IS_ARRAY) {
				ZVAL_COPY_VALUE(arr, gv);
				zend_string_free(str);
				return SUCCESS;
			}
		}
	}
	array_init(arr);
	zend_hash_update(&EG(symbol_table), str, arr);
	zend_string_free(str);
	return SUCCESS;
}
Beispiel #2
0
char* fpm_php_get_string_from_table(zend_string *table, char *key) /* {{{ */
{
	zval *data, *tmp;
	zend_string *str;
	if (!table || !key) {
		return NULL;
	}

	/* inspired from ext/standard/info.c */

	zend_is_auto_global(table);

	/* find the table and ensure it's an array */
	data = zend_hash_find(&EG(symbol_table), table);
	if (!data || Z_TYPE_P(data) != IS_ARRAY) {
		return NULL;
	}

	ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(data), str, tmp) {
		if (str && !strncmp(str->val, key, str->len)) {
			return Z_STRVAL_P(tmp);
		}
	} ZEND_HASH_FOREACH_END();

	return NULL;
}
Beispiel #3
0
static void smd_mark_global(char *name, int len, zend_uchar mark) /* {{{ */ {
    zend_string * str = zend_string_init(name, len, 0);
    if (zend_is_auto_global(str)) {
        zval *zv = zend_hash_find(&EG(symbol_table), str);
        SMD_SET_MARK(Z_ARRVAL(*zv), mark);
    }

    efree(str);
} /* }}} */
Beispiel #4
0
/* {{{ proto int owsrequest.loadParams()
   Initializes the OWSRequest object from the cgi environment variables
   REQUEST_METHOD, QUERY_STRING and HTTP_COOKIE. Returns the number of
   name/value pairs collected. */
PHP_METHOD(OWSRequestObj, loadParams)
{
    zval *zobj = getThis();
    zval **val;
    php_owsrequest_object *php_owsrequest;
    void *thread_context;

#ifdef ZTS
    thread_context = (void*)TSRMLS_C;
#else
    thread_context = NULL;
#endif

    //PHP_MAPSCRIPT_ERROR_HANDLING(TRUE);
    if (zend_parse_parameters_none() == FAILURE) {
      //PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
        return;
    }
    //PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE);
    
    php_owsrequest = (php_owsrequest_object *) zend_object_store_get_object(zobj TSRMLS_CC);

    if ( (STRING_EQUAL(sapi_module.name,"cli")) || 
         (STRING_EQUAL(sapi_module.name,"cgi")) ||
         (STRING_EQUAL(sapi_module.name,"cgi-fcgi")) )
    {
        cgirequestObj_loadParams(php_owsrequest->cgirequest, NULL, NULL, 0, thread_context);
    }
    else
    {
        // check if we have input data for GET method
        if (SG(request_info).request_method &&
            STRING_EQUAL(SG(request_info).request_method, "GET"))
        {
            zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC);
            if ( PG(http_globals)[TRACK_VARS_SERVER] &&
                 (zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, "QUERY_STRING", sizeof("QUERY_STRING"), (void **) &val) == SUCCESS) &&
                 (Z_TYPE_PP(val) == IS_STRING) &&
                 (Z_STRLEN_PP(val) > 0) ) 
            {
                cgirequestObj_loadParams(php_owsrequest->cgirequest, owsrequest_getenv, NULL, 0, thread_context);
            }
        }
        else
        {
            cgirequestObj_loadParams(php_owsrequest->cgirequest, owsrequest_getenv, 
                                     SG(request_info).raw_post_data,
                                     SG(request_info).raw_post_data_length, thread_context);
        }
    }
    
    RETURN_LONG(php_owsrequest->cgirequest->NumParams);
}
Beispiel #5
0
static void _add_assoc_zval_helper(zval *event, char *name, uint name_len TSRMLS_DC)
{	
	zval **ppzval;
	
	if (PG(auto_globals_jit)) {
		zend_is_auto_global(name, name_len TSRMLS_CC);
	}
	
	if (zend_hash_find(&EG(symbol_table), name, name_len, (void **) &ppzval) == SUCCESS) {
		/* Make sure that freeing jam_array doesn't destroy superglobals */
		Z_ADDREF_PP(ppzval);
		add_assoc_zval(event, name, *ppzval);
	}	
}
/**
 *  Convert object to a value
 *  @return Value
 */
Value Super::value()
{
    // call zend_is_auto_global to ensure that the just-in-time globals are loaded
    if (_name) {
        // make the variable an auto global
        zend_is_auto_global(String{ _name });

        // reset because we only need to do this once
        _name = nullptr;
    }

    // create a value object that wraps around the actual zval
    return &PG(http_globals)[_index];
}
Beispiel #7
0
/* {{{ php_zlib_output_encoding() */
static int php_zlib_output_encoding(TSRMLS_D)
{
	zval **enc;

	if (!ZLIBG(compression_coding)) {
		zend_is_auto_global(ZEND_STRL("_SERVER") TSRMLS_CC);
		if (PG(http_globals)[TRACK_VARS_SERVER] && SUCCESS == zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_ACCEPT_ENCODING", sizeof("HTTP_ACCEPT_ENCODING"), (void *) &enc)) {
			convert_to_string(*enc);
			if (strstr(Z_STRVAL_PP(enc), "gzip")) {
				ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_GZIP;
			} else if (strstr(Z_STRVAL_PP(enc), "deflate")) {
				ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_DEFLATE;
			}
		}
	}
	return ZLIBG(compression_coding);
}
Beispiel #8
0
char *owsrequest_getenv(const char *name, void *thread_context)
{
    zval **val, **ppzval;
    zval *cookie_result, *key;
    HashTable *cookies;
    char *string_key = NULL, *cookie_tmp;
    ulong num_key;
    int numElements, i = 0;
    TSRMLS_FETCH_FROM_CTX(thread_context);

    if  (STRING_EQUAL(name, "HTTP_COOKIE"))
    {
        cookies = PG(http_globals)[TRACK_VARS_COOKIE]->value.ht;
        numElements = zend_hash_num_elements(cookies);
        MAKE_STD_ZVAL(cookie_result);
        ZVAL_STRING(cookie_result, "",1);
        for(zend_hash_internal_pointer_reset(cookies); 
            zend_hash_has_more_elements(cookies) == SUCCESS; 
            zend_hash_move_forward(cookies), ++i)
        { 
            zend_hash_get_current_data(cookies, (void **)&ppzval);
            zend_hash_get_current_key(cookies, &string_key, &num_key, 1);
            cookie_tmp = malloc((strlen(string_key)+Z_STRLEN_PP(ppzval)+3) * sizeof(char));
            sprintf(cookie_tmp, "%s=%s;",string_key,Z_STRVAL_PP(ppzval));
            MAKE_STD_ZVAL(key);
            ZVAL_STRING(key, cookie_tmp,1);
            add_string_to_string(cookie_result,cookie_result, key);
            zval_dtor(key);
            free(cookie_tmp);
        }
        return Z_STRVAL_P(cookie_result);
    }
    else 
    {
        zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC);
        if ( PG(http_globals)[TRACK_VARS_SERVER] &&
             (zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, name, strlen(name)+1, (void **) &val) == SUCCESS) &&
             (Z_TYPE_PP(val) == IS_STRING))
        {
            return Z_STRVAL_PP(val);
        }
    }
    
    return NULL;
}
Beispiel #9
0
int
execPhpScript( char *scrFile, int scrArgc, char **scrArgv ) {
    zend_file_handle file_handle;
    int status = 0;
    int lineno = 0;

    if ( ( status = php_seek_file_begin( &file_handle, scrFile, &lineno TSRMLS_CC ) )
            < 0 ) {
        rodsLog( LOG_ERROR,
                 "execPhpScript: php_seek_file_begin error for %s", scrFile );
        return status;
    }

    file_handle.type = ZEND_HANDLE_FP;
    file_handle.opened_path = NULL;
    file_handle.free_filename = 0;
    SG( request_info ).argc = scrArgc;

    SG( request_info ).path_translated = file_handle.filename;
    SG( request_info ).argv = scrArgv;

    if ( php_request_startup( TSRMLS_C ) == FAILURE ) {
        rodsLog( LOG_ERROR,
                 "execPhpScript: php_request_startup error for %s", scrFile );
        fclose( file_handle.handle.fp );
        return PHP_REQUEST_STARTUP_ERR;
    }
    CG( start_lineno ) = lineno;
    zend_is_auto_global( "_SERVER", sizeof( "_SERVER" ) - 1 TSRMLS_CC );
    PG( during_request_startup ) = 0;
    php_execute_script( &file_handle TSRMLS_CC );
    status = EG( exit_status );

    if ( status != SUCCESS ) {
        rodsLog( LOG_ERROR,
                 "execPhpScript: php_execute_script error for %s", scrFile );
        status = PHP_EXEC_SCRIPT_ERR;
    }

    php_request_shutdown( ( void * ) 0 );

    return status;
}
Beispiel #10
0
/* {{{ php_zlib_output_encoding() */
static int php_zlib_output_encoding(TSRMLS_D)
{
	zval *enc;

	if (!ZLIBG(compression_coding)) {
		zend_string *name = zend_string_init("_SERVER", sizeof("_SERVER") - 1, 0);
		zend_is_auto_global(name TSRMLS_CC);
		zend_string_release(name);
		if (Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY &&
			(enc = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_ACCEPT_ENCODING", sizeof("HTTP_ACCEPT_ENCODING") - 1))) {
			convert_to_string(enc);
			if (strstr(Z_STRVAL_P(enc), "gzip")) {
				ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_GZIP;
			} else if (strstr(Z_STRVAL_P(enc), "deflate")) {
				ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_DEFLATE;
			}
		}
	}
	return ZLIBG(compression_coding);
}
Beispiel #11
0
BUESSION_API zval *buession_get_global_variables(uint type TSRMLS_DC){
	zval **result;

	#if(PHP_MAJOR_VERSION == 5)&&(PHP_MINOR_VERSION < 4)
		zend_bool jit_initialization = (PG(auto_globals_jit)&&!PG(register_globals)&&!PG(register_long_arrays));
	#else
		zend_bool jit_initialization = PG(auto_globals_jit);
	#endif

	#if HAVE_BUESSION_DEBUG
		switch(type){
			case TRACK_VARS_POST:
				zend_hash_find(&EG(symbol_table), "_POST", 6, (void **) &result);
				break;
			case TRACK_VARS_GET:
				zend_hash_find(&EG(symbol_table), "_GET", 5, (void **) &result);
				break;
			case TRACK_VARS_SESSION:
				result = &PS(http_session_vars);
				break;
			case TRACK_VARS_COOKIE:
				zend_hash_find(&EG(symbol_table), "_COOKIE", 8, (void **) &result);
				break;
			case TRACK_VARS_SERVER:
				if(jit_initialization){
					zend_is_auto_global("_SERVER", 7 TSRMLS_CC);
				}
				zend_hash_find(&EG(symbol_table), "_SERVER", 8, (void **) &result);
				break;
			case TRACK_VARS_ENV:
				if(jit_initialization){
					zend_is_auto_global("_ENV", 4 TSRMLS_CC);
				}
				result = &PG(http_globals)[TRACK_VARS_ENV];
				break;
			case TRACK_VARS_FILES:
				result = &PG(http_globals)[TRACK_VARS_FILES];
				break;
			case TRACK_VARS_REQUEST:
				if(jit_initialization){
					zend_is_auto_global("_REQUEST", 9 TSRMLS_CC);
				}
				zend_hash_find(&EG(symbol_table), "_REQUEST", 9, (void **) &result);
				break;
			case TRACK_VARS_GLOBALS:
				zend_hash_find(&EG(symbol_table), "GLOBALS", 8, (void **) &result);
				break;
			default:
				break;
		}
	#else
		switch(type){
			case TRACK_VARS_POST: case TRACK_VARS_GET: case TRACK_VARS_FILES: case TRACK_VARS_COOKIE:
				result = &PG(http_globals)[type];
				break;
			case TRACK_VARS_SESSION:
				result = &PS(http_session_vars);
				break;
			case TRACK_VARS_ENV:
				if(jit_initialization){
					zend_is_auto_global("_ENV", 4 TSRMLS_CC);
				}
				result = &PG(http_globals)[type];
				break;
			case TRACK_VARS_SERVER:
				if(jit_initialization){
					zend_is_auto_global("_SERVER", 7 TSRMLS_CC);
				}
				result = &PG(http_globals)[type];
				break;
			case TRACK_VARS_REQUEST:
				if(jit_initialization){
					zend_is_auto_global("_REQUEST", 8 TSRMLS_CC);
				}
				result = &PG(http_globals)[type];
				break;
			case TRACK_VARS_GLOBALS:
				zend_hash_find(&EG(symbol_table), "GLOBALS", 8, (void **) &result);
				break;
			default:
				break;
		}
	#endif

	if(!result||!(*result)){
		BUESSION_ARRAY_INIT(*result);
		return *result;
	}

	Z_ADDREF_PP(result);
	return *result;
}
Beispiel #12
0
/* {{{ proto void run()
 */
PHP_METHOD(slightphp, run)
{
		zval *zone=NULL;
		zval *page=NULL;
		zval *entry=NULL;

		zval **token;
		zval *path_array;

		//{{{
		int isPart;
		zval * path = NULL;
		if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &path) != FAILURE) {
				if (Z_TYPE_P(path)!= IS_STRING){
						RETURN_FALSE;
				}
				isPart = 1;
		}else{
			isPart = 0;
			path = zend_read_static_property(slightphp_ce_ptr,"pathInfo",sizeof("pathInfo")-1,1 TSRMLS_CC);
			int s = Z_STRLEN_P(path);
			if(s==0){
				zend_is_auto_global("_SERVER", sizeof("_SERVER") - 1 TSRMLS_CC);
				if(zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_GET]), 
							"PATH_INFO", sizeof("PATH_INFO"), (void **) &token) == SUCCESS
				){
					path = *token;
				}else if(zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), 
							"PATH_INFO", sizeof("PATH_INFO"), (void **) &token) == SUCCESS
				){
					path = *token;
				}
			}
		}
		//}}}

		MAKE_STD_ZVAL(path_array);
		array_init(path_array);

		if (path){
				//{{{
				zval quotedFlag;
				regex_t re;
				char	*regex;
				regmatch_t subs[1];
				int err,size;
				char *strp = Z_STRVAL_P(path);
				char *endp = strp + Z_STRLEN_P(path);
				zval *splitFlag = zend_read_static_property(slightphp_ce_ptr,"splitFlag",sizeof("splitFlag")-1,1 TSRMLS_CC);

				if(preg_quote(splitFlag,&quotedFlag)>0){
						spprintf(&regex,0,"[%s\\/]",Z_STRVAL(quotedFlag));
				}else{
						spprintf(&regex,0,"[\\/]");
				}
				err = regcomp(&re, regex, REG_ICASE);
				if (err) {
				}else{
						while (!(err = regexec(&re, strp, 1, subs, 0))) {
								if (subs[0].rm_so == 0 && subs[0].rm_eo) {
										//ignore empty string 
										strp += subs[0].rm_eo;
								}else if (subs[0].rm_so == 0 && subs[0].rm_eo == 0) {
								}else{
										size = subs[0].rm_so;
										add_next_index_stringl(path_array, strp, size, 1);
										strp += size;

								}
						}
						if (!err || err == REG_NOMATCH) {
								size = endp - strp;
								if(size>0) add_next_index_stringl(path_array, strp, size, 1);
						}
						regfree(&re);
				}
				efree(regex);
				//}}}
				int n_elems = zend_hash_num_elements(Z_ARRVAL_P(path_array));
				if(zend_hash_index_find(Z_ARRVAL_P(path_array), 0, (void **)&token) != FAILURE) {
						zone = *token;
				}
				if(zend_hash_index_find(Z_ARRVAL_P(path_array), 1, (void **)&token) != FAILURE) {
						page = *token;
				}
				if(zend_hash_index_find(Z_ARRVAL_P(path_array), 2, (void **)&token) != FAILURE) {
						entry = *token;
				}

		}
		if(!zone){
				zone = zend_read_static_property(slightphp_ce_ptr,"defaultZone",sizeof("defaultZone")-1,1 TSRMLS_CC);
				zend_hash_next_index_insert(Z_ARRVAL_P(path_array),&zone,sizeof(zval*),NULL);
		}
		if(!page){
				page = zend_read_static_property(slightphp_ce_ptr,"defaultPage",sizeof("defaultPage")-1,1 TSRMLS_CC);
				zend_hash_next_index_insert(Z_ARRVAL_P(path_array),&page,sizeof(zval*),NULL);
		}
		if(!entry){
				entry = zend_read_static_property(slightphp_ce_ptr,"defaultEntry",sizeof("defaultEntry")-1,1 TSRMLS_CC);
				zend_hash_next_index_insert(Z_ARRVAL_P(path_array),&entry,sizeof(zval*),NULL);
		}
		//{{{
		zval *zoneAlias = zend_read_static_property(slightphp_ce_ptr,"zoneAlias",sizeof("zoneAlias")-1,1 TSRMLS_CC);
		if(zoneAlias && Z_TYPE_P(zoneAlias)==IS_ARRAY){
				char *string_key;uint str_key_len;ulong num_key;
				HashPosition pos;
				zval **entry2;
				zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(zoneAlias), &pos);
				while (zend_hash_get_current_data_ex(Z_ARRVAL_P(zoneAlias), (void **)&entry2, &pos) == SUCCESS) {
						if(strcmp(Z_STRVAL_PP(entry2) ,Z_STRVAL_P(zone))==0){
								switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(zoneAlias), &string_key, &str_key_len, &num_key, 0, &pos)) {
										case HASH_KEY_IS_STRING:
												ZVAL_STRING(zone,string_key,1);
												break;
								}
						}
						zend_hash_move_forward_ex(Z_ARRVAL_P(zoneAlias), &pos);
				}
				if(entry2)zval_ptr_dtor(entry2);
				if(string_key)efree(string_key);
		}
		//if(zoneAlias)FREE_ZVAL(zoneAlias);
		//}}}
		if(!isPart){
				zend_update_static_property(slightphp_ce_ptr,"zone",sizeof("zone")-1,zone TSRMLS_CC);
				zend_update_static_property(slightphp_ce_ptr,"page",sizeof("page")-1,page TSRMLS_CC);
				zend_update_static_property(slightphp_ce_ptr,"entry",sizeof("entry")-1,entry TSRMLS_CC);
		}else{
				if(
								strcmp(Z_STRVAL_P(zone),Z_STRVAL_P(zend_read_static_property(slightphp_ce_ptr,"zone",sizeof("zone")-1,1 TSRMLS_CC)))==0 
								&&
								strcmp(Z_STRVAL_P(page),Z_STRVAL_P(zend_read_static_property(slightphp_ce_ptr,"page",sizeof("page")-1,1 TSRMLS_CC)))==0 
								&&
								strcmp(Z_STRVAL_P(entry),Z_STRVAL_P(zend_read_static_property(slightphp_ce_ptr,"entry",sizeof("entry")-1,1 TSRMLS_CC)))==0 
				  ){
						debug("part ignored [%s]",Z_STRVAL_P(path));
						return;
				}
		}


		zval *appDir = zend_read_static_property(slightphp_ce_ptr,"appDir",sizeof("appDir")-1,1 TSRMLS_CC);

		zval *params[1];
		params[0]=path_array;


		if(slightphp_load(appDir,zone,page TSRMLS_CC) == SUCCESS){
				if(slightphp_run(zone,page,entry,return_value,1,params TSRMLS_CC)==SUCCESS){
						if(path_array)FREE_ZVAL(path_array);
						RETURN_ZVAL(return_value,1,0);
				};
		}
		if(path_array)FREE_ZVAL(path_array);
		RETURN_FALSE;
}