static int map_binfile_open(struct map_priv *m) { int *magic; struct zip_cd *first_cd; dbg(1,"file_create %s\n", m->filename); m->fi=file_create(m->filename); if (! m->fi) { dbg(0,"Failed to load '%s'\n", m->filename); return 0; } if (m->check_version) m->version=file_version(m->fi, m->check_version == 2); magic=(int *)file_data_read(m->fi, 0, 4); *magic = le32_to_cpu(*magic); if (*magic == zip_lfh_sig) { if ((m->eoc=binfile_read_eoc(m->fi)) && binfile_get_index(m) && (first_cd=binfile_read_cd(m, 0, 0))) { m->cde_size=sizeof(struct zip_cd)+first_cd->zipcfnl; m->zip_members=m->index_offset/m->cde_size+1; dbg(1,"cde_size %d\n", m->cde_size); dbg(1,"members %d\n",m->zip_members); file_data_free(m->fi, (unsigned char *)first_cd); } else { dbg(0,"invalid file format for '%s'\n", m->filename); return 0; } } else file_mmap(m->fi); file_data_free(m->fi, (unsigned char *)magic); m->cachedir="/tmp/navit"; return 1; }
static void map_binfile_close(struct map_priv *m) { file_data_free(m->fi, (unsigned char *)m->index_cd); file_data_free(m->fi, (unsigned char *)m->eoc); file_destroy(m->fi); }
static void do_server_request(struct server *sv, int connfd) { int ret; struct request *rq; struct file_data *data; data = file_data_init(); rq = request_init(connfd, data); if (!rq) { file_data_free(data); return; } if(cache_active ==1){ pthread_mutex_lock( &conditionMutex); struct hash_node *cache_stored; cache_stored= cache_lookup(data->file_name); if(cache_stored!=NULL){ // check if it populated in the cache{ data->file_buf = Malloc(cache_stored->data->file_size); strncpy(data->file_buf, cache_stored->data->file_buf, cache_stored->data->file_size); data->file_size =cache_stored->data->file_size; } else{ /* reads file, * fills data->file_buf with the file contents, * data->file_size with file size. */ pthread_mutex_unlock( &conditionMutex ); ret = request_readfile(rq); pthread_mutex_lock( &conditionMutex ); // need to renew the cache if(data->file_size<max_cache){ if(data->file_size <=(max_cache-cache_current_size) ){ cache_insert(data); } else{ cache_evict(data->file_size); cache_insert(data); } } } pthread_mutex_unlock( &conditionMutex ); } else{ ret = request_readfile(rq); if (!ret) goto out; } /* sends file to client */ request_sendfile(rq); out: request_destroy(rq); file_data_free(data); }
static void list__process_line (char *line, gpointer data) { FileData *fdata; FrCommand *comm = FR_COMMAND (data); FrCommandIso *comm_iso = FR_COMMAND_ISO (comm); char **fields; const char *name_field; g_return_if_fail (line != NULL); if (line[0] == 'd') /* Ignore directories. */ return; if (line[0] == 'D') { g_free (comm_iso->cur_path); comm_iso->cur_path = g_strdup (get_last_field (line, 4)); } else if (line[0] == '-') { /* Is file */ const char *last_field, *first_bracket; fdata = file_data_new (); fields = split_line (line, 8); fdata->size = g_ascii_strtoull (fields[4], NULL, 10); fdata->modified = mktime_from_string (fields[5], fields[6], fields[7]); g_strfreev (fields); /* Full path */ last_field = get_last_field (line, 9); first_bracket = strchr (last_field, ']'); if (first_bracket == NULL) { file_data_free (fdata); return; } name_field = eat_spaces (first_bracket + 1); if ((name_field == NULL) || (strcmp (name_field, ".") == 0) || (strcmp (name_field, "..") == 0)) { file_data_free (fdata); return; } if (comm_iso->cur_path[0] != '/') fdata->full_path = g_strstrip (g_strconcat ("/", comm_iso->cur_path, name_field, NULL)); else fdata->full_path = g_strstrip (g_strconcat (comm_iso->cur_path, name_field, NULL)); fdata->original_path = fdata->full_path; fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); fr_command_add_file (comm, fdata); } }
static char * binfile_extract(struct map_priv *m, char *dir, char *filename, int partial) { char *full,*fulld,*sep; unsigned char *start; int len,offset=m->index_offset; struct zip_cd *cd; struct zip_lfh *lfh; FILE *f; for (;;) { offset=binfile_search_cd(m, offset, filename, partial, 1); if (offset == -1) break; cd=binfile_read_cd(m, offset, -1); len=strlen(dir)+1+cd->zipcfnl+1; full=g_malloc(len); strcpy(full,dir); strcpy(full+strlen(full),"/"); strncpy(full+strlen(full),cd->zipcfn,cd->zipcfnl); full[len-1]='\0'; fulld=g_strdup(full); sep=strrchr(fulld, '/'); if (sep) { *sep='\0'; file_mkdir(fulld, 1); } if (full[len-2] != '/') { lfh=binfile_read_lfh(m->fi, cd->zipofst); start=binfile_read_content(m->fi, cd->zipofst, lfh); dbg(0,"fopen '%s'\n", full); f=fopen(full,"w"); fwrite(start, lfh->zipuncmp, 1, f); fclose(f); file_data_free(m->fi, start); file_data_free(m->fi, (unsigned char *)lfh); } file_data_free(m->fi, (unsigned char *)cd); g_free(fulld); g_free(full); if (! partial) break; } return g_strdup_printf("%s/%s",dir,filename); }
static void map_rect_destroy_binfile(struct map_rect_priv *mr) { while (pop_tile(mr)); file_data_free(mr->m->fi, (unsigned char *)(mr->tiles[0].start)); g_free(mr->url); g_free(mr); }
static int pop_tile(struct map_rect_priv *mr) { if (mr->tile_depth <= 1) return 0; file_data_free(mr->m->fi, (unsigned char *)(mr->t->start)); mr->t=&mr->tiles[--mr->tile_depth-1]; return 1; }
static void fr_command_cfile_list (FrCommand *comm) { FrCommandCFile *comm_cfile = FR_COMMAND_CFILE (comm); if (is_mime_type (comm->mime_type, "application/x-gzip")) { /* gzip let us known the uncompressed size */ fr_process_set_out_line_func (FR_COMMAND (comm)->process, list__process_line, comm); fr_process_begin_command (comm->process, "gzip"); fr_process_add_arg (comm->process, "-l"); fr_process_add_arg (comm->process, "-q"); fr_process_add_arg (comm->process, comm->filename); fr_process_end_command (comm->process); fr_process_start (comm->process); } else { /* ... other compressors do not support this feature so * simply use the archive size, suboptimal but there is no * alternative. */ FileData *fdata; char *filename; fdata = file_data_new (); filename = remove_extension_from_path (comm->filename); fdata->full_path = g_strconcat ("/", file_name_from_path (filename), NULL); g_free (filename); fdata->original_path = fdata->full_path + 1; fdata->link = NULL; fdata->size = get_file_size_for_path (comm->filename); fdata->modified = get_file_mtime_for_path (comm->filename); fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); comm_cfile->error.type = FR_PROC_ERROR_NONE; comm_cfile->error.status = 0; g_signal_emit_by_name (G_OBJECT (comm), "done", comm->action, &comm_cfile->error); } }
static void list__begin (gpointer data) { FrCommand7z *p7z_comm = data; if (p7z_comm->fdata != NULL) { file_data_free (p7z_comm->fdata); p7z_comm->fdata = NULL; } p7z_comm->list_started = FALSE; }
static int zipfile_to_tile(struct file *f, struct zip_cd *cd, struct tile *t) { char buffer[1024]; struct zip_lfh *lfh; char *zipfn; dbg(1,"enter %p %p %p\n", f, cd, t); dbg(1,"cd->zipofst=0x%x\n", cd->zipofst); t->start=NULL; lfh=binfile_read_lfh(f, cd->zipofst); zipfn=(char *)(file_data_read(f,cd->zipofst+sizeof(struct zip_lfh), lfh->zipfnln)); strncpy(buffer, zipfn, lfh->zipfnln); buffer[lfh->zipfnln]='\0'; t->start=(int *)binfile_read_content(f, cd->zipofst, lfh); t->end=t->start+lfh->zipuncmp/4; dbg(1,"0x%x '%s' %d %d,%d\n", lfh->ziplocsig, buffer, sizeof(*cd)+cd->zipcfnl, lfh->zipsize, lfh->zipuncmp); file_data_free(f, (unsigned char *)zipfn); file_data_free(f, (unsigned char *)lfh); return t->start != NULL; }
static struct zip_cd * binfile_read_cd(struct map_priv *m, int offset, int len) { struct zip_cd *cd; if (len == -1) { cd=(struct zip_cd *)file_data_read(m->fi,m->eoc->zipeofst+offset, sizeof(*cd)); cd_to_cpu(m->index_cd); len=cd->zipcfnl; file_data_free(m->fi,(unsigned char *)cd); } cd=(struct zip_cd *)file_data_read(m->fi,m->eoc->zipeofst+offset, sizeof(*cd)+len); if (cd) { cd_to_cpu(cd); dbg(1,"sig 0x%x\n", cd->zipcensig); if (cd->zipcensig != zip_cd_sig) { file_data_free(m->fi,(unsigned char *)cd); cd=NULL; } } return cd; }
void filelist_free(GList *list) { GList *work; work = list; while (work) { file_data_free((FileData *)work->data); work = work->next; } g_list_free(list); }
static void push_zipfile_tile(struct map_rect_priv *mr, int zipfile) { struct map_priv *m=mr->m; struct file *f=m->fi; struct tile t; struct zip_cd *cd=(struct zip_cd *)(file_data_read(f, m->eoc->zipeofst + zipfile*m->cde_size, sizeof(struct zip_cd))); cd_to_cpu(cd); dbg(1,"enter %p %d\n", mr, zipfile); t.zipfile_num=zipfile; if (zipfile_to_tile(f, cd, &t)) push_tile(mr, &t); file_data_free(f, (unsigned char *)cd); }
static struct zip_eoc * binfile_read_eoc(struct file *fi) { struct zip_eoc *eoc; eoc=(struct zip_eoc *)file_data_read(fi,fi->size-sizeof(struct zip_eoc), sizeof(struct zip_eoc)); if (eoc) { eoc_to_cpu(eoc); dbg(1,"sig 0x%x\n", eoc->zipesig); if (eoc->zipesig != zip_eoc_sig) { file_data_free(fi,(unsigned char *)eoc); eoc=NULL; } } return eoc; }
static struct zip_lfh * binfile_read_lfh(struct file *fi, int offset) { struct zip_lfh *lfh; lfh=(struct zip_lfh *)(file_data_read(fi,offset,sizeof(struct zip_lfh))); if (lfh) { lfh_to_cpu(lfh); if (lfh->ziplocsig != zip_lfh_sig) { file_data_free(fi,(unsigned char *)lfh); lfh=NULL; } } return lfh; }
static void list__process_line (char *line, gpointer data) { FileData *fdata; FrCommand *comm = FR_COMMAND (data); g_return_if_fail (line != NULL); if (strlen (line) == 0) return; if (! g_str_has_prefix (line, "Decompressed file size:")) return; fdata = file_data_new (); fdata->size = g_ascii_strtoull (_g_str_get_last_field (line, 4), NULL, 10); struct stat st; if (stat (comm->filename, &st) == 0) fdata->modified = st.st_mtim.tv_sec; else time(&(fdata->modified)); fdata->encrypted = FALSE; char *new_fname = g_strdup (_g_path_get_basename (comm->filename)); if (g_str_has_suffix (new_fname, ".lrz")) new_fname[strlen (new_fname) - 4] = '\0'; if (*new_fname == '/') { fdata->full_path = g_strdup (new_fname); fdata->original_path = fdata->full_path; } else { fdata->full_path = g_strconcat ("/", new_fname, NULL); fdata->original_path = fdata->full_path + 1; } fdata->path = _g_path_remove_level (fdata->full_path); fdata->name = new_fname; fdata->dir = FALSE; fdata->link = NULL; if (fdata->name == 0) file_data_free (fdata); else fr_archive_add_file (FR_ARCHIVE (comm), fdata); }
static void process_line (char *line, gpointer data) { FileData *fdata; FrCommand *comm = FR_COMMAND (data); char **fields; const char *name_field; g_return_if_fail (line != NULL); fdata = file_data_new (); fields = split_line_lha (line); fdata->size = g_ascii_strtoull (fields[2], NULL, 10); fdata->modified = mktime_from_string (fields[4], fields[5], fields[6]); g_strfreev (fields); /* Full path */ name_field = get_last_field_lha (line); if (name_field && *name_field == '/') { fdata->full_path = g_strdup (name_field); fdata->original_path = fdata->full_path; } else { fdata->full_path = g_strconcat ("/", name_field, NULL); fdata->original_path = fdata->full_path + 1; } fdata->link = NULL; fdata->dir = line[0] == 'd'; if (fdata->dir) fdata->name = dir_name_from_path (fdata->full_path); else fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); }
static int binfile_search_cd(struct map_priv *m, int offset, char *name, int partial, int skip) { int size=4096; int end=m->eoc->zipecsz; int len=strlen(name); struct zip_cd *cd; #if 0 dbg(0,"end=%d\n",end); #endif while (offset < end) { cd=(struct zip_cd *)(m->search_data+offset-m->search_offset); if (! m->search_data || m->search_offset > offset || offset-m->search_offset+sizeof(*cd) > m->search_size || offset-m->search_offset+sizeof(*cd)+cd->zipcfnl > m->search_size ) { #if 0 dbg(0,"reload %p %d %d\n", m->search_data, m->search_offset, offset); #endif if (m->search_data) file_data_free(m->fi,m->search_data); m->search_offset=offset; m->search_size=end-offset; if (m->search_size > size) m->search_size=size; m->search_data=file_data_read(m->fi,m->eoc->zipeofst+m->search_offset,m->search_size); cd=(struct zip_cd *)m->search_data; } #if 0 dbg(0,"offset=%d search_offset=%d search_size=%d search_data=%p cd=%p\n", offset, m->search_offset, m->search_size, m->search_data, cd); dbg(0,"offset=%d fn='%s'\n",offset,cd->zipcfn); #endif if (!skip && (partial || cd->zipcfnl == len) && !strncmp(cd->zipcfn, name, len)) return offset; skip=0; offset+=sizeof(*cd)+cd->zipcfnl+cd->zipcxtl+cd->zipccml; ; } return -1; }
GList *pan_list_tree(const gchar *path, SortType sort, gint ascend, gint ignore_symlinks) { GList *flist = NULL; GList *dlist = NULL; GList *result; GList *folders; filelist_read(path, &flist, &dlist); if (sort != SORT_NONE) { flist = filelist_sort(flist, sort, ascend); dlist = filelist_sort(dlist, sort, ascend); } result = flist; folders = dlist; while (folders) { FileData *fd; fd = folders->data; folders = g_list_remove(folders, fd); if (!pan_is_ignored(fd->path, ignore_symlinks) && filelist_read(fd->path, &flist, &dlist)) { if (sort != SORT_NONE) { flist = filelist_sort(flist, sort, ascend); dlist = filelist_sort(dlist, sort, ascend); } result = g_list_concat(result, flist); folders = g_list_concat(dlist, folders); } file_data_free(fd); } return result; }
static void list__process_line (char *line, gpointer data) { FrCommand *comm = FR_COMMAND (data); FileData *fdata; char **fields; char *filename; fdata = file_data_new (); fields = split_line (line, 2); if (strcmp (fields[1], "-1") != 0) fdata->size = g_ascii_strtoull (fields[1], NULL, 10); g_strfreev (fields); if (fdata->size == 0) fdata->size = get_file_size (comm->filename); filename = get_uncompressed_name_from_archive (comm, comm->filename); if (filename == NULL) filename = remove_extension_from_path (comm->filename); fdata->full_path = g_strconcat ("/", file_name_from_path (filename), NULL); g_free (filename); fdata->original_path = fdata->full_path + 1; fdata->link = NULL; fdata->modified = get_file_mtime_for_path (comm->filename); fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); }
unsigned char * file_data_read(struct file *file, long long offset, int size) { void *ret; if (file->special) return NULL; if (file->begin) return file->begin+offset; if (file->cache) { struct file_cache_id id={offset,size,file->name_id,0}; ret=cache_lookup(file_cache,&id); if (ret) return ret; ret=cache_insert_new(file_cache,&id,size); } else ret=g_malloc(size); lseek(file->fd, offset, SEEK_SET); if (read(file->fd, ret, size) != size) { file_data_free(file, ret); ret=NULL; } return ret; }
static void process_data_line (char *line, gpointer data) { FileData *fdata; FrCommand *comm = FR_COMMAND (data); char **fields; char **tmfields; struct tm tm = {0, }; const char *name; g_return_if_fail (line != NULL); if (line[0] == ' ') { /* This is the output of dpkg-deb -I */ process_metadata_line (line, comm); return; } fdata = file_data_new (); fields = split_line (line, 5); fdata->size = g_ascii_strtoull (fields[2], NULL, 10); tmfields = g_strsplit(fields[3], "-", 3); if (tmfields[2]) { tm.tm_year = atoi (tmfields[0]) - 1900; tm.tm_mon = atoi (tmfields[1]); tm.tm_mday = atoi (tmfields[2]); } g_strfreev (tmfields); tmfields = g_strsplit (fields[4], ":", 2); if (tmfields[1]) { tm.tm_hour = atoi (tmfields[0]); tm.tm_min = atoi (tmfields[1]); } g_strfreev (tmfields); fdata->modified = mktime (&tm); g_strfreev (fields); name = get_last_field (line, 6); fields = g_strsplit (name, " -> ", 2); fdata->dir = line[0] == 'd'; name = fields[0]; if (g_str_has_prefix (name, "./")) { /* Should generally be the case */ fdata->full_path = g_strdup (name + 1); fdata->original_path = fdata->full_path + 1; } else if (name[0] == '/') { fdata->full_path = g_strdup (name); fdata->original_path = fdata->full_path; } else { fdata->full_path = g_strconcat ("/", name, NULL); fdata->original_path = fdata->full_path + 1; } if (fdata->dir && (name[strlen (name) - 1] != '/')) { char *old_full_path = fdata->full_path; fdata->full_path = g_strconcat (old_full_path, "/", NULL); g_free (old_full_path); fdata->original_path = g_strdup (name); fdata->free_original_path = TRUE; } if (fields[1] != NULL) fdata->link = g_strdup (fields[1]); g_strfreev (fields); if (fdata->dir) fdata->name = dir_name_from_path (fdata->full_path); else fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); }
static void list__process_line (char *line, gpointer data) { FrCommand7z *self = FR_COMMAND_7Z (data); FrArchive *archive = FR_ARCHIVE (data); char **fields; FileData *fdata; g_return_if_fail (line != NULL); if (! self->list_started) { if (strncmp (line, "p7zip Version ", 14) == 0) { const char *ver_start; int ver_len; char version[256]; ver_start = _g_str_eat_spaces (line + 14); ver_len = strchr (ver_start, ' ') - ver_start; strncpy (version, ver_start, ver_len); version[ver_len] = 0; if (strcmp (version, "4.55") < 0) self->old_style = TRUE; else self->old_style = FALSE; } else if (self->old_style && (strncmp (line, "Listing archive: ", 17) == 0)) self->list_started = TRUE; else if (! self->old_style && (strcmp (line, "----------") == 0)) self->list_started = TRUE; else if (strncmp (line, "Multivolume = ", 14) == 0) { fields = g_strsplit (line, " = ", 2); archive->multi_volume = (strcmp (fields[1], "+") == 0); g_strfreev (fields); } return; } if (strcmp (line, "") == 0) { if (self->fdata != NULL) { if (self->fdata->original_path == NULL) { file_data_free (self->fdata); self->fdata = NULL; } else { fdata = self->fdata; if (fdata->dir) fdata->name = _g_path_get_dir_name (fdata->full_path); else fdata->name = g_strdup (_g_path_get_basename (fdata->full_path)); fdata->path = _g_path_remove_level (fdata->full_path); fr_archive_add_file (archive, fdata); self->fdata = NULL; } } return; } if (self->fdata == NULL) self->fdata = file_data_new (); fields = g_strsplit (line, " = ", 2); if (g_strv_length (fields) < 2) { g_strfreev (fields); return; } fdata = self->fdata; if (strcmp (fields[0], "Path") == 0) { fdata->free_original_path = TRUE; fdata->original_path = g_strdup (fields[1]); fdata->full_path = g_strconcat ((fdata->original_path[0] != '/') ? "/" : "", fdata->original_path, (fdata->dir && (fdata->original_path[strlen (fdata->original_path) - 1] != '/')) ? "/" : "", NULL); } else if (strcmp (fields[0], "Folder") == 0) { fdata->dir = (strcmp (fields[1], "+") == 0); } else if (strcmp (fields[0], "Size") == 0) { fdata->size = g_ascii_strtoull (fields[1], NULL, 10); } else if (strcmp (fields[0], "Modified") == 0) { char **modified_fields; modified_fields = g_strsplit (fields[1], " ", 2); if (modified_fields[0] != NULL) fdata->modified = mktime_from_string (modified_fields[0], modified_fields[1]); g_strfreev (modified_fields); } else if (strcmp (fields[0], "Encrypted") == 0) { if (strcmp (fields[1], "+") == 0) fdata->encrypted = TRUE; } else if (strcmp (fields[0], "Method") == 0) { if (strstr (fields[1], "AES") != NULL) fdata->encrypted = TRUE; } else if (strcmp (fields[0], "Attributes") == 0) { if (fields[1][0] == 'D') fdata->dir = TRUE; } g_strfreev (fields); }
static void process_line (char *line, gpointer data) { FileData *fdata; FrCommandAce *ace_comm = FR_COMMAND_ACE (data); FrCommand *comm = FR_COMMAND (data); char **fields = NULL; const char *field_name = NULL; g_return_if_fail (line != NULL); if (ace_comm->command_type == FR_ACE_COMMAND_UNKNOWN) { if (g_str_has_prefix (line, "UNACE")) { if (strstr (line, "public version") != NULL) ace_comm->command_type = FR_ACE_COMMAND_PUBLIC; else ace_comm->command_type = FR_ACE_COMMAND_NONFREE; } return; } if (! ace_comm->list_started) { if (ace_comm->command_type == FR_ACE_COMMAND_PUBLIC) { if (g_str_has_prefix (line, "Date")) ace_comm->list_started = TRUE; } else if (ace_comm->command_type == FR_ACE_COMMAND_NONFREE) { if (g_str_has_prefix (line, " Date")) ace_comm->list_started = TRUE; } return; } fdata = file_data_new (); if (ace_comm->command_type == FR_ACE_COMMAND_PUBLIC) fields = g_strsplit (line, "|", 6); else if (ace_comm->command_type == FR_ACE_COMMAND_NONFREE) fields = split_line (line, 5); if ((fields == NULL) || (fields[0] == NULL) || (n_fields (fields) < 5)) return; fdata->size = g_ascii_strtoull (fields[3], NULL, 10); fdata->modified = mktime_from_string (fields[0], fields[1]); if (ace_comm->command_type == FR_ACE_COMMAND_PUBLIC) { field_name = fields[5]; field_name = field_name + 1; } else if (ace_comm->command_type == FR_ACE_COMMAND_NONFREE) field_name = get_last_field (line, 6); g_assert (field_name != NULL); if (field_name[0] != '/') { fdata->full_path = g_strconcat ("/", field_name, NULL); fdata->original_path = fdata->full_path + 1; } else { fdata->full_path = g_strdup (field_name); fdata->original_path = fdata->full_path; } g_strfreev (fields); fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); }
static void list__process_line (char *line, gpointer data) { FileData *fdata; FrCommand *comm = FR_COMMAND (data); char **fields; const char *name_field; char *name; int ofs = 0; g_return_if_fail (line != NULL); fdata = file_data_new (); #ifdef __sun fields = split_line (line, 9); fdata->size = g_ascii_strtoull (fields[4], NULL, 10); fdata->modified = mktime_from_string (fields[5], fields[6], fields[8]); g_strfreev (fields); name_field = get_last_field (line, 10); #else /* !__sun */ /* Handle char and block device files */ if ((line[0] == 'c') || (line[0] == 'b')) { fields = split_line (line, 9); ofs = 1; fdata->size = 0; /* FIXME: We should also specify the content type */ } else { fields = split_line (line, 8); fdata->size = g_ascii_strtoull (fields[4], NULL, 10); } fdata->modified = mktime_from_string (fields[5+ofs], fields[6+ofs], fields[7+ofs]); g_strfreev (fields); name_field = get_last_field (line, 9+ofs); #endif /* !__sun */ fields = g_strsplit (name_field, " -> ", 2); if (fields[1] == NULL) { g_strfreev (fields); fields = g_strsplit (name_field, " link to ", 2); } fdata->dir = line[0] == 'd'; name = g_strcompress (fields[0]); if (*(fields[0]) == '/') { fdata->full_path = g_strdup (name); fdata->original_path = fdata->full_path; } else { fdata->full_path = g_strconcat ("/", name, NULL); fdata->original_path = fdata->full_path + 1; } if (fdata->dir && (name[strlen (name) - 1] != '/')) { char *old_full_path = fdata->full_path; fdata->full_path = g_strconcat (old_full_path, "/", NULL); g_free (old_full_path); fdata->original_path = g_strdup (name); fdata->free_original_path = TRUE; } g_free (name); if (fields[1] != NULL) fdata->link = g_strcompress (fields[1]); g_strfreev (fields); if (fdata->dir) fdata->name = dir_name_from_path (fdata->full_path); else fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); }
static void list__process_line (char *line, gpointer data) { FrCommand *comm = FR_COMMAND (data); FrCommandArj *arj_comm = FR_COMMAND_ARJ (comm); g_return_if_fail (line != NULL); if (! arj_comm->list_started) { if (strncmp (line, "--------", 8) == 0) { arj_comm->list_started = TRUE; arj_comm->line_no = 1; } return; } if (strncmp (line, "--------", 8) == 0) { arj_comm->list_started = FALSE; return; } if (g_regex_match (arj_comm->filename_line_regex, line, 0, NULL)) { /* Read the filename. */ FileData *fdata; const char *name_field; arj_comm->line_no = 1; arj_comm->fdata = fdata = file_data_new (); name_field = get_last_field (line, 2); if (*name_field == '/') { fdata->full_path = g_strdup (name_field); fdata->original_path = fdata->full_path; } else { fdata->full_path = g_strconcat ("/", name_field, NULL); fdata->original_path = fdata->full_path + 1; } fdata->link = NULL; fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); } else if (arj_comm->line_no == 2) { /* Read file size and date. */ FileData *fdata; char **fields; fdata = arj_comm->fdata; /* read file info. */ fields = split_line (line, 10); fdata->size = g_ascii_strtoull (fields[2], NULL, 10); fdata->modified = mktime_from_string (fields[5], fields[6]); if ((strcmp (fields[1], "MS-DOS") == 0) || (strcmp (fields[1], "WIN32") == 0)) fdata->encrypted = (g_ascii_strcasecmp (fields[7], "11") == 0); else fdata->encrypted = (g_ascii_strcasecmp (fields[9], "11") == 0); g_strfreev (fields); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); arj_comm->fdata = NULL; } arj_comm->line_no++; }
static void end_element (GMarkupParseContext *context, const gchar *element_name, gpointer user_data, GError **error) { ParseState *state = user_data; GError *my_error = NULL; if (strcmp (element_name, "gresource") == 0) { g_free (state->prefix); state->prefix = NULL; } else if (strcmp (element_name, "file") == 0) { gchar *file; gchar *real_file = NULL; gchar *key; FileData *data = NULL; char *tmp_file = NULL; char *tmp_file2 = NULL; file = state->string->str; key = file; if (state->alias) key = state->alias; if (state->prefix) key = g_build_path ("/", "/", state->prefix, key, NULL); else key = g_build_path ("/", "/", key, NULL); if (g_hash_table_lookup (state->table, key) != NULL) { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, _("File %s appears multiple times in the resource"), key); return; } if (sourcedirs != NULL) { real_file = find_file (file); if (real_file == NULL && state->collect_data) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Failed to locate “%s” in any source directory"), file); return; } } else { gboolean exists; exists = g_file_test (file, G_FILE_TEST_EXISTS); if (!exists && state->collect_data) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Failed to locate “%s” in current directory"), file); return; } } if (real_file == NULL) real_file = g_strdup (file); data = g_new0 (FileData, 1); data->filename = g_strdup (real_file); if (!state->collect_data) goto done; if (state->preproc_options) { gchar **options; guint i; gboolean xml_stripblanks = FALSE; gboolean to_pixdata = FALSE; options = g_strsplit (state->preproc_options, ",", -1); for (i = 0; options[i]; i++) { if (!strcmp (options[i], "xml-stripblanks")) xml_stripblanks = TRUE; else if (!strcmp (options[i], "to-pixdata")) to_pixdata = TRUE; else { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, _("Unknown processing option “%s”"), options[i]); g_strfreev (options); goto cleanup; } } g_strfreev (options); if (xml_stripblanks && xmllint != NULL) { int fd; GSubprocess *proc; tmp_file = g_strdup ("resource-XXXXXXXX"); if ((fd = g_mkstemp (tmp_file)) == -1) { int errsv = errno; g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv), _("Failed to create temp file: %s"), g_strerror (errsv)); g_free (tmp_file); tmp_file = NULL; goto cleanup; } close (fd); proc = g_subprocess_new (G_SUBPROCESS_FLAGS_STDOUT_SILENCE, error, xmllint, "--nonet", "--noblanks", "--output", tmp_file, real_file, NULL); g_free (real_file); real_file = NULL; if (!proc) goto cleanup; if (!g_subprocess_wait_check (proc, NULL, error)) { g_object_unref (proc); goto cleanup; } g_object_unref (proc); real_file = g_strdup (tmp_file); } if (to_pixdata) { int fd; GSubprocess *proc; if (gdk_pixbuf_pixdata == NULL) { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "to-pixbuf preprocessing requested but GDK_PIXBUF_PIXDATA " "not set and gdk-pixbuf-pixdata not found in path"); goto cleanup; } tmp_file2 = g_strdup ("resource-XXXXXXXX"); if ((fd = g_mkstemp (tmp_file2)) == -1) { int errsv = errno; g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv), _("Failed to create temp file: %s"), g_strerror (errsv)); g_free (tmp_file2); tmp_file2 = NULL; goto cleanup; } close (fd); proc = g_subprocess_new (G_SUBPROCESS_FLAGS_STDOUT_SILENCE, error, gdk_pixbuf_pixdata, real_file, tmp_file2, NULL); g_free (real_file); real_file = NULL; if (!g_subprocess_wait_check (proc, NULL, error)) { g_object_unref (proc); goto cleanup; } g_object_unref (proc); real_file = g_strdup (tmp_file2); } } if (!g_file_get_contents (real_file, &data->content, &data->size, &my_error)) { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, _("Error reading file %s: %s"), real_file, my_error->message); g_clear_error (&my_error); goto cleanup; } /* Include zero termination in content_size for uncompressed files (but not in size) */ data->content_size = data->size + 1; if (state->compressed) { GOutputStream *out = g_memory_output_stream_new (NULL, 0, g_realloc, g_free); GZlibCompressor *compressor = g_zlib_compressor_new (G_ZLIB_COMPRESSOR_FORMAT_ZLIB, 9); GOutputStream *out2 = g_converter_output_stream_new (out, G_CONVERTER (compressor)); if (!g_output_stream_write_all (out2, data->content, data->size, NULL, NULL, NULL) || !g_output_stream_close (out2, NULL, NULL)) { g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, _("Error compressing file %s"), real_file); goto cleanup; } g_free (data->content); data->content_size = g_memory_output_stream_get_size (G_MEMORY_OUTPUT_STREAM (out)); data->content = g_memory_output_stream_steal_data (G_MEMORY_OUTPUT_STREAM (out)); g_object_unref (compressor); g_object_unref (out); g_object_unref (out2); data->flags |= G_RESOURCE_FLAGS_COMPRESSED; } done: g_hash_table_insert (state->table, key, data); data = NULL; cleanup: /* Cleanup */ g_free (state->alias); state->alias = NULL; g_string_free (state->string, TRUE); state->string = NULL; g_free (state->preproc_options); state->preproc_options = NULL; g_free (real_file); if (tmp_file) { unlink (tmp_file); g_free (tmp_file); } if (tmp_file2) { unlink (tmp_file2); g_free (tmp_file2); } if (data != NULL) file_data_free (data); } }
static void process_line (char *line, gpointer data) { FileData *fdata; FrCommand *comm = FR_COMMAND (data); char **fields; int date_idx; char *field_date, *field_time, *field_size, *field_name; char *name; g_return_if_fail (line != NULL); date_idx = _g_line_get_index_from_pattern (line, "%n%n%n%n-%n%n-%n%n %n%n:%n%n"); if (date_idx < 0) return; fdata = file_data_new (); field_size = _g_line_get_prev_field (line, date_idx, 1); fdata->size = g_ascii_strtoull (field_size, NULL, 10); g_free (field_size); field_date = _g_line_get_next_field (line, date_idx, 1); field_time = _g_line_get_next_field (line, date_idx, 2); fdata->modified = mktime_from_string (field_date, field_time); g_free (field_date); g_free (field_time); /* Full path */ field_name = tar_get_last_field (line, date_idx, 3); fields = g_strsplit (field_name, " -> ", 2); if (fields[1] == NULL) { g_strfreev (fields); fields = g_strsplit (field_name, " link to ", 2); } name = g_strcompress (fields[0]); if (*name == '/') { fdata->full_path = g_strdup (name); fdata->original_path = fdata->full_path; } else { fdata->full_path = g_strconcat ("/", name, NULL); fdata->original_path = fdata->full_path + 1; } g_free (name); name = g_filename_from_utf8 (fdata->original_path, -1, NULL, NULL, NULL); if (name) fdata->original_path = name; if (fields[1] != NULL) fdata->link = g_strdup (fields[1]); g_strfreev (fields); g_free (field_name); fdata->dir = line[0] == 'd'; if (fdata->dir) fdata->name = _g_path_get_dir_name (fdata->full_path); else fdata->name = g_strdup (_g_path_get_basename (fdata->full_path)); fdata->path = _g_path_remove_level (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_archive_add_file (FR_ARCHIVE (comm), fdata); }
static void list__process_line (char *line, gpointer data) { FileData *fdata; FrCommand *comm = FR_COMMAND (data); char **fields; const char *name_field; gint line_l; g_return_if_fail (line != NULL); /* check whether unzip gave the empty archive warning. */ if (FR_COMMAND_ZIP (comm)->is_empty) return; line_l = strlen (line); if (line_l == 0) return; if (strcmp (line, EMPTY_ARCHIVE_WARNING) == 0) { FR_COMMAND_ZIP (comm)->is_empty = TRUE; return; } /* ignore lines that do not describe a file or a * directory. */ if ((line[0] != '?') && (line[0] != 'd') && (line[0] != '-')) return; /**/ fdata = file_data_new (); fields = split_line (line, 7); fdata->size = g_ascii_strtoull (fields[3], NULL, 10); fdata->modified = mktime_from_string (fields[6]); fdata->encrypted = (*fields[4] == 'B') || (*fields[4] == 'T'); g_strfreev (fields); /* Full path */ name_field = get_last_field (line, 8); if (*name_field == '/') { fdata->full_path = g_strdup (name_field); fdata->original_path = fdata->full_path; } else { fdata->full_path = g_strconcat ("/", name_field, NULL); fdata->original_path = fdata->full_path + 1; } fdata->link = NULL; fdata->dir = line[0] == 'd'; if (fdata->dir) fdata->name = dir_name_from_path (fdata->full_path); else fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); }
static void process_line (char *line, gpointer data) { FileData *fdata; FrCommand *comm = FR_COMMAND (data); char **fields; int date_idx; char *field_month, *field_day, *field_time, *field_year; char *field_size, *field_name; g_return_if_fail (line != NULL); fdata = file_data_new (); date_idx = file_list__get_index_from_pattern (line, "%c%c%c %a%n %n%n:%n%n %n%n%n%n"); field_size = file_list__get_prev_field (line, date_idx, 1); fdata->size = g_ascii_strtoull (field_size, NULL, 10); g_free (field_size); field_month = file_list__get_next_field (line, date_idx, 1); field_day = file_list__get_next_field (line, date_idx, 2); field_time = file_list__get_next_field (line, date_idx, 3); field_year = file_list__get_next_field (line, date_idx, 4); fdata->modified = mktime_from_string (field_time, field_day, field_month, field_year); g_free (field_day); g_free (field_month); g_free (field_year); g_free (field_time); /* Full path */ field_name = ar_get_last_field (line, date_idx, 5); fields = g_strsplit (field_name, " -> ", 2); if (fields[0] == NULL) { g_strfreev (fields); g_free (field_name); file_data_free (fdata); return; } if (fields[1] == NULL) { g_strfreev (fields); fields = g_strsplit (field_name, " link to ", 2); } if (*(fields[0]) == '/') { fdata->full_path = g_strdup (fields[0]); fdata->original_path = fdata->full_path; } else { fdata->full_path = g_strconcat ("/", fields[0], NULL); fdata->original_path = fdata->full_path + 1; } if (fields[1] != NULL) fdata->link = g_strdup (fields[1]); g_strfreev (fields); g_free (field_name); fdata->name = g_strdup (file_name_from_path (fdata->full_path)); fdata->path = remove_level_from_path (fdata->full_path); if (*fdata->name == 0) file_data_free (fdata); else fr_command_add_file (comm, fdata); }