#include <stdint.h>
#endif
-#ifndef TRUE
- # define TRUE 1
- # define FALSE 0
-#endif
-
#ifndef E_RECOVERABLE_ERROR
#define E_RECOVERABLE_ERROR E_ERROR
#endif
#define PHAR_ENT_COMPRESSED_GZ 0x0001
#define PHAR_ENT_COMPRESSED_BZ2 0x0002
-/* an entry has been marked as deleted from a writeable phar */
-#define PHAR_ENT_DELETED 0x10
-/* an entry has been modified, and should be saved */
-#define PHAR_ENT_MODIFIED 0x20
-
+#ifdef ZTS
+# include "TSRM.h"
+# define PHAR_G(v) TSRMG(phar_globals_id, zend_phar_globals *, v)
+# define PHAR_GLOBALS ((zend_phar_globals *) (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(phar_globals_id)])
+#else
+# define PHAR_G(v) (phar_globals.v)
+# define PHAR_GLOBALS (&phar_globals)
+#endif
ZEND_BEGIN_MODULE_GLOBALS(phar)
HashTable phar_fname_map;
php_uint32 filename_len;
char *filename;
long offset_within_phar;
- zend_bool crc_checked;
php_stream *fp;
php_stream *temp_file;
+ int is_crc_checked:1;
+ int is_modified:1;
+ int is_deleted:1;
} phar_entry_info;
/* information about a phar file (the archive itself) */
int fname_len;
char *alias;
int alias_len;
- zend_bool explicit_alias;
char version[12];
size_t internal_file_start;
size_t halt_offset;
php_uint32 sig_flags;
int sig_len;
char *signature;
+ int is_explicit_alias:1;
} phar_archive_data;
/* stream access data for one file entry in a phar file */
return NULL;
}
if (SUCCESS == zend_hash_find(&phar->manifest, path, path_len, (void**)&entry)) {
- if (entry->flags & PHAR_ENT_DELETED) {
+ if (entry->is_deleted) {
/* entry is deleted, but has not been flushed to disk yet */
return NULL;
}
ret = (phar_entry_data *) emalloc(sizeof(phar_entry_data));
if ((entry = phar_get_entry_info(phar, path, path_len TSRMLS_CC)) == NULL) {
/* create an entry, this is a new file */
- etemp.flags = 0;
+ memset(&etemp, 0, sizeof(phar_entry_info));
etemp.filename_len = path_len;
etemp.filename = estrndup(path, path_len);
- etemp.uncompressed_filesize = 0;
- etemp.compressed_filesize = 0;
etemp.timestamp = time(0);
etemp.offset_within_phar = -1;
- etemp.crc32 = 0;
- etemp.crc_checked = TRUE;
- etemp.fp = NULL;
- etemp.temp_file = 0;
+ etemp.is_crc_checked = 1;
zend_hash_add(&phar->manifest, etemp.filename, path_len, (void*)&etemp, sizeof(phar_entry_info), NULL);
/* retrieve the phar manifest copy */
entry = phar_get_entry_info(phar, path, path_len TSRMLS_CC);
if (ret->internal_file->temp_file == 0) {
/* create a temporary stream for our new file */
ret->internal_file->temp_file = php_stream_fopen_tmpfile();
- ret->internal_file->flags |= PHAR_ENT_MODIFIED;
+ ret->internal_file->is_modified = 1;
ret->phar->modified = 1;
}
return ret;
if (buffer + 4 > endbuffer) {
MAPPHAR_FAIL("internal corruption of phar \"%s\" (truncated manifest entry)")
}
+ memset(&entry, 0, sizeof(phar_entry_info));
PHAR_GET_32(buffer, entry.filename_len);
if (entry.filename_len == 0) {
MAPPHAR_FAIL("zero-length filename encountered in phar \"%s\"");
break;
}
manifest_flags |= (entry.flags & PHAR_ENT_COMPRESSION_MASK);
- entry.crc_checked = 0;
+ entry.is_crc_checked = 0;
entry.fp = NULL;
zend_hash_add(&mydata->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), NULL);
}
mydata->signature = signature;
zend_hash_add(&(PHAR_GLOBALS->phar_fname_map), fname, fname_len, (void*)&mydata, sizeof(phar_archive_data*), NULL);
if (register_alias) {
- mydata->explicit_alias = TRUE;
+ mydata->is_explicit_alias = 1;
zend_hash_add(&(PHAR_GLOBALS->phar_alias_map), alias, alias_len, (void*)&mydata, sizeof(phar_archive_data*), NULL);
} else {
- mydata->explicit_alias = FALSE;
+ mydata->is_explicit_alias = 0;
}
efree(savebuf);
mydata->alias = alias ? estrndup(alias, alias_len) : mydata->fname;
mydata->alias_len = alias ? alias_len : fname_len;
snprintf(mydata->version, sizeof(mydata->version), "%s", PHAR_VERSION_STR);
- mydata->explicit_alias = alias ? TRUE : FALSE;
+ mydata->is_explicit_alias = alias ? 1 : 0;
mydata->internal_file_start = -1;
mydata->fp = fp;
if (!alias_len || !alias) {
efree(internal_file);
return NULL;
}
- idata->internal_file->crc_checked = 1;
+ idata->internal_file->is_crc_checked = 1;
fpf = php_stream_alloc(&phar_ops, idata, NULL, mode);
idata->phar->refcount++;
}
data->internal_file->uncompressed_filesize += count;
data->internal_file->compressed_filesize = data->internal_file->uncompressed_filesize;
- data->internal_file->flags |= PHAR_ENT_MODIFIED;
+ data->internal_file->is_modified = 1;
data->phar->modified = 1;
return count;
}
if (zend_hash_get_current_data(&data->phar->manifest, (void **)&entry) == FAILURE) {
continue;
}
- if (entry->flags & PHAR_ENT_DELETED) {
+ if (entry->is_deleted) {
/* remove this from the new phar */
continue;
}
offset += 4 + entry->filename_len + sizeof(entry_buffer);
/* compress as necessary */
- if (entry->flags & PHAR_ENT_MODIFIED) {
+ if (entry->is_modified) {
if (!entry->temp_file) {
/* nothing to do here */
continue;
CRC32(newcrc32, php_stream_getc(file));
}
entry->crc32 = ~newcrc32;
- entry->crc_checked = 1;
+ entry->is_crc_checked = 1;
}
} else {
if (-1 == php_stream_seek(oldfile, entry->offset_within_phar + data->phar->internal_file_start, SEEK_SET)) {
CRC32(newcrc32, php_stream_getc(compfile));
}
entry->crc32 = ~newcrc32;
- entry->crc_checked = 1;
+ entry->is_crc_checked = 1;
if (entry->temp_file) {
/* no longer need the uncompressed contents */
php_stream_close(entry->temp_file);
/* use temp_file to store the newly compressed data */
entry->temp_file = compfile;
entry->compressed_filesize = copy;
- entry->flags |= PHAR_ENT_MODIFIED;
+ entry->is_modified = 1;
global_flags |= (entry->flags & PHAR_ENT_COMPRESSION_MASK);
}
}
* 4: alias length, the rest is the alias itself
*/
restore_alias_len = data->phar->alias_len;
- if (!data->phar->explicit_alias) {
+ if (!data->phar->is_explicit_alias) {
data->phar->alias_len = 0;
}
if (zend_hash_get_current_data(&data->phar->manifest, (void **)&entry) == FAILURE) {
continue;
}
- if (entry->flags & PHAR_ENT_DELETED) {
+ if (entry->is_deleted) {
/* remove this from the new phar */
continue;
}
if (zend_hash_get_current_data(&data->phar->manifest, (void **)&entry) == FAILURE) {
continue;
}
- if (entry->flags & PHAR_ENT_DELETED) {
+ if (entry->is_deleted) {
/* remove this from the new phar */
continue;
}
- if ((entry->flags & PHAR_ENT_MODIFIED) && entry->temp_file) {
+ if (entry->is_modified && entry->temp_file) {
php_stream_rewind(entry->temp_file);
file = entry->temp_file;
} else {
return EOF;
}
/* close the temporary file, no longer needed */
- if (entry->flags & PHAR_ENT_MODIFIED) {
+ if (entry->is_modified) {
if (entry->temp_file) {
php_stream_close(entry->temp_file);
entry->temp_file = 0;
- entry->flags &= ~PHAR_ENT_MODIFIED;
+ entry->is_modified = 0;
}
}
}
fname = estrndup(data->phar->fname, data->phar->fname_len);
fname_len = data->phar->fname_len;
- if (data->phar->explicit_alias == TRUE) {
+ if (data->phar->is_explicit_alias) {
alias = estrndup(data->phar->alias, data->phar->alias_len);
} else {
alias = 0;
php_url_free(resource);
return FAILURE;
}
- if (idata->internal_file->flags & PHAR_ENT_MODIFIED) {
- idata->internal_file->flags &= ~PHAR_ENT_MODIFIED;
+ if (idata->internal_file->is_modified) {
+ idata->internal_file->is_modified = 0;
if (idata->internal_file->temp_file) {
php_stream_close(idata->internal_file->temp_file);
idata->internal_file->temp_file = 0;
}
}
- idata->internal_file->flags |= PHAR_ENT_DELETED;
+ idata->internal_file->is_deleted = 1;
efree(internal_file);
if (idata->fp) {
php_stream_close(idata->fp);
if (zend_hash_exists(&phar_obj->arc.archive->manifest, fname, (uint) fname_len)) {
if (SUCCESS == zend_hash_find(&phar_obj->arc.archive->manifest, fname, (uint) fname_len, (void**)&entry)) {
- if (entry->flags & PHAR_ENT_DELETED) {
+ if (entry->is_deleted) {
/* entry is deleted, but has not been flushed to disk yet */
RETURN_FALSE;
}
if (zend_hash_exists(&phar_obj->arc.archive->manifest, fname, (uint) fname_len)) {
if (SUCCESS == zend_hash_find(&phar_obj->arc.archive->manifest, fname, (uint) fname_len, (void**)&entry)) {
- if (entry->flags & PHAR_ENT_DELETED) {
+ if (entry->is_deleted) {
/* entry is deleted, but has not been flushed to disk yet */
return;
}
- entry->flags &= ~PHAR_ENT_MODIFIED;
- entry->flags |= PHAR_ENT_DELETED;
+ entry->is_modified = 0;
+ entry->is_deleted = 1;
/* we need to "flush" the stream to save the newly deleted file on disk */
data = (phar_entry_data *) emalloc(sizeof(phar_entry_data));
data->phar = phar_obj->arc.archive;
{
PHAR_ENTRY_OBJECT();
- if (entry_obj->ent.entry->crc_checked) {
+ if (entry_obj->ent.entry->is_crc_checked) {
RETURN_LONG(entry_obj->ent.entry->crc32);
} else {
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, \
{
PHAR_ENTRY_OBJECT();
- RETURN_BOOL(entry_obj->ent.entry->crc_checked);
+ RETURN_BOOL(entry_obj->ent.entry->is_crc_checked);
}
/* }}} */