Debian Codegraph @

modules/scripting/perl/api/perl_hooks_extra.h

raw
1 #ifndef PERL_HOOKS_EXTRA_H
2 #define PERL_HOOKS_EXTRA_H
3
4 /*
5 * Special-case. Pass undef to the handler routine where it takes no argument.
6 */
7 static void perl_hook_marshal_void(perl_hook_marshal_direction_t dir, void * data, SV ** psv)
8 {
9 if (dir == PERL_HOOK_TO_PERL)
10 *psv = &PL_sv_undef;
11 }
12
13 /*
14 * Another special case. This hook structure has a union in it, with the type
15 * used (and hence the package to which to bless it) dependent on the hook that's
16 * being called.
17 */
18 static void perl_hook_marshal_hook_expiry_req_t(perl_hook_marshal_direction_t dir, hook_expiry_req_t * data, SV **psv,
19 const char * argname, const char * packagename)
20 {
21 if (dir == PERL_HOOK_TO_PERL)
22 {
23 HV *hash = newHV();
24 SV *sv_tmp = NULL;
25 /* Doesn't matter which we pick here; the package name determines what it'll be
26 * converted to before use. */
27 sv_tmp = bless_pointer_to_package(data->data.mc, packagename);
28 hv_store(hash, argname, strlen(argname), sv_tmp, 0);
29 sv_setiv(sv_tmp, data->do_expire);
30 hv_store(hash, "do_expire", 8, sv_tmp, 0);
31
32 *psv = newRV_noinc((SV*)hash);
33 } else {
34 return_if_fail(SvROK(*psv) && SvTYPE(SvRV(*psv)) == SVt_PVHV);
35 HV *hash = (HV*)SvRV(*psv);
36 SV **psv_tmp = NULL;
37 psv_tmp = hv_fetch(hash, "do_expire", 8, 0);
38 data->do_expire = SvIV(*psv_tmp);
39 }
40 }
41
42
43 /*
44 * These hook functions need special handling, since they use the same argument
45 * structure but need to populate it in different ways.
46 */
47
48 static void perl_hook_expiry_check(hook_expiry_req_t * data, const char *hookname, const char *packagename, const char * argname)
49 {
50 SV *arg;
51 perl_hook_marshal_hook_expiry_req_t(PERL_HOOK_TO_PERL, data, &arg, packagename, argname);
52
53 dSP;
54 ENTER;
55 SAVETMPS;
56 PUSHMARK(SP);
57
58 XPUSHs(sv_2mortal(newRV_noinc((SV*)get_cv("Atheme::Hooks::call_hooks", 0))));
59 XPUSHs(sv_2mortal(newSVpv(hookname, 0)));
60 XPUSHs(arg);
61 call_pv("Atheme::Init::call_wrapper", G_EVAL | G_DISCARD);
62
63 SPAGAIN;
64 FREETMPS;
65 LEAVE;
66
67 perl_hook_marshal_hook_expiry_req_t(PERL_HOOK_FROM_PERL, data, &arg, NULL, NULL);
68 SvREFCNT_dec(arg);
69 invalidate_object_references();
70 }
71
72
73
74 static void perl_hook_user_check_expire(hook_expiry_req_t * data)
75 {
76 perl_hook_expiry_check(data, "user_check_expire", "Atheme::Account", "account");
77 }
78
79 static void perl_hook_nick_check_expire(hook_expiry_req_t * data)
80 {
81 perl_hook_expiry_check(data, "nick_check_expire", "Atheme::NickRegistration", "nick");
82 }
83
84 static void perl_hook_channel_check_expire(hook_expiry_req_t * data)
85 {
86 perl_hook_expiry_check(data, "channel_check_expire", "Atheme::ChannelRegistration", "channel");
87 }
88
89 #endif