head	1.3;
access;
symbols
	tcllib-1-13:1.3
	tcllib-1-12:1.3
	tklib-0-5:1.3
	tcllib-1-11-1:1.3
	tcllib-1-11:1.3
	tcllib-1-10:1.3;
locks; strict;
comment	@# @;


1.3
date	2007.07.18.22.37.37;	author andreas_kupries;	state Exp;
branches;
next	1.2;

1.2
date	2007.05.08.22.03.56;	author andreas_kupries;	state Exp;
branches;
next	1.1;

1.1
date	2007.05.04.21.31.09;	author andreas_kupries;	state Exp;
branches;
next	;


desc
@@


1.3
log
@
	* ../../apps/nnsd: Fixed option bug. Bumped version to 1.0.1.

	* ../../apps/nns: Extended example client application with
	* ../../apps/nns.man: continuous search. Further extended to
	  detect and handle loss of connection with service, by exiting.
	  Bumped version to 1.1

	* server.tcl: Implemented asynchronous and continuous searches.
	* nns.tcl: Ditto in client. Documented this feature, and the
	* nns_client.man: extensions to the protocol it needs.
	* nns_server.man: Bumped both server and client to version 0.3.
	* nns_protocol.man:
	* pkgIndex.tcl:
@
text
@#! /bin/sh
# -*- tcl -*- \
exec tclsh "$0" ${1+"$@@"}

# @@@@ Meta Begin
# Application nnsd 1.0.1
# Meta platform     tcl
# Meta summary      Nano Name Service Demon
# Meta description  This application is a simple demon on top
# Meta description  of the nano name service facilities
# Meta subject      {name service} server demon
# Meta require      {Tcl 8.4}
# Meta require      comm
# Meta require      logger
# Meta require      interp
# Meta require      nameserv::common
# Meta require      nameserv::server
# Meta author       Andreas Kupries
# Meta license      BSD
# @@@@ Meta End

package provide nnsd 1.0.1

# nnsd - Nano Name Service Demon
# ==== = =======================
#
# Use cases
# ---------
# 
# (1)	Run a simple trusted name service on some host.
#	
# Command syntax
# --------------
#
# Ad 1) nnsd ?-localonly BOOL? ?-port PORT?
#
#       Run the server. If no port is specified the default port 38573
#       is used to listen for client. The option -localonly determines
#       what connections are acceptable, local only (default), or
#       remote connections as well. Local connections are whose
#       originating from the same host which is running the server.
#       Remote connections come from other hosts.

lappend auto_path [file join [file dirname [file dirname [file normalize [info script]]]] modules]

package require nameserv::server

namespace eval ::nnsd {}

proc ::nnsd::ProcessCommandLine {} {
    global argv

    # Process the options, perform basic validation.

    while {[llength $argv]} {
	set opt [lindex $argv 0]
	if {![string match "-*" $opt]} break

	switch -exact -- $opt {
	    -localonly {
		if {[llength $argv] % 2 == 1} Usage

		# Todo: Check boolean 
		set local [lindex $argv 1]
		set argv [lrange $argv 2 end]

		nameserv::server::configure -localonly $local
	    }
	    -port {
		if {[llength $argv] % 2 == 1} Usage

		# Todo: Check non-zero unsigned short integer
		set port [lindex $argv 1]
		set argv [lrange $argv 2 end]

		nameserv::server::configure -port $port
	    }
	    -debug {
		# Undocumented. Activate the logger services provided
		# by various packages.
		logger::setlevel debug
		set argv [lrange $argv 1 end]
	    }
	    default {
		Usage
	    }
	}
    }

    # Additional validation, and extraction of the non-option
    # arguments. Of which this application has none.

    if {[llength $argv]} Usage

    return
}

proc ::nnsd::Usage {} {
    global argv0
    puts stderr "$argv0 wrong#args, expected:\
	    ?-localonly BOOL? ?-port PORT?"
    exit 1
}

proc ::nnsd::ArgError {text} {
    global argv0
    puts stderr "$argv0: $text"
    exit 1
}

proc bgerror {args} {
    puts stderr $args
    puts stderr $::errorInfo
    return
}

# ### ### ### ######### ######### #########
## Main

proc ::nnsd::Headline {} {
    global argv0 
    set p        [nameserv::server::cget -port]
    set l [expr {[nameserv::server::cget -localonly]
		 ? "local only"
		 : "local & remote"}]

    puts "$argv0 [package require nnsd], listening on $p ($l)"
    return
}

proc ::nnsd::Do {} {
    global argv0 

    ProcessCommandLine

    nameserv::server::start
    Headline

    vwait forever
    return
}

# ### ### ### ######### ######### #########
## Invoking the functionality.

if {[catch {
    ::nnsd::Do
} msg]} {
    puts $::errorInfo
    #::nnsd::ArgError $msg
}

# ### ### ### ######### ######### #########
exit
@


1.2
log
@
	* nns_client.man: New name for nns.man, to avoid clashing with the
	* nns.tcl: nns.man of the command line client, and removed unwanted
	  log output from the client package.

	* ../../apps/nnsl: Merged nnsl and nnst into one command line client
	* ../../apps/nnst: application, nns. Added documentation for that
	* ../../apps/nns: application.
	* ../../apps/nns.man

	* ../../apps/nnsd.man: Added documentation for the command line
	  server application.

	* nns_server.man: Changed configuration -local to -localonly
	* server.tcl: for better understanding. Bumped to version 0.2
	* pkgIndex.tcl: Removed unwanted log output.
@
text
@d6 1
a6 1
# Application nnsd 1.0
d22 1
a22 1
package provide nnsd 1.0
d123 1
a123 1
    set l [expr {[nameserv::server::cget -local]
@


1.1
log
@
	* support/installation/modules.tcl: New module 'nns' added, a
	  nano-sized name service based on and for 'comm'. Derived from
	  the nserver code in the Pool_Net bundle of packages.

	* NNS - Nano Name Service.
	  Initial commit. TODO: Documentation for client and server, ditto
	  testsuites, are needed. Only the trivial code shared by both is
	  documented and tested. Manual testing has been done however,
	  using the nns* applications, see apps/
@
text
@d35 1
a35 1
# Ad 1) nnsd ?-local BOOL? ?-port PORT?
d38 1
a38 1
#       is used to listen for client. The option -local determines
d60 1
a60 1
	    -local {
d67 1
a67 1
		nameserv::server::configure -local $local
d101 1
a101 1
	    ?-local BOOL? ?-port PORT?"
@

