[evolution-data-server] Reimplement camel_mime_parser_init_with_fd().



commit f44a3d2a547f9a76d68bc63bb13eaaf165455400
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed Feb 5 16:50:19 2014 -0500

    Reimplement camel_mime_parser_init_with_fd().
    
    Now creates a GUnixInputStream and hands it off to
    camel_mime_parser_init_with_input_stream().
    
    Removed functions:
    
      camel_mime_parser_fd()

 camel/Makefile.am                       |    2 +
 camel/camel-mime-parser.c               |   63 ++++++-------------------------
 camel/camel-mime-parser.h               |    3 -
 docs/reference/camel/camel-sections.txt |    1 -
 4 files changed, 14 insertions(+), 55 deletions(-)
---
diff --git a/camel/Makefile.am b/camel/Makefile.am
index 9643268..f1a00fc 100644
--- a/camel/Makefile.am
+++ b/camel/Makefile.am
@@ -57,6 +57,7 @@ libcamel_1_2_la_CPPFLAGS = \
        -DLOCALEDIR=\""$(localedir)"\" \
        -DCAMEL_COMPILATION \
        $(CAMEL_CFLAGS) \
+       $(GIO_UNIX_CFLAGS) \
        $(CODE_COVERAGE_CFLAGS) \
        $(NULL)
 
@@ -299,6 +300,7 @@ libcamel_1_2_la_LDFLAGS = -version-info $(LIBCAMEL_CURRENT):$(LIBCAMEL_REVISION)
 
 libcamel_1_2_la_LIBADD = \
        $(CAMEL_LIBS) \
+       $(GIO_UNIX_LIBS) \
        $(SOCKET_LIBS) \
        $(ICONV_LIBS) \
        $(REGEX_LIBS) \
diff --git a/camel/camel-mime-parser.c b/camel/camel-mime-parser.c
index 2785683..13f81e9 100644
--- a/camel/camel-mime-parser.c
+++ b/camel/camel-mime-parser.c
@@ -31,6 +31,8 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
+#include <gio/gunixinputstream.h>
+
 #include "camel-mempool.h"
 #include "camel-mime-filter.h"
 #include "camel-mime-parser.h"
@@ -71,8 +73,7 @@ struct _header_scan_state {
        gchar *outptr;
        gchar *outend;
 
-       gint fd;                        /* input for a fd input */
-       CamelStream *stream;            /* or for a stream */
+       CamelStream *stream;
        GInputStream *input_stream;
 
        gint ioerrno;           /* io error state */
@@ -142,7 +143,6 @@ struct _header_scan_filter {
 static void folder_scan_reset (struct _header_scan_state *s);
 static void folder_scan_step (struct _header_scan_state *s, gchar **databuffer, gsize *datalength);
 static void folder_scan_drop_step (struct _header_scan_state *s);
-static gint folder_scan_init_with_fd (struct _header_scan_state *s, gint fd);
 static gint folder_scan_init_with_stream (struct _header_scan_state *s, CamelStream *stream, GError **error);
 static struct _header_scan_state *folder_scan_init (void);
 static void folder_scan_close (struct _header_scan_state *s);
@@ -441,12 +441,16 @@ camel_mime_parser_from_line (CamelMimeParser *m)
  * Returns: Returns -1 on error.
  **/
 gint
-camel_mime_parser_init_with_fd (CamelMimeParser *m,
+camel_mime_parser_init_with_fd (CamelMimeParser *parser,
                                 gint fd)
 {
-       struct _header_scan_state *s = _PRIVATE (m);
+       GInputStream *input_stream;
+
+       input_stream = g_unix_input_stream_new (fd, TRUE);
+       camel_mime_parser_init_with_input_stream (parser, input_stream);
+       g_object_unref (input_stream);
 
-       return folder_scan_init_with_fd (s, fd);
+       return 0;
 }
 
 /**
@@ -897,28 +901,6 @@ camel_mime_parser_stream (CamelMimeParser *parser)
        return s->stream;
 }
 
-/**
- * camel_mime_parser_fd:
- * @parser: MIME parser object
- *
- * Return the file descriptor, if any, the parser has been
- * initialised with.
- *
- * Should not be read from unless the parser it to terminate,
- * or the seek offset can be reset before the next parse
- * step.
- *
- * Returns: The file descriptor or -1 if the parser
- * is reading from a stream or has not been initialised.
- **/
-gint
-camel_mime_parser_fd (CamelMimeParser *parser)
-{
-       struct _header_scan_state *s = _PRIVATE (parser);
-
-       return s->fd;
-}
-
 /* Return errno of the parser, incase any error occurred during processing */
 gint
 camel_mime_parser_errno (CamelMimeParser *parser)
@@ -953,12 +935,10 @@ folder_read (struct _header_scan_state *s)
        if (s->stream) {
                len = camel_stream_read (
                        s->stream, s->inbuf + inoffset, SCAN_BUF - inoffset, NULL, NULL);
-       } else if (s->input_stream != NULL) {
+       } else {
                len = g_input_stream_read (
                        s->input_stream, s->inbuf + inoffset,
                        SCAN_BUF - inoffset, NULL, NULL);
-       } else {
-               len = read (s->fd, s->inbuf + inoffset, SCAN_BUF - inoffset);
        }
        r (printf ("read %d bytes, offset = %d\n", len, inoffset));
        if (len >= 0) {
@@ -1013,7 +993,7 @@ folder_seek (struct _header_scan_state *s,
                        newoffset = -1;
                        errno = EINVAL;
                }
-       } else if (s->input_stream != NULL) {
+       } else {
                if (G_IS_SEEKABLE (s->input_stream)) {
                        /* NOTE: assumes whence seekable stream == whence libc, which is probably
                         * the case (or bloody well should've been) */
@@ -1025,8 +1005,6 @@ folder_seek (struct _header_scan_state *s,
                        newoffset = -1;
                        errno = EINVAL;
                }
-       } else {
-               newoffset = lseek (s->fd, offset, whence);
        }
 #ifdef PURIFY
        purify_watch_remove (inend_id);
@@ -1490,8 +1468,6 @@ folder_scan_close (struct _header_scan_state *s)
        g_free (s->outbuf);
        while (s->parts)
                folder_pull_part (s);
-       if (s->fd != -1)
-               close (s->fd);
        g_clear_object (&s->stream);
        g_clear_object (&s->input_stream);
        g_free (s);
@@ -1504,7 +1480,6 @@ folder_scan_init (void)
 
        s = g_malloc (sizeof (*s));
 
-       s->fd = -1;
        s->stream = NULL;
        s->input_stream = NULL;
        s->ioerrno = 0;
@@ -1559,10 +1534,6 @@ folder_scan_reset (struct _header_scan_state *s)
        s->inend = s->inbuf;
        s->inptr = s->inbuf;
        s->inend[0] = '\n';
-       if (s->fd != -1) {
-               close (s->fd);
-               s->fd = -1;
-       }
        g_clear_object (&s->stream);
        g_clear_object (&s->input_stream);
        s->ioerrno = 0;
@@ -1570,16 +1541,6 @@ folder_scan_reset (struct _header_scan_state *s)
 }
 
 static gint
-folder_scan_init_with_fd (struct _header_scan_state *s,
-                          gint fd)
-{
-       folder_scan_reset (s);
-       s->fd = fd;
-
-       return 0;
-}
-
-static gint
 folder_scan_init_with_stream (struct _header_scan_state *s,
                               CamelStream *stream,
                               GError **error)
diff --git a/camel/camel-mime-parser.h b/camel/camel-mime-parser.h
index 4651f51..7b5dd94 100644
--- a/camel/camel-mime-parser.h
+++ b/camel/camel-mime-parser.h
@@ -97,14 +97,11 @@ CamelMimeParser *camel_mime_parser_new (void);
 /* quick-fix for parser not erroring, we can find out if it had an error afterwards */
 gint           camel_mime_parser_errno (CamelMimeParser *parser);
 
-/* using an fd will be a little faster, but not much (over a simple stream) */
 gint           camel_mime_parser_init_with_fd (CamelMimeParser *m, gint fd);
 gint           camel_mime_parser_init_with_stream (CamelMimeParser *m, CamelStream *stream, GError **error);
 void           camel_mime_parser_init_with_input_stream (CamelMimeParser *parser, GInputStream 
*input_stream);
 
-/* get the stream or fd back of the parser */
 CamelStream    *camel_mime_parser_stream (CamelMimeParser *parser);
-gint           camel_mime_parser_fd (CamelMimeParser *parser);
 
 /* scan 'From' separators? */
 void camel_mime_parser_scan_from (CamelMimeParser *parser, gboolean scan_from);
diff --git a/docs/reference/camel/camel-sections.txt b/docs/reference/camel/camel-sections.txt
index f5de9c3..8f2c7c5 100644
--- a/docs/reference/camel/camel-sections.txt
+++ b/docs/reference/camel/camel-sections.txt
@@ -1227,7 +1227,6 @@ camel_mime_parser_init_with_fd
 camel_mime_parser_init_with_stream
 camel_mime_parser_init_with_input_stream
 camel_mime_parser_stream
-camel_mime_parser_fd
 camel_mime_parser_scan_from
 camel_mime_parser_scan_pre_from
 camel_mime_parser_set_header_regex


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]