• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* exif-mnote-data.c
2  *
3  * Copyright (C) 2003 Lutz Mueller <lutz@users.sourceforge.net>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA  02110-1301  USA.
19  *
20  * SPDX-License-Identifier: LGPL-2.1-or-later
21  */
22 
23 #include <config.h>
24 
25 #include <libexif/exif-mnote-data.h>
26 #include <libexif/exif-mnote-data-priv.h>
27 
28 #include <stdlib.h>
29 #include <string.h>
30 
31 struct _ExifMnoteDataPriv
32 {
33 	unsigned int ref_count;
34 };
35 
36 void
exif_mnote_data_construct(ExifMnoteData * d,ExifMem * mem)37 exif_mnote_data_construct (ExifMnoteData *d, ExifMem *mem)
38 {
39 	if (!d || !mem) return;
40 	if (d->priv) return;
41 	d->priv = exif_mem_alloc (mem, sizeof (ExifMnoteDataPriv));
42 	if (!d->priv) return;
43 
44 	d->priv->ref_count = 1;
45 
46 	d->mem = mem;
47 	exif_mem_ref (mem);
48 }
49 
50 void
exif_mnote_data_ref(ExifMnoteData * d)51 exif_mnote_data_ref (ExifMnoteData *d)
52 {
53 	if (d && d->priv) d->priv->ref_count++;
54 }
55 
56 static void
exif_mnote_data_free(ExifMnoteData * d)57 exif_mnote_data_free (ExifMnoteData *d)
58 {
59 	ExifMem *mem = d ? d->mem : NULL;
60 
61 	if (!d) return;
62 	if (d->priv) {
63 		if (d->methods.free) d->methods.free (d);
64 		exif_mem_free (mem, d->priv);
65 		d->priv = NULL;
66 	}
67 	exif_log_unref (d->log);
68 	exif_mem_free (mem, d);
69 	exif_mem_unref (mem);
70 }
71 
72 void
exif_mnote_data_unref(ExifMnoteData * d)73 exif_mnote_data_unref (ExifMnoteData *d)
74 {
75 	if (!d || !d->priv) return;
76 	if (d->priv->ref_count > 0) d->priv->ref_count--;
77 	if (!d->priv->ref_count)
78 		exif_mnote_data_free (d);
79 }
80 
81 void
exif_mnote_data_load(ExifMnoteData * d,const unsigned char * buf,unsigned int buf_size)82 exif_mnote_data_load (ExifMnoteData *d, const unsigned char *buf,
83 		      unsigned int buf_size)
84 {
85 	if (!d || !d->methods.load) return;
86 	d->methods.load (d, buf, buf_size);
87 }
88 
89 void
exif_mnote_data_save(ExifMnoteData * d,unsigned char ** buf,unsigned int * buf_size)90 exif_mnote_data_save (ExifMnoteData *d, unsigned char **buf,
91 		      unsigned int *buf_size)
92 {
93 	if (!d || !d->methods.save) return;
94 	d->methods.save (d, buf, buf_size);
95 }
96 
97 void
exif_mnote_data_set_byte_order(ExifMnoteData * d,ExifByteOrder o)98 exif_mnote_data_set_byte_order (ExifMnoteData *d, ExifByteOrder o)
99 {
100 	if (!d || !d->methods.set_byte_order) return;
101 	d->methods.set_byte_order (d, o);
102 }
103 
104 void
exif_mnote_data_set_offset(ExifMnoteData * d,unsigned int o)105 exif_mnote_data_set_offset (ExifMnoteData *d, unsigned int o)
106 {
107 	if (!d || !d->methods.set_offset) return;
108 	d->methods.set_offset (d, o);
109 }
110 
111 unsigned int
exif_mnote_data_count(ExifMnoteData * d)112 exif_mnote_data_count (ExifMnoteData *d)
113 {
114 	if (!d || !d->methods.count) return 0;
115 	return d->methods.count (d);
116 }
117 
118 unsigned int
exif_mnote_data_get_id(ExifMnoteData * d,unsigned int n)119 exif_mnote_data_get_id (ExifMnoteData *d, unsigned int n)
120 {
121 	if (!d || !d->methods.get_id) return 0;
122 	return d->methods.get_id (d, n);
123 }
124 
125 const char *
exif_mnote_data_get_name(ExifMnoteData * d,unsigned int n)126 exif_mnote_data_get_name (ExifMnoteData *d, unsigned int n)
127 {
128 	if (!d || !d->methods.get_name) return NULL;
129 	return d->methods.get_name (d, n);
130 }
131 
132 const char *
exif_mnote_data_get_title(ExifMnoteData * d,unsigned int n)133 exif_mnote_data_get_title (ExifMnoteData *d, unsigned int n)
134 {
135 	if (!d || !d->methods.get_title) return NULL;
136 	return d->methods.get_title (d, n);
137 }
138 
139 const char *
exif_mnote_data_get_description(ExifMnoteData * d,unsigned int n)140 exif_mnote_data_get_description (ExifMnoteData *d, unsigned int n)
141 {
142 	if (!d || !d->methods.get_description) return NULL;
143 	return d->methods.get_description (d, n);
144 }
145 
146 char *
exif_mnote_data_get_value(ExifMnoteData * d,unsigned int n,char * val,unsigned int maxlen)147 exif_mnote_data_get_value (ExifMnoteData *d, unsigned int n, char *val, unsigned int maxlen)
148 {
149 	if (!d || !d->methods.get_value) return NULL;
150 	return d->methods.get_value (d, n, val, maxlen);
151 }
152 
153 void
exif_mnote_data_log(ExifMnoteData * d,ExifLog * log)154 exif_mnote_data_log (ExifMnoteData *d, ExifLog *log)
155 {
156 	if (!d) return;
157 	exif_log_unref (d->log);
158 	d->log = log;
159 	exif_log_ref (log);
160 }
161