This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "snap-core".

The branch, master has been updated
       via  54630146de2527cd8c294955005688c903a6a6c8 (commit)
      from  23d051fe3a14d07ecd800299852ffdf4612037cb (commit)


Summary of changes:
 cbits/timefuncs.c               |    6 +++++
 src/Snap/Internal/Http/Types.hs |   41 ++++++++++++++++++++++++++++++++------
 src/Snap/Iteratee.hs            |    4 +-
 3 files changed, 42 insertions(+), 9 deletions(-)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 54630146de2527cd8c294955005688c903a6a6c8
Author: Gregory Collins <[email protected]>
Date:   Thu May 27 21:17:35 2010 -0400

    Tweak time functions

diff --git a/cbits/timefuncs.c b/cbits/timefuncs.c
index 52b513d..ed6d035 100644
--- a/cbits/timefuncs.c
+++ b/cbits/timefuncs.c
@@ -19,3 +19,9 @@ void c_format_http_time(time_t src, char* dest) {
     gmtime_r(&src, &t);
     strftime(dest, 40, "%a, %d %b %Y %H:%M:%S GMT", &t);
 }
+
+void c_format_log_time(time_t src, char* dest) {
+    struct tm t;
+    localtime_r(&src, &t);
+    strftime(dest, 40, "%d/%b/%Y:%H:%M:%S %z", &t);
+}
diff --git a/src/Snap/Internal/Http/Types.hs b/src/Snap/Internal/Http/Types.hs
index 4c451ec..f43b0b2 100644
--- a/src/Snap/Internal/Http/Types.hs
+++ b/src/Snap/Internal/Http/Types.hs
@@ -25,6 +25,7 @@ import           Data.ByteString (ByteString)
 import           Data.ByteString.Internal (c2w,w2c)
 import qualified Data.ByteString.Nums.Careless.Hex as Cvt
 import qualified Data.ByteString as S
+import qualified Data.ByteString.Unsafe as S
 import           Data.Char
 import           Data.DList (DList)
 import qualified Data.DList as DL
@@ -41,7 +42,9 @@ import           Foreign.C.Types
 import           Prelude hiding (take)
 import           System.Locale (defaultTimeLocale)
 
+
 #ifdef WIN32
+import           Data.Time.LocalTime
 import           Data.Time.Clock.POSIX
 #else
 import           Foreign.C.String
@@ -55,19 +58,20 @@ import qualified Snap.Iteratee as I
 #ifndef WIN32
 
 ------------------------------------------------------------------------------
+-- foreign imports from cbits
+
 foreign import ccall unsafe "set_c_locale"
         set_c_locale :: IO ()
 
-
-------------------------------------------------------------------------------
 foreign import ccall unsafe "c_parse_http_time"
         c_parse_http_time :: CString -> IO CTime
 
-
-------------------------------------------------------------------------------
 foreign import ccall unsafe "c_format_http_time"
         c_format_http_time :: CTime -> CString -> IO ()
 
+foreign import ccall unsafe "c_format_log_time"
+        c_format_log_time :: CTime -> CString -> IO ()
+
 #endif
 
 ------------------------------------------------------------------------------
@@ -515,6 +519,9 @@ clearContentLength r = r { rspContentLength = Nothing }
 -- | Converts a 'CTime' into an HTTP timestamp.
 formatHttpTime :: CTime -> IO ByteString
 
+-- | Converts a 'CTime' into common log entry format.
+formatLogTime :: CTime -> IO ByteString
+
 -- | Converts an HTTP timestamp into a 'CTime'.
 parseHttpTime :: ByteString -> IO CTime
 
@@ -528,6 +535,20 @@ formatHttpTime = return . format . posixSecondsToUTCTime . 
toPOSIXTime
     toPOSIXTime :: CTime -> POSIXTime
     toPOSIXTime = realToFrac
 
+formatLogTime = do
+    t <- utcToLocalZonedTime .
+         posixSecondsToUTCTime .
+         toPOSIXTime
+    return $ format t
+
+  where
+    format :: ZonedTime -> ByteString
+    format = fromStr . formatTime defaultTimeLocale "%d/%b/%Y:%H:%M:%S %z"
+
+    toPOSIXTime :: CTime -> POSIXTime
+    toPOSIXTime = realToFrac
+
+
 parseHttpTime = return . toCTime . parse . toStr
   where
     parse :: String -> Maybe UTCTime
@@ -539,11 +560,17 @@ parseHttpTime = return . toCTime . parse . toStr
 
 #else
 
-formatHttpTime t = allocaBytes 40 $ \ptr -> do
+formatLogTime t = do
+    ptr <- mallocBytes 40
+    c_format_log_time t ptr
+    S.unsafePackMallocCString ptr
+
+formatHttpTime t = do
+    ptr <- mallocBytes 40
     c_format_http_time t ptr
-    S.packCString ptr
+    S.unsafePackMallocCString ptr
 
-parseHttpTime s = S.useAsCString s $ \ptr ->
+parseHttpTime s = S.unsafeUseAsCString s $ \ptr ->
     c_parse_http_time ptr
 
 #endif
diff --git a/src/Snap/Iteratee.hs b/src/Snap/Iteratee.hs
index 9181099..0f07bd6 100644
--- a/src/Snap/Iteratee.hs
+++ b/src/Snap/Iteratee.hs
@@ -267,9 +267,9 @@ enumBS bs = enumPure1Chunk $ WrapBS bs
 enumLBS :: (Monad m) => L.ByteString -> Enumerator m a
 enumLBS lbs = el chunks
   where
-    el [] i     = return i
+    el [] i     = liftM liftI $ runIter i (EOF Nothing)
     el (x:xs) i = do
-        i' <- enumBS x i
+        i' <- liftM liftI $ runIter i (Chunk $ WrapBS x)
         el xs i'
 
     chunks = L.toChunks lbs
-----------------------------------------------------------------------


hooks/post-receive
-- 
snap-core
_______________________________________________
Snap mailing list
[email protected]
http://mailman-mail5.webfaction.com/listinfo/snap

Reply via email to