Ticket #289: xc_swap_file_wrapper.patch

File xc_swap_file_wrapper.patch, 3.0 KB (added by ferengee, 2 years ago)

file wrapper patch to 2.0.1 version

  • xcache.c

    diff --git a/xcache.c b/xcache.c
    index f7b0fad..0681f8b 100644
    a b static int xc_entry_data_php_init_md5(xc_cache_t *cache, xc_compiler_t *compiler 
    12141214    php_stream     *stream; 
    12151215    ulong           old_rsid = EG(regular_list).nNextFreeElement; 
    12161216 
     1217    php_stream_wrapper *wrapper = NULL;  
     1218    char *path_for_open = NULL;  
     1219    wrapper = php_stream_locate_url_wrapper(compiler->filename, &path_for_open, 0 TSRMLS_CC);  
     1220    TRACE("wrapper == &php_plain_files_wrapper => (%i) for file %s", wrapper == &php_plain_files_wrapper, compiler->filename); 
     1221   
    12171222    stream = php_stream_open_wrapper((char *) compiler->filename, "rb", USE_PATH | REPORT_ERRORS | ENFORCE_SAFE_MODE | STREAM_DISABLE_OPEN_BASEDIR, NULL); 
    12181223    if (!stream) { 
    12191224        return FAILURE; 
    static zend_op_array *xc_compile_file_cached(xc_compiler_t *compiler, zend_file_ 
    21352140    } 
    21362141} 
    21372142/* }}} */ 
     2143 
     2144static php_stream_wrapper *xc_swap_file_stream_wrapper(php_stream_wrapper *new_wrapper, zend_file_handle *h){ 
     2145    php_stream_wrapper *wrapper = NULL;  
     2146    char *path_for_open = NULL;  
     2147    char *protocol = "file"; 
     2148    int succes =0; 
     2149 
     2150    wrapper = php_stream_locate_url_wrapper( h->filename, &path_for_open, 0 TSRMLS_CC);  
     2151    succes = php_unregister_url_stream_wrapper_volatile(protocol TSRMLS_CC); 
     2152    TRACE("php_unregister_url_stream_wrapper => (%i)", succes == SUCCESS); 
     2153    succes = php_register_url_stream_wrapper_volatile(protocol, new_wrapper TSRMLS_DC); 
     2154    TRACE("php_register_url_stream_wrapper => (%i)", succes == SUCCESS); 
     2155    return wrapper; 
     2156} 
     2157 
    21382158static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) /* {{{ */ 
    21392159{ 
    21402160    xc_compiler_t compiler; 
    static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) / 
    21422162 
    21432163    assert(xc_initized); 
    21442164 
     2165    php_stream_wrapper *stream_wrapper = NULL;  
     2166    TRACE("using plain wrapper in xc_compile_file",0); 
     2167    stream_wrapper =  xc_swap_file_stream_wrapper(&php_plain_files_wrapper, h); 
     2168 
    21452169    TRACE("xc_compile_file: type=%d name=%s", h->type, h->filename ? h->filename : "NULL"); 
    21462170 
    21472171    if (!XG(cacher) 
    static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) / 
    21562180#endif 
    21572181     ) { 
    21582182        TRACE("%s", "cacher not enabled"); 
     2183        xc_swap_file_stream_wrapper(stream_wrapper, h); 
    21592184        return old_compile_file(h, type TSRMLS_CC); 
    21602185    } 
    21612186 
    static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) / 
    21652190    compiler.filename_len = strlen(compiler.filename); 
    21662191    if (xc_entry_php_init_key(&compiler TSRMLS_CC) != SUCCESS) { 
    21672192        TRACE("failed to init key for %s", compiler.filename); 
     2193        xc_swap_file_stream_wrapper(stream_wrapper, h); 
    21682194        return old_compile_file(h, type TSRMLS_CC); 
    21692195    } 
    21702196    /* }}} */ 
    static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) / 
    21722198    op_array = xc_compile_file_cached(&compiler, h, type TSRMLS_CC); 
    21732199 
    21742200    xc_entry_free_key_php(&compiler.new_entry TSRMLS_CC); 
    2175  
     2201    xc_swap_file_stream_wrapper(stream_wrapper, h); 
    21762202    return op_array; 
    21772203} 
    21782204/* }}} */