/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; -*- */ /* camel-data-wrapper.c : Abstract class for a data_wrapper */ /* * * Authors: Bertrand Guiheneuf * * Copyright 1999, 2000 Helix Code, Inc. (http://www.helixcode.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #include #include "camel-data-wrapper.h" #include "camel-mime-utils.h" #include "camel-stream.h" #include "camel-exception.h" #include #define d(x) static CamelObjectClass *parent_class = NULL; /* Returns the class for a CamelDataWrapper */ #define CDW_CLASS(so) CAMEL_DATA_WRAPPER_CLASS (CAMEL_OBJECT_GET_CLASS(so)) static int construct_from_stream(CamelDataWrapper *, CamelStream *); static int write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream); static void set_mime_type (CamelDataWrapper *data_wrapper, const gchar *mime_type); static gchar *get_mime_type (CamelDataWrapper *data_wrapper); static CamelContentType *get_mime_type_field (CamelDataWrapper *data_wrapper); static void set_mime_type_field (CamelDataWrapper *data_wrapper, CamelContentType *mime_type); static void camel_data_wrapper_class_init (CamelDataWrapperClass *camel_data_wrapper_class) { parent_class = camel_type_get_global_classfuncs (camel_object_get_type ()); /* virtual method definition */ camel_data_wrapper_class->write_to_stream = write_to_stream; camel_data_wrapper_class->set_mime_type = set_mime_type; camel_data_wrapper_class->get_mime_type = get_mime_type; camel_data_wrapper_class->get_mime_type_field = get_mime_type_field; camel_data_wrapper_class->set_mime_type_field = set_mime_type_field; camel_data_wrapper_class->construct_from_stream = construct_from_stream; } static void camel_data_wrapper_init (gpointer object, gpointer klass) { CamelDataWrapper *camel_data_wrapper = CAMEL_DATA_WRAPPER (object); camel_data_wrapper->mime_type = header_content_type_new ("application", "octet-stream"); camel_data_wrapper->offline = FALSE; } static void camel_data_wrapper_finalize (CamelObject *object) { CamelDataWrapper *camel_data_wrapper = CAMEL_DATA_WRAPPER (object); if (camel_data_wrapper->mime_type) header_content_type_unref (camel_data_wrapper->mime_type); if (camel_data_wrapper->stream) camel_object_unref (CAMEL_OBJECT (camel_data_wrapper->stream)); } CamelType camel_data_wrapper_get_type (void) { static CamelType camel_data_wrapper_type = CAMEL_INVALID_TYPE; if (camel_data_wrapper_type == CAMEL_INVALID_TYPE) { camel_data_wrapper_type = camel_type_register (CAMEL_OBJECT_TYPE, "CamelDataWrapper", sizeof (CamelDataWrapper), sizeof (CamelDataWrapperClass), (CamelObjectClassInitFunc) camel_data_wrapper_class_init, NULL, (CamelObjectInitFunc) camel_data_wrapper_init, (CamelObjectFinalizeFunc) camel_data_wrapper_finalize); } return camel_data_wrapper_type; } static int write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) { if (data_wrapper->stream == NULL) { return -1; } if (camel_stream_reset (data_wrapper->stream) == -1) return -1; return camel_stream_write_to_stream (data_wrapper->stream, stream); } CamelDataWrapper * camel_data_wrapper_new(void) { return (CamelDataWrapper *)camel_object_new(camel_data_wrapper_get_type()); } /** * camel_data_wrapper_write_to_stream: * @data_wrapper: a data wrapper * @stream: stream for data to be written to * @ex: a CamelException * * Writes the data content to @stream in a machine-independent format * appropriate for the data. It should be possible to construct an * equivalent data wrapper object later by passing this stream to * camel_data_construct_from_stream(). * * Return value: the number of bytes written, or -1 if an error occurs. **/ int camel_data_wrapper_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) { g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper), -1); g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1); return CDW_CLASS (data_wrapper)->write_to_stream (data_wrapper, stream); } static int construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) { if (data_wrapper->stream) camel_object_unref((CamelObject *)data_wrapper->stream); data_wrapper->stream = stream; camel_object_ref (CAMEL_OBJECT (stream)); return 0; } /** * camel_data_wrapper_construct_from_stream: * @data_wrapper: a data wrapper * @stream: A stream that can be read from. * * Constructs the content of the data wrapper from the * supplied @stream. * * Return value: -1 on error. **/ int camel_data_wrapper_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream) { g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper), -1); g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1); return CDW_CLASS (data_wrapper)->construct_from_stream (data_wrapper, stream); } static void set_mime_type (CamelDataWrapper *data_wrapper, const gchar *mime_type) { if (data_wrapper->mime_type) header_content_type_unref (data_wrapper->mime_type); data_wrapper->mime_type = header_content_type_decode (mime_type); } /** * camel_data_wrapper_set_mime_type: * @data_wrapper: a data wrapper * @mime_type: the text representation of a MIME type * * This sets the data wrapper's MIME type. * It might fail, but you won't know. It will allow you to set * Content-Type parameters on the data wrapper, which are meaningless. * You should not be allowed to change the MIME type of a data wrapper * that contains data, or at least, if you do, it should invalidate the * data. **/ void camel_data_wrapper_set_mime_type (CamelDataWrapper *data_wrapper, const gchar *mime_type) { g_return_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper)); g_return_if_fail (mime_type != NULL); CDW_CLASS (data_wrapper)->set_mime_type (data_wrapper, mime_type); } static gchar * get_mime_type (CamelDataWrapper *data_wrapper) { return header_content_type_simple (data_wrapper->mime_type); } /** * camel_data_wrapper_get_mime_type: * @data_wrapper: a data wrapper * * Return value: the text form of the data wrapper's MIME type, * which the caller must free. **/ gchar * camel_data_wrapper_get_mime_type (CamelDataWrapper *data_wrapper) { g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper), NULL); return CDW_CLASS (data_wrapper)->get_mime_type (data_wrapper); } static CamelContentType * get_mime_type_field (CamelDataWrapper *data_wrapper) { return data_wrapper->mime_type; } /** * camel_data_wrapper_get_mime_type_field: * @data_wrapper: a data wrapper * * Return value: the parsed form of the data wrapper's MIME type **/ CamelContentType * camel_data_wrapper_get_mime_type_field (CamelDataWrapper *data_wrapper) { g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper), NULL); return CDW_CLASS (data_wrapper)->get_mime_type_field (data_wrapper); } /** * camel_data_wrapper_set_mime_type_field: * @data_wrapper: a data wrapper * @mime_type: the parsed representation of a MIME type * * This sets the data wrapper's MIME type. It suffers from the same * flaws as camel_data_wrapper_set_mime_type. **/ static void set_mime_type_field (CamelDataWrapper *data_wrapper, CamelContentType *mime_type) { g_return_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper)); g_return_if_fail (mime_type != NULL); if (data_wrapper->mime_type) header_content_type_unref (data_wrapper->mime_type); data_wrapper->mime_type = mime_type; if (mime_type) header_content_type_ref (data_wrapper->mime_type); } void camel_data_wrapper_set_mime_type_field (CamelDataWrapper *data_wrapper, CamelContentType *mime_type) { CDW_CLASS (data_wrapper)->set_mime_type_field (data_wrapper, mime_type); } /** * camel_data_wrapper_is_offline: * @data_wrapper: a data wrapper * * Return value: whether @data_wrapper is "offline" (data stored * remotely) or not. Some optional code paths may choose to not * operate on offline data. **/ gboolean camel_data_wrapper_is_offline (CamelDataWrapper *data_wrapper) { return data_wrapper->offline; } an class='deletions'>-2/+2 * KDE/FreeBSD team presents KDE SC 4.12.3 and KDE Workspace 4.11.7!makc2014-03-051-2/+2 * KDE/FreeBSD team presents KDE SC 4.12.2 and KDE Workspace 4.11.6!makc2014-02-184-19/+40 * Add NO_STAGE all over the place in preparation for the staging support (cat: ...bapt2013-09-211-0/+1 * Finish fixing the kde4-l10nbapt2013-07-101-0/+1 * KDE4 l10n fixes.rakuco2013-07-102-3/+1 * Update the KDE Software Compilation to 4.10.5.rakuco2013-07-051-2/+2 * Update to KDE SC 4.10.4, proudly presented by the KDE on FreeBSD team.rakuco2013-07-031-2/+2 * KDE/FreeBSD team presents KDE SC 4.10.3 ports!makc2013-05-192-4/+3 * KDE/FreeBSD team presents KDE SC 4.10.1 ports!makc2013-03-273-16/+32 * KDE/FreeBSD team presents KDE SC 4.9.5 ports!makc2013-02-043-27/+27 * KDE/FreeBSD team presents KDE SC 4.8.4, probably the last release in 4.8.x se...makc2012-06-152-3/+2 * - update png to 1.5.10dinoex2012-06-011-0/+1 * KDE/FreeBSD team presents long awaited KDE SC 4.8.3!makc2012-05-253-13/+22 * - Bump PORTREVISION to chase the update of multimedia/libvpxashish2012-02-161-0/+1 * The KDE/FreeBSD team is pleased to announce KDE SC 4.7.4, whichavilla2012-01-251-2/+2 * The KDE on FreeBSD team is pleased to update the KDE4 ports to 4.7.3.rakuco2011-11-141-2/+2 * The KDE/FreeBSD team is pleased to announce KDE Software Compilationavilla2011-10-172-7/+14 * Update KDE Software Compilation ports to 4.6.5makc2011-07-082-2/+55 * The FreeBSD KDE Team is pleased to announce KDE SC 4.6.4. Read fullavilla2011-06-141-2/+2 * Update KDE Software Compilation ports to 4.6.3makc2011-05-172-2/+51 * The FreeBSD KDE Team is pleased to announce April updates for KDEavilla2011-04-071-2/+2 * The FreeBSD KDE Team is pleased to announce KDE SC 4.6.1 and KDE PIMavilla2011-03-252-13/+50 * - The KDE FreeBSD team is proud to announce the release of KDE 4.5.5fluffy2011-01-081-2/+2 * KDE FreeBSD team presents KDE SC 4.5.4.makc2010-12-031-2/+2 * KDE FreeBSD team presents KDE SC 4.5.3.makc2010-11-041-3/+2 * KDE FreeBSD team presents KDE SC 4.5.2.makc2010-10-062-27/+3 * KDE FreeBSD team presents KDE SC 4.5.1.makc2010-09-032-118/+50 * Present KDE SC 4.4.5 for FreeBSD.makc2010-06-301-3/+3 * Present KDE SC 4.4.4 for FreeBSD.makc2010-06-021-3/+3 * - The FreeBSD KDE team is pleased to announce KDE SC 4.4.3 for FreeBSDfluffy2010-05-113-28/+74 * - update to 1.4.1dinoex2010-03-281-0/+1 * Presenting KDE 4.3.5 for FreeBSD. The official release notes for thismiwi2010-02-072-4/+3 * - update to jpeg-8dinoex2010-02-051-0/+1 * The FreeBSD KDE is please to announce the release of KDE 4.3.4,miwi2009-12-021-3/+3 * The KDE FreeBSD team is proud to announce the release of KDE 4.3.3miwi2009-11-272-5/+11 * The FreeBSD KDE is please to announce the release of KDE 4.3.1,tabthorpe2009-09-022-4/+4 * clean upmakc2009-08-081-3/+0 * The KDE FreeBSD team is proud to announce the release of KDE 4.3.0miwi2009-08-053-18/+91 * - bump all port that indirectly depends on libjpeg and have not yet been bump...dinoex2009-07-311-0/+1 * The KDE FreeBSD team is pleased to announce KDE 4.2.4, the last bugfixmiwi2009-06-031-3/+3 * Update KDE ports to 4.2.3makc2009-05-101-3/+3 * The KDE FreeBSD team is proud to announce the release of KDE 4.2.2miwi2009-04-022-7/+3 * Update KDE to 4.2.1.makc2009-03-091-3/+3 * The KDE FreeBSD team is proud to announce the release of KDE 4.2.0miwi2009-02-092-21/+72 * kde@freebsd team is pleased to announce KDE 4.1.4, the last bugfix release in...makc2009-01-143-6/+6 * The KDE FreeBSD team is proud to announce the release of KDE 4.1.1miwi2008-09-032-8/+5 * - Change distinfo and pkg-plist from kde-l10n-zh_CN to kde-l10n-zh_TW.miwi2008-08-112-515/+518 * - Fix duplicate INDEX entry.miwi2008-08-101-3/+3 * - Fix INDEXmiwi2008-08-104-54/+528 * The KDE FreeBSD team is proud to announce the release of KDE 4.1.0miwi2008-08-104-607/+42 * Update to KDE 3.5.8lofi2007-10-302-4/+3 * Update to KDE 3.5.7 / KOffice 1.6.3lofi2007-07-043-13/+3 * - Welcome X.org 7.2 \o/.flz2007-05-201-0/+1 * Update to KDE 3.5.6 / KOffice 1.6.2lofi2007-03-142-3/+13 * Update to KDE 3.5.5 / KOffice 1.6.1lofi2006-12-202-3/+36 * KDE 3.5.4 / KOffice 1.5.2lofi2006-09-132-5/+187 * Update to KDE 3.5.3lofi2006-06-062-11/+10