From f0819da6a94d143ee4d6d42ee22cbe76255b8ff2 Mon Sep 17 00:00:00 2001 From: Alexander Vdolainen Date: Thu, 10 Mar 2016 01:35:48 +0200 Subject: [PATCH] [core] Added function sxlink_connect_at() adding a private data for implementation on the client side; --- include/sxmp/sxmp.h | 4 ++++ lib/sxmplv2.c | 34 ++++++++++++++++++++++------------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/include/sxmp/sxmp.h b/include/sxmp/sxmp.h index 2b397a8..529309e 100644 --- a/include/sxmp/sxmp.h +++ b/include/sxmp/sxmp.h @@ -358,6 +358,10 @@ sxlink_t *sxlink_master_accept(sxhub_t *hub, int sck, struct in_addr *addr); sxlink_t *sxlink_connect(sxhub_t *hub, const char *host, int port, const char *SSL_cert, const char *login, const char *passwd); +sxlink_t *sxlink_connect_at(sxhub_t *hub, const char *host, + int port, const char *SSL_cert, const char *login, + const char *passwd, const void *priv); + int sxlink_close(sxlink_t *co); /* channels */ diff --git a/lib/sxmplv2.c b/lib/sxmplv2.c index fa8ebba..8fb340d 100644 --- a/lib/sxmplv2.c +++ b/lib/sxmplv2.c @@ -1109,8 +1109,15 @@ enum { }; sxlink_t *sxlink_connect(sxhub_t *hub, const char *host, - int port, const char *SSL_cert, const char *login, - const char *passwd) + int port, const char *SSL_cert, const char *login, + const char *passwd) +{ + return sxlink_connect_at(hub, host, port, SSL_cert, login, passwd, NULL); +} + +sxlink_t *sxlink_connect_at(sxhub_t *hub, const char *host, + int port, const char *SSL_cert, const char *login, + const char *passwd, const void *priv) { sxlink_t *link = __link_minimal_alloc(NULL); struct hostent *host_; @@ -1202,6 +1209,9 @@ sxlink_t *sxlink_connect(sxhub_t *hub, const char *host, bbuf += sizeof(sxmplv2_head_t); head = (sxmplv2_head_t *)buf; + /* set out data */ + if(priv) sxlink_setpriv(link, priv); + /* authentification first both V2 and newer */ /* form a message -- credentials */ ln = snprintf(bbuf, 65535 - sizeof(sxmplv2_head_t), "(auth-set-credentials \"%s\" \"%s\")", @@ -1210,13 +1220,13 @@ sxlink_t *sxlink_connect(sxhub_t *hub, const char *host, head->opcode = SXE_SUCCESS; head->payload_length = ln; wr = __conn_write(link, buf, ln + sizeof(sxmplv2_head_t)); - if(wr < 0) goto __fail2; + if(wr < 0) goto __fail3; rd = __conn_read(link, head, sizeof(sxmplv2_head_t)); - if(rd < 0) goto __fail2; + if(rd < 0) goto __fail3; if(head->opcode != SXE_SUCCESS) { r = head->opcode; - goto __fail2; + goto __fail3; } /* since V2.1 syncronization should be done here */ @@ -1238,22 +1248,22 @@ sxlink_t *sxlink_connect(sxhub_t *hub, const char *host, /* write a message */ head->payload_length = ln; wr = __conn_write(link, buf, ln + sizeof(sxmplv2_head_t)); - if(wr < 0) goto __fail2; + if(wr < 0) goto __fail3; rd = __conn_read(link, head, sizeof(sxmplv2_head_t)); - if(rd < 0) goto __fail2; - if(head->opcode != SXE_SUCCESS) goto __fail2; + if(rd < 0) goto __fail3; + if(head->opcode != SXE_SUCCESS) goto __fail3; if(!head->payload_length) { sync_state++; continue; } rd = __conn_read(link, bbuf, head->payload_length); - if(rd < 0) goto __fail2; + if(rd < 0) goto __fail3; /* perform a parsing of the desired message */ bbuf[rd] = '\0'; sx = parse_sexp(bbuf, rd); - if(!sx) { r = SXE_BADPROTO; goto __fail2; } + if(!sx) { r = SXE_BADPROTO; goto __fail3; } r = __eval_syssexp(link, sx); if(!r) r = SXE_SUCCESS; destroy_sexp(sx); @@ -1263,8 +1273,8 @@ sxlink_t *sxlink_connect(sxhub_t *hub, const char *host, head->opcode = r; head->payload_length = 0; wr = __conn_write(link, head, sizeof(sxmplv2_head_t)); - if(wr < 0) { r = SXE_LINKERROR; goto __fail2;} - if(r != SXE_SUCCESS) { r = SXE_LINKERROR; goto __fail2;} + if(wr < 0) { r = SXE_LINKERROR; goto __fail3;} + if(r != SXE_SUCCESS) { r = SXE_LINKERROR; goto __fail3;} } sync_state++; }