summaryrefslogtreecommitdiff
path: root/src/libwaitress/waitress.c
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2011-06-12 13:52:21 +0200
committerLars-Dominik Braun <lars@6xq.net>2011-06-13 20:22:24 +0200
commitf0af48a4f70dfed1372112f2247a4f3bbb10cf72 (patch)
tree34eae2dbf95ba6d896e94356e6877da73363a329 /src/libwaitress/waitress.c
parent58b1579f56a4fc49cef4f0e3a8b87e392b5fc376 (diff)
downloadpianobar-f0af48a4f70dfed1372112f2247a4f3bbb10cf72.tar.gz
pianobar-f0af48a4f70dfed1372112f2247a4f3bbb10cf72.tar.bz2
pianobar-f0af48a4f70dfed1372112f2247a4f3bbb10cf72.zip
waitress: http "basic" authentication support
Closes #109
Diffstat (limited to 'src/libwaitress/waitress.c')
-rw-r--r--src/libwaitress/waitress.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/libwaitress/waitress.c b/src/libwaitress/waitress.c
index 3c48616..8bef2f6 100644
--- a/src/libwaitress/waitress.c
+++ b/src/libwaitress/waitress.c
@@ -466,6 +466,27 @@ static WaitressReturn_t WaitressPollRead (int sockfd, char *buf, size_t count,
CLOSE_RET (wRet); \
}
+/* send basic http authorization
+ * @param waitress handle
+ * @param url containing user/password
+ * @param header name prefix
+ */
+static bool WaitressFormatAuthorization (WaitressHandle_t *waith,
+ WaitressUrl_t *url, const char *prefix, char *writeBuf,
+ const size_t writeBufSize) {
+ if (url->user != NULL) {
+ char userPass[1024], *encodedUserPass;
+ snprintf (userPass, sizeof (userPass), "%s:%s", url->user,
+ (url->password != NULL) ? url->password : "");
+ encodedUserPass = WaitressBase64Encode (userPass);
+ snprintf (writeBuf, writeBufSize, "%sAuthorization: Basic %s\r\n",
+ prefix, encodedUserPass);
+ free (encodedUserPass);
+ return true;
+ }
+ return false;
+}
+
/* get default http port if none was given
*/
static const char *WaitressDefaultPort (WaitressUrl_t *url) {
@@ -576,6 +597,16 @@ WaitressReturn_t WaitressFetchCall (WaitressHandle_t *waith) {
strlen (waith->postData));
WRITE_RET (writeBuf, strlen (writeBuf));
}
+
+ /* write authorization headers */
+ if (WaitressFormatAuthorization (waith, &waith->url, "", writeBuf,
+ sizeof (writeBuf))) {
+ WRITE_RET (writeBuf, strlen (writeBuf));
+ }
+ if (WaitressFormatAuthorization (waith, &waith->proxy, "Proxy-",
+ writeBuf, sizeof (writeBuf))) {
+ WRITE_RET (writeBuf, strlen (writeBuf));
+ }
if (waith->extraHeaders != NULL) {
WRITE_RET (waith->extraHeaders, strlen (waith->extraHeaders));