Permalink
Browse files

- Fixed bug in dimensions handler.

- Added tests for read_dimensions handler.
- Methods/functions that receive no parameters enforce that.
- Added rar_is_broken and rar_allow_broken_set.

git-svn-id: http://svn.php.net/repository/pecl/rar/trunk@300009 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent 7bfe225 commit 929b2526651e09250a1fadb5e3754b9360294a0a cataphract committed May 31, 2010
Showing with 354 additions and 46 deletions.
  1. +2 −0 extflow.txt
  2. +20 −10 php_rar.h
  3. +17 −6 rar.c
  4. +85 −30 rararch.c
  5. +26 −0 rarentry.c
  6. +36 −0 tests/082.phpt
  7. +24 −0 tests/083.phpt
  8. +72 −0 tests/084.phpt
  9. +72 −0 tests/085.phpt
View
@@ -1,3 +1,5 @@
+(some information is outdated)
+
rar_open/RarArchive::open()
gives
RarArchive object
View
@@ -42,10 +42,9 @@
/* TODO: make configurable the capacity of the url_stater/dir_opener cache */
/* TODO: test url_stater/dir_opener cache exaustion */
/* TODO: optimize _rar_nav_directory_match with the depth */
-/* TODO: make RarArchive have dimensions */
/* TODO: tests with truncated RAR archive (for which _rar_list_files fails) */
-/* TODO: tests for dimensions stuff */
-/* TODO: allow dirty read of RAR files */
+/* TODO: tests for allow broken RAR */
+/* TODO: tests for has_property, write_property and [] */
#ifndef PHP_RAR_H
#define PHP_RAR_H
@@ -104,6 +103,18 @@ typedef struct rar {
int allow_broken;
} rar_file_t;
+/* Misc */
+#ifdef ZTS
+# define RAR_TSRMLS_TC , void ***
+#else
+# define RAR_TSRMLS_TC
+#endif
+
+#define RAR_RETNULL_ON_ARGS() \
+ if (zend_parse_parameters_none() == FAILURE) { \
+ RETURN_NULL(); \
+ }
+
/* Per-request cache or make last the duration of the PHP lifespan?
* - per-request advantages: we can re-use rar_open and store close RarArchive
* objects. We store either pointers to the objects directly and manipulate
@@ -121,12 +132,6 @@ typedef struct rar {
* I'll also go with a FIFO eviction policy because it's simpler to implement
* (just delete the first element of the HashTable).
*/
-#ifdef ZTS
-# define RAR_TSRMLS_TC , void ***
-#else
-# define RAR_TSRMLS_TC
-#endif
-
typedef struct _rar_contents_cache {
int max_size;
HashTable *data; //persistent HashTable, will hold rar_cache_entry
@@ -148,8 +153,11 @@ ZEND_EXTERN_MODULE_GLOBALS(rar);
# define RAR_G(v) (rar_globals.v)
#endif
-//PHP 5.2 compatibility
+/* PHP 5.2 compatibility */
#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3
+#define zend_parse_parameters_none() \
+ zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "")
+#define Z_DELREF_P ZVAL_DELREF
# define STREAM_ASSUME_REALPATH 0
# define ALLOC_PERMANENT_ZVAL(z) \
(z) = (zval*) malloc(sizeof(zval));
@@ -264,6 +272,8 @@ PHP_FUNCTION(rar_list);
PHP_FUNCTION(rar_entry_get);
PHP_FUNCTION(rar_solid_is);
PHP_FUNCTION(rar_comment_get);
+PHP_FUNCTION(rar_broken_is);
+PHP_FUNCTION(rar_allow_broken_set);
PHP_FUNCTION(rar_close);
/* rarentry.c */
View
23 rar.c
@@ -574,18 +574,29 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_rar_entry_get, 0, 0, 2)
#endif
ZEND_ARG_INFO(0, filename)
ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_rar_allow_broken_set, 0, 0, 2)
+#if 0 /* don't turn on type hinting yet */
+ ZEND_ARG_OBJ_INFO(0, rarfile, RarArchive, 0)
+#else
+ ZEND_ARG_INFO(0, rarfile)
+#endif
+ ZEND_ARG_INFO(0, allow_broken)
+ZEND_END_ARG_INFO()
/* }}} */
/* {{{ rar_functions[]
*
*/
static zend_function_entry rar_functions[] = {
- PHP_FE(rar_open, arginfo_rar_open)
- PHP_FE(rar_list, arginfo_rar_void_archmeth)
- PHP_FE(rar_entry_get, arginfo_rar_entry_get)
- PHP_FE(rar_solid_is, arginfo_rar_void_archmeth)
- PHP_FE(rar_comment_get, arginfo_rar_void_archmeth)
- PHP_FE(rar_close, arginfo_rar_void_archmeth)
+ PHP_FE(rar_open, arginfo_rar_open)
+ PHP_FE(rar_list, arginfo_rar_void_archmeth)
+ PHP_FE(rar_entry_get, arginfo_rar_entry_get)
+ PHP_FE(rar_solid_is, arginfo_rar_void_archmeth)
+ PHP_FE(rar_comment_get, arginfo_rar_void_archmeth)
+ PHP_FE(rar_broken_is, arginfo_rar_void_archmeth)
+ PHP_FE(rar_allow_broken_set, arginfo_rar_allow_broken_set)
+ PHP_FE(rar_close, arginfo_rar_void_archmeth)
{NULL, NULL, NULL}
};
/* }}} */
View
115 rararch.c
@@ -58,6 +58,19 @@ static zend_class_entry *rararch_ce_ptr;
static zend_object_handlers rararch_object_handlers;
/* }}} */
+/* {{{ Helper macros */
+#define RAR_THIS_OR_NO_ARGS(file) \
+ if (file == NULL) { \
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", \
+ &file, rararch_ce_ptr) == FAILURE) { \
+ RETURN_NULL(); \
+ } \
+ } \
+ else { \
+ RAR_RETNULL_ON_ARGS(); \
+ }
+/* }}} */
+
/* {{{ Function prototypes for functions with internal linkage */
static zend_object_value rararch_ce_create_object(zend_class_entry *class_type TSRMLS_DC);
static void rararch_ce_destroy_object(ze_rararch_object *object,
@@ -444,6 +457,7 @@ static zval *rararch_read_dimension(zval *object, zval *offset, int type TSRMLS_
_rar_entry_to_zval(object, out->header, out->packed_size, out->position,
ret TSRMLS_CC);
_rar_entry_search_end(out);
+ Z_DELREF_P(ret); /* set refcount to 0 */
return ret;
}
@@ -543,10 +557,7 @@ PHP_FUNCTION(rar_list)
zval *file = getThis();
rar_file_t *rar = NULL;
- if (file == NULL && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O",
- &file, rararch_ce_ptr) == FAILURE) {
- return;
- }
+ RAR_THIS_OR_NO_ARGS(file);
if (_rar_get_file_resource(file, &rar TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
@@ -574,15 +585,13 @@ PHP_FUNCTION(rar_entry_get)
if (file == NULL) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os",
- &file, rararch_ce_ptr, &filename, &filename_len) == FAILURE) {
+ &file, rararch_ce_ptr, &filename, &filename_len) == FAILURE) {
return;
}
}
- else {
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
+ else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
&filename, &filename_len) == FAILURE) {
- return;
- }
+ return;
}
if (_rar_get_file_resource(file, &rar TSRMLS_CC) == FAILURE) {
@@ -620,10 +629,7 @@ PHP_FUNCTION(rar_solid_is)
zval *file = getThis();
rar_file_t *rar = NULL;
- if (file == NULL && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O",
- &file, rararch_ce_ptr) == FAILURE) {
- return;
- }
+ RAR_THIS_OR_NO_ARGS(file);
if (_rar_get_file_resource(file, &rar TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
@@ -641,10 +647,7 @@ PHP_FUNCTION(rar_comment_get)
rar_file_t *rar = NULL;
unsigned cmt_state;
- if (file == NULL && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O",
- &file, rararch_ce_ptr) == FAILURE) {
- return;
- }
+ RAR_THIS_OR_NO_ARGS(file);
if (_rar_get_file_resource(file, &rar TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
@@ -666,17 +669,61 @@ PHP_FUNCTION(rar_comment_get)
}
/* }}} */
+/* {{{ proto bool rar_is_broken(RarArchive rarfile)
+ Check whether a RAR archive is broken */
+PHP_FUNCTION(rar_broken_is)
+{
+ zval *file = getThis();
+ rar_file_t *rar = NULL;
+ int result;
+
+ RAR_THIS_OR_NO_ARGS(file);
+
+ if (_rar_get_file_resource(file, &rar TSRMLS_CC) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ result = _rar_list_files(rar TSRMLS_CC);
+
+ RETURN_BOOL(_rar_error_to_string(result) != NULL);
+}
+
+/* {{{ proto bool rar_allow_broken_set(RarArchive rarfile, bool allow_broken)
+ Whether to allow entry retrieval of broken RAR archives */
+PHP_FUNCTION(rar_allow_broken_set)
+{
+ zval *file = getThis();
+ rar_file_t *rar = NULL;
+ zend_bool allow_broken;
+
+ if (file == NULL) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Ob",
+ &file, rararch_ce_ptr, &allow_broken) == FAILURE) {
+ return;
+ }
+ }
+ else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b",
+ &allow_broken) == FAILURE) {
+ return;
+ }
+
+ if (_rar_get_file_resource(file, &rar TSRMLS_CC) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ rar->allow_broken = (int) allow_broken;
+
+ RETURN_TRUE;
+}
+
/* {{{ proto bool rar_close(RarArchive rarfile)
Close Rar archive and free all resources */
PHP_FUNCTION(rar_close)
{
zval *file = getThis();
rar_file_t *rar = NULL;
- if (file == NULL && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O",
- &file, rararch_ce_ptr) == FAILURE) {
- return;
- }
+ RAR_THIS_OR_NO_ARGS(file);
if (_rar_get_file_resource(file, &rar TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
@@ -699,6 +746,8 @@ PHP_METHOD(rararch, __toString)
char *restring;
size_t restring_size;
int is_closed;
+
+ RAR_RETNULL_ON_ARGS();
if (_rar_get_file_resource_ex(arch_obj, &rar, TRUE TSRMLS_CC) == FAILURE) {
RETURN_FALSE;
@@ -732,22 +781,28 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_rararchive_getentry, 0, 0, 1)
ZEND_ARG_INFO(0, filename)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_rararchive_setallowbroken, 0, 0, 1)
+ ZEND_ARG_INFO(0, allow_broken)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO(arginfo_rararchive_void, 0)
ZEND_END_ARG_INFO()
/* }}} */
static zend_function_entry php_rararch_class_functions[] = {
- PHP_ME_MAPPING(open, rar_open, arginfo_rararchive_open, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
- PHP_ME_MAPPING(getEntries, rar_list, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
- PHP_ME_MAPPING(getEntry, rar_entry_get, arginfo_rararchive_getentry, ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(open, rar_open, arginfo_rararchive_open, ZEND_ACC_STATIC | ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(getEntries, rar_list, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(getEntry, rar_entry_get, arginfo_rararchive_getentry, ZEND_ACC_PUBLIC)
#ifdef RAR_ARCHIVE_LIST_ALIAS
- PHP_ME_MAPPING(list, rar_list, arginfo_rararchive_void, ZEND_ACC_PUBLIC | ZEND_ACC_DEPRECATED)
+ PHP_ME_MAPPING(list, rar_list, arginfo_rararchive_void, ZEND_ACC_PUBLIC | ZEND_ACC_DEPRECATED)
#endif
- PHP_ME_MAPPING(isSolid, rar_solid_is, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
- PHP_ME_MAPPING(getComment, rar_comment_get, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
- PHP_ME_MAPPING(close, rar_close, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
- PHP_ME(rararch, __toString, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
- PHP_ME_MAPPING(__construct, rar_bogus_ctor, arginfo_rararchive_void, ZEND_ACC_PRIVATE | ZEND_ACC_CTOR)
+ PHP_ME_MAPPING(isSolid, rar_solid_is, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(getComment, rar_comment_get, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(isBroken, rar_broken_is, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(setAllowBroken, rar_allow_broken_set, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(close, rar_close, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
+ PHP_ME(rararch, __toString, arginfo_rararchive_void, ZEND_ACC_PUBLIC)
+ PHP_ME_MAPPING(__construct, rar_bogus_ctor, arginfo_rararchive_void, ZEND_ACC_PRIVATE | ZEND_ACC_CTOR)
{NULL, NULL, NULL}
};
Oops, something went wrong.

0 comments on commit 929b252

Please sign in to comment.