]> gitweb @ CieloNegro.org - Lucu.git/commitdiff
Voker57's fix for getRemoteAddr' only works on little-endian architectures. We should...
authorpho <pho@cielonegro.org>
Sun, 5 Jul 2009 09:31:25 +0000 (18:31 +0900)
committerpho <pho@cielonegro.org>
Sun, 5 Jul 2009 09:31:25 +0000 (18:31 +0900)
Ignore-this: c425d7e5c2faecde880d01d684967d71

darcs-hash:20090705093125-62b54-ec72d6afcf735ef68a34d25466688314af943b98.gz

Lucu.cabal
NEWS
Network/HTTP/Lucu/Resource.hs

index f6e887eb5508a9faa0880f78a55eabaf00cd8a0f..d9f6fc8d5b8940b0f3369c0cfd071ff15aa2cf96 100644 (file)
@@ -8,7 +8,7 @@ Description:
         messing around FastCGI. It is also intended to be run behind a
         reverse-proxy so it doesn't have some facilities like logging,
         client filtering or such like.
         messing around FastCGI. It is also intended to be run behind a
         reverse-proxy so it doesn't have some facilities like logging,
         client filtering or such like.
-Version: 0.3
+Version: 0.3.1
 License: PublicDomain
 License-File: COPYING
 Author: PHO <pho at cielonegro dot org>
 License: PublicDomain
 License-File: COPYING
 Author: PHO <pho at cielonegro dot org>
@@ -43,7 +43,7 @@ Flag build-lucu-implant-file
 
 Library
     Build-Depends:
 
 Library
     Build-Depends:
-        HsOpenSSL, base >= 4, bytestring, containers, dataenc,
+        HsOpenSSL, base >= 4 && < 5, bytestring, containers, dataenc,
         directory, haskell-src, hxt, mtl, network, stm, time, unix,
         zlib
     Exposed-Modules:
         directory, haskell-src, hxt, mtl, network, stm, time, unix,
         zlib
     Exposed-Modules:
diff --git a/NEWS b/NEWS
index fc0a8fb2a882f49e4e62607fd432d2e65b180dba..2ee14bc1776834a301186aef48e554294a77d74c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,10 @@
+Changes from 0.3 to 0.3.1
+-------------------------
+* Network.HTTP.Lucu.Resource:
+    - Bugfix: getRemoteAddr' didn't work on little-endian architectures. (Thanks: Voker57)
+    - Bugfix: getRemoteAddr' didn't work for IPv6 network.
+    - New function: getRemoteHost
+
 Changes from 0.2.1 to 0.3
 -------------------------
 * Added SSL support:
 Changes from 0.2.1 to 0.3
 -------------------------
 * Added SSL support:
index e48ea217ff99b6c7bc9c6e0a3057ab8c904db636..3a27e9ca5e1acbe786d83a949e7711c6d0657ffb 100644 (file)
@@ -73,6 +73,7 @@ module Network.HTTP.Lucu.Resource
     , getConfig
     , getRemoteAddr
     , getRemoteAddr'
     , getConfig
     , getRemoteAddr
     , getRemoteAddr'
+    , getRemoteHost
     , getRemoteCertificate
     , getRequest
     , getMethod
     , getRemoteCertificate
     , getRequest
     , getMethod
@@ -136,7 +137,6 @@ module Network.HTTP.Lucu.Resource
 
 import           Control.Concurrent.STM
 import           Control.Monad.Reader
 
 import           Control.Concurrent.STM
 import           Control.Monad.Reader
-import           Data.Bits
 import qualified Data.ByteString as Strict (ByteString)
 import qualified Data.ByteString.Lazy as Lazy (ByteString)
 import qualified Data.ByteString.Char8 as C8 hiding (ByteString)
 import qualified Data.ByteString as Strict (ByteString)
 import qualified Data.ByteString.Lazy as Lazy (ByteString)
 import qualified Data.ByteString.Char8 as C8 hiding (ByteString)
@@ -211,20 +211,15 @@ getRemoteAddr = do itr <- getInteraction
 -- you want a 'Network.Socket.SockAddr' instead of 'Prelude.String',
 -- use 'getRemoteAddr'.
 getRemoteAddr' :: Resource String
 -- you want a 'Network.Socket.SockAddr' instead of 'Prelude.String',
 -- use 'getRemoteAddr'.
 getRemoteAddr' :: Resource String
-getRemoteAddr' = do addr <- getRemoteAddr
-                    case addr of
-                      -- Network.Socket は IPv6 を考慮してゐないやうだ…
-                      SockAddrInet _ v4addr
-                          -> let b1 = (v4addr `shiftR` 24) .&. 0xFF
-                                 b2 = (v4addr `shiftR` 16) .&. 0xFF
-                                 b3 = (v4addr `shiftR`  8) .&. 0xFF
-                                 b4 =  v4addr              .&. 0xFF
-                             in
-                               return $ concat $ intersperse "." $ map show [b4, b3, b2, b1]
-                      SockAddrUnix path
-                          -> return path
-                      _
-                          -> undefined
+getRemoteAddr' = do addr          <- getRemoteAddr
+                    (Just str, _) <- liftIO $! getNameInfo [NI_NUMERICHOST] True False addr
+                    return str
+
+-- |Resolve an address to the remote host.
+getRemoteHost :: Resource String
+getRemoteHost = do addr          <- getRemoteAddr
+                   (Just str, _) <- liftIO $! getNameInfo [] True False addr
+                   return str
 
 -- | Return the X.509 certificate of the client, or 'Nothing' if:
 --
 
 -- | Return the X.509 certificate of the client, or 'Nothing' if:
 --