NetSNMP 0.3.0.6 → 0.3.1.0
raw patch · 4 files changed
+110/−112 lines, 4 filesdep +utf8-stringdep ~bytestringPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: utf8-string
Dependency ranges changed: bytestring
API changes (from Hackage documentation)
- Network.Protocol.NetSNMP: type OIDpart = Word32
+ Network.Protocol.NetSNMP: type OIDpart = Word64
Files
- NetSNMP.cabal +44/−36
- changes.md +2/−0
- src/Network/Protocol/NetSNMP.hsc +64/−75
- tests/RunTests.hs +0/−1
NetSNMP.cabal view
@@ -1,41 +1,49 @@+name: NetSNMP+version: 0.3.1.0+synopsis: Bindings for net-snmp's C API for clients+description: Network.Protocol.NetSNMP is a partial binding to the+ library portion of the net-snmp package. It uses the+ 'single-session api', which is claimed to be+ thread-safe. Not all operations are supported yet;+ please contact the maintainer if you're in need of+ expanded functionality, and especially if you would+ like to contribute.+category: Network+cabal-version: >= 1.8+license: BSD3+license-file: LICENSE+author: Pavlo Kerestey and Humane Software for Global Access Internet Services GmbH+maintainer: Pavlo Kerestey <pavlo@kerestey.net>+stability: alpha+build-type: Simple+homepage: https://github.com/ptek/netsnmp+bug-reports: https://github.com/ptek/netsnmp/issues+extra-source-files: changes.md -Name: NetSNMP-Version: 0.3.0.6-Synopsis: Bindings for net-snmp's C API for clients-Description: Network.Protocol.NetSNMP is a partial binding to the- library portion of the net-snmp package. It uses the- 'single-session api', which is claimed to be- thread-safe. Not all operations are supported yet;- please contact the maintainer if you're in need of- expanded functionality, and especially if you would- like to contribute.-Category: Network-Cabal-Version: >= 1.8-License: BSD3-License-file: LICENSE-Author: Pavlo Kerestey and Humane Software for Global Access Internet Services GmbH-Maintainer: Pavlo Kerestey <pavlo@kerestey.net>-Stability: alpha-Build-type: Simple-Homepage: https://github.com/ptek/netsnmp-Bug-reports: https://github.com/ptek/netsnmp/issues+source-repository head+ type: git+ location: git@github.com:ptek/netsnmp.git library- hs-source-dirs: src- build-depends: base >=4.5 && <5- ,bytestring >= 0.10 && < 0.11- build-tools: hsc2hs- exposed-modules: Network.Protocol.NetSNMP- extensions: ForeignFunctionInterface, CPP, EmptyDataDecls- extra-libraries: netsnmp- ghc-options: -static -optc-static -optl-static -optl-pthread+ hs-source-dirs: src+ build-tools: hsc2hs+ exposed-modules: Network.Protocol.NetSNMP+ extensions: ForeignFunctionInterface, CPP, EmptyDataDecls+ extra-libraries: netsnmp+ ghc-options: -Wall -static -fno-warn-missing-signatures -fno-warn-unused-binds+ build-depends: base >=4.5 && <5+ ,bytestring >= 0.9 && < 0.11+ ,utf8-string >= 0.3 && < 0.4 test-suite tests- hs-source-dirs: tests- extensions: OverloadedStrings- type: exitcode-stdio-1.0- main-is: RunTests.hs- build-depends: base >= 4.5 && <5- ,HUnit- ,NetSNMP- ,process > 1.1 && < 1.2+ hs-source-dirs: tests+ extensions: OverloadedStrings+ ghc-options: -Wall -static -threaded -fno-warn-missing-signatures -fno-warn-unused-binds -fno-warn-unused-do-bind+ type: exitcode-stdio-1.0+ main-is: RunTests.hs+ build-depends: base >= 4.5 && <5+ ,bytestring >= 0.9 && < 0.11+ ,utf8-string >= 0.3 && < 0.4+ ,HUnit+ ,NetSNMP+ ,process > 1.1 && < 1.2
+ changes.md view
@@ -0,0 +1,2 @@+0.3.1.0 - 19. April 2014+ * Make the library work on Debian 7 with ByteString 0.9
src/Network/Protocol/NetSNMP.hsc view
@@ -32,9 +32,10 @@ import Control.Monad import Data.ByteString (ByteString) import qualified Data.ByteString as B+import Data.ByteString.Char8 ()+import qualified Data.ByteString.UTF8 as Utf8 import Data.List-import Data.String-import Foreign+import Foreign hiding (void) import Foreign.C.String import Foreign.C.Types @@ -82,7 +83,7 @@ showOid = concatMap (('.':) . show) oidToByteString :: RawOID -> ByteString-oidToByteString = fromString . showOid+oidToByteString = Utf8.fromString . showOid -- I don't know whether (or which of) net-snmp's library functions -- account for bytesex; there may be endian bugs lurking here.@@ -242,11 +243,10 @@ initialize :: IO () initialize = do withCString "Haskell bindings" c_init_snmp- withCString "127.0.0.1" $ \localhost -> - withCString "public" $ \public -> - alloca $ \session -> runTrouble $ - readyCommunitySession snmp_version_2c localhost public session >>= closeSession- return ()+ void $ withCString "127.0.0.1" $ \localhost ->+ withCString "public" $ \public ->+ alloca $ \session -> runTrouble $+ readyCommunitySession snmp_version_2c localhost public session >>= closeSession -- |Create an abstract session, suitable for reuse, responsible -- for freeing the string components@@ -289,14 +289,14 @@ -> Community -- ^SNMP community (password) -> RawOID -- ^OID to be queried -> IO (Either String SnmpResult)-snmpGet version hostname community oid =+snmpGet version hostname community oid' = B.useAsCString hostname $ \cshost -> B.useAsCString community $ \cscomm -> alloca $ \session -> runTrouble $ bracketT (readyCommunitySession version cshost cscomm session) closeSession- (flip (mkSnmpGet snmp_msg_get) oid)+ (flip (mkSnmpGet snmp_msg_get) oid') -- |Simple community-authenticated SNMP getnext. Returns the first object -- after the OID queried, or a descriptive error message.@@ -313,14 +313,14 @@ -> Community -- ^SNMP community (password) -> RawOID -- ^OID to be queried -> IO (Either String SnmpResult)-snmpNext version hostname community oid =+snmpNext version hostname community oid' = B.useAsCString hostname $ \cshost -> B.useAsCString community $ \cscomm -> alloca $ \session -> runTrouble $ bracketT (readyCommunitySession version cshost cscomm session) closeSession- (flip (mkSnmpGet snmp_msg_getnext) oid)+ (flip (mkSnmpGet snmp_msg_getnext) oid') -- |Simple community-authenticated SNMP walk. Returns a list of objects, -- starting with the object after the OID queried, and continuing@@ -352,14 +352,14 @@ (go walkoid . mkSnmpGet snmp_msg_getnext) where go :: RawOID -> (RawOID -> Trouble SnmpResult) -> Trouble [SnmpResult]- go oid next = do- v@(SnmpResult nextoid val) <- next oid+ go oid' next = do+ v@(SnmpResult nextoid _) <- next oid' case () of- _ | nextoid == oid -> return [] -- throwT "end of mib" -- return []+ _ | nextoid == oid' -> return [] -- throwT "end of mib" | walkoid `isPrefixOf` nextoid -> do vs <- go nextoid next return (v:vs)- | otherwise -> return [] -- throwT "end of walk" -- return []+ | otherwise -> return [] -- throwT "end of walk" -- |Same as snmpWalk but implemented with bulk requests@@ -397,10 +397,10 @@ -- the supplied oid -- It is the caller's obligation to ensure the session's validity. mkSnmpBulkGet :: CLong -> CLong -> RawOID -> Session -> Trouble [SnmpResult]-mkSnmpBulkGet non_repeaters max_repetitions oid session =+mkSnmpBulkGet non_repeaters max_repetitions oid' session = allocaArrayT (fromIntegral max_oid_len) $ \oids -> do let version = getVersion session- pdu_req <- buildPDU snmp_msg_getbulk oid oids version+ pdu_req <- buildPDU snmp_msg_getbulk oid' oids version pokePDUNonRepeaters pdu_req non_repeaters pokePDUMaxRepetitions pdu_req max_repetitions dispatchSnmpReq pdu_req session@@ -409,12 +409,12 @@ -- the supplied oid -- It is the caller's obligation to ensure the session's validity. mkSnmpGet :: SnmpPDUType -> Session -> RawOID -> Trouble SnmpResult-mkSnmpGet pdutype session oid = do+mkSnmpGet pdutype session oid' = do res <- allocaArrayT (fromIntegral max_oid_len) $ \oids -> do let version = getVersion session- pdu_req <- buildPDU pdutype oid oids version+ pdu_req <- buildPDU pdutype oid' oids version dispatchSnmpReq pdu_req session- if null res then throwT ("Could not get the snmp value at " ++ showOid oid)+ if null res then throwT ("Could not get the snmp value at " ++ showOid oid') else return $ head res dispatchSnmpReq :: Ptr SnmpPDU -> Session -> Trouble [SnmpResult]@@ -456,7 +456,7 @@ extractVar :: Ptr CVarList -> Trouble SnmpResult extractVar rv = do- oid <- vlist2oid rv+ oid' <- vlist2oid rv t <- peekVariableType rv v <- case () of _ | t == asn_octet_str -> extractOctetStr rv@@ -475,7 +475,7 @@ _ -> do descr <- rawvar2cstring rv return $ Unsupported (fromIntegral t) descr- return (SnmpResult oid v)+ return (SnmpResult oid' v) extractOctetStr rv = do ptr <- peekVariableValString rv@@ -498,12 +498,12 @@ extractIntegral64Type rv constructor = do ptr <- peekVariableValInt rv (high:low:[]) <- peekArrayT 2 (castPtr ptr) :: Trouble [Word64]- return (constructor (fromIntegral ((high * (2 ^ 32) + low) :: Word64)))+ return (constructor (fromIntegral ((high * (2 ^ (32 :: Word64)) + low) :: Word64))) extractIpAddress rv = do ptr <- peekVariableValInt rv octets <- peekArrayT 4 (castPtr ptr) :: Trouble [Word8]- let str = B.intercalate "." (map (fromString . show) octets)+ let str = B.intercalate "." (map (B.pack . (:[])) octets) return (IpAddress str octets) extractOID :: Ptr CVarList -> Trouble ASNValue@@ -511,10 +511,10 @@ oidptr <- peekVariableValObjid rv :: Trouble (Ptr OIDpart) len <- peekVariableValLen rv let oidlen = (fromIntegral len) `div` #{size oid}- oid <- peekArrayT oidlen oidptr :: Trouble RawOID- let str = oidToByteString oid+ oid' <- peekArrayT oidlen oidptr :: Trouble RawOID+ let str = oidToByteString oid' descr <- rawvar2cstring rv- return (OID descr str (map fromIntegral oid))+ return (OID descr str (map fromIntegral oid')) extractTimeTicks rv = do intptr <- peekVariableValInt rv@@ -529,15 +529,15 @@ showASNValue v = case v of OctetString s _ -> show s IpAddress s _ -> show s- Counter32 c -> show c - Gauge32 c -> show c - OID d os ol -> show os+ Counter32 c -> show c+ Gauge32 c -> show c+ OID _ os _ -> show os Opaque cs -> show cs Integer32 c -> show c- Unsigned32 c -> show c - Counter64 c -> show c + Unsigned32 c -> show c+ Counter64 c -> show c Integer64 c -> show c- Unsigned64 c -> show c + Unsigned64 c -> show c TimeTicks s _ -> show s Boolean c -> show c IEEEDouble c -> show c@@ -553,14 +553,14 @@ -> Ptr OIDpart -- OIDpart array passed in b/c I don't know when it dallocs -> SnmpVersion -- eg. snmp_version_1 or snmp_version_2c -> Trouble (Ptr SnmpPDU) -- returns pdu and oid length-buildPDU pdutype oid oids version =- withCStringT (showOid oid) $ \oid_cstr ->- allocaT $ \oidlen_ptr -> do+buildPDU pdutype oid' oids version =+ withCStringT (showOid oid') $ \oid_cstr ->+ allocaT $ \oidlen_ptr -> do pdu_req <- t_snmp_pdu_create pdutype pokePDUVersion pdu_req (unSnmpVersion version) pokePDUCommand pdu_req (unSnmpPDUType pdutype) pokeT oidlen_ptr (fromIntegral max_oid_len)- t_read_objid oid_cstr oids oidlen_ptr -- or t_get_node+ _ <- t_read_objid oid_cstr oids oidlen_ptr -- or t_get_node oidlen <- peekT oidlen_ptr t_snmp_add_null_var pdu_req oids oidlen return pdu_req@@ -568,8 +568,8 @@ rawvar2cstring :: Ptr CVarList -> Trouble ByteString rawvar2cstring rv = allocaArray0T max_string_len $ \buf -> do- rc <- t_snprint_by_type buf (fromIntegral max_string_len) rv- nullPtr nullPtr nullPtr+ _ <- t_snprint_by_type buf (fromIntegral max_string_len) rv+ nullPtr nullPtr nullPtr peekCStringT buf allocaT :: (Storable a) => (Ptr a -> Trouble b) -> Trouble b@@ -710,13 +710,13 @@ c_snmp_pdu_create -- Parse string argument as OID; populate OIDpart array and size-foreign import ccall unsafe "net-snmp/net-snmp-includes.h get_node"- c_get_node :: CString -> Ptr OIDpart -> Ptr CSize -> IO CInt+-- foreign import ccall unsafe "net-snmp/net-snmp-includes.h get_node"+-- c_get_node :: CString -> Ptr OIDpart -> Ptr CSize -> IO CInt -t_get_node = hoistTE3- (predToMaybe (not . (>0)) "get_node failed")- -- (\i -> if (i <= 0) then Just "get_node failed" else Nothing)- c_get_node+-- t_get_node = hoistTE3+-- (predToMaybe (not . (>0)) "get_node failed")+-- -- (\i -> if (i <= 0) then Just "get_node failed" else Nothing)+-- c_get_node -- OID parser/builder script. How does this differ from get_node? foreign import ccall unsafe "net-snmp/net-snmp-includes.h read_objid"@@ -728,13 +728,13 @@ c_read_objid -- OID parser/builder script. How does this differ from get_node?-foreign import ccall unsafe "net-snmp/net-snmp-includes.h snmp_parse_oid"- c_snmp_parse_oid :: CString -> Ptr OIDpart -> Ptr CSize -> IO CInt+-- foreign import ccall unsafe "net-snmp/net-snmp-includes.h snmp_parse_oid"+-- c_snmp_parse_oid :: CString -> Ptr OIDpart -> Ptr CSize -> IO CInt -t_snmp_parse_oid = hoistTE3- (predToMaybe (not . (>0)) "snmp_parse_oid failed")- -- (\i -> if (i <= 0) then Just "snmp_parse_oid failed" else Nothing)- c_snmp_parse_oid+-- t_snmp_parse_oid = hoistTE3+-- (predToMaybe (not . (>0)) "snmp_parse_oid failed")+-- -- (\i -> if (i <= 0) then Just "snmp_parse_oid failed" else Nothing)+-- c_snmp_parse_oid -- Add oid with void result; suitable for building a query foreign import ccall unsafe "net-snmp/net-snmp-includes.h snmp_add_null_var"@@ -766,21 +766,18 @@ foreign import ccall unsafe "net-snmp/net-snmp-includes.h snmp_sess_close" c_snmp_sess_close :: Ptr SnmpSession -> IO () -t_snmp_sess_close = hoistT1 c_snmp_sess_close+-- t_snmp_sess_close = hoistT1 c_snmp_sess_close -- Send and enqueue request PDU for asynch use, not currently supported. -- foreign import ccall unsafe "net-snmp/net-snmp-includes.h snmp_sess_send" -- c_snmp_sess_send :: Ptr SnmpSession -> Ptr SnmpPDU -> IO CInt -- Print result value to stdout-foreign import ccall safe "net-snmp/net-snmp-includes.h print_variable"- c_print_variable :: Ptr OIDpart -> CSize -> Ptr CVarList -> IO ()--t_print_variable = hoistT3 c_print_variable+-- foreign import ccall safe "net-snmp/net-snmp-includes.h print_variable"+-- c_print_variable :: Ptr OIDpart -> CSize -> Ptr CVarList -> IO () -- t_print_variable :: Ptr OIDpart -> CSize -> Ptr CVarList -> Trouble ()--- t_print_variable o s r = Trouble $ Right <$> c_print_variable o s r-+-- t_print_variable = hoistT3 c_print_variable -- Return library error description -- This one should only be used for failure of snmp_sess_open; use@@ -810,9 +807,9 @@ -- snmp_sess_open failure. -- library/snmp_api.h -- void snmp_sess_error(void *, int *, int *, char **);-foreign import ccall unsafe "net-snmp/net-snmp-includes.h snmp_sess_error"- c_snmp_sess_error :: Ptr SnmpSession -> Ptr CInt -> Ptr CInt- -> Ptr CString -> IO ()+-- foreign import ccall unsafe "net-snmp/net-snmp-includes.h snmp_sess_error"+-- c_snmp_sess_error :: Ptr SnmpSession -> Ptr CInt -> Ptr CInt+-- -> Ptr CString -> IO () -- int snprint_by_type(char *buf, size_t buf_len, netsnmp_variable_list * var, -- const struct enum_list *enums, const char *hint, const char *units);@@ -860,24 +857,16 @@ catchT m h = Trouble $ do r <- runTrouble m case r of (Left s) -> runTrouble (h s)- (Right v) -> return r+ (Right _) -> return r handleT :: (String -> Trouble a) -> Trouble a -> Trouble a handleT = flip catchT --- _bracketT :: Trouble a -> (a -> Trouble b) -> (a -> Trouble c) -> Trouble c--- _bracketT before after thing = do--- a <- before--- handleT (\s -> after a >> throwT s) $ do--- result <- thing a--- after a--- return result- bracketT :: Trouble a -> (a -> Trouble b) -> (a -> Trouble c) -> Trouble c bracketT before after thing = do a <- before result <- handleT (\s -> after a >> throwT s) (thing a)- after a+ _ <- after a return result -- Routines to 'hoist' anything with IO return type into the@@ -903,9 +892,9 @@ hoistTE1 e f a = hoistTE0 e (f a) hoistTE2 e f a = hoistTE1 e (f a) hoistTE3 e f a = hoistTE2 e (f a)-hoistTE4 e f a = hoistTE3 e (f a)-hoistTE5 e f a = hoistTE4 e (f a)-hoistTE6 e f a = hoistTE5 e (f a)+--hoistTE4 e f a = hoistTE3 e (f a)+--hoistTE5 e f a = hoistTE4 e (f a)+--hoistTE6 e f a = hoistTE5 e (f a) predToMaybe :: (a -> Bool) -> b -> a -> Maybe b predToMaybe p b a = if p a then Just b else Nothing
tests/RunTests.hs view
@@ -1,6 +1,5 @@ module Main where -import Network.Protocol.NetSNMP import System.Exit import SystemTest.Platform (tests) import Test.HUnit