X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fraop.c;h=0a18391f77ba7e1b6e13dd6a7d5254dda2e44b83;hb=406e97773573c7f8b4d019025e2694b914aca830;hp=484b3f4774c2ef9cd3ed030048e43dbdb57352ce;hpb=1b4a582b04fc39d9d4d930acb4d0803bdedfb32e;p=deb_shairplay.git diff --git a/src/lib/raop.c b/src/lib/raop.c index 484b3f4..0a18391 100644 --- a/src/lib/raop.c +++ b/src/lib/raop.c @@ -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 #include #include @@ -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); }