diff --git a/Makefile.am b/Makefile.am index 38d595d..6c9163b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -15,7 +15,7 @@ endif SUBDIRS = include lib man $(EXAMPLES) $(TESTS) libsxmpdocdir = ${prefix}/doc/libsxmp -libsntldoc_DATA = \ +libsxmpdoc_DATA = \ README\ COPYING\ AUTHORS\ diff --git a/include/sxmp/sxmp.h b/include/sxmp/sxmp.h index c974c82..7dea8ef 100644 --- a/include/sxmp/sxmp.h +++ b/include/sxmp/sxmp.h @@ -163,7 +163,7 @@ typedef struct __sxhub_type { usrtc_t *links; pthread_rwlock_t rwlock; char *rootca, *certpem, *certkey; /* path name to the certificates */ - cx_rpc_list_t *system_rpc; + sxl_rpclist_t *system_rpc; /* special functions pointers */ 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, @@ -189,7 +189,7 @@ typedef struct __sxhub_type { typedef struct __rpc_typed_list_type { int type_id; char *description; - cx_rpc_list_t *rpc_list; + sxl_rpclist_t *rpc_list; usrtc_node_t lnode; } rpc_typed_list_t; diff --git a/lib/channel.c b/lib/channel.c index 5c3a8bb..c6a8ef9 100644 --- a/lib/channel.c +++ b/lib/channel.c @@ -38,33 +38,33 @@ #include #include -#include +#include #include "internal.h" /* locally used functions */ -uint8_t _channel_open(conn_t *co, uint16_t *chid) +uint8_t _channel_open(sxlink_t *co, uint16_t *chid) { - chnl_t *chan; + sxchnl_t *chan; int typeid = *chid; /* our type */ uint16_t chidx; usrtc_t *rpc_list = co->rpc_list; usrtc_node_t *node; rpc_typed_list_t *rlist; - cx_rpc_list_t *rpclist; + sxl_rpclist_t *rpclist; node = usrtc_lookup(rpc_list, &typeid); - if(!node) return SNE_EPERM; + if(!node) return SXE_EPERM; else rlist = (rpc_typed_list_t *)usrtc_node_getdata(node); if(rlist) rpclist = rlist->rpc_list; - else return SNE_FAILED; + else return SXE_FAILED; - chan = malloc(sizeof(chnl_t)); - if(!chan) return SNE_ENOMEM; + chan = malloc(sizeof(sxchnl_t)); + if(!chan) return SXE_ENOMEM; /* init channel */ - chan->connection = co; + chan->link = co; chan->rpc_list = rpclist; chan->flags = 0; @@ -74,25 +74,25 @@ uint8_t _channel_open(conn_t *co, uint16_t *chid) if(chidx == IDX_INVAL) { free(chan); - return SNE_MCHANNELS; + return SXE_MCHANNELS; } chan->cid = chidx; co->channels[chidx] = chan; *chid = chidx; - return SNE_SUCCESS; + return SXE_SUCCESS; } -uint8_t _channel_close(conn_t *co, uint16_t chid) +uint8_t _channel_close(sxlink_t *co, uint16_t chid) { - chnl_t *chan; + sxchnl_t *chan; ulong_t chidx = chid; - if(chid > 512) return SNE_INVALINDEX; + if(chid > 512) return SXE_INVALINDEX; else chan = co->channels[chidx]; - if(!chan) return SNE_NOSUCHCHAN; + if(!chan) return SXE_NOSUCHCHAN; pthread_mutex_lock(&co->idx_ch_lock); idx_free(&co->idx_ch, chidx); @@ -101,31 +101,31 @@ uint8_t _channel_close(conn_t *co, uint16_t chid) free(chan); - return SNE_SUCCESS; + return SXE_SUCCESS; } -chnl_t *sxchannel_open(conn_t *co, int type) +sxchnl_t *sxchannel_open(sxlink_t *co, int type) { - chnl_t *chan = NULL; + sxchnl_t *chan = NULL; sxmsg_t *msg = NULL; - sntllv2_head_t *head; + sxmplv2_head_t *head; int msgidx, r, ccid; if(!co) { - r = SNE_FAILED; + r = SXE_FAILED; goto __reterr; } - if(!(chan = malloc(sizeof(chnl_t)))) { + if(!(chan = malloc(sizeof(sxchnl_t)))) { __enomem: if(chan) free(chan); - r = SNE_ENOMEM; + r = SXE_ENOMEM; goto __reterr; } if(!(msg = malloc(sizeof(sxmsg_t)))) goto __enomem; /* early init for the channel */ - chan->connection = co; + chan->link = co; chan->flags = 0; /* early init for the message */ @@ -133,7 +133,7 @@ chnl_t *sxchannel_open(conn_t *co, int type) pthread_mutex_lock(&msg->wait); msg->pch = chan; msg->payload = NULL; - memset(&msg->mhead, 0, sizeof(sntllv2_head_t)); + memset(&msg->mhead, 0, sizeof(sxmplv2_head_t)); head = &msg->mhead; /* form a header */ @@ -147,16 +147,16 @@ chnl_t *sxchannel_open(conn_t *co, int type) if(msgidx != IDX_INVAL) co->messages[msgidx] = msg; pthread_mutex_unlock(&co->idx_msg_lock); - if(msgidx == IDX_INVAL) { r = SNE_MMESSAGES; goto __reterr2; } + if(msgidx == IDX_INVAL) { r = SXE_MMESSAGES; goto __reterr2; } else head->msgid = msgidx; /* now we're ready to write it */ - r = _sntll_writemsg(co, msg); - if(r == SNE_SUCCESS) pthread_mutex_lock(&msg->wait); + r = _sxmpl_writemsg(co, msg); + if(r == SXE_SUCCESS) pthread_mutex_lock(&msg->wait); else goto __reterr3; /* we will wakeup on return */ - if(msg->mhead.opcode != SNE_SUCCESS) { r = msg->mhead.opcode; goto __reterr3; } + if(msg->mhead.opcode != SXE_SUCCESS) { r = msg->mhead.opcode; goto __reterr3; } /* ok all is fine */ chan->cid = msg->mhead.reserve; @@ -194,24 +194,24 @@ chnl_t *sxchannel_open(conn_t *co, int type) return NULL; } -int sxchannel_close(chnl_t *channel) +int sxchannel_close(sxchnl_t *channel) { - int r = SNE_SUCCESS; + int r = SXE_SUCCESS; sxmsg_t *msg; - sntllv2_head_t *head; - conn_t *co; + sxmplv2_head_t *head; + sxlink_t *co; int msgidx = 0, chidx = 0; /* check channel validity */ - if(!channel) return SNE_FAILED; - else if(!(co = channel->connection)) return SNE_FAILED; - if(channel->cid > 512) return SNE_IGNORED; + if(!channel) return SXE_FAILED; + else if(!(co = channel->link)) return SXE_FAILED; + if(channel->cid > 512) return SXE_IGNORED; else chidx = channel->cid; - if(channel != co->channels[chidx]) return SNE_IGNORED; + if(channel != co->channels[chidx]) return SXE_IGNORED; - if(!(msg = malloc(sizeof(sxmsg_t)))) return SNE_ENOMEM; + if(!(msg = malloc(sizeof(sxmsg_t)))) return SXE_ENOMEM; head = &msg->mhead; - memset(head, 0, sizeof(sntllv2_head_t)); + memset(head, 0, sizeof(sxmplv2_head_t)); /* setup head */ head->attr = SXMSG_PROTO | SXMSG_REPLYREQ; /* close channel */ @@ -228,11 +228,11 @@ int sxchannel_close(chnl_t *channel) if(msgidx != IDX_INVAL) co->messages[msgidx] = msg; pthread_mutex_unlock(&co->idx_msg_lock); - if(msgidx == IDX_INVAL) { r = SNE_MMESSAGES; goto __reterr2; } + if(msgidx == IDX_INVAL) { r = SXE_MMESSAGES; goto __reterr2; } else head->msgid = msgidx; - r = _sntll_writemsg(co, msg); - if(r == SNE_SUCCESS) { + r = _sxmpl_writemsg(co, msg); + if(r == SXE_SUCCESS) { pthread_mutex_lock(&msg->wait); r = head->opcode; diff --git a/lib/internal.h b/lib/internal.h index 121106a..101e8c2 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -1,14 +1,14 @@ -#ifndef __SNTLL_INTERNAL_H__ -#define __SNTLL_INTERNAL_H__ +#ifndef __SXMPL_INTERNAL_H__ +#define __SXMPL_INTERNAL_H__ /* link related */ -int _sntll_writemsg(conn_t *co, sxmsg_t *msg); +int _sxmpl_writemsg(sxlink_t *co, sxmsg_t *msg); /* channel operations */ -uint8_t _channel_open(conn_t *co, uint16_t *chid); -uint8_t _channel_close(conn_t *co, uint16_t chid); +uint8_t _channel_open(sxlink_t *co, uint16_t *chid); +uint8_t _channel_close(sxlink_t *co, uint16_t chid); /* messages */ void _message_process(sxmsg_t *msg); -#endif /* __SNTLL_INTERNAL_H__ */ +#endif /* __SXMPL_INTERNAL_H__ */ diff --git a/lib/link.c b/lib/link.c index 14f3b29..3af06f4 100644 --- a/lib/link.c +++ b/lib/link.c @@ -38,11 +38,12 @@ #include #include -#include +#include +#include static int __insert_rpc_function(usrtc_t *tree, const char *name, int (*rpcf)(void *, sexp_t *)) { - cx_rpc_t *ent = malloc(sizeof(cx_rpc_t)); + sxl_rpc_t *ent = malloc(sizeof(sxl_rpc_t)); usrtc_node_t *node; if(!ent) return ENOMEM; @@ -62,10 +63,10 @@ static int __insert_rpc_function(usrtc_t *tree, const char *name, int (*rpcf)(vo static void __destroy_rpc_list_tree(usrtc_t *tree) { usrtc_node_t *node; - cx_rpc_t *ent; + sxl_rpc_t *ent; for(node = usrtc_first(tree); node != NULL; node = usrtc_first(tree)) { - ent = (cx_rpc_t *)usrtc_node_getdata(node); + ent = (sxl_rpc_t *)usrtc_node_getdata(node); usrtc_delete(tree, node); free(ent->name); free(ent); @@ -83,45 +84,45 @@ static void __destroy_rpc_list_tree(usrtc_t *tree) static int __set_credentials(void *cctx, sexp_t *sx) { register int idx; - conn_t *co = (conn_t *)cctx; - conn_sys_t *ssys = co->ssys; + sxlink_t *co = (sxlink_t *)cctx; + sxhub_t *ssys = co->ssys; sexp_t *isx; char *login = NULL; char *passwd = NULL; /* take a deal with S-exp */ SEXP_ITERATE_LIST(sx, isx, idx) { - if(isx->ty == SEXP_LIST) return SNE_BADPROTO; + if(isx->ty == SEXP_LIST) return SXE_BADPROTO; - if(idx > 0 && isx->aty != SEXP_DQUOTE) return SNE_BADPROTO; + if(idx > 0 && isx->aty != SEXP_DQUOTE) return SXE_BADPROTO; if(idx == 1) login = isx->val; else if(idx == 2) passwd = isx->val; - else if(idx > 2) return SNE_BADPROTO; + else if(idx > 2) return SXE_BADPROTO; } - if(!login || !passwd) return SNE_BADPROTO; + if(!login || !passwd) return SXE_BADPROTO; co->pctx->login = strdup(login); co->pctx->passwd = strdup(passwd); if(!co->pctx->login || !co->pctx->passwd) { if(co->pctx->login) free(co->pctx->login); if(co->pctx->passwd) free(co->pctx->passwd); - return SNE_ENOMEM; + return SXE_ENOMEM; } if(ssys->secure_check) return ssys->secure_check(co); - else return SNE_SUCCESS; + else return SXE_SUCCESS; } static int __get_channels_list(void *cctx, sexp_t *sx) { - conn_t *co = (conn_t *)cctx; - conn_sys_t *ssys = co->ssys; + sxlink_t *co = (sxlink_t *)cctx; + sxhub_t *ssys = co->ssys; sxmsg_t *msg = co->messages[0]; char *buf = msg->payload; usrtc_node_t *node; rpc_typed_list_t *list_ent; - size_t maxlen = 65535 - sizeof(sntllv2_head_t); + size_t maxlen = 65535 - sizeof(sxmplv2_head_t); size_t ulen = 0; /* we will avoid S-exp scanning here */ @@ -129,8 +130,8 @@ static int __get_channels_list(void *cctx, sexp_t *sx) /* call the function */ if(ssys->get_rpc_typed_list_tree) co->rpc_list = ssys->get_rpc_typed_list_tree(co); - if(!co->rpc_list) return SNE_EPERM; - //buf += sizeof(sntllv2_head_t); + if(!co->rpc_list) return SXE_EPERM; + //buf += sizeof(sxmplv2_head_t); ulen += snprintf(buf + ulen, maxlen - ulen, "(set-channels-list "); for(node = usrtc_first(co->rpc_list); node != NULL; node = usrtc_next(co->rpc_list, node)) { /* fill the list */ @@ -142,49 +143,49 @@ static int __get_channels_list(void *cctx, sexp_t *sx) msg->mhead.payload_length = ulen + 1; /* we're ready for messaging mode */ - co->flags |= SNSX_MESSAGINGMODE; + co->flags |= SXMP_MESSAGINGMODE; - return SNE_SUCCESS; + return SXE_SUCCESS; } static int __set_channels_list(void *cctx, sexp_t *sx) { register int idx; - conn_t *co = (conn_t *)cctx; - conn_sys_t *ssys = co->ssys; + sxlink_t *co = (sxlink_t *)cctx; + sxhub_t *ssys = co->ssys; sexp_t *isx, *iisx; int id, r; SEXP_ITERATE_LIST(sx, isx, idx) { if(!idx) continue; - if(isx->ty != SEXP_LIST) return SNE_BADPROTO; - if(sexp_list_length(isx) != 2) return SNE_BADPROTO; + if(isx->ty != SEXP_LIST) return SXE_BADPROTO; + if(sexp_list_length(isx) != 2) return SXE_BADPROTO; /* get id */ sexp_list_car(isx, &iisx); - if(iisx->ty == SEXP_LIST) return SNE_BADPROTO; - if(iisx->aty != SEXP_BASIC) return SNE_BADPROTO; - if(iisx->val[0] != ':') return SNE_BADPROTO; + if(iisx->ty == SEXP_LIST) return SXE_BADPROTO; + if(iisx->aty != SEXP_BASIC) return SXE_BADPROTO; + if(iisx->val[0] != ':') return SXE_BADPROTO; id = atoi(iisx->val + sizeof(char)); /* get short description */ sexp_list_cdr(isx, &iisx); - if(iisx->ty == SEXP_LIST) return SNE_BADPROTO; - if(iisx->aty != SEXP_DQUOTE) return SNE_BADPROTO; + if(iisx->ty == SEXP_LIST) return SXE_BADPROTO; + if(iisx->aty != SEXP_DQUOTE) return SXE_BADPROTO; /* ok, here we go */ if(ssys->set_typed_list_callback) { r = ssys->set_typed_list_callback(co, id, iisx->val); - if(r != SNE_SUCCESS) return r; + if(r != SXE_SUCCESS) return r; } } /* we're ready for messaging mode */ - co->flags |= SNSX_MESSAGINGMODE; - co->flags &= ~SNSX_BATCHMODE; + co->flags |= SXMP_MESSAGINGMODE; + co->flags &= ~SXMP_BATCHMODE; - return SNE_SUCCESS; + return SXE_SUCCESS; } static int __init_systemrpc_tree(usrtc_t *rtree) @@ -206,23 +207,23 @@ static long __cmp_cstr(const void *a, const void *b) return (long)strcmp((const char *)a, (const char *)b); } -int connections_init(conn_sys_t *ssys) +int links_init(sxhub_t *ssys) { int r = 0; if(!ssys) return EINVAL; - else memset(ssys, 0, sizeof(conn_sys_t)); + else memset(ssys, 0, sizeof(sxhub_t)); - if(!(ssys->connections = malloc(sizeof(usrtc_t)))) return ENOMEM; + if(!(ssys->links = malloc(sizeof(usrtc_t)))) return ENOMEM; - /* init connections list */ - usrtc_init(ssys->connections, USRTC_REDBLACK, MAX_CONNECTIONS, + /* init links list */ + usrtc_init(ssys->links, USRTC_REDBLACK, MAX_LINKS, __cmp_cstr); if((r = pthread_rwlock_init(&(ssys->rwlock), NULL))) goto __fini; /* init RPC list related functions */ - if(!(ssys->system_rpc = malloc(sizeof(cx_rpc_list_t)))) { + if(!(ssys->system_rpc = malloc(sizeof(sxl_rpclist_t)))) { r = ENOMEM; goto __lfini; } else { @@ -244,42 +245,42 @@ int connections_init(conn_sys_t *ssys) if(ssys->system_rpc) free(ssys->system_rpc); pthread_rwlock_destroy(&(ssys->rwlock)); __fini: - if(ssys->connections) free(ssys->connections); + if(ssys->links) free(ssys->links); return r; } -int connections_free(conn_sys_t *ssys) +int links_free(sxhub_t *ssys) { __destroy_rpc_list_tree(ssys->system_rpc->rpc_tree); free(ssys->system_rpc->rpc_tree); free(ssys->system_rpc); - free(ssys->connections); + free(ssys->links); pthread_rwlock_destroy(&(ssys->rwlock)); SSL_CTX_free(ssys->ctx); return 0; } -int connections_destroy(conn_sys_t *ssys) +int links_destroy(sxhub_t *ssys) { - int r = connections_free(ssys); + int r = links_free(ssys); free(ssys); return r; } -conn_sys_t *connections_create(void) +sxhub_t *links_create(void) { int r = 0; - conn_sys_t *nsys = malloc(sizeof(conn_sys_t)); + sxhub_t *nsys = malloc(sizeof(sxhub_t)); if(!nsys) { errno = ENOMEM; return NULL; } - r = connections_init(nsys); + r = links_init(nsys); if(r) { errno = r; free(nsys); @@ -289,7 +290,7 @@ conn_sys_t *connections_create(void) return nsys; } -int connections_setsslserts(conn_sys_t *ssys, const char *rootca, +int links_setsslserts(sxhub_t *ssys, const char *rootca, const char *certpem, const char *certkey) { int r = ENOMEM; @@ -316,31 +317,31 @@ struct __scerrcode { }; static struct __scerrcode __lerr[] = { - {SNE_SUCCESS, "Success"}, - {SNE_FAILED, "Failed, invalid parameters given"}, - {SNE_ENOMEM, "Not enough memory"}, - {SNE_BADPROTO, "Bad protocol"}, - {SNE_ENORPC, "No such RPC exists"}, - {SNE_EPERM, "Permission denied"}, - {SNE_TOOLONG, "Message data payload too long to be sent with one message pass"}, - {SNE_EBUSY, "Index or working threads are busy"}, - {SNE_WOULDBLOCK, "Call will block operation"}, - {SNE_LINKERROR, "Connection link error"}, - {SNE_NOSUCHMSG, "No such message"}, - {SNE_NOSUCHCHAN, "No such channel"}, - {SNE_ETIMEDOUT, "Timeout exceed"}, - {SNE_IGNORED, "Function call was ignored"}, - {SNE_REPLYREQ, "Reply required to the message"}, - {SNE_RAPIDMSG, "Message is a rapid reply and dialog closed"}, - {SNE_ESSL, "SSL error occurs on connection link"}, - {SNE_NOCHANNELS, "No channels available"}, - {SNE_MCHANNELS, "Active channels limit exceed"}, - {SNE_MMESSAGES, "Active messages limit exceed"}, - {SNE_LINKBROKEN, "Connection link was broken"}, - {SNE_INVALINDEX, "Invalid index given"}, + {SXE_SUCCESS, "Success"}, + {SXE_FAILED, "Failed, invalid parameters given"}, + {SXE_ENOMEM, "Not enough memory"}, + {SXE_BADPROTO, "Bad protocol"}, + {SXE_ENORPC, "No such RPC exists"}, + {SXE_EPERM, "Permission denied"}, + {SXE_TOOLONG, "Message data payload too long to be sent with one message pass"}, + {SXE_EBUSY, "Index or working threads are busy"}, + {SXE_WOULDBLOCK, "Call will block operation"}, + {SXE_LINKERROR, "Connection link error"}, + {SXE_NOSUCHMSG, "No such message"}, + {SXE_NOSUCHCHAN, "No such channel"}, + {SXE_ETIMEDOUT, "Timeout exceed"}, + {SXE_IGNORED, "Function call was ignored"}, + {SXE_REPLYREQ, "Reply required to the message"}, + {SXE_RAPIDMSG, "Message is a rapid reply and dialog closed"}, + {SXE_ESSL, "SSL error occurs on connection link"}, + {SXE_NOCHANNELS, "No channels available"}, + {SXE_MCHANNELS, "Active channels limit exceed"}, + {SXE_MMESSAGES, "Active messages limit exceed"}, + {SXE_LINKBROKEN, "Connection link was broken"}, + {SXE_INVALINDEX, "Invalid index given"}, }; const char *sntll_errno2cstr(int ec) { - return __lerr[ec - __SNTL_EPREFIX].desc; + return __lerr[ec - __SXMP_EPREFIX].desc; } diff --git a/lib/message.c b/lib/message.c index f5c0280..84e9cb6 100644 --- a/lib/message.c +++ b/lib/message.c @@ -26,31 +26,31 @@ #include #include -#include -#include +#include +#include #include "internal.h" void _message_process(sxmsg_t *msg) { - chnl_t *chan = msg->pch; + sxchnl_t *chan = msg->pch; sexp_t *sx, *isx; usrtc_t *listrpc = chan->rpc_list->rpc_tree; usrtc_node_t *node; - cx_rpc_t *rpcc; + sxl_rpc_t *rpcc; int r; sx = parse_sexp(msg->payload, msg->mhead.payload_length); - if(!sx) sxmsg_return(msg, SNE_BADPROTO); + if(!sx) sxmsg_return(msg, SXE_BADPROTO); sexp_list_car(sx, &isx); - if(!isx) { r = SNE_BADPROTO; goto __return_err; } - if(isx->ty == SEXP_LIST) { r = SNE_BADPROTO; goto __return_err; } - if(isx->aty != SEXP_BASIC) { r = SNE_BADPROTO; goto __return_err; } + if(!isx) { r = SXE_BADPROTO; goto __return_err; } + if(isx->ty == SEXP_LIST) { r = SXE_BADPROTO; goto __return_err; } + if(isx->aty != SEXP_BASIC) { r = SXE_BADPROTO; goto __return_err; } node = usrtc_lookup(listrpc, (void *)isx->val); - if(!node) { r = SNE_ENORPC; goto __return_err; } - else rpcc = (cx_rpc_t *)usrtc_node_getdata(node); + if(!node) { r = SXE_ENORPC; goto __return_err; } + else rpcc = (sxl_rpc_t *)usrtc_node_getdata(node); rpcc->rpcf((void *)msg, sx); @@ -64,22 +64,22 @@ void _message_process(sxmsg_t *msg) return; } -static inline int __sxmsg_send(chnl_t *channel, const char *data, size_t datalen, +static inline int __sxmsg_send(sxchnl_t *channel, const char *data, size_t datalen, sxmsg_t **omsg, int pp) { - conn_t *co; + sxlink_t *co; sxmsg_t *msg; - sntllv2_head_t *head; - ppmsg_t *ppm; + sxmplv2_head_t *head; + sxppmsg_t *ppm; int msgidx, r; - if(!channel) return SNE_FAILED; - if(!data || !datalen) return SNE_FAILED; + if(!channel) return SXE_FAILED; + if(!data || !datalen) return SXE_FAILED; - if(!(msg = malloc(sizeof(sxmsg_t)))) return SNE_ENOMEM; + if(!(msg = malloc(sizeof(sxmsg_t)))) return SXE_ENOMEM; else memset(msg, 0, sizeof(sxmsg_t)); - co = channel->connection; + co = channel->link; head = &msg->mhead; /* form a head */ head->attr = SXMSG_OPEN | SXMSG_REPLYREQ; @@ -96,13 +96,13 @@ static inline int __sxmsg_send(chnl_t *channel, const char *data, size_t datalen if(msgidx != IDX_INVAL) co->messages[msgidx] = msg; pthread_mutex_unlock(&co->idx_msg_lock); - if(msgidx == IDX_INVAL) { r = SNE_MMESSAGES; goto __freemsg; } + if(msgidx == IDX_INVAL) { r = SXE_MMESSAGES; goto __freemsg; } else head->msgid = (uint16_t)msgidx; /* ready to send it */ if(!pp) { - r = _sntll_writemsg(co, msg); - if(r != SNE_SUCCESS) { + r = _sxmpl_writemsg(co, msg); + if(r != SXE_SUCCESS) { __unpinmsg: pthread_mutex_lock(&co->idx_msg_lock); idx_free(&co->idx_msg, msgidx); @@ -111,7 +111,7 @@ static inline int __sxmsg_send(chnl_t *channel, const char *data, size_t datalen goto __freemsg; } } else { /* postponed */ - if(!(ppm = malloc(sizeof(ppmsg_t)))) { r = SNE_ENOMEM; goto __unpinmsg; } + if(!(ppm = malloc(sizeof(sxppmsg_t)))) { r = SXE_ENOMEM; goto __unpinmsg; } list_init_node(&ppm->node); ppm->msg = msg; @@ -143,37 +143,37 @@ static inline int __sxmsg_send(chnl_t *channel, const char *data, size_t datalen return r; } -int sxmsg_send(chnl_t *channel, const char *data, size_t datalen, sxmsg_t **omsg) +int sxmsg_send(sxchnl_t *channel, const char *data, size_t datalen, sxmsg_t **omsg) { return __sxmsg_send(channel, data, datalen, omsg, 0); } /* the same - postponed message i.e. will be written to the queue - not to write immendatly */ -int sxmsg_send_pp(chnl_t *channel, const char *data, size_t datalen, sxmsg_t **omsg) +int sxmsg_send_pp(sxchnl_t *channel, const char *data, size_t datalen, sxmsg_t **omsg) { return __sxmsg_send(channel, data, datalen, omsg, 1); } /* send a pulse message */ -int sxmsg_pulse(conn_t *co, const char *data, size_t datalen) +int sxmsg_pulse(sxlink_t *co, const char *data, size_t datalen) { sxmsg_t *msg = malloc(sizeof(sxmsg_t)); - sntllv2_head_t *head; + sxmplv2_head_t *head; int r; /* a little bit of paranoid tests */ - if(!msg) return SNE_ENOMEM; + if(!msg) return SXE_ENOMEM; else memset(msg, 0, sizeof(sxmsg_t)); /* prepare it */ head = &msg->mhead; head->attr = 0; head->attr = SXMSG_PULSE | SXMSG_LINK; - head->opcode = SNE_RAPIDMSG; + head->opcode = SXE_RAPIDMSG; head->payload_length = datalen; msg->payload = (void *)data; - r = _sntll_writemsg(co, msg); + r = _sxmpl_writemsg(co, msg); free(msg); @@ -183,35 +183,35 @@ int sxmsg_pulse(conn_t *co, const char *data, size_t datalen) static inline int __sxmsg_reply(sxmsg_t *msg, const char *data, size_t datalen, int pp) { - chnl_t *ch; - conn_t *co; - sntllv2_head_t *head; - ppmsg_t *ppm; + sxchnl_t *ch; + sxlink_t *co; + sxmplv2_head_t *head; + sxppmsg_t *ppm; int r, i; pthread_t self = pthread_self(); /* a little bit of paranoid tests */ - if(!msg) return SNE_FAILED; - if(!(ch = msg->pch)) return SNE_FAILED; - if(!(co = ch->connection)) return SNE_FAILED; + if(!msg) return SXE_FAILED; + if(!(ch = msg->pch)) return SXE_FAILED; + if(!(co = ch->link)) return SXE_FAILED; /* test for blocking */ - for(i = 0; i < MAX_SNTLLTHREADS; i++) - if(pthread_equal(self, co->thrd_poll[i])) return SNE_WOULDBLOCK; + for(i = 0; i < MAX_SXMPLTHREADS; i++) + if(pthread_equal(self, co->thrd_poll[i])) return SXE_WOULDBLOCK; /* prepare it */ head = &msg->mhead; head->attr = 0; head->attr |= SXMSG_REPLYREQ; - head->opcode = SNE_REPLYREQ; + head->opcode = SXE_REPLYREQ; head->payload_length = datalen; msg->payload = (void *)data; if(!pp) { - r = _sntll_writemsg(co, msg); - if(r != SNE_SUCCESS) return r; + r = _sxmpl_writemsg(co, msg); + if(r != SXE_SUCCESS) return r; } else { - if(!(ppm = malloc(sizeof(ppmsg_t)))) return SNE_ENOMEM; + if(!(ppm = malloc(sizeof(sxppmsg_t)))) return SXE_ENOMEM; list_init_node(&ppm->node); ppm->msg = msg; @@ -247,21 +247,21 @@ int sxmsg_reply_pp(sxmsg_t *msg, const char *data, size_t datalen) int sxmsg_rreply(sxmsg_t *msg, size_t datalen) { - chnl_t *ch; - conn_t *co; - sntllv2_head_t *head; + sxchnl_t *ch; + sxlink_t *co; + sxmplv2_head_t *head; int r, mid; /* a little bit of paranoid tests */ - if(!msg) return SNE_FAILED; - if(!(ch = msg->pch)) return SNE_FAILED; - if(!(co = ch->connection)) return SNE_FAILED; + if(!msg) return SXE_FAILED; + if(!(ch = msg->pch)) return SXE_FAILED; + if(!(co = ch->link)) return SXE_FAILED; /* prepare it */ head = &msg->mhead; head->attr = 0; head->attr |= SXMSG_CLOSED; - head->opcode = SNE_RAPIDMSG; + head->opcode = SXE_RAPIDMSG; head->payload_length = datalen; mid = head->msgid; @@ -270,7 +270,7 @@ int sxmsg_rreply(sxmsg_t *msg, size_t datalen) co->messages[mid] = NULL; pthread_mutex_unlock(&co->idx_msg_lock); - r = _sntll_writemsg(co, msg); + r = _sxmpl_writemsg(co, msg); pthread_mutex_unlock(&msg->wait); /* we able to invalidate it */ pthread_mutex_destroy(&msg->wait); @@ -281,16 +281,16 @@ int sxmsg_rreply(sxmsg_t *msg, size_t datalen) static inline int __sxmsg_return(sxmsg_t *msg, int opcode, int pp) { - chnl_t *ch; - conn_t *co; - sntllv2_head_t *head; - ppmsg_t *ppm; + sxchnl_t *ch; + sxlink_t *co; + sxmplv2_head_t *head; + sxppmsg_t *ppm; int r, mid; /* a little bit of paranoid tests */ - if(!msg) return SNE_FAILED; - if(!(ch = msg->pch)) return SNE_FAILED; - if(!(co = ch->connection)) return SNE_FAILED; + if(!msg) return SXE_FAILED; + if(!(ch = msg->pch)) return SXE_FAILED; + if(!(co = ch->link)) return SXE_FAILED; head = &msg->mhead; head->attr = 0; @@ -306,10 +306,10 @@ static inline int __sxmsg_return(sxmsg_t *msg, int opcode, int pp) co->messages[mid] = NULL; pthread_mutex_unlock(&co->idx_msg_lock); - r = _sntll_writemsg(co, msg); + r = _sxmpl_writemsg(co, msg); free(msg); } else { - if(!(ppm = malloc(sizeof(ppmsg_t)))) return SNE_ENOMEM; + if(!(ppm = malloc(sizeof(sxppmsg_t)))) return SXE_ENOMEM; else { /* remove it */ pthread_mutex_lock(&co->idx_msg_lock); idx_free(&co->idx_msg, mid); @@ -326,7 +326,7 @@ static inline int __sxmsg_return(sxmsg_t *msg, int opcode, int pp) list_add2tail(&co->write_pending, &ppm->node); /* push it to the FIFO */ pthread_mutex_unlock(&co->write_pending_lock); - r = SNE_SUCCESS; + r = SXE_SUCCESS; } return r; diff --git a/lib/rpc.c b/lib/rpc.c index 5810b0d..0b4b97e 100644 --- a/lib/rpc.c +++ b/lib/rpc.c @@ -16,8 +16,8 @@ #include #include -#include -#include +#include +#include static long __cmp_int(const void *a, const void *b) { @@ -39,7 +39,7 @@ int sntl_rpclist_add(usrtc_t *tree, int type, const char *description, const char *version) { rpc_typed_list_t *nlist = NULL; - cx_rpc_list_t *rpc_list = NULL; + sxl_rpclist_t *rpc_list = NULL; usrtc_t *rtree = NULL; usrtc_node_t *node = NULL; int r = ENOMEM; @@ -51,8 +51,8 @@ int sntl_rpclist_add(usrtc_t *tree, int type, const char *description, /* allocate all */ if(!(nlist = malloc(sizeof(rpc_typed_list_t)))) goto __fail; else memset(nlist, 0, sizeof(rpc_typed_list_t)); - if(!(rpc_list = malloc(sizeof(cx_rpc_list_t)))) goto __fail; - else memset(rpc_list, 0, sizeof(cx_rpc_list_t)); + if(!(rpc_list = malloc(sizeof(sxl_rpclist_t)))) goto __fail; + else memset(rpc_list, 0, sizeof(sxl_rpclist_t)); if(!(rtree = malloc(sizeof(usrtc_t)))) goto __fail; /* version and description */ @@ -86,8 +86,8 @@ int sntl_rpclist_add_function(usrtc_t *tree, int type, const char *fu_name, { usrtc_node_t *node; rpc_typed_list_t *tlist; - cx_rpc_list_t *rlist; - cx_rpc_t *rentry = NULL; + sxl_rpclist_t *rlist; + sxl_rpc_t *rentry = NULL; node = usrtc_lookup(tree, &type); if(!node) return ENOENT; @@ -97,7 +97,7 @@ int sntl_rpclist_add_function(usrtc_t *tree, int type, const char *fu_name, /* ok, we don't allow dupes */ node = usrtc_lookup(rlist->rpc_tree, fu_name); if(node) return EEXIST; - if(!(rentry = malloc(sizeof(cx_rpc_t)))) return ENOMEM; + if(!(rentry = malloc(sizeof(sxl_rpc_t)))) return ENOMEM; else if(!(rentry->name = strdup(fu_name))) { free(rentry); return ENOMEM; @@ -124,11 +124,11 @@ int sntl_rpclist_filter(usrtc_t *source, usrtc_t **dest, int flag, int *filter) else usrtc_init(destination, USRTC_REDBLACK, MAX_RPC_LIST, __cmp_int); switch(flag) { - case SNTL_FILTER_EXC: + case SXMP_FILTER_EXC: for(node = usrtc_first(source); ; node = usrtc_next(source, node)) { tlist = (rpc_typed_list_t *)usrtc_node_getdata(node); r = ENOENT; - for(i = *f; i != SNTL_FILTER_END; f++, i = *f) { + for(i = *f; i != SXMP_FILTER_END; f++, i = *f) { if(tlist->type_id == i) { r = 0; break; } @@ -148,8 +148,8 @@ int sntl_rpclist_filter(usrtc_t *source, usrtc_t **dest, int flag, int *filter) } r = 0; break; - case SNTL_FILTER_INC: - for(i = *f; i != SNTL_FILTER_END; f++, i = *f) { + case SXMP_FILTER_INC: + for(i = *f; i != SXMP_FILTER_END; f++, i = *f) { node = usrtc_lookup(source, &i); if(!node) continue; /* skip it at all */ else tlist = (rpc_typed_list_t *)usrtc_node_getdata(node); diff --git a/lib/sxmplv2.c b/lib/sxmplv2.c index 8d19329..062ee3d 100644 --- a/lib/sxmplv2.c +++ b/lib/sxmplv2.c @@ -294,7 +294,7 @@ static int __verify_certcall(int preverify_ok, X509_STORE_CTX *ctx) int err = X509_STORE_CTX_get_error(ctx), depth = X509_STORE_CTX_get_error_depth(ctx); SSL *ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx()); sxlink_t *co = SSL_get_ex_data(ssl, ex_ssldata_index); /* this is a custom data we're set before */ - conn_sys_t *ssys = co->ssys; + sxhub_t *ssys = co->ssys; /* now we need to check for certificates with a long chain, * so since we have a short one, reject long ones */ @@ -408,8 +408,8 @@ sxlink_t *__link_minimal_alloc(struct in_addr *addr) if(!(co->messages = malloc(sizeof(uintptr_t)*1024))) { r = ENOMEM; goto __fail; } else memset(co->messages, 0, sizeof(uintptr_t)*1024); - if(!(co->pctx = malloc(sizeof(perm_ctx_t)))) { r = ENOMEM; goto __fail; } - else memset(co->pctx, 0, sizeof(perm_ctx_t)); + if(!(co->pctx = malloc(sizeof(sxsession_ctx_t)))) { r = ENOMEM; goto __fail; } + else memset(co->pctx, 0, sizeof(sxsession_ctx_t)); if(addr) { if(!(co->pctx->addr = malloc(sizeof(struct in_addr)))) { r = ENOMEM; goto __fail; } @@ -495,9 +495,9 @@ static void __link_minimal_free(sxlink_t *co) static int __eval_syssexp(sxlink_t *co, sexp_t *sx) { - cx_rpc_list_t *rpc_list = co->ssys->system_rpc; + sxl_rpclist_t *rpc_list = co->ssys->system_rpc; usrtc_node_t *node; - cx_rpc_t *rentry; + sxl_rpc_t *rentry; char *rpcf; if(sx->ty == SEXP_LIST) @@ -508,13 +508,13 @@ static int __eval_syssexp(sxlink_t *co, sexp_t *sx) node = usrtc_lookup(rpc_list->rpc_tree, rpcf); if(!node) return SXE_ENORPC; - else rentry = (cx_rpc_t *)usrtc_node_getdata(node); + else rentry = (sxl_rpc_t *)usrtc_node_getdata(node); /* call it */ return rentry->rpcf((void *)co, sx); } -#ifdef _NO_SNTLMP +#ifdef _NO_SXMPMP #define _CONN_INUSE(co) (co)->usecount++; #define _CONN_NOTINUSE(co) (co)->usecount--; #define _CONN_UCOUNT(co) (co)->usecount @@ -544,17 +544,17 @@ static void __link_destroy(sxlink_t *co) { int i = 0, fd; sxmsg_t *msg, *omsg; - ppmsg_t *ppm; + sxppmsg_t *ppm; list_node_t *iter, *siter; - chnl_t *chan; + sxchnl_t *chan; sxmplv2_head_t *head; - conn_sys_t *ssys = co->ssys; + sxhub_t *ssys = co->ssys; /* first we will unpin all messages and mark it as errors on */ if(co->pending_messages) { pthread_mutex_lock(&co->write_pending_lock); list_for_each_safe(&co->write_pending, iter, siter) { - ppm = container_of(iter, ppmsg_t, node); + ppm = container_of(iter, sxppmsg_t, node); omsg = ppm->msg; /* ok, now we're able to remove it from list */ @@ -642,9 +642,9 @@ static void *__sxmpl_thread(void *b) sxmplv2_head_t *mhead = (sxmplv2_head_t *)buf; sxmsg_t *msg, *omsg; sexp_t *sx; - chnl_t *channel; + sxchnl_t *channel; list_node_t *iter, *siter; - ppmsg_t *ppm; + sxppmsg_t *ppm; pthread_t self = pthread_self(); struct timespec wtick; int dispatch = 0, e; @@ -684,7 +684,7 @@ static void *__sxmpl_thread(void *b) if(co->pending_messages && !(co->flags & SXMP_CLOSED)) { pthread_mutex_lock(&co->write_pending_lock); list_for_each_safe(&co->write_pending, iter, siter) { - ppm = container_of(iter, ppmsg_t, node); + ppm = container_of(iter, sxppmsg_t, node); omsg = ppm->msg; if(_sxmpl_writemsg(co, omsg) != SXE_SUCCESS) { pthread_mutex_unlock(&co->write_pending_lock); @@ -955,7 +955,7 @@ static void *__sxmpl_thread(void *b) return NULL; } -sxlink_t *sxlink_master_accept(conn_sys_t *ssys, int sck, struct in_addr *addr) +sxlink_t *sxlink_master_accept(sxhub_t *ssys, int sck, struct in_addr *addr) { void *buf = NULL; char *bbuf; @@ -1103,7 +1103,7 @@ sxlink_t *sxlink_master_accept(conn_sys_t *ssys, int sck, struct in_addr *addr) bundle->conn = co; } - for(i = 0; i < MAX_SNTLLTHREADS; i++) { + for(i = 0; i < MAX_SXMPLTHREADS; i++) { if(bundle == (void *)0xdead) bundle = __sxmpl_bundle_create(co); if(!bundle) goto __fail5; r = pthread_create(&co->thrd_poll[i], NULL, __sxmpl_thread, bundle); /* and here, alloc tls */ @@ -1153,7 +1153,7 @@ sxlink_t *sxlink_master_accept(conn_sys_t *ssys, int sck, struct in_addr *addr) return NULL; } -sxlink_t *sxlink_connect(conn_sys_t *ssys, const char *host, +sxlink_t *sxlink_connect(sxhub_t *ssys, const char *host, int port, const char *SSL_cert, const char *login, const char *passwd) { @@ -1356,7 +1356,7 @@ sxlink_t *sxlink_connect(conn_sys_t *ssys, const char *host, bundle->buf = buf; bundle->conn = co; } - for(i = 0; i < MAX_SNTLLTHREADS; i++) { + for(i = 0; i < MAX_SXMPLTHREADS; i++) { if(bundle == (void *)0xdead) bundle = __sxmpl_bundle_create(co); if(!bundle) goto __fail5; r = pthread_create(&co->thrd_poll[i], NULL, __sxmpl_thread, bundle); diff --git a/lib/uuid.c b/lib/uuid.c index 23a4862..2bf2e70 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -15,18 +15,14 @@ #include #ifdef WIN32 - #include #include #include - #else - #include #include #include #include - #endif #include