- Use sandi instead of dataenc (bugs.debian.org/836686)
authorunc0rr
Sat, 01 Oct 2016 21:27:05 +0300
changeset 11860 ad435d95ca4b
parent 11859 0b8f2116aa26
child 11861 dea8411974f9
- Use sandi instead of dataenc (bugs.debian.org/836686) - Only try to import module from the package being tested (sometimes packages have modules with equal names, so a test for module presence could succeed when you have one package installed instead of another)
cmake_modules/CheckHaskellModuleExists.cmake
gameServer/CMakeLists.txt
gameServer/EngineInteraction.hs
gameServer/NetRoutines.hs
gameServer/hedgewars-server.cabal
--- a/cmake_modules/CheckHaskellModuleExists.cmake	Sat Oct 01 20:56:42 2016 +0300
+++ b/cmake_modules/CheckHaskellModuleExists.cmake	Sat Oct 01 21:27:05 2016 +0300
@@ -28,6 +28,9 @@
                     "-DMODULE=${MODULE}"
                     "-DFUNCTION=${FUNCTION}"
                     "-DPARAMETERS=${PARAMETERS}"
+                    -hide-all-packages
+                    -package ${LIBRARY}
+                    -package base
                     -cpp
                     -c "${CMAKE_MODULE_PATH}/checkModule.hs"
                     RESULT_VARIABLE COMMAND_RESULT
--- a/gameServer/CMakeLists.txt	Sat Oct 01 20:56:42 2016 +0300
+++ b/gameServer/CMakeLists.txt	Sat Oct 01 21:27:05 2016 +0300
@@ -12,7 +12,7 @@
 check_haskell_module_exists("Network.BSD" getHostName 0 network)
 check_haskell_module_exists("Data.Time" getCurrentTime 0 time)
 check_haskell_module_exists("Control.Monad.State" fix 1 mtl)
-check_haskell_module_exists("Codec.Binary.Base64" encode 1 dataenc)
+check_haskell_module_exists("Codec.Binary.Base64" encode 1 sandi)
 check_haskell_module_exists("System.Log.Logger" warningM 1 hslogger)
 check_haskell_module_exists("System.Process" createProcess 3 process)
 check_haskell_module_exists("Data.ByteString.Lazy.UTF8" decode 1 utf8-string)
--- a/gameServer/EngineInteraction.hs	Sat Oct 01 20:56:42 2016 +0300
+++ b/gameServer/EngineInteraction.hs	Sat Oct 01 21:27:05 2016 +0300
@@ -63,7 +63,7 @@
 #endif
 
 toEngineMsg :: B.ByteString -> B.ByteString
-toEngineMsg msg = B.pack $ Base64.encode (fromIntegral (BW.length msg) : BW.unpack msg)
+toEngineMsg msg = Base64.encode (fromIntegral (BW.length msg) `BW.cons` msg)
 
 
 {-fromEngineMsg :: B.ByteString -> Maybe B.ByteString
@@ -85,15 +85,15 @@
 checkNetCmd :: [Word8] -> B.ByteString -> (B.ByteString, B.ByteString, Maybe (Maybe B.ByteString))
 checkNetCmd teamsIndexes msg = check decoded
     where
-        decoded = liftM (splitMessages . BW.pack) $ Base64.decode $ B.unpack msg
-        check Nothing = (B.empty, B.empty, Nothing)
-        check (Just msgs) = let (a, b) = (filter isLegal msgs, filter isNonEmpty a) in (encode a, encode b, lft a)
-        encode = B.pack . Base64.encode . BW.unpack . B.concat
+        decoded = liftM splitMessages $ Base64.decode msg
+        check (Left _) = (B.empty, B.empty, Nothing)
+        check (Right msgs) = let (a, b) = (filter isLegal msgs, filter isNonEmpty a) in (encode a, encode b, lft a)
+        encode = Base64.encode . B.concat
         isLegal m = (B.length m > 1) && (flip Set.member legalMessages . B.head . B.tail $ m) && not (isMalformed (B.head m) (B.tail m))
         lft = foldr l Nothing
         l m n = let m' = B.head $ B.tail m; tst = flip Set.member in
                       if not $ tst timedMessages m' then n
-                        else if '+' /= m' then Just Nothing else Just . Just . B.pack . Base64.encode . BW.unpack $ m
+                        else if '+' /= m' then Just Nothing else Just . Just . Base64.encode $ m
         isNonEmpty = (/=) '+' . B.head . B.tail
         legalMessages = Set.fromList $ "M#+LlRrUuDdZzAaSjJ,NpPwtgfhbc12345" ++ slotMessages
         slotMessages = "\128\129\130\131\132\133\134\135\136\137\138"
--- a/gameServer/NetRoutines.hs	Sat Oct 01 20:56:42 2016 +0300
+++ b/gameServer/NetRoutines.hs	Sat Oct 01 21:27:05 2016 +0300
@@ -25,11 +25,8 @@
 import Control.Monad
 import Data.Unique
 import qualified Codec.Binary.Base64 as Base64
-import qualified Data.ByteString as BW
-import qualified Data.ByteString.Char8 as B
 import qualified Control.Exception as E
 import System.Entropy
-import Data.Either
 -----------------------------
 import CoreTypes
 import Utils
@@ -48,7 +45,7 @@
         sendChan' <- newChan
 
         uid <- newUnique
-        salt <- liftM (B.pack . Base64.encode . BW.unpack) $ hGetEntropy ch 18
+        salt <- liftM Base64.encode $ hGetEntropy ch 18
 
         let newClient =
                 (ClientInfo
--- a/gameServer/hedgewars-server.cabal	Sat Oct 01 20:56:42 2016 +0300
+++ b/gameServer/hedgewars-server.cabal	Sat Oct 01 21:27:05 2016 +0300
@@ -25,7 +25,7 @@
     random,
     time,
     mtl >= 2,
-    dataenc,
+    sandi,
     hslogger,
     process,
     deepseq,