bool RaopService::init()
{
const char hwaddr[] = { 0x48, 0x5d, 0x60, 0x7c, 0xee, 0x22 };
+
raop_callbacks_t raop_cbs;
int error;
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;
}
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;
};
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);
}
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;
assert(callbacks);
assert(pemkey);
- assert(hwaddr);
/* Initialize the network */
if (netutils_init() < 0) {
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) {
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;
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;
}
}
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);
}
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);