| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  |  * Secure X Message Passing Library v2 implementation. | 
					
						
							|  |  |  |  * (sxmplv2) it superseed all versions before due to the: | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |  * - memory consumption | 
					
						
							|  |  |  |  * - new features such as pulse emitting | 
					
						
							|  |  |  |  * - performance optimization | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * (c) Askele Group 2013-2015 <http://askele.com>
 | 
					
						
							| 
									
										
										
										
											2015-12-29 20:16:55 +02:00
										 |  |  |  * (c) Alexander Vdolainen 2013-2015 <avdolainen@gmail.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * libsxmp is free software: you can redistribute it and/or modify it | 
					
						
							|  |  |  |  * under the terms of the GNU Lesser General Public License as published | 
					
						
							|  |  |  |  * by the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * libsxmp 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 Lesser General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Lesser General Public License | 
					
						
							|  |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>.";
 | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | #ifndef __SXMP_SXMPLV2_H__
 | 
					
						
							|  |  |  | #define	__SXMP_SXMPLV2_H__
 | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <stdint.h>
 | 
					
						
							|  |  |  | #include <time.h>
 | 
					
						
							|  |  |  | #include <sys/types.h>
 | 
					
						
							|  |  |  | #include <pthread.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <openssl/ssl.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <tdata/usrtc.h>
 | 
					
						
							|  |  |  | #include <tdata/idx_allocator.h>
 | 
					
						
							|  |  |  | #include <tdata/list.h>
 | 
					
						
							|  |  |  | #include <sexpr/sexp.h>
 | 
					
						
							|  |  |  | #include <sexpr/faststack.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | #include <sxmp/errno.h>
 | 
					
						
							| 
									
										
										
										
											2015-11-10 23:06:51 +02:00
										 |  |  | #include <sxmp/version.h>
 | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define VERIFY_DEPTH  1  /* FIXME: */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | typedef struct __session_context_type { | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |   char *login; | 
					
						
							|  |  |  |   char *passwd; | 
					
						
							|  |  |  |   uint64_t certid; | 
					
						
							|  |  |  |   struct in_addr *addr; | 
					
						
							|  |  |  |   void *priv; | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | } sxsession_ctx_t; | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* 8 byte header */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | typedef struct __sxmplv2_head_type { | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |   uint16_t msgid; | 
					
						
							|  |  |  |   uint16_t payload_length; | 
					
						
							|  |  |  |   uint8_t attr; | 
					
						
							|  |  |  |   uint8_t opcode; | 
					
						
							|  |  |  |   uint16_t reserve; | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | }__attribute__((packed)) sxmplv2_head_t; | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | struct __sxhub_type; | 
					
						
							|  |  |  | struct __sxchannel_t; | 
					
						
							|  |  |  | struct __sxmsg_t; | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* flags for the connection link */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | #define SXMP_BATCHMODE      (1 << 1)
 | 
					
						
							|  |  |  | #define SXMP_MESSAGINGMODE  (1 << 2)
 | 
					
						
							|  |  |  | #define SXMP_ALIVE          (1 << 3)
 | 
					
						
							|  |  |  | #define SXMP_CLOSED         (1 << 4)
 | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * älä jätä kommentteja omalla kielellä! yksinkertaisia englanti sijaan! | 
					
						
							|  |  |  |  * i found somebody who write comments and messages in non-english, | 
					
						
							|  |  |  |  * it's a fucking practice - forget it. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | typedef struct __sxlink_t { | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |   /* General section */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  |   struct __sxhub_type *ssys; /* < hub subsystem */ | 
					
						
							|  |  |  |   char *uuid; /** < uuid of the link */ | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |   /* Channels section */ | 
					
						
							|  |  |  |   idx_allocator_t idx_ch; /** < index allocation for channels */ | 
					
						
							|  |  |  |   pthread_mutex_t idx_ch_lock; /** < mutex for allocating and deallocating channels */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  |   struct __sxchannel_t **channels; /** < channels O(1) storage */ | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |   /* RPC section */ | 
					
						
							|  |  |  |   usrtc_t *rpc_list; /** < search tree of possible RPC typed lists */ | 
					
						
							|  |  |  |   /* SSL related section */ | 
					
						
							|  |  |  |   SSL *ssl; /** < SSL connection */ | 
					
						
							|  |  |  |   int ssl_data_index; /** < SSL index for the custom data */ | 
					
						
							|  |  |  |   pthread_mutex_t sslinout[2]; /** < SSL related locks for in and out */ | 
					
						
							|  |  |  |   /* Security section */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  |   sxsession_ctx_t *pctx; /** < higher layer authentification and session context */ | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |   /* Messages section */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  |   struct __sxmsg_t **messages; /** < messages O(1) storage */ | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |   idx_allocator_t idx_msg; | 
					
						
							|  |  |  |   pthread_mutex_t idx_msg_lock; | 
					
						
							|  |  |  |   list_head_t write_pending;  /** < list of messages waiting for write */ | 
					
						
							|  |  |  |   pthread_mutex_t write_pending_lock; | 
					
						
							| 
									
										
										
										
											2015-07-25 03:25:35 +03:00
										 |  |  |   volatile uint8_t pending_messages; /** < pending message count */ | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |   /* Other stuff */ | 
					
						
							|  |  |  |   pthread_t thrd_poll[8]; | 
					
						
							|  |  |  |   volatile uint8_t flags; /** < flags of the connection */ | 
					
						
							| 
									
										
										
										
											2015-08-07 15:35:02 +03:00
										 |  |  |   volatile uint8_t usecount; /** < use count for the connection link */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  |   usrtc_node_t csnode; /** < node to store the link within list */ | 
					
						
							|  |  |  | } sxlink_t; | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | #define sxlink_getpctx(c)     (c)->pctx
 | 
					
						
							|  |  |  | #define sxlink_getpriv(c)     (c)->pctx->priv
 | 
					
						
							|  |  |  | #define sxlink_setpriv(c, p)  (c)->pctx->priv = (void *)(p)
 | 
					
						
							| 
									
										
										
										
											2015-08-04 17:38:33 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | struct __link_rpc_list_type; | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | typedef struct __pp_msg_type { /* postponed message entry */ | 
					
						
							|  |  |  |   struct __sxmsg_t *msg; | 
					
						
							| 
									
										
										
										
											2015-07-21 02:24:08 +03:00
										 |  |  |   list_node_t node; | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | } sxppmsg_t; | 
					
						
							| 
									
										
										
										
											2015-07-21 02:24:08 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | typedef struct __sxchannel_t { | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |   uint16_t cid; /** < ID of the channel */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  |   sxlink_t *link; /** < pointer to the underlying link */ | 
					
						
							|  |  |  |   struct __link_rpc_list_type *rpc_list; /** < rpc functions list */ | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |   int flags; /** < flags of the channel */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | } sxchnl_t; | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* message flags */ | 
					
						
							|  |  |  | #define SXMSG_OPEN      (1 << 1)
 | 
					
						
							|  |  |  | #define SXMSG_CLOSED    (1 << 2)
 | 
					
						
							|  |  |  | #define SXMSG_PROTO     (1 << 3)
 | 
					
						
							|  |  |  | #define SXMSG_LINK      (1 << 4)
 | 
					
						
							|  |  |  | #define SXMSG_REPLYREQ  (1 << 5)
 | 
					
						
							|  |  |  | #define SXMSG_PULSE     (1 << 6)
 | 
					
						
							|  |  |  | #define SXMSG_TIMEDOUT  (1 << 7)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  |  * \brief Message used in sxmp message passing | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This structure used to manage a message within a channel | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  |  * of the sxmp structure stack. | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | typedef struct __sxmsg_t { | 
					
						
							|  |  |  |   sxchnl_t *pch; /** < channel of the message(if applicable) */ | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |   pthread_mutex_t wait; /** < special wait mutex, used for pending list and sync */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  |   sxmplv2_head_t mhead; /** < last actual head of the message */ | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |   void *payload; /** < payload */ | 
					
						
							|  |  |  | } sxmsg_t; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define sxmsg_payload(m)   (m)->payload
 | 
					
						
							|  |  |  | #define sxmsg_datalen(m)   (m)->mhead.payload_length
 | 
					
						
							|  |  |  | #define sxmsg_rapidbuf(m)  (m)->payload
 | 
					
						
							|  |  |  | #define sxmsg_retcode(m)   (m)->mhead.opcode
 | 
					
						
							|  |  |  | #define sxmsg_waitlock(m)  pthread_mutex_lock(&((m)->wait))
 | 
					
						
							|  |  |  | #define sxmsg_waitunlock(m)  pthread_mutex_unlock(&((m)->wait))
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | typedef struct __link_rpc_entry_type { | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |   char *name; | 
					
						
							|  |  |  |   int (*rpcf)(void *, sexp_t *); | 
					
						
							|  |  |  |   usrtc_node_t node; | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | } sxl_rpc_t; | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | typedef struct __link_rpc_list_type { | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |   usrtc_t *rpc_tree; /** < search tree for the rpc lookup */ | 
					
						
							|  |  |  |   char *opt_version; /** < reserved for future implementations */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | } sxl_rpclist_t; | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  |  * \brief Hub subsystem structure. | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This structure used for management and control a set of a | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  |  * determined links with the same RPC lists and the same | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |  * mode (server, client). | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | typedef struct __sxhub_type { | 
					
						
							|  |  |  |   usrtc_t *links; | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |   pthread_rwlock_t rwlock; | 
					
						
							|  |  |  |   char *rootca, *certpem, *certkey; /* path name to the certificates */ | 
					
						
							| 
									
										
										
										
											2015-10-22 19:05:30 +03:00
										 |  |  |   sxl_rpclist_t *system_rpc; | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |   /* special functions pointers */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  |   int (*validate_sslpem)(sxlink_t *); /** < this function used to validate SSL certificate while SSL handshake */ | 
					
						
							|  |  |  |   int (*secure_check)(sxlink_t *); /** < this function authorize user to login,
 | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |                                   * and also should check SSL cert and user, and already made sessions */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  |   usrtc_t* (*get_rpc_typed_list_tree)(sxlink_t *); /** < this function is used to set RPC list of the functions */ | 
					
						
							|  |  |  |   int (*set_typed_list_callback)(sxlink_t *, int, char *); /** < this function is a callback
 | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |                                                           * during setting up a typed channel */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  |   void (*on_destroy)(sxlink_t *); /** < callback on connection destroy  */ | 
					
						
							|  |  |  |   void (*on_pulse)(sxlink_t *, sexp_t *);  /** < callback on pulse emit */ | 
					
						
							| 
									
										
										
										
											2015-08-03 14:17:11 +03:00
										 |  |  |   SSL_CTX *ctx; /** < SSL context */ | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |   void *priv; | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | } sxhub_t; | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | #define sxhub_set_sslvalidate(c, f)  (c)->validate_sslpem = (f)
 | 
					
						
							|  |  |  | #define sxhub_set_authcheck(c, f)  (c)->secure_check = (f)
 | 
					
						
							|  |  |  | #define sxhub_set_rpcvalidator(c, f)  (c)->get_rpc_typed_list_tree = (f)
 | 
					
						
							|  |  |  | #define sxhub_set_channelcall(c, f)  (c)->set_typed_list_callback = (f)
 | 
					
						
							|  |  |  | #define sxhub_set_ondestroy(c, f)  (c)->on_destroy = (f)
 | 
					
						
							|  |  |  | #define sxhub_set_onpulse(c, f)  (c)->on_pulse = (f)
 | 
					
						
							|  |  |  | #define sxhub_set_priv(c, p)  (c)->priv = (p)
 | 
					
						
							|  |  |  | #define sxhub_get_priv(c)  (c)->priv
 | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | typedef struct __rpc_typed_list_type { | 
					
						
							|  |  |  |   int type_id; | 
					
						
							|  |  |  |   char *description; | 
					
						
							| 
									
										
										
										
											2015-10-22 19:05:30 +03:00
										 |  |  |   sxl_rpclist_t *rpc_list; | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  |   usrtc_node_t lnode; | 
					
						
							|  |  |  | } rpc_typed_list_t; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-21 04:06:06 +03:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | /* API */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | int sxmp_init(void); | 
					
						
							| 
									
										
										
										
											2015-07-25 02:37:21 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | void sxmp_finalize(void); | 
					
						
							| 
									
										
										
										
											2015-08-07 15:35:02 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | int sxhub_init(sxhub_t *ssys); | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | sxhub_t *sxhub_create(void); | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | int sxhub_destroy(sxhub_t *ssys); | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | int sxhub_free(sxhub_t *ssys); | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | int sxhub_setsslserts(sxhub_t *ssys, const char *rootca, | 
					
						
							|  |  |  |                       const char *certpem, const char *certkey); | 
					
						
							| 
									
										
										
										
											2015-07-23 14:57:30 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | /* create links */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | sxlink_t *sxlink_master_accept(sxhub_t *ssys, int sck, struct in_addr *addr); | 
					
						
							|  |  |  | sxlink_t *sxlink_connect(sxhub_t *ssys, const char *host, | 
					
						
							|  |  |  |                          int port, const char *SSL_cert, const char *login, | 
					
						
							|  |  |  |                          const char *passwd); | 
					
						
							|  |  |  | int sxlink_close(sxlink_t *co); | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* channels */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | sxchnl_t *sxchannel_open(sxlink_t *co, int type); | 
					
						
							|  |  |  | int sxchannel_close(sxchnl_t *channel); | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* messages */ | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * creates a message with a payload. | 
					
						
							|  |  |  |  * Will return a error code, and, if applicable, pointer to message | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | int sxmsg_send(sxchnl_t *channel, const char *data, size_t datalen, sxmsg_t **msg); | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | /* the same - postponed message i.e. will be written to the queue - not to write immendatly */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | int sxmsg_send_pp(sxchnl_t *channel, const char *data, size_t datalen, sxmsg_t **msg); | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | /* send a pulse message */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | int sxmsg_pulse(sxlink_t *co, const char *data, size_t datalen); | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 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); | 
					
						
							| 
									
										
										
										
											2015-07-21 04:06:06 +03:00
										 |  |  | int sxmsg_rreply(sxmsg_t *msg, size_t datalen); | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | int sxmsg_return(sxmsg_t *msg, int opcode); | 
					
						
							|  |  |  | int sxmsg_return_pp(sxmsg_t *msg, int opcode); | 
					
						
							| 
									
										
										
										
											2015-07-23 23:50:22 +03:00
										 |  |  | void sxmsg_clean(sxmsg_t *msg); | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-21 04:06:06 +03:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-20 19:15:08 +03:00
										 |  |  | /* RPC List API */ | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | #define SXMP_FILTER_INC  0xa
 | 
					
						
							|  |  |  | #define SXMP_FILTER_EXC  0xb
 | 
					
						
							|  |  |  | #define SXMP_FILTER_END  -1
 | 
					
						
							| 
									
										
										
										
											2015-07-20 19:15:08 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-21 04:06:06 +03:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | int sxmp_rpclist_init(usrtc_t *tree); | 
					
						
							| 
									
										
										
										
											2015-07-21 04:06:06 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | int sxmp_rpclist_add(usrtc_t *tree, int type, const char *description, | 
					
						
							| 
									
										
										
										
											2015-07-21 04:06:06 +03:00
										 |  |  |                      const char *version); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | int sxmp_rpclist_add_function(usrtc_t *tree, int type, const char *fu_name, | 
					
						
							| 
									
										
										
										
											2015-07-21 04:06:06 +03:00
										 |  |  |                               int (*rpcf)(void *, sexp_t *)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | int sxmp_rpclist_filter(usrtc_t *source, usrtc_t **dest, int flag, int *filter); | 
					
						
							| 
									
										
										
										
											2015-07-21 04:06:06 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 17:49:17 +03:00
										 |  |  | #define blub(txt)  fprintf(stderr, "%s:%d in %s > %s\n", __FILE__, __LINE__, __FUNCTION__, txt)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 23:50:22 +03:00
										 |  |  | #define dumphead(head) fprintf(stderr, "id: %d, opcode: %d, attr: %d, len = %d\n", head->msgid, head->opcode, head->attr, head->payload_length)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-22 04:42:57 +03:00
										 |  |  | #endif /* __SXMP_SXMPLV2_H__ */
 | 
					
						
							| 
									
										
										
										
											2015-07-20 18:34:07 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 |