/[cvs]/eggdrop1.4/src/modules.c
ViewVC logotype

Contents of /eggdrop1.4/src/modules.c

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


Revision 1.1.1.1 - (show annotations) (download) (as text) (vendor branch)
Wed Jun 23 19:51:31 1999 UTC (22 years, 4 months ago) by segfault
Branch: eggdev
CVS Tags: start
Changes since 1.1: +0 -0 lines
File MIME type: text/x-chdr
Eggdrop 1.3.28 CVS Code

1 /*
2 * modules.c - support for code modules in eggdrop
3 * by Darrin Smith (beldin@light.iinet.net.au)
4 */
5 /*
6 * This file is part of the eggdrop source code
7 * copyright (c) 1997 Robey Pointer
8 * and is distributed according to the GNU general public license.
9 * For full details, read the top of 'main.c' or the file called
10 * COPYING that was distributed with this code.
11 */
12
13 #include "main.h"
14 #include "modules.h"
15 #include "tandem.h"
16 #ifndef STATIC
17 #ifdef HPUX_HACKS
18 #include <dl.h>
19 #else
20 #ifdef OSF1_HACKS
21 #include <loader.h>
22 #else
23 #if DLOPEN_1
24 char *dlerror();
25 void *dlopen(const char *, int);
26 int dlclose(void *);
27 void *dlsym(void *, char *);
28
29 #define DLFLAGS 1
30 #else
31 #include <dlfcn.h>
32 #ifndef RTLD_GLOBAL
33 #define RTLD_GLOBAL 0
34 #endif
35 #ifndef RTLD_NOW
36 #define RTLD_NOW 1
37 #endif
38 #ifdef RTLD_LAZY
39 #define DLFLAGS RTLD_LAZY|RTLD_GLOBAL
40 #else
41 #define DLFLAGS RTLD_NOW|RTLD_GLOBAL
42 #endif
43 #endif /* DLOPEN_1 */
44 #endif /* OSF1_HACKS */
45 #endif /* HPUX_HACKS */
46
47 #endif /* STATIC */
48 extern struct dcc_t *dcc;
49
50 #include "users.h"
51 int cmd_note();
52
53 /* from other areas */
54 extern Tcl_Interp *interp;
55 extern struct userrec *userlist, *lastuser;
56 extern char tempdir[], botnetnick[], botname[], natip[], hostname[];
57 extern char origbotname[], botuser[], admin[], userfile[], ver[], notify_new[];
58 extern char helpdir[], version[];
59 extern int reserved_port, noshare, dcc_total, egg_numver, use_silence;
60 extern int use_console_r, ignore_time, debug_output, gban_total, make_userfile;
61 extern int default_flags, require_p, max_dcc, share_greet, password_timeout;
62 extern int min_dcc_port, max_dcc_port; /* dw */
63 extern int do_restart;
64 extern time_t now, online_since;
65 extern struct chanset_t *chanset;
66 int cmd_die(), xtra_kill(), xtra_unpack(); /* wtf ??? */
67 static int module_rename(char *name, char *newname);
68
69 #ifndef STATIC
70 /* directory to look for modules */
71 char moddir[121] = "modules/";
72
73 #else
74 struct static_list {
75 struct static_list *next;
76 char *name;
77 char *(*func) ();
78 } *static_modules = NULL;
79
80 void check_static(char *name, char *(*func) ())
81 {
82 struct static_list *p = nmalloc(sizeof(struct static_list));
83
84 p->name = nmalloc(strlen(name) + 1);
85 strcpy(p->name, name);
86 p->func = func;
87 p->next = static_modules;
88 static_modules = p;
89 }
90
91 #endif
92
93 /* the null functions */
94 void null_func()
95 {
96 }
97
98 char *charp_func()
99 {
100 return NULL;
101 }
102 int minus_func()
103 {
104 return -1;
105 }
106
107 /* various hooks & things */
108 /* the REAL hooks, when these are called, a return of 0 indicates unhandled
109 * 1 is handled */
110 struct hook_entry *hook_list[REAL_HOOKS];
111
112 static void null_share(int idx, char *x)
113 {
114 if ((x[0] == 'u') && (x[1] == 'n')) {
115 putlog(LOG_BOTS, "*", "User file rejected by %s: %s",
116 dcc[idx].nick, x + 3);
117 dcc[idx].status &= ~STAT_OFFERED;
118 if (!(dcc[idx].status & STAT_GETTING)) {
119 dcc[idx].status &= ~STAT_SHARE;
120 }
121 } else if ((x[0] != 'v') && (x[0] != 'e'))
122 dprintf(idx, "s un Not sharing userfile.\n");
123 }
124
125 /* these are obscure ones that I hope to neaten eventually :/ */
126 void (*encrypt_pass) (char *, char *) = 0;
127 void (*shareout) () = null_func;
128 void (*sharein) (int, char *) = null_share;
129 void (*qserver) (int, char *, int) = null_func;
130 void (*add_mode) () = null_func;
131
132 module_entry *module_list;
133 dependancy *dependancy_list = NULL;
134
135 void mod_context(char *module, char *file, int line)
136 {
137 char x[100];
138
139 sprintf(x, "%s:%s", module, file);
140 x[30] = 0;
141 cx_ptr = ((cx_ptr + 1) & 15);
142 strcpy(cx_file[cx_ptr], x);
143 cx_line[cx_ptr] = line;
144 }
145
146 /* the horrible global lookup table for functions */
147 /* BUT it makes the whole thing *much* more portable than letting each
148 * OS screw up the symbols their own special way :/ */
149
150 Function global_table[] =
151 {
152 /* 0 - 3 */
153 (Function) mod_malloc,
154 (Function) mod_free,
155 (Function) mod_context,
156 (Function) module_rename,
157 /* 4 - 7 */
158 (Function) module_register,
159 (Function) module_find,
160 (Function) module_depend,
161 (Function) module_undepend,
162 /* 8 - 11 */
163 (Function) add_bind_table,
164 (Function) del_bind_table,
165 (Function) find_bind_table,
166 (Function) check_tcl_bind,
167 /* 12 - 15 */
168 (Function) add_builtins,
169 (Function) rem_builtins,
170 (Function) add_tcl_commands,
171 (Function) rem_tcl_commands,
172 /* 16 - 19 */
173 (Function) add_tcl_ints,
174 (Function) rem_tcl_ints,
175 (Function) add_tcl_strings,
176 (Function) rem_tcl_strings,
177 /* 20 - 23 */
178 (Function) base64_to_int,
179 (Function) int_to_base64,
180 (Function) int_to_base10,
181 (Function) simple_sprintf,
182 /* 24 - 27 */
183 (Function) botnet_send_zapf,
184 (Function) botnet_send_zapf_broad,
185 (Function) botnet_send_unlinked,
186 (Function) botnet_send_bye,
187 /* 28 - 31 */
188 (Function) botnet_send_chat,
189 (Function) botnet_send_filereject,
190 (Function) botnet_send_filesend,
191 (Function) botnet_send_filereq,
192 /* 32 - 35 */
193 (Function) botnet_send_join_idx,
194 (Function) botnet_send_part_idx,
195 (Function) updatebot,
196 (Function) nextbot,
197 /* 36 - 39 */
198 (Function) zapfbot,
199 (Function) n_free,
200 (Function) u_pass_match,
201 (Function) _user_malloc,
202 /* 40 - 43 */
203 (Function) get_user,
204 (Function) set_user,
205 (Function) add_entry_type,
206 (Function) del_entry_type,
207 /* 44 - 47 */
208 (Function) get_user_flagrec,
209 (Function) set_user_flagrec,
210 (Function) get_user_by_host,
211 (Function) get_user_by_handle,
212 /* 48 - 51 */
213 (Function) find_entry_type,
214 (Function) find_user_entry,
215 (Function) adduser,
216 (Function) deluser,
217 /* 52 - 55 */
218 (Function) addhost_by_handle,
219 (Function) delhost_by_handle,
220 (Function) readuserfile,
221 (Function) write_userfile,
222 /* 56 - 59 */
223 (Function) geticon,
224 (Function) clear_chanlist,
225 (Function) reaffirm_owners,
226 (Function) change_handle,
227 /* 60 - 63 */
228 (Function) write_user,
229 (Function) clear_userlist,
230 (Function) count_users,
231 (Function) sanity_check,
232 /* 64 - 67 */
233 (Function) break_down_flags,
234 (Function) build_flags,
235 (Function) flagrec_eq,
236 (Function) flagrec_ok,
237 /* 68 - 71 */
238 (Function) & shareout,
239 (Function) dprintf,
240 (Function) chatout,
241 (Function) chanout_but,
242 /* 72 - 75 */
243 (Function) check_validity,
244 (Function) list_delete,
245 (Function) list_append,
246 (Function) list_contains,
247 /* 76 - 79 */
248 (Function) answer,
249 (Function) getmyip,
250 (Function) neterror,
251 (Function) tputs,
252 /* 80 - 83 */
253 (Function) new_dcc,
254 (Function) lostdcc,
255 (Function) getsock,
256 (Function) killsock,
257 /* 84 - 87 */
258 (Function) open_listen,
259 (Function) open_telnet_dcc,
260 (Function) _get_data_ptr,
261 (Function) open_telnet,
262 /* 88 - 91 */
263 #ifdef HAVE_BZERO
264 (Function) null_func,
265 #else
266 (Function) bzero,
267 #endif
268 (Function) my_memcpy,
269 (Function) my_atoul,
270 (Function) my_strcpy,
271 /* 92 - 95 */
272 (Function) & dcc, /* struct dcc_t * */
273 (Function) & chanset, /* struct chanset_t * */
274 (Function) & userlist, /* struct userrec * */
275 (Function) & lastuser, /* struct userrec * */
276 /* 96 - 99 */
277 (Function) & global_bans, /* struct banrec * */
278 (Function) & global_ign, /* struct igrec * */
279 (Function) & password_timeout, /* int */
280 (Function) & share_greet, /* int */
281 /* 100 - 103 */
282 (Function) & max_dcc, /* int */
283 (Function) & require_p, /* int */
284 (Function) & use_silence, /* int */
285 (Function) & use_console_r, /* int */
286 /* 104 - 107 */
287 (Function) & ignore_time, /* int */
288 (Function) & reserved_port, /* int */
289 (Function) & debug_output, /* int */
290 (Function) & noshare, /* int */
291 /* 108 - 111 */
292 (Function) & gban_total, /* int */
293 (Function) & make_userfile, /* int */
294 (Function) & default_flags, /* int */
295 (Function) & dcc_total, /* int */
296 /* 112 - 115 */
297 (Function) tempdir, /* char * */
298 (Function) natip, /* char * */
299 (Function) hostname, /* char * */
300 (Function) origbotname, /* char * */
301 /* 116 - 119 */
302 (Function) botuser, /* char * */
303 (Function) admin, /* char * */
304 (Function) userfile, /* char * */
305 (Function) ver, /* char * */
306 /* 120 - 123 */
307 (Function) notify_new, /* char * */
308 (Function) helpdir, /* char * */
309 (Function) version, /* char * */
310 (Function) botnetnick, /* char * */
311 /* 124 - 127 */
312 (Function) & DCC_CHAT_PASS, /* struct dcc_table * */
313 (Function) & DCC_BOT, /* struct dcc_table * */
314 (Function) & DCC_LOST, /* struct dcc_table * */
315 (Function) & DCC_CHAT, /* struct dcc_table * */
316 /* 128 - 131 */
317 (Function) & interp, /* Tcl_Interp * */
318 (Function) & now, /* time_t */
319 (Function) findanyidx,
320 (Function) findchan,
321 /* 132 - 135 */
322 (Function) cmd_die,
323 (Function) days,
324 (Function) daysago,
325 (Function) daysdur,
326 /* 136 - 139 */
327 (Function) ismember,
328 (Function) newsplit,
329 (Function) splitnick,
330 (Function) splitc,
331 /* 140 - 143 */
332 (Function) addignore,
333 (Function) match_ignore,
334 (Function) delignore,
335 (Function) fatal,
336 /* 144 - 147 */
337 (Function) xtra_kill,
338 (Function) xtra_unpack,
339 (Function) movefile,
340 (Function) copyfile,
341 /* 148 - 151 */
342 (Function) do_tcl,
343 (Function) readtclprog,
344 (Function) get_language,
345 (Function) def_get,
346 /* 152 - 155 */
347 (Function) makepass,
348 (Function) _wild_match,
349 (Function) maskhost,
350 (Function) show_motd,
351 /* 156 - 159 */
352 (Function) tellhelp,
353 (Function) showhelp,
354 (Function) add_help_reference,
355 (Function) rem_help_reference,
356 /* 160 - 163 */
357 (Function) touch_laston,
358 (Function) & add_mode,
359 (Function) rmspace,
360 (Function) in_chain,
361 /* 164 - 167 */
362 (Function) add_note,
363 (Function) cmd_note,
364 (Function) detect_dcc_flood,
365 (Function) flush_lines,
366 /* 168 - 171 */
367 (Function) expected_memory,
368 (Function) tell_mem_status,
369 (Function) & do_restart,
370 (Function) check_tcl_filt,
371 /* 172 - 175 */
372 (Function) add_hook,
373 (Function) del_hook,
374 (Function) & H_dcc,
375 (Function) & H_filt,
376 /* 176 - 179 */
377 (Function) & H_chon,
378 (Function) & H_chof,
379 (Function) & H_load,
380 (Function) & H_unld,
381 /* 180 - 183 */
382 (Function) & H_chat,
383 (Function) & H_act,
384 (Function) & H_bcst,
385 (Function) & H_bot,
386 /* 184 - 187 */
387 (Function) & H_link,
388 (Function) & H_disc,
389 (Function) & H_away,
390 (Function) & H_nkch,
391 /* 188 - 191 */
392 (Function) & USERENTRY_BOTADDR,
393 (Function) & USERENTRY_BOTFL,
394 (Function) & USERENTRY_HOSTS,
395 (Function) & USERENTRY_PASS,
396 /* 192 - 195 */
397 (Function) & USERENTRY_XTRA,
398 (Function) 0,
399 (Function) & USERENTRY_INFO,
400 (Function) & USERENTRY_COMMENT,
401 /* 196 - 199 */
402 (Function) & USERENTRY_LASTON,
403 (Function) putlog,
404 (Function) botnet_send_chan,
405 (Function) list_type_kill,
406 /* 200 - 203 */
407 (Function) logmodes,
408 (Function) masktype,
409 (Function) stripmodes,
410 (Function) stripmasktype,
411 /* 204 - 207 */
412 (Function) sub_lang,
413 (Function) & online_since,
414 (Function) cmd_loadlanguage,
415 (Function) check_dcc_attrs,
416 /* 208 - 211 */
417 (Function) check_dcc_chanattrs,
418 (Function) add_tcl_coups,
419 (Function) rem_tcl_coups,
420 (Function) botname,
421 /* 212 - 215 */
422 (Function) remove_gunk,
423 (Function) check_tcl_chjn,
424 (Function) sanitycheck_dcc,
425 (Function) isowner, /* Daemus */
426 /* 216 - 219 */
427 (Function) & min_dcc_port, /* dw */
428 (Function) & max_dcc_port,
429 (Function) rfc_casecmp,
430 (Function) rfc_ncasecmp,
431 (Function) & H_event,
432 };
433
434 void init_modules(void)
435 {
436 int i;
437
438 context;
439 module_list = nmalloc(sizeof(module_entry));
440 module_list->name = nmalloc(8);
441 strcpy(module_list->name, "eggdrop");
442 module_list->major = (egg_numver) / 10000;
443 module_list->minor = ((egg_numver) / 100) % 100;
444 #ifndef STATIC
445 module_list->hand = NULL;
446 #endif
447 module_list->next = NULL;
448 module_list->funcs = NULL;
449 for (i = 0; i < REAL_HOOKS; i++)
450 hook_list[i] = NULL;
451 }
452
453 int expmem_modules(int y)
454 {
455 int c = 0;
456 int i;
457 module_entry *p = module_list;
458 dependancy *d = dependancy_list;
459
460 #ifdef STATIC
461 struct static_list *s;
462
463 #endif
464 Function *f;
465
466 context;
467 #ifdef STATIC
468 for (s = static_modules; s; s = s->next)
469 c += sizeof(struct static_list) + strlen(s->name) + 1;
470
471 #endif
472 for (i = 0; i < REAL_HOOKS; i++) {
473 struct hook_entry *q = hook_list[i];
474
475 while (q) {
476 c += sizeof(struct hook_entry);
477
478 q = q->next;
479 }
480 }
481 while (d) {
482 c += sizeof(dependancy);
483 d = d->next;
484 }
485 while (p) {
486 c += sizeof(module_entry);
487 c += strlen(p->name) + 1;
488 f = p->funcs;
489 if (f && f[MODCALL_EXPMEM] && !y)
490 c += (int) (f[MODCALL_EXPMEM] ());
491 p = p->next;
492 }
493 return c;
494 }
495
496 int module_register(char *name, Function * funcs,
497 int major, int minor)
498 {
499 module_entry *p = module_list;
500
501 context;
502 while (p) {
503 if (p->name && !strcasecmp(name, p->name)) {
504 p->major = major;
505 p->minor = minor;
506 p->funcs = funcs;
507 return 1;
508 }
509 p = p->next;
510 }
511 return 0;
512 }
513
514 const char *module_load(char *name)
515 {
516 module_entry *p;
517 char *e;
518 Function f;
519
520 #ifndef STATIC
521 char workbuf[1024];
522
523 #ifdef HPUX_HACKS
524 shl_t hand;
525
526 #else
527 #ifdef OSF1_HACKS
528 ldr_module_t hand;
529
530 #else
531 void *hand;
532
533 #endif
534 #endif
535 #else
536 struct static_list *sl;
537
538 #endif
539
540 context;
541 if (module_find(name, 0, 0) != NULL)
542 return MOD_ALREADYLOAD;
543 #ifndef STATIC
544 context;
545 if (moddir[0] != '/') {
546 if (getcwd(workbuf, 1024) == NULL)
547 return MOD_BADCWD;
548 sprintf(&(workbuf[strlen(workbuf)]), "/%s%s.so", moddir, name);
549 } else
550 sprintf(workbuf, "%s%s.so", moddir, name);
551 #ifdef HPUX_HACKS
552 hand = shl_load(workbuf, BIND_IMMEDIATE, 0L);
553 context;
554 if (!hand)
555 return "Can't load module.";
556 #else
557 #ifdef OSF1_HACKS
558 hand = (Tcl_PackageInitProc *) load(workbuf, LDR_NOFLAGS);
559 if (hand == LDR_NULL_MODULE)
560 return "Can't load module.";
561 #else
562 context;
563 hand = dlopen(workbuf, DLFLAGS);
564 if (!hand)
565 return dlerror();
566 #endif
567 #endif
568
569 sprintf(workbuf, "%s_start", name);
570 #ifdef HPUX_HACKS
571 context;
572 if (shl_findsym(&hand, workbuf, (short) TYPE_PROCEDURE, (void *) &f))
573 f = NULL;
574 #else
575 #ifdef OSF1_HACKS
576 f = ldr_lookup_package(hand, workbuf);
577 #else
578 f = dlsym(hand, workbuf);
579 #endif
580 #endif
581 if (f == NULL) { /* some OS's need the _ */
582 sprintf(workbuf, "_%s_start", name);
583 #ifdef HPUX_HACKS
584 if (shl_findsym(&hand, workbuf, (short) TYPE_PROCEDURE, (void *) &f))
585 f = NULL;
586 #else
587 #ifdef OSF1_HACKS
588 f = ldr_lookup_package(hand, workbuf);
589 #else
590 f = dlsym(hand, workbuf);
591 #endif
592 #endif
593 if (f == NULL) {
594 #ifdef HPUX_HACKS
595 shl_unload(hand);
596 #else
597 #ifdef OSF1_HACKS
598 #else
599 dlclose(hand);
600 #endif
601 #endif
602 return MOD_NOSTARTDEF;
603 }
604 }
605 #else
606 for (sl = static_modules; sl && strcasecmp(sl->name, name); sl = sl->next);
607 context;
608 if (!sl)
609 return "Unkown module.";
610 f = (Function) sl->func;
611 #endif
612 p = nmalloc(sizeof(module_entry));
613 if (p == NULL)
614 return "Malloc error";
615 p->name = nmalloc(strlen(name) + 1);
616 strcpy(p->name, name);
617 context;
618 p->major = 0;
619 p->minor = 0;
620 #ifndef STATIC
621 p->hand = hand;
622 #endif
623 p->funcs = 0;
624 p->next = module_list;
625 module_list = p;
626 e = (((char *(*)()) f) (global_table));
627 context;
628 if (e) {
629 module_list = module_list->next;
630 nfree(p->name);
631 nfree(p);
632 return e;
633 }
634 check_tcl_load(name);
635 putlog(LOG_MISC, "*", "%s %s", MOD_LOADED, name);
636 context;
637 return NULL;
638 }
639
640 char *module_unload(char *name, char *user)
641 {
642 module_entry *p = module_list, *o = NULL;
643 char *e;
644 Function *f;
645
646 context;
647 while (p) {
648 if ((p->name != NULL) && (!strcmp(name, p->name))) {
649 dependancy *d = dependancy_list;
650
651 while (d != NULL) {
652 if (d->needed == p) {
653 return MOD_NEEDED;
654 }
655 d = d->next;
656 }
657 f = p->funcs;
658 if (f && !f[MODCALL_CLOSE])
659 return MOD_NOCLOSEDEF;
660 if (f) {
661 check_tcl_unld(name);
662 e = (((char *(*)()) f[MODCALL_CLOSE]) (user));
663 if (e != NULL)
664 return e;
665 #ifndef STATIC
666 #ifdef HPUX_HACKS
667 shl_unload(p->hand);
668 #else
669 #ifdef OSF1_HACKS
670 #else
671 dlclose(p->hand);
672 #endif
673 #endif
674 #endif /* STATIC */
675 }
676 nfree(p->name);
677 if (o == NULL) {
678 module_list = p->next;
679 } else {
680 o->next = p->next;
681 }
682 nfree(p);
683 putlog(LOG_MISC, "*", "%s %s", MOD_UNLOADED, name);
684 return NULL;
685 }
686 o = p;
687 p = p->next;
688 }
689 return MOD_NOSUCH;
690 }
691
692 module_entry *module_find(char *name, int major, int minor)
693 {
694 module_entry *p = module_list;
695
696 while (p) {
697 if (p->name && !strcasecmp(name, p->name) &&
698 ((major == p->major) || (major == 0)) &&
699 (minor <= p->minor))
700 return p;
701 p = p->next;
702 }
703 return NULL;
704 }
705
706 static int module_rename(char *name, char *newname)
707 {
708 module_entry *p = module_list;
709
710 while (p) {
711 if (!strcasecmp(newname, p->name))
712 return 0;
713 p = p->next;
714 }
715 p = module_list;
716 while (p) {
717 if (p->name && !strcasecmp(name, p->name)) {
718 nfree(p->name);
719 p->name = nmalloc(strlen(newname) + 1);
720 strcpy(p->name, newname);
721 return 1;
722 }
723 p = p->next;
724 }
725 return 0;
726 }
727
728 Function *module_depend(char *name1, char *name2, int major, int minor)
729 {
730 module_entry *p = module_find(name2, major, minor);
731 module_entry *o = module_find(name1, 0, 0);
732 dependancy *d;
733
734 context;
735 if (!p) {
736 if (module_load(name2))
737 return 0;
738 p = module_find(name2, major, minor);
739 }
740 if (!p || !o)
741 return 0;
742 d = nmalloc(sizeof(dependancy));
743
744 d->needed = p;
745 d->needing = o;
746 d->next = dependancy_list;
747 d->major = major;
748 d->minor = minor;
749 dependancy_list = d;
750 context;
751 return p->funcs ? p->funcs : (Function *) 1;
752 }
753
754 int module_undepend(char *name1)
755 {
756 int ok = 0;
757 module_entry *p = module_find(name1, 0, 0);
758 dependancy *d = dependancy_list, *o = NULL;
759
760 context;
761 if (p == NULL)
762 return 0;
763 while (d != NULL) {
764 if (d->needing == p) {
765 if (o == NULL) {
766 dependancy_list = d->next;
767 } else {
768 o->next = d->next;
769 }
770 nfree(d);
771 if (o == NULL)
772 d = dependancy_list;
773 else
774 d = o->next;
775 ok++;
776 } else {
777 o = d;
778 d = d->next;
779 }
780 }
781 context;
782 return ok;
783 }
784
785 void *mod_malloc(int size, char *modname, char *filename, int line)
786 {
787 char x[100];
788
789 sprintf(x, "%s:%s", modname, filename);
790 x[19] = 0;
791 return n_malloc(size, x, line);
792 }
793
794 void mod_free(void *ptr, char *modname, char *filename, int line)
795 {
796 char x[100];
797
798 sprintf(x, "%s:%s", modname, filename);
799 x[19] = 0;
800 n_free(ptr, x, line);
801 }
802
803 /* hooks, various tables of functions to call on ceratin events */
804 void add_hook(int hook_num, void *func)
805 {
806 context;
807 if (hook_num < REAL_HOOKS) {
808 struct hook_entry *p;
809
810 for (p = hook_list[hook_num]; p; p = p->next)
811 if (p->func == func)
812 return; /* dont add it if it's already there */
813 p = nmalloc(sizeof(struct hook_entry));
814
815 p->next = hook_list[hook_num];
816 hook_list[hook_num] = p;
817 p->func = func;
818 } else
819 switch (hook_num) {
820 case HOOK_ENCRYPT_PASS:
821 encrypt_pass = func;
822 break;
823 case HOOK_SHAREOUT:
824 shareout = func;
825 break;
826 case HOOK_SHAREIN:
827 sharein = func;
828 break;
829 case HOOK_QSERV:
830 if (qserver == null_func)
831 qserver = func;
832 break;
833 case HOOK_ADD_MODE:
834 if (add_mode == null_func)
835 add_mode = func;
836 break;
837 }
838 }
839
840 void del_hook(int hook_num, void *func)
841 {
842 context;
843 if (hook_num < REAL_HOOKS) {
844 struct hook_entry *p = hook_list[hook_num], *o = NULL;
845
846 while (p) {
847 if (p->func == func) {
848 if (o == NULL)
849 hook_list[hook_num] = p->next;
850 else
851 o->next = p->next;
852 nfree(p);
853 break;
854 }
855 o = p;
856 p = p->next;
857 }
858 } else
859 switch (hook_num) {
860 case HOOK_ENCRYPT_PASS:
861 if (encrypt_pass == func)
862 encrypt_pass = null_func;
863 break;
864 case HOOK_SHAREOUT:
865 if (shareout == func)
866 shareout = null_func;
867 break;
868 case HOOK_SHAREIN:
869 if (sharein == func)
870 sharein = null_share;
871 break;
872 case HOOK_QSERV:
873 if (qserver == func)
874 qserver = null_func;
875 break;
876 case HOOK_ADD_MODE:
877 if (add_mode == func)
878 add_mode = null_func;
879 break;
880 }
881 }
882
883 int call_hook_cccc(int hooknum, char *a, char *b, char *c, char *d)
884 {
885 struct hook_entry *p;
886 int f = 0;
887
888 if (hooknum >= REAL_HOOKS)
889 return 0;
890 p = hook_list[hooknum];
891 context;
892 while ((p != NULL) && !f) {
893 f = p->func(a, b, c, d);
894 p = p->next;
895 }
896 return f;
897 }
898
899 void do_module_report(int idx, int details, char *which)
900 {
901 module_entry *p = module_list;
902
903 if (p && !which && details)
904 dprintf(idx, "MODULES LOADED:\n");
905 while (p) {
906 if (!which || !strcasecmp(which, p->name)) {
907 dependancy *d = dependancy_list;
908
909 if (details)
910 dprintf(idx, "Module: %s, v %d.%d\n", p->name ? p->name : "CORE",
911 p->major, p->minor);
912 if (details > 1) {
913 while (d != NULL) {
914 if (d->needing == p)
915 dprintf(idx, " requires: %s, v %d.%d\n", d->needed->name,
916 d->major, d->minor);
917 d = d->next;
918 }
919 }
920 if (p->funcs) {
921 Function f = p->funcs[MODCALL_REPORT];
922
923 if (f != NULL)
924 f(idx, details);
925 }
926 if (which)
927 return;
928 }
929 p = p->next;
930 }
931 if (which)
932 dprintf(idx, "No such module.\n");
933 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23