Merge branch 'master' of ssh://askele.com/libsntl

v0.5.xx
Eugen Tarasov 10 years ago
commit 23d26fe5b8

6
.gitignore vendored

@ -52,3 +52,9 @@ coq
lib/libsntllv2.pc lib/libsntllv2.pc
lv2sd lv2sd
lv2sc lv2sc
debian/substvars
tests/*.xml
tests/lv2ftpd
tests/lv2ftpc
tests/*.cfg
debian/libsntl.substvars

@ -1,6 +0,0 @@
libsntl for Debian
-------------------
<possible notes regarding this package - if none, delete this file>
-- Alexander Vdolainen <vdo@daze> Mon, 24 Nov 2014 11:52:48 +0200

@ -1,9 +0,0 @@
libsntl for Debian
-------------------
<this file describes information about the source package, see Debian policy
manual section 4.14. You WILL either need to modify or delete this file>

8
debian/changelog vendored

@ -4,24 +4,24 @@ libsntl (0.3.0) stable; urgency=high
* Performance tricks * Performance tricks
* Long messages * Long messages
* Extended API * Extended API
* It's incompatible with 0.2.xx and below by protocol * Manual pages added
-- Alexander Vdolainen <vdo@askele.com> Thu, 16 Jul 2015 22:50:32 +0200 -- Alexander Vdolainen <vdo@askele.com> Thu, 16 Jul 2015 22:50:32 +0200
libsntl (0.2.1) stable; urgency=low libsntl (0.2.1) stable; urgency=low
* Initial release (Closes: #nnnn) <nnnn is the bug number of your ITP> * Initial release
-- Alexander Vdolainen <vdo@askele.com> Thu, 11 Jun 2015 03:37:48 +0200 -- Alexander Vdolainen <vdo@askele.com> Thu, 11 Jun 2015 03:37:48 +0200
libsntl (0.2.0) stable; urgency=low libsntl (0.2.0) stable; urgency=low
* Initial release (Closes: #nnnn) <nnnn is the bug number of your ITP> * Initial release
-- Alexander Vdolainen <vdo@askele.com> Thu, 04 Jun 2015 16:00:00 +0200 -- Alexander Vdolainen <vdo@askele.com> Thu, 04 Jun 2015 16:00:00 +0200
libsntl (0.1.0) stable; urgency=low libsntl (0.1.0) stable; urgency=low
* Initial release (Closes: #nnnn) <nnnn is the bug number of your ITP> * Initial release
-- Alexander Vdolainen <vdo@askele.com> Mon, 24 Nov 2014 11:52:48 +0200 -- Alexander Vdolainen <vdo@askele.com> Mon, 24 Nov 2014 11:52:48 +0200

1
debian/compat vendored

@ -0,0 +1 @@
7

40
debian/copyright vendored

@ -1,38 +1,12 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: libsntl Upstream-Name: libsntl
Source: <url://example.com> Source: <url://askele.com>
Files: * Files: *
Copyright: <years> <put author's name and email here> Copyright: 2015 Askele Group
<years> <likewise for another author> 2014 Askele Oy
License: <special license> License: Askele PL
<Put the license of the package here indented by 1 space> Askele Group Proprietary License 1.0
<This follows the format of Description: lines in control file> Not allow any distrbution without license
. .
<Including paragraphs> No warrantly
# If you want to use GPL v2 or later for the /debian/* files use
# the following clauses, or change it to suit. Delete these two lines
Files: debian/*
Copyright: 2014 Alexander Vdolainen <vdo@daze>
License: GPL-2+
This package is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
.
This package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
.
On Debian systems, the complete text of the GNU General
Public License version 2 can be found in "/usr/share/common-licenses/GPL-2".
# Please also look if there are files or directories which have a
# different copyright/license attached and list them here.
# Please avoid to pick license terms that are more restrictive than the
# packaged work, as it may make Debian's contributions unacceptable upstream.

@ -1,50 +0,0 @@
dh_autotools-dev_updateconfig
dh_auto_configure
dh_auto_build
dh_auto_test
dh_prep
dh_installdirs
dh_auto_install
dh_install
dh_installdocs
dh_installchangelogs
dh_installexamples
dh_installman
dh_installcatalogs
dh_installcron
dh_installdebconf
dh_installemacsen
dh_installifupdown
dh_installinfo
dh_pysupport
dh_installinit
dh_installmenu
dh_installmime
dh_installmodules
dh_installlogcheck
dh_installlogrotate
dh_installpam
dh_installppp
dh_installudev
dh_installwm
dh_installxfonts
dh_installgsettings
dh_bugfiles
dh_ucf
dh_lintian
dh_gconf
dh_icons
dh_perl
dh_usrlocal
dh_link
dh_compress
dh_fixperms
dh_strip
dh_makeshlibs
dh_shlibdeps
dh_installdeb
dh_gencontrol
dh_md5sums
dh_builddeb
dh_builddeb
dh_builddeb

@ -1,4 +1,5 @@
usr/lib usr/lib
usr/include usr/include
usr/include/sntl
usr/share/man usr/share/man
usr/share/man/man3 usr/share/man/man3

@ -1,5 +1,5 @@
usr/include/* usr/include/sntl/*.h
usr/lib/lib*.a usr/lib/libsntl*.a
usr/lib/lib*.so usr/lib/libsntl*.la
usr/lib/pkgconfig/* usr/lib/pkgconfig/*
usr/share/man/man3/* usr/share/man/man3/*

@ -1,10 +1,29 @@
man/sxmsg_rreply.3 man/connection_close.3
man/connection_link.3
man/connection_master_link.3
man/connections_create.3 man/connections_create.3
man/connections_destroy.3 man/connections_destroy.3
man/connections_free.3 man/connections_free.3
man/connections_get_priv.3
man/connections_init.3 man/connections_init.3
man/sntl_init.3 man/connections_set_authcheck.3
man/connections_setsslserts.3 man/connections_set_channelcall.3
man/connections_set_ondestroy.3
man/connections_set_onpulse.3
man/connections_set_priv.3 man/connections_set_priv.3
man/connections_get_priv.3 man/connections_set_rpcvalidator.3
man/connections_set_ondestroy.3 man/connections_setsslserts.3
man/connections_set_sslvalidate.3
man/sntl_finalize.3
man/sntl_init.3
man/sxchannel_close.3
man/sxchannel_open.3
man/sxmsg_clean.3
man/sxmsg_pulse.3
man/sxmsg_reply.3
man/sxmsg_reply_pp.3
man/sxmsg_return.3
man/sxmsg_return_pp.3
man/sxmsg_rreply.3
man/sxmsg_send.3
man/sxmsg_send_pp.3

@ -1 +1 @@
usr/lib/lib*.so.* usr/lib/libsntl.so.*

@ -1,2 +0,0 @@
shlibs:Depends=libc6 (>= 2.2.5), libsexpr, libssl1.0.0 (>= 1.0.1), libtdata, libuuid1 (>= 2.20.1)
misc:Depends=

39
debian/postinst.ex vendored

@ -1,39 +0,0 @@
#!/bin/sh
# postinst script for libsntl
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
case "$1" in
configure)
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0

37
debian/postrm.ex vendored

@ -1,37 +0,0 @@
#!/bin/sh
# postrm script for libsntl
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <postrm> `remove'
# * <postrm> `purge'
# * <old-postrm> `upgrade' <new-version>
# * <new-postrm> `failed-upgrade' <old-version>
# * <new-postrm> `abort-install'
# * <new-postrm> `abort-install' <old-version>
# * <new-postrm> `abort-upgrade' <old-version>
# * <disappearer's-postrm> `disappear' <overwriter>
# <overwriter-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
case "$1" in
purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
;;
*)
echo "postrm called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0

35
debian/preinst.ex vendored

@ -1,35 +0,0 @@
#!/bin/sh
# preinst script for libsntl
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <new-preinst> `install'
# * <new-preinst> `install' <old-version>
# * <new-preinst> `upgrade' <old-version>
# * <old-preinst> `abort-upgrade' <new-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
case "$1" in
install|upgrade)
;;
abort-upgrade)
;;
*)
echo "preinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0

38
debian/prerm.ex vendored

@ -1,38 +0,0 @@
#!/bin/sh
# prerm script for libsntl
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <prerm> `remove'
# * <old-prerm> `upgrade' <new-version>
# * <new-prerm> `failed-upgrade' <old-version>
# * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
# * <deconfigured's-prerm> `deconfigure' `in-favour'
# <package-being-installed> <version> `removing'
# <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
case "$1" in
remove|upgrade|deconfigure)
;;
failed-upgrade)
;;
*)
echo "prerm called with unknown argument \`$1'" >&2
exit 1
;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0

23
debian/watch.ex vendored

@ -1,23 +0,0 @@
# Example watch control file for uscan
# Rename this file to "watch" and then you can run the "uscan" command
# to check for upstream updates and more.
# See uscan(1) for format
# Compulsory line, this is a version 3 file
version=3
# Uncomment to examine a Webpage
# <Webpage URL> <string match>
#http://www.example.com/downloads.php libsntl-(.*)\.tar\.gz
# Uncomment to examine a Webserver directory
#http://www.example.com/pub/libsntl-(.*)\.tar\.gz
# Uncommment to examine a FTP server
#ftp://ftp.example.com/pub/libsntl-(.*)\.tar\.gz debian uupdate
# Uncomment to find new files on sourceforge, for devscripts >= 2.9
# http://sf.net/libsntl/libsntl-(.*)\.tar\.gz
# Uncomment to find new files on GooglePages
# http://example.googlepages.com/foo.html libsntl-(.*)\.tar\.gz

@ -89,10 +89,14 @@ typedef struct __connection_t {
/* Other stuff */ /* Other stuff */
pthread_t thrd_poll[8]; pthread_t thrd_poll[8];
volatile uint8_t flags; /** < flags of the connection */ volatile uint8_t flags; /** < flags of the connection */
volatile uint8_t usecount; volatile uint8_t usecount; /** < use count for the connection link */
usrtc_node_t csnode; /** < node to store the connection within list */ usrtc_node_t csnode; /** < node to store the connection within list */
} conn_t; } conn_t;
#define connection_getpctx(c) (c)->pctx
#define connection_getpriv(c) (c)->pctx->priv
#define connection_setpriv(c, p) (c)->pctx->priv = (void *)(p)
struct __connection_rpc_list_type; struct __connection_rpc_list_type;
struct __message_t; struct __message_t;
@ -126,7 +130,7 @@ typedef struct __channel_t {
typedef struct __message_t { typedef struct __message_t {
chnl_t *pch; /** < channel of the message(if applicable) */ chnl_t *pch; /** < channel of the message(if applicable) */
pthread_mutex_t wait; /** < special wait mutex, used for pending list and sync */ pthread_mutex_t wait; /** < special wait mutex, used for pending list and sync */
sntllv2_head_t mhead; sntllv2_head_t mhead; /** < last actual head of the message */
void *payload; /** < payload */ void *payload; /** < payload */
} sxmsg_t; } sxmsg_t;
@ -199,6 +203,8 @@ extern "C" {
/* API */ /* API */
int sntl_init(void); int sntl_init(void);
void sntl_finalize(void);
int connections_init(conn_sys_t *ssys); int connections_init(conn_sys_t *ssys);
conn_sys_t *connections_create(void); conn_sys_t *connections_create(void);

@ -139,7 +139,7 @@ static int __get_channels_list(void *cctx, sexp_t *sx)
list_ent->type_id, list_ent->description); list_ent->type_id, list_ent->description);
} }
ulen += snprintf(buf + ulen, maxlen - ulen, ")"); ulen += snprintf(buf + ulen, maxlen - ulen, ")");
msg->mhead.payload_length = ulen + sizeof(sntllv2_head_t); msg->mhead.payload_length = ulen + 1;
/* we're ready for messaging mode */ /* we're ready for messaging mode */
co->flags |= SNSX_MESSAGINGMODE; co->flags |= SNSX_MESSAGINGMODE;
@ -249,6 +249,26 @@ int connections_init(conn_sys_t *ssys)
return r; return r;
} }
int connections_free(conn_sys_t *ssys)
{
__destroy_rpc_list_tree(ssys->system_rpc->rpc_tree);
free(ssys->system_rpc->rpc_tree);
free(ssys->system_rpc);
free(ssys->connections);
pthread_rwlock_destroy(&(ssys->rwlock));
SSL_CTX_free(ssys->ctx);
return 0;
}
int connections_destroy(conn_sys_t *ssys)
{
int r = connections_free(ssys);
free(ssys);
return r;
}
conn_sys_t *connections_create(void) conn_sys_t *connections_create(void)
{ {
int r = 0; int r = 0;
@ -289,3 +309,38 @@ int connections_setsslserts(conn_sys_t *ssys, const char *rootca,
return r; return r;
} }
struct __scerrcode {
int code;
const char *desc;
};
static struct __scerrcode __lerr[] = {
{SNE_SUCCESS, "Success"},
{SNE_FAILED, "Failed, invalid parameters given"},
{SNE_ENOMEM, "Not enough memory"},
{SNE_BADPROTO, "Bad protocol"},
{SNE_ENORPC, "No such RPC exists"},
{SNE_EPERM, "Permission denied"},
{SNE_TOOLONG, "Message data payload too long to be sent with one message pass"},
{SNE_EBUSY, "Index or working threads are busy"},
{SNE_WOULDBLOCK, "Call will block operation"},
{SNE_LINKERROR, "Connection link error"},
{SNE_NOSUCHMSG, "No such message"},
{SNE_NOSUCHCHAN, "No such channel"},
{SNE_ETIMEDOUT, "Timeout exceed"},
{SNE_IGNORED, "Function call was ignored"},
{SNE_REPLYREQ, "Reply required to the message"},
{SNE_RAPIDMSG, "Message is a rapid reply and dialog closed"},
{SNE_ESSL, "SSL error occurs on connection link"},
{SNE_NOCHANNELS, "No channels available"},
{SNE_MCHANNELS, "Active channels limit exceed"},
{SNE_MMESSAGES, "Active messages limit exceed"},
{SNE_LINKBROKEN, "Connection link was broken"},
{SNE_INVALINDEX, "Invalid index given"},
};
const char *sntll_errno2cstr(int ec)
{
return __lerr[ec - __SNTL_EPREFIX].desc;
}

@ -35,6 +35,7 @@
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/engine.h>
#include <tdata/usrtc.h> #include <tdata/usrtc.h>
#include <tdata/list.h> #include <tdata/list.h>
@ -389,6 +390,11 @@ void sntl_finalize(void)
OPENSSL_free(lock_cs); OPENSSL_free(lock_cs);
OPENSSL_free(lock_count); OPENSSL_free(lock_count);
ERR_free_strings();
ENGINE_cleanup();
CRYPTO_cleanup_all_ex_data();
EVP_cleanup();
return; return;
} }
@ -509,9 +515,31 @@ static int __eval_syssexp(conn_t *co, sexp_t *sx)
return rentry->rpcf((void *)co, sx); return rentry->rpcf((void *)co, sx);
} }
#ifdef _NO_SNTLMP
#define _CONN_INUSE(co) (co)->usecount++; #define _CONN_INUSE(co) (co)->usecount++;
#define _CONN_NOTINUSE(co) (co)->usecount--; #define _CONN_NOTINUSE(co) (co)->usecount--;
#define _CONN_UCOUNT(co) (co)->usecount #define _CONN_UCOUNT(co) (co)->usecount
#else
static inline void _CONN_INUSE(conn_t *co) {
pthread_rwlock_wrlock(&co->ssys->rwlock);
co->usecount++;
pthread_rwlock_unlock(&co->ssys->rwlock);
}
static inline void _CONN_NOTINUSE(conn_t *co) {
pthread_rwlock_wrlock(&co->ssys->rwlock);
co->usecount--;
pthread_rwlock_unlock(&co->ssys->rwlock);
}
static inline int _CONN_UCOUNT(conn_t *co) {
int r;
pthread_rwlock_rdlock(&co->ssys->rwlock);
r = co->usecount;
pthread_rwlock_unlock(&co->ssys->rwlock);
return r;
}
#endif
static void __connection_destroy(conn_t *co) static void __connection_destroy(conn_t *co)
{ {
@ -548,9 +576,10 @@ static void __connection_destroy(conn_t *co)
/* free queue */ /* free queue */
ERR_remove_state(0); ERR_remove_state(0);
ERR_remove_thread_state(0);
ERR_free_strings();
/* update use count */ /* update use count */
usleep(1500);
_CONN_NOTINUSE(co); _CONN_NOTINUSE(co);
/* ok, let's free other if we can */ /* ok, let's free other if we can */
@ -584,28 +613,18 @@ static void __connection_destroy(conn_t *co)
if(co->pctx->login) free(co->pctx->login); if(co->pctx->login) free(co->pctx->login);
if(co->pctx->passwd) free(co->pctx->passwd); if(co->pctx->passwd) free(co->pctx->passwd);
/*while((fd = SSL_shutdown(co->ssl)) != 1) {
if(fd < 0) break;
}*/
SSL_set_shutdown(co->ssl, SSL_RECEIVED_SHUTDOWN | SSL_SENT_SHUTDOWN); SSL_set_shutdown(co->ssl, SSL_RECEIVED_SHUTDOWN | SSL_SENT_SHUTDOWN);
fd = SSL_get_fd(co->ssl); fd = SSL_get_fd(co->ssl);
//int ti = CRYPTO_add(&co->ssl->references, -1, CRYPTO_LOCK_SSL);
//printf("ti = %d;\n", ti);
SSL_free(co->ssl); SSL_free(co->ssl);
//SSL_CTX_free(co->ssys->ctx);
co->ssl = NULL; co->ssl = NULL;
ERR_remove_thread_state(0); ERR_remove_thread_state(0);
ERR_remove_state(0); ERR_remove_state(0);
//ENGINE_cleanup();
//CRYPTO_cleanup_all_ex_data();
ERR_free_strings(); ERR_free_strings();
//ERR_remove_state(0);
//EVP_cleanup();
// ENGINE_cleanup();
close(fd); close(fd);
__connection_second_free(co); __connection_second_free(co);
@ -650,7 +669,7 @@ static void *__sntll_thread(void *b)
/* check up a thread */ /* check up a thread */
if(pthread_equal(self, co->thrd_poll[7])) /* dispatcher */ if(pthread_equal(self, co->thrd_poll[7])) /* dispatcher */
dispatch = 0; dispatch = 1;
/* update use count */ /* update use count */
_CONN_INUSE(co); _CONN_INUSE(co);
@ -661,7 +680,7 @@ static void *__sntll_thread(void *b)
*/ */
while(1) { while(1) {
__again: __again:
//if(co->flags & SNSX_CLOSED) goto __finish; /* go away if required asap */ if(co->flags & SNSX_CLOSED) goto __finish; /* go away if required asap */
/* works with pending messages */ /* works with pending messages */
if(co->pending_messages && !(co->flags & SNSX_CLOSED)) { if(co->pending_messages && !(co->flags & SNSX_CLOSED)) {
pthread_mutex_lock(&co->write_pending_lock); pthread_mutex_lock(&co->write_pending_lock);
@ -709,6 +728,11 @@ static void *__sntll_thread(void *b)
} else printf("connread(head) µS: %ld\n", end.tv_usec - beg.tv_usec); } else printf("connread(head) µS: %ld\n", end.tv_usec - beg.tv_usec);
#endif #endif
if(co->flags & SNSX_CLOSED) {
pthread_mutex_unlock(&(co->sslinout[0]));
goto __finish; /* go away if required asap */
}
#ifdef _VERBOSE_DEBUG #ifdef _VERBOSE_DEBUG
dumphead(mhead); dumphead(mhead);
#endif #endif
@ -760,7 +784,7 @@ static void *__sntll_thread(void *b)
pthread_mutex_lock(&(co->sslinout[1])); pthread_mutex_lock(&(co->sslinout[1]));
wr = __conn_write(co, mhead, sizeof(sntllv2_head_t)); wr = __conn_write(co, mhead, sizeof(sntllv2_head_t));
pthread_mutex_unlock(&(co->sslinout[1])); pthread_mutex_unlock(&(co->sslinout[1]));
if(wr < 0) goto __finish; if(wr == -1) goto __finish;
else goto __again; else goto __again;
} }
} else pthread_mutex_unlock(&(co->sslinout[0])); } else pthread_mutex_unlock(&(co->sslinout[0]));
@ -925,6 +949,7 @@ static void *__sntll_thread(void *b)
} }
__finish: __finish:
co->flags |= SNSX_CLOSED; co->flags |= SNSX_CLOSED;
__connection_destroy(co); __connection_destroy(co);
__sntll_bundle_destroy(b); /* destroy bundle */ __sntll_bundle_destroy(b); /* destroy bundle */
@ -997,8 +1022,8 @@ conn_t *connection_master_link(conn_sys_t *ssys, int sck, struct in_addr *addr)
/* set the context to verify ssl connection */ /* set the context to verify ssl connection */
SSL_set_ex_data(co->ssl, ex_ssldata_index, (void *)co); SSL_set_ex_data(co->ssl, ex_ssldata_index, (void *)co);
SSL_set_accept_state(co->ssl); SSL_set_accept_state(co->ssl);
// if(SSL_accept(co->ssl) == -1) { r = SNE_EPERM; goto __fail; } /* leak here ? */ if(SSL_accept(co->ssl) == -1) { r = SNE_EPERM; goto __fail; } /* leak here ? */
SSL_do_handshake(co->ssl); // SSL_do_handshake(co->ssl);
/* ok, now we are able to allocate and so on */ /* ok, now we are able to allocate and so on */
/* set connection to the batch mode */ /* set connection to the batch mode */
@ -1034,6 +1059,7 @@ conn_t *connection_master_link(conn_sys_t *ssys, int sck, struct in_addr *addr)
if(!head->payload_length) continue; /* pass the following check up */ if(!head->payload_length) continue; /* pass the following check up */
rd = __conn_read(co, bbuf, head->payload_length); rd = __conn_read(co, bbuf, head->payload_length);
if(rd == -1) { r = SNE_LINKERROR; goto __fail3; }
if(rd != head->payload_length) { r = SNE_LINKERROR; goto __fail3; } if(rd != head->payload_length) { r = SNE_LINKERROR; goto __fail3; }
bbuf[rd] = '\0'; bbuf[rd] = '\0';
sx = parse_sexp(bbuf, rd); sx = parse_sexp(bbuf, rd);
@ -1053,6 +1079,7 @@ conn_t *connection_master_link(conn_sys_t *ssys, int sck, struct in_addr *addr)
goto __fail3; goto __fail3;
} }
rd = __conn_write(co, buf, sizeof(sntllv2_head_t) + msg->mhead.payload_length); rd = __conn_write(co, buf, sizeof(sntllv2_head_t) + msg->mhead.payload_length);
if(rd == -1) { r = SNE_LINKERROR; goto __fail3; }
if(rd != sizeof(sntllv2_head_t) + msg->mhead.payload_length) { if(rd != sizeof(sntllv2_head_t) + msg->mhead.payload_length) {
destroy_sexp(sx); destroy_sexp(sx);
goto __fail3; goto __fail3;
@ -1112,7 +1139,13 @@ conn_t *connection_master_link(conn_sys_t *ssys, int sck, struct in_addr *addr)
SSL_shutdown(co->ssl); SSL_shutdown(co->ssl);
__fail: __fail:
if(co) { if(co) {
if(co->ssl) SSL_free(co->ssl); if(co->ssl) {
ERR_remove_thread_state(0);
ERR_remove_state(0);
ERR_free_strings();
SSL_free(co->ssl);
}
__connection_minimal_free(co); __connection_minimal_free(co);
} }
close(sck); close(sck);
@ -1329,7 +1362,10 @@ conn_t *connection_link(conn_sys_t *ssys, const char *host,
if(!bundle) goto __fail5; if(!bundle) goto __fail5;
r = pthread_create(&co->thrd_poll[i], NULL, __sntll_thread, bundle); r = pthread_create(&co->thrd_poll[i], NULL, __sntll_thread, bundle);
if(r) goto __fail5; if(r) goto __fail5;
else bundle = (void *)0xdead; else {
pthread_detach(co->thrd_poll[i]);
bundle = (void *)0xdead;
}
} }
/* all is done, connection now ready */ /* all is done, connection now ready */
@ -1347,6 +1383,9 @@ conn_t *connection_link(conn_sys_t *ssys, const char *host,
__fail2: __fail2:
if(buf != MAP_FAILED) munmap(buf, 65536); if(buf != MAP_FAILED) munmap(buf, 65536);
SSL_shutdown(co->ssl); SSL_shutdown(co->ssl);
ERR_remove_thread_state(0);
ERR_remove_state(0);
close(sck); close(sck);
__fail: __fail:
if(co) { if(co) {

@ -1,3 +1,7 @@
man_MANS = sxmsg_rreply.3 connections_create.3 connections_init.3 connections_destroy.3 connections_free.3 \ man_MANS = sxmsg_rreply.3 connections_create.3 connections_init.3 connections_destroy.3 connections_free.3 \
sntl_init.3 connections_setsslserts.3 connections_set_priv.3 connections_get_priv.3 \ sntl_init.3 connections_setsslserts.3 connections_set_priv.3 connections_get_priv.3 \
connections_set_ondestroy.3 connections_set_ondestroy.3 connections_set_onpulse.3 connections_set_sslvalidate.3 \
connections_set_authcheck.3 connections_set_rpcvalidator.3 connections_set_channelcall.3 \
connection_master_link.3 connection_link.3 connection_close.3 sxchannel_open.3 \
sxchannel_close.3 sxmsg_send.3 sxmsg_send_pp.3 sxmsg_clean.3 sntl_finalize.3 sxmsg_pulse.3 \
sxmsg_reply.3 sxmsg_reply_pp.3 sxmsg_return.3 sxmsg_return_pp.3

@ -0,0 +1 @@
connection_master_link.3

@ -0,0 +1 @@
connection_master_link.3

@ -0,0 +1,101 @@
.TH CONNECTION_MASTER_LINK 3 "20 July 2015" "SNTLLv2" "SNTL Library Manual"
.SH NAME
connection_master_link \- Create a connection on already accept TCP connection on the master side.
.br
connection_link \- Create connection to the master.
.br
connection_close \- Close connection.
.SH SYNOPSIS
.B #include <sntl/sntllv2.h>
.sp
conn_t *connection_master_link(conn_sys_t *ssys, int sck, struct in_addr *addr);
conn_t *connection_link(conn_sys_t *ssys, const char *host,
int port, const char *SSL_cert, const char *login,
const char *passwd);
int connection_close(conn_t *co);
.br
.sp
.SH DESCRIPTION
.B connection_master_link
will create a connection link based on
.B ssys
connections set with already accepted socket fd
.B sck
and set ip address of this connection pointed by
.B addr.
If
.B addr
is NULL, peer address will not set.
.br
.B connection_link
will create a connection link to the master side based on
.B ssys
connections set to the master side pointed via hostname or ip address in nul terminated string
.B host
running on port number
.B port
and send a X.509 certificate located on pathname pointed by
.B SSL_cert
trying to authorizated with username pointed by
.B login
and password pointed by
.B passwd
.br
.B connection_close
will close connection pointed by
.B co
destroying all allocated structures, including connection link itself.
.br
.SH RETURN VALUE
Upon successful completion, the functions
.B connection_master_link
and
.B connection_link
will return a valid pointer to the newly created connection link. Otherwise NULL will be returned and
.B errno will be set with appropriate error.
.B connection_close
will return
.B SNE_SUCCESS
on successful case, otherwise it will return an error described below.
.SH ERRORS
.B SNE_FAILED
will be returned in case of bad params given.
.br
.B SNE_ENOMEM
will be returned if there are no memory available.
.br
.B SNE_BADPROTO
will be returned if other side has an invalid protocol.
.B SNE_EPERM
will be returned if permission was denied.
.br
.B SNE_LINKERROR
or
.B SNE_LINKBROKEN
will be returned if connection link is broken i.e. SSL read or write was failed due to the broken TCP connection.
.br
.SH BUGS
Not known yet.
.SH EXAMPLE
None.
.SH APPLICATION USAGE
None.
.SH RATIONALE
Using connection_link on master side with initialized connections set for master functionality will cause memory leaks, use different connections set structure if you need this functionality on the masters side.
.SH SEE ALSO
.BI connections_setsslserts(3)
,
.BI connections_create(3)
,
.BI connections_destroy(3)
,
.BI sntl_init(3)
.SH COPYRIGHT
This is a proprietary software. See COPYING for further details.
.br
(c) Askele Group 2013-2015 <http://askele.com>
.SH AUTHOR
Alexander Vdolainen (vdo@askele.com)

@ -0,0 +1,74 @@
.TH CONNECTIONS_SET_AUTHCHECK 3 "20 July 2015" "SNTLLv2" "SNTL Library Manual"
.SH NAME
connections_set_authcheck \- Set callback for the connection links based on the connections set, called to validate user name and password of the peer.
.br
.SH SYNOPSIS
.B #include <sntl/sntllv2.h>
.sp
#define connections_set_authcheck(c, f)
.br
.sp
.SH DESCRIPTION
This macro should be used if you want to setup callback function fired while connection link initiating, and depending on returning value will establish link or destroy it.
.br
This macro will set on
.B c
connections link set callback
.B f
which is a function pointer of the type:
.br
.sp
.B typedef int (*authcheck_t)(conn_t *);
.br
.sp
It will pass a pointer to the connection link initiating now. Link isn't set fully at this moment and doesn't pass any messages and don't works with channel's operations. To pass initiation to the next stage this function should return
.B SNE_SUCCESS.
In fail case other code error should be returned. It's a good practice to return
.B SNE_EPERM
if username and password mismatch.
.SH RETURN VALUE
None.
.SH ERRORS
None.
.SH BUGS
None known yet.
.SH EXAMPLE
This example shows the code prototype for the simple username and password check:
.RS
.nf
.if t .ft CW
int logincheck(conn_t *co)
{
perm_ctx_t *ctx = connection_getpctx(co);
char *login = ctx->login;
char *password = ctx->password;
/* do checks ... */
/* your fail case */return SNE_EPERM;
return SNE_SUCCESS; /* all is fine */
}
.SH APPLICATION USAGE
This function should be used on the master service, it will not be called on the client application anyway.
.SH RATIONALE
None.
.SH SEE ALSO
.BI connections_set_priv(3)
,
.BI connections_get_priv(3)
,
.BI connections_set_ondestroy(3)
,
.BI connections_set_sslvalidate(3)
,
.BI connection_getpctx(3)
,
.BI connection_getpriv(3)
,
.BI connection_setpriv(3)
.SH COPYRIGHT
This is a proprietary software. See COPYING for further details.
.br
(c) Askele Group 2013-2015 <http://askele.com>
.SH AUTHOR
Alexander Vdolainen (vdo@askele.com)

@ -0,0 +1,69 @@
.TH CONNECTIONS_SET_CHANNELCALL 3 "20 July 2015" "SNTLLv2" "SNTL Library Manual"
.SH NAME
connections_set_channelcall \- Set callback for the connection links based on the connections set, called during connection link initiation on the client side.
.br
.SH SYNOPSIS
.B #include <sntl/sntllv2.h>
.sp
#define connections_set_channelcall(c, f)
.br
.sp
.SH DESCRIPTION
This macro should be used if you want to setup callback function fired while connection link initiating, it might be useful to sync your client ability to support masters protocol and/or correctly initialize your application.
.br
This macro will set on
.B c
connections link set callback
.B f
which is a function pointer of the type:
.br
.sp
.B typedef int (*channelcall_t)(conn_t *co, int tid, char *desc);
.br
.sp
It will pass a pointer to the connection link initiating now. Link isn't set fully at this moment and doesn't pass any messages and don't works with channel's operations. To pass initiation to the next stage this function should return
.B SNE_SUCCESS.
In fail case other code error should be returned. It's a good practice to return
.B SNE_IGNORED
if your application doesn't support protocol channels or outdated.
.br
SNTL will push channel type id in
.B tid
and text description in
.B desc
.br
This call will be invoked on each RPC channel.
.SH RETURN VALUE
None.
.SH ERRORS
None.
.SH BUGS
None known yet.
.SH EXAMPLE
This example shows the code prototype of such function:
.RS
.nf
.if t .ft CW
int rpcchanack(conn_t *co, int tid, char *desc)
{
fprintf(stdout, "Master side supported RPC channel type: %d '%s'\n", tid, desc);
return SNE_SUCCESS; /* all is fine */
}
.SH APPLICATION USAGE
This function should be used on the client service, it will not be called on the master side anyway, since master provide RPC channels.
.SH RATIONALE
None.
.SH SEE ALSO
.BI connections_set_ondestroy(3)
,
.BI connection_getpriv(3)
,
.BI connection_setpriv(3)
.SH COPYRIGHT
This is a proprietary software. See COPYING for further details.
.br
(c) Askele Group 2013-2015 <http://askele.com>
.SH AUTHOR
Alexander Vdolainen (vdo@askele.com)

@ -1,6 +1,6 @@
.TH CONNECTIONS_ON_DESTROY 3 "20 July 2015" "SNTLLv2" "SNTL Library Manual" .TH CONNECTIONS_SET_ONDESTROY 3 "20 July 2015" "SNTLLv2" "SNTL Library Manual"
.SH NAME .SH NAME
connections_on_destroy \- Set callback for the connection links based on the connections set, called in case of link destroying connections_set_ondestroy \- Set callback for the connection links based on the connections set, called in case of link destroying
.br .br
.SH SYNOPSIS .SH SYNOPSIS
.B #include <sntl/sntllv2.h> .B #include <sntl/sntllv2.h>
@ -39,6 +39,8 @@ None.
.BI connections_set_priv(3) .BI connections_set_priv(3)
, ,
.BI connections_get_priv(3) .BI connections_get_priv(3)
,
.BI connections_set_onpulse(3)
.SH COPYRIGHT .SH COPYRIGHT
This is a proprietary software. See COPYING for further details. This is a proprietary software. See COPYING for further details.
.br .br

@ -0,0 +1,49 @@
.TH CONNECTIONS_SET_ONPULSE 3 "20 July 2015" "SNTLLv2" "SNTL Library Manual"
.SH NAME
connections_set_onpulse \- Set callback for the connection links based on the connections set, called in case of link pulse message
.br
.SH SYNOPSIS
.B #include <sntl/sntllv2.h>
.sp
#define connections_set_onpulse(c, f)
.br
.sp
.SH DESCRIPTION
This macro should be used if you want to setup callback function fired while pulse link message came.
.br
This macro will set on
.B c
connections link set callback
.B f
which is a function pointer of the type:
.br
.sp
.B typedef void (*onpulse_t)(conn_t *, sexp_t *);
.br
.sp
This function will be called if connection link will receive pulse message. It will pass a pointer to the connection where pulse message came and prepared S expression. Please note, prepared S expression structure will be destroyed after a function call.
.SH RETURN VALUE
None.
.SH ERRORS
None.
.SH BUGS
None known yet.
.SH EXAMPLE
None.
.SH APPLICATION USAGE
None.
.SH RATIONALE
None.
.SH SEE ALSO
.BI connections_set_priv(3)
,
.BI connections_get_priv(3)
,
.BI connections_set_ondestroy(3)
.SH COPYRIGHT
This is a proprietary software. See COPYING for further details.
.br
(c) Askele Group 2013-2015 <http://askele.com>
.SH AUTHOR
Alexander Vdolainen (vdo@askele.com)

@ -0,0 +1,72 @@
.TH CONNECTIONS_SET_RPCVALIDATOR 3 "20 July 2015" "SNTLLv2" "SNTL Library Manual"
.SH NAME
connections_set_rpcvalidator \- Set callback for the connection links based on the connections set, called to validate and setup RPC channels.
.br
.SH SYNOPSIS
.B #include <sntl/sntllv2.h>
.sp
#define connections_set_rpcvalidator(c, f)
.br
.sp
.SH DESCRIPTION
This macro should be used if you want to setup callback function fired while connection link initiating, this call shouldn't be ignored since it setups the RPC channels tree structure used within the connection link.
.br
This macro will set on
.B c
connections link set callback
.B f
which is a function pointer of the type:
.br
.sp
.B typedef usrtc_t* (*rpcvalidate_t)(conn_t *);
.br
.sp
It will pass a pointer to the connection link initiating now. Link isn't set fully at this moment and doesn't pass any messages and don't works with channel's operations. To pass initiation to the next stage this function should return
a valid pointer to the
.B usrtc_t
structure, this structure must be created with
.B sntl_rpclist_init
,
.B sntl_rpclist_add
,
.B sntl_rpclist_add_function
series functions.
.br
The returned value will be not handled by library and you should care about freeing it in your application.
.SH RETURN VALUE
None.
.SH ERRORS
None.
.SH BUGS
None known yet.
.SH EXAMPLE
None.
.SH APPLICATION USAGE
This function should be used on the master service only, the client isn't set any RPC channels yet.
.SH RATIONALE
None.
.SH SEE ALSO
.BI connections_set_priv(3)
,
.BI connections_get_priv(3)
,
.BI connections_set_sslvalidate(3)
,
.BI connection_getpctx(3)
,
.BI connection_getpriv(3)
,
.BI connection_setpriv(3)
,
.BI sntl_rpclist_init(3)
,
.BI sntl_rpclist_add(3)
,
.BI sntl_rpclist_add_function(3)
.SH COPYRIGHT
This is a proprietary software. See COPYING for further details.
.br
(c) Askele Group 2013-2015 <http://askele.com>
.SH AUTHOR
Alexander Vdolainen (vdo@askele.com)

@ -0,0 +1,69 @@
.TH CONNECTIONS_SET_SSLVALIDATE 3 "20 July 2015" "SNTLLv2" "SNTL Library Manual"
.SH NAME
connections_set_sslvalidate \- Set callback for the connection links based on the connections set, called to validate x.509 certificate of peer by serial number.
.br
.SH SYNOPSIS
.B #include <sntl/sntllv2.h>
.sp
#define connections_set_sslvalidate(c, f)
.br
.sp
.SH DESCRIPTION
This macro should be used if you want to setup callback function fired while connection link initiating, and depending on returning value will establish link or destroy it.
.br
This macro will set on
.B c
connections link set callback
.B f
which is a function pointer of the type:
.br
.sp
.B typedef int (*validate_sslpem_t)(conn_t *);
.br
.sp
It will pass a pointer to the connection link initiating now. Link isn't set fully at this moment and doesn't pass any messages and don't works with channel's operations. To pass initiation to the next stage this function should return
.B 0.
In fail case other code error should be returned.
.SH RETURN VALUE
None.
.SH ERRORS
None.
.SH BUGS
None known yet.
.SH EXAMPLE
This example shows the code prototype for the simple check:
.RS
.nf
.if t .ft CW
int validatex509(conn_t *co)
{
perm_ctx_t *ctx = connection_getpctx(co);
uint64_t x509serial = ctx->certid;
/* do checks ... */
/* your fail case */return 1;
return 0; /* all is fine */
}
.SH APPLICATION USAGE
This function should be used on the master service, currently it's not applicable for client applications, and may cause undefined behavoir.
.SH RATIONALE
None.
.SH SEE ALSO
.BI connections_set_priv(3)
,
.BI connections_get_priv(3)
,
.BI connections_set_ondestroy(3)
,
.BI connection_getpctx(3)
,
.BI connection_getpriv(3)
,
.BI connection_setpriv(3)
.SH COPYRIGHT
This is a proprietary software. See COPYING for further details.
.br
(c) Askele Group 2013-2015 <http://askele.com>
.SH AUTHOR
Alexander Vdolainen (vdo@askele.com)

@ -0,0 +1 @@
sntl_init.3

@ -2,11 +2,14 @@
.SH NAME .SH NAME
sntl_init \- Initialize all required globals to run sntl library functions sntl_init \- Initialize all required globals to run sntl library functions
.br .br
sntl_finalize \- Destroy all allocated resources for SNTL operation
.br
.SH SYNOPSIS .SH SYNOPSIS
.B #include <sntl/sntllv2.h> .B #include <sntl/sntllv2.h>
.sp .sp
int *sntl_init(void); int sntl_init(void);
void sntl_finalize(void);
.br .br
.sp .sp
.SH DESCRIPTION .SH DESCRIPTION
@ -14,6 +17,8 @@ int *sntl_init(void);
will initialize all globals required to run sntl related functions, it mostly about will initialize all globals required to run sntl related functions, it mostly about
openssl library initialization. openssl library initialization.
.br .br
.B sntl_finalize
will destroy all resources allocated for SNTL library operation.
.SH RETURN VALUE .SH RETURN VALUE
Always returns Always returns
.B 0 .B 0
@ -28,6 +33,10 @@ None.
.SH APPLICATION USAGE .SH APPLICATION USAGE
Call this function from the main thread before using sntl library. Otherwise it will not works. There are also Call this function from the main thread before using sntl library. Otherwise it will not works. There are also
useful to know if you are using other openssl functionality there are no need to initialize globals for it. useful to know if you are using other openssl functionality there are no need to initialize globals for it.
.br
If you are using openssl, don't call
.B sntl_finalize
until you will finish with them.
.SH RATIONALE .SH RATIONALE
None. None.
.SH SEE ALSO .SH SEE ALSO

@ -0,0 +1 @@
sxchannel_open.3

@ -0,0 +1,75 @@
.TH SXCHANNEL_OPEN 3 "20 July 2015" "SNTLLv2" "SNTL Library Manual"
.SH NAME
sxchannel_open \- Open RPC channel.
.br
sxchannel_close \- Close RPC channel
.SH SYNOPSIS
.B #include <sntl/sntllv2.h>
.sp
chnl_t *sxchannel_open(conn_t *co, int type);
int sxchannel_close(chnl_t *channel);
.br
.sp
.SH DESCRIPTION
.B sxchannel_open
will open RPC channel using
.B co
connection link with specified type via
.B type
that available/permitted to use for current peer.
.br
.B sxchannel_close
will close RPC channel pointed by
.B channel
destroying all allocated structures, including channel itself.
.br
.SH RETURN VALUE
Upon successful completion, the function
.B sxchannel_open
will return a valid pointer to the newly opened RPC channel. Or NULL otherwise setting
.B errno
with error code.
.br
.B sxchannel_close
will return
.B SNE_SUCCESS
on success, otherwise error will be returned.
.SH ERRORS
.B SNE_FAILED
will be returned in case of bad params given.
.br
.B SNE_ENOMEM
will be returned if there are no memory available.
.br
.B SNE_BADPROTO
will be returned if other side has an invalid protocol.
.B SNE_EPERM
will be returned if permission was denied.
.br
.B SNE_LINKERROR
or
.B SNE_LINKBROKEN
will be returned if connection link is broken i.e. SSL read or write was failed due to the broken TCP connection.
.br
.SH BUGS
Not known yet.
.SH EXAMPLE
None.
.SH APPLICATION USAGE
None.
.SH RATIONALE
None.
.SH SEE ALSO
.BI connections_set_rpcvalidator(3)
,
.BI connection_link(3)
,
.BI connection_close(3)
.SH COPYRIGHT
This is a proprietary software. See COPYING for further details.
.br
(c) Askele Group 2013-2015 <http://askele.com>
.SH AUTHOR
Alexander Vdolainen (vdo@askele.com)

@ -0,0 +1 @@
sxmsg_send.3

@ -0,0 +1,47 @@
.TH SXMSG_PULSE 3 "20 July 2015" "SNTLLv2" "SNTL Library Manual"
.SH NAME
sxmsg_pulse \- Function used to send a pulse
.SH SYNOPSIS
.B #include <sntl/sntllv2.h>
.sp
int sxmsg_pulse(conn_t *co, const char *data, size_t datalen);
.sp
.SH DESCRIPTION
.B sxmsg_pulse
Will send a pulse message to the peer of underlying connection link
.B co
with given buffer
.B data
with given length in bytes
.B datalen.
.br
.SH RETURN VALUE
Upon successful completion, the function will write a pulse message returning
.B SNE_SUCCESS
Othrewise other error code will be returned.
.SH ERRORS
.B SNE_FAILED
returns if message has invalid index, channel or message pointer is NULL.
.br
.B SNE_ESSL
returns if write was failed i.e. connection link was broken, or SSL error occurs.
.br
.B SNE_EBUSY
Limit exceed.
.B SNE_SUCCESS
returns on success.
.br
.SH BUGS
Not known yet.
.SH EXAMPLE
None.
.SH APPLICATION USAGE
This function might be useful to send events to the peer.
.SH RATIONALE
Calling this function from the client might blocks all operation with callee.
.SH COPYRIGHT
This is a proprietary software. See COPYING for further details.
.br
(c) Askele Group 2013-2015 <http://askele.com>
.SH AUTHOR
Alexander Vdolainen (vdo@askele.com)

@ -0,0 +1,94 @@
.TH SXMSG_REPLY 3 "20 July 2015" "SNTLLv2" "SNTL Library Manual"
.SH NAME
sxmsg_reply \- Reply to the message from the peer and wait while confirmation will be received.
.br
sxmsg_send_pp \- Reply to the message from the peer and wait while confirmation will be received in postponed message send mode.
.SH SYNOPSIS
.B #include <sntl/sntllv2.h>
.br
.sp
int sxmsg_reply(sxmsg_t *msg, const char *data, size_t datalen);
int sxmsg_reply_pp(sxmsg_t *msg, const char *data, size_t datalen);
.br
.sp
.SH DESCRIPTION
.B sxmsg_reply
Will reply to the message pointed by
.B msg
and awaits for the reply from the peer. It will attach the data pointed by
.B data
with length in bytes pointed by
.B datalen.
This message will be sent within context of the calling thread.
.br
.B sxmsg_reply_pp
Will do exactly the same, but message sending will be postponed and sent by one of the thread serving the underlying connection link.
.br
Both calls will cause a sleep of the calling thread until reply or error will be returned. I.e. this call is blocking one. Also, message is actually atom of the dialog, that means one side sending a first message creates dialog, other side may or may not close this dialog with error code (actual a message without data) or with some data, you should track the message return code to correctly close dialogs.
.br
If dialogs will be not finished correctly the limit of active messages will be exceeded and you will be not able to create a new dialog while message poll is full with opened dialogs. It's a good practice to avoid long dialog queues in critical operations or operations required to send a lot of data, since each message can take a lot of time (SSL time, network time).
.br
.SH RETURN VALUE
Dialog will be closed in all cases except the following error codes returns:
.sp
.B SNE_REPLYREQ
means other side waiting a reply for this message (i.e. dialog isn't closed).
.br
Other possible errors:
.br
.B SNE_SUCCESS
will returns if message was processed and dialog is closed.
.br
.B SNE_FAILED
pointed data is invalid.
.br
.B SNE_ENOMEM
not available memory for operation.
.br
.B SNE_BADPROTO
bad protocol.
.br
.B SNE_ENORPC
No RPC call exists i.e. message sent contains an invalid RPC function name.
.br
.B SNE_TOOLONG
Data os too long to be sent with one message.
.br
.B SNE_NOSUCHCHAN
Pointed channel doesn't exists
.br
.B SNE_ETIMEDOUT
Other side timedout with replying to your message.
.br
.B SNE_LINKBROKEN
Connection link is broken during a message send.
.br
.B SNE_MMESSAGES
Limit for the active messages exceeded.
.br
.SH BUGS
Not known yet.
.SH EXAMPLE
None.
.SH APPLICATION USAGE
None.
.SH RATIONALE
None.
.SH SEE_ALSO
.BI connection_link(3)
,
.BI sxchannel_open(3)
,
.BI sxmsg_rreply(3)
,
.BI sxmsg_return(3)
,
.BI sxmsg_send(3)
.SH COPYRIGHT
This is a proprietary software. See COPYING for further details.
.br
(c) Askele Group 2013-2015 <http://askele.com>
.SH AUTHOR
Alexander Vdolainen (vdo@askele.com)

@ -0,0 +1 @@
sxmsg_reply.3

@ -0,0 +1,76 @@
.TH SXMSG_RETURN 3 "20 July 2015" "SNTLLv2" "SNTL Library Manual"
.SH NAME
sxmsg_return \- Return a message with error and close dialog.
.br
sxmsg_return_pp \- Return a message with error and close dialog in postponed message send mode.
.SH SYNOPSIS
.B #include <sntl/sntllv2.h>
.br
.sp
int sxmsg_return(sxmsg_t *msg, int opcode);
int sxmsg_return_pp(sxmsg_t *msg, int opcode);
.br
.sp
.SH DESCRIPTION
.B sxmsg_return
Will return a message with error code
.B opcode
pointed by
.B msg.
This message will be sent within context of the calling thread.
.br
.B sxmsg_reply_pp
Will do exactly the same, but message sending will be postponed and sent by one of the thread serving the underlying connection link.
.br
.SH RETURN VALUE
Functions may fail with the following errors:
.br
.B SNE_SUCCESS
will returns if message was processed and dialog is closed.
.br
.B SNE_FAILED
pointed data is invalid.
.br
.B SNE_ENOMEM
not available memory for operation.
.br
.B SNE_BADPROTO
bad protocol.
.br
.B SNE_NOSUCHCHAN
Pointed channel doesn't exists
.br
.B SNE_ETIMEDOUT
Other side timedout with replying to your message.
.br
.B SNE_LINKBROKEN
Connection link is broken during a message send.
.br
.SH BUGS
Not known yet.
.SH EXAMPLE
None.
.SH APPLICATION USAGE
None.
.SH RATIONALE
None.
.SH SEE_ALSO
.BI sxchannel_open(3)
,
.BI sxchannel_close(3)
,
.BI sxmsg_reply(3)
,
.BI sxmsg_rreply(3)
,
.BI sxmsg_return(3)
,
.BI sxmsg_send(3)
.SH COPYRIGHT
This is a proprietary software. See COPYING for further details.
.br
(c) Askele Group 2013-2015 <http://askele.com>
.SH AUTHOR
Alexander Vdolainen (vdo@askele.com)

@ -0,0 +1 @@
sxmsg_return.3

@ -48,9 +48,9 @@ char *buf = sxmsg_rapidbuf(msg);
int ln = snprintf(buf, MAX_RBBUF_LEN, "(is-done)"); int ln = snprintf(buf, MAX_RBBUF_LEN, "(is-done)");
return sxmsg_rreply(msg, str, ln); return sxmsg_rreply(msg, str, ln);
.SH APPLICATION USAGE .SH APPLICATION USAGE
This function will be useful in RPC functions required to reply ASAP i.e. for getting some data. It RPC function takes a lot of time it's better to use other functions and postponed message processing. This function will be useful in RPC functions required to reply ASAP i.e. for getting some data. If RPC function takes a lot of time it's better to use other functions and/or postponed message processing.
.SH RATIONALE .SH RATIONALE
Use for lightweight RPC functions, this method may be used only in RPC call i.e. within SNTL thread context. Use for lightweight RPC functions, this method can be used only in RPC call i.e. within SNTL thread context.
.SH COPYRIGHT .SH COPYRIGHT
This is a proprietary software. See COPYING for further details. This is a proprietary software. See COPYING for further details.
.br .br

@ -0,0 +1,103 @@
.TH SXMSG_SEND 3 "20 July 2015" "SNTLLv2" "SNTL Library Manual"
.SH NAME
sxmsg_send \- Create and send a message within called thread context.
.br
sxmsg_send_pp \- Create and send a message in postponed mode.
.SH SYNOPSIS
.B #include <sntl/sntllv2.h>
.br
.sp
int sxmsg_send(chnl_t *channel, const char *data, size_t datalen, sxmsg_t **msg);
int sxmsg_send_pp(chnl_t *channel, const char *data, size_t datalen, sxmsg_t **msg);
void sxmsg_clean(sxmsg_t *msg);
.br
.sp
.SH DESCRIPTION
.B sxmsg_send
Will create and send message using channel pointed by
.B channel
with data pointed by
.B data
with length pointed in bytes using
.B datalen.
If message dialog will continue pointer to the message with reply will be pushed to
.B msg.
This message will be sent within context of the calling thread.
.br
.B sxmsg_send_pp
Will do exactly the same, but message sending will be postponed and sent by one of the thread serving the underlying connection link.
.br
Both calls will cause a sleep of the calling thread until reply or error will be returned. I.e. this call is blocking one. Also, message is actually atom of the dialog, that means one side sending a first message creates dialog, other side may or may not close this dialog with error code (actual a message without data) or with some data, you should track the message return code to correctly close dialogs.
.br
If dialogs will be not finished correctly the limit of active messages will be exceeded and you will be not able to create a new dialog while message poll is full with opened dialogs. It's a good practice to avoid long dialog queues in critical operations or operations required to send a lot of data, since each message can take a lot of time (SSL time, network time).
.br
.B sxmsg_clean
will clean up the data used for closed dialog message, it should be used in case of rapid reply to avoid memory leaks.
.SH RETURN VALUE
Dialog will be closed in all cases except the following error codes returns:
.sp
.B SNE_REPLYREQ
means other side waiting a reply for this message (i.e. dialog isn't closed).
.br
In other cases message will not set except
.B SNE_RAPIDMSG
error code, in this case to avoid memory leaks
.B sxmsg_clean
must be called after data is processed. In other cases a different and specific error code might be returned, but usual cases listed below:
.br
.B SNE_SUCCESS
will returns if message was processed and dialog is closed.
.br
.B SNE_FAILED
pointed data is invalid.
.br
.B SNE_ENOMEM
not available memory for operation.
.br
.B SNE_BADPROTO
bad protocol.
.br
.B SNE_ENORPC
No RPC call exists i.e. message sent contains an invalid RPC function name.
.br
.B SNE_TOOLONG
Data os too long to be sent with one message.
.br
.B SNE_NOSUCHCHAN
Pointed channel doesn't exists
.br
.B SNE_ETIMEDOUT
Other side timedout with replying to your message.
.br
.B SNE_LINKBROKEN
Connection link is broken during a message send.
.br
.B SNE_MMESSAGES
Limit for the active messages exceeded.
.br
.SH BUGS
Not known yet.
.SH EXAMPLE
None.
.SH APPLICATION USAGE
None.
.SH RATIONALE
None.
.SH SEE_ALSO
.BI connection_link(3)
,
.BI sxchannel_open(3)
,
.BI sxmsg_rreply(3)
,
.BI sxmsg_return(3)
,
.BI sxmsg_reply
.SH COPYRIGHT
This is a proprietary software. See COPYING for further details.
.br
(c) Askele Group 2013-2015 <http://askele.com>
.SH AUTHOR
Alexander Vdolainen (vdo@askele.com)

@ -0,0 +1 @@
sxmsg_send.3

@ -156,53 +156,6 @@ int msg_send(chnl_t *ch, const char *mmbuf, size_t buflen, sxmsg_t *msg, char **
return mr; return mr;
} }
static pthread_mutex_t *lockarray;
static void lock_callback(int mode, int type, char *file, int line)
{
(void)file;
(void)line;
if (mode & CRYPTO_LOCK) {
pthread_mutex_lock(&(lockarray[type]));
}
else {
pthread_mutex_unlock(&(lockarray[type]));
}
}
static unsigned long thread_id(void)
{
unsigned long ret;
ret=(unsigned long)pthread_self();
return(ret);
}
static void init_locks(void)
{
int i;
lockarray=(pthread_mutex_t *)OPENSSL_malloc(CRYPTO_num_locks() *
sizeof(pthread_mutex_t));
for (i=0; i<CRYPTO_num_locks(); i++) {
pthread_mutex_init(&(lockarray[i]),NULL);
}
CRYPTO_set_id_callback((unsigned long (*)())thread_id);
CRYPTO_set_locking_callback((void (*)())lock_callback);
}
static void kill_locks(void)
{
int i;
CRYPTO_set_locking_callback(NULL);
for (i=0; i<CRYPTO_num_locks(); i++)
pthread_mutex_destroy(&(lockarray[i]));
OPENSSL_free(lockarray);
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char *rootca = NULL, *cert = NULL; char *rootca = NULL, *cert = NULL;
@ -265,7 +218,6 @@ int main(int argc, char **argv)
} }
sntl_init(); sntl_init();
init_locks();
/* all is fine let's init connection subsystem */ /* all is fine let's init connection subsystem */
ssys = connections_create(); ssys = connections_create();
if(!ssys) { if(!ssys) {
@ -392,5 +344,9 @@ __finish:
connection_close(co); connection_close(co);
connections_destroy(ssys);
sntl_finalize();
return 0; return 0;
} }

@ -429,6 +429,11 @@ int main(int argc, char **argv)
fprintf(stderr, "Failed to add typed RPC channel\n Failure.\n"); fprintf(stderr, "Failed to add typed RPC channel\n Failure.\n");
return opt; return opt;
} }
opt = sntl_rpclist_add(fulist, 1, "Public", NULL);
if(opt) {
fprintf(stderr, "Failed to add typed RPC channel\n Failure.\n");
return opt;
}
/* ok, let's add stream functions */ /* ok, let's add stream functions */
opt = sntl_rpclist_add_function(fulist, 12, "dir-open", __dir_open); opt = sntl_rpclist_add_function(fulist, 12, "dir-open", __dir_open);
@ -478,6 +483,10 @@ int main(int argc, char **argv)
#endif #endif
} }
connections_destroy(ssys);
sntl_finalize();
return 0; return 0;
} }

Loading…
Cancel
Save