/* {{{ proto void Riak\Property\ModuleFunction->__construct(string $module, string $function) Creates a new Riak\Property\ModuleFunction */ PHP_METHOD(RiakModuleFunction, __construct) { char *module, *efunction; int module_len, efunction_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &module, &module_len, &efunction, &efunction_len) == FAILURE) { zend_throw_exception(riak_badarguments_exception_ce, "Bad or missing argument", 500 TSRMLS_CC); return; } zend_update_property_stringl(riak_module_function_ce, getThis(), "module", sizeof("module")-1, module, module_len TSRMLS_CC); zend_update_property_stringl(riak_module_function_ce, getThis(), "function", sizeof("function")-1, efunction, efunction_len TSRMLS_CC); }
/* {{{ proto void Riak\MapReduce\Input\BucketInput->setIndexFilter($indexname, $start [, $end]) Add a index query filter */ PHP_METHOD(Riak_MapReduce_Input_BucketInput, setIndexFilter) { char *index, *start, *end; int indexlen, startlen, endlen; end = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|s", &index, &indexlen, &start, &startlen, &end, &endlen) == FAILURE) { return; } zend_update_property_stringl(riak_mrinput_bucket_ce, getThis(), "idxname", sizeof("idxname")-1, index, indexlen TSRMLS_CC); zend_update_property_stringl(riak_mrinput_bucket_ce, getThis(), "idxstart", sizeof("idxstart")-1, start, startlen TSRMLS_CC); if (end != NULL && endlen > 0) { zend_update_property_stringl(riak_mrinput_bucket_ce, getThis(), "idxend", sizeof("idxend")-1, end, endlen TSRMLS_CC); } RIAK_RETURN_THIS }
/* {{{ php_crypto_get_algorithm_object_ex */ static inline void php_crypto_cipher_set_algorithm_name(zval *object, char *algorithm, phpc_str_size_t algorithm_len TSRMLS_DC) { php_strtoupper(algorithm, algorithm_len); zend_update_property_stringl(php_crypto_cipher_ce, object, "algorithm", sizeof("algorithm")-1, algorithm, algorithm_len TSRMLS_CC); }
/* {{{ proto SymmetricModeCbc::__construct(Cryptopp\BlockCipherInterface cipher) */ PHP_METHOD(Cryptopp_SymmetricModeCbc, __construct) { zval *cipherObject; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &cipherObject, cryptopp_ce_BlockCipherInterface)) { return; } // get needed cipher elements CryptoPP::BlockCipher *cipherEncryptor; CryptoPP::BlockCipher *cipherDecryptor; std::string *modeName; bool cipherMustBeDestructed; if (!cryptoppSymmetricModeGetCipherElements("cbc", cipherObject, getThis(), &cipherEncryptor, &cipherDecryptor, &modeName, cipherMustBeDestructed TSRMLS_CC)) { RETURN_NULL() } // instanciate mode encryptor/decryptor byte dummyIv[cipherEncryptor->BlockSize()]; Cbc::Encryption *encryptor = new Cbc::Encryption(cipherEncryptor, cipherMustBeDestructed, dummyIv, cipherEncryptor->BlockSize()); Cbc::Decryption *decryptor = new Cbc::Decryption(cipherDecryptor, cipherMustBeDestructed, dummyIv, cipherEncryptor->BlockSize()); setCryptoppSymmetricModeEncryptorPtr(getThis(), encryptor TSRMLS_CC); setCryptoppSymmetricModeDecryptorPtr(getThis(), decryptor TSRMLS_CC); zend_update_property_stringl(cryptopp_ce_SymmetricModeAbstract, getThis(), "name", 4, modeName->c_str(), modeName->size() TSRMLS_CC); delete modeName; // hold the cipher object. if not, it can be deleted and associated encryptor/decryptor objects will be deleted too zend_update_property(cryptopp_ce_SymmetricModeAbstract, getThis(), "cipher", 6, cipherObject TSRMLS_CC); }
PHP_METHOD(Money, __construct) { long amount; zval *currency, *currency_obj; if (zend_parse_parameters(ZEND_NUM_ARGS(), "lz", &amount, ¤cy) == 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); }
/* {{{ proto void MustacheCode::__construct(string binaryString) */ PHP_METHOD(MustacheCode, __construct) { try { // Custom parameters char * str = NULL; long str_len = 0; // Check parameters zval * _this_zval = NULL; if( zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), (char *) "O|s", &_this_zval, MustacheCode_ce_ptr, &str, &str_len) == FAILURE) { throw PhpInvalidParameterException(); } // Class parameters _this_zval = getThis(); // Check if data was null if( str != NULL ) { zend_update_property_stringl(MustacheCode_ce_ptr, _this_zval, "binaryString", sizeof("binaryString") - 1, str, str_len TSRMLS_CC); } } catch(...) { mustache_exception_handler(TSRMLS_C); } }
/* {{{ proto void Riak\MapReduce\Input\BucketInput->__construct(string $bucketName) Creates a new BucketInput */ PHP_METHOD(Riak_MapReduce_Input_BucketInput, __construct) { char *name; int namelen; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &namelen) == FAILURE) { return; } zend_update_property_stringl(riak_mrinput_bucket_ce, getThis(), "name", sizeof("name")-1, name, namelen TSRMLS_CC); }
/* {{{ proto AMQPExchange::setType(string type) Set the exchange type */ static PHP_METHOD(amqp_exchange_class, setType) { char *type = NULL; PHP5to7_param_str_len_type_t type_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &type, &type_len) == FAILURE) { return; } zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("type"), type, type_len TSRMLS_CC); }
/* {{{ MongoRegex::__construct() */ PHP_METHOD(MongoRegex, __construct) { zval *regex; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", ®ex) == FAILURE) { return; } if (Z_TYPE_P(regex) == IS_OBJECT && Z_OBJCE_P(regex) == mongo_ce_Regex) { zval *oregex, *oflags; oregex = zend_read_property(mongo_ce_Regex, regex, "regex", strlen("regex"), NOISY TSRMLS_CC); zend_update_property(mongo_ce_Regex, getThis(), "regex", strlen("regex"), oregex TSRMLS_CC); oflags = zend_read_property(mongo_ce_Regex, regex, "flags", strlen("flags"), NOISY TSRMLS_CC); zend_update_property(mongo_ce_Regex, getThis(), "flags", strlen("flags"), oflags TSRMLS_CC); } else if (Z_TYPE_P(regex) == IS_STRING) { int pattern_len, flags_len; char *re = Z_STRVAL_P(regex); char *eopattern = strrchr(re, '/'); if (!eopattern) { zend_throw_exception(mongo_ce_Exception, "invalid regex", 9 TSRMLS_CC); return; } pattern_len = eopattern - re - 1; if (pattern_len < 0) { zend_throw_exception(mongo_ce_Exception, "invalid regex", 9 TSRMLS_CC); return; } /* move beyond the second '/' in /foo/bar */ eopattern++; flags_len = Z_STRLEN_P(regex) - (eopattern - re); zend_update_property_stringl(mongo_ce_Regex, getThis(), "regex", strlen("regex"), re + 1, pattern_len TSRMLS_CC); zend_update_property_stringl(mongo_ce_Regex, getThis(), "flags", strlen("flags"), eopattern, flags_len TSRMLS_CC); } }
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; }
/* {{{ MongoInt64::__construct(string) */ PHP_METHOD(MongoInt64, __construct) { char *value; int value_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) == FAILURE) { return; } zend_update_property_stringl(mongo_ce_Int64, getThis(), "value", strlen("value"), value, value_len TSRMLS_CC); }
/* {{{ proto void Riak\Bucket->__construct(Riak\Connection $connection, string $name) Create a new Riak\Bucket */ PHP_METHOD(RiakBucket, __construct) { char *name; int nameLen; zval* zconnection; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "os", &zconnection, &name, &nameLen) == FAILURE) { return; } zend_update_property_stringl(riak_bucket_ce, getThis(), "name", sizeof("name")-1, name, nameLen TSRMLS_CC); zend_update_property(riak_bucket_ce, getThis(), "connection", sizeof("connection")-1, zconnection TSRMLS_CC); }
PHP_METHOD(Currency, __construct) { char *currency_code; int currency_code_len; if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", ¤cy_code, ¤cy_code_len) == FAILURE) { return; } zend_update_property_stringl(Z_OBJCE_P(getThis()), getThis(), CURRENCY_PROP_CURRENCYCODE_WS, currency_code, currency_code_len); }
/* {{{ 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); }
/* {{{ proto void Riak\Crdt\Counter->__construct(Riak\Connection $connection, Riak\Bucket $bucket, string $key) Create a Riak\Crdt\Counter */ PHP_METHOD(Riak_Crdt_Counter, __construct) { char *key; int keylen; zval *zbucket; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os", &zbucket, riak_bucket_ce, &key, &keylen) == FAILURE) { zend_throw_exception(riak_badarguments_exception_ce, "Bad or missing argument", 500 TSRMLS_CC); return; } zend_update_property(riak_crdt_counter_ce, getThis(), "bucket", sizeof("bucket")-1, zbucket TSRMLS_CC); zend_update_property_stringl(riak_crdt_counter_ce, getThis(), "key", sizeof("key")-1, key, keylen TSRMLS_CC); }
PHP_METHOD(air_router, set_url) { AIR_INIT_THIS; char *url; uint len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &url, &len) == FAILURE) { AIR_NEW_EXCEPTION(1, "invalid set_url param"); }else{ zend_update_property_stringl(air_router_ce, self, ZEND_STRL("_url"), url, len TSRMLS_CC); } AIR_RET_THIS; }
YRMCDS_METHOD(Client, recv) { yrmcds_client_object* obj = YRMCDS_CLIENT_OBJECT_P(getThis()); yrmcds_response r; CHECK_YRMCDS( yrmcds_recv(&obj->conn->res, &r) ); object_init_ex(return_value, ce_yrmcds_response); #define UPDATE_PROP_LONG(name, value) \ zend_update_property_long(ce_yrmcds_response, return_value, ZEND_STRL(name), (long)value) UPDATE_PROP_LONG("serial", r.serial); UPDATE_PROP_LONG("length", r.length); UPDATE_PROP_LONG("status", r.status); UPDATE_PROP_LONG("command", r.command); UPDATE_PROP_LONG("cas_unique", r.cas_unique); UPDATE_PROP_LONG("flags", r.flags); if( r.key_len > 0 ) zend_update_property_stringl(ce_yrmcds_response, return_value, ZEND_STRL("key"), r.key, r.key_len); if( r.data_len > 0 ) zend_update_property_stringl(ce_yrmcds_response, return_value, ZEND_STRL("data"), r.data, r.data_len); UPDATE_PROP_LONG("value", r.value); #undef UPDATE_PROP_LONG }
/* {{{ MongoBinData::__construct() */ PHP_METHOD(MongoBinData, __construct) { char *bin; long bin_len, type = 2; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &bin, &bin_len, &type) == FAILURE) { return; } if (ZEND_NUM_ARGS() == 1) { php_error_docref(NULL TSRMLS_CC, MONGO_E_DEPRECATED, "The default value for type will change to 0 in the future. Please pass in '2' explicitly."); } 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); }
static PHP_METHOD(Hello, __construct) { char *name; int name_len; long age; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &name, &name_len, &age) == FAILURE) { return; } zval *obj; obj = getThis(); zend_update_property_stringl(hello_ce, obj, "name", sizeof("name") -1, name, name_len TSRMLS_CC);//更新属性值, $this->name = name zend_update_property_long(hello_ce, obj, "age", sizeof("age") -1, age TSRMLS_CC); //this->age = age }
static PHP_METHOD(swoole_http2_client, __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) { swoole_php_fatal_error(E_ERROR, "host is empty."); RETURN_FALSE; } zend_update_property_stringl(swoole_http2_client_class_entry_ptr, getThis(), ZEND_STRL("host"), host, host_len TSRMLS_CC); zend_update_property_long(swoole_http2_client_class_entry_ptr, getThis(), ZEND_STRL("port"), port TSRMLS_CC); 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_PROPERTY_INDEX, hcc); hcc->requests = swLinkedList_new(0, http2_client_request_free); hcc->streams = swHashMap_new(8, http2_client_stream_free); zval *ztype; SW_MAKE_STD_ZVAL(ztype); long type = SW_FLAG_ASYNC | SW_SOCK_TCP; if (ssl) { type |= SW_SOCK_SSL; hcc->ssl = 1; } ZVAL_LONG(ztype, type); zval *zobject = getThis(); zval *retval = NULL; sw_zend_call_method_with_1_params(&zobject, swoole_client_class_entry_ptr, NULL, "__construct", &retval, ztype); if (retval) { sw_zval_ptr_dtor(&retval); } }
/* {{{ proto AMQPExchange::setName(string name) Set the exchange name */ static PHP_METHOD(amqp_exchange_class, setName) { char *name = NULL; PHP5to7_param_str_len_type_t name_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { return; } /* Verify that the name is not null and not an empty string */ if (name_len > 255) { zend_throw_exception(amqp_exchange_exception_class_entry, "Invalid exchange name given, must be less than 255 characters long.", 0 TSRMLS_CC); return; } /* Set the exchange name */ zend_update_property_stringl(this_ce, getThis(), ZEND_STRL("name"), name, name_len TSRMLS_CC); }
/* {{{ proto void Riak\Bucket->__construct(Riak\Connection $connection, string $name) Create a new Riak\Bucket */ PHP_METHOD(RiakBucket, __construct) { char *name, *type; int nameLen, typeLen; zval* zconnection; type = NULL; typeLen = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os|s", &zconnection, riak_connection_ce, &name, &nameLen, &type, &typeLen) == FAILURE) { zend_throw_exception(riak_badarguments_exception_ce, "Bad or missing argument", 500 TSRMLS_CC); return; } zend_update_property_stringl(riak_bucket_ce, getThis(), "name", sizeof("name")-1, name, nameLen TSRMLS_CC); zend_update_property(riak_bucket_ce, getThis(), "connection", sizeof("connection")-1, zconnection TSRMLS_CC); if (type != NULL && typeLen > 0) { zend_update_property(riak_bucket_ce, getThis(), "type", sizeof("type")-1, zconnection TSRMLS_CC); } }
/** {{{void yaf_trigger_error(int type TSRMLS_DC, char *format, ...) */ void yaf_trigger_error(int type TSRMLS_DC, char *format, ...) { va_list args; char *message; uint msg_len; va_start(args, format); msg_len = vspprintf(&message, 0, format, args); va_end(args); if (YAF_G(throw_exception)) { yaf_throw_exception(type, message TSRMLS_CC); } else { yaf_application_t *app = zend_read_static_property(yaf_application_ce, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_APP), 1 TSRMLS_CC); zend_update_property_long(yaf_application_ce, app, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_ERRNO), type TSRMLS_CC); zend_update_property_stringl(yaf_application_ce, app, ZEND_STRL(YAF_APPLICATION_PROPERTY_NAME_ERRMSG), message, msg_len TSRMLS_CC); php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, message); } efree(message); }
/* {{{ yaf_route_t * yaf_route_map_instance(yaf_route_t *this_ptr, zend_bool controller_prefer, char *delim, uint len TSRMLS_DC) */ yaf_route_t * yaf_route_map_instance(yaf_route_t *this_ptr, zend_bool controller_prefer, char *delim, uint len TSRMLS_DC) { yaf_route_t *instance; if (this_ptr) { instance = this_ptr; } else { MAKE_STD_ZVAL(instance); object_init_ex(instance, yaf_route_map_ce); } if (controller_prefer) { zend_update_property_bool(yaf_route_map_ce, instance, ZEND_STRL(YAF_ROUTE_MAP_VAR_NAME_CTL_PREFER), 1 TSRMLS_CC); } if (delim && len) { zend_update_property_stringl(yaf_route_map_ce, instance, ZEND_STRL(YAF_ROUTE_MAP_VAR_NAME_DELIMETER), delim, len TSRMLS_CC); } return instance; }
/* {{{ PHP_SOLR_API void solr_set_response_object_properties(zend_class_entry *scope, zval *response_object, const solr_client_t *client, const solr_string_t *request_url, zend_bool success TSRMLS_DC) */ PHP_SOLR_API void solr_set_response_object_properties(zend_class_entry *scope, zval *response_object, const solr_client_t *client, const solr_string_t *request_url, zend_bool success TSRMLS_DC) { const solr_curl_t *handle = &(client->handle); const solr_string_t *raw_request_headers = &(handle->request_header.buffer); const solr_string_t *raw_request = &(handle->request_body_debug.buffer); const solr_string_t *raw_response_headers = &(handle->response_header.buffer); const solr_string_t *raw_response = &(handle->response_body.buffer); const solr_string_t *response_writer = &(client->options.response_writer); long int http_status = handle->response_header.response_code; zend_update_property_long(scope, response_object, "http_status", sizeof("http_status")-1, http_status TSRMLS_CC); zend_update_property_bool(scope, response_object, "success", sizeof("success")-1, success TSRMLS_CC); if (response_writer->str) { zend_update_property_stringl(scope, response_object, "response_writer", sizeof("response_writer")-1, (char *)response_writer->str, response_writer->len TSRMLS_CC); } if (request_url->str) { zend_update_property_stringl(scope, response_object, "http_request_url", sizeof("http_request_url")-1, (char *)request_url->str, request_url->len TSRMLS_CC); } if (raw_request_headers->str) { zend_update_property_stringl(scope, response_object, "http_raw_request_headers", sizeof("http_raw_request_headers")-1, (char *)raw_request_headers->str, raw_request_headers->len TSRMLS_CC); } if (raw_request->str) { zend_update_property_stringl(scope, response_object, "http_raw_request", sizeof("http_raw_request")-1, (char *)raw_request->str, raw_request->len TSRMLS_CC); } if (raw_response_headers->str) { zend_update_property_stringl(scope, response_object, "http_raw_response_headers", sizeof("http_raw_response_headers")-1, (char *)raw_response_headers->str, raw_response_headers->len TSRMLS_CC); } if (raw_response->str) { zend_update_property_stringl(scope, response_object, "http_raw_response", sizeof("http_raw_response")-1, (char *)raw_response->str, raw_response->len TSRMLS_CC); } }
/* {{{ MongoCode::__construct(string code[, array scope]) * Creates a new MongoCode object */ PHP_METHOD(MongoCode, __construct) { char *code; int code_len; zval *zcope = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a", &code, &code_len, &zcope) == FAILURE) { return; } zend_update_property_stringl(mongo_ce_Code, getThis(), "code", strlen("code"), code, code_len TSRMLS_CC); if (!zcope) { MAKE_STD_ZVAL(zcope); array_init(zcope); } else { zval_add_ref(&zcope); } zend_update_property(mongo_ce_Code, getThis(), "scope", strlen("scope"), zcope TSRMLS_CC); /* get rid of extra ref */ zval_ptr_dtor(&zcope); }
/* {{{ 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; }
static inline void yaf_dispatcher_fix_default(yaf_dispatcher_t *dispatcher, yaf_request_t *request) /* {{{ */ { zval *module, *controller, *action; module = zend_read_property(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_MODULE), 1, NULL); action = zend_read_property(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_ACTION), 1, NULL); controller = zend_read_property(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_CONTROLLER), 1, NULL); if (Z_TYPE_P(module) != IS_STRING || !Z_STRLEN_P(module)) { zval *default_module = zend_read_property(yaf_dispatcher_ce, dispatcher, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_MODULE), 1, NULL); zend_update_property(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_MODULE), default_module); } else { char *p = zend_str_tolower_dup(Z_STRVAL_P(module), Z_STRLEN_P(module)); *p = toupper(*p); zend_update_property_stringl(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_MODULE), p, Z_STRLEN_P(module)); efree(p); } if (Z_TYPE_P(controller) != IS_STRING || !Z_STRLEN_P(controller)) { zval *default_controller = zend_read_property(yaf_dispatcher_ce, dispatcher, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_CONTROLLER), 1, NULL); zend_update_property(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_CONTROLLER), default_controller); } else { char *q, *p = zend_str_tolower_dup(Z_STRVAL_P(controller), Z_STRLEN_P(controller)); /** * Upper controller name * eg: Index_sub -> Index_Sub */ q = p; *q = toupper(*q); while (*q != '\0') { if (*q == '_' || *q == '\\') { if (*(q+1) != '\0') { *(q+1) = toupper(*(q+1)); q++; } } q++; } zend_update_property_stringl(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_CONTROLLER), p, Z_STRLEN_P(controller)); efree(p); } if (Z_TYPE_P(action) != IS_STRING || !Z_STRLEN_P(action)) { zval *default_action = zend_read_property(yaf_dispatcher_ce, dispatcher, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_ACTION), 1, NULL); zend_update_property(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_ACTION), default_action); } else { char *p = zend_str_tolower_dup(Z_STRVAL_P(action), Z_STRLEN_P(action)); zend_update_property_stringl(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_ACTION), p, Z_STRLEN_P(action)); efree(p); } }
/** * Digest solr server raw response * and return SolrObject or array */ PHP_SOLR_API void solr_response_get_response_impl( INTERNAL_FUNCTION_PARAMETERS, int return_array) { zend_bool silent = 0; zval *objptr = getThis(); if (return_value_used) { zval *response_writer = solr_read_response_object_property(objptr, "response_writer", silent); zval *raw_response = solr_read_response_object_property(objptr, "http_raw_response", silent); zval *success = solr_read_response_object_property(objptr, "success", silent); zval *parser_mode = solr_read_response_object_property(objptr, "parser_mode", silent); if (Z_BVAL_P(success) && Z_STRLEN_P(raw_response)) { solr_string_t buffer; php_unserialize_data_t var_hash; const unsigned char *raw_resp; size_t raw_res_length; const unsigned char *str_end; int successful = 1; memset(&buffer, 0, sizeof(solr_string_t)); if (Z_STRLEN_P(response_writer)) { if (0 == strcmp(Z_STRVAL_P(response_writer), SOLR_XML_RESPONSE_WRITER)) { /* SOLR_XML_RESPONSE_WRITER */ /* Convert from XML serialization to PHP serialization format */ solr_encode_generic_xml_response(&buffer, Z_STRVAL_P(raw_response), Z_STRLEN_P(raw_response), Z_LVAL_P(parser_mode) TSRMLS_CC); if(return_array) { solr_sobject_to_sarray(&buffer TSRMLS_CC); } } else if (0 == strcmp(Z_STRVAL_P(response_writer), SOLR_PHP_NATIVE_RESPONSE_WRITER) || 0 == strcmp(Z_STRVAL_P(response_writer), SOLR_PHP_SERIALIZED_RESPONSE_WRITER)) { /* SOLR_PHP_NATIVE_RESPONSE_WRITER */ /* Response string is already in Native PHP serialization format */ solr_string_set(&buffer, Z_STRVAL_P(raw_response), Z_STRLEN_P(raw_response)); if(!return_array) { solr_sarray_to_sobject(&buffer TSRMLS_CC); } } else if (0 == strcmp(Z_STRVAL_P(response_writer), SOLR_JSON_RESPONSE_WRITER)) { int json_translation_result = solr_json_to_php_native(&buffer, Z_STRVAL_P(raw_response), Z_STRLEN_P(raw_response) TSRMLS_CC); /* SOLR_JSON_RESPONSE_WRITER */ /* Convert from JSON serialization to PHP serialization format */ if (json_translation_result > 0) { solr_throw_exception_ex(solr_ce_SolrException, SOLR_ERROR_1000 TSRMLS_CC, SOLR_FILE_LINE_FUNC, solr_get_json_error_msg(json_translation_result)); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error in JSON->PHP conversion. JSON Error Code %d", json_translation_result); } if(!return_array) { solr_sarray_to_sobject(&buffer TSRMLS_CC); } } } if (buffer.len) { zend_update_property_stringl(Z_OBJCE_P(objptr), objptr, "http_digested_response", sizeof("http_digested_response")-1, buffer.str, buffer.len TSRMLS_CC); } memset(&var_hash, 0, sizeof(php_unserialize_data_t)); PHP_VAR_UNSERIALIZE_INIT(var_hash); raw_resp = (unsigned char *) buffer.str; raw_res_length = buffer.len; str_end = (unsigned char *) (raw_resp + raw_res_length); if (!php_var_unserialize(&return_value, &raw_resp, str_end, &var_hash TSRMLS_CC)) { successful = 0; solr_throw_exception_ex(solr_ce_SolrException, SOLR_ERROR_1000 TSRMLS_CC, SOLR_FILE_LINE_FUNC, SOLR_ERROR_1000_MSG); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error unserializing raw response."); } PHP_VAR_UNSERIALIZE_DESTROY(var_hash); solr_string_free(&buffer); if (successful) { /* Overriding the default object handlers */ Z_OBJ_HT_P(return_value) = &solr_object_handlers; } return ; } RETURN_NULL(); } else { php_error_docref(NULL TSRMLS_CC, E_NOTICE, SOLR_ERROR_4002_MSG); } }
static int http_onReceive(swFactory *factory, swEventData *req) { TSRMLS_FETCH_FROM_CTX(sw_thread_ctx ? sw_thread_ctx : NULL); int fd = req->info.fd; // swTrace("on receive:%s pid:%d\n", zdata, getpid()); swConnection *conn = swServer_connection_get(SwooleG.serv, fd); if(conn->websocket_status == WEBSOCKET_STATUS_HANDSHAKE) //websocket callback { zval *zdata = php_swoole_get_data(req TSRMLS_CC); swTrace("on message callback\n"); char *buf = Z_STRVAL_P(zdata); long fin = buf[0] ? 1 : 0; long opcode = buf[1] ? 1 : 0; buf+=2; zval *zresponse; MAKE_STD_ZVAL(zresponse); object_init_ex(zresponse, swoole_http_wsresponse_class_entry_ptr); //socket fd zend_update_property_long(swoole_http_wsresponse_class_entry_ptr, zresponse, ZEND_STRL("fd"), fd TSRMLS_CC); zend_update_property_long(swoole_http_wsresponse_class_entry_ptr, zresponse, ZEND_STRL("fin"), fin TSRMLS_CC); zend_update_property_long(swoole_http_wsresponse_class_entry_ptr, zresponse, ZEND_STRL("opcode"), opcode TSRMLS_CC); zend_update_property_stringl(swoole_http_wsresponse_class_entry_ptr, zresponse, ZEND_STRL("data"), buf, (Z_STRLEN_P(zdata)-2) TSRMLS_CC); zval **args[1]; args[0] = &zresponse; zval *retval; if (call_user_function_ex(EG(function_table), NULL, php_sw_http_server_callbacks[1], &retval, 1, args, 0, NULL TSRMLS_CC) == FAILURE) { zval_ptr_dtor(&zdata); php_error_docref(NULL TSRMLS_CC, E_WARNING, "onMessage handler error"); } swTrace("===== message callback end======"); if (EG(exception)) { zval_ptr_dtor(&zdata); zend_exception_error(EG(exception), E_ERROR TSRMLS_CC); } if (retval) { zval_ptr_dtor(&retval); } zval_ptr_dtor(&zdata); return SW_OK; } http_client *client = swHashMap_find_int(php_sw_http_clients, fd); if (!client) { client = http_client_new(fd TSRMLS_CC); } php_http_parser *parser = &client->parser; /** * create request and response object */ http_request_new(client TSRMLS_CC); parser->data = client; php_http_parser_init(parser, PHP_HTTP_REQUEST); zval *zdata = php_swoole_get_data(req TSRMLS_CC); //server info zval *_request; MAKE_STD_ZVAL(_request); array_init(_request); zend_update_property(swoole_http_request_class_entry_ptr, client->zrequest, ZEND_STRL("request"), _request TSRMLS_CC); size_t n = php_http_parser_execute(parser, &http_parser_settings, Z_STRVAL_P(zdata), Z_STRLEN_P(zdata)); zval_ptr_dtor(&zdata); if (n < 0) { swWarn("php_http_parser_execute failed."); if(conn->websocket_status == WEBSOCKET_STATUS_CONNECTION) { SwooleG.serv->factory.end(&SwooleG.serv->factory, fd); } } else { if(conn->websocket_status == WEBSOCKET_STATUS_CONNECTION) // need handshake { if(php_sw_http_server_callbacks[2] == NULL) { int ret = websocket_handshake(client); http_request_free(client TSRMLS_CC); if (ret == SW_ERR) { swTrace("websocket handshake error\n"); SwooleG.serv->factory.end(&SwooleG.serv->factory, fd); } else { handshake_success(fd); swTrace("websocket handshake_success\n"); return SW_OK; } return ret; } } zval *retval; zval **args[2]; zval *zrequest = client->zrequest; //server info zval *zserver; MAKE_STD_ZVAL(zserver); array_init(zserver); zend_update_property(swoole_http_request_class_entry_ptr, zrequest, ZEND_STRL("server"), zserver TSRMLS_CC); switch (parser->method) { case PHP_HTTP_GET: add_assoc_string(zserver, "REQUEST_METHOD", "GET", 1);break; case PHP_HTTP_POST: add_assoc_string(zserver, "REQUEST_METHOD", "POST", 1);break; case PHP_HTTP_HEAD: add_assoc_string(zserver, "REQUEST_METHOD", "HEAD", 1);break; case PHP_HTTP_PUT: add_assoc_string(zserver, "REQUEST_METHOD", "PUT", 1);break; case PHP_HTTP_DELETE: add_assoc_string(zserver, "REQUEST_METHOD", "DELETE", 1);break; case PHP_HTTP_PATCH: add_assoc_string(zserver, "REQUEST_METHOD", "PATCH", 1);break; /* pathological */ case PHP_HTTP_CONNECT: add_assoc_string(zserver, "REQUEST_METHOD", "CONNECT", 1);break; case PHP_HTTP_OPTIONS: add_assoc_string(zserver, "REQUEST_METHOD", "OPTIONS", 1);break; case PHP_HTTP_TRACE: add_assoc_string(zserver, "REQUEST_METHOD", "TRACE", 1);break; /* webdav */ case PHP_HTTP_COPY: add_assoc_string(zserver, "REQUEST_METHOD", "COPY", 1);break; case PHP_HTTP_LOCK: add_assoc_string(zserver, "REQUEST_METHOD", "LOCK", 1);break; case PHP_HTTP_MKCOL: add_assoc_string(zserver, "REQUEST_METHOD", "MKCOL", 1);break; case PHP_HTTP_MOVE: add_assoc_string(zserver, "REQUEST_METHOD", "MOVE", 1);break; case PHP_HTTP_PROPFIND: add_assoc_string(zserver, "REQUEST_METHOD", "PROPFIND", 1);break; case PHP_HTTP_PROPPATCH: add_assoc_string(zserver, "REQUEST_METHOD", "PROPPATCH", 1);break; case PHP_HTTP_UNLOCK: add_assoc_string(zserver, "REQUEST_METHOD", "UNLOCK", 1);break; /* subversion */ case PHP_HTTP_REPORT: add_assoc_string(zserver, "REQUEST_METHOD", "REPORT", 1);break; case PHP_HTTP_MKACTIVITY: add_assoc_string(zserver, "REQUEST_METHOD", "MKACTIVITY", 1);break; case PHP_HTTP_CHECKOUT: add_assoc_string(zserver, "REQUEST_METHOD", "CHECKOUT", 1);break; case PHP_HTTP_MERGE: add_assoc_string(zserver, "REQUEST_METHOD", "MERGE", 1);break; /* upnp */ case PHP_HTTP_MSEARCH: add_assoc_string(zserver, "REQUEST_METHOD", "MSEARCH", 1);break; case PHP_HTTP_NOTIFY: add_assoc_string(zserver, "REQUEST_METHOD", "NOTIFY", 1);break; case PHP_HTTP_SUBSCRIBE: add_assoc_string(zserver, "REQUEST_METHOD", "SUBSCRIBE", 1);break; case PHP_HTTP_UNSUBSCRIBE: add_assoc_string(zserver, "REQUEST_METHOD", "UNSUBSCRIBE", 1);break; case PHP_HTTP_NOT_IMPLEMENTED: add_assoc_string(zserver, "REQUEST_METHOD", "GET", 1);break; } // if (parser->method == PHP_HTTP_POST) // { // add_assoc_string(zserver, "REQUEST_METHOD", "POST", 1); // } // else // { // add_assoc_string(zserver, "REQUEST_METHOD", "GET", 1); // } add_assoc_stringl(zserver, "REQUEST_URI", client->request.path, client->request.path_len, 1); add_assoc_stringl(zserver, "PATH_INFO", client->request.path, client->request.path_len, 1); add_assoc_long_ex(zserver, ZEND_STRS("REQUEST_TIME"), SwooleGS->now); swConnection *conn = swServer_connection_get(SwooleG.serv, fd); add_assoc_long(zserver, "SERVER_PORT", SwooleG.serv->connection_list[conn->from_fd].addr.sin_port); add_assoc_long(zserver, "REMOTE_PORT", ntohs(conn->addr.sin_port)); add_assoc_string(zserver, "REMOTE_ADDR", inet_ntoa(conn->addr.sin_addr), 1); if (client->request.version == 101) { add_assoc_string(zserver, "SERVER_PROTOCOL", "HTTP/1.1", 1); } else { add_assoc_string(zserver, "SERVER_PROTOCOL", "HTTP/1.0", 1); } add_assoc_string(zserver, "SERVER_SOFTWARE", SW_HTTP_SERVER_SOFTWARE, 1); add_assoc_string(zserver, "GATEWAY_INTERFACE", SW_HTTP_SERVER_SOFTWARE, 1); // ZEND_SET_SYMBOL(&EG(symbol_table), "_SERVER", zserver); zval *zresponse; MAKE_STD_ZVAL(zresponse); object_init_ex(zresponse, swoole_http_response_class_entry_ptr); //socket fd zend_update_property_long(swoole_http_response_class_entry_ptr, zresponse, ZEND_STRL("fd"), client->fd TSRMLS_CC); client->zresponse = zresponse; args[0] = &zrequest; args[1] = &zresponse; int called = 0; if(conn->websocket_status == WEBSOCKET_STATUS_CONNECTION) { called = 2; } if (call_user_function_ex(EG(function_table), NULL, php_sw_http_server_callbacks[called], &retval, 2, args, 0, NULL TSRMLS_CC) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "onRequest handler error"); } if (EG(exception)) { zend_exception_error(EG(exception), E_ERROR TSRMLS_CC); } if (retval) { zval_ptr_dtor(&retval); } swTrace("======call end======\n"); if(called == 2) { handshake_success(fd); } } return SW_OK; }