#include <lightmediascanner_utils.h>
#include <ctype.h>
+#include <stdlib.h>
#include <alloca.h>
/**
}
/**
+ * If string exists, strips it, in place, free if *p_len = 0
+ *
+ * @param p_str pointer to string to be stripped.
+ * @param p_len string length to analyse, also the place where the final size
+ * is stored.
+ *
+ * @note this will call free() on *p_str if it becomes empty.
+ */
+void
+lms_strstrip_and_free(char **p_str, unsigned int *p_len)
+{
+ if (!*p_str)
+ return;
+
+ lms_strstrip(*p_str, p_len);
+ if (*p_len == 0) {
+ free(*p_str);
+ *p_str = NULL;
+ }
+}
+
+/**
+ * lms_string_size version of lms_strstrip_and_free().
+ *
+ * @param *p pointer to lms_string_size to be stripped.
+ *
+ * @note this will call free() on lms_string_size->str if it becomes empty.
+ */
+void
+lms_string_size_strip_and_free(struct lms_string_size *p)
+{
+ if (!*p->str)
+ return;
+
+ lms_strstrip(p->str, &p->len);
+ if (p->len == 0) {
+ free(p->str);
+ p->str = NULL;
+ }
+}
+
+
+/**
* Find out which of the given extensions matches the given name.
*
* @param name string to analyse.
API void lms_strstrip(char *str, unsigned int *p_len) GNUC_NON_NULL(1, 2);
+ API void lms_strstrip_and_free(char **p_str, unsigned int *p_len) GNUC_NON_NULL(1, 2);
+ API void lms_string_size_strip_and_free(struct lms_string_size *p) GNUC_NON_NULL(1);
API int lms_which_extension(const char *name, unsigned int name_len, const struct lms_string_size *exts, unsigned int exts_len) GNUC_NON_NULL(1, 3);
}
}
-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);
- _strstrip(&info.album.str, &info.album.len);
- _strstrip(&info.genre.str, &info.genre.len);
+ lms_string_size_strip_and_free(&info.title);
+ lms_string_size_strip_and_free(&info.artist);
+ lms_string_size_strip_and_free(&info.album);
+ lms_string_size_strip_and_free(&info.genre);
if (!info.title.str) {
int ext_idx;
size++;
s->str = (char *)malloc(size * sizeof(char));
s->len = field->Get(s->str, size);
- if (s->len > 0)
- lms_strstrip(s->str, &s->len);
-
- if (s->len < 1) {
- free(s->str);
- s->str = NULL;
- s->len = 0;
- }
+ lms_string_size_strip_and_free(s);
done:
field->SetEncoding(enc);
comment->str[len] = '\0';
comment->len = len;
- lms_strstrip(comment->str, &comment->len);
- if (comment->len == 0) {
- free(comment->str);
- comment->str = NULL;
- }
+ lms_string_size_strip_and_free(comment);
return 0;
}
s->str[count] = '\0';
s->len = count;
- lms_strstrip(s->str, &s->len);
- if (s->len == 0) {
- free(s->str);
- s->str = NULL;
- }
+ lms_string_size_strip_and_free(s);
return 0;
}
s->str[count - 1] = '\0';
s->len = count - 1;
- lms_strstrip(s->str, &s->len);
- if (s->len == 0) {
- free(s->str);
- s->str = NULL;
- }
+ lms_string_size_strip_and_free(s);
return 0;
}
LMS_STATIC_STRING_SIZE(".mp4")
};
-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)
{
if (num_tracks > 0)
stream_type = STREAM_TYPE_VIDEO;
- _strstrip(&info.title.str, &info.title.len);
- _strstrip(&info.artist.str, &info.artist.len);
- _strstrip(&info.album.str, &info.album.len);
- _strstrip(&info.genre.str, &info.genre.len);
+ lms_string_size_strip_and_free(&info.title);
+ lms_string_size_strip_and_free(&info.artist);
+ lms_string_size_strip_and_free(&info.album);
+ lms_string_size_strip_and_free(&info.genre);
if (!info.title.str) {
int ext_idx;
info->title.len = size;
info->title.str = malloc(size * sizeof(char));
memcpy(info->title.str, tag, size);
+ lms_string_size_strip_and_free(&info->title);
}
tag = vorbis_comment_query(&vc, "ARTIST", 0);
info->artist.len = size;
info->artist.str = malloc(size * sizeof(char));
memcpy(info->artist.str, tag, size);
+ lms_string_size_strip_and_free(&info->artist);
}
tag = vorbis_comment_query(&vc, "ALBUM", 0);
info->album.len = size;
info->album.str = malloc(size * sizeof(char));
memcpy(info->album.str, tag, size);
+ lms_string_size_strip_and_free(&info->album);
}
tag = vorbis_comment_query(&vc, "TRACKNUMBER", 0);
info->genre.len = size;
info->genre.str = malloc(size * sizeof(char));
memcpy(info->genre.str, tag, size);
+ lms_string_size_strip_and_free(&info->genre);
}
fclose(file);
_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;