예제 #1
0
inline int wrapper_zend_hash_get_current_key(HashTable *ht, char **key, uint *idx, ulong *num) {
    zval str_key;
    ZVAL_STRING(&str_key, *key);
    int type = zend_hash_get_current_key(ht, &Z_STR(str_key), (zend_ulong*) num);
    *key = Z_STR(str_key)->val;
    return type;
}
예제 #2
0
void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf)
{
	php_conf_rec *d = base_conf, *e = new_conf, *n = NULL;
	php_dir_entry *pe;
	php_dir_entry *data;
	char *str;
	uint str_len;
	ulong num_index;

	n = create_php_config(p, "merge_php_config");
	zend_hash_copy(&n->config, &e->config, NULL, NULL, sizeof(php_dir_entry));

	phpapdebug((stderr, "Merge dir (%p)+(%p)=(%p)\n", base_conf, new_conf, n));
	for (zend_hash_internal_pointer_reset(&d->config);
			zend_hash_get_current_key(&d->config, &str, &str_len, 
				&num_index) == HASH_KEY_IS_STRING;
			zend_hash_move_forward(&d->config)) {
		pe = NULL;
		zend_hash_get_current_data(&d->config, (void **) &data);
		if ((pe = zend_hash_find(&n->config, str, str_len) != NULL) != NULL) {
			if (pe->status >= data->status) continue;
		}
		zend_hash_update(&n->config, str, str_len, data, sizeof(*data), NULL);
		phpapdebug((stderr, "ADDING/OVERWRITING %s (%d vs. %d)\n", str, data->status, pe?pe->status:-1));
	}

	return n;
}
예제 #3
0
inline int sw_zend_hash_get_current_key(HashTable *ht, char **key, uint32_t *keylen, ulong *num)
{
    zval str_key;
    int type = zend_hash_get_current_key(ht, &Z_STR(str_key), (zend_ulong* ) num);
    *key = Z_STRVAL(str_key);
    *keylen = Z_STRLEN(str_key);
    return type;
}
예제 #4
0
PHP_METHOD(MIME, load) {
	zval *array, *arg, retval;

	/* Fetch allowHEAD */
	MAKE_STD_ZVAL(array);
	array_init_size(array, 2);
	add_next_index_stringl(array, "Pancake\\Config", sizeof("Pancake\\Config") - 1, 1);
	add_next_index_stringl(array, "get", 3, 1);

	MAKE_STD_ZVAL(arg);
	Z_TYPE_P(arg) = IS_STRING;
	Z_STRLEN_P(arg) = 4;
	Z_STRVAL_P(arg) = estrndup("mime", 4);

	call_user_function(CG(function_table), NULL, array, &retval, 1, &arg TSRMLS_CC);

	if(Z_TYPE(retval) != IS_ARRAY) {
		zend_error(E_ERROR, "Bad MIME type array - Please check Pancake MIME type configuration");
	}

	ALLOC_HASHTABLE(PANCAKE_GLOBALS(mimeTable));
	zend_hash_init(PANCAKE_GLOBALS(mimeTable), 0, NULL, ZVAL_PTR_DTOR, 0);

	zval **data, **ext;
	char *key;

	for(zend_hash_internal_pointer_reset(Z_ARRVAL(retval));
		zend_hash_get_current_data(Z_ARRVAL(retval), (void**) &data) == SUCCESS &&
		zend_hash_get_current_key(Z_ARRVAL(retval), &key, NULL, 0) == HASH_KEY_IS_STRING;
		zend_hash_move_forward(Z_ARRVAL(retval))) {

		for(zend_hash_internal_pointer_reset(Z_ARRVAL_PP(data));
			zend_hash_get_current_data(Z_ARRVAL_PP(data), (void**) &ext) == SUCCESS;
			zend_hash_move_forward(Z_ARRVAL_PP(data))) {

			zval *zkey;
			MAKE_STD_ZVAL(zkey);
			Z_TYPE_P(zkey) = IS_STRING;
			Z_STRLEN_P(zkey) = strlen(key);
			Z_STRVAL_P(zkey) = estrndup(key, Z_STRLEN_P(zkey));

			zend_hash_add(PANCAKE_GLOBALS(mimeTable), Z_STRVAL_PP(ext), Z_STRLEN_PP(ext), (void*) &zkey, sizeof(zval*), NULL);
		}
	}

	MAKE_STD_ZVAL(PANCAKE_GLOBALS(defaultMimeType));
	Z_TYPE_P(PANCAKE_GLOBALS(defaultMimeType)) = IS_STRING;
	Z_STRLEN_P(PANCAKE_GLOBALS(defaultMimeType)) = sizeof("application/octet-stream") - 1;
	Z_STRVAL_P(PANCAKE_GLOBALS(defaultMimeType)) = estrndup("application/octet-stream", sizeof("application/octet-stream") - 1);

	free:
	zval_dtor(&retval);
	zval_ptr_dtor(&array);
	zval_ptr_dtor(&arg);
}
예제 #5
0
파일: Rows.c 프로젝트: NSRagu/php-driver
PHP_METHOD(Rows, key)
{
  ulong key;
  char* string;
  cassandra_rows* self = NULL;

  if (zend_parse_parameters_none() == FAILURE)
    return;

  self = (cassandra_rows*) zend_object_store_get_object(getThis() TSRMLS_CC);

  if (zend_hash_get_current_key(Z_ARRVAL_P(self->rows), &string, &key, 0) == HASH_KEY_IS_LONG)
    RETURN_LONG(key);
}
예제 #6
0
파일: php_ini.c 프로젝트: Tyrael/php-src
/* {{{ php_ini_activate_config
 */
PHPAPI void php_ini_activate_config(HashTable *source_hash, int modify_type, int stage)
{
	zend_string *str;
	zval *data;
	zend_ulong num_index;

	/* Walk through config hash and alter matching ini entries using the values found in the hash */
	for (zend_hash_internal_pointer_reset(source_hash);
		zend_hash_get_current_key(source_hash, &str, &num_index) == HASH_KEY_IS_STRING;
		zend_hash_move_forward(source_hash)
	) {
		data = zend_hash_get_current_data(source_hash);
		zend_alter_ini_entry_ex(str, Z_STR_P(data), modify_type, stage, 0);
	}
}
예제 #7
0
파일: pip_convert.c 프로젝트: demos/Motif
/* {{{ pip_zobject_to_pyobject(zval **obj)
   Convert a PHP (Zend) object to a Python object */
PyObject *
pip_zobject_to_pyobject(zval **obj)
{
	PyObject *dict, *item, *str;
	zval **entry;
	char *string_key;
	long num_key;

	/*
	 * At this point, we represent a PHP object as a dictionary of
	 * its properties.  In the future, we may provide a true object
	 * conversion (which is entirely possible, but it's more work
	 * that I plan on doing right now).
	 */
	dict = PyDict_New();

	/* Start at the beginning of the object properties hash */
	zend_hash_internal_pointer_reset(Z_OBJPROP_PP(obj));

	/* Iterate over the hash's elements */
	while (zend_hash_get_current_data(Z_OBJPROP_PP(obj),
									  (void **)&entry) == SUCCESS) {

		/* Convert the PHP value to its Python equivalent (recursion) */
		item = pip_zval_to_pyobject(entry);

		switch (zend_hash_get_current_key(Z_OBJPROP_PP(obj),
										  &string_key, &num_key, 0)) {
			case HASH_KEY_IS_STRING:
				PyDict_SetItemString(dict, string_key, item);
				break;
			case HASH_KEY_IS_LONG:
				str = PyString_FromFormat("%d", num_key);
				PyObject_SetItem(dict, str, item);
				Py_DECREF(str);
				break;
			case HASH_KEY_NON_EXISTANT:
				php_error(E_ERROR, "No array key");
				break;
		}

		/* Advance to the next entry */
		zend_hash_move_forward(Z_OBJPROP_PP(obj));
	}

	return dict;
}
예제 #8
0
void apply_config(void *dummy)
{
	php_conf_rec *d = dummy;
	char *str;
	uint str_len;
	php_dir_entry *data;
	
	for (zend_hash_internal_pointer_reset(&d->config);
			zend_hash_get_current_key(&d->config, &str, &str_len, NULL) == HASH_KEY_IS_STRING;
			zend_hash_move_forward(&d->config)) {
		zend_hash_get_current_data(&d->config, (void **) &data);
		phpapdebug((stderr, "APPLYING (%s)(%s)\n", str, data->value));
		if (zend_alter_ini_entry(str, str_len, data->value, data->value_len, data->status, data->htaccess?PHP_INI_STAGE_HTACCESS:PHP_INI_STAGE_ACTIVATE) == FAILURE) {
			phpapdebug((stderr, "..FAILED\n"));
		}	
	}
}
예제 #9
0
파일: pip_convert.c 프로젝트: demos/Motif
/* {{{ pip_hash_to_dict(zval **hash)
   Convert a PHP hash to a Python dictionary */
PyObject *
pip_hash_to_dict(zval **hash)
{
	PyObject *dict, *item, *integer;
	zval **entry;
	char *string_key;
	long num_key = 0;

	/* Make sure we were given a PHP hash */
	if (Z_TYPE_PP(hash) != IS_ARRAY) {
		return NULL;
	}

	/* Create a new empty dictionary */
	dict = PyDict_New();

	/* Let's start at the very beginning, a very good place to start. */
	zend_hash_internal_pointer_reset(Z_ARRVAL_PP(hash));

	/* Iterate over the hash's elements */
	while (zend_hash_get_current_data(Z_ARRVAL_PP(hash),
									  (void **)&entry) == SUCCESS) {

		/* Convert the PHP value to its Python equivalent (recursion) */
		item = pip_zval_to_pyobject(entry);

		/* Assign the item with the appropriate key type (string or integer) */
		switch (zend_hash_get_current_key(Z_ARRVAL_PP(hash), &string_key,
										  &num_key, 0)) {
			case HASH_KEY_IS_STRING:
				PyDict_SetItemString(dict, string_key, item);
				break;
			case HASH_KEY_IS_LONG:
				integer = PyInt_FromLong(num_key);
				PyDict_SetItem(dict, integer, item);
				Py_DECREF(integer);
				break;
		}

		/* Advance to the next entry */
		zend_hash_move_forward(Z_ARRVAL_PP(hash));
	}

	return dict;
}
예제 #10
0
char *owsrequest_getenv(const char *name, void *thread_context)
{
    zval **val, **ppzval;
    zval *cookie_result, *key;
    HashTable *cookies;
    char *string_key = NULL, *cookie_tmp;
    ulong num_key;
    int numElements, i = 0;
    TSRMLS_FETCH_FROM_CTX(thread_context);

    if  (STRING_EQUAL(name, "HTTP_COOKIE"))
    {
        cookies = PG(http_globals)[TRACK_VARS_COOKIE]->value.ht;
        numElements = zend_hash_num_elements(cookies);
        MAKE_STD_ZVAL(cookie_result);
        ZVAL_STRING(cookie_result, "",1);
        for(zend_hash_internal_pointer_reset(cookies); 
            zend_hash_has_more_elements(cookies) == SUCCESS; 
            zend_hash_move_forward(cookies), ++i)
        { 
            zend_hash_get_current_data(cookies, (void **)&ppzval);
            zend_hash_get_current_key(cookies, &string_key, &num_key, 1);
            cookie_tmp = malloc((strlen(string_key)+Z_STRLEN_PP(ppzval)+3) * sizeof(char));
            sprintf(cookie_tmp, "%s=%s;",string_key,Z_STRVAL_PP(ppzval));
            MAKE_STD_ZVAL(key);
            ZVAL_STRING(key, cookie_tmp,1);
            add_string_to_string(cookie_result,cookie_result, key);
            zval_dtor(key);
            free(cookie_tmp);
        }
        return Z_STRVAL_P(cookie_result);
    }
    else 
    {
        zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC);
        if ( PG(http_globals)[TRACK_VARS_SERVER] &&
             (zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, name, strlen(name)+1, (void **) &val) == SUCCESS) &&
             (Z_TYPE_PP(val) == IS_STRING))
        {
            return Z_STRVAL_PP(val);
        }
    }
    
    return NULL;
}
예제 #11
0
/** {{{ proto public Yaf_Config_Simple::key(void)
*/
PHP_METHOD(yaf_config_simple, key) {
	zval *prop;
	zend_string *string;
	ulong index;

	prop = zend_read_property(yaf_config_simple_ce, getThis(), ZEND_STRL(YAF_CONFIG_PROPERT_NAME), 1, NULL);
	zend_hash_get_current_key(Z_ARRVAL_P(prop), &string, &index);
	switch(zend_hash_get_current_key_type(Z_ARRVAL_P(prop))) {
		case HASH_KEY_IS_LONG:
			RETURN_LONG(index);
			break;
		case HASH_KEY_IS_STRING:
			RETURN_STR(zend_string_copy(string));
			break;
		default:
			RETURN_FALSE;
	}
}
예제 #12
0
파일: jz_data.c 프로젝트: jonnywang/jz
PHP_METHOD(jz_data, key) {
	zval *prop;
	zend_string *string;
	zend_ulong index;

	prop = zend_read_property(jz_data_class_entry, getThis(), ZEND_STRL(JZ_DATA_PROPERT_NAME), 1, NULL);
	zend_hash_get_current_key(Z_ARRVAL_P(prop), &string, &index);
	switch(zend_hash_get_current_key_type(Z_ARRVAL_P(prop))) {
		case HASH_KEY_IS_LONG:
			RETURN_LONG(index);
			break;
		case HASH_KEY_IS_STRING:
			RETURN_STR(zend_string_copy(string));
			break;
		default:
			RETURN_FALSE;
	}
}
예제 #13
0
static void php_print_gpcse_array(char *name, uint name_length ELS_DC)
{
	zval **data, **tmp, tmp2;
	char *string_key;
	ulong num_key;

	if (zend_hash_find(&EG(symbol_table), name, name_length+1, (void **) &data)!=FAILURE
		&& ((*data)->type==IS_ARRAY)) {
		zend_hash_internal_pointer_reset((*data)->value.ht);
		while (zend_hash_get_current_data((*data)->value.ht, (void **) &tmp) == SUCCESS) {
			PUTS("<TR VALIGN=\"baseline\" BGCOLOR=\"" PHP_CONTENTS_COLOR "\">");
			PUTS("<TD BGCOLOR=\"" PHP_ENTRY_NAME_COLOR "\"><B>");
			PUTS(name);
			PUTS("[\"");
			switch (zend_hash_get_current_key((*data)->value.ht, &string_key, &num_key, 0)) {
				case HASH_KEY_IS_STRING:
					zend_html_puts(string_key, strlen(string_key));
					break;
				case HASH_KEY_IS_LONG:
					php_printf("%ld",num_key);
					break;
			}
			PUTS("\"]</B></TD><TD>");
			if ((*tmp)->type == IS_ARRAY) {
				PUTS("<PRE>");
				zend_print_zval_r(*tmp, 0);
				PUTS("</PRE>");
			} else if ((*tmp)->type != IS_STRING) {
				tmp2 = **tmp;
				zval_copy_ctor(&tmp2);
				convert_to_string(&tmp2);
				zend_html_puts(tmp2.value.str.val, tmp2.value.str.len);
				zval_dtor(&tmp2);
			} else {
				zend_html_puts((*tmp)->value.str.val, (*tmp)->value.str.len);
			}
			PUTS("&nbsp;</TD></TR>\n");
			zend_hash_move_forward((*data)->value.ht);
		}
	}
}
예제 #14
0
/* {{{ xslt_make_array()
   Make an XSLT array (char **) from a zval array (HashTable *) */
extern void xslt_make_array(zval **zarr, char ***carr)
{
    zval      **current;
    HashTable  *arr;
    int         idx = 0;

    arr = HASH_OF(*zarr);
    if (! arr) {
        php_error(E_WARNING, "Invalid argument or parameter array to %s",
                  get_active_function_name());
        return;
    }

    *carr = emalloc((zend_hash_num_elements(arr) * 2) + 1);

    for (zend_hash_internal_pointer_reset(arr);
            zend_hash_get_current_data(arr, (void **) &current) == SUCCESS;
            zend_hash_move_forward(arr)) {
        char  *string_key = NULL;
        ulong  num_key;
        int    type;

        SEPARATE_ZVAL(current);
        convert_to_string_ex(current);

        type = zend_hash_get_current_key(arr, &string_key, &num_key, 0);
        if (type == HASH_KEY_IS_LONG) {
            php_error(E_WARNING, "Invalid argument or parameter array to %s",
                      get_active_function_name());
            return;
        }

        (*carr)[idx++] = estrdup(string_key);
        (*carr)[idx++] = estrndup(Z_STRVAL_PP(current), Z_STRLEN_PP(current));
    }

    (*carr)[idx] = NULL;
}
예제 #15
0
/**
 * Used for readdir() on an opendir()ed phar directory handle
 */
static size_t phar_dir_read(php_stream *stream, char *buf, size_t count) /* {{{ */
{
	size_t to_read;
	HashTable *data = (HashTable *)stream->abstract;
	zend_string *str_key;
	zend_ulong unused;

	if (HASH_KEY_NON_EXISTENT == zend_hash_get_current_key(data, &str_key, &unused)) {
		return 0;
	}

	zend_hash_move_forward(data);
	to_read = MIN(ZSTR_LEN(str_key), count);

	if (to_read == 0 || count < ZSTR_LEN(str_key)) {
		return 0;
	}

	memset(buf, 0, sizeof(php_stream_dirent));
	memcpy(((php_stream_dirent *) buf)->d_name, ZSTR_VAL(str_key), to_read);
	((php_stream_dirent *) buf)->d_name[to_read + 1] = '\0';

	return sizeof(php_stream_dirent);
}
예제 #16
0
static bool getMocData(zval* z_this_ptr, const char* classname, const QMetaObject* superdata, QString* meta_stringdata, uint* signature)
{
    /*
    // - reads all methods defined in a class
    // - see zend_compile.h for types
    // - case sensitive
    // - types need to be matched

    zend_class_entry* ce_ = Z_OBJCE_P(this_ptr);
    HashTable* function_table = &Z_OBJCE_P(this_ptr)->function_table;
    zend_hash_internal_pointer_reset(function_table);
    zval** prop;
    union _zend_function *fbc;

    if (zend_hash_num_elements( function_table ) > 0) {
        while(zend_hash_has_more_elements(function_table) == SUCCESS)
        {
        zend_hash_get_current_data(function_table,(void**)&fbc);
            zend_hash_move_forward(function_table);
            QByteArray name( (*fbc).common.function_name );
            if( !name.contains("__destruct") &&
                !name.contains("__construct") &&
                !name.contains("__toString") &&
                !name.contains("proxyMethod") &&
                !name.contains("staticProxyMethod") &&
                !name.contains("emit")
            ){
                for( int i=0; i<(*fbc).common.num_args; i++)
                {
                    qDebug() <<"++ "<< (*fbc).common.arg_info[i].name <<","<< (*fbc).common.arg_info[i].array_type_hint;
                }
                qDebug()  << (*fbc).common.function_name;// << fbc->internal_function->function_name;
            }
        }
    }
     */

    /// - readout the slots table
    zval **slotdata;
    zval *zslot;
    zslot = zend_read_property(Z_OBJCE_P(z_this_ptr),z_this_ptr,"slots",5,1);

    zval *zsignal;
    zsignal = zend_read_property(Z_OBJCE_P(z_this_ptr),z_this_ptr,"signals",7,1);

    if((zslot)->type==IS_ARRAY && (zsignal)->type==IS_ARRAY )
    {
        HashTable* slots_hash = HASH_OF(zslot);
        HashTable* signals_hash = HASH_OF(zsignal);

        char* assocKey;
        ulong numKey;
        int signaturecount = 2 + strlen(classname);

#ifdef MOC_DEBUG
        QString qr;
        pDebug( PHPQt::Moc ) << "+== begin metaobject dump ==+\n";
        pDebug( PHPQt::Moc ) << "\t" << classname << "\n\t1 0 0 0 " << zend_hash_num_elements(slots_hash)+zend_hash_num_elements(signals_hash) << " 10 0 0 0 0" << endl << endl;
#endif

        /// - write class signature
        signature[0] = 1;
        signature[4] = zend_hash_num_elements(slots_hash)+zend_hash_num_elements(signals_hash);
        signature[5] = 10;

        /// - write classname
        meta_stringdata->append(classname);
        meta_stringdata->append(QChar::Null);
        meta_stringdata->append(QChar::Null);

        int i = 10;
        zend_hash_internal_pointer_reset(signals_hash);
        while(zend_hash_has_more_elements(signals_hash) == SUCCESS)
        {
            /// - read slot from hashtable
            zend_hash_get_current_key(signals_hash,&assocKey,&numKey,0);
            zend_hash_get_current_data(signals_hash,(void**)&slotdata);
#ifdef MOC_DEBUG
            qr.append(Z_STRVAL_PP(slotdata));
            qr.append(" ");
            pDebug( PHPQt::Moc ) << "\t" << signaturecount << "8 8 8 0x05 ::s" << endl;
#endif

            meta_stringdata->append(Z_STRVAL_PP(slotdata));
            meta_stringdata->append(QChar::Null);

            zend_hash_move_forward(signals_hash);

            /// - write signal signature
            signature[i++] = signaturecount;
            signature[i++] = 8;
            signature[i++] = 8;
            signature[i++] = 8;
            signature[i++] = 0x05;

            signaturecount += strlen(Z_STRVAL_PP(slotdata)) + 1;
        }

        zend_hash_internal_pointer_reset(slots_hash);

        while(zend_hash_has_more_elements(slots_hash) == SUCCESS)
        {
            /// - read slot from hashtable
            zend_hash_get_current_key(slots_hash,&assocKey,&numKey,0);
            zend_hash_get_current_data(slots_hash,(void**)&slotdata);

#ifdef MOC_DEBUG
            qr.append(Z_STRVAL_PP(slotdata));
            qr.append(" ");
            pDebug( PHPQt::Moc ) << "\t" << signaturecount << "8 8 8 0x0a ::s" << endl;
#endif
            meta_stringdata->append(Z_STRVAL_PP(slotdata));
            meta_stringdata->append(QChar::Null);

            zend_hash_move_forward(slots_hash);

            /// - write slot signature
            signature[i++] = signaturecount;
            signature[i++] = 8;
            signature[i++] = 8;
            signature[i++] = 8;
            signature[i++] = 0x0a;

            signaturecount += strlen(Z_STRVAL_PP(slotdata)) + 1;
        }
        // TODO freeing this crashs
        //     efree( assocKey );
#ifdef MOC_DEBUG
        pDebug( PHPQt::Moc ) << qr << endl;
#endif
        pDebug( PHPQt::Moc ) << "+== end metaobject dump ==+" << endl;
        return true;
    } else {
        return false;
    }
} // getMocData
예제 #17
0
파일: protocol.c 프로젝트: Lucups/Skyray
void skyray_http_protocol_send_headers(skyray_http_protocol_t *self, skyray_http_message_t *message)
{
    zval *zconnection = NULL;

    zconnection = skyray_http_message_get_header(message, intern_str_connection, 1);

    zend_array *ht = &message->headers;
    zend_array *headers;
    zend_string *name;
    zend_string *value;

    skyray_buffer_t header_s;

    skyray_buffer_init(&header_s, 2048);

    if (!skyray_http_message_has_header(message, intern_str_server)) {
        skyray_buffer_appendl(&header_s, ZEND_STRL("Server: Skyray Http Server\r\n"));
    }

    if (!skyray_http_message_has_header(message, intern_str_date)) {
        time_t tm;
        time(&tm);
        char *buf = ctime(&tm);

        skyray_buffer_appendl(&header_s, ZEND_STRL("Date: "));
        skyray_buffer_appendl(&header_s, buf, strlen(buf) - 1);
        skyray_buffer_appendl(&header_s, ZEND_STRL("\r\n"));
    }

    zend_hash_internal_pointer_reset(ht);
    while(zend_hash_has_more_elements(ht) == SUCCESS) {

        zend_hash_get_current_key(ht, &name, NULL);
        headers = Z_ARR_P(zend_hash_get_current_data(ht));

        zend_hash_internal_pointer_reset(headers);
        while(zend_hash_has_more_elements(headers) == SUCCESS) {
            value = Z_STR_P(zend_hash_get_current_data(headers));

            skyray_buffer_appendl(&header_s, name->val, name->len);
            skyray_buffer_appendl(&header_s, ZEND_STRL(": "));
            skyray_buffer_appendl(&header_s, value->val, value->len);
            skyray_buffer_appendl(&header_s, ZEND_STRL("\r\n"));

            zend_hash_move_forward(headers);
        }

        zend_hash_move_forward(ht);
    }

    self->close = 0;

    if (!zconnection) {
        if (http_should_keep_alive(&self->parser)) {
            skyray_buffer_appendl(&header_s, ZEND_STRL("Connection: keep-alive\r\n"));
        } else {
            skyray_buffer_appendl(&header_s, ZEND_STRL("Connection: close\r\n"));
            self->close = 1;
        }
    } else if (strcasecmp(Z_STR_P(zconnection)->val, "close") == 0) {
        self->close = 1;
    }

    self->chunked = 0;

    if (!skyray_http_message_has_header(message, intern_str_content_length)) {
        skyray_buffer_appendl(&header_s, ZEND_STRL("Transfer-Encoding: chunked\r\n"));
        self->chunked = 1;
    }

    skyray_buffer_appendl(&header_s, ZEND_STRL("\r\n"));

    skyray_stream_write(skyray_stream_from_obj(self->stream), header_s.buf);
    skyray_buffer_release(&header_s);
}
예제 #18
0
파일: pvt_trace.c 프로젝트: codenote/pvt
void dump_dot(void)
{

    int x, print_header, key_type;
    int *block_num;
    int c = 0, len = 0, flag_ho;
    long index, key_len;
    char *block_name = NULL;
    char *time_buff = pvt_get_time();
    smart_str str_dot_func = {0};

    TSRMLS_FETCH();

    char *tmp_buff = NULL;
    tmp_buff = pvt_sprintf(tpl_dot[0], time_buff);
    fprintf(PVT_G(trace_file_f_dot), "%s", tmp_buff);
    efree(time_buff);
    efree(tmp_buff);

    if (PVT_G(pvt_graph_fold)) {
        hide_functions();
    }

    /* Iterate through all blocks/nodes */
    for (zend_hash_internal_pointer_reset(PVT_G(block_summary));
        zend_hash_has_more_elements(PVT_G(block_summary)) == SUCCESS;
        zend_hash_move_forward(PVT_G(block_summary))) {

        key_type = zend_hash_get_current_key(PVT_G(block_summary), &block_name, &index, 0);
        if (key_type == HASH_KEY_IS_STRING) {
            key_len = strlen(block_name);
        }
        zend_hash_get_current_data(PVT_G(block_summary), (void*) &block_num);

        print_header = 1;

        int flag_started = 0;
        int flag_break   = 0;
        int flag_nop     = 0;
        flag_ho = 1;

        size_t ret_len;

        /* Iterate through all functions */
        for (x = 0; x < PVT_G(funcs)->len; x++) {

            if (PVT_G(funcs)->file_id[x] == *block_num) {

                flag_started = 1;
                if (print_header) {
                    if (PVT_G(funcs)->type[x] == 2 && flag_ho) {

                        char *ret;
                        php_basename(
                            PVT_G(funcs)->file_name[x],
                            strlen(PVT_G(funcs)->file_name[x]),
                            NULL, 0, &ret, &ret_len TSRMLS_CC
                        );
                        char *escaped_str = php_escape_html_entities(
                            block_name,
                            strlen(block_name),
                            &len, 0, ENT_QUOTES, NULL TSRMLS_CC
                        );
                        /* Print the block header */
                        fprintf(PVT_G(trace_file_f_dot),
                            tpl_point_func[0],
                            *block_num,
                            PVT_G(funcs)->line[x],
                            *block_num,
                            PVT_G(funcs)->file_name[x], PVT_G(funcs)->line[x],
                            ret,
                            escaped_str,
                            PVT_G(funcs)->func_id[x]
                        );
                        flag_ho = 0;
                        efree(ret);
                        efree(escaped_str);
                    }
                }
            }

            if (PVT_G(funcs)->stack[x] <= PVT_G(dot_funcs_i)->file_id[c] && flag_started) {
                if (0 == print_header) {
                    flag_break = 1;
                } else {
                    flag_break = 0;
                }
            }

            if (0 == flag_started) {
                continue;
            }

            if ((PVT_G(funcs)->stack[x]-1) != PVT_G(dot_funcs_i)->file_id[c]) {
                if (!flag_break) {
                    continue;
                } else {
                    flag_nop = 1;
                }
            }

            if (flag_nop != 1) {
                flag_nop = 0;
                if (print_header) {
                    print_header = 0;
                }

                if (PVT_G(dot_funcs_i)->empty[c]) {
                    flag_started = 0;
                    break;
                }

                /* Check if function repeats */
                if (0 == PVT_G(funcs)->hide[x] || !PVT_G(pvt_graph_fold)) {
                    if (2 == PVT_G(funcs)->type[x]) {

                        /* This is USER function */
                        char *escaped_str = php_escape_html_entities(
                            PVT_G(funcs)->func_name[x],
                            strlen(PVT_G(funcs)->func_name[x]),
                            &len, 0, ENT_QUOTES, NULL TSRMLS_CC
                        );

                        fprintf(PVT_G(trace_file_f_dot),
                            tpl_point_func[1],
                            PVT_G(funcs)->line[x],
                            PVT_G(funcs)->line[x],
                            escaped_str,
                            PVT_G(funcs)->func_id[x]
                        );
                        efree(escaped_str);

                        char *tmp_buff = pvt_sprintf(
                            tpl_relation_func[0],
                            *block_num,
                            PVT_G(funcs)->line[x],
                            PVT_G(funcs)->file_id[x],
                            PVT_G(funcs)->file_id[x],
                            PVT_G(funcs)->func_id[x]
                        );
                        smart_str_appends(&str_dot_func, tmp_buff);
                        efree(tmp_buff);

                    } else {
                        /* This is ZEND function */
                        char *escaped_str = php_escape_html_entities(
                            PVT_G(funcs)->func_name[x],
                            strlen(PVT_G(funcs)->func_name[x]),
                            &len, 0, ENT_QUOTES, NULL TSRMLS_CC
                        );

                        fprintf(PVT_G(trace_file_f_dot),
                            tpl_point_func[2],
                            PVT_G(funcs)->line[x],
                            (1 == PVT_G(funcs)->is_evil[x] ? "d63333" : "e0ebcc"),
                            escaped_str,
                            PVT_G(funcs)->func_id[x]
                        );
                        efree(escaped_str);
                    }

                } /* end if (0 ==... */
            } /* end if (flag_nop... */

            if (flag_break) {
                if (!flag_nop) {
                    flag_break   = 0;
                    flag_started = 0;
                    break;
                }
            }
        } /* end for (x... */
        c++;
        fprintf(PVT_G(trace_file_f_dot), "</TABLE>>\n]\n");
    }

    smart_str_0(&str_dot_func);
    if (str_dot_func.c != NULL) {
        fprintf(PVT_G(trace_file_f_dot), "%s", str_dot_func.c);
    }
    smart_str_free(&str_dot_func);
    fprintf(PVT_G(trace_file_f_dot), "\n}\n");
    fclose(PVT_G(trace_file_f_dot));
}
예제 #19
0
/**
 * Create a opendir() directory stream handle by iterating over each of the
 * files in a phar and retrieving its relative path.  From this, construct
 * a list of files/directories that are "in" the directory represented by dir
 */
static php_stream *phar_make_dirstream(char *dir, HashTable *manifest) /* {{{ */
{
	HashTable *data;
	size_t dirlen = strlen(dir);
	char *entry, *found, *save;
	zend_string *str_key;
	uint32_t keylen;
	zend_ulong unused;

	ALLOC_HASHTABLE(data);
	zend_hash_init(data, 64, NULL, NULL, 0);

	if ((*dir == '/' && dirlen == 1 && (manifest->nNumOfElements == 0)) || (dirlen >= sizeof(".phar")-1 && !memcmp(dir, ".phar", sizeof(".phar")-1))) {
		/* make empty root directory for empty phar */
		/* make empty directory for .phar magic directory */
		efree(dir);
		return php_stream_alloc(&phar_dir_ops, data, NULL, "r");
	}

	zend_hash_internal_pointer_reset(manifest);

	while (FAILURE != zend_hash_has_more_elements(manifest)) {
		if (HASH_KEY_NON_EXISTENT == zend_hash_get_current_key(manifest, &str_key, &unused)) {
			break;
		}

		keylen = ZSTR_LEN(str_key);
		if (keylen <= (uint32_t)dirlen) {
			if (keylen == 0 || keylen < (uint32_t)dirlen || !strncmp(ZSTR_VAL(str_key), dir, dirlen)) {
				if (SUCCESS != zend_hash_move_forward(manifest)) {
					break;
				}
				continue;
			}
		}

		if (*dir == '/') {
			/* root directory */
			if (keylen >= sizeof(".phar")-1 && !memcmp(ZSTR_VAL(str_key), ".phar", sizeof(".phar")-1)) {
				/* do not add any magic entries to this directory */
				if (SUCCESS != zend_hash_move_forward(manifest)) {
					break;
				}
				continue;
			}

			if (NULL != (found = (char *) memchr(ZSTR_VAL(str_key), '/', keylen))) {
				/* the entry has a path separator and is a subdirectory */
				entry = (char *) safe_emalloc(found - ZSTR_VAL(str_key), 1, 1);
				memcpy(entry, ZSTR_VAL(str_key), found - ZSTR_VAL(str_key));
				keylen = found - ZSTR_VAL(str_key);
				entry[keylen] = '\0';
			} else {
				entry = (char *) safe_emalloc(keylen, 1, 1);
				memcpy(entry, ZSTR_VAL(str_key), keylen);
				entry[keylen] = '\0';
			}

			goto PHAR_ADD_ENTRY;
		} else {
			if (0 != memcmp(ZSTR_VAL(str_key), dir, dirlen)) {
				/* entry in directory not found */
				if (SUCCESS != zend_hash_move_forward(manifest)) {
					break;
				}
				continue;
			} else {
				if (ZSTR_VAL(str_key)[dirlen] != '/') {
					if (SUCCESS != zend_hash_move_forward(manifest)) {
						break;
					}
					continue;
				}
			}
		}

		save = ZSTR_VAL(str_key);
		save += dirlen + 1; /* seek to just past the path separator */

		if (NULL != (found = (char *) memchr(save, '/', keylen - dirlen - 1))) {
			/* is subdirectory */
			save -= dirlen + 1;
			entry = (char *) safe_emalloc(found - save + dirlen, 1, 1);
			memcpy(entry, save + dirlen + 1, found - save - dirlen - 1);
			keylen = found - save - dirlen - 1;
			entry[keylen] = '\0';
		} else {
			/* is file */
			save -= dirlen + 1;
			entry = (char *) safe_emalloc(keylen - dirlen, 1, 1);
			memcpy(entry, save + dirlen + 1, keylen - dirlen - 1);
			entry[keylen - dirlen - 1] = '\0';
			keylen = keylen - dirlen - 1;
		}
PHAR_ADD_ENTRY:
		if (keylen) {
			phar_add_empty(data, entry, keylen);
		}

		efree(entry);

		if (SUCCESS != zend_hash_move_forward(manifest)) {
			break;
		}
	}

	if (FAILURE != zend_hash_has_more_elements(data)) {
		efree(dir);
		if (zend_hash_sort(data, phar_compare_dir_name, 0) == FAILURE) {
			FREE_HASHTABLE(data);
			return NULL;
		}
		return php_stream_alloc(&phar_dir_ops, data, NULL, "r");
	} else {
		efree(dir);
		return php_stream_alloc(&phar_dir_ops, data, NULL, "r");
	}
}
예제 #20
0
PHP_COUCHBASE_LOCAL
void php_couchbase_store_multi_impl_oo(INTERNAL_FUNCTION_PARAMETERS)
{
	lcb_error_t retval;
	php_couchbase_res *couchbase_res;
	php_couchbase_ctx *ctx;
	time_t exp = {0};
	long expire = 0;
	zval *akeys;
	long persist_to = 0;
	long replicate_to = 0;
	struct observe_entry *entries;
	int numkeys;
	lcb_store_cmd_t *cmds;
	lcb_store_cmd_t **commands;
	int ii;

	PHP_COUCHBASE_GET_PARAMS(couchbase_res, PHP_COUCHBASE_ARG_F_OO, "a|lll",
							 &akeys, &expire, &persist_to, &replicate_to);

	if (pcbc_check_expiry(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1,
						  expire, &exp) == -1) {
		/* Incorrect expiry time */
		return;
	}

	if (validate_simple_observe_clause(couchbase_res->handle,
									   persist_to,
									   replicate_to TSRMLS_CC) == -1) {
		/* Exception already thrown */
		return;
	}

	numkeys = zend_hash_num_elements(Z_ARRVAL_P(akeys));
	if (numkeys == 0) {
		zend_throw_exception(cb_illegal_key_exception,
							 "No items specified",
							 0 TSRMLS_CC);
		return ;
	}

	entries = ecalloc(numkeys, sizeof(struct observe_entry));
	commands = ecalloc(numkeys, sizeof(lcb_store_cmd_t *));
	cmds = ecalloc(numkeys, sizeof(lcb_store_cmd_t));
	/* link the command pointers */
	for (ii = 0; ii < numkeys; ++ii) {
		commands[ii] = cmds + ii;
	}

	ctx = ecalloc(1, sizeof(php_couchbase_ctx));
	ctx->res = couchbase_res;
	ctx->rv	= return_value;
	array_init(ctx->rv);

	for (ii = 0, zend_hash_internal_pointer_reset(Z_ARRVAL_P(akeys));
			zend_hash_has_more_elements(Z_ARRVAL_P(akeys)) == SUCCESS;
			zend_hash_move_forward(Z_ARRVAL_P(akeys)), ++ii) {
		char *key = NULL;
		uint klen;
		size_t payload_len = 0;
		char *payload;
		unsigned int flags = 0;
		zval **ppzval;

		if (zend_hash_get_current_key_type(Z_ARRVAL_P(akeys)) != HASH_KEY_IS_STRING) {
			int xx;
			for (xx = 0; xx < ii; ++xx) {
				efree((void *)cmds[xx].v.v0.bytes);
			}
			efree(commands);
			efree(cmds);
			efree(ctx);
			release_entry_array(entries,  xx);

			zend_throw_exception(cb_illegal_key_exception,
								 "Invalid key specified (not a string)",
								 0 TSRMLS_CC);
			return ;
		}

		zend_hash_get_current_key(Z_ARRVAL_P(akeys), &key, NULL, 0);
		if ((klen = strlen(key)) == 0) {
			int xx;
			for (xx = 0; xx < ii; ++xx) {
				efree((void *)cmds[xx].v.v0.bytes);
			}
			efree(commands);
			efree(cmds);
			efree(ctx);
			release_entry_array(entries,  xx);

			zend_throw_exception(cb_illegal_key_exception,
								 "Invalid key specified (empty string)",
								 0 TSRMLS_CC);
			return ;
		}

		if (zend_hash_get_current_data(Z_ARRVAL_P(akeys),
									   (void **)&ppzval) == FAILURE) {
			int xx;
			for (xx = 0; xx < ii; ++xx) {
				efree((void *)cmds[xx].v.v0.bytes);
			}
			efree(commands);
			efree(cmds);
			efree(ctx);
			release_entry_array(entries,  xx);

			zend_throw_exception(cb_exception,
								 "Failed to get data for key",
								 0 TSRMLS_CC);
			return ;
		}

		payload = php_couchbase_zval_to_payload(*ppzval, &payload_len, &flags,
												couchbase_res->serializer,
												couchbase_res->compressor
												TSRMLS_CC);

		if (payload == NULL) {
			/* Shouldn't we call an exception? */
			RETURN_FALSE;
		}

		if (couchbase_res->prefix_key_len) {
			char *new_key;
			klen = spprintf(&new_key, 0, "%s_%s", couchbase_res->prefix_key, key);
			key = new_key;
		}

		entries[ii].nkey = klen;
		entries[ii].key = emalloc(klen);
		memcpy(entries[ii].key, key, klen);
		cmds[ii].v.v0.operation = LCB_SET;
		cmds[ii].v.v0.key = entries[ii].key;
		cmds[ii].v.v0.nkey = klen;
		cmds[ii].v.v0.bytes = payload;
		cmds[ii].v.v0.nbytes = payload_len;
		cmds[ii].v.v0.flags = flags;
		cmds[ii].v.v0.exptime = exp;

		if (couchbase_res->prefix_key_len) {
			efree(key);
		}
	}

	retval = lcb_store(couchbase_res->handle, ctx, numkeys,
					   (const lcb_store_cmd_t * const *)commands);
	couchbase_res->seqno += numkeys;
	pcbc_start_loop(couchbase_res);

	/*
	 * Time to release the payloads...
	 */
	for (ii = 0; ii < numkeys; ++ii) {
		efree((void *)cmds[ii].v.v0.bytes);
	}
	efree(cmds);
	efree(commands);

	if (LCB_SUCCESS != retval) {
		efree(ctx);
		couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1,
							   cb_lcb_exception,
							   "Failed to schedule set request: %s",
							   lcb_strerror(couchbase_res->handle, retval));
		release_entry_array(entries,  numkeys);
		RETURN_FALSE;
	}

	/*
	 * The item was stored successfully. Did the user want to wait until
	 * it was persisted/replicated?
	 */
	if (persist_to != 0 || replicate_to != 0) {
		int ii = 0;
		for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(return_value));
				zend_hash_has_more_elements(Z_ARRVAL_P(return_value)) == SUCCESS;
				zend_hash_move_forward(Z_ARRVAL_P(return_value)), ++ii) {
			zval **curr_cas;
			zend_hash_get_current_data(Z_ARRVAL_P(return_value),
									   (void **)&curr_cas);
			if (Z_STRLEN_PP(curr_cas)) {
				entries[ii].cas = strtoull(Z_STRVAL_PP(curr_cas), 0, 10);
			} else {
				/* @todo what to do here? */
				fprintf(stderr, "wtf!\n");
			}
		}

		retval = simple_observe(couchbase_res->handle, entries, numkeys,
								persist_to, replicate_to);
		couchbase_res->rc = retval;

		if (retval != LCB_SUCCESS) {
			if (retval == LCB_ETIMEDOUT) {
				zend_throw_exception(cb_timeout_exception,
									 "Timed out waiting for the objects to persist",
									 0 TSRMLS_CC);
			} else {
				char errmsg[256];
				snprintf(errmsg, sizeof(errmsg),
						 "An error occured while waiting for the objects to persist: %s",
						 lcb_strerror(couchbase_res->handle, retval));
				zend_throw_exception(cb_lcb_exception, errmsg, 0 TSRMLS_CC);
			}
		} else {
			int currsize = 4096;
			char *errmsg = malloc(currsize);
			int offset = sprintf(errmsg, "The following documents was mutated:");
			int errors = 0;

			for (ii = 0; ii < numkeys; ++ii) {
				if (entries[ii].mutated) {
					if ((offset + entries[ii].nkey + 3) > currsize) {
						char *p = realloc(errmsg, currsize * 2);
						if (p) {
							currsize *= 2;
							errmsg = p;
						}
					}

					if ((offset + entries[ii].nkey + 3) < currsize) {
						offset += sprintf(errmsg + offset, " \"");
						memcpy(errmsg + offset, entries[ii].key,
							   entries[ii].nkey);
						offset += entries[ii].nkey;
						offset += sprintf(errmsg + offset, "\"");
					}
					errors = 1;
				}
			}

			if (errors) {
				zend_throw_exception(cb_key_mutated_exception, errmsg,
									 0 TSRMLS_CC);
			}

			free(errmsg);
		}
	}

	release_entry_array(entries,  numkeys);
	efree(ctx);
}
예제 #21
0
PHP_COUCHBASE_LOCAL
void php_couchbase_store_impl(INTERNAL_FUNCTION_PARAMETERS, lcb_storage_t op, int multi)
{
	lcb_error_t retval;
	php_couchbase_res *couchbase_res;
	php_couchbase_ctx *ctx;
	time_t exp = {0};
	unsigned int flags = 0;
	char *payload, *cas = NULL;
	size_t payload_len = 0;
	unsigned long long cas_v = 0;
	long expire = 0, cas_len = 0;
	char *key = NULL;

	if (!multi) {
		char *key = NULL;
		zval *value;
		long klen = 0;
		PHP_COUCHBASE_GET_PARAMS(couchbase_res,
								 PHP_COUCHBASE_ARG_F_FUNCTIONAL,
								 "sz|ls",
								 &key, &klen,
								 &value,
								 &expire,
								 &cas, &cas_len);

		if (pcbc_check_expiry(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0,
							  expire, &exp) == -1) {
			/* Incorrect expiry time */
			return;
		}

		if (!klen) {
			couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0,
								   cb_illegal_key_exception,
								   "No key specified: Empty key");
			return;
		}

		if (cas) {
			char *e;
			cas_v = (lcb_cas_t)strtoull(cas, &e, 10);
			if (*e != '\0') {
				couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0,
									   cb_illegal_key_exception,
									   "Invalid CAS specified");
				return;
			}
		}

		payload = php_couchbase_zval_to_payload(value, &payload_len,
												&flags,
												couchbase_res->serializer,
												couchbase_res->compressor
												TSRMLS_CC);
		if (payload == NULL) {
			RETURN_FALSE;
		}

		if (couchbase_res->prefix_key_len) {
			klen = spprintf(&key, 0, "%s_%s", couchbase_res->prefix_key, key);
		}

		ctx = ecalloc(1, sizeof(php_couchbase_ctx));
		ctx->res = couchbase_res;
		ctx->rv	 = return_value;
		couchbase_res->seqno += 1;

		{
			lcb_store_cmd_t cmd;
			lcb_store_cmd_t *commands[] = { &cmd };
			memset(&cmd, 0, sizeof(cmd));
			cmd.v.v0.operation = op;
			cmd.v.v0.key = key;
			cmd.v.v0.nkey = klen;
			cmd.v.v0.bytes = payload;
			cmd.v.v0.nbytes = payload_len;
			cmd.v.v0.flags = flags;
			cmd.v.v0.exptime = exp;
			cmd.v.v0.cas = (uint64_t)cas_v;

			retval = lcb_store(couchbase_res->handle, ctx,
							   1, (const lcb_store_cmd_t * const *)commands);
		}

		efree(payload);
		if (couchbase_res->prefix_key_len) {
			efree(key);
		}
		if (LCB_SUCCESS != retval) {
			efree(ctx);
			couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0,
								   cb_lcb_exception,
								   "Failed to schedule set request: %s",
								   lcb_strerror(couchbase_res->handle, retval));
			return;
		}

	} else { /* multi */
		zval *akeys, **ppzval;
		char *key = NULL;
		uint klen = 0;
		ulong idx;
		int key_type, nkey = 0;

		PHP_COUCHBASE_GET_PARAMS(couchbase_res,
								 PHP_COUCHBASE_ARG_F_FUNCTIONAL,
								 "a|l",
								 &akeys, &expire);

		if (pcbc_check_expiry(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0,
							  expire, &exp) == -1) {
			/* Incorrect expiry time */
			return;
		}

		ctx = ecalloc(1, sizeof(php_couchbase_ctx));
		ctx->res = couchbase_res;
		ctx->rv	 = return_value;
		array_init(ctx->rv);

		for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(akeys));
				zend_hash_has_more_elements(Z_ARRVAL_P(akeys)) == SUCCESS;
				zend_hash_move_forward(Z_ARRVAL_P(akeys))) {
			if (zend_hash_get_current_data(Z_ARRVAL_P(akeys), (void **)&ppzval) == FAILURE) {
				continue;
			}
			switch ((key_type = zend_hash_get_current_key(Z_ARRVAL_P(akeys), &key, &idx, 0))) {
			case HASH_KEY_IS_LONG:
				spprintf(&key, 0, "%ld", idx);
				break;
			case HASH_KEY_IS_STRING:
				break;
			default:
				continue;
			}

			if (!(klen = strlen(key))) {
				continue;
			}

			payload = php_couchbase_zval_to_payload(*ppzval, &payload_len,
													&flags,
													couchbase_res->serializer,
													couchbase_res->compressor
													TSRMLS_CC);
			if (payload == NULL) {
				RETURN_FALSE;
			}

			if (couchbase_res->prefix_key_len) {
				char *new_key;
				klen = spprintf(&new_key, 0, "%s_%s", couchbase_res->prefix_key, key);
				if (key_type == HASH_KEY_IS_LONG) {
					efree(key);
				}
				key = new_key;
			}

			{
				lcb_store_cmd_t cmd;
				lcb_store_cmd_t *commands[] = { &cmd };
				memset(&cmd, 0, sizeof(cmd));
				cmd.v.v0.operation = op;
				cmd.v.v0.key = key;
				cmd.v.v0.nkey = klen;
				cmd.v.v0.bytes = payload;
				cmd.v.v0.nbytes = payload_len;
				cmd.v.v0.flags = flags;
				cmd.v.v0.exptime = exp;

				retval = lcb_store(couchbase_res->handle, ctx,
								   1, (const lcb_store_cmd_t * const *)commands);
			}

			efree(payload);
			if (couchbase_res->prefix_key_len || HASH_KEY_IS_LONG == key_type) {
				efree(key);
			}
			if (LCB_SUCCESS != retval) {
				efree(ctx);
				couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0,
									   cb_lcb_exception,
									   "Failed to schedule set request: %s",
									   lcb_strerror(couchbase_res->handle,
													retval));
				return;
			}
			nkey++;
		}
		if (!nkey) {
			efree(ctx);
			return;
		}
		couchbase_res->seqno += nkey;
	}
	{
		pcbc_start_loop(couchbase_res);
		if (IS_ARRAY != Z_TYPE_P(return_value)) {
			if (LCB_SUCCESS != ctx->res->rc) {
				RETVAL_FALSE;
				switch (op) {
				case LCB_ADD:
					if (LCB_KEY_EEXISTS == ctx->res->rc) {
						break;
					}
				case LCB_APPEND:
				case LCB_PREPEND:
					if (LCB_NOT_STORED == ctx->res->rc) {
						break;
					}
				case LCB_REPLACE:
				case LCB_SET:
					if (LCB_KEY_ENOENT == ctx->res->rc) {
						break;
					}
					if (cas && LCB_KEY_EEXISTS == ctx->res->rc) {
						break;
					}
				default:
					couchbase_report_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0,
										   cb_lcb_exception,
										   "Failed to store a value to server: %s",
										   lcb_strerror(couchbase_res->handle,
														ctx->res->rc));
					break;
				}
			}
		}

		efree(ctx);
	}
}