packages feed

zmcat (empty) → 0.2

raw patch · 5 files changed

+169/−0 lines, 5 filesdep +basedep +bytestringdep +zeromq3-haskellsetup-changed

Dependencies added: base, bytestring, zeromq3-haskell, zmcat

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2012, Lucas DiCioccio++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Falko Peters nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@++main = defaultMain
+ bin/Zmcat.hs view
@@ -0,0 +1,25 @@+{-# LANGUAGE OverloadedStrings #-}++module Main where++import System.Exit (exitFailure)+import System.IO+import System.Environment (getArgs)+import qualified Data.ByteString.Char8 as C++import Network.Zmcat++main :: IO ()+main = do +	args  <- getArgs+	case args of+		["pub", uri, k]		-> pub uri k+		["sub", uri, k] 	-> sub uri $ C.pack k+		["pub", uri]		-> pub uri ""+		["sub", uri] 		-> sub uri ""+		["push", uri] 		-> push uri+		["pull", uri] 		-> pull uri+		["req", uri] 		-> req uri+		["rep", uri] 		-> rep uri+		_	  		-> (hPutStrLn stderr usage) >> exitFailure+	where usage = "cli <pub|sub|push|pull|rep|req> <uri> [key-for-pub-or-sub='']"
+ src/Network/Zmcat.hs view
@@ -0,0 +1,64 @@++module Network.Zmcat where++import System.ZMQ3+import Control.Monad (forever)+import qualified Data.ByteString as BS+import Data.ByteString.Char8 (pack, unpack)+import System.IO++runCtx :: SocketType a1 => a1 -> (Socket a1 -> IO a) -> IO a+runCtx t blk = withContext $ \ctx -> do+        withSocket ctx t $ \skt -> do+            blk skt++pub :: String -> String -> IO a+pub uri k = runCtx Pub $ \skt -> do+        bind skt uri+        forever $ do+            pkt <- hGetLine stdin+            send skt [] (pack $ k ++ pkt)++sub :: String -> BS.ByteString -> IO a+sub uri k = runCtx Sub $ \skt -> do+        subscribe skt k+        connect skt uri+        forever $ do+            line <- receive skt+            putStrLn $ drop (BS.length k) (unpack line)+            hFlush stdout+                +pull :: String -> IO a+pull uri = runCtx Pull $ \skt -> do+        bind skt uri+        forever $ do+            line <- receive skt+            putStrLn $ unpack line+            hFlush stdout++push :: String -> IO a+push uri = runCtx Push $ \skt -> do+        connect skt uri+        forever $ do+            pkt <- hGetLine stdin+            send skt [] (pack pkt)++rep :: String -> IO a+rep uri = runCtx Rep $ \skt -> do+    bind skt uri+    forever $ do+        line <- receive skt+        putStrLn $ unpack line+        hFlush stdout+        pkt <- hGetLine stdin+        send skt [] (pack pkt)++req :: String -> IO a+req uri = runCtx Req $ \skt -> do+    connect skt uri+    forever $ do+        pkt <- hGetLine stdin+        send skt [] (pack pkt)+        line <- receive skt+        putStrLn $ unpack line+        hFlush stdout
+ zmcat.cabal view
@@ -0,0 +1,48 @@+name:               zmcat+version:            0.2+synopsis:+    Command-line tool for ZeroMQ.+Description:+    ZeroMQ is a handy way to communicate between applications:+    .+    [Rationale:] Zmcat is an handy command-line tool to debug or communicate+        with ZeroMQ applications from the shell.+    One use of zmcat is to easily audit, monitor, add cron-jobs shell scripts+    which speak zmq.+    .+    [Limitations:]+    A limitation is that Zmcat only supports printable text. Support for +    random binary streams will come later.+    .+license:            BSD3+license-file:       LICENSE+author:             Lucas DiCioccio+maintainer:         lucas@dicioccio.fr+copyright:          Copyright (c) 2013 Lucas DiCioccio+category:           Network+build-type:         Simple+cabal-version:      >=1.8++homepage:           https://github.com/lucasdicioccio/zmcat+bug-reports:        https://github.com/lucasdicioccio/zmcat/issues++source-repository head+  type:     git+  location: https://github.com/lucasdicioccio/zmcat++library+  hs-source-dirs:   src+  ghc-options:      -Wall+  ghc-prof-options: -auto-all+  exposed-modules:  Network.Zmcat+  build-depends:    bytestring,+                    base >= 4.5.1.0 && < 5,+                    zeromq3-haskell >= 0.3.1++executable zmcat+    main-is: bin/Zmcat.hs+    build-depends: base >= 4.5.1.0 && < 5,+                   zmcat,+                   bytestring+    ghc-options: -Wall -rtsopts+    ghc-prof-options: -auto-all