/** * Checks whether put has certain index * * @param string $name * @return boolean */ PHP_METHOD(Phalcon_Http_Request, hasPut) { zval *name, is_put = {}, put = {}, raw = {}, new_put = {}; char *tmp; phalcon_fetch_params(0, 1, 0, &name); PHALCON_CALL_METHODW(&is_put, getThis(), "isput"); if (!zend_is_true(&is_put)) { phalcon_read_global_str(&new_put, SL("_PUT")); } else { phalcon_read_property(&put, getThis(), SL("_put"), PH_NOISY); if (Z_TYPE(put) != IS_ARRAY) { PHALCON_CALL_METHODW(&raw, getThis(), "getrawbody"); array_init(&new_put); PHALCON_ENSURE_IS_STRING(&raw); tmp = estrndup(Z_STRVAL(raw), Z_STRLEN(raw)); sapi_module.treat_data(PARSE_STRING, tmp, &new_put); phalcon_update_property_zval(getThis(), SL("_put"), &new_put); } else { PHALCON_CPY_WRT(&new_put, &put); } } RETVAL_BOOL(phalcon_array_isset(&new_put, name)); }
/* {{{ proto bool Spoofchecker::areConfusable( string str1, string str2[, int &error_code ] ) * Checks if a given text contains any confusable characters */ PHP_METHOD(Spoofchecker, areConfusable) { int ret; char *s1, *s2; int s1_len, s2_len; zval *error_code = NULL; SPOOFCHECKER_METHOD_INIT_VARS; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|z", &s1, &s1_len, &s2, &s2_len, &error_code)) { return; } SPOOFCHECKER_METHOD_FETCH_OBJECT; ret = uspoof_areConfusableUTF8(co->uspoof, s1, s1_len, s2, s2_len, SPOOFCHECKER_ERROR_CODE_P(co)); if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co))); RETURN_TRUE; } if (error_code) { zval_dtor(error_code); ZVAL_LONG(error_code, ret); } RETVAL_BOOL(ret != 0); }
/* {{{ proto bool Spoofchecker::isSuspicious( string text[, int &error_code ] ) * Checks if a given text contains any suspicious characters */ PHP_METHOD(Spoofchecker, isSuspicious) { int ret; char *text; int text_len; zval *error_code = NULL; SPOOFCHECKER_METHOD_INIT_VARS; if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &text, &text_len, &error_code)) { return; } SPOOFCHECKER_METHOD_FETCH_OBJECT; ret = uspoof_checkUTF8(co->uspoof, text, text_len, NULL, SPOOFCHECKER_ERROR_CODE_P(co)); if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co))); RETURN_TRUE; } if (error_code) { zval_dtor(error_code); ZVAL_LONG(error_code, ret); } RETVAL_BOOL(ret != 0); }
PHP_METHOD(WinGdiPath, beizerTo) { wingdi_devicecontext_object *dc_obj; wingdi_path_object *path_obj; zval ***parameters, **x, **y; POINT *points = NULL; DWORD points_total = 0; int param_count, i; WINGDI_ERROR_HANDLING(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", ¶meters, ¶m_count) == FAILURE) return; WINGDI_RESTORE_ERRORS(); path_obj = zend_object_store_get_object(getThis() TSRMLS_CC); dc_obj = zend_object_store_get_object(path_obj->device_context TSRMLS_CC); points = emalloc(param_count * sizeof(POINT)); for (i = 0; i < param_count; i++) { // We expect only arrays if (Z_TYPE_PP(parameters[i]) != IS_ARRAY) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected array for parameter %d, got %s", i + 1, zend_zval_type_name(*(parameters[i]))); goto CLEANUP; } else { // We want 2 elements if (zend_hash_num_elements(Z_ARRVAL_PP(parameters[i])) != 2) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "expected 2 elements for array at parameter %d, got %d", i + 1, zend_hash_num_elements(Z_ARRVAL_PP(parameters[i]))); goto CLEANUP; } else { zend_hash_index_find(Z_ARRVAL_PP(parameters[i]), 0, (void **)&x); zend_hash_index_find(Z_ARRVAL_PP(parameters[i]), 1, (void **)&y); if (Z_TYPE_PP(x) != IS_LONG) convert_to_long(*x); if (Z_TYPE_PP(y) != IS_LONG) convert_to_long(*y); points[i].x = Z_LVAL_PP(x); points[i].y = Z_LVAL_PP(y); points_total++; } } } RETVAL_BOOL(PolyBezierTo(dc_obj->hdc, points, points_total)); CLEANUP: efree(points); }
/* {{{ proto bool SessionHandler::close() Wraps the old close handler */ PHP_METHOD(SessionHandler, close) { PS_SANITY_CHECK_IS_OPEN; // don't return on failure, since not closing the default handler // could result in memory leaks or other nasties zend_parse_parameters_none(); PS(mod_user_is_open) = 0; RETVAL_BOOL(SUCCESS == PS(default_mod)->s_close(&PS(mod_data) TSRMLS_CC)); }
// CHash method useExceptions(bool) -> bool PHP_METHOD(CHash, useExceptions) { chash_object *instance = (chash_object *)zend_object_store_get_object(getThis() TSRMLS_CC); u_char use; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &use) == SUCCESS) { instance->use_exceptions = use; } RETVAL_BOOL(instance->use_exceptions); }
/** * Execute a watermarking. * * @param Phalcon\Image\Adapter $watermark * @param int $offset_x * @param int $offset_y * @param int $opacity */ PHP_METHOD(Phalcon_Image_Adapter_GD, _watermark) { zval *watermark, *offset_x = NULL, *offset_y = NULL, *opacity = NULL, op = {}, image = {}, overlay = {}, blob = {}, saveflag = {}, width = {}, height = {}, color = {}, tmp = {}, effect = {}, blendmode = {}, ret = {}; int int_opacity; double num; phalcon_fetch_params(0, 4, 0, &watermark, &offset_x, &offset_y, &opacity); phalcon_return_property(&image, getThis(), SL("_image")); PHALCON_CALL_METHODW(&blob, watermark, "render"); PHALCON_CALL_FUNCTIONW(&overlay, "imagecreatefromstring", &blob); ZVAL_TRUE(&saveflag); PHALCON_CALL_FUNCTIONW(NULL, "imagesavealpha", &overlay, &saveflag); PHALCON_CALL_FUNCTIONW(&width, "imagesx", &overlay); PHALCON_CALL_FUNCTIONW(&height, "imagesy", &overlay); int_opacity = Z_LVAL_P(opacity); if (int_opacity < 100) { num = (int_opacity * 127.0 / 100) - 127; if (num < 0) { num = -num; } int_opacity = (int)num; ZVAL_LONG(&op, int_opacity); ZVAL_LONG(&tmp, 127); PHALCON_CALL_FUNCTIONW(&color, "imagecolorallocatealpha", &overlay, &tmp, &tmp, &tmp, &op); if (!phalcon_get_constant(&effect, SL("IMG_EFFECT_OVERLAY"))) { return; } PHALCON_CALL_FUNCTIONW(NULL, "imagelayereffect", &overlay, &effect); ZVAL_LONG(&tmp, 0); PHALCON_CALL_FUNCTIONW(NULL, "imagefilledrectangle", &overlay, &tmp, &tmp, &width, &height, &color); } ZVAL_LONG(&blendmode, 1); PHALCON_CALL_FUNCTIONW(NULL, "imagealphablending", &image, &blendmode); ZVAL_LONG(&tmp, 0); PHALCON_CALL_FUNCTIONW(&ret, "imagecopy", &image, &overlay, offset_x, offset_y, &tmp, &tmp, &width, &height); RETVAL_BOOL(zend_is_true(&ret)); }
/** * bool \Phalcon\Flash\Session::has(string $type) * * @see https://github.com/phalcon/cphalcon/issues/1342 */ PHP_METHOD(Phalcon_Flash_Session, has) { zval *type, *messages = NULL; phalcon_fetch_params(0, 0, 1, &type); PHALCON_MM_GROW(); PHALCON_CALL_METHOD(&messages, this_ptr, "_getsessionmessages", PHALCON_GLOBAL(z_false)); RETVAL_BOOL(phalcon_array_isset(messages, type)); PHALCON_MM_RESTORE(); }
/* {{{ proto bool SessionUpdateTimestampHandler::updateTimestamp(string id, string data) Simply call update_timestamp */ PHP_METHOD(SessionHandler, updateTimestamp) { zend_string *key, *val; PS_SANITY_CHECK_IS_OPEN; if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &key, &val) == FAILURE) { return; } /* Legacy save handler may not support update_timestamp API. Just write. */ RETVAL_BOOL(SUCCESS == PS(default_mod)->s_write(&PS(mod_data), key, val, PS(gc_maxlifetime))); }
PHP_METHOD(MongoCollection, setSlaveOkay) { zend_bool slave_okay = 1; mongo_collection *c; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &slave_okay) == FAILURE) { return; } PHP_MONGO_GET_COLLECTION(getThis()); RETVAL_BOOL(c->slave_okay); c->slave_okay = slave_okay; }
PHP_METHOD(MongoDB, setSlaveOkay) { zend_bool slave_okay = 1; mongo_db *db; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &slave_okay) == FAILURE) { return; } PHP_MONGO_GET_DB(getThis()); RETVAL_BOOL(db->slave_okay); db->slave_okay = slave_okay; }
/* {{{ proto bool SessionHandler::gc(int maxlifetime) Wraps the old gc handler */ PHP_METHOD(SessionHandler, gc) { long maxlifetime; int nrdels; PS_SANITY_CHECK_IS_OPEN; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &maxlifetime) == FAILURE) { return; } RETVAL_BOOL(SUCCESS == PS(default_mod)->s_gc(&PS(mod_data), maxlifetime, &nrdels TSRMLS_CC)); }
/* {{{ proto bool SessionHandler::destroy(string id) Wraps the old destroy handler */ PHP_METHOD(SessionHandler, destroy) { char *key; int key_len; PS_SANITY_CHECK_IS_OPEN; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) == FAILURE) { return; } RETVAL_BOOL(SUCCESS == PS(default_mod)->s_destroy(&PS(mod_data), key TSRMLS_CC)); }
/* {{{ proto bool SessionHandler::write(string id, string data) Wraps the old write handler */ PHP_METHOD(SessionHandler, write) { char *key, *val; int key_len, val_len; PS_SANITY_CHECK_IS_OPEN; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &key, &key_len, &val, &val_len) == FAILURE) { return; } RETVAL_BOOL(SUCCESS == PS(default_mod)->s_write(&PS(mod_data), key, val, val_len TSRMLS_CC)); }
/* {{{ proto bool SessionHandler::open(string save_path, string session_name) Wraps the old open handler */ PHP_METHOD(SessionHandler, open) { char *save_path = NULL, *session_name = NULL; int save_path_len, session_name_len; PS_SANITY_CHECK; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &save_path, &save_path_len, &session_name, &session_name_len) == FAILURE) { return; } PS(mod_user_is_open) = 1; RETVAL_BOOL(SUCCESS == PS(default_mod)->s_open(&PS(mod_data), save_path, session_name TSRMLS_CC)); }
PHP_METHOD(MongoDB, setSlaveOkay) { zend_bool slave_okay = 1; mongo_db *db; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &slave_okay) == FAILURE) { return; } PHP_MONGO_GET_DB(getThis()); RETVAL_BOOL(db->read_pref.type != MONGO_RP_PRIMARY); db->read_pref.type = slave_okay ? MONGO_RP_SECONDARY_PREFERRED : MONGO_RP_PRIMARY; }
PHP_METHOD(MongoCollection, setSlaveOkay) { zend_bool slave_okay = 1; mongo_collection *c; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &slave_okay) == FAILURE) { return; } PHP_MONGO_GET_COLLECTION(getThis()); RETVAL_BOOL(c->read_pref.type != MONGO_RP_PRIMARY); c->read_pref.type = slave_okay ? MONGO_RP_SECONDARY_PREFERRED : MONGO_RP_PRIMARY; }
PHP_METHOD(Mongo, setSlaveOkay) { zend_bool slave_okay = 1; mongoclient *link; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &slave_okay) == FAILURE) { return; } PHP_MONGO_GET_LINK(getThis()); RETVAL_BOOL(link->servers->read_pref.type != MONGO_RP_PRIMARY); link->servers->read_pref.type = slave_okay ? MONGO_RP_SECONDARY_PREFERRED : MONGO_RP_PRIMARY; }
/** * Check whether a model is already initialized * * @param string $modelName * @return bool */ PHP_METHOD(Phalcon_Mvc_Collection_Manager, isInitialized){ zval *model_name, *initialized, *lowercased; phalcon_fetch_params(0, 1, 0, &model_name); initialized = phalcon_fetch_nproperty_this(this_ptr, SL("_initialized"), PH_NOISY TSRMLS_CC); ALLOC_INIT_ZVAL(lowercased); phalcon_fast_strtolower(lowercased, model_name); RETVAL_BOOL(phalcon_array_isset(initialized, lowercased)); zval_ptr_dtor(&lowercased); }
/* {{{ proto bool SessionHandler::close() Wraps the old close handler */ PHP_METHOD(SessionHandler, close) { int ret; PS_SANITY_CHECK_IS_OPEN; // don't return on failure, since not closing the default handler // could result in memory leaks or other nasties zend_parse_parameters_none(); PS(mod_user_is_open) = 0; zend_try { ret = PS(default_mod)->s_close(&PS(mod_data)); } zend_catch { PS(session_status) = php_session_none; zend_bailout(); } zend_end_try(); RETVAL_BOOL(SUCCESS == ret); }
/* {{{ proto bool SessionHandler::open(string save_path, string session_name) Wraps the old open handler */ PHP_METHOD(SessionHandler, open) { char *save_path = NULL, *session_name = NULL; size_t save_path_len, session_name_len; int ret; PS_SANITY_CHECK; if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &save_path, &save_path_len, &session_name, &session_name_len) == FAILURE) { return; } PS(mod_user_is_open) = 1; zend_try { ret = PS(default_mod)->s_open(&PS(mod_data), save_path, session_name); } zend_catch { PS(session_status) = php_session_none; zend_bailout(); } zend_end_try(); RETVAL_BOOL(SUCCESS == ret); }
static void _dispatch_magick_cmd(INTERNAL_FUNCTION_PARAMETERS, MagickCommand cmd, char *command) { zval *arr, **entry; HashPosition pos; int argc, i, k = -1; char *argv[32], **argvp; zval tval[32], *tvalp; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &arr) == FAILURE) { return; } /* Build command args */ argc = zend_hash_num_elements(Z_ARRVAL_P(arr)) + 1; if (argc > 32) { argvp = (char **) ecalloc(argc, sizeof(char *)); tvalp = (zval *) ecalloc(argc, sizeof(zval)); } else { argvp = argv; tvalp = tval; } argvp[0] = command; for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos), i = 1; zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **)&entry, &pos) == SUCCESS; zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos), ++i ) { if (Z_TYPE_PP(entry) == IS_ARRAY || Z_TYPE_PP(entry) == IS_OBJECT) { continue; } if (Z_TYPE_PP(entry) == IS_STRING) { argvp[i] = Z_STRVAL_PP(entry); } else { tvalp[++k] = **entry; zval_copy_ctor(&tvalp[k]); convert_to_string(&tvalp[k]); argvp[i] = Z_STRVAL(tvalp[k]); } } /* Imagick processes */ { MagickBooleanType result; ImageInfo *ii; ExceptionInfo *ei; char *metadata = NULL; ii = AcquireImageInfo(); ei = AcquireExceptionInfo(); result = (cmd)(ii, argc, argvp, &metadata, ei); if (ei->reason) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", ei->reason); } if (metadata) { RETVAL_STRING(metadata, 1); } else { RETVAL_BOOL(result); } if (metadata) { DestroyString(metadata); } DestroyImageInfo(ii); DestroyExceptionInfo(ei); } /* Release resources */ while (k != -1) { zval_dtor(&tvalp[k--]); } if (argvp != argv) { efree(argvp); efree(tvalp); } }
SPL_METHOD(SplCharIterator, valid) { FETCH_OBJECT RETVAL_BOOL(obj->offset <= obj->max_offset); }
static void php_xpath_eval(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ { zval *id, retval, *context = NULL; xmlXPathContextPtr ctxp; xmlNodePtr nodep = NULL; xmlXPathObjectPtr xpathobjp; size_t expr_len, nsnbr = 0, xpath_type; dom_xpath_object *intern; dom_object *nodeobj; char *expr; xmlDoc *docp = NULL; xmlNsPtr *ns = NULL; zend_bool register_node_ns = 1; if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os|O!b", &id, dom_xpath_class_entry, &expr, &expr_len, &context, dom_node_class_entry, ®ister_node_ns) == FAILURE) { return; } intern = Z_XPATHOBJ_P(id); ctxp = (xmlXPathContextPtr) intern->dom.ptr; if (ctxp == NULL) { php_error_docref(NULL, E_WARNING, "Invalid XPath Context"); RETURN_FALSE; } docp = (xmlDocPtr) ctxp->doc; if (docp == NULL) { php_error_docref(NULL, E_WARNING, "Invalid XPath Document Pointer"); RETURN_FALSE; } if (context != NULL) { DOM_GET_OBJ(nodep, context, xmlNodePtr, nodeobj); } if (!nodep) { nodep = xmlDocGetRootElement(docp); } if (nodep && docp != nodep->doc) { php_error_docref(NULL, E_WARNING, "Node From Wrong Document"); RETURN_FALSE; } ctxp->node = nodep; if (register_node_ns) { /* Register namespaces in the node */ ns = xmlGetNsList(docp, nodep); if (ns != NULL) { while (ns[nsnbr] != NULL) nsnbr++; } } ctxp->namespaces = ns; ctxp->nsNr = nsnbr; xpathobjp = xmlXPathEvalExpression((xmlChar *) expr, ctxp); ctxp->node = NULL; if (ns != NULL) { xmlFree(ns); ctxp->namespaces = NULL; ctxp->nsNr = 0; } if (! xpathobjp) { RETURN_FALSE; } if (type == PHP_DOM_XPATH_QUERY) { xpath_type = XPATH_NODESET; } else { xpath_type = xpathobjp->type; } switch (xpath_type) { case XPATH_NODESET: { int i; xmlNodeSetPtr nodesetp; array_init(&retval); if (xpathobjp->type == XPATH_NODESET && NULL != (nodesetp = xpathobjp->nodesetval)) { for (i = 0; i < nodesetp->nodeNr; i++) { xmlNodePtr node = nodesetp->nodeTab[i]; zval child; if (node->type == XML_NAMESPACE_DECL) { xmlNsPtr curns; xmlNodePtr nsparent; nsparent = node->_private; curns = xmlNewNs(NULL, node->name, NULL); if (node->children) { curns->prefix = xmlStrdup((xmlChar *) node->children); } if (node->children) { node = xmlNewDocNode(docp, NULL, (xmlChar *) node->children, node->name); } else { node = xmlNewDocNode(docp, NULL, (xmlChar *) "xmlns", node->name); } node->type = XML_NAMESPACE_DECL; node->parent = nsparent; node->ns = curns; } php_dom_create_object(node, &child, &intern->dom); add_next_index_zval(&retval, &child); } } php_dom_create_interator(return_value, DOM_NODELIST); nodeobj = Z_DOMOBJ_P(return_value); dom_xpath_iter(&retval, nodeobj); break; } case XPATH_BOOLEAN: RETVAL_BOOL(xpathobjp->boolval); break; case XPATH_NUMBER: RETVAL_DOUBLE(xpathobjp->floatval) break; case XPATH_STRING: RETVAL_STRING((char *) xpathobjp->stringval); break; default: RETVAL_NULL(); break; } xmlXPathFreeObject(xpathobjp); }