From 6f642f487b7015fd4969124e472c264d0e29ce22 Mon Sep 17 00:00:00 2001 From: Julien BLACHE Date: Sat, 25 Sep 2010 19:00:03 +0200 Subject: [PATCH] Rework WWW-Authenticate header parsing Make it work for both WWW-Authenticate: Digest realm="raop", nonce="518C974C3847DEAE59B1FE0609C437C702C4BEFE" and WWW-Authenticate: Digest realm="raop" nonce="3328882a152ab0b51bc16b15a038b3bb" 802.11g and 802.11n AirPort Express, respectively. --- src/raop.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/raop.c b/src/raop.c index 1818970e..91aeaf57 100644 --- a/src/raop.c +++ b/src/raop.c @@ -836,6 +836,8 @@ raop_parse_auth(struct raop_session *rs, struct evrtsp_request *req) return -1; } + DPRINTF(E_DBG, L_RAOP, "WWW-Authenticate: %s\n", param); + if (strncmp(param, "Digest ", strlen("Digest ")) != 0) { DPRINTF(E_LOG, L_RAOP, "Unsupported authentication method: %s\n", param); @@ -859,19 +861,19 @@ raop_parse_auth(struct raop_session *rs, struct evrtsp_request *req) { if (strcmp(token, "realm") == 0) { - token = strtok_r(NULL, " =", &ptr); + token = strtok_r(NULL, "=\"", &ptr); if (!token) break; - rs->realm = strndup(token + 1, strlen(token) - 2); + rs->realm = strdup(token); } else if (strcmp(token, "nonce") == 0) { - token = strtok_r(NULL, " =", &ptr); + token = strtok_r(NULL, "=\"", &ptr); if (!token) break; - rs->nonce = strndup(token + 1, strlen(token) - 2); + rs->nonce = strdup(token); } token = strtok_r(NULL, " =", &ptr); @@ -898,6 +900,8 @@ raop_parse_auth(struct raop_session *rs, struct evrtsp_request *req) return -1; } + DPRINTF(E_DBG, L_RAOP, "Found realm: [%s], nonce: [%s]\n", rs->realm, rs->nonce); + return 0; }