#include "config.h"
#endif
+#define _XOPEN_SOURCE 600
#include <lightmediascanner_plugin.h>
#include <lightmediascanner_db.h>
#include <sys/types.h>
#include <string.h>
#include <unistd.h>
+#define BE_4BYTE(a) ((((unsigned char*)a)[0] << 24) | \
+ (((unsigned char*)a)[1] << 16) | \
+ (((unsigned char*)a)[2] << 8) | \
+ ((unsigned char*)a)[3])
+#define BE_2BYTE(a) ((((unsigned char*)a)[0] << 8) | ((unsigned char*)a)[1])
+
enum StreamTypes {
STREAM_TYPE_UNKNOWN = 0,
STREAM_TYPE_AUDIO,
}
/* convert to host byte order */
- file_header->size = ntohl(file_header->size);
+ file_header->size = BE_4BYTE(&file_header->size);
#if 0
fprintf(stderr, "file_header type=%.*s\n", 4, file_header->type);
if (read(fd, size, 4) != 4)
return -1;
- *size = ntohl(*size);
+ *size = BE_4BYTE(size);
#if 0
fprintf(stderr, "header type=%.*s\n", 4, type);
}
static int
-_read_string(int fd, char **out, int *out_len)
+_read_string(int fd, char **out, unsigned int *out_len)
{
char *s;
uint16_t len;
if (read(fd, &len, 2) == -1)
return -1;
- len = ntohs(len);
+ len = BE_2BYTE(&len);
if (out) {
if (len > 0) {
- s = malloc(sizeof(char) * len + 1);
+ s = malloc(sizeof(char) * (len + 1));
if (read(fd, s, len) == -1) {
free(s);
return -1;
}
s[len] = '\0';
*out = s;
- }
- else {
+ } else
*out = NULL;
- }
*out_len = len;
- }
- else {
+ } else
lseek(fd, len, SEEK_CUR);
- }
+
+ return 0;
}
/*
* word Comment string length
* byte[] Comment string
*/
-static int
+static void
_parse_cont_header(int fd, struct rm_info *info)
{
- uint16_t version;
- uint16_t title_len;
- char *title;
-
/* Ps.: type and size were already read */
/* ignore version */
_read_string(fd, NULL, NULL); /* comment */
}
-static void
-_strstrip(char **str, unsigned int *p_len)
-{
- if (*str)
- lms_strstrip(*str, p_len);
-
- if (*p_len == 0 && *str) {
- free(*str);
- *str = NULL;
- }
-}
-
static void *
_match(struct plugin *p, const char *path, int len, int base)
{
stream_type = STREAM_TYPE_VIDEO;
}
- _strstrip(&info.title.str, &info.title.len);
- _strstrip(&info.artist.str, &info.artist.len);
+ lms_string_size_strip_and_free(&info.title);
+ lms_string_size_strip_and_free(&info.artist);
if (!info.title.str) {
int ext_idx;
info.title.str = malloc((info.title.len + 1) * sizeof(char));
memcpy(info.title.str, finfo->path + finfo->base, info.title.len);
info.title.str[info.title.len] = '\0';
- lms_charset_conv(ctxt->cs_conv, &info.title.str, &info.title.len);
}
+ lms_charset_conv(ctxt->cs_conv, &info.title.str, &info.title.len);
+
+ if (info.artist.str)
+ lms_charset_conv(ctxt->cs_conv, &info.artist.str, &info.artist.len);
#if 0
fprintf(stderr, "file %s info\n", finfo->path);