LICENSE: sxmp going to be opensource; removed obsolete examples;
parent
b7ab605c09
commit
139d63f50b
@ -1,6 +1,2 @@
|
|||||||
This software was developed by Askele companies group.
|
* Alexander Vdolainen <avdolainen@gmail.com>
|
||||||
* EU part: http://askele.com
|
* Win32/64 porting: Eugene Tarasov <etr@askele.com>
|
||||||
* NW European part of Russia: http://askele-ingria.com
|
|
||||||
Team:
|
|
||||||
* General SW Architect and PM: Alexander Vdolainen <vdo@askele.com>
|
|
||||||
* Win32 porting: Eugene Tarasov <etr@askele.com>
|
|
||||||
|
@ -1,3 +1,166 @@
|
|||||||
Askele business software license.
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
|
||||||
|
This version of the GNU Lesser General Public License incorporates
|
||||||
|
the terms and conditions of version 3 of the GNU General Public
|
||||||
|
License, supplemented by the additional permissions listed below.
|
||||||
|
|
||||||
|
0. Additional Definitions.
|
||||||
|
|
||||||
|
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||||
|
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||||
|
General Public License.
|
||||||
|
|
||||||
|
"The Library" refers to a covered work governed by this License,
|
||||||
|
other than an Application or a Combined Work as defined below.
|
||||||
|
|
||||||
|
An "Application" is any work that makes use of an interface provided
|
||||||
|
by the Library, but which is not otherwise based on the Library.
|
||||||
|
Defining a subclass of a class defined by the Library is deemed a mode
|
||||||
|
of using an interface provided by the Library.
|
||||||
|
|
||||||
|
A "Combined Work" is a work produced by combining or linking an
|
||||||
|
Application with the Library. The particular version of the Library
|
||||||
|
with which the Combined Work was made is also called the "Linked
|
||||||
|
Version".
|
||||||
|
|
||||||
|
The "Minimal Corresponding Source" for a Combined Work means the
|
||||||
|
Corresponding Source for the Combined Work, excluding any source code
|
||||||
|
for portions of the Combined Work that, considered in isolation, are
|
||||||
|
based on the Application, and not on the Linked Version.
|
||||||
|
|
||||||
|
The "Corresponding Application Code" for a Combined Work means the
|
||||||
|
object code and/or source code for the Application, including any data
|
||||||
|
and utility programs needed for reproducing the Combined Work from the
|
||||||
|
Application, but excluding the System Libraries of the Combined Work.
|
||||||
|
|
||||||
|
1. Exception to Section 3 of the GNU GPL.
|
||||||
|
|
||||||
|
You may convey a covered work under sections 3 and 4 of this License
|
||||||
|
without being bound by section 3 of the GNU GPL.
|
||||||
|
|
||||||
|
2. Conveying Modified Versions.
|
||||||
|
|
||||||
|
If you modify a copy of the Library, and, in your modifications, a
|
||||||
|
facility refers to a function or data to be supplied by an Application
|
||||||
|
that uses the facility (other than as an argument passed when the
|
||||||
|
facility is invoked), then you may convey a copy of the modified
|
||||||
|
version:
|
||||||
|
|
||||||
|
a) under this License, provided that you make a good faith effort to
|
||||||
|
ensure that, in the event an Application does not supply the
|
||||||
|
function or data, the facility still operates, and performs
|
||||||
|
whatever part of its purpose remains meaningful, or
|
||||||
|
|
||||||
|
b) under the GNU GPL, with none of the additional permissions of
|
||||||
|
this License applicable to that copy.
|
||||||
|
|
||||||
|
3. Object Code Incorporating Material from Library Header Files.
|
||||||
|
|
||||||
|
The object code form of an Application may incorporate material from
|
||||||
|
a header file that is part of the Library. You may convey such object
|
||||||
|
code under terms of your choice, provided that, if the incorporated
|
||||||
|
material is not limited to numerical parameters, data structure
|
||||||
|
layouts and accessors, or small macros, inline functions and templates
|
||||||
|
(ten or fewer lines in length), you do both of the following:
|
||||||
|
|
||||||
|
a) Give prominent notice with each copy of the object code that the
|
||||||
|
Library is used in it and that the Library and its use are
|
||||||
|
covered by this License.
|
||||||
|
|
||||||
|
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||||
|
document.
|
||||||
|
|
||||||
|
4. Combined Works.
|
||||||
|
|
||||||
|
You may convey a Combined Work under terms of your choice that,
|
||||||
|
taken together, effectively do not restrict modification of the
|
||||||
|
portions of the Library contained in the Combined Work and reverse
|
||||||
|
engineering for debugging such modifications, if you also do each of
|
||||||
|
the following:
|
||||||
|
|
||||||
|
a) Give prominent notice with each copy of the Combined Work that
|
||||||
|
the Library is used in it and that the Library and its use are
|
||||||
|
covered by this License.
|
||||||
|
|
||||||
|
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||||
|
document.
|
||||||
|
|
||||||
|
c) For a Combined Work that displays copyright notices during
|
||||||
|
execution, include the copyright notice for the Library among
|
||||||
|
these notices, as well as a reference directing the user to the
|
||||||
|
copies of the GNU GPL and this license document.
|
||||||
|
|
||||||
|
d) Do one of the following:
|
||||||
|
|
||||||
|
0) Convey the Minimal Corresponding Source under the terms of this
|
||||||
|
License, and the Corresponding Application Code in a form
|
||||||
|
suitable for, and under terms that permit, the user to
|
||||||
|
recombine or relink the Application with a modified version of
|
||||||
|
the Linked Version to produce a modified Combined Work, in the
|
||||||
|
manner specified by section 6 of the GNU GPL for conveying
|
||||||
|
Corresponding Source.
|
||||||
|
|
||||||
|
1) Use a suitable shared library mechanism for linking with the
|
||||||
|
Library. A suitable mechanism is one that (a) uses at run time
|
||||||
|
a copy of the Library already present on the user's computer
|
||||||
|
system, and (b) will operate properly with a modified version
|
||||||
|
of the Library that is interface-compatible with the Linked
|
||||||
|
Version.
|
||||||
|
|
||||||
|
e) Provide Installation Information, but only if you would otherwise
|
||||||
|
be required to provide such information under section 6 of the
|
||||||
|
GNU GPL, and only to the extent that such information is
|
||||||
|
necessary to install and execute a modified version of the
|
||||||
|
Combined Work produced by recombining or relinking the
|
||||||
|
Application with a modified version of the Linked Version. (If
|
||||||
|
you use option 4d0, the Installation Information must accompany
|
||||||
|
the Minimal Corresponding Source and Corresponding Application
|
||||||
|
Code. If you use option 4d1, you must provide the Installation
|
||||||
|
Information in the manner specified by section 6 of the GNU GPL
|
||||||
|
for conveying Corresponding Source.)
|
||||||
|
|
||||||
|
5. Combined Libraries.
|
||||||
|
|
||||||
|
You may place library facilities that are a work based on the
|
||||||
|
Library side by side in a single library together with other library
|
||||||
|
facilities that are not Applications and are not covered by this
|
||||||
|
License, and convey such a combined library under terms of your
|
||||||
|
choice, if you do both of the following:
|
||||||
|
|
||||||
|
a) Accompany the combined library with a copy of the same work based
|
||||||
|
on the Library, uncombined with any other library facilities,
|
||||||
|
conveyed under the terms of this License.
|
||||||
|
|
||||||
|
b) Give prominent notice with the combined library that part of it
|
||||||
|
is a work based on the Library, and explaining where to find the
|
||||||
|
accompanying uncombined form of the same work.
|
||||||
|
|
||||||
|
6. Revised Versions of the GNU Lesser General Public License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the GNU Lesser General Public License from time to time. Such new
|
||||||
|
versions will be similar in spirit to the present version, but may
|
||||||
|
differ in detail to address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Library as you received it specifies that a certain numbered version
|
||||||
|
of the GNU Lesser General Public License "or any later version"
|
||||||
|
applies to it, you have the option of following the terms and
|
||||||
|
conditions either of that published version or of any later version
|
||||||
|
published by the Free Software Foundation. If the Library as you
|
||||||
|
received it does not specify a version number of the GNU Lesser
|
||||||
|
General Public License, you may choose any version of the GNU Lesser
|
||||||
|
General Public License ever published by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Library as you received it specifies that a proxy can decide
|
||||||
|
whether future versions of the GNU Lesser General Public License shall
|
||||||
|
apply, that proxy's public statement of acceptance of any version is
|
||||||
|
permanent authorization for you to choose that version for the
|
||||||
|
Library.
|
||||||
|
|
||||||
Libs and others might be under LGPLv3.
|
|
@ -1,166 +0,0 @@
|
|||||||
GNU LESSER GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 29 June 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
|
|
||||||
This version of the GNU Lesser General Public License incorporates
|
|
||||||
the terms and conditions of version 3 of the GNU General Public
|
|
||||||
License, supplemented by the additional permissions listed below.
|
|
||||||
|
|
||||||
0. Additional Definitions.
|
|
||||||
|
|
||||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
||||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
||||||
General Public License.
|
|
||||||
|
|
||||||
"The Library" refers to a covered work governed by this License,
|
|
||||||
other than an Application or a Combined Work as defined below.
|
|
||||||
|
|
||||||
An "Application" is any work that makes use of an interface provided
|
|
||||||
by the Library, but which is not otherwise based on the Library.
|
|
||||||
Defining a subclass of a class defined by the Library is deemed a mode
|
|
||||||
of using an interface provided by the Library.
|
|
||||||
|
|
||||||
A "Combined Work" is a work produced by combining or linking an
|
|
||||||
Application with the Library. The particular version of the Library
|
|
||||||
with which the Combined Work was made is also called the "Linked
|
|
||||||
Version".
|
|
||||||
|
|
||||||
The "Minimal Corresponding Source" for a Combined Work means the
|
|
||||||
Corresponding Source for the Combined Work, excluding any source code
|
|
||||||
for portions of the Combined Work that, considered in isolation, are
|
|
||||||
based on the Application, and not on the Linked Version.
|
|
||||||
|
|
||||||
The "Corresponding Application Code" for a Combined Work means the
|
|
||||||
object code and/or source code for the Application, including any data
|
|
||||||
and utility programs needed for reproducing the Combined Work from the
|
|
||||||
Application, but excluding the System Libraries of the Combined Work.
|
|
||||||
|
|
||||||
1. Exception to Section 3 of the GNU GPL.
|
|
||||||
|
|
||||||
You may convey a covered work under sections 3 and 4 of this License
|
|
||||||
without being bound by section 3 of the GNU GPL.
|
|
||||||
|
|
||||||
2. Conveying Modified Versions.
|
|
||||||
|
|
||||||
If you modify a copy of the Library, and, in your modifications, a
|
|
||||||
facility refers to a function or data to be supplied by an Application
|
|
||||||
that uses the facility (other than as an argument passed when the
|
|
||||||
facility is invoked), then you may convey a copy of the modified
|
|
||||||
version:
|
|
||||||
|
|
||||||
a) under this License, provided that you make a good faith effort to
|
|
||||||
ensure that, in the event an Application does not supply the
|
|
||||||
function or data, the facility still operates, and performs
|
|
||||||
whatever part of its purpose remains meaningful, or
|
|
||||||
|
|
||||||
b) under the GNU GPL, with none of the additional permissions of
|
|
||||||
this License applicable to that copy.
|
|
||||||
|
|
||||||
3. Object Code Incorporating Material from Library Header Files.
|
|
||||||
|
|
||||||
The object code form of an Application may incorporate material from
|
|
||||||
a header file that is part of the Library. You may convey such object
|
|
||||||
code under terms of your choice, provided that, if the incorporated
|
|
||||||
material is not limited to numerical parameters, data structure
|
|
||||||
layouts and accessors, or small macros, inline functions and templates
|
|
||||||
(ten or fewer lines in length), you do both of the following:
|
|
||||||
|
|
||||||
a) Give prominent notice with each copy of the object code that the
|
|
||||||
Library is used in it and that the Library and its use are
|
|
||||||
covered by this License.
|
|
||||||
|
|
||||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
||||||
document.
|
|
||||||
|
|
||||||
4. Combined Works.
|
|
||||||
|
|
||||||
You may convey a Combined Work under terms of your choice that,
|
|
||||||
taken together, effectively do not restrict modification of the
|
|
||||||
portions of the Library contained in the Combined Work and reverse
|
|
||||||
engineering for debugging such modifications, if you also do each of
|
|
||||||
the following:
|
|
||||||
|
|
||||||
a) Give prominent notice with each copy of the Combined Work that
|
|
||||||
the Library is used in it and that the Library and its use are
|
|
||||||
covered by this License.
|
|
||||||
|
|
||||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
||||||
document.
|
|
||||||
|
|
||||||
c) For a Combined Work that displays copyright notices during
|
|
||||||
execution, include the copyright notice for the Library among
|
|
||||||
these notices, as well as a reference directing the user to the
|
|
||||||
copies of the GNU GPL and this license document.
|
|
||||||
|
|
||||||
d) Do one of the following:
|
|
||||||
|
|
||||||
0) Convey the Minimal Corresponding Source under the terms of this
|
|
||||||
License, and the Corresponding Application Code in a form
|
|
||||||
suitable for, and under terms that permit, the user to
|
|
||||||
recombine or relink the Application with a modified version of
|
|
||||||
the Linked Version to produce a modified Combined Work, in the
|
|
||||||
manner specified by section 6 of the GNU GPL for conveying
|
|
||||||
Corresponding Source.
|
|
||||||
|
|
||||||
1) Use a suitable shared library mechanism for linking with the
|
|
||||||
Library. A suitable mechanism is one that (a) uses at run time
|
|
||||||
a copy of the Library already present on the user's computer
|
|
||||||
system, and (b) will operate properly with a modified version
|
|
||||||
of the Library that is interface-compatible with the Linked
|
|
||||||
Version.
|
|
||||||
|
|
||||||
e) Provide Installation Information, but only if you would otherwise
|
|
||||||
be required to provide such information under section 6 of the
|
|
||||||
GNU GPL, and only to the extent that such information is
|
|
||||||
necessary to install and execute a modified version of the
|
|
||||||
Combined Work produced by recombining or relinking the
|
|
||||||
Application with a modified version of the Linked Version. (If
|
|
||||||
you use option 4d0, the Installation Information must accompany
|
|
||||||
the Minimal Corresponding Source and Corresponding Application
|
|
||||||
Code. If you use option 4d1, you must provide the Installation
|
|
||||||
Information in the manner specified by section 6 of the GNU GPL
|
|
||||||
for conveying Corresponding Source.)
|
|
||||||
|
|
||||||
5. Combined Libraries.
|
|
||||||
|
|
||||||
You may place library facilities that are a work based on the
|
|
||||||
Library side by side in a single library together with other library
|
|
||||||
facilities that are not Applications and are not covered by this
|
|
||||||
License, and convey such a combined library under terms of your
|
|
||||||
choice, if you do both of the following:
|
|
||||||
|
|
||||||
a) Accompany the combined library with a copy of the same work based
|
|
||||||
on the Library, uncombined with any other library facilities,
|
|
||||||
conveyed under the terms of this License.
|
|
||||||
|
|
||||||
b) Give prominent notice with the combined library that part of it
|
|
||||||
is a work based on the Library, and explaining where to find the
|
|
||||||
accompanying uncombined form of the same work.
|
|
||||||
|
|
||||||
6. Revised Versions of the GNU Lesser General Public License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions
|
|
||||||
of the GNU Lesser General Public License from time to time. Such new
|
|
||||||
versions will be similar in spirit to the present version, but may
|
|
||||||
differ in detail to address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Library as you received it specifies that a certain numbered version
|
|
||||||
of the GNU Lesser General Public License "or any later version"
|
|
||||||
applies to it, you have the option of following the terms and
|
|
||||||
conditions either of that published version or of any later version
|
|
||||||
published by the Free Software Foundation. If the Library as you
|
|
||||||
received it does not specify a version number of the GNU Lesser
|
|
||||||
General Public License, you may choose any version of the GNU Lesser
|
|
||||||
General Public License ever published by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Library as you received it specifies that a proxy can decide
|
|
||||||
whether future versions of the GNU Lesser General Public License shall
|
|
||||||
apply, that proxy's public statement of acceptance of any version is
|
|
||||||
permanent authorization for you to choose that version for the
|
|
||||||
Library.
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
|||||||
## AUTOMAKE_OPTIONS = foreign
|
|
||||||
|
|
||||||
AM_CPPFLAGS = \
|
|
||||||
-DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \
|
|
||||||
-DPACKAGE_SRC_DIR=\""$(srcdir)"\" \
|
|
||||||
-DPACKAGE_DATA_DIR=\""$(pkgdatadir)"\" \
|
|
||||||
-DCNFPATH=\""$(prefix)/etc"\" \
|
|
||||||
-I../include \
|
|
||||||
-I../lib
|
|
||||||
|
|
||||||
AM_CFLAGS = -Wall -g
|
|
||||||
|
|
||||||
if !COND_WIN32
|
|
||||||
LIBS += $(ZOFFICE_LIBS)
|
|
||||||
endif !COND_WIN32
|
|
||||||
|
|
||||||
libsntl = ../lib/.libs/libsntl.la
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if !COND_WIN32
|
|
||||||
|
|
||||||
bin_PROGRAMS = sntlc sntld gentest
|
|
||||||
|
|
||||||
sntld_SOURCES = sntld.c
|
|
||||||
sntld_LDADD = $(LIBTDATA_LIBS) $(LIBSEXPR_LIBS) $(OPENSSL_LIBS) \
|
|
||||||
$(LIBUUID_LIBS) $(libsntl)
|
|
||||||
|
|
||||||
sntlc_SOURCES = sntlc.c
|
|
||||||
sntlc_LDADD = $(LIBTDATA_LIBS) $(LIBSEXPR_LIBS) $(OPENSSL_LIBS) \
|
|
||||||
$(LIBUUID_LIBS) $(libsntl)
|
|
||||||
|
|
||||||
gentest_SOURCES = gentest.c
|
|
||||||
gentest_LDADD = $(LIBTDATA_LIBS) $(LIBSEXPR_LIBS) $(OPENSSL_LIBS) \
|
|
||||||
$(LIBUUID_LIBS) $(libsntl)
|
|
||||||
|
|
||||||
else COND_WIN32
|
|
||||||
|
|
||||||
bin_PROGRAMS = sntlc
|
|
||||||
|
|
||||||
sntlc_SOURCES = sntlc.c
|
|
||||||
sntlc_LDADD = $(LIBTDATA_LIBS) $(LIBSEXPR_LIBS) $(OPENSSL_LIBS) \
|
|
||||||
$(LIBUUID_LIBS) $(libsntl) -lws2_32
|
|
||||||
|
|
||||||
endif COND_WIN32
|
|
||||||
|
|
||||||
#zsyncd_LDFLAGS = \
|
|
||||||
# -Wl,--export-dynamic
|
|
||||||
#zsyncd_LDADD = $(GMODULE_LIBS) $(GLIB_LIBS) $(GIO_LIBS) ../libs/libdata/.libs/libtdata.a ../libs/libsexpr/.libs/libsexpr.a
|
|
@ -1,418 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#define __USE_GNU
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <getopt.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#include <Winsock2.h>
|
|
||||||
#include <signal.h>
|
|
||||||
// #include <ws2tcpip.h>
|
|
||||||
#else
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <sys/select.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/resource.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <uuid/uuid.h>
|
|
||||||
#include <execinfo.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <tdata/usrtc.h>
|
|
||||||
#include <sexpr/sexp.h>
|
|
||||||
#include <sntl/connection.h>
|
|
||||||
|
|
||||||
/* define a little bit */
|
|
||||||
#define DEFAULT_PORT 13133
|
|
||||||
#define CHANNEL_COUNT 200
|
|
||||||
#define CLIENT_COUNT 100
|
|
||||||
#define MESSAGES_PER_SESSION 10000
|
|
||||||
#define ITERATION_COUNT 1000
|
|
||||||
|
|
||||||
#define FAILS_ONLY
|
|
||||||
//#define SIMPLE_TESTING
|
|
||||||
|
|
||||||
static FILE *log_file = NULL;
|
|
||||||
|
|
||||||
inline int log_init(const char *file)
|
|
||||||
{
|
|
||||||
if(log_file) {
|
|
||||||
fclose(log_file);
|
|
||||||
}
|
|
||||||
log_file = fopen(file, "w");
|
|
||||||
if(!log_file) return EIO;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void log_msg(const char *prefix, const char *data)
|
|
||||||
{
|
|
||||||
if(log_file) fprintf(log_file, "[%s]: %s\n", prefix, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void log_begin(const char *data)
|
|
||||||
{
|
|
||||||
#ifndef FAILS_ONLY
|
|
||||||
log_msg("BEGIN", data);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void log_end(const char *data)
|
|
||||||
{
|
|
||||||
#ifndef FAILS_ONLY
|
|
||||||
log_msg("END", data);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void log_info(const char *data)
|
|
||||||
{
|
|
||||||
#ifndef FAILS_ONLY
|
|
||||||
log_msg("INFO", data);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void log_error(const char *data)
|
|
||||||
{
|
|
||||||
log_msg("FAILED", data);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void log_assert(const char *info, int rc, int exp)
|
|
||||||
{
|
|
||||||
if(log_file && (rc) != (exp)) {
|
|
||||||
fprintf(log_file, "[FAILED]: %s result: %d, expected: %d\n", info, rc, exp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void log_close()
|
|
||||||
{
|
|
||||||
if(log_file) {
|
|
||||||
fflush(log_file);
|
|
||||||
fclose(log_file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void log_flush()
|
|
||||||
{
|
|
||||||
fflush(log_file);
|
|
||||||
}
|
|
||||||
|
|
||||||
void signal_error(int sig, siginfo_t *si, void *ptr)
|
|
||||||
{
|
|
||||||
void* error_addr;
|
|
||||||
void* trace[16];
|
|
||||||
int x;
|
|
||||||
int trace_size;
|
|
||||||
char** messages;
|
|
||||||
|
|
||||||
fprintf(stderr, "Something is wrong: backtrace: \n");
|
|
||||||
uintptr_t fptr = (uintptr_t)(si->si_addr);
|
|
||||||
fprintf(stderr, "Signal: %d, function pointer: 0x%.12lX \n", sig, fptr);
|
|
||||||
#if __WORDSIZE == 64
|
|
||||||
error_addr = (void*)((ucontext_t*)ptr)->uc_mcontext.gregs[REG_RIP];
|
|
||||||
#else
|
|
||||||
error_addr = (void*)((ucontext_t*)ptr)->uc_mcontext.gregs[REG_EIP];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
trace_size = backtrace(trace, 16);
|
|
||||||
trace[1] = error_addr;
|
|
||||||
|
|
||||||
messages = backtrace_symbols(trace, trace_size);
|
|
||||||
if (messages)
|
|
||||||
{
|
|
||||||
for (x = 1; x < trace_size; x++)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s\n", messages[x]);
|
|
||||||
}
|
|
||||||
free(messages);
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stderr, "end of backtrace\n");
|
|
||||||
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
pthread_t **threads;
|
|
||||||
int thread_count;
|
|
||||||
conn_t *co;
|
|
||||||
} test_data_t;
|
|
||||||
|
|
||||||
/*static*/ sexp_t *make_request(const char *req)
|
|
||||||
{
|
|
||||||
char *request = strdup(req);
|
|
||||||
sexp_t *sx = parse_sexp(request, strlen(request));
|
|
||||||
free(request);
|
|
||||||
return sx;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*static */int allocate_threads(int count, test_data_t *data)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
data->threads = (pthread_t **)malloc(count * sizeof(pthread_t *));
|
|
||||||
for(i = 0; i < count; ++i) {
|
|
||||||
data->threads[i] = (pthread_t *)malloc(sizeof(pthread_t));
|
|
||||||
if(!data->threads) return ENOMEM;
|
|
||||||
}
|
|
||||||
data->thread_count = count;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/*static */int deallocate_threads(test_data_t *data)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
for(i = 0; i < data->thread_count; ++i) {
|
|
||||||
if(!data->threads[i]) return EINVAL;
|
|
||||||
pthread_join(*data->threads[i], NULL);
|
|
||||||
free(data->threads[i]);
|
|
||||||
data->threads[i] = 0;
|
|
||||||
}
|
|
||||||
free(data->threads);
|
|
||||||
data->thread_count = 0;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *test_invalid_channel(void *ctx)
|
|
||||||
{
|
|
||||||
log_begin("Invalid channel testing");
|
|
||||||
conn_t *co = (conn_t *)ctx;
|
|
||||||
chnl_t *channel = NULL;
|
|
||||||
int rc = 0, i;
|
|
||||||
for(i = 0; i < ITERATION_COUNT || ITERATION_COUNT < 0; ++i) {
|
|
||||||
rc = channel_open(co, &channel, 1);
|
|
||||||
log_assert("channel_open with type 1", rc, EINVAL);
|
|
||||||
// TODO: segmentation fault below
|
|
||||||
//rc = channel_close(channel);
|
|
||||||
//log_assert("channel_close with type 1", rc, EINVAL);
|
|
||||||
}
|
|
||||||
log_end("Invalid channel testing");
|
|
||||||
return 0x00;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *test_correct_channel(void *ctx)
|
|
||||||
{
|
|
||||||
log_begin("Channel testing");
|
|
||||||
|
|
||||||
conn_t *co = (conn_t *)ctx;
|
|
||||||
chnl_t *channel = NULL;
|
|
||||||
int rc = 0, i, j;
|
|
||||||
char buf[128];
|
|
||||||
time_t start, end;
|
|
||||||
int a, b;
|
|
||||||
sexp_t *add_request = NULL;
|
|
||||||
sxmsg_t *msg = NULL;
|
|
||||||
double exec_time;
|
|
||||||
|
|
||||||
for(j = 0; j < ITERATION_COUNT || ITERATION_COUNT < 0; ++j) {
|
|
||||||
rc = channel_open(co, &channel, 12);
|
|
||||||
log_assert("channel_open with type 12", rc, 0);
|
|
||||||
log_begin("Test messaging");
|
|
||||||
//#if 0
|
|
||||||
for(i = 0; i < MESSAGES_PER_SESSION; ++i) {
|
|
||||||
a = rand() % 100;
|
|
||||||
b = rand() % 100;
|
|
||||||
sprintf(buf, "(ar-add (%d %d))", a, b);
|
|
||||||
add_request = make_request(buf);
|
|
||||||
time(&start);
|
|
||||||
rc = msg_send(channel, add_request, &msg);
|
|
||||||
time(&end);
|
|
||||||
exec_time = difftime(end, start);
|
|
||||||
sprintf(buf, "rpc execution time: %lf", exec_time);
|
|
||||||
log_info(buf);
|
|
||||||
log_assert("rpc execution", rc, a + b);
|
|
||||||
//destroy_sexp(add_request);
|
|
||||||
}
|
|
||||||
//#endif
|
|
||||||
log_end("Test messaging");
|
|
||||||
|
|
||||||
rc = channel_close(channel);
|
|
||||||
log_assert("channel_close with type 12", rc, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
log_end("Channel testing");
|
|
||||||
return 0x00;
|
|
||||||
}
|
|
||||||
|
|
||||||
int test_channels(test_data_t *data, int index)
|
|
||||||
{
|
|
||||||
int rc = 0;
|
|
||||||
if(index < CLIENT_COUNT) {
|
|
||||||
rc = pthread_create(data->threads[index], NULL, test_correct_channel, data->co);
|
|
||||||
} else {
|
|
||||||
rc = pthread_create(data->threads[index], NULL, test_invalid_channel, data->co);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_channel_handling(conn_t *co)
|
|
||||||
{
|
|
||||||
chnl_t *channel = NULL;
|
|
||||||
int rc = 0, i = 0;
|
|
||||||
|
|
||||||
for(i = 0; i < ITERATION_COUNT; ++i) {
|
|
||||||
rc = channel_open(co, &channel, 12);
|
|
||||||
log_assert("channel open function", rc, 0);
|
|
||||||
rc = channel_close(channel);
|
|
||||||
log_assert("channel close function", rc, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_message_handling(conn_t* co)
|
|
||||||
{
|
|
||||||
chnl_t *channel = NULL;
|
|
||||||
int rc = 0, i = 0, a = 0, b = 0;
|
|
||||||
sexp_t *sx = NULL;
|
|
||||||
char *buf = NULL;
|
|
||||||
sxmsg_t *msg = NULL;
|
|
||||||
|
|
||||||
buf = malloc(4096);
|
|
||||||
rc = channel_open(co, &channel, 12);
|
|
||||||
log_assert("channel open function", rc, 0);
|
|
||||||
for(i = 0; i < ITERATION_COUNT; ++i) {
|
|
||||||
a = rand() % 100;
|
|
||||||
b = rand() % 100;
|
|
||||||
sprintf(buf, "(ar-add (%d %d))", a, b);
|
|
||||||
sx = parse_sexp(buf, strlen(buf));
|
|
||||||
rc = msg_send(channel, sx, &msg);
|
|
||||||
log_assert("message send function", rc, a + b);
|
|
||||||
// destroy_sexp(sx);
|
|
||||||
}
|
|
||||||
rc = channel_close(channel);
|
|
||||||
free(buf);
|
|
||||||
log_assert("channel close function", rc, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
// set detailed signal handler
|
|
||||||
struct sigaction sigact;
|
|
||||||
sigact.sa_flags = SA_SIGINFO;
|
|
||||||
sigact.sa_sigaction = signal_error;
|
|
||||||
sigemptyset(&sigact.sa_mask);
|
|
||||||
sigaction(SIGFPE, &sigact, 0);
|
|
||||||
sigaction(SIGILL, &sigact, 0);
|
|
||||||
sigaction(SIGSEGV, &sigact, 0);
|
|
||||||
sigaction(SIGBUS, &sigact, 0);
|
|
||||||
|
|
||||||
char *rootca = NULL, *cert = NULL;
|
|
||||||
int port = DEFAULT_PORT;
|
|
||||||
char *addr = NULL, *login = NULL, *password = NULL;
|
|
||||||
int opt;
|
|
||||||
#ifndef SIMPLE_TESTING
|
|
||||||
int rc, i;
|
|
||||||
#endif
|
|
||||||
while((opt = getopt(argc, argv, "p:r:a:u:l:w:")) != -1) {
|
|
||||||
switch(opt) {
|
|
||||||
case 'p':
|
|
||||||
port = atoi(optarg);
|
|
||||||
break;
|
|
||||||
case 'r':
|
|
||||||
rootca = strdup(optarg);
|
|
||||||
break;
|
|
||||||
case 'a':
|
|
||||||
addr = strdup(optarg);
|
|
||||||
break;
|
|
||||||
case 'u':
|
|
||||||
cert = strdup(optarg);
|
|
||||||
break;
|
|
||||||
case 'l':
|
|
||||||
login = strdup(optarg);
|
|
||||||
break;
|
|
||||||
case 'w':
|
|
||||||
password = strdup(optarg);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fprintf(stderr, "usage: %s [-p <PORTNUM>] -r <PATH to Root CA> -a <Server ip address> -u <PATH"
|
|
||||||
" to SSL certificate> -l <User login> -w <User password>\n", argv[0]);
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!rootca) {
|
|
||||||
fprintf(stderr, "Root CA not pointed.\n Failure.\n");
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!addr) {
|
|
||||||
fprintf(stderr, "Server address not pointed.\n Failure.\n");
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!cert) {
|
|
||||||
fprintf(stderr, "User certificate not pointed.\n Failure.\n");
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!login) {
|
|
||||||
fprintf(stderr, "User login not pointed.\n Failure.\n");
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!password) {
|
|
||||||
fprintf(stderr, "User password not pointed.\n Failure.\n");
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* all is fine let's init connection subsystem */
|
|
||||||
opt = connections_subsystem_init();
|
|
||||||
if(opt) {
|
|
||||||
fprintf(stderr, "Subsystem init failed: %d\n", opt);
|
|
||||||
return opt;
|
|
||||||
}
|
|
||||||
/* set working certificates */
|
|
||||||
opt = connections_subsystem_setsslserts(rootca, cert, cert);
|
|
||||||
if(opt) {
|
|
||||||
fprintf(stderr, "Subsystem init failed (set SSL x.509 pems): %d\n", opt);
|
|
||||||
return opt;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Tests */
|
|
||||||
/* try to open connection */
|
|
||||||
conn_t *co = malloc(sizeof(conn_t)), *co2 = malloc(sizeof(conn_t));
|
|
||||||
perm_ctx_t *ctx = (perm_ctx_t *)malloc(sizeof(perm_ctx_t));
|
|
||||||
ctx->login = login;
|
|
||||||
ctx->passwd = password;
|
|
||||||
|
|
||||||
log_init("test.log");
|
|
||||||
|
|
||||||
log_begin("Connection initiate");
|
|
||||||
log_assert("Connection initiate", connection_initiate(co, addr, port, cert, ctx), 0);
|
|
||||||
log_end("Connection initiate");
|
|
||||||
|
|
||||||
log_begin("Connection initiate (second one for test)");
|
|
||||||
log_assert("Connection initiate (second)", connection_initiate(co2, addr, port, cert, ctx), 0);
|
|
||||||
log_end("Connection initiate (second)");
|
|
||||||
|
|
||||||
printf("HERE!!!!\n");
|
|
||||||
|
|
||||||
log_begin("Connection close");
|
|
||||||
log_assert("Connection close", connection_close(co), 0);
|
|
||||||
log_end("Connection close");
|
|
||||||
|
|
||||||
log_begin("Connection close (second)");
|
|
||||||
log_assert("Connection close (second)", connection_close(co2), 0);
|
|
||||||
log_end("Connection close (second)");
|
|
||||||
|
|
||||||
log_close();
|
|
||||||
|
|
||||||
free(rootca);
|
|
||||||
free(cert);
|
|
||||||
free(co);
|
|
||||||
free(ctx);
|
|
||||||
free(password);
|
|
||||||
free(login);
|
|
||||||
free(addr);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,433 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#define __USE_GNU
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
// #include <arpa/inet.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <getopt.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <assert.h>
|
|
||||||
#include <time.h>
|
|
||||||
// #include <sys/wait.h>
|
|
||||||
|
|
||||||
#include <tdata/usrtc.h>
|
|
||||||
#include <sexpr/sexp.h>
|
|
||||||
#include <sntl/connection.h>
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#include <Winsock2.h>
|
|
||||||
#include <signal.h>
|
|
||||||
// #include <ws2tcpip.h>
|
|
||||||
#else
|
|
||||||
#include <sys/select.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/resource.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <uuid/uuid.h>
|
|
||||||
#include <execinfo.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#endif
|
|
||||||
/* define a little bit */
|
|
||||||
#define DEFAULT_PORT 13133
|
|
||||||
#define CHANNEL_COUNT 200
|
|
||||||
#define CLIENT_COUNT 100
|
|
||||||
#define MESSAGES_PER_SESSION 10000
|
|
||||||
#define ITERATION_COUNT 1000
|
|
||||||
|
|
||||||
#define FAILS_ONLY
|
|
||||||
//#define SIMPLE_TESTING
|
|
||||||
|
|
||||||
static FILE *log_file = NULL;
|
|
||||||
|
|
||||||
inline int log_init(const char *file)
|
|
||||||
{
|
|
||||||
if(log_file) {
|
|
||||||
fclose(log_file);
|
|
||||||
}
|
|
||||||
log_file = fopen(file, "w");
|
|
||||||
if(!log_file) return EIO;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void log_msg(const char *prefix, const char *data)
|
|
||||||
{
|
|
||||||
if(log_file) fprintf(log_file, "[%s]: %s\n", prefix, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void log_begin(const char *data)
|
|
||||||
{
|
|
||||||
#ifndef FAILS_ONLY
|
|
||||||
log_msg("BEGIN", data);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void log_end(const char *data)
|
|
||||||
{
|
|
||||||
#ifndef FAILS_ONLY
|
|
||||||
log_msg("END", data);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void log_info(const char *data)
|
|
||||||
{
|
|
||||||
#ifndef FAILS_ONLY
|
|
||||||
log_msg("INFO", data);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void log_error(const char *data)
|
|
||||||
{
|
|
||||||
log_msg("FAILED", data);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void log_assert(const char *info, int rc, int exp)
|
|
||||||
{
|
|
||||||
if(log_file && (rc) != (exp)) {
|
|
||||||
fprintf(log_file, "[FAILED]: %s result: %d, expected: %d\n", info, rc, exp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void log_close()
|
|
||||||
{
|
|
||||||
if(log_file) {
|
|
||||||
fflush(log_file);
|
|
||||||
fclose(log_file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void log_flush()
|
|
||||||
{
|
|
||||||
fflush(log_file);
|
|
||||||
}
|
|
||||||
|
|
||||||
// void signal_error(int sig, siginfo_t *si, void *ptr)
|
|
||||||
// {
|
|
||||||
// void* error_addr;
|
|
||||||
// void* trace[16];
|
|
||||||
// int x;
|
|
||||||
// int trace_size;
|
|
||||||
// char** messages;
|
|
||||||
|
|
||||||
// fprintf(stderr, "Something is wrong: backtrace: \n");
|
|
||||||
// uintptr_t fptr = (uintptr_t)(si->si_addr);
|
|
||||||
// fprintf(stderr, "Signal: %d, function pointer: 0x%.12lX \n", sig, fptr);
|
|
||||||
// #if __WORDSIZE == 64
|
|
||||||
// error_addr = (void*)((ucontext_t*)ptr)->uc_mcontext.gregs[REG_RIP];
|
|
||||||
// #else
|
|
||||||
// error_addr = (void*)((ucontext_t*)ptr)->uc_mcontext.gregs[REG_EIP];
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
// trace_size = backtrace(trace, 16);
|
|
||||||
// trace[1] = error_addr;
|
|
||||||
|
|
||||||
// messages = backtrace_symbols(trace, trace_size);
|
|
||||||
// if (messages)
|
|
||||||
// {
|
|
||||||
// for (x = 1; x < trace_size; x++)
|
|
||||||
// {
|
|
||||||
// fprintf(stderr, "%s\n", messages[x]);
|
|
||||||
// }
|
|
||||||
// free(messages);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fprintf(stderr, "end of backtrace\n");
|
|
||||||
|
|
||||||
// exit(1);
|
|
||||||
// }
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
pthread_t **threads;
|
|
||||||
int thread_count;
|
|
||||||
conn_t *co;
|
|
||||||
} test_data_t;
|
|
||||||
|
|
||||||
/*static*/ sexp_t *make_request(const char *req)
|
|
||||||
{
|
|
||||||
char *request = strdup(req);
|
|
||||||
sexp_t *sx = parse_sexp(request, strlen(request));
|
|
||||||
free(request);
|
|
||||||
return sx;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*static */int allocate_threads(int count, test_data_t *data)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
data->threads = (pthread_t **)malloc(count * sizeof(pthread_t *));
|
|
||||||
for(i = 0; i < count; ++i) {
|
|
||||||
data->threads[i] = (pthread_t *)malloc(sizeof(pthread_t));
|
|
||||||
if(!data->threads) return ENOMEM;
|
|
||||||
}
|
|
||||||
data->thread_count = count;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/*static */int deallocate_threads(test_data_t *data)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
for(i = 0; i < data->thread_count; ++i) {
|
|
||||||
if(!data->threads[i]) return EINVAL;
|
|
||||||
pthread_join(*data->threads[i], NULL);
|
|
||||||
free(data->threads[i]);
|
|
||||||
data->threads[i] = 0;
|
|
||||||
}
|
|
||||||
free(data->threads);
|
|
||||||
data->thread_count = 0;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *test_invalid_channel(void *ctx)
|
|
||||||
{
|
|
||||||
log_begin("Invalid channel testing");
|
|
||||||
conn_t *co = (conn_t *)ctx;
|
|
||||||
chnl_t *channel = NULL;
|
|
||||||
int rc = 0, i;
|
|
||||||
for(i = 0; i < ITERATION_COUNT || ITERATION_COUNT < 0; ++i) {
|
|
||||||
rc = channel_open(co, &channel, 1);
|
|
||||||
log_assert("channel_open with type 1", rc, EINVAL);
|
|
||||||
// TODO: segmentation fault below
|
|
||||||
//rc = channel_close(channel);
|
|
||||||
//log_assert("channel_close with type 1", rc, EINVAL);
|
|
||||||
}
|
|
||||||
log_end("Invalid channel testing");
|
|
||||||
return 0x00;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *test_correct_channel(void *ctx)
|
|
||||||
{
|
|
||||||
log_begin("Channel testing");
|
|
||||||
|
|
||||||
conn_t *co = (conn_t *)ctx;
|
|
||||||
chnl_t *channel = NULL;
|
|
||||||
int rc = 0, i, j;
|
|
||||||
char buf[128];
|
|
||||||
time_t start, end;
|
|
||||||
int a, b;
|
|
||||||
sexp_t *add_request = NULL;
|
|
||||||
sxmsg_t *msg = NULL;
|
|
||||||
double exec_time;
|
|
||||||
|
|
||||||
for(j = 0; j < ITERATION_COUNT || ITERATION_COUNT < 0; ++j) {
|
|
||||||
rc = channel_open(co, &channel, 12);
|
|
||||||
log_assert("channel_open with type 12", rc, 0);
|
|
||||||
log_begin("Test messaging");
|
|
||||||
//#if 0
|
|
||||||
for(i = 0; i < MESSAGES_PER_SESSION; ++i) {
|
|
||||||
a = rand() % 100;
|
|
||||||
b = rand() % 100;
|
|
||||||
sprintf(buf, "(ar-add (%d %d))", a, b);
|
|
||||||
add_request = make_request(buf);
|
|
||||||
time(&start);
|
|
||||||
rc = msg_send(channel, add_request, &msg);
|
|
||||||
time(&end);
|
|
||||||
exec_time = difftime(end, start);
|
|
||||||
sprintf(buf, "rpc execution time: %lf", exec_time);
|
|
||||||
log_info(buf);
|
|
||||||
log_assert("rpc execution", rc, a + b);
|
|
||||||
//destroy_sexp(add_request);
|
|
||||||
}
|
|
||||||
//#endif
|
|
||||||
log_end("Test messaging");
|
|
||||||
|
|
||||||
rc = channel_close(channel);
|
|
||||||
log_assert("channel_close with type 12", rc, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
log_end("Channel testing");
|
|
||||||
return 0x00;
|
|
||||||
}
|
|
||||||
|
|
||||||
int test_channels(test_data_t *data, int index)
|
|
||||||
{
|
|
||||||
int rc = 0;
|
|
||||||
if(index < CLIENT_COUNT) {
|
|
||||||
rc = pthread_create(data->threads[index], NULL, test_correct_channel, data->co);
|
|
||||||
} else {
|
|
||||||
rc = pthread_create(data->threads[index], NULL, test_invalid_channel, data->co);
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_channel_handling(conn_t *co)
|
|
||||||
{
|
|
||||||
chnl_t *channel = NULL;
|
|
||||||
int rc = 0, i = 0;
|
|
||||||
|
|
||||||
for(i = 0; i < ITERATION_COUNT; ++i) {
|
|
||||||
rc = channel_open(co, &channel, 12);
|
|
||||||
log_assert("channel open function", rc, 0);
|
|
||||||
rc = channel_close(channel);
|
|
||||||
log_assert("channel close function", rc, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_message_handling(conn_t* co)
|
|
||||||
{
|
|
||||||
chnl_t *channel = NULL;
|
|
||||||
int rc = 0, i = 0, a = 0, b = 0;
|
|
||||||
sexp_t *sx = NULL;
|
|
||||||
char *buf = NULL;
|
|
||||||
sxmsg_t *msg = NULL;
|
|
||||||
|
|
||||||
buf = malloc(4096);
|
|
||||||
rc = channel_open(co, &channel, 12);
|
|
||||||
log_assert("channel open function", rc, 0);
|
|
||||||
for(i = 0; i < ITERATION_COUNT; ++i) {
|
|
||||||
a = rand() % 100;
|
|
||||||
b = rand() % 100;
|
|
||||||
sprintf(buf, "(ar-add (%d %d))", a, b);
|
|
||||||
sx = parse_sexp(buf, strlen(buf));
|
|
||||||
rc = msg_send(channel, sx, &msg);
|
|
||||||
log_assert("message send function", rc, a + b);
|
|
||||||
// destroy_sexp(sx);
|
|
||||||
}
|
|
||||||
rc = channel_close(channel);
|
|
||||||
free(buf);
|
|
||||||
log_assert("channel close function", rc, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
// set detailed signal handler
|
|
||||||
// struct sigaction sigact;
|
|
||||||
// sigact.sa_flags = SA_SIGINFO;
|
|
||||||
// sigact.sa_sigaction = signal_error;
|
|
||||||
// sigemptyset(&sigact.sa_mask);
|
|
||||||
// sigaction(SIGFPE, &sigact, 0);
|
|
||||||
// sigaction(SIGILL, &sigact, 0);
|
|
||||||
// sigaction(SIGSEGV, &sigact, 0);
|
|
||||||
// sigaction(SIGBUS, &sigact, 0);
|
|
||||||
|
|
||||||
char *rootca = NULL, *cert = NULL;
|
|
||||||
int port = DEFAULT_PORT;
|
|
||||||
char *addr = NULL, *login = NULL, *password = NULL;
|
|
||||||
int opt,ret;
|
|
||||||
#ifndef SIMPLE_TESTING
|
|
||||||
int rc, i;
|
|
||||||
#endif
|
|
||||||
while((opt = getopt(argc, argv, "p:r:a:u:l:w:")) != -1) {
|
|
||||||
switch(opt) {
|
|
||||||
case 'p':
|
|
||||||
port = atoi(optarg);
|
|
||||||
break;
|
|
||||||
case 'r':
|
|
||||||
rootca = strdup(optarg);
|
|
||||||
break;
|
|
||||||
case 'a':
|
|
||||||
addr = strdup(optarg);
|
|
||||||
break;
|
|
||||||
case 'u':
|
|
||||||
cert = strdup(optarg);
|
|
||||||
break;
|
|
||||||
case 'l':
|
|
||||||
login = strdup(optarg);
|
|
||||||
break;
|
|
||||||
case 'w':
|
|
||||||
password = strdup(optarg);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fprintf(stderr, "usage: %s [-p <PORTNUM>] -r <PATH to Root CA> -a <Server ip address> -u <PATH"
|
|
||||||
" to SSL certificate> -l <User login> -w <User password>\n", argv[0]);
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!rootca) {
|
|
||||||
fprintf(stderr, "Root CA not pointed.\n Failure.\n");
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!addr) {
|
|
||||||
fprintf(stderr, "Server address not pointed.\n Failure.\n");
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!cert) {
|
|
||||||
fprintf(stderr, "User certificate not pointed.\n Failure.\n");
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!login) {
|
|
||||||
fprintf(stderr, "User login not pointed.\n Failure.\n");
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!password) {
|
|
||||||
fprintf(stderr, "User password not pointed.\n Failure.\n");
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* all is fine let's init connection subsystem */
|
|
||||||
opt = connections_subsystem_init();
|
|
||||||
if(opt) {
|
|
||||||
fprintf(stderr, "Subsystem init failed: %d\n", opt);
|
|
||||||
return opt;
|
|
||||||
}
|
|
||||||
/* set working certificates */
|
|
||||||
opt = connections_subsystem_setsslserts(rootca, cert, cert);
|
|
||||||
if(opt) {
|
|
||||||
fprintf(stderr, "Subsystem init failed (set SSL x.509 pems): %d\n", opt);
|
|
||||||
return opt;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Tests */
|
|
||||||
/* try to open connection */
|
|
||||||
conn_t *co = malloc(sizeof(conn_t));
|
|
||||||
perm_ctx_t *ctx = (perm_ctx_t *)malloc(sizeof(perm_ctx_t));
|
|
||||||
ctx->login = login;
|
|
||||||
ctx->passwd = password;
|
|
||||||
|
|
||||||
log_init("test.log");
|
|
||||||
|
|
||||||
log_begin("Connection initiate");
|
|
||||||
|
|
||||||
connections_subsystem_set_rpctlist_call(conn_sys,NULL);
|
|
||||||
ret=connection_initiate(co, addr, port, cert, ctx);
|
|
||||||
|
|
||||||
// log_assert("Connection initiate", connection_initiate(co, addr, port, cert, ctx), 0);
|
|
||||||
|
|
||||||
if(ret)
|
|
||||||
return;
|
|
||||||
|
|
||||||
log_end("Connection initiate");
|
|
||||||
|
|
||||||
#ifndef SIMPLE_TESTING
|
|
||||||
test_data_t data;
|
|
||||||
data.co = co;
|
|
||||||
rc = allocate_threads(CHANNEL_COUNT, &data);
|
|
||||||
log_assert("Thread list allocation", rc, 0);
|
|
||||||
|
|
||||||
for(i = 0; i < CHANNEL_COUNT; ++i) {
|
|
||||||
log_assert("Channel testing", test_channels(&data, i), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = deallocate_threads(&data);
|
|
||||||
log_assert("Thread list deallocation", rc, 0);
|
|
||||||
#endif
|
|
||||||
#ifdef SIMPLE_TESTING
|
|
||||||
test_channel_handling(co);
|
|
||||||
//test_message_handling(co);
|
|
||||||
#endif
|
|
||||||
printf("HERE!!!!\n");
|
|
||||||
log_begin("Connection close");
|
|
||||||
log_assert("Connection close", connection_close(co), 0);
|
|
||||||
log_end("Connection close");
|
|
||||||
|
|
||||||
log_close();
|
|
||||||
|
|
||||||
|
|
||||||
free(rootca);
|
|
||||||
free(cert);
|
|
||||||
free(co);
|
|
||||||
free(ctx);
|
|
||||||
free(password);
|
|
||||||
free(login);
|
|
||||||
free(addr);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,307 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#define __USE_GNU
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#include <Winsock2.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <ws2tcpip.h>
|
|
||||||
#else
|
|
||||||
#include <sys/select.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/resource.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <uuid/uuid.h>
|
|
||||||
#include <execinfo.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <tdata/usrtc.h>
|
|
||||||
#include <sexpr/sexp.h>
|
|
||||||
#include <sntl/connection.h>
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
// #include <unistd.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <getopt.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef WIN32
|
|
||||||
void signal_error(int sig, siginfo_t *si, void *ptr)
|
|
||||||
{
|
|
||||||
void* error_addr;
|
|
||||||
void* trace[16];
|
|
||||||
int x;
|
|
||||||
int trace_size;
|
|
||||||
char** messages;
|
|
||||||
|
|
||||||
fprintf(stderr, "Something is wrong: backtrace: \n");
|
|
||||||
uintptr_t fptr = (uintptr_t)(si->si_addr);
|
|
||||||
fprintf(stderr, "Signal: %d, function pointer: 0x%.12lX \n", sig, fptr);
|
|
||||||
#if __WORDSIZE == 64
|
|
||||||
error_addr = (void*)((ucontext_t*)ptr)->uc_mcontext.gregs[REG_RIP];
|
|
||||||
#else
|
|
||||||
error_addr = (void*)((ucontext_t*)ptr)->uc_mcontext.gregs[REG_EIP];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
trace_size = backtrace(trace, 16);
|
|
||||||
trace[1] = error_addr;
|
|
||||||
|
|
||||||
messages = backtrace_symbols(trace, trace_size);
|
|
||||||
if (messages)
|
|
||||||
{
|
|
||||||
for (x = 1; x < trace_size; x++)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s\n", messages[x]);
|
|
||||||
}
|
|
||||||
free(messages);
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stderr, "end of backtrace\n");
|
|
||||||
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* helper functions */
|
|
||||||
int __openlistener(int port)
|
|
||||||
{
|
|
||||||
int sd;
|
|
||||||
struct sockaddr_in addr;
|
|
||||||
|
|
||||||
sd = socket(PF_INET, SOCK_STREAM, 0);
|
|
||||||
bzero(&addr, sizeof(addr));
|
|
||||||
addr.sin_family = AF_INET;
|
|
||||||
addr.sin_port = htons(port);
|
|
||||||
addr.sin_addr.s_addr = INADDR_ANY;
|
|
||||||
if ( bind(sd, (struct sockaddr*)&addr, sizeof(addr)) != 0 ) {
|
|
||||||
perror("can't bind port");
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
if ( listen(sd, 10) != 0 ) {
|
|
||||||
perror("Can't configure listening port");
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
return sd;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Validation of the SSL certificate
|
|
||||||
* this function must be exist.
|
|
||||||
*/
|
|
||||||
static int __validate_sslpem(conn_t *co)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* validate - authorize user with password
|
|
||||||
*/
|
|
||||||
static int __secure_check(conn_t *co)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* typed list callback
|
|
||||||
*/
|
|
||||||
static int __set_typed_list_callback(conn_t *co, int ch, char *desc)
|
|
||||||
{
|
|
||||||
printf("allowed channel %d (%s)\n", ch, desc);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* list of rpc calls functions */
|
|
||||||
usrtc_t *fulist;
|
|
||||||
|
|
||||||
/* our fake */
|
|
||||||
usrtc_t *__rettlist(conn_t *c)
|
|
||||||
{
|
|
||||||
return fulist;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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;
|
|
||||||
|
|
||||||
if(sexp_list_cdr(sx, &lsx)) {
|
|
||||||
printf("Invalid protocol\n");
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
sum += atoi(sx_iter->val);
|
|
||||||
}
|
|
||||||
rc = msg_return(msg, sum);
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int __ar_multiply(void *data, sexp_t *sx)
|
|
||||||
{
|
|
||||||
sexp_t *lsx = NULL;
|
|
||||||
int idx;
|
|
||||||
sexp_t *sx_iter;
|
|
||||||
if(sexp_list_cdr(sx, &lsx)) {
|
|
||||||
printf("Invalid protocol\n");
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
mult *= atoi(sx_iter->val);
|
|
||||||
}
|
|
||||||
char buf[128];
|
|
||||||
sprintf(buf, "(ar_mult_set (%ld))", mult);
|
|
||||||
printf("result %s\n", buf);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* define a little bit */
|
|
||||||
#define DEFAULT_PORT 13133
|
|
||||||
|
|
||||||
static void sigpipe_handler(int a)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
// set detailed signal handler
|
|
||||||
// struct sigaction sigact, sigpipe;
|
|
||||||
// sigact.sa_flags = SA_SIGINFO;
|
|
||||||
// sigact.sa_sigaction = signal_error;
|
|
||||||
// sigemptyset(&sigact.sa_mask);
|
|
||||||
// sigaction(SIGFPE, &sigact, 0);
|
|
||||||
// sigaction(SIGILL, &sigact, 0);
|
|
||||||
// sigaction(SIGSEGV, &sigact, 0);
|
|
||||||
// sigaction(SIGBUS, &sigact, 0);
|
|
||||||
|
|
||||||
// memset(&sigpipe, 0, sizeof(struct sigaction));
|
|
||||||
// sigpipe.sa_handler = sigpipe_handler;
|
|
||||||
// sigaction(SIGPIPE, &sigpipe, NULL);
|
|
||||||
|
|
||||||
char *rootca = NULL, *cert = NULL;
|
|
||||||
int port = DEFAULT_PORT;
|
|
||||||
int opt;
|
|
||||||
|
|
||||||
while((opt = getopt(argc, argv, "p:r:u:")) != -1) {
|
|
||||||
switch(opt) {
|
|
||||||
case 'p':
|
|
||||||
port = atoi(optarg);
|
|
||||||
break;
|
|
||||||
case 'r':
|
|
||||||
rootca = strdup(optarg);
|
|
||||||
break;
|
|
||||||
case 'u':
|
|
||||||
cert = strdup(optarg);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
fprintf(stderr, "usage: %s [-p <PORTNUM>] -r <PATH to Root CA> -u <PATH"
|
|
||||||
" to SSL certificate>\n", argv[0]);
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!rootca) {
|
|
||||||
fprintf(stderr, "Root CA not pointed.\n Failure.\n");
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!cert) {
|
|
||||||
fprintf(stderr, "User certificate not pointed.\n Failure.\n");
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* all is fine let's init connection subsystem */
|
|
||||||
opt = connections_subsystem_init();
|
|
||||||
if(opt) {
|
|
||||||
fprintf(stderr, "Subsystem init failed: %d\n", opt);
|
|
||||||
return opt;
|
|
||||||
}
|
|
||||||
/* set wroking certificates */
|
|
||||||
opt = connections_subsystem_setsslserts(rootca, cert, cert);
|
|
||||||
if(opt) {
|
|
||||||
fprintf(stderr, "Subsystem init failed (set SSL x.509 pems): %d\n", opt);
|
|
||||||
return opt;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* clean up */
|
|
||||||
free(rootca);
|
|
||||||
free(cert);
|
|
||||||
|
|
||||||
/* set important callbacks to do the security checking */
|
|
||||||
connections_subsystem_set_securecheck(conn_sys, __secure_check);
|
|
||||||
connections_subsystem_set_sslvalidator(conn_sys, __validate_sslpem);
|
|
||||||
/* set a callback, it's optional and doesn't required in server side apps */
|
|
||||||
connections_subsystem_set_rpctlist_call(conn_sys, __set_typed_list_callback);
|
|
||||||
|
|
||||||
/* ok, now we need to construct RPC lists (channels) */
|
|
||||||
if(!(fulist = malloc(sizeof(usrtc_t)))) {
|
|
||||||
fprintf(stderr, "Cannot allocate memory for RPC lists\n Failure.\n");
|
|
||||||
return ENOMEM;
|
|
||||||
}
|
|
||||||
opt = sntl_rpclist_init(fulist);
|
|
||||||
if(opt) {
|
|
||||||
fprintf(stderr, "Failed to init rpc list\n Failure.\n");
|
|
||||||
return opt;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* we will add one channel with type id 12 "Demo rpc list" */
|
|
||||||
opt = sntl_rpclist_add(fulist, 12, "Demo RPC list", NULL);
|
|
||||||
if(opt) {
|
|
||||||
fprintf(stderr, "Failed to add typed RPC channel\n Failure.\n");
|
|
||||||
return opt;
|
|
||||||
}
|
|
||||||
/* ok, let's add two functions */
|
|
||||||
opt = sntl_rpclist_add_function(fulist, 12, "ar-add", __ar_add);
|
|
||||||
if(opt) {
|
|
||||||
__fail:
|
|
||||||
fprintf(stderr, "Failed to add functions to typed RPC channel\n Failure.\n");
|
|
||||||
return opt;
|
|
||||||
}
|
|
||||||
opt = sntl_rpclist_add_function(fulist, 12, "ar-multiply", __ar_multiply);
|
|
||||||
if(opt) goto __fail;
|
|
||||||
|
|
||||||
/* ok, setup it */
|
|
||||||
connections_subsystem_setrpclist_function(__rettlist);
|
|
||||||
|
|
||||||
/* now we're ready to run the listen process */
|
|
||||||
int srv = __openlistener(port);
|
|
||||||
while(1) {
|
|
||||||
struct sockaddr_in addr;
|
|
||||||
socklen_t len = sizeof(addr);
|
|
||||||
conn_t *co = malloc(sizeof(conn_t));
|
|
||||||
|
|
||||||
int client = accept(srv, (struct sockaddr*)&addr, &len); /* accept connection as usual */
|
|
||||||
opt = connection_create(co, client); /* create connection, that's all */
|
|
||||||
if(opt) {
|
|
||||||
fprintf(stderr, "Cannot create connetion (%d)\n", opt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
Reference in New Issue