Exemple #1
0
SKYRAY_METHOD(HttpRequest, setUri)
{
    zend_string *uri;
    int i;

    if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &uri) ==  FAILURE) {
        return;
    }

    skyray_http_request_t *intern = skyray_http_request_from_obj(Z_OBJ_P(getThis()));

    zval_dtor(&intern->uri);
    ZVAL_STR(&intern->uri, uri);
    zval_addref_p(&intern->uri);

    RETURN_ZVAL(getThis(), 1, 0);
}
Exemple #2
0
void yee_behavior_attach(zval *self, zval *owner) {
	zend_class_entry *ce = Z_OBJCE_P(self);
	zval *events = NULL, **handler_ptr;
	char *event;
	int event_size;
	
	zend_update_property(ce, self, ZEND_STRL("owner"), owner);
	
	zend_call_method(&self, ce, NULL, ZEND_STRL("events"), &events, 0, NULL, NULL);
	
	if (events && Z_TYPE_P(events) == IS_ARRAY) {
		HashTable *ht = Z_ARRVAL_P(events);
		zend_hash_internal_pointer_reset(ht);
		while(zend_hash_has_more_elements(ht) == SUCCESS) {
			zend_hash_get_current_key_ex(ht, &event, &event_size, NULL, 0, NULL);
			zend_hash_get_current_data(ht, (void **)&handler_ptr);
			
			zval *zv_event, *zv_handler;
			
			MAKE_STD_ZVAL(zv_event);
			ZVAL_STRINGL(zv_event, event, event_size - 1, 0);
			
			if (Z_TYPE_PP(handler_ptr) == IS_STRING) {
				MAKE_STD_ZVAL(zv_handler);
				array_init(zv_handler);
				add_next_index_zval(zv_handler, self);
				add_next_index_zval(zv_handler, *handler_ptr);

				zval_addref_p(self);
			}else {
				zv_handler = *handler_ptr;
			}
			
			zend_call_method(&owner, Z_OBJCE_P(owner), NULL, ZEND_STRL("on"), NULL, 2, zv_event, zv_handler);
			
			efree(zv_event);
			if (zv_handler != *handler_ptr) {
				zval_ptr_dtor(&zv_handler);
			}
			zend_hash_move_forward(ht);
		}
		
	}
	zval_ptr_dtor(&events);
}
/* {{{ proto void Riak\MapReduce\Input\KeyDataListInput->add(string|RiakBucket $bucket, string|RiakObject $object, $data)
Add a bucket/key/data set to input */
PHP_METHOD(Riak_MapReduce_Input_KeyDataListInput, add)
{
    zval *zbucket, *zkey, *zdata, *zarr, *zlist;
    char *bucket, *key;
    int bucketlen, keylen;
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &zbucket, &zkey, &zdata) == FAILURE) {
        return;
    }
    bucket = NULL;
    bucketlen = 0;
    if (Z_TYPE_P(zbucket) == IS_STRING) {
        bucket = Z_STRVAL_P(zbucket);
        bucketlen = Z_STRLEN_P(zbucket);
    } else if (Z_TYPE_P(zbucket) == IS_OBJECT) {
        riak_name_from_bucket(zbucket, &bucket, &bucketlen TSRMLS_CC);
    }
    if (Z_TYPE_P(zkey) == IS_STRING) {
        key = Z_STRVAL_P(zkey);
        keylen = Z_STRLEN_P(zkey);
    } else if (Z_TYPE_P(zkey) == IS_OBJECT) {
        riak_key_from_object(zkey, &key, &keylen TSRMLS_CC);
    }
    if (bucket != NULL && bucketlen > 0 && key != NULL && keylen > 0) {
        MAKE_STD_ZVAL(zarr);
        array_init(zarr);
        add_next_index_stringl(zarr, bucket, bucketlen, 1);
        add_next_index_stringl(zarr, key, keylen, 1);
        zval_addref_p(zdata);
        add_next_index_zval(zarr, zdata);
        zlist = zend_read_property(riak_mrinput_keydatalist_ce, getThis(), "inputList", sizeof("inputList")-1, 1 TSRMLS_CC);
        add_next_index_zval(zlist, zarr);
    } else {
        zend_throw_exception(riak_badarguments_exception_ce, "Key or bucketname missing", 5001 TSRMLS_CC);
    }
    RIAK_RETURN_THIS
}
Exemple #4
0
/* {{{ proto array Riak\MapReduce\Phase\MapPhase->toArray()
Convert this phase into an array */
PHP_METHOD(Riak_MapReduce_Phase_MapPhase, toArray)
{
    zval *zarray, *zfuncarray, *zfunc, *zarg, zname;
    zend_bool keep;
    MAKE_STD_ZVAL(zarray);
    array_init(zarray);

    MAKE_STD_ZVAL(zfuncarray);
    zfunc = zend_read_property(riak_mr_mapphase_ce, getThis(), "function", sizeof("function")-1, 1 TSRMLS_CC);
    ZVAL_STRING(&zname, "toArray", 0);
    call_user_function(NULL, &zfunc, &zname, zfuncarray, 0, NULL TSRMLS_CC);

    keep = Z_BVAL_P(zend_read_property(riak_mr_mapphase_ce, getThis(), "keep", sizeof("keep")-1, 1 TSRMLS_CC));
    if (keep) {
        add_assoc_bool_ex(zfuncarray, "keep", sizeof("keep"), 1);
    }
    add_assoc_zval_ex(zarray, "map", sizeof("map"), zfuncarray);
    zarg = zend_read_property(riak_mr_mapphase_ce, getThis(), "arg", sizeof("arg")-1, 1 TSRMLS_CC);
    if (Z_TYPE_P(zarg) != IS_NULL) {
        add_assoc_zval_ex(zarray, "arg", sizeof("arg"), zarg);
        zval_addref_p(zarg);
    }
    RETURN_ZVAL(zarray, 0, 1);
}
/* {{{ proto string|array Riak\MapReduce\Input\BucketInput->getValue()
Returns value to use in Mapreduce */
PHP_METHOD(Riak_MapReduce_Input_BucketInput, getValue)
{
    zval* zname, *zfilters, *zresult, *zindex;
    zname = zend_read_property(riak_mrinput_bucket_ce, getThis(), "name", sizeof("name")-1, 1 TSRMLS_CC);
    zfilters = zend_read_property(riak_mrinput_bucket_ce, getThis(), "keyFilters", sizeof("keyFilters")-1, 1 TSRMLS_CC);
    zindex = zend_read_property(riak_mrinput_bucket_ce, getThis(), "idxname", sizeof("idxname")-1, 1 TSRMLS_CC);

    if (Z_TYPE_P(zfilters) == IS_ARRAY || Z_TYPE_P(zindex) == IS_STRING) {
        MAKE_STD_ZVAL(zresult);
        array_init(zresult);
        zval_addref_p(zname);
        add_assoc_zval_ex(zresult, "bucket", sizeof("bucket"), zname);
        if (Z_TYPE_P(zindex) == IS_STRING) {
            zval *start, *end;
            start = zend_read_property(riak_mrinput_bucket_ce, getThis(), "idxstart", sizeof("idxstart")-1, 1 TSRMLS_CC);
            end = zend_read_property(riak_mrinput_bucket_ce, getThis(), "idxend", sizeof("idxend")-1, 1 TSRMLS_CC);

            zval_addref_p(zindex);
            add_assoc_zval_ex(zresult, "index", sizeof("index"), zindex);
            if (Z_TYPE_P(end) != IS_STRING) {
                zval_addref_p(start);
                add_assoc_zval_ex(zresult, "key", sizeof("key"), start);
            } else {
                zval_addref_p(start);
                zval_addref_p(end);
                add_assoc_zval_ex(zresult, "start", sizeof("start"), start);
                add_assoc_zval_ex(zresult, "end", sizeof("end"), end);
            }
        }
        if (Z_TYPE_P(zfilters) == IS_ARRAY) {
            zval_addref_p(zfilters);
            add_assoc_zval_ex(zresult, "key_filters", sizeof("key_filters"), zfilters);
        }
        RETURN_ZVAL(zresult, 0, 1);
    } else {
        RETURN_ZVAL(zname, 1, 0);
    }
}
Exemple #6
0
	KPHPObject::KPHPObject(zval* object) :
		object(object)
	{
		zval_addref_p(object);
	}
	KPHPObject::KPHPObject(zval* object) :
		KObject("PHP.KPHPObject"),
		object(object)
	{
		zval_addref_p(object);
	}
Exemple #8
0
static void php_intl_idn_to_46(INTERNAL_FUNCTION_PARAMETERS,
		const char *domain, int32_t domain_len, uint32_t option, int mode, zval *idna_info)
{
	UErrorCode	  status = U_ZERO_ERROR;
	UIDNA		  *uts46;
	int32_t		  len;
	int32_t		  buffer_capac = 255; /* no domain name may exceed this */
	zend_string	  *buffer = zend_string_alloc(buffer_capac, 0);
	UIDNAInfo	  info = UIDNA_INFO_INITIALIZER;
	int			  buffer_used = 0;

	uts46 = uidna_openUTS46(option, &status);
	if (php_intl_idn_check_status(status, "failed to open UIDNA instance",
			mode) == FAILURE) {
		zend_string_free(buffer);
		RETURN_FALSE;
	}

	if (mode == INTL_IDN_TO_ASCII) {
		len = uidna_nameToASCII_UTF8(uts46, domain, domain_len,
				ZSTR_VAL(buffer), buffer_capac, &info, &status);
	} else {
		len = uidna_nameToUnicodeUTF8(uts46, domain, domain_len,
				ZSTR_VAL(buffer), buffer_capac, &info, &status);
	}
	if (php_intl_idn_check_status(status, "failed to convert name",
			mode) == FAILURE) {
		uidna_close(uts46);
		zend_string_free(buffer);
		RETURN_FALSE;
	}
	if (len >= 255) {
		php_error_docref(NULL, E_ERROR, "ICU returned an unexpected length");
	}

	ZSTR_VAL(buffer)[len] = '\0';
	ZSTR_LEN(buffer) = len;

	if (info.errors == 0) {
		RETVAL_STR(buffer);
		buffer_used = 1;
	} else {
		RETVAL_FALSE;
	}

	if (idna_info) {
		if (buffer_used) { /* used in return_value then */
			zval_addref_p(return_value);
			add_assoc_zval_ex(idna_info, "result", sizeof("result")-1, return_value);
		} else {
			zval zv;
			ZVAL_NEW_STR(&zv, buffer);
			buffer_used = 1;
			add_assoc_zval_ex(idna_info, "result", sizeof("result")-1, &zv);
		}
		add_assoc_bool_ex(idna_info, "isTransitionalDifferent",
				sizeof("isTransitionalDifferent")-1, info.isTransitionalDifferent);
		add_assoc_long_ex(idna_info, "errors", sizeof("errors")-1, (zend_long)info.errors);
	}

	if (!buffer_used) {
		zend_string_free(buffer);
	}

	uidna_close(uts46);
}