head	1.2;
access;
symbols;
locks; strict;
comment	@# @;


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

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


desc
@@


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
@#! /bin/sh
# -*- tcl -*- \
exec tclsh "$0" ${1+"$@@"}

# @@@@ Meta Begin
# Application nnst 1.0
# Meta platform     tcl
# Meta summary      Nano Name Service Test Client
# Meta description  This application connects to a name service demon
# Meta description  and binds itself to a configurable name/data pair.
# Meta description  It does not exit on its own, to keep the name alive.
# Meta subject      {name service} client test
# Meta require      {Tcl 8.4}
# Meta require      comm
# Meta require      logger
# Meta require      nameserv::common
# Meta require      nameserv
# Meta author       Andreas Kupries
# Meta license      BSD
# @@@@ Meta End

package provide nnst 1.0

# nnst - Nano Name Service Test Client
# ==== = =============================
#
# Use cases
# ---------
# 
# (1)	Query a nano name service
#	
# Command syntax
# --------------
#
# Ad 1) nnst ?-host NAME|IP? ?-port PORT? name data
#
#       Register a name with data. If no port is specified the default
# 	port 38573 is used to connect to it. If no host is specified
# 	the default (localhost) is used to connect to it.

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

package require nameserv

namespace eval ::nnst {}

proc ::nnst::ProcessCommandLine {} {
    global argv
    variable xname
    variable xdata

    # Process the options, perform basic validation.

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

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

		set host [lindex $argv 1]
		set argv [lrange $argv 2 end]

		nameserv::configure -host $host
	    }
	    -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::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] != 2} Usage

    foreach {xname xdata} $argv break
    return
}

proc ::nnst::Usage {} {
    global argv0
    puts stderr "$argv0 wrong#args, expected:\
	    ?-host NAME|IP? ?-port PORT? NAME DATA"
    exit 1
}

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

# ### ### ### ######### ######### #########
## Setup a text|graphical report

proc ::nnst::blank {s} {
    regsub -all -- {[^	]} $s { } s
    return $s
}

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

proc ::nnst::Do {} {
    global argv0
    variable xname
    variable xdata

    ProcessCommandLine

    set mp [nameserv::protocol]
    set sp [nameserv::server_protocol]
    set sf [join [nameserv::server_features] {, }]

    if {[llength $sf] > 1} {
	set sf [linsert $sf end-1 and]
    }

    set app "$argv0 [package require nnst]"
    set pfx [blank $app]

    puts "$app (Client Protocol $mp)"
    puts "$pfx (Server Protocol $sp, Features: $sf)"

    puts "Binding name \"$xname\""
    puts " Client data \"$xdata\""

    nameserv::bind $xname $xdata
    vwait forever
    return
}

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

if {[catch {
    ::nnst::Do
} msg]} {
    ::nnst::ArgError $msg
}

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


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
@@

