/** * svsperl.xs: Perl extension module for Ermyth * * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in doc/pod/gplicense.pod. * * $Id: svsperl.xs,v 1.6 2007/09/16 18:54:43 pippijn Exp $ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include // macro clashes #undef _ #define warn_opers warn #undef warn #include #include #include #include "perlxsi.c" static char const rcsid[] = "$Id: svsperl.xs,v 1.6 2007/09/16 18:54:43 pippijn Exp $"; REGISTER_MODULE ("misc/svsperl", false, "The Ermyth Team "); static PerlInterpreter *perl; static HV *stash_svs; // Make an std::map from a HV typedef std::map charmap; charmap HvMAP (HV *hv) { SV *sv; char *key; STRLEN len; charmap hvmap; I32 i, count = hv_iterinit (hv); for (i = 1; i <= count; i++) { sv = hv_iternextsv(hv, &key, (I32*) &len); hvmap[key] = SvPV(sv, len); } return hvmap; } void * get_mortalspace (int nbytes) { SV *mortal; mortal = sv_2mortal (NEWSV (2040, nbytes)); return (void *) SvPVX (mortal); } // convert a perl arrayref to a char* array char ** XS_unpack_charPtrPtr (SV *arg) { AV *avref; char **array; int len; SV **elem; int i; avref = (AV *) SvRV (arg); len = av_len (avref) + 1; array = (char **) get_mortalspace ((len + 1) * sizeof (*array)); for (i = 0; i < len; i++) { elem = av_fetch (avref, i, 0); array[i] = SvPV_nolen (*elem); } array[len] = NULL; return array; } // convert char* array to perl arrayref void XS_pack_charPtrPtr (SV *arg, char **array, int count) { int i; AV *avref; avref = (AV *) sv_2mortal ((SV *) newAV ()); for (i = 0; i < count; i++) av_push (avref, newSVpv (array[i], strlen (array[i]))); SvSetSV (arg, newRV ((SV *) avref)); } SV *sv_cast (char const * v) { return newSVpv (v, 0); } SV *sv_cast (bool v) { return newSViv (v); } SV *sv_cast ( signed char v) { return newSViv (v); } SV *sv_cast (unsigned char v) { return newSViv (v); } SV *sv_cast ( signed short v) { return newSViv (v); } SV *sv_cast (unsigned short v) { return newSVuv (v); } SV *sv_cast ( signed int v) { return newSViv (v); } SV *sv_cast (unsigned int v) { return newSVuv (v); } SV *sv_cast ( signed long v) { return newSViv (v); } SV *sv_cast (unsigned long v) { return newSVuv (v); } SV *sv_cast (float v) { return newSVnv (v); } SV *sv_cast (double v) { return newSVnv (v); } // base template for casting from SV * template outT sv_cast (SV *from); template<> char const * sv_cast (SV *from) { return SvOK (from) ? SvPV_nolen (from) : 0; } template<> bool sv_cast (SV *from) { return SvIV (from); } template<> signed char sv_cast< signed char > (SV *from) { return SvIV (from); } template<> unsigned char sv_cast (SV *from) { return SvUV (from); } template<> signed short sv_cast< signed short> (SV *from) { return SvIV (from); } template<> unsigned short sv_cast (SV *from) { return SvUV (from); } template<> signed int sv_cast< signed int > (SV *from) { return SvIV (from); } template<> unsigned int sv_cast (SV *from) { return SvUV (from); } template<> signed long sv_cast< signed long > (SV *from) { return SvIV (from); } template<> unsigned long sv_cast (SV *from) { return SvUV (from); } template<> float sv_cast (SV *from) { return SvNV (from); } template<> double sv_cast (SV *from) { return SvNV (from); } void _perlinit () { stash_svs = gv_stashpvn ("svs", 3, 1); } bool _modinit (module *m) { PERL_SYS_INIT3 (&me.argc, &me.argv, 0); perl = perl_alloc (); perl_construct (perl); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; char *argv[] = { me.argv [0], "-e" "use strict; use warnings; use utf8;" "svs->bootstrap;" "unshift @INC, svs::DATADIR ();" "require svs;" }; if (perl_parse (perl, xs_init, 2, argv, NULL) || perl_run (perl)) return false; dSP; PUSHMARK (SP); PUTBACK; call_pv ("svs::init", G_DISCARD | G_VOID); return true; } void _moddeinit () { perl_destruct (perl); perl_free (perl); PERL_SYS_TERM (); } MODULE = svs PACKAGE = svs BOOT: { #define const_iv(name) { const_cast (#name), name } // XXX: constness hack #define stash_pv(name) newCONSTSUB (stash_svs, const_cast (#name), newSVpv (name, sizeof (name) - 1)) _perlinit (); // provided on the commandline stash_pv (PREFIX); stash_pv (LOCALEDIR); stash_pv (SHAREDIR); stash_pv (SYSCONFDIR); stash_pv (LOGDIR); stash_pv (RUNDIR); stash_pv (DATADIR); stash_pv (PRIV_USER_AUSPEX); stash_pv (PRIV_USER_ADMIN); stash_pv (PRIV_USER_SENDPASS); stash_pv (PRIV_USER_VHOST); stash_pv (PRIV_USER_FREGISTER); stash_pv (PRIV_CHAN_AUSPEX); stash_pv (PRIV_CHAN_ADMIN); stash_pv (PRIV_CHAN_CMODES); stash_pv (PRIV_JOIN_STAFFONLY); stash_pv (PRIV_MARK); stash_pv (PRIV_HOLD); stash_pv (PRIV_REG_NOLIMIT); stash_pv (PRIV_SERVER_AUSPEX); stash_pv (PRIV_VIEWPRIVS); stash_pv (PRIV_FLOOD); stash_pv (PRIV_METADATA); stash_pv (PRIV_ADMIN); stash_pv (PRIV_OMODE); stash_pv (PRIV_AKILL); stash_pv (PRIV_MASS_AKILL); stash_pv (PRIV_JUPE); stash_pv (PRIV_NOOP); stash_pv (PRIV_GLOBAL); stash_pv (PRIV_GRANT); stash_pv (AC_IRCOP); stash_pv (AC_SRA); stash_pv (PACKAGE); stash_pv (PACKAGE_BUGREPORT); stash_pv (PACKAGE_NAME); stash_pv (PACKAGE_STRING); stash_pv (PACKAGE_TARNAME); stash_pv (PACKAGE_VERSION); stash_pv (VERSION); #undef stash_pv static const struct { char *name; IV iv; } *civ, const_iv[] = { // channels.h const_iv (MAXEXTMODES), const_iv (CMODE_OP), const_iv (CMODE_VOICE), const_iv (CMODE_INVITE), const_iv (CMODE_KEY), const_iv (CMODE_LIMIT), const_iv (CMODE_MOD), const_iv (CMODE_NOEXT), const_iv (CMODE_PRIV), const_iv (CMODE_SEC), const_iv (CMODE_TOPIC), const_iv (MTYPE_NUL), const_iv (MTYPE_ADD), const_iv (MTYPE_DEL), // common.h const_iv (BUFSIZE), const_iv (MAXMODES), const_iv (MAX_EVENTS), const_iv (HOSTLEN), const_iv (NICKLEN), const_iv (IDLEN), const_iv (CHANNELLEN), const_iv (USERLEN), const_iv (HOSTIPLEN), const_iv (GECOSLEN), const_iv (KEYLEN), const_iv (EMAILLEN), const_iv (MEMOLEN), const_iv (MAXMSIGNORES), // connection.h const_iv (CF_UPLINK), const_iv (CF_DCCOUT), const_iv (CF_DCCIN), const_iv (CF_CONNECTING), const_iv (CF_LISTENING), const_iv (CF_CONNECTED), const_iv (CF_DEAD), const_iv (CF_NONEWLINE), const_iv (CF_SEND_EOF), const_iv (CF_SEND_DEAD), // global.h const_iv (AUTH_NONE), const_iv (AUTH_EMAIL), const_iv (RF_LIVE), const_iv (RF_SHUTDOWN), const_iv (RF_STARTING), const_iv (RF_RESTART), const_iv (RF_REHASHING), // match.h const_iv (MATCH_RFC1459), const_iv (MATCH_ASCII), const_iv (C_ALPHA), const_iv (C_DIGIT), const_iv (AREGEX_ICASE), // metadata.h const_iv (metadata::MYUSER), const_iv (metadata::MYCHAN), const_iv (metadata::CHANACS), // phandler.h const_iv (PROTOCOL_ASUKA), const_iv (PROTOCOL_BAHAMUT), const_iv (PROTOCOL_CHARYBDIS), const_iv (PROTOCOL_DREAMFORGE), const_iv (PROTOCOL_HYPERION), const_iv (PROTOCOL_INSPIRCD), const_iv (PROTOCOL_IRCNET), const_iv (PROTOCOL_MONKEY), const_iv (PROTOCOL_PLEXUS), const_iv (PROTOCOL_PTLINK), const_iv (PROTOCOL_RATBOX), const_iv (PROTOCOL_SCYLLA), const_iv (PROTOCOL_SHADOWIRCD), const_iv (PROTOCOL_SORCERY), const_iv (PROTOCOL_ULTIMATE3), const_iv (PROTOCOL_UNDERNET), const_iv (PROTOCOL_UNREAL), const_iv (PROTOCOL_SOLIDIRCD), const_iv (PROTOCOL_NEFARIOUS), const_iv (PROTOCOL_OFFICEIRC), const_iv (PROTOCOL_OTHER), const_iv (IRCD_CIDR_BANS), const_iv (FNC_REGAIN), const_iv (FNC_FORCE), // privs.h const_iv (OPERCLASS_NEEDOPER), const_iv (SOPER_CONF), // sasl.h const_iv (ASASL_FAIL), const_iv (ASASL_MORE), const_iv (ASASL_DONE), const_iv (ASASL_MARKED_FOR_DELETION), const_iv (ASASL_NEED_LOG), // servers.h const_iv (SF_HIDE), const_iv (SF_EOB), const_iv (SF_EOB2), const_iv (SF_JUPE_PENDING), // tools.h const_iv (EMAIL_REGISTER), const_iv (EMAIL_SENDPASS), const_iv (EMAIL_SETEMAIL), const_iv (EMAIL_MEMO), const_iv (EMAIL_SETPASS), const_iv (LG_NONE), const_iv (LG_INFO), const_iv (LG_ERROR), const_iv (LG_IOERROR), const_iv (LG_DEBUG), const_iv (LG_CMD_ADMIN), const_iv (LG_CMD_REGISTER), const_iv (LG_CMD_SET), const_iv (LG_CMD_DO), const_iv (LG_CMD_LOGIN), const_iv (LG_CMD_GET), const_iv (LG_NETWORK), const_iv (LG_WALLOPS), const_iv (LG_RAWDATA), const_iv (LG_REGISTER), const_iv (LG_WARN1), const_iv (LG_WARN2), const_iv (LG_CMD_ALL), const_iv (LG_ALL), const_iv (CMDLOG_ADMIN), const_iv (CMDLOG_REGISTER), const_iv (CMDLOG_SET), const_iv (CMDLOG_DO), const_iv (CMDLOG_LOGIN), const_iv (CMDLOG_GET), // users.h const_iv (UF_AWAY), const_iv (UF_INVIS), const_iv (UF_IRCOP), const_iv (UF_ADMIN), const_iv (UF_SEENINFO), const_iv (UF_HIDEHOSTREQ), // account/chanacs.h const_iv (CA_VOICE), const_iv (CA_AUTOVOICE), const_iv (CA_OP), const_iv (CA_AUTOOP), const_iv (CA_TOPIC), const_iv (CA_SET), const_iv (CA_REMOVE), const_iv (CA_INVITE), const_iv (CA_RECOVER), const_iv (CA_FLAGS), const_iv (CA_HALFOP), const_iv (CA_AUTOHALFOP), const_iv (CA_ACLVIEW), const_iv (CA_AKICK), const_iv (CA_NONE), const_iv (CA_VOP_DEF), const_iv (CA_HOP_DEF), const_iv (CA_AOP_DEF), const_iv (CA_SOP_DEF), const_iv (CA_SUCCESSOR_0), const_iv (CA_FOUNDER_0), const_iv (CA_INITIAL), const_iv (CA_USEDUPDATE), const_iv (CA_ALLPRIVS), const_iv (CA_ALL_ALL), const_iv (OLD_CA_AOP), const_iv (SHRIKE_CA_VOP), const_iv (SHRIKE_CA_AOP), const_iv (SHRIKE_CA_SOP), const_iv (SHRIKE_CA_FOUNDER), const_iv (SHRIKE_CA_SUCCESSOR), // account/mychan.h const_iv (MC_HOLD), const_iv (MC_NOOP), const_iv (MC_RESTRICTED), const_iv (MC_SECURE), const_iv (MC_VERBOSE), const_iv (MC_STAFFONLY), const_iv (MC_KEEPTOPIC), const_iv (MC_VERBOSE_OPS), const_iv (MC_TOPICLOCK), const_iv (MC_GUARD), const_iv (MC_INHABIT), const_iv (MC_MLOCK_CHECK), const_iv (MC_FORCEVERBOSE), const_iv (MC_VERBOSE_MASK), // account/mymemo.h const_iv (MEMO_READ), const_iv (MEMO_CHANNEL), const_iv (MEMO_MAX_NUM), const_iv (MEMO_MAX_TIME), // account/myuser.h const_iv (MU_HOLD), const_iv (MU_NEVEROP), const_iv (MU_NOOP), const_iv (MU_WAITAUTH), const_iv (MU_HIDEMAIL), const_iv (MU_OLD_ALIAS), const_iv (MU_NOMEMO), const_iv (MU_EMAILMEMOS), const_iv (MU_CRYPTPASS), const_iv (MU_OLD_SASL), const_iv (MU_NOBURSTLOGIN) }; #undef const_iv for (civ = const_iv + sizeof const_iv / sizeof const_iv[0]; civ-- > const_iv; ) newCONSTSUB (stash_svs, civ->name, newSViv (civ->iv)); } void slog (unsigned level, char *msg) char *gen_pw (int sz) void tb2sp (char *line) char *replace (char *s, int size, char const *src, char const *dest) #-------------------------------------------------- # char *itoa (int num) # CODE: # RETVAL = itoa (num); # OUTPUT: # RETVAL # # int validemail (char *email) # # bool validhostmask (char *host) # # char const *sbytes (float x) # # float bytes (float x) # # unsigned long makekey () # # unsigned int shash (unsigned char const *text) # # char *time_ago (time_t event) # # char *timediff (time_t seconds) # # int sjtoken (char *message, char delimiter, AV *parv) # CODE: # { # char *cparv[256]; # int i; # RETVAL = sjtoken (message, delimiter, cparv); # # /if (!parv) # { # parv = newAV (); # av_extend (parv, RETVAL); # } # # for (i = 0; i < RETVAL; i++) # av_push (parv, newSVpv (cparv[i], 0)); # } # OUTPUT: # RETVAL # # char const *uinttobase64 (char *buf, uint64_t v, int64_t count) # # unsigned int base64touint (char const *buf) # # # MODULE = svs PACKAGE = svs::kline_t # # kline_t * # new (char const *klass, char *user, char *host, char *reason, long duration) # CODE: # RETVAL = kline_t::create (user, host, reason, duration); # OUTPUT: # RETVAL # # void # destroy (char const *klass, char const *user, char const *host) # CODE: # kline_t::destroy (user, host); # # kline_t * # find (char const *klass, char const *user, char const *host) # CODE: # RETVAL = kline_t::find (user, host); # OUTPUT: # RETVAL # # kline_t * # find_num (char const *klass, unsigned number) # CODE: # RETVAL = kline_t::find (number); # OUTPUT: # RETVAL # # kline_t * # find_user (char const *klass, user_t *u) # CODE: # RETVAL = kline_t::find (u); # OUTPUT: # RETVAL # # INCLUDE: $PERL $SRCDIR/svsperl/genacc kline_t $SRCDIR/../../include/account/kline.h | # # # MODULE = svs PACKAGE = svs::server_t # # server_t * # new (char const *klass, char const *name, unsigned int hops, char const *uplink, char const *id, char const *desc) # CODE: # RETVAL = server_t::create (name, hops, uplink, id, desc); # OUTPUT: # RETVAL # # server_t * # find (char const *klass, char const *name) # CODE: # RETVAL = server_t::find (name); # OUTPUT: # RETVAL # # void # destroy (char const *klass, char const *name) # CODE: # server_delete (name); # # INCLUDE: $PERL $SRCDIR/svsperl/genacc server_t $SRCDIR/../../include/servers.h | # # # MODULE = svs PACKAGE = svs::svsignore_t # # svsignore_t * # new (char const *klass, char *mask, char *reason) # CODE: # RETVAL = svsignore_add (mask, reason); # OUTPUT: # RETVAL # # void # svsignore_t::DESTROY () # CODE: # svsignore_delete (THIS); # # svsignore_t * # find (char const *klass, user_t *u) # CODE: # RETVAL = svsignore_find (u); # OUTPUT: # RETVAL # # INCLUDE: $PERL $SRCDIR/svsperl/genacc svsignore_t $SRCDIR/../../include/account/svsignore.h | # # # MODULE = svs PACKAGE = svs::user_t # # user_t * # 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) # CODE: # RETVAL = user_t::create (nick, user, host, vhost, ip, uid, gecos, server, ts); # OUTPUT: # RETVAL # # void # user_t::DESTROY () # CODE: # user_delete (THIS); # # user_t * # find (char const *klass, char const *nick) # CODE: # RETVAL = user_t::find (nick); # OUTPUT: # RETVAL # # user_t * # find_named (char const *klass, char const *nick) # CODE: # RETVAL = user_t::find_named (nick); # OUTPUT: # RETVAL # # INCLUDE: $PERL $SRCDIR/svsperl/genacc user_t $SRCDIR/../../include/users.h | #--------------------------------------------------