From: PHO Date: Tue, 2 Jun 2009 03:29:21 +0000 (+0900) Subject: Main.hs --> ServerMain.hs X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=commitdiff_plain;h=c0afc68ff35fc668809c488fc55d14b4dbcb863c;p=blackboard-dns.git Main.hs --> ServerMain.hs --- diff --git a/GNUmakefile b/GNUmakefile index d6d702a..2bb908f 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -1,4 +1,4 @@ -RUN_COMMAND = ./dist/build/blackboard-dns/blackboard-dns +RUN_COMMAND = ./dist/build/bbdns-server/bbdns-server include cabal-package.mk diff --git a/Main.hs b/Main.hs deleted file mode 100644 index 163d01e..0000000 --- a/Main.hs +++ /dev/null @@ -1,17 +0,0 @@ -module Main where - -import DDNS.DBInfo -import qualified Database.HDBC as RAW -import qualified Database.HDBC.Sqlite3 as RAW -import Database.HaskellDB.DBSpec -import Database.HaskellDB.HDBC.SQLite3 - - -main :: IO () -main = do sqliteConnect "ddns.db" $ \ db -> - dbSpecToDatabase db dbinfo - - rawCon <- RAW.connectSqlite3 "ddns.db" - mapM_ (\ sql -> RAW.run rawCon sql []) indexDeclarations - RAW.commit rawCon - RAW.disconnect rawCon diff --git a/ServerMain.hs b/ServerMain.hs new file mode 100644 index 0000000..833256f --- /dev/null +++ b/ServerMain.hs @@ -0,0 +1,84 @@ +{-# LANGUAGE CPP #-} +module Main where + +import Control.Monad +{- +import DDNS.DBInfo +import qualified Database.HDBC as RAW +import qualified Database.HDBC.Sqlite3 as RAW +import Database.HaskellDB.DBSpec +import Database.HaskellDB.HDBC.SQLite3 +-} +import System.Console.ParseArgs + +data Options + = Help + | LSDir + | DNSPort + | HTTPSPort + | AllowTransfer + | Command + deriving (Show, Eq, Ord) + +arginfo :: [Arg Options] +arginfo = [ Arg { + argIndex = Help + , argAbbr = Just 'h' + , argName = Just "help" + , argData = Nothing + , argDesc = "print this help." + } + , Arg { + argIndex = LSDir + , argAbbr = Just 'd' + , argName = Just "localstatedir" + -- LOCALSTATEDIR will be replaced by CPP + , argData = argDataDefaulted "DIR" ArgtypeString LOCALSTATEDIR + , argDesc = "specify the local state directory (def: " ++ LOCALSTATEDIR ++ ")." + } + , Arg { + argIndex = DNSPort + , argAbbr = Just 'p' + , argName = Just "dns-port" + , argData = argDataDefaulted "PORT" ArgtypeString "53" + , argDesc = "port to listen for DNS packets (default: 53)." + } + , Arg { + argIndex = HTTPSPort + , argAbbr = Just 'P' + , argName = Just "https-port" + , argData = argDataDefaulted "PORT" ArgtypeString "443" + , argDesc = "port to listen for HTTPS connections (def: 443)." + } + , Arg { + argIndex = AllowTransfer + , argAbbr = Just 'a' + , argName = Just "allow-transfer" + , argData = Nothing + , argDesc = "accept AXFR requests." + } + , Arg { + argIndex = Command + , argAbbr = Nothing + , argName = Nothing + , argData = argDataDefaulted "COMMAND" ArgtypeString "daemon" + , argDesc = "command to the server (default: \"daemon\")." + } + ] + +main :: IO () +main = do m <- parseArgsIO ArgsComplete arginfo + when (gotArg m Help) + $ usageError m "" `seq` return () + + usageError m "" `seq` return () + +{- +main = do sqliteConnect "ddns.db" $ \ db -> + dbSpecToDatabase db dbinfo + + rawCon <- RAW.connectSqlite3 "ddns.db" + mapM_ (\ sql -> RAW.run rawCon sql []) indexDeclarations + RAW.commit rawCon + RAW.disconnect rawCon +-} \ No newline at end of file diff --git a/blackboard-dns.buildinfo.in b/blackboard-dns.buildinfo.in index a817b1c..fed0e64 100644 --- a/blackboard-dns.buildinfo.in +++ b/blackboard-dns.buildinfo.in @@ -1,4 +1,4 @@ -- -*- haskell-cabal -*- -Executable: blackboard-dns +Executable: bbdns-server GHC-Options: -DLOCALSTATEDIR="@DDNS_LOCALSTATEDIR@" diff --git a/blackboard-dns.cabal b/blackboard-dns.cabal index 5a68ea1..b66aa22 100644 --- a/blackboard-dns.cabal +++ b/blackboard-dns.cabal @@ -16,9 +16,10 @@ Extra-Source-Files: data/GNUmakefile data/GenDBModules.hs -Executable blackboard-dns +Executable bbdns-server Build-Depends: - HDBC, HDBC-sqlite3, base, haskelldb, haskelldb-hdbc-sqlite3 + HDBC, HDBC-sqlite3, base, haskelldb, haskelldb-hdbc-sqlite3, + parseargs Other-Modules: DDNS.DB @@ -27,7 +28,7 @@ Executable blackboard-dns DDNS.DBInfo Main-Is: - Main.hs + ServerMain.hs GHC-Options: -Wall