Back to index

php5  5.3.10
Classes | Functions
zip_source_zip.c File Reference
#include <stdlib.h>
#include <string.h>
#include "zipint.h"

Go to the source code of this file.

Classes

struct  read_zip

Functions

static ssize_t read_zip (void *st, void *data, size_t len, enum zip_source_cmd cmd)
 zip_source_zip (struct zip *za, struct zip *srcza, int srcidx, int flags, off_t start, off_t len)

Class Documentation

struct read_zip

Definition at line 41 of file zip_source_zip.c.

Collaboration diagram for read_zip:
Class Members
off_t len
off_t off
struct zip_file * zf

Function Documentation

static ssize_t read_zip ( void *  st,
void *  data,
size_t  len,
enum zip_source_cmd  cmd 
) [static]

Definition at line 119 of file zip_source_zip.c.

{
    struct read_zip *z;
    char b[8192], *buf;
    int i, n;

    z = (struct read_zip *)state;
    buf = (char *)data;

    switch (cmd) {
    case ZIP_SOURCE_OPEN:
       for (n=0; n<z->off; n+= i) {
           i = (z->off-n > sizeof(b) ? sizeof(b) : z->off-n);
           if ((i=zip_fread(z->zf, b, i)) < 0) {
              zip_fclose(z->zf);
              z->zf = NULL;
              return -1;
           }
       }
       return 0;
       
    case ZIP_SOURCE_READ:
       if (z->len != -1)
           n = len > z->len ? z->len : len;
       else
           n = len;
       

       if ((i=zip_fread(z->zf, buf, n)) < 0)
           return -1;

       if (z->len != -1)
           z->len -= i;

       return i;
       
    case ZIP_SOURCE_CLOSE:
       return 0;

    case ZIP_SOURCE_STAT:
       if (len < sizeof(z->st))
           return -1;
       len = sizeof(z->st);

       memcpy(data, &z->st, len);
       return len;

    case ZIP_SOURCE_ERROR:
       {
           int *e;

           if (len < sizeof(int)*2)
              return -1;

           e = (int *)data;
           zip_file_error_get(z->zf, e, e+1);
       }
       return sizeof(int)*2;

    case ZIP_SOURCE_FREE:
       zip_fclose(z->zf);
       free(z);
       return 0;

    default:
       ;
    }

    return -1;
}

Here is the call graph for this function:

zip_source_zip ( struct zip za,
struct zip srcza,
int  srcidx,
int  flags,
off_t  start,
off_t  len 
)

Definition at line 53 of file zip_source_zip.c.

{
    struct zip_error error;
    struct zip_source *zs;
    struct read_zip *p;

    /* XXX: ZIP_FL_RECOMPRESS */

    if (za == NULL)
       return NULL;

    if (srcza == NULL || start < 0 || len < -1 || srcidx < 0 || srcidx >= srcza->nentry) {
       _zip_error_set(&za->error, ZIP_ER_INVAL, 0);
       return NULL;
    }

    if ((flags & ZIP_FL_UNCHANGED) == 0
       && ZIP_ENTRY_DATA_CHANGED(srcza->entry+srcidx)) {
       _zip_error_set(&za->error, ZIP_ER_CHANGED, 0);
       return NULL;
    }

    if (len == 0)
       len = -1;

    if (start == 0 && len == -1 && (flags & ZIP_FL_RECOMPRESS) == 0)
       flags |= ZIP_FL_COMPRESSED;
    else
       flags &= ~ZIP_FL_COMPRESSED;

    if ((p=(struct read_zip *)malloc(sizeof(*p))) == NULL) {
       _zip_error_set(&za->error, ZIP_ER_MEMORY, 0);
       return NULL;
    }
       
    _zip_error_copy(&error, &srcza->error);
       
    if (zip_stat_index(srcza, srcidx, flags, &p->st) < 0
       || (p->zf=zip_fopen_index(srcza, srcidx, flags)) == NULL) {
       free(p);
       _zip_error_copy(&za->error, &srcza->error);
       _zip_error_copy(&srcza->error, &error);
       
       return NULL;
    }
    p->off = start;
    p->len = len;

    if ((flags & ZIP_FL_COMPRESSED) == 0) {
       p->st.size = p->st.comp_size = len;
       p->st.comp_method = ZIP_CM_STORE;
       p->st.crc = 0;
    }
    
    if ((zs=zip_source_function(za, read_zip, p)) == NULL) {
       free(p);
       return NULL;
    }

    return zs;
}

Here is the call graph for this function:

Here is the caller graph for this function: