mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-26 23:25:56 -05:00
Move dmap_add_field() to DMAP common code
This commit is contained in:
parent
39542aee27
commit
07df6bb4aa
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
138
src/httpd_daap.c
138
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)
|
||||
|
Loading…
Reference in New Issue
Block a user