/* {{{ proto void SplDoublyLinkedList::offsetSet(mixed index, mixed newval) Sets the value at the specified $index to $newval. */ SPL_METHOD(SplDoublyLinkedList, offsetSet) { zval *zindex, *value; spl_dllist_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &zindex, &value) == FAILURE) { return; } intern = Z_SPLDLLIST_P(getThis()); if (Z_TYPE_P(zindex) == IS_NULL) { /* $obj[] = ... */ spl_ptr_llist_push(intern->llist, value); } else { /* $obj[$foo] = ... */ zend_long index; spl_ptr_llist_element *element; index = spl_offset_convert_to_long(zindex); if (index < 0 || index >= intern->llist->count) { zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0); return; } element = spl_ptr_llist_offset(intern->llist, index, intern->flags & SPL_DLLIST_IT_LIFO); if (element != NULL) { /* call dtor on the old element as in spl_ptr_llist_pop */ if (intern->llist->dtor) { intern->llist->dtor(element); } /* the element is replaced, delref the old one as in * SplDoublyLinkedList::pop() */ zval_ptr_dtor(&element->data); ZVAL_COPY_VALUE(&element->data, value); /* new element, call ctor as in spl_ptr_llist_push */ if (intern->llist->ctor) { intern->llist->ctor(element); } } else { zval_ptr_dtor(value); zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0); return; } } } /* }}} */
void php_grpc_read_args_array(zval *args_array, grpc_channel_args *args) { HashTable *array_hash; //HashPosition array_pointer; int args_index; zval *data; zend_string *key; //zend_ulong index; array_hash = HASH_OF(args_array); if (!array_hash) { zend_throw_exception(spl_ce_InvalidArgumentException, "array_hash is NULL", 1); return; } args->num_args = zend_hash_num_elements(array_hash); args->args = ecalloc(args->num_args, sizeof(grpc_arg)); args_index = 0; ZEND_HASH_FOREACH_STR_KEY_VAL(array_hash, key, data) { /*for (zend_hash_internal_pointer_reset_ex(array_hash, &array_pointer); (data = zend_hash_get_current_data_ex(array_hash, &array_pointer)) != NULL; zend_hash_move_forward_ex(array_hash, &array_pointer)) { if (zend_hash_get_current_key_ex(array_hash, &key, &index, &array_pointer) != HASH_KEY_IS_STRING) { zend_throw_exception(spl_ce_InvalidArgumentException, "args keys must be strings", 1); return; }*/ if (key == NULL) { zend_throw_exception(spl_ce_InvalidArgumentException, "args keys must be strings", 1); } args->args[args_index].key = ZSTR_VAL(key); switch (Z_TYPE_P(data)) { case IS_LONG: args->args[args_index].value.integer = (int)Z_LVAL_P(data); args->args[args_index].type = GRPC_ARG_INTEGER; break; case IS_STRING: args->args[args_index].value.string = Z_STRVAL_P(data); args->args[args_index].type = GRPC_ARG_STRING; break; default: zend_throw_exception(spl_ce_InvalidArgumentException, "args values must be int or string", 1); return; } args_index++; } ZEND_HASH_FOREACH_END(); }
/* Selects a collection and returns it as zval. If the return value is no, an * Exception is set. This only happens if the passed in DB was invalid. */ zval *php_mongo_db_selectcollection(zval *z_client, char *collection, int collection_len TSRMLS_DC) { zval *z_collection; zval *return_value; mongo_db *db; db = (mongo_db*)zend_object_store_get_object(z_client TSRMLS_CC); if (!(db->name)) { zend_throw_exception(mongo_ce_Exception, "The MongoDB object has not been correctly initialized by its constructor", 0 TSRMLS_CC); return NULL; } MAKE_STD_ZVAL(z_collection); ZVAL_STRINGL(z_collection, collection, collection_len, 1); MAKE_STD_ZVAL(return_value); object_init_ex(return_value, mongo_ce_Collection); php_mongo_collection_construct(return_value, z_client, collection, collection_len TSRMLS_CC); if (EG(exception)) { zval_ptr_dtor(&return_value); return_value = NULL; } zval_ptr_dtor(&z_collection); return return_value; }
PHP_METHOD(ArrayList, addToBottom){ zval* temp; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &temp) == FAILURE) { RETURN_NULL(); } list_object* obj = (list_object*) zend_object_store_get_object(getThis() TSRMLS_CC); if (obj->object != NULL) { try { if(obj->type == TYPE_LONG) { ((List<long>*) obj->object)->addToBottom(zval2long(temp)); } else if (obj->type == TYPE_DOUBLE) { ((List<double>*) obj->object)->addToBottom(zval2double(temp)); } else if (obj->type == TYPE_BOOLEAN) { ((List<char>*) obj->object)->addToBottom(zval2bool(temp)); } else if (obj->type == TYPE_STRING) { ((List<char*>*) obj->object)->addToBottom(zval2str(temp, obj->memory_manager)); } else if (obj->type == TYPE_OBJECT) { ((List<zval*>*) obj->object)->addToBottom(zval2object(temp, obj->class_entry)); } else { ((List<zval*>*) obj->object)->addToBottom(temp); } } catch (const std::runtime_error& e) { zend_throw_exception(NULL, e.what(), 0 TSRMLS_CC); RETURN_NULL(); } } }
PHP_METHOD(ArrayList, __construct){ zval* temp; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &temp) == FAILURE) { RETURN_NULL(); } // get type char type = 0; try { type = getDataType(temp); } catch (const std::runtime_error& e) { zend_throw_exception(NULL, e.what(), 0 TSRMLS_CC); RETURN_NULL(); } // create object list_object* obj = (list_object*) zend_object_store_get_object(getThis() TSRMLS_CC); obj->type = type; if(type == TYPE_LONG) { obj->object = new ArrayList<long>; } else if (type == TYPE_DOUBLE) { obj->object = new ArrayList<double>; } else if (type == TYPE_BOOLEAN) { obj->object = new ArrayList<char>; } else if (type == TYPE_STRING) { obj->memory_manager = new MemoryManager<char*>; obj->object = new ArrayList<char*>; } else if(type==TYPE_OBJECT) { obj->class_entry = str2class(temp); obj->object = new ArrayList<zval*>; } else { obj->object = new ArrayList<zval*>; } }
/* {{{ Mosquitto\Client::onPublish() */ PHP_METHOD(Mosquitto_Client, onPublish) { mosquitto_client_object *object; zend_fcall_info publish_callback = empty_fcall_info; zend_fcall_info_cache publish_callback_cache = empty_fcall_info_cache; PHP_MOSQUITTO_ERROR_HANDLING(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f!", &publish_callback, &publish_callback_cache) == FAILURE) { PHP_MOSQUITTO_RESTORE_ERRORS(); return; } PHP_MOSQUITTO_RESTORE_ERRORS(); object = (mosquitto_client_object *) mosquitto_client_object_get(getThis() TSRMLS_CC); if (!ZEND_FCI_INITIALIZED(publish_callback)) { zend_throw_exception(mosquitto_ce_exception, "Need a valid callback", 0 TSRMLS_CC); } object->publish_callback = publish_callback; object->publish_callback_cache = publish_callback_cache; Z_ADDREF_P(publish_callback.function_name); if (publish_callback.object_ptr != NULL) { Z_ADDREF_P(publish_callback.object_ptr); } mosquitto_publish_callback_set(object->client, php_mosquitto_publish_callback); }
/** * Creates an IO event which will trigger when there is data to read and/or data to write * on the supplied stream. * * @param callback the PHP callback to call * @param resource the PHP stream to watch * @param int either IOEvent::READ and/or IOEvent::WRITE depending on type of event */ PHP_METHOD(IOEvent, __construct) { dFILE_DESC; dCALLBACK; long events; event_object *obj; PARSE_PARAMETERS(IOEvent, "zZl", &callback, &fd, &events); /* Check if we have the correct flags */ if( ! (events & (EV_READ | EV_WRITE))) { /* TODO: libev-specific exception class here */ zend_throw_exception(NULL, "libev\\IOEvent: events parameter must be " "at least one of IOEvent::READ or IOEvent::WRITE", 1 TSRMLS_CC); return; } EXTRACT_FILE_DESC(IOEvent, __construct); CHECK_CALLBACK; EVENT_OBJECT_PREPARE(obj, callback); event_io_init(obj, (int) file_desc, (int) events); }
/* {{{ proto string MarkdownDocument::transformFragment(string $markdown_fragment [, int $flags = 0 ]) */ PHP_METHOD(markdowndoc, transformFragment) { char *markdown; int markdown_len; long flags = 0; char *out = NULL; int out_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &markdown, &markdown_len, &flags) == FAILURE) { RETURN_FALSE; } if (markdown_len == 0) { RETURN_EMPTY_STRING(); } out_len = mkd_line(markdown, markdown_len, &out, (mkd_flag_t) flags); if (out_len < 0) { zend_throw_exception(spl_ce_RuntimeException, "Error parsing the fragment", 0 TSRMLS_CC); RETVAL_FALSE; } else { RETVAL_STRINGL(out, out_len, 0); } if (Z_TYPE_P(return_value) == IS_BOOL && out != NULL) { efree(out); } }
/** * Normal constructor for EventLoop instance. */ PHP_METHOD(EventLoop, __construct) { int backend = EVFLAG_AUTO; event_loop_object *obj = (event_loop_object *)zend_object_store_get_object(getThis() TSRMLS_CC); assert( ! obj->loop); if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &backend) != SUCCESS) { return; } /* Check parameter */ if(EVFLAG_AUTO != backend && EVBACKEND_SELECT != backend && EVBACKEND_POLL != backend && EVBACKEND_EPOLL != backend && EVBACKEND_KQUEUE != backend && EVBACKEND_DEVPOLL != backend && EVBACKEND_PORT != backend && EVBACKEND_ALL != backend) { /* TODO: libev-specific exception class here */ zend_throw_exception(NULL, "libev\\EventLoop: backend parameter must be " "one of the EventLoop::BACKEND_* constants.", 1 TSRMLS_DC); return; } obj->loop = ev_loop_new(backend); IF_DEBUG(ev_verify(obj->loop)); }
PHP_METHOD(swoole_atomic_long, __construct) { zend_long value = 0; #ifdef FAST_ZPP ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL Z_PARAM_LONG(value) ZEND_PARSE_PARAMETERS_END(); #else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &value) == FAILURE) { RETURN_FALSE; } #endif sw_atomic_long_t *atomic = SwooleG.memory_pool->alloc(SwooleG.memory_pool, sizeof(sw_atomic_long_t)); if (atomic == NULL) { zend_throw_exception(swoole_exception_class_entry_ptr, "global memory allocation failure.", SW_ERROR_MALLOC_FAIL TSRMLS_CC); RETURN_FALSE; } *atomic = (sw_atomic_long_t) value; swoole_set_object(getThis(), (void*) atomic); RETURN_TRUE; }
void create_struct_ex(zval *retval, Any *anyval, char *str, int str_len TSRMLS_DC) { Reference <XIdlReflection> *x_idl_reflec_p; int type; int rsrc_id; try { //restore XIdlReflection resource x_idl_reflec_p = (Reference <XIdlReflection> *) zend_list_find( PUNO_G(x_idl_reflec_rsrc_id),&type); TEST_PTR(x_idl_reflec_p,); Reference <XIdlClass> xIdlClass = (*x_idl_reflec_p)->forName(OUString(str,str_len,RTL_TEXTENCODING_ISO_8859_15,OSTRING_TO_OUSTRING_CVTFLAGS)); TEST_PTR(xIdlClass.is(),); //Reference <XIdlField2> field (xidlfield, UNO_QUERY); Any any_obj; xIdlClass->createObject(any_obj); if(anyval!=NULL) { any_obj.setValue((*anyval).getValue(),(*anyval).getValueType()); } Any *any_obj_p= new Any(any_obj); TEST_PTR(any_obj_p,); //init object object_init_ex (retval, ce_ptr); puno_class_object *new_struct_p; new_struct_p = (puno_class_object *) zend_object_store_get_object(retval TSRMLS_CC); TEST_PTR(new_struct_p,); //type is Structs new_struct_p->type = TypeClass_STRUCT; //register and store the Any object rsrc_id = ZEND_REGISTER_RESOURCE ( NULL, any_obj_p, uno_any_rsrc_dtor); TEST_PTR(rsrc_id,); new_struct_p->this_rsrc_id = rsrc_id; //register and store the XIdlClass Interface Reference <XIdlClass> *x_idl_class_p=new Reference <XIdlClass> (xIdlClass); TEST_PTR(x_idl_class_p,); rsrc_id = ZEND_REGISTER_RESOURCE ( NULL, x_idl_class_p, uno_refer_rsrc_dtor); TEST_PTR(rsrc_id,); new_struct_p->x_idl_class_rsrc_id = rsrc_id; } catch(Exception& e) { //throw PHP EXCEPTION zend_throw_exception(zend_exception_get_default(),(char *)OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr(),0 TSRMLS_CC); } }
/** * Create SSL credentials. * @param string pem_root_certs PEM encoding of the server root certificates * @param string pem_private_key PEM encoding of the client's private key * @param string pem_cert_chain PEM encoding of the client's certificate chain * @return Credentials The new SSL credentials object */ PHP_METHOD(ServerCredentials, createSsl) { zend_string *pem_root_certs = NULL; zend_string *private_key; zend_string *cert_chain; grpc_ssl_pem_key_cert_pair pem_key_cert_pair; /* "S!SS" == 1 nullable string, 2 strings */ /* TODO: support multiple key cert pairs. */ if (zend_parse_parameters(ZEND_NUM_ARGS(), "S!SS", &pem_root_certs, &private_key, &cert_chain) == FAILURE) { zend_throw_exception(spl_ce_InvalidArgumentException, "createSsl expects 3 strings", 1); return; } if (private_key) { pem_key_cert_pair.private_key = ZSTR_VAL(private_key); } if (cert_chain) { pem_key_cert_pair.cert_chain = ZSTR_VAL(cert_chain); } /* TODO: add a client_certificate_request field in ServerCredentials and pass * it as the last parameter. */ grpc_server_credentials *creds = grpc_ssl_server_credentials_create_ex( pem_root_certs == NULL ? NULL : ZSTR_VAL(pem_root_certs), &pem_key_cert_pair, 1, GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE, NULL); grpc_php_wrap_server_credentials(creds, return_value); RETURN_DESTROY_ZVAL(return_value); }
/* {{{ proto bool SplPriorityQueue::insert(mixed $value, mixed $priority) Push $value with the priority $priodiry on the priorityqueue */ SPL_METHOD(SplPriorityQueue, insert) { zval *data, *priority, elem; spl_heap_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &data, &priority) == FAILURE) { return; } intern = Z_SPLHEAP_P(getThis()); if (intern->heap->flags & SPL_HEAP_CORRUPTED) { zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0); return; } if (Z_REFCOUNTED_P(data)) Z_ADDREF_P(data); if (Z_REFCOUNTED_P(priority)) Z_ADDREF_P(priority); array_init(&elem); add_assoc_zval_ex(&elem, "data", sizeof("data") - 1, data); add_assoc_zval_ex(&elem, "priority", sizeof("priority") - 1, priority); spl_ptr_heap_insert(intern->heap, &elem, getThis()); RETURN_TRUE; }
void php_com_throw_exception(HRESULT code, char *message) { int free_msg = 0; if (message == NULL) { message = php_win32_error_to_msg(code); free_msg = 1; } #if SIZEOF_ZEND_LONG == 8 zend_throw_exception(php_com_exception_class_entry, message, (zend_long)(uint32_t)code); #else zend_throw_exception(php_com_exception_class_entry, message, (zend_long)code); #endif if (free_msg) { LocalFree(message); } }
/* {{{ */ static int php_rsa_check_padding(phpc_long_t padding, zend_bool sigver TSRMLS_DC) { zend_bool ok; switch (padding) { case RSA_PKCS1_PADDING: case RSA_NO_PADDING: ok = 1; break; case RSA_PKCS1_OAEP_PADDING: case RSA_SSLV23_PADDING: ok = !sigver; break; case RSA_X931_PADDING: ok = sigver; break; default: ok = 0; } if (ok) { return SUCCESS; } zend_throw_exception(php_rsa_exception_ce, "Ivalid padding parameter", PHP_RSA_ERROR_INVALID_PADDING TSRMLS_CC); return FAILURE; }
zend_object_iterator *spl_dllist_get_iterator(zend_class_entry *ce, zval *object, int by_ref) /* {{{ */ { spl_dllist_it *iterator; spl_dllist_object *dllist_object = Z_SPLDLLIST_P(object); if (by_ref) { zend_throw_exception(spl_ce_RuntimeException, "An iterator cannot be used with foreach by reference", 0); return NULL; } iterator = emalloc(sizeof(spl_dllist_it)); zend_iterator_init((zend_object_iterator*)iterator); ZVAL_COPY(&iterator->intern.it.data, object); iterator->intern.it.funcs = &spl_dllist_it_funcs; iterator->intern.ce = ce; iterator->traverse_position = dllist_object->traverse_position; iterator->traverse_pointer = dllist_object->traverse_pointer; iterator->flags = dllist_object->flags & SPL_DLLIST_IT_MASK; ZVAL_UNDEF(&iterator->intern.value); SPL_LLIST_CHECK_ADDREF(iterator->traverse_pointer); return &iterator->intern.it; }
/* {{{ proto void SplDoublyLinkedList::__unserialize(array serialized) */ SPL_METHOD(SplDoublyLinkedList, __unserialize) { spl_dllist_object *intern = Z_SPLDLLIST_P(ZEND_THIS); HashTable *data; zval *flags_zv, *storage_zv, *members_zv, *elem; if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "h", &data) == FAILURE) { return; } flags_zv = zend_hash_index_find(data, 0); storage_zv = zend_hash_index_find(data, 1); members_zv = zend_hash_index_find(data, 2); if (!flags_zv || !storage_zv || !members_zv || Z_TYPE_P(flags_zv) != IS_LONG || Z_TYPE_P(storage_zv) != IS_ARRAY || Z_TYPE_P(members_zv) != IS_ARRAY) { zend_throw_exception(spl_ce_UnexpectedValueException, "Incomplete or ill-typed serialization data", 0); return; } intern->flags = (int) Z_LVAL_P(flags_zv); ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(storage_zv), elem) { spl_ptr_llist_push(intern->llist, elem); } ZEND_HASH_FOREACH_END();
static void php_yar_client_trigger_error(int throw_exception TSRMLS_DC, int code, const char *format, ...) { /* {{{ */ va_list arg; char *message; zend_class_entry *ce; va_start(arg, format); vspprintf(&message, 0, format, arg); va_end(arg); if (throw_exception) { switch (code) { case YAR_ERR_PACKAGER: ce = yar_client_packager_exception_ce; break; case YAR_ERR_PROTOCOL: ce = yar_client_protocol_exception_ce; break; case YAR_ERR_TRANSPORT: ce = yar_client_transport_exception_ce; break; case YAR_ERR_REQUEST: case YAR_ERR_EXCEPTION: ce = yar_server_exception_ce; break; default: ce = yar_client_exception_ce; break; } zend_throw_exception(ce, message, code TSRMLS_CC); } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "[%d] %s", code, message); } efree(message); } /* }}} */
/* {{{ proto void Riak\Bucket->getKeyStream(Riak\Output\KeyStreamOutput streamer [, int $timeout = 0]) Streams all keys in the bucket */ PHP_METHOD(RiakBucket, getKeyStream) { struct riak_stream_key_cb_param cb_params; riack_string rsbucket, *rstype; riak_connection *connection, *stream_connection; zval* zstreamer; long timeout; int riackstatus; timeout = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|l", &zstreamer, riak_key_streamer_ce, &timeout) == FAILURE) { zend_throw_exception(riak_badarguments_exception_ce, "Bad or missing argument", 500 TSRMLS_CC); return; } // Create a new connection only for this stream // LibRiack can only handle one operation at the time pr connection connection = get_riak_connection(getThis() TSRMLS_CC); THROW_EXCEPTION_IF_CONNECTION_IS_NULL(connection); stream_connection = take_connection(connection->client->host, strlen(connection->client->host), connection->client->port TSRMLS_CC); if (!stream_connection) { CHECK_RIACK_STATUS_THROW_AND_RETURN_ON_ERROR(stream_connection, RIACK_ERROR_COMMUNICATION); } rsbucket = riack_name_from_bucket(getThis() TSRMLS_CC); #ifdef ZTS cb_params.tsrm_ls = TSRMLS_C; #endif cb_params.zstreamer = zstreamer; rstype = riack_get_bucket_type_from_bucket(connection->client, getThis() TSRMLS_CC); // Not gonna do a retry here on purpose... no reason to retry a mistake in the first place riackstatus = riack_stream_keys_ext(stream_connection->client, &rsbucket, rstype, riak_stream_key_cb, &cb_params, timeout); CHECK_RIACK_STATUS_THROW_ON_ERROR(stream_connection, riackstatus); RFREE(connection->client, rstype); release_connection(stream_connection TSRMLS_CC); }
/** * Return negative, 0, or positive according to whether a < b, a == b, or a > b * respectively. * @param Timeval $a The first time to compare * @param Timeval $b The second time to compare * @return long */ PHP_METHOD(Timeval, compare) { zval *a_obj; zval *b_obj; /* "OO" == 2 Objects */ #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "OO", &a_obj, grpc_ce_timeval, &b_obj, grpc_ce_timeval) == FAILURE) { zend_throw_exception(spl_ce_InvalidArgumentException, "compare expects two Timevals", 1); return; } #else ZEND_PARSE_PARAMETERS_START(2, 2) Z_PARAM_OBJECT_OF_CLASS(a_obj, grpc_ce_timeval) Z_PARAM_OBJECT_OF_CLASS(b_obj, grpc_ce_timeval) ZEND_PARSE_PARAMETERS_END(); #endif wrapped_grpc_timeval *a = Z_WRAPPED_GRPC_TIMEVAL_P(a_obj); wrapped_grpc_timeval *b = Z_WRAPPED_GRPC_TIMEVAL_P(b_obj); long result = gpr_time_cmp(a->wrapped, b->wrapped); RETURN_LONG(result); }
/* {{{ proto bool MarkdownDocument::dumpTree(mixed $out_stream [, string $title = "" ]) */ PHP_METHOD(markdowndoc, dumpTree) { discount_object *dobj; zval *zstream; php_stream *stream; int close; FILE *f; char *title = ""; int title_len = 0; int status; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|s", &zstream, &title, &title_len) == FAILURE) { RETURN_FALSE; } if ((dobj = markdowndoc_get_object(getThis(), 1 TSRMLS_CC)) == NULL) { RETURN_FALSE; } if (markdowndoc_get_file(zstream, 1, &stream, &close, &f TSRMLS_CC) == FAILURE) { RETURN_FALSE; } status = mkd_dump(dobj->markdoc, f, title); markdown_sync_stream_and_file(stream, close, f TSRMLS_CC); if (status == -1) { /* should never happen */ zend_throw_exception(spl_ce_RuntimeException, "Error dumping tree: call to the library failed", 0 TSRMLS_CC); RETURN_FALSE; } RETURN_TRUE; }
/** * Checks whether the two times are within $threshold of each other * @param Timeval $a The first time to compare * @param Timeval $b The second time to compare * @param Timeval $threshold The threshold to check against * @return bool True if $a and $b are within $threshold, False otherwise */ PHP_METHOD(Timeval, similar) { zval *a_obj; zval *b_obj; zval *thresh_obj; /* "OOO" == 3 Objects */ #ifndef FAST_ZPP if (zend_parse_parameters(ZEND_NUM_ARGS(), "OOO", &a_obj, grpc_ce_timeval, &b_obj, grpc_ce_timeval, &thresh_obj, grpc_ce_timeval) == FAILURE) { zend_throw_exception(spl_ce_InvalidArgumentException, "compare expects three Timevals", 1); return; } #else ZEND_PARSE_PARAMETERS_START(3, 3) Z_PARAM_OBJECT_OF_CLASS(a_obj, grpc_ce_timeval) Z_PARAM_OBJECT_OF_CLASS(b_obj, grpc_ce_timeval) Z_PARAM_OBJECT_OF_CLASS(thresh_obj, grpc_ce_timeval) ZEND_PARSE_PARAMETERS_END(); #endif wrapped_grpc_timeval *a = Z_WRAPPED_GRPC_TIMEVAL_P(a_obj); wrapped_grpc_timeval *b = Z_WRAPPED_GRPC_TIMEVAL_P(b_obj); wrapped_grpc_timeval *thresh = Z_WRAPPED_GRPC_TIMEVAL_P(thresh_obj); int result = gpr_time_similar(a->wrapped, b->wrapped, thresh->wrapped); RETURN_BOOL(result); }
PHP_METHOD( Transliterator, __construct ) { /* this constructor shouldn't be called as it's private */ zend_throw_exception( NULL, "An object of this type cannot be created with the new operator.", 0 ); }
/* Socket-related functions */ int php_amqp_set_resource_read_timeout(amqp_connection_resource *resource, double timeout TSRMLS_DC) { assert(timeout >= 0.0); #ifdef PHP_WIN32 DWORD read_timeout; /* In Windows, setsockopt with SO_RCVTIMEO sets actual timeout to a value that's 500ms greater than specified value. Also, it's not possible to set timeout to any value below 500ms. Zero timeout works like it should, however. */ if (timeout == 0.) { read_timeout = 0; } else { read_timeout = (int) (max(connection->read_timeout * 1.e+3 - .5e+3, 1.)); } #else struct timeval read_timeout; read_timeout.tv_sec = (int) floor(timeout); read_timeout.tv_usec = (int) ((timeout - floor(timeout)) * 1.e+6); #endif if (0 != setsockopt(amqp_get_sockfd(resource->connection_state), SOL_SOCKET, SO_RCVTIMEO, (char *)&read_timeout, sizeof(read_timeout))) { zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: cannot setsockopt SO_RCVTIMEO", 0 TSRMLS_CC); return 0; } return 1; }
/* {{{ Mosquitto\Client::__construct() */ PHP_METHOD(Mosquitto_Client, __construct) { mosquitto_client_object *object; char *id = NULL; int id_len = 0; zend_bool clean_session = 1; PHP_MOSQUITTO_ERROR_HANDLING(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!b", &id, &id_len, &clean_session) == FAILURE) { PHP_MOSQUITTO_RESTORE_ERRORS(); return; } PHP_MOSQUITTO_RESTORE_ERRORS(); object = (mosquitto_client_object *) zend_object_store_get_object(getThis() TSRMLS_CC); object->client = mosquitto_new(id, clean_session, object); if (!object->client) { char *message = php_mosquitto_strerror_wrapper(errno); zend_throw_exception(mosquitto_ce_exception, message, 1 TSRMLS_CC); #ifndef STRERROR_R_CHAR_P if (message != NULL) { efree(message); } #endif } }
int php_amqp_set_resource_write_timeout(amqp_connection_resource *resource, double timeout TSRMLS_DC) { assert(timeout >= 0.0); #ifdef PHP_WIN32 DWORD write_timeout; if (timeout == 0.) { write_timeout = 0; } else { write_timeout = (int) (max(timeout * 1.e+3 - .5e+3, 1.)); } #else struct timeval write_timeout; write_timeout.tv_sec = (int) floor(timeout); write_timeout.tv_usec = (int) ((timeout - floor(timeout)) * 1.e+6); #endif if (0 != setsockopt(amqp_get_sockfd(resource->connection_state), SOL_SOCKET, SO_SNDTIMEO, (char *)&write_timeout, sizeof(write_timeout))) { zend_throw_exception(amqp_connection_exception_class_entry, "Socket error: cannot setsockopt SO_SNDTIMEO", 0 TSRMLS_CC); return 0; } return 1; }
PHP_METHOD(ArrayList, removeIndex){ size_t index; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) { RETURN_NULL(); } list_object* obj = (list_object*) zend_object_store_get_object(getThis() TSRMLS_CC); if (obj->object != NULL) { try { if(obj->type == TYPE_LONG) { ((List<long>*) obj->object)->removeIndex(index); } else if (obj->type == TYPE_DOUBLE) { ((List<double>*) obj->object)->removeIndex(index); } else if (obj->type == TYPE_BOOLEAN) { ((List<char>*) obj->object)->removeIndex(index); } else if (obj->type == TYPE_STRING) { ((List<char*>*) obj->object)->removeIndex(index); } else { ((List<zval*>*) obj->object)->removeIndex(index); } } catch (const std::out_of_range& e) { zend_throw_exception(NULL, e.what(), 0 TSRMLS_CC); RETURN_NULL(); } } }
ZEND_METHOD(Nc_Sql_MasterSlaveConnection, query) { zval *sql, *flag; zval *connection, *r; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &sql, &flag) == FAILURE || Z_TYPE_P(flag) != IS_LONG) return; if (Z_LVAL_P(flag) & NC_SQL_CONNECTION_WRITE) { connection = nc_kernel_injection_property(getThis(), "masterConnection", Nc_Sql_Connection_ce); } else { connection = nc_kernel_injection_property(getThis(), "slaveConnection", Nc_Sql_Connection_ce); } if (!connection) return; r = zend_call_method_with_2_params(&connection, Z_OBJCE_P(connection), NULL, "query", &r, sql, flag); zval_ptr_dtor(&connection); if (!r) { zend_throw_exception(Nc_Sql_Exception_ce, "Cannot invoke query of injection property masterConnection/slaveConnection.", 0 TSRMLS_CC); return; } RETVAL_ZVAL(r, 0, 0); efree(r); }
/* {{{ proto AMQPExchange::setArgument(key, value) */ static PHP_METHOD(amqp_exchange_class, setArgument) { PHP5to7_READ_PROP_RV_PARAM_DECL; char *key= NULL; PHP5to7_param_str_len_type_t key_len = 0; zval *value = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &key, &key_len, &value) == FAILURE) { return; } switch (Z_TYPE_P(value)) { case IS_NULL: PHP5to7_ZEND_HASH_DEL(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, (uint) (key_len + 1)); break; PHP5to7_CASE_IS_BOOL: case IS_LONG: case IS_DOUBLE: case IS_STRING: PHP5to7_ZEND_HASH_ADD(PHP_AMQP_READ_THIS_PROP_ARR("arguments"), key, (uint) (key_len + 1), value, sizeof(zval *)); Z_TRY_ADDREF_P(value); break; default: zend_throw_exception(amqp_exchange_exception_class_entry, "The value parameter must be of type NULL, int, double or string.", 0 TSRMLS_CC); return; } RETURN_TRUE; }
/* {{{ MongoCursor::addOption */ PHP_METHOD(MongoCursor, addOption) { char *key; int key_len; zval *query, *value; mongo_cursor *cursor; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &key, &key_len, &value) == FAILURE) { return; } cursor = (mongo_cursor*)zend_object_store_get_object(getThis() TSRMLS_CC); MONGO_CHECK_INITIALIZED(cursor->link, MongoCursor); if (cursor->started_iterating) { zend_throw_exception(mongo_ce_CursorException, "cannot modify cursor after beginning iteration.", 0 TSRMLS_CC); return; } make_special(cursor); query = cursor->query; add_assoc_zval(query, key, value); zval_add_ref(&value); RETURN_ZVAL(getThis(), 1, 0); }