#include "utils.h"
#include "netutils.h"
#include "logger.h"
+#include "compat.h"
/* Actually 345 bytes for 2048-bit key */
#define MAX_SIGNATURE_LEN 512
#define MAX_PASSWORD_LEN 64
/* MD5 as hex fits here */
-#define MAX_NONCE_LEN 33
+#define MAX_NONCE_LEN 32
struct raop_s {
/* Callbacks for audio */
if (locallen == 4) {
logger_log(&conn->raop->logger, LOGGER_INFO,
- "Local: %d.%d.%d.%d\n",
+ "Local: %d.%d.%d.%d",
local[0], local[1], local[2], local[3]);
} else if (locallen == 16) {
logger_log(&conn->raop->logger, LOGGER_INFO,
- "Local: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
+ "Local: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
local[0], local[1], local[2], local[3], local[4], local[5], local[6], local[7],
local[8], local[9], local[10], local[11], local[12], local[13], local[14], local[15]);
}
if (remotelen == 4) {
logger_log(&conn->raop->logger, LOGGER_INFO,
- "Remote: %d.%d.%d.%d\n",
+ "Remote: %d.%d.%d.%d",
remote[0], remote[1], remote[2], remote[3]);
} else if (remotelen == 16) {
logger_log(&conn->raop->logger, LOGGER_INFO,
- "Remote: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
+ "Remote: %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
remote[0], remote[1], remote[2], remote[3], remote[4], remote[5], remote[6], remote[7],
remote[8], remote[9], remote[10], remote[11], remote[12], remote[13], remote[14], remote[15]);
}
authorization = http_request_get_header(request, "Authorization");
if (authorization) {
- logger_log(&conn->raop->logger, LOGGER_DEBUG, "Authorization: %s\n", authorization);
+ logger_log(&conn->raop->logger, LOGGER_DEBUG, "Our nonce: %s", conn->nonce);
+ logger_log(&conn->raop->logger, LOGGER_DEBUG, "Authorization: %s", authorization);
}
- if (!digest_is_valid("AppleTV", raop->password, conn->nonce, method, authorization)) {
+ if (!digest_is_valid("AppleTV", raop->password, conn->nonce, method, http_request_get_url(request), authorization)) {
char *authstr;
int authstrlen;
http_response_add_header(res, "WWW-Authenticate", authstr);
free(authstr);
} else {
- logger_log(&conn->raop->logger, LOGGER_DEBUG, "AUTHENTICATION SUCCESS!\n");
+ logger_log(&conn->raop->logger, LOGGER_DEBUG, "AUTHENTICATION SUCCESS!");
}
}
http_response_add_header(res, "Apple-Jack-Status", "connected; type=analog");
challenge = http_request_get_header(request, "Apple-Challenge");
- if (challenge) {
+ if (!require_auth && challenge) {
char signature[MAX_SIGNATURE_LEN];
memset(signature, 0, sizeof(signature));
conn->local, conn->locallen, raop->hwaddr, raop->hwaddrlen);
http_response_add_header(res, "Apple-Response", signature);
- logger_log(&conn->raop->logger, LOGGER_DEBUG, "Got challenge: %s\n", challenge);
- logger_log(&conn->raop->logger, LOGGER_DEBUG, "Got response: %s\n", signature);
+ logger_log(&conn->raop->logger, LOGGER_DEBUG, "Got challenge: %s", challenge);
+ logger_log(&conn->raop->logger, LOGGER_DEBUG, "Got response: %s", signature);
}
if (require_auth) {
aeskeystr = sdp_get_rsaaeskey(sdp);
aesivstr = sdp_get_aesiv(sdp);
- logger_log(&conn->raop->logger, LOGGER_DEBUG, "connection: %s\n", remotestr);
- logger_log(&conn->raop->logger, LOGGER_DEBUG, "fmtp: %s\n", fmtpstr);
- logger_log(&conn->raop->logger, LOGGER_DEBUG, "rsaaeskey: %s\n", aeskeystr);
- logger_log(&conn->raop->logger, LOGGER_DEBUG, "aesiv: %s\n", aesivstr);
+ logger_log(&conn->raop->logger, LOGGER_DEBUG, "connection: %s", remotestr);
+ logger_log(&conn->raop->logger, LOGGER_DEBUG, "fmtp: %s", fmtpstr);
+ logger_log(&conn->raop->logger, LOGGER_DEBUG, "rsaaeskey: %s", aeskeystr);
+ logger_log(&conn->raop->logger, LOGGER_DEBUG, "aesiv: %s", aesivstr);
aeskeylen = rsakey_decrypt(raop->rsakey, aeskey, sizeof(aeskey), aeskeystr);
aesivlen = rsakey_parseiv(raop->rsakey, aesiv, sizeof(aesiv), aesivstr);
- logger_log(&conn->raop->logger, LOGGER_DEBUG, "aeskeylen: %d\n", aeskeylen);
- logger_log(&conn->raop->logger, LOGGER_DEBUG, "aesivlen: %d\n", aesivlen);
+ logger_log(&conn->raop->logger, LOGGER_DEBUG, "aeskeylen: %d", aeskeylen);
+ logger_log(&conn->raop->logger, LOGGER_DEBUG, "aesivlen: %d", aesivlen);
if (conn->raop_rtp) {
/* This should never happen */
transport = http_request_get_header(request, "Transport");
assert(transport);
- logger_log(&conn->raop->logger, LOGGER_INFO, "Transport: %s\n", transport);
+ logger_log(&conn->raop->logger, LOGGER_INFO, "Transport: %s", transport);
use_udp = strncmp(transport, "RTP/AVP/TCP", 11);
if (use_udp) {
char *original, *current, *tmpstr;
ret = sscanf(tmpstr, "control_port=%hu", &value);
if (ret == 1) {
- logger_log(&conn->raop->logger, LOGGER_DEBUG, "Found remote control port: %hu\n", value);
+ logger_log(&conn->raop->logger, LOGGER_DEBUG, "Found remote control port: %hu", value);
remote_cport = value;
}
ret = sscanf(tmpstr, "timing_port=%hu", &value);
if (ret == 1) {
- logger_log(&conn->raop->logger, LOGGER_DEBUG, "Found remote timing port: %hu\n", value);
+ logger_log(&conn->raop->logger, LOGGER_DEBUG, "Found remote timing port: %hu", value);
remote_tport = value;
}
}
"RTP/AVP/TCP;unicast;interleaved=0-1;mode=record;server_port=%u",
dport);
}
- logger_log(&conn->raop->logger, LOGGER_INFO, "Responding with %s\n", buffer);
+ logger_log(&conn->raop->logger, LOGGER_INFO, "Responding with %s", buffer);
http_response_add_header(res, "Transport", buffer);
http_response_add_header(res, "Session", "DEADBEEF");
} else if (!strcmp(method, "SET_PARAMETER")) {
+ const char *content_type;
const char *data;
int datalen;
- char *datastr;
+ content_type = http_request_get_header(request, "Content-Type");
data = http_request_get_data(request, &datalen);
- datastr = calloc(1, datalen+1);
- if (data && datastr && conn->raop_rtp) {
- memcpy(datastr, data, datalen);
- if (!strncmp(datastr, "volume: ", 8)) {
- float vol = 0.0;
- sscanf(data+8, "%f", &vol);
- raop_rtp_set_volume(conn->raop_rtp, vol);
+ if (!strcmp(content_type, "text/parameters")) {
+ char *datastr;
+ datastr = calloc(1, datalen+1);
+ if (data && datastr && conn->raop_rtp) {
+ memcpy(datastr, data, datalen);
+ if (!strncmp(datastr, "volume: ", 8)) {
+ float vol = 0.0;
+ sscanf(datastr+8, "%f", &vol);
+ raop_rtp_set_volume(conn->raop_rtp, vol);
+ }
}
+ free(datastr);
+ } else if (!strcmp(content_type, "image/jpeg")) {
+ logger_log(&conn->raop->logger, LOGGER_INFO, "Got image data of %d bytes", datalen);
+ raop_rtp_set_coverart(conn->raop_rtp, data, datalen);
+ } else if (!strcmp(content_type, "application/x-dmap-tagged")) {
+ logger_log(&conn->raop->logger, LOGGER_INFO, "Got metadata of %d bytes", datalen);
+ raop_rtp_set_metadata(conn->raop_rtp, data, datalen);
}
} else if (!strcmp(method, "FLUSH")) {
const char *rtpinfo;
rtpinfo = http_request_get_header(request, "RTP-Info");
if (rtpinfo) {
- logger_log(&conn->raop->logger, LOGGER_INFO, "Flush with RTP-Info: %s\n", rtpinfo);
+ logger_log(&conn->raop->logger, LOGGER_INFO, "Flush with RTP-Info: %s", rtpinfo);
if (!strncmp(rtpinfo, "seq=", 4)) {
next_seq = strtol(rtpinfo+4, NULL, 10);
}
}
http_response_finish(res, NULL, 0);
- logger_log(&conn->raop->logger, LOGGER_DEBUG, "Got request %s with URL %s\n", method, http_request_get_url(request));
+ logger_log(&conn->raop->logger, LOGGER_DEBUG, "Got request %s with URL %s", method, http_request_get_url(request));
*response = res;
}
}
/* Validate the callbacks structure */
- if (!callbacks->audio_init || !callbacks->audio_set_volume ||
- !callbacks->audio_process || !callbacks->audio_flush ||
+ if (!callbacks->audio_init ||
+ !callbacks->audio_process ||
!callbacks->audio_destroy) {
return NULL;
}
}
}
+int
+raop_is_running(raop_t *raop)
+{
+ assert(raop);
+
+ return httpd_is_running(raop->httpd);
+}
+
int
raop_start(raop_t *raop, unsigned short *port, const char *hwaddr, int hwaddrlen, const char *password)
{