|
|
|
@ -35,7 +35,8 @@
|
|
|
|
|
|
|
|
|
|
#include <tdata/usrtc.h>
|
|
|
|
|
#include <sexpr/sexp.h>
|
|
|
|
|
#include <sntl/connection.h>
|
|
|
|
|
#include <sntl/limits.h>
|
|
|
|
|
#include <sntl/sntllv2.h>
|
|
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
// #include <unistd.h>
|
|
|
|
@ -104,52 +105,58 @@ usrtc_t *__rettlist(conn_t *c)
|
|
|
|
|
/* RPC functions implementation */
|
|
|
|
|
static int __ar_add(void *m, sexp_t *sx)
|
|
|
|
|
{
|
|
|
|
|
// int timout = rand() % 1000000;
|
|
|
|
|
// usleep(timout);
|
|
|
|
|
sexp_t *lsx = NULL, *sx_iter;
|
|
|
|
|
sxmsg_t *msg = (sxmsg_t *)m;
|
|
|
|
|
int idx, rc = 0;
|
|
|
|
|
|
|
|
|
|
char *buf;
|
|
|
|
|
int idx;
|
|
|
|
|
size_t ln = 0;
|
|
|
|
|
|
|
|
|
|
if(sexp_list_cdr(sx, &lsx)) {
|
|
|
|
|
printf("Invalid protocol\n");
|
|
|
|
|
return EINVAL;
|
|
|
|
|
return sxmsg_return(msg, SNE_BADPROTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long int sum = 0;
|
|
|
|
|
SEXP_ITERATE_LIST(lsx, sx_iter, idx) {
|
|
|
|
|
if(!SEXP_IS_TYPE(sx_iter, SEXP_BASIC)) {
|
|
|
|
|
printf("Invalid value type\n");
|
|
|
|
|
return EINVAL;
|
|
|
|
|
fprintf(stderr, "Invalid value type\n");
|
|
|
|
|
return sxmsg_return(msg, SNE_BADPROTO);
|
|
|
|
|
}
|
|
|
|
|
sum += atoi(sx_iter->val);
|
|
|
|
|
}
|
|
|
|
|
rc = msg_return(msg, sum);
|
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
|
|
buf = sxmsg_rapidbuf(msg);
|
|
|
|
|
ln = snprintf(buf, MAX_RBBUF_LEN, "(add-result %ld)", sum);
|
|
|
|
|
|
|
|
|
|
return sxmsg_rreply(msg, ln);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int __ar_multiply(void *data, sexp_t *sx)
|
|
|
|
|
{
|
|
|
|
|
sexp_t *lsx = NULL;
|
|
|
|
|
sxmsg_t *msg = (sxmsg_t *)data;
|
|
|
|
|
char *buf;
|
|
|
|
|
int idx;
|
|
|
|
|
sexp_t *sx_iter;
|
|
|
|
|
size_t ln;
|
|
|
|
|
|
|
|
|
|
if(sexp_list_cdr(sx, &lsx)) {
|
|
|
|
|
printf("Invalid protocol\n");
|
|
|
|
|
return EINVAL;
|
|
|
|
|
return sxmsg_return(msg, SNE_BADPROTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long int mult = 0;
|
|
|
|
|
SEXP_ITERATE_LIST(lsx, sx_iter, idx) {
|
|
|
|
|
if(!SEXP_IS_TYPE(sx_iter, SEXP_BASIC)) {
|
|
|
|
|
printf("Invalid value type\n");
|
|
|
|
|
return EINVAL;
|
|
|
|
|
return sxmsg_return(msg, SNE_BADPROTO);
|
|
|
|
|
}
|
|
|
|
|
mult *= atoi(sx_iter->val);
|
|
|
|
|
}
|
|
|
|
|
char buf[128];
|
|
|
|
|
sprintf(buf, "(ar_mult_set (%ld))", mult);
|
|
|
|
|
printf("result %s\n", buf);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
buf = sxmsg_rapidbuf(msg);
|
|
|
|
|
ln = snprintf(buf, MAX_RBBUF_LEN, "(multiply-result %ld)", mult);
|
|
|
|
|
|
|
|
|
|
return sxmsg_rreply(msg, ln);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* define a little bit */
|
|
|
|
@ -210,12 +217,12 @@ int main(int argc, char **argv)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* all is fine let's init connection subsystem */
|
|
|
|
|
if(ssys) {
|
|
|
|
|
if(!ssys) {
|
|
|
|
|
fprintf(stderr, "Subsystem init failed: %d\n", opt);
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
/* set wroking certificates */
|
|
|
|
|
opt = connections_subsystem_setsslserts(rootca, cert, cert);
|
|
|
|
|
opt = connections_setsslserts(ssys, rootca, cert, cert);
|
|
|
|
|
if(opt) {
|
|
|
|
|
fprintf(stderr, "Subsystem init failed (set SSL x.509 pems): %d\n", opt);
|
|
|
|
|
return opt;
|
|
|
|
@ -226,10 +233,10 @@ int main(int argc, char **argv)
|
|
|
|
|
free(cert);
|
|
|
|
|
|
|
|
|
|
/* set important callbacks to do the security checking */
|
|
|
|
|
connections_subsystem_set_securecheck(ssys, __secure_check);
|
|
|
|
|
connections_subsystem_set_sslvalidator(ssys, __validate_sslpem);
|
|
|
|
|
connections_set_authcheck(ssys, __secure_check);
|
|
|
|
|
connections_set_sslvalidate(ssys, __validate_sslpem);
|
|
|
|
|
/* set a callback, it's optional and doesn't required in server side apps */
|
|
|
|
|
connections_subsystem_set_rpctlist_call(ssys, __set_typed_list_callback);
|
|
|
|
|
connections_set_channelcall(ssys, __set_typed_list_callback);
|
|
|
|
|
|
|
|
|
|
/* ok, now we need to construct RPC lists (channels) */
|
|
|
|
|
if(!(fulist = malloc(sizeof(usrtc_t)))) {
|
|
|
|
@ -259,7 +266,7 @@ int main(int argc, char **argv)
|
|
|
|
|
if(opt) goto __fail;
|
|
|
|
|
|
|
|
|
|
/* ok, setup it */
|
|
|
|
|
connections_subsystem_setrpclist_function(__rettlist);
|
|
|
|
|
connections_set_rpcvalidator(ssys, __rettlist);
|
|
|
|
|
|
|
|
|
|
/* now we're ready to run the listen process */
|
|
|
|
|
int srv = __openlistener(port);
|
|
|
|
|