本文整理汇总了C++中PG函数的典型用法代码示例。如果您正苦于以下问题:C++ PG函数的具体用法?C++ PG怎么用?C++ PG使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mysqli_common_connect
void mysqli_common_connect(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_real_connect, zend_bool in_ctor) /* {{{ */
{
MY_MYSQL *mysql = NULL;
MYSQLI_RESOURCE *mysqli_resource = NULL;
zval *object = getThis();
char *hostname = NULL, *username=NULL, *passwd=NULL, *dbname=NULL, *socket=NULL;
size_t hostname_len = 0, username_len = 0, passwd_len = 0, dbname_len = 0, socket_len = 0;
zend_bool persistent = FALSE;
zend_long port = 0, flags = 0;
zend_string *hash_key = NULL;
zend_bool new_connection = FALSE;
zend_resource *le;
mysqli_plist_entry *plist = NULL;
zend_bool self_alloced = 0;
#if !defined(MYSQL_USE_MYSQLND)
if ((MYSQL_VERSION_ID / 100) != (mysql_get_client_version() / 100)) {
php_error_docref(NULL, E_WARNING,
"Headers and client library minor version mismatch. Headers:%d Library:%ld",
MYSQL_VERSION_ID, mysql_get_client_version());
}
#endif
if (getThis() && !ZEND_NUM_ARGS() && in_ctor) {
php_mysqli_init(INTERNAL_FUNCTION_PARAM_PASSTHRU, in_ctor);
return;
}
hostname = username = dbname = passwd = socket = NULL;
if (!is_real_connect) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ssssls", &hostname, &hostname_len, &username, &username_len,
&passwd, &passwd_len, &dbname, &dbname_len, &port, &socket, &socket_len) == FAILURE) {
return;
}
if (object && instanceof_function(Z_OBJCE_P(object), mysqli_link_class_entry)) {
mysqli_resource = (Z_MYSQLI_P(object))->ptr;
if (mysqli_resource && mysqli_resource->ptr) {
mysql = (MY_MYSQL*) mysqli_resource->ptr;
}
}
if (!mysql) {
mysql = (MY_MYSQL *) ecalloc(1, sizeof(MY_MYSQL));
self_alloced = 1;
}
flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */
} else {
/* We have flags too */
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|sssslsl", &object, mysqli_link_class_entry,
&hostname, &hostname_len, &username, &username_len, &passwd, &passwd_len, &dbname, &dbname_len, &port, &socket, &socket_len,
&flags) == FAILURE) {
return;
}
mysqli_resource = (Z_MYSQLI_P(object))->ptr;
MYSQLI_FETCH_RESOURCE_CONN(mysql, object, MYSQLI_STATUS_INITIALIZED);
/* set some required options */
flags |= CLIENT_MULTI_RESULTS; /* needed for mysql_multi_query() */
/* remove some insecure options */
flags &= ~CLIENT_MULTI_STATEMENTS; /* don't allow multi_queries via connect parameter */
#if !defined(MYSQLI_USE_MYSQLND)
if (PG(open_basedir) && PG(open_basedir)[0] != '\0') {
flags &= ~CLIENT_LOCAL_FILES;
}
#endif
}
if (!socket_len || !socket) {
socket = MyG(default_socket);
}
if (!port){
port = MyG(default_port);
}
if (!passwd) {
passwd = MyG(default_pw);
passwd_len = strlen(SAFE_STR(passwd));
}
if (!username){
username = MyG(default_user);
}
if (!hostname || !hostname_len) {
hostname = MyG(default_host);
}
if (mysql->mysql && mysqli_resource &&
(mysqli_resource->status > MYSQLI_STATUS_INITIALIZED))
{
/* already connected, we should close the connection */
php_mysqli_close(mysql, MYSQLI_CLOSE_IMPLICIT, mysqli_resource->status);
}
if (strlen(SAFE_STR(hostname)) > 2 && !strncasecmp(hostname, "p:", 2)) {
hostname += 2;
if (!MyG(allow_persistent)) {
php_error_docref(NULL, E_WARNING, "Persistent connections are disabled. Downgrading to normal");
} else {
mysql->persistent = persistent = TRUE;
//.........这里部分代码省略.........
示例2: php_startup_ticks
int php_startup_ticks(TSRMLS_D)
{
zend_llist_init(&PG(tick_functions), sizeof(void(*)(int)), NULL, 1);
return SUCCESS;
}
示例3: php_fopen_primary_script
/* {{{ php_fopen_primary_script
*/
PHPAPI int php_fopen_primary_script(zend_file_handle *file_handle)
{
char *path_info;
char *filename = NULL;
zend_string *resolved_path = NULL;
int length;
zend_bool orig_display_errors;
path_info = SG(request_info).request_uri;
#if HAVE_PWD_H
if (PG(user_dir) && *PG(user_dir) && path_info && '/' == path_info[0] && '~' == path_info[1]) {
char *s = strchr(path_info + 2, '/');
if (s) { /* if there is no path name after the file, do not bother */
char user[32]; /* to try open the directory */
struct passwd *pw;
#if defined(ZTS) && defined(HAVE_GETPWNAM_R) && defined(_SC_GETPW_R_SIZE_MAX)
struct passwd pwstruc;
long pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
char *pwbuf;
if (pwbuflen < 1) {
return FAILURE;
}
pwbuf = emalloc(pwbuflen);
#endif
length = s - (path_info + 2);
if (length > (int)sizeof(user) - 1) {
length = sizeof(user) - 1;
}
memcpy(user, path_info + 2, length);
user[length] = '\0';
#if defined(ZTS) && defined(HAVE_GETPWNAM_R) && defined(_SC_GETPW_R_SIZE_MAX)
if (getpwnam_r(user, &pwstruc, pwbuf, pwbuflen, &pw)) {
efree(pwbuf);
return FAILURE;
}
#else
pw = getpwnam(user);
#endif
if (pw && pw->pw_dir) {
spprintf(&filename, 0, "%s%c%s%c%s", pw->pw_dir, PHP_DIR_SEPARATOR, PG(user_dir), PHP_DIR_SEPARATOR, s + 1); /* Safe */
} else {
filename = SG(request_info).path_translated;
}
#if defined(ZTS) && defined(HAVE_GETPWNAM_R) && defined(_SC_GETPW_R_SIZE_MAX)
efree(pwbuf);
#endif
}
} else
#endif
if (PG(doc_root) && path_info && (length = (int)strlen(PG(doc_root))) &&
IS_ABSOLUTE_PATH(PG(doc_root), length)) {
int path_len = (int)strlen(path_info);
filename = emalloc(length + path_len + 2);
if (filename) {
memcpy(filename, PG(doc_root), length);
if (!IS_SLASH(filename[length - 1])) { /* length is never 0 */
filename[length++] = PHP_DIR_SEPARATOR;
}
if (IS_SLASH(path_info[0])) {
length--;
}
strncpy(filename + length, path_info, path_len + 1);
}
} else {
filename = SG(request_info).path_translated;
}
if (filename) {
resolved_path = zend_resolve_path(filename, (int)strlen(filename));
}
if (!resolved_path) {
if (SG(request_info).path_translated != filename) {
if (filename) {
efree(filename);
}
}
/* we have to free SG(request_info).path_translated here because
* php_destroy_request_info assumes that it will get
* freed when the include_names hash is emptied, but
* we're not adding it in this case */
if (SG(request_info).path_translated) {
efree(SG(request_info).path_translated);
SG(request_info).path_translated = NULL;
}
return FAILURE;
}
zend_string_release(resolved_path);
orig_display_errors = PG(display_errors);
PG(display_errors) = 0;
if (zend_stream_open(filename, file_handle) == FAILURE) {
PG(display_errors) = orig_display_errors;
if (SG(request_info).path_translated != filename) {
//.........这里部分代码省略.........
示例4: SAPI_TREAT_DATA_FUNC
/* {{{ MBSTRING_API SAPI_TREAT_DATA_FUNC(mbstr_treat_data)
* http input processing */
MBSTRING_API SAPI_TREAT_DATA_FUNC(mbstr_treat_data)
{
char *res = NULL, *separator=NULL;
const char *c_var;
zval *array_ptr;
int free_buffer=0;
const mbfl_encoding *detected;
php_mb_encoding_handler_info_t info;
if (arg != PARSE_STRING) {
char *value = MBSTRG(internal_encoding_name);
_php_mb_ini_mbstring_internal_encoding_set(value, value ? strlen(value): 0 TSRMLS_CC);
}
if (!MBSTRG(encoding_translation)) {
php_default_treat_data(arg, str, destArray TSRMLS_CC);
return;
}
switch (arg) {
case PARSE_POST:
case PARSE_GET:
case PARSE_COOKIE:
ALLOC_ZVAL(array_ptr);
array_init(array_ptr);
INIT_PZVAL(array_ptr);
switch (arg) {
case PARSE_POST:
PG(http_globals)[TRACK_VARS_POST] = array_ptr;
break;
case PARSE_GET:
PG(http_globals)[TRACK_VARS_GET] = array_ptr;
break;
case PARSE_COOKIE:
PG(http_globals)[TRACK_VARS_COOKIE] = array_ptr;
break;
}
break;
default:
array_ptr=destArray;
break;
}
if (arg==PARSE_POST) {
sapi_handle_post(array_ptr TSRMLS_CC);
return;
}
if (arg == PARSE_GET) { /* GET data */
c_var = SG(request_info).query_string;
if (c_var && *c_var) {
res = (char *) estrdup(c_var);
free_buffer = 1;
} else {
free_buffer = 0;
}
} else if (arg == PARSE_COOKIE) { /* Cookie data */
c_var = SG(request_info).cookie_data;
if (c_var && *c_var) {
res = (char *) estrdup(c_var);
free_buffer = 1;
} else {
free_buffer = 0;
}
} else if (arg == PARSE_STRING) { /* String data */
res = str;
free_buffer = 1;
}
if (!res) {
return;
}
switch (arg) {
case PARSE_POST:
case PARSE_GET:
case PARSE_STRING:
separator = (char *) estrdup(PG(arg_separator).input);
break;
case PARSE_COOKIE:
separator = ";\0";
break;
}
switch(arg) {
case PARSE_POST:
MBSTRG(http_input_identify_post) = NULL;
break;
case PARSE_GET:
MBSTRG(http_input_identify_get) = NULL;
break;
case PARSE_COOKIE:
MBSTRG(http_input_identify_cookie) = NULL;
break;
case PARSE_STRING:
MBSTRG(http_input_identify_string) = NULL;
break;
}
//.........这里部分代码省略.........
示例5: setThreadNotRunning
void ScriptEngine::execute(const std::string path, const std::string arguments, std::shared_ptr<std::vector<char>> output, int32_t* exitCode, bool wait, int32_t threadId)
{
try
{
if(_disposing)
{
setThreadNotRunning(threadId);
return;
}
if(path.empty())
{
//No thread yet
return;
}
if(!output) output.reset(new std::vector<char>());
if(!wait)
{
collectGarbage();
if(!scriptThreadMaxReached())
{
_scriptThreadMutex.lock();
try
{
int32_t threadId = _currentScriptThreadID++;
if(threadId == -1) threadId = _currentScriptThreadID++;
_scriptThreads.insert(std::pair<int32_t, std::pair<std::thread, bool>>(threadId, std::pair<std::thread, bool>(std::thread(&ScriptEngine::execute, this, path, arguments, output, nullptr, true, threadId), true)));
}
catch(const std::exception& ex)
{
GD::out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
}
catch(...)
{
GD::out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
}
_scriptThreadMutex.unlock();
}
if(exitCode) *exitCode = 0;
//No thread yet
return;
}
}
catch(const std::exception& ex)
{
GD::bl->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
setThreadNotRunning(threadId);
return;
}
catch(BaseLib::Exception& ex)
{
GD::bl->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
setThreadNotRunning(threadId);
return;
}
catch(...)
{
GD::bl->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
setThreadNotRunning(threadId);
return;
}
if(exitCode) *exitCode = -1;
if(!GD::bl->io.fileExists(path))
{
GD::out.printError("Error: PHP script \"" + path + "\" does not exist.");
setThreadNotRunning(threadId);
return;
}
ts_resource_ex(0, NULL); //Replaces TSRMLS_FETCH()
try
{
zend_file_handle script;
/* Set up a File Handle structure */
script.type = ZEND_HANDLE_FILENAME;
script.filename = path.c_str();
script.opened_path = NULL;
script.free_filename = 0;
zend_homegear_globals* globals = php_homegear_get_globals();
if(!globals)
{
ts_free_thread();
setThreadNotRunning(threadId);
return;
}
globals->output = output.get();
globals->commandLine = true;
globals->cookiesParsed = true;
if(!tsrm_get_ls_cache() || !((sapi_globals_struct *) (*((void ***) tsrm_get_ls_cache()))[((sapi_globals_id)-1)]) || !((php_core_globals *) (*((void ***) tsrm_get_ls_cache()))[((core_globals_id)-1)]))
{
GD::out.printCritical("Critical: Error in PHP: No thread safe resource exists.");
ts_free_thread();
setThreadNotRunning(threadId);
return;
}
PG(register_argc_argv) = 1;
SG(server_context) = (void*)output.get(); //Must be defined! Otherwise php_homegear_activate is not called.
SG(options) |= SAPI_OPTION_NO_CHDIR;
SG(headers_sent) = 1;
//.........这里部分代码省略.........
示例6: php_var_unserialize
//.........这里部分代码省略.........
return 0;
}
class_name = (char*)YYCURSOR;
YYCURSOR += len;
if (*(YYCURSOR) != '"') {
*p = YYCURSOR;
return 0;
}
if (*(YYCURSOR+1) != ':') {
*p = YYCURSOR+1;
return 0;
}
len3 = strspn(class_name, "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377\\");
if (len3 != len)
{
*p = YYCURSOR + len3 - len;
return 0;
}
class_name = estrndup(class_name, len);
do {
/* Try to find class directly */
if (zend_lookup_class(class_name, len2, &pce TSRMLS_CC) == SUCCESS) {
ce = *pce;
break;
}
/* Check for unserialize callback */
if ((PG(unserialize_callback_func) == NULL) || (PG(unserialize_callback_func)[0] == '\0')) {
incomplete_class = 1;
ce = PHP_IC_ENTRY;
break;
}
/* Call unserialize callback */
MAKE_STD_ZVAL(user_func);
ZVAL_STRING(user_func, PG(unserialize_callback_func), 1);
args[0] = &arg_func_name;
MAKE_STD_ZVAL(arg_func_name);
ZVAL_STRING(arg_func_name, class_name, 1);
if (call_user_function_ex(CG(function_table), NULL, user_func, &retval_ptr, 1, args, 0, NULL TSRMLS_CC) != SUCCESS) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "defined (%s) but not found", user_func->value.str.val);
incomplete_class = 1;
ce = PHP_IC_ENTRY;
zval_ptr_dtor(&user_func);
zval_ptr_dtor(&arg_func_name);
break;
}
if (retval_ptr) {
zval_ptr_dtor(&retval_ptr);
}
/* The callback function may have defined the class */
if (zend_lookup_class(class_name, len2, &pce TSRMLS_CC) == SUCCESS) {
ce = *pce;
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Function %s() hasn't defined the class it was called for", user_func->value.str.val);
incomplete_class = 1;
ce = PHP_IC_ENTRY;
}
示例7: php_apache_add_version
static void php_apache_add_version(apr_pool_t *p)
{
if (PG(expose_php)) {
ap_add_version_component(p, "PHP/" PHP_VERSION);
}
}
示例8: zend_optimizer_pass1
//.........这里部分代码省略.........
if ((func = zend_hash_find_ptr(EG(function_table), lc_name)) != NULL &&
func->type == ZEND_INTERNAL_FUNCTION &&
func->module->type == MODULE_PERSISTENT) {
zval t;
if (Z_STRLEN(ZEND_OP2_LITERAL(init_opline)) == sizeof("is_callable") - 1 ||
func->handler != ZEND_FN(display_disabled_function)) {
ZVAL_TRUE(&t);
} else {
ZVAL_FALSE(&t);
}
if (zend_optimizer_replace_by_const(op_array, opline + 1, IS_VAR, ZEND_RESULT(opline).var, &t)) {
literal_dtor(&ZEND_OP2_LITERAL(init_opline));
MAKE_NOP(init_opline);
literal_dtor(&ZEND_OP1_LITERAL(send1_opline));
MAKE_NOP(send1_opline);
MAKE_NOP(opline);
zend_string_release(lc_name);
break;
}
}
zend_string_release(lc_name);
} else if (Z_STRLEN(ZEND_OP2_LITERAL(init_opline)) == sizeof("extension_loaded")-1 &&
!memcmp(Z_STRVAL(ZEND_OP2_LITERAL(init_opline)),
"extension_loaded", sizeof("extension_loaded")-1)) {
zval t;
zend_string *lc_name = zend_string_tolower(
Z_STR(ZEND_OP1_LITERAL(send1_opline)));
zend_module_entry *m = zend_hash_find_ptr(&module_registry,
lc_name);
zend_string_release(lc_name);
if (!m) {
if (!PG(enable_dl)) {
break;
} else {
ZVAL_FALSE(&t);
}
} else {
if (m->type == MODULE_PERSISTENT) {
ZVAL_TRUE(&t);
} else {
break;
}
}
if (zend_optimizer_replace_by_const(op_array, opline + 1, IS_VAR, ZEND_RESULT(opline).var, &t)) {
literal_dtor(&ZEND_OP2_LITERAL(init_opline));
MAKE_NOP(init_opline);
literal_dtor(&ZEND_OP1_LITERAL(send1_opline));
MAKE_NOP(send1_opline);
MAKE_NOP(opline);
break;
}
} else if (Z_STRLEN(ZEND_OP2_LITERAL(init_opline)) == sizeof("defined")-1 &&
!memcmp(Z_STRVAL(ZEND_OP2_LITERAL(init_opline)),
"defined", sizeof("defined")-1)) {
zval t;
if (zend_optimizer_get_persistent_constant(Z_STR(ZEND_OP1_LITERAL(send1_opline)), &t, 0)) {
ZVAL_TRUE(&t);
if (zend_optimizer_replace_by_const(op_array, opline + 1, IS_VAR, ZEND_RESULT(opline).var, &t)) {
literal_dtor(&ZEND_OP2_LITERAL(init_opline));
MAKE_NOP(init_opline);
literal_dtor(&ZEND_OP1_LITERAL(send1_opline));
示例9: php_init_config
/* {{{ php_init_config
*/
int php_init_config(void)
{
char *php_ini_file_name = NULL;
char *php_ini_search_path = NULL;
int php_ini_scanned_path_len;
char *open_basedir;
int free_ini_search_path = 0;
zend_file_handle fh;
zend_hash_init(&configuration_hash, 8, NULL, config_zval_dtor, 1);
if (sapi_module.ini_defaults) {
sapi_module.ini_defaults(&configuration_hash);
}
zend_llist_init(&extension_lists.engine, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
zend_llist_init(&extension_lists.functions, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
open_basedir = PG(open_basedir);
if (sapi_module.php_ini_path_override) {
php_ini_file_name = sapi_module.php_ini_path_override;
php_ini_search_path = sapi_module.php_ini_path_override;
free_ini_search_path = 0;
} else if (!sapi_module.php_ini_ignore) {
int search_path_size;
char *default_location;
char *env_location;
static const char paths_separator[] = { ZEND_PATHS_SEPARATOR, 0 };
#ifdef PHP_WIN32
char *reg_location;
char phprc_path[MAXPATHLEN];
#endif
env_location = getenv("PHPRC");
#ifdef PHP_WIN32
if (!env_location) {
char dummybuf;
int size;
SetLastError(0);
/*If the given bugger is not large enough to hold the data, the return value is
the buffer size, in characters, required to hold the string and its terminating
null character. We use this return value to alloc the final buffer. */
size = GetEnvironmentVariableA("PHPRC", &dummybuf, 0);
if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
/* The environment variable doesn't exist. */
env_location = "";
} else {
if (size == 0) {
env_location = "";
} else {
size = GetEnvironmentVariableA("PHPRC", phprc_path, size);
if (size == 0) {
env_location = "";
} else {
env_location = phprc_path;
}
}
}
}
#else
if (!env_location) {
env_location = "";
}
#endif
/*
* Prepare search path
*/
search_path_size = MAXPATHLEN * 4 + (int)strlen(env_location) + 3 + 1;
php_ini_search_path = (char *) emalloc(search_path_size);
free_ini_search_path = 1;
php_ini_search_path[0] = 0;
/* Add environment location */
if (env_location[0]) {
if (*php_ini_search_path) {
strlcat(php_ini_search_path, paths_separator, search_path_size);
}
strlcat(php_ini_search_path, env_location, search_path_size);
php_ini_file_name = env_location;
}
#ifdef PHP_WIN32
/* Add registry location */
reg_location = GetIniPathFromRegistry();
if (reg_location != NULL) {
if (*php_ini_search_path) {
strlcat(php_ini_search_path, paths_separator, search_path_size);
}
strlcat(php_ini_search_path, reg_location, search_path_size);
efree(reg_location);
}
#endif
//.........这里部分代码省略.........
示例10: smart_str_setl
ctx->buf.len = rest;
}
char *php_url_scanner_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, size_t *newlen TSRMLS_DC)
{
smart_str surl = {0};
smart_str buf = {0};
smart_str url_app = {0};
smart_str_setl(&surl, url, urllen);
smart_str_appends(&url_app, name);
smart_str_appendc(&url_app, '=');
smart_str_appends(&url_app, value);
append_modified_url(&surl, &buf, &url_app, PG(arg_separator).output);
smart_str_0(&buf);
if (newlen) *newlen = buf.len;
smart_str_free(&url_app);
return buf.c;
}
static char *url_adapt_ext(const char *src, size_t srclen, size_t *newlen, zend_bool do_flush TSRMLS_DC)
{
url_adapt_state_ex_t *ctx;
char *retval;
示例11: litespeed_php_import_environment_variables
static void litespeed_php_import_environment_variables(zval *array_ptr)
{
char buf[128];
char **env, *p, *t = buf;
size_t alloc_size = sizeof(buf);
unsigned long nlen; /* ptrdiff_t is not portable */
#if PHP_MAJOR_VERSION >= 7
if (Z_TYPE(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY &&
Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_ENV]) &&
zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_ENV])) > 0
) {
zval_dtor(array_ptr);
ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_ENV]);
return;
} else if (Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY &&
Z_ARR_P(array_ptr) != Z_ARR(PG(http_globals)[TRACK_VARS_SERVER]) &&
zend_hash_num_elements(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER])) > 0
) {
zval_dtor(array_ptr);
ZVAL_DUP(array_ptr, &PG(http_globals)[TRACK_VARS_SERVER]);
return;
}
#else
if (PG(http_globals)[TRACK_VARS_ENV] &&
array_ptr != PG(http_globals)[TRACK_VARS_ENV] &&
Z_TYPE_P(PG(http_globals)[TRACK_VARS_ENV]) == IS_ARRAY &&
zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_ENV])) > 0
) {
zval_dtor(array_ptr);
*array_ptr = *PG(http_globals)[TRACK_VARS_ENV];
INIT_PZVAL(array_ptr);
zval_copy_ctor(array_ptr);
return;
} else if (PG(http_globals)[TRACK_VARS_SERVER] &&
array_ptr != PG(http_globals)[TRACK_VARS_SERVER] &&
Z_TYPE_P(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY &&
zend_hash_num_elements(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER])) > 0
) {
zval_dtor(array_ptr);
*array_ptr = *PG(http_globals)[TRACK_VARS_SERVER];
INIT_PZVAL(array_ptr);
zval_copy_ctor(array_ptr);
return;
}
#endif
for (env = environ; env != NULL && *env != NULL; env++) {
p = strchr(*env, '=');
if (!p) { /* malformed entry? */
continue;
}
nlen = p - *env;
if (nlen >= alloc_size) {
alloc_size = nlen + 64;
t = (t == buf ? emalloc(alloc_size): erealloc(t, alloc_size));
}
memcpy(t, *env, nlen);
t[nlen] = '\0';
add_variable(t, nlen, p + 1, strlen( p + 1 ), array_ptr);
}
if (t != buf && t != NULL) {
efree(t);
}
}
示例12: do_cli
//.........这里部分代码省略.........
file_handle.type = ZEND_HANDLE_FP;
file_handle.opened_path = NULL;
file_handle.free_filename = 0;
php_self = (char*)file_handle.filename;
/* before registering argv to module exchange the *new* argv[0] */
/* we can achieve this without allocating more memory */
SG(request_info).argc=argc-php_optind+1;
arg_excp = argv+php_optind-1;
arg_free = argv[php_optind-1];
SG(request_info).path_translated = translated_path? translated_path: (char*)file_handle.filename;
argv[php_optind-1] = (char*)file_handle.filename;
SG(request_info).argv=argv+php_optind-1;
if (php_request_startup()==FAILURE) {
*arg_excp = arg_free;
fclose(file_handle.handle.fp);
PUTS("Could not startup.\n");
goto err;
}
request_started = 1;
CG(start_lineno) = lineno;
*arg_excp = arg_free; /* reconstuct argv */
if (hide_argv) {
int i;
for (i = 1; i < argc; i++) {
memset(argv[i], 0, strlen(argv[i]));
}
}
zend_is_auto_global_str(ZEND_STRL("_SERVER"));
PG(during_request_startup) = 0;
switch (behavior) {
case PHP_MODE_STANDARD:
if (strcmp(file_handle.filename, "-")) {
cli_register_file_handles();
}
if (interactive && cli_shell_callbacks.cli_shell_run) {
exit_status = cli_shell_callbacks.cli_shell_run();
} else {
php_execute_script(&file_handle);
exit_status = EG(exit_status);
}
break;
case PHP_MODE_LINT:
exit_status = php_lint_script(&file_handle);
if (exit_status==SUCCESS) {
zend_printf("No syntax errors detected in %s\n", file_handle.filename);
} else {
zend_printf("Errors parsing %s\n", file_handle.filename);
}
break;
case PHP_MODE_STRIP:
if (open_file_for_scanning(&file_handle)==SUCCESS) {
zend_strip();
}
goto out;
break;
case PHP_MODE_HIGHLIGHT:
{
zend_syntax_highlighter_ini syntax_highlighter_ini;
if (open_file_for_scanning(&file_handle)==SUCCESS) {
示例13: mbfl_string_init_set
/* {{{ mbfl_no_encoding _php_mb_encoding_handler_ex() */
const mbfl_encoding *_php_mb_encoding_handler_ex(const php_mb_encoding_handler_info_t *info, zval *arg, char *res)
{
char *var, *val;
const char *s1, *s2;
char *strtok_buf = NULL, **val_list = NULL;
zval *array_ptr = (zval *) arg;
int n, num, *len_list = NULL;
size_t val_len, new_val_len;
mbfl_string string, resvar, resval;
const mbfl_encoding *from_encoding = NULL;
mbfl_encoding_detector *identd = NULL;
mbfl_buffer_converter *convd = NULL;
mbfl_string_init_set(&string, info->to_language, info->to_encoding->no_encoding);
mbfl_string_init_set(&resvar, info->to_language, info->to_encoding->no_encoding);
mbfl_string_init_set(&resval, info->to_language, info->to_encoding->no_encoding);
if (!res || *res == '\0') {
goto out;
}
/* count the variables(separators) contained in the "res".
* separator may contain multiple separator chars.
*/
num = 1;
for (s1=res; *s1 != '\0'; s1++) {
for (s2=info->separator; *s2 != '\0'; s2++) {
if (*s1 == *s2) {
num++;
}
}
}
num *= 2; /* need space for variable name and value */
val_list = (char **)ecalloc(num, sizeof(char *));
len_list = (int *)ecalloc(num, sizeof(int));
/* split and decode the query */
n = 0;
strtok_buf = NULL;
var = php_strtok_r(res, info->separator, &strtok_buf);
while (var) {
val = strchr(var, '=');
if (val) { /* have a value */
len_list[n] = php_url_decode(var, val-var);
val_list[n] = var;
n++;
*val++ = '\0';
val_list[n] = val;
len_list[n] = php_url_decode(val, strlen(val));
} else {
len_list[n] = php_url_decode(var, strlen(var));
val_list[n] = var;
n++;
val_list[n] = "";
len_list[n] = 0;
}
n++;
var = php_strtok_r(NULL, info->separator, &strtok_buf);
}
if (n > (PG(max_input_vars) * 2)) {
php_error_docref(NULL, E_WARNING, "Input variables exceeded %pd. To increase the limit change max_input_vars in php.ini.", PG(max_input_vars));
goto out;
}
num = n; /* make sure to process initialized vars only */
/* initialize converter */
if (info->num_from_encodings <= 0) {
from_encoding = &mbfl_encoding_pass;
} else if (info->num_from_encodings == 1) {
from_encoding = info->from_encodings[0];
} else {
/* auto detect */
from_encoding = NULL;
identd = mbfl_encoding_detector_new2(info->from_encodings, info->num_from_encodings, MBSTRG(strict_detection));
if (identd != NULL) {
n = 0;
while (n < num) {
string.val = (unsigned char *)val_list[n];
string.len = len_list[n];
if (mbfl_encoding_detector_feed(identd, &string)) {
break;
}
n++;
}
from_encoding = mbfl_encoding_detector_judge2(identd);
mbfl_encoding_detector_delete(identd);
}
if (!from_encoding) {
if (info->report_errors) {
php_error_docref(NULL, E_WARNING, "Unable to detect encoding");
}
from_encoding = &mbfl_encoding_pass;
}
}
//.........这里部分代码省略.........
示例14: php_mail
/* {{{ php_mail
*/
PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd)
{
#ifdef PHP_WIN32
int tsm_err;
char *tsm_errmsg = NULL;
#endif
FILE *sendmail;
int ret;
char *sendmail_path = INI_STR("sendmail_path");
char *sendmail_cmd = NULL;
char *mail_log = INI_STR("mail.log");
char *hdr = headers;
#if PHP_SIGCHILD
void (*sig_handler)() = NULL;
#endif
#define MAIL_RET(val) \
if (hdr != headers) { \
efree(hdr); \
} \
return val; \
if (mail_log && *mail_log) {
char *tmp;
time_t curtime;
size_t l;
zend_string *date_str;
time(&curtime);
date_str = php_format_date("d-M-Y H:i:s e", 13, curtime, 1);
l = spprintf(&tmp, 0, "[%s] mail() on [%s:%d]: To: %s -- Headers: %s -- Subject: %s\n", ZSTR_VAL(date_str), zend_get_executed_filename(), zend_get_executed_lineno(), to, hdr ? hdr : "", subject);
zend_string_free(date_str);
if (hdr) {
php_mail_log_crlf_to_spaces(tmp);
}
if (!strcmp(mail_log, "syslog")) {
/* Drop the final space when logging to syslog. */
tmp[l - 1] = 0;
php_mail_log_to_syslog(tmp);
}
else {
/* Convert the final space to a newline when logging to file. */
tmp[l - 1] = '\n';
php_mail_log_to_file(mail_log, tmp, l);
}
efree(tmp);
}
if (PG(mail_x_header)) {
const char *tmp = zend_get_executed_filename();
zend_string *f;
f = php_basename(tmp, strlen(tmp), NULL, 0);
if (headers != NULL && *headers) {
spprintf(&hdr, 0, "X-PHP-Originating-Script: " ZEND_LONG_FMT ":%s\n%s", php_getuid(), ZSTR_VAL(f), headers);
} else {
spprintf(&hdr, 0, "X-PHP-Originating-Script: " ZEND_LONG_FMT ":%s", php_getuid(), ZSTR_VAL(f));
}
zend_string_release(f);
}
if (hdr && php_mail_detect_multiple_crlf(hdr)) {
php_error_docref(NULL, E_WARNING, "Multiple or malformed newlines found in additional_header");
MAIL_RET(0);
}
if (!sendmail_path) {
#ifdef PHP_WIN32
/* handle old style win smtp sending */
if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, hdr, subject, to, message, NULL, NULL, NULL) == FAILURE) {
if (tsm_errmsg) {
php_error_docref(NULL, E_WARNING, "%s", tsm_errmsg);
efree(tsm_errmsg);
} else {
php_error_docref(NULL, E_WARNING, "%s", GetSMErrorText(tsm_err));
}
MAIL_RET(0);
}
MAIL_RET(1);
#else
MAIL_RET(0);
#endif
}
if (extra_cmd != NULL) {
spprintf(&sendmail_cmd, 0, "%s %s", sendmail_path, extra_cmd);
} else {
sendmail_cmd = sendmail_path;
}
#if PHP_SIGCHILD
/* Set signal handler of SIGCHLD to default to prevent other signal handlers
* from being called and reaping the return code when our child exits.
//.........这里部分代码省略.........
示例15: PHP_METHOD
/* {{{ 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,"edFlag)>0){
spprintf(®ex,0,"[%s\\/]",Z_STRVAL(quotedFlag));
}else{
spprintf(®ex,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);
}
//.........这里部分代码省略.........