mplib.c File Reference

#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
#include "xmalloc.h"
#include "mplib.h"
#include "mplib_s.h"
#include "mplib_s.c"

Go to the source code of this file.

Defines

#define FLD(str1, str2, str3, str4)

Functions

mpeg_headermp_get_mpeg_header_from_file (const char *filename)
 Allocates a MPEG header structure from a file.
mpeg_headermp_get_mpeg_header_from_fd (int fd)
 Gets the header structure from a file descriptor.
char * mp_get_str_version (const mpeg_header *h)
 Allocates a label with the appropriate header field value as a string.
char * mp_get_str_layer (const mpeg_header *h)
 Allocates a label with the appropriate header field value as a string.
char * mp_get_str_bitrate (const mpeg_header *h)
 Allocates a label with the appropriate header field value as a string.
char * mp_get_str_samplingfreq (const mpeg_header *h)
 Allocates a label with the appropriate header field value as a string.
char * mp_get_str_mode (const mpeg_header *h)
 Allocates a label with the appropriate header field value as a string.
id3_tag_listmp_get_tag_list_from_mem (void *buf, size_t size)
 Allocates and fills a list of tags found in the given memory buffer.
id3_tag_listmp_get_tag_list_from_file (const char *filename)
 Allocates and fills a list of tags found in the given file.
id3_tag_listmp_get_tag_list_from_fd (int fd)
 Allocates and fills a list of tags found in the given file.
id3_tag_listmp_get_tag_list (size_t(*read_func)(void *, size_t, void *), off_t(*lseek_func)(off_t, int, void *), void *arg)
 Allocates and fills a list of tags using read and seek wrapper functions.
id3_contentmp_get_content (const id3_tag *tag, int field)
 Gets the first content found of a specified field in the given tag and allocates a struct.
id3_contentmp_get_content_at_pos (const id3_tag *tag, int field, int pos)
 It's posible that a tag has multiple ocurances of a field, use this function to get a specified field by position.
id3_contentmp_get_content_custom (const id3_tag *tag, const char *field)
 Gets a custom fields content and allocates a struct.
id3_contentmp_get_content_custom_at_pos (const id3_tag *tag, const char *field, int pos)
 See mp_get_content_at_pos() and mp_get_content_custom().
int mp_set_content (id3_tag *tag, const int field, id3_content *new_content)
 Copys the value of a specified field into the given tag.
int mp_set_content_at_pos (id3_tag *tag, const int field, id3_content *new_content, int pos)
 Copys the value of a specified field into the given tag.
int mp_set_custom_content (id3_tag *tag, char *field, id3_content *new_content)
 Sets up a new custom field with the given value.
int mp_set_custom_content_at_pos (id3_tag *tag, char *field, id3_content *new_content, int pos)
 Sets up a new custom field with the given value on a certain frame position.
int mp_write_to_file (const id3_tag_list *tag_list, const char *filename)
 Writes the tag to the specified file.
int mp_write_to_fd (const id3_tag_list *tag_list, const int fd)
 Writes the tag to the specified file.
int mp_del_tags_from_file (const char *filename)
 Deletes all tags in file.
int mp_del_tags_from_fd (const int fd)
 Deletes all tags in file.
int mp_del_tags_by_ver_from_file (const char *filename, const int version)
 Deletes all tags in file with the specified version.
int mp_del_tags_by_ver_from_fd (const int fd, const int version)
 Deletes all tags in file with the specified version.
int mp_convert_to_v2 (id3_tag *tag)
 Converts a tag to id3v2 tag format.
int mp_convert_to_v1 (id3_tag *tag)
 Converts a tag to id3v1 tag format.
int mp_is_valid_v1_value (int field, char *value)
 Checks wether the given value would be a valid v1 field.
void mp_free_list (id3_tag_list *list)
 Frees a tag list beginning with the given element XXX.
id3_tagmp_alloc_tag (void)
 Gets a new allocated tag.
id3_tagmp_alloc_tag_with_version (int v)
 Gets a new allocated tag with the specified version.
void mp_free_tag (id3_tag *tag)
 Frees tag struct.
void mp_free_content (id3_content *content)
 Frees a content struct.
void mp_free_text_content (id3_text_content *content)
 Frees a text struct.
void mp_free_comment_content (id3_comment_content *content)
 Frees a comment struct.


Define Documentation

#define FLD str1,
str2,
str3,
str4   ) 
 

Value:

case str1:\
                                if(!new_content) v1->str2 = NULL;\
                                else\
                                {\
                                        id3_text_content *tc = str4(new_content);\
                                        if(strlen(tc->text) > str3 || tc->encoding != ISO_8859_1)\
                                        {\
                                                mp_convert_to_v2(tag);\
                                                mp_free_text_content(tc);\
                                                return mp_set_content(tag, field, new_content);\
                                        }\
                                        \
                                        v1->str2 = tc->text;\
                                        xfree(tc);\
                                }\
                                break;


Function Documentation

id3_tag* mp_alloc_tag void   ) 
 

Gets a new allocated tag.

Returns:
new allocated tag

Definition at line 961 of file mplib.c.

id3_tag* mp_alloc_tag_with_version int   ) 
 

Gets a new allocated tag with the specified version.

Returns:
new allocated tag with specified version

Definition at line 970 of file mplib.c.

int mp_convert_to_v1 id3_tag t  ) 
 

Converts a tag to id3v1 tag format.

Parameters:
t The tag to be converted
Returns:
0 on success or one of the following errors
  • MP_EVERSION - Function isn't able to handle a tag of this version

Definition at line 819 of file mplib.c.

int mp_convert_to_v2 id3_tag t  ) 
 

Converts a tag to id3v2 tag format.

Parameters:
t The tag to be converted
Returns:
0 on success or one of the following errors
  • MP_EVERSION - Function isn't able to handle a tag of this version

Definition at line 764 of file mplib.c.

int mp_del_tags_by_ver_from_fd int  fd,
int  version
 

Deletes all tags in file with the specified version.

Parameters:
fd The file descriptor
version Version of the tag that should be deleted
Returns:
0 on success

Definition at line 749 of file mplib.c.

int mp_del_tags_by_ver_from_file const char *  path,
int  version
 

Deletes all tags in file with the specified version.

Parameters:
path The filename
version Version of the tag that should be deleted
Returns:
0 on success

Definition at line 734 of file mplib.c.

int mp_del_tags_from_fd int  fd  ) 
 

Deletes all tags in file.

Parameters:
fd The file descriptor
Returns:
0 on success

Definition at line 723 of file mplib.c.

int mp_del_tags_from_file const char *  path  ) 
 

Deletes all tags in file.

Parameters:
path The filename
Returns:
0 on success

Definition at line 708 of file mplib.c.

void mp_free_comment_content id3_comment_content content  ) 
 

Frees a comment struct.

Definition at line 1041 of file mplib.c.

void mp_free_content id3_content content  ) 
 

Frees a content struct.

Definition at line 1025 of file mplib.c.

void mp_free_list id3_tag_list list  ) 
 

Frees a tag list beginning with the given element XXX.

Definition at line 946 of file mplib.c.

void mp_free_tag id3_tag t  ) 
 

Frees tag struct.

Parameters:
t the tag to free

Definition at line 1009 of file mplib.c.

void mp_free_text_content id3_text_content content  ) 
 

Frees a text struct.

Definition at line 1033 of file mplib.c.

id3_content* mp_get_content const id3_tag t,
int  f
 

Gets the first content found of a specified field in the given tag and allocates a struct.

Parameters:
t The tag
f The fields identifier
Returns:
The new allocated content for the specified field or NULL On NULL: errno set to the following values
  • MP_EERROR - General failure: may occure on wrong usage, but should never happen
  • MP_EFNF - Field does not exists in tag /invalid identifier
  • MP_EVERSION - Tag has a version set that is not supported by the library

Definition at line 314 of file mplib.c.

id3_content* mp_get_content_at_pos const id3_tag t,
int  f,
int  pos
 

It's posible that a tag has multiple ocurances of a field, use this function to get a specified field by position.

The first ocurance of the field in the tag is 0. e.g.: To get the third comment in an id3v2 tag use mp_get_content_at_pos(tag, MP_COMMENT, 2);

Parameters:
t The tag
f The fields identifier
pos The content position in the tag
Returns:
See also:
mp_get_content()

Definition at line 320 of file mplib.c.

id3_content* mp_get_content_custom const id3_tag t,
const char *  f
 

Gets a custom fields content and allocates a struct.

This function can only be applied to ID3v2 tags. It will lookup a by the given identifier and return its content.

Parameters:
t The tag
f The field names identifier e.g. ENCR
Returns:
See also:
mp_get_content()

Definition at line 374 of file mplib.c.

id3_content* mp_get_content_custom_at_pos const id3_tag t,
const char *  f,
int  pos
 

See mp_get_content_at_pos() and mp_get_content_custom().

Parameters:
t The tag
f The field names identifier e.g. ENCR
pos The content position in the tag
Returns:
See also:
mp_get_content()

Definition at line 392 of file mplib.c.

mpeg_header* mp_get_mpeg_header_from_fd int  fd  ) 
 

Gets the header structure from a file descriptor.

Parameters:
fd The file descriptor
Returns:
A pointer to a new initialized header structure - NULL on IO Error

Definition at line 88 of file mplib.c.

mpeg_header* mp_get_mpeg_header_from_file const char *  path  ) 
 

Allocates a MPEG header structure from a file.

Parameters:
path The filename
Returns:
A pointer to a new initialized header structure - NULL on IO Error

Definition at line 71 of file mplib.c.

char* mp_get_str_bitrate const mpeg_header h  ) 
 

Allocates a label with the appropriate header field value as a string.

Definition at line 142 of file mplib.c.

char* mp_get_str_layer const mpeg_header h  ) 
 

Allocates a label with the appropriate header field value as a string.

Definition at line 130 of file mplib.c.

char* mp_get_str_mode const mpeg_header h  ) 
 

Allocates a label with the appropriate header field value as a string.

Definition at line 208 of file mplib.c.

char* mp_get_str_samplingfreq const mpeg_header h  ) 
 

Allocates a label with the appropriate header field value as a string.

Definition at line 183 of file mplib.c.

char* mp_get_str_version const mpeg_header h  ) 
 

Allocates a label with the appropriate header field value as a string.

Definition at line 124 of file mplib.c.

id3_tag_list* mp_get_tag_list size_t(*)(void *, size_t, void *)  read_func,
off_t(*)(off_t, int, void *)  lseek_func,
void *  arg
 

Allocates and fills a list of tags using read and seek wrapper functions.

Parameters:
read_func Pointer to function that reads
lseek_func Pointer to function that seeks
arg Pointer to argument for read and seek wrapper functions
Returns:
A pointer to a initialized list struct or null if no tags have been found

Definition at line 259 of file mplib.c.

id3_tag_list* mp_get_tag_list_from_fd int  fd  ) 
 

Allocates and fills a list of tags found in the given file.

This list will contain at least one and at most two tags or is NULL if no tags have been found. This function prepares argument and calls mp_get_tag_list() function.

Parameters:
fd The file descriptor
Returns:
A pointer to a initialized list struct or null if no tags have been found

Definition at line 250 of file mplib.c.

id3_tag_list* mp_get_tag_list_from_file const char *  path  ) 
 

Allocates and fills a list of tags found in the given file.

This list will contain at least one and at most two tags or is NULL if no tags have been found. This function prepares argument and calls mp_get_tag_list() function.

Parameters:
path The files name to search for tags
Returns:
A pointer to a initialized list struct or null if no tags have been found

Definition at line 233 of file mplib.c.

id3_tag_list* mp_get_tag_list_from_mem void *  buf,
size_t  s
 

Allocates and fills a list of tags found in the given memory buffer.

This list will contain at least one and at most two tags or is NULL if no tags have been found. This function prepares argument and calls mp_get_tag_list() function.

Parameters:
buf Pointer to buffer to search for tags
s Size of the buffer
Returns:
A pointer to a initialized list struct or null if no tags have been found

Definition at line 221 of file mplib.c.

int mp_is_valid_v1_value int  field,
char *  value
 

Checks wether the given value would be a valid v1 field.

Parameters:
field The field
value The value
Returns:
0 if test failed

Definition at line 909 of file mplib.c.

int mp_set_content id3_tag t,
int  field,
id3_content content
 

Copys the value of a specified field into the given tag.

The content argument may be freed after using this function. The way a content is represented in a tag depends from the tags version and kind of field. I.e. it may be nessecary to represent a track number as a binary value in a v1 tag or to embeded it into a frame for a v2 tag. The caller just needs to give the correct identifier with the value as a id3_content and to take care of freeing the id3_content value afterwards.

Parameters:
t The tag to edit
field The fields identifier
content The fields new content
Returns:
0 success or one of the following errors
  • MP_EERROR - General failure: may occure on wrong usage, but should never happen
  • MP_EFNF - Field does not exists in tag /invalid identifier
  • MP_EVERSION - Function isn't able to handle a tag of this version

Definition at line 415 of file mplib.c.

int mp_set_content_at_pos id3_tag t,
int  field,
id3_content content,
int  pos
 

Copys the value of a specified field into the given tag.

This function allows to specify a certain frame position.

See also:
mp_set_content(id3_tag* t, int field, id3_content* content)
Parameters:
t The tag to edit
field The fields identifier
content The fields new content
pos The frame position that should be used
Returns:
0 success or one of the following errors
  • MP_EERROR - General failure: may occure on wrong usage, but should never happen
  • MP_EFNF - Field does not exists in tag /invalid identifier
  • MP_EVERSION - Function isn't able to handle a tag of this version

Definition at line 527 of file mplib.c.

int mp_set_custom_content id3_tag t,
char *  field,
id3_content content
 

Sets up a new custom field with the given value.

Parameters:
t The tag to edit
field The new fields name - A four chars upper case identifier e.g. ENCR
content The fields new content
Returns:
See mp_set_content

Definition at line 550 of file mplib.c.

int mp_set_custom_content_at_pos id3_tag t,
char *  field,
id3_content content,
int  pos
 

Sets up a new custom field with the given value on a certain frame position.

Parameters:
t The tag to edit
field The new fields name - A four chars upper case identifier e.g. ENCR
content The fields new content
pos The frame position that should be used
Returns:
See mp_set_content

Definition at line 556 of file mplib.c.

int mp_write_to_fd const id3_tag_list ls,
int  fd
 

Writes the tag to the specified file.

Parameters:
ls The tag list to be added to file - may be NULL for deleting all tags
fd The file descriptor
Returns:
0 on success or one of the following errors
  • MP_EERROR - General failure: may occure on wrong usage, but should never happen
  • MP_EVERSION - Function isn't able to handle a tag of this version

Definition at line 628 of file mplib.c.

int mp_write_to_file const id3_tag_list ls,
const char *  path
 

Writes the tag to the specified file.

Parameters:
ls The tag list to be added to file - may be NULL for deleting all tags
path The filename
Returns:
0 on success or one of the following errors
  • MP_EERROR - General failure: may occure on wrong usage, but should never happen
  • MP_EVERSION - Function isn't able to handle a tag of this version

Definition at line 611 of file mplib.c.