summaryrefslogtreecommitdiff
path: root/Hsbot/Utils.hs
diff options
context:
space:
mode:
authorJulien Dessaux2011-04-23 13:35:04 +0200
committerJulien Dessaux2011-04-23 13:35:04 +0200
commitd4be110200ba3f3a2f19236ec3c16f980ab458aa (patch)
tree832402a3a83927b0f3242b2306b4f1a79e681de8 /Hsbot/Utils.hs
parentBegan a big refactoring/rewriting (again) (diff)
downloadhsbot-d4be110200ba3f3a2f19236ec3c16f980ab458aa.tar.gz
hsbot-d4be110200ba3f3a2f19236ec3c16f980ab458aa.tar.bz2
hsbot-d4be110200ba3f3a2f19236ec3c16f980ab458aa.zip
Continue refactoring, worked on the core loop and the plugin infrastructure.
Diffstat (limited to '')
-rw-r--r--Hsbot/Utils.hs23
1 files changed, 19 insertions, 4 deletions
diff --git a/Hsbot/Utils.hs b/Hsbot/Utils.hs
index 785fb10..6b7f85e 100644
--- a/Hsbot/Utils.hs
+++ b/Hsbot/Utils.hs
@@ -4,13 +4,16 @@ module Hsbot.Utils
, first
, initTLSEnv
, readCertificate
+ , readMsg
, readPrivateKey
- , sendStrToClient
+ , sendStr
, setGlobalQuitMVar
+ , writeMsg
) where
import Control.Concurrent
import Control.Monad.Reader
+import Control.Monad.State
import qualified Crypto.Cipher.RSA as RSA
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C
@@ -23,6 +26,7 @@ import Network.TLS
import System.IO
import Hsbot.Config
+import Hsbot.Message
import Hsbot.Types
-- utility functions
@@ -45,9 +49,20 @@ first :: (a, b, c) -> a
first (a, _, _) = a
-- Helpers
-sendStrToClient :: Handle -> Maybe TLSCtx -> String -> IO ()
-sendStrToClient _ (Just ctx) msg = sendData ctx $ L.fromChunks [C.pack msg]
-sendStrToClient handle Nothing msg = hPutStrLn handle msg
+sendStr :: Handle -> Maybe TLSCtx -> String -> IO ()
+sendStr _ (Just ctx) msg = sendData ctx $ L.fromChunks [C.pack msg]
+sendStr handle Nothing msg = hPutStrLn handle msg
+
+-- Plugin Utils
+readMsg :: Plugin IO (Message)
+readMsg = do
+ chan <- gets pluginChan
+ liftIO $ readChan chan >>= return
+
+writeMsg :: Message -> Plugin IO ()
+writeMsg msg = do
+ chan <- gets pluginMaster
+ liftIO $ writeChan chan msg
-- TLS utils
initTLSEnv :: TLSConfig -> IO (TLSParams)