Add optimized indexing capabilities for phone number values.
[platform/upstream/evolution-data-server.git] / camel / camel-stream-null.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*- */
2 /* camel-stream.c : abstract class for a stream */
3
4 /*
5  * Author:
6  *  Michael Zucchi <notzed@ximian.com>
7  *
8  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of version 2 of the GNU Lesser General Public
12  * License as published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
22  * USA
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28
29 #include <glib/gi18n-lib.h>
30
31 #include "camel-stream-null.h"
32
33 static void camel_stream_null_seekable_init (GSeekableIface *interface);
34
35 G_DEFINE_TYPE_WITH_CODE (CamelStreamNull, camel_stream_null, CAMEL_TYPE_STREAM,
36         G_IMPLEMENT_INTERFACE (G_TYPE_SEEKABLE, camel_stream_null_seekable_init))
37
38 static gssize
39 stream_null_write (CamelStream *stream,
40                    const gchar *buffer,
41                    gsize n,
42                    GCancellable *cancellable,
43                    GError **error)
44 {
45         CAMEL_STREAM_NULL (stream)->written += n;
46
47         return n;
48 }
49
50 static gboolean
51 stream_null_eos (CamelStream *stream)
52 {
53         return TRUE;
54 }
55
56 static goffset
57 stream_null_tell (GSeekable *seekable)
58 {
59         return 0;
60 }
61
62 static gboolean
63 stream_null_can_seek (GSeekable *seekable)
64 {
65         return TRUE;
66 }
67
68 static gboolean
69 stream_null_seek (GSeekable *seekable,
70                   goffset offset,
71                   GSeekType type,
72                   GCancellable *cancellable,
73                   GError **error)
74 {
75         if (type != G_SEEK_SET || offset != 0) {
76                 g_set_error_literal (
77                         error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
78                         _("Only reset to beginning is supported with CamelHttpStream"));
79                 return FALSE;
80         }
81
82         CAMEL_STREAM_NULL (seekable)->written = 0;
83
84         return TRUE;
85 }
86
87 static gboolean
88 stream_null_can_truncate (GSeekable *seekable)
89 {
90         return FALSE;
91 }
92
93 static gboolean
94 stream_null_truncate_fn (GSeekable *seekable,
95                          goffset offset,
96                          GCancellable *cancellable,
97                          GError **error)
98 {
99         /* XXX Don't bother translating this.  Camel never calls it. */
100         g_set_error_literal (
101                 error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
102                 "Truncation is not supported");
103
104         return FALSE;
105 }
106
107 static void
108 camel_stream_null_class_init (CamelStreamNullClass *class)
109 {
110         CamelStreamClass *stream_class;
111
112         stream_class = CAMEL_STREAM_CLASS (class);
113         stream_class->write = stream_null_write;
114         stream_class->eos = stream_null_eos;
115 }
116
117 static void
118 camel_stream_null_seekable_init (GSeekableIface *interface)
119 {
120         interface->tell = stream_null_tell;
121         interface->can_seek = stream_null_can_seek;
122         interface->seek = stream_null_seek;
123         interface->can_truncate = stream_null_can_truncate;
124         interface->truncate_fn = stream_null_truncate_fn;
125 }
126
127 static void
128 camel_stream_null_init (CamelStreamNull *stream_null)
129 {
130 }
131
132 /**
133  * camel_stream_null_new:
134  *
135  * Returns a null stream.  A null stream is always at eof, and
136  * always returns success for all reads and writes.
137  *
138  * Returns: a new #CamelStreamNull
139  **/
140 CamelStream *
141 camel_stream_null_new (void)
142 {
143         return g_object_new (CAMEL_TYPE_STREAM_NULL, NULL);
144 }