예제 #1
0
PHP_METHOD(Edge_Loader, __construct)
{
    char *lib_path;
    char *lib_prefix;
    int lb_len = 0;
    int lp_len = 0;
    if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &lib_path, &lb_len, &lib_prefix, &lp_len) == FAILURE)
    {
        return;
    }
    if(lb_len != 0)
    {
        zend_update_property_string(edge_loader_ce, getThis(), LOADER_DEFAULT_LIB_PATH, sizeof(LOADER_DEFAULT_LIB_PATH)-1, lib_path TSRMLS_DC);
    }

    if(lp_len != 0)
    {
        zend_update_property_string(edge_loader_ce, getThis(), LOADER_DEFAULT_LIB_PREFIX, sizeof(LOADER_DEFAULT_LIB_PREFIX)-1, lib_prefix TSRMLS_DC);
    }
    //op spl_autoload_register function.
    if(!edge_register_autoload(getThis(), "autoload"))
    {
        //throw auto load function register error in here..
        php_errir_docref(NULL TSRMLS_CC, E_WARNING, "Unable to register auto loader function");
    }

}
예제 #2
0
PHP_METHOD(MTF, login) {
	char *url = INI_STR("mtf.url");
	char *user = NULL;
	int user_len;
	
	char *password = NULL;
	int password_len;
	
	int len;
	char *strg;
	
	if(ZEND_NUM_ARGS() == 0){
		user 	 = INI_STR("mtf.user");
		password = INI_STR("mtf.password");
	} else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &user, &user_len, &password, &password_len) == FAILURE) {
		return;
	}
	
	char *result = login(url, user, password);
	char *session = login_session_id(result);
	if(session){
		zend_update_property_string(object, getThis(), "session", strlen("session"), session TSRMLS_CC);
	}
	zend_update_property_string(object, getThis(), "debug", strlen("debug"), result TSRMLS_CC);
	len = spprintf(&strg, 0, "%s", result);
	RETURN_STRINGL(strg, len, 0);
}
예제 #3
0
파일: objects1.c 프로젝트: Leon2012/php-ext
static PHP_METHOD(Hello, updateProperties) {

    zval *obj;
    obj = getThis();

    zend_update_property_string(hello_ce, obj, "name", sizeof("name") -1, "name-update" TSRMLS_CC);//更新属性值, $this->name = name
    zend_update_property_long(hello_ce, obj, "age", sizeof("age") -1, 10 TSRMLS_CC); //this->age = age
    zend_update_property_string(hello_ce, obj, "last_name", sizeof("last_name") -1, "leon-update" TSRMLS_CC);//this->last_name = "leon"
    zend_update_property_null(hello_ce, obj, "first_name", sizeof("first_name") - 1 TSRMLS_CC); //this->first_name = null;
    zend_update_property_bool(hello_ce, obj, "sex", sizeof("sex") -1, 0 TSRMLS_CC); //this->sex = true
    zend_update_property_double(hello_ce, obj, "score", sizeof("score") -1, 15.50 TSRMLS_CC); //this->score = 12.50
}
예제 #4
0
/**{{{ proto Mylogs::logInit
*/
PHP_METHOD(Mylogs, logInit) {
	long level, maxNum, maxSize;
	char  *logPath, *fileName;
	int logPath_len, fileName_len;
	zval *instance = _getInstance();
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllss", &level, &maxNum, &maxSize, &logPath, &logPath_len, &fileName, &fileName_len) == FAILURE)
		return;

	zend_update_property_long(mylogs_ce, instance, ZEND_STRL(MYLOGS_LEVEL), level TSRMLS_CC);
	zend_update_property_long(mylogs_ce, instance, ZEND_STRL(MYLOGS_MAXFILE_NUM), maxNum TSRMLS_CC);
	zend_update_property_long(mylogs_ce, instance, ZEND_STRL(MYLOGS_MAXFILE_SIZE), maxSize TSRMLS_CC);
	zend_update_property_string(mylogs_ce, instance, ZEND_STRL(MYLOGS_PATH), logPath TSRMLS_CC);
	zend_update_property_string(mylogs_ce, instance, ZEND_STRL(MYLOGS_FILE_NAME), fileName TSRMLS_CC);

	RETURN_TRUE;
}
예제 #5
0
static zend_object *zend_default_exception_new_ex(zend_class_entry *class_type, int skip_top_traces) /* {{{ */
{
	zval obj;
	zend_object *object;
	zval trace;
	zend_class_entry *base_ce;
	zend_string *filename;

	Z_OBJ(obj) = object = zend_objects_new(class_type);
	Z_OBJ_HT(obj) = &default_exception_handlers;

	object_properties_init(object, class_type);

	if (EG(current_execute_data)) {
		zend_fetch_debug_backtrace(&trace, skip_top_traces, 0, 0);
	} else {
		array_init(&trace);
	}
	Z_SET_REFCOUNT(trace, 0);

	base_ce = i_get_exception_base(&obj);

	if (EXPECTED(class_type != zend_ce_parse_error || !(filename = zend_get_compiled_filename()))) {
		zend_update_property_string(base_ce, &obj, "file", sizeof("file")-1, zend_get_executed_filename());
		zend_update_property_long(base_ce, &obj, "line", sizeof("line")-1, zend_get_executed_lineno());
	} else {
		zend_update_property_str(base_ce, &obj, "file", sizeof("file")-1, filename);
		zend_update_property_long(base_ce, &obj, "line", sizeof("line")-1, zend_get_compiled_lineno());
	}
	zend_update_property(base_ce, &obj, "trace", sizeof("trace")-1, &trace);

	return object;
}
예제 #6
0
void php_mongo_db_construct(zval *z_client, zval *zlink, char *name, int name_len TSRMLS_DC)
{
	mongo_db *db;
	mongoclient *link;

	if (!php_mongo_db_is_valid_dbname(name, name_len TSRMLS_CC)) {
		return;
	}

	db = (mongo_db*)zend_object_store_get_object(z_client TSRMLS_CC);

	db->link = zlink;
	zval_add_ref(&db->link);

	link = (mongoclient*)zend_object_store_get_object(zlink TSRMLS_CC);
	if (!(link->servers)) {
		zend_throw_exception(mongo_ce_Exception, "The MongoDB object has not been correctly initialized by its constructor", 0 TSRMLS_CC);
		return;
	}

	if (link->servers->options.default_w != -1) {
		zend_update_property_long(mongo_ce_DB, z_client, "w", strlen("w"), link->servers->options.default_w TSRMLS_CC);
	} else if (link->servers->options.default_wstring != NULL) {
		zend_update_property_string(mongo_ce_DB, z_client, "w", strlen("w"), link->servers->options.default_wstring TSRMLS_CC);
	}
	if (link->servers->options.default_wtimeout != -1) {
		zend_update_property_long(mongo_ce_DB, z_client, "wtimeout", strlen("wtimeout"), link->servers->options.default_wtimeout TSRMLS_CC);
	}
	mongo_read_preference_copy(&link->servers->read_pref, &db->read_pref);

	MAKE_STD_ZVAL(db->name);
	ZVAL_STRING(db->name, name, 1);
}
예제 #7
0
파일: glib_util.c 프로젝트: gtkforphp/glib
/* {{{ proto string Glib::userSpecialDir(int user_dir_type)
	   Returns the full path of a special directory using its logical id.
	   One of Glib::USER_DIRECTORY_* constants is supposed to be used as parameter
*/
PHP_METHOD(Glib, userSpecialDir)
{
	long dir_type;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &dir_type) == FAILURE) {
		return;
	}

	if (dir_type < 0 || dir_type >= G_USER_N_DIRECTORIES) {
		zval *exception;

		MAKE_STD_ZVAL(exception);
		object_init_ex(exception, glib_ce_exception);
		zend_update_property_string(glib_ce_exception, exception, "message", sizeof("message")-1, "invalid user-directory type" TSRMLS_CC);
		zend_throw_exception_object(exception TSRMLS_CC);

		return;
	}

	const char *retval = g_get_user_special_dir(dir_type);

	if (NULL == retval) {
		RETURN_NULL();
	}

	RETURN_STRING(retval, 1);
}
예제 #8
0
PHP_METHOD(MTF, change_flag) {
	char *loginname = NULL;
	int loginname_len;
	char *flag = NULL;
	int flag_len;
	
	char *strg;
	int len;
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &loginname, &loginname_len, &flag, &flag_len) == FAILURE) {
		return;
	}
	zval *attrs, *obj;
	obj = getThis();
	attrs = zend_read_property(Z_OBJCE_P(obj), obj, "session", strlen("session"), 0 TSRMLS_CC);
	
    //php_var_dump(&attrs, 1 TSRMLS_CC);
	char *session = Z_STRVAL_P(attrs);
	
	char *xml = NULL;
	if(session){
		char *xmlpro = 	protocol_flag(session, loginname, flag);
		char *url;
		asprintf(&url, "%s/change_member_flag.ucs", INI_STR("mtf.url"));
		xml = conn(url, xmlpro);
		
		char *debug = NULL;
		asprintf(&debug, "%s?%s",url, xmlpro);
		zend_update_property_string(object, getThis(), "debug", strlen("debug"), debug TSRMLS_CC);
	}
	
	len = spprintf(&strg, 0, "%s", xml);
	RETURN_STRINGL(strg, len, 0);
}
예제 #9
0
PHP_METHOD(MTF, balance) {
	char *login = NULL;
	int login_len;

	char *url, *proto;
	char *strg;
	int len;
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &login, &login_len) == FAILURE) {
		return;
	}
	zval *attrs, *obj;
	obj = getThis();
	attrs = zend_read_property(Z_OBJCE_P(obj), obj, "session", strlen("session"), 0 TSRMLS_CC);
	char *session = Z_STRVAL_P(attrs);
	
	char *xml = NULL;
	if(session){
		asprintf(&url, "%s/check_balance.ucs",INI_STR("mtf.url"));
		asprintf(&proto, "sid=%s&loginname=%s", session, login);

		xml = conn(url, proto);
		
		char *debug = NULL;
		asprintf(&debug, "%s?%s",url, proto);
		zend_update_property_string(object, getThis(), "debug", strlen("debug"), debug TSRMLS_CC);
	}
	
	len = spprintf(&strg, 0, "%s", xml);
	RETURN_STRINGL(strg, len, 0);
}
예제 #10
0
/**
 * Throws a zval object as exception
 */
void zephir_throw_exception_debug(zval *object, const char *file, zend_uint line)
{
	zend_class_entry *default_exception_ce;
	int ZEPHIR_LAST_CALL_STATUS = 0;
	zval curline;
	zval object_copy;

	ZVAL_UNDEF(&curline);

	ZEPHIR_MM_GROW();

	if (Z_TYPE_P(object) != IS_OBJECT) {
		ZVAL_COPY_VALUE(&object_copy, object);
		object_init_ex(object, zend_exception_get_default());
		ZEPHIR_CALL_METHOD(NULL, object, "__construct", NULL, 0, &object_copy);
		zval_ptr_dtor(&object_copy);
	}

	Z_ADDREF_P(object);

	if (line > 0) {
		ZEPHIR_CALL_METHOD(&curline, object, "getline", NULL, 0);
		zephir_check_call_status();
		if (ZEPHIR_IS_LONG(&curline, 0)) {
			default_exception_ce = zend_exception_get_default();
			zend_update_property_string(default_exception_ce, object, SL("file"), file);
			zend_update_property_long(default_exception_ce, object, SL("line"), line);
		}
	}

	if (ZEPHIR_LAST_CALL_STATUS != FAILURE) {
		zend_throw_exception_object(object);
	}
	ZEPHIR_MM_RESTORE();
}
예제 #11
0
파일: rlogger.c 프로젝트: hnw/php-rlogger
/* {{{ proto void Rlogger::close()
 */
PHP_METHOD(rlogger, close)
{
	zval *object = getThis();
	php_rlogger_object *rlogger_obj;

	if (zend_parse_parameters_none() == FAILURE) {
		return;
	}

#if PHP_VERSION_ID >= 70000
	rlogger_obj = Z_RLOGGER_P(object);
#else
	rlogger_obj = (php_rlogger_object *)zend_object_store_get_object(object TSRMLS_CC);
#endif

	if (rlogger_obj->initialized) {
		if (rlogger_obj->rlog) {
			rlog_close(rlogger_obj->rlog);
			rlogger_obj->rlog = NULL;
		}
		rlogger_obj->initialized = 0;
		zend_update_property_string(php_rlogger_entry, object, "address", sizeof("address") - 1, "" TSRMLS_CC);
	}

	return;
}
예제 #12
0
PHP_METHOD(MTF, __construct) {
	// TODO     
	//php_printf("Hello\n");  
	char *str="2014-08-27";
	zend_update_property_string(object, getThis(), "version", strlen("version"), str TSRMLS_CC);
	//zend_update_property_string(object, getThis(), "session", strlen("session"), session TSRMLS_CC);
}
예제 #13
0
/* {{{ proto ErrorException::__construct(string message, int code, int severity [, string filename [, int lineno [, Throwable previous]]])
   ErrorException constructor */
ZEND_METHOD(error_exception, __construct)
{
	char  *message = NULL, *filename = NULL;
	zend_long   code = 0, severity = E_ERROR, lineno;
	zval  *object, *previous = NULL;
	int    argc = ZEND_NUM_ARGS();
	size_t message_len, filename_len;

	if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc, "|sllslO!", &message, &message_len, &code, &severity, &filename, &filename_len, &lineno, &previous, zend_ce_throwable) == FAILURE) {
		zend_class_entry *ce;

		if (execute_data->called_scope) {
			ce = execute_data->called_scope;
		} else {
			ce = zend_ce_error_exception;
		}
		zend_throw_error(NULL, "Wrong parameters for %s([string $message [, long $code, [ long $severity, [ string $filename, [ long $lineno  [, Throwable $previous = NULL]]]]]])", ZSTR_VAL(ce->name));
		return;
	}

	object = getThis();

	if (message) {
		zend_update_property_string(zend_ce_exception, object, "message", sizeof("message")-1, message);
	}

	if (code) {
		zend_update_property_long(zend_ce_exception, object, "code", sizeof("code")-1, code);
	}

	if (previous) {
		zend_update_property(zend_ce_exception, object, "previous", sizeof("previous")-1, previous);
	}

	zend_update_property_long(zend_ce_error_exception, object, "severity", sizeof("severity")-1, severity);

	if (argc >= 4) {
	    zend_update_property_string(zend_ce_exception, object, "file", sizeof("file")-1, filename);
    	if (argc < 5) {
    	    lineno = 0; /* invalidate lineno */
    	}
		zend_update_property_long(zend_ce_exception, object, "line", sizeof("line")-1, lineno);
	}
}
예제 #14
0
파일: curl_file.c 프로젝트: AzerTyQsdF/osx
static void curlfile_set_property(char *name, INTERNAL_FUNCTION_PARAMETERS)
{
	char *arg = NULL;
	int arg_len;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
		return;
	}
	zend_update_property_string(curl_CURLFile_class, getThis(), name, strlen(name), arg TSRMLS_CC);
}
예제 #15
0
파일: curl_file.c 프로젝트: AllenJB/php-src
static void curlfile_set_property(char *name, size_t name_len, INTERNAL_FUNCTION_PARAMETERS)
{
	zend_string *arg;

	ZEND_PARSE_PARAMETERS_START(1,1)
		Z_PARAM_STR(arg)
	ZEND_PARSE_PARAMETERS_END();

	zend_update_property_string(curl_CURLFile_class, getThis(), name, name_len, ZSTR_VAL(arg));
}
예제 #16
0
void php_mysqli_throw_sql_exception(char *sqlstate, int errorno TSRMLS_DC, char *format, ...) 
{
	zval	*sql_ex;
	va_list arg;
	char 	*message;

	va_start(arg, format); 
	vspprintf(&message, 0, format, arg);
	va_end(arg);;

#if WANT_EXCEPTIONS
	if (!(MyG(report_mode) & MYSQLI_REPORT_STRICT))
#endif
	{
	 	php_error_docref(NULL TSRMLS_CC, E_WARNING, "(%s/%d): %s", sqlstate, errorno, message);
		efree(message);
		return;
	}

#if WANT_EXCEPTIONS
	MAKE_STD_ZVAL(sql_ex);
	object_init_ex(sql_ex, mysqli_exception_class_entry);

	if (message) {
		zend_update_property_string(mysqli_exception_class_entry, sql_ex, "message", sizeof("message") - 1,
									message TSRMLS_CC);
	}

	if (sqlstate) {
		zend_update_property_string(mysqli_exception_class_entry, sql_ex, "sqlstate", sizeof("sqlstate") - 1,
									sqlstate TSRMLS_CC);
	} else {
		zend_update_property_string(mysqli_exception_class_entry, sql_ex, "sqlstate", sizeof("sqlstate") - 1,
									"00000" TSRMLS_CC);
	}

	efree(message);
	zend_update_property_long(mysqli_exception_class_entry, sql_ex, "code", sizeof("code") - 1, errorno TSRMLS_CC);

	zend_throw_exception_object(sql_ex TSRMLS_CC);
#endif
}
예제 #17
0
void ctypes_exception(char * message, int errorno TSRMLS_DC)
{
    zval * tc_ex;

    MAKE_STD_ZVAL(tc_ex);
    object_init_ex(tc_ex, class_ce);

    zend_update_property_string(class_ce, tc_ex, "message", sizeof("message") - 1,
            message TSRMLS_CC);
    zend_throw_exception_object(tc_ex TSRMLS_CC);
}
예제 #18
0
파일: curl_file.c 프로젝트: AzerTyQsdF/osx
static void curlfile_ctor(INTERNAL_FUNCTION_PARAMETERS)
{
	char *fname = NULL, *mime = NULL, *postname = NULL;
	int fname_len, mime_len, postname_len;
	zval *cf = return_value;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ss", &fname, &fname_len, &mime, &mime_len, &postname, &postname_len) == FAILURE) {
		return;
	}

	if (fname) {
		zend_update_property_string(curl_CURLFile_class, cf, "name", sizeof("name")-1, fname TSRMLS_CC);
	}

	if (mime) {
		zend_update_property_string(curl_CURLFile_class, cf, "mime", sizeof("mime")-1, mime TSRMLS_CC);
	}

	if (postname) {
		zend_update_property_string(curl_CURLFile_class, cf, "postname", sizeof("postname")-1, postname TSRMLS_CC);
	}
}
예제 #19
0
파일: curl_file.c 프로젝트: AllenJB/php-src
static void curlfile_ctor(INTERNAL_FUNCTION_PARAMETERS)
{
	zend_string *fname, *mime = NULL, *postname = NULL;
	zval *cf = return_value;

	ZEND_PARSE_PARAMETERS_START(1,3)
		Z_PARAM_PATH_STR(fname)
		Z_PARAM_OPTIONAL
		Z_PARAM_STR(mime)
		Z_PARAM_STR(postname)
	ZEND_PARSE_PARAMETERS_END();

	zend_update_property_string(curl_CURLFile_class, cf, "name", sizeof("name")-1, ZSTR_VAL(fname));

	if (mime) {
		zend_update_property_string(curl_CURLFile_class, cf, "mime", sizeof("mime")-1, ZSTR_VAL(mime));
	}

	if (postname) {
		zend_update_property_string(curl_CURLFile_class, cf, "postname", sizeof("postname")-1, ZSTR_VAL(postname));
	}
}
예제 #20
0
zend_object * pion_exception_new(zend_class_entry * exception_ce, const char * message, long code) {
    zval ex;
//    A(ex);
    object_init_ex(&ex, exception_ce);
//    zend_objects_new();
    if (message) {
        zend_update_property_string(exception_ce, &ex, "message", sizeof("message")-1, message);
    }
    if (code) {
        zend_update_property_long(exception_ce, &ex, "code", sizeof("code")-1, code);
    }
    return Z_OBJ(ex);
}
예제 #21
0
void php_mysqli_throw_sql_exception(char *sqlstate, int errorno, char *format, ...)
{
	zval	sql_ex;
	va_list arg;
	char 	*message;

	va_start(arg, format);
	vspprintf(&message, 0, format, arg);
	va_end(arg);;

	if (!(MyG(report_mode) & MYSQLI_REPORT_STRICT)) {
	 	php_error_docref(NULL, E_WARNING, "(%s/%d): %s", sqlstate, errorno, message);
		efree(message);
		return;
	}

	object_init_ex(&sql_ex, mysqli_exception_class_entry);

	if (message) {
		zend_update_property_string(mysqli_exception_class_entry, &sql_ex, "message", sizeof("message") - 1,
									message);
	}

	if (sqlstate) {
		zend_update_property_string(mysqli_exception_class_entry, &sql_ex, "sqlstate", sizeof("sqlstate") - 1,
									sqlstate);
	} else {
		zend_update_property_string(mysqli_exception_class_entry, &sql_ex, "sqlstate", sizeof("sqlstate") - 1,
									"00000");
	}

	efree(message);
	zend_update_property_long(mysqli_exception_class_entry, &sql_ex, "code", sizeof("code") - 1, errorno);

	zend_throw_exception_object(&sql_ex);
}
예제 #22
0
zval * create_exception(zend_class_entry *exception_ce, const char *message, long code TSRMLS_DC) {
	zend_class_entry *default_exception_ce = zend_exception_get_default(TSRMLS_C);
	zval *ex;

	MAKE_STD_ZVAL(ex);
	object_init_ex(ex, exception_ce);

	if (message) {
		zend_update_property_string(default_exception_ce, ex, "message", sizeof("message")-1, message TSRMLS_CC);
	}
	if (code) {
		zend_update_property_long(default_exception_ce, ex, "code", sizeof("code")-1, code TSRMLS_CC);
	}

	return ex;
}
예제 #23
0
파일: rlogger.c 프로젝트: hnw/php-rlogger
/* {{{ proto int Rlogger::__construct([string address, [int timeout]])
   __constructor for Rlogger. */
PHP_METHOD(rlogger, __construct)
{
	zval *object = getThis();
	php_rlogger_object *rlogger_obj;
	struct rlog *rlog;
	char *address = NULL;
	size_t address_len;
	int timeout;
	zend_error_handling error_handling;

#if PHP_VERSION_ID >= 70000
	rlogger_obj = Z_RLOGGER_P(object);
#else
	rlogger_obj = (php_rlogger_object *)zend_object_store_get_object(object TSRMLS_CC);
#endif

	if (rlogger_obj->initialized) {
		zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Already initialized Rlogger Object", 0 TSRMLS_CC);
	}

	zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC);
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl", &address, &address_len, &timeout) == FAILURE) {
		zend_restore_error_handling(&error_handling TSRMLS_CC);
		return;
	}
	zend_restore_error_handling(&error_handling TSRMLS_CC);

	switch (ZEND_NUM_ARGS()) {
	case 0:
		address = INI_STR("rlogger.address");
	case 1:
		timeout = INI_INT("rlogger.timeout");
	}

	rlog = rlog_open(address, timeout);
	if (rlog == NULL) {
		zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Unable to open socket: %s", address);
		return;
	}

	rlogger_obj->rlog = rlog;
	rlogger_obj->initialized = 1;

	zend_update_property_string(php_rlogger_entry, object, "address", sizeof("address") - 1, address TSRMLS_CC);
}
예제 #24
0
/* {{{ MongoDB::__construct
 */
PHP_METHOD(MongoDB, __construct) {
    zval *zlink;
    char *name;
    int name_len;
    mongo_db *db;
    mongoclient *link;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os", &zlink, mongo_ce_MongoClient, &name, &name_len) == FAILURE) {
        zval *object = getThis();
        ZVAL_NULL(object);
        return;
    }

    if (0 == name_len ||
            0 != strchr(name, ' ') || 0 != strchr(name, '.') || 0 != strchr(name, '\\') ||
            0 != strchr(name, '/') || 0 != strchr(name, '$')) {
#if ZEND_MODULE_API_NO >= 20060613
        zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "MongoDB::__construct(): invalid name %s", name);
#else
        zend_throw_exception_ex(zend_exception_get_default(), 0 TSRMLS_CC, "MongoDB::__construct(): invalid name %s", name);
#endif /* ZEND_MODULE_API_NO >= 20060613 */
        return;
    }

    db = (mongo_db*)zend_object_store_get_object(getThis() TSRMLS_CC);

    db->link = zlink;
    zval_add_ref(&db->link);

    PHP_MONGO_GET_LINK(zlink);

    if (link->servers->options.default_w != -1) {
        zend_update_property_long(mongo_ce_DB, getThis(), "w", strlen("w"), link->servers->options.default_w TSRMLS_CC);
    } else if (link->servers->options.default_wstring != NULL) {
        zend_update_property_string(mongo_ce_DB, getThis(), "w", strlen("w"), link->servers->options.default_wstring TSRMLS_CC);
    }
    if (link->servers->options.default_wtimeout != -1) {
        zend_update_property_long(mongo_ce_DB, getThis(), "wtimeout", strlen("wtimeout"), link->servers->options.default_wtimeout TSRMLS_CC);
    }
    mongo_read_preference_copy(&link->servers->read_pref, &db->read_pref);

    MAKE_STD_ZVAL(db->name);
    ZVAL_STRING(db->name, name, 1);
}
예제 #25
0
static void swoole_redis_onResult(redisAsyncContext *c, void *r, void *privdata)
{
#if PHP_MAJOR_VERSION < 7
    TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL);
#endif

    redisReply *reply = r;
    if (reply == NULL)
    {
        return;
    }

    swRedisClient *redis = c->ev.data;
    zval *result, *retval;
    SW_MAKE_STD_ZVAL(result);

    if (reply->str == NULL)
    {
        ZVAL_BOOL(result, 0);
        zend_update_property_long(swoole_redis_class_entry_ptr, redis->object, ZEND_STRL("errCode"), c->err TSRMLS_CC);
        zend_update_property_string(swoole_redis_class_entry_ptr, redis->object, ZEND_STRL("errMsg"), c->errstr TSRMLS_CC);
    }
    else
    {
        SW_ZVAL_STRINGL(result, reply->str, reply->len, 1);
    }

    redis->state = SWOOLE_REDIS_STATE_READY;

    zval **args[2];
    args[0] = &redis->object;
    args[1] = &result;

    if (sw_call_user_function_ex(EG(function_table), NULL, redis->result_callback, &retval, 2, args, 0, NULL TSRMLS_CC) != SUCCESS)
    {
        swoole_php_fatal_error(E_WARNING, "swoole_async_mysql callback handler error.");
    }
    if (retval != NULL)
    {
        sw_zval_ptr_dtor(&retval);
    }
    sw_zval_ptr_dtor(&result);
}
예제 #26
0
void make_exception(zapval *ex, zend_class_entry *exception_ce, const char *message, long code TSRMLS_DC) {
    zapval_alloc(*ex);
    object_init_ex(zapval_zvalptr_p(ex), cb_exception_ce);

    if (message) {
        zend_update_property_string(
                cb_exception_ce,
                zapval_zvalptr_p(ex),
                "message", sizeof("message")-1,
                message TSRMLS_CC);
    }
    if (code) {
        zend_update_property_long(
                cb_exception_ce,
                zapval_zvalptr_p(ex),
                "code", sizeof("code")-1,
                code TSRMLS_CC);
    }
}
예제 #27
0
PHP_METHOD(MTF, result){
	char *arg = NULL;
	int arg_len, len;
	char *strg;
	
	zend_update_property_string(object, getThis(), "debug", strlen("debug"), "" TSRMLS_CC);

	array_init(return_value);
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
		return;
	}
	xmlDocPtr doc = xmlParseDoc(arg);
	if (doc == NULL ) {
		fprintf(stderr,"Document not parsed successfully. \n");
		return;
	}
	xmlNodePtr cur = xmlDocGetRootElement(doc);
	
	if (cur == NULL) {
		fprintf(stderr,"empty document\n");
		xmlFreeDoc(doc);
		return;
	}
	
	if (xmlStrcmp(cur->name, (const xmlChar *) "Result")) {
		fprintf(stderr,"document of the wrong type, root node != story");
		xmlFreeDoc(doc);
		return;
	}

	if ((!xmlStrcmp(cur->name, (const xmlChar *)"Result"))) {
		//printf("uri: %s\n", xmlGetProp(cur, "Code"));
		xmlAttrPtr attr;
		for(attr = cur->properties; NULL != attr; attr = attr->next){
			//printf("uri: %s\n", xmlGetProp(cur, attr->name));
			add_assoc_string(return_value, attr->name, (char *)xmlGetProp(cur, attr->name), 1);
		}
	}

	xmlFreeDoc(doc);
}
예제 #28
0
PHP_METHOD(MTF, demo) {
	char *arg = NULL;
	int arg_len, len;
	char *strg;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) == FAILURE) {
		return;
	}
	
	char *xmlpro = 	protocol_demo(arg);
	char *url;
	asprintf(&url, "%s/add_demo_member.ucs", INI_STR("mtf.url"));		
	char *xml = conn(url, xmlpro);
	char *debug = NULL;
	asprintf(&debug, "%s?%s",url, xmlpro);
	zend_update_property_string(object, getThis(), "debug", strlen("debug"), debug TSRMLS_CC);
	
	len = spprintf(&strg, 0, "%s", xml);
	RETURN_STRINGL(strg, len, 0);
}
예제 #29
0
char * exception_error(zval *exception, int severity TSRMLS_DC) {
    char * result;
    zend_class_entry *ce_exception = Z_OBJCE_P(exception);
    if (instanceof_function(ce_exception, default_exception_ce TSRMLS_CC)) {
        zval *str, *file, *line;

        EG(exception) = NULL;
        zend_call_method(&exception, ce_exception, NULL, "__tostring", 10, &str, 0, NULL, NULL TSRMLS_CC);
        if (!EG(exception)) {
            if (Z_TYPE_P(str) != IS_STRING) {
                result = "Exception::__toString() must return a string";
            } else {
                zend_update_property_string(default_exception_ce, exception, "string", sizeof("string")-1, EG(exception) ? ce_exception->name : Z_STRVAL_P(str) TSRMLS_CC);
            }
        }
        zval_ptr_dtor(&str);

        if (EG(exception)) {
            /* do the best we can to inform about the inner exception */
            if (instanceof_function(ce_exception, default_exception_ce TSRMLS_CC)) {
                file = zend_read_property(default_exception_ce, EG(exception), "file", sizeof("file")-1, 1 TSRMLS_CC);
                line = zend_read_property(default_exception_ce, EG(exception), "line", sizeof("line")-1, 1 TSRMLS_CC);
            } else {
                file = NULL;
                line = NULL;
            }
            result = "Uncaught in exception handling during call to __tostring()";
        }

        str = zend_read_property(default_exception_ce, exception, "string", sizeof("string")-1, 1 TSRMLS_CC);
        file = zend_read_property(default_exception_ce, exception, "file", sizeof("file")-1, 1 TSRMLS_CC);
        line = zend_read_property(default_exception_ce, exception, "line", sizeof("line")-1, 1 TSRMLS_CC);

        result = "Uncaught %s\n  thrown";
    } else {
        size_t n = snprintf(NULL, 0, "Uncaught exception '%s'", ce_exception->name);
        result = malloc(n + 1);
        snprintf(result, n + 1, "Uncaught exception '%s'", ce_exception->name);
    }
    return result;
}
예제 #30
0
PHP_METHOD(MTF, transfer) {
	char *login = NULL;
	int login_len;
	char *amount = NULL;
	int amount_len;
	char *extdata = NULL;
	int extdata_len;
	char *dealid = NULL;
	int dealid_len;
	
	char *url, *proto;
	char *strg;
	int len;
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssss", &login, &login_len, &amount, &amount_len, &extdata, &extdata_len, &dealid, &dealid_len) == FAILURE) {
		return;
	}
	zval *attrs, *obj;
	obj = getThis();
	attrs = zend_read_property(Z_OBJCE_P(obj), obj, "session", strlen("session"), 0 TSRMLS_CC);
	char *session = Z_STRVAL_P(attrs);
	
	char *xml = NULL;
	char *debug = NULL;
	
	if(session){
		asprintf(&url, "%s/SpecialAPI/member_transfer.ucs",INI_STR("mtf.url"));
		asprintf(&proto, "sid=%s&Login=%s&Amount=%s&ExtData=%s&DealID=%s", session, login, amount, extdata, dealid);
		asprintf(&debug, "%s?%s",url, proto);
		
		xml = conn(url, proto);
		zend_update_property_string(object, getThis(), "debug", strlen("debug"), debug TSRMLS_CC);
		//printf("url %s\nxml: %s\n", url, xml);
	}
	
	len = spprintf(&strg, 0, "%s", xml);
	RETURN_STRINGL(strg, len, 0);
}