/*
*/
-/*
- * hbytes raw2h BINARY => hex
- * hbytes h2raw HEX => binary
- *
- * hbytes prepend VAR [VALUE ...] = set VAR [concat VALUE ... $VAR]
- * hbytes append VAR [VALUE ...] = set VAR [concat $VAR VALUE ...]
- * hbytes concat VAR [VALUE ...] = set VAR [concat VALUE ...]
- * hbytes unprepend VAR PREFIXLENGTH => prefix (removed from VAR)
- * hbytes unappend VAR SUFFIXLENGTH => suffix (removed from VAR)
- * hbytes chopto VAR NEWVARLENGTH => suffix (removed from VAR)
- * (too short? error)
- *
- * hbytes pkcs5 pa|ua VAR ALG => worked? (always 1 for p)
- * hbytes pkcs5 pn|un VAR BLOCKSIZE => worked? (always 1 for p)
- * hbytes blockcipher d|e VAR ALG MODE [IV] => IV
- *
- * hbytes hash ALG MESSAGE => hash
- * hbytes hmac ALG MESSAGE KEY [MACLENGTH] => mac
- *
- * Refs: HMAC: RFC2104
- */
-#ifndef HBYTES_H
-#define HBYTES_H
+#ifndef CHIARK_TCL_H
+#define CHIARK_TCL_H
#include <assert.h>
#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+#include <sys/un.h>
+#include <arpa/inet.h>
+
+#include <tcl8.3/tcl.h>
-#include <tcl.h>
+#include <adns.h>
typedef unsigned char Byte;
-/* from hbytes.c */
+/* for assisting tcmdifgen and tcmdiflib.c */
-/* Internal representation details: */
-#define HBYTES_ISEMPTY(hb) (!(hb)->begin_complex && !(hb)->end_0)
-#define HBYTES_ISSENTINEL(hb) (!(hb)->begin_complex && (hb)->end_0)
-#define HBYTES_ISSIMPLE(hb) ((hb)->begin_complex && (hb)->end_0)
-#define HBYTES_ISCOMPLEX(hb) ((hb)->begin_complex && !(hb)->end_0)
+typedef struct TopLevel_Command TopLevel_Command;
-typedef struct {
- void *begin_complex, *end_0;
-} HBytes_Value; /* overlays internalRep */
+struct TopLevel_Command {
+ const char *name;
+ Tcl_ObjCmdProc *func;
+};
-typedef struct {
- Byte *dstart; /* always allocated dynamically */
- int prespace, len, avail;
- /*
- * | SPARE | USED | SPARE |
- * |<-prespace->|<-len->| |
- * | |<----avail---->|
- * ^start
- */
-} HBytes_ComplexValue; /* pointed to from internalRep.otherValuePtr */
+void cht_setstringresult(Tcl_Interp*, const char*);
+int cht_pat_enum(Tcl_Interp*, Tcl_Obj*, const void**,
+ const void*, size_t, const char *what);
-/* Public interfaces: */
+/* from scriptinv.c */
-extern Tcl_ObjType hbytes_type;
+typedef struct { /* semi-opaque - read only, and then only where commented */
+ Tcl_Interp *ip; /* valid, non-0 and useable if set */
+ Tcl_Obj *obj; /* non-0 iff set (but only test for 0/non-0) */
+ Tcl_Obj *xargs;
+ int llength; /* after set, is llength of script + xargs */
+} ScriptToInvoke;
-int hbytes_len(const HBytes_Value *v);
-Byte *hbytes_data(const HBytes_Value *v); /* caller may then modify data! */
-int hbytes_issentinel(const HBytes_Value *v);
+void cht_scriptinv_init(ScriptToInvoke *si);
+int cht_scriptinv_set(ScriptToInvoke *si, Tcl_Interp *ip,
+ Tcl_Obj *newscript, Tcl_Obj *xargs);
+void cht_scriptinv_cancel(ScriptToInvoke *si); /* then don't invoke */
+ /* no separate free function - just cancel */
-Byte *hbytes_prepend(HBytes_Value *upd, int el);
-Byte *hbytes_append(HBytes_Value *upd, int el);
- /* return value is where to put the data */
+int cht_scriptinv_invoke_fg(ScriptToInvoke *si, int argc,
+ Tcl_Obj *const *argv);
+ /* if script fails, returns that error */
-const Byte *hbytes_unprepend(HBytes_Value *upd, int rl);
-const Byte *hbytes_unappend(HBytes_Value *upd, int rl);
- /* return value points to the removed data, which remains valid
- * until next op on the HBytes_Value. If original value is
- * shorter than rl or negative, returns 0 and does nothing. */
+void cht_scriptinv_invoke(ScriptToInvoke *si, int argc, Tcl_Obj *const *argv);
+ /* if script fails, reports it with Tcl_BackgroundError */
-void hbytes_empty(HBytes_Value *returns);
-void hbytes_sentinel(HBytes_Value *returns);
-void hbytes_array(HBytes_Value *returns, const Byte *array, int l);
-Byte *hbytes_arrayspace(HBytes_Value *returns, int l);
-void hbytes_free(HBytes_Value *frees);
- /* _empty, _sentinel and _array do not free or read the old value;
- * _free it first if needed. _free leaves it garbage, so you
- * have to call _empty to reuse it. _arrayspace doesn't fill
- * the array; you get a pointer and must fill it with data
- * yourself. */
+/* from idtable.c */
-/* The value made by hbytes_sentinel should not be passed to
- * anything except HBYTES_IS..., and hbytes_free. */
+typedef struct {
+ const char *valprefix, *assockey;
+ void (*destroyitem)(Tcl_Interp *ip, void *val);
+} IdDataSpec;
+
+/* The stored struct must start with a single int, conventionally
+ * named `ix'. When the struct is returned for the first time ix must
+ * be -1; on subsequent occasions it must be >=0. ix will be -1 iff
+ * the struct is registered by the iddatatable machinery. */
+
+extern Tcl_ObjType cht_tabledataid_nearlytype;
+int cht_tabledataid_parse(Tcl_Interp *ip, Tcl_Obj *o, const IdDataSpec *idds);
+void cht_tabledataid_disposing(Tcl_Interp *ip, void *val, const IdDataSpec *idds);
+ /* call this when you destroy the struct, to remove its name;
+ * _disposing is idempotent */
/* from hook.c */
-int staticerr(Tcl_Interp *ip, const char *m);
-void objfreeir(Tcl_Obj *o);
+int cht_initextension(Tcl_Interp *ip, const TopLevel_Command *cmds,
+ int *donep /* or 0, meaning no types follow */,
+ ... /* types, terminated by 0 */);
+
+int cht_staticerr(Tcl_Interp *ip, const char *m, const char *ec);
+int cht_posixerr(Tcl_Interp *ip, int errnoval, const char *m);
+int cht_newfdposixerr(Tcl_Interp *ip, int fd, const char *m);
+void cht_objfreeir(Tcl_Obj *o);
+int cht_get_urandom(Tcl_Interp *ip, Byte *buffer, int l);
+
+void cht_obj_updatestr_array(Tcl_Obj *o, const Byte *array, int l);
+void cht_obj_updatestr_array_prefix(Tcl_Obj *o, const Byte *byte,
+ int l, const char *prefix);
+
+void cht_obj_updatestr_vstringls(Tcl_Obj *o, ...);
+ /* const char*, int, const char*, int, ..., (const char*)0 */
+void cht_obj_updatestr_string_len(Tcl_Obj *o, const char *str, int l);
+void cht_obj_updatestr_string(Tcl_Obj *o, const char *str);
/* from parse.c */
typedef struct {
- HBytes_Value *hb;
Tcl_Obj *obj, *var;
-} HBytes_Var;
-
-void fini_hbv(Tcl_Interp *ip, int rc, HBytes_Var *agg);
+ int copied;
+} Something_Var;
-/* from chop.c */
+void cht_init_somethingv(Something_Var *sth);
+void cht_fini_somethingv(Tcl_Interp *ip, int rc, Something_Var *sth);
+int cht_pat_somethingv(Tcl_Interp *ip, Tcl_Obj *var,
+ Something_Var *sth, Tcl_ObjType *type);
/* from enum.c */
-extern Tcl_ObjType enum_nearlytype;
-extern Tcl_ObjType enum1_nearlytype;
+extern Tcl_ObjType cht_enum_nearlytype;
+extern Tcl_ObjType cht_enum1_nearlytype;
-const void *enum_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o,
+const void *cht_enum_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o,
const void *firstentry, size_t entrysize,
const char *what);
#define enum_lookup_cached(ip,o,table,what) \
- (enum_lookup_cached_func((ip),(o), \
- sizeof((table)[0]),&(table)[0], \
+ (cht_enum_lookup_cached_func((ip),(o), \
+ &(table)[0],sizeof((table)[0]), \
(what)))
/* table should be a pointer to an array of structs of size
* entrysize, the first member of which should be a const char*.
* set to the error message.
*/
-int enum1_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o,
+int cht_enum1_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o,
const char *opts, const char *what);
/* -1 => error */
-/* from crypto.c */
-
-typedef struct {
- int blocksize, hashsize;
-} HashAlgInfo;
-
-typedef struct {
- int blocksize;
-} BlockCipherAlgInfo;
-
-typedef struct {
- int dummy;
-} BlockCipherModeInfo;
-
/* useful macros */
-#define OBJ_HBYTES(o) ((HBytes_Value*)&(o)->internalRep.twoPtrValue)
-
#define TALLOC(s) ((void*)Tcl_Alloc((s)))
#define TFREE(f) (Tcl_Free((void*)(f)))
+#define TREALLOC(p,l) ((void*)Tcl_Realloc((void*)(p),(l)))
-#endif /*HBYTES_H*/
+#endif /*CHIARK_TCL_H*/