/* {{{ proto XmlResults execute() */ PHP_DBXML_METHOD_BEGIN(XmlIndexLookup, execute) { zval *zqc,*zt; long flags = 0; PHP_DBXML_STUFFED_THIS(XmlIndexLookup); #define SET_PTR(expr) \ XmlQueryContext c = php_dbxml_get_XmlQueryContext_object_pointer(zqc TSRMLS_CC); \ XmlResults r = expr; \ object_init_ex(return_value, php_dbxml_XmlResults_ce); \ php_dbxml_set_XmlResults_object_pointer(return_value, r TSRMLS_CC); if (SUCCESS == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "O|l", &zqc, php_dbxml_XmlQueryContext_ce, &flags)) { SET_PTR(This.execute(c, flags)); php_dbxml_set_XmlResults_object_pointer(return_value, r TSRMLS_CC); } else if (SUCCESS == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "OO", &zt, php_dbxml_XmlTransaction_ce, &zqc, php_dbxml_XmlQueryContext_ce, &flags)) { XmlTransaction t = php_dbxml_get_XmlTransaction_object_pointer(zt TSRMLS_CC); SET_PTR(This.execute(t, c, flags)); } else { WRONG_PARAM_COUNT; } } PHP_DBXML_METHOD_END()
/* {{{ proto XmlIndexSpecification::replaceIndex(...) replaces an index */ PHP_DBXML_METHOD_BEGIN(XmlIndexSpecification, replaceIndex) { char *uri, *name, *index; int uri_len, name_len, index_len; long type, syntax; PHP_DBXML_STUFFED_THIS(XmlIndexSpecification); if (SUCCESS == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "ssll", &uri, &uri_len, &name, &name_len, &type, &syntax)) { This.replaceIndex(std::string(uri, uri_len), std::string(name, name_len), (XmlIndexSpecification::Type)type, (XmlValue::Type)syntax); } else if (SUCCESS == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "sss", &uri, &uri_len, &name, &name_len, &index, &index_len)) { This.replaceIndex(std::string(uri, uri_len), std::string(name, name_len), std::string(index, index_len)); } else { WRONG_PARAM_COUNT; } } PHP_DBXML_METHOD_END()
/* {{{ proto XmlIndexSpecification::addDefaultIndex(...) Adds an index */ PHP_DBXML_METHOD_BEGIN(XmlIndexSpecification, addDefaultIndex) { char *index; int index_len; long type, syntax; PHP_DBXML_STUFFED_THIS(XmlIndexSpecification); if (SUCCESS == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "ll", &type, &syntax)) { This.addDefaultIndex((XmlIndexSpecification::Type)type, (XmlValue::Type)syntax); } else if (SUCCESS == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "s", &index, &index_len)) { This.addDefaultIndex(std::string(index, index_len)); } else { WRONG_PARAM_COUNT; } } PHP_DBXML_METHOD_END()
/* {{{ proto MongoDB\Driver\UTCDatetime UTCDatetime::__construct(integer $milliseconds) Construct a new UTCDatetime */ PHP_METHOD(UTCDatetime, __construct) { php_phongo_utcdatetime_t *intern; zend_error_handling error_handling; long milliseconds; #if SIZEOF_LONG == 4 char *s_milliseconds; int s_milliseconds_len; #endif zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC); intern = (php_phongo_utcdatetime_t *)zend_object_store_get_object(getThis() TSRMLS_CC); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &milliseconds) == FAILURE) { zend_restore_error_handling(&error_handling TSRMLS_CC); return; } #if SIZEOF_LONG == 4 if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "s", &s_milliseconds, &s_milliseconds_len) == FAILURE) { zend_restore_error_handling(&error_handling TSRMLS_CC); return; } intern->milliseconds = strtoll(s_milliseconds, NULL, 10); #else intern->milliseconds = milliseconds; #endif zend_restore_error_handling(&error_handling TSRMLS_CC); }
/* {{{ proto object Win\System\Mutex->__construct([string|Unicode name[, own[, inherit]]]) creates a new mutex, optionally sets the owner to the thread that called it if the mutex cannot be created, will attempt to open it instead if ownership is requested, and the mutex cannot be owned this will throw an exception */ PHP_METHOD(WinSystemMutex, __construct) { /* Used for regular string */ char * name = NULL; int name_length; /* Used for wchar string */ zval *unicode = NULL; int use_unicode = 0; /* Variables for a and w versions */ SECURITY_ATTRIBUTES mutex_attributes; zend_bool inherit = TRUE; zend_bool own = FALSE; HANDLE mutex_handle; DWORD error_num; winsystem_mutex_object *mutex = (winsystem_mutex_object *)zend_object_store_get_object(getThis() TSRMLS_CC); PHP_WINSYSTEM_EXCEPTIONS /* version one, use unicode */ if (FAILURE != zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "O|bb", &unicode, ce_winsystem_unicode, &own, &inherit)) { use_unicode = 1; } else if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!bb", &name, &name_length, &own, &inherit)) { PHP_WINSYSTEM_RESTORE_ERRORS return; }
/* {{{ 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); } }
/* {{{ */ static int collator_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) { const char* locale; size_t locale_len = 0; zval* object; Collator_object* co; int zpp_flags = is_constructor ? ZEND_PARSE_PARAMS_THROW : 0; intl_error_reset( NULL ); object = return_value; /* Parse parameters. */ if( zend_parse_parameters_ex( zpp_flags, ZEND_NUM_ARGS(), "s", &locale, &locale_len ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "collator_create: unable to parse input params", 0 ); return FAILURE; } INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len); COLLATOR_METHOD_FETCH_OBJECT; if(locale_len == 0) { locale = intl_locale_get_default(); } /* Open ICU collator. */ co->ucoll = ucol_open( locale, COLLATOR_ERROR_CODE_P( co ) ); INTL_CTOR_CHECK_STATUS(co, "collator_create: unable to open ICU collator"); return SUCCESS; }
/* {{{ ResourceBundle_ctor */ static int resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) { const char *bundlename; size_t bundlename_len = 0; const char *locale; size_t locale_len = 0; zend_bool fallback = 1; int zpp_flags = is_constructor ? ZEND_PARSE_PARAMS_THROW : 0; zval *object = return_value; ResourceBundle_object *rb = Z_INTL_RESOURCEBUNDLE_P( object ); intl_error_reset( NULL ); if( zend_parse_parameters_ex( zpp_flags, ZEND_NUM_ARGS(), "s!s!|b", &locale, &locale_len, &bundlename, &bundlename_len, &fallback ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "resourcebundle_ctor: unable to parse input parameters", 0 ); return FAILURE; } INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len); if (locale == NULL) { locale = intl_locale_get_default(); } if (bundlename_len >= MAXPATHLEN) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "Bundle name too long", 0 ); zval_ptr_dtor(return_value); ZVAL_NULL(return_value); return FAILURE; } if (fallback) { rb->me = ures_open(bundlename, locale, &INTL_DATA_ERROR_CODE(rb)); } else { rb->me = ures_openDirect(bundlename, locale, &INTL_DATA_ERROR_CODE(rb)); } INTL_CTOR_CHECK_STATUS(rb, "resourcebundle_ctor: Cannot load libICU resource bundle"); if (!fallback && (INTL_DATA_ERROR_CODE(rb) == U_USING_FALLBACK_WARNING || INTL_DATA_ERROR_CODE(rb) == U_USING_DEFAULT_WARNING)) { char *pbuf; intl_errors_set_code(NULL, INTL_DATA_ERROR_CODE(rb)); spprintf(&pbuf, 0, "resourcebundle_ctor: Cannot load libICU resource " "'%s' without fallback from %s to %s", bundlename ? bundlename : "(default data)", locale, ures_getLocaleByType( rb->me, ULOC_ACTUAL_LOCALE, &INTL_DATA_ERROR_CODE(rb))); intl_errors_set_custom_msg(INTL_DATA_ERROR_P(rb), pbuf, 1); efree(pbuf); return FAILURE; } return SUCCESS; }
PHP_METHOD(MongoDB, createCollection) { zval *data = NULL, *temp, *options = NULL; char *collection; int collection_len; zend_bool capped = 0; long size = 0, max = 0; if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "s|bll", &collection, &collection_len, &capped, &size, &max) == SUCCESS) { MAKE_STD_ZVAL(data); array_init(data); add_assoc_stringl(data, "create", collection, collection_len, 1); if (size) { add_assoc_long(data, "size", size); } if (capped) { php_error_docref(NULL TSRMLS_CC, MONGO_E_DEPRECATED, "This method now accepts arguments as an options array instead of the three optional arguments for capped, size and max elements"); add_assoc_bool(data, "capped", 1); if (max) { add_assoc_long(data, "max", max); } } } else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a", &collection, &collection_len, &options) == SUCCESS) { zval *tmp_copy; /* We create a new array here, instead of just tagging "create" => * <name> at the end of the array. This is because MongoDB wants the * name of the command as first element in the array. */ MAKE_STD_ZVAL(data); array_init(data); add_assoc_stringl(data, "create", collection, collection_len, 1); if (options) { zend_hash_merge(Z_ARRVAL_P(data), Z_ARRVAL_P(options), (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *), 0); } } else { return; } MAKE_STD_ZVAL(temp); MONGO_METHOD1(MongoDB, command, temp, getThis(), data); zval_ptr_dtor(&temp); zval_ptr_dtor(&data); if (!EG(exception)) { zval *zcollection; /* get the collection we just created */ MAKE_STD_ZVAL(zcollection); ZVAL_STRINGL(zcollection, collection, collection_len, 1); MONGO_METHOD1(MongoDB, selectCollection, return_value, getThis(), zcollection); zval_ptr_dtor(&zcollection); } }
static void variant_unary_operation(enum variant_unary_opcode op, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */ { VARIANT vres; VARIANT left_val; VARIANT *vleft = NULL; zval *zleft = NULL; php_com_dotnet_object *obj; HRESULT result; int codepage = CP_ACP; VariantInit(&left_val); VariantInit(&vres); if (SUCCESS == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "O", &zleft, php_com_variant_class_entry)) { obj = CDNO_FETCH(zleft); vleft = &obj->v; } else if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z!", &zleft)) { vleft = &left_val; php_com_variant_from_zval(vleft, zleft, codepage); } else { return; } switch (op) { case VOP_ABS: result = VarAbs(vleft, &vres); break; case VOP_FIX: result = VarFix(vleft, &vres); break; case VOP_INT: result = VarInt(vleft, &vres); break; case VOP_NEG: result = VarNeg(vleft, &vres); break; case VOP_NOT: result = VarNot(vleft, &vres); break; default: result = E_INVALIDARG; } if (SUCCEEDED(result)) { php_com_wrap_variant(return_value, &vres, codepage); } else { php_com_throw_exception(result, NULL); } VariantClear(&vres); VariantClear(&left_val); }
/* {{{ proto null setContainer() */ PHP_DBXML_METHOD_BEGIN(XmlIndexLookup, setContainer) { zval *zv; PHP_DBXML_STUFFED_THIS(XmlIndexLookup); if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "O", &zv, php_dbxml_XmlContainer_ce)) { WRONG_PARAM_COUNT; } XmlContainer c = php_dbxml_get_XmlContainer_object_pointer(zv TSRMLS_CC); This.setContainer(c); } PHP_DBXML_METHOD_END()
/* {{{ proto null setHighBound() */ PHP_DBXML_METHOD_BEGIN(XmlIndexLookup, setHighBound) { zval *zv; long op; PHP_DBXML_STUFFED_THIS(XmlIndexLookup); if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "Ol", &zv, php_dbxml_XmlValue_ce, &op)) { WRONG_PARAM_COUNT; } XmlValue v = php_dbxml_get_XmlValue_object_pointer(zv TSRMLS_CC); This.setHighBound(v, (XmlIndexLookup::Operation) op); } PHP_DBXML_METHOD_END()
/* {{{ 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 tmp, *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 (Z_TYPE(EX(This)) == IS_OBJECT) { ce = Z_OBJCE(EX(This)); } else if (Z_CE(EX(This))) { ce = Z_CE(EX(This)); } 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) { ZVAL_STRING(&tmp, message); zend_update_property_ex(zend_ce_exception, object, CG(known_strings)[ZEND_STR_MESSAGE], &tmp); zval_ptr_dtor(&tmp); } if (code) { ZVAL_LONG(&tmp, code); zend_update_property_ex(zend_ce_exception, object, CG(known_strings)[ZEND_STR_CODE], &tmp); } if (previous) { zend_update_property_ex(zend_ce_exception, object, CG(known_strings)[ZEND_STR_PREVIOUS], previous); } ZVAL_LONG(&tmp, severity); zend_update_property_ex(zend_ce_exception, object, CG(known_strings)[ZEND_STR_SEVERITY], &tmp); if (argc >= 4) { ZVAL_STRING(&tmp, filename); zend_update_property_ex(zend_ce_exception, object, CG(known_strings)[ZEND_STR_FILE], &tmp); zval_ptr_dtor(&tmp); if (argc < 5) { lineno = 0; /* invalidate lineno */ } ZVAL_LONG(&tmp, lineno); zend_update_property_ex(zend_ce_exception, object, CG(known_strings)[ZEND_STR_LINE], &tmp); } }
/* {{{ */ static int numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) { const char* locale; char* pattern = NULL; size_t locale_len = 0, pattern_len = 0; zend_long style; UChar* spattern = NULL; int32_t spattern_len = 0; int zpp_flags = is_constructor ? ZEND_PARSE_PARAMS_THROW : 0; FORMATTER_METHOD_INIT_VARS; /* Parse parameters. */ if( zend_parse_parameters_ex( zpp_flags, ZEND_NUM_ARGS(), "sl|s", &locale, &locale_len, &style, &pattern, &pattern_len ) == FAILURE ) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "numfmt_create: unable to parse input parameters", 0 ); return FAILURE; } INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len); object = return_value; FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK; /* Convert pattern (if specified) to UTF-16. */ if(pattern && pattern_len) { intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(nfo)); INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: error converting pattern to UTF-16"); } if(locale_len == 0) { locale = intl_locale_get_default(); } /* Create an ICU number formatter. */ FORMATTER_OBJECT(nfo) = unum_open(style, spattern, spattern_len, locale, NULL, &INTL_DATA_ERROR_CODE(nfo)); if(spattern) { efree(spattern); } INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: number formatter creation failed"); return SUCCESS; }
/* {{{ 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); } }
/* {{{ 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 tmp, *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 (Z_TYPE(EX(This)) == IS_OBJECT) { ce = Z_OBJCE(EX(This)); } else if (Z_CE(EX(This))) { ce = Z_CE(EX(This)); } 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) { ZVAL_STR(&tmp, message); zend_update_property_ex(base_ce, object, ZSTR_KNOWN(ZEND_STR_MESSAGE), &tmp); } if (code) { ZVAL_LONG(&tmp, code); zend_update_property_ex(base_ce, object, ZSTR_KNOWN(ZEND_STR_CODE), &tmp); } if (previous) { zend_update_property_ex(base_ce, object, ZSTR_KNOWN(ZEND_STR_PREVIOUS), previous); } }
/* {{{ proto void Win\Gui\Text::__construct(Win\Gui\Window parent, string|object text[, array options]) Create a new text area static control */ PHP_METHOD(WinGuiControlText, __construct) { HashTable *options = NULL; /* Defaults for the window */ zend_bool use_unicode = FALSE; char * text; int text_length; long x = 0, y = 0, width = 400, height = 400, style = WS_CHILD | SS_LEFT | WS_VISIBLE, extrastyle = 0; zval *parent = NULL, *unicode; HWND window_handle = NULL; wingui_window_object *window_object; zval **value; PHP_WINGUI_EXCEPTIONS /* version one, use unicode */ if (FAILURE != zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "OO|H", &parent, ce_wingui_window, &unicode, ce_winsystem_unicode, &options)) { use_unicode = 1; } else if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os|H", &parent, ce_wingui_window, &text, &text_length, &options)) { PHP_WINGUI_RESTORE_ERRORS return; }
PHP_METHOD(jsonrpc_server, register) { zval *closure=NULL; zval *val; zval *name; zval *callbacks; char *lcname; char *name_str, *tmp; int name_len, tmp_len; zval *classname; zend_class_entry **pce; zend_class_entry *ce; zend_function *fptr; zval *object = getThis(); if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "zO", &name, &closure, zend_ce_closure) == SUCCESS) { fptr = (zend_function*)zend_get_closure_method_def(closure TSRMLS_CC); Z_ADDREF_P(closure); } else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &name, &name_str, &name_len) == SUCCESS) { if ((tmp = strstr(name_str, "::")) == NULL) { char *nsname; lcname = zend_str_tolower_dup(name_str, name_len); // Ignore leading "\" nsname = lcname; if (lcname[0] == '\\') { nsname = &lcname[1]; name_len--; } if (zend_hash_find(EG(function_table), nsname, name_len + 1, (void **)&fptr) == FAILURE) { efree(lcname); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Function %s() does not exist", name_str); return; } efree(lcname); }else { tmp_len = tmp - name_str; MAKE_STD_ZVAL(classname); ZVAL_STRINGL(classname, name_str, tmp_len, 1); name_len = name_len - (tmp_len + 2); name_str = tmp + 2; //php_printf("classname: %s, method: %s\n", Z_STRVAL_P(classname), name_str); if (zend_lookup_class(Z_STRVAL_P(classname), Z_STRLEN_P(classname), &pce TSRMLS_CC) == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Class %s does exist", Z_STRVAL_P(classname)); //zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, // "Class %s does not exist", Z_STRVAL_P(classname)); zval_dtor(classname); return; } ce = *pce; lcname = zend_str_tolower_dup(name_str, name_len); if (zend_hash_find(&ce->function_table, lcname, name_len + 1, (void **) &fptr) == FAILURE) { efree(lcname); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Method %s::%s() does not exist", ce->name, name_str); //zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, // "Method %s::%s() does not exist", ce->name, name_str); return; } efree(lcname); } }else { return ; } callbacks = zend_read_property( php_jsonrpc_server_entry, object, "callbacks", sizeof("callbacks")-1, 0 TSRMLS_CC ); MAKE_STD_ZVAL(val); #if PHP_VERSION_ID < 50399 zend_create_closure(val, fptr TSRMLS_CC); #else zend_create_closure(val, fptr, NULL, NULL TSRMLS_CC); #endif add_assoc_zval(callbacks, Z_STRVAL_P(name), val); zend_update_property(php_jsonrpc_server_entry, object, "callbacks", sizeof("callbacks")-1, callbacks TSRMLS_CC); RETURN_ZVAL(object,1,0); }
/* {{{ */ static int datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) { zval *object; const char *locale_str; size_t locale_len = 0; Locale locale; zend_long date_type = 0; zend_long time_type = 0; zval *calendar_zv = NULL; Calendar *calendar = NULL; zend_long calendar_type; bool calendar_owned; zval *timezone_zv = NULL; TimeZone *timezone = NULL; bool explicit_tz; char* pattern_str = NULL; size_t pattern_str_len = 0; UChar* svalue = NULL; /* UTF-16 pattern_str */ int32_t slength = 0; IntlDateFormatter_object* dfo; int zpp_flags = is_constructor ? ZEND_PARSE_PARAMS_THROW : 0; intl_error_reset(NULL); object = return_value; /* Parse parameters. */ if (zend_parse_parameters_ex(zpp_flags, ZEND_NUM_ARGS(), "sll|zzs", &locale_str, &locale_len, &date_type, &time_type, &timezone_zv, &calendar_zv, &pattern_str, &pattern_str_len) == FAILURE) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: " "unable to parse input parameters", 0); return FAILURE; } INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len); if (locale_len == 0) { locale_str = intl_locale_get_default(); } locale = Locale::createFromName(locale_str); DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; if (DATE_FORMAT_OBJECT(dfo) != NULL) { intl_errors_set(INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: cannot call constructor twice", 0); return FAILURE; } /* process calendar */ if (datefmt_process_calendar_arg(calendar_zv, locale, "datefmt_create", INTL_DATA_ERROR_P(dfo), calendar, calendar_type, calendar_owned) == FAILURE) { goto error; } /* process timezone */ explicit_tz = timezone_zv != NULL && Z_TYPE_P(timezone_zv) != IS_NULL; if (explicit_tz || calendar_owned ) { //we have an explicit time zone or a non-object calendar timezone = timezone_process_timezone_argument(timezone_zv, INTL_DATA_ERROR_P(dfo), "datefmt_create"); if (timezone == NULL) { goto error; } } /* Convert pattern (if specified) to UTF-16. */ if (pattern_str && pattern_str_len > 0) { intl_convert_utf8_to_utf16(&svalue, &slength, pattern_str, pattern_str_len, &INTL_DATA_ERROR_CODE(dfo)); if (U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { /* object construction -> only set global error */ intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: " "error converting pattern to UTF-16", 0); goto error; } } if (pattern_str && pattern_str_len > 0) { DATE_FORMAT_OBJECT(dfo) = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale_str, NULL, 0, svalue, slength, &INTL_DATA_ERROR_CODE(dfo)); } else { DATE_FORMAT_OBJECT(dfo) = udat_open((UDateFormatStyle)time_type, (UDateFormatStyle)date_type, locale_str, NULL, 0, svalue, slength, &INTL_DATA_ERROR_CODE(dfo)); } if (!U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { DateFormat *df = (DateFormat*)DATE_FORMAT_OBJECT(dfo); if (calendar_owned) { df->adoptCalendar(calendar); calendar_owned = false; } else { df->setCalendar(*calendar); } if (timezone != NULL) { df->adoptTimeZone(timezone); } } else { intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: date " "formatter creation failed", 0); goto error; } /* Set the class variables */ dfo->date_type = date_type; dfo->time_type = time_type; dfo->calendar = calendar_type; dfo->requested_locale = estrdup(locale_str); error: if (svalue) { efree(svalue); } if (timezone != NULL && DATE_FORMAT_OBJECT(dfo) == NULL) { delete timezone; } if (calendar != NULL && calendar_owned) { delete calendar; } return U_FAILURE(intl_error_get_code(NULL)) ? FAILURE : SUCCESS; }
static void _php_intlgregcal_constructor_body( INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) { zval *tz_object = NULL; zval args_a[6] = {0}, *args = &args_a[0]; char *locale = NULL; size_t locale_len; zend_long largs[6]; UErrorCode status = U_ZERO_ERROR; int variant; int zpp_flags = is_constructor ? ZEND_PARSE_PARAMS_THROW : 0; intl_error_reset(NULL); // parameter number validation / variant determination if (ZEND_NUM_ARGS() > 6 || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: too many arguments", 0); if (!is_constructor) { zval_dtor(return_value); RETVAL_NULL(); } return; } for (variant = ZEND_NUM_ARGS(); variant > 0 && Z_TYPE(args[variant - 1]) == IS_NULL; variant--) {} if (variant == 4) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: no variant with 4 arguments " "(excluding trailing NULLs)", 0); if (!is_constructor) { zval_dtor(return_value); RETVAL_NULL(); } return; } // argument parsing if (variant <= 2) { if (zend_parse_parameters_ex(zpp_flags, MIN(ZEND_NUM_ARGS(), 2), "|z!s!", &tz_object, &locale, &locale_len) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: bad arguments", 0); if (!is_constructor) { zval_dtor(return_value); RETVAL_NULL(); } return; } } if (variant > 2 && zend_parse_parameters_ex(zpp_flags, ZEND_NUM_ARGS(), "lll|lll", &largs[0], &largs[1], &largs[2], &largs[3], &largs[4], &largs[5]) == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: bad arguments", 0); if (!is_constructor) { zval_dtor(return_value); RETVAL_NULL(); } return; } // instantion of ICU object GregorianCalendar *gcal = NULL; if (variant <= 2) { // From timezone and locale (0 to 2 arguments) TimeZone *tz = timezone_process_timezone_argument(tz_object, NULL, "intlgregcal_create_instance"); if (tz == NULL) { if (!EG(exception)) { zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0); } if (!is_constructor) { zval_dtor(return_value); RETVAL_NULL(); } return; } if (!locale) { locale = const_cast<char*>(intl_locale_get_default()); } gcal = new GregorianCalendar(tz, Locale::createFromName(locale), status); if (U_FAILURE(status)) { intl_error_set(NULL, status, "intlgregcal_create_instance: error " "creating ICU GregorianCalendar from time zone and locale", 0); if (gcal) { delete gcal; } delete tz; if (!is_constructor) { zval_dtor(return_value); RETVAL_NULL(); } return; } } else { // From date/time (3, 5 or 6 arguments) for (int i = 0; i < variant; i++) { if (largs[i] < INT32_MIN || largs[i] > INT32_MAX) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: at least one of the arguments" " has an absolute value that is too large", 0); if (!is_constructor) { zval_dtor(return_value); RETVAL_NULL(); } return; } } if (variant == 3) { gcal = new GregorianCalendar((int32_t)largs[0], (int32_t)largs[1], (int32_t)largs[2], status); } else if (variant == 5) { gcal = new GregorianCalendar((int32_t)largs[0], (int32_t)largs[1], (int32_t)largs[2], (int32_t)largs[3], (int32_t)largs[4], status); } else if (variant == 6) { gcal = new GregorianCalendar((int32_t)largs[0], (int32_t)largs[1], (int32_t)largs[2], (int32_t)largs[3], (int32_t)largs[4], (int32_t)largs[5], status); } if (U_FAILURE(status)) { intl_error_set(NULL, status, "intlgregcal_create_instance: error " "creating ICU GregorianCalendar from date", 0); if (gcal) { delete gcal; } if (!is_constructor) { zval_dtor(return_value); RETVAL_NULL(); } return; } timelib_tzinfo *tzinfo = get_timezone_info(); #if U_ICU_VERSION_MAJOR_NUM * 10 + U_ICU_VERSION_MINOR_NUM >= 42 UnicodeString tzstr = UnicodeString::fromUTF8(StringPiece(tzinfo->name)); #else UnicodeString tzstr = UnicodeString(tzinfo->name, strlen(tzinfo->name), US_INV); #endif if (tzstr.isBogus()) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: could not create UTF-8 string " "from PHP's default timezone name (see date_default_timezone_get())", 0); delete gcal; if (!is_constructor) { zval_dtor(return_value); RETVAL_NULL(); } return; } TimeZone *tz = TimeZone::createTimeZone(tzstr); gcal->adoptTimeZone(tz); } Calendar_object *co = Z_INTL_CALENDAR_P(return_value); co->ucal = gcal; }
static void variant_binary_operation(enum variant_binary_opcode op, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */ { VARIANT vres; VARIANT left_val, right_val; VARIANT *vleft = NULL, *vright = NULL; zval *zleft = NULL, *zright = NULL; php_com_dotnet_object *obj; HRESULT result; int codepage = CP_ACP; VariantInit(&left_val); VariantInit(&right_val); VariantInit(&vres); if (SUCCESS == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "OO", &zleft, php_com_variant_class_entry, &zright, php_com_variant_class_entry)) { obj = CDNO_FETCH(zleft); vleft = &obj->v; obj = CDNO_FETCH(zright); vright = &obj->v; } else if (SUCCESS == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "Oz!", &zleft, php_com_variant_class_entry, &zright)) { obj = CDNO_FETCH(zleft); vleft = &obj->v; vright = &right_val; php_com_variant_from_zval(vright, zright, codepage); } else if (SUCCESS == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "z!O", &zleft, &zright, php_com_variant_class_entry)) { obj = CDNO_FETCH(zright); vright = &obj->v; vleft = &left_val; php_com_variant_from_zval(vleft, zleft, codepage); } else if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "z!z!", &zleft, &zright)) { vleft = &left_val; php_com_variant_from_zval(vleft, zleft, codepage); vright = &right_val; php_com_variant_from_zval(vright, zright, codepage); } else { return; } switch (op) { case VOP_ADD: result = VarAdd(vleft, vright, &vres); break; case VOP_CAT: result = VarCat(vleft, vright, &vres); break; case VOP_SUB: result = VarSub(vleft, vright, &vres); break; case VOP_MUL: result = VarMul(vleft, vright, &vres); break; case VOP_AND: result = VarAnd(vleft, vright, &vres); break; case VOP_DIV: result = VarDiv(vleft, vright, &vres); break; case VOP_EQV: result = VarEqv(vleft, vright, &vres); break; case VOP_IDIV: result = VarIdiv(vleft, vright, &vres); break; case VOP_IMP: result = VarImp(vleft, vright, &vres); break; case VOP_MOD: result = VarMod(vleft, vright, &vres); break; case VOP_OR: result = VarOr(vleft, vright, &vres); break; case VOP_POW: result = VarPow(vleft, vright, &vres); break; case VOP_XOR: result = VarXor(vleft, vright, &vres); break; /*Let say it fails as no valid op has been given */ default: result = E_INVALIDARG; } if (SUCCEEDED(result)) { php_com_wrap_variant(return_value, &vres, codepage); } else { php_com_throw_exception(result, NULL); } VariantClear(&vres); VariantClear(&left_val); VariantClear(&right_val); }
PHP_METHOD(MongoDB, createCollection) { zval *cmd = NULL, *temp, *options = NULL; char *collection; int collection_len; zend_bool capped = 0; long size = 0, max = 0; mongo_db *db; if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "s|bll", &collection, &collection_len, &capped, &size, &max) == SUCCESS) { MAKE_STD_ZVAL(cmd); array_init(cmd); add_assoc_stringl(cmd, "create", collection, collection_len, 1); if (size) { add_assoc_long(cmd, "size", size); } if (capped) { php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "This method now accepts arguments as an options array instead of the three optional arguments for capped, size and max elements"); add_assoc_bool(cmd, "capped", 1); if (max) { add_assoc_long(cmd, "max", max); } } } else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a", &collection, &collection_len, &options) == SUCCESS) { zval *tmp_copy; /* We create a new array here, instead of just tagging "create" => * <name> at the end of the array. This is because MongoDB wants the * name of the command as first element in the array. */ MAKE_STD_ZVAL(cmd); array_init(cmd); add_assoc_stringl(cmd, "create", collection, collection_len, 1); if (options) { zend_hash_merge(Z_ARRVAL_P(cmd), Z_ARRVAL_P(options), (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *), 0); } } else { return; } PHP_MONGO_GET_DB(getThis()); temp = php_mongo_runcommand(db->link, &db->read_pref, Z_STRVAL_P(db->name), Z_STRLEN_P(db->name), cmd, options, 0, NULL TSRMLS_CC); zval_ptr_dtor(&cmd); if (temp) { zval_ptr_dtor(&temp); } if (!EG(exception)) { zval *zcollection; /* get the collection we just created */ zcollection = php_mongo_db_selectcollection(getThis(), collection, collection_len TSRMLS_CC); if (zcollection) { /* Only copy the zval into return_value if it worked. If * zcollection is NULL here, an exception is set */ RETURN_ZVAL(zcollection, 0, 1); } } }
/* {{{ proto Router Router::addRoute(string method, string uri, Callable handler) proto Router Router::addRoute(Route route) Throws RoutingException on failure */ static PHP_METHOD(Router, addRoute) { const char *request_method = NULL; size_t request_method_length = 0L; const char *request_uri = NULL; size_t request_uri_length = 0L; zval *callable = NULL; zend_class_entry *ce = NULL; router_t *router = getRouter(); switch (ZEND_NUM_ARGS()) { case 3: if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "ssz", &request_method, &request_method_length, &request_uri, &request_uri_length, &callable) != SUCCESS) { return; } break; case 1: if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "O", &callable, ce) != SUCCESS) { return; } break; default: zend_throw_exception( RoutingException, "Router::addRoute expects one or three arguments, please see documentation", 0 TSRMLS_CC); return; } { route_t route = {ROUTER_ROUTE_NORMAL}; route.callable = callable; if (ZEND_NUM_ARGS() == 1) { zval *pmethod = NULL, *puri = NULL; zend_call_method_with_0_params( &callable, ce, NULL, "getMethod", &pmethod); if (Z_TYPE_P(pmethod) != IS_STRING) { zend_throw_exception( RoutingException, "getMethod returned a non-string value", 0 TSRMLS_CC); zval_ptr_dtor(&pmethod); return; } zend_call_method_with_0_params( &callable, ce, NULL, "getURI", &puri); if (Z_TYPE_P(puri) != IS_STRING) { zend_throw_exception( RoutingException, "getURI returned a non-string value", 0 TSRMLS_CC); zval_ptr_dtor(&pmethod); zval_ptr_dtor(&puri); return; } ZVAL_STRINGL(&route.method, Z_STRVAL_P(pmethod), Z_STRLEN_P(pmethod), 1); ZVAL_STRINGL(&route.uri, Z_STRVAL_P(puri), Z_STRLEN_P(puri), 1); Z_ADDREF_P(route.callable); zend_hash_next_index_insert( &router->routes, (void**) &route, sizeof(route_t), NULL); zval_ptr_dtor(&pmethod); zval_ptr_dtor(&puri); } else { char *callable_name = NULL; if (!zend_is_callable(callable, 0, &callable_name TSRMLS_CC)) { zend_throw_exception( RoutingException, "handler is not callable", 0 TSRMLS_CC); if (callable_name) efree(callable_name); return; } ZVAL_STRINGL(&route.method, request_method, request_method_length, 1); ZVAL_STRINGL(&route.uri, request_uri, request_uri_length, 1); Z_ADDREF_P(route.callable); zend_hash_next_index_insert( &router->routes, (void**) &route, sizeof(route_t), NULL); if (callable_name) efree(callable_name); } } RETURN_CHAIN(); } /* }}} */