Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: xapi-project/wsproxy
base: master
...
head fork: freddy77/wsproxy
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jul 04, 2013
@jonludlam jonludlam Wean wsproxy off stdext
Signed-off-by: Jon Ludlam <jonathan.ludlam@eu.citrix.com>
750771d
Commits on Jul 22, 2013
@jonludlam jonludlam Merge pull request #1 from jonludlam/ea1254
Wean wsproxy off stdext
9873261
Showing with 95 additions and 6 deletions.
  1. +5 −5 Makefile
  2. +68 −0 base64.ml
  3. +20 −0 base64.mli
  4. +2 −1  wsproxy.ml
View
10 Makefile
@@ -1,5 +1,5 @@
-PACKS=lwt,lwt.syntax,lwt.unix,stdext
-OBJS=helpers iteratees lwt_support test websockets wsproxy
+PACKS=lwt,lwt.syntax,lwt.unix,re.str
+OBJS=base64 helpers iteratees lwt_support test websockets wsproxy
OCAMLC=ocamlc
OCAMLOPT=ocamlopt
OCAMLFIND=ocamlfind
@@ -45,15 +45,15 @@ lwt_support.cmo: iteratees.cmi lwt_support.cmi
lwt_support.cmx: iteratees.cmx lwt_support.cmi
test.cmo: iteratees.cmi test.cmi
test.cmx: iteratees.cmx test.cmi
-websockets.cmo: test.cmi iteratees.cmi helpers.cmi websockets.cmi
-websockets.cmx: test.cmx iteratees.cmx helpers.cmx websockets.cmi
+websockets.cmo: test.cmi iteratees.cmi helpers.cmi websockets.cmi base64.cmi
+websockets.cmx: test.cmx iteratees.cmx helpers.cmx websockets.cmi base64.cmi
wsproxy.cmo: websockets.cmi lwt_support.cmi wsproxy.cmi
wsproxy.cmx: websockets.cmx lwt_support.cmx wsproxy.cmi
helpers.cmi:
iteratees.cmi:
lwt_support.cmi: iteratees.cmi
test.cmi:
-websockets.cmi: iteratees.cmi
+websockets.cmi: iteratees.cmi base64.cmi
wsproxy.cmi:
View
68 base64.ml
@@ -0,0 +1,68 @@
+(*
+ * Copyright (C) 2006-2009 Citrix Systems Inc.
+ * 2010 Thomas Gazagnaire <thomas@gazagnaire.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+let code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
+let padding = '='
+
+let of_char x = if x = padding then 0 else String.index code x
+
+let to_char x = code.[x]
+
+let decode x =
+ let words = String.length x / 4 in
+ let padding =
+ if String.length x = 0 then 0 else (
+ if x.[String.length x - 2] = padding
+ then 2 else (if x.[String.length x - 1] = padding then 1 else 0)) in
+ let output = String.make (words * 3 - padding) '\000' in
+ for i = 0 to words - 1 do
+ let a = of_char x.[4 * i + 0]
+ and b = of_char x.[4 * i + 1]
+ and c = of_char x.[4 * i + 2]
+ and d = of_char x.[4 * i + 3] in
+ let n = (a lsl 18) lor (b lsl 12) lor (c lsl 6) lor d in
+ let x = (n lsr 16) land 255
+ and y = (n lsr 8) land 255
+ and z = n land 255 in
+ output.[3 * i + 0] <- char_of_int x;
+ if i <> words - 1 || padding < 2 then output.[3 * i + 1] <- char_of_int y;
+ if i <> words - 1 || padding < 1 then output.[3 * i + 2] <- char_of_int z;
+ done;
+ output
+
+let encode x =
+ let length = String.length x in
+ let words = (length + 2) / 3 in (* rounded up *)
+ let padding = if length mod 3 = 0 then 0 else 3 - (length mod 3) in
+ let output = String.make (words * 4) '\000' in
+ let get i = if i >= length then 0 else int_of_char x.[i] in
+ for i = 0 to words - 1 do
+ let x = get (3 * i + 0)
+ and y = get (3 * i + 1)
+ and z = get (3 * i + 2) in
+ let n = (x lsl 16) lor (y lsl 8) lor z in
+ let a = (n lsr 18) land 63
+ and b = (n lsr 12) land 63
+ and c = (n lsr 6) land 63
+ and d = n land 63 in
+ output.[4 * i + 0] <- to_char a;
+ output.[4 * i + 1] <- to_char b;
+ output.[4 * i + 2] <- to_char c;
+ output.[4 * i + 3] <- to_char d;
+ done;
+ for i = 1 to padding do
+ output.[String.length output - i] <- '=';
+ done;
+ output
View
20 base64.mli
@@ -0,0 +1,20 @@
+(*
+ * Copyright (C) 2006-2009 Citrix Systems Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+(** decode a string encoded in base64. Will leave trailing NULLs on the string
+ padding it out to a multiple of 3 characters *)
+val decode: string -> string
+
+(** encode a string into base64 *)
+val encode: string -> string
View
3  wsproxy.ml
@@ -80,7 +80,8 @@ let proxy (fd : Lwt_unix.file_descr) protocol ty localport =
let handler sock msg =
lwt _ = Lwt_io.printf "Got msg: %s\n" msg in
- match Stringext.String.split ':' msg with
+ let colon = Re_str.regexp_string ":" in
+ match Re_str.split_delim colon msg with
| [protocol;ty;sport] ->
let port = int_of_string sport in
proxy sock protocol ty port

No commit comments for this range

Something went wrong with that request. Please try again.