From: Juho Vähä-Herttua Date: Thu, 15 Mar 2012 11:57:10 +0000 (+0200) Subject: Move hwaddress to raop_start instead of raop_init. X-Git-Tag: upstream/0.9.0~4^2~111 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=406e97773573c7f8b4d019025e2694b914aca830;p=deb_shairplay.git Move hwaddress to raop_start instead of raop_init. --- diff --git a/AirTV-Qt/raopservice.cpp b/AirTV-Qt/raopservice.cpp index 43689c3..19ba624 100644 --- a/AirTV-Qt/raopservice.cpp +++ b/AirTV-Qt/raopservice.cpp @@ -80,6 +80,7 @@ RaopService::~RaopService() bool RaopService::init() { const char hwaddr[] = { 0x48, 0x5d, 0x60, 0x7c, 0xee, 0x22 }; + raop_callbacks_t raop_cbs; int error; @@ -106,7 +107,7 @@ bool RaopService::init() QByteArray array = file.read(file.size()); array.append('\0'); - m_raop = raop_init(&raop_cbs, array.data(), hwaddr, sizeof(hwaddr)); + m_raop = raop_init(&raop_cbs, array.data()); if (!m_raop) { return false; } @@ -123,12 +124,14 @@ bool RaopService::init() bool RaopService::start(const QString & name, quint16 port) { + const char hwaddr[] = { 0x48, 0x5d, 0x60, 0x7c, 0xee, 0x22 }; + if (!m_raop || !m_dnssd || m_thread.isRunning()) { return false; } m_thread.start(); - if (raop_start(m_raop, &port) < 0) { + if (raop_start(m_raop, &port, hwaddr, sizeof(hwaddr)) < 0) { m_thread.quit(); m_thread.wait(); return false; diff --git a/src/include/raop.h b/src/include/raop.h index 604957a..4eb045c 100644 --- a/src/include/raop.h +++ b/src/include/raop.h @@ -16,10 +16,10 @@ struct raop_callbacks_s { }; typedef struct raop_callbacks_s raop_callbacks_t; -raop_t *raop_init(raop_callbacks_t *callbacks, const char *pemkey, const char *hwaddr, int hwaddrlen); -raop_t *raop_init_from_keyfile(raop_callbacks_t *callbacks, const char *keyfile, const char *hwaddr, int hwaddrlen); +raop_t *raop_init(raop_callbacks_t *callbacks, const char *pemkey); +raop_t *raop_init_from_keyfile(raop_callbacks_t *callbacks, const char *keyfile); -int raop_start(raop_t *raop, unsigned short *port); +int raop_start(raop_t *raop, unsigned short *port, const char *hwaddr, int hwaddrlen); void raop_stop(raop_t *raop); void raop_destroy(raop_t *raop); diff --git a/src/lib/raop.c b/src/lib/raop.c index 850737e..0a18391 100644 --- a/src/lib/raop.c +++ b/src/lib/raop.c @@ -234,7 +234,7 @@ conn_destroy(void *ptr) } raop_t * -raop_init(raop_callbacks_t *callbacks, const char *pemkey, const char *hwaddr, int hwaddrlen) +raop_init(raop_callbacks_t *callbacks, const char *pemkey) { raop_t *raop; httpd_t *httpd; @@ -243,7 +243,6 @@ raop_init(raop_callbacks_t *callbacks, const char *pemkey, const char *hwaddr, i assert(callbacks); assert(pemkey); - assert(hwaddr); /* Initialize the network */ if (netutils_init() < 0) { @@ -257,11 +256,6 @@ raop_init(raop_callbacks_t *callbacks, const char *pemkey, const char *hwaddr, i return NULL; } - /* Validate hardware address */ - if (hwaddrlen > MAX_HWADDR_LEN) { - return NULL; - } - /* Allocate the raop_t structure */ raop = calloc(1, sizeof(raop_t)); if (!raop) { @@ -299,15 +293,11 @@ raop_init(raop_callbacks_t *callbacks, const char *pemkey, const char *hwaddr, i raop->httpd = httpd; raop->rsakey = rsakey; - /* Copy hwaddr to resulting structure */ - memcpy(raop->hwaddr, hwaddr, hwaddrlen); - raop->hwaddrlen = hwaddrlen; - return raop; } raop_t * -raop_init_from_keyfile(raop_callbacks_t *callbacks, const char *keyfile, const char *hwaddr, int hwaddrlen) +raop_init_from_keyfile(raop_callbacks_t *callbacks, const char *keyfile) { raop_t *raop; char *pemstr; @@ -315,7 +305,7 @@ raop_init_from_keyfile(raop_callbacks_t *callbacks, const char *keyfile, const c if (utils_read_file(&pemstr, keyfile) < 0) { return NULL; } - raop = raop_init(callbacks, pemstr, hwaddr, hwaddrlen); + raop = raop_init(callbacks, pemstr); free(pemstr); return raop; } @@ -336,10 +326,20 @@ raop_destroy(raop_t *raop) } int -raop_start(raop_t *raop, unsigned short *port) +raop_start(raop_t *raop, unsigned short *port, const char *hwaddr, int hwaddrlen) { assert(raop); assert(port); + assert(hwaddr); + + /* Validate hardware address */ + if (hwaddrlen > MAX_HWADDR_LEN) { + return -1; + } + + /* Copy hwaddr to the raop structure */ + memcpy(raop->hwaddr, hwaddr, hwaddrlen); + raop->hwaddrlen = hwaddrlen; return httpd_start(raop->httpd, port); } diff --git a/src/test/example.c b/src/test/example.c index 15f91f6..999bb6b 100644 --- a/src/test/example.c +++ b/src/test/example.c @@ -56,8 +56,8 @@ main(int argc, char *argv[]) raop_cbs.audio_flush = audio_flush; raop_cbs.audio_destroy = audio_destroy; - raop = raop_init_from_keyfile(&raop_cbs, "airport.key", hwaddr, sizeof(hwaddr)); - raop_start(raop, &raop_port); + raop = raop_init_from_keyfile(&raop_cbs, "airport.key"); + raop_start(raop, &raop_port, hwaddr, sizeof(hwaddr)); dnssd = dnssd_init(hwaddr, sizeof(hwaddr), NULL); dnssd_register_raop(dnssd, name, raop_port);