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

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

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


Revision 1.5.2.2 - (show annotations) (download) (as text)
Wed Jan 12 13:54:00 2011 UTC (8 years, 10 months ago) by pseudo
Branch: gettext
Changes since 1.5.2.1: +2 -2 lines
File MIME type: text/x-chdr
Removed memcpy(), memset() and strftime() compatibility replacements.

1 /*
2 * tclmisc.c -- handles:
3 * Tcl stubs for everything else
4 *
5 * $Id: tclmisc.c,v 1.5.2.1 2010/11/10 13:39:19 pseudo Exp $
6 */
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 extern int max_logs, cache_hit, cache_miss;
56 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, 4, " minutes command ?count?");
260
261 if (atoi(argv[1]) < 0) {
262 Tcl_AppendResult(irp, "time value must be positive", NULL);
263 return TCL_ERROR;
264 }
265 if (argc == 4 && atoi(argv[3]) < 0) {
266 Tcl_AppendResult(irp, "count value must be >= 0", NULL);
267 return TCL_ERROR;
268 }
269 if (argv[2][0] != '#') {
270 x = add_timer(&timer, atoi(argv[1]), (argc == 4 ? atoi(argv[3]) : 1),
271 argv[2], 0L);
272 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 BADARGS(3, 4, " seconds command ?count?");
284
285 if (atoi(argv[1]) < 0) {
286 Tcl_AppendResult(irp, "time value must be positive", NULL);
287 return TCL_ERROR;
288 }
289 if (argc == 4 && atoi(argv[3]) < 0) {
290 Tcl_AppendResult(irp, "count value must be >= 0", NULL);
291 return TCL_ERROR;
292 }
293 if (argv[2][0] != '#') {
294 x = add_timer(&utimer, atoi(argv[1]), (argc == 4 ? atoi(argv[3]) : 1),
295 argv[2], 0L);
296 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 (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 getdccaddr(NULL, s, sizeof s);
448 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, "Already loaded.") && !strcmp(argv[0], "loadmodule"))
557 putlog(LOG_MISC, "*", _("Can't load modules %s: %s"), 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 case 'a':
667 flags |= STRIP_ANSI;
668 break;
669 case 'b':
670 flags |= STRIP_BOLD;
671 break;
672 case 'c':
673 flags |= STRIP_COLOR;
674 break;
675 case 'g':
676 flags |= STRIP_BELLS;
677 break;
678 case 'r':
679 flags |= STRIP_REV;
680 break;
681 case 'u':
682 flags |= STRIP_UNDER;
683 break;
684 default:
685 Tcl_AppendResult(irp, "Invalid strip-flags: ", argv[1], NULL);
686 return TCL_ERROR;
687 }
688
689 strip_mirc_codes(flags, argv[2]);
690 Tcl_AppendResult(irp, argv[2], NULL);
691 return TCL_OK;
692 }
693
694 #ifdef USE_TCL_OBJ
695 static int tcl_md5(cd, irp, objc, objv)
696 ClientData cd;
697 Tcl_Interp *irp;
698 int objc;
699 Tcl_Obj *CONST objv[];
700 {
701 #else
702 static int tcl_md5 STDVAR
703 {
704 #endif /* USE_TCL_OBJ */
705 MD5_CTX md5context;
706 char digest_string[33], *string;
707 unsigned char digest[16];
708 int i, len;
709
710 #ifdef USE_TCL_OBJ
711 if (objc != 2) {
712 Tcl_WrongNumArgs(irp, 1, objv, "string");
713 return TCL_ERROR;
714 }
715 # ifdef USE_TCL_BYTE_ARRAYS
716 string = (char *)Tcl_GetByteArrayFromObj(objv[1], &len);
717 # else
718 string = Tcl_GetStringFromObj(objv[1], &len);
719 # endif /* USE_TCL_BYTE_ARRAYS */
720 #else /* USE_TCL_OBJ */
721 BADARGS(2, 2, " string");
722
723 string = argv[1];
724 len = strlen(argv[1]);
725 #endif /* USE_TCL_OBJ */
726
727 MD5_Init(&md5context);
728 MD5_Update(&md5context, (unsigned char *) string, len);
729 MD5_Final(digest, &md5context);
730 for (i = 0; i < 16; i++)
731 sprintf(digest_string + (i * 2), "%.2x", digest[i]);
732 Tcl_AppendResult(irp, digest_string, NULL);
733 return TCL_OK;
734 }
735
736 static int tcl_matchaddr STDVAR
737 {
738 BADARGS(3, 3, " mask address");
739
740 if (match_addr(argv[1], argv[2]))
741 Tcl_AppendResult(irp, "1", NULL);
742 else
743 Tcl_AppendResult(irp, "0", NULL);
744 return TCL_OK;
745 }
746
747 static int tcl_matchcidr STDVAR
748 {
749 BADARGS(4, 4, " block address prefix");
750
751 if (cidr_match(argv[1], argv[2], atoi(argv[3])))
752 Tcl_AppendResult(irp, "1", NULL);
753 else
754 Tcl_AppendResult(irp, "0", NULL);
755 return TCL_OK;
756 }
757
758 static int tcl_matchstr STDVAR
759 {
760 BADARGS(3, 3, " pattern string");
761
762 if (wild_match(argv[1], argv[2]))
763 Tcl_AppendResult(irp, "1", NULL);
764 else
765 Tcl_AppendResult(irp, "0", NULL);
766 return TCL_OK;
767 }
768
769 tcl_cmds tclmisc_objcmds[] = {
770 #ifdef USE_TCL_OBJ
771 {"md5", tcl_md5},
772 #endif /* USE_TCL_OBJ */
773 {NULL, NULL}
774 };
775
776 static int tcl_status STDVAR
777 {
778 char s[15];
779
780 BADARGS(1, 2, " ?type?");
781
782 if ((argc < 2) || !strcmp(argv[1], "cpu")) {
783 Tcl_AppendElement(irp, "cputime");
784 snprintf(s, sizeof s, "%f", getcputime());
785 Tcl_AppendElement(irp, s);
786 }
787 if ((argc < 2) || !strcmp(argv[1], "mem")) {
788 Tcl_AppendElement(irp, "expmem");
789 snprintf(s, sizeof s, "%d", expected_memory());
790 Tcl_AppendElement(irp, s);
791 }
792 if ((argc < 2) || !strcmp(argv[1], "ipv6")) {
793 Tcl_AppendElement(irp, "ipv6");
794 #ifdef IPV6
795 Tcl_AppendElement(irp, "enabled");
796 #else
797 Tcl_AppendElement(irp, "disabled");
798 #endif
799 }
800 if ((argc < 2) || !strcmp(argv[1], "tls")) {
801 Tcl_AppendElement(irp, "tls");
802 #ifdef TLS
803 Tcl_AppendElement(irp, SSLeay_version(SSLEAY_VERSION));
804 #else
805 Tcl_AppendElement(irp, "disabled");
806 #endif
807 }
808 if ((argc < 2) || !strcmp(argv[1], "cache")) {
809 Tcl_AppendElement(irp, "usercache");
810 snprintf(s, sizeof s, "%4.1f", 100.0 *
811 ((float) cache_hit) / ((float) (cache_hit + cache_miss)));
812 Tcl_AppendElement(irp, s);
813 }
814
815 return TCL_OK;
816 }
817
818 tcl_cmds tclmisc_cmds[] = {
819 {"logfile", tcl_logfile},
820 {"putlog", tcl_putlog},
821 {"putcmdlog", tcl_putcmdlog},
822 {"putxferlog", tcl_putxferlog},
823 {"putloglev", tcl_putloglev},
824 {"timer", tcl_timer},
825 {"utimer", tcl_utimer},
826 {"killtimer", tcl_killtimer},
827 {"killutimer", tcl_killutimer},
828 {"timers", tcl_timers},
829 {"utimers", tcl_utimers},
830 {"unixtime", tcl_unixtime},
831 {"strftime", tcl_strftime},
832 {"ctime", tcl_ctime},
833 {"myip", tcl_myip},
834 {"rand", tcl_rand},
835 {"sendnote", tcl_sendnote},
836 {"dumpfile", tcl_dumpfile},
837 {"dccdumpfile", tcl_dccdumpfile},
838 {"backup", tcl_backup},
839 {"exit", tcl_die},
840 {"die", tcl_die},
841 {"unames", tcl_unames},
842 {"unloadmodule", tcl_unloadmodule},
843 {"loadmodule", tcl_loadmodule},
844 {"checkmodule", tcl_loadmodule},
845 {"modules", tcl_modules},
846 {"loadhelp", tcl_loadhelp},
847 {"unloadhelp", tcl_unloadhelp},
848 {"reloadhelp", tcl_reloadhelp},
849 {"duration", tcl_duration},
850 #ifndef USE_TCL_OBJ
851 {"md5", tcl_md5},
852 #endif /* USE_TCL_OBJ */
853 {"binds", tcl_binds},
854 {"callevent", tcl_callevent},
855 {"stripcodes", tcl_stripcodes},
856 {"matchaddr", tcl_matchaddr},
857 {"matchcidr", tcl_matchcidr},
858 {"matchstr", tcl_matchstr},
859 {"status", tcl_status},
860 {NULL, NULL}
861 };

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23