+/*
+ * HTTP Basic authentication is described at:
+ * http://tools.ietf.org/html/rfc1945#section-11.1
+ */
+void z_HTTP_header_add_basic_auth(ODR o, Z_HTTP_Header **hp,
+ const char *username, const char *password)
+{
+ char *tmp, *buf;
+ int len;
+
+ if (username == 0)
+ return;
+ if (password == 0)
+ password = "";
+
+ len = strlen(username) + strlen(password);
+ tmp = (char *) odr_malloc(o, len+2);
+ sprintf(tmp, "%s:%s", username, password);
+ buf = (char *) odr_malloc(o, (len+1) * 8/6 + 12);
+ strcpy(buf, "Basic ");
+ yaz_base64encode(tmp, &buf[strlen(buf)]);
+ z_HTTP_header_set(o, hp, "Authorization", buf);
+}
+
+