Browse files

New method MogileFs::fileInfo() (contributed by Jan Kantert <jan.kant…

…ert@researchgate.net>)

git-svn-id: https://svn.usrportage.de/php-mogilefs/trunk@251 6ae05860-910a-4080-baf6-befe656c970c
  • Loading branch information...
1 parent 3368dda commit 0e5ed578379dea4148058a4fa68e60740082052f lars committed Jun 8, 2011
Showing with 83 additions and 6 deletions.
  1. +45 −0 mogilefs.c
  2. +1 −6 package.xml
  3. +1 −0 php_mogilefs.h
  4. +36 −0 tests/mogilefs-fileInfo.phpt
View
45 mogilefs.c
@@ -89,6 +89,11 @@ ZEND_BEGIN_ARG_INFO(arginfo_MogileFs_get, 0)
ZEND_END_ARG_INFO()
MOGILEFS_ARG_INFO
+ZEND_BEGIN_ARG_INFO(arginfo_MogileFs_fileInfo, 0)
+ ZEND_ARG_INFO(0, key)
+ZEND_END_ARG_INFO()
+
+MOGILEFS_ARG_INFO
ZEND_BEGIN_ARG_INFO(arginfo_MogileFs_getDomains, 0)
ZEND_END_ARG_INFO()
@@ -138,6 +143,7 @@ zend_function_entry php_mogilefs_methods[] = {
PHP_ME(MogileFs, connect, arginfo_MogileFs_connect, ZEND_ACC_PUBLIC)
PHP_ME(MogileFs, get, arginfo_MogileFs_get, ZEND_ACC_PUBLIC)
PHP_ME(MogileFs, getDomains, arginfo_MogileFs_getDomains, ZEND_ACC_PUBLIC)
+ PHP_ME(MogileFs, fileInfo, arginfo_MogileFs_fileInfo, ZEND_ACC_PUBLIC)
PHP_ME(MogileFs, listKeys, NULL, ZEND_ACC_PUBLIC)
PHP_ME(MogileFs, listFids, NULL, ZEND_ACC_PUBLIC)
PHP_ME(MogileFs, getHosts, NULL, ZEND_ACC_PUBLIC)
@@ -912,6 +918,45 @@ PHP_METHOD(MogileFs, rename)
/* }}} */
+
+/* {{{ proto array MogileFs::fileInfo(string key)
+ Get MogileFs fileInfo */
+PHP_METHOD(MogileFs, fileInfo)
+{
+ zval *object;
+ MogilefsSock *mogilefs_sock;
+ char *key = NULL, *request, *response;
+ int key_len, request_len, response_len;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
+ &object, mogilefs_ce, &key, &key_len) == FAILURE) {
+
+ return;
+ }
+
+ if (mogilefs_sock_get(object, &mogilefs_sock TSRMLS_CC) < 0) {
+ zend_throw_exception(mogilefs_exception_ce, "Could not connect to tracker", 0 TSRMLS_CC);
+ RETURN_FALSE;
+ }
+
+ request_len = spprintf(&request, 0, "FILE_INFO domain=%s&key=%s\r\n", mogilefs_sock->domain, key);
+ if (MOGILEFS_SOCK_WRITE_FREE(mogilefs_sock, request, request_len) < 0) {
+ RETURN_FALSE;
+ }
+
+ if ((response = mogilefs_sock_read(mogilefs_sock, &response_len TSRMLS_CC)) == NULL) {
+ RETURN_FALSE;
+ }
+
+ if (mogilefs_parse_response_to_array(INTERNAL_FUNCTION_PARAM_PASSTHRU, response, response_len) < 0) {
+ RETURN_FALSE;
+ }
+}
+
+/* }}} */
+
+
+
/* {{{ proto array MogileFs::getDomains()
Get MogileFs domains */
PHP_METHOD(MogileFs, getDomains)
View
7 package.xml
@@ -22,12 +22,7 @@ PHP MogileFS is a client library to communicate with MogileFS trackers. Those tr
</stability>
<license uri="http://www.opensource.org/licenses/bsd-license.php">BSD License</license>
<notes>
-- Adding new methods setReadTimeout(float readTimeout) and getReadTimeout()
-- Remove PHP max version limit
-- Comply with stricter c99 standard
-- Fixed tests and made them more robust
-- Optimized mogilefs_sock_read() and introduced maximum message size (based on a patch from Andre Pascha of kwick.de)
-- MogileFs::put() throws more exceptions
+- New method MogileFs::fileInfo(string $key) contributed by Jan Kantert <jan.kantert@researchgate.net>
</notes>
<contents>
<dir name="/">
View
1 php_mogilefs.h
@@ -51,6 +51,7 @@ PHP_METHOD(MogileFs, connect);
PHP_METHOD(MogileFs, get);
PHP_METHOD(MogileFs, getPaths);
PHP_METHOD(MogileFs, getDomains);
+PHP_METHOD(MogileFs, fileInfo);
PHP_METHOD(MogileFs, listKeys);
PHP_METHOD(MogileFs, listFids);
PHP_METHOD(MogileFs, getHosts);
View
36 tests/mogilefs-fileInfo.phpt
@@ -0,0 +1,36 @@
+--TEST--
+MogileFS::getDomains()
+--SKIPIF--
+<?php
+require_once dirname(__FILE__) . '/test-helper.php';
+if (mogilefs_skipped()) print "skip";
+--FILE--
+<?php
+require_once dirname(__FILE__) . '/test-helper.php';
+
+$client = mogilefs_test_factory();
+
+$k = 'mogilefs-fileinfo-testkey';
+var_dump($client->put("foo", $k, MOGILEFS_CLASS, false));
+var_dump($client->fileInfo($k));
+var_dump($client->delete($k));
+?>
+==DONE==
+--EXPECTF--
+bool(true)
+array(6) {
+ ["length"]=>
+ string(%d) "3"
+ ["domain"]=>
+ string(%d) "%s"
+ ["fid"]=>
+ string(%d) "%d"
+ ["devcount"]=>
+ string(%d) "%d"
+ ["class"]=>
+ string(%d) "%s"
+ ["key"]=>
+ string(%d) "mogilefs-fileinfo-testkey"
+}
+bool(true)
+==DONE==

0 comments on commit 0e5ed57

Please sign in to comment.