/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* camel-execpetion.c : exception utils */ /* * * Author : * Bertrand Guiheneuf * * Copyright 1999, 2000 Ximian, Inc. (www.ximian.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 */ #ifdef HAVE_CONFIG_H #include #endif #include #include "camel-exception.h" /* i dont know why gthread_mutex stuff even exists, this is easier */ /* also, i'm not convinced mutexes are needed here. But it doesn't really hurt either */ #ifdef ENABLE_THREADS #include static pthread_mutex_t exception_mutex = PTHREAD_MUTEX_INITIALIZER; #define CAMEL_EXCEPTION_LOCK(e) (pthread_mutex_lock(&exception_mutex)) #define CAMEL_EXCEPTION_UNLOCK(e) (pthread_mutex_unlock(&exception_mutex)) #else #define CAMEL_EXCEPTION_LOCK(e) #define CAMEL_EXCEPTION_UNLOCK(e) #endif /** * camel_exception_new: allocate a new exception object. * * Create and returns a new exception object. * * * Return value: The newly allocated exception object. **/ CamelException * camel_exception_new (void) { CamelException *ex; ex = g_new (CamelException, 1); ex->desc = NULL; /* set the Exception Id to NULL */ ex->id = CAMEL_EXCEPTION_NONE; return ex; } /** * camel_exception_init: init a (statically allocated) exception. * * Init an exception. This routine is mainly * useful when using a statically allocated * exception. * * **/ void camel_exception_init (CamelException *ex) { ex->desc = NULL; /* set the Exception Id to NULL */ ex->id = CAMEL_EXCEPTION_NONE; } /** * camel_exception_clear: Clear an exception * @exception: the exception object * * Clear an exception, that is, set the * exception ID to CAMEL_EXCEPTION_NONE and * free the description text. * If the exception is NULL, this funtion just * returns. **/ void camel_exception_clear (CamelException *exception) { if (!exception) return; CAMEL_EXCEPTION_LOCK(exception); if (exception->desc) g_free (exception->desc); exception->desc = NULL; exception->id = CAMEL_EXCEPTION_NONE; CAMEL_EXCEPTION_UNLOCK(exception); } /** * camel_exception_free: Free an exception * @exception: The exception object to free * * Free an exception object. If the exception * is NULL, nothing is done, the routine simply * returns. **/ void camel_exception_free (CamelException *exception) { if (!exception) return; if (exception->desc) g_free (exception->desc); g_free (exception); } /** * camel_exception_set: set an exception * @ex: exception object * @id: exception id * @desc: textual description of the exception * * Set the value of an exception. The exception id is * a unique number representing the exception. The * textual description is a small text explaining * what happened and provoked the exception. * * When @ex is NULL, nothing is done, this routine * simply returns. * **/ void camel_exception_set (CamelException *ex, ExceptionId id, const char *desc) { if (!ex) return; CAMEL_EXCEPTION_LOCK(exception); ex->id = id; if (ex->desc) g_free(ex->desc); ex->desc = g_strdup(desc); CAMEL_EXCEPTION_UNLOCK(exception); } /** * camel_exception_setv: set an exception * @ex: exception object * @id: exception id * @format: format of the description string. The format string is * used as in printf(). * * Set the value of an exception. The exception id is * a unique number representing the exception. The * textual description is a small text explaining * what happened and provoked the exception. * In this version, the string is created from the format * string and the variable argument list. * * It is safe to say: * camel_exception_setv (ex, ..., camel_exception_get_description (ex), ...); * * When @ex is NULL, nothing is done, this routine * simply returns. * **/ void camel_exception_setv (CamelException *ex, ExceptionId id, const char *format, ...) { va_list args; if (!ex) return; CAMEL_EXCEPTION_LOCK(exception); if (ex->desc) g_free (ex->desc); va_start(args, format); ex->desc = g_strdup_vprintf (format, args); va_end (args); ex->id = id; CAMEL_EXCEPTION_UNLOCK(exception); } /** * camel_exception_xfer: transfer an exception * @ex_dst: Destination exception object * @ex_src: Source exception object * * Transfer the content of an exception from * an exception object to another. * The destination exception receives the id and * the description text of the source exception. **/ void camel_exception_xfer (CamelException *ex_dst, CamelException *ex_src) { if (ex_src == NULL) { g_warning ("camel_exception_xfer: trying to transfer NULL exception to %p\n", ex_dst); return; } if (ex_dst == NULL) { /* must have same side-effects */ camel_exception_clear (ex_src); return; } CAMEL_EXCEPTION_LOCK(exception); if (ex_dst->desc) g_free (ex_dst->desc); ex_dst->id = ex_src->id; ex_dst->desc = ex_src->desc; ex_src->desc = NULL; ex_src->id = CAMEL_EXCEPTION_NONE; CAMEL_EXCEPTION_UNLOCK(exception); } /** * camel_exception_get_id: get the exception id * @ex: The exception object * * Return the id of an exception. * If @ex is NULL, return CAMEL_EXCEPTION_NONE; * * Return value: Exception ID. **/ ExceptionId camel_exception_get_id (CamelException *ex) { if (ex) return ex->id; else { g_warning ("camel_exception_get_id called with NULL parameter."); return CAMEL_EXCEPTION_NONE; } } /** * camel_exception_get_description: get the description of an exception. * @ex: The exception object * * Return the exception description text. * If @ex is NULL, return NULL; * * * Return value: Exception description text. **/ const gchar * camel_exception_get_description (CamelException *ex) { char *ret = NULL; if (ex) ret = ex->desc; else g_warning ("camel_exception_get_description called with NULL parameter."); return ret; } horAgeFilesLines * Bump PORTREVISION for ports depending on the canonical version of GCCgerald2018-12-122-2/+2 * These ports now build on powerpc64.linimon2018-12-121-1/+0 * news/xpn: Add a trayicontobik2018-11-162-2/+100 * - Fix with INN's shared libraries;thierry2018-11-143-4/+43 * Update `databases/gdbm' to version 1.18.1, an important bugfix releasedanfe2018-11-113-3/+3 * Install texinfo files (GNU info) into ${PREFIX}/share/infobapt2018-11-115-2/+5 * news/pan: Update to 0.145swills2018-11-104-188/+29 * Compiling on GCC-based architectures (only) requires using c+11.linimon2018-11-101-2/+8 * Update to 2.3.5flo2018-11-022-4/+4 * devel/icu: update to 63.1jbeich2018-10-231-1/+1 * - Update WWWamdmi32018-10-141-1/+1 * - Update to 0.09wen2018-10-102-4/+8 * Apply a correct fix.mat2018-10-102-4/+4 * news/nzbget: Unbreak portfeld2018-10-102-6/+3 * Mark BROKEN: fails to packageantoine2018-10-071-0/+2 * Fix every instance of RUN_DEPENDS:=${BUILD_DEPENDS} in p5 ports, exceptdes2018-10-062-4/+4 * news/nzbget: Update to 20.0feld2018-10-045-11/+48 * Update Objective-C LLVM version to 6.0.brooks2018-09-261-1/+1 * Add EXAMPLES options to ports that should have one.mat2018-09-101-1/+1 * Add DOCS options to ports that should have one.mat2018-09-106-1/+11 * After an include, PLIST_SUB must be appended to, not overwritten.mat2018-09-101-1/+1 * news/newscache: Fix build with Clang 6tobik2018-09-011-0/+15 * news/nget: Fix build on 12.0tobik2018-08-251-0/+1 * Fix a common grammar error: "can not" means the opposite of "cannot."adamw2018-08-021-1/+1 * Bump PORTREVISION for ports depending on the canonical version of GCCgerald2018-07-301-1/+1 * Remove all := from BUILD_DEPENDS, here are never needed.mat2018-07-091-1/+1 * Mark ports broken on mips64 that are already broken on powerpc64. Inlinimon2018-07-021-5/+6 * news/slrn: fix crash with SIGSERV in the iconv_convert_string()eugen2018-06-301-1/+2 * devel/icu: update to 62.1jbeich2018-06-291-1/+1 * Use PY_FLAVOR for dependencies.mat2018-06-213-4/+4 * Adjust USES to fix builds on gcc-based architectures.linimon2018-06-191-1/+1 * Update to 2.3.4flo2018-06-053-5/+4 * Update to 3.3.5flo2018-06-022-4/+4 * Back to the poolflo2018-06-021-1/+1 * Update WWWsunpoet2018-05-285-5/+5 * - remove option INETDdinoex2018-04-307-17/+212 * Switch all pypi.python.org WWWs to a new PyPi home pypi.org whereamdmi32018-04-261-1/+1 * devel/icu: update to 61.1jbeich2018-04-061-1/+1 * news/mmail: Update 0.49 -> 0.51yuri2018-04-023-23/+4 * Add LICENSE.mandree2018-03-311-0/+2 * Fix build with Perl 5.26.mat2018-03-291-0/+14 * Add missing requirement on LOGIN for rc script.bdrewery2018-03-042-1/+2 * Reduce dependency on the python2 metaportantoine2018-02-192-4/+4 * Canonicalize PyPi WWWs:amdmi32018-02-091-1/+1 * Unbreak Clang 6 build.fjoe2018-01-271-0/+20 * Update to 2.3.2flo2018-01-213-7/+9 * Update to 3.3.2flo2018-01-212-4/+4 * Remove superfluous linefeeds and fix some other minor whitespace bugs.danfe2018-01-121-1/+0 * Do not abuse INSTALL_MAN when installing documentation, examples, anddanfe2018-01-111-1/+1 * Remove support for variables that have been deprecated for a while.mat2018-01-092-5/+4 * news/pan: unbreak build with Clang 6 (C++14 by default)jbeich2018-01-061-0/+166 * - add back setuid bits for poudriere buildsdinoex2018-01-052-1/+3 * - Add LICENSEamdmi32017-12-272-1/+4 * Update to tin 2.4.2johans2017-12-253-5/+6 * Fix configure options for gnustep-maketheraven2017-12-031-1/+1 * - Add explicit FLAVOR to a few dependenciesantoine2017-12-031-2/+2 * Convert Python ports to FLAVORS.mat2017-11-306-14/+14 * Remove expired ports:rene2017-11-224-49/+0 * devel/icu: update to 60.1jbeich2017-11-091-1/+1 * - Reset MAINTAINER due to fatal email bounces, maintainer timeoutszi2017-11-041-1/+1 * lang/tcl84, x11-toolkits/tk84: extend expiration for another monthgahr2017-10-201-0/+3 * news/nget: Fix build with Clang and GCC > 4.8tobik2017-10-145-16/+77 * Remove news/py-twistedNewssunpoet2017-09-304-37/+0 * devel/icu: update to 59.1jbeich2017-09-251-1/+1 * news/py-sabyenc: Update to 3.3.1dbaio2017-09-232-5/+7 * news/sabnzbdplus: Update to 2.3.0dbaio2017-09-233-7/+6 * - update to pgpverify-1.29dinoex2017-09-172-9/+16 * Fix license information for portgs that use "the same license as Perl".mat2017-09-152-2/+2 * Bump PORTREVISION for ports depending on the canonical version of GCCgerald2017-09-112-1/+2 * Change from USES=twisted to devel/py-twistedsunpoet2017-09-041-2/+3 * * Updated to 2.2.1ultima2017-09-033-5/+18 * Update GNUstep core libraries.theraven2017-08-211-1/+1 * Mark DEPRECATED and set EXPIRATION_DATE to 2017-09-30sunpoet2017-08-201-0/+3 * - news/nzbget: Update from 19.0 to 19.1joneum2017-08-152-4/+4 * - remove obsolte option PGP2dinoex2017-08-021-2/+1 * news/nzbget: Update 18.1 -> 19.0bhughes2017-07-032-5/+4 * Remove Perl core modulessunpoet2017-07-012-7/+8 * - Update SABnzbd to 2.1.0.tdb2017-06-133-8/+7 * - Use correct license (see https://github.com/sabnzbd/sabyenc/issues/5).tdb2017-06-122-8/+7 * - Add LICENSEamdmi32017-06-124-16/+18 * New port: news/py-sabyenctdb2017-06-104-0/+35 * news/husky-sqpack is a subport for news/husky to purge squish and jam msgbases.eugen2017-05-253-0/+26 * Handle special permissions through pkg-plist and not through makejohans2017-05-222-20/+16 * Mark some ports failing on power64. In cases where the error messagelinimon2017-05-141-1/+2 * - Update to INN 2.6.1johans2017-05-123-10/+22 * news/nzbget: Update to 18.1feld2017-05-122-19/+12 * UNRAR description is now available in bsd.options.desc.mkfeld2017-04-271-1/+0 * - Fix plistmiwi2017-04-232-1/+3 * - Fix shebangsmiwi2017-04-191-1/+3 * - Optionize docsamdmi32017-04-101-6/+5 * Bump PORTREVISIONs for ports depending on the canonical version of GCC andgerald2017-04-011-1/+1 * news/sabnzbdplus: Update to 1.2.3tdb2017-03-22