Hi all !

I've prepared a patch to add http auth to sources/http.ml

It adds the parsing of the http://user:[EMAIL PROTECTED]:port/mount URIs..

However, I cannot commit since I added mandatory dependency to extlib vie 
Base64.
Actually extlib is optional, and we have our internal base64_decode, so I 
don't know yet what to do..

I have noticed the bug with extlib's Base64, but adding an additional 
trailing "=" solved the issue..

To my point, adding a mandatory dependency on extlib is not a good idea, but 
I'm too lazy (and to bad at ocaml) to write the encoder for now..

I attach the patch, and wait for your feedback..


Romain
-- 
Think the word peace means coming together ?
Peace is a diploma you get in the cemetry
Seen ?
On top of your grave, that is marked:
"Here lies the body of John Strokes
Rest in Peace"
Seen ?
And I and I know many of you little brothers,
Who wouldn't like to hear your daughter say:
"Just going to give away a little peace"
A Bongo cliping ya no seen ?
So you can imagine how defective the word peace is,
Seen ?
- Peter Tosh - Live at One Live Peace Soncert '78
Index: src/sources/http.ml
===================================================================
--- src/sources/http.ml	(révision 4276)
+++ src/sources/http.ml	(copie de travail)
@@ -140,6 +140,7 @@
 
 let url_expr = Str.regexp "^http://\\([^/]+\\)\\(/.*\\)?$"
 let host_expr = Str.regexp "^\\([^:]+\\):\\([0-9]+\\)$"
+let auth_split_expr = Str.regexp "^\\([EMAIL PROTECTED])@\\(.+\\)$"
 
 let parse_url url =
   let host,mount =
@@ -149,12 +150,20 @@
     else
       failwith (Printf.sprintf "Invalid URL %S!" url)
   in
+  let auth,host = 
+    if Str.string_match auth_split_expr host 0 then
+      (Str.matched_group 1 host),
+      (Str.matched_group 2 host)
+    else
+      "",host
+  in 
     if Str.string_match host_expr host 0 then
       (Str.matched_group 1 host),
       (int_of_string (Str.matched_group 2 host)),
-      mount
+      mount,
+      auth
     else
-      host,80,mount
+      host,80,mount,auth
 
 let ok header = Pcre.pmatch ~pat:".*200 OK" header
 
@@ -182,16 +191,21 @@
   val mutable request = ""
 
   method set_url url =
-    let h,p,m = parse_url url in
+    let h,p,m,a = parse_url url in
     let req =
       Printf.sprintf
         "GET %s HTTP/1.0\r\nHost: %s:%d\r\n"
         m h p
     in
+    let auth = 
+      match a with
+        | "" -> ""
+	| _ -> "Authorization: Basic " ^ (Base64.str_encode a) ^ "=\r\n"
+    in
     let req =
       Printf.sprintf
-        "%sUser-Agent: liquidsoap/%s (%s; ocaml %s)\r\nIcy-MetaData:1\r\n\r\n"
-        req Configure.version Sys.os_type Sys.ocaml_version
+        "%sUser-Agent: liquidsoap/%s (%s; ocaml %s)\r\n%sIcy-MetaData:1\r\n\r\n"
+        req Configure.version Sys.os_type Sys.ocaml_version auth
     in
       host <- h;
       port <- p;

Répondre à