Move hwaddress to raop_start instead of raop_init.
authorJuho Vähä-Herttua <juhovh@iki.fi>
Thu, 15 Mar 2012 11:57:10 +0000 (13:57 +0200)
committerJuho Vähä-Herttua <juhovh@iki.fi>
Wed, 16 May 2012 21:33:31 +0000 (00:33 +0300)
AirTV-Qt/raopservice.cpp
src/include/raop.h
src/lib/raop.c
src/test/example.c

index 43689c3e7118c42a54e2f28d5d1332db57a2f1e1..19ba624c480438311c92b99849b891e64ee02c3e 100644 (file)
@@ -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;
index 604957a1caf4f9939cbe0581c78d0d6e25cdd13b..4eb045c4a7ac9ff3d59798da265cdb37557236b2 100644 (file)
@@ -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);
index 850737e5c216b417daf4a23a3859d2588b0497b9..0a18391f77ba7e1b6e13dd6a7d5254dda2e44b83 100644 (file)
@@ -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);
 }
index 15f91f620c923e74449ac920eda3c4a013da3f72..999bb6b0c4b1500cb39e09b452851a5d674e0f95 100644 (file)
@@ -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);