[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[dev-serveez] Guile test program

From: Martin Grabmueller
Subject: [dev-serveez] Guile test program
Date: Mon, 08 Jan 2001 21:11:40 +0100

Hi all,

I have written the test program Stefan requested.  It initializes the
Guile library, defines some variables and a procedure and sources a
config file.  In order to build it, I had to do the following: 

  gcc -o test-guile test-guile.c -L/usr/local/lib -lguile

Then (with config.scm in the current directory), run it:

address@hidden (~/guile): ./test-guile 
defining server `fakeident-server1' of type `fakeident'
defining server `tunnel-server1' of type `tunnel'
defining server `tunnel-server2' of type `tunnel'
** Welcome to Serveez 0.0.20 using Guile 1.4.1 (debugging enabled) 
* This is the Win32 port, good luck.

(Of course this was not really the win32 port, I just set the variable
to 1).

The C program and the config file are attached.  It should build with
Guile 1.3 and 1.4.  If anyone has questions about it, feel free to
ask, as always.


Martin Grabmueller              address@hidden  address@hidden on EFnet

===File ~/guile/test-guile.c================================

#include <guile/gh.h>

#define FUNC_NAME "define-server!"
static SCM
define_server_x (SCM type, SCM name, SCM alist)
  char * ctype;
  char * cname;
  SCM cpair;

  SCM_VALIDATE_STRING_COPY (1, type, ctype);
  SCM_VALIDATE_STRING_COPY (2, name, cname);
  SCM_VALIDATE_LIST (3, alist);

  while (gh_pair_p (alist))
      SCM_VALIDATE_ALISTCELL_COPYSCM (3, alist, cpair);
      alist = gh_cdr (alist);
  printf ("defining server `%s' of type `%s'\n",
          cname, ctype);
#undef FUNC_NAME

char * version_string = "0.0.20";
int have_debug = 1;
int have_win32 = 1;
int verbosity = 2;
int max_sockets = 100;
char server_password[128] = "secret";

static void
  gh_define ("serveez-version", gh_str02scm(version_string));
  gh_define ("guile-version", scm_version ());

  gh_define ("have-debug", gh_bool2scm(have_debug));
  gh_define ("have-win32", gh_bool2scm(have_win32));

  gh_define ("serveez-verbosity", gh_int2scm(verbosity));
  gh_define ("serveez-sockets", gh_int2scm(max_sockets));
  gh_define ("serveez-pass", gh_str02scm(server_password));

  gh_new_procedure("define-server!", define_server_x, 3, 0, 0);

static void
inner_main (int argc, char * argv[])
  init_test_guile ();
  gh_eval_file ("config.scm");

main (int argc, char **argv)
  gh_enter (argc, argv, inner_main);
  return 0; /* never reached */

===File ~/guile/config.scm==================================
;; Definition of a fake ident server.
(define-server! "fakeident" "fakeident-server1" 
  '((port       . ((proto  . "tcp")
                   (port   . 113)
                   (ipaddr ."*")))
    (systemtype . "UNIX")
    (username   . "supa-raimi")))

;; The tunnel server 1 and 2 create a tunnel between the local telnet
;; daemon and a tcp connection.
(define-server! "tunnel" "tunnel-server1"
  '((source . ((proto  . "tcp")
               (port   . 42425)))
    (target . ((proto  . "icmp")
               (ipaddr . "")))))

(define-server! "tunnel" "tunnel-server2"
  '((source . ((proto  . "icmp")))
    (target . ((proto  . "tcp")
               (port   . 23)
               (ipaddr . "")))))

;; === Convenience functions - Scheme for beginners, thanks to 'mgrabmue.
(define (println . args) (for-each display args)(newline))
(define (printsln spacer . args)
  (for-each (lambda(x)(display x)(display spacer)) args)(newline))

;; === Greet the user
(printsln " "
          "** Welcome to Serveez" serveez-version 
          "using Guile" guile-version
          (if have-debug
              "(debugging enabled)"

(if have-win32
    (println "* This is the Win32 port, good luck."))

;; === general options for serveez ========================

;; log level 0..4 (lesser values mean fewer logging messages)
;; use 0 for production environment
(set! serveez-verbosity 4)

;; maximum accepted remote connections
(set! serveez-sockets 100)

;; password for the control protocol (plain/crypted)
(set! serveez-pass "secret")
;;(set! serveez-pass "xmA9CY34MxkGg")

;; If you want to include more settings from other files use this.
;;(primitive-load "otherfile.cfg")

reply via email to

[Prev in Thread] Current Thread [Next in Thread]