view release on metacpan or search on metacpan
Bluetooth.xs view on Meta::CPAN
# * bt_device_list()
# *****************************************************************************/
void
bt_device_list( ... )
PREINIT:
bdaddr_t addr[256];
int r;
my_thread_var_t *tv;
char tmp[20];
PPCODE:
r = bt_device_list( addr, sizeof( addr ) / sizeof( bdaddr_t ) );
if( r == SOCKET_ERROR ) {
tv = items > 0 ? my_thread_var_find( ST(0) ) : NULL;
if( tv != NULL )
tv->last_errno = Socket_errno();
else
global.last_errno = Socket_errno();
XPUSHs( &PL_sv_undef );
}
else {
Bluetooth.xs view on Meta::CPAN
# *****************************************************************************/
void
bt_device_name( ... )
PREINIT:
char tmp[256], *s1;
STRLEN l1;
int r;
bdaddr_t addr;
my_thread_var_t *tv;
PPCODE:
if( items > 1 ) {
s1 = SvPVbyte( ST(1), l1 );
if( l1 == sizeof( bdaddr_t ) )
r = bt_device_name( (bdaddr_t *) s1, tmp, sizeof( tmp ) - 1 );
else {
my_str2ba( s1, &addr );
r = bt_device_name( &addr, tmp, sizeof( tmp ) - 1 );
}
}
else {
Bluetooth.xs view on Meta::CPAN
# *****************************************************************************/
void
bt_service_list( ... )
PREINIT:
char tmp[256], *s1;
STRLEN l1;
int r;
bdaddr_t addr;
my_thread_var_t *tv;
PPCODE:
if( items > 1 ) {
s1 = SvPVbyte( ST(1), l1 );
if( l1 == sizeof( bdaddr_t ) )
r = bt_service_list( (bdaddr_t *) s1 );
else {
my_str2ba( s1, &addr );
r = bt_service_list( &addr );
}
}
else {
g_mod_sc = INT2PTR(mod_sc_t *, SvIV(*psv));
}
void
test()
PREINIT:
sc_t *socket;
char *args[4];
int r;
SV *sv;
PPCODE:
args[0] = "local_port";
args[1] = "8080";
args[2] = "listen";
args[3] = "10";
r = g_mod_sc->sc_create(args, 4, &socket);
if (r != SC_OK)
croak(g_mod_sc->sc_get_error(NULL));
g_mod_sc->sc_create_class(socket, NULL, &sv);
ST(0) = sv_2mortal(sv);
XSRETURN(1);
(void) hv_store( PL_modglobal,
"Socket::Class", 13, newSViv( PTR2IV( &mod_sc ) ), 0 );
}
#/*****************************************************************************
# * c_module()
# *****************************************************************************/
void
c_module( ... )
PPCODE:
/* returns the c module interface */
XSRETURN_IV( PTR2IV( &mod_sc ) );
#/*****************************************************************************
# * END()
# *****************************************************************************/
void
END( ... )
# * CLONE()
# *****************************************************************************/
#ifdef USE_ITHREADS
void
CLONE( ... )
PREINIT:
socket_class_t *sc;
int i;
PPCODE:
GLOBAL_LOCK();
for( i = 0; i <= SC_CASCADE; i ++ ) {
for( sc = sc_global.socket[i]; sc != NULL; sc = sc->next ) {
if( sc->do_clone )
sc->refcnt ++;
#ifdef SC_DEBUG
_debug( "CLONE called for sc %lu refcnt: %d\n", sc->id, sc->refcnt );
#endif
}
}
#/*****************************************************************************
# * DESTROY( this )
# *****************************************************************************/
void
DESTROY( this, ... )
SV *this;
PREINIT:
socket_class_t *sc;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
#ifdef SC_DEBUG
_debug( "DESTROY called for sc %lu refcnt: %d\n", sc->id, sc->refcnt - 1 );
#endif
#ifdef USE_ITHREADS
if( sc->do_clone && sc->thread_id == THREAD_ID() ) {
sc->do_clone = FALSE;
#ifdef SC_DEBUG
_debug( "Disabled futher CLONE for sc %lu\n", sc->id );
# *****************************************************************************/
void
new( class, ... )
SV *class;
PREINIT:
socket_class_t *sc;
char **args;
int argc = 0, r, i;
SV *sv;
PPCODE:
Newx( args, items - 1, char * );
/* read options */
for( i = 1; i < items - 1; ) {
args[argc ++] = SvPV_nolen( ST(i) );
i ++;
args[argc ++] = SvPV_nolen( ST(i) );
i ++;
}
r = mod_sc_create( args, argc, &sc );
Safefree( args );
# * connect( this )
# *****************************************************************************/
void
connect( this, ... )
SV *this;
PREINIT:
socket_class_t *sc;
const char *s1 = NULL, *s2 = NULL;
double ms = 0;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
switch( sc->s_domain ) {
case AF_INET:
case AF_INET6:
default:
switch( items ) {
case 4:
default:
if( SvNOK( ST(3) ) || SvIOK( ST(3) ) )
#/*****************************************************************************
# * free( this )
# *****************************************************************************/
void
free( this )
SV *this;
PREINIT:
socket_class_t *sc;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
mod_sc_destroy( sc );
XSRETURN_YES;
#/*****************************************************************************
# * close( this )
# *****************************************************************************/
void
close( this )
SV *this;
PREINIT:
socket_class_t *sc;
PPCODE:
if( (sc = socket_class_find( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_close( sc ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * shutdown( this )
# *****************************************************************************/
void
shutdown( this, how = 0 )
SV *this;
int how
PREINIT:
socket_class_t *sc;
PPCODE:
if( (sc = socket_class_find( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_shutdown( sc, how ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * bind( this )
# *****************************************************************************/
void
bind( this, addr = NULL, port = NULL )
SV *this;
char *addr;
char *port;
PREINIT:
socket_class_t *sc;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_bind( sc, addr, port ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * listen( this )
# *****************************************************************************/
void
listen( this, queue = SOMAXCONN )
SV *this;
int queue;
PREINIT:
socket_class_t *sc;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_listen( sc, queue < 0 ? SOMAXCONN : queue ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * accept( this )
# *****************************************************************************/
void
accept( this, pkg = NULL )
SV *this;
char *pkg;
PREINIT:
socket_class_t *sc, *sc2;
SV *sv;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_accept( sc, &sc2 ) != SC_OK )
XSRETURN_EMPTY;
if( sc2 == NULL )
XSRETURN_NO;
if( mod_sc_create_class( sc2, pkg, &sv ) != SC_OK ) {
mod_sc_destroy( sc2 );
XSRETURN_EMPTY;
}
void
recv( this, buf, len, flags = 0 )
SV *this;
SV *buf;
unsigned int len;
unsigned int flags;
PREINIT:
socket_class_t *sc;
int rlen;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( sc->buffer_len < len ) {
sc->buffer_len = len;
Renew( sc->buffer, len, char );
}
if( mod_sc_recv( sc, sc->buffer, len, flags, &rlen ) != SC_OK )
XSRETURN_EMPTY;
if( rlen == 0 )
XSRETURN_NO;
void
send( this, buf, flags = 0 )
SV *this;
SV *buf;
unsigned int flags;
PREINIT:
socket_class_t *sc;
const char *msg;
STRLEN len;
int rlen;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
msg = SvPV( buf, len );
if( mod_sc_send( sc, msg, (int) len, flags, &rlen ) != SC_OK )
XSRETURN_EMPTY;
if( rlen == 0 )
XSRETURN_NO;
XSRETURN_IV( rlen );
void
recvfrom( this, buf, len, flags = 0 )
SV *this;
SV *buf;
size_t len;
unsigned int flags;
PREINIT:
socket_class_t *sc;
int rlen;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( sc->buffer_len < len ) {
sc->buffer_len = len;
Renew( sc->buffer, len, char );
}
if( mod_sc_recvfrom( sc, sc->buffer, (int) len, flags, &rlen ) != SC_OK )
XSRETURN_EMPTY;
if( rlen == 0 )
XSRETURN_NO;
SV *this;
SV *buf;
SV *to;
unsigned int flags;
PREINIT:
socket_class_t *sc;
const char *msg;
STRLEN len;
sc_addr_t *peer = NULL;
int rlen;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( to != NULL && SvPOK( to ) ) {
peer = (my_sockaddr_t *) SvPVbyte( to, len );
if( len < sizeof( int ) || len != SC_ADDR_SIZE(*peer) ) {
my_snprintf_(
sc->last_error, sizeof( sc->last_error ),
"Invalid address"
);
XSRETURN_EMPTY;
# *****************************************************************************/
void
read( this, buf, len )
SV *this;
SV *buf;
unsigned int len;
PREINIT:
socket_class_t *sc;
int rlen;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( sc->buffer_len < len ) {
sc->buffer_len = len;
Renew( sc->buffer, len, char );
}
if( mod_sc_read( sc, sc->buffer, len, &rlen ) != SC_OK )
XSRETURN_EMPTY;
if( rlen == 0 )
XSRETURN_NO;
void
write( this, buf, ... )
SV *this;
SV *buf;
PREINIT:
socket_class_t *sc;
const char *msg;
STRLEN l1;
int start = 0, len, max, l2;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
msg = SvPVx( buf, l1 );
max = len = (int) l1;
if( items > 2 ) {
start = (int) SvIV( ST(2) );
if( start < 0 ) {
start += max;
if( start < 0 )
start = 0;
void
readline( this, separator = NULL, maxsize = 0 )
SV *this;
char *separator;
int maxsize;
PREINIT:
socket_class_t *sc;
int rlen, r;
char *rbuf;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( separator != NULL ) {
r = mod_sc_read_packet(
sc, separator, (size_t) maxsize, &rbuf, &rlen );
if( r != SC_OK )
XSRETURN_EMPTY;
}
else {
if( mod_sc_readline( sc, &rbuf, &rlen ) != SC_OK )
void
writeline( this, buf )
SV *this;
SV *buf;
PREINIT:
socket_class_t *sc;
const char *msg;
STRLEN len;
int rlen;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
msg = SvPVx( buf, len );
if( mod_sc_writeln( sc, msg, (int) len, &rlen ) != SC_OK )
XSRETURN_EMPTY;
if( rlen == 0 )
XSRETURN_NO;
XSRETURN_IV( rlen );
void
print( this, ... )
SV *this;
PREINIT:
socket_class_t *sc;
const char *s1;
char *tmp = NULL;
STRLEN l1, len = 0, pos = 0;
int r, rlen;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
for( r = 1; r < items; r ++ ) {
if( ! SvOK( ST(r) ) )
continue;
s1 = SvPV( ST(r), l1 );
if( pos + l1 > len ) {
len = pos + l1 + 64;
Renew( tmp, len, char );
}
void
read_packet( this, separator, maxsize = 0 )
SV *this;
char *separator;
int maxsize;
PREINIT:
socket_class_t *sc;
int rlen, r;
char *rbuf;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
r = mod_sc_read_packet( sc, separator, (size_t) maxsize, &rbuf, &rlen );
if( r != SC_OK )
XSRETURN_EMPTY;
ST(0) = sv_2mortal( newSVpvn( rbuf, rlen ) );
XSRETURN(1);
#/*****************************************************************************
# * available( this )
# *****************************************************************************/
void
available( this )
SV *this;
PREINIT:
socket_class_t *sc;
int len;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_available( sc, &len ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_IV( (IV) len );
#/*****************************************************************************
# * pack_addr( this, addr [, port] )
# *****************************************************************************/
void
pack_addr( this, addr, ... )
SV *this;
SV *addr;
PREINIT:
socket_class_t *sc;
my_sockaddr_t saddr;
char *s1, *s2;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
s1 = SvPV_nolen( addr );
if( items > 2 )
s2 = SvPV_nolen( ST(2) );
else
s2 = NULL;
if( mod_sc_pack_addr( sc, s1, s2, &saddr ) != SC_OK )
XSRETURN_EMPTY;
ST(0) = sv_2mortal( newSVpvn( (char *) &saddr, SC_ADDR_SIZE(saddr) ) );
void
unpack_addr( this, paddr )
SV *this;
SV *paddr;
PREINIT:
socket_class_t *sc;
my_sockaddr_t *saddr;
STRLEN len;
char addr[NI_MAXHOST], port[NI_MAXSERV];
int addr_len = NI_MAXHOST, port_len = NI_MAXSERV, r;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
saddr = (my_sockaddr_t *) SvPVbyte( paddr, len );
if( len < sizeof( int ) || len != SC_ADDR_SIZE(*saddr) ) {
my_snprintf_(
sc->last_error, sizeof( sc->last_error ),
"Invalid address"
);
XSRETURN_EMPTY;
}
get_hostname( this, addr = NULL )
SV *this;
SV *addr;
PREINIT:
socket_class_t *sc;
my_sockaddr_t *saddr, sa2;
const char *s1 = NULL;
STRLEN l1;
char host[NI_MAXHOST];
int host_len = NI_MAXHOST;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( addr != NULL ) {
s1 = SvPV( addr, l1 );
saddr = (my_sockaddr_t *) s1;
if( l1 <= sizeof( int ) || l1 != SC_ADDR_SIZE(*saddr) ) {
if( mod_sc_pack_addr( sc, s1, NULL, &sa2 ) != SC_OK )
XSRETURN_EMPTY;
saddr = &sa2;
}
# *****************************************************************************/
void
get_hostaddr( this, name )
SV *this;
SV *name;
PREINIT:
socket_class_t *sc;
char addr[40];
int addr_len = 40, r;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
r = mod_sc_gethostbyname( sc, SvPV_nolen( name ), addr, &addr_len );
if( r != SC_OK )
XSRETURN_EMPTY;
ST(0) = sv_2mortal( newSVpvn( addr, addr_len ) );
XSRETURN(1);
#/*****************************************************************************
getaddrinfo( ... )
PREINIT:
socket_class_t *sc = NULL;
int ipos = 0, r;
sc_addrinfo_t aih;
sc_addrinfo_t *ail = NULL, *ai;
const char *host, *service;
HV *hv;
char tmp[40];
my_sockaddr_t saddr;
PPCODE:
if( items > 0 ) {
if( (sc = mod_sc_get_socket( ST(0) )) != NULL ) {
ipos ++;
}
else if(
SvPOK( ST(0) ) &&
strcmp( SvPV_nolen( ST(0) ), __PACKAGE__ ) == 0
) {
ipos ++;
}
void
getnameinfo( ... )
PREINIT:
socket_class_t *sc = NULL;
int ipos = 0, r, family = AF_UNSPEC, flags = 0;
char host[NI_MAXHOST], serv[NI_MAXSERV], *addr, *port = "";
my_sockaddr_t saddr, *psaddr;
sc_addrinfo_t aih, *ail = NULL;
STRLEN len;
PPCODE:
if( items > 0 ) {
if( (sc = mod_sc_get_socket( ST(0) )) != NULL ) {
ipos ++;
}
else if(
SvPOK( ST(0) ) &&
strcmp( SvPV_nolen( ST(0) ), __PACKAGE__ ) == 0
) {
ipos ++;
}
#/*****************************************************************************
# * set_blocking( this [, bool] )
# *****************************************************************************/
void
set_blocking( this, mode = 1 )
SV *this;
int mode;
PREINIT:
socket_class_t *sc;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_set_blocking( sc, mode ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * get_blocking( this )
# *****************************************************************************/
void
get_blocking( this )
SV *this;
PREINIT:
socket_class_t *sc;
int mode;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_get_blocking( sc, &mode ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_IV( mode );
#/*****************************************************************************
# * set_reuseaddr( this [, bool] )
# *****************************************************************************/
void
set_reuseaddr( this, mode = 1 )
SV *this;
int mode;
PREINIT:
socket_class_t *sc;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_set_reuseaddr( sc, mode ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * get_reuseaddr( this )
# *****************************************************************************/
void
get_reuseaddr( this )
SV *this;
PREINIT:
socket_class_t *sc;
int mode;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_get_reuseaddr( sc, &mode ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_IV( mode );
#/*****************************************************************************
# * set_broadcast( this [, bool] )
# *****************************************************************************/
void
set_broadcast( this, mode = 1 )
SV *this;
int mode;
PREINIT:
socket_class_t *sc;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_set_broadcast( sc, mode ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * get_broadcast( this )
# *****************************************************************************/
void
get_broadcast( this )
SV *this;
PREINIT:
socket_class_t *sc;
int mode;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_get_broadcast( sc, &mode ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_IV( mode );
#/*****************************************************************************
# * set_rcvbuf_size( this, size )
# *****************************************************************************/
void
set_rcvbuf_size( this, size )
SV *this;
int size;
PREINIT:
socket_class_t *sc;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_set_rcvbuf_size( sc, size ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * get_rcvbuf_size( this )
# *****************************************************************************/
void
get_rcvbuf_size( this )
SV *this;
PREINIT:
socket_class_t *sc;
int size;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_get_rcvbuf_size( sc, &size ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_IV( size );
#/*****************************************************************************
# * set_sndbuf_size( this, size )
# *****************************************************************************/
void
set_sndbuf_size( this, size )
SV *this;
int size;
PREINIT:
socket_class_t *sc;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_set_sndbuf_size( sc, size ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * get_sndbuf_size( this )
# *****************************************************************************/
void
get_sndbuf_size( this )
SV *this;
PREINIT:
socket_class_t *sc;
int size;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_get_sndbuf_size( sc, &size ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_IV( size );
#/*****************************************************************************
# * set_tcp_nodelay( this [, value] )
# *****************************************************************************/
void
set_tcp_nodelay( this, mode = 1 )
SV *this;
int mode;
PREINIT:
socket_class_t *sc;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_set_tcp_nodelay( sc, mode ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * get_tcp_nodelay( this )
# *****************************************************************************/
void
get_tcp_nodelay( this )
SV *this;
PREINIT:
socket_class_t *sc;
int mode;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_get_tcp_nodelay( sc, &mode ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_IV( mode );
#/*****************************************************************************
# * set_option( this, level, optname, value )
# *****************************************************************************/
SV *this;
int level;
int optname;
SV *value;
PREINIT:
socket_class_t *sc;
int r;
STRLEN len;
const void *val;
char tmp[20];
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( SvIOK( value ) && level == SOL_SOCKET ) {
switch( optname ) {
case SO_LINGER:
if( items > 4 ) {
((struct linger *) tmp)->l_onoff = (uint16_t) SvUV( value );
((struct linger *) tmp)->l_linger = (uint16_t) SvUV( ST(4) );
}
else {
void
get_option( this, level, optname )
SV *this;
int level;
int optname;
PREINIT:
socket_class_t *sc;
char tmp[20];
socklen_t l = sizeof( tmp );
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
l = sizeof( tmp );
if( mod_sc_getsockopt( sc, level, optname, tmp, &l ) != SC_OK )
XSRETURN_EMPTY;
if( level == SOL_SOCKET ) {
switch( optname ) {
case SO_LINGER:
XPUSHs( sv_2mortal(
newSVuv( ((struct linger *) tmp)->l_onoff ) ) );
#/*****************************************************************************
# * set_timeout( this, ms )
# *****************************************************************************/
void
set_timeout( this, ms )
SV *this;
double ms;
PREINIT:
socket_class_t *sc;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
sc->timeout.tv_sec = (long) (ms / 1000);
sc->timeout.tv_usec = (long) (ms * 1000) % 1000000;
XSRETURN_YES;
#/*****************************************************************************
# * get_timeout( this )
# *****************************************************************************/
void
get_timeout( this )
SV *this;
PREINIT:
socket_class_t *sc;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
XSRETURN_NV( sc->timeout.tv_sec * 1000 + sc->timeout.tv_usec / 1000 );
#/*****************************************************************************
# * is_readable( this [, timeout] )
# *****************************************************************************/
void
is_readable( this, timeout = NULL )
SV *this;
SV *timeout;
PREINIT:
socket_class_t *sc;
double ms;
int readable;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
ms = timeout != NULL ? SvNV( timeout ) : -1;
if( mod_sc_is_readable( sc, ms, &readable ) != SC_OK )
XSRETURN_EMPTY;
ST(0) = readable ? &PL_sv_yes : &PL_sv_no;
XSRETURN(1);
#/*****************************************************************************
# *****************************************************************************/
void
is_writable( this, timeout = NULL )
SV *this;
SV *timeout;
PREINIT:
socket_class_t *sc;
double ms;
int writable;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
ms = timeout != NULL ? SvNV( timeout ) : -1;
if( mod_sc_is_writable( sc, ms, &writable ) != SC_OK )
XSRETURN_EMPTY;
ST(0) = writable ? &PL_sv_yes : &PL_sv_no;
XSRETURN(1);
#/*****************************************************************************
select( this, read = NULL, write = NULL, except = NULL, timeout = NULL )
SV *this;
SV *read;
SV *write;
SV *except;
SV *timeout;
PREINIT:
socket_class_t *sc;
int dr, dw, de, vr, vw, ve;
double ms;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
vr = dr = read != NULL && SvTRUE( read );
vw = dw = write != NULL && SvTRUE( write );
ve = de = except != NULL && SvTRUE( except );
ms = timeout != NULL ? SvNV( timeout ) : -1;
if( mod_sc_select( sc, &vr, &vw, &ve, ms ) != SC_OK )
XSRETURN_EMPTY;
if( dr && ! SvREADONLY( read ) )
sv_setiv( read, vr );
#/*****************************************************************************
# * wait( this, timeout )
# *****************************************************************************/
void
wait( this, timeout )
SV *this;
double timeout;
PPCODE:
if( this != NULL ) {} /* avoid compiler warning */
mod_sc_sleep( timeout );
#/*****************************************************************************
# * handle( this )
# *****************************************************************************/
void
handle( this )
SV *this;
PREINIT:
socket_class_t *sc;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
ST(0) = sv_2mortal( newSViv( sc->sock ) );
XSRETURN( 1 );
#/*****************************************************************************
# * state( this )
# *****************************************************************************/
void
state( this )
SV *this;
PREINIT:
socket_class_t *sc;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
ST(0) = sv_2mortal( newSViv( sc->state ) );
XSRETURN( 1 );
#/*****************************************************************************
# * local_addr( this )
# *****************************************************************************/
void
local_addr( this )
SV *this;
PREINIT:
socket_class_t *sc;
char host[NI_MAXHOST], serv[NI_MAXSERV];
int r, host_len = NI_MAXHOST, serv_len = NI_MAXSERV;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
r = mod_sc_unpack_addr( sc, &sc->l_addr, host, &host_len, serv, &serv_len );
if( r != SC_OK )
XSRETURN_EMPTY;
ST(0) = sv_2mortal( newSVpvn( host, host_len ) );
XSRETURN(1);
#/*****************************************************************************
# * local_path( this )
# *****************************************************************************/
void
local_path( this )
SV *this;
PREINIT:
socket_class_t *sc;
char *s1;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
switch( sc->s_domain ) {
case AF_UNIX:
s1 = ((struct sockaddr_un *) sc->l_addr.a )->sun_path;
ST(0) = sv_2mortal( newSVpvn( s1, strlen( s1 ) ) );
break;
default:
ST(0) = &PL_sv_undef;
}
# *****************************************************************************/
void
local_port( this )
SV *this;
PREINIT:
PREINIT:
socket_class_t *sc;
char host[NI_MAXHOST], serv[NI_MAXSERV];
int r, host_len = NI_MAXHOST, serv_len = NI_MAXSERV;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
r = mod_sc_unpack_addr( sc, &sc->l_addr, host, &host_len, serv, &serv_len );
if( r != SC_OK )
XSRETURN_EMPTY;
ST(0) = sv_2mortal( newSVpvn( serv, serv_len ) );
XSRETURN(1);
#/*****************************************************************************
# * remote_addr( this )
# *****************************************************************************/
void
remote_addr( this )
SV *this;
PREINIT:
socket_class_t *sc;
char host[NI_MAXHOST], serv[NI_MAXSERV];
int r, host_len = NI_MAXHOST, serv_len = NI_MAXSERV;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
r = mod_sc_unpack_addr( sc, &sc->r_addr, host, &host_len, serv, &serv_len );
if( r != SC_OK )
XSRETURN_EMPTY;
ST(0) = sv_2mortal( newSVpvn( host, host_len ) );
XSRETURN(1);
#/*****************************************************************************
# * remote_path( this )
# *****************************************************************************/
void
remote_path( this )
SV *this;
PREINIT:
socket_class_t *sc;
char *s1;
PPCODE:
if( (sc = socket_class_find( this )) == NULL )
XSRETURN_EMPTY;
switch( sc->s_domain ) {
case AF_UNIX:
s1 = ((struct sockaddr_un *) sc->r_addr.a )->sun_path;
ST(0) = sv_2mortal( newSVpvn( s1, strlen( s1 ) ) );
break;
default:
ST(0) = &PL_sv_undef;
}
# * remote_port( this )
# *****************************************************************************/
void
remote_port( this )
SV *this;
PREINIT:
socket_class_t *sc;
char host[NI_MAXHOST], serv[NI_MAXSERV];
int r, host_len = NI_MAXHOST, serv_len = NI_MAXSERV;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
r = mod_sc_unpack_addr( sc, &sc->r_addr, host, &host_len, serv, &serv_len );
if( r != SC_OK )
XSRETURN_EMPTY;
ST(0) = sv_2mortal( newSVpvn( serv, serv_len ) );
XSRETURN(1);
#/*****************************************************************************
# * to_string( this )
# *****************************************************************************/
void
to_string( this )
SV *this;
PREINIT:
socket_class_t *sc;
char tmp[1024];
size_t len = sizeof(tmp);
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_to_string( sc, tmp, &len ) != SC_OK )
XSRETURN_EMPTY;
ST(0) = sv_2mortal( newSVpvn( tmp, len ) );
XSRETURN(1);
#/*****************************************************************************
# * is_error( this )
# *****************************************************************************/
void
is_error( this )
SV *this;
PREINIT:
socket_class_t *sc;
PPCODE:
if( (sc = mod_sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
ST(0) = (sc->state == SC_STATE_ERROR) ? &PL_sv_yes : &PL_sv_no;
XSRETURN(1);
#/*****************************************************************************
# * errno( this )
# *****************************************************************************/
void
errno( this )
SV *this;
PREINIT:
socket_class_t *sc;
PPCODE:
sc = mod_sc_get_socket( this );
XSRETURN_IV( mod_sc_get_errno( sc ) );
#/*****************************************************************************
# * error( this [, code] )
# *****************************************************************************/
void
error( this, code = 0 )
SV *this;
int code;
PREINIT:
socket_class_t *sc;
const char *msg;
PPCODE:
sc = mod_sc_get_socket( this );
if( code != 0 )
mod_sc_set_errno( sc, code );
msg = mod_sc_get_error( sc );
ST(0) = sv_2mortal( newSVpvn( msg, strlen( msg ) ) );
XSRETURN(1);
xs/sc_const/Const.xs view on Meta::CPAN
export( package, ... )
SV *package;
PREINIT:
int i, make_var;
char *str, *pkg, *tmp = NULL;
const char *s2;
STRLEN len, pkg_len;
HV *stash;
SV *sv;
const export_item_t *item;
PPCODE:
pkg = SvPV( package, pkg_len );
stash = gv_stashpvn( pkg, (I32) pkg_len, TRUE );
Newx( tmp, pkg_len + 3, char );
Copy( pkg, tmp, pkg_len, char );
tmp[pkg_len ++] = ':';
tmp[pkg_len ++] = ':';
for( i = 1; i < items; i ++ ) {
s2 = str = SvPV( ST(i), len );
switch( *str ) {
case ':':
xs/sc_ssl/SSL.pod view on Meta::CPAN
g_mod_sc_ssl = INT2PTR(mod_sc_ssl_t *, SvIV(*psv));
}
void
test()
PREINIT:
sc_t *socket;
char *args[8];
int r;
SV *sv;
PPCODE:
args[0] = "local_port";
args[1] = "443";
args[2] = "listen";
args[3] = "10";
args[4] = "private_key";
args[5] = "/path/to/private_key.pem";
args[6] = "certificate";
args[7] = "/path/to/certificate.pem";
r = g_mod_sc_ssl->sc_create(args, 8, &socket);
if (r != SC_OK)
xs/sc_ssl/SSL.xs view on Meta::CPAN
#ifdef USE_ITHREADS
MUTEX_INIT( &sc_ssl_global.thread_lock );
#endif
}
#/*****************************************************************************
# * SSL_c_module()
# *****************************************************************************/
void
SSL_c_module( ... )
PPCODE:
/* returns the c module interface */
XSRETURN_IV( PTR2IV( &mod_sc_ssl ) );
#/*****************************************************************************
# * SSL_END()
# *****************************************************************************/
void
SSL_END( ... )
xs/sc_ssl/SSL.xs view on Meta::CPAN
# * SSL_CLONE()
# *****************************************************************************/
#ifdef USE_ITHREADS
void
SSL_CLONE( ... )
PREINIT:
sc_ssl_ctx_t *ctx;
int i;
PPCODE:
(void) items; /* avoid compiler warning */
MUTEX_LOCK( &sc_ssl_global.thread_lock );
for( i = 0; i <= SC_SSL_CTX_CASCADE; i ++ ) {
for( ctx = sc_ssl_global.ctx[i]; ctx != NULL; ctx = ctx->next ) {
/*if( !ctx->dont_clone )*/
ctx->refcnt ++;
#ifdef SC_DEBUG
_debug( "CLONE called for ctx %d, refcnt: %d\n", ctx->id, ctx->refcnt );
#endif
}
xs/sc_ssl/SSL.xs view on Meta::CPAN
# *****************************************************************************/
void
SSL_new( pkg, ... )
SV *pkg;
PREINIT:
sc_t *socket;
int r, i, argc = 0;
SV *sv;
char **args, *key, *val;
PPCODE:
Newx( args, items - 1, char * );
/* read options */
for( i = 1; i < items - 1; ) {
key = SvPV_nolen( ST(i) );
i++;
switch( *key ) {
case 'u':
case 'U':
if( my_stricmp( key, "use_ctx" ) == 0 ) {
val = (char *) mod_sc_ssl_ctx_from_class( ST(i) );
xs/sc_ssl/SSL.xs view on Meta::CPAN
# * SSL_connect( this, host, serv, timeout )
# *****************************************************************************/
void
SSL_connect( this, ... )
SV *this;
PREINIT:
sc_t *socket;
const char *ra = NULL, *rp = NULL;
double ms = 0;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
switch( mod_sc->sc_get_family( socket ) ) {
case AF_INET:
case AF_INET6:
default:
switch( items ) {
case 4:
default:
if( SvNOK( ST(3) ) || SvIOK( ST(3) ) )
xs/sc_ssl/SSL.xs view on Meta::CPAN
#/*****************************************************************************
# * SSL_listen( this [, queue] )
# *****************************************************************************/
void
SSL_listen( this, queue = SOMAXCONN )
SV *this;
int queue;
PREINIT:
sc_t *socket;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_listen( socket, queue ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * SSL_accept( this [, pkg] )
# *****************************************************************************/
void
SSL_accept( this, pkg = NULL )
SV *this;
char *pkg;
PREINIT:
sc_t *socket, *client;
SV *sv;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_accept( socket, &client ) != SC_OK )
XSRETURN_EMPTY;
if( client == NULL )
XSRETURN_NO;
if( mod_sc->sc_create_class( client, pkg, &sv ) != SC_OK ) {
mod_sc->sc_set_error( socket,
mod_sc->sc_get_errno( client ), mod_sc->sc_get_error( client ) );
mod_sc->sc_destroy( client );
xs/sc_ssl/SSL.xs view on Meta::CPAN
void
SSL_recv( this, buf, len, flags = 0 )
SV *this;
SV *buf;
unsigned int len;
unsigned int flags;
PREINIT:
sc_t *socket;
userdata_t *ud;
int rlen;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
ud = (userdata_t *) mod_sc->sc_get_userdata( socket );
if( ud->buffer_len < (int) len ) {
ud->buffer_len = (int) len;
Renew( ud->buffer, len, char );
}
if( mod_sc_ssl_recv( socket, ud->buffer, len, flags, &rlen ) != SC_OK )
XSRETURN_EMPTY;
if( rlen == 0 )
xs/sc_ssl/SSL.xs view on Meta::CPAN
void
SSL_send( this, buf, flags = 0 )
SV *this;
SV *buf;
unsigned int flags;
PREINIT:
sc_t *socket;
const char *msg;
STRLEN len;
int rlen;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
msg = SvPV( buf, len );
if( mod_sc_ssl_send( socket, msg, (int) len, flags, &rlen ) != SC_OK )
XSRETURN_EMPTY;
if( rlen == 0 )
XSRETURN_NO;
XSRETURN_IV( rlen );
xs/sc_ssl/SSL.xs view on Meta::CPAN
SSL_recvfrom( this, buf, len, flags = 0 )
SV *this;
SV *buf;
unsigned int len;
unsigned int flags;
PREINIT:
sc_t *socket;
userdata_t *ud;
sc_addr_t addr;
int r, rlen;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
ud = mod_sc->sc_get_userdata( socket );
if( ud->buffer_len < (int) len ) {
ud->buffer_len = (int) len;
Renew( ud->buffer, len, char );
}
r = mod_sc_ssl_recvfrom( socket, ud->buffer, (int) len, flags, &rlen );
if( r != SC_OK )
XSRETURN_EMPTY;
xs/sc_ssl/SSL.xs view on Meta::CPAN
SV *this;
SV *buf;
SV *to;
unsigned int flags;
PREINIT:
sc_t *socket;
const char *msg;
STRLEN len;
sc_addr_t *peer = NULL;
int rlen, r;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( to != NULL && SvPOK( to ) ) {
peer = (sc_addr_t *) SvPVbyte( to, len );
if( len < sizeof( int ) || len != SC_ADDR_SIZE( *peer ) ) {
mod_sc->sc_set_error( socket, -9999, "Invalid address" );
XSRETURN_EMPTY;
}
}
msg = SvPV( buf, len );
xs/sc_ssl/SSL.xs view on Meta::CPAN
void
SSL_read( this, buf, len )
SV *this;
SV *buf;
int len;
PREINIT:
sc_t *socket;
userdata_t *ud;
int rlen;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
ud = (userdata_t *) mod_sc->sc_get_userdata( socket );
if( ud->buffer_len < len ) {
ud->buffer_len = len;
Renew( ud->buffer, len, char );
}
if( mod_sc_ssl_read( socket, ud->buffer, len, &rlen ) != SC_OK )
XSRETURN_EMPTY;
if( rlen == 0 )
xs/sc_ssl/SSL.xs view on Meta::CPAN
void
SSL_write( this, buf, ... )
SV *this;
SV *buf;
PREINIT:
sc_t *socket;
const char *msg;
STRLEN l1;
int start = 0, len, max, l2;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
msg = SvPV( buf, l1 );
max = len = (int) l1;
if( items > 2 ) {
start = (int) SvIV( ST(2) );
if( start < 0 ) {
start += max;
if( start < 0 )
start = 0;
xs/sc_ssl/SSL.xs view on Meta::CPAN
void
SSL_readline( this, separator = NULL, maxsize = 0 )
SV *this;
char *separator;
int maxsize;
PREINIT:
sc_t *socket;
int rlen, r;
char *rbuf;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( separator != NULL ) {
r = mod_sc_ssl_read_packet(
socket, separator, (size_t) maxsize, &rbuf, &rlen );
if( r != SC_OK )
XSRETURN_EMPTY;
}
else {
if( mod_sc_ssl_readline( socket, &rbuf, &rlen ) != SC_OK )
xs/sc_ssl/SSL.xs view on Meta::CPAN
void
SSL_writeline( this, buf )
SV *this;
SV *buf;
PREINIT:
sc_t *socket;
const char *msg;
STRLEN len;
int rlen;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
msg = SvPVx( buf, len );
if( mod_sc_ssl_writeln( socket, msg, (int) len, &rlen ) != SC_OK )
XSRETURN_EMPTY;
if( rlen == 0 )
XSRETURN_NO;
XSRETURN_IV( rlen );
xs/sc_ssl/SSL.xs view on Meta::CPAN
void
SSL_print( this, ... )
SV *this;
PREINIT:
sc_t *socket;
const char *s1;
char *tmp = NULL;
STRLEN l1, len = 0, pos = 0;
int r, rlen;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
for( r = 1; r < items; r ++ ) {
if( ! SvOK( ST(r) ) )
continue;
s1 = SvPVx( ST(r), l1 );
if( pos + l1 > len ) {
len = pos + l1 + 64;
Renew( tmp, len, char );
}
xs/sc_ssl/SSL.xs view on Meta::CPAN
void
SSL_read_packet( this, separator, maxsize = 0 )
SV *this;
char *separator;
int maxsize;
PREINIT:
sc_t *socket;
int rlen, r;
char *rbuf;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
r = mod_sc_ssl_read_packet(
socket, separator, (size_t) maxsize, &rbuf, &rlen );
if( r != SC_OK )
XSRETURN_EMPTY;
ST(0) = sv_2mortal( newSVpvn( rbuf, rlen ) );
XSRETURN(1);
xs/sc_ssl/SSL.xs view on Meta::CPAN
# *****************************************************************************/
void
SSL_to_string( this )
SV *this;
PREINIT:
sc_t *socket;
char tmp[1024], *s;
size_t len = sizeof(tmp);
userdata_t *ud;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc->sc_to_string( socket, tmp, &len ) != SC_OK )
XSRETURN_EMPTY;
ud = (userdata_t *) mod_sc->sc_get_userdata( socket );
s = tmp + len - 1;
if( ud->ssl != NULL ) {
s = my_strcpy( s, ";SSL=" );
s = my_strcpy( s, SSL_get_version( ud->ssl ) );
}
xs/sc_ssl/SSL.xs view on Meta::CPAN
#/*****************************************************************************
# * SSL_set_private_key( this, private_key )
# *****************************************************************************/
void
SSL_set_private_key( this, private_key )
SV *this;
char *private_key;
PREINIT:
sc_t *socket;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_set_private_key( socket, private_key ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * SSL_set_certificate( this, certificate )
# *****************************************************************************/
void
SSL_set_certificate( this, certificate )
SV *this;
char *certificate;
PREINIT:
sc_t *socket;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_set_certificate( socket, certificate ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * SSL_set_client_ca( this, client_ca )
# *****************************************************************************/
void
SSL_set_client_ca( this, client_ca )
SV *this;
char *client_ca;
PREINIT:
sc_t *socket;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_set_client_ca( socket, client_ca ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * SSL_set_verify_locations( this, ca_file [, ca_path] )
# *****************************************************************************/
void
SSL_set_verify_locations( this, ca_file, ca_path = NULL )
SV *this;
SV *ca_file;
SV *ca_path;
PREINIT:
sc_t *socket;
char *caf, *cap;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
caf = SvPOK( ca_file ) ? SvPV_nolen( ca_file ) : NULL;
cap = ca_path != NULL && SvPOK( ca_path ) ? SvPV_nolen( ca_path ) : NULL;
if( mod_sc_ssl_set_verify_locations( socket, caf, cap ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * SSL_create_client_context( this )
# *****************************************************************************/
void
SSL_create_client_context( this )
SV *this;
PREINIT:
sc_t *socket;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_create_client_context( socket ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * SSL_create_server_context( this )
# *****************************************************************************/
void
SSL_create_server_context( this )
SV *this;
PREINIT:
sc_t *socket;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_create_server_context( socket ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * SSL_check_private_key( this )
# *****************************************************************************/
void
SSL_check_private_key( this )
SV *this;
PREINIT:
sc_t *socket;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_check_private_key( socket ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * SSL_enable_compatibility( this )
# *****************************************************************************/
void
SSL_enable_compatibility( this )
SV *this;
PREINIT:
sc_t *socket;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_enable_compatibility( socket ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * SSL_get_cipher_name( this )
# *****************************************************************************/
void
SSL_get_cipher_name( this )
SV *this;
PREINIT:
sc_t *socket;
const char *s;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
s = mod_sc_ssl_get_cipher_name( socket );
if( s == NULL )
XSRETURN_EMPTY;
ST(0) = sv_2mortal( newSVpvn( s, strlen( s ) ) );
XSRETURN_EMPTY;
#/*****************************************************************************
# * SSL_get_cipher_version( this )
# *****************************************************************************/
void
SSL_get_cipher_version( this )
SV *this;
PREINIT:
sc_t *socket;
const char *s;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
s = mod_sc_ssl_get_cipher_version( socket );
if( s == NULL )
XSRETURN_EMPTY;
ST(0) = sv_2mortal( newSVpvn( s, strlen( s ) ) );
XSRETURN_EMPTY;
#/*****************************************************************************
# * SSL_get_ssl_version( this )
# *****************************************************************************/
void
SSL_get_ssl_version( this )
SV *this;
PREINIT:
sc_t *socket;
const char *s;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
s = mod_sc_ssl_get_version( socket );
if( s == NULL )
XSRETURN_EMPTY;
ST(0) = sv_2mortal( newSVpvn( s, strlen( s ) ) );
XSRETURN_EMPTY;
#/*****************************************************************************
xs/sc_ssl/SSL.xs view on Meta::CPAN
void
SSL_starttls( pkg, this, ... )
SV *pkg;
SV *this;
PREINIT:
sc_t *socket;
SV *sv;
char **args, *key, *val;
int argc = 0, i, r;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
Newx( args, items - 1, char * );
/* read options */
for( i = 2; i < items - 1; ) {
key = SvPV_nolen( ST(i) );
i++;
switch( *key ) {
case 'u':
case 'U':
xs/sc_ssl/SSL.xs view on Meta::CPAN
#/*****************************************************************************
# * SSL_set_ssl_method( this, name )
# *****************************************************************************/
void
SSL_set_ssl_method( this, name )
SV *this;
char *name;
PREINIT:
sc_t *socket;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_set_ssl_method( socket, name ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * SSL_set_cipher_list( this, str )
# *****************************************************************************/
void
SSL_set_cipher_list( this, str )
SV *this;
char *str;
PREINIT:
sc_t *socket;
PPCODE:
if( (socket = mod_sc->sc_get_socket( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_set_cipher_list( socket, str ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*############################### SSL CONTEXT ###############################*/
xs/sc_ssl/SSL.xs view on Meta::CPAN
# *****************************************************************************/
void
CTX_new( pkg, ... )
char *pkg;
PREINIT:
sc_ssl_ctx_t *ctx;
int r, i, argc = 0;
SV *sv;
char **args;
PPCODE:
(void) pkg; /* unused */
Newx( args, items - 1, char * );
/* read options */
for( i = 1; i < items - 1; ) {
args[argc ++] = SvPV_nolen( ST(i) );
i ++;
args[argc ++] = SvPV_nolen( ST(i) );
i ++;
}
r = mod_sc_ssl_ctx_create( args, argc, &ctx );
xs/sc_ssl/SSL.xs view on Meta::CPAN
#/*****************************************************************************
# * CTX_DESTROY( this, ... )
# *****************************************************************************/
void
CTX_DESTROY( this, ... )
SV *this;
PREINIT:
sc_ssl_ctx_t *ctx;
PPCODE:
if( (ctx = mod_sc_ssl_ctx_from_class( this )) == NULL )
XSRETURN_EMPTY;
/*
#ifdef USE_ITHREADS
if( !ctx->dont_clone && ctx->thread_id == THREAD_ID() ) {
ctx->dont_clone = TRUE;
#ifdef SC_DEBUG
_debug( "disable futher CLONE for ctx %d\n", ctx->id );
#endif
}
xs/sc_ssl/SSL.xs view on Meta::CPAN
#/*****************************************************************************
# * CTX_set_ssl_method( this, name )
# *****************************************************************************/
void
CTX_set_ssl_method( this, name )
SV *this;
char *name;
PREINIT:
sc_ssl_ctx_t *ctx;
PPCODE:
if( (ctx = mod_sc_ssl_ctx_from_class( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_ctx_set_ssl_method( ctx, name ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * CTX_set_private_key( this, pk )
# *****************************************************************************/
void
CTX_set_private_key( this, pk )
SV *this;
char *pk;
PREINIT:
sc_ssl_ctx_t *ctx;
PPCODE:
if( (ctx = mod_sc_ssl_ctx_from_class( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_ctx_set_private_key( ctx, pk ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * CTX_set_certificate( this, crt )
# *****************************************************************************/
void
CTX_set_certificate( this, crt )
SV *this;
char *crt;
PREINIT:
sc_ssl_ctx_t *ctx;
PPCODE:
if( (ctx = mod_sc_ssl_ctx_from_class( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_ctx_set_certificate( ctx, crt ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * CTX_set_client_ca( this, client_ca )
# *****************************************************************************/
void
CTX_set_client_ca( this, client_ca )
SV *this;
char *client_ca;
PREINIT:
sc_ssl_ctx_t *ctx;
PPCODE:
if( (ctx = mod_sc_ssl_ctx_from_class( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_ctx_set_client_ca( ctx, client_ca ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * CTX_set_verify_locations( this, ca_file )
# *****************************************************************************/
void
CTX_set_verify_locations( this, ca_file, ca_path = NULL )
SV *this;
char *ca_file;
char *ca_path;
PREINIT:
sc_ssl_ctx_t *ctx;
PPCODE:
if( (ctx = mod_sc_ssl_ctx_from_class( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_ctx_set_verify_locations( ctx, ca_file, ca_path ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * CTX_set_cipher_list( this, str )
# *****************************************************************************/
void
CTX_set_cipher_list( this, str )
SV *this;
char *str;
PREINIT:
sc_ssl_ctx_t *ctx;
PPCODE:
if( (ctx = mod_sc_ssl_ctx_from_class( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_ctx_set_cipher_list( ctx, str ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * CTX_check_private_key( this )
# *****************************************************************************/
void
CTX_check_private_key( this )
SV *this;
PREINIT:
sc_ssl_ctx_t *ctx;
PPCODE:
if( (ctx = mod_sc_ssl_ctx_from_class( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_ctx_check_private_key( ctx ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
#/*****************************************************************************
# * CTX_enable_compatibility( this )
# *****************************************************************************/
void
CTX_enable_compatibility( this )
SV *this;
PREINIT:
sc_ssl_ctx_t *ctx;
PPCODE:
if( (ctx = mod_sc_ssl_ctx_from_class( this )) == NULL )
XSRETURN_EMPTY;
if( mod_sc_ssl_ctx_enable_compatibility( ctx ) != SC_OK )
XSRETURN_EMPTY;
XSRETURN_YES;
xs/sc_ssl/openssl/source/crypto/des/DES.xs view on Meta::CPAN
MODULE = DES PACKAGE = DES PREFIX = des_
char *
des_crypt(buf,salt)
char * buf
char * salt
void
des_set_odd_parity(key)
des_cblock * key
PPCODE:
{
SV *s;
s=sv_newmortal();
sv_setpvn(s,(char *)key,8);
des_set_odd_parity((des_cblock *)SvPV(s,na));
PUSHs(s);
}
int
xs/sc_ssl/openssl/source/crypto/des/DES.xs view on Meta::CPAN
des_ecb_encrypt(input,&RETVAL,*ks,encrypt);
OUTPUT:
RETVAL
void
des_cbc_encrypt(input,ks,ivec,encrypt)
char * input
des_key_schedule * ks
des_cblock * ivec
int encrypt
PPCODE:
{
SV *s;
STRLEN len,l;
char *c;
l=SvCUR(ST(0));
len=((((unsigned long)l)+7)/8)*8;
s=sv_newmortal();
sv_setpvn(s,"",0);
SvGROW(s,len);
xs/sc_ssl/openssl/source/crypto/des/DES.xs view on Meta::CPAN
}
void
des_cbc3_encrypt(input,ks1,ks2,ivec1,ivec2,encrypt)
char * input
des_key_schedule * ks1
des_key_schedule * ks2
des_cblock * ivec1
des_cblock * ivec2
int encrypt
PPCODE:
{
SV *s;
STRLEN len,l;
l=SvCUR(ST(0));
len=((((unsigned long)l)+7)/8)*8;
s=sv_newmortal();
sv_setpvn(s,"",0);
SvGROW(s,len);
SvCUR_set(s,len);
xs/sc_ssl/openssl/source/crypto/des/DES.xs view on Meta::CPAN
sv_setpvn(ST(3),(char *)ivec1,8);
sv_setpvn(ST(4),(char *)ivec2,8);
PUSHs(s);
}
void
des_cbc_cksum(input,ks,ivec)
char * input
des_key_schedule * ks
des_cblock * ivec
PPCODE:
{
SV *s1,*s2;
STRLEN len,l;
des_cblock c;
unsigned long i1,i2;
s1=sv_newmortal();
s2=sv_newmortal();
l=SvCUR(ST(0));
des_cbc_cksum((des_cblock *)input,(des_cblock *)c,
xs/sc_ssl/openssl/source/crypto/des/DES.xs view on Meta::CPAN
PUSHs(s2);
}
void
des_cfb_encrypt(input,numbits,ks,ivec,encrypt)
char * input
int numbits
des_key_schedule * ks
des_cblock * ivec
int encrypt
PPCODE:
{
SV *s;
STRLEN len;
char *c;
len=SvCUR(ST(0));
s=sv_newmortal();
sv_setpvn(s,"",0);
SvGROW(s,len);
SvCUR_set(s,len);
xs/sc_ssl/openssl/source/crypto/des/DES.xs view on Meta::CPAN
}
OUTPUT:
RETVAL
void
des_ofb_encrypt(input,numbits,ks,ivec)
unsigned char * input
int numbits
des_key_schedule * ks
des_cblock * ivec
PPCODE:
{
SV *s;
STRLEN len,l;
unsigned char *c;
len=SvCUR(ST(0));
s=sv_newmortal();
sv_setpvn(s,"",0);
SvGROW(s,len);
SvCUR_set(s,len);
xs/sc_ssl/openssl/source/crypto/des/DES.xs view on Meta::CPAN
sv_setpvn(ST(3),(char *)ivec,8);
PUSHs(s);
}
void
des_pcbc_encrypt(input,ks,ivec,encrypt)
char * input
des_key_schedule * ks
des_cblock * ivec
int encrypt
PPCODE:
{
SV *s;
STRLEN len,l;
char *c;
l=SvCUR(ST(0));
len=((((unsigned long)l)+7)/8)*8;
s=sv_newmortal();
sv_setpvn(s,"",0);
SvGROW(s,len);
xs/sc_ssl/openssl/source/crypto/des/DES.xs view on Meta::CPAN
des_string_to_key(str,&c);
RETVAL=&c;
}
OUTPUT:
RETVAL
void
des_string_to_2keys(str)
char * str
PPCODE:
{
des_cblock c1,c2;
SV *s1,*s2;
des_string_to_2keys(str,&c1,&c2);
EXTEND(sp,2);
s1=sv_newmortal();
sv_setpvn(s1,(char *)c1,8);
s2=sv_newmortal();
sv_setpvn(s2,(char *)c2,8);