2004-06-16 23:52:59 +02:00
|
|
|
/* the Music Player Daemon (MPD)
|
2006-07-14 21:37:45 +02:00
|
|
|
* (c)2003-2006 by Warren Dukes (warren.dukes@gmail.com)
|
2004-06-16 23:52:59 +02:00
|
|
|
* This project's homepage is: http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2004-06-06 21:41:03 +02:00
|
|
|
#include "metadataChunk.h"
|
2006-07-30 12:31:41 +02:00
|
|
|
#include "gcc.h"
|
2004-06-06 21:41:03 +02:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static void initMetadataChunk(MetadataChunk * chunk)
|
|
|
|
{
|
2004-06-06 21:41:03 +02:00
|
|
|
chunk->name = -1;
|
|
|
|
chunk->artist = -1;
|
|
|
|
chunk->album = -1;
|
|
|
|
chunk->title = -1;
|
|
|
|
}
|
|
|
|
|
2004-11-10 22:58:27 +01:00
|
|
|
#define dupElementToTag(item, element) { \
|
2004-06-06 22:34:00 +02:00
|
|
|
if(element >= 0 && element < METADATA_BUFFER_LENGTH) { \
|
2004-11-10 22:58:27 +01:00
|
|
|
addItemToMpdTag(ret, item, chunk->buffer+element); \
|
2004-06-06 22:34:00 +02:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
MpdTag *metadataChunkToMpdTagDup(MetadataChunk * chunk)
|
|
|
|
{
|
|
|
|
MpdTag *ret = newMpdTag();
|
2004-06-06 21:41:03 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
chunk->buffer[METADATA_BUFFER_LENGTH - 1] = '\0';
|
2004-06-06 22:34:00 +02:00
|
|
|
|
2004-11-10 22:58:27 +01:00
|
|
|
dupElementToTag(TAG_ITEM_NAME, chunk->name);
|
|
|
|
dupElementToTag(TAG_ITEM_TITLE, chunk->title);
|
|
|
|
dupElementToTag(TAG_ITEM_ARTIST, chunk->artist);
|
|
|
|
dupElementToTag(TAG_ITEM_ALBUM, chunk->album);
|
2004-06-06 21:41:03 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define copyStringToChunk(string, element) { \
|
2004-11-11 01:04:16 +01:00
|
|
|
if(element < 0 && string && (slen = strlen(string)) && \
|
2004-06-06 21:41:03 +02:00
|
|
|
pos < METADATA_BUFFER_LENGTH-1) \
|
|
|
|
{ \
|
2006-07-30 12:31:41 +02:00
|
|
|
size_t len = slen; \
|
|
|
|
size_t max = METADATA_BUFFER_LENGTH - 1 - pos; \
|
|
|
|
if (mpd_unlikely(len > max)) \
|
|
|
|
len = max; \
|
|
|
|
memcpy(chunk->buffer+pos, string, len); \
|
|
|
|
*(chunk->buffer+pos+len) = '\0'; \
|
2004-06-06 21:41:03 +02:00
|
|
|
element = pos; \
|
|
|
|
pos += slen+1; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
void copyMpdTagToMetadataChunk(MpdTag * tag, MetadataChunk * chunk)
|
|
|
|
{
|
2004-06-06 21:41:03 +02:00
|
|
|
int pos = 0;
|
|
|
|
int slen;
|
2004-11-11 01:04:16 +01:00
|
|
|
int i;
|
2004-06-06 21:41:03 +02:00
|
|
|
|
|
|
|
initMetadataChunk(chunk);
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!tag)
|
|
|
|
return;
|
2004-10-25 22:09:03 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
for (i = 0; i < tag->numOfItems; i++) {
|
|
|
|
switch (tag->items[i].type) {
|
2004-11-11 01:04:16 +01:00
|
|
|
case TAG_ITEM_NAME:
|
|
|
|
copyStringToChunk(tag->items[i].value, chunk->name);
|
|
|
|
break;
|
|
|
|
case TAG_ITEM_TITLE:
|
|
|
|
copyStringToChunk(tag->items[i].value, chunk->title);
|
|
|
|
break;
|
|
|
|
case TAG_ITEM_ARTIST:
|
|
|
|
copyStringToChunk(tag->items[i].value, chunk->artist);
|
|
|
|
break;
|
|
|
|
case TAG_ITEM_ALBUM:
|
2006-04-22 03:36:52 +02:00
|
|
|
copyStringToChunk(tag->items[i].value, chunk->album);
|
2004-11-11 01:04:16 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-06-06 21:41:03 +02:00
|
|
|
}
|