/[cvs]/eggdrop1.8/src/tclmisc.c
ViewVC logotype

Annotation of /eggdrop1.8/src/tclmisc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (hide annotations) (download) (as text)
Tue Oct 19 14:20:56 2010 UTC (9 years ago) by pseudo
Branch: MAIN
Changes since 1.3: +9 -1 lines
File MIME type: text/x-chdr
Added few autoconf checks for ssl.
Added tls to tcl_status()

1 simple 1.1 /*
2     * tclmisc.c -- handles:
3     * Tcl stubs for everything else
4     *
5 pseudo 1.4 * $Id: tclmisc.c,v 1.3 2010/10/10 18:22:47 pseudo Exp $
6 simple 1.1 */
7     /*
8     * Copyright (C) 1997 Robey Pointer
9     * Copyright (C) 1999 - 2010 Eggheads Development Team
10     *
11     * This program is free software; you can redistribute it and/or
12     * modify it under the terms of the GNU General Public License
13     * as published by the Free Software Foundation; either version 2
14     * of the License, or (at your option) any later version.
15     *
16     * This program is distributed in the hope that it will be useful,
17     * but WITHOUT ANY WARRANTY; without even the implied warranty of
18     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19     * GNU General Public License for more details.
20     *
21     * You should have received a copy of the GNU General Public License
22     * along with this program; if not, write to the Free Software
23     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24     */
25    
26     #include "main.h"
27     #include "modules.h"
28     #include "tandem.h"
29     #include "md5/md5.h"
30    
31     #ifdef TIME_WITH_SYS_TIME
32     # include <sys/time.h>
33     # include <time.h>
34     #else
35     # ifdef HAVE_SYS_TIME_H
36     # include <sys/time.h>
37     # else
38     # include <time.h>
39     # endif
40     #endif
41    
42     #include <sys/stat.h>
43    
44     #ifdef HAVE_UNAME
45     # include <sys/utsname.h>
46     #endif
47    
48     extern p_tcl_bind_list bind_table_list;
49     extern tcl_timer_t *timer, *utimer;
50     extern struct dcc_t *dcc;
51     extern char botnetnick[], quit_msg[];
52     extern struct userrec *userlist;
53     extern time_t now;
54     extern module_entry *module_list;
55 pseudo 1.3 extern int max_logs, cache_hit, cache_miss;
56 simple 1.1 extern log_t *logs;
57     extern Tcl_Interp *interp;
58    
59     int expmem_tclmisc()
60     {
61     int i, tot = 0;
62    
63     for (i = 0; i < max_logs; i++) {
64     if (logs[i].filename != NULL) {
65     tot += strlen(logs[i].filename) + 1;
66     tot += strlen(logs[i].chname) + 1;
67     }
68     }
69    
70     return tot;
71     }
72    
73     /*
74     * Logging
75     */
76    
77     /* logfile [<modes> <channel> <filename>] */
78     static int tcl_logfile STDVAR
79     {
80     int i;
81     char s[151];
82    
83     BADARGS(1, 4, " ?logModes channel logFile?");
84    
85     if (argc == 1) {
86     /* They just want a list of the logfiles and modes */
87     for (i = 0; i < max_logs; i++)
88     if (logs[i].filename != NULL) {
89     snprintf(s, sizeof s, "%s %s %s", masktype(logs[i].mask),
90     logs[i].chname, logs[i].filename);
91     Tcl_AppendElement(interp, s);
92     }
93     return TCL_OK;
94     }
95    
96     BADARGS(4, 4, " ?logModes channel logFile?");
97    
98     if (*argv[1] && !*argv[2]) {
99     Tcl_AppendResult(interp,
100     "log modes set, but no channel specified", NULL);
101     return TCL_ERROR;
102     }
103     if (*argv[2] && !strchr(CHANMETA, *argv[2]) && strcmp(argv[2], "*")) {
104     Tcl_AppendResult(interp, "invalid channel prefix", NULL);
105     return TCL_ERROR;
106     }
107     if (*argv[2] && strchr(argv[2], ' ')) {
108     Tcl_AppendResult(interp, "channel names cannot contain spaces", NULL);
109     return TCL_ERROR;
110     }
111    
112     for (i = 0; i < max_logs; i++)
113     if ((logs[i].filename != NULL) && (!strcmp(logs[i].filename, argv[3]))) {
114     logs[i].flags &= ~LF_EXPIRING;
115     logs[i].mask = logmodes(argv[1]);
116     nfree(logs[i].chname);
117     logs[i].chname = NULL;
118     if (!logs[i].mask) {
119     /* ending logfile */
120     nfree(logs[i].filename);
121     logs[i].filename = NULL;
122     if (logs[i].f != NULL) {
123     fclose(logs[i].f);
124     logs[i].f = NULL;
125     }
126     logs[i].flags = 0;
127     } else {
128     logs[i].chname = nmalloc(strlen(argv[2]) + 1);
129     strcpy(logs[i].chname, argv[2]);
130     }
131     Tcl_AppendResult(interp, argv[3], NULL);
132     return TCL_OK;
133     }
134     /* Do not add logfiles without any flags to log ++rtc */
135     if (!logmodes(argv[1])) {
136     Tcl_AppendResult(interp, "can't remove \"", argv[3],
137     "\" from list: no such logfile", NULL);
138     return TCL_ERROR;
139     }
140     for (i = 0; i < max_logs; i++)
141     if (logs[i].filename == NULL) {
142     logs[i].flags = 0;
143     logs[i].mask = logmodes(argv[1]);
144     logs[i].filename = nmalloc(strlen(argv[3]) + 1);
145     strcpy(logs[i].filename, argv[3]);
146     logs[i].chname = nmalloc(strlen(argv[2]) + 1);
147     strcpy(logs[i].chname, argv[2]);
148     Tcl_AppendResult(interp, argv[3], NULL);
149     return TCL_OK;
150     }
151     Tcl_AppendResult(interp, "reached max # of logfiles", NULL);
152     return TCL_ERROR;
153     }
154    
155     static int tcl_putlog STDVAR
156     {
157     char logtext[501];
158    
159     BADARGS(2, 2, " text");
160    
161     strncpyz(logtext, argv[1], sizeof logtext);
162     putlog(LOG_MISC, "*", "%s", logtext);
163     return TCL_OK;
164     }
165    
166     static int tcl_putcmdlog STDVAR
167     {
168     char logtext[501];
169    
170     BADARGS(2, 2, " text");
171    
172     strncpyz(logtext, argv[1], sizeof logtext);
173     putlog(LOG_CMDS, "*", "%s", logtext);
174     return TCL_OK;
175     }
176    
177     static int tcl_putxferlog STDVAR
178     {
179     char logtext[501];
180    
181     BADARGS(2, 2, " text");
182    
183     strncpyz(logtext, argv[1], sizeof logtext);
184     putlog(LOG_FILES, "*", "%s", logtext);
185     return TCL_OK;
186     }
187    
188     static int tcl_putloglev STDVAR
189     {
190     int lev = 0;
191     char logtext[501];
192    
193     BADARGS(4, 4, " level(s) channel text");
194    
195     lev = logmodes(argv[1]);
196     if (!lev) {
197     Tcl_AppendResult(irp, "No valid log-level given", NULL);
198     return TCL_ERROR;
199     }
200     strncpyz(logtext, argv[3], sizeof logtext);
201    
202     putlog(lev, argv[2], "%s", logtext);
203     return TCL_OK;
204     }
205    
206     static int tcl_binds STDVAR
207     {
208     int matching = 0;
209     char *g, flg[100], hits[11];
210     EGG_CONST char *list[5];
211     tcl_bind_list_t *tl, *tl_kind;
212     tcl_bind_mask_t *tm;
213     tcl_cmd_t *tc;
214    
215     BADARGS(1, 2, " ?type/mask?");
216    
217     if (argv[1])
218     tl_kind = find_bind_table(argv[1]);
219     else
220     tl_kind = NULL;
221     if (!tl_kind && argv[1])
222     matching = 1;
223     for (tl = tl_kind ? tl_kind : bind_table_list; tl;
224     tl = tl_kind ? 0 : tl->next) {
225     if (tl->flags & HT_DELETED)
226     continue;
227     for (tm = tl->first; tm; tm = tm->next) {
228     if (tm->flags & TBM_DELETED)
229     continue;
230     for (tc = tm->first; tc; tc = tc->next) {
231     if (tc->attributes & TC_DELETED)
232     continue;
233     if (matching &&
234     !wild_match_per(argv[1], tl->name) &&
235     !wild_match_per(argv[1], tm->mask) &&
236     !wild_match_per(argv[1], tc->func_name))
237     continue;
238     build_flags(flg, &(tc->flags), NULL);
239     egg_snprintf(hits, sizeof hits, "%i", (int) tc->hits);
240     list[0] = tl->name;
241     list[1] = flg;
242     list[2] = tm->mask;
243     list[3] = hits;
244     list[4] = tc->func_name;
245     g = Tcl_Merge(5, list);
246     Tcl_AppendElement(irp, g);
247     Tcl_Free((char *) g);
248     }
249     }
250     }
251     return TCL_OK;
252     }
253    
254     static int tcl_timer STDVAR
255     {
256     unsigned long x;
257     char s[16];
258    
259     BADARGS(3, 3, " minutes command");
260    
261     if (atoi(argv[1]) < 0) {
262     Tcl_AppendResult(irp, "time value must be positive", NULL);
263     return TCL_ERROR;
264     }
265     if (argv[2][0] != '#') {
266     x = add_timer(&timer, atoi(argv[1]), argv[2], 0L);
267     egg_snprintf(s, sizeof s, "timer%lu", x);
268     Tcl_AppendResult(irp, s, NULL);
269     }
270     return TCL_OK;
271     }
272    
273     static int tcl_utimer STDVAR
274     {
275     unsigned long x;
276     char s[16];
277    
278     BADARGS(3, 3, " seconds command");
279    
280     if (atoi(argv[1]) < 0) {
281     Tcl_AppendResult(irp, "time value must be positive", NULL);
282     return TCL_ERROR;
283     }
284     if (argv[2][0] != '#') {
285     x = add_timer(&utimer, atoi(argv[1]), argv[2], 0L);
286     egg_snprintf(s, sizeof s, "timer%lu", x);
287     Tcl_AppendResult(irp, s, NULL);
288     }
289     return TCL_OK;
290     }
291    
292     static int tcl_killtimer STDVAR
293     {
294     BADARGS(2, 2, " timerID");
295    
296     if (strncmp(argv[1], "timer", 5)) {
297     Tcl_AppendResult(irp, "argument is not a timerID", NULL);
298     return TCL_ERROR;
299     }
300     if (remove_timer(&timer, atol(&argv[1][5])))
301     return TCL_OK;
302     Tcl_AppendResult(irp, "invalid timerID", NULL);
303     return TCL_ERROR;
304     }
305    
306     static int tcl_killutimer STDVAR
307     {
308     BADARGS(2, 2, " timerID");
309    
310     if (strncmp(argv[1], "timer", 5)) {
311     Tcl_AppendResult(irp, "argument is not a timerID", NULL);
312     return TCL_ERROR;
313     }
314     if (remove_timer(&utimer, atol(&argv[1][5])))
315     return TCL_OK;
316     Tcl_AppendResult(irp, "invalid timerID", NULL);
317     return TCL_ERROR;
318     }
319    
320     static int tcl_timers STDVAR
321     {
322     BADARGS(1, 1, "");
323    
324     list_timers(irp, timer);
325     return TCL_OK;
326     }
327    
328     static int tcl_utimers STDVAR
329     {
330     BADARGS(1, 1, "");
331    
332     list_timers(irp, utimer);
333     return TCL_OK;
334     }
335    
336     static int tcl_duration STDVAR
337     {
338     char s[70];
339     unsigned long sec, tmp;
340    
341     BADARGS(2, 2, " seconds");
342    
343     if (atol(argv[1]) <= 0) {
344     Tcl_AppendResult(irp, "0 seconds", NULL);
345     return TCL_OK;
346     }
347     sec = atol(argv[1]);
348    
349     s[0] = 0;
350     if (sec >= 31536000) {
351     tmp = (sec / 31536000);
352     sprintf(s, "%lu year%s ", tmp, (tmp == 1) ? "" : "s");
353     sec -= (tmp * 31536000);
354     }
355     if (sec >= 604800) {
356     tmp = (sec / 604800);
357     sprintf(&s[strlen(s)], "%lu week%s ", tmp, (tmp == 1) ? "" : "s");
358     sec -= (tmp * 604800);
359     }
360     if (sec >= 86400) {
361     tmp = (sec / 86400);
362     sprintf(&s[strlen(s)], "%lu day%s ", tmp, (tmp == 1) ? "" : "s");
363     sec -= (tmp * 86400);
364     }
365     if (sec >= 3600) {
366     tmp = (sec / 3600);
367     sprintf(&s[strlen(s)], "%lu hour%s ", tmp, (tmp == 1) ? "" : "s");
368     sec -= (tmp * 3600);
369     }
370     if (sec >= 60) {
371     tmp = (sec / 60);
372     sprintf(&s[strlen(s)], "%lu minute%s ", tmp, (tmp == 1) ? "" : "s");
373     sec -= (tmp * 60);
374     }
375     if (sec > 0) {
376     tmp = (sec);
377     sprintf(&s[strlen(s)], "%lu second%s", tmp, (tmp == 1) ? "" : "s");
378     }
379     if (strlen(s) > 0 && s[strlen(s) - 1] == ' ')
380     s[strlen(s) - 1] = 0;
381     Tcl_AppendResult(irp, s, NULL);
382     return TCL_OK;
383     }
384    
385     static int tcl_unixtime STDVAR
386     {
387     char s[11];
388     time_t now2 = time(NULL);
389    
390     BADARGS(1, 1, "");
391    
392     egg_snprintf(s, sizeof s, "%li", (long) now2);
393     Tcl_AppendResult(irp, s, NULL);
394     return TCL_OK;
395     }
396    
397     static int tcl_ctime STDVAR
398     {
399     time_t tt;
400     char s[25];
401    
402     BADARGS(2, 2, " unixtime");
403    
404     tt = (time_t) atol(argv[1]);
405     strncpyz(s, ctime(&tt), sizeof s);
406     Tcl_AppendResult(irp, s, NULL);
407     return TCL_OK;
408     }
409    
410     static int tcl_strftime STDVAR
411     {
412     char buf[512];
413     struct tm *tm1;
414     time_t t;
415    
416     BADARGS(2, 3, " format ?time?");
417    
418     if (argc == 3)
419     t = atol(argv[2]);
420     else
421     t = now;
422     tm1 = localtime(&t);
423     if (egg_strftime(buf, sizeof(buf) - 1, argv[1], tm1)) {
424     Tcl_AppendResult(irp, buf, NULL);
425     return TCL_OK;
426     }
427     Tcl_AppendResult(irp, " error with strftime", NULL);
428     return TCL_ERROR;
429     }
430    
431     static int tcl_myip STDVAR
432     {
433     char s[16];
434    
435     BADARGS(1, 1, "");
436    
437 pseudo 1.2 getdccaddr(NULL, s, sizeof s);
438 simple 1.1 Tcl_AppendResult(irp, s, NULL);
439     return TCL_OK;
440     }
441    
442     static int tcl_rand STDVAR
443     {
444     long i;
445     unsigned long x;
446     char s[11];
447    
448     BADARGS(2, 2, " limit");
449    
450     i = atol(argv[1]);
451    
452     if (i <= 0) {
453     Tcl_AppendResult(irp, "random limit must be greater than zero", NULL);
454     return TCL_ERROR;
455     } else if (i > RANDOM_MAX) {
456     Tcl_AppendResult(irp, "random limit must be less than ", RANDOM_MAX, NULL);
457     return TCL_ERROR;
458     }
459    
460     x = randint(i);
461    
462     egg_snprintf(s, sizeof s, "%lu", x);
463    
464     Tcl_AppendResult(irp, s, NULL);
465     return TCL_OK;
466     }
467    
468     static int tcl_sendnote STDVAR
469     {
470     char s[5], from[NOTENAMELEN + 1], to[NOTENAMELEN + 1], msg[451];
471    
472     BADARGS(4, 4, " from to message");
473    
474     strncpyz(from, argv[1], sizeof from);
475     strncpyz(to, argv[2], sizeof to);
476     strncpyz(msg, argv[3], sizeof msg);
477     egg_snprintf(s, sizeof s, "%d", add_note(to, from, msg, -1, 0));
478     Tcl_AppendResult(irp, s, NULL);
479     return TCL_OK;
480     }
481    
482     static int tcl_dumpfile STDVAR
483     {
484     char nick[NICKLEN];
485     struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
486    
487     BADARGS(3, 3, " nickname filename");
488    
489     strncpyz(nick, argv[1], sizeof nick);
490     get_user_flagrec(get_user_by_nick(nick), &fr, NULL);
491     showhelp(argv[1], argv[2], &fr, HELP_TEXT);
492     return TCL_OK;
493     }
494    
495     static int tcl_dccdumpfile STDVAR
496     {
497     int idx, i;
498     struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0 };
499    
500     BADARGS(3, 3, " idx filename");
501    
502     i = atoi(argv[1]);
503     idx = findidx(i);
504     if (idx < 0) {
505     Tcl_AppendResult(irp, "illegal idx", NULL);
506     return TCL_ERROR;
507     }
508     get_user_flagrec(get_user_by_handle(userlist, dcc[idx].nick), &fr, NULL);
509    
510     tellhelp(idx, argv[2], &fr, HELP_TEXT);
511     return TCL_OK;
512     }
513    
514     static int tcl_backup STDVAR
515     {
516     BADARGS(1, 1, "");
517    
518     call_hook(HOOK_BACKUP);
519     return TCL_OK;
520     }
521    
522     static int tcl_die STDVAR
523     {
524     char s[1024];
525    
526     BADARGS(1, 2, " ?reason?");
527    
528     if (argc == 2) {
529     egg_snprintf(s, sizeof s, "BOT SHUTDOWN (%s)", argv[1]);
530     strncpyz(quit_msg, argv[1], 1024);
531     } else {
532     strncpyz(s, "BOT SHUTDOWN (No reason)", sizeof s);
533     quit_msg[0] = 0;
534     }
535     kill_bot(s, quit_msg[0] ? quit_msg : "EXIT");
536     return TCL_OK;
537     }
538    
539     static int tcl_loadmodule STDVAR
540     {
541     const char *p;
542    
543     BADARGS(2, 2, " module-name");
544    
545     p = module_load(argv[1]);
546     if (p && strcmp(p, MOD_ALREADYLOAD) && !strcmp(argv[0], "loadmodule"))
547     putlog(LOG_MISC, "*", "%s %s: %s", MOD_CANTLOADMOD, argv[1], p);
548     Tcl_AppendResult(irp, p, NULL);
549     return TCL_OK;
550     }
551    
552     static int tcl_unloadmodule STDVAR
553     {
554     BADARGS(2, 2, " module-name");
555    
556     Tcl_AppendResult(irp, module_unload(argv[1], botnetnick), NULL);
557     return TCL_OK;
558     }
559    
560     static int tcl_unames STDVAR
561     {
562     char *unix_n, *vers_n;
563     #ifdef HAVE_UNAME
564     struct utsname un;
565    
566     if (uname(&un) < 0) {
567     #endif
568     unix_n = "*unknown*";
569     vers_n = "";
570     #ifdef HAVE_UNAME
571     } else {
572     unix_n = un.sysname;
573     vers_n = un.release;
574     }
575     #endif
576     Tcl_AppendResult(irp, unix_n, " ", vers_n, NULL);
577     return TCL_OK;
578     }
579    
580     static int tcl_modules STDVAR
581     {
582     int i;
583     char *p, s[24], s2[24];
584     EGG_CONST char *list[100], *list2[2];
585     dependancy *dep;
586     module_entry *current;
587    
588     BADARGS(1, 1, "");
589    
590     for (current = module_list; current; current = current->next) {
591     list[0] = current->name;
592     egg_snprintf(s, sizeof s, "%d.%d", current->major, current->minor);
593     list[1] = s;
594     i = 2;
595     for (dep = dependancy_list; dep && (i < 100); dep = dep->next) {
596     if (dep->needing == current) {
597     list2[0] = dep->needed->name;
598     egg_snprintf(s2, sizeof s2, "%d.%d", dep->major, dep->minor);
599     list2[1] = s2;
600     list[i] = Tcl_Merge(2, list2);
601     i++;
602     }
603     }
604     p = Tcl_Merge(i, list);
605     Tcl_AppendElement(irp, p);
606     Tcl_Free((char *) p);
607     while (i > 2) {
608     i--;
609     Tcl_Free((char *) list[i]);
610     }
611     }
612     return TCL_OK;
613     }
614    
615     static int tcl_loadhelp STDVAR
616     {
617     BADARGS(2, 2, " helpfile-name");
618    
619     add_help_reference(argv[1]);
620     return TCL_OK;
621     }
622    
623     static int tcl_unloadhelp STDVAR
624     {
625     BADARGS(2, 2, " helpfile-name");
626    
627     rem_help_reference(argv[1]);
628     return TCL_OK;
629     }
630    
631     static int tcl_reloadhelp STDVAR
632     {
633     BADARGS(1, 1, "");
634    
635     reload_help_data();
636     return TCL_OK;
637     }
638    
639     static int tcl_callevent STDVAR
640     {
641     BADARGS(2, 2, " event");
642    
643     check_tcl_event(argv[1]);
644     return TCL_OK;
645     }
646    
647     static int tcl_stripcodes STDVAR
648     {
649     int flags = 0;
650     char *p;
651    
652     BADARGS(3, 3, " strip-flags string");
653    
654     for (p = argv[1]; *p; p++)
655     switch (*p) {
656     case 'a':
657     flags |= STRIP_ANSI;
658     break;
659     case 'b':
660     flags |= STRIP_BOLD;
661     break;
662     case 'c':
663     flags |= STRIP_COLOR;
664     break;
665     case 'g':
666     flags |= STRIP_BELLS;
667     break;
668     case 'r':
669     flags |= STRIP_REV;
670     break;
671     case 'u':
672     flags |= STRIP_UNDER;
673     break;
674     default:
675     Tcl_AppendResult(irp, "Invalid strip-flags: ", argv[1], NULL);
676     return TCL_ERROR;
677     }
678    
679     strip_mirc_codes(flags, argv[2]);
680     Tcl_AppendResult(irp, argv[2], NULL);
681     return TCL_OK;
682     }
683    
684     #ifdef USE_TCL_OBJ
685     static int tcl_md5(cd, irp, objc, objv)
686     ClientData cd;
687     Tcl_Interp *irp;
688     int objc;
689     Tcl_Obj *CONST objv[];
690     {
691     #else
692     static int tcl_md5 STDVAR
693     {
694     #endif /* USE_TCL_OBJ */
695     MD5_CTX md5context;
696     char digest_string[33], *string;
697     unsigned char digest[16];
698     int i, len;
699    
700     #ifdef USE_TCL_OBJ
701     if (objc != 2) {
702     Tcl_WrongNumArgs(irp, 1, objv, "string");
703     return TCL_ERROR;
704     }
705     # ifdef USE_TCL_BYTE_ARRAYS
706     string = (char *)Tcl_GetByteArrayFromObj(objv[1], &len);
707     # else
708     string = Tcl_GetStringFromObj(objv[1], &len);
709     # endif /* USE_TCL_BYTE_ARRAYS */
710     #else /* USE_TCL_OBJ */
711     BADARGS(2, 2, " string");
712    
713     string = argv[1];
714     len = strlen(argv[1]);
715     #endif /* USE_TCL_OBJ */
716    
717     MD5_Init(&md5context);
718     MD5_Update(&md5context, (unsigned char *) string, len);
719     MD5_Final(digest, &md5context);
720     for (i = 0; i < 16; i++)
721     sprintf(digest_string + (i * 2), "%.2x", digest[i]);
722     Tcl_AppendResult(irp, digest_string, NULL);
723     return TCL_OK;
724     }
725    
726     static int tcl_matchaddr STDVAR
727     {
728     BADARGS(3, 3, " mask address");
729    
730     if (match_addr(argv[1], argv[2]))
731     Tcl_AppendResult(irp, "1", NULL);
732     else
733     Tcl_AppendResult(irp, "0", NULL);
734     return TCL_OK;
735     }
736    
737     static int tcl_matchcidr STDVAR
738     {
739     BADARGS(4, 4, " block address prefix");
740    
741     if (cidr_match(argv[1], argv[2], atoi(argv[3])))
742     Tcl_AppendResult(irp, "1", NULL);
743     else
744     Tcl_AppendResult(irp, "0", NULL);
745     return TCL_OK;
746     }
747    
748     static int tcl_matchstr STDVAR
749     {
750     BADARGS(3, 3, " pattern string");
751    
752     if (wild_match(argv[1], argv[2]))
753     Tcl_AppendResult(irp, "1", NULL);
754     else
755     Tcl_AppendResult(irp, "0", NULL);
756     return TCL_OK;
757     }
758    
759     tcl_cmds tclmisc_objcmds[] = {
760     #ifdef USE_TCL_OBJ
761     {"md5", tcl_md5},
762     #endif /* USE_TCL_OBJ */
763     {NULL, NULL}
764     };
765    
766 pseudo 1.3 static int tcl_status STDVAR
767     {
768     char s[15];
769    
770     BADARGS(1, 2, " ?type?");
771    
772     if ((argc < 2) || !strcmp(argv[1], "cpu")) {
773     Tcl_AppendElement(irp, "cputime");
774     snprintf(s, sizeof s, "%f", getcputime());
775     Tcl_AppendElement(irp, s);
776     }
777     if ((argc < 2) || !strcmp(argv[1], "mem")) {
778     Tcl_AppendElement(irp, "expmem");
779     snprintf(s, sizeof s, "%d", expected_memory());
780     Tcl_AppendElement(irp, s);
781     }
782     if ((argc < 2) || !strcmp(argv[1], "ipv6")) {
783     Tcl_AppendElement(irp, "ipv6");
784     #ifdef IPV6
785     Tcl_AppendElement(irp, "enabled");
786     #else
787     Tcl_AppendElement(irp, "disabled");
788     #endif
789     }
790 pseudo 1.4 if ((argc < 2) || !strcmp(argv[1], "tls")) {
791     Tcl_AppendElement(irp, "tls");
792     #ifdef TLS
793     Tcl_AppendElement(irp, SSLeay_version(SSLEAY_VERSION));
794     #else
795     Tcl_AppendElement(irp, "disabled");
796     #endif
797     }
798 pseudo 1.3 if ((argc < 2) || !strcmp(argv[1], "cache")) {
799     Tcl_AppendElement(irp, "usercache");
800     snprintf(s, sizeof s, "%4.1f", 100.0 *
801     ((float) cache_hit) / ((float) (cache_hit + cache_miss)));
802     Tcl_AppendElement(irp, s);
803     }
804    
805     return TCL_OK;
806     }
807    
808 simple 1.1 tcl_cmds tclmisc_cmds[] = {
809     {"logfile", tcl_logfile},
810     {"putlog", tcl_putlog},
811     {"putcmdlog", tcl_putcmdlog},
812     {"putxferlog", tcl_putxferlog},
813     {"putloglev", tcl_putloglev},
814     {"timer", tcl_timer},
815     {"utimer", tcl_utimer},
816     {"killtimer", tcl_killtimer},
817     {"killutimer", tcl_killutimer},
818     {"timers", tcl_timers},
819     {"utimers", tcl_utimers},
820     {"unixtime", tcl_unixtime},
821     {"strftime", tcl_strftime},
822     {"ctime", tcl_ctime},
823     {"myip", tcl_myip},
824     {"rand", tcl_rand},
825     {"sendnote", tcl_sendnote},
826     {"dumpfile", tcl_dumpfile},
827     {"dccdumpfile", tcl_dccdumpfile},
828     {"backup", tcl_backup},
829     {"exit", tcl_die},
830     {"die", tcl_die},
831     {"unames", tcl_unames},
832     {"unloadmodule", tcl_unloadmodule},
833     {"loadmodule", tcl_loadmodule},
834     {"checkmodule", tcl_loadmodule},
835     {"modules", tcl_modules},
836     {"loadhelp", tcl_loadhelp},
837     {"unloadhelp", tcl_unloadhelp},
838     {"reloadhelp", tcl_reloadhelp},
839     {"duration", tcl_duration},
840     #ifndef USE_TCL_OBJ
841     {"md5", tcl_md5},
842     #endif /* USE_TCL_OBJ */
843     {"binds", tcl_binds},
844     {"callevent", tcl_callevent},
845     {"stripcodes", tcl_stripcodes},
846     {"matchaddr", tcl_matchaddr},
847     {"matchcidr", tcl_matchcidr},
848     {"matchstr", tcl_matchstr},
849 pseudo 1.3 {"status", tcl_status},
850 simple 1.1 {NULL, NULL}
851     };

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23