annotate Plugins/Input/mpg123/id3.c @ 790:8f437afc4f4a trunk

[svn] - more sanity checking
author nenolod
date Fri, 03 Mar 2006 20:09:52 -0800
parents 18b54ee82c24
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
1 /*********************************************************************
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
2 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
3 * Copyright (C) 1999, 2001, Espen Skoglund
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
4 * Department of Computer Science, University of Tromsų
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
5 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
6 * Filename: id3.c
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
7 * Description: Code for accessing ID3 tags.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
8 * Author: Espen Skoglund <espensk@stud.cs.uit.no>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
9 * Created at: Fri Feb 5 23:55:13 1999
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
10 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
11 * $Id: id3.c,v 1.6 2004/07/20 21:47:22 descender Exp $
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
12 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
13 * This program is free software; you can redistribute it and/or
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
14 * modify it under the terms of the GNU General Public License
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
15 * as published by the Free Software Foundation; either version 2
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
16 * of the License, or (at your option) any later version.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
17 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
18 * This program is distributed in the hope that it will be useful,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
21 * GNU General Public License for more details.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
22 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
23 * You should have received a copy of the GNU General Public License
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
24 * along with this program; if not, write to the Free Software
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
26 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
27 ********************************************************************/
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
28 #include "config.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
29
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
30 #include <sys/types.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
31 #include <sys/uio.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
32 #include <glib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
33 #include <fcntl.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
34 #include <unistd.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
35 #include <string.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
36 #include <stdlib.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
37 #include <stdarg.h>
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
38
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
39 #include "xmms-id3.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
40 #include "id3_header.h"
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
41
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
42
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
43 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
44 **
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
45 ** Functions for accessing the ID3 tag using a memory pointer.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
46 **
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
47 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
48
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
49 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
50 * Function id3_seek_mem (id3, offset)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
51 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
52 * Seek `offset' bytes forward in the indicated ID3-tag. Return 0
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
53 * upon success, or -1 if an error occured.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
54 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
55 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
56 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
57 id3_seek_mem(struct id3_tag *id3, int offset)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
58 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
59 if (id3->id3_pos + offset > id3->id3_tagsize || id3->id3_pos + offset < 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
60 id3_error(id3, "seeking beyond tag boundary");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
61 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
62 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
63 id3->s.me.id3_ptr = (char *) id3->s.me.id3_ptr + offset;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
64 id3->id3_pos += offset;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
65
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
66 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
67 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
68
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
69
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
70 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
71 * Function id3_read_mem (id3, buf, size)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
72 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
73 * Read `size' bytes from indicated ID3-tag. If `buf' is non-NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
74 * read into that buffer. Return a pointer to the data which was
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
75 * read, or NULL upon error.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
76 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
77 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
78 static void *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
79 id3_read_mem(struct id3_tag *id3, void *buf, int size)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
80 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
81 void *ret = id3->s.me.id3_ptr;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
82
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
83 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
84 * Check boundary.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
85 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
86 if (id3->id3_pos + size > id3->id3_tagsize) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
87 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
88 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
89
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
90 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
91 * If buffer is non-NULL, we have to copy the data.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
92 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
93 if (buf != NULL) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
94 if (size > ID3_FD_BUFSIZE)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
95 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
96 memcpy(buf, id3->s.me.id3_ptr, size);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
97 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
98
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
99 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
100 * Update memory pointer.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
101 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
102 id3->s.me.id3_ptr = (char *) id3->s.me.id3_ptr + size;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
103 id3->id3_pos += size;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
104
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
105 return ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
106 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
107
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
108
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
109 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
110 **
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
111 ** Functions for accessing the ID3 tag using a file descriptor.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
112 **
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
113 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
114
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
115 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
116 * Function id3_seek_fd (id3, offset)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
117 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
118 * Seek `offset' bytes forward in the indicated ID3-tag. Return 0
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
119 * upon success, or -1 if an error occured.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
120 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
121 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
122 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
123 id3_seek_fd(struct id3_tag *id3, int offset)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
124 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
125 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
126 * Check boundary.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
127 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
128 if (id3->id3_pos + offset > id3->id3_tagsize || id3->id3_pos + offset < 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
129 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
130
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
131 if (lseek(id3->s.fd.id3_fd, offset, SEEK_CUR) == -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
132 id3_error(id3, "seeking beyond tag boundary");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
133 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
134 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
135 id3->id3_pos += offset;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
136
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
137 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
138 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
139
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
140
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
141 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
142 * Function id3_read_fd (id3, buf, size)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
143 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
144 * Read `size' bytes from indicated ID3-tag. If `buf' is non-NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
145 * read into that buffer. Return a pointer to the data which was
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
146 * read, or NULL upon error.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
147 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
148 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
149 static void *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
150 id3_read_fd(struct id3_tag *id3, void *buf, int size)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
151 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
152 int done = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
153
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
154 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
155 * Check boundary.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
156 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
157 if (id3->id3_pos + size > id3->id3_tagsize) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
158 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
159 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
160
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
161 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
162 * If buffer is NULL, we use the default buffer.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
163 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
164 if (buf == NULL) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
165 if (size > ID3_FD_BUFSIZE)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
166 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
167 buf = id3->s.fd.id3_buf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
168 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
169
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
170 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
171 * Read until we have slurped as much data as we wanted.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
172 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
173 while (done < size) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
174 char *buffer = (char *) buf + done;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
175 int ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
176
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
177 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
178 * Try reading from file.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
179 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
180 ret = read(id3->s.fd.id3_fd, buffer, size);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
181 if (ret <= 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
182 id3_error(id3, "read(2) failed");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
183 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
184 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
185
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
186 id3->id3_pos += ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
187 done += ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
188 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
189
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
190 return buf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
191 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
192
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
193
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
194 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
195 **
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
196 ** Functions for accessing the ID3 tag using a file pointer.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
197 **
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
198 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
199
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
200 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
201 * Function id3_seek_fp (id3, offset)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
202 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
203 * Seek `offset' bytes forward in the indicated ID3-tag. Return 0
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
204 * upon success, or -1 if an error occured.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
205 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
206 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
207 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
208 id3_seek_fp(struct id3_tag *id3, int offset)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
209 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
210 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
211 * Check boundary.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
212 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
213 if (id3->id3_pos + offset > id3->id3_tagsize || id3->id3_pos + offset < 0)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
214 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
215
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
216 if (offset > 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
217 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
218 * If offset is positive, we use vfs_fread() instead of vfs_fseek(). This
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
219 * is more robust with respect to streams.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
220 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
221 char buf[64];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
222 int r, remain = offset;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
223
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
224 while (remain > 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
225 int size = MIN(64, remain);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
226 r = vfs_fread(buf, 1, size, id3->s.fp.id3_fp);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
227 if (r == 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
228 id3_error(id3, "vfs_fread() failed");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
229 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
230 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
231 remain -= r;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
232 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
233 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
234 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
235 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
236 * If offset is negative, we ahve to use vfs_fseek(). Let us hope
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
237 * that it works.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
238 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
239 if (vfs_fseek(id3->s.fp.id3_fp, offset, SEEK_CUR) == -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
240 id3_error(id3, "seeking beyond tag boundary");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
241 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
242 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
243 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
244 id3->id3_pos += offset;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
245
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
246 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
247 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
248
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
249
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
250 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
251 * Function id3_read_fp (id3, buf, size)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
252 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
253 * Read `size' bytes from indicated ID3-tag. If `buf' is non-NULL,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
254 * read into that buffer. Return a pointer to the data which was
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
255 * read, or NULL upon error.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
256 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
257 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
258 static void *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
259 id3_read_fp(struct id3_tag *id3, void *buf, int size)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
260 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
261 int ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
262
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
263 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
264 * Check boundary.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
265 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
266 if (id3->id3_pos + size > id3->id3_tagsize) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
267 size = id3->id3_tagsize - id3->id3_pos;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
268 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
269
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
270 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
271 * If buffer is NULL, we use the default buffer.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
272 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
273 if (buf == NULL) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
274 if (size > ID3_FD_BUFSIZE)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
275 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
276 buf = id3->s.fd.id3_buf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
277 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
278
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
279 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
280 * Try reading from file.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
281 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
282 ret = vfs_fread(buf, 1, size, id3->s.fp.id3_fp);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
283 if (ret != size) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
284 id3_error(id3, "vfs_fread() failed");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
285 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
286 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
287
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
288 id3->id3_pos += ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
289
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
290 return buf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
291 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
292
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
293
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
294
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
295
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
296 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
297 * Function id3_open_mem (ptr, flags)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
298 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
299 * Open an ID3 tag using a memory pointer. Return a pointer to a
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
300 * structure describing the ID3 tag, or NULL if an error occured.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
301 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
302 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
303 struct id3_tag *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
304 id3_open_mem(void *ptr, int flags)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
305 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
306 struct id3_tag *id3;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
307
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
308 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
309 * Allocate ID3 structure.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
310 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
311 id3 = g_malloc0(sizeof(struct id3_tag));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
312
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
313 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
314 * Initialize access pointers.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
315 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
316 id3->id3_seek = id3_seek_mem;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
317 id3->id3_read = id3_read_mem;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
318
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
319 id3->id3_oflags = flags;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
320 id3->id3_type = ID3_TYPE_MEM;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
321 id3->id3_pos = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
322 id3->s.me.id3_ptr = ptr;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
323
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
324 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
325 * Try reading ID3 tag.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
326 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
327 if (id3_read_tag(id3) == -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
328 if (~flags & ID3_OPENF_CREATE)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
329 goto Return_NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
330 id3_init_tag(id3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
331 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
332
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
333 return id3;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
334
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
335 Return_NULL:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
336 g_free(id3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
337 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
338 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
339
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
340
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
341 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
342 * Function id3_open_fd (fd, flags)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
343 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
344 * Open an ID3 tag using a file descriptor. Return a pointer to a
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
345 * structure describing the ID3 tag, or NULL if an error occured.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
346 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
347 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
348 struct id3_tag *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
349 id3_open_fd(int fd, int flags)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
350 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
351 struct id3_tag *id3;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
352
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
353 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
354 * Allocate ID3 structure.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
355 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
356 id3 = g_malloc0(sizeof(struct id3_tag));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
357
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
358 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
359 * Initialize access pointers.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
360 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
361 id3->id3_seek = id3_seek_fd;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
362 id3->id3_read = id3_read_fd;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
363
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
364 id3->id3_oflags = flags;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
365 id3->id3_type = ID3_TYPE_FD;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
366 id3->id3_pos = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
367 id3->s.fd.id3_fd = fd;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
368
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
369 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
370 * Allocate buffer to hold read data.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
371 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
372 id3->s.fd.id3_buf = g_malloc(ID3_FD_BUFSIZE);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
373
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
374 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
375 * Try reading ID3 tag.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
376 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
377 if (id3_read_tag(id3) == -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
378 if (~flags & ID3_OPENF_CREATE)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
379 goto Return_NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
380 id3_init_tag(id3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
381 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
382
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
383 return id3;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
384
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
385 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
386 * Cleanup code.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
387 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
388 Return_NULL:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
389 g_free(id3->s.fd.id3_buf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
390 g_free(id3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
391 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
392 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
393
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
394
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
395 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
396 * Function id3_open_fp (fp, flags)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
397 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
398 * Open an ID3 tag using a file pointer. Return a pointer to a
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
399 * structure describing the ID3 tag, or NULL if an error occured.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
400 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
401 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
402 struct id3_tag *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
403 id3_open_fp(VFSFile * fp, int flags)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
404 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
405 struct id3_tag *id3;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
406
780
18b54ee82c24 [svn] - do not operate on a non-existant fd
nenolod
parents: 240
diff changeset
407 if (fp == NULL)
18b54ee82c24 [svn] - do not operate on a non-existant fd
nenolod
parents: 240
diff changeset
408 return NULL;
18b54ee82c24 [svn] - do not operate on a non-existant fd
nenolod
parents: 240
diff changeset
409
61
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
410 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
411 * Allocate ID3 structure.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
412 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
413 id3 = g_malloc0(sizeof(struct id3_tag));
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
414
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
415 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
416 * Initialize access pointers.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
417 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
418 id3->id3_seek = id3_seek_fp;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
419 id3->id3_read = id3_read_fp;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
420
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
421 id3->id3_oflags = flags;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
422 id3->id3_type = ID3_TYPE_FP;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
423 id3->id3_pos = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
424 id3->s.fp.id3_fp = fp;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
425
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
426 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
427 * Allocate buffer to hold read data.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
428 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
429 id3->s.fp.id3_buf = g_malloc(ID3_FD_BUFSIZE);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
430
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
431 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
432 * Try reading ID3 tag.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
433 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
434 if (id3_read_tag(id3) == -1) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
435 if (~flags & ID3_OPENF_CREATE)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
436 goto Return_NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
437 id3_init_tag(id3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
438 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
439
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
440
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
441 return id3;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
442
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
443 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
444 * Cleanup code.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
445 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
446 Return_NULL:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
447 g_free(id3->s.fp.id3_buf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
448 g_free(id3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
449 return NULL;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
450 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
451
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
452
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
453 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
454 * Function id3_close (id3)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
455 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
456 * Free all resources assoicated with the ID3 tag.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
457 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
458 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
459 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
460 id3_close(struct id3_tag *id3)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
461 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
462 int ret = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
463
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
464 switch (id3->id3_type) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
465 case ID3_TYPE_MEM:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
466 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
467 case ID3_TYPE_FD:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
468 g_free(id3->s.fd.id3_buf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
469 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
470 case ID3_TYPE_FP:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
471 g_free(id3->s.fp.id3_buf);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
472 break;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
473 case ID3_TYPE_NONE:
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
474 id3_error(id3, "unknown ID3 type");
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
475 ret = -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
476 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
477
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
478 id3_destroy_frames(id3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
479
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
480 g_free(id3);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
481
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
482 return ret;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
483 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
484
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
485
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
486 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
487 * Function id3_tell (id3)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
488 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
489 * Return the current position in ID3 tag. This will always be
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
490 * directly after the tag.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
491 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
492 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
493 #if 0
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
494 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
495 id3_tell(struct id3_tag *id3)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
496 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
497 if (id3->id3_newtag) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
498 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
499 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
500 else {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
501 return id3->id3_tagsize + 3 + sizeof(id3_taghdr_t);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
502 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
503 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
504 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
505
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
506
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
507 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
508 * Function id3_alter_file (id3)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
509 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
510 * When altering a file, some ID3 tags should be discarded. As the ID3
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
511 * library has no means of knowing when a file has been altered
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
512 * outside of the library, this function must be called manually
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
513 * whenever the file is altered.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
514 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
515 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
516 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
517 id3_alter_file(struct id3_tag *id3)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
518 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
519 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
520 * List of frame classes that should be discarded whenever the
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
521 * file is altered.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
522 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
523 static guint32 discard_list[] = {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
524 ID3_ETCO, ID3_EQUA, ID3_MLLT, ID3_POSS, ID3_SYLT,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
525 ID3_SYTC, ID3_RVAD, ID3_TENC, ID3_TLEN, ID3_TSIZ,
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
526 0
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
527 };
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
528 struct id3_frame *fr;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
529 guint32 id, i = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
530
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
531 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
532 * Go through list of frame types that should be discarded.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
533 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
534 while ((id = discard_list[i++]) != 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
535 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
536 * Discard all frames of that type.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
537 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
538 while ((fr = id3_get_frame(id3, id, 1))) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
539 id3_delete_frame(fr);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
540 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
541 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
542
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
543 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
544 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
545
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
546
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
547 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
548 * Function safe_write (fd, buf, size)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
549 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
550 * Like write(2), except that the whole buffer will be written.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
551 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
552 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
553 static int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
554 safe_write(int fd, void *buf, int size)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
555 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
556 int remaining = size;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
557 char *ptr = buf;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
558 int r;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
559
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
560 while (remaining > 0) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
561 if ((r = write(fd, ptr, remaining)) == -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
562 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
563 remaining -= r;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
564 ptr += r;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
565 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
566
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
567 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
568 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
569
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
570
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
571 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
572 * Function id3_write_tag (id3, fd)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
573 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
574 * Wrtite the ID3 tag to the indicated file descriptor. Return 0
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
575 * upon success, or -1 if an error occured.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
576 *
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
577 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
578 int
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
579 id3_write_tag(struct id3_tag *id3, int fd)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
580 {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
581 struct id3_frame *fr;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
582 GList *node;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
583 int size = 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
584 char buf[ID3_TAGHDR_SIZE];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
585
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
586 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
587 * Calculate size of ID3 tag.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
588 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
589 for (node = id3->id3_frame; node != NULL; node = node->next) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
590 fr = node->data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
591 size += fr->fr_size + ID3_FRAMEHDR_SIZE;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
592 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
593
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
594 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
595 * Write tag header.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
596 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
597 buf[0] = id3->id3_version;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
598 buf[1] = id3->id3_revision;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
599 buf[2] = id3->id3_flags;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
600 ID3_SET_SIZE28(size, buf[3], buf[4], buf[5], buf[6]);
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
601
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
602 if (safe_write(fd, "ID3", 3) == -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
603 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
604 if (safe_write(fd, buf, ID3_TAGHDR_SIZE) == -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
605 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
606
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
607 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
608 * TODO: Write extended header.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
609 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
610 #if 0
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
611 if (id3->id3_flags & ID3_THFLAG_EXT) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
612 id3_exthdr_t exthdr;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
613 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
614 #endif
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
615
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
616 for (node = id3->id3_frame; node != NULL; node = node->next) {
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
617 char fhdr[ID3_FRAMEHDR_SIZE];
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
618
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
619 fr = node->data;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
620
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
621 /*
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
622 * TODO: Support compressed headers, encoded
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
623 * headers, and grouping info.
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
624 */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
625 /* fhdr.fh_id = fr->fr_desc ? g_htonl(fr->fr_desc->fd_id) : 0; */
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
626 fhdr[3] = (fr->fr_size >> 24) & 0xff;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
627 fhdr[4] = (fr->fr_size >> 16) & 0xff;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
628 fhdr[5] = (fr->fr_size >> 8) & 0xff;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
629 fhdr[6] = fr->fr_size & 0xff;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
630 fhdr[7] = (fr->fr_flags >> 8) & 0xff;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
631 fhdr[8] = fr->fr_flags & 0xff;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
632
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
633 if (safe_write(fd, fhdr, sizeof(fhdr)) == -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
634 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
635
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
636 if (safe_write(fd, fr->fr_data, fr->fr_size) == -1)
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
637 return -1;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
638 }
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
639 return 0;
fa848bd484d8 [svn] Move plugins to Plugins/
nenolod
parents:
diff changeset
640 }