comparison Plugins/Input/mpg123/xmms-id3.h @ 227:539a0fa7f030 trunk

[svn] Unicode support fixes, based on an XMMS patch written by Ilya Konstantinov. <ikonst@users.sourceforge.net>: - Fixes UTF16 to UTF8 down-conversion. - Fixes length management of UTF8 entities. - Doesn't break ASCII support. - Corrects several issues with the original implementation.
author nenolod
date Fri, 25 Nov 2005 20:23:40 -0800
parents fa848bd484d8
children 18cb7405b5e9
comparison
equal deleted inserted replaced
226:f6ad670bb500 227:539a0fa7f030
147 #define ID3_ENCODING_UTF16 0x01 147 #define ID3_ENCODING_UTF16 0x01
148 #define ID3_ENCODING_UTF16BE 0x02 148 #define ID3_ENCODING_UTF16BE 0x02
149 #define ID3_ENCODING_UTF8 0x03 149 #define ID3_ENCODING_UTF8 0x03
150 150
151 151
152 /*
153 * Handy macros which help us writing more secure length-aware code
154 * which involves reading the frame's data buffer.
155 */
156
157 #define ID3_FRAME_DEFINE_CURSOR(frame) \
158 gsize length = frame->fr_size; \
159 guint8* cursor = frame->fr_data;
160
161 #define ID3_FRAME_READ_OR_RETVAL(variable, retval) \
162 if (length < sizeof(variable)) \
163 return retval; \
164 memcpy((void*)&variable, (void*)cursor, sizeof(variable)); \
165 cursor += sizeof(variable); \
166 length -= sizeof(variable);
152 167
153 /* 168 /*
154 * ID3 frame id numbers. 169 * ID3 frame id numbers.
155 */ 170 */
156 #define ID3_FRAME_ID(a,b,c,d) ((a << 24) | (b << 16) | (c << 8) | d) 171 #define ID3_FRAME_ID(a,b,c,d) ((a << 24) | (b << 16) | (c << 8) | d)
316 #define ID3_WCM ID3_FRAME_ID_22('W', 'C', 'M') 331 #define ID3_WCM ID3_FRAME_ID_22('W', 'C', 'M')
317 #define ID3_WCP ID3_FRAME_ID_22('W', 'C', 'P') 332 #define ID3_WCP ID3_FRAME_ID_22('W', 'C', 'P')
318 #define ID3_WPB ID3_FRAME_ID_22('W', 'P', 'B') 333 #define ID3_WPB ID3_FRAME_ID_22('W', 'P', 'B')
319 #define ID3_WXX ID3_FRAME_ID_22('W', 'X', 'X') 334 #define ID3_WXX ID3_FRAME_ID_22('W', 'X', 'X')
320 335
336 /*
337 * Handy macros which help us writing more secure length-aware code
338 * which involves reading the frame's data buffer.
339 */
340
341 #define ID3_FRAME_DEFINE_CURSOR(frame) \
342 gsize length = frame->fr_size; \
343 guint8* cursor = frame->fr_data;
344
345 #define ID3_FRAME_READ_OR_RETVAL(variable, retval) \
346 if (length < sizeof(variable)) \
347 return retval; \
348 memcpy((void*)&variable, (void*)cursor, sizeof(variable)); \
349 cursor += sizeof(variable); \
350 length -= sizeof(variable);
321 351
322 /* 352 /*
323 * Prototypes. 353 * Prototypes.
324 */ 354 */
325 355
330 int id3_set_output(struct id3_tag *, char *); 360 int id3_set_output(struct id3_tag *, char *);
331 int id3_close(struct id3_tag *); 361 int id3_close(struct id3_tag *);
332 int id3_tell(struct id3_tag *); 362 int id3_tell(struct id3_tag *);
333 int id3_alter_file(struct id3_tag *); 363 int id3_alter_file(struct id3_tag *);
334 int id3_write_tag(struct id3_tag *, int); 364 int id3_write_tag(struct id3_tag *, int);
365 char *id3_utf16_to_ascii(void *);
335 366
336 /* From id3_frame.c */ 367 /* From id3_frame.c */
337 int id3_read_frame(struct id3_tag *id3); 368 int id3_read_frame(struct id3_tag *id3);
338 struct id3_frame *id3_get_frame(struct id3_tag *, guint32, int); 369 struct id3_frame *id3_get_frame(struct id3_tag *, guint32, int);
339 int id3_delete_frame(struct id3_frame *frame); 370 int id3_delete_frame(struct id3_frame *frame);
341 int id3_decompress_frame(struct id3_frame *); 372 int id3_decompress_frame(struct id3_frame *);
342 void id3_destroy_frames(struct id3_tag *id); 373 void id3_destroy_frames(struct id3_tag *id);
343 void id3_frame_clear_data(struct id3_frame *frame); 374 void id3_frame_clear_data(struct id3_frame *frame);
344 375
345 /* From id3_frame_text.c */ 376 /* From id3_frame_text.c */
346 char *id3_utf16_to_ascii(void *); 377 gsize id3_string_size(guint8 encoding, const void* text, gsize max_size);
378 gchar* id3_string_decode(guint8 encoding, const void* text, gsize max_size);
347 gint8 id3_get_encoding(struct id3_frame *); 379 gint8 id3_get_encoding(struct id3_frame *);
348 int id3_set_encoding(struct id3_frame *, gint8); 380 int id3_set_encoding(struct id3_frame *, gint8);
349 char *id3_get_text(struct id3_frame *); 381 char *id3_get_text(struct id3_frame *);
350 char *id3_get_text_desc(struct id3_frame *); 382 char *id3_get_text_desc(struct id3_frame *);
351 int id3_get_text_number(struct id3_frame *); 383 int id3_get_text_number(struct id3_frame *);