ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/misc/svsperl.xs
Revision: 1.6
Committed: Sun Sep 16 18:54:43 2007 UTC (16 years, 8 months ago) by pippijn
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +6 -6 lines
Log Message:
#defines to enum

File Contents

# Content
1 /**
2 * svsperl.xs: Perl extension module for Ermyth
3 *
4 * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
5 * Rights to this code are as documented in doc/pod/gplicense.pod.
6 *
7 * $Id: svsperl.xs,v 1.5 2007-09-05 11:23:13 pippijn Exp $
8 */
9
10 #include <map>
11
12 #include <atheme.h>
13 #include <users.h>
14
15 #include <connection.h>
16
17 #include <ermyth/module.h>
18
19 #include <account/chanacs.h>
20 #include <account/kline.h>
21 #include <account/metadata.h>
22 #include <account/mychan.h>
23 #include <account/mymemo.h>
24 #include <account/mynick.h>
25 #include <account/myuser.h>
26 #include <account/svsignore.h>
27 #include <confparse.h>
28 #include <servers.h>
29 #include <sasl.h>
30
31 // macro clashes
32 #undef _
33 #define warn_opers warn
34 #undef warn
35
36 #include <EXTERN.h>
37 #include <perl.h>
38 #include <XSUB.h>
39
40 #include "perlxsi.c"
41
42 static char const rcsid[] = "$Id: svsperl.xs,v 1.5 2007-09-05 11:23:13 pippijn Exp $";
43
44 REGISTER_MODULE ("misc/svsperl", false, "The Ermyth Team <http://services.one09.net>");
45
46 static PerlInterpreter *perl;
47
48 static HV *stash_svs;
49
50 // Make an std::map<char *, char *> from a HV
51 typedef std::map<char *, char *, str_lt> charmap;
52
53 charmap
54 HvMAP (HV *hv)
55 {
56 SV *sv;
57 char *key;
58 STRLEN len;
59 charmap hvmap;
60
61 I32 i, count = hv_iterinit (hv);
62
63 for (i = 1; i <= count; i++)
64 {
65 sv = hv_iternextsv(hv, &key, (I32*) &len);
66 hvmap[key] = SvPV(sv, len);
67 }
68
69 return hvmap;
70 }
71
72
73 void *
74 get_mortalspace (int nbytes)
75 {
76 SV *mortal;
77 mortal = sv_2mortal (NEWSV (2040, nbytes));
78 return (void *) SvPVX (mortal);
79 }
80
81 // convert a perl arrayref to a char* array
82 char **
83 XS_unpack_charPtrPtr (SV *arg)
84 {
85 AV *avref;
86 char **array;
87 int len;
88 SV **elem;
89 int i;
90
91 avref = (AV *) SvRV (arg);
92 len = av_len (avref) + 1;
93
94 array = (char **) get_mortalspace ((len + 1) * sizeof (*array));
95
96 for (i = 0; i < len; i++) {
97 elem = av_fetch (avref, i, 0);
98 array[i] = SvPV_nolen (*elem);
99 }
100
101 array[len] = NULL;
102
103 return array;
104 }
105
106 // convert char* array to perl arrayref
107 void
108 XS_pack_charPtrPtr (SV *arg, char **array, int count)
109 {
110 int i;
111 AV *avref;
112
113 avref = (AV *) sv_2mortal ((SV *) newAV ());
114
115 for (i = 0; i < count; i++)
116 av_push (avref, newSVpv (array[i], strlen (array[i])));
117
118 SvSetSV (arg, newRV ((SV *) avref));
119 }
120
121
122 SV *sv_cast (char const * v) { return newSVpv (v, 0); }
123 SV *sv_cast (bool v) { return newSViv (v); }
124 SV *sv_cast ( signed char v) { return newSViv (v); }
125 SV *sv_cast (unsigned char v) { return newSViv (v); }
126 SV *sv_cast ( signed short v) { return newSViv (v); }
127 SV *sv_cast (unsigned short v) { return newSVuv (v); }
128 SV *sv_cast ( signed int v) { return newSViv (v); }
129 SV *sv_cast (unsigned int v) { return newSVuv (v); }
130 SV *sv_cast ( signed long v) { return newSViv (v); }
131 SV *sv_cast (unsigned long v) { return newSVuv (v); }
132 SV *sv_cast (float v) { return newSVnv (v); }
133 SV *sv_cast (double v) { return newSVnv (v); }
134
135 // base template for casting from SV *
136 template<class outT> outT sv_cast (SV *from);
137
138 template<> char const * sv_cast<char const * > (SV *from) { return SvOK (from) ? SvPV_nolen (from) : 0; }
139 template<> bool sv_cast<bool > (SV *from) { return SvIV (from); }
140 template<> signed char sv_cast< signed char > (SV *from) { return SvIV (from); }
141 template<> unsigned char sv_cast<unsigned char > (SV *from) { return SvUV (from); }
142 template<> signed short sv_cast< signed short> (SV *from) { return SvIV (from); }
143 template<> unsigned short sv_cast<unsigned short> (SV *from) { return SvUV (from); }
144 template<> signed int sv_cast< signed int > (SV *from) { return SvIV (from); }
145 template<> unsigned int sv_cast<unsigned int > (SV *from) { return SvUV (from); }
146 template<> signed long sv_cast< signed long > (SV *from) { return SvIV (from); }
147 template<> unsigned long sv_cast<unsigned long > (SV *from) { return SvUV (from); }
148 template<> float sv_cast<float > (SV *from) { return SvNV (from); }
149 template<> double sv_cast<double > (SV *from) { return SvNV (from); }
150
151
152 void
153 _perlinit ()
154 {
155 stash_svs = gv_stashpvn ("svs", 3, 1);
156 }
157
158 bool
159 _modinit (module *m)
160 {
161 PERL_SYS_INIT3 (&me.argc, &me.argv, 0);
162 perl = perl_alloc ();
163 perl_construct (perl);
164
165 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
166
167 char *argv[] = {
168 me.argv [0],
169 "-e"
170 "use strict; use warnings; use utf8;"
171 "svs->bootstrap;"
172 "unshift @INC, svs::DATADIR ();"
173 "require svs;"
174 };
175
176 if (perl_parse (perl, xs_init, 2, argv, NULL)
177 || perl_run (perl))
178 return false;
179
180 dSP;
181
182 PUSHMARK (SP);
183 PUTBACK;
184 call_pv ("svs::init", G_DISCARD | G_VOID);
185
186 return true;
187 }
188
189 void
190 _moddeinit ()
191 {
192 perl_destruct (perl);
193 perl_free (perl);
194 PERL_SYS_TERM ();
195 }
196
197 MODULE = svs PACKAGE = svs
198
199 BOOT:
200 {
201 #define const_iv(name) { const_cast<char *> (#name), name } // XXX: constness hack
202 #define stash_pv(name) newCONSTSUB (stash_svs, const_cast<char *> (#name), newSVpv (name, sizeof (name) - 1))
203
204 _perlinit ();
205
206 // provided on the commandline
207 stash_pv (PREFIX);
208 stash_pv (LOCALEDIR);
209 stash_pv (SHAREDIR);
210 stash_pv (SYSCONFDIR);
211 stash_pv (LOGDIR);
212 stash_pv (RUNDIR);
213 stash_pv (DATADIR);
214
215 stash_pv (PRIV_USER_AUSPEX);
216 stash_pv (PRIV_USER_ADMIN);
217 stash_pv (PRIV_USER_SENDPASS);
218 stash_pv (PRIV_USER_VHOST);
219 stash_pv (PRIV_USER_FREGISTER);
220 stash_pv (PRIV_CHAN_AUSPEX);
221 stash_pv (PRIV_CHAN_ADMIN);
222 stash_pv (PRIV_CHAN_CMODES);
223 stash_pv (PRIV_JOIN_STAFFONLY);
224 stash_pv (PRIV_MARK);
225 stash_pv (PRIV_HOLD);
226 stash_pv (PRIV_REG_NOLIMIT);
227 stash_pv (PRIV_SERVER_AUSPEX);
228 stash_pv (PRIV_VIEWPRIVS);
229 stash_pv (PRIV_FLOOD);
230 stash_pv (PRIV_METADATA);
231 stash_pv (PRIV_ADMIN);
232 stash_pv (PRIV_OMODE);
233 stash_pv (PRIV_AKILL);
234 stash_pv (PRIV_MASS_AKILL);
235 stash_pv (PRIV_JUPE);
236 stash_pv (PRIV_NOOP);
237 stash_pv (PRIV_GLOBAL);
238 stash_pv (PRIV_GRANT);
239
240 stash_pv (AC_IRCOP);
241 stash_pv (AC_SRA);
242
243 stash_pv (PACKAGE);
244 stash_pv (PACKAGE_BUGREPORT);
245 stash_pv (PACKAGE_NAME);
246 stash_pv (PACKAGE_STRING);
247 stash_pv (PACKAGE_TARNAME);
248 stash_pv (PACKAGE_VERSION);
249 stash_pv (VERSION);
250 #undef stash_pv
251
252 static const struct {
253 char *name;
254 IV iv;
255 } *civ, const_iv[] = {
256 // channels.h
257 const_iv (MAXEXTMODES),
258
259 const_iv (CMODE_OP), const_iv (CMODE_VOICE), const_iv (CMODE_INVITE), const_iv (CMODE_KEY), const_iv (CMODE_LIMIT),
260 const_iv (CMODE_MOD), const_iv (CMODE_NOEXT), const_iv (CMODE_PRIV), const_iv (CMODE_SEC), const_iv (CMODE_TOPIC),
261
262 const_iv (MTYPE_NUL), const_iv (MTYPE_ADD), const_iv (MTYPE_DEL),
263
264 // common.h
265 const_iv (BUFSIZE), const_iv (MAXMODES), const_iv (MAX_EVENTS), const_iv (HOSTLEN), const_iv (NICKLEN), const_iv (IDLEN),
266 const_iv (CHANNELLEN), const_iv (USERLEN), const_iv (HOSTIPLEN), const_iv (GECOSLEN), const_iv (KEYLEN), const_iv (EMAILLEN),
267 const_iv (MEMOLEN), const_iv (MAXMSIGNORES),
268
269 // connection.h
270 const_iv (CF_UPLINK), const_iv (CF_DCCOUT), const_iv (CF_DCCIN),
271 const_iv (CF_CONNECTING), const_iv (CF_LISTENING), const_iv (CF_CONNECTED),
272 const_iv (CF_DEAD), const_iv (CF_NONEWLINE), const_iv (CF_SEND_EOF),
273 const_iv (CF_SEND_DEAD),
274
275 // global.h
276 const_iv (AUTH_NONE), const_iv (AUTH_EMAIL),
277
278 const_iv (RF_LIVE), const_iv (RF_SHUTDOWN), const_iv (RF_STARTING), const_iv (RF_RESTART), const_iv (RF_REHASHING),
279
280 // match.h
281 const_iv (MATCH_RFC1459), const_iv (MATCH_ASCII), const_iv (C_ALPHA), const_iv (C_DIGIT), const_iv (AREGEX_ICASE),
282
283 // metadata.h
284 const_iv (metadata::MYUSER), const_iv (metadata::MYCHAN), const_iv (metadata::CHANACS),
285
286 // phandler.h
287 const_iv (PROTOCOL_ASUKA), const_iv (PROTOCOL_BAHAMUT), const_iv (PROTOCOL_CHARYBDIS), const_iv (PROTOCOL_DREAMFORGE),
288 const_iv (PROTOCOL_HYPERION), const_iv (PROTOCOL_INSPIRCD), const_iv (PROTOCOL_IRCNET), const_iv (PROTOCOL_MONKEY),
289 const_iv (PROTOCOL_PLEXUS), const_iv (PROTOCOL_PTLINK), const_iv (PROTOCOL_RATBOX), const_iv (PROTOCOL_SCYLLA),
290 const_iv (PROTOCOL_SHADOWIRCD), const_iv (PROTOCOL_SORCERY), const_iv (PROTOCOL_ULTIMATE3), const_iv (PROTOCOL_UNDERNET),
291 const_iv (PROTOCOL_UNREAL), const_iv (PROTOCOL_SOLIDIRCD), const_iv (PROTOCOL_NEFARIOUS), const_iv (PROTOCOL_OFFICEIRC),
292 const_iv (PROTOCOL_OTHER),
293
294 const_iv (IRCD_CIDR_BANS),
295
296 const_iv (FNC_REGAIN), const_iv (FNC_FORCE),
297
298 // privs.h
299 const_iv (OPERCLASS_NEEDOPER), const_iv (SOPER_CONF),
300
301 // sasl.h
302 const_iv (ASASL_FAIL), const_iv (ASASL_MORE), const_iv (ASASL_DONE), const_iv (ASASL_MARKED_FOR_DELETION),
303 const_iv (ASASL_NEED_LOG),
304
305 // servers.h
306 const_iv (SF_HIDE), const_iv (SF_EOB), const_iv (SF_EOB2), const_iv (SF_JUPE_PENDING),
307
308 // tools.h
309 const_iv (EMAIL_REGISTER), const_iv (EMAIL_SENDPASS), const_iv (EMAIL_SETEMAIL),
310 const_iv (EMAIL_MEMO), const_iv (EMAIL_SETPASS),
311
312 const_iv (LG_NONE), const_iv (LG_INFO), const_iv (LG_ERROR), const_iv (LG_IOERROR), const_iv (LG_DEBUG),
313 const_iv (LG_CMD_ADMIN), const_iv (LG_CMD_REGISTER), const_iv (LG_CMD_SET), const_iv (LG_CMD_DO),
314 const_iv (LG_CMD_LOGIN), const_iv (LG_CMD_GET), const_iv (LG_NETWORK), const_iv (LG_WALLOPS),
315 const_iv (LG_RAWDATA), const_iv (LG_REGISTER), const_iv (LG_WARN1), const_iv (LG_WARN2),
316 const_iv (LG_CMD_ALL), const_iv (LG_ALL),
317
318 const_iv (CMDLOG_ADMIN), const_iv (CMDLOG_REGISTER), const_iv (CMDLOG_SET), const_iv (CMDLOG_DO),
319 const_iv (CMDLOG_LOGIN), const_iv (CMDLOG_GET),
320
321 // users.h
322 const_iv (UF_AWAY), const_iv (UF_INVIS), const_iv (UF_IRCOP),
323 const_iv (UF_ADMIN), const_iv (UF_SEENINFO), const_iv (UF_HIDEHOSTREQ),
324
325 // account/chanacs.h
326 const_iv (CA_VOICE), const_iv (CA_AUTOVOICE), const_iv (CA_OP),
327 const_iv (CA_AUTOOP), const_iv (CA_TOPIC), const_iv (CA_SET),
328 const_iv (CA_REMOVE), const_iv (CA_INVITE), const_iv (CA_RECOVER),
329 const_iv (CA_FLAGS), const_iv (CA_HALFOP), const_iv (CA_AUTOHALFOP),
330 const_iv (CA_ACLVIEW), const_iv (CA_AKICK), const_iv (CA_NONE),
331 const_iv (CA_VOP_DEF), const_iv (CA_HOP_DEF), const_iv (CA_AOP_DEF),
332 const_iv (CA_SOP_DEF), const_iv (CA_SUCCESSOR_0), const_iv (CA_FOUNDER_0),
333 const_iv (CA_INITIAL), const_iv (CA_USEDUPDATE), const_iv (CA_ALLPRIVS),
334 const_iv (CA_ALL_ALL), const_iv (OLD_CA_AOP), const_iv (SHRIKE_CA_VOP),
335 const_iv (SHRIKE_CA_AOP), const_iv (SHRIKE_CA_SOP), const_iv (SHRIKE_CA_FOUNDER),
336 const_iv (SHRIKE_CA_SUCCESSOR),
337
338 // account/mychan.h
339 const_iv (MC_HOLD), const_iv (MC_NOOP), const_iv (MC_RESTRICTED),
340 const_iv (MC_SECURE), const_iv (MC_VERBOSE), const_iv (MC_STAFFONLY),
341 const_iv (MC_KEEPTOPIC), const_iv (MC_VERBOSE_OPS), const_iv (MC_TOPICLOCK),
342 const_iv (MC_GUARD), const_iv (MC_INHABIT), const_iv (MC_MLOCK_CHECK),
343 const_iv (MC_FORCEVERBOSE), const_iv (MC_VERBOSE_MASK),
344
345 // account/mymemo.h
346 const_iv (MEMO_READ), const_iv (MEMO_CHANNEL), const_iv (MEMO_MAX_NUM), const_iv (MEMO_MAX_TIME),
347
348 // account/myuser.h
349 const_iv (MU_HOLD), const_iv (MU_NEVEROP), const_iv (MU_NOOP), const_iv (MU_WAITAUTH),
350 const_iv (MU_HIDEMAIL), const_iv (MU_OLD_ALIAS), const_iv (MU_NOMEMO),
351 const_iv (MU_EMAILMEMOS), const_iv (MU_CRYPTPASS), const_iv (MU_OLD_SASL),
352 const_iv (MU_NOBURSTLOGIN)
353 };
354 #undef const_iv
355
356 for (civ = const_iv + sizeof const_iv / sizeof const_iv[0]; civ-- > const_iv; )
357 newCONSTSUB (stash_svs, civ->name, newSViv (civ->iv));
358 }
359
360 void slog (unsigned level, char *msg)
361
362 char *gen_pw (int sz)
363
364 void tb2sp (char *line)
365
366 char *replace (char *s, int size, char const *src, char const *dest)
367
368 #--------------------------------------------------
369 # char *itoa (int num)
370 # CODE:
371 # RETVAL = itoa<char> (num);
372 # OUTPUT:
373 # RETVAL
374 #
375 # int validemail (char *email)
376 #
377 # bool validhostmask (char *host)
378 #
379 # char const *sbytes (float x)
380 #
381 # float bytes (float x)
382 #
383 # unsigned long makekey ()
384 #
385 # unsigned int shash (unsigned char const *text)
386 #
387 # char *time_ago (time_t event)
388 #
389 # char *timediff (time_t seconds)
390 #
391 # int sjtoken (char *message, char delimiter, AV *parv)
392 # CODE:
393 # {
394 # char *cparv[256];
395 # int i;
396 # RETVAL = sjtoken (message, delimiter, cparv);
397 #
398 # /if (!parv)
399 # {
400 # parv = newAV ();
401 # av_extend (parv, RETVAL);
402 # }
403 #
404 # for (i = 0; i < RETVAL; i++)
405 # av_push (parv, newSVpv (cparv[i], 0));
406 # }
407 # OUTPUT:
408 # RETVAL
409 #
410 # char const *uinttobase64 (char *buf, uint64_t v, int64_t count)
411 #
412 # unsigned int base64touint (char const *buf)
413 #
414 #
415 # MODULE = svs PACKAGE = svs::kline_t
416 #
417 # kline_t *
418 # new (char const *klass, char *user, char *host, char *reason, long duration)
419 # CODE:
420 # RETVAL = kline_t::create (user, host, reason, duration);
421 # OUTPUT:
422 # RETVAL
423 #
424 # void
425 # destroy (char const *klass, char const *user, char const *host)
426 # CODE:
427 # kline_t::destroy (user, host);
428 #
429 # kline_t *
430 # find (char const *klass, char const *user, char const *host)
431 # CODE:
432 # RETVAL = kline_t::find (user, host);
433 # OUTPUT:
434 # RETVAL
435 #
436 # kline_t *
437 # find_num (char const *klass, unsigned number)
438 # CODE:
439 # RETVAL = kline_t::find (number);
440 # OUTPUT:
441 # RETVAL
442 #
443 # kline_t *
444 # find_user (char const *klass, user_t *u)
445 # CODE:
446 # RETVAL = kline_t::find (u);
447 # OUTPUT:
448 # RETVAL
449 #
450 # INCLUDE: $PERL $SRCDIR/svsperl/genacc kline_t $SRCDIR/../../include/account/kline.h |
451 #
452 #
453 # MODULE = svs PACKAGE = svs::server_t
454 #
455 # server_t *
456 # new (char const *klass, char const *name, unsigned int hops, char const *uplink, char const *id, char const *desc)
457 # CODE:
458 # RETVAL = server_t::create (name, hops, uplink, id, desc);
459 # OUTPUT:
460 # RETVAL
461 #
462 # server_t *
463 # find (char const *klass, char const *name)
464 # CODE:
465 # RETVAL = server_t::find (name);
466 # OUTPUT:
467 # RETVAL
468 #
469 # void
470 # destroy (char const *klass, char const *name)
471 # CODE:
472 # server_delete (name);
473 #
474 # INCLUDE: $PERL $SRCDIR/svsperl/genacc server_t $SRCDIR/../../include/servers.h |
475 #
476 #
477 # MODULE = svs PACKAGE = svs::svsignore_t
478 #
479 # svsignore_t *
480 # new (char const *klass, char *mask, char *reason)
481 # CODE:
482 # RETVAL = svsignore_add (mask, reason);
483 # OUTPUT:
484 # RETVAL
485 #
486 # void
487 # svsignore_t::DESTROY ()
488 # CODE:
489 # svsignore_delete (THIS);
490 #
491 # svsignore_t *
492 # find (char const *klass, user_t *u)
493 # CODE:
494 # RETVAL = svsignore_find (u);
495 # OUTPUT:
496 # RETVAL
497 #
498 # INCLUDE: $PERL $SRCDIR/svsperl/genacc svsignore_t $SRCDIR/../../include/account/svsignore.h |
499 #
500 #
501 # MODULE = svs PACKAGE = svs::user_t
502 #
503 # user_t *
504 # new (char const *klass, char const *nick, char const *user, char const *host, char const *vhost, char const *ip, char const *uid, char const *gecos, server_t *server, time_t ts)
505 # CODE:
506 # RETVAL = user_t::create (nick, user, host, vhost, ip, uid, gecos, server, ts);
507 # OUTPUT:
508 # RETVAL
509 #
510 # void
511 # user_t::DESTROY ()
512 # CODE:
513 # user_delete (THIS);
514 #
515 # user_t *
516 # find (char const *klass, char const *nick)
517 # CODE:
518 # RETVAL = user_t::find (nick);
519 # OUTPUT:
520 # RETVAL
521 #
522 # user_t *
523 # find_named (char const *klass, char const *nick)
524 # CODE:
525 # RETVAL = user_t::find_named (nick);
526 # OUTPUT:
527 # RETVAL
528 #
529 # INCLUDE: $PERL $SRCDIR/svsperl/genacc user_t $SRCDIR/../../include/users.h |
530 #--------------------------------------------------