chiark / gitweb /
hbytes compiles
authorian <ian>
Sat, 7 Jan 2006 20:16:37 +0000 (20:16 +0000)
committerian <ian>
Sat, 7 Jan 2006 20:16:37 +0000 (20:16 +0000)
19 files changed:
adns/.cvsignore
base/.cvsignore
base/chiark-tcl-base.h [new file with mode: 0644]
base/tcmdifgen
crypto/crypto.h [new file with mode: 0644]
crypto/hook.c [new file with mode: 0644]
dgram/dgram.h [new file with mode: 0644]
dgram/hook.c [new file with mode: 0644]
hbytes/.cvsignore [new file with mode: 0644]
hbytes/Makefile
hbytes/chiark_tcl_hbytes.h [new file with mode: 0644]
hbytes/hbglue.c [deleted file]
hbytes/hbytes.tct
hbytes/hook.c
hbytes/parse.c
maskmap/maskmap-bits.c [new file with mode: 0644]
maskmap/maskmap.tct [new file with mode: 0644]
tuntap/tuntap.h [new file with mode: 0644]
tuntap/tuntap.tct [new file with mode: 0644]

index 6796ef38cb5f8853af2024dc53adccd71db1232f..fc2ec4f28b72a1fc622f5cf742b5c6a02c6838dc 100644 (file)
@@ -1,2 +1,2 @@
-tables.[ch]
+*+tcmdif.[ch]
 *.d
index e7a6c222eee3994daa89d8103c2d45056676ca47..fc2ec4f28b72a1fc622f5cf742b5c6a02c6838dc 100644 (file)
@@ -1,2 +1,2 @@
-adns+tcmdif.[ch]
+*+tcmdif.[ch]
 *.d
diff --git a/base/chiark-tcl-base.h b/base/chiark-tcl-base.h
new file mode 100644 (file)
index 0000000..d8f000a
--- /dev/null
@@ -0,0 +1,5 @@
+#include <string.h>
+#include <errno.h>
+
+#include "chiark-tcl.h"
+#include "base+tcmdif.h"
index d5e662234ddba0951fb59b300469b22a3e9821d3..4b675968217e6d0f09dc6dfa2339749551db37d9 100755 (executable)
@@ -56,7 +56,7 @@
 #     Arranges for generated .h files to #include the specified
 #     file.  C-INCLUDE-SPECIFIER should include the <..> or "..".
 #
-#  Table TABLENAME C-ENTRY-TYPE
+#  Table [*]TABLENAME C-ENTRY-TYPE
 #     Starts a table of commands or subcommands.  The generated .h
 #     will contain a definition of C-ENTRY-TYPE containing
 #         const char *name;
 #     arguments, processes the command, and sets any result, as
 #     applicable.
 #
+#     `*' should be used if the table name is not useful for error
+#     messages.  It suppresses `TABLENAME ' from the front of the
+#     autogenerated argument parsing error strings.
+#
 #  ExtraEntry C-ENTRY-TYPE
 #     Introduces a section of additional C code which will be inserted
 #     into the definition of C-ENTRY-TYPE by `Table'.  The C
@@ -178,11 +182,12 @@ sub parse ($$) {
            unshift @i, $this_indent;
        }
 
-       if (@i==0 && m/^Table\s+(\w+)\s+(\w+)$/) {
+       if (@i==0 && m/^Table\s+(\*?)(\w+)\s+(\w+)$/) {
            zilch();
-           $c_table= $1;
-           $table_x{$c_table}{C}= $2;
-           $entrytype_x{$2}= '' unless exists $entrytype_x{$2};
+           $c_table= $2;
+           $table_x{$c_table}{T}= $1;
+           $table_x{$c_table}{C}= $3;
+           $entrytype_x{$3}= '' unless exists $entrytype_x{$3};
        } elsif (@i==0 && m/^Untabled$/) {
            zilch();
            $c_table= '';
@@ -291,7 +296,8 @@ foreach $c_table (sort keys %tables) {
        $any_eerr= 0;
        $any_eargc= 0;
        $pa_hint= '';
-       $pa_hint .= "$c_table " if length $c_table;
+       $pa_hint .= "$c_table " if length $c_table &&
+           !length $table_x{$c_table}{T};
        $pa_hint.= $c_entry;
        foreach $arg (@{ $r_entry->{A} }) {
            $n= $arg->{N};
diff --git a/crypto/crypto.h b/crypto/crypto.h
new file mode 100644 (file)
index 0000000..82efb61
--- /dev/null
@@ -0,0 +1,77 @@
+/* from crypto.c */
+
+void memxor(Byte *dest, const Byte *src, int l);
+
+typedef struct {
+  const char *name;
+  int pad, use_algname;
+} PadOp;
+
+extern Tcl_ObjType blockcipherkey_type;
+
+/* from algtables.c */
+
+typedef struct {
+  const char *name;
+  int int_offset;
+} BlockCipherPropInfo, HashAlgPropInfo;
+
+typedef struct {
+  const char *name;
+  int hashsize, blocksize, statesize;
+  void (*init)(void *state);
+  void (*update)(void *state, const void *data, int len);
+  void (*final)(void *state, void *digest);
+  void (*oneshot)(void *digest, const void *data, int len);
+} HashAlgInfo;
+
+extern const HashAlgInfo hashalginfos[];
+
+typedef struct {
+  void (*make_schedule)(void *schedule, const void *key, int keylen);
+  void (*crypt)(const void *schedule, const void *in, void *out);
+     /* in and out may be the same, but if they aren't they may not overlap */
+     /* in and out for crypt will have been through block_byteswap */
+} BlockCipherPerDirectionInfo;
+
+typedef struct {
+  const char *name;
+  int blocksize, schedule_size, key_min, key_max;
+  BlockCipherPerDirectionInfo encrypt, decrypt;
+} BlockCipherAlgInfo;
+
+extern const BlockCipherAlgInfo blockcipheralginfos[];
+
+/* from bcmode.c */
+
+typedef struct {
+  const char *name;
+  int iv_blocks, buf_blocks, mac_blocks;
+
+  /* Each function is allowed to use up to buf_blocks * blocksize
+   * bytes of space in buf.  data is blocks * blocksize bytes
+   * long.  data should be modified in place by encrypt and decrypt;
+   * modes may not change the size of data.  iv is always provided and
+   * is always of length iv_blocks * blocksize; encrypt and
+   * decrypt may modify the iv value (in which case the Tcl caller
+   * will get the modified IV) but this is not recommended.  mac
+   * should leave the mac, which must be mac_blocks * blocksize
+   * bytes, in buf.  (Therefore mac_blocks must be at least
+   * buf_blocks.)
+   */
+  const char *(*encrypt)(Byte *data, int nblocks,
+                        const Byte *iv, Byte *buf,
+                        const BlockCipherAlgInfo *alg, int encr,
+                        const void *sch);
+  const char *(*decrypt)(Byte *data, int nblocks,
+                        const Byte *iv, Byte *buf,
+                        const BlockCipherAlgInfo *alg, int encr,
+                        const void *sch);
+  const char *(*mac)(const Byte *data, int nblocks,
+                    const Byte *iv, Byte *buf,
+                    const BlockCipherAlgInfo *alg,
+                    const void *sch);
+} BlockCipherModeInfo;
+
+extern const BlockCipherModeInfo blockciphermodeinfos[];
+
diff --git a/crypto/hook.c b/crypto/hook.c
new file mode 100644 (file)
index 0000000..3e1f87e
--- /dev/null
@@ -0,0 +1 @@
+  Tcl_RegisterObjType(&blockcipherkey_type);
diff --git a/dgram/dgram.h b/dgram/dgram.h
new file mode 100644 (file)
index 0000000..d95185c
--- /dev/null
@@ -0,0 +1,22 @@
+/* from sockaddr.c */
+
+typedef struct {
+  Byte *begin, *end;
+} SockAddr_Value;
+
+extern Tcl_ObjType sockaddr_type;
+
+void sockaddr_clear(SockAddr_Value*);
+void sockaddr_create(SockAddr_Value*, const struct sockaddr *addr, int len);
+int sockaddr_len(const SockAddr_Value*);
+const struct sockaddr *sockaddr_addr(const SockAddr_Value*);
+void sockaddr_free(const SockAddr_Value*);
+
+/* from dgram.c */
+
+extern const IdDataSpec dgram_socks;
+
+/* from misc.c */
+
+int setnonblock(int fd, int isnonblock);
+
diff --git a/dgram/hook.c b/dgram/hook.c
new file mode 100644 (file)
index 0000000..72b3f70
--- /dev/null
@@ -0,0 +1 @@
+  Tcl_RegisterObjType(&sockaddr_type);
diff --git a/hbytes/.cvsignore b/hbytes/.cvsignore
new file mode 100644 (file)
index 0000000..fc2ec4f
--- /dev/null
@@ -0,0 +1,2 @@
+*+tcmdif.[ch]
+*.d
index a1955b7056c2fc0111ae4ef0de4c80852c959852..8551e29c134487ca35396ccc3e67b2885bfba70a 100644 (file)
@@ -1,6 +1,6 @@
 BASE_DIR =     ../base
 EXTBASE =      hbytes
-CFILES =       addrmap chop hbytes hook parse ulongs
+CFILES =       chop hbytes hook parse ulongs
 
 include ../base/extension.make
 
diff --git a/hbytes/chiark_tcl_hbytes.h b/hbytes/chiark_tcl_hbytes.h
new file mode 100644 (file)
index 0000000..8786a6a
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ */
+
+#ifndef CHIARK_TCL_HBYTES_H
+#define CHIARK_TCL_HBYTES_H
+
+#include "hbytes.h"
+
+typedef struct {
+  Byte *start; /* byl bytes */
+  Tcl_Obj *data; /* may be 0 to mean empty */
+} AddrMap_Entry;
+
+struct AddrMap_Value {
+  int byl, used, space;
+  AddrMap_Entry *entries;
+  /* Entries are sorted by start.  Each entry gives value (or lack of
+   * it) for all A st START <= A < NEXT-START.  Last entry has value
+   * (or lack of it) for all A >= START.  First entry is always
+   * present and always has start all-bits-0. */
+}; /* internalRep.otherValuePtr */
+
+#include "hbytes+tcmdif.h"
+
+#endif /*CHIARK_TCL_HBYTES_H*/
diff --git a/hbytes/hbglue.c b/hbytes/hbglue.c
deleted file mode 100644 (file)
index 1ac833d..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-int cht_pat_hbv(Tcl_Interp *ip, Tcl_Obj *var, HBytes_Var *agg) {
-  int rc;
-  rc= pat_somethingv(ip,var,&agg->sth,&hbytes_type);  if (rc) return rc;
-  agg->hb= OBJ_HBYTES(agg->sth.obj);
-  return TCL_OK;
-}
-
-int cht_pat_hb(Tcl_Interp *ip, Tcl_Obj *obj, HBytes_Value *val) {
-  int rc;
-  rc= Tcl_ConvertToType(ip,obj,&hbytes_type);  if (rc) return rc;
-  *val= *OBJ_HBYTES(obj);
-  return TCL_OK;
-}
-
-Tcl_Obj *cht_ret_hb(Tcl_Interp *ip, HBytes_Value val) {
-  Tcl_Obj *obj;
-  obj= Tcl_NewObj();
-  Tcl_InvalidateStringRep(obj);
-  *OBJ_HBYTES(obj)= val;
-  obj->typePtr= &hbytes_type;
-  return obj;
-}
-
index abfd45a50620b8134ba5b540cd90073f2ee1a963..299d4a912131522146fd4636d9d1a522ba31dc73 100644 (file)
@@ -9,7 +9,7 @@ Type addrmapv:                  AddrMap_Var @
 Init addrmapv                  @.am=0; cht_init_somethingv(&@.sth);
 Fini addrmapv                  cht_fini_somethingv(ip, rc, &@.sth);
 
-Table hbytestoplevel TopLevel_Command
+Table *hbytestoplevel TopLevel_Command
        hbytes
                subcmd  enum(HBytes/_SubCommand, "hbytes subcommand")
                ...     obj
@@ -126,24 +126,3 @@ Table hbytes HBytes_SubCommand
        random
                length  int
                =>      hb
-#      addr-map
-#              subcmd  enum(AddrMap/_SubCommand, "hbytes addr-map subcommand")
-#              ...     obj
-
-#Table addrmap AddrMap_SubCommand
-#      lookup
-#              map     constv(&cht_addrmap_type)
-#              addr    hb
-#              ?def    obj
-#              =>      obj
-#      amend-range
-#              map     addrmapv
-#              start   hb
-#              end     hb
-#              data    obj
-#      amend-mask
-#              map     addrmapv
-#              prefix  hb
-#              preflen obj
-#              data    obj
-
index 4c742f3dcd99de2a1140c17733edd95e473384c1..7eeb4377b9ff70f73287c4d7d4c6b72c982a548d 100644 (file)
@@ -266,12 +266,6 @@ int cht_do_hbytes_range(ClientData cd, Tcl_Interp *ip,
   return TCL_OK;
 }
 
-int cht_do_hbytes_addr_map(ClientData cd, Tcl_Interp *ip,
-                      const AddrMap_SubCommand *subcmd,
-                      int objc, Tcl_Obj *const *objv) {
-  return subcmd->func(0,ip,objc,objv);
-}
-
 /* hbytes representing uint16_t's */
 
 int cht_do_hbytes_h2ushort(ClientData cd, Tcl_Interp *ip,
@@ -323,6 +317,5 @@ int Chiark_tcl_hbytes_Init(Tcl_Interp *ip) {
   return cht_initextension(ip, cht_hbytestoplevel_entries, &initd,
                           &cht_hbytes_type,
                           &cht_ulong_type,
-                          &cht_addrmap_type,
                           (Tcl_ObjType*)0);
 }
index a3635142bb3dfe186da16b1051a2a513693b4b0d..266de4b6739ab96534539906450f7b0f3af264d2 100644 (file)
@@ -3,6 +3,13 @@
 
 #include "chiark_tcl_hbytes.h"
 
+int cht_pat_hbv(Tcl_Interp *ip, Tcl_Obj *var, HBytes_Var *agg) {
+  int rc;
+  rc= cht_pat_somethingv(ip,var,&agg->sth,&cht_hbytes_type);
+  if (rc) return rc;
+  agg->hb= OBJ_HBYTES(agg->sth.obj);
+  return TCL_OK;
+}
 int cht_pat_hb(Tcl_Interp *ip, Tcl_Obj *obj, HBytes_Value *val) {
   int rc;
   rc= Tcl_ConvertToType(ip,obj,&cht_hbytes_type);  if (rc) return rc;
diff --git a/maskmap/maskmap-bits.c b/maskmap/maskmap-bits.c
new file mode 100644 (file)
index 0000000..88cb31c
--- /dev/null
@@ -0,0 +1,15 @@
+int cht_do_hbytes_addr_map(ClientData cd, Tcl_Interp *ip,
+                      const AddrMap_SubCommand *subcmd,
+                      int objc, Tcl_Obj *const *objv) {
+  return subcmd->func(0,ip,objc,objv);
+}
+
+xxxx
+extern int Chiark_tcl_hbytes_Init(Tcl_Interp *ip); /*called by load(3tcl)*/
+int Chiark_tcl_hbytes_Init(Tcl_Interp *ip) {
+  static int initd;
+  
+  return cht_initextension(ip, cht_hbytestoplevel_entries, &initd,
+                          &cht_addrmap_type,
+                          (Tcl_ObjType*)0);
+}
diff --git a/maskmap/maskmap.tct b/maskmap/maskmap.tct
new file mode 100644 (file)
index 0000000..ed1ca77
--- /dev/null
@@ -0,0 +1,22 @@
+Table maskmaptoplevel TopLevel_Command
+       addr-map
+               subcmd  enum(AddrMap/_SubCommand, "addr-map subcommand")
+               ...     obj
+
+Table addrmap AddrMap_SubCommand
+       lookup
+               map     constv(&cht_addrmap_type)
+               addr    hb
+               ?def    obj
+               =>      obj
+       amend-range
+               map     addrmapv
+               start   hb
+               end     hb
+               data    obj
+       amend-mask
+               map     addrmapv
+               prefix  hb
+               preflen obj
+               data    obj
+
diff --git a/tuntap/tuntap.h b/tuntap/tuntap.h
new file mode 100644 (file)
index 0000000..f23eee1
--- /dev/null
@@ -0,0 +1,4 @@
+/* from tuntap.c */
+
+extern const IdDataSpec tuntap_socks;
+
diff --git a/tuntap/tuntap.tct b/tuntap/tuntap.tct
new file mode 100644 (file)
index 0000000..22f01fb
--- /dev/null
@@ -0,0 +1,18 @@
+
+Table tuntap_socket_raw TunSocket_SubCommand
+       create
+               ?ifname string
+               =>      iddata(&tuntap_socks)
+       close
+               sock    iddata(&tuntap_socks)
+       ifname
+               sock    iddata(&tuntap_socks)
+               =>      string
+       receive
+               sock    iddata(&tuntap_socks)
+               data    hb
+       on-transmit
+               sock    iddata(&tuntap_socks)
+               mtu     long
+               ?script obj
+