Back to index

php5  5.3.10
Defines | Functions | Variables
phar_object.c File Reference
#include "phar_internal.h"
#include "func_interceptors.h"

Go to the source code of this file.

Defines

#define PHAR_ARG_INFO   static
#define REGISTER_PHAR_CLASS_CONST_LONG(class_name, const_name, value)   zend_declare_class_constant_long(class_name, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC);
#define phar_exception_get_default()   zend_exception_get_default()

Functions

static int phar_file_type (HashTable *mimes, char *file, char **mime_type TSRMLS_DC)
static void phar_mung_server_vars (char *fname, char *entry, int entry_len, char *basename, int request_uri_len TSRMLS_DC)
static int phar_file_action (phar_archive_data *phar, phar_entry_info *info, char *mime_type, int code, char *entry, int entry_len, char *arch, char *basename, char *ru, int ru_len TSRMLS_DC)
static void phar_do_403 (char *entry, int entry_len TSRMLS_DC)
static void phar_do_404 (phar_archive_data *phar, char *fname, int fname_len, char *f404, int f404_len, char *entry, int entry_len TSRMLS_DC)
static void phar_postprocess_ru_web (char *fname, int fname_len, char **entry, int *entry_len, char **ru, int *ru_len TSRMLS_DC)
 PHP_METHOD (Phar, running)
 PHP_METHOD (Phar, mount)
 PHP_METHOD (Phar, webPhar)
 PHP_METHOD (Phar, mungServer)
 PHP_METHOD (Phar, interceptFileFuncs)
 PHP_METHOD (Phar, createDefaultStub)
 PHP_METHOD (Phar, mapPhar)
 PHP_METHOD (Phar, loadPhar)
 PHP_METHOD (Phar, apiVersion)
 PHP_METHOD (Phar, canCompress)
 PHP_METHOD (Phar, canWrite)
 PHP_METHOD (Phar, isValidPharFilename)
 PHP_METHOD (Phar, __construct)
 PHP_METHOD (Phar, getSupportedSignatures)
 PHP_METHOD (Phar, getSupportedCompression)
 PHP_METHOD (Phar, unlinkArchive)
void phar_object_init (TSRMLS_D)

Variables

static zend_class_entry * phar_ce_archive
static zend_class_entry * phar_ce_data
static zend_class_entry * phar_ce_PharException
PHAR_ARG_INFO PHAR_ARG_INFO
PHAR_ARG_INFO PHAR_ARG_INFO
PHAR_ARG_INFO PHAR_ARG_INFO
PHAR_ARG_INFO PHAR_ARG_INFO
PHAR_ARG_INFO PHAR_ARG_INFO
PHAR_ARG_INFO
zend_function_entry 
php_archive_methods []
zend_function_entry phar_exception_methods []

Define Documentation

#define PHAR_ARG_INFO   static

Definition at line 36 of file phar_object.c.

Definition at line 5549 of file phar_object.c.

#define REGISTER_PHAR_CLASS_CONST_LONG (   class_name,
  const_name,
  value 
)    zend_declare_class_constant_long(class_name, const_name, sizeof(const_name)-1, (long)value TSRMLS_CC);

Definition at line 5545 of file phar_object.c.


Function Documentation

static void phar_do_403 ( char *  entry,
int entry_len  TSRMLS_DC 
) [static]

Definition at line 425 of file phar_object.c.

{
       sapi_header_line ctr = {0};

       ctr.response_code = 403;
       ctr.line_len = sizeof("HTTP/1.0 403 Access Denied");
       ctr.line = "HTTP/1.0 403 Access Denied";
       sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
       sapi_send_headers(TSRMLS_C);
       PHPWRITE("<html>\n <head>\n  <title>Access Denied</title>\n </head>\n <body>\n  <h1>403 - File ", sizeof("<html>\n <head>\n  <title>Access Denied</title>\n </head>\n <body>\n  <h1>403 - File ") - 1);
       PHPWRITE(entry, entry_len);
       PHPWRITE(" Access Denied</h1>\n </body>\n</html>", sizeof(" Access Denied</h1>\n </body>\n</html>") - 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void phar_do_404 ( phar_archive_data *  phar,
char *  fname,
int  fname_len,
char *  f404,
int  f404_len,
char *  entry,
int entry_len  TSRMLS_DC 
) [static]

Definition at line 440 of file phar_object.c.

{
       sapi_header_line ctr = {0};
       phar_entry_info      *info;

       if (phar && f404_len) {
              info = phar_get_entry_info(phar, f404, f404_len, NULL, 1 TSRMLS_CC);

              if (info) {
                     phar_file_action(phar, info, "text/html", PHAR_MIME_PHP, f404, f404_len, fname, NULL, NULL, 0 TSRMLS_CC);
                     return;
              }
       }

       ctr.response_code = 404;
       ctr.line_len = sizeof("HTTP/1.0 404 Not Found")+1;
       ctr.line = "HTTP/1.0 404 Not Found";
       sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
       sapi_send_headers(TSRMLS_C);
       PHPWRITE("<html>\n <head>\n  <title>File Not Found</title>\n </head>\n <body>\n  <h1>404 - File ", sizeof("<html>\n <head>\n  <title>File Not Found</title>\n </head>\n <body>\n  <h1>404 - File ") - 1);
       PHPWRITE(entry, entry_len);
       PHPWRITE(" Not Found</h1>\n </body>\n</html>",  sizeof(" Not Found</h1>\n </body>\n</html>") - 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int phar_file_action ( phar_archive_data *  phar,
phar_entry_info info,
char *  mime_type,
int  code,
char *  entry,
int  entry_len,
char *  arch,
char *  basename,
char *  ru,
int ru_len  TSRMLS_DC 
) [static]

Definition at line 258 of file phar_object.c.

{
       char *name = NULL, buf[8192], *cwd;
       zend_syntax_highlighter_ini syntax_highlighter_ini;
       sapi_header_line ctr = {0};
       size_t got;
       int dummy = 1, name_len;
       zend_file_handle file_handle;
       zend_op_array *new_op_array;
       zval *result = NULL;
       php_stream *fp;
       off_t position;

       switch (code) {
              case PHAR_MIME_PHPS:
                     efree(basename);
                     /* highlight source */
                     if (entry[0] == '/') {
                            name_len = spprintf(&name, 4096, "phar://%s%s", arch, entry);
                     } else {
                            name_len = spprintf(&name, 4096, "phar://%s/%s", arch, entry);
                     }
                     php_get_highlight_struct(&syntax_highlighter_ini);

                     highlight_file(name, &syntax_highlighter_ini TSRMLS_CC);

                     efree(name);
#ifdef PHP_WIN32
                     efree(arch);
#endif
                     zend_bailout();
              case PHAR_MIME_OTHER:
                     /* send headers, output file contents */
                     efree(basename);
                     ctr.line_len = spprintf(&(ctr.line), 0, "Content-type: %s", mime_type);
                     sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
                     efree(ctr.line);
                     ctr.line_len = spprintf(&(ctr.line), 0, "Content-length: %u", info->uncompressed_filesize);
                     sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
                     efree(ctr.line);

                     if (FAILURE == sapi_send_headers(TSRMLS_C)) {
                            zend_bailout();
                     }

                     /* prepare to output  */
                     fp = phar_get_efp(info, 1 TSRMLS_CC);

                     if (!fp) {
                            char *error;
                            if (!phar_open_jit(phar, info, &error TSRMLS_CC)) {
                                   if (error) {
                                          zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "%s", error);
                                          efree(error);
                                   }
                                   return -1;
                            }
                            fp = phar_get_efp(info, 1 TSRMLS_CC);
                     }
                     position = 0;
                     phar_seek_efp(info, 0, SEEK_SET, 0, 1 TSRMLS_CC);

                     do {
                            got = php_stream_read(fp, buf, MIN(8192, info->uncompressed_filesize - position));
                            if (got > 0) {
                                   PHPWRITE(buf, got);
                                   position += got;
                                   if (position == (off_t) info->uncompressed_filesize) {
                                          break;
                                   }
                            }
                     } while (1);

                     zend_bailout();
              case PHAR_MIME_PHP:
                     if (basename) {
                            phar_mung_server_vars(arch, entry, entry_len, basename, ru_len TSRMLS_CC);
                            efree(basename);
                     }

                     if (entry[0] == '/') {
                            name_len = spprintf(&name, 4096, "phar://%s%s", arch, entry);
                     } else {
                            name_len = spprintf(&name, 4096, "phar://%s/%s", arch, entry);
                     }

                     file_handle.type = ZEND_HANDLE_FILENAME;
                     file_handle.handle.fd = 0;
                     file_handle.filename = name;
                     file_handle.opened_path = NULL;
                     file_handle.free_filename = 0;

                     PHAR_G(cwd) = NULL;
                     PHAR_G(cwd_len) = 0;

                     if (zend_hash_add(&EG(included_files), name, name_len+1, (void *)&dummy, sizeof(int), NULL) == SUCCESS) {
                            if ((cwd = zend_memrchr(entry, '/', entry_len))) {
                                   PHAR_G(cwd_init) = 1;
                                   if (entry == cwd) {
                                          /* root directory */
                                          PHAR_G(cwd_len) = 0;
                                          PHAR_G(cwd) = NULL;
                                   } else if (entry[0] == '/') {
                                          PHAR_G(cwd_len) = cwd - (entry + 1);
                                          PHAR_G(cwd) = estrndup(entry + 1, PHAR_G(cwd_len));
                                   } else {
                                          PHAR_G(cwd_len) = cwd - entry;
                                          PHAR_G(cwd) = estrndup(entry, PHAR_G(cwd_len));
                                   }
                            }

                            new_op_array = zend_compile_file(&file_handle, ZEND_REQUIRE TSRMLS_CC);

                            if (!new_op_array) {
                                   zend_hash_del(&EG(included_files), name, name_len+1);
                            }

                            zend_destroy_file_handle(&file_handle TSRMLS_CC);

                     } else {
                            efree(name);
                            new_op_array = NULL;
                     }
#ifdef PHP_WIN32
                     efree(arch);
#endif
                     if (new_op_array) {
                            EG(return_value_ptr_ptr) = &result;
                            EG(active_op_array) = new_op_array;

                            zend_try {
                                   zend_execute(new_op_array TSRMLS_CC);
                                   if (PHAR_G(cwd)) {
                                          efree(PHAR_G(cwd));
                                          PHAR_G(cwd) = NULL;
                                          PHAR_G(cwd_len) = 0;
                                   }

                                   PHAR_G(cwd_init) = 0;
                                   efree(name);
                                   destroy_op_array(new_op_array TSRMLS_CC);
                                   efree(new_op_array);


                                   if (EG(return_value_ptr_ptr) && *EG(return_value_ptr_ptr)) {
                                          zval_ptr_dtor(EG(return_value_ptr_ptr));
                                   }
                            } zend_catch {
                                   if (PHAR_G(cwd)) {
                                          efree(PHAR_G(cwd));
                                          PHAR_G(cwd) = NULL;
                                          PHAR_G(cwd_len) = 0;
                                   }

                                   PHAR_G(cwd_init) = 0;
                                   efree(name);
                            } zend_end_try();

                            zend_bailout();
                     }

                     return PHAR_MIME_PHP;
       }
       return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int phar_file_type ( HashTable mimes,
char *  file,
char **mime_type  TSRMLS_DC 
) [static]

Definition at line 39 of file phar_object.c.

{
       char *ext;
       phar_mime_type *mime;
       ext = strrchr(file, '.');
       if (!ext) {
              *mime_type = "text/plain";
              /* no file extension = assume text/plain */
              return PHAR_MIME_OTHER;
       }
       ++ext;
       if (SUCCESS != zend_hash_find(mimes, ext, strlen(ext), (void **) &mime)) {
              *mime_type = "application/octet-stream";
              return PHAR_MIME_OTHER;
       }
       *mime_type = mime->mime;
       return mime->type;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void phar_mung_server_vars ( char *  fname,
char *  entry,
int  entry_len,
char *  basename,
int request_uri_len  TSRMLS_DC 
) [static]

Definition at line 59 of file phar_object.c.

{
#if PHP_MAJOR_VERSION >= 6
       int is_unicode = 0;
#endif
       HashTable *_SERVER;
       zval **stuff;
       char *path_info;
       int basename_len = strlen(basename);
       int code;
       zval *temp;

       /* "tweak" $_SERVER variables requested in earlier call to Phar::mungServer() */
       if (!PG(http_globals)[TRACK_VARS_SERVER]) {
              return;
       }

       _SERVER = Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]);

       /* PATH_INFO and PATH_TRANSLATED should always be munged */
#if PHP_MAJOR_VERSION >= 6
       if (phar_find_key(_SERVER, "PATH_INFO", sizeof("PATH_INFO"), (void **) &stuff TSRMLS_CC)) {
              if (Z_TYPE_PP(stuff) == IS_UNICODE) {
                     is_unicode = 1;
                     zval_unicode_to_string(*stuff TSRMLS_CC);
              } else {
                     is_unicode = 0;
              }
#else
       if (SUCCESS == zend_hash_find(_SERVER, "PATH_INFO", sizeof("PATH_INFO"), (void **) &stuff)) {
#endif

              path_info = Z_STRVAL_PP(stuff);
              code = Z_STRLEN_PP(stuff);

              if (Z_STRLEN_PP(stuff) > entry_len && !memcmp(Z_STRVAL_PP(stuff), entry, entry_len)) {
                     ZVAL_STRINGL(*stuff, Z_STRVAL_PP(stuff) + entry_len, request_uri_len, 1);

                     MAKE_STD_ZVAL(temp);
                     ZVAL_STRINGL(temp, path_info, code, 0);
#if PHP_MAJOR_VERSION >= 6
                     if (is_unicode) {
                            zval_string_to_unicode(*stuff TSRMLS_CC);
                     }
#endif
                     zend_hash_update(_SERVER, "PHAR_PATH_INFO", sizeof("PHAR_PATH_INFO"), &temp, sizeof(zval **), NULL);
              }
       }

#if PHP_MAJOR_VERSION >= 6
       if (phar_find_key(_SERVER, "PATH_TRANSLATED", sizeof("PATH_TRANSLATED"), (void **) &stuff TSRMLS_CC)) {
              if (Z_TYPE_PP(stuff) == IS_UNICODE) {
                     is_unicode = 1;
                     zval_unicode_to_string(*stuff TSRMLS_CC);
              } else {
                     is_unicode = 0;
              }
#else
       if (SUCCESS == zend_hash_find(_SERVER, "PATH_TRANSLATED", sizeof("PATH_TRANSLATED"), (void **) &stuff)) {
#endif

              path_info = Z_STRVAL_PP(stuff);
              code = Z_STRLEN_PP(stuff);
              Z_STRLEN_PP(stuff) = spprintf(&(Z_STRVAL_PP(stuff)), 4096, "phar://%s%s", fname, entry);

              MAKE_STD_ZVAL(temp);
              ZVAL_STRINGL(temp, path_info, code, 0);
#if PHP_MAJOR_VERSION >= 6
              if (is_unicode) {
                     zval_string_to_unicode(*stuff TSRMLS_CC);
              }
#endif
              zend_hash_update(_SERVER, "PHAR_PATH_TRANSLATED", sizeof("PHAR_PATH_TRANSLATED"), (void *) &temp, sizeof(zval **), NULL);
       }

       if (!PHAR_GLOBALS->phar_SERVER_mung_list) {
              return;
       }

       if (PHAR_GLOBALS->phar_SERVER_mung_list & PHAR_MUNG_REQUEST_URI) {
#if PHP_MAJOR_VERSION >= 6
              if (phar_find_key(_SERVER, "REQUEST_URI", sizeof("REQUEST_URI"), (void **) &stuff TSRMLS_CC)) {
              if (Z_TYPE_PP(stuff) == IS_UNICODE) {
                     is_unicode = 1;
                     zval_unicode_to_string(*stuff TSRMLS_CC);
              } else {
                     is_unicode = 0;
              }
#else
              if (SUCCESS == zend_hash_find(_SERVER, "REQUEST_URI", sizeof("REQUEST_URI"), (void **) &stuff)) {
#endif

                     path_info = Z_STRVAL_PP(stuff);
                     code = Z_STRLEN_PP(stuff);

                     if (Z_STRLEN_PP(stuff) > basename_len && !memcmp(Z_STRVAL_PP(stuff), basename, basename_len)) {
                            ZVAL_STRINGL(*stuff, Z_STRVAL_PP(stuff) + basename_len, Z_STRLEN_PP(stuff) - basename_len, 1);

                            MAKE_STD_ZVAL(temp);
                            ZVAL_STRINGL(temp, path_info, code, 0);
#if PHP_MAJOR_VERSION >= 6
                            if (is_unicode) {
                                   zval_string_to_unicode(*stuff TSRMLS_CC);
                            }
#endif
                            zend_hash_update(_SERVER, "PHAR_REQUEST_URI", sizeof("PHAR_REQUEST_URI"), (void *) &temp, sizeof(zval **), NULL);
                     }
              }
       }

       if (PHAR_GLOBALS->phar_SERVER_mung_list & PHAR_MUNG_PHP_SELF) {
#if PHP_MAJOR_VERSION >= 6
              if (phar_find_key(_SERVER, "PHP_SELF", sizeof("PHP_SELF"), (void **) &stuff TSRMLS_CC)) {
              if (Z_TYPE_PP(stuff) == IS_UNICODE) {
                     is_unicode = 1;
                     zval_unicode_to_string(*stuff TSRMLS_CC);
              } else {
                     is_unicode = 0;
              }
#else
              if (SUCCESS == zend_hash_find(_SERVER, "PHP_SELF", sizeof("PHP_SELF"), (void **) &stuff)) {
#endif

                     path_info = Z_STRVAL_PP(stuff);
                     code = Z_STRLEN_PP(stuff);

                     if (Z_STRLEN_PP(stuff) > basename_len && !memcmp(Z_STRVAL_PP(stuff), basename, basename_len)) {
                            ZVAL_STRINGL(*stuff, Z_STRVAL_PP(stuff) + basename_len, Z_STRLEN_PP(stuff) - basename_len, 1);

                            MAKE_STD_ZVAL(temp);
                            ZVAL_STRINGL(temp, path_info, code, 0);
#if PHP_MAJOR_VERSION >= 6
                            if (is_unicode) {
                                   zval_string_to_unicode(*stuff TSRMLS_CC);
                            }
#endif
                            zend_hash_update(_SERVER, "PHAR_PHP_SELF", sizeof("PHAR_PHP_SELF"), (void *) &temp, sizeof(zval **), NULL);
                     }
              }
       }

       if (PHAR_GLOBALS->phar_SERVER_mung_list & PHAR_MUNG_SCRIPT_NAME) {
#if PHP_MAJOR_VERSION >= 6
              if (phar_find_key(_SERVER, "SCRIPT_NAME", sizeof("SCRIPT_NAME"), (void **) &stuff TSRMLS_CC)) {
              if (Z_TYPE_PP(stuff) == IS_UNICODE) {
                     is_unicode = 1;
                     zval_unicode_to_string(*stuff TSRMLS_CC);
              } else {
                     is_unicode = 0;
              }
#else
              if (SUCCESS == zend_hash_find(_SERVER, "SCRIPT_NAME", sizeof("SCRIPT_NAME"), (void **) &stuff)) {
#endif

                     path_info = Z_STRVAL_PP(stuff);
                     code = Z_STRLEN_PP(stuff);
                     ZVAL_STRINGL(*stuff, entry, entry_len, 1);

                     MAKE_STD_ZVAL(temp);
                     ZVAL_STRINGL(temp, path_info, code, 0);
#if PHP_MAJOR_VERSION >= 6
                     if (is_unicode) {
                            zval_string_to_unicode(*stuff TSRMLS_CC);
                     }
#endif
                     zend_hash_update(_SERVER, "PHAR_SCRIPT_NAME", sizeof("PHAR_SCRIPT_NAME"), (void *) &temp, sizeof(zval **), NULL);
              }
       }

       if (PHAR_GLOBALS->phar_SERVER_mung_list & PHAR_MUNG_SCRIPT_FILENAME) {
#if PHP_MAJOR_VERSION >= 6
              if (phar_find_key(_SERVER, "SCRIPT_FILENAME", sizeof("SCRIPT_FILENAME"), (void **) &stuff TSRMLS_CC)) {
              if (Z_TYPE_PP(stuff) == IS_UNICODE) {
                     is_unicode = 1;
                     zval_unicode_to_string(*stuff TSRMLS_CC);
              } else {
                     is_unicode = 0;
              }
#else
              if (SUCCESS == zend_hash_find(_SERVER, "SCRIPT_FILENAME", sizeof("SCRIPT_FILENAME"), (void **) &stuff)) {
#endif

                     path_info = Z_STRVAL_PP(stuff);
                     code = Z_STRLEN_PP(stuff);
                     Z_STRLEN_PP(stuff) = spprintf(&(Z_STRVAL_PP(stuff)), 4096, "phar://%s%s", fname, entry);

                     MAKE_STD_ZVAL(temp);
                     ZVAL_STRINGL(temp, path_info, code, 0);
#if PHP_MAJOR_VERSION >= 6
                     if (is_unicode) {
                            zval_string_to_unicode(*stuff TSRMLS_CC);
                     }
#endif
                     zend_hash_update(_SERVER, "PHAR_SCRIPT_FILENAME", sizeof("PHAR_SCRIPT_FILENAME"), (void *) &temp, sizeof(zval **), NULL);
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 5554 of file phar_object.c.

{
       zend_class_entry ce;

       INIT_CLASS_ENTRY(ce, "PharException", phar_exception_methods);
       phar_ce_PharException = zend_register_internal_class_ex(&ce, phar_exception_get_default(), NULL  TSRMLS_CC);

#if HAVE_SPL
       INIT_CLASS_ENTRY(ce, "Phar", php_archive_methods);
       phar_ce_archive = zend_register_internal_class_ex(&ce, spl_ce_RecursiveDirectoryIterator, NULL  TSRMLS_CC);

       zend_class_implements(phar_ce_archive TSRMLS_CC, 2, spl_ce_Countable, zend_ce_arrayaccess);

       INIT_CLASS_ENTRY(ce, "PharData", php_archive_methods);
       phar_ce_data = zend_register_internal_class_ex(&ce, spl_ce_RecursiveDirectoryIterator, NULL  TSRMLS_CC);

       zend_class_implements(phar_ce_data TSRMLS_CC, 2, spl_ce_Countable, zend_ce_arrayaccess);

       INIT_CLASS_ENTRY(ce, "PharFileInfo", php_entry_methods);
       phar_ce_entry = zend_register_internal_class_ex(&ce, spl_ce_SplFileInfo, NULL  TSRMLS_CC);
#else
       INIT_CLASS_ENTRY(ce, "Phar", php_archive_methods);
       phar_ce_archive = zend_register_internal_class(&ce TSRMLS_CC);
       phar_ce_archive->ce_flags |= ZEND_ACC_FINAL_CLASS;

       INIT_CLASS_ENTRY(ce, "PharData", php_archive_methods);
       phar_ce_data = zend_register_internal_class(&ce TSRMLS_CC);
       phar_ce_data->ce_flags |= ZEND_ACC_FINAL_CLASS;
#endif

       REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "BZ2", PHAR_ENT_COMPRESSED_BZ2)
       REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "GZ", PHAR_ENT_COMPRESSED_GZ)
       REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "NONE", PHAR_ENT_COMPRESSED_NONE)
       REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "PHAR", PHAR_FORMAT_PHAR)
       REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "TAR", PHAR_FORMAT_TAR)
       REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "ZIP", PHAR_FORMAT_ZIP)
       REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "COMPRESSED", PHAR_ENT_COMPRESSION_MASK)
       REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "PHP", PHAR_MIME_PHP)
       REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "PHPS", PHAR_MIME_PHPS)
       REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "MD5", PHAR_SIG_MD5)
       REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "OPENSSL", PHAR_SIG_OPENSSL)
       REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "SHA1", PHAR_SIG_SHA1)
       REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "SHA256", PHAR_SIG_SHA256)
       REGISTER_PHAR_CLASS_CONST_LONG(phar_ce_archive, "SHA512", PHAR_SIG_SHA512)
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void phar_postprocess_ru_web ( char *  fname,
int  fname_len,
char **  entry,
int entry_len,
char **  ru,
int *ru_len  TSRMLS_DC 
) [static]

Definition at line 468 of file phar_object.c.

{
       char *e = *entry + 1, *u = NULL, *u1 = NULL, *saveu = NULL;
       int e_len = *entry_len - 1, u_len = 0;
       phar_archive_data **pphar = NULL;

       /* we already know we can retrieve the phar if we reach here */
       zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), fname, fname_len, (void **) &pphar);

       if (!pphar && PHAR_G(manifest_cached)) {
              zend_hash_find(&cached_phars, fname, fname_len, (void **) &pphar);
       }

       do {
              if (zend_hash_exists(&((*pphar)->manifest), e, e_len)) {
                     if (u) {
                            u[0] = '/';
                            *ru = estrndup(u, u_len+1);
                            ++u_len;
                            u[0] = '\0';
                     } else {
                            *ru = NULL;
                     }
                     *ru_len = u_len;
                     *entry_len = e_len + 1;
                     return;
              }

              if (u) {
                     u1 = strrchr(e, '/');
                     u[0] = '/';
                     saveu = u;
                     e_len += u_len + 1;
                     u = u1;
                     if (!u) {
                            return;
                     }
              } else {
                     u = strrchr(e, '/');
                     if (!u) {
                            if (saveu) {
                                   saveu[0] = '/';
                            }
                            return;
                     }
              }

              u[0] = '\0';
              u_len = strlen(u + 1);
              e_len -= u_len + 1;

              if (e_len < 0) {
                     if (saveu) {
                            saveu[0] = '/';
                     }
                     return;
              }
       } while (1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHP_METHOD ( Phar  ,
running   
)

Definition at line 533 of file phar_object.c.

{
       char *fname, *arch, *entry;
       int fname_len, arch_len, entry_len;
       zend_bool retphar = 1;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &retphar) == FAILURE) {
              return;
       }

       fname = zend_get_executed_filename(TSRMLS_C);
       fname_len = strlen(fname);

       if (fname_len > 7 && !memcmp(fname, "phar://", 7) && SUCCESS == phar_split_fname(fname, fname_len, &arch, &arch_len, &entry, &entry_len, 2, 0 TSRMLS_CC)) {
              efree(entry);
              if (retphar) {
                     RETVAL_STRINGL(fname, arch_len + 7, 1);
                     efree(arch);
                     return;
              } else {
                     RETURN_STRINGL(arch, arch_len, 0);
              }
       }

       RETURN_STRINGL("", 0, 1);
}

Here is the call graph for this function:

PHP_METHOD ( Phar  ,
mount   
)

Definition at line 567 of file phar_object.c.

{
       char *fname, *arch = NULL, *entry = NULL, *path, *actual;
       int fname_len, arch_len, entry_len, path_len, actual_len;
       phar_archive_data **pphar;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &path, &path_len, &actual, &actual_len) == FAILURE) {
              return;
       }

       fname = zend_get_executed_filename(TSRMLS_C);
       fname_len = strlen(fname);

#ifdef PHP_WIN32
       phar_unixify_path_separators(fname, fname_len);
#endif

       if (fname_len > 7 && !memcmp(fname, "phar://", 7) && SUCCESS == phar_split_fname(fname, fname_len, &arch, &arch_len, &entry, &entry_len, 2, 0 TSRMLS_CC)) {
              efree(entry);
              entry = NULL;

              if (path_len > 7 && !memcmp(path, "phar://", 7)) {
                     zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Can only mount internal paths within a phar archive, use a relative path instead of \"%s\"", path);
                     efree(arch);
                     return;
              }
carry_on2:
              if (SUCCESS != zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), arch, arch_len, (void **)&pphar)) {
                     if (PHAR_G(manifest_cached) && SUCCESS == zend_hash_find(&cached_phars, arch, arch_len, (void **)&pphar)) {
                            if (SUCCESS == phar_copy_on_write(pphar TSRMLS_CC)) {
                                   goto carry_on;
                            }
                     }

                     zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "%s is not a phar archive, cannot mount", arch);

                     if (arch) {
                            efree(arch);
                     }
                     return;
              }
carry_on:
              if (SUCCESS != phar_mount_entry(*pphar, actual, actual_len, path, path_len TSRMLS_CC)) {
                     zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Mounting of %s to %s within phar %s failed", path, actual, arch);
                     if (path && path == entry) {
                            efree(entry);
                     }

                     if (arch) {
                            efree(arch);
                     }

                     return;
              }

              if (entry && path && path == entry) {
                     efree(entry);
              }

              if (arch) {
                     efree(arch);
              }

              return;
       } else if (PHAR_GLOBALS->phar_fname_map.arBuckets && SUCCESS == zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), fname, fname_len, (void **)&pphar)) {
              goto carry_on;
       } else if (PHAR_G(manifest_cached) && SUCCESS == zend_hash_find(&cached_phars, fname, fname_len, (void **)&pphar)) {
              if (SUCCESS == phar_copy_on_write(pphar TSRMLS_CC)) {
                     goto carry_on;
              }

              goto carry_on;
       } else if (SUCCESS == phar_split_fname(path, path_len, &arch, &arch_len, &entry, &entry_len, 2, 0 TSRMLS_CC)) {
              path = entry;
              path_len = entry_len;
              goto carry_on2;
       }

       zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Mounting of %s to %s failed", path, actual);
}

Here is the call graph for this function:

PHP_METHOD ( Phar  ,
webPhar   
)

Definition at line 656 of file phar_object.c.

{
       zval *mimeoverride = NULL, *rewrite = NULL;
       char *alias = NULL, *error, *index_php = NULL, *f404 = NULL, *ru = NULL;
       int alias_len = 0, ret, f404_len = 0, free_pathinfo = 0, ru_len = 0;
       char *fname, *basename, *path_info, *mime_type = NULL, *entry, *pt;
       int fname_len, entry_len, code, index_php_len = 0, not_cgi;
       phar_archive_data *phar = NULL;
       phar_entry_info *info = NULL;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!saz", &alias, &alias_len, &index_php, &index_php_len, &f404, &f404_len, &mimeoverride, &rewrite) == FAILURE) {
              return;
       }

       phar_request_initialize(TSRMLS_C);
       fname = zend_get_executed_filename(TSRMLS_C);
       fname_len = strlen(fname);

       if (phar_open_executed_filename(alias, alias_len, &error TSRMLS_CC) != SUCCESS) {
              if (error) {
                     zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "%s", error);
                     efree(error);
              }
              return;
       }

       /* retrieve requested file within phar */
       if (!(SG(request_info).request_method && SG(request_info).request_uri && (!strcmp(SG(request_info).request_method, "GET") || !strcmp(SG(request_info).request_method, "POST")))) {
              return;
       }

#ifdef PHP_WIN32
       fname = estrndup(fname, fname_len);
       phar_unixify_path_separators(fname, fname_len);
#endif
       basename = zend_memrchr(fname, '/', fname_len);

       if (!basename) {
              basename = fname;
       } else {
              ++basename;
       }

       if ((strlen(sapi_module.name) == sizeof("cgi-fcgi")-1 && !strncmp(sapi_module.name, "cgi-fcgi", sizeof("cgi-fcgi")-1))
              || (strlen(sapi_module.name) == sizeof("cgi")-1 && !strncmp(sapi_module.name, "cgi", sizeof("cgi")-1))) {

              if (PG(http_globals)[TRACK_VARS_SERVER]) {
                     HashTable *_server = Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]);
                     zval **z_script_name, **z_path_info;

                     if (SUCCESS != zend_hash_find(_server, "SCRIPT_NAME", sizeof("SCRIPT_NAME"), (void**)&z_script_name) ||
                            IS_STRING != Z_TYPE_PP(z_script_name) ||
                            !strstr(Z_STRVAL_PP(z_script_name), basename)) {
                            return;
                     }

                     if (SUCCESS == zend_hash_find(_server, "PATH_INFO", sizeof("PATH_INFO"), (void**)&z_path_info) &&
                            IS_STRING == Z_TYPE_PP(z_path_info)) {
                            entry_len = Z_STRLEN_PP(z_path_info);
                            entry = estrndup(Z_STRVAL_PP(z_path_info), entry_len);
                            path_info = emalloc(Z_STRLEN_PP(z_script_name) + entry_len + 1);
                            memcpy(path_info, Z_STRVAL_PP(z_script_name), Z_STRLEN_PP(z_script_name));
                            memcpy(path_info + Z_STRLEN_PP(z_script_name), entry, entry_len + 1);
                            free_pathinfo = 1;
                     } else {
                            entry_len = 0;
                            entry = estrndup("", 0);
                            path_info = Z_STRVAL_PP(z_script_name);
                     }

                     pt = estrndup(Z_STRVAL_PP(z_script_name), Z_STRLEN_PP(z_script_name));

              } else {
                     char *testit;

                     testit = sapi_getenv("SCRIPT_NAME", sizeof("SCRIPT_NAME")-1 TSRMLS_CC);
                     if (!(pt = strstr(testit, basename))) {
                            efree(testit);
                            return;
                     }

                     path_info = sapi_getenv("PATH_INFO", sizeof("PATH_INFO")-1 TSRMLS_CC);

                     if (path_info) {
                            entry = path_info;
                            entry_len = strlen(entry);
                            spprintf(&path_info, 0, "%s%s", testit, path_info);
                            free_pathinfo = 1;
                     } else {
                            path_info = testit;
                            free_pathinfo = 1;
                            entry = estrndup("", 0);
                            entry_len = 0;
                     }

                     pt = estrndup(testit, (pt - testit) + (fname_len - (basename - fname)));
              }
              not_cgi = 0;
       } else {
              path_info = SG(request_info).request_uri;

              if (!(pt = strstr(path_info, basename))) {
                     /* this can happen with rewrite rules - and we have no idea what to do then, so return */
                     return;
              }

              entry_len = strlen(path_info);
              entry_len -= (pt - path_info) + (fname_len - (basename - fname));
              entry = estrndup(pt + (fname_len - (basename - fname)), entry_len);

              pt = estrndup(path_info, (pt - path_info) + (fname_len - (basename - fname)));
              not_cgi = 1;
       }

       if (rewrite) {
              zend_fcall_info fci;
              zend_fcall_info_cache fcc;
              zval *params, *retval_ptr, **zp[1];

              MAKE_STD_ZVAL(params);
              ZVAL_STRINGL(params, entry, entry_len, 1);
              zp[0] = &params;

#if PHP_VERSION_ID < 50300
              if (FAILURE == zend_fcall_info_init(rewrite, &fci, &fcc TSRMLS_CC)) {
#else
              if (FAILURE == zend_fcall_info_init(rewrite, 0, &fci, &fcc, NULL, NULL TSRMLS_CC)) {
#endif
                     zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "phar error: invalid rewrite callback");

                     if (free_pathinfo) {
                            efree(path_info);
                     }

                     return;
              }

              fci.param_count = 1;
              fci.params = zp;
#if PHP_VERSION_ID < 50300
              ++(params->refcount);
#else
              Z_ADDREF_P(params);
#endif
              fci.retval_ptr_ptr = &retval_ptr;

              if (FAILURE == zend_call_function(&fci, &fcc TSRMLS_CC)) {
                     if (!EG(exception)) {
                            zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "phar error: failed to call rewrite callback");
                     }

                     if (free_pathinfo) {
                            efree(path_info);
                     }

                     return;
              }

              if (!fci.retval_ptr_ptr || !retval_ptr) {
                     if (free_pathinfo) {
                            efree(path_info);
                     }
                     zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "phar error: rewrite callback must return a string or false");
                     return;
              }

              switch (Z_TYPE_P(retval_ptr)) {
#if PHP_VERSION_ID >= 60000
                     case IS_UNICODE:
                            zval_unicode_to_string(retval_ptr TSRMLS_CC);
                            /* break intentionally omitted */
#endif
                     case IS_STRING:
                            efree(entry);

                            if (fci.retval_ptr_ptr != &retval_ptr) {
                                   entry = estrndup(Z_STRVAL_PP(fci.retval_ptr_ptr), Z_STRLEN_PP(fci.retval_ptr_ptr));
                                   entry_len = Z_STRLEN_PP(fci.retval_ptr_ptr);
                            } else {
                                   entry = Z_STRVAL_P(retval_ptr);
                                   entry_len = Z_STRLEN_P(retval_ptr);
                            }

                            break;
                     case IS_BOOL:
                            phar_do_403(entry, entry_len TSRMLS_CC);

                            if (free_pathinfo) {
                                   efree(path_info);
                            }

                            zend_bailout();
                            return;
                     default:
                            efree(retval_ptr);

                            if (free_pathinfo) {
                                   efree(path_info);
                            }

                            zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "phar error: rewrite callback must return a string or false");
                            return;
              }
       }

       if (entry_len) {
              phar_postprocess_ru_web(fname, fname_len, &entry, &entry_len, &ru, &ru_len TSRMLS_CC);
       }

       if (!entry_len || (entry_len == 1 && entry[0] == '/')) {
              efree(entry);
              /* direct request */
              if (index_php_len) {
                     entry = index_php;
                     entry_len = index_php_len;
                     if (entry[0] != '/') {
                            spprintf(&entry, 0, "/%s", index_php);
                            ++entry_len;
                     }
              } else {
                     /* assume "index.php" is starting point */
                     entry = estrndup("/index.php", sizeof("/index.php"));
                     entry_len = sizeof("/index.php")-1;
              }

              if (FAILURE == phar_get_archive(&phar, fname, fname_len, NULL, 0, NULL TSRMLS_CC) ||
                     (info = phar_get_entry_info(phar, entry, entry_len, NULL, 0 TSRMLS_CC)) == NULL) {
                     phar_do_404(phar, fname, fname_len, f404, f404_len, entry, entry_len TSRMLS_CC);

                     if (free_pathinfo) {
                            efree(path_info);
                     }

                     zend_bailout();
              } else {
                     char *tmp = NULL, sa = '\0';
                     sapi_header_line ctr = {0};
                     ctr.response_code = 301;
                     ctr.line_len = sizeof("HTTP/1.1 301 Moved Permanently")+1;
                     ctr.line = "HTTP/1.1 301 Moved Permanently";
                     sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);

                     if (not_cgi) {
                            tmp = strstr(path_info, basename) + fname_len;
                            sa = *tmp;
                            *tmp = '\0';
                     }

                     ctr.response_code = 0;

                     if (path_info[strlen(path_info)-1] == '/') {
                            ctr.line_len = spprintf(&(ctr.line), 4096, "Location: %s%s", path_info, entry + 1);
                     } else {
                            ctr.line_len = spprintf(&(ctr.line), 4096, "Location: %s%s", path_info, entry);
                     }

                     if (not_cgi) {
                            *tmp = sa;
                     }

                     if (free_pathinfo) {
                            efree(path_info);
                     }

                     sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC);
                     sapi_send_headers(TSRMLS_C);
                     efree(ctr.line);
                     zend_bailout();
              }
       }

       if (FAILURE == phar_get_archive(&phar, fname, fname_len, NULL, 0, NULL TSRMLS_CC) ||
              (info = phar_get_entry_info(phar, entry, entry_len, NULL, 0 TSRMLS_CC)) == NULL) {
              phar_do_404(phar, fname, fname_len, f404, f404_len, entry, entry_len TSRMLS_CC);
#ifdef PHP_WIN32
              efree(fname);
#endif
              zend_bailout();
       }

       if (mimeoverride && zend_hash_num_elements(Z_ARRVAL_P(mimeoverride))) {
              char *ext = zend_memrchr(entry, '.', entry_len);
              zval **val;

              if (ext) {
                     ++ext;

#if PHP_MAJOR_VERSION >= 6
                     if (phar_find_key(Z_ARRVAL_P(mimeoverride), ext, strlen(ext)+1, (void **) &val TSRMLS_CC)) {
#else
                     if (SUCCESS == zend_hash_find(Z_ARRVAL_P(mimeoverride), ext, strlen(ext)+1, (void **) &val)) {
#endif
                            switch (Z_TYPE_PP(val)) {
                                   case IS_LONG:
                                          if (Z_LVAL_PP(val) == PHAR_MIME_PHP || Z_LVAL_PP(val) == PHAR_MIME_PHPS) {
                                                 mime_type = "";
                                                 code = Z_LVAL_PP(val);
                                          } else {
                                                 zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Unknown mime type specifier used, only Phar::PHP, Phar::PHPS and a mime type string are allowed");
#ifdef PHP_WIN32
                                                 efree(fname);
#endif
                                                 RETURN_FALSE;
                                          }
                                          break;
#if PHP_MAJOR_VERSION >= 6
                                   case IS_UNICODE:
                                          zval_unicode_to_string(*(val) TSRMLS_CC);
                                          /* break intentionally omitted */
#endif
                                   case IS_STRING:
                                          mime_type = Z_STRVAL_PP(val);
                                          code = PHAR_MIME_OTHER;
                                          break;
                                   default:
                                          zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Unknown mime type specifier used (not a string or int), only Phar::PHP, Phar::PHPS and a mime type string are allowed");
#ifdef PHP_WIN32
                                          efree(fname);
#endif
                                          RETURN_FALSE;
                            }
                     }
              }
       }

       if (!mime_type) {
              code = phar_file_type(&PHAR_G(mime_types), entry, &mime_type TSRMLS_CC);
       }
       ret = phar_file_action(phar, info, mime_type, code, entry, entry_len, fname, pt, ru, ru_len TSRMLS_CC);
}

Here is the call graph for this function:

PHP_METHOD ( Phar  ,
mungServer   
)

Definition at line 994 of file phar_object.c.

{
       zval *mungvalues;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &mungvalues) == FAILURE) {
              return;
       }

       if (!zend_hash_num_elements(Z_ARRVAL_P(mungvalues))) {
              zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "No values passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME");
              return;
       }

       if (zend_hash_num_elements(Z_ARRVAL_P(mungvalues)) > 4) {
              zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Too many values passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME");
              return;
       }

       phar_request_initialize(TSRMLS_C);

       for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(mungvalues)); SUCCESS == zend_hash_has_more_elements(Z_ARRVAL_P(mungvalues)); zend_hash_move_forward(Z_ARRVAL_P(mungvalues))) {
              zval **data = NULL;
#if PHP_MAJOR_VERSION >= 6
              zval *unicopy = NULL;
#endif

              if (SUCCESS != zend_hash_get_current_data(Z_ARRVAL_P(mungvalues), (void **) &data)) {
                     zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "unable to retrieve array value in Phar::mungServer()");
                     return;
              }

#if PHP_MAJOR_VERSION >= 6
              if (Z_TYPE_PP(data) == IS_UNICODE) {
                     MAKE_STD_ZVAL(unicopy);
                     *unicopy = **data;
                     zval_copy_ctor(unicopy);
                     INIT_PZVAL(unicopy);
                     zval_unicode_to_string(unicopy TSRMLS_CC);
                     data = &unicopy;
              }
#endif

              if (Z_TYPE_PP(data) != IS_STRING) {
                     zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Non-string value passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME");
                     return;
              }

              if (Z_STRLEN_PP(data) == sizeof("PHP_SELF")-1 && !strncmp(Z_STRVAL_PP(data), "PHP_SELF", sizeof("PHP_SELF")-1)) {
                     PHAR_GLOBALS->phar_SERVER_mung_list |= PHAR_MUNG_PHP_SELF;
              }

              if (Z_STRLEN_PP(data) == sizeof("REQUEST_URI")-1) {
                     if (!strncmp(Z_STRVAL_PP(data), "REQUEST_URI", sizeof("REQUEST_URI")-1)) {
                            PHAR_GLOBALS->phar_SERVER_mung_list |= PHAR_MUNG_REQUEST_URI;
                     }
                     if (!strncmp(Z_STRVAL_PP(data), "SCRIPT_NAME", sizeof("SCRIPT_NAME")-1)) {
                            PHAR_GLOBALS->phar_SERVER_mung_list |= PHAR_MUNG_SCRIPT_NAME;
                     }
              }

              if (Z_STRLEN_PP(data) == sizeof("SCRIPT_FILENAME")-1 && !strncmp(Z_STRVAL_PP(data), "SCRIPT_FILENAME", sizeof("SCRIPT_FILENAME")-1)) {
                     PHAR_GLOBALS->phar_SERVER_mung_list |= PHAR_MUNG_SCRIPT_FILENAME;
              }
#if PHP_MAJOR_VERSION >= 6
              if (unicopy) {
                     zval_ptr_dtor(&unicopy);
              }
#endif
       }
}

Here is the call graph for this function:

PHP_METHOD ( Phar  ,
interceptFileFuncs   
)

Definition at line 1074 of file phar_object.c.

Here is the call graph for this function:

PHP_METHOD ( Phar  ,
createDefaultStub   
)

Definition at line 1088 of file phar_object.c.

{
       char *index = NULL, *webindex = NULL, *stub, *error;
       int index_len = 0, webindex_len = 0;
       size_t stub_len;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &index, &index_len, &webindex, &webindex_len) == FAILURE) {
              return;
       }

       stub = phar_create_default_stub(index, webindex, &stub_len, &error TSRMLS_CC);

       if (error) {
              zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "%s", error);
              efree(error);
              return;
       }
       RETURN_STRINGL(stub, stub_len, 0);
}

Here is the call graph for this function:

PHP_METHOD ( Phar  ,
mapPhar   
)

Definition at line 1111 of file phar_object.c.

{
       char *alias = NULL, *error;
       int alias_len = 0;
       long dataoffset = 0;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!l", &alias, &alias_len, &dataoffset) == FAILURE) {
              return;
       }

       phar_request_initialize(TSRMLS_C);

       RETVAL_BOOL(phar_open_executed_filename(alias, alias_len, &error TSRMLS_CC) == SUCCESS);

       if (error) {
              zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "%s", error);
              efree(error);
       }
} /* }}} */

Here is the call graph for this function:

PHP_METHOD ( Phar  ,
loadPhar   
)

Definition at line 1133 of file phar_object.c.

{
       char *fname, *alias = NULL, *error;
       int fname_len, alias_len = 0;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!", &fname, &fname_len, &alias, &alias_len) == FAILURE) {
              return;
       }

       phar_request_initialize(TSRMLS_C);

       RETVAL_BOOL(phar_open_from_filename(fname, fname_len, alias, alias_len, REPORT_ERRORS, NULL, &error TSRMLS_CC) == SUCCESS);

       if (error) {
              zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "%s", error);
              efree(error);
       }
} /* }}} */

Here is the call graph for this function:

PHP_METHOD ( Phar  ,
apiVersion   
)

Definition at line 1154 of file phar_object.c.

PHP_METHOD ( Phar  ,
canCompress   
)

Definition at line 1165 of file phar_object.c.

{
       long method = 0;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &method) == FAILURE) {
              return;
       }

       phar_request_initialize(TSRMLS_C);
       switch (method) {
       case PHAR_ENT_COMPRESSED_GZ:
              if (PHAR_G(has_zlib)) {
                     RETURN_TRUE;
              } else {
                     RETURN_FALSE;
              }
       case PHAR_ENT_COMPRESSED_BZ2:
              if (PHAR_G(has_bz2)) {
                     RETURN_TRUE;
              } else {
                     RETURN_FALSE;
              }
       default:
              if (PHAR_G(has_zlib) || PHAR_G(has_bz2)) {
                     RETURN_TRUE;
              } else {
                     RETURN_FALSE;
              }
       }
}

Here is the call graph for this function:

PHP_METHOD ( Phar  ,
canWrite   
)

Definition at line 1199 of file phar_object.c.

PHP_METHOD ( Phar  ,
isValidPharFilename   
)

Definition at line 1210 of file phar_object.c.

{
       char *fname;
       const char *ext_str;
       int fname_len, ext_len, is_executable;
       zend_bool executable = 1;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &fname, &fname_len, &executable) == FAILURE) {
              return;
       }

       is_executable = executable;
       RETVAL_BOOL(phar_detect_phar_fname_ext(fname, fname_len, &ext_str, &ext_len, is_executable, 2, 1 TSRMLS_CC) == SUCCESS);
}

Here is the call graph for this function:

PHP_METHOD ( Phar  ,
__construct   
)

Definition at line 1270 of file phar_object.c.

{
#if !HAVE_SPL
       zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Cannot instantiate Phar object without SPL extension");
#else
       char *fname, *alias = NULL, *error, *arch = NULL, *entry = NULL, *save_fname;
       int fname_len, alias_len = 0, arch_len, entry_len, is_data;
#if PHP_VERSION_ID < 50300
       long flags = 0;
#else
       long flags = SPL_FILE_DIR_SKIPDOTS|SPL_FILE_DIR_UNIXPATHS;
#endif
       long format = 0;
       phar_archive_object *phar_obj;
       phar_archive_data   *phar_data;
       zval *zobj = getThis(), arg1, arg2;

       phar_obj = (phar_archive_object*)zend_object_store_get_object(getThis() TSRMLS_CC);

       is_data = instanceof_function(Z_OBJCE_P(zobj), phar_ce_data TSRMLS_CC);

       if (is_data) {
              if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls!l", &fname, &fname_len, &flags, &alias, &alias_len, &format) == FAILURE) {
                     return;
              }
       } else {
              if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls!", &fname, &fname_len, &flags, &alias, &alias_len) == FAILURE) {
                     return;
              }
       }

       if (phar_obj->arc.archive) {
              zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot call constructor twice");
              return;
       }

       save_fname = fname;
       if (SUCCESS == phar_split_fname(fname, fname_len, &arch, &arch_len, &entry, &entry_len, !is_data, 2 TSRMLS_CC)) {
              /* use arch (the basename for the archive) for fname instead of fname */
              /* this allows support for RecursiveDirectoryIterator of subdirectories */
#ifdef PHP_WIN32
              phar_unixify_path_separators(arch, arch_len);
#endif
              fname = arch;
              fname_len = arch_len;
#ifdef PHP_WIN32
       } else {
              arch = estrndup(fname, fname_len);
              arch_len = fname_len;
              fname = arch;
              phar_unixify_path_separators(arch, arch_len);
#endif
       }

       if (phar_open_or_create_filename(fname, fname_len, alias, alias_len, is_data, REPORT_ERRORS, &phar_data, &error TSRMLS_CC) == FAILURE) {

              if (fname == arch && fname != save_fname) {
                     efree(arch);
                     fname = save_fname;
              }

              if (entry) {
                     efree(entry);
              }

              if (error) {
                     zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC,
                            "%s", error);
                     efree(error);
              } else {
                     zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC,
                            "Phar creation or opening failed");
              }

              return;
       }

       if (is_data && phar_data->is_tar && phar_data->is_brandnew && format == PHAR_FORMAT_ZIP) {
              phar_data->is_zip = 1;
              phar_data->is_tar = 0;
       }

       if (fname == arch) {
              efree(arch);
              fname = save_fname;
       }

       if ((is_data && !phar_data->is_data) || (!is_data && phar_data->is_data)) {
              if (is_data) {
                     zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC,
                            "PharData class can only be used for non-executable tar and zip archives");
              } else {
                     zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC,
                            "Phar class can only be used for executable tar and zip archives");
              }
              efree(entry);
              return;
       }

       is_data = phar_data->is_data;

       if (!phar_data->is_persistent) {
              ++(phar_data->refcount);
       }

       phar_obj->arc.archive = phar_data;
       phar_obj->spl.oth_handler = &phar_spl_foreign_handler;

       if (entry) {
              fname_len = spprintf(&fname, 0, "phar://%s%s", phar_data->fname, entry);
              efree(entry);
       } else {
              fname_len = spprintf(&fname, 0, "phar://%s", phar_data->fname);
       }

       INIT_PZVAL(&arg1);
       ZVAL_STRINGL(&arg1, fname, fname_len, 0);
       INIT_PZVAL(&arg2);
       ZVAL_LONG(&arg2, flags);

       zend_call_method_with_2_params(&zobj, Z_OBJCE_P(zobj), 
              &spl_ce_RecursiveDirectoryIterator->constructor, "__construct", NULL, &arg1, &arg2);

       if (!phar_data->is_persistent) {
              phar_obj->arc.archive->is_data = is_data;
       } else if (!EG(exception)) {
              /* register this guy so we can modify if necessary */
              zend_hash_add(&PHAR_GLOBALS->phar_persist_map, (const char *) phar_obj->arc.archive, sizeof(phar_obj->arc.archive), (void *) &phar_obj, sizeof(phar_archive_object **), NULL);
       }

       phar_obj->spl.info_class = phar_ce_entry;
       efree(fname);
#endif /* HAVE_SPL */
}

Here is the call graph for this function:

PHP_METHOD ( Phar  ,
getSupportedSignatures   
)

Definition at line 1409 of file phar_object.c.

{
       if (zend_parse_parameters_none() == FAILURE) {
              return;
       }
       
       array_init(return_value);

       add_next_index_stringl(return_value, "MD5", 3, 1);
       add_next_index_stringl(return_value, "SHA-1", 5, 1);
#ifdef PHAR_HASH_OK
       add_next_index_stringl(return_value, "SHA-256", 7, 1);
       add_next_index_stringl(return_value, "SHA-512", 7, 1);
#endif
#if PHAR_HAVE_OPENSSL
       add_next_index_stringl(return_value, "OpenSSL", 7, 1);
#else
       if (zend_hash_exists(&module_registry, "openssl", sizeof("openssl"))) {
              add_next_index_stringl(return_value, "OpenSSL", 7, 1);
       }
#endif
}

Here is the call graph for this function:

PHP_METHOD ( Phar  ,
getSupportedCompression   
)

Definition at line 1436 of file phar_object.c.

{
       if (zend_parse_parameters_none() == FAILURE) {
              return;
       }
       
       array_init(return_value);
       phar_request_initialize(TSRMLS_C);

       if (PHAR_G(has_zlib)) {
              add_next_index_stringl(return_value, "GZ", 2, 1);
       }

       if (PHAR_G(has_bz2)) {
              add_next_index_stringl(return_value, "BZIP2", 5, 1);
       }
}

Here is the call graph for this function:

PHP_METHOD ( Phar  ,
unlinkArchive   
)

Definition at line 1458 of file phar_object.c.

{
       char *fname, *error, *zname, *arch, *entry;
       int fname_len, zname_len, arch_len, entry_len;
       phar_archive_data *phar;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &fname, &fname_len) == FAILURE) {
              RETURN_FALSE;
       }

       if (!fname_len) {
              zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Unknown phar archive \"\"");
              return;
       }

       if (FAILURE == phar_open_from_filename(fname, fname_len, NULL, 0, REPORT_ERRORS, &phar, &error TSRMLS_CC)) {
              if (error) {
                     zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Unknown phar archive \"%s\": %s", fname, error);
                     efree(error);
              } else {
                     zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "Unknown phar archive \"%s\"", fname);
              }
              return;
       }

       zname = zend_get_executed_filename(TSRMLS_C);
       zname_len = strlen(zname);

       if (zname_len > 7 && !memcmp(zname, "phar://", 7) && SUCCESS == phar_split_fname(zname, zname_len, &arch, &arch_len, &entry, &entry_len, 2, 0 TSRMLS_CC)) {
              if (arch_len == fname_len && !memcmp(arch, fname, arch_len)) {
                     zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "phar archive \"%s\" cannot be unlinked from within itself", fname);
                     efree(arch);
                     efree(entry);
                     return;
              }
              efree(arch);
              efree(entry);
       }

       if (phar->is_persistent) {
              zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "phar archive \"%s\" is in phar.cache_list, cannot unlinkArchive()", fname);
              return;
       }

       if (phar->refcount) {
              zend_throw_exception_ex(phar_ce_PharException, 0 TSRMLS_CC, "phar archive \"%s\" has open file handles or objects.  fclose() all file handles, and unset() all objects prior to calling unlinkArchive()", fname);
              return;
       }

       fname = estrndup(phar->fname, phar->fname_len);

       /* invalidate phar cache */
       PHAR_G(last_phar) = NULL;
       PHAR_G(last_phar_name) = PHAR_G(last_alias) = NULL;

       phar_archive_delref(phar TSRMLS_CC);
       unlink(fname);
       efree(fname);
       RETURN_TRUE;
}

Here is the call graph for this function:


Variable Documentation

zend_class_entry* phar_ce_archive [static]

Definition at line 25 of file phar_object.c.

zend_class_entry* phar_ce_data [static]

Definition at line 26 of file phar_object.c.

zend_class_entry* phar_ce_PharException [static]

Definition at line 27 of file phar_object.c.

Initial value:

Definition at line 5540 of file phar_object.c.

Definition at line 5444 of file phar_object.c.