diff --git a/src/dmap_common.c b/src/dmap_common.c index ae25991c..7a85e02d 100644 --- a/src/dmap_common.c +++ b/src/dmap_common.c @@ -26,8 +26,22 @@ #include #include "evhttp/evhttp.h" -#include "dmap_common.h" +#include "db.h" #include "logger.h" +#include "dmap_common.h" + + +/* gperf static hash, dmap_fields.gperf */ +#include "dmap_fields_hash.c" + + +const struct dmap_field * +dmap_get_fields_table(int *nfields) +{ + *nfields = sizeof(dmap_fields) / sizeof(dmap_fields[0]); + + return dmap_fields; +} void diff --git a/src/dmap_common.h b/src/dmap_common.h index d0665e08..f8c5db5c 100644 --- a/src/dmap_common.h +++ b/src/dmap_common.h @@ -21,6 +21,35 @@ enum dmap_type DMAP_TYPE_LIST = 0x0c, }; +struct dmap_field_map { + ssize_t mfi_offset; + ssize_t pli_offset; + ssize_t gri_offset; +}; + +struct dmap_field { + char *desc; + char *tag; + const struct dmap_field_map *dfm; + enum dmap_type type; +}; + + +extern const struct dmap_field_map dfm_dmap_mikd; +extern const struct dmap_field_map dfm_dmap_asdk; +extern const struct dmap_field_map dfm_dmap_ascd; +extern const struct dmap_field_map dfm_dmap_mimc; +extern const struct dmap_field_map dfm_dmap_aeSP; + + +const struct dmap_field * +dmap_get_fields_table(int *nfields); + +/* From dmap_fields.gperf - keep in sync, don't alter */ +const struct dmap_field * +dmap_find_field (register const char *str, register unsigned int len); + + void dmap_add_container(struct evbuffer *evbuf, char *tag, int len); diff --git a/src/dmap_fields.gperf b/src/dmap_fields.gperf index db6fd642..bae24132 100644 --- a/src/dmap_fields.gperf +++ b/src/dmap_fields.gperf @@ -11,16 +11,17 @@ %struct-type %omit-struct-type %{ +/* Non-static fields are exported by dmap_common.h */ static const struct dmap_field_map dfm_dmap_miid = { dbmfi_offsetof(id), dbpli_offsetof(id), -1 }; static const struct dmap_field_map dfm_dmap_minm = { dbmfi_offsetof(title), dbpli_offsetof(title), dbgri_offsetof(itemname) }; -static const struct dmap_field_map dfm_dmap_mikd = { dbmfi_offsetof(item_kind), -1, -1 }; +const struct dmap_field_map dfm_dmap_mikd = { dbmfi_offsetof(item_kind), -1, -1 }; static const struct dmap_field_map dfm_dmap_mper = { dbmfi_offsetof(id), dbpli_offsetof(id), dbgri_offsetof(persistentid) }; static const struct dmap_field_map dfm_dmap_mcon = { -1, -1, -1 }; static const struct dmap_field_map dfm_dmap_mcti = { dbmfi_offsetof(id), -1, -1 }; static const struct dmap_field_map dfm_dmap_mpco = { -1, -1, -1 }; static const struct dmap_field_map dfm_dmap_mstt = { -1, -1, -1 }; static const struct dmap_field_map dfm_dmap_msts = { -1, -1, -1 }; -static const struct dmap_field_map dfm_dmap_mimc = { dbmfi_offsetof(total_tracks), dbpli_offsetof(items), dbgri_offsetof(itemcount) }; +const struct dmap_field_map dfm_dmap_mimc = { dbmfi_offsetof(total_tracks), dbpli_offsetof(items), dbgri_offsetof(itemcount) }; static const struct dmap_field_map dfm_dmap_mctc = { -1, -1, -1 }; static const struct dmap_field_map dfm_dmap_mrco = { -1, -1, -1 }; static const struct dmap_field_map dfm_dmap_mtco = { -1, -1, -1 }; @@ -88,7 +89,7 @@ static const struct dmap_field_map dfm_dmap_astc = { dbmfi_offsetof(total_tracks static const struct dmap_field_map dfm_dmap_astn = { dbmfi_offsetof(track), -1, -1 }; static const struct dmap_field_map dfm_dmap_asur = { dbmfi_offsetof(rating), -1, -1 }; static const struct dmap_field_map dfm_dmap_asyr = { dbmfi_offsetof(year), -1, -1 }; -static const struct dmap_field_map dfm_dmap_asdk = { dbmfi_offsetof(data_kind), -1, -1 }; +const struct dmap_field_map dfm_dmap_asdk = { dbmfi_offsetof(data_kind), -1, -1 }; static const struct dmap_field_map dfm_dmap_asul = { dbmfi_offsetof(url), -1, -1 }; static const struct dmap_field_map dfm_dmap_aply = { -1, -1, -1 }; static const struct dmap_field_map dfm_dmap_abpl = { -1, -1, -1 }; @@ -96,9 +97,9 @@ static const struct dmap_field_map dfm_dmap_apso = { -1, static const struct dmap_field_map dfm_dmap_arsv = { -1, -1, -1 }; static const struct dmap_field_map dfm_dmap_arif = { -1, -1, -1 }; static const struct dmap_field_map dfm_dmap_aeNV = { -1, -1, -1 }; -static const struct dmap_field_map dfm_dmap_aeSP = { -1, -1, -1 }; +const struct dmap_field_map dfm_dmap_aeSP = { -1, -1, -1 }; static const struct dmap_field_map dfm_dmap_aePS = { -1, -1, -1 }; -static const struct dmap_field_map dfm_dmap_ascd = { dbmfi_offsetof(codectype), -1, -1 }; +const struct dmap_field_map dfm_dmap_ascd = { dbmfi_offsetof(codectype), -1, -1 }; static const struct dmap_field_map dfm_dmap_ascs = { -1, -1, -1 }; static const struct dmap_field_map dfm_dmap_agrp = { dbmfi_offsetof(grouping), -1, -1 }; static const struct dmap_field_map dfm_dmap_aeSV = { -1, -1, -1 }; diff --git a/src/httpd_daap.c b/src/httpd_daap.c index f8925f24..bbe530c2 100644 --- a/src/httpd_daap.c +++ b/src/httpd_daap.c @@ -79,19 +79,6 @@ struct daap_update_request { struct daap_update_request *next; }; -struct dmap_field_map { - ssize_t mfi_offset; - ssize_t pli_offset; - ssize_t gri_offset; -}; - -struct dmap_field { - char *desc; - char *tag; - const struct dmap_field_map *dfm; - enum dmap_type type; -}; - struct sort_ctx { struct evbuffer *headerlist; int16_t mshc; @@ -101,9 +88,6 @@ struct sort_ctx { }; -/* gperf static hash, dmap_fields.gperf */ -#include "dmap_fields_hash.c" - /* Default meta tags if not provided in the query */ static char *default_meta_plsongs = "dmap.itemkind,dmap.itemid,dmap.itemname,dmap.containeritemid,dmap.parentcontainerid"; static char *default_meta_pl = "dmap.itemid,dmap.itemname,dmap.persistentid,com.apple.itunes.smart-playlist"; @@ -811,12 +795,16 @@ daap_reply_server_info(struct evhttp_request *req, struct evbuffer *evbuf, char static void daap_reply_content_codes(struct evhttp_request *req, struct evbuffer *evbuf, char **uri, struct evkeyvalq *query) { + const struct dmap_field *dmap_fields; + int nfields; int i; int len; int ret; + dmap_fields = dmap_get_fields_table(&nfields); + len = 12; - for (i = 0; i < (sizeof(dmap_fields) / sizeof(dmap_fields[0])); i++) + for (i = 0; i < nfields; i++) len += 8 + 12 + 10 + 8 + strlen(dmap_fields[i].desc); ret = evbuffer_expand(evbuf, len + 8); @@ -831,7 +819,7 @@ daap_reply_content_codes(struct evhttp_request *req, struct evbuffer *evbuf, cha dmap_add_container(evbuf, "mccr", len); dmap_add_int(evbuf, "mstt", 200); - for (i = 0; i < (sizeof(dmap_fields) / sizeof(dmap_fields[0])); i++) + for (i = 0; i < nfields; i++) { len = 12 + 10 + 8 + strlen(dmap_fields[i].desc); @@ -1064,6 +1052,7 @@ daap_reply_songlist_generic(struct evhttp_request *req, struct evbuffer *evbuf, struct evbuffer *song; struct evbuffer *songlist; const struct dmap_field_map *dfm; + const struct dmap_field *dmap_fields; const struct dmap_field *df; const struct dmap_field **meta; struct sort_ctx *sctx; @@ -1071,6 +1060,7 @@ daap_reply_songlist_generic(struct evhttp_request *req, struct evbuffer *evbuf, char *tag; char **strval; char *ptr; + int nfields; int nmeta; int sort_headers; int nsongs; @@ -1081,6 +1071,8 @@ daap_reply_songlist_generic(struct evhttp_request *req, struct evbuffer *evbuf, int i; int ret; + dmap_fields = dmap_get_fields_table(&nfields); + DPRINTF(E_DBG, L_DAAP, "Fetching song list for playlist %d\n", playlist); if (playlist != -1) @@ -1224,7 +1216,7 @@ daap_reply_songlist_generic(struct evhttp_request *req, struct evbuffer *evbuf, else { /* End of list */ - if (i == (sizeof(dmap_fields) / sizeof(dmap_fields[0]))) + if (i == nfields) break; df = &dmap_fields[i];