/* {{{ proto Riak\Search\Output\Output Riak\Search->search(string $index, string $query[, Riak\Search\Input] $parameters) Create a new Search object */ PHP_METHOD(Riak_Search, search) { riak_connection *connection; riack_search_optional_params search_params; riack_search_result *search_result; riack_string rsquery, rsindex; char* index, *query; int index_len, query_len, riackstatus; zval *zclient, *zresult, *zparams = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|o", &index, &index_len, &query, &query_len, &zparams) == FAILURE) { return; } zclient = zend_read_property(riak_search_ce, getThis(), "connection", sizeof("connection")-1, 1 TSRMLS_CC); connection = get_client_connection(zclient TSRMLS_CC); THROW_EXCEPTION_IF_CONNECTION_IS_NULL(connection); memset(&search_params, 0, sizeof(riack_search_optional_params)); rsquery.value = query; rsquery.len = query_len; rsindex.value = index; rsindex.len = index_len; riak_search_set_optional_params(connection->client, zparams, &search_params TSRMLS_CC); RIACK_RETRY_OP(riackstatus, connection, riack_search(connection->client, &rsquery, &rsindex, &search_params, &search_result)); riak_search_free_optional_params(connection->client, &search_params TSRMLS_CC); CHECK_RIACK_STATUS_THROW_AND_RETURN_ON_ERROR(connection, riackstatus); zresult = riak_search_output_from_riack_search_result(search_result TSRMLS_CC); riack_free_search_result_p(connection->client, &search_result); RETURN_ZVAL(zresult, 0, 1); }
/* {{{ proto void Riak\Bucket->getKeyStream(Riak\Output\KeyStreamOutput streamer [, int $timeout = 0]) Streams all keys in the bucket */ PHP_METHOD(RiakBucket, getKeyStream) { struct riak_stream_key_cb_param cb_params; riack_string rsbucket, *rstype; riak_connection *connection, *stream_connection; zval* zstreamer; long timeout; int riackstatus; timeout = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|l", &zstreamer, riak_key_streamer_ce, &timeout) == FAILURE) { zend_throw_exception(riak_badarguments_exception_ce, "Bad or missing argument", 500 TSRMLS_CC); return; } // Create a new connection only for this stream // LibRiack can only handle one operation at the time pr connection connection = get_riak_connection(getThis() TSRMLS_CC); THROW_EXCEPTION_IF_CONNECTION_IS_NULL(connection); stream_connection = take_connection(connection->client->host, strlen(connection->client->host), connection->client->port TSRMLS_CC); if (!stream_connection) { CHECK_RIACK_STATUS_THROW_AND_RETURN_ON_ERROR(stream_connection, RIACK_ERROR_COMMUNICATION); } rsbucket = riack_name_from_bucket(getThis() TSRMLS_CC); #ifdef ZTS cb_params.tsrm_ls = TSRMLS_C; #endif cb_params.zstreamer = zstreamer; rstype = riack_get_bucket_type_from_bucket(connection->client, getThis() TSRMLS_CC); // Not gonna do a retry here on purpose... no reason to retry a mistake in the first place riackstatus = riack_stream_keys_ext(stream_connection->client, &rsbucket, rstype, riak_stream_key_cb, &cb_params, timeout); CHECK_RIACK_STATUS_THROW_ON_ERROR(stream_connection, riackstatus); RFREE(connection->client, rstype); release_connection(stream_connection TSRMLS_CC); }
/* {{{ proto Riak\BucketPropertyList Riak\Bucket->getPropertyList() Fetch and return a RiakBucketProperties object with properties for this bucket */ PHP_METHOD(RiakBucket, getPropertyList) { riak_connection *connection; RIACK_STRING bucketName; uint32_t nVal = 3; uint8_t allowMult = 0; int riackResult; zval *zBucketProps, *zAllowMult, *zNVal; GET_RIAK_CONNECTION_RETURN_EXC_ON_ERROR(connection) bucketName = riack_name_from_bucket(getThis() TSRMLS_CC); riackResult = riack_get_bucket_props(connection->client, bucketName, &nVal, &allowMult); CHECK_RIACK_STATUS_THROW_AND_RETURN_ON_ERROR(connection, riackResult); MAKE_STD_ZVAL(zNVal); ZVAL_LONG(zNVal, nVal); MAKE_STD_ZVAL(zAllowMult); ZVAL_BOOL(zAllowMult, allowMult); MAKE_STD_ZVAL(zBucketProps); object_init_ex(zBucketProps, riak_bucket_properties_ce); RIAK_CALL_METHOD2(RiakBucketProperties, __construct, zBucketProps, zBucketProps, zNVal, zAllowMult); RETVAL_ZVAL(zBucketProps, 0, 1); zval_ptr_dtor(&zNVal); zval_ptr_dtor(&zAllowMult); }
/* {{{ proto void Riak\Bucket->getKeyStream(Riak\Output\KeyStreamOutput streamer) Streams all keys in the bucket */ PHP_METHOD(RiakBucket, getKeyStream) { struct riak_stream_key_cb_param cb_params; RIACK_STRING rsbucket; riak_connection *connection; zval* zstreamer; int riackstatus; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zstreamer) == FAILURE) { return; } GET_RIAK_CONNECTION_RETURN_EXC_ON_ERROR(connection) rsbucket = riack_name_from_bucket(getThis() TSRMLS_CC); #ifdef ZTS cb_params.tsrm_ls = TSRMLS_C; #endif cb_params.zstreamer = zstreamer; riackstatus = riack_stream_keys(connection->client, rsbucket, riak_stream_key_cb, &cb_params); CHECK_RIACK_STATUS_THROW_AND_RETURN_ON_ERROR(connection, riackstatus); }
/* {{{ proto array Riak\Bucket->index(string $index, string $from [, string $to]) Perform a secondary index lookup */ PHP_METHOD(RiakBucket, index) { riack_string rsbucket, rsindex, rsfrom, rsto, *type; riack_string_list *resultlist; char *index, *from, *to; int indexlen, fromlen, tolen, riackstatus, i; riak_connection *connection; zval *zresult; tolen = 0; to = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|s", &index, &indexlen, &from, &fromlen, &to, &tolen) == FAILURE) { zend_throw_exception(riak_badarguments_exception_ce, "Bad or missing argument", 500 TSRMLS_CC); return; } connection = get_riak_connection(getThis() TSRMLS_CC); rsbucket = riack_name_from_bucket(getThis() TSRMLS_CC); type = riack_get_bucket_type_from_bucket(connection->client, getThis() TSRMLS_CC); THROW_EXCEPTION_IF_CONNECTION_IS_NULL(connection); rsindex.len = indexlen; rsindex.value = index; rsfrom.len = fromlen; rsfrom.value = from; if (to != NULL && tolen > 0) { rsto.len = tolen; rsto.value = to; RIACK_RETRY_OP(riackstatus, connection, riack_2i_query_range_ext(connection->client, &rsbucket, type, &rsindex, &rsfrom, &rsto, &resultlist)); } else { RIACK_RETRY_OP(riackstatus, connection, riack_2i_query_exact_ext(connection->client, &rsbucket, type, &rsindex, &rsfrom, &resultlist)); } RFREE(connection->client, type); CHECK_RIACK_STATUS_THROW_AND_RETURN_ON_ERROR(connection, riackstatus); MAKE_STD_ZVAL(zresult); array_init(zresult); for (i=0; i<resultlist->string_count; ++i) { add_next_index_stringl(zresult, resultlist->strings[i].value, resultlist->strings[i].len, 1); } riack_free_string_list_p(connection->client, &resultlist); RETURN_ZVAL(zresult, 0, 1); }
/* {{{ proto Riak\Bucket Riak\Bucket->setPropertyList(Riak\BucketProperties $properties) Apply given properties to this bucket */ PHP_METHOD(RiakBucket, setPropertyList) { riak_connection *connection; RIACK_STRING bucketName; zval* zpropsObj, znval, zallowmult; int riackResult; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &zpropsObj) == FAILURE) { return; } GET_RIAK_CONNECTION_RETURN_EXC_ON_ERROR(connection) bucketName = riack_name_from_bucket(getThis() TSRMLS_CC); RIAK_CALL_METHOD(RiakBucketProperties, getNValue, &znval, zpropsObj); RIAK_CALL_METHOD(RiakBucketProperties, getAllowMult, &zallowmult, zpropsObj); riackResult = riack_set_bucket_props(connection->client, bucketName, Z_LVAL(znval), Z_BVAL(zallowmult)); CHECK_RIACK_STATUS_THROW_AND_RETURN_ON_ERROR(connection, riackResult); RIAK_RETURN_THIS }
/* {{{ proto string[] Riak\Bucket->getKeyList() List all keys in the bucket */ PHP_METHOD(RiakBucket, getKeyList) { struct RIACK_STRING_LINKED_LIST* resultlist, *curr; RIACK_STRING rsbucket; riak_connection *connection; zval* zresultarr; int riackstatus; GET_RIAK_CONNECTION_RETURN_EXC_ON_ERROR(connection) rsbucket = riack_name_from_bucket(getThis() TSRMLS_CC); riackstatus = riack_list_keys(connection->client, rsbucket, &resultlist); CHECK_RIACK_STATUS_THROW_AND_RETURN_ON_ERROR(connection, riackstatus); MAKE_STD_ZVAL(zresultarr); array_init(zresultarr); curr = resultlist; while (curr) { add_next_index_stringl(zresultarr, curr->string.value, curr->string.len, 1); curr = curr->next; } riack_free_string_linked_list(connection->client, &resultlist); RETURN_ZVAL(zresultarr, 0, 1); }
/* {{{ proto array Riak\Bucket->index(string $index, string $from [, string $to]) Apply given properties to this bucket */ PHP_METHOD(RiakBucket, index) { RIACK_STRING rsbucket, rsindex, rsfrom, rsto; RIACK_STRING_LIST resultlist; char *index, *from, *to; int indexlen, fromlen, tolen, riackstatus, i; riak_connection *connection; zval *zresult; tolen = 0; to = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|s", &index, &indexlen, &from, &fromlen, &to, &tolen) == FAILURE) { return; } GET_RIAK_CONNECTION_RETURN_EXC_ON_ERROR(connection) rsbucket = riack_name_from_bucket(getThis() TSRMLS_CC); rsindex.len = indexlen; rsindex.value = index; rsfrom.len = fromlen; rsfrom.value = from; if (to != NULL && tolen > 0) { rsto.len = tolen; rsto.value = to; riackstatus = riack_2i_query_range(connection->client, rsbucket, rsindex, rsfrom, rsto, &resultlist); } else { riackstatus = riack_2i_query_exact(connection->client, rsbucket, rsindex, rsfrom, &resultlist); } CHECK_RIACK_STATUS_THROW_AND_RETURN_ON_ERROR(connection, riackstatus); MAKE_STD_ZVAL(zresult); array_init(zresult); for (i=0; i<resultlist.string_count; ++i) { add_next_index_stringl(zresult, resultlist.strings[i].value, resultlist.strings[i].len, 1); } riack_free_string_list(connection->client, &resultlist); RETURN_ZVAL(zresult, 0, 1); }
/* {{{ proto string[] Riak\Bucket->getKeyList([int $timeout = 0]) List all keys in the bucket */ PHP_METHOD(RiakBucket, getKeyList) { riack_string_linked_list* resultlist, *curr; riack_string rsbucket, *rstype; riak_connection *connection; zval* zresultarr; long timeout; int riackstatus; timeout = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &timeout) == FAILURE) { zend_throw_exception(riak_badarguments_exception_ce, "Bad or missing argument", 500 TSRMLS_CC); return; } connection = get_riak_connection(getThis() TSRMLS_CC); rsbucket = riack_name_from_bucket(getThis() TSRMLS_CC); THROW_EXCEPTION_IF_CONNECTION_IS_NULL(connection); rstype = riack_get_bucket_type_from_bucket(connection->client, getThis() TSRMLS_CC); // Not gonna do a retry here on purpose... no reason to retry a mistake in the first place riackstatus = riack_list_keys_ext(connection->client, &rsbucket, rstype, &resultlist, timeout); RFREE(connection->client, rstype); CHECK_RIACK_STATUS_THROW_AND_RETURN_ON_ERROR(connection, riackstatus); MAKE_STD_ZVAL(zresultarr); array_init(zresultarr); curr = resultlist; while (curr) { add_next_index_stringl(zresultarr, curr->string.value, curr->string.len, 1); curr = curr->next; } riack_free_string_linked_list_p(connection->client, &resultlist); RETURN_ZVAL(zresultarr, 0, 1); }
/* {{{ proto array Riak\Bucket->indexQuery(IndexQuery $query[, IndexInput $input]) Apply given properties to this bucket */ PHP_METHOD(RiakBucket, indexQuery) { riak_connection *connection; riack_2i_query_req req; riack_string_list *result_keys; riack_string *continuation, *type; zval *zquery, *zinput, *zname, *zisrange, *zcontinuation, *zresult; int riackstatus; zinput = zquery = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|O", &zquery, riak_index_query_ce, &zinput, riak_index_input_ce) == FAILURE) { zend_throw_exception(riak_badarguments_exception_ce, "Bad or missing argument", 500 TSRMLS_CC); return; } // TODO Validate query have exact or ranged values connection = get_riak_connection(getThis() TSRMLS_CC); THROW_EXCEPTION_IF_CONNECTION_IS_NULL(connection); memset(&req, 0, sizeof(req)); type = riack_get_bucket_type_from_bucket(connection->client, getThis() TSRMLS_CC); if (type != NULL) { req.bucket_type.len = type->len; req.bucket_type.value = type->value; } req.bucket = riack_name_from_bucket(getThis() TSRMLS_CC); MAKE_STD_ZVAL(zname); RIAK_CALL_METHOD(Riak_Query_IndexQuery, getName, zname, zquery); req.index.len = Z_STRLEN_P(zname); req.index.value = Z_STRVAL_P(zname); continuation = NULL; zcontinuation = NULL; if (zinput) { zval *zmaxresults; MAKE_STD_ZVAL(zmaxresults); RIAK_CALL_METHOD(Riak_Input_IndexInput, getMaxResults, zmaxresults, zinput); if (Z_TYPE_P(zmaxresults) == IS_LONG) { req.max_results = Z_LVAL_P(zmaxresults); } zval_ptr_dtor(&zmaxresults); MAKE_STD_ZVAL(zcontinuation); RIAK_CALL_METHOD(Riak_Input_IndexInput, getContinuation, zcontinuation, zinput); if (Z_TYPE_P(zcontinuation) == IS_STRING) { req.continuation_token.len = Z_STRLEN_P(zcontinuation); req.continuation_token.value = Z_STRVAL_P(zcontinuation); } } MAKE_STD_ZVAL(zisrange); RIAK_CALL_METHOD(Riak_Query_IndexQuery, isRangeQuery, zisrange, zquery); if (Z_BVAL_P(zisrange)) { zval *zmin, *zmax; // TODO Call getter instead, this is cheat zmin = zend_read_property(riak_index_query_ce, zquery, "minValue", sizeof("minValue")-1, 1 TSRMLS_CC); zmax = zend_read_property(riak_index_query_ce, zquery, "maxValue", sizeof("maxValue")-1, 1 TSRMLS_CC); req.search_min.len = Z_STRLEN_P(zmin); req.search_min.value = Z_STRVAL_P(zmin); req.search_max.len = Z_STRLEN_P(zmax); req.search_max.value = Z_STRVAL_P(zmax); RIACK_RETRY_OP(riackstatus, connection, riack_2i_query(connection->client, &req, &result_keys, &continuation)); } else { zval *zexact; zexact = zend_read_property(riak_index_query_ce, zquery, "exactValue", sizeof("exactValue")-1, 1 TSRMLS_CC); req.search_exact.len = Z_STRLEN_P(zexact); req.search_exact.value = Z_STRVAL_P(zexact); RIACK_RETRY_OP(riackstatus, connection, riack_2i_query(connection->client, &req, &result_keys, &continuation)); } zval_ptr_dtor(&zname); zval_ptr_dtor(&zisrange); if (zcontinuation) { zval_ptr_dtor(&zcontinuation); } RFREE(connection->client, type); CHECK_RIACK_STATUS_THROW_AND_RETURN_ON_ERROR(connection, riackstatus); zresult = riak_index_output_from_string_list_and_continuation(result_keys, continuation TSRMLS_CC); riack_free_string_p(connection->client, &continuation); riack_free_string_list_p(connection->client, &result_keys); RETURN_ZVAL(zresult, 0, 1); }