fixes due to the new naming;

v0.5.xx
Alexander Vdolainen 9 years ago
parent a61f1bbd83
commit 0dbff0dca7

@ -60,7 +60,6 @@ int __resolvehost(const char *hostname, char *buf, int buf_len,
struct hostent *hp = *rhp = NULL;
int herr = 0, hres = 0;
hostbuf = malloc(sizeof(struct hostent));
if(!hostbuf) return NO_ADDRESS;
hres = gethostbyname_r(hostname, hostbuf,
@ -91,7 +90,7 @@ static int __conn_read(sxlink_t *co, void *buf, size_t buf_len)
do {
__try_again:
if(co->flags & SNSX_CLOSED) {
if(co->flags & SXMP_CLOSED) {
return -1;
}
r = SSL_read(co->ssl, buf, (int)buf_len);
@ -127,7 +126,7 @@ static int __conn_read(sxlink_t *co, void *buf, size_t buf_len)
default:
__close_conn:
ERR_free_strings();
co->flags |= SNSX_CLOSED;
co->flags |= SXMP_CLOSED;
fprintf(stderr, "[sxmplv2] (RD)Unknown error on %s (errno = %d)\n", co->uuid, errno);
ERR_remove_state(0);
return -1;
@ -175,7 +174,7 @@ static int __conn_write(sxlink_t *co, void *buf, size_t buf_len)
fd_set writeset;
__retry:
if(co->flags & SNSX_CLOSED) {
if(co->flags & SXMP_CLOSED) {
return -1;
}
r = SSL_write(co->ssl, buf, (int)buf_len);
@ -197,7 +196,7 @@ static int __conn_write(sxlink_t *co, void *buf, size_t buf_len)
if(r < 0) {
/* set closed flag */
ERR_free_strings();
co->flags |= SNSX_CLOSED;
co->flags |= SXMP_CLOSED;
fprintf(stderr, "[sxmplv2] (WR)Unknown error on %s (%d)\n", co->uuid, r);
ERR_remove_state(0);
return -1;
@ -214,11 +213,11 @@ int _sxmpl_writemsg(sxlink_t *co, sxmsg_t *msg)
int r;
char *buf = NULL;
if(!co || !msg) return SNE_FAILED;
if(!co || !msg) return SXE_FAILED;
/* check message for validity */
head = &msg->mhead;
if(head->payload_length && !msg->payload) return SNE_FAILED;
if(head->payload_length && !msg->payload) return SXE_FAILED;
if(head->payload_length) {
buf = malloc(sizeof(sxmplv2_head_t) + head->payload_length);
@ -232,12 +231,12 @@ int _sxmpl_writemsg(sxlink_t *co, sxmsg_t *msg)
rd = __conn_write(co, head, sizeof(sxmplv2_head_t));
else rd = __conn_write(co, buf, sizeof(sxmplv2_head_t) + head->payload_length);
if(rd < 0) {
co->flags |= SNSX_CLOSED;
r = SNE_ESSL;
co->flags |= SXMP_CLOSED;
r = SXE_ESSL;
}
pthread_mutex_unlock(&co->sslinout[1]);
if(!(co->flags & SNSX_CLOSED)) r = SNE_SUCCESS;
if(!(co->flags & SXMP_CLOSED)) r = SXE_SUCCESS;
if(buf) free(buf);
return r;
}
@ -456,12 +455,12 @@ static int __link_second_alloc(sxlink_t *co)
/* init list */
list_init_head(&co->write_pending);
return SNE_SUCCESS;
return SXE_SUCCESS;
__fail:
idx_allocator_destroy(&co->idx_msg);
idx_allocator_destroy(&co->idx_ch);
return SNE_ENOMEM;
return SXE_ENOMEM;
}
static void __link_second_free(sxlink_t *co)
@ -503,12 +502,12 @@ static int __eval_syssexp(sxlink_t *co, sexp_t *sx)
if(sx->ty == SEXP_LIST)
rpcf = sx->list->val;
else return SNE_BADPROTO;
else return SXE_BADPROTO;
/* find an appropriate function */
node = usrtc_lookup(rpc_list->rpc_tree, rpcf);
if(!node) return SNE_ENORPC;
if(!node) return SXE_ENORPC;
else rentry = (cx_rpc_t *)usrtc_node_getdata(node);
/* call it */
@ -565,7 +564,7 @@ static void __link_destroy(sxlink_t *co)
pthread_mutex_destroy(&omsg->wait);
free(omsg);
} else { /* wake up */
omsg->mhead.opcode = SNE_LINKERROR;
omsg->mhead.opcode = SXE_LINKERROR;
pthread_mutex_unlock(&omsg->wait);
}
free(ppm);
@ -590,7 +589,7 @@ static void __link_destroy(sxlink_t *co)
msg = co->messages[i];
if(!msg) continue;
else head = &msg->mhead;
head->opcode = SNE_LINKERROR;
head->opcode = SXE_LINKERROR;
pthread_mutex_unlock(&msg->wait);
pthread_mutex_destroy(&msg->wait);
free(msg);
@ -659,8 +658,8 @@ static void *__sxmpl_thread(void *b)
__wait_alive:
/* flag test - FIXME: make it atomic (it will works atomically on x86, btw on others not) */
if(!(co->flags & SNSX_ALIVE)) {
if(co->flags & SNSX_CLOSED) goto __finish;
if(!(co->flags & SXMP_ALIVE)) {
if(co->flags & SXMP_CLOSED) goto __finish;
else {
usleep(20);
goto __wait_alive;
@ -680,14 +679,14 @@ static void *__sxmpl_thread(void *b)
*/
while(1) {
__again:
if(co->flags & SNSX_CLOSED) goto __finish; /* go away if required asap */
if(co->flags & SXMP_CLOSED) goto __finish; /* go away if required asap */
/* works with pending messages */
if(co->pending_messages && !(co->flags & SNSX_CLOSED)) {
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);
omsg = ppm->msg;
if(_sxmpl_writemsg(co, omsg) != SNE_SUCCESS) {
if(_sxmpl_writemsg(co, omsg) != SXE_SUCCESS) {
pthread_mutex_unlock(&co->write_pending_lock);
goto __finish; /* write failed - finishing ... */
}
@ -711,7 +710,7 @@ static void *__sxmpl_thread(void *b)
e = pthread_mutex_timedlock(&(co->sslinout[0]), &wtick);
if(e == ETIMEDOUT) goto __again;
}
if(co->flags & SNSX_CLOSED) {
if(co->flags & SXMP_CLOSED) {
pthread_mutex_unlock(&(co->sslinout[0]));
goto __finish;
}
@ -728,7 +727,7 @@ static void *__sxmpl_thread(void *b)
} else printf("connread(head) µS: %ld\n", end.tv_usec - beg.tv_usec);
#endif
if(co->flags & SNSX_CLOSED) {
if(co->flags & SXMP_CLOSED) {
pthread_mutex_unlock(&(co->sslinout[0]));
goto __finish; /* go away if required asap */
}
@ -738,7 +737,7 @@ static void *__sxmpl_thread(void *b)
#endif
if(rd < 0) {
__sslproto_error:
co->flags |= SNSX_CLOSED;
co->flags |= SXMP_CLOSED;
pthread_mutex_unlock(&(co->sslinout[0]));
goto __finish;
} else {
@ -763,7 +762,7 @@ static void *__sxmpl_thread(void *b)
mid = mhead->msgid;
/* if we're need to do something */
if(mhead->msgid >= 1024) {
mhead->opcode = SNE_INVALINDEX;
mhead->opcode = SXE_INVALINDEX;
goto __return_error;
} else {
// pthread_mutex_lock(&co->idx_msg_lock);
@ -771,11 +770,11 @@ static void *__sxmpl_thread(void *b)
//thread_mutex_unlock(&co->idx_msg_lock);
}
if(!msg) {
if(mhead->attr & SXMSG_OPEN) mhead->opcode = SNE_BADPROTO;
if(mhead->attr & SXMSG_OPEN) mhead->opcode = SXE_BADPROTO;
else {
if((mhead->attr & SXMSG_PROTO) || (mhead->attr & SXMSG_LINK))
mhead->opcode = SNE_BADPROTO;
else mhead->opcode = SNE_NOSUCHMSG;
mhead->opcode = SXE_BADPROTO;
else mhead->opcode = SXE_NOSUCHMSG;
}
}
__return_error:
@ -824,7 +823,7 @@ static void *__sxmpl_thread(void *b)
if(mhead->attr & SXMSG_CLOSED) goto __finish; /* close the link */
if(mhead->attr & SXMSG_PULSE) { /* it's a link pulse messages */
/* TODO: syncronization and so on */
if(mhead->opcode == SNE_RAPIDMSG) { /* custom pulse */
if(mhead->opcode == SXE_RAPIDMSG) { /* custom pulse */
sx = parse_sexp(bbuf, mhead->payload_length);
if(sx && co->ssys->on_pulse) co->ssys->on_pulse(co, sx);
if(sx) destroy_sexp(sx);
@ -834,7 +833,7 @@ static void *__sxmpl_thread(void *b)
if((mhead->attr & SXMSG_OPEN) && (mhead->attr & SXMSG_REPLYREQ)) { /* dialog initiation */
channel = co->channels[mhead->reserve];
if(!channel) { /* ok, we'are failed */
mhead->opcode = SNE_NOSUCHCHAN;
mhead->opcode = SXE_NOSUCHCHAN;
__ret_regerr:
mhead->payload_length = 0;
mhead->attr &= ~SXMSG_REPLYREQ;
@ -849,11 +848,11 @@ static void *__sxmpl_thread(void *b)
/* if message is busy - fails */
mid = mhead->msgid;
msg = co->messages[mid];
if(msg) { mhead->opcode = SNE_EBUSY; goto __ret_regerr; }
if(msg) { mhead->opcode = SXE_EBUSY; goto __ret_regerr; }
/* now we will take a deal */
if(!(msg = malloc(sizeof(sxmsg_t)))) {
mhead->opcode = SNE_ENOMEM; goto __ret_regerr;
mhead->opcode = SXE_ENOMEM; goto __ret_regerr;
} else {
/* set mutex and channel */
pthread_mutex_init(&msg->wait, NULL);
@ -896,7 +895,7 @@ static void *__sxmpl_thread(void *b)
if(mhead->payload_length) {
msg->payload = malloc(mhead->payload_length);
if(msg->payload) memcpy(msg->payload, bbuf, mhead->payload_length);
else msg->mhead.opcode = SNE_ENOMEM;
else msg->mhead.opcode = SXE_ENOMEM;
}
pthread_mutex_unlock(&msg->wait); /* wake up thread waiting for */
@ -920,7 +919,7 @@ static void *__sxmpl_thread(void *b)
free(msg);
/* we must reply */
mhead->opcode = SNE_ETIMEDOUT;
mhead->opcode = SXE_ETIMEDOUT;
goto __ret_regerr;
} else {
memcpy(&msg->mhead, mhead, sizeof(sxmplv2_head_t));
@ -928,7 +927,7 @@ static void *__sxmpl_thread(void *b)
msg->payload = malloc(mhead->payload_length);
if(msg->payload) memcpy(msg->payload, bbuf, mhead->payload_length);
else {
mhead->opcode = msg->mhead.opcode = SNE_ENOMEM; /* we will return it to waitee */
mhead->opcode = msg->mhead.opcode = SXE_ENOMEM; /* we will return it to waitee */
msg->mhead.attr &= ~SXMSG_REPLYREQ; /* doesn't need to reply */
/* reply here now */
mhead->payload_length = 0;
@ -943,14 +942,14 @@ static void *__sxmpl_thread(void *b)
}
pthread_mutex_unlock(&msg->wait); /* wake up thread waiting for */
}
} else { mhead->opcode = SNE_BADPROTO; goto __ret_regerr; }
} else { mhead->opcode = SXE_BADPROTO; goto __ret_regerr; }
}
}
}
__finish:
co->flags |= SNSX_CLOSED;
co->flags |= SXMP_CLOSED;
__link_destroy(co);
__sxmpl_bundle_destroy(b); /* destroy bundle */
return NULL;
@ -966,10 +965,10 @@ sxlink_t *sxlink_master_accept(conn_sys_t *ssys, int sck, struct in_addr *addr)
sxmplv2_bundle_t *bundle;
sexp_t *sx;
size_t rd;
int r = SNE_FAILED, i;
int r = SXE_FAILED, i;
if(!co) {
errno = SNE_ENOMEM;
errno = SXE_ENOMEM;
return NULL;
}
@ -980,7 +979,7 @@ sxlink_t *sxlink_master_accept(conn_sys_t *ssys, int sck, struct in_addr *addr)
if(!ssys->ctx) {
/* init SSL certificates and context */
ssys->ctx = SSL_CTX_new(TLSv1_2_server_method());
if(!ssys->ctx) { r = SNE_ENOMEM; goto __fail; }
if(!ssys->ctx) { r = SXE_ENOMEM; goto __fail; }
else {
/* set verify context */
SSL_CTX_set_verify(ssys->ctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
@ -998,18 +997,18 @@ sxlink_t *sxlink_master_accept(conn_sys_t *ssys, int sck, struct in_addr *addr)
/* set the local certificate from CertFile */
if(SSL_CTX_use_certificate_file(ssys->ctx, ssys->certpem,
SSL_FILETYPE_PEM)<=0) {
r = SNE_ESSL;
r = SXE_ESSL;
goto __fail;
}
/* set the private key from KeyFile (may be the same as CertFile) */
if(SSL_CTX_use_PrivateKey_file(ssys->ctx, ssys->certkey,
SSL_FILETYPE_PEM)<=0) {
r = SNE_ESSL;
r = SXE_ESSL;
goto __fail;
}
/* verify private key */
if (!SSL_CTX_check_private_key(ssys->ctx)) {
r = SNE_ESSL;
r = SXE_ESSL;
goto __fail;
}
@ -1017,23 +1016,23 @@ sxlink_t *sxlink_master_accept(conn_sys_t *ssys, int sck, struct in_addr *addr)
/* now we will create an SSL connection */
co->ssl = SSL_new(ssys->ctx);
if(!co->ssl) { r = SNE_ENOMEM; goto __fail; }
if(!co->ssl) { r = SXE_ENOMEM; goto __fail; }
else SSL_set_fd(co->ssl, sck); /* attach connected socket */
/* set the context to verify ssl connection */
SSL_set_ex_data(co->ssl, ex_ssldata_index, (void *)co);
SSL_set_accept_state(co->ssl);
if(SSL_accept(co->ssl) == -1) { r = SNE_EPERM; goto __fail; } /* leak here ? */
if(SSL_accept(co->ssl) == -1) { r = SXE_EPERM; goto __fail; } /* leak here ? */
// SSL_do_handshake(co->ssl);
/* ok, now we are able to allocate and so on */
/* set connection to the batch mode */
co->flags |= SNSX_BATCHMODE;
co->flags |= SXMP_BATCHMODE;
/* allocate our first buffer */
buf = mmap(NULL, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if(buf == MAP_FAILED) { r = SNE_ENOMEM; goto __fail2; }
if(buf == MAP_FAILED) { r = SXE_ENOMEM; goto __fail2; }
/* allocate first message */
if(!(msg = malloc(sizeof(sxmsg_t)))) { r = SNE_ENOMEM; goto __fail2; }
if(!(msg = malloc(sizeof(sxmsg_t)))) { r = SXE_ENOMEM; goto __fail2; }
else {
memset(msg, 0, sizeof(sxmsg_t));
co->messages[0] = msg;
@ -1041,17 +1040,17 @@ sxlink_t *sxlink_master_accept(conn_sys_t *ssys, int sck, struct in_addr *addr)
bbuf = (char *)buf;
bbuf += sizeof(sxmplv2_head_t);
while(co->flags & SNSX_BATCHMODE) {
while(co->flags & SXMP_BATCHMODE) {
rd = __conn_read(co, buf, sizeof(sxmplv2_head_t));
if(rd == sizeof(sxmplv2_head_t)) {
head = (sxmplv2_head_t *)buf;
/* check for returns */
if(head->opcode != SNE_SUCCESS) { r = head->opcode; goto __fail3; }
if(head->opcode != SXE_SUCCESS) { r = head->opcode; goto __fail3; }
else { /* opcode is fine */
/* if we're ready for messaging mode, turn off batch mode */
if(co->flags & SNSX_MESSAGINGMODE) {
co->flags &= ~SNSX_BATCHMODE;
if(co->flags & SXMP_MESSAGINGMODE) {
co->flags &= ~SXMP_BATCHMODE;
break;
}
}
@ -1059,8 +1058,8 @@ sxlink_t *sxlink_master_accept(conn_sys_t *ssys, int sck, struct in_addr *addr)
if(!head->payload_length) continue; /* pass the following check up */
rd = __conn_read(co, bbuf, head->payload_length);
if(rd == -1) { r = SNE_LINKERROR; goto __fail3; }
if(rd != head->payload_length) { r = SNE_LINKERROR; goto __fail3; }
if(rd == -1) { r = SXE_LINKERROR; goto __fail3; }
if(rd != head->payload_length) { r = SXE_LINKERROR; goto __fail3; }
bbuf[rd] = '\0';
sx = parse_sexp(bbuf, rd);
if(!sx) goto __fail3;
@ -1072,33 +1071,33 @@ sxlink_t *sxlink_master_accept(conn_sys_t *ssys, int sck, struct in_addr *addr)
r = __eval_syssexp(co, sx);
memcpy(head, &msg->mhead, sizeof(sxmplv2_head_t));
head->opcode = r;
if(r != SNE_SUCCESS) { /* we finish */
if(r != SXE_SUCCESS) { /* we finish */
head->payload_length = 0;
__conn_write(co, head, sizeof(sxmplv2_head_t));
destroy_sexp(sx);
goto __fail3;
}
rd = __conn_write(co, buf, sizeof(sxmplv2_head_t) + msg->mhead.payload_length);
if(rd == -1) { r = SNE_LINKERROR; goto __fail3; }
if(rd == -1) { r = SXE_LINKERROR; goto __fail3; }
if(rd != sizeof(sxmplv2_head_t) + msg->mhead.payload_length) {
destroy_sexp(sx);
goto __fail3;
}
destroy_sexp(sx);
} else { r = SNE_LINKERROR; goto __fail3; }
} else { r = SXE_LINKERROR; goto __fail3; }
}
/* if we're there - negotiation is done, going to init messaging mode */
r = __link_second_alloc(co);
if(r != SNE_SUCCESS) goto __fail3;
if(r != SXE_SUCCESS) goto __fail3;
/* free message */
co->messages[0] = NULL;
free(msg);
/* and now we're need to create a thread poll */
if(!(bundle = malloc(sizeof(sxmplv2_bundle_t)))) { r = SNE_ENOMEM; goto __fail4; }
if(!(bundle = malloc(sizeof(sxmplv2_bundle_t)))) { r = SXE_ENOMEM; goto __fail4; }
else {
bundle->buf = buf;
bundle->conn = co;
@ -1116,9 +1115,9 @@ sxlink_t *sxlink_master_accept(conn_sys_t *ssys, int sck, struct in_addr *addr)
}
/* all is done, connection now ready */
co->flags |= SNSX_ALIVE;
co->flags |= SXMP_ALIVE;
r = SNE_SUCCESS;
r = SXE_SUCCESS;
errno = r;
/* free context for this thread */
@ -1127,7 +1126,7 @@ sxlink_t *sxlink_master_accept(conn_sys_t *ssys, int sck, struct in_addr *addr)
return co;
__fail5:
r = SNE_ENOMEM;
r = SXE_ENOMEM;
/* bundles will be freed by the threads when SSL_read will fails. */
__fail4:
__link_second_free(co);
@ -1161,7 +1160,7 @@ sxlink_t *sxlink_connect(conn_sys_t *ssys, const char *host,
sxlink_t *co = __link_minimal_alloc(NULL);
struct hostent *host_;
struct sockaddr_in addr;
int r = SNE_SUCCESS, sck;
int r = SXE_SUCCESS, sck;
#ifdef WIN32
WSADATA wsaData;
#endif
@ -1174,9 +1173,9 @@ sxlink_t *sxlink_connect(conn_sys_t *ssys, const char *host,
size_t rd, wr;
int i;
r = SNE_IGNORED;
r = SXE_IGNORED;
if(!host || !SSL_cert) goto __fail;
if(!co) { r = SNE_ENOMEM; goto __fail; }
if(!co) { r = SXE_ENOMEM; goto __fail; }
#ifdef WIN32
WSAStartup(MAKEWORD(2, 2), &wsaData);
@ -1189,7 +1188,7 @@ sxlink_t *sxlink_connect(conn_sys_t *ssys, const char *host,
if(!ssys->ctx) {
/* init SSL certificates and context */
ssys->ctx = SSL_CTX_new(TLSv1_2_client_method());
if(!ssys->ctx) { r = SNE_ENOMEM; goto __fail; }
if(!ssys->ctx) { r = SXE_ENOMEM; goto __fail; }
else {
/* set verify context */
SSL_CTX_set_verify(ssys->ctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
@ -1203,36 +1202,36 @@ sxlink_t *sxlink_connect(conn_sys_t *ssys, const char *host,
/* set the local certificate from CertFile */
if(SSL_CTX_use_certificate_file(ssys->ctx, SSL_cert,
SSL_FILETYPE_PEM)<=0) {
r = SNE_ESSL;
r = SXE_ESSL;
goto __fail;
}
/* set the private key from KeyFile (may be the same as CertFile) */
if(SSL_CTX_use_PrivateKey_file(ssys->ctx, SSL_cert,
SSL_FILETYPE_PEM)<=0) {
r = SNE_ESSL;
r = SXE_ESSL;
goto __fail;
}
/* verify private key */
if (!SSL_CTX_check_private_key(ssys->ctx)) {
r = SNE_ESSL;
r = SXE_ESSL;
goto __fail;
}
} else {
/* set the local certificate from CertFile */
if(SSL_CTX_use_certificate_file(ssys->ctx, SSL_cert,
SSL_FILETYPE_PEM)<=0) {
r = SNE_ESSL;
r = SXE_ESSL;
goto __fail;
}
/* set the private key from KeyFile (may be the same as CertFile) */
if(SSL_CTX_use_PrivateKey_file(ssys->ctx, SSL_cert,
SSL_FILETYPE_PEM)<=0) {
r = SNE_ESSL;
r = SXE_ESSL;
goto __fail;
}
/* verify private key */
if (!SSL_CTX_check_private_key(ssys->ctx)) {
r = SNE_ESSL;
r = SXE_ESSL;
goto __fail;
}
}
@ -1241,13 +1240,13 @@ sxlink_t *sxlink_connect(conn_sys_t *ssys, const char *host,
#ifdef WIN32
host_ = gethostbyname(host);
if(!host_) {
r = SNE_FAILED;
r = SXE_FAILED;
goto __fail;
}
#else
r = __resolvehost(host, hostbuf, 2048, &host_);
if(r) {
r = SNE_FAILED;
r = SXE_FAILED;
goto __fail;
}
#endif
@ -1263,7 +1262,7 @@ sxlink_t *sxlink_connect(conn_sys_t *ssys, const char *host,
r = connect(sck, (struct sockaddr*)&addr, sizeof(addr));
if(r) {
close(sck);
r = SNE_FAILED; /* couldn't connect to the desired host */
r = SXE_FAILED; /* couldn't connect to the desired host */
goto __fail;
}
@ -1272,19 +1271,19 @@ sxlink_t *sxlink_connect(conn_sys_t *ssys, const char *host,
SSL_set_fd(co->ssl, sck); /* attach connected socket */
SSL_set_connect_state(co->ssl);
if(SSL_connect(co->ssl) == -1) {
r = SNE_EPERM;
r = SXE_EPERM;
/* shutdown connection */
goto __fail;
} /* if success we're ready to use established SSL channel */
/* set connection to the batch mode */
co->flags |= SNSX_BATCHMODE;
co->flags |= SXMP_BATCHMODE;
/* allocate our first buffer */
buf = mmap(NULL, 65536, PROT_READ|PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if(buf == MAP_FAILED) { r = SNE_ENOMEM; goto __fail2; }
if(buf == MAP_FAILED) { r = SXE_ENOMEM; goto __fail2; }
/* allocate first message */
if(!(msg = malloc(sizeof(sxmsg_t)))) { r = SNE_ENOMEM; goto __fail2; }
if(!(msg = malloc(sizeof(sxmsg_t)))) { r = SXE_ENOMEM; goto __fail2; }
else {
memset(msg, 0, sizeof(sxmsg_t));
co->messages[0] = msg;
@ -1295,25 +1294,25 @@ sxlink_t *sxlink_connect(conn_sys_t *ssys, const char *host,
sexp_t *sx;
size_t ln;
while(co->flags & SNSX_BATCHMODE) {
while(co->flags & SXMP_BATCHMODE) {
/* form a message -- credentials */
ln = snprintf(bbuf, 65535 - sizeof(sxmplv2_head_t), "(auth-set-credentials \"%s\" \"%s\")",
login ? login : "nil", passwd ? passwd : "nil");
head->opcode = SNE_SUCCESS;
head->opcode = SXE_SUCCESS;
head->payload_length = ln;
wr = __conn_write(co, buf, ln + sizeof(sxmplv2_head_t));
if(wr < 0) goto __fail2;
rd = __conn_read(co, head, sizeof(sxmplv2_head_t));
if(rd < 0) goto __fail2;
if(head->opcode != SNE_SUCCESS) {
if(head->opcode != SXE_SUCCESS) {
r = head->opcode;
goto __fail2;
}
/* ok, get available channels */
head->opcode = SNE_SUCCESS;
head->opcode = SXE_SUCCESS;
ln = snprintf(bbuf, 65535 - sizeof(sxmplv2_head_t), "(get-channels-list)");
head->payload_length = ln;
wr = __conn_write(co, buf, ln + sizeof(sxmplv2_head_t));
@ -1321,7 +1320,7 @@ sxlink_t *sxlink_connect(conn_sys_t *ssys, const char *host,
rd = __conn_read(co, head, sizeof(sxmplv2_head_t));
if(rd < 0) goto __fail2;
if(head->opcode != SNE_SUCCESS) goto __fail2;
if(head->opcode != SXE_SUCCESS) goto __fail2;
if(!head->payload_length) goto __fail2;
rd = __conn_read(co, bbuf, head->payload_length);
if(rd < 0) goto __fail2;
@ -1329,9 +1328,9 @@ sxlink_t *sxlink_connect(conn_sys_t *ssys, const char *host,
/* perform a parsing of the desired message */
bbuf[rd] = '\0';
sx = parse_sexp(bbuf, rd);
if(!sx) { r = SNE_BADPROTO; goto __fail2; }
if(!sx) { r = SXE_BADPROTO; goto __fail2; }
r = __eval_syssexp(co, sx);
if(!r) r = SNE_SUCCESS;
if(!r) r = SXE_SUCCESS;
destroy_sexp(sx);
/* write back */
@ -1339,20 +1338,20 @@ sxlink_t *sxlink_connect(conn_sys_t *ssys, const char *host,
head->payload_length = 0;
wr = __conn_write(co, head, sizeof(sxmplv2_head_t));
if(wr < 0) {
r = SNE_LINKERROR; goto __fail2;}
if(r != SNE_SUCCESS) { r = SNE_LINKERROR; goto __fail2;}
r = SXE_LINKERROR; goto __fail2;}
if(r != SXE_SUCCESS) { r = SXE_LINKERROR; goto __fail2;}
}
/* if we're there - negotiation is done, going to init messaging mode */
r = __link_second_alloc(co);
if(r != SNE_SUCCESS) goto __fail3;
if(r != SXE_SUCCESS) goto __fail3;
/* free message */
co->messages[0] = NULL;
free(msg);
/* and now we're need to create a thread poll */
if(!(bundle = malloc(sizeof(sxmplv2_bundle_t)))) { r = SNE_ENOMEM; goto __fail4; }
if(!(bundle = malloc(sizeof(sxmplv2_bundle_t)))) { r = SXE_ENOMEM; goto __fail4; }
else {
bundle->buf = buf;
bundle->conn = co;
@ -1369,12 +1368,12 @@ sxlink_t *sxlink_connect(conn_sys_t *ssys, const char *host,
}
/* all is done, connection now ready */
co->flags |= SNSX_ALIVE;
co->flags |= SXMP_ALIVE;
return co;
__fail5:
r = SNE_ENOMEM;
r = SXE_ENOMEM;
/* bundles will be freed by the threads when SSL_read will fails. */
__fail4:
__link_second_free(co);
@ -1409,10 +1408,10 @@ int sxlink_close(sxlink_t *co)
pthread_mutex_unlock(&(co->sslinout[1]));
/* we will not wait anything */
co->flags |= SNSX_CLOSED;
co->flags |= SXMP_CLOSED;
/* TODO: wait until all threads will finish */
usleep(20000);
return SNE_SUCCESS;
return SXE_SUCCESS;
}

Loading…
Cancel
Save