Exemple #1
0
/* {{{ php_stream_bucket_attach */
static void php_stream_bucket_attach(int append, INTERNAL_FUNCTION_PARAMETERS)
{
	zval *zbrigade, *zobject;
	zval *pzbucket, *pzdata;
	php_stream_bucket_brigade *brigade;
	php_stream_bucket *bucket;

	ZEND_PARSE_PARAMETERS_START(2, 2)
		Z_PARAM_RESOURCE(zbrigade)
		Z_PARAM_OBJECT(zobject)
	ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);

	if (NULL == (pzbucket = zend_hash_str_find(Z_OBJPROP_P(zobject), "bucket", sizeof("bucket")-1))) {
		php_error_docref(NULL, E_WARNING, "Object has no bucket property");
		RETURN_FALSE;
	}

	if ((brigade = (php_stream_bucket_brigade*)zend_fetch_resource(
					Z_RES_P(zbrigade), PHP_STREAM_BRIGADE_RES_NAME, le_bucket_brigade)) == NULL) {
		RETURN_FALSE;
	}

	if ((bucket = (php_stream_bucket *)zend_fetch_resource_ex(pzbucket, PHP_STREAM_BUCKET_RES_NAME, le_bucket)) == NULL) {
		RETURN_FALSE;
	}

	if (NULL != (pzdata = zend_hash_str_find(Z_OBJPROP_P(zobject), "data", sizeof("data")-1)) && Z_TYPE_P(pzdata) == IS_STRING) {
		if (!bucket->own_buf) {
			bucket = php_stream_bucket_make_writeable(bucket);
		}
		if (bucket->buflen != Z_STRLEN_P(pzdata)) {
			bucket->buf = perealloc(bucket->buf, Z_STRLEN_P(pzdata), bucket->is_persistent);
			bucket->buflen = Z_STRLEN_P(pzdata);
		}
		memcpy(bucket->buf, Z_STRVAL_P(pzdata), bucket->buflen);
	}

	if (append) {
		php_stream_bucket_append(brigade, bucket);
	} else {
		php_stream_bucket_prepend(brigade, bucket);
	}
	/* This is a hack necessary to accommodate situations where bucket is appended to the stream
 	 * multiple times. See bug35916.phpt for reference.
	 */
	if (bucket->refcount == 1) {
		bucket->refcount++;
	}
}
Exemple #2
0
/* Fill ib_link and trans with the correct database link and transaction. */
void _php_ibase_get_link_trans(INTERNAL_FUNCTION_PARAMETERS, /* {{{ */
	zval *link_id, ibase_db_link **ib_link, ibase_trans **trans)
{
	IBDEBUG("Transaction or database link?");
	if (Z_RES_P(link_id)->type == le_trans) {
		/* Transaction resource: make sure it refers to one link only, then
		   fetch it; database link is stored in ib_trans->db_link[]. */
		IBDEBUG("Type is le_trans");
		*trans = (ibase_trans *)zend_fetch_resource_ex(link_id, LE_TRANS, le_trans);
		if ((*trans)->link_cnt > 1) {
			_php_ibase_module_error("Link id is ambiguous: transaction spans multiple connections."
				);
			return;
		}
		*ib_link = (*trans)->db_link[0];
		return;
	}
	IBDEBUG("Type is le_[p]link or id not found");
	/* Database link resource, use default transaction. */
	*trans = NULL;
	*ib_link = (ibase_db_link *)zend_fetch_resource2_ex(link_id, LE_LINK, le_link, le_plink);
}
Exemple #3
0
static void _php_ibase_user(INTERNAL_FUNCTION_PARAMETERS, char operation) /* {{{ */
{
    /* user = 0, password = 1, first_name = 2, middle_name = 3, last_name = 4 */
    static char const user_flags[] = { isc_spb_sec_username, isc_spb_sec_password,
                                       isc_spb_sec_firstname, isc_spb_sec_middlename, isc_spb_sec_lastname
                                     };
    char buf[128], *args[] = { NULL, NULL, NULL, NULL, NULL };
    int i, args_len[] = { 0, 0, 0, 0, 0 };
    unsigned short spb_len = 1;
    zval *res;
    ibase_service *svm;

    RESET_ERRMSG;

    if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(),
                                         (operation == isc_action_svc_delete_user) ? "rs" : "rss|sss",
                                         &res, &args[0], &args_len[0], &args[1], &args_len[1], &args[2], &args_len[2],
                                         &args[3], &args_len[3], &args[4], &args_len[4])) {
        RETURN_FALSE;
    }

    svm = (ibase_service *)zend_fetch_resource_ex(res, "Interbase service manager handle",
            le_service);

    buf[0] = operation;

    for (i = 0; i < sizeof(user_flags); ++i) {
        if (args[i] != NULL) {
            int chunk = slprintf(&buf[spb_len], sizeof(buf) - spb_len, "%c%c%c%s",
                                 user_flags[i], (char)args_len[i], (char)(args_len[i] >> 8), args[i]);

            if ((spb_len + chunk) > sizeof(buf) || chunk <= 0) {
                _php_ibase_module_error("Internal error: insufficient buffer space for SPB (%d)", spb_len);
                RETURN_FALSE;
            }
            spb_len += chunk;
        }
    }