Move hwaddress to raop_start instead of raop_init.
[deb_shairplay.git] / src / lib / raop.c
index 484b3f4774c2ef9cd3ed030048e43dbdb57352ce..0a18391f77ba7e1b6e13dd6a7d5254dda2e44b83 100644 (file)
@@ -1,3 +1,17 @@
+/**
+ *  Copyright (C) 2011-2012  Juho Vähä-Herttua
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ */
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -220,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;
@@ -229,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) {
@@ -243,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) {
@@ -285,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;
@@ -301,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;
 }
@@ -322,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);
 }