00001 /* 00002 * Copyright (C) 2008 Patrick Ohly 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 00017 * 02111-1307 USA 00018 */ 00019 00020 #ifndef ICALSTRDUP_H 00021 #define ICALSTRDUP_H 00022 00023 #ifndef HANDLE_LIBICAL_MEMORY 00024 # define HANDLE_LIBICAL_MEMORY 1 00025 #endif 00026 #include <libical/ical.h> 00027 00028 #ifdef __cplusplus 00029 extern "C" { 00030 #pragma } 00031 #endif /* __cplusplus */ 00032 00033 #if !defined(LIBICAL_MEMFIXES) || defined(EVOLUTION_COMPATIBILITY) 00034 /** 00035 * The patch in http://bugzilla.gnome.org/show_bug.cgi?id=516408 00036 * changes the ownership of strings returned by some libical and libecal 00037 * functions: previously, the memory was owned by the library. 00038 * After the patch the caller owns the copied string and must free it. 00039 * 00040 * The upstream SourceForge libical has incorporated the patch, but 00041 * without changing the semantic of the existing calls. Instead they 00042 * added _r variants which return memory that the caller must free. 00043 * As soon as Evolution switches to upstream libical (planned for 2.25), 00044 * it probably will have to bump the libecal version because the API 00045 * is reverted so that binaries which free strings will crash. 00046 * When EVOLUTION_COMPATIBILITY is defined, SyncEvolution deals with 00047 * this by always checking at runtime what the memory handling is. 00048 * 00049 * This utility function ensures that the caller *always* owns the 00050 * returned string. When compiled against a current Evolution 00051 * Dataserver, the function becomes a NOP macro, unless compatibility 00052 * mode is on (in which case the current binary might later run with 00053 * an older Evolution release!). If not a NOP macro, then the function 00054 * duplicates the string; it handles NULL by passing it through. 00055 * 00056 * When compiled against an old Evolution Dataserver, then a runtime 00057 * check can be enabled to to determine whether the string needs to be 00058 * duplicated. If uncertain, it always duplicates the string. If the 00059 * check fails, then memory is leaked, which also happens when running 00060 * programs which do not know about the patch. 00061 * 00062 * To enable the runtime check, compile the .c file with -D_GNU_SOURCE 00063 * and -DHAVE_DLFCN_H. If HAVE_CONFIG_H is set, then config.h is included 00064 * and can be set to set some of these defines. If enabled, then link with 00065 * -ldl. 00066 * 00067 * ical_strdup() must be wrapped around the following functions: 00068 * - icalreqstattype_as_string 00069 * - icalproperty_as_ical_string 00070 * - icalproperty_get_parameter_as_string 00071 * - icalproperty_get_value_as_string 00072 * - icallangbind_property_eval_string 00073 * - icalperiodtype_as_ical_string 00074 * - icaltime_as_ical_string 00075 * - icalvalue_as_ical_string 00076 * - icalcomponent_as_ical_string 00077 * - e_cal_component_get_recurid_as_string 00078 * 00079 * @param x result of one of the functions above 00080 * @return string which has to be freed by caller, may be NULL if x was NULL 00081 */ 00082 extern char *ical_strdup(const char *x); 00083 #else 00084 # define ical_strdup(_x) (_x) 00085 #endif 00086 00087 #ifdef __cplusplus 00088 } 00089 #endif /* __cplusplus */ 00090 00091 00092 #endif /* ICALSTRDUP_H */