2008-05-02 21:05:37 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Patrick Ohly
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ICALSTRDUP_H
|
|
|
|
#define ICALSTRDUP_H
|
|
|
|
|
|
|
|
#ifndef HANDLE_LIBICAL_MEMORY
|
|
|
|
# define HANDLE_LIBICAL_MEMORY 1
|
|
|
|
#endif
|
|
|
|
#include <libical/ical.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#pragma }
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2008-10-09 17:55:11 +02:00
|
|
|
#if !defined(LIBICAL_MEMFIXES) || defined(EVOLUTION_COMPATIBILITY)
|
2008-05-02 21:05:37 +02:00
|
|
|
/**
|
|
|
|
* The patch in http://bugzilla.gnome.org/show_bug.cgi?id=516408
|
|
|
|
* changes the ownership of strings returned by some libical and libecal
|
|
|
|
* functions: previously, the memory was owned by the library.
|
|
|
|
* After the patch the caller owns the copied string and must free it.
|
|
|
|
*
|
2008-10-09 17:55:11 +02:00
|
|
|
* The upstream SourceForge libical has incorporated the patch, but
|
|
|
|
* without changing the semantic of the existing calls. Instead they
|
|
|
|
* added _r variants which return memory that the caller must free.
|
|
|
|
* As soon as Evolution switches to upstream libical (planned for 2.25),
|
|
|
|
* it probably will have to bump the libecal version because the API
|
|
|
|
* is reverted so that binaries which free strings will crash.
|
|
|
|
* When EVOLUTION_COMPATIBILITY is defined, SyncEvolution deals with
|
|
|
|
* this by always checking at runtime what the memory handling is.
|
|
|
|
*
|
2008-05-02 21:05:37 +02:00
|
|
|
* This utility function ensures that the caller *always* owns the
|
2008-10-09 17:55:11 +02:00
|
|
|
* returned string. When compiled against a current Evolution
|
|
|
|
* Dataserver, the function becomes a NOP macro, unless compatibility
|
|
|
|
* mode is on (in which case the current binary might later run with
|
|
|
|
* an older Evolution release!). If not a NOP macro, then the function
|
|
|
|
* duplicates the string; it handles NULL by passing it through.
|
2008-05-02 21:05:37 +02:00
|
|
|
*
|
|
|
|
* When compiled against an old Evolution Dataserver, then a runtime
|
|
|
|
* check can be enabled to to determine whether the string needs to be
|
|
|
|
* duplicated. If uncertain, it always duplicates the string. If the
|
|
|
|
* check fails, then memory is leaked, which also happens when running
|
|
|
|
* programs which do not know about the patch.
|
|
|
|
*
|
|
|
|
* To enable the runtime check, compile the .c file with -D_GNU_SOURCE
|
|
|
|
* and -DHAVE_DLFCN_H. If HAVE_CONFIG_H is set, then config.h is included
|
|
|
|
* and can be set to set some of these defines. If enabled, then link with
|
|
|
|
* -ldl.
|
|
|
|
*
|
|
|
|
* ical_strdup() must be wrapped around the following functions:
|
|
|
|
* - icalreqstattype_as_string
|
|
|
|
* - icalproperty_as_ical_string
|
|
|
|
* - icalproperty_get_parameter_as_string
|
|
|
|
* - icalproperty_get_value_as_string
|
|
|
|
* - icallangbind_property_eval_string
|
|
|
|
* - icalperiodtype_as_ical_string
|
|
|
|
* - icaltime_as_ical_string
|
|
|
|
* - icalvalue_as_ical_string
|
|
|
|
* - icalcomponent_as_ical_string
|
|
|
|
* - e_cal_component_get_recurid_as_string
|
|
|
|
*
|
|
|
|
* @param x result of one of the functions above
|
|
|
|
* @return string which has to be freed by caller, may be NULL if x was NULL
|
|
|
|
*/
|
|
|
|
extern char *ical_strdup(const char *x);
|
|
|
|
#else
|
|
|
|
# define ical_strdup(_x) (_x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* ICALSTRDUP_H */
|