示例#1
0
文件: hash.c 项目: 31H0B1eV/php-src
static void php_hash_do_hash(INTERNAL_FUNCTION_PARAMETERS, int isfilename, zend_bool raw_output_default) /* {{{ */
{
	char *algo, *data, *digest;
	int algo_len, data_len;
	zend_bool raw_output = raw_output_default;
	const php_hash_ops *ops;
	void *context;
	php_stream *stream = NULL;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &algo, &algo_len, &data, &data_len, &raw_output) == FAILURE) {
		return;
	}

	ops = php_hash_fetch_ops(algo, algo_len);
	if (!ops) {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown hashing algorithm: %s", algo);
		RETURN_FALSE;
	}
	if (isfilename) {
		if (CHECK_NULL_PATH(data, data_len)) {
			RETURN_FALSE;
		}
		stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, DEFAULT_CONTEXT);
		if (!stream) {
			/* Stream will report errors opening file */
			RETURN_FALSE;
		}
	}

	context = emalloc(ops->context_size);
	ops->hash_init(context);

	if (isfilename) {
		char buf[1024];
		int n;

		while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
			ops->hash_update(context, (unsigned char *) buf, n);
		}
		php_stream_close(stream);
	} else {
		ops->hash_update(context, (unsigned char *) data, data_len);
	}

	digest = emalloc(ops->digest_size + 1);
	ops->hash_final((unsigned char *) digest, context);
	efree(context);

	if (raw_output) {
		digest[ops->digest_size] = 0;
		RETURN_STRINGL(digest, ops->digest_size, 0);
	} else {
		char *hex_digest = safe_emalloc(ops->digest_size, 2, 1);

		php_hash_bin2hex(hex_digest, (unsigned char *) digest, ops->digest_size);
		hex_digest[2 * ops->digest_size] = 0;
		efree(digest);
		RETURN_STRINGL(hex_digest, 2 * ops->digest_size, 0);
	}
}
/* ArchiveReader::getCurrentEntryData {{{
 *
*/
ZEND_METHOD(ArchiveReader, getCurrentEntryData) 
{
	zval *this = getThis();
	archive_file_t *arch;
	int result, error_num;
	size_t len;
	off_t offset;
	const char *error_string;
	char *buf;
    zend_error_handling error_handling;
	
    zend_replace_error_handling(EH_THROW, ce_ArchiveException, &error_handling TSRMLS_CC);

	if (!_archive_get_fd(this, &arch TSRMLS_CC)) {
        zend_restore_error_handling(&error_handling TSRMLS_CC);
		return;
	}

	if (arch->current_entry == NULL) {
		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Current archive entry is not available");
        zend_restore_error_handling(&error_handling TSRMLS_CC);
		return;
	}
	
	if (arch->current_entry->data) {
        zend_restore_error_handling(&error_handling TSRMLS_CC);
		RETURN_STRINGL(arch->current_entry->data, arch->current_entry->data_len, 1);
	}
	
	while ((result = archive_read_data_block(arch->arch, (const void **)&buf, &len, &offset)) == ARCHIVE_OK) {
		arch->current_entry->data = erealloc(arch->current_entry->data, arch->current_entry->data_len + len + 1);
		memcpy(arch->current_entry->data + arch->current_entry->data_len, buf, len);
		arch->current_entry->data_len += len;
	}
	
	if (result && result != ARCHIVE_EOF) {
		error_num = archive_errno(arch->arch);
		error_string = archive_error_string(arch->arch);
		
		if (error_num && error_string) {
			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to read entry data: error #%d, %s", error_num, error_string);
		}
		else {
			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to read entry data: unknown error %d", result);
		}
        zend_restore_error_handling(&error_handling TSRMLS_CC);
		return;
	}
	
    zend_restore_error_handling(&error_handling TSRMLS_CC);
	RETURN_STRINGL(arch->current_entry->data, arch->current_entry->data_len, 1);
}
示例#3
0
文件: zlib.c 项目: Furgas/php-src
/* {{{ proto string zlib_get_coding_type(void)
   Returns the coding type used for output compression */
static PHP_FUNCTION(zlib_get_coding_type)
{
	if (zend_parse_parameters_none() == FAILURE) {
		return;
	}
	switch (ZLIBG(compression_coding)) {
		case PHP_ZLIB_ENCODING_GZIP:
			RETURN_STRINGL("gzip", sizeof("gzip") - 1);
		case PHP_ZLIB_ENCODING_DEFLATE:
			RETURN_STRINGL("deflate", sizeof("deflate") - 1);
		default:
			RETURN_FALSE;
	}
}
U_CFUNC PHP_FUNCTION(rbbi_get_binary_rules)
{
    BREAKITER_METHOD_INIT_VARS;
    object = getThis();

    if (zend_parse_parameters_none() == FAILURE) {
        intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
                       "rbbi_get_binary_rules: bad arguments", 0 TSRMLS_CC);
        RETURN_FALSE;
    }

    BREAKITER_METHOD_FETCH_OBJECT;

    uint32_t		rules_len;
    const uint8_t	*rules = fetch_rbbi(bio)->getBinaryRules(rules_len);

    if (rules_len > INT_MAX - 1) {
        intl_errors_set(BREAKITER_ERROR_P(bio), BREAKITER_ERROR_CODE(bio),
                        "rbbi_get_binary_rules: the rules are too large",
                        0 TSRMLS_CC);
        RETURN_FALSE;
    }

    char *ret_rules = static_cast<char*>(emalloc(rules_len + 1));
    memcpy(ret_rules, rules, rules_len);
    ret_rules[rules_len] = '\0';

    RETURN_STRINGL(ret_rules, rules_len, 0);
}
示例#5
0
PHP_METHOD(MTF, change_flag) {
	char *loginname = NULL;
	int loginname_len;
	char *flag = NULL;
	int flag_len;
	
	char *strg;
	int len;
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &loginname, &loginname_len, &flag, &flag_len) == FAILURE) {
		return;
	}
	zval *attrs, *obj;
	obj = getThis();
	attrs = zend_read_property(Z_OBJCE_P(obj), obj, "session", strlen("session"), 0 TSRMLS_CC);
	
    //php_var_dump(&attrs, 1 TSRMLS_CC);
	char *session = Z_STRVAL_P(attrs);
	
	char *xml = NULL;
	if(session){
		char *xmlpro = 	protocol_flag(session, loginname, flag);
		char *url;
		asprintf(&url, "%s/change_member_flag.ucs", INI_STR("mtf.url"));
		xml = conn(url, xmlpro);
		
		char *debug = NULL;
		asprintf(&debug, "%s?%s",url, xmlpro);
		zend_update_property_string(object, getThis(), "debug", strlen("debug"), debug TSRMLS_CC);
	}
	
	len = spprintf(&strg, 0, "%s", xml);
	RETURN_STRINGL(strg, len, 0);
}
示例#6
0
ONPHP_METHOD(Ternary, toString)
{
	zval *trinity = ONPHP_READ_PROPERTY(getThis(), "trinity");
	
	if (Z_TYPE_P(trinity) == IS_BOOL) {
		if (zval_is_true(trinity)) {
			RETURN_STRINGL("true", 4, 1);
		} else {
			RETURN_STRINGL("false", 5, 1);
		}
	} else if (Z_TYPE_P(trinity) == IS_NULL) {
		RETURN_STRINGL("null", 4, 1);
	}
	
	ONPHP_THROW(WrongStateException, NULL);
}
示例#7
0
U_CFUNC PHP_FUNCTION(intltz_get_id)
{
	TIMEZONE_METHOD_INIT_VARS;

	if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
			&object, TimeZone_ce_ptr) == FAILURE) {
		intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
			"intltz_get_id: bad arguments", 0 TSRMLS_CC);
		RETURN_FALSE;
	}

	TIMEZONE_METHOD_FETCH_OBJECT;

	UnicodeString id_us;
	to->utimezone->getID(id_us);

	char *id = NULL;
	int  id_len   = 0;

	intl_convert_utf16_to_utf8(&id, &id_len,
		id_us.getBuffer(), id_us.length(), TIMEZONE_ERROR_CODE_P(to));
	INTL_METHOD_CHECK_STATUS(to, "intltz_get_id: Could not convert id to UTF-8");

	RETURN_STRINGL(id, id_len, 0);
}
示例#8
0
PHP_METHOD(MTF, login) {
	char *url = INI_STR("mtf.url");
	char *user = NULL;
	int user_len;
	
	char *password = NULL;
	int password_len;
	
	int len;
	char *strg;
	
	if(ZEND_NUM_ARGS() == 0){
		user 	 = INI_STR("mtf.user");
		password = INI_STR("mtf.password");
	} else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &user, &user_len, &password, &password_len) == FAILURE) {
		return;
	}
	
	char *result = login(url, user, password);
	char *session = login_session_id(result);
	if(session){
		zend_update_property_string(object, getThis(), "session", strlen("session"), session TSRMLS_CC);
	}
	zend_update_property_string(object, getThis(), "debug", strlen("debug"), result TSRMLS_CC);
	len = spprintf(&strg, 0, "%s", result);
	RETURN_STRINGL(strg, len, 0);
}
示例#9
0
U_CFUNC PHP_FUNCTION(intltz_get_region)
{
	char	*str_id;
	size_t	 str_id_len;
	char	 outbuf[3];
	intl_error_reset(NULL);

	if (zend_parse_parameters(ZEND_NUM_ARGS(), "s",
			&str_id, &str_id_len) == FAILURE) {
		intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
			"intltz_get_region: bad arguments", 0);
		RETURN_FALSE;
	}

	UErrorCode status = UErrorCode();
	UnicodeString id;
	if (intl_stringFromChar(id, str_id, str_id_len, &status) == FAILURE) {
		intl_error_set(NULL, status,
			"intltz_get_region: could not convert time zone id to UTF-16", 0);
		RETURN_FALSE;
	}

	int32_t region_len = TimeZone::getRegion(id, outbuf, sizeof(outbuf), status);
	INTL_CHECK_STATUS(status, "intltz_get_region: Error obtaining region");

	RETURN_STRINGL(outbuf, region_len);
}
示例#10
0
文件: url.c 项目: 11mariom/cphalcon
void phalcon_raw_url_encode(zval *return_value, zval *url) {

	zval copy;
	char *escaped;
	int use_copy = 0, length;

	if (Z_TYPE_P(url) == IS_STRING) {
		zend_make_printable_zval(url, &copy, &use_copy);
		if (use_copy) {
			url = &copy;
		}
	}

	escaped = php_raw_url_encode(Z_STRVAL_P(url), Z_STRLEN_P(url), &length);

	if (use_copy) {
		zval_dtor(url);
	}

	if (escaped) {
		RETURN_STRINGL(escaped, length, 0);
	} else {
		RETURN_NULL();
	}
}
/* {{{ proto string MarkdownDocument::getToc() */
PHP_METHOD(markdowndoc, getToc)
{
	discount_object *dobj;
	char			*data	= NULL;
	int				status;

	if (zend_parse_parameters_none() == FAILURE) {
		RETURN_FALSE;
	}
	if ((dobj = markdowndoc_get_object(getThis(), 1 TSRMLS_CC)) == NULL) {
		RETURN_FALSE;
	}
	
	status = mkd_toc(dobj->markdoc, &data);
	if (status < 0) {
		/* no doc->ctx, shouldn't happen */
		zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC,
			"Call to library function mkd_toc() failed (should not happen!)");
		RETURN_FALSE;
	}
	/* status == 0 can indicate either empty string or no MKD_TOC, we
	 * must use data to disambiguate */
	if (data == NULL) {
		RETURN_FALSE; /* no MKD_TOC */
	}
	/* empty string included in general case */
	RETURN_STRINGL(data, status, 0);	
}
示例#12
0
PHP_METHOD(MTF, balance) {
	char *login = NULL;
	int login_len;

	char *url, *proto;
	char *strg;
	int len;
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &login, &login_len) == FAILURE) {
		return;
	}
	zval *attrs, *obj;
	obj = getThis();
	attrs = zend_read_property(Z_OBJCE_P(obj), obj, "session", strlen("session"), 0 TSRMLS_CC);
	char *session = Z_STRVAL_P(attrs);
	
	char *xml = NULL;
	if(session){
		asprintf(&url, "%s/check_balance.ucs",INI_STR("mtf.url"));
		asprintf(&proto, "sid=%s&loginname=%s", session, login);

		xml = conn(url, proto);
		
		char *debug = NULL;
		asprintf(&debug, "%s?%s",url, proto);
		zend_update_property_string(object, getThis(), "debug", strlen("debug"), debug TSRMLS_CC);
	}
	
	len = spprintf(&strg, 0, "%s", xml);
	RETURN_STRINGL(strg, len, 0);
}
static PHP_METHOD(php_midgard_reflection_method, getDocComment)
{
	reflection_object *intern;
	zend_function *fptr;
	RETVAL_FALSE;

	if (zend_parse_parameters_none() == FAILURE) 
		return;

	GET_REFLECTION_OBJECT_PTR(fptr);

	if (fptr->type == ZEND_USER_FUNCTION) {
#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 3
		RETURN_FALSE;
#endif
		if (fptr->op_array.doc_comment) {
			RETURN_STRINGL(fptr->op_array.doc_comment, fptr->op_array.doc_comment_len, 1);
		} else {
			RETURN_FALSE;
		}
	} else {
		zval *ref_class = zend_read_property(php_midgard_reflection_class_class, getThis(), "class", sizeof("class")-1, 0 TSRMLS_CC); \
		zval *ref_method = zend_read_property(php_midgard_reflection_class_class, getThis(), "name", sizeof("name")-1, 0 TSRMLS_CC); \

		if (!ref_class || !ref_method)
			RETURN_FALSE;

		const char *comment = php_midgard_docs_get_method_comment((const gchar *) Z_STRVAL_P(ref_class), (const gchar *) Z_STRVAL_P(ref_method));
		RETURN_STRING ((char *)comment, 1);
	}
}
示例#14
0
ONPHP_METHOD(ExtractPart, toDialectString)
{
	zval *dialect, *what, *from, *whatString, *fromString;
	smart_str string = {0};
	
	ONPHP_GET_ARGS("O", &dialect, onphp_ce_Dialect);
	
	what = ONPHP_READ_PROPERTY(getThis(), "what");
	from = ONPHP_READ_PROPERTY(getThis(), "from");
	
	ONPHP_CALL_METHOD_0(what, "tostring", &whatString);
	
	ONPHP_CALL_METHOD_1_NORET(from, "todialectstring", &fromString, dialect);
	
	if (EG(exception)) {
		ZVAL_FREE(whatString);
		return;
	}
	
	smart_str_appendl(&string, "EXTRACT(", 8);
	onphp_append_zval_to_smart_string(&string, whatString);
	smart_str_appendl(&string, " FROM ", 6);
	onphp_append_zval_to_smart_string(&string, fromString);
	smart_str_appendc(&string, ')');
	smart_str_0(&string);
	
	zval_ptr_dtor(&whatString);
	zval_ptr_dtor(&fromString);
	
	RETURN_STRINGL(string.c, string.len, 0);
}
示例#15
0
/** public function ION\HTTP\Message::getProtocolVersion() : string */
CLASS_METHOD(ION_HTTP_Message, getProtocolVersion) {
    ion_http_message * message = ION_THIS_OBJECT(ion_http_message);
    if(message->version) {
        RETURN_STR(zend_string_copy(message->version));
    } else {
        RETURN_STRINGL(ION_HTTP_VERSION_DEFAULT, sizeof(ION_HTTP_VERSION_DEFAULT) - 1);
    }
}
示例#16
0
文件: Blob.c 项目: moarty/php-driver
/* {{{ Cassandra\Blob::toBinaryString() */
PHP_METHOD(Blob, toBinaryString)
{
  cassandra_blob* blob = (cassandra_blob*) zend_object_store_get_object(getThis() TSRMLS_CC);
  char* bytes = (char *) emalloc(sizeof(char) * (blob->size + 1));
  memcpy(bytes, blob->data, blob->size);
  bytes[blob->size] = '\0';

  RETURN_STRINGL(bytes, blob->size, 0);
}
示例#17
0
/* {{{ Cassandra\Blob::bytes() */
PHP_METHOD(CassandraBlob, bytes)
{
  cassandra_blob* blob = (cassandra_blob*) zend_object_store_get_object(getThis() TSRMLS_CC);
  char* hex;
  int hex_len;
  php_cassandra_bytes_to_hex((const char *) blob->data, blob->size, &hex, &hex_len);

  RETURN_STRINGL(hex, hex_len, 0);
}
示例#18
0
ONPHP_METHOD(Joiner, toDialectString)
{
	zval
		*dialect,
		*from = ONPHP_READ_PROPERTY(getThis(), "from"),
		*table;
	zend_class_entry **cep;
	smart_str string = {0};
	unsigned int i = 0, count = zend_hash_num_elements(Z_ARRVAL_P(from));
	
	if (!count) {
		RETURN_NULL();
	} else {
		smart_str_appendl(&string, " FROM ", 6);
	}
	
	ONPHP_GET_ARGS("O", &dialect, onphp_ce_Dialect);
	
	ONPHP_FIND_FOREIGN_CLASS("SelectQuery", cep);
	
	for (i = 0; i < count; ++i) {
		zval *out;
		
		ONPHP_ARRAY_GET(from, i, table);
		
		if (i == 0) {
			/* nop */
		} else {
			if (ONPHP_INSTANCEOF(from, FromTable)) {
				zval *name;
				
				ONPHP_CALL_METHOD_0(table, "gettable", &name);
				
				if (instanceof_function(Z_OBJCE_P(table), *cep TSRMLS_CC)) {
					smart_str_appendl(&string, ", ", 2);
				} else {
					smart_str_appendc(&string, ' ');
				}
				
				zval_ptr_dtor(&name);
			} else {
				smart_str_appendc(&string, ' ');
			}
		}
		
		ONPHP_CALL_METHOD_1(table, "todialectstring", &out, dialect);
		
		onphp_append_zval_to_smart_string(&string, out);
		
		zval_ptr_dtor(&out);
	}
	
	smart_str_0(&string);
	
	RETURN_STRINGL(string.c, string.len, 0);
}
示例#19
0
文件: tidy.c 项目: CooCoooo/php-src
/* {{{ proto string tidy_get_error_buffer()
   Return warnings and errors which occurred parsing the specified document*/
static PHP_FUNCTION(tidy_get_error_buffer)
{
	TIDY_FETCH_OBJECT;

	if (obj->ptdoc->errbuf && obj->ptdoc->errbuf->bp) {
		RETURN_STRINGL((char*)obj->ptdoc->errbuf->bp, obj->ptdoc->errbuf->size-1);
	} else {
		RETURN_FALSE;
	}
}
/* {{{ proto string SolrResponse::getRawRequestHeaders(void)
   Returns the raw http request headers sent to the server. */
PHP_METHOD(SolrResponse, getRawRequestHeaders)
{
	zend_bool silent = 1;
	zval rv;
	zval *objptr = getThis();
	zval *prop = NULL;

	prop = solr_read_response_object_property(objptr, "http_raw_request_headers", silent, &rv);

	RETURN_STRINGL(Z_STRVAL_P(prop), Z_STRLEN_P(prop));
}
/* {{{ proto string SolrResponse::getHttpStatusMessage(void)
   Returns the http_status_message property. */
PHP_METHOD(SolrResponse, getHttpStatusMessage)
{
	zend_bool silent = 1;
	zval rv;
	zval *objptr = getThis();
	zval *http_status_message = NULL;

	http_status_message = solr_read_response_object_property(objptr, "http_status_message", silent, &rv);

	RETURN_STRINGL(Z_STRVAL_P(http_status_message), Z_STRLEN_P(http_status_message));
}
示例#22
0
文件: hylog.c 项目: lovelock/neolog
PHP_METHOD(Hylog, getBasePath)
{
	char *str;
	int len;

	len = spprintf(&str, 0, "%s", HYLOG_G(base_path));

	if (zend_parse_parameters_none() == FAILURE)
		return;

	RETURN_STRINGL(str, len);
}
示例#23
0
/* {{{ proto string Binary::getData()
    */
PHP_METHOD(Binary, getData)
{
    php_phongo_binary_t      *intern;


    intern = (php_phongo_binary_t *)zend_object_store_get_object(getThis() TSRMLS_CC);

    if (zend_parse_parameters_none() == FAILURE) {
        return;
    }

    RETURN_STRINGL(intern->data, intern->data_len, 1);
}
示例#24
0
ONPHP_METHOD(DBField, toDialectString)
{
	smart_str string = {0};
	zval *table, *field, *dialect, *cast, *quoted;
	
	ONPHP_GET_ARGS("O", &dialect, onphp_ce_Dialect);
	
	table = ONPHP_READ_PROPERTY(getThis(), "table");
	field = ONPHP_READ_PROPERTY(getThis(), "field");
	cast = ONPHP_READ_PROPERTY(getThis(), "cast");
	
	// either null or instance of DialectString
	if (Z_TYPE_P(table) == IS_OBJECT) {
		zval *tmp;
		
		ONPHP_CALL_METHOD_1(table, "todialectstring", &tmp, dialect);
		
		onphp_append_zval_to_smart_string(&string, tmp);
		zval_ptr_dtor(&tmp);
		smart_str_appendc(&string, '.');
	}
	
	ONPHP_CALL_METHOD_1(dialect, "quotefield", &quoted, field);
	
	onphp_append_zval_to_smart_string(&string, quoted);
	
	zval_ptr_dtor(&quoted);
	
	smart_str_0(&string);
	
	if (Z_STRLEN_P(cast)) {
		zval *tmp, *out;
		
		ALLOC_INIT_ZVAL(tmp);
		
		ZVAL_STRINGL(tmp, string.c, string.len, 1);
		
		ONPHP_CALL_METHOD_2_NORET(dialect, "tocasted", &out, tmp, cast);
		
		ZVAL_FREE(tmp);
		smart_str_free(&string);
		
		if (EG(exception)) {
			return;
		}
		
		RETURN_ZVAL(out, 1, 1);
	}
	
	RETURN_STRINGL(string.c, string.len, 0);
}
示例#25
0
/**
 * 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();
}
/* {{{ proto string SolrResponse::getDigestedResponse(void)
   Returns the serialized object string derived from the XML response. */
PHP_METHOD(SolrResponse, getDigestedResponse)
{
	zend_bool silent = 0;
	zval rv;
	zval *objptr = getThis();
	zval *prop = NULL;

	prop = solr_read_response_object_property(objptr, "http_digested_response", silent, &rv);

	if (Z_STRLEN_P(prop))
	{
		RETURN_STRINGL(Z_STRVAL_P(prop), Z_STRLEN_P(prop));
	}

	RETURN_NULL();
}
示例#27
0
/* {{{ proto string ProtocolBuffersEnum::getName(long $value)
*/
PHP_METHOD(protocolbuffers_enum, getName)
{
#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 3)
	zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "ProtocolBuffersEnum::getName can't work under PHP 5.3. please consider upgrading your PHP");
	return;
#else
	long value;
	zval *result;

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
		"l", &value) == FAILURE) {
		return;
	}

	if (zend_call_method_with_0_params(NULL, EG(called_scope), NULL, "getenumdescriptor", &result)) {
		zval *values, **entry;
		HashPosition pos;

		if (!instanceof_function_ex(Z_OBJCE_P(result), php_protocol_buffers_enum_descriptor_class_entry, 0 TSRMLS_CC)) {
			zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "ProtocolBuffersEnum::getEnumDescriptor returns unexpected value.");
			zval_ptr_dtor(&result);
			return;
		}

		php_protocolbuffers_read_protected_property(result, ZEND_STRS("values"), &values TSRMLS_CC);
		zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(values), &pos);
		while (zend_hash_get_current_data_ex(Z_ARRVAL_P(values), (void **)&entry, &pos) == SUCCESS) {
			if (Z_LVAL_PP(entry) == value) {
				char *key;
				uint key_len;
				ulong index;


				zend_hash_get_current_key_ex(Z_ARRVAL_P(values), &key, &key_len, &index, 0, &pos);
				RETURN_STRINGL(key, key_len, 1);
				break;
			}
			zend_hash_move_forward_ex(Z_ARRVAL_P(values), &pos);
		}
		zval_ptr_dtor(&result);
		RETVAL_FALSE;
	} else {
			zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "cannot call ProtocolBuffersEnum::getEnumDescriptor.");
			return;
	}
#endif
}
示例#28
0
ZEND_METHOD(Vedis, eval)
{
    char *cmd;
    int cmd_len;
    int rc;
    php_vedis_object_t *intern;
    vedis_value *result = NULL;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
                              &cmd, &cmd_len) == FAILURE) {
        return;
    }

    VEDIS_SELF(intern);

    if (vedis_exec(intern->vedis->store, cmd, cmd_len) != VEDIS_OK) {
        php_vedis_error(intern, E_WARNING TSRMLS_CC);
        RETURN_FALSE;
    }

    vedis_exec_result(intern->vedis->store, &result);
    if (!result) {
        php_vedis_error(intern, E_WARNING TSRMLS_CC);
        RETURN_FALSE;
    }

    if (vedis_value_is_array(result)) {
        vedis_value *entry;
        array_init(return_value);
        while ((entry = vedis_array_next_elem(result)) != 0) {
            if (vedis_value_is_null(entry)) {
                add_next_index_null(return_value);
            } else {
                int len = 0;
                const char *str = vedis_value_to_string(entry, &len);
                add_next_index_stringl(return_value, str, len, 1);
            }
        }
    } else if (vedis_value_is_int(result)) {
        RETURN_LONG(vedis_value_to_int64(result));
    } else {
        int len = 0;
        const char *str = vedis_value_to_string(result, &len);
        RETURN_STRINGL(str, len, 1);
    }
}
/* {{{ proto string SolrResponse::getRequestUrl(void)
   Returns the URL used for the request. */
PHP_METHOD(SolrResponse, getRequestUrl)
{
	zend_bool silent = 1;
	zval *objptr = getThis();
	zval *prop = NULL;

	if (!return_value_used) {

		php_error_docref(NULL TSRMLS_CC, E_NOTICE, SOLR_ERROR_4002_MSG);

		return;
	}

	prop = solr_read_response_object_property(objptr, "http_request_url", silent);

	RETURN_STRINGL(Z_STRVAL_P(prop), Z_STRLEN_P(prop), 1);
}
/* {{{ proto string SolrResponse::getHttpStatusMessage(void)
   Returns the http_status_message property. */
PHP_METHOD(SolrResponse, getHttpStatusMessage)
{
	zend_bool silent = 1;
	zval *objptr = getThis();
	zval *http_status_message = NULL;

	if (!return_value_used) {

		php_error_docref(NULL TSRMLS_CC, E_NOTICE, SOLR_ERROR_4002_MSG);

		return;
	}

	http_status_message = solr_read_response_object_property(objptr, "http_status_message", silent);

	RETURN_STRINGL(Z_STRVAL_P(http_status_message), Z_STRLEN_P(http_status_message), 1);
}