GrowlNotify (empty) → 0.1
raw patch · 4 files changed
+120/−0 lines, 4 filesdep +Cryptodep +basedep +binarybuild-type:Customsetup-changed
Dependencies added: Crypto, base, binary, haskell98, network
Files
- GrowlNotify.cabal +16/−0
- LICENSE +18/−0
- Setup.hs +2/−0
- growlnotify.hs +84/−0
+ GrowlNotify.cabal view
@@ -0,0 +1,16 @@+Name: GrowlNotify+Version: 0.1+Author: Nick Burlett+Maintainer: nickburlett@mac.com+Description: Notification utility for Growl.+Synopsis: Notification utility for Growl.+License: BSD3+License-file: LICENSE+Category: Network+Build-Depends: + base, network, haskell98, Crypto, binary++Executable: growlnotify+Main-Is: growlnotify.hs+Extra-libraries: + pcap
+ LICENSE view
@@ -0,0 +1,18 @@+Copyright (c) Nicholas Burlett 2007+All rights reserved.+++Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:+++1. Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.+2. 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.+3. Neither the name of the author nor the names of any 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 @@+import Distribution.Simple+main = defaultMain
+ growlnotify.hs view
@@ -0,0 +1,84 @@+import Data.Word+import Data.Binary.Put+import qualified Data.ByteString.Lazy as B+import qualified Char+import Data.Digest.MD5+import Network.Socket+import System (getArgs)+++growl_udp_port=9887+growl_protocol_version=1+growl_type_registration=0+growl_type_notification=1++makeBS s = B.pack $ map (fromIntegral . Char.ord) s++putString :: String -> Put+putString = do putLazyByteString . makeBS++-- register this application and its notification with growl+-- any notifications will be on by default+registrationPacket :: String -> [String] -> B.ByteString+registrationPacket appName notiNames = runPut $ do+ putWord8 growl_protocol_version+ putWord8 growl_type_registration+ putWord16be $ fromIntegral $ length appName+ putWord8 $ fromIntegral $ lengthnames+ putWord8 $ fromIntegral $ lengthnames+ putString appName+ mapM_ addNotification notiNames+ mapM_ putWord8 [0..(fromIntegral lengthnames)-1]+ where+ addNotification :: String -> Put+ addNotification s = do+ putWord16be $ fromIntegral $ length s+ putLazyByteString $ makeBS s+ lengthnames = length notiNames++-- make a notification+notificationPacket :: String -> String -> String -> String -> B.ByteString+notificationPacket appName notification title description = runPut $ do+ putWord8 growl_protocol_version+ putWord8 growl_type_notification+ putWord16be 0+ putLength notification+ putLength title+ putLength description+ putLength appName+ putString notification+ putString title+ putString description+ putString appName+ where+ putLength = putWord16be . fromIntegral . length++addMD5Sum :: String -> B.ByteString -> B.ByteString+addMD5Sum password message = B.append message s+ where+ s = B.pack $ hash $ map fromIntegral $ B.unpack $ B.append message bspassword+ bspassword = makeBS password++main = do+ args <- getArgs+ (server,title, message) <- case args of+ server:title:message -> return $ (server, title, message)+ _ -> error "Usage: server title message"+ let b = registrationPacket "growlnotify" ["Command-Line Growl Notification"]+ let m = addMD5Sum "None" b+ let b2 = notificationPacket "growlnotify" "Command-Line Growl Notification" title (unwords message)+ let m2 = addMD5Sum "None" b2+ doit server m + doit server m2+ where+ port = 9887+ doit server m = do+ let d = map (Char.chr . fromIntegral) $ B.unpack m+ s <- socket AF_INET Datagram 0+ write server s d+ sClose s+ write :: String -> Socket -> String -> IO ()+ write server sock s = do+ addr <- inet_addr server+ sendTo sock s (SockAddrInet (fromIntegral port) addr) + return ()