diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-07-17 16:43:15 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-07-17 16:43:15 +0300 |
commit | d9a94ef4e033021a47dae2b5b476347d770adf66 (patch) | |
tree | 0ab15f0b0d84da2577388def15a2c107a0a17581 /src | |
parent | 18cdf3341f738741f120e4f7e2a45c352232cfbe (diff) | |
download | idest-d9a94ef4e033021a47dae2b5b476347d770adf66.tar.gz idest-d9a94ef4e033021a47dae2b5b476347d770adf66.tar.bz2 |
Support for URL frames.
* src/frametab.gperf: Add URL frames.
Return meaningful error codes.
Diffstat (limited to 'src')
-rw-r--r-- | src/frametab.gperf | 118 |
1 files changed, 110 insertions, 8 deletions
diff --git a/src/frametab.gperf b/src/frametab.gperf index 3b8ab1d..83f3d9d 100644 --- a/src/frametab.gperf +++ b/src/frametab.gperf @@ -23,6 +23,7 @@ DQ(COMM) = { "lang", "condesc" }; DQ(TXXX) = { "descr" }; +DQ(WXXX) = { "descr" }; #define QUAL(name) sizeof(QID(name))/sizeof(QID(name)[0]), QID(name) #define QUALTEXT 0, NULL @@ -246,13 +247,14 @@ comm_encode(struct id3_frame *frame, const struct ed_item *item) static int comm_decode(struct ed_item *item, struct id3_frame const *frame) { + int rc; union id3_field *field; - if (decode_qv(item, frame, 1, 2)) - return 1; + if (rc = decode_qv(item, frame, 1, 2)) + return rc; field = id3_frame_field(frame, 3); if (!field) - return 1; + return IDEST_ERR_NOFIELD; /* FIXME: Recode as necessary */ item->value = field_to_string(field, 0); @@ -293,13 +295,13 @@ text_decode(struct ed_item *item, struct id3_frame const *frame) field = id3_frame_field(frame, 0); if (!field) - return 1; + return IDEST_ERR_NOFIELD; encoding = id3_field_gettextencoding(field); if (encoding == -1) - return 1; + return IDEST_ERR_BADCONV; field = id3_frame_field(frame, 1); if (!field) - return 1; + return IDEST_ERR_NOFIELD; /* FIXME: Recode as necessary */ item->value = field_to_string(field, isgenre); return 0; @@ -352,18 +354,109 @@ txxx_encode(struct id3_frame *frame, const struct ed_item *item) static int txxx_decode(struct ed_item *item, struct id3_frame const *frame) { + int rc; union id3_field *field; - if (decode_qv(item, frame, 1, 1)) - return 1; + if (rc = decode_qv(item, frame, 1, 1)) + return rc; field = id3_frame_field(frame, 2); if (!field) + return IDEST_ERR_NOFIELD; + /* FIXME: Recode as necessary */ + item->value = field_to_string(field, 0); + + return 0; +} + +/* FIXME: Comparator is defined, but there is still no way to + address multiple URL frames in the tag, as they lack qualifiers. +*/ +static int +url_cmp(struct id3_frame const *frame, const struct ed_item const *item) +{ + int rc; + union id3_field *field; + char *value; + + field = id3_frame_field(frame, 0); + if (!field) return 1; + value = field_to_string(field, 0); + rc = strcmp(value, item->value); + free(value); + return rc; +} + +static int +url_encode(struct id3_frame *frame, const struct ed_item *item) +{ + return frame_field_from_string(frame, 0, item->value); +} + +static int +url_decode(struct ed_item *item, struct id3_frame const *frame) +{ + union id3_field *field; + + field = id3_frame_field(frame, 0); + if (!field) + return IDEST_ERR_NOFIELD; /* FIXME: Recode as necessary */ item->value = field_to_string(field, 0); return 0; } + +static int +wxxx_cmp(struct id3_frame const *frame, const struct ed_item const *item) +{ + int rc; + struct ed_item itm; + + memset(&itm, 0, sizeof(itm)); + if (decode_qv(&itm, frame, 1, 1)) + return 1; + + rc = ed_item_qv_cmp(&itm, item); + ed_item_free_content(&itm); + return rc; +} + +static int +wxxx_encode(struct id3_frame *frame, const struct ed_item *item) +{ + int rc; + + /* Set encoding */ + rc = frame_field_from_string(frame, 0, NULL); + if (rc) + return rc; + + /* Set subfields */ + rc = encode_qv(frame, 1, item); + if (rc) + return rc; + return frame_field_from_string(frame, 2, item->value); +} + +static int +wxxx_decode(struct ed_item *item, struct id3_frame const *frame) +{ + int rc; + union id3_field *field; + + if (rc = decode_qv(item, frame, 1, 1)) + return rc; + + field = id3_frame_field(frame, 2); + if (!field) + return IDEST_ERR_NOFIELD; + /* FIXME: Recode as necessary */ + item->value = field_to_string(field, 0); + + return 0; +} + %} %define lookup-function-name idest_frame_lookup_len @@ -417,6 +510,15 @@ TSSE, QUALTEXT, NULL, text_encode, text_decode TSST, QUALTEXT, NULL, text_encode, text_decode TXXX, QUAL(TXXX), txxx_cmp, txxx_encode, txxx_decode USLT, QUAL(COMM), comm_cmp, comm_encode, comm_decode +WCOM, 0, NULL, url_cmp, url_encode, url_decode +WCOP, 0, NULL, NULL, url_encode, url_decode +WOAF, 0, NULL, NULL, url_encode, url_decode +WOAR, 0, NULL, url_cmp, url_encode, url_decode +WOAS, 0, NULL, NULL, url_encode, url_decode +WORS, 0, NULL, NULL, url_encode, url_decode +WPAY, 0, NULL, NULL, url_encode, url_decode +WPUB, 0, NULL, NULL, url_encode, url_decode +WXXX, QUAL(WXXX), wxxx_cmp, wxxx_encode, wxxx_decode %% const struct idest_frametab * idest_frame_lookup(const char *str) |