/[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.10 - (hide annotations) (download) (as text)
Thu Oct 2 19:27:43 2014 UTC (4 years, 7 months ago) by thommey
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +5 -3 lines
File MIME type: text/x-chdr
Remove length limit of info line. Fix stripcodes modifying the Tcl object in-place. Only permanent owners can
delete owners.

1 simple 1.1 /*
2     * tclmisc.c -- handles:
3     * Tcl stubs for everything else
4     *
5 thommey 1.10 * $Id: tclmisc.c,v 1.9 2013/07/31 01:09:33 thommey 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 pseudo 1.5 BADARGS(3, 4, " minutes command ?count?");
260 simple 1.1
261     if (atoi(argv[1]) < 0) {
262     Tcl_AppendResult(irp, "time value must be positive", NULL);
263     return TCL_ERROR;
264     }
265 pseudo 1.5 if (argc == 4 && atoi(argv[3]) < 0) {
266     Tcl_AppendResult(irp, "count value must be >= 0", NULL);
267     return TCL_ERROR;
268     }
269 simple 1.1 if (argv[2][0] != '#') {
270 pseudo 1.5 x = add_timer(&timer, atoi(argv[1]), (argc == 4 ? atoi(argv[3]) : 1),
271     argv[2], 0L);
272 simple 1.1 egg_snprintf(s, sizeof s, "timer%lu", x);
273     Tcl_AppendResult(irp, s, NULL);
274     }
275     return TCL_OK;
276     }
277    
278     static int tcl_utimer STDVAR
279     {
280     unsigned long x;
281     char s[16];
282    
283 pseudo 1.5 BADARGS(3, 4, " seconds command ?count?");
284 simple 1.1
285     if (atoi(argv[1]) < 0) {
286     Tcl_AppendResult(irp, "time value must be positive", NULL);
287     return TCL_ERROR;
288     }
289 pseudo 1.5 if (argc == 4 && atoi(argv[3]) < 0) {
290     Tcl_AppendResult(irp, "count value must be >= 0", NULL);
291     return TCL_ERROR;
292     }
293 simple 1.1 if (argv[2][0] != '#') {
294 pseudo 1.5 x = add_timer(&utimer, atoi(argv[1]), (argc == 4 ? atoi(argv[3]) : 1),
295     argv[2], 0L);
296 simple 1.1 egg_snprintf(s, sizeof s, "timer%lu", x);
297     Tcl_AppendResult(irp, s, NULL);
298     }
299     return TCL_OK;
300     }
301    
302     static int tcl_killtimer STDVAR
303     {
304     BADARGS(2, 2, " timerID");
305    
306     if (strncmp(argv[1], "timer", 5)) {
307     Tcl_AppendResult(irp, "argument is not a timerID", NULL);
308     return TCL_ERROR;
309     }
310     if (remove_timer(&timer, atol(&argv[1][5])))
311     return TCL_OK;
312     Tcl_AppendResult(irp, "invalid timerID", NULL);
313     return TCL_ERROR;
314     }
315    
316     static int tcl_killutimer STDVAR
317     {
318     BADARGS(2, 2, " timerID");
319    
320     if (strncmp(argv[1], "timer", 5)) {
321     Tcl_AppendResult(irp, "argument is not a timerID", NULL);
322     return TCL_ERROR;
323     }
324     if (remove_timer(&utimer, atol(&argv[1][5])))
325     return TCL_OK;
326     Tcl_AppendResult(irp, "invalid timerID", NULL);
327     return TCL_ERROR;
328     }
329    
330     static int tcl_timers STDVAR
331     {
332     BADARGS(1, 1, "");
333    
334     list_timers(irp, timer);
335     return TCL_OK;
336     }
337    
338     static int tcl_utimers STDVAR
339     {
340     BADARGS(1, 1, "");
341    
342     list_timers(irp, utimer);
343     return TCL_OK;
344     }
345    
346     static int tcl_duration STDVAR
347     {
348     char s[70];
349     unsigned long sec, tmp;
350    
351     BADARGS(2, 2, " seconds");
352    
353     if (atol(argv[1]) <= 0) {
354     Tcl_AppendResult(irp, "0 seconds", NULL);
355     return TCL_OK;
356     }
357     sec = atol(argv[1]);
358    
359     s[0] = 0;
360     if (sec >= 31536000) {
361     tmp = (sec / 31536000);
362     sprintf(s, "%lu year%s ", tmp, (tmp == 1) ? "" : "s");
363     sec -= (tmp * 31536000);
364     }
365     if (sec >= 604800) {
366     tmp = (sec / 604800);
367     sprintf(&s[strlen(s)], "%lu week%s ", tmp, (tmp == 1) ? "" : "s");
368     sec -= (tmp * 604800);
369     }
370     if (sec >= 86400) {
371     tmp = (sec / 86400);
372     sprintf(&s[strlen(s)], "%lu day%s ", tmp, (tmp == 1) ? "" : "s");
373     sec -= (tmp * 86400);
374     }
375     if (sec >= 3600) {
376     tmp = (sec / 3600);
377     sprintf(&s[strlen(s)], "%lu hour%s ", tmp, (tmp == 1) ? "" : "s");
378     sec -= (tmp * 3600);
379     }
380     if (sec >= 60) {
381     tmp = (sec / 60);
382     sprintf(&s[strlen(s)], "%lu minute%s ", tmp, (tmp == 1) ? "" : "s");
383     sec -= (tmp * 60);
384     }
385     if (sec > 0) {
386     tmp = (sec);
387     sprintf(&s[strlen(s)], "%lu second%s", tmp, (tmp == 1) ? "" : "s");
388     }
389     if (strlen(s) > 0 && s[strlen(s) - 1] == ' ')
390     s[strlen(s) - 1] = 0;
391     Tcl_AppendResult(irp, s, NULL);
392     return TCL_OK;
393     }
394    
395     static int tcl_unixtime STDVAR
396     {
397     char s[11];
398     time_t now2 = time(NULL);
399    
400     BADARGS(1, 1, "");
401    
402     egg_snprintf(s, sizeof s, "%li", (long) now2);
403     Tcl_AppendResult(irp, s, NULL);
404     return TCL_OK;
405     }
406    
407     static int tcl_ctime STDVAR
408     {
409     time_t tt;
410     char s[25];
411    
412     BADARGS(2, 2, " unixtime");
413    
414     tt = (time_t) atol(argv[1]);
415     strncpyz(s, ctime(&tt), sizeof s);
416     Tcl_AppendResult(irp, s, NULL);
417     return TCL_OK;
418     }
419    
420     static int tcl_strftime STDVAR
421     {
422     char buf[512];
423     struct tm *tm1;
424     time_t t;
425    
426     BADARGS(2, 3, " format ?time?");
427    
428     if (argc == 3)
429     t = atol(argv[2]);
430     else
431     t = now;
432     tm1 = localtime(&t);
433     if (egg_strftime(buf, sizeof(buf) - 1, argv[1], tm1)) {
434     Tcl_AppendResult(irp, buf, NULL);
435     return TCL_OK;
436     }
437     Tcl_AppendResult(irp, " error with strftime", NULL);
438     return TCL_ERROR;
439     }
440    
441     static int tcl_myip STDVAR
442     {
443     char s[16];
444    
445     BADARGS(1, 1, "");
446    
447 pseudo 1.2 getdccaddr(NULL, s, sizeof s);
448 simple 1.1 Tcl_AppendResult(irp, s, NULL);
449     return TCL_OK;
450     }
451    
452     static int tcl_rand STDVAR
453     {
454     long i;
455     unsigned long x;
456     char s[11];
457    
458     BADARGS(2, 2, " limit");
459    
460     i = atol(argv[1]);
461    
462     if (i <= 0) {
463     Tcl_AppendResult(irp, "random limit must be greater than zero", NULL);
464     return TCL_ERROR;
465     } else if (i > RANDOM_MAX) {
466     Tcl_AppendResult(irp, "random limit must be less than ", RANDOM_MAX, NULL);
467     return TCL_ERROR;
468     }
469    
470     x = randint(i);
471    
472     egg_snprintf(s, sizeof s, "%lu", x);
473    
474     Tcl_AppendResult(irp, s, NULL);
475     return TCL_OK;
476     }
477    
478     static int tcl_sendnote STDVAR
479     {
480     char s[5], from[NOTENAMELEN + 1], to[NOTENAMELEN + 1], msg[451];
481    
482     BADARGS(4, 4, " from to message");
483    
484     strncpyz(from, argv[1], sizeof from);
485     strncpyz(to, argv[2], sizeof to);
486     strncpyz(msg, argv[3], sizeof msg);
487     egg_snprintf(s, sizeof s, "%d", add_note(to, from, msg, -1, 0));
488     Tcl_AppendResult(irp, s, NULL);
489     return TCL_OK;
490     }
491    
492     static int tcl_dumpfile STDVAR
493     {
494     char nick[NICKLEN];
495     struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
496    
497     BADARGS(3, 3, " nickname filename");
498    
499     strncpyz(nick, argv[1], sizeof nick);
500     get_user_flagrec(get_user_by_nick(nick), &fr, NULL);
501     showhelp(argv[1], argv[2], &fr, HELP_TEXT);
502     return TCL_OK;
503     }
504    
505     static int tcl_dccdumpfile STDVAR
506     {
507     int idx, i;
508     struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0 };
509    
510     BADARGS(3, 3, " idx filename");
511    
512     i = atoi(argv[1]);
513     idx = findidx(i);
514     if (idx < 0) {
515     Tcl_AppendResult(irp, "illegal idx", NULL);
516     return TCL_ERROR;
517     }
518     get_user_flagrec(get_user_by_handle(userlist, dcc[idx].nick), &fr, NULL);
519    
520     tellhelp(idx, argv[2], &fr, HELP_TEXT);
521     return TCL_OK;
522     }
523    
524     static int tcl_backup STDVAR
525     {
526     BADARGS(1, 1, "");
527    
528     call_hook(HOOK_BACKUP);
529     return TCL_OK;
530     }
531    
532     static int tcl_die STDVAR
533     {
534     char s[1024];
535    
536     BADARGS(1, 2, " ?reason?");
537    
538     if (argc == 2) {
539     egg_snprintf(s, sizeof s, "BOT SHUTDOWN (%s)", argv[1]);
540     strncpyz(quit_msg, argv[1], 1024);
541     } else {
542     strncpyz(s, "BOT SHUTDOWN (No reason)", sizeof s);
543     quit_msg[0] = 0;
544     }
545     kill_bot(s, quit_msg[0] ? quit_msg : "EXIT");
546     return TCL_OK;
547     }
548    
549     static int tcl_loadmodule STDVAR
550     {
551     const char *p;
552    
553     BADARGS(2, 2, " module-name");
554    
555     p = module_load(argv[1]);
556     if (p && strcmp(p, MOD_ALREADYLOAD) && !strcmp(argv[0], "loadmodule"))
557     putlog(LOG_MISC, "*", "%s %s: %s", MOD_CANTLOADMOD, argv[1], p);
558     Tcl_AppendResult(irp, p, NULL);
559     return TCL_OK;
560     }
561    
562     static int tcl_unloadmodule STDVAR
563     {
564     BADARGS(2, 2, " module-name");
565    
566     Tcl_AppendResult(irp, module_unload(argv[1], botnetnick), NULL);
567     return TCL_OK;
568     }
569    
570     static int tcl_unames STDVAR
571     {
572     char *unix_n, *vers_n;
573     #ifdef HAVE_UNAME
574     struct utsname un;
575    
576     if (uname(&un) < 0) {
577     #endif
578     unix_n = "*unknown*";
579     vers_n = "";
580     #ifdef HAVE_UNAME
581     } else {
582     unix_n = un.sysname;
583     vers_n = un.release;
584     }
585     #endif
586     Tcl_AppendResult(irp, unix_n, " ", vers_n, NULL);
587     return TCL_OK;
588     }
589    
590     static int tcl_modules STDVAR
591     {
592     int i;
593     char *p, s[24], s2[24];
594     EGG_CONST char *list[100], *list2[2];
595     dependancy *dep;
596     module_entry *current;
597    
598     BADARGS(1, 1, "");
599    
600     for (current = module_list; current; current = current->next) {
601     list[0] = current->name;
602     egg_snprintf(s, sizeof s, "%d.%d", current->major, current->minor);
603     list[1] = s;
604     i = 2;
605     for (dep = dependancy_list; dep && (i < 100); dep = dep->next) {
606     if (dep->needing == current) {
607     list2[0] = dep->needed->name;
608     egg_snprintf(s2, sizeof s2, "%d.%d", dep->major, dep->minor);
609     list2[1] = s2;
610     list[i] = Tcl_Merge(2, list2);
611     i++;
612     }
613     }
614     p = Tcl_Merge(i, list);
615     Tcl_AppendElement(irp, p);
616     Tcl_Free((char *) p);
617     while (i > 2) {
618     i--;
619     Tcl_Free((char *) list[i]);
620     }
621     }
622     return TCL_OK;
623     }
624    
625     static int tcl_loadhelp STDVAR
626     {
627     BADARGS(2, 2, " helpfile-name");
628    
629     add_help_reference(argv[1]);
630     return TCL_OK;
631     }
632    
633     static int tcl_unloadhelp STDVAR
634     {
635     BADARGS(2, 2, " helpfile-name");
636    
637     rem_help_reference(argv[1]);
638     return TCL_OK;
639     }
640    
641     static int tcl_reloadhelp STDVAR
642     {
643     BADARGS(1, 1, "");
644    
645     reload_help_data();
646     return TCL_OK;
647     }
648    
649     static int tcl_callevent STDVAR
650     {
651     BADARGS(2, 2, " event");
652    
653     check_tcl_event(argv[1]);
654     return TCL_OK;
655     }
656    
657     static int tcl_stripcodes STDVAR
658     {
659     int flags = 0;
660     char *p;
661    
662     BADARGS(3, 3, " strip-flags string");
663    
664     for (p = argv[1]; *p; p++)
665     switch (*p) {
666 thommey 1.8 case 'c':
667     flags |= STRIP_COLOR;
668 simple 1.1 break;
669     case 'b':
670     flags |= STRIP_BOLD;
671     break;
672 thommey 1.8 case 'r':
673     flags |= STRIP_REVERSE;
674 simple 1.1 break;
675 thommey 1.8 case 'u':
676     flags |= STRIP_UNDERLINE;
677 thommey 1.7 break;
678 thommey 1.8 case 'a':
679     flags |= STRIP_ANSI;
680 thommey 1.7 break;
681 simple 1.1 case 'g':
682     flags |= STRIP_BELLS;
683     break;
684 thommey 1.8 case 'o':
685     flags |= STRIP_ORDINARY;
686 simple 1.1 break;
687 thommey 1.8 case 'i':
688     flags |= STRIP_ITALICS;
689 thommey 1.6 break;
690     case '*':
691     flags |= STRIP_ALL;
692     break;
693 simple 1.1 default:
694     Tcl_AppendResult(irp, "Invalid strip-flags: ", argv[1], NULL);
695     return TCL_ERROR;
696     }
697    
698 thommey 1.10 p = Tcl_Alloc(strlen(argv[2]) + 1);
699     strcpy(p, argv[2]);
700     strip_mirc_codes(flags, p);
701     Tcl_SetResult(irp, p, TCL_DYNAMIC);
702 simple 1.1 return TCL_OK;
703     }
704    
705     static int tcl_md5(cd, irp, objc, objv)
706     ClientData cd;
707     Tcl_Interp *irp;
708     int objc;
709     Tcl_Obj *CONST objv[];
710     {
711     MD5_CTX md5context;
712     char digest_string[33], *string;
713     unsigned char digest[16];
714     int i, len;
715    
716     if (objc != 2) {
717     Tcl_WrongNumArgs(irp, 1, objv, "string");
718     return TCL_ERROR;
719     }
720     string = Tcl_GetStringFromObj(objv[1], &len);
721    
722     MD5_Init(&md5context);
723     MD5_Update(&md5context, (unsigned char *) string, len);
724     MD5_Final(digest, &md5context);
725     for (i = 0; i < 16; i++)
726     sprintf(digest_string + (i * 2), "%.2x", digest[i]);
727     Tcl_AppendResult(irp, digest_string, NULL);
728     return TCL_OK;
729     }
730    
731     static int tcl_matchaddr STDVAR
732     {
733     BADARGS(3, 3, " mask address");
734    
735     if (match_addr(argv[1], argv[2]))
736     Tcl_AppendResult(irp, "1", NULL);
737     else
738     Tcl_AppendResult(irp, "0", NULL);
739     return TCL_OK;
740     }
741    
742     static int tcl_matchcidr STDVAR
743     {
744     BADARGS(4, 4, " block address prefix");
745    
746     if (cidr_match(argv[1], argv[2], atoi(argv[3])))
747     Tcl_AppendResult(irp, "1", NULL);
748     else
749     Tcl_AppendResult(irp, "0", NULL);
750     return TCL_OK;
751     }
752    
753     static int tcl_matchstr STDVAR
754     {
755     BADARGS(3, 3, " pattern string");
756    
757     if (wild_match(argv[1], argv[2]))
758     Tcl_AppendResult(irp, "1", NULL);
759     else
760     Tcl_AppendResult(irp, "0", NULL);
761     return TCL_OK;
762     }
763    
764     tcl_cmds tclmisc_objcmds[] = {
765     {"md5", tcl_md5},
766     {NULL, NULL}
767     };
768    
769 pseudo 1.3 static int tcl_status STDVAR
770     {
771     char s[15];
772    
773     BADARGS(1, 2, " ?type?");
774    
775     if ((argc < 2) || !strcmp(argv[1], "cpu")) {
776     Tcl_AppendElement(irp, "cputime");
777     snprintf(s, sizeof s, "%f", getcputime());
778     Tcl_AppendElement(irp, s);
779     }
780     if ((argc < 2) || !strcmp(argv[1], "mem")) {
781     Tcl_AppendElement(irp, "expmem");
782     snprintf(s, sizeof s, "%d", expected_memory());
783     Tcl_AppendElement(irp, s);
784     }
785     if ((argc < 2) || !strcmp(argv[1], "ipv6")) {
786     Tcl_AppendElement(irp, "ipv6");
787     #ifdef IPV6
788     Tcl_AppendElement(irp, "enabled");
789     #else
790     Tcl_AppendElement(irp, "disabled");
791     #endif
792     }
793 pseudo 1.4 if ((argc < 2) || !strcmp(argv[1], "tls")) {
794     Tcl_AppendElement(irp, "tls");
795     #ifdef TLS
796     Tcl_AppendElement(irp, SSLeay_version(SSLEAY_VERSION));
797     #else
798     Tcl_AppendElement(irp, "disabled");
799     #endif
800     }
801 pseudo 1.3 if ((argc < 2) || !strcmp(argv[1], "cache")) {
802     Tcl_AppendElement(irp, "usercache");
803     snprintf(s, sizeof s, "%4.1f", 100.0 *
804     ((float) cache_hit) / ((float) (cache_hit + cache_miss)));
805     Tcl_AppendElement(irp, s);
806     }
807    
808     return TCL_OK;
809     }
810    
811 simple 1.1 tcl_cmds tclmisc_cmds[] = {
812     {"logfile", tcl_logfile},
813     {"putlog", tcl_putlog},
814     {"putcmdlog", tcl_putcmdlog},
815     {"putxferlog", tcl_putxferlog},
816     {"putloglev", tcl_putloglev},
817     {"timer", tcl_timer},
818     {"utimer", tcl_utimer},
819     {"killtimer", tcl_killtimer},
820     {"killutimer", tcl_killutimer},
821     {"timers", tcl_timers},
822     {"utimers", tcl_utimers},
823     {"unixtime", tcl_unixtime},
824     {"strftime", tcl_strftime},
825     {"ctime", tcl_ctime},
826     {"myip", tcl_myip},
827     {"rand", tcl_rand},
828     {"sendnote", tcl_sendnote},
829     {"dumpfile", tcl_dumpfile},
830     {"dccdumpfile", tcl_dccdumpfile},
831     {"backup", tcl_backup},
832     {"exit", tcl_die},
833     {"die", tcl_die},
834     {"unames", tcl_unames},
835     {"unloadmodule", tcl_unloadmodule},
836     {"loadmodule", tcl_loadmodule},
837     {"checkmodule", tcl_loadmodule},
838     {"modules", tcl_modules},
839     {"loadhelp", tcl_loadhelp},
840     {"unloadhelp", tcl_unloadhelp},
841     {"reloadhelp", tcl_reloadhelp},
842     {"duration", tcl_duration},
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