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

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

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


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

1 simple 1.1 /*
2     * modules.c -- handles:
3     * support for modules in eggdrop
4     *
5     * by Darrin Smith (beldin@light.iinet.net.au)
6     *
7 pseudo 1.3.2.3 * $Id: modules.c,v 1.3.2.2 2010/11/17 13:58:37 pseudo Exp $
8 simple 1.1 */
9     /*
10     * Copyright (C) 1997 Robey Pointer
11     * Copyright (C) 1999 - 2010 Eggheads Development Team
12     *
13     * This program is free software; you can redistribute it and/or
14     * modify it under the terms of the GNU General Public License
15     * as published by the Free Software Foundation; either version 2
16     * of the License, or (at your option) any later version.
17     *
18     * This program is distributed in the hope that it will be useful,
19     * but WITHOUT ANY WARRANTY; without even the implied warranty of
20     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21     * GNU General Public License for more details.
22     *
23     * You should have received a copy of the GNU General Public License
24     * along with this program; if not, write to the Free Software
25     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26     */
27    
28     #include <ctype.h>
29     #include "main.h"
30     #include "modules.h"
31     #include "tandem.h"
32     #include "md5/md5.h"
33     #include "users.h"
34    
35     #ifndef STATIC
36     # ifdef MOD_USE_SHL
37     # include <dl.h>
38     # endif
39     # ifdef MOD_USE_DYLD
40     # include <mach-o/dyld.h>
41     # define DYLDFLAGS NSLINKMODULE_OPTION_BINDNOW|NSLINKMODULE_OPTION_PRIVATE|NSLINKMODULE_OPTION_RETURN_ON_ERROR
42     # endif
43     # ifdef MOD_USE_RLD
44     # ifdef HAVE_MACH_O_RLD_H
45     # include <mach-o/rld.h>
46     # else
47     # ifdef HAVE_RLD_H
48     # indluce <rld.h>
49     # endif
50     # endif
51     # endif
52     # ifdef MOD_USE_LOADER
53     # include <loader.h>
54     # endif
55    
56     # ifdef MOD_USE_DL
57     # ifdef DLOPEN_1
58     char *dlerror();
59     void *dlopen(const char *, int);
60     int dlclose(void *);
61     void *dlsym(void *, char *);
62     # define DLFLAGS 1
63     # else /* DLOPEN_1 */
64     # include <dlfcn.h>
65    
66     # ifndef RTLD_GLOBAL
67     # define RTLD_GLOBAL 0
68     # endif
69     # ifndef RTLD_NOW
70     # define RTLD_NOW 1
71     # endif
72     # ifdef RTLD_LAZY
73     # define DLFLAGS RTLD_LAZY|RTLD_GLOBAL
74     # else
75     # define DLFLAGS RTLD_NOW|RTLD_GLOBAL
76     # endif
77     # endif /* DLOPEN_1 */
78     # endif /* MOD_USE_DL */
79     #endif /* !STATIC */
80    
81    
82    
83     extern struct dcc_t *dcc;
84     extern struct userrec *userlist, *lastuser;
85     extern struct chanset_t *chanset;
86    
87 pseudo 1.2 extern char tempdir[], botnetnick[], botname[], origbotname[], botuser[],
88     admin[], userfile[], ver[], notify_new[], helpdir[], version[],
89 pseudo 1.3 quit_msg[], log_ts[];
90 simple 1.1
91     extern int parties, noshare, dcc_total, egg_numver, userfile_perm, do_restart,
92     ignore_time, must_be_owner, raw_log, max_dcc, make_userfile,
93     default_flags, require_p, share_greet, use_invites, use_exempts,
94     password_timeout, force_expire, protect_readonly, reserved_port_min,
95     reserved_port_max, copy_to_tmp, quiet_reject;
96    
97 pseudo 1.2 #ifdef IPV6
98     extern int pref_af;
99     #endif
100    
101 pseudo 1.3 #ifdef TLS
102     extern int tls_vfyclients, tls_vfydcc, tls_vfybots;
103     #endif
104    
105 simple 1.1 extern party_t *party;
106     extern time_t now, online_since;
107     extern tand_t *tandbot;
108     extern Tcl_Interp *interp;
109     extern sock_list *socklist;
110    
111     int cmd_die();
112     int xtra_kill();
113     int xtra_unpack();
114     static int module_rename(char *name, char *newname);
115    
116     #ifndef STATIC
117     char moddir[121] = "modules/";
118     #endif
119    
120     #ifdef STATIC
121     struct static_list {
122     struct static_list *next;
123     char *name;
124     char *(*func) ();
125     } *static_modules = NULL;
126    
127     void check_static(char *name, char *(*func) ())
128     {
129     struct static_list *p = nmalloc(sizeof(struct static_list));
130    
131     p->name = nmalloc(strlen(name) + 1);
132     strcpy(p->name, name);
133     p->func = func;
134     p->next = static_modules;
135     static_modules = p;
136     }
137     #endif /* STATIC */
138    
139    
140     /* The null functions */
141     void null_func()
142     {
143     }
144    
145     char *charp_func()
146     {
147     return NULL;
148     }
149    
150     int minus_func()
151     {
152     return -1;
153     }
154    
155     int false_func()
156     {
157     return 0;
158     }
159    
160    
161     /* The REAL hooks. When these are called, a return of 0 indicates unhandled;
162     * 1 indicates handled. */
163     struct hook_entry *hook_list[REAL_HOOKS];
164    
165     static void null_share(int idx, char *x)
166     {
167     if ((x[0] == 'u') && (x[1] == 'n')) {
168 pseudo 1.3.2.1 putlog(LOG_BOTS, "*", _("User file rejected by %s: %s"), dcc[idx].nick, x + 3);
169 simple 1.1 dcc[idx].status &= ~STAT_OFFERED;
170     if (!(dcc[idx].status & STAT_GETTING)) {
171     dcc[idx].status &= ~STAT_SHARE;
172     }
173     } else if ((x[0] != 'v') && (x[0] != 'e')) {
174     dprintf(idx, "s un Not sharing userfile.\n");
175     }
176     }
177    
178     void (*encrypt_pass) (char *, char *) = 0;
179     char *(*encrypt_string) (char *, char *) = 0;
180     char *(*decrypt_string) (char *, char *) = 0;
181     void (*shareout) () = null_func;
182     void (*sharein) (int, char *) = null_share;
183     void (*qserver) (int, char *, int) = (void (*)(int, char *, int)) null_func;
184     void (*add_mode) () = null_func;
185     int (*match_noterej) (struct userrec *, char *) =
186     (int (*)(struct userrec *, char *)) false_func;
187     int (*rfc_casecmp) (const char *, const char *) = _rfc_casecmp;
188     int (*rfc_ncasecmp) (const char *, const char *, int) = _rfc_ncasecmp;
189     int (*rfc_toupper) (int) = _rfc_toupper;
190     int (*rfc_tolower) (int) = _rfc_tolower;
191 pseudo 1.2 void (*dns_hostbyip) (sockname_t *) = block_dns_hostbyip;
192 simple 1.1 void (*dns_ipbyhost) (char *) = block_dns_ipbyhost;
193    
194     module_entry *module_list;
195     dependancy *dependancy_list = NULL;
196    
197     /* The horrible global lookup table for functions
198     * BUT it makes the whole thing *much* more portable than letting each
199     * OS screw up the symbols their own special way :/
200     */
201     Function global_table[] = {
202     /* 0 - 3 */
203     (Function) mod_malloc,
204     (Function) mod_free,
205     #ifdef DEBUG_CONTEXT
206     (Function) eggContext,
207     #else
208     (Function) 0,
209     #endif
210     (Function) module_rename,
211     /* 4 - 7 */
212     (Function) module_register,
213     (Function) module_find,
214     (Function) module_depend,
215     (Function) module_undepend,
216     /* 8 - 11 */
217     (Function) add_bind_table,
218     (Function) del_bind_table,
219     (Function) find_bind_table,
220     (Function) check_tcl_bind,
221     /* 12 - 15 */
222     (Function) add_builtins,
223     (Function) rem_builtins,
224     (Function) add_tcl_commands,
225     (Function) rem_tcl_commands,
226     /* 16 - 19 */
227     (Function) add_tcl_ints,
228     (Function) rem_tcl_ints,
229     (Function) add_tcl_strings,
230     (Function) rem_tcl_strings,
231     /* 20 - 23 */
232     (Function) base64_to_int,
233     (Function) int_to_base64,
234     (Function) int_to_base10,
235     (Function) simple_sprintf,
236     /* 24 - 27 */
237     (Function) botnet_send_zapf,
238     (Function) botnet_send_zapf_broad,
239     (Function) botnet_send_unlinked,
240     (Function) botnet_send_bye,
241     /* 28 - 31 */
242     (Function) botnet_send_chat,
243     (Function) botnet_send_filereject,
244     (Function) botnet_send_filesend,
245     (Function) botnet_send_filereq,
246     /* 32 - 35 */
247     (Function) botnet_send_join_idx,
248     (Function) botnet_send_part_idx,
249     (Function) updatebot,
250     (Function) nextbot,
251     /* 36 - 39 */
252     (Function) zapfbot,
253     (Function) n_free,
254     (Function) u_pass_match,
255     (Function) _user_malloc,
256     /* 40 - 43 */
257     (Function) get_user,
258     (Function) set_user,
259     (Function) add_entry_type,
260     (Function) del_entry_type,
261     /* 44 - 47 */
262     (Function) get_user_flagrec,
263     (Function) set_user_flagrec,
264     (Function) get_user_by_host,
265     (Function) get_user_by_handle,
266     /* 48 - 51 */
267     (Function) find_entry_type,
268     (Function) find_user_entry,
269     (Function) adduser,
270     (Function) deluser,
271     /* 52 - 55 */
272     (Function) addhost_by_handle,
273     (Function) delhost_by_handle,
274     (Function) readuserfile,
275     (Function) write_userfile,
276     /* 56 - 59 */
277     (Function) geticon,
278     (Function) clear_chanlist,
279     (Function) reaffirm_owners,
280     (Function) change_handle,
281     /* 60 - 63 */
282     (Function) write_user,
283     (Function) clear_userlist,
284     (Function) count_users,
285     (Function) sanity_check,
286     /* 64 - 67 */
287     (Function) break_down_flags,
288     (Function) build_flags,
289     (Function) flagrec_eq,
290     (Function) flagrec_ok,
291     /* 68 - 71 */
292     (Function) & shareout,
293     (Function) dprintf,
294     (Function) chatout,
295     (Function) chanout_but,
296     /* 72 - 75 */
297     (Function) check_validity,
298     (Function) egg_list_delete,
299     (Function) egg_list_append,
300     (Function) egg_list_contains,
301     /* 76 - 79 */
302     (Function) answer,
303 pseudo 1.2 (Function) getvhost,
304 pseudo 1.3 #ifdef TLS
305     (Function) ssl_handshake,
306     #else
307     (Function) 0,
308     #endif
309 simple 1.1 (Function) tputs,
310     /* 80 - 83 */
311     (Function) new_dcc,
312     (Function) lostdcc,
313     (Function) getsock,
314     (Function) killsock,
315     /* 84 - 87 */
316     (Function) open_listen,
317 pseudo 1.2 (Function) getdccaddr,
318 simple 1.1 (Function) _get_data_ptr,
319     (Function) open_telnet,
320     /* 88 - 91 */
321     (Function) check_tcl_event,
322 pseudo 1.3.2.3 (Function) 0, /* egg_memcpy -- UNUSED! (pseudo) */
323 simple 1.1 (Function) my_atoul,
324     (Function) my_strcpy,
325     /* 92 - 95 */
326     (Function) & dcc, /* struct dcc_t * */
327     (Function) & chanset, /* struct chanset_t * */
328     (Function) & userlist, /* struct userrec * */
329     (Function) & lastuser, /* struct userrec * */
330     /* 96 - 99 */
331     (Function) & global_bans, /* struct banrec * */
332     (Function) & global_ign, /* struct igrec * */
333     (Function) & password_timeout, /* int */
334     (Function) & share_greet, /* int */
335     /* 100 - 103 */
336     (Function) & max_dcc, /* int */
337     (Function) & require_p, /* int */
338     (Function) & ignore_time, /* int */
339 pseudo 1.3 #ifdef TLS
340     (Function) dcc_fingerprint,
341     #else
342 simple 1.1 (Function) 0, /* was use_console_r <Wcc[02/02/03]> */
343 pseudo 1.3 #endif
344 simple 1.1 /* 104 - 107 */
345     (Function) & reserved_port_min,
346     (Function) & reserved_port_max,
347     (Function) & raw_log, /* int */
348     (Function) & noshare, /* int */
349     /* 108 - 111 */
350 pseudo 1.3 #ifdef TLS
351     (Function) & tls_vfybots, /* int */
352     #else
353 simple 1.1 (Function) 0, /* gban_total -- UNUSED! (Eule) */
354 pseudo 1.3 #endif
355 simple 1.1 (Function) & make_userfile, /* int */
356     (Function) & default_flags, /* int */
357     (Function) & dcc_total, /* int */
358     /* 112 - 115 */
359     (Function) tempdir, /* char * */
360 pseudo 1.3 #ifdef TLS
361     (Function) & tls_vfyclients, /* int */
362     (Function) & tls_vfydcc, /* int */
363     #else
364 pseudo 1.2 (Function) 0, /* was natip -- use getmyip() instead */
365     (Function) 0, /* was myip -- use getvhost() instead */
366 pseudo 1.3 #endif
367 simple 1.1 (Function) origbotname, /* char * */
368     /* 116 - 119 */
369     (Function) botuser, /* char * */
370     (Function) admin, /* char * */
371     (Function) userfile, /* char * */
372     (Function) ver, /* char * */
373     /* 120 - 123 */
374     (Function) notify_new, /* char * */
375     (Function) helpdir, /* char * */
376     (Function) version, /* char * */
377     (Function) botnetnick, /* char * */
378     /* 124 - 127 */
379     (Function) & DCC_CHAT_PASS, /* struct dcc_table * */
380     (Function) & DCC_BOT, /* struct dcc_table * */
381     (Function) & DCC_LOST, /* struct dcc_table * */
382     (Function) & DCC_CHAT, /* struct dcc_table * */
383     /* 128 - 131 */
384     (Function) & interp, /* Tcl_Interp * */
385     (Function) & now, /* time_t */
386     (Function) findanyidx,
387     (Function) findchan,
388     /* 132 - 135 */
389     (Function) cmd_die,
390     (Function) days,
391     (Function) daysago,
392     (Function) daysdur,
393     /* 136 - 139 */
394     (Function) ismember,
395     (Function) newsplit,
396     (Function) splitnick,
397     (Function) splitc,
398     /* 140 - 143 */
399     (Function) addignore,
400     (Function) match_ignore,
401     (Function) delignore,
402     (Function) fatal,
403     /* 144 - 147 */
404     (Function) xtra_kill,
405     (Function) xtra_unpack,
406     (Function) movefile,
407     (Function) copyfile,
408     /* 148 - 151 */
409     (Function) do_tcl,
410     (Function) readtclprog,
411 pseudo 1.3.2.2 (Function) 0, /* was get_language() */
412 simple 1.1 (Function) def_get,
413     /* 152 - 155 */
414     (Function) makepass,
415     (Function) _wild_match,
416     (Function) maskaddr,
417     (Function) show_motd,
418     /* 156 - 159 */
419     (Function) tellhelp,
420     (Function) showhelp,
421     (Function) add_help_reference,
422     (Function) rem_help_reference,
423     /* 160 - 163 */
424     (Function) touch_laston,
425     (Function) & add_mode, /* Function * */
426     (Function) rmspace,
427     (Function) in_chain,
428     /* 164 - 167 */
429     (Function) add_note,
430 pseudo 1.3.2.2 (Function) 0,
431 simple 1.1 (Function) detect_dcc_flood,
432     (Function) flush_lines,
433     /* 168 - 171 */
434     (Function) expected_memory,
435     (Function) tell_mem_status,
436     (Function) & do_restart, /* int */
437     (Function) check_tcl_filt,
438     /* 172 - 175 */
439     (Function) add_hook,
440     (Function) del_hook,
441     (Function) & H_dcc, /* p_tcl_bind_list * */
442     (Function) & H_filt, /* p_tcl_bind_list * */
443     /* 176 - 179 */
444     (Function) & H_chon, /* p_tcl_bind_list * */
445     (Function) & H_chof, /* p_tcl_bind_list * */
446     (Function) & H_load, /* p_tcl_bind_list * */
447     (Function) & H_unld, /* p_tcl_bind_list * */
448     /* 180 - 183 */
449     (Function) & H_chat, /* p_tcl_bind_list * */
450     (Function) & H_act, /* p_tcl_bind_list * */
451     (Function) & H_bcst, /* p_tcl_bind_list * */
452     (Function) & H_bot, /* p_tcl_bind_list * */
453     /* 184 - 187 */
454     (Function) & H_link, /* p_tcl_bind_list * */
455     (Function) & H_disc, /* p_tcl_bind_list * */
456     (Function) & H_away, /* p_tcl_bind_list * */
457     (Function) & H_nkch, /* p_tcl_bind_list * */
458     /* 188 - 191 */
459     (Function) & USERENTRY_BOTADDR, /* struct user_entry_type * */
460     (Function) & USERENTRY_BOTFL, /* struct user_entry_type * */
461     (Function) & USERENTRY_HOSTS, /* struct user_entry_type * */
462     (Function) & USERENTRY_PASS, /* struct user_entry_type * */
463     /* 192 - 195 */
464     (Function) & USERENTRY_XTRA, /* struct user_entry_type * */
465     (Function) user_del_chan,
466     (Function) & USERENTRY_INFO, /* struct user_entry_type * */
467     (Function) & USERENTRY_COMMENT, /* struct user_entry_type * */
468     /* 196 - 199 */
469     (Function) & USERENTRY_LASTON, /* struct user_entry_type * */
470     (Function) putlog,
471     (Function) botnet_send_chan,
472     (Function) list_type_kill,
473     /* 200 - 203 */
474     (Function) logmodes,
475     (Function) masktype,
476     (Function) stripmodes,
477     (Function) stripmasktype,
478     /* 204 - 207 */
479     (Function) sub_lang,
480     (Function) & online_since, /* time_t * */
481 pseudo 1.3.2.2 (Function) 0,
482 simple 1.1 (Function) check_dcc_attrs,
483     /* 208 - 211 */
484     (Function) check_dcc_chanattrs,
485     (Function) add_tcl_coups,
486     (Function) rem_tcl_coups,
487     (Function) botname,
488     /* 212 - 215 */
489     (Function) 0, /* remove_gunk() -- UNUSED! (drummer) */
490     (Function) check_tcl_chjn,
491     (Function) sanitycheck_dcc,
492     (Function) isowner,
493     /* 216 - 219 */
494     (Function) 0, /* min_dcc_port -- UNUSED! (guppy) */
495     (Function) 0, /* max_dcc_port -- UNUSED! (guppy) */
496     (Function) & rfc_casecmp, /* Function * */
497     (Function) & rfc_ncasecmp, /* Function * */
498     /* 220 - 223 */
499     (Function) & global_exempts, /* struct exemptrec * */
500     (Function) & global_invites, /* struct inviterec * */
501     (Function) 0, /* ginvite_total -- UNUSED! (Eule) */
502     (Function) 0, /* gexempt_total -- UNUSED! (Eule) */
503     /* 224 - 227 */
504     (Function) & H_event, /* p_tcl_bind_list * */
505     (Function) & use_exempts, /* int */
506     (Function) & use_invites, /* int */
507     (Function) & force_expire, /* int */
508     /* 228 - 231 */
509 pseudo 1.3.2.2 (Function) 0,
510 simple 1.1 (Function) _user_realloc,
511     (Function) mod_realloc,
512     (Function) xtra_set,
513     /* 232 - 235 */
514     #ifdef DEBUG_CONTEXT
515     (Function) eggContextNote,
516     #else
517     (Function) 0,
518     #endif
519     #ifdef DEBUG_ASSERT
520     (Function) eggAssert,
521     #else
522     (Function) 0,
523     #endif
524     (Function) allocsock,
525     (Function) call_hostbyip,
526     /* 236 - 239 */
527     (Function) call_ipbyhost,
528     (Function) iptostr,
529     (Function) & DCC_DNSWAIT, /* struct dcc_table * */
530     (Function) hostsanitycheck_dcc,
531     /* 240 - 243 */
532     (Function) dcc_dnsipbyhost,
533     (Function) dcc_dnshostbyip,
534     (Function) changeover_dcc,
535     (Function) make_rand_str,
536     /* 244 - 247 */
537     (Function) & protect_readonly, /* int */
538     (Function) findchan_by_dname,
539     (Function) removedcc,
540     (Function) & userfile_perm, /* int */
541     /* 248 - 251 */
542     (Function) sock_has_data,
543     (Function) bots_in_subtree,
544     (Function) users_in_subtree,
545     (Function) egg_inet_aton,
546     /* 252 - 255 */
547     (Function) egg_snprintf,
548     (Function) egg_vsnprintf,
549 pseudo 1.3.2.3 (Function) 0,
550 simple 1.1 (Function) egg_strcasecmp,
551     /* 256 - 259 */
552     (Function) egg_strncasecmp,
553     (Function) is_file,
554     (Function) & must_be_owner, /* int */
555     (Function) & tandbot, /* tand_t * */
556     /* 260 - 263 */
557     (Function) & party, /* party_t * */
558     (Function) open_address_listen,
559     (Function) str_escape,
560     (Function) strchr_unescape,
561     /* 264 - 267 */
562     (Function) str_unescape,
563     (Function) egg_strcatn,
564     (Function) clear_chanlist_member,
565     (Function) fixfrom,
566     /* 268 - 271 */
567     (Function) & socklist, /* sock_list * */
568     (Function) sockoptions,
569     (Function) flush_inbuf,
570     (Function) kill_bot,
571     /* 272 - 275 */
572     (Function) quit_msg, /* char * */
573     (Function) module_load,
574     (Function) module_unload,
575     (Function) & parties, /* int */
576     /* 276 - 279 */
577     (Function) tell_bottree,
578     (Function) MD5_Init,
579     (Function) MD5_Update,
580     (Function) MD5_Final,
581     /* 280 - 283 */
582     (Function) _wild_match_per,
583     (Function) killtransfer,
584     (Function) write_ignores,
585     (Function) & copy_to_tmp, /* int */
586     /* 284 - 287 */
587     (Function) & quiet_reject, /* int */
588     (Function) file_readable,
589 pseudo 1.2 (Function) setsockname,
590     (Function) open_telnet_raw,
591 simple 1.1 /* 288 - 291 */
592 pseudo 1.2 #ifdef IPV6
593     (Function) & pref_af, /* int */
594     #else
595 simple 1.1 (Function) 0, /* IPv6 leftovers: 288 */
596 pseudo 1.2 #endif
597 simple 1.1 (Function) strip_mirc_codes,
598     (Function) check_ansi,
599     (Function) oatoi,
600     /* 292 - 295 */
601     (Function) str_isdigit,
602     (Function) remove_crlf,
603     (Function) addr_match,
604     (Function) mask_match,
605     /* 296 - 299 */
606     (Function) check_conflags,
607     (Function) increase_socks_max,
608     (Function) log_ts
609     };
610    
611     void init_modules(void)
612     {
613     int i;
614    
615     module_list = nmalloc(sizeof(module_entry));
616     module_list->name = nmalloc(8);
617     strcpy(module_list->name, "eggdrop");
618     module_list->major = (egg_numver) / 10000;
619     module_list->minor = (egg_numver / 100) % 100;
620     #ifndef STATIC
621     module_list->hand = NULL;
622     #endif
623     module_list->next = NULL;
624     module_list->funcs = NULL;
625     for (i = 0; i < REAL_HOOKS; i++)
626     hook_list[i] = NULL;
627     }
628    
629     int expmem_modules(int y)
630     {
631     int c = 0, i;
632     module_entry *p;
633     dependancy *d;
634     struct hook_entry *q;
635     Function *f;
636     #ifdef STATIC
637     struct static_list *s;
638    
639     for (s = static_modules; s; s = s->next)
640     c += sizeof(struct static_list) + strlen(s->name) + 1;
641     #endif
642    
643     for (i = 0; i < REAL_HOOKS; i++)
644     for (q = hook_list[i]; q; q = q->next)
645     c += sizeof(struct hook_entry);
646    
647     for (d = dependancy_list; d; d = d->next)
648     c += sizeof(dependancy);
649    
650     for (p = module_list; p; p = p->next) {
651     c += sizeof(module_entry);
652     c += strlen(p->name) + 1;
653     f = p->funcs;
654     if (f && f[MODCALL_EXPMEM] && !y)
655     c += (int) (f[MODCALL_EXPMEM] ());
656     }
657     return c;
658     }
659    
660     int module_register(char *name, Function *funcs, int major, int minor)
661     {
662     module_entry *p;
663    
664     for (p = module_list; p && p->name; p = p->next) {
665     if (!egg_strcasecmp(name, p->name)) {
666     p->major = major;
667     p->minor = minor;
668     p->funcs = funcs;
669     return 1;
670     }
671     }
672    
673     return 0;
674     }
675    
676     const char *module_load(char *name)
677     {
678     module_entry *p;
679     char *e;
680     Function f;
681     #ifdef STATIC
682     struct static_list *sl;
683     #endif
684    
685     #ifndef STATIC
686     char workbuf[1024];
687     # ifdef MOD_USE_SHL
688     shl_t hand;
689     # endif
690     # ifdef MOD_USE_DYLD
691     NSObjectFileImage file;
692     NSObjectFileImageReturnCode ret;
693     NSModule hand;
694     NSSymbol sym;
695     # endif
696     # ifdef MOD_USE_RLD
697     long ret;
698     # endif
699     # ifdef MOD_USE_LOADER
700     ldr_module_t hand;
701     # endif
702     # ifdef MOD_USE_DL
703     void *hand;
704     # endif
705     #endif /* !STATIC */
706    
707     if (module_find(name, 0, 0) != NULL)
708 pseudo 1.3.2.1 return _("Already loaded.");
709 simple 1.1
710     #ifndef STATIC
711     if (moddir[0] != '/') {
712     if (getcwd(workbuf, 1024) == NULL)
713 pseudo 1.3.2.1 return _("Can't determine current directory.");
714 simple 1.1 sprintf(&(workbuf[strlen(workbuf)]), "/%s%s." EGG_MOD_EXT, moddir, name);
715     } else {
716     sprintf(workbuf, "%s%s." EGG_MOD_EXT, moddir, name);
717     }
718    
719     # ifdef MOD_USE_SHL
720     hand = shl_load(workbuf, BIND_IMMEDIATE, 0L);
721     if (!hand)
722 pseudo 1.3.2.1 return _("Can't load module.");
723 simple 1.1 sprintf(workbuf, "%s_start", name);
724     if (shl_findsym(&hand, workbuf, (short) TYPE_PROCEDURE, (void *) &f))
725     f = NULL;
726     if (f == NULL) {
727     /* Some OS's require a _ to be prepended to the symbol name (Darwin, etc). */
728     sprintf(workbuf, "_%s_start", name);
729     if (shl_findsym(&hand, workbuf, (short) TYPE_PROCEDURE, (void *) &f))
730     f = NULL;
731     }
732     if (f == NULL) {
733     shl_unload(hand);
734 pseudo 1.3.2.1 return _("No start function defined.");
735 simple 1.1 }
736     # endif /* MOD_USE_SHL */
737    
738     # ifdef MOD_USE_DYLD
739     ret = NSCreateObjectFileImageFromFile(workbuf, &file);
740     if (ret != NSObjectFileImageSuccess)
741 pseudo 1.3.2.1 return _("Can't load module.");
742 simple 1.1 hand = NSLinkModule(file, workbuf, DYLDFLAGS);
743     sprintf(workbuf, "_%s_start", name);
744     sym = NSLookupSymbolInModule(hand, workbuf);
745     if (sym)
746     f = (Function) NSAddressOfSymbol(sym);
747     else
748     f = NULL;
749     if (f == NULL) {
750     NSUnLinkModule(hand, NSUNLINKMODULE_OPTION_NONE);
751 pseudo 1.3.2.1 return _("No start function defined.");
752 simple 1.1 }
753     # endif /* MOD_USE_DYLD */
754    
755     # ifdef MOD_USE_RLD
756     ret = rld_load(NULL, (struct mach_header **) 0, workbuf, (const char *) 0);
757     if (!ret)
758 pseudo 1.3.2.1 return _("Can't load module.");
759 simple 1.1 sprintf(workbuf, "_%s_start", name);
760     ret = rld_lookup(NULL, workbuf, &f)
761     if (!ret || f == NULL)
762 pseudo 1.3.2.1 return _("No start function defined.");
763 simple 1.1 /* There isn't a reliable way to unload at this point... just keep it loaded. */
764     # endif /* MOD_USE_DYLD */
765    
766     # ifdef MOD_USE_LOADER
767     hand = load(workbuf, LDR_NOFLAGS);
768     if (hand == LDR_NULL_MODULE)
769 pseudo 1.3.2.1 return _("Can't load module.");
770 simple 1.1 sprintf(workbuf, "%s_start", name);
771     f = (Function) ldr_lookup_package(hand, workbuf);
772     if (f == NULL) {
773     sprintf(workbuf, "_%s_start", name);
774     f = (Function) ldr_lookup_package(hand, workbuf);
775     }
776     if (f == NULL) {
777     unload(hand);
778 pseudo 1.3.2.1 return _("No start function defined.");
779 simple 1.1 }
780     # endif /* MOD_USE_LOADER */
781    
782     # ifdef MOD_USE_DL
783     hand = dlopen(workbuf, DLFLAGS);
784     if (!hand)
785     return dlerror();
786     sprintf(workbuf, "%s_start", name);
787     f = (Function) dlsym(hand, workbuf);
788     if (f == NULL) {
789     sprintf(workbuf, "_%s_start", name);
790     f = (Function) dlsym(hand, workbuf);
791     }
792     if (f == NULL) {
793     dlclose(hand);
794 pseudo 1.3.2.1 return _("No start function defined.");
795 simple 1.1 }
796     # endif /* MOD_USE_DL */
797     #endif /* !STATIC */
798    
799     #ifdef STATIC
800     for (sl = static_modules; sl && egg_strcasecmp(sl->name, name); sl = sl->next);
801     if (!sl)
802 pseudo 1.3.2.1 return _("Unknown module.");
803 simple 1.1 f = (Function) sl->func;
804     #endif /* STATIC */
805    
806     p = nmalloc(sizeof(module_entry));
807     if (p == NULL)
808 pseudo 1.3.2.1 return _("Malloc error");
809 simple 1.1 p->name = nmalloc(strlen(name) + 1);
810     strcpy(p->name, name);
811     p->major = 0;
812     p->minor = 0;
813     #ifndef STATIC
814     p->hand = hand;
815     #endif
816     p->funcs = 0;
817     p->next = module_list;
818     module_list = p;
819     e = (((char *(*)()) f) (global_table));
820     if (e) {
821     module_list = module_list->next;
822     nfree(p->name);
823     nfree(p);
824     return e;
825     }
826     check_tcl_load(name);
827    
828 pseudo 1.3.2.2 if (0)
829 pseudo 1.3.2.1 putlog(LOG_MISC, "*", _("Module loaded: %-16s (with lang support)"), name);
830 simple 1.1 else
831 pseudo 1.3.2.1 putlog(LOG_MISC, "*", _("Module loaded: %-16s"), name);
832 simple 1.1
833     return NULL;
834     }
835    
836     char *module_unload(char *name, char *user)
837     {
838     module_entry *p = module_list, *o = NULL;
839     char *e;
840     Function *f;
841    
842     while (p) {
843     if ((p->name != NULL) && !strcmp(name, p->name)) {
844     dependancy *d;
845    
846     for (d = dependancy_list; d; d = d->next)
847     if (d->needed == p)
848 pseudo 1.3.2.1 return _("Needed by another module");
849 simple 1.1
850     f = p->funcs;
851     if (f && !f[MODCALL_CLOSE])
852 pseudo 1.3.2.1 return _("No close function");
853 simple 1.1 if (f) {
854     check_tcl_unld(name);
855     e = (((char *(*)()) f[MODCALL_CLOSE]) (user));
856     if (e != NULL)
857     return e;
858     #ifndef STATIC
859     # ifdef MOD_USE_SHL
860     shl_unload(p->hand);
861     # endif
862     # ifdef MOD_USE_DYLD
863     NSUnLinkModule(p->hand, NSUNLINKMODULE_OPTION_NONE);
864     # endif
865     # ifdef MOD_USE_LOADER
866     unload(p->hand);
867     # endif
868     # ifdef MOD_USE_DL
869     dlclose(p->hand);
870     # endif
871     #endif /* !STATIC */
872     }
873     nfree(p->name);
874     if (o == NULL)
875     module_list = p->next;
876     else
877     o->next = p->next;
878     nfree(p);
879 pseudo 1.3.2.1 putlog(LOG_MISC, "*", "%s %s", _("Module unloaded:"), name);
880 simple 1.1 return NULL;
881     }
882     o = p;
883     p = p->next;
884     }
885    
886 pseudo 1.3.2.1 return _("No such module");
887 simple 1.1 }
888    
889     module_entry *module_find(char *name, int major, int minor)
890     {
891     module_entry *p;
892    
893     for (p = module_list; p && p->name; p = p->next) {
894     if ((major == p->major || !major) && minor <= p->minor &&
895     !egg_strcasecmp(name, p->name))
896     return p;
897     }
898     return NULL;
899     }
900    
901     static int module_rename(char *name, char *newname)
902     {
903     module_entry *p;
904    
905     for (p = module_list; p; p = p->next)
906     if (!egg_strcasecmp(newname, p->name))
907     return 0;
908    
909     for (p = module_list; p && p->name; p = p->next) {
910     if (!egg_strcasecmp(name, p->name)) {
911     nfree(p->name);
912     p->name = nmalloc(strlen(newname) + 1);
913     strcpy(p->name, newname);
914     return 1;
915     }
916     }
917     return 0;
918     }
919    
920     Function *module_depend(char *name1, char *name2, int major, int minor)
921     {
922     module_entry *p = module_find(name2, major, minor);
923     module_entry *o = module_find(name1, 0, 0);
924     dependancy *d;
925    
926     if (!p) {
927     if (module_load(name2))
928     return 0;
929     p = module_find(name2, major, minor);
930     }
931     if (!p || !o)
932     return 0;
933     d = nmalloc(sizeof(dependancy));
934    
935     d->needed = p;
936     d->needing = o;
937     d->next = dependancy_list;
938     d->major = major;
939     d->minor = minor;
940     dependancy_list = d;
941     return p->funcs ? p->funcs : (Function *) 1;
942     }
943    
944     int module_undepend(char *name1)
945     {
946     int ok = 0;
947     module_entry *p = module_find(name1, 0, 0);
948     dependancy *d = dependancy_list, *o = NULL;
949    
950     if (p == NULL)
951     return 0;
952     while (d != NULL) {
953     if (d->needing == p) {
954     if (o == NULL) {
955     dependancy_list = d->next;
956     } else {
957     o->next = d->next;
958     }
959     nfree(d);
960     if (o == NULL)
961     d = dependancy_list;
962     else
963     d = o->next;
964     ok++;
965     } else {
966     o = d;
967     d = d->next;
968     }
969     }
970     return ok;
971     }
972    
973     void *mod_malloc(int size, const char *modname, const char *filename, int line)
974     {
975     #ifdef DEBUG_MEM
976     char x[100], *p;
977    
978     p = strrchr(filename, '/');
979     egg_snprintf(x, sizeof x, "%s:%s", modname, p ? p + 1 : filename);
980     x[19] = 0;
981     return n_malloc(size, x, line);
982     #else
983     return nmalloc(size);
984     #endif
985     }
986    
987     void *mod_realloc(void *ptr, int size, const char *modname,
988     const char *filename, int line)
989     {
990     #ifdef DEBUG_MEM
991     char x[100], *p;
992    
993     p = strrchr(filename, '/');
994     egg_snprintf(x, sizeof x, "%s:%s", modname, p ? p + 1 : filename);
995     x[19] = 0;
996     return n_realloc(ptr, size, x, line);
997     #else
998     return nrealloc(ptr, size);
999     #endif
1000     }
1001    
1002     void mod_free(void *ptr, const char *modname, const char *filename, int line)
1003     {
1004     char x[100], *p;
1005    
1006     p = strrchr(filename, '/');
1007     egg_snprintf(x, sizeof x, "%s:%s", modname, p ? p + 1 : filename);
1008     x[19] = 0;
1009     n_free(ptr, x, line);
1010     }
1011    
1012     /* Hooks, various tables of functions to call on certain events
1013     */
1014     void add_hook(int hook_num, Function func)
1015     {
1016     if (hook_num < REAL_HOOKS) {
1017     struct hook_entry *p;
1018    
1019     for (p = hook_list[hook_num]; p; p = p->next)
1020     if (p->func == func)
1021     return; /* Don't add it if it's already there */
1022     p = nmalloc(sizeof(struct hook_entry));
1023    
1024     p->next = hook_list[hook_num];
1025     hook_list[hook_num] = p;
1026     p->func = func;
1027     } else
1028     switch (hook_num) {
1029     case HOOK_ENCRYPT_PASS:
1030     encrypt_pass = (void (*)(char *, char *)) func;
1031     break;
1032     case HOOK_ENCRYPT_STRING:
1033     encrypt_string = (char *(*)(char *, char *)) func;
1034     break;
1035     case HOOK_DECRYPT_STRING:
1036     decrypt_string = (char *(*)(char *, char *)) func;
1037     break;
1038     case HOOK_SHAREOUT:
1039     shareout = (void (*)()) func;
1040     break;
1041     case HOOK_SHAREIN:
1042     sharein = (void (*)(int, char *)) func;
1043     break;
1044     case HOOK_QSERV:
1045     if (qserver == (void (*)(int, char *, int)) null_func)
1046     qserver = (void (*)(int, char *, int)) func;
1047     break;
1048     case HOOK_ADD_MODE:
1049     if (add_mode == (void (*)()) null_func)
1050     add_mode = (void (*)()) func;
1051     break;
1052     /* special hook <drummer> */
1053     case HOOK_RFC_CASECMP:
1054     if (func == NULL) {
1055     rfc_casecmp = egg_strcasecmp;
1056     rfc_ncasecmp =
1057     (int (*)(const char *, const char *, int)) egg_strncasecmp;
1058     rfc_tolower = tolower;
1059     rfc_toupper = toupper;
1060     } else {
1061     rfc_casecmp = _rfc_casecmp;
1062     rfc_ncasecmp = _rfc_ncasecmp;
1063     rfc_tolower = _rfc_tolower;
1064     rfc_toupper = _rfc_toupper;
1065     }
1066     break;
1067     case HOOK_MATCH_NOTEREJ:
1068     if (match_noterej == false_func)
1069     match_noterej = (int (*)(struct userrec *, char *)) func;
1070     break;
1071     case HOOK_DNS_HOSTBYIP:
1072     if (dns_hostbyip == block_dns_hostbyip)
1073 pseudo 1.2 dns_hostbyip = (void (*)(sockname_t *)) func;
1074 simple 1.1 break;
1075     case HOOK_DNS_IPBYHOST:
1076     if (dns_ipbyhost == block_dns_ipbyhost)
1077     dns_ipbyhost = (void (*)(char *)) func;
1078     break;
1079     }
1080     }
1081    
1082     void del_hook(int hook_num, Function func)
1083     {
1084     if (hook_num < REAL_HOOKS) {
1085     struct hook_entry *p = hook_list[hook_num], *o = NULL;
1086    
1087     while (p) {
1088     if (p->func == func) {
1089     if (o == NULL)
1090     hook_list[hook_num] = p->next;
1091     else
1092     o->next = p->next;
1093     nfree(p);
1094     break;
1095     }
1096     o = p;
1097     p = p->next;
1098     }
1099     } else
1100     switch (hook_num) {
1101     case HOOK_ENCRYPT_PASS:
1102     if (encrypt_pass == (void (*)(char *, char *)) func)
1103     encrypt_pass = (void (*)(char *, char *)) null_func;
1104     break;
1105     case HOOK_ENCRYPT_STRING:
1106     if (encrypt_string == (char *(*)(char *, char *)) func)
1107     encrypt_string = (char *(*)(char *, char *)) null_func;
1108     break;
1109     case HOOK_DECRYPT_STRING:
1110     if (decrypt_string == (char *(*)(char *, char *)) func)
1111     decrypt_string = (char *(*)(char *, char *)) null_func;
1112     break;
1113     case HOOK_SHAREOUT:
1114     if (shareout == (void (*)()) func)
1115     shareout = null_func;
1116     break;
1117     case HOOK_SHAREIN:
1118     if (sharein == (void (*)(int, char *)) func)
1119     sharein = null_share;
1120     break;
1121     case HOOK_QSERV:
1122     if (qserver == (void (*)(int, char *, int)) func)
1123     qserver = null_func;
1124     break;
1125     case HOOK_ADD_MODE:
1126     if (add_mode == (void (*)()) func)
1127     add_mode = null_func;
1128     break;
1129     case HOOK_MATCH_NOTEREJ:
1130     if (match_noterej == (int (*)(struct userrec *, char *)) func)
1131     match_noterej = false_func;
1132     break;
1133     case HOOK_DNS_HOSTBYIP:
1134 pseudo 1.2 if (dns_hostbyip == (void (*)(sockname_t *)) func)
1135 simple 1.1 dns_hostbyip = block_dns_hostbyip;
1136     break;
1137     case HOOK_DNS_IPBYHOST:
1138     if (dns_ipbyhost == (void (*)(char *)) func)
1139     dns_ipbyhost = block_dns_ipbyhost;
1140     break;
1141     }
1142     }
1143    
1144     int call_hook_cccc(int hooknum, char *a, char *b, char *c, char *d)
1145     {
1146     struct hook_entry *p, *pn;
1147     int f = 0;
1148    
1149     if (hooknum >= REAL_HOOKS)
1150     return 0;
1151     p = hook_list[hooknum];
1152     for (p = hook_list[hooknum]; p && !f; p = pn) {
1153     pn = p->next;
1154     f = p->func(a, b, c, d);
1155     }
1156     return f;
1157     }
1158    
1159     void do_module_report(int idx, int details, char *which)
1160     {
1161     module_entry *p = module_list;
1162    
1163     if (p && !which)
1164 pseudo 1.3.2.1 dprintf(idx, _("Loaded module information:\n"));
1165 simple 1.1 for (; p; p = p->next) {
1166     if (!which || !egg_strcasecmp(which, p->name)) {
1167     dependancy *d;
1168    
1169     if (details)
1170 pseudo 1.3.2.1 dprintf(idx, _(" Module: %s, v %d.%d\n"), p->name ? p->name : "CORE",
1171 simple 1.1 p->major, p->minor);
1172     if (details > 1) {
1173     for (d = dependancy_list; d; d = d->next)
1174     if (d->needing == p)
1175 pseudo 1.3.2.1 dprintf(idx, _(" requires: %s, v %d.%d\n"), d->needed->name,
1176 simple 1.1 d->major, d->minor);
1177     }
1178     if (p->funcs) {
1179     Function f = p->funcs[MODCALL_REPORT];
1180    
1181     if (f != NULL)
1182     f(idx, details);
1183     }
1184     if (which)
1185     return;
1186     }
1187     }
1188     if (which)
1189 pseudo 1.3.2.1 dprintf(idx, _("No such module.\n"));
1190 simple 1.1 }

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23