2 ======================================================================
4 CREATOR: acampi 28 May 02
6 $Id: icalattach.c,v 1.3 2007-04-30 13:57:47 artcancro Exp $
10 (C) COPYRIGHT 2000, Andrea Campi
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of either:
15 The LGPL as published by the Free Software Foundation, version
16 2.1, available at: http://www.fsf.org/copyleft/lesser.html
20 The Mozilla Public License Version 1.0. You may obtain a copy of
21 the License at http://www.mozilla.org/MPL/
23 The original code is icaltypes.c
25 ======================================================================*/
30 #include "icaltypes.h"
31 #include "icalerror.h"
32 #include "icalmemory.h"
33 #include "icalattachimpl.h"
34 #include <stdlib.h> /* for malloc and abs() */
35 #include <errno.h> /* for errno */
36 #include <string.h> /* for icalmemory_strdup */
40 icalattach_new_from_url (const char *url)
45 icalerror_check_arg_rz ((url != NULL), "url");
47 if ((attach = malloc (sizeof (icalattach))) == NULL) {
52 if ((url_copy = strdup (url)) == NULL) {
60 attach->u.url.url = url_copy;
66 icalattach_new_from_data (const char *data, icalattach_free_fn_t free_fn,
72 icalerror_check_arg_rz ((data != NULL), "data");
74 if ((attach = malloc (sizeof (icalattach))) == NULL) {
79 if ((data_copy = strdup (data)) == NULL) {
87 attach->u.data.data = data_copy;
88 attach->u.data.free_fn = free_fn;
89 attach->u.data.free_fn_data = free_fn_data;
95 icalattach_ref (icalattach *attach)
97 icalerror_check_arg_rv ((attach != NULL), "attach");
98 icalerror_check_arg_rv ((attach->refcount > 0), "attach->refcount > 0");
104 icalattach_unref (icalattach *attach)
106 icalerror_check_arg_rv ((attach != NULL), "attach");
107 icalerror_check_arg_rv ((attach->refcount > 0), "attach->refcount > 0");
111 if (attach->refcount != 0)
114 if (attach->is_url) {
115 free (attach->u.url.url);
117 free (attach->u.data.data);
119 if (attach->u.data.free_fn)
120 (* attach->u.data.free_fn) (attach->u.data.data, attach->u.data.free_fn_data);
128 icalattach_get_is_url (icalattach *attach)
130 icalerror_check_arg_rz ((attach != NULL), "attach");
132 return attach->is_url ? 1 : 0;
136 icalattach_get_url (icalattach *attach)
138 icalerror_check_arg_rz ((attach != NULL), "attach");
139 icalerror_check_arg_rz ((attach->is_url), "attach->is_url");
141 return attach->u.url.url;
145 icalattach_get_data (icalattach *attach)
147 icalerror_check_arg_rz ((attach != NULL), "attach");
148 icalerror_check_arg_rz ((!attach->is_url), "!attach->is_url");
150 return attach->u.data.data;