CVS: sml-dist/src/eXene/graph-util get-dpy.sml,1.4,1.5 xauth.sml,1.5,1.6
Matthias Blume <[email protected]>
| Newsgroups | gmane.comp.lang.sml.smlnj.commits |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/smlnj/sml-dist/src/eXene/graph-util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32471/graph-util
Modified Files:
get-dpy.sml xauth.sml
Log Message:
merge Kansas changes to eXene into repository
Index: get-dpy.sml
===================================================================
RCS file: /cvsroot/smlnj/sml-dist/src/eXene/graph-util/get-dpy.sml,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** get-dpy.sml 7 Nov 2005 23:03:17 -0000 1.4
--- get-dpy.sml 3 Mar 2006 03:33:15 -0000 1.5
***************
*** 13,19 ****
fun getDpyName NONE = (case (OS.Process.getEnv "DISPLAY")
! of NONE => ""
! | (SOME dpy) => dpy
! (* end case *))
| getDpyName (SOME dpy) = dpy
--- 13,19 ----
fun getDpyName NONE = (case (OS.Process.getEnv "DISPLAY")
! of NONE => ""
! | (SOME dpy) => dpy
! (* end case *))
| getDpyName (SOME dpy) = dpy
***************
*** 35,59 ****
* variable if it is defined, and "" if it is not defined.
*)
! fun getDpy dpyOpt = let
! val dpy = getDpyName dpyOpt
! val auth = (case dpy
! of "" => XAuth.getAuthByAddr {
family = XAuth.familyLocal,
addr = "",
dpy = "0"
! }
! | d => let
! val {dpy,...} = parseDisplay d
! in
! XAuth.getAuthByAddr {
! family = XAuth.familyInternet,
! addr = "",
! dpy = dpy
! }
! end
! (* end case *))
! in
! (dpy, auth)
! end
end;
--- 35,65 ----
* variable if it is defined, and "" if it is not defined.
*)
! fun getDpy dpyOpt =
! let
! val dpy = getDpyName dpyOpt
! val auth =
! (case dpy of
! "" => XAuth.getAuthByAddr {
family = XAuth.familyLocal,
addr = "",
dpy = "0"
! }
! | d => let
! (* following line modified, ddeboer, Jan 2005. was:
! val {dpy,...} = parseDisplay d *)
! val {dpy,host,...} = parseDisplay d
! in
! XAuth.getAuthByAddr {
! family = XAuth.familyInternet,
! (* following line modified, ddeboer, Jan 2005: was:
! addr = "", *)
! addr = host,
! dpy = dpy
! }
! end
! (* end case *))
! in
! (dpy, auth)
! end
end;
Index: xauth.sml
===================================================================
RCS file: /cvsroot/smlnj/sml-dist/src/eXene/graph-util/xauth.sml,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** xauth.sml 2 Nov 2005 22:24:38 -0000 1.5
--- xauth.sml 3 Mar 2006 03:33:15 -0000 1.6
***************
*** 36,47 ****
fun getData (s, i, n) = w8vextract (s, i, SOME n)
fun getString (s, i, n) =
! Byte.unpackStringVec (Word8VectorSlice.slice (s, i, SOME n))
!
(* the different family codes (from X.h and xc/lib/Xau/Xauth.h) *)
! val familyInternet = 0
! val familyDECnet = 1
! val familyChaos = 2
! val familyLocal = 256
! val familyWild = 65535
(* return the default name of the authentication file (either
--- 36,54 ----
fun getData (s, i, n) = w8vextract (s, i, SOME n)
fun getString (s, i, n) =
! Byte.unpackStringVec (Word8VectorSlice.slice (s, i, SOME n))
! (* added ddeboer: ip addresses are encoded as raw bytes not a string. *)
! fun getAddressString (s, i, n) =
! case (n,(Word8VectorSlice.foldr (fn (e,a) =>
! (Int.toString (Char.ord (Byte.byteToChar e)))::a) []
! (Word8VectorSlice.slice (s, i, SOME n)))) of
! (4,[a,b,c,d]) => a^"."^b^"."^c^"."^d
! | _ => ""
!
(* the different family codes (from X.h and xc/lib/Xau/Xauth.h) *)
! val familyInternet = 0
! val familyDECnet = 1
! val familyChaos = 2
! val familyLocal = 256
! val familyWild = 65535
(* return the default name of the authentication file (either
***************
*** 51,98 ****
*)
fun authFileName () = (case (OS.Process.getEnv "XAUTHORITY")
! of (SOME fname) => fname
! | NONE => (case (OS.Process.getEnv "HOME")
! of (SOME path) => path ^ "/.Xauthority"
! | NONE => ".Xauthority"
! (* end case *))
! (* end case *))
(* read the entire contents of a file *)
fun readFile file = let
! val instrm = BinIO.openIn file
! val contents = BinIO.inputAll instrm
! in
! BinIO.closeIn instrm;
! contents
! end
(* extract an authentication entry from a data string *)
fun extractAuth contents = let
! val len = Word8Vector.length contents
! fun getLen start = get16(contents, start-2)
! fun extract offset = if (offset < len)
! then let
! val addrStart = 4 + offset
! val addrLen = getLen addrStart
! val dpyStart = addrStart + addrLen + 2
! val dpyLen = getLen dpyStart
! val nameStart = dpyStart + dpyLen + 2
! val nameLen = getLen nameStart
! val dataStart = nameStart + nameLen + 2
! val dataLen = getLen dataStart
! val next = dataStart + dataLen
! in
! SOME(EXB.AUTH{
! family = get16 (contents, offset),
! addr = getString (contents, addrStart, addrLen),
! dpy = getString (contents, dpyStart, dpyLen),
! name = getString (contents, nameStart, nameLen),
! data = getData (contents, dataStart, dataLen)
! }, next)
! end
! else NONE
! in
! extract
! end
(* searches the default authentication file for the first entry that
--- 58,121 ----
*)
fun authFileName () = (case (OS.Process.getEnv "XAUTHORITY")
! of (SOME fname) => fname
! | NONE => (case (OS.Process.getEnv "HOME")
! of (SOME path) => path ^ "/.Xauthority"
! | NONE => ".Xauthority"
! (* end case *))
! (* end case *))
(* read the entire contents of a file *)
fun readFile file = let
! val instrm = BinIO.openIn file
! val contents = BinIO.inputAll instrm
! in
! BinIO.closeIn instrm;
! contents
! end
(* extract an authentication entry from a data string *)
fun extractAuth contents = let
! val len = Word8Vector.length contents
! fun getLen start = get16(contents, start-2)
! fun extract offset = if (offset < len)
! then let
! val addrStart = 4 + offset
! val addrLen = getLen addrStart
! val dpyStart = addrStart + addrLen + 2
! val dpyLen = getLen dpyStart
! val nameStart = dpyStart + dpyLen + 2
! val nameLen = getLen nameStart
! val dataStart = nameStart + nameLen + 2
! val dataLen = getLen dataStart
! val next = dataStart + dataLen
! (* added following line, Feb 2005, ddeboer *)
! val family = get16 (contents, offset)
! in
! SOME(EXB.AUTH{
! (* modified by ddeboer:
! * entries of family=familyInternet are stored as 4-byte ip addresses.
! * it seems that we must convert these into hostnames for comparison...?!?
! original:
! family = get16 (contents, offset),
! addr = getString (contents, addrStart, addrLen),*)
! family = family,
! addr = (if (family = familyInternet)
! then (let val str = getAddressString(contents,addrStart,addrLen) in
! (case (NetHostDB.fromString str) of
! NONE => ""
! | SOME ia => (case (NetHostDB.getByAddr ia) of
! NONE => ""
! | SOME e => (NetHostDB.name e))) end)
! else getString (contents, addrStart, addrLen)),
! (* end modification *)
! dpy = getString (contents, dpyStart, dpyLen),
! name = getString (contents, nameStart, nameLen),
! data = getData (contents, dataStart, dataLen)
! }, next)
! end
! else NONE
! in
! extract
! end
(* searches the default authentication file for the first entry that
***************
*** 102,122 ****
*)
fun getAuthByAddr {family, dpy, addr} = let
! val extractAuth = extractAuth (readFile (authFileName()))
! fun cmpStr ("", _) = true
! | cmpStr (_, "") = true
! | cmpStr (a, b) = (a = b)
! fun chkAuth (EXB.AUTH{family=f, dpy=d, addr=a, ...}) = (
! ((family = familyWild) orelse (f = familyWild) orelse (family = f))
! andalso cmpStr(dpy, d)
! andalso cmpStr(addr, a))
! fun look offset = (case (extractAuth offset)
! of NONE => NONE
! | (SOME(auth, next)) =>
! if (chkAuth auth) then (SOME auth) else look next
! (* end case *))
! in
! look 0
! end
! handle _ => NONE
(* this similar to getAuthByAddr, except that a list of acceptable
--- 125,162 ----
*)
fun getAuthByAddr {family, dpy, addr} = let
! val extractAuth = extractAuth (readFile (authFileName()))
! (* hack by ddeboer, Feb 2005 - this is surely not the right way to do this...??
! if family is internet and address is localhost, change to the local hostname
! and familyLocal. *)
! val (family,addr) = if (((addr="localhost") (* orelse (addr="")*) ) andalso family=familyInternet)
! then (familyLocal,NetHostDB.getHostName())
! else (family,addr)
! (* end hack *)
! fun cmpStr ("", _) = true
! | cmpStr (_, "") = true
! | cmpStr (a, b) = (a = b)
! fun chkAuth (EXB.AUTH{family=f, dpy=d, addr=a, ...}) = (
! (* tracing added ddeboer, Jan 2005.
! (TextIO.print ("chkAuth seeking family="^(Int.toString(family))^", dpy="
! ^dpy^", addr="^addr^"; examining addr="^a^",dpy="^d^"\n"));*)
! ((family = familyWild) orelse (f = familyWild) orelse (family = f))
! andalso cmpStr(dpy, d)
! andalso cmpStr(addr, a))
! fun look offset = (case (extractAuth offset)
! of NONE => NONE
! | (SOME(auth, next)) =>
! if (chkAuth auth) then (SOME auth) else look next
! (* end case *))
! in
! look 0
! (* modified ddeboer, Jan 2005 for testing. *)
! (*(let val rv = look 0 in
! (case rv of (SOME (EXB.AUTH{addr,dpy,name,data,...})) =>
! (TextIO.print ("getAuthByAddr returns SOME EXB.AUTH{addr="^
! addr^",dpy="^dpy^",name="^name^",...}\n"))
! | NONE => (TextIO.print ("getAuthByAddr returns NONE (addr="^
! addr^",dpy="^dpy^")\n"))); rv end)*)
! end
! handle _ => NONE
(* this similar to getAuthByAddr, except that a list of acceptable
***************
*** 126,158 ****
*)
fun getBestAuthByAddr {family, addr, dpy, authNames} = let
! val extractAuth = extractAuth (readFile (authFileName()))
! fun cmpStr ("", _) = true
! | cmpStr (_, "") = true
! | cmpStr (a, b) = (a = b)
! fun chkAuth (EXB.AUTH{family=f, dpy=d, addr=a, ...}) = (
! ((family = familyWild) orelse (f = familyWild) orelse (family = f))
! andalso cmpStr(dpy, d)
! andalso cmpStr(addr, a))
! fun look (offset, bestRank, best) = (case (extractAuth offset)
! of NONE => best
! | (SOME(auth as EXB.AUTH{name, ...}, next)) =>
! if (chkAuth auth)
! then let
! fun chkName ([], _) = look (next, bestRank, best)
! | chkName (n::r, rank) =
! if (rank < bestRank)
! then if (name = n)
! then look (next, rank, SOME auth)
! else chkName (r, rank+1)
! else look (next, bestRank, best)
! in
! chkName (authNames, 0)
! end
! else look (next, bestRank, best)
! (* end case *))
! in
! look (0, length authNames, NONE)
! end
! handle _ => NONE
(* read the specified authentication file and return a list of
--- 166,205 ----
*)
fun getBestAuthByAddr {family, addr, dpy, authNames} = let
! val extractAuth = extractAuth (readFile (authFileName()))
! (* hack by ddeboer, Feb 2005 - this is surely not the right way to do this...??
! if family is internet and address is localhost, change to the local hostname
! and familyLocal. *)
! val (family,addr) = if (((addr="localhost") (* orelse (addr="")*) ) andalso family=familyInternet)
! then (familyLocal,NetHostDB.getHostName())
! else (family,addr)
! (* end hack *)
! fun cmpStr ("", _) = true
! | cmpStr (_, "") = true
! | cmpStr (a, b) = (a = b)
! fun chkAuth (EXB.AUTH{family=f, dpy=d, addr=a, ...}) = (
! ((family = familyWild) orelse (f = familyWild) orelse (family = f))
! andalso cmpStr(dpy, d)
! andalso cmpStr(addr, a))
! fun look (offset, bestRank, best) = (case (extractAuth offset)
! of NONE => best
! | (SOME(auth as EXB.AUTH{name, ...}, next)) =>
! if (chkAuth auth)
! then let
! fun chkName ([], _) = look (next, bestRank, best)
! | chkName (n::r, rank) =
! if (rank < bestRank)
! then if (name = n)
! then look (next, rank, SOME auth)
! else chkName (r, rank+1)
! else look (next, bestRank, best)
! in
! chkName (authNames, 0)
! end
! else look (next, bestRank, best)
! (* end case *))
! in
! look (0, length authNames, NONE)
! end
! handle _ => NONE
(* read the specified authentication file and return a list of
***************
*** 160,173 ****
*)
fun readAuthFile checkAuth file = let
! val extractAuth = extractAuth (readFile file)
! fun filter (offset, l) = (case (extractAuth offset)
! of NONE => rev l
! | (SOME(auth, next)) => if (checkAuth auth)
! then filter (next, auth::l)
! else filter (next, l)
! (* end case *))
! in
! filter (0, [])
! end
end;
--- 207,220 ----
*)
fun readAuthFile checkAuth file = let
! val extractAuth = extractAuth (readFile file)
! fun filter (offset, l) = (case (extractAuth offset)
! of NONE => rev l
! | (SOME(auth, next)) => if (checkAuth auth)
! then filter (next, auth::l)
! else filter (next, l)
! (* end case *))
! in
! filter (0, [])
! end
end;
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642