mplib.h

Go to the documentation of this file.
00001 /*
00002  * mplib - a library that enables you to edit ID3 tags
00003  *
00004  * Copyright (c) 2001,2002,2003,2004,2005,2006 Stefan Podkowinski
00005  *               2006                          Michal Kowalczuk
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without 
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * * Redistributions of source code must retain the above copyright notice, this
00012  *   list of conditions and the following disclaimer.
00013  * * Redistributions in binary form must reproduce the above copyright notice,
00014  *   this list of conditions and the following disclaimer in the documentation
00015  *   and/or other materials provided with the distribution.
00016  * * Neither the name of the author nor the names of its contributors
00017  *   may be used to endorse or promote products derived from this software
00018  *   without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00021  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00022  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00023  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00024  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00025  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00026  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00029  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00030  * POSSIBILITY OF SUCH DAMAGE.
00031  */
00032 
00033 #ifndef __MPLIB_H
00034 #define __MPLIB_H
00035 
00036 
00037 /* __BEGIN_DECLS should be used at the beginning of your declarations,
00038    so that C++ compilers don't mangle their names.  Use __END_DECLS at
00039    the end of C declarations. */
00040 #undef __BEGIN_DECLS
00041 #undef __END_DECLS
00042 #ifdef __cplusplus
00043 # define __BEGIN_DECLS extern "C" {
00044 # define __END_DECLS }
00045 #else
00046 # define __BEGIN_DECLS /* empty */
00047 # define __END_DECLS /* empty */
00048 #endif
00049 
00050 /* __P is a macro used to wrap function prototypes, so that compilers
00051    that don't understand ANSI C prototypes still work, and ANSI C
00052    compilers can issue warnings about type mismatches. */
00053 #undef __P
00054 #if defined (__STDC__) || defined (_AIX) \
00055         || (defined (__mips) && defined (_SYSTYPE_SVR4)) \
00056         || defined(WIN32) || defined(__cplusplus)
00057 # define __P(protos) protos
00058 #else
00059 # define __P(protos) ()
00060 #endif
00061 
00062 
00063 __BEGIN_DECLS
00064 
00065 
00085 /*************************************/
00086 /*             Defines               */
00087 /*************************************/
00088 
00089 #define MP_ARTIST 1
00090 #define MP_TITLE 2
00091 #define MP_ALBUM 3
00092 #define MP_GENRE 4
00093 #define MP_COMMENT 5
00094 #define MP_YEAR 6
00095 #define MP_TRACK 7
00096 
00097 #define ISO_8859_1 0
00098 #define UTF16 1
00099 #define UTF16BE 2
00100 #define UTF8 3
00101 
00102 
00103 /*************************************/
00104 /*              errno values         */
00105 /*************************************/
00106 #define MP_EERROR 1
00107 #define MP_EFNF 2
00108 #define MP_EFCOMPR 3
00109 #define MP_EFENCR 4
00110 /*define MP_EUNICODE 5*/
00111 #define MP_EVERSION 6
00112 
00113 
00114 /*************************************/
00115 /*        Structs and company        */
00116 /*************************************/
00117 
00119 typedef struct _mpeg_header 
00120 {
00121   unsigned int syncword; 
00122   unsigned int version; 
00123   unsigned int layer; 
00124   unsigned int protbit; 
00125   unsigned int bitrate; 
00126   unsigned int samplingfreq; 
00127   unsigned int padbit; 
00128   unsigned int privbit; 
00129   unsigned int mode; 
00130   unsigned int mode_ext; 
00131   unsigned int copyright; 
00132   unsigned int originalhome; 
00133   unsigned int emphasis; 
00134 } mpeg_header;
00135 
00136 
00138 typedef struct _id3_tag
00139 {
00140   int version; 
00141   void *tag; 
00142 } id3_tag;
00143 
00144 
00146 typedef struct _id3_tag_list
00147 {
00148   id3_tag *tag;
00149   struct _id3_tag_list *next;
00150   struct _id3_tag_list *first;
00151 } id3_tag_list;
00152 
00153 
00154 /*
00155  * The following structures are ment as low-level data holders. I strongly
00156  * suggest you to use the appropriate generic functions below to access them.
00157  */
00158 
00159 /* V 1 */
00160 
00162 typedef struct _id3v1_tag
00163 {
00164   char *title;
00165   char *artist;
00166   char *album;
00167   char *year;
00168   char *comment;
00169   unsigned char track; 
00170   unsigned char genre; 
00171 } id3v1_tag;
00172 
00173 
00174 /* V 2 */
00175 
00177 typedef struct _id3v2_frame
00178 {
00179   char* frame_id; 
00180   unsigned char status_flag;
00181   unsigned char format_flag;
00182   char *data;
00183   unsigned int data_size; 
00185 } id3v2_frame;
00186 
00188 typedef struct _id3v2_frame_list
00189 {
00190   struct _id3v2_frame *data;
00191   struct _id3v2_frame_list *next;
00192   struct _id3v2_frame_list *start;
00193 } id3v2_frame_list;
00194 
00196 typedef struct _id3v2_extended_header
00197 {
00198   unsigned long size;
00199   char *flag_bytes;
00200   unsigned int no_flag_bytes;
00201   unsigned int is_update;
00202   unsigned int crc_data_present;
00203   unsigned char crc_data_length;
00204   unsigned char* crc_data;
00205   unsigned int restrictions;
00206   unsigned char restrictions_data_length;
00207   unsigned char* restrictions_data;
00208 } id3v2_extended_header;
00209 
00211 typedef struct _id3v2_header
00212 {
00214   unsigned int version_minor;
00215   unsigned int version_revision;
00216   char flags; 
00218   unsigned int unsyncronization;
00219   unsigned int has_extended_header;
00220   unsigned int is_experimental;
00221   unsigned int has_footer;
00222   unsigned long total_tag_size; 
00224   id3v2_extended_header *extended_header;   
00225 } id3v2_header;
00226 
00227 
00229 typedef struct _id3v2_tag
00230 {
00231   id3v2_header *header;
00232   id3v2_frame_list *frame_list;
00233 } id3v2_tag;
00234 
00236 typedef struct _id3_content
00237 {
00238   unsigned int compressed;
00239   unsigned int encrypted;
00240   char *data;
00241   unsigned int length;
00242 } id3_content;
00243 
00245 typedef enum _id3_encoding
00246 {
00247   iso_8859_1 = ISO_8859_1,
00248   utf16 = UTF16,
00249   utf16be = UTF16BE,
00250   utf8 = UTF8
00251 } id3_encoding;
00252 
00254 typedef struct _id3_text_content
00255 {
00256   id3_encoding encoding;
00257   char *text; 
00258 } id3_text_content;
00259 
00261 typedef struct _id3_comment_content
00262 {
00263   id3_encoding encoding;
00264   char *language; 
00265   char *short_descr; 
00266   char *text; 
00267 } id3_comment_content;
00268 
00269 /***************************************/
00270 /*               Functions             */
00271 /***************************************/
00272 
00278 extern mpeg_header *mp_get_mpeg_header_from_file __P((const char* path));
00279 
00280 
00286 extern mpeg_header *mp_get_mpeg_header_from_fd __P((int fd));
00287 
00288 
00293 #define mp_free_mpeg_header(str) xfree(str)
00294 
00295 
00297 extern char *mp_get_str_version __P((const mpeg_header*));
00299 extern char *mp_get_str_layer __P((const mpeg_header*));
00301 extern char *mp_get_str_bitrate __P((const mpeg_header*));
00303 extern char *mp_get_str_samplingfreq __P((const mpeg_header*));
00305 extern char *mp_get_str_mode __P((const mpeg_header*));
00306 
00307 
00317 extern id3_tag_list* mp_get_tag_list_from_file __P((const char* path));
00318 
00328 extern id3_tag_list* mp_get_tag_list_from_fd __P((int fd));
00329 
00330 
00341 extern id3_tag_list* mp_get_tag_list_from_mem __P((void * buf, size_t s));
00342 
00351 extern id3_tag_list* mp_get_tag_list __P((size_t (*read_func)(void *, size_t, void *),
00352                                                 off_t (*lseek_func)(off_t, int, void *),
00353                                                 void *arg));
00354 
00355 
00357 extern void mp_free_list __P((id3_tag_list*));
00358 
00359 
00372 extern id3_content* mp_get_content __P((const id3_tag* t, int f));
00373 
00385 extern id3_content* mp_get_content_at_pos __P((const id3_tag* t, int f, int pos));
00386 
00395 extern id3_content* mp_get_content_custom __P((const id3_tag* t, const char* f));
00396 
00404 extern id3_content* mp_get_content_custom_at_pos __P((const id3_tag* t, const char* f, int pos));
00405 
00407 extern void mp_free_content __P((id3_content*));
00409 extern void mp_free_text_content __P((id3_text_content*));
00411 extern void mp_free_comment_content __P((id3_comment_content*));
00412 
00413 
00430 extern int mp_set_content __P((id3_tag* t, int field, id3_content* content));
00431 
00445 extern int mp_set_content_at_pos __P((id3_tag* t, int field, id3_content* content, int pos));
00446 
00454 extern int mp_set_custom_content __P((id3_tag* t, char* field, id3_content* content));
00455 
00464 extern int mp_set_custom_content_at_pos __P((id3_tag* t, char* field, id3_content* content, int pos));
00465 
00474 extern int mp_write_to_file __P((const id3_tag_list* ls, const char* path));
00475 
00484 extern int mp_write_to_fd __P((const id3_tag_list* ls, int fd));
00485 
00491 extern int mp_del_tags_from_file __P((const char* path));
00492 
00498 extern int mp_del_tags_from_fd __P((int fd));
00499 
00506 extern int mp_del_tags_by_ver_from_file __P((const char* path, int version));
00507 
00514 extern int mp_del_tags_by_ver_from_fd __P((int fd, int version));
00515 
00522 extern int mp_convert_to_v1 __P((id3_tag* t));
00523 
00530 extern int mp_convert_to_v2 __P((id3_tag* t));
00531 
00538 extern int mp_is_valid_v1_value __P((int field, char* value));
00539 
00550 extern id3_text_content *mp_parse_artist __P((const id3_content* content));
00551 
00562 extern id3_text_content *mp_parse_title __P((const id3_content* content));
00563 
00574 extern id3_text_content *mp_parse_album __P((const id3_content* content));
00575 
00586 extern id3_text_content *mp_parse_year __P((const id3_content* content));
00587 
00598 extern id3_text_content *mp_parse_genre __P((const id3_content* content));
00599 
00610 extern id3_text_content *mp_parse_track __P((const id3_content* content));
00611 
00622 extern id3_text_content *mp_parse_text __P((const id3_content* content));
00623 
00634 extern id3_comment_content *mp_parse_comment __P((const id3_content* content));
00635 
00642 extern id3_content *mp_assemble_text_content __P((const char* text, id3_encoding enc));
00643 
00652 extern id3_content *mp_assemble_comment_content __P((const char* text, const char* descr, 
00653     id3_encoding enc, const char* lang));
00654 
00659 extern id3_tag* mp_alloc_tag __P((void));
00660 
00665 extern id3_tag* mp_alloc_tag_with_version __P((int));
00666 
00671 extern void mp_free_tag __P((id3_tag* t));
00672 
00673 
00674 typedef struct _mem_arg
00675 {
00676         void *buf;
00677         size_t size;
00678         void *act;
00679 } mem_arg;
00680 
00681 typedef struct _file_arg
00682 {
00683         int fd;
00684 } file_arg;
00685 
00686 
00687 __END_DECLS
00688 
00689 #endif /* __MPLIB_H */