1#ifndef TRF_INT_H
2#define TRF_INT_H
3
4/* -*- c -*-
5 * transformInt.h - internal definitions
6 *
7 * Copyright (C) 1996, 1997 Andreas Kupries (a.kupries@westend.com)
8 * All rights reserved.
9 *
10 * Permission is hereby granted, without written agreement and without
11 * license or royalty fees, to use, copy, modify, and distribute this
12 * software and its documentation for any purpose, provided that the
13 * above copyright notice and the following two paragraphs appear in
14 * all copies of this software.
15 *
16 * IN NO EVENT SHALL I BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
17 * INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
18 * SOFTWARE AND ITS DOCUMENTATION, EVEN IF I HAVE BEEN ADVISED OF THE
19 * POSSIBILITY OF SUCH DAMAGE.
20 *
21 * I SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND
24 * I HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
25 * ENHANCEMENTS, OR MODIFICATIONS.
26 *
27 * CVS: $Id: transformInt.h,v 1.45 2008/12/11 19:04:25 andreas_kupries Exp $
28 */
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#include "transform.h"
35#include <errno.h>
36#include <string.h>
37#include <assert.h>
38
39#ifndef ___MAKEDEPEND___
40/*
41 * Hide external references during runs of 'makedepend'.
42 * It may fail on some systems, if the files are not installed.
43 */
44#ifdef MAC_TCL
45#include "compat:dlfcn.h"
46#include "compat:zlib.h"
47#include "compat:bzlib.h"
48#else
49#ifdef HAVE_DLFCN_H
50#   include <dlfcn.h>
51#else
52#   include "../compat/dlfcn.h"
53#endif
54#ifdef HAVE_zlibtcl_PACKAGE
55#   include "zlibtcl.h"
56#else
57#   ifdef HAVE_ZLIB_H
58#      include <zlib.h>
59#   else
60#      include "../compat/zlib.h"
61#   endif
62#endif
63#endif
64#ifdef HAVE_BZ2_H
65#   include <bzlib.h>
66#else
67#   include "../compat/bzlib.h"
68#endif
69#ifdef HAVE_STDLIB_H
70#   include <stdlib.h>
71#else
72#   include "../compat/stdlib.h"
73#endif
74#endif
75
76
77/*
78 * Ensure WORDS_BIGENDIAN is defined correcly:
79 * Needs to happen here in addition to configure to work with fat compiles on
80 * Darwin (where configure runs only once for multiple architectures).
81 */
82
83#ifdef HAVE_SYS_TYPES_H
84#    include <sys/types.h>
85#endif
86#ifdef HAVE_SYS_PARAM_H
87#    include <sys/param.h>
88#endif
89#ifdef BYTE_ORDER
90#    ifdef BIG_ENDIAN
91#        if BYTE_ORDER == BIG_ENDIAN
92#            undef WORDS_BIGENDIAN
93#            define WORDS_BIGENDIAN 1
94#        endif
95#    endif
96#    ifdef LITTLE_ENDIAN
97#        if BYTE_ORDER == LITTLE_ENDIAN
98#            undef WORDS_BIGENDIAN
99#        endif
100#    endif
101#endif
102
103
104
105#ifdef TCL_STORAGE_CLASS
106# undef TCL_STORAGE_CLASS
107#endif
108#ifdef BUILD_Trf
109# define TCL_STORAGE_CLASS DLLEXPORT
110#else
111# define TCL_STORAGE_CLASS DLLIMPORT
112#endif
113
114/* 04/13/1999 Fileevent patch from Matt Newman <matt@novadigm.com>
115 * Normally defined in tcl*Port.h
116 */
117
118#ifndef EWOULDBLOCK
119#define EWOULDBLOCK EAGAIN
120#endif
121
122/* Debugging definitions.
123 */
124
125#ifdef _WIN32
126#undef TRF_DEBUG
127#endif
128
129#ifdef TRF_DEBUG
130extern int n;
131#define BLNKS {int i; for (i=0;i<n;i++) printf (" "); }
132#define IN n+=4
133#define OT n-=4 ; if (n<0) {n=0;}
134#define FL       fflush (stdout)
135#define START(p)   BLNKS; printf ("Start %s...\n",#p); FL; IN
136#define DONE(p)    OT ; BLNKS; printf ("....Done %s\n",#p); FL;
137#define PRINT      BLNKS; printf
138#define PRINTLN(a) BLNKS; printf ("%s\n", (a))
139#define NPRINT     printf
140#define PRTSTR(fmt,len,bytes) PrintString (fmt,len,bytes)
141#define DUMP(len,bytes) DumpString (n, len, bytes)
142
143extern void PrintString _ANSI_ARGS_ ((char* fmt, int len, char* bytes));
144extern void DumpString  _ANSI_ARGS_ ((int level, int len, char* bytes));
145#else
146#define BLNKS
147#define IN
148#define OT
149#define FL
150#define START(p)
151#define DONE(p)
152#define PRINT  if (0) printf
153#define NPRINT if (0) printf
154#define PRINTLN(a)
155#define PRTSTR(fmt,len,bytes)
156#define DUMP(len,bytes)
157#endif
158
159
160/* Convenience macros
161 * - construction of (nested) lists
162 */
163
164#define LIST_ADDOBJ(errlabel,list,o) \
165  res = Tcl_ListObjAppendElement (interp, list, o); \
166  if (res != TCL_OK) {                              \
167    goto errlabel;                               \
168  }
169
170#define LIST_ADDSTR(el, list, str) \
171  LIST_ADDOBJ (el, list, Tcl_NewStringObj (str, -1))
172
173#define LIST_ADDFSTR(el, list, str, len) \
174    LIST_ADDOBJ (el, list, Tcl_NewStringObj (str, len))
175
176#define LIST_ADDINT(el, list, i) \
177    LIST_ADDOBJ (el, list, Tcl_NewIntObj (i))
178
179
180/* Define macro which is TRUE for tcl versions >= 8.1
181 * Required as there are incompatibilities between 8.0 and 8.1
182 */
183
184#define GT81 ((TCL_MAJOR_VERSION > 8) || \
185	      ((TCL_MAJOR_VERSION == 8) && \
186	       (TCL_MINOR_VERSION >= 1)))
187
188/* Define macro which is TRUE for tcl versions >= 8.3.2
189 */
190
191#define GT832 ((TCL_MAJOR_VERSION > 8) || \
192	      ((TCL_MAJOR_VERSION == 8) && \
193	       ((TCL_MINOR_VERSION > 3) || \
194		((TCL_MINOR_VERSION == 3) && \
195		 (TCL_RELEASE_LEVEL == TCL_FINAL_RELEASE) && \
196		 (TCL_RELEASE_SERIAL >= 2)))))
197
198#if ! (GT81)
199/*
200 * Tcl version 8.0.x don't export their 'panic' procedure. Here we
201 * define the necessary interface and map it to the name exported and
202 * used by the higher versions.
203 */
204
205EXTERN void
206panic _ANSI_ARGS_ (TCL_VARARGS(CONST char*, format));
207
208#undef  Tcl_Panic
209#define Tcl_Panic panic
210#endif
211
212/*
213 * A single structure of the type below is created and maintained for
214 * every interpreter. Beyond the table of registered transformers it
215 * contains version information about the interpreter used to switch
216 * runtime behaviour.
217 */
218
219typedef struct _Trf_Registry_ {
220  Tcl_HashTable* registry;        /* Table containing all registered
221				   * transformers. */
222#ifdef USE_TCL_STUBS
223  int            patchVariant;   /* Defined only for versions of Tcl
224				  * supporting stubs, and thus enable
225				  * the extension to switch its
226				  * runtime behaviour depending on the
227				  * version of the core loading
228				  * it. The possible values are
229				  * defined below. This information is
230				  * propagated into the state of
231				  * running transformers as well. */
232#endif
233} Trf_Registry;
234
235#ifdef USE_TCL_STUBS
236#define PATCH_ORIG (0) /* Patch as used in 8.0.x and 8.1.x */
237#define PATCH_82   (1) /* Patch as included into 8.2. Valid till 8.3.1 */
238#define PATCH_832  (2) /* Patch as rewritten for 8.3.2 and beyond */
239#endif
240
241
242/*
243 * A structure of the type below is created and maintained
244 * for every registered transformer (and every interpreter).
245 */
246
247typedef struct _Trf_RegistryEntry_ {
248  Trf_Registry*       registry;   /* Backpointer to the registry */
249
250  Trf_TypeDefinition* trfType;    /* reference to transformer specification */
251  Tcl_ChannelType*    transType;  /* reference to derived channel type
252				   * specification */
253  Tcl_Command         trfCommand; /* command associated to the transformer */
254  Tcl_Interp*         interp;     /* interpreter the command is registered
255				   * in. */
256} Trf_RegistryEntry;
257
258
259/*
260 * Procedures to access the registry of transformers for a specified
261 * interpreter. The registry is a hashtable mapping from transformer
262 * names to structures of type 'Trf_RegistryEntry' (see above).
263 */
264
265EXTERN Trf_Registry*
266TrfGetRegistry  _ANSI_ARGS_ ((Tcl_Interp* interp));
267
268EXTERN Trf_Registry*
269TrfPeekForRegistry _ANSI_ARGS_ ((Tcl_Interp* interp));
270
271EXTERN int
272Trf_Unregister _ANSI_ARGS_ ((Tcl_Interp*        interp,
273			     Trf_RegistryEntry* entry));
274
275
276/*
277 * Procedures used by 3->4 encoders (uu, base64).
278 */
279
280EXTERN void TrfSplit3to4 _ANSI_ARGS_ ((CONST unsigned char* in,
281				       unsigned char* out, int length));
282
283EXTERN void TrfMerge4to3 _ANSI_ARGS_ ((CONST unsigned char* in,
284				       unsigned char* out));
285
286EXTERN void TrfApplyEncoding   _ANSI_ARGS_ ((unsigned char* buf, int length,
287					     CONST char* map));
288
289EXTERN int  TrfReverseEncoding _ANSI_ARGS_ ((unsigned char* buf, int length,
290					     CONST char* reverseMap,
291					     unsigned int padChar,
292					     int* hasPadding));
293
294/*
295 * Definition of option information for message digests and accessor
296 * to set of vectors processing these.
297 */
298
299
300typedef struct _TrfMDOptionBlock {
301  int         behaviour; /* IMMEDIATE vs. ATTACH, got from checkProc */
302  int         mode;      /* what to to with the generated hashvalue */
303
304  char*       readDestination;	/* Name of channel (or global variable)
305				 * to write the hash of read data to
306				 * (mode = TRF_WRITE_HASH / ..TRANSPARENT) */
307  char*       writeDestination;	/* Name of channel (or global variable)
308				 * to write the hash of written data to
309				 * (mode = TRF_WRITE_HASH / ..TRANSPARENT) */
310
311  int        rdIsChannel; /* typeflag for 'readDestination',  true for a channel */
312  int        wdIsChannel; /* typeflag for 'writeDestination', true for a channel */
313
314  char*       matchFlag; /* Name of global variable to write the match-
315			  * result into (TRF_ABSORB_HASH) */
316
317  Tcl_Interp* vInterp;	/* Interpreter containing the variable named in
318			 * 'matchFlag', or '*Destination'. */
319
320  /* derived information */
321
322  Tcl_Channel rdChannel;  /* Channel associated to 'readDestination' */
323  Tcl_Channel wdChannel;  /* Channel associated to 'writeDestination' */
324} TrfMDOptionBlock;
325
326#define TRF_IMMEDIATE (1)
327#define TRF_ATTACH    (2)
328
329#define TRF_ABSORB_HASH (1)
330#define TRF_WRITE_HASH  (2)
331#define TRF_TRANSPARENT (3)
332
333EXTERN Trf_OptionVectors*
334TrfMDOptions _ANSI_ARGS_ ((void));
335
336
337
338
339
340/*
341 * Definition of option information for general transformation (reflect.c, ref_opt.c)
342 * to set of vectors processing these.
343 */
344
345typedef struct _TrfTransformOptionBlock {
346  int mode; /* operation to execute (transform for read or write) */
347
348#if (TCL_MAJOR_VERSION >= 8)
349  Tcl_Obj*       command; /* tcl code to execute for a buffer */
350#else
351  unsigned char* command; /* tcl code to execute for a buffer */
352#endif
353} TrfTransformOptionBlock;
354
355/*#define TRF_UNKNOWN_MODE (0) -- transform.h */
356#define TRF_WRITE_MODE (1)
357#define TRF_READ_MODE  (2)
358
359
360
361EXTERN Trf_OptionVectors*
362TrfTransformOptions _ANSI_ARGS_ ((void));
363
364
365/*
366 * Definition of option information for ZIP compressor
367 * + accessor to set of vectors processing them
368 */
369
370typedef struct _TrfZipOptionBlock {
371  int mode;   /* compressor mode: compress/decompress */
372  int level;  /* compression level (1..9, -1 = default) */
373  int nowrap; /* pkzip-compatibility (0..1, 0 = default) */
374} TrfZipOptionBlock;
375
376EXTERN Trf_OptionVectors*
377TrfZIPOptions _ANSI_ARGS_ ((void));
378
379/*
380 * Definition of option information for BZ2 compressor
381 * + accessor to set of vectors processing them
382 */
383
384typedef struct _TrfBz2OptionBlock {
385  int mode;   /* compressor mode: compress/decompress */
386  int level;  /* compression level (1..9, 9 = default) */
387} TrfBz2OptionBlock;
388
389EXTERN Trf_OptionVectors*
390TrfBZ2Options _ANSI_ARGS_ ((void));
391
392#define TRF_COMPRESS   (1)
393#define TRF_DECOMPRESS (2)
394
395#define TRF_MIN_LEVEL      (1)
396#define TRF_MAX_LEVEL      (9)
397#define TRF_DEFAULT_LEVEL (-1)
398
399#define TRF_MIN_LEVEL_STR "1"
400#define TRF_MAX_LEVEL_STR "9"
401
402#ifndef WINAPI
403#define WINAPI
404#endif
405
406#ifdef ZLIB_STATIC_BUILD
407#undef  ZEXPORT
408#define ZEXPORT
409#else
410#undef  ZEXPORT
411#define ZEXPORT WINAPI
412#endif
413#ifdef HAVE_zlibtcl_PACKAGE
414#undef  ZEXPORT
415#define ZEXPORT
416#endif
417
418/*
419 * 'zlib' will be dynamically loaded. Following a structure to
420 * contain the addresses of all functions required by this extension.
421 *
422 * Affected commands are: zip, adler, crc-zlib.
423 * They will fail, if the library could not be loaded.
424 */
425
426typedef struct ZFunctions {
427  VOID *handle;
428  int (ZEXPORT * zdeflate)           _ANSI_ARGS_ ((z_streamp strm, int flush));
429  int (ZEXPORT * zdeflateEnd)        _ANSI_ARGS_ ((z_streamp strm));
430
431  int (ZEXPORT * zdeflateInit2_)     _ANSI_ARGS_ ((z_streamp strm, int level,
432						  int method, int windowBits,
433						  int memLevel, int strategy,
434						  CONST char *version,
435						 int stream_size));
436  int (ZEXPORT * zdeflateReset)      _ANSI_ARGS_ ((z_streamp strm));
437  int (ZEXPORT * zinflate)           _ANSI_ARGS_ ((z_streamp strm, int flush));
438  int (ZEXPORT * zinflateEnd)        _ANSI_ARGS_ ((z_streamp strm));
439  int (ZEXPORT * zinflateInit2_)     _ANSI_ARGS_ ((z_streamp strm,
440						  int windowBits,
441						  CONST char *version,
442						  int stream_size));
443  int (ZEXPORT * zinflateReset)      _ANSI_ARGS_ ((z_streamp strm));
444  unsigned long (ZEXPORT * zadler32) _ANSI_ARGS_ ((unsigned long adler,
445						  CONST unsigned char *buf,
446						  unsigned int len));
447  unsigned long (ZEXPORT * zcrc32)   _ANSI_ARGS_ ((unsigned long crc,
448						  CONST unsigned char *buf,
449						  unsigned int len));
450} zFunctions;
451
452
453EXTERN zFunctions zf; /* THREADING: serialize initialization */
454
455EXTERN int
456TrfLoadZlib _ANSI_ARGS_ ((Tcl_Interp *interp));
457
458/*
459 * 'libbz2' will be dynamically loaded. Following a structure to
460 * contain the addresses of all functions required by this extension.
461 *
462 * Affected commands are: bzip.
463 * They will fail, if the library could not be loaded.
464 */
465
466#ifdef BZLIB_STATIC_BUILD
467#undef  BZEXPORT
468#define BZEXPORT
469#else
470#undef  BZEXPORT
471#define BZEXPORT WINAPI
472#endif
473
474typedef struct BZFunctions {
475  VOID *handle;
476  int (BZEXPORT * bcompress)           _ANSI_ARGS_ ((bz_stream* strm,
477						    int action));
478  int (BZEXPORT * bcompressEnd)        _ANSI_ARGS_ ((bz_stream* strm));
479  int (BZEXPORT * bcompressInit)       _ANSI_ARGS_ ((bz_stream* strm,
480						    int blockSize100k,
481						    int verbosity,
482						    int workFactor));
483  int (BZEXPORT * bdecompress)         _ANSI_ARGS_ ((bz_stream* strm));
484  int (BZEXPORT * bdecompressEnd)      _ANSI_ARGS_ ((bz_stream* strm));
485  int (BZEXPORT * bdecompressInit)     _ANSI_ARGS_ ((bz_stream* strm,
486						    int verbosity, int small));
487} bzFunctions;
488
489
490EXTERN bzFunctions bz; /* THREADING: serialize initialization */
491
492EXTERN int
493TrfLoadBZ2lib _ANSI_ARGS_ ((Tcl_Interp *interp));
494
495/*
496 * The following definitions have to be usable for 8.0.x, 8.1.x, 8.2.x,
497 * 8.3.[01], 8.3.2 and beyond. The differences between these versions:
498 *
499 * 8.0.x:      Trf usable only if core is patched, to check at compile time
500 *             (Check = Fails to compile, for now).
501 *
502 * 8.1:        Trf usable with unpatched core, but restricted, check at
503 *             compile time for missing definitions, check at runtime to
504 *             disable the missing features.
505 *
506 * 8.2.x:      Changed semantics for Tcl_StackChannel (Tcl_ReplaceChannel).
507 * 8.3.[01]:   Check at runtime to switch the behaviour. The patch is part
508 *             of the core from now on.
509 *
510 * 8.3.2+:     Stacked channels rewritten for better behaviour in some
511 *             situations (closing). Some new API's, semantic changes.
512 */
513
514#ifdef USE_TCL_STUBS
515#ifndef Tcl_StackChannel
516/* The core we are compiling against is not patched, so supply the
517 * necesssary definitions here by ourselves. The form chosen for
518 * the procedure macros (reservedXXX) will notify us if the core
519 * does not have these reserved locations anymore.
520 *
521 * !! Synchronize the procedure indices in their definitions with
522 *    the patch to tcl.decls, as they have to be the same.
523 */
524
525/* 281 */
526typedef Tcl_Channel (trf_StackChannel) _ANSI_ARGS_((Tcl_Interp* interp,
527						    Tcl_ChannelType* typePtr,
528						    ClientData instanceData,
529						    int mask,
530						    Tcl_Channel prevChan));
531/* 282 */
532typedef void (trf_UnstackChannel) _ANSI_ARGS_((Tcl_Interp* interp,
533					       Tcl_Channel chan));
534
535#define Tcl_StackChannel     ((trf_StackChannel*) tclStubsPtr->reserved281)
536#define Tcl_UnstackChannel ((trf_UnstackChannel*) tclStubsPtr->reserved282)
537
538#endif /* Tcl_StackChannel */
539
540
541#ifndef Tcl_GetStackedChannel
542/*
543 * Separate definition, available in 8.2, but not 8.1 and before !
544 */
545
546/* 283 */
547typedef Tcl_Channel (trf_GetStackedChannel) _ANSI_ARGS_((Tcl_Channel chan));
548
549#define Tcl_GetStackedChannel ((trf_GetStackedChannel*) tclStubsPtr->reserved283)
550
551#endif /* Tcl_GetStackedChannel */
552
553
554#ifndef Tcl_WriteRaw
555/* Core is older than 8.3.2., so supply the missing definitions for
556 * the new API's in 8.3.2.
557 */
558
559/* 394 */
560typedef int (trf_ReadRaw)  _ANSI_ARGS_((Tcl_Channel chan,
561					char*       dst,
562					int         bytesToRead));
563/* 395 */
564typedef int (trf_WriteRaw) _ANSI_ARGS_((Tcl_Channel chan,
565					char*       src,
566					int         srcLen));
567
568/* 396 */
569typedef int (trf_GetTopChannel) _ANSI_ARGS_((Tcl_Channel chan));
570
571/* 397 */
572typedef int (trf_ChannelBuffered) _ANSI_ARGS_((Tcl_Channel chan));
573
574/*
575 * Generating code for accessing these parts of the stub table when
576 * compiling against a core older than 8.3.2 is a hassle because even
577 * the 'reservedXXX' fields of the structure are not defined yet. So
578 * we have to write up some macros hiding some very hackish pointer
579 * arithmetics to get at these fields. We assume that pointer to
580 * functions are always of the same size.
581 */
582
583#define STUB_BASE   ((char*)(&(tclStubsPtr->tcl_UtfNcasecmp))) /* field 370 */
584#define procPtrSize (sizeof (Tcl_DriverBlockModeProc *))
585#define IDX(n)      (((n)-370) * procPtrSize)
586#define SLOT(n)     (STUB_BASE + IDX (n))
587
588#define Tcl_ReadRaw         (*((trf_ReadRaw**)         (SLOT (394))))
589#define Tcl_WriteRaw        (*((trf_WriteRaw**)        (SLOT (395))))
590#define Tcl_GetTopChannel   (*((trf_GetTopChannel**)   (SLOT (396))))
591#define Tcl_ChannelBuffered (*((trf_ChannelBuffered**) (SLOT (397))))
592
593/*
594#define Tcl_ReadRaw         ((trf_ReadRaw*)         tclStubsPtr->reserved394)
595#define Tcl_WriteRaw        ((trf_WriteRaw*)        tclStubsPtr->reserved395)
596#define Tcl_GetTopChannel   ((trf_GetTopChannel*)   tclStubsPtr->reserved396)
597#define Tcl_ChannelBuffered ((trf_ChannelBuffered*) tclStubsPtr->reserved397)
598*/
599
600/* Always required, easy emulation.
601 */
602#define Tcl_ChannelWatchProc(chanDriver)     ((chanDriver)->watchProc)
603#define Tcl_ChannelSetOptionProc(chanDriver) ((chanDriver)->setOptionProc)
604#define Tcl_ChannelGetOptionProc(chanDriver) ((chanDriver)->getOptionProc)
605#define Tcl_ChannelSeekProc(chanDriver)      ((chanDriver)->seekProc)
606
607#endif /* Tcl_WriteRaw */
608#endif /* USE_TCL_STUBS */
609
610
611/*
612 * Internal initialization procedures for all transformers implemented here.
613 */
614
615EXTERN int TrfInit_Bin       _ANSI_ARGS_ ((Tcl_Interp* interp));
616EXTERN int TrfInit_Oct       _ANSI_ARGS_ ((Tcl_Interp* interp));
617EXTERN int TrfInit_Hex       _ANSI_ARGS_ ((Tcl_Interp* interp));
618EXTERN int TrfInit_UU        _ANSI_ARGS_ ((Tcl_Interp* interp));
619EXTERN int TrfInit_B64       _ANSI_ARGS_ ((Tcl_Interp* interp));
620EXTERN int TrfInit_Ascii85   _ANSI_ARGS_ ((Tcl_Interp* interp));
621EXTERN int TrfInit_OTP_WORDS _ANSI_ARGS_ ((Tcl_Interp* interp));
622EXTERN int TrfInit_QP        _ANSI_ARGS_ ((Tcl_Interp* interp));
623
624EXTERN int TrfInit_CRC       _ANSI_ARGS_ ((Tcl_Interp* interp));
625EXTERN int TrfInit_MD5       _ANSI_ARGS_ ((Tcl_Interp* interp));
626EXTERN int TrfInit_MD2       _ANSI_ARGS_ ((Tcl_Interp* interp));
627EXTERN int TrfInit_HAVAL     _ANSI_ARGS_ ((Tcl_Interp* interp));
628EXTERN int TrfInit_SHA       _ANSI_ARGS_ ((Tcl_Interp* interp));
629EXTERN int TrfInit_SHA1      _ANSI_ARGS_ ((Tcl_Interp* interp));
630EXTERN int TrfInit_OTP_SHA1  _ANSI_ARGS_ ((Tcl_Interp* interp));
631EXTERN int TrfInit_ADLER     _ANSI_ARGS_ ((Tcl_Interp* interp));
632EXTERN int TrfInit_CRC_ZLIB  _ANSI_ARGS_ ((Tcl_Interp* interp));
633EXTERN int TrfInit_RIPEMD128 _ANSI_ARGS_ ((Tcl_Interp* interp));
634EXTERN int TrfInit_RIPEMD160 _ANSI_ARGS_ ((Tcl_Interp* interp));
635EXTERN int TrfInit_OTP_MD5   _ANSI_ARGS_ ((Tcl_Interp* interp));
636
637EXTERN int TrfInit_RS_ECC    _ANSI_ARGS_ ((Tcl_Interp* interp));
638EXTERN int TrfInit_ZIP       _ANSI_ARGS_ ((Tcl_Interp* interp));
639EXTERN int TrfInit_BZ2       _ANSI_ARGS_ ((Tcl_Interp* interp));
640
641EXTERN int TrfInit_Info      _ANSI_ARGS_ ((Tcl_Interp* interp));
642EXTERN int TrfInit_Unstack   _ANSI_ARGS_ ((Tcl_Interp* interp));
643EXTERN int TrfInit_Binio     _ANSI_ARGS_ ((Tcl_Interp* interp));
644
645EXTERN int TrfInit_Transform _ANSI_ARGS_ ((Tcl_Interp* interp));
646EXTERN int TrfInit_Crypt     _ANSI_ARGS_ ((Tcl_Interp* interp));
647
648
649
650/* Compile time distinctions between various versions of Tcl.
651 */
652
653/* Do we support locking ? Has to be a version of 8.1 or
654 * beyond with threading enabled.
655 */
656
657#if GT81 && defined (TCL_THREADS) /* THREADING: Lock procedures */
658
659EXTERN void TrfLockIt   _ANSI_ARGS_ ((void));
660EXTERN void TrfUnlockIt _ANSI_ARGS_ ((void));
661
662#define TrfLock   TrfLockIt ()
663#define TrfUnlock TrfUnlockIt ()
664#else
665/* Either older version of Tcl, or non-threaded 8.1.x.
666 * Whatever, locking is not required, undefine the calls.
667 */
668
669#define TrfLock
670#define TrfUnlock
671#endif
672
673/* Tcl 8.1 and beyond have better support for binary data. We have to
674 * use that to avoid mangling information going through the
675 * transformations.
676 */
677
678#if GT81
679#define GET_DATA(in,len) (unsigned char*) Tcl_GetByteArrayFromObj ((in), (len))
680#define NEW_DATA(r)      Tcl_NewByteArrayObj ((r).buf, (r).used);
681#else
682#define GET_DATA(in,len) (unsigned char*) Tcl_GetStringFromObj ((in), (len))
683#define NEW_DATA(r)      Tcl_NewStringObj ((char*) (r).buf, (r).used)
684#endif
685
686/* Map the names of some procedures from the stubs-variant to their
687 * pre-stubs names.
688 */
689
690#ifndef USE_TCL_STUBS
691#define Tcl_UnstackChannel Tcl_UndoReplaceChannel
692#define Tcl_StackChannel   Tcl_ReplaceChannel
693#endif
694
695/* Define the code to 'provide' this package to the loading interpreter.
696 */
697
698#if !(GT81)
699#define PROVIDE(interp,stubs) Tcl_PkgProvide ((interp), PACKAGE_NAME, PACKAGE_VERSION);
700#else
701#ifndef __WIN32__
702#define PROVIDE(interp,stubs) \
703    Tcl_PkgProvideEx ((interp), PACKAGE_NAME, PACKAGE_VERSION, (ClientData) &(stubs)); \
704    Trf_InitStubs    ((interp), PACKAGE_VERSION, 0);
705#else
706#define PROVIDE(interp,stubs) Tcl_PkgProvideEx ((interp), PACKAGE_NAME, PACKAGE_VERSION, (ClientData) &(stubs));
707#endif
708#endif
709
710
711#include "trfIntDecls.h"
712
713#undef TCL_STORAGE_CLASS
714#define TCL_STORAGE_CLASS DLLIMPORT
715
716#ifdef __cplusplus
717}
718#endif /* C++ */
719#endif /* TRF_INT_H */
720