void phalcon_get_uri(zval *return_value, zval *path) { int i, found = 0, mark = 0; char *cursor, *str, ch; if (Z_TYPE_P(path) != IS_STRING) { RETURN_EMPTY_STRING(); } if (Z_STRLEN_P(path) > 0) { cursor = Z_STRVAL_P(path) + Z_STRLEN_P(path) - 1; for (i = Z_STRLEN_P(path); i > 0; i--) { ch = *cursor; if (ch == '/' || ch == '\\') { found++; if (found == 1) { mark = i - 1; } else { str = emalloc(mark - i + 1); memcpy(str, Z_STRVAL_P(path) + i, mark - i); str[mark - i] = '\0'; ZVAL_STRINGL(return_value, str, mark - i, 0); return; } } cursor--; } } RETURN_EMPTY_STRING(); }
/** * Gets HTTP header from request data * * @param string $header * @return string */ PHP_METHOD(Phalcon_Http_Request, getHeader){ zval *header, *_SERVER, *server_value = NULL, *key; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &header) == FAILURE) { RETURN_MM_NULL(); } phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); if (phalcon_array_isset(_SERVER, header)) { PHALCON_OBS_VAR(server_value); phalcon_array_fetch(&server_value, _SERVER, header, PH_NOISY_CC); RETURN_CCTOR(server_value); } else { PHALCON_INIT_VAR(key); PHALCON_CONCAT_SV(key, "HTTP_", header); if (phalcon_array_isset(_SERVER, key)) { PHALCON_OBS_NVAR(server_value); phalcon_array_fetch(&server_value, _SERVER, key, PH_NOISY_CC); RETURN_CCTOR(server_value); } } PHALCON_MM_RESTORE(); RETURN_EMPTY_STRING(); }
/* {{{ proto string json_encode(mixed data [, int options[, int depth]]) Returns the JSON representation of a value */ static PHP_FUNCTION(json_encode) { zval *parameter; php_json_encoder encoder; smart_str buf = {0}; zend_long options = 0; zend_long depth = PHP_JSON_PARSER_DEFAULT_DEPTH; ZEND_PARSE_PARAMETERS_START(1, 3) Z_PARAM_ZVAL_DEREF(parameter) Z_PARAM_OPTIONAL Z_PARAM_LONG(options) Z_PARAM_LONG(depth) ZEND_PARSE_PARAMETERS_END(); php_json_encode_init(&encoder); encoder.max_depth = (int)depth; encoder.error_code = PHP_JSON_ERROR_NONE; php_json_encode_zval(&buf, parameter, (int)options, &encoder); JSON_G(error_code) = encoder.error_code; if (encoder.error_code != PHP_JSON_ERROR_NONE && !(options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR)) { smart_str_free(&buf); RETURN_FALSE; } smart_str_0(&buf); /* copy? */ if (buf.s) { RETURN_NEW_STR(buf.s); } RETURN_EMPTY_STRING(); }
/* {{{ 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); } }
/* {{{ proto string json_encode(mixed data [, int options[, int depth]]) Returns the JSON representation of a value */ static PHP_FUNCTION(json_encode) { zval *parameter; php_json_encoder encoder; smart_str buf = {0}; zend_long options = 0; zend_long depth = PHP_JSON_PARSER_DEFAULT_DEPTH; if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|ll", ¶meter, &options, &depth) == FAILURE) { return; } php_json_encode_init(&encoder); encoder.max_depth = (int)depth; encoder.error_code = PHP_JSON_ERROR_NONE; php_json_encode_zval(&buf, parameter, (int)options, &encoder); JSON_G(error_code) = encoder.error_code; if (encoder.error_code != PHP_JSON_ERROR_NONE && !(options & PHP_JSON_PARTIAL_OUTPUT_ON_ERROR)) { smart_str_free(&buf); RETURN_FALSE; } smart_str_0(&buf); /* copy? */ if (buf.s) { RETURN_NEW_STR(buf.s); } RETURN_EMPTY_STRING(); }
/** * Generates the SQL to describe the table creation options * * @param string $table * @param string $schema * @return string */ PHP_METHOD(Phalcon_Db_Dialect_Oracle, tableOptions){ zval *table, *schema = NULL; phalcon_fetch_params(0, 1, 1, &table, &schema); RETURN_EMPTY_STRING(); }
/** * Gets HTTP method which request has been made * * @return string */ PHP_METHOD(Phalcon_Http_Request, getMethod){ const char *method = phalcon_http_request_getmethod_helper(); if (method) { RETURN_STRING(method); } RETURN_EMPTY_STRING(); }
ZEND_METHOD(hprose_bytes_io, getc) { HPROSE_THIS(bytes_io); if (HB_INITED_P(_this) && (HB_POS_P(_this) < HB_LEN_P(_this))) { #if PHP_MAJOR_VERSION < 7 RETURN_STRINGL_0(hprose_bytes_io_read(_this, 1), 1); #else RETURN_STR(hprose_bytes_io_read(_this, 1)); #endif } RETURN_EMPTY_STRING(); }
/** * Gets HTTP user agent used to made the request * * @return string */ PHP_METHOD(Phalcon_Http_Request, getUserAgent){ zval *server, user_agent = {}; server = phalcon_get_global_str(SL("_SERVER")); if (phalcon_array_isset_fetch_str(&user_agent, server, SL("HTTP_USER_AGENT"))) { RETURN_CTORW(&user_agent); } RETURN_EMPTY_STRING(); }
/** * Gets HTTP URI which request has been made * * @return string */ PHP_METHOD(Phalcon_Http_Request, getURI){ zval *value, *_SERVER, key = {}; PHALCON_STR(&key, "REQUEST_URI"); _SERVER = phalcon_get_global_str(SL("_SERVER")); value = (Z_TYPE_P(_SERVER) == IS_ARRAY) ? phalcon_hash_get(Z_ARRVAL_P(_SERVER), &key, BP_VAR_UNSET) : NULL; if (value && Z_TYPE_P(value) == IS_STRING) { RETURN_ZVAL(value, 1, 0); } RETURN_EMPTY_STRING(); }
/** * Gets query string which request has been made * * @return string */ PHP_METHOD(Phalcon_Http_Request, getQueryString){ zval *value, *_SERVER, key = {}; PHALCON_STR(&key, "QUERY_STRING"); _SERVER = phalcon_get_global_str(SS("_SERVER") TSRMLS_CC); value = (Z_TYPE_P(_SERVER) == IS_ARRAY) ? phalcon_hash_get(Z_ARRVAL_P(_SERVER), &key, BP_VAR_UNSET) : NULL; if (value && Z_TYPE_P(value) == IS_STRING) { RETURN_ZVAL(value, 1, 0); } RETURN_EMPTY_STRING(); }
/** * Replaces directory separators by the virtual separator */ void zephir_prepare_virtual_path(zval *return_value, zval *path, zval *virtual_separator) { unsigned int i; unsigned char ch; smart_str virtual_str = {0}; if (Z_TYPE_P(path) != IS_STRING || Z_TYPE_P(virtual_separator) != IS_STRING) { if (Z_TYPE_P(path) == IS_STRING) { RETURN_STR(zval_get_string(path)); } else { RETURN_EMPTY_STRING(); } return; } for (i = 0; i < Z_STRLEN_P(path); i++) { ch = Z_STRVAL_P(path)[i]; if (ch == '\0') { break; } if (ch == '/' || ch == '\\' || ch == ':') { smart_str_appendl(&virtual_str, Z_STRVAL_P(virtual_separator), Z_STRLEN_P(virtual_separator)); } else { smart_str_appendc(&virtual_str, tolower(ch)); } } smart_str_0(&virtual_str); if (virtual_str.s) { RETURN_STR(virtual_str.s); } else { RETURN_EMPTY_STRING(); } }
/** * Generates the SQL to describe the table creation options * * @param string $table * @param string $schema * @return string */ PHP_METHOD(Phalcon_Db_Dialect_Oracle, tableOptions){ zval *table, *schema = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &table, &schema); if (!schema) { PHALCON_INIT_VAR(schema); } PHALCON_MM_RESTORE(); RETURN_EMPTY_STRING(); }
/** * Gets HTTP header from request data * * @param string $header * @return string */ PHP_METHOD(Phalcon_Http_Request, getHeader) { zval *header, *_SERVER, key = {}; phalcon_fetch_params(0, 1, 0, &header); _SERVER = phalcon_get_global_str(SL("_SERVER")); if (!phalcon_array_isset_fetch(return_value, _SERVER, header, 0)) { PHALCON_CONCAT_SV(&key, "HTTP_", header); if (phalcon_array_isset_fetch(return_value, _SERVER, &key, 0)) { return; } } RETURN_EMPTY_STRING(); }
/** * Returns an option * * @param string $option * @return mixed */ PHP_METHOD(Phalcon_Mvc_Model_Validator, getOption){ zval *option, *options, *value; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &option); PHALCON_OBS_VAR(options); phalcon_read_property_this(&options, this_ptr, SL("_options"), PH_NOISY_CC); if (phalcon_array_isset(options, option)) { PHALCON_OBS_VAR(value); phalcon_array_fetch(&value, options, option, PH_NOISY_CC); RETURN_CCTOR(value); } PHALCON_MM_RESTORE(); RETURN_EMPTY_STRING(); }
/** * Filter identifiers string like variables or database columns/tables */ void phalcon_filter_identifier(zval *return_value, zval *param){ int i; char ch; zval copy = {}; smart_str filtered_str = {0}; int use_copy = 0; if (Z_TYPE_P(param) != IS_STRING) { use_copy = zend_make_printable_zval(param, ©); if (use_copy) { param = © } } for (i = 0; i < Z_STRLEN_P(param); i++) { ch = Z_STRVAL_P(param)[i]; if (ch == '\0') { break; } if (isalnum(ch) || ch == '_') { smart_str_appendc(&filtered_str, ch); } } if (use_copy) { zval_ptr_dtor(param); } smart_str_0(&filtered_str); if (filtered_str.s) { RETURN_NEW_STR(filtered_str.s); } else { smart_str_free(&filtered_str); RETURN_EMPTY_STRING(); } }
/** * Filter identifiers string like variables or database columns/tables */ void zephir_filter_identifier(zval *return_value, zval *param){ unsigned int i; unsigned char ch; zval copy; smart_str filtered_str = {0}; int use_copy = 0; if (Z_TYPE_P(param) != IS_STRING) { zend_make_printable_zval(param, ©, &use_copy); if (use_copy) { param = © } } for (i = 0; i < Z_STRLEN_P(param); i++) { ch = Z_STRVAL_P(param)[i]; if (ch == '\0') { break; } if (isalnum(ch) || ch == '_') { smart_str_appendc(&filtered_str, ch); } } if (use_copy) { zval_dtor(param); } smart_str_0(&filtered_str); if (filtered_str.c) { RETURN_STRINGL(filtered_str.c, filtered_str.len, 0); } else { RETURN_EMPTY_STRING(); } }
/** * Gets HTTP raw request body * * @return string */ PHP_METHOD(Phalcon_Http_Request, getRawBody){ zval *raw; if (SG(request_info).raw_post_data) { RETURN_STRINGL(SG(request_info).raw_post_data, SG(request_info).raw_post_data_length, 1); } phalcon_read_property_this(&raw, getThis(), SL("_rawBody"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(raw) == IS_STRING) { RETURN_ZVAL(raw, 1, 1); } else if (sapi_module.read_post) { int read_bytes; char *buf = emalloc(8192); smart_str raw_data = { NULL, 0, 0 }; while ((read_bytes = sapi_module.read_post(buf, 8192 TSRMLS_CC)) > 0) { smart_str_appendl(&raw_data, buf, read_bytes); SG(read_post_bytes) += read_bytes; } efree(buf); if (raw_data.c) { smart_str_0(&raw_data); RETVAL_STRINGL(raw_data.c, raw_data.len, 0); } else { RETVAL_EMPTY_STRING(); } phalcon_update_property_this(getThis(), SL("_rawBody"), return_value TSRMLS_CC); } else { RETURN_EMPTY_STRING(); } }
/* {{{ proto Crypto\Base64::decodeFinish() Decodes characters that left in the encoding context */ PHP_CRYPTO_METHOD(Base64, decodeFinish) { char buff[PHP_CRYPTO_BASE64_DECODING_SIZE_MIN]; int final_len; PHPC_THIS_DECLARE(crypto_base64); if (zend_parse_parameters_none() == FAILURE) { return; } PHPC_THIS_FETCH(crypto_base64); if (PHPC_THIS->status != PHP_CRYPTO_BASE64_STATUS_DECODE) { php_crypto_error(PHP_CRYPTO_ERROR_ARGS(Base64, DECODE_FINISH_FORBIDDEN)); RETURN_FALSE; } php_crypto_base64_decode_finish(PHPC_THIS->ctx, buff, &final_len); if (final_len == 0) { RETURN_EMPTY_STRING(); } buff[final_len] = 0; PHPC_CSTRL_RETURN(buff, final_len); }
/* {{{ proto Crypto\Base64::encodeFinish() Encodes characters that left in the encoding context */ PHP_CRYPTO_METHOD(Base64, encodeFinish) { char out[PHP_CRYPTO_BASE64_ENCODING_SIZE_MIN+1]; int out_len; PHPC_THIS_DECLARE(crypto_base64); if (zend_parse_parameters_none() == FAILURE) { return; } PHPC_THIS_FETCH(crypto_base64); if (PHPC_THIS->status != PHP_CRYPTO_BASE64_STATUS_ENCODE) { php_crypto_error(PHP_CRYPTO_ERROR_ARGS(Base64, ENCODE_FINISH_FORBIDDEN)); RETURN_FALSE; } php_crypto_base64_encode_finish(PHPC_THIS->ctx, out, &out_len); if (out_len == 0) { RETURN_EMPTY_STRING(); } out[out_len] = '\0'; PHPC_CSTRL_RETURN(out, out_len); }
/** * Gets HTTP raw request body * * @return string */ PHP_METHOD(Phalcon_Http_Request, getRawBody){ if (SG(request_info).raw_post_data) { RETURN_STRINGL(SG(request_info).raw_post_data, SG(request_info).raw_post_data_length, 1); } if (sapi_module.read_post) { int read_bytes; char *buf = emalloc(8192); smart_str raw_data = { NULL, 0, 0 }; while ((read_bytes = sapi_module.read_post(buf, 8192 TSRMLS_CC)) > 0) { smart_str_appendl(&raw_data, buf, read_bytes); SG(read_post_bytes) += read_bytes; } efree(buf); if (raw_data.c) { RETURN_STRINGL(raw_data.c, raw_data.len, 0); } } RETURN_EMPTY_STRING(); }
/** * Perform escaping of non-alphanumeric characters to different formats */ void zephir_escape_multi(zval *return_value, zval *param, const char *escape_char, unsigned int escape_length, char escape_extra, int use_whitelist) { unsigned int i; zval copy; smart_str escaped_str = {0}; char machine_little_endian, *hex; int big_endian_long_map[4]; int use_copy = 0, machine_endian_check = 1; int issigned = 0; long value; if (Z_TYPE_P(param) != IS_STRING) { use_copy = zend_make_printable_zval(param, ©); if (use_copy) { param = © } } if (Z_STRLEN_P(param) <= 0) { RETURN_FALSE; } /** * This is how the big_ending_long_map is calculated as in 'pack' */ machine_little_endian = ((char *) &machine_endian_check)[0]; if (machine_little_endian) { big_endian_long_map[0] = 3; big_endian_long_map[1] = 2; big_endian_long_map[2] = 1; big_endian_long_map[3] = 0; } else { int size = sizeof(Z_LVAL_P(param)); big_endian_long_map[0] = size - 4; big_endian_long_map[1] = size - 3; big_endian_long_map[2] = size - 2; big_endian_long_map[3] = size - 1; } /** * The input must be a valid UTF-32 string */ if ((Z_STRLEN_P(param) % 4) != 0) { RETURN_FALSE; } for (i = 0; i < Z_STRLEN_P(param); i += 4) { issigned = Z_STRVAL_P(param)[i] & 0x80; value = 0; if (sizeof(long) > 4 && issigned) { value = ~INT_MAX; } value |= zephir_unpack(&Z_STRVAL_P(param)[i], 4, issigned, big_endian_long_map); if (sizeof(long) > 4) { value = (unsigned int) value; } /** * CSS 2.1 section 4.1.3: "It is undefined in CSS 2.1 what happens if a * style sheet does contain a character with Unicode codepoint zero." */ if (value == '\0') { RETURN_FALSE; } /** * Alphanumeric characters are not escaped */ if (value < 256 && isalnum(value)) { smart_str_appendc(&escaped_str, (unsigned char) value); continue; } /** * Chararters in the whitelist are left as they are */ if (use_whitelist) { switch (value) { case ' ': case '/': case '*': case '+': case '-': case '\t': case '\n': case '^': case '$': case '!': case '?': case '\\': case '#': case '}': case '{': case ')': case '(': case ']': case '[': case '.': case ',': case ':': case ';': case '_': case '|': smart_str_appendc(&escaped_str, (unsigned char) value); continue; } } /** * Convert character to hexadecimal */ hex = zephir_longtohex(value); /** * Append the escaped character */ smart_str_appendl(&escaped_str, escape_char, escape_length); smart_str_appendl(&escaped_str, hex, strlen(hex)); if (escape_extra != '\0') { smart_str_appendc(&escaped_str, escape_extra); } efree(hex); } if (use_copy) { zval_dtor(param); } smart_str_0(&escaped_str); if (escaped_str.s) { RETURN_STR(escaped_str.s); } else { RETURN_EMPTY_STRING(); } }
/** {{{ public ZeActiveString::toString($separator) */ PHP_METHOD(ze_activestring, toString) { zval * self = NULL; zval * items = NULL; zval * actives = NULL; char * sep = NULL; int sep_len = 0; smart_str sstr = {NULL, 0, 0}; HashTable * items_table = NULL; HashPosition items_pointer = NULL; HashTable * actives_table = NULL; char * key = NULL; uint key_len = 0; ulong idx = 0; zval ** val = NULL; char * str = NULL; int str_len = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s" , &sep, &sep_len ) == FAILURE) { WRONG_PARAM_COUNT; } self = getThis(); items = zend_read_property(ze_activestring_ce, self, ZEND_STRL(ZE_ITEMS) , 0 TSRMLS_CC); actives = zend_read_property(ze_activestring_ce, self, ZEND_STRL(ZE_ACTIVES), 0 TSRMLS_CC); do { if (!items || Z_TYPE_P(items) != IS_ARRAY) { ZE_PTR_DTOR(items); ze_error(E_ERROR TSRMLS_CC, "recorder.toString.items.not_array"); break; } if (!actives || Z_TYPE_P(actives) != IS_ARRAY) { ZE_PTR_DTOR(actives); ze_error(E_ERROR TSRMLS_CC, "recorder.toString.actives.not_array"); break; } items_table = Z_ARRVAL_P(items); actives_table = Z_ARRVAL_P(actives); for (zend_hash_internal_pointer_reset_ex(items_table, &items_pointer); zend_hash_get_current_key_ex(items_table, &key, &key_len, &idx, 0, &items_pointer) == HASH_KEY_IS_STRING; zend_hash_move_forward_ex(items_table, &items_pointer)) { if (!key || !key_len) { continue; } if (zend_hash_exists(actives_table, key, key_len )) { if (zend_hash_get_current_data_ex(items_table , (void**) &val, &items_pointer) == SUCCESS) { smart_str_appendl(&sstr, Z_STRVAL_PP(val), Z_STRLEN_PP(val)); if (sep_len) { smart_str_appendl(&sstr, sep, sep_len); } } } } smart_str_0(&sstr); } while(0); if (sstr.len) { str_len = sstr.len - sep_len; spprintf(&str, str_len, "%s", sstr.c); smart_str_free(&sstr); RETURN_STRING(str , 0); }else{ smart_str_free(&sstr); RETURN_EMPTY_STRING(); } }