From 07df6bb4aa3d4848be0793f44477c2c75fd50612 Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Sat, 2 Apr 2011 14:46:51 +0200 Subject: [PATCH] Move dmap_add_field() to DMAP common code --- src/dmap_common.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++ src/dmap_common.h | 4 ++ src/httpd_daap.c | 138 ---------------------------------------------- 3 files changed, 142 insertions(+), 138 deletions(-) diff --git a/src/dmap_common.c b/src/dmap_common.c index 7a85e02d..e6b63f8c 100644 --- a/src/dmap_common.c +++ b/src/dmap_common.c @@ -27,6 +27,7 @@ #include "evhttp/evhttp.h" #include "db.h" +#include "misc.h" #include "logger.h" #include "dmap_common.h" @@ -191,6 +192,143 @@ dmap_add_string(struct evbuffer *evbuf, char *tag, const char *str) evbuffer_add(evbuf, str, len); } +void +dmap_add_field(struct evbuffer *evbuf, const struct dmap_field *df, char *strval, int32_t intval) +{ + union { + int32_t v_i32; + uint32_t v_u32; + int64_t v_i64; + uint64_t v_u64; + } val; + int ret; + + if (strval && (df->type != DMAP_TYPE_STRING)) + { + switch (df->type) + { + case DMAP_TYPE_DATE: + case DMAP_TYPE_UBYTE: + case DMAP_TYPE_USHORT: + case DMAP_TYPE_UINT: + ret = safe_atou32(strval, &val.v_u32); + if (ret < 0) + val.v_u32 = 0; + break; + + case DMAP_TYPE_BYTE: + case DMAP_TYPE_SHORT: + case DMAP_TYPE_INT: + ret = safe_atoi32(strval, &val.v_i32); + if (ret < 0) + val.v_i32 = 0; + break; + + case DMAP_TYPE_ULONG: + ret = safe_atou64(strval, &val.v_u64); + if (ret < 0) + val.v_u64 = 0; + break; + + case DMAP_TYPE_LONG: + ret = safe_atoi64(strval, &val.v_i64); + if (ret < 0) + val.v_i64 = 0; + break; + + /* DMAP_TYPE_VERSION & DMAP_TYPE_LIST not handled here */ + default: + DPRINTF(E_LOG, L_DAAP, "Unsupported DMAP type %d for DMAP field %s\n", df->type, df->desc); + return; + } + } + else if (!strval && (df->type != DMAP_TYPE_STRING)) + { + switch (df->type) + { + case DMAP_TYPE_DATE: + case DMAP_TYPE_UBYTE: + case DMAP_TYPE_USHORT: + case DMAP_TYPE_UINT: + val.v_u32 = intval; + break; + + case DMAP_TYPE_BYTE: + case DMAP_TYPE_SHORT: + case DMAP_TYPE_INT: + val.v_i32 = intval; + break; + + case DMAP_TYPE_ULONG: + val.v_u64 = intval; + break; + + case DMAP_TYPE_LONG: + val.v_i64 = intval; + break; + + /* DMAP_TYPE_VERSION & DMAP_TYPE_LIST not handled here */ + default: + DPRINTF(E_LOG, L_DAAP, "Unsupported DMAP type %d for DMAP field %s\n", df->type, df->desc); + return; + } + } + + switch (df->type) + { + case DMAP_TYPE_UBYTE: + if (val.v_u32) + dmap_add_char(evbuf, df->tag, val.v_u32); + break; + + case DMAP_TYPE_BYTE: + if (val.v_i32) + dmap_add_char(evbuf, df->tag, val.v_i32); + break; + + case DMAP_TYPE_USHORT: + if (val.v_u32) + dmap_add_short(evbuf, df->tag, val.v_u32); + break; + + case DMAP_TYPE_SHORT: + if (val.v_i32) + dmap_add_short(evbuf, df->tag, val.v_i32); + break; + + case DMAP_TYPE_DATE: + case DMAP_TYPE_UINT: + if (val.v_u32) + dmap_add_int(evbuf, df->tag, val.v_u32); + break; + + case DMAP_TYPE_INT: + if (val.v_i32) + dmap_add_int(evbuf, df->tag, val.v_i32); + break; + + case DMAP_TYPE_ULONG: + if (val.v_u64) + dmap_add_long(evbuf, df->tag, val.v_u64); + break; + + case DMAP_TYPE_LONG: + if (val.v_i64) + dmap_add_long(evbuf, df->tag, val.v_i64); + break; + + case DMAP_TYPE_STRING: + if (strval) + dmap_add_string(evbuf, df->tag, strval); + break; + + case DMAP_TYPE_VERSION: + case DMAP_TYPE_LIST: + return; + } +} + + void dmap_send_error(struct evhttp_request *req, char *container, char *errmsg) { diff --git a/src/dmap_common.h b/src/dmap_common.h index f8c5db5c..83734483 100644 --- a/src/dmap_common.h +++ b/src/dmap_common.h @@ -71,6 +71,10 @@ dmap_add_literal(struct evbuffer *evbuf, char *tag, char *str, int len); void dmap_add_string(struct evbuffer *evbuf, char *tag, const char *str); +void +dmap_add_field(struct evbuffer *evbuf, const struct dmap_field *df, char *strval, int32_t intval); + + void dmap_send_error(struct evhttp_request *req, char *container, char *errmsg); diff --git a/src/httpd_daap.c b/src/httpd_daap.c index bbe530c2..d705434e 100644 --- a/src/httpd_daap.c +++ b/src/httpd_daap.c @@ -280,144 +280,6 @@ update_fail_cb(struct evhttp_connection *evcon, void *arg) } -/* DMAP fields helpers */ -static void -dmap_add_field(struct evbuffer *evbuf, const struct dmap_field *df, char *strval, int32_t intval) -{ - union { - int32_t v_i32; - uint32_t v_u32; - int64_t v_i64; - uint64_t v_u64; - } val; - int ret; - - if (strval && (df->type != DMAP_TYPE_STRING)) - { - switch (df->type) - { - case DMAP_TYPE_DATE: - case DMAP_TYPE_UBYTE: - case DMAP_TYPE_USHORT: - case DMAP_TYPE_UINT: - ret = safe_atou32(strval, &val.v_u32); - if (ret < 0) - val.v_u32 = 0; - break; - - case DMAP_TYPE_BYTE: - case DMAP_TYPE_SHORT: - case DMAP_TYPE_INT: - ret = safe_atoi32(strval, &val.v_i32); - if (ret < 0) - val.v_i32 = 0; - break; - - case DMAP_TYPE_ULONG: - ret = safe_atou64(strval, &val.v_u64); - if (ret < 0) - val.v_u64 = 0; - break; - - case DMAP_TYPE_LONG: - ret = safe_atoi64(strval, &val.v_i64); - if (ret < 0) - val.v_i64 = 0; - break; - - /* DMAP_TYPE_VERSION & DMAP_TYPE_LIST not handled here */ - default: - DPRINTF(E_LOG, L_DAAP, "Unsupported DMAP type %d for DMAP field %s\n", df->type, df->desc); - return; - } - } - else if (!strval && (df->type != DMAP_TYPE_STRING)) - { - switch (df->type) - { - case DMAP_TYPE_DATE: - case DMAP_TYPE_UBYTE: - case DMAP_TYPE_USHORT: - case DMAP_TYPE_UINT: - val.v_u32 = intval; - break; - - case DMAP_TYPE_BYTE: - case DMAP_TYPE_SHORT: - case DMAP_TYPE_INT: - val.v_i32 = intval; - break; - - case DMAP_TYPE_ULONG: - val.v_u64 = intval; - break; - - case DMAP_TYPE_LONG: - val.v_i64 = intval; - break; - - /* DMAP_TYPE_VERSION & DMAP_TYPE_LIST not handled here */ - default: - DPRINTF(E_LOG, L_DAAP, "Unsupported DMAP type %d for DMAP field %s\n", df->type, df->desc); - return; - } - } - - switch (df->type) - { - case DMAP_TYPE_UBYTE: - if (val.v_u32) - dmap_add_char(evbuf, df->tag, val.v_u32); - break; - - case DMAP_TYPE_BYTE: - if (val.v_i32) - dmap_add_char(evbuf, df->tag, val.v_i32); - break; - - case DMAP_TYPE_USHORT: - if (val.v_u32) - dmap_add_short(evbuf, df->tag, val.v_u32); - break; - - case DMAP_TYPE_SHORT: - if (val.v_i32) - dmap_add_short(evbuf, df->tag, val.v_i32); - break; - - case DMAP_TYPE_DATE: - case DMAP_TYPE_UINT: - if (val.v_u32) - dmap_add_int(evbuf, df->tag, val.v_u32); - break; - - case DMAP_TYPE_INT: - if (val.v_i32) - dmap_add_int(evbuf, df->tag, val.v_i32); - break; - - case DMAP_TYPE_ULONG: - if (val.v_u64) - dmap_add_long(evbuf, df->tag, val.v_u64); - break; - - case DMAP_TYPE_LONG: - if (val.v_i64) - dmap_add_long(evbuf, df->tag, val.v_i64); - break; - - case DMAP_TYPE_STRING: - if (strval) - dmap_add_string(evbuf, df->tag, strval); - break; - - case DMAP_TYPE_VERSION: - case DMAP_TYPE_LIST: - return; - } -} - - /* DAAP sort headers helpers */ static struct sort_ctx * daap_sort_context_new(void)