Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-archive.c File Reference
#include "config.h"
#include "ev-archive.h"
#include <archive.h>
#include <archive_entry.h>
#include <unarr/unarr.h>
#include <gio/gio.h>
+ Include dependency graph for ev-archive.c:

Go to the source code of this file.

Data Structures

struct  _EvArchive
 

Macros

#define BUFFER_SIZE   (64 * 1024)
 

Functions

 G_DEFINE_TYPE (EvArchive, ev_archive, G_TYPE_OBJECT)
 
static void ev_archive_finalize (GObject *object)
 
static void ev_archive_class_init (EvArchiveClass *klass)
 
EvArchive * ev_archive_new (void)
 
static void libarchive_set_archive_type (EvArchive *archive, EvArchiveType archive_type)
 
EvArchiveType ev_archive_get_archive_type (EvArchive *archive)
 
gboolean ev_archive_set_archive_type (EvArchive *archive, EvArchiveType archive_type)
 
gboolean ev_archive_open_filename (EvArchive *archive, const char *path, GError **error)
 
static gboolean libarchive_read_next_header (EvArchive *archive, GError **error)
 
gboolean ev_archive_read_next_header (EvArchive *archive, GError **error)
 
const char * ev_archive_get_entry_pathname (EvArchive *archive)
 
gint64 ev_archive_get_entry_size (EvArchive *archive)
 
gssize ev_archive_read_data (EvArchive *archive, void *buf, gsize count, GError **error)
 
void ev_archive_reset (EvArchive *archive)
 
static void ev_archive_init (EvArchive *archive)
 

Macro Definition Documentation

#define BUFFER_SIZE   (64 * 1024)

Definition at line 28 of file ev-archive.c.

Function Documentation

static void ev_archive_class_init ( EvArchiveClass *  klass)
static

Definition at line 68 of file ev-archive.c.

69 {
70  GObjectClass *object_class = (GObjectClass *) klass;
71 
72  object_class->finalize = ev_archive_finalize;
73 }
static void ev_archive_finalize ( GObject *  object)
static

Definition at line 46 of file ev-archive.c.

47 {
48  EvArchive *archive = EV_ARCHIVE (object);
49 
50  switch (archive->type) {
52  g_clear_pointer (&archive->unarr, ar_close_archive);
53  g_clear_pointer (&archive->unarr_stream, ar_close);
54  break;
56  case EV_ARCHIVE_TYPE_7Z:
58  g_clear_pointer (&archive->libar, archive_free);
59  break;
60  default:
61  break;
62  }
63 
64  G_OBJECT_CLASS (ev_archive_parent_class)->finalize (object);
65 }

+ Here is the caller graph for this function:

EvArchiveType ev_archive_get_archive_type ( EvArchive *  archive)

Definition at line 97 of file ev-archive.c.

98 {
99  g_return_val_if_fail (EV_IS_ARCHIVE (archive), EV_ARCHIVE_TYPE_NONE);
100 
101  return archive->type;
102 }
const char* ev_archive_get_entry_pathname ( EvArchive *  archive)

Definition at line 221 of file ev-archive.c.

222 {
223  g_return_val_if_fail (EV_IS_ARCHIVE (archive), NULL);
224  g_return_val_if_fail (archive->type != EV_ARCHIVE_TYPE_NONE, NULL);
225 
226  switch (archive->type) {
228  g_assert_not_reached ();
229  case EV_ARCHIVE_TYPE_RAR:
230  g_return_val_if_fail (archive->unarr != NULL, NULL);
231  return ar_entry_get_name (archive->unarr);
232  case EV_ARCHIVE_TYPE_ZIP:
233  case EV_ARCHIVE_TYPE_7Z:
234  case EV_ARCHIVE_TYPE_TAR:
235  g_return_val_if_fail (archive->libar_entry != NULL, NULL);
236  return archive_entry_pathname (archive->libar_entry);
237  }
238 
239  return NULL;
240 }

+ Here is the caller graph for this function:

gint64 ev_archive_get_entry_size ( EvArchive *  archive)

Definition at line 243 of file ev-archive.c.

244 {
245  g_return_val_if_fail (EV_IS_ARCHIVE (archive), -1);
246  g_return_val_if_fail (archive->type != EV_ARCHIVE_TYPE_NONE, -1);
247 
248  switch (archive->type) {
249  case EV_ARCHIVE_TYPE_RAR:
250  g_return_val_if_fail (archive->unarr != NULL, -1);
251  return ar_entry_get_size (archive->unarr);
253  g_assert_not_reached ();
254  case EV_ARCHIVE_TYPE_ZIP:
255  case EV_ARCHIVE_TYPE_7Z:
256  case EV_ARCHIVE_TYPE_TAR:
257  g_return_val_if_fail (archive->libar_entry != NULL, -1);
258  return archive_entry_size (archive->libar_entry);
259  }
260 
261  return -1;
262 }

+ Here is the caller graph for this function:

static void ev_archive_init ( EvArchive *  archive)
static

Definition at line 325 of file ev-archive.c.

326 {
327 }
EvArchive* ev_archive_new ( void  )

Definition at line 76 of file ev-archive.c.

77 {
78  return g_object_new (EV_TYPE_ARCHIVE, NULL);
79 }

+ Here is the caller graph for this function:

gboolean ev_archive_open_filename ( EvArchive *  archive,
const char *  path,
GError **  error 
)

Definition at line 128 of file ev-archive.c.

131 {
132  int r;
133 
134  g_return_val_if_fail (EV_IS_ARCHIVE (archive), FALSE);
135  g_return_val_if_fail (archive->type != EV_ARCHIVE_TYPE_NONE, FALSE);
136  g_return_val_if_fail (path != NULL, FALSE);
137 
138  switch (archive->type) {
140  g_assert_not_reached ();
141  case EV_ARCHIVE_TYPE_RAR:
142  archive->unarr_stream = ar_open_file (path);
143  if (archive->unarr_stream == NULL) {
144  g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
145  "Error opening archive");
146  return FALSE;
147  }
148  archive->unarr = ar_open_rar_archive (archive->unarr_stream);
149  if (archive->unarr == NULL) {
150  g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
151  "Error opening RAR archive");
152  return FALSE;
153  }
154  return TRUE;
155  case EV_ARCHIVE_TYPE_ZIP:
156  case EV_ARCHIVE_TYPE_7Z:
157  case EV_ARCHIVE_TYPE_TAR:
158  r = archive_read_open_filename (archive->libar, path, BUFFER_SIZE);
159  if (r != ARCHIVE_OK) {
160  g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
161  "Error opening archive: %s", archive_error_string (archive->libar));
162  return FALSE;
163  }
164  return TRUE;
165  }
166 
167  return FALSE;
168 }

+ Here is the caller graph for this function:

gssize ev_archive_read_data ( EvArchive *  archive,
void *  buf,
gsize  count,
GError **  error 
)

Definition at line 265 of file ev-archive.c.

269 {
270  gssize r = -1;
271 
272  g_return_val_if_fail (EV_IS_ARCHIVE (archive), -1);
273  g_return_val_if_fail (archive->type != EV_ARCHIVE_TYPE_NONE, -1);
274 
275  switch (archive->type) {
276  case EV_ARCHIVE_TYPE_RAR:
277  g_return_val_if_fail (archive->unarr != NULL, -1);
278  if (!ar_entry_uncompress (archive->unarr, buf, count)) {
279  g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
280  "Failed to decompress RAR data");
281  return -1;
282  }
283  r = count;
284  break;
286  g_assert_not_reached ();
287  case EV_ARCHIVE_TYPE_ZIP:
288  case EV_ARCHIVE_TYPE_7Z:
289  case EV_ARCHIVE_TYPE_TAR:
290  g_return_val_if_fail (archive->libar_entry != NULL, -1);
291  r = archive_read_data (archive->libar, buf, count);
292  if (r < 0) {
293  g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
294  "Failed to decompress data: %s", archive_error_string (archive->libar));
295  }
296  break;
297  }
298 
299  return r;
300 }

+ Here is the caller graph for this function:

gboolean ev_archive_read_next_header ( EvArchive *  archive,
GError **  error 
)

Definition at line 200 of file ev-archive.c.

202 {
203  g_return_val_if_fail (EV_IS_ARCHIVE (archive), FALSE);
204  g_return_val_if_fail (archive->type != EV_ARCHIVE_TYPE_NONE, FALSE);
205 
206  switch (archive->type) {
208  g_assert_not_reached ();
209  case EV_ARCHIVE_TYPE_RAR:
210  return ar_parse_entry (archive->unarr);
211  case EV_ARCHIVE_TYPE_ZIP:
212  case EV_ARCHIVE_TYPE_7Z:
213  case EV_ARCHIVE_TYPE_TAR:
214  return libarchive_read_next_header (archive, error);
215  }
216 
217  return FALSE;
218 }

+ Here is the caller graph for this function:

void ev_archive_reset ( EvArchive *  archive)

Definition at line 303 of file ev-archive.c.

304 {
305  g_return_if_fail (EV_IS_ARCHIVE (archive));
306  g_return_if_fail (archive->type != EV_ARCHIVE_TYPE_NONE);
307 
308  switch (archive->type) {
309  case EV_ARCHIVE_TYPE_RAR:
310  g_clear_pointer (&archive->unarr, ar_close_archive);
311  g_clear_pointer (&archive->unarr_stream, ar_close);
312  break;
313  case EV_ARCHIVE_TYPE_ZIP:
314  case EV_ARCHIVE_TYPE_7Z:
315  case EV_ARCHIVE_TYPE_TAR:
316  g_clear_pointer (&archive->libar, archive_free);
317  libarchive_set_archive_type (archive, archive->type);
318  break;
319  default:
320  g_assert_not_reached ();
321  }
322 }

+ Here is the caller graph for this function:

gboolean ev_archive_set_archive_type ( EvArchive *  archive,
EvArchiveType  archive_type 
)

Definition at line 105 of file ev-archive.c.

107 {
108  g_return_val_if_fail (EV_IS_ARCHIVE (archive), FALSE);
109  g_return_val_if_fail (archive->type == EV_ARCHIVE_TYPE_NONE, FALSE);
110 
111  switch (archive_type) {
112  case EV_ARCHIVE_TYPE_RAR:
113  archive->type = archive_type;
114  break;
115  case EV_ARCHIVE_TYPE_ZIP:
116  case EV_ARCHIVE_TYPE_7Z:
117  case EV_ARCHIVE_TYPE_TAR:
118  libarchive_set_archive_type (archive, archive_type);
119  break;
120  default:
121  g_assert_not_reached ();
122  }
123 
124  return TRUE;
125 }

+ Here is the caller graph for this function:

G_DEFINE_TYPE ( EvArchive  ,
ev_archive  ,
G_TYPE_OBJECT   
)
static gboolean libarchive_read_next_header ( EvArchive *  archive,
GError **  error 
)
static

Definition at line 171 of file ev-archive.c.

173 {
174  while (1) {
175  int r;
176 
177  r = archive_read_next_header (archive->libar, &archive->libar_entry);
178  if (r != ARCHIVE_OK) {
179  if (r != ARCHIVE_EOF)
180  g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
181  "Error reading archive: %s", archive_error_string (archive->libar));
182  return FALSE;
183  }
184 
185  if (archive_entry_filetype (archive->libar_entry) != AE_IFREG) {
186  g_debug ("Skipping '%s' as it's not a regular file",
187  archive_entry_pathname (archive->libar_entry));
188  continue;
189  }
190 
191  g_debug ("At header for file '%s'", archive_entry_pathname (archive->libar_entry));
192 
193  break;
194  }
195 
196  return TRUE;
197 }

+ Here is the caller graph for this function:

static void libarchive_set_archive_type ( EvArchive *  archive,
EvArchiveType  archive_type 
)
static

Definition at line 82 of file ev-archive.c.

84 {
85  archive->type = archive_type;
86  archive->libar = archive_read_new ();
87 
88  if (archive_type == EV_ARCHIVE_TYPE_ZIP)
89  archive_read_support_format_zip (archive->libar);
90  else if (archive_type == EV_ARCHIVE_TYPE_7Z)
91  archive_read_support_format_7zip (archive->libar);
92  else if (archive_type == EV_ARCHIVE_TYPE_TAR)
93  archive_read_support_format_tar (archive->libar);
94 }

+ Here is the caller graph for this function: