]> www.fi.muni.cz Git - evince.git/commitdiff
Make sure load job doesn't finish successfully when the document is not
authorCarlos Garcia Campos <carlosgc@gnome.org>
Tue, 29 Apr 2008 19:09:39 +0000 (19:09 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Tue, 29 Apr 2008 19:09:39 +0000 (19:09 +0000)
2008-04-29  Carlos Garcia Campos  <carlosgc@gnome.org>

* backend/djvu/djvu-document-private.h:
* backend/djvu/djvu-links.c:
* backend/djvu/djvu-text.c:
* backend/djvu/djvu-document.c: (djvu_handle_events),
(djvu_wait_for_message), (djvu_document_load),
(document_get_page_size), (djvu_document_render),
(djvu_document_thumbnails_get_thumbnail),
(djvu_document_file_exporter_end):

Make sure load job doesn't finish successfully when the document
is not successfully decoded by libdjvu. Fixes bug #530202.

svn path=/trunk/; revision=3027

ChangeLog
backend/djvu/djvu-document-private.h
backend/djvu/djvu-document.c
backend/djvu/djvu-links.c
backend/djvu/djvu-text.c

index e4d89dab7381ade84fb416218b44f1a89c768cd0..b5ff07d62ac611f9e47a828f1474ed1afd31b14a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2008-04-29  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * backend/djvu/djvu-document-private.h:
+       * backend/djvu/djvu-links.c:
+       * backend/djvu/djvu-text.c:
+       * backend/djvu/djvu-document.c: (djvu_handle_events),
+       (djvu_wait_for_message), (djvu_document_load),
+       (document_get_page_size), (djvu_document_render),
+       (djvu_document_thumbnails_get_thumbnail),
+       (djvu_document_file_exporter_end):
+
+       Make sure load job doesn't finish successfully when the document
+       is not successfully decoded by libdjvu. Fixes bug #530202.
+       
 2008-04-27  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * configure.ac:
index 3e7deedffd8ec939b7ba140ae6681b49e2e15364..30810bbc43c70fc4a319b0a4e62c4cee8f4a1521 100644 (file)
@@ -45,6 +45,7 @@ struct _DjvuDocument {
 
 int  djvu_document_get_n_pages (EvDocument   *document);
 void djvu_handle_events        (DjvuDocument *djvu_document, 
-                               int           wait);
+                               int           wait,
+                               GError      **error);
 
 #endif /* __DJVU_DOCUMENT_INTERNAL_H__ */
index 392a7dc2514642467a84cbe097f54c832a33fbdc..5f59a8ea3ab34c27baffcf97b1de158515235c79 100644 (file)
@@ -68,8 +68,51 @@ EV_BACKEND_REGISTER_WITH_CODE (DjvuDocument, djvu_document,
      });
 
 
-void 
-djvu_handle_events (DjvuDocument *djvu_document, int wait)
+#define EV_DJVU_ERROR ev_djvu_error_quark ()
+
+static GQuark
+ev_djvu_error_quark (void)
+{
+       static GQuark q = 0;
+       if (q == 0)
+               q = g_quark_from_static_string ("ev-djvu-quark");
+       
+       return q;
+}
+
+static void
+handle_message (const ddjvu_message_t *msg, GError **error)
+{
+       switch (msg->m_any.tag) {
+               case DDJVU_ERROR: {
+                       gchar *error_str;
+                       
+                       if (msg->m_error.filename) {
+                               error_str = g_strdup_printf ("DjvuLibre error: %s:%d",
+                                                            msg->m_error.filename,
+                                                            msg->m_error.lineno);
+                       } else {
+                               error_str = g_strdup_printf ("DjvuLibre error: %s",
+                                                            msg->m_error.message);
+                       }
+                       
+                       if (error) {
+                               g_set_error (error, EV_DJVU_ERROR, 0, error_str);
+                       } else {
+                               g_warning (error_str);
+                       }
+                               
+                       g_free (error_str);
+                       return;
+                       }                                                    
+                       break;
+               default:
+                       break;
+       }
+}
+
+void
+djvu_handle_events (DjvuDocument *djvu_document, int wait, GError **error)
 {
        ddjvu_context_t *ctx = djvu_document->d_context;
        const ddjvu_message_t *msg;
@@ -78,23 +121,31 @@ djvu_handle_events (DjvuDocument *djvu_document, int wait)
                return;
 
        if (wait)
-               msg = ddjvu_message_wait (ctx);
+               ddjvu_message_wait (ctx);
 
        while ((msg = ddjvu_message_peek (ctx))) {
-               switch (msg->m_any.tag) {
-                       case DDJVU_ERROR:
-                               g_warning ("DjvuLibre error: %s", 
-                                          msg->m_error.message);
-                               if (msg->m_error.filename)
-                                       g_warning ("DjvuLibre error: %s:%d", 
-                                                  msg->m_error.filename,
-                                                  msg->m_error.lineno);
-                               break;
-                       default:
-                               break;
-               }
+               handle_message (msg, error);
+               ddjvu_message_pop (ctx);
+               if (error && *error)
+                       return;
+       }
+}
+
+static void
+djvu_wait_for_message (DjvuDocument *djvu_document, ddjvu_message_tag_t message, GError **error)
+{
+       ddjvu_context_t *ctx = djvu_document->d_context;
+       const ddjvu_message_t *msg;
+
+       ddjvu_message_wait (ctx);
+       while ((msg = ddjvu_message_peek (ctx)) && (msg->m_any.tag != message)) {
+               handle_message (msg, error);
                ddjvu_message_pop (ctx);
+               if (error && *error)
+                       return;
        }
+       if (msg && msg->m_any.tag == message)
+               ddjvu_message_pop (ctx);
 }
 
 static gboolean
@@ -106,6 +157,7 @@ djvu_document_load (EvDocument  *document,
        ddjvu_document_t *doc;
        gchar *filename;
        gboolean missing_files = FALSE;
+       GError *djvu_error = NULL;
 
        /* FIXME: We could actually load uris  */
        filename = g_filename_from_uri (uri, NULL, error);
@@ -124,8 +176,36 @@ djvu_document_load (EvDocument  *document,
 
        djvu_document->d_document = doc;
 
-       while (!ddjvu_document_decoding_done (djvu_document->d_document)) 
-               djvu_handle_events (djvu_document, TRUE);
+       djvu_wait_for_message (djvu_document, DDJVU_DOCINFO, &djvu_error);
+       if (djvu_error) {
+               g_set_error (error,
+                            EV_DOCUMENT_ERROR,
+                            EV_DOCUMENT_ERROR_INVALID,
+                            djvu_error->message);
+               g_error_free (djvu_error);
+               g_free (filename);
+               ddjvu_document_release (djvu_document->d_document);
+               djvu_document->d_document = NULL;
+
+               return FALSE;
+       }
+
+       if (ddjvu_document_decoding_error (djvu_document->d_document))
+               djvu_handle_events (djvu_document, TRUE, &djvu_error);
+
+       if (djvu_error) {
+               g_set_error (error,
+                            EV_DOCUMENT_ERROR,
+                            EV_DOCUMENT_ERROR_INVALID,
+                            djvu_error->message);
+               g_error_free (djvu_error);
+               g_free (filename);
+               ddjvu_document_release (djvu_document->d_document);
+               djvu_document->d_document = NULL;
+               
+               return FALSE;
+       }
+       
        g_free (djvu_document->uri);
        djvu_document->uri = g_strdup (uri);
 
@@ -204,10 +284,10 @@ document_get_page_size (DjvuDocument *djvu_document,
        ddjvu_status_t r;
        
        while ((r = ddjvu_document_get_pageinfo(djvu_document->d_document, page, &info)) < DDJVU_JOB_OK)
-               djvu_handle_events(djvu_document, TRUE);
+               djvu_handle_events(djvu_document, TRUE, NULL);
        
        if (r >= DDJVU_JOB_FAILED)
-               djvu_handle_events(djvu_document, TRUE);
+               djvu_handle_events(djvu_document, TRUE, NULL);
 
         *width = info.width * SCALE_FACTOR; 
         *height = info.height * SCALE_FACTOR;
@@ -245,7 +325,7 @@ djvu_document_render (EvDocument      *document,
        d_page = ddjvu_page_create_by_pageno (djvu_document->d_document, rc->page->index);
        
        while (!ddjvu_page_decoding_done (d_page))
-               djvu_handle_events(djvu_document, TRUE);
+               djvu_handle_events(djvu_document, TRUE, NULL);
 
        page_width = ddjvu_page_get_width (d_page) * rc->scale * SCALE_FACTOR + 0.5;
        page_height = ddjvu_page_get_height (d_page) * rc->scale * SCALE_FACTOR + 0.5;
@@ -435,7 +515,7 @@ djvu_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
        pixels = gdk_pixbuf_get_pixels (pixbuf);
        
        while (ddjvu_thumbnail_status (djvu_document->d_document, rc->page->index, 1) < DDJVU_JOB_OK)
-               djvu_handle_events(djvu_document, TRUE);
+               djvu_handle_events(djvu_document, TRUE, NULL);
                    
        ddjvu_thumbnail_render (djvu_document->d_document, rc->page->index, 
                                &thumb_width, &thumb_height,
@@ -504,7 +584,7 @@ djvu_document_file_exporter_end (EvFileExporter *exporter)
 
        ddjvu_job_t * job = ddjvu_document_print(djvu_document->d_document, fn, d_optc, d_optv);
        while (!ddjvu_job_done(job)) {  
-               djvu_handle_events (djvu_document, TRUE);
+               djvu_handle_events (djvu_document, TRUE, NULL);
        }
 
        fclose(fn); 
index 4e3578e6f45f98b69bb118a2be383aa4251d9be2..d54c410bb79586090f930a63ba4d4f0abce542fe 100644 (file)
@@ -344,7 +344,7 @@ djvu_links_has_document_links (EvDocumentLinks *document_links)
        miniexp_t outline;
 
        while ((outline = ddjvu_document_get_outline (djvu_document->d_document)) == miniexp_dummy)
-               djvu_handle_events (djvu_document, TRUE);
+               djvu_handle_events (djvu_document, TRUE, NULL);
 
        if (outline) {
                ddjvu_miniexp_release (djvu_document->d_document, outline);
@@ -367,10 +367,10 @@ djvu_links_get_links (EvDocumentLinks *document_links,
         ddjvu_pageinfo_t page_info;
 
        while ((page_annotations = ddjvu_document_get_pageanno (djvu_document->d_document, page)) == miniexp_dummy)
-               djvu_handle_events (djvu_document, TRUE);
+               djvu_handle_events (djvu_document, TRUE, NULL);
 
        while (ddjvu_document_get_pageinfo (djvu_document->d_document, page, &page_info) < DDJVU_JOB_OK)
-               djvu_handle_events(djvu_document, TRUE);
+               djvu_handle_events(djvu_document, TRUE, NULL);
 
        if (page_annotations) {
                hyperlinks = ddjvu_anno_get_hyperlinks (page_annotations);
@@ -417,7 +417,7 @@ djvu_links_get_links_model (EvDocumentLinks *document_links)
        miniexp_t outline = miniexp_nil;
 
        while ((outline = ddjvu_document_get_outline (djvu_document->d_document)) == miniexp_dummy)
-               djvu_handle_events (djvu_document, TRUE);
+               djvu_handle_events (djvu_document, TRUE, NULL);
 
        if (outline) {
                model = (GtkTreeModel *) gtk_tree_store_new (EV_DOCUMENT_LINKS_COLUMN_NUM_COLUMNS,
index 8c7c4aae673575fd186158269734032a9ceb446e..e87dbb123374171acd1d85bda87509dd12083d5b 100644 (file)
@@ -62,7 +62,7 @@ djvu_text_idle_callback (void *data)
                ddjvu_document_get_pagetext (djvu_document->d_document,
                                             djvu_text->search_page,
                                             "char")) == miniexp_dummy)
-               djvu_handle_events (djvu_document, TRUE);
+               djvu_handle_events (djvu_document, TRUE, NULL);
 
        if (page_text != miniexp_nil) {
                DjvuTextPage *page = djvu_text_page_new (page_text);
@@ -168,7 +168,7 @@ djvu_text_copy (DjvuDocument *djvu_document,
        while ((page_text =
                ddjvu_document_get_pagetext (djvu_document->d_document,
                                             page, "char")) == miniexp_dummy)
-               djvu_handle_events (djvu_document, TRUE);
+               djvu_handle_events (djvu_document, TRUE, NULL);
 
        if (page_text != miniexp_nil) {
                DjvuTextPage *page = djvu_text_page_new (page_text);