Beispiel #1
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);
}
Beispiel #2
0
/* {{{ proto AMQPDecimal::__construct(int $e, int $n)
 */
static PHP_METHOD(amqp_decimal_class, __construct)
{
    PHP5to7_param_long_type_t exponent, significand;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &exponent, &significand) == FAILURE) {
		return;
	}

	if (exponent < AMQP_DECIMAL_EXPONENT_MIN) {
		zend_throw_exception_ex(amqp_value_exception_class_entry, 0 TSRMLS_CC, "Decimal exponent value must be unsigned.");
		return;
	}

	if (exponent > AMQP_DECIMAL_EXPONENT_MAX) {
		zend_throw_exception_ex(amqp_value_exception_class_entry, 0 TSRMLS_CC, "Decimal exponent value must be less than %u.", AMQP_DECIMAL_EXPONENT_MAX);
		return;
	}
    if (significand < AMQP_DECIMAL_SIGNIFICAND_MIN) {
        zend_throw_exception_ex(amqp_value_exception_class_entry, 0 TSRMLS_CC, "Decimal significand value must be unsigned.");
        return;
    }

    if (significand > AMQP_DECIMAL_SIGNIFICAND_MAX) {
        zend_throw_exception_ex(amqp_value_exception_class_entry, 0 TSRMLS_CC, "Decimal significand value must be less than %u.", AMQP_DECIMAL_SIGNIFICAND_MAX);
        return;
    }

    zend_update_property_long(this_ce, getThis(), ZEND_STRL("exponent"), exponent TSRMLS_CC);
    zend_update_property_long(this_ce, getThis(), ZEND_STRL("significand"), significand TSRMLS_CC);
}
Beispiel #3
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;
}
Beispiel #4
0
static PHP_METHOD(swoole_process, useQueue)
{
    long msgkey = 0;
    long mode = 2;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &msgkey, &mode) == FAILURE)
    {
        RETURN_FALSE;
    }

    swWorker *process = swoole_get_object(getThis());

    if (msgkey <= 0)
    {
#if PHP_MAJOR_VERSION >= 7
        msgkey = ftok(zend_get_executed_filename(), 0);
#else
        msgkey = ftok(zend_get_executed_filename(TSRMLS_C), 0);
#endif
    }

    swMsgQueue *queue = emalloc(sizeof(swMsgQueue));
    if (swMsgQueue_create(queue, 1, msgkey, 0) < 0)
    {
        RETURN_FALSE;
    }
    queue->remove = 0;
    process->queue = queue;
    process->ipc_mode = mode;
    zend_update_property_long(swoole_process_class_entry_ptr, getThis(), ZEND_STRL("msgQueueId"), queue->msg_id TSRMLS_CC);
    zend_update_property_long(swoole_process_class_entry_ptr, getThis(), ZEND_STRL("msgQueueKey"), msgkey TSRMLS_CC);
    RETURN_TRUE;
}
Beispiel #5
0
int swoole_websocket_onMessage(swEventData *req)
{
#if PHP_MAJOR_VERSION < 7
    TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL);
#endif

    int fd = req->info.fd;
    zval *zdata;
    SW_MAKE_STD_ZVAL(zdata);
    zdata = php_swoole_get_recv_data(zdata, req TSRMLS_CC);

    char *buf = Z_STRVAL_P(zdata);
    long finish = buf[0] ? 1 : 0;
    long opcode = buf[1] ? 1 : 0;

    zval *zframe;
    SW_MAKE_STD_ZVAL(zframe);
    object_init_ex(zframe, swoole_websocket_frame_class_entry_ptr);

    zend_update_property_long(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("fd"), fd TSRMLS_CC);
    zend_update_property_long(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("finish"), finish TSRMLS_CC);
    zend_update_property_long(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("opcode"), opcode TSRMLS_CC);
    zend_update_property_stringl(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("data"), buf + 2, (Z_STRLEN_P(zdata) - 2) TSRMLS_CC);

    swServer *serv = SwooleG.serv;
    zval *zserv = (zval *) serv->ptr2;

    zval **args[2];
    args[0] = &zserv;
    args[1] = &zframe;

    zval *retval = NULL;

    if (sw_call_user_function_ex(EG(function_table), NULL, websocket_callbacks[WEBSOCKET_CALLBACK_onMessage], &retval, 2,
            args, 0, NULL TSRMLS_CC) == FAILURE)
    {
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "onMessage handler error");
    }

    if (EG(exception))
    {
        zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
    }

    if (retval)
    {
        sw_zval_ptr_dtor(&retval);
    }

    sw_zval_ptr_dtor(&zdata);
    sw_zval_ptr_dtor(&zframe);

    return SW_OK;
}
int swoole_websocket_onMessage(swEventData *req)
{
#if PHP_MAJOR_VERSION < 7
    TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL);
#endif

    int fd = req->info.fd;

    zval *zdata;
    SW_MAKE_STD_ZVAL(zdata);

    char frame_header[2];
    php_swoole_get_recv_data(zdata, req, frame_header, 2);

    long finish = frame_header[0] ? 1 : 0;
    long opcode = frame_header[1];

    zval *zframe;
    SW_MAKE_STD_ZVAL(zframe);
    object_init_ex(zframe, swoole_websocket_frame_class_entry_ptr);

    zend_update_property_long(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("fd"), fd TSRMLS_CC);
    zend_update_property_bool(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("finish"), finish TSRMLS_CC);
    zend_update_property_long(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("opcode"), opcode TSRMLS_CC);
    zend_update_property(swoole_websocket_frame_class_entry_ptr, zframe, ZEND_STRL("data"), zdata TSRMLS_CC);

    swServer *serv = SwooleG.serv;
    zval *zserv = (zval *) serv->ptr2;

    zval **args[2];
    args[0] = &zserv;
    args[1] = &zframe;

    zval *retval = NULL;
    zval *zcallback = php_swoole_server_get_callback(serv, req->info.from_fd, SW_SERVER_CB_onMessage);
    if (sw_call_user_function_ex(EG(function_table), NULL, zcallback, &retval, 2, args, 0, NULL TSRMLS_CC) == FAILURE)
    {
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "onMessage handler error");
    }
    if (EG(exception))
    {
        zend_exception_error(EG(exception), E_ERROR TSRMLS_CC);
    }
    if (retval)
    {
        sw_zval_ptr_dtor(&retval);
    }
    sw_zval_ptr_dtor(&zdata);
    sw_zval_ptr_dtor(&zframe);
    return SW_OK;
}
PHP_METHOD(MongoCollection, __construct) {
  zval *parent, *name, *zns, *w, *wtimeout;
  mongo_collection *c;
  mongo_db *db;
  char *ns, *name_str;
  int name_len;

  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os", &parent, mongo_ce_DB, &name_str, &name_len) == FAILURE) {
    zval *object = getThis();
    ZVAL_NULL(object);
    return;
  }

  // check for empty collection name
  if (name_len == 0) {
#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_str);
#else
    zend_throw_exception_ex(zend_exception_get_default(), 0 TSRMLS_CC, "MongoDB::__construct(): invalid name %s", name_str);
#endif /* ZEND_MODULE_API_NO >= 20060613 */
    return;
  }

  c = (mongo_collection*)zend_object_store_get_object(getThis() TSRMLS_CC);

  PHP_MONGO_GET_DB(parent);

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

  c->parent = parent;
  zval_add_ref(&parent);

  MAKE_STD_ZVAL(name);
  ZVAL_STRINGL(name, name_str, name_len, 1);
  c->name = name;

  spprintf(&ns, 0, "%s.%s", Z_STRVAL_P(db->name), Z_STRVAL_P(name));

  MAKE_STD_ZVAL(zns);
  ZVAL_STRING(zns, ns, 0);
  c->ns = zns;
  mongo_read_preference_copy(&db->read_pref, &c->read_pref);

  w = zend_read_property(mongo_ce_DB, parent, "w", strlen("w"), NOISY TSRMLS_CC);
  zend_update_property_long(mongo_ce_Collection, getThis(), "w", strlen("w"), Z_LVAL_P(w) TSRMLS_CC);
  wtimeout = zend_read_property(mongo_ce_DB, parent, "wtimeout", strlen("wtimeout"), NOISY TSRMLS_CC);
  zend_update_property_long(mongo_ce_Collection, getThis(), "wtimeout", strlen("wtimeout"), Z_LVAL_P(wtimeout) TSRMLS_CC);
}
Beispiel #8
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;
}
Beispiel #9
0
void php_mongo_mongodate_populate(zval *mongodate_object, long sec, long usec TSRMLS_DC)
{
	mongo_date *date;
	int64_t internal_date = 0;

	internal_date += usec / 1000;
	internal_date += (sec * 1000);

	usec = (usec / 1000) * 1000;
	
	zend_update_property_long(mongo_ce_Date, mongodate_object, "usec", strlen("usec"), usec TSRMLS_CC);
	zend_update_property_long(mongo_ce_Date, mongodate_object, "sec", strlen("sec"), sec TSRMLS_CC);

	date = (mongo_date*) zend_object_store_get_object(mongodate_object TSRMLS_CC);
	date->datetime = internal_date;
}
Beispiel #10
0
/* {{{ proto Exception|Error::__construct(string message, int code [, Throwable previous])
   Exception constructor */
ZEND_METHOD(exception, __construct)
{
	zend_string *message = NULL;
	zend_long   code = 0;
	zval  *object, *previous = NULL;
	zend_class_entry *base_ce;
	int    argc = ZEND_NUM_ARGS();

	object = getThis();
	base_ce = i_get_exception_base(object);

	if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, argc, "|SlO!", &message, &code, &previous, zend_ce_throwable) == FAILURE) {
		zend_class_entry *ce;

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

	if (message) {
		zend_update_property_str(base_ce, object, "message", sizeof("message")-1, message);
	}

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

	if (previous) {
		zend_update_property(base_ce, object, "previous", sizeof("previous")-1, previous);
	}
}
Beispiel #11
0
PHP_METHOD(Money, __construct)
{
	long amount;
	zval *currency, *currency_obj;

	if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz", &amount, &currency) == FAILURE) {
		return;
	}

	switch(Z_TYPE_P(currency)) {
		case IS_OBJECT:
			if (!instanceof_function(currency_ce, Z_OBJCE_P(currency))) {
				zend_throw_exception(spl_ce_InvalidArgumentException, "Invalid currency object", 0);
				return;
			}
		break;
		case IS_STRING:
			ALLOC_INIT_ZVAL(currency_obj);
			object_init_ex(currency_obj, currency_ce);
			zend_update_property_stringl(currency_ce, currency_obj, CURRENCY_PROP_CURRENCYCODE_WS, Z_STRVAL_P(currency), Z_STRLEN_P(currency));
			currency = currency_obj;
			Z_DELREF_P(currency);
		break;
		default:
			zend_throw_exception(spl_ce_InvalidArgumentException, "Invalid currency value", 0);
			return;
	}

	zend_update_property_long(Z_OBJCE_P(getThis()), getThis(), MONEY_PROP_AMOUNT_WS, amount);
	zend_update_property(Z_OBJCE_P(getThis()), getThis(), MONEY_PROP_CURRENCY_WS, currency);
}
Beispiel #12
0
static PHP_METHOD(swoole_buffer, clear)
{
    swString *buffer = swoole_get_object(getThis());
    buffer->length = 0;
    buffer->offset = 0;
    zend_update_property_long(swoole_buffer_class_entry_ptr, getThis(), ZEND_STRL("length"), 0 TSRMLS_CC);
}
Beispiel #13
0
static
PHP_METHOD(MsgqueForPhp_MqDumpS, __destruct)
{
  SETUP_dump;
  MqDumpDelete(&dump);
  zend_update_property_long(NS(MqDumpS), getThis(), ID(__ctx), 0L TSRMLS_CC);
}
Beispiel #14
0
static PHP_METHOD(swoole_buffer, __construct)
{
    long size = SW_STRING_BUFFER_DEFAULT;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &size) == FAILURE)
    {
        RETURN_FALSE;
    }

    if (size < 1)
    {
        php_error_docref(NULL TSRMLS_CC, E_ERROR, "buffer size cannot be less than 0");
        RETURN_FALSE;
    }
    else if (size > SW_STRING_BUFFER_MAXLEN)
    {
        php_error_docref(NULL TSRMLS_CC, E_ERROR, "buffer size must not exceed %d", SW_STRING_BUFFER_MAXLEN);
        RETURN_FALSE;
    }

    swString *buffer = swString_new(size);
    if (buffer == NULL)
    {
        php_error_docref(NULL TSRMLS_CC, E_ERROR, "malloc(%ld) failed.", size);
        RETURN_FALSE;
    }

    swoole_set_object(getThis(), buffer);
    zend_update_property_long(swoole_buffer_class_entry_ptr, getThis(), ZEND_STRL("capacity"), size TSRMLS_CC);
}
Beispiel #15
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();
}
Beispiel #16
0
static PHP_METHOD(swoole_process, __construct)
{
    zend_bool redirect_stdin_and_stdout = 0;
    long create_pipe = 1;
    zval *callback;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|bl", &callback, &redirect_stdin_and_stdout, &create_pipe) == FAILURE)
    {
        RETURN_FALSE;
    }

    char *func_name = NULL;
    if (!sw_zend_is_callable(callback, 0, &func_name TSRMLS_CC))
    {
        php_error_docref(NULL TSRMLS_CC, E_ERROR, "function '%s' is not callable", func_name);
        efree(func_name);
        RETURN_FALSE;
    }
    efree(func_name);

    swWorker *process = emalloc(sizeof(swWorker));
    bzero(process, sizeof(swWorker));

    process->id = php_swoole_worker_round_id++;

    if (php_swoole_worker_round_id == 0)
    {
        php_swoole_worker_round_id = 1;
    }

    if (redirect_stdin_and_stdout)
    {
        process->redirect_stdin = 1;
        process->redirect_stdout = 1;
        process->redirect_stderr = 1;
        create_pipe = 1;
    }

    if (create_pipe > 0)
    {
        swPipe *_pipe = emalloc(sizeof(swWorker));
        int socket_type = create_pipe == 1 ? SOCK_STREAM : SOCK_DGRAM;
        if (swPipeUnsock_create(_pipe, 1, socket_type) < 0)
        {
            RETURN_FALSE;
        }
        process->pipe_object = _pipe;
        process->pipe_master = _pipe->getFd(_pipe, SW_PIPE_MASTER);
        process->pipe_worker = _pipe->getFd(_pipe, SW_PIPE_WORKER);
        process->pipe = process->pipe_master;

        zend_update_property_long(swoole_process_class_entry_ptr, getThis(), ZEND_STRL("pipe"), process->pipe_master TSRMLS_CC);
    }

    swoole_set_object(getThis(), process);
    zend_update_property(swoole_process_class_entry_ptr, getThis(), ZEND_STRL("callback"), callback TSRMLS_CC);
}
Beispiel #17
0
/* Timestamp is 4 bytes of seconds since epoch and 4 bytes of increment. */
PHP_METHOD(MongoTimestamp, __construct)
{
    long sec = 0, inc = 0;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &sec, &inc) == FAILURE) {
        return;
    }

    if (ZEND_NUM_ARGS() == 0) {
        sec = time(0);
    }
    if (ZEND_NUM_ARGS() <= 1 && !inc) {
        inc = MonGlo(ts_inc)++;
    }

    zend_update_property_long(mongo_ce_Timestamp, getThis(), "sec", strlen("sec"), sec TSRMLS_CC);
    zend_update_property_long(mongo_ce_Timestamp, getThis(), "inc", strlen("inc"), inc TSRMLS_CC);
}
Beispiel #18
0
PHP_METHOD(pdo_connect_pool_PDOStatement, next)
{
    zval *pos;
    zend_class_entry *ce;
    ce = Z_OBJCE_P(getThis());
    pos = cp_zend_read_property(ce, getThis(), "pos", sizeof ("pos") - 1, 0 TSRMLS_DC);

    zend_update_property_long(ce, getThis(), "pos", sizeof ("pos") - 1, ++Z_LVAL_P(pos) TSRMLS_CC);
}
Beispiel #19
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);
}
Beispiel #20
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);
	}
}
Beispiel #21
0
/* {{{ proto void Riak\BucketProperties->__construct(int $nVal, bool $allowMult)
Creates a new RiakBucketProperties */
PHP_METHOD(RiakBucketProperties, __construct)
{
	long nVal;
	zend_bool allowMult;
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lb", &nVal, &allowMult) == FAILURE) {
		return;
	}
	zend_update_property_long(riak_bucket_properties_ce, getThis(), "nVal", sizeof("nVal")-1, nVal TSRMLS_CC);
	zend_update_property_bool(riak_bucket_properties_ce, getThis(), "allowMult", sizeof("allowMult")-1, allowMult TSRMLS_CC);
}
void NS(MqBufferS_New) (zval *return_value, MQ_BUF buf TSRMLS_DC)
{
    // convert to an object instance
    if (object_init_ex(return_value, NS(MqBufferS)) == FAILURE) {
        RaiseError("unable to create an 'MqBufferS' instance.");
        return;
    }
    // link 'buf' with the object instance
    zend_update_property_long(NS(MqBufferS), return_value, ID(__buf), (long) buf TSRMLS_CC);
    return;
}
static int coro_exit_handler(zend_execute_data *execute_data)
{
    zval ex;
    zend_object *obj;
    zend_long flags = 0;
    if (sw_get_current_cid() != -1)
    {
        flags |= SW_EXIT_IN_COROUTINE;
    }
    if (SwooleG.serv && SwooleG.serv->gs->start)
    {
        flags |= SW_EXIT_IN_SERVER;
    }
    if (flags)
    {
        const zend_op *opline = EX(opline);
        zval _exit_status;
        zval *exit_status = NULL;

        if (opline->op1_type != IS_UNUSED)
        {
            if (opline->op1_type == IS_CONST)
            {
                // see: https://github.com/php/php-src/commit/e70618aff6f447a298605d07648f2ce9e5a284f5
#ifdef EX_CONSTANT
                exit_status = EX_CONSTANT(opline->op1);
#else
                exit_status = RT_CONSTANT(opline, opline->op1);
#endif
            }
            else
            {
                exit_status = EX_VAR(opline->op1.var);
            }
            if (Z_ISREF_P(exit_status))
            {
                exit_status = Z_REFVAL_P(exit_status);
            }
        }
        else
        {
            exit_status = &_exit_status;
            ZVAL_NULL(exit_status);
        }
        obj = zend_throw_error_exception(swoole_exit_exception_class_entry_ptr, "swoole exit.", 0, E_ERROR TSRMLS_CC);
        ZVAL_OBJ(&ex, obj);
        zend_update_property_long(swoole_exit_exception_class_entry_ptr, &ex, ZEND_STRL("flags"), flags);
        Z_TRY_ADDREF_P(exit_status);
        zend_update_property(swoole_exit_exception_class_entry_ptr, &ex, ZEND_STRL("status"), exit_status);
    }

    return ZEND_USER_OPCODE_DISPATCH;
}
Beispiel #24
0
/* {{{ MongoBinData::__construct()
 */
PHP_METHOD(MongoBinData, __construct)
{
	char *bin;
	long bin_len, type = PHP_MONGO_BIN_GENERIC;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &bin, &bin_len, &type) == FAILURE) {
		return;
	}

	zend_update_property_stringl(mongo_ce_BinData, getThis(), "bin", strlen("bin"), bin, bin_len TSRMLS_CC);
	zend_update_property_long(mongo_ce_BinData, getThis(), "type", strlen("type"), type TSRMLS_CC);
}
Beispiel #25
0
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
}
static PHP_METHOD(swoole_http2_client_coro, __construct)
{
    char *host;
    zend_size_t host_len;
    long port = 80;
    zend_bool ssl = SW_FALSE;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lb", &host, &host_len, &port, &ssl) == FAILURE)
    {
        return;
    }

    if (host_len <= 0)
    {
        zend_throw_exception(swoole_exception_class_entry_ptr, "host is empty.", SW_ERROR_INVALID_PARAMS TSRMLS_CC);
        RETURN_FALSE;
    }

    http2_client_property *hcc;
    hcc = (http2_client_property*) emalloc(sizeof(http2_client_property));
    bzero(hcc, sizeof(http2_client_property));
    swoole_set_property(getThis(), HTTP2_CLIENT_CORO_PROPERTY, hcc);

    php_context *context = emalloc(sizeof(php_context));
    swoole_set_property(getThis(), HTTP2_CLIENT_CORO_CONTEXT, context);
    context->onTimeout = NULL;
#if PHP_MAJOR_VERSION < 7
    context->coro_params = getThis();
#else
    context->coro_params = *getThis();
#endif

    hcc->streams = swHashMap_new(8, http2_client_stream_free);
    hcc->stream_id = 1;

    long type = SW_FLAG_ASYNC | SW_SOCK_TCP;
    if (ssl)
    {
#ifdef SW_USE_OPENSSL
        type |= SW_SOCK_SSL;
        hcc->ssl = 1;
#else
        swoole_php_fatal_error(E_ERROR, "require openssl library.");
#endif
    }

    zend_update_property_long(swoole_http2_client_coro_class_entry_ptr, getThis(), ZEND_STRL("type"), type TSRMLS_CC);

    hcc->host = estrndup(host, host_len);
    hcc->host_len = host_len;
    hcc->port = port;
}
Beispiel #27
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);
}
Beispiel #28
0
static PHP_METHOD(swoole_buffer, append)
{
    swString str;
    bzero(&str, sizeof(str));

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str.str, &str.length) == FAILURE)
    {
        RETURN_FALSE;
    }
    if (str.length < 1)
    {
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "string empty.");
        RETURN_FALSE;
    }
    swString *buffer = swoole_get_object(getThis());

    if ((str.length + buffer->size) > SW_STRING_BUFFER_MAXLEN)
    {
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "buffer size must not exceed %d", SW_STRING_BUFFER_MAXLEN);
        RETURN_FALSE;
    }

    size_t size_old = buffer->size;
    if (swString_append(buffer, &str) == SW_OK)
    {
        if (buffer->size > size_old)
        {
            zend_update_property_long(swoole_buffer_class_entry_ptr, getThis(), ZEND_STRL("capacity"), buffer->size TSRMLS_CC);
        }
        zend_update_property_long(swoole_buffer_class_entry_ptr, getThis(), ZEND_STRL("length"), buffer->length TSRMLS_CC);
        RETURN_LONG(buffer->length);
    }
    else
    {
        RETURN_FALSE;
    }
}
Beispiel #29
0
/* {{{ bool MongoDB::setWriteConcern(mixed w [, int wtimeout])
 * Set the MongoDB write concern, which will be inherited by constructed
 * MongoCollection objects. */
PHP_METHOD(MongoDB, setWriteConcern)
{
	zval *write_concern;
	long  wtimeout;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|l", &write_concern, &wtimeout) == FAILURE) {
		return;
	}

	if (Z_TYPE_P(write_concern) == IS_LONG) {
		zend_update_property_long(mongo_ce_DB, getThis(), "w", strlen("w"), Z_LVAL_P(write_concern) TSRMLS_CC);
	} else if (Z_TYPE_P(write_concern) == IS_STRING) {
		zend_update_property_stringl(mongo_ce_DB, getThis(), "w", strlen("w"), Z_STRVAL_P(write_concern), Z_STRLEN_P(write_concern) TSRMLS_CC);
	} else {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "expects parameter 1 to be an string or integer, %s given", zend_get_type_by_const(Z_TYPE_P(write_concern)));
		RETURN_FALSE;
	}

	if (ZEND_NUM_ARGS() > 1) {
		zend_update_property_long(mongo_ce_DB, getThis(), "wtimeout", strlen("wtimeout"), wtimeout TSRMLS_CC);
	}

	RETURN_TRUE;
}
Beispiel #30
0
static PHP_METHOD(swoole_buffer, expand)
{
    long size = -1;
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &size) == FAILURE)
    {
        RETURN_FALSE;
    }
    swString *buffer = swoole_get_object(getThis());
    if (size <= buffer->size)
    {
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "new size must more than %ld", buffer->size);
        RETURN_FALSE;
    }
    zend_update_property_long(swoole_buffer_class_entry_ptr, getThis(), ZEND_STRL("capacity"), size TSRMLS_CC);
    SW_CHECK_RETURN(swString_extend(buffer, size));
}