1 /* $Id: tcl.c 6124 2003-01-14 06:03:29Z rra $
3 ** Support for TCL things
5 ** By Bob Heiney, Network Systems Laboratory, Digital Equipment Corporation
11 #include "inn/innconf.h"
16 Tcl_Interp *TCLInterpreter;
18 struct buffer *TCLCurrArticle;
21 static char *TCLSTARTUP = NULL;
22 static char *TCLFILTER = NULL;
29 TCLFilterActive=value;
31 syslog(L_NOTICE, "%s tcl filtering %s", LogName,
32 TCLFilterActive ? "enabled" : "disabled");
41 /* do before reload callback */
42 code = Tcl_Eval(TCLInterpreter, "filter_before_reload");
44 if (strcmp(TCLInterpreter->result,
45 "invalid command name: \"filter_before_reload\"")!=0)
46 syslog(L_ERROR, "%s Tcl filter_before_reload failed: %s",
47 LogName, TCLInterpreter->result);
50 /* read the filter file */
51 if (TCLFILTER == NULL)
52 TCLFILTER = concatpath(innconf->pathfilter, _PATH_TCL_FILTER);
53 code = Tcl_EvalFile(TCLInterpreter, TCLFILTER);
55 syslog(L_ERROR, "%s cant evaluate Tcl filter file: %s", LogName,
56 TCLInterpreter->result);
60 /* do the after callback, discarding any errors */
61 code = Tcl_Eval(TCLInterpreter, "filter_after_reload");
63 if (strcmp(TCLInterpreter->result,
64 "invalid command name: \"filter_after_reload\"")!=0)
65 syslog(L_ERROR, "%s Tcl filter_after_reload failed: %s",
66 LogName, TCLInterpreter->result);
73 * Compute a checksum. This function does a one's-complement addition
74 * of a series of 32-bit words. "buflen" is in bytes, not words. This is
75 * hard because the number of bits with which our machine can do arithmetic
76 * is the same as the size of the checksum being created, but our hardware
77 * is 2's-complement and C has no way to check for integer overflow.
79 * Note that the checksum is returned in network byte order and not host
80 * byte order; this makes it suitable for putting into packets and for
81 * comparing with what is found in packets.
85 makechecksum(u_char *sumbuf, int buflen)
87 u_char *buf = (u_char *)sumbuf;
90 uint32_t bwordl,bwordr,bword,suml,sumr;
98 rmdr = buflen - 4*len;
101 bwordr = (buf[3] & 0xFF)
102 + ((buf[2] & 0xFF) << 8);
103 bwordl = (buf[1] & 0xFF)
104 + ((buf[0] & 0xFF) << 8);
105 bword = ( bwordl << 16) | bwordr;
106 bword = ntohl(bword);
107 bwordl = (bword >> 16) & 0xFFFF;
108 bwordr = bword & 0xFFFF;
110 if (sumr & ~0xFFFF) {
115 if (suml & ~0xFFFF) {
121 /* if buffer size was not an even multiple of 4 bytes,
122 we have work to do */
124 tbuf[3] = 0; tbuf[2] = 0; tbuf[1] = 0;
125 /* tbuf[0] will always be copied into, and tbuf[3] will
126 * always be zero (else this would not be a remainder)
129 while (rmdr--) *ptbuf++ = *buf++;
130 bwordr = (tbuf[3] & 0xFF)
131 + ((tbuf[2] & 0xFF) << 8);
132 bwordl = (tbuf[1] & 0xFF)
133 + ((tbuf[0] & 0xFF) << 8);
134 bword = ( bwordl << 16) | bwordr;
135 bword = ntohl(bword);
136 bwordl = (bword >> 16) & 0xFFFF;
137 bwordr = bword & 0xFFFF;
139 if (sumr & ~0xFFFF) {
144 if (suml & ~0xFFFF) {
149 sum = htonl( (suml << 16) | sumr);
155 TCLCksumArt(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
159 snprintf(buf, sizeof(buf), "%08x",
160 makechecksum(TCLCurrArticle->data + TCLCurrData->Body,
162 Tcl_SetResult(interp, buf, TCL_VOLATILE);
172 TCLInterpreter = Tcl_CreateInterp();
173 if (TCLSTARTUP == NULL)
174 TCLSTARTUP = concatpath(innconf->pathfilter, _PATH_TCL_STARTUP);
175 code = Tcl_EvalFile(TCLInterpreter, TCLSTARTUP);
176 if (code != TCL_OK) {
177 syslog(L_FATAL, "%s cant read Tcl startup file: %s", LogName,
178 TCLInterpreter->result);
182 Tcl_CreateCommand(TCLInterpreter, "checksum_article", TCLCksumArt,
196 #endif /* defined(DO_TCL) */