[core] Added function sxlink_connect_at() adding a private data for implementation on the client side;

v0.5.xx
Alexander Vdolainen 9 years ago
parent 2a675d798a
commit f0819da6a9

@ -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, sxlink_t *sxlink_connect(sxhub_t *hub, const char *host,
int port, const char *SSL_cert, const char *login, int port, const char *SSL_cert, const char *login,
const char *passwd); 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); int sxlink_close(sxlink_t *co);
/* channels */ /* channels */

@ -1109,8 +1109,15 @@ enum {
}; };
sxlink_t *sxlink_connect(sxhub_t *hub, const char *host, sxlink_t *sxlink_connect(sxhub_t *hub, const char *host,
int port, const char *SSL_cert, const char *login, int port, const char *SSL_cert, const char *login,
const char *passwd) 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); sxlink_t *link = __link_minimal_alloc(NULL);
struct hostent *host_; struct hostent *host_;
@ -1202,6 +1209,9 @@ sxlink_t *sxlink_connect(sxhub_t *hub, const char *host,
bbuf += sizeof(sxmplv2_head_t); bbuf += sizeof(sxmplv2_head_t);
head = (sxmplv2_head_t *)buf; head = (sxmplv2_head_t *)buf;
/* set out data */
if(priv) sxlink_setpriv(link, priv);
/* authentification first both V2 and newer */ /* authentification first both V2 and newer */
/* form a message -- credentials */ /* form a message -- credentials */
ln = snprintf(bbuf, 65535 - sizeof(sxmplv2_head_t), "(auth-set-credentials \"%s\" \"%s\")", 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->opcode = SXE_SUCCESS;
head->payload_length = ln; head->payload_length = ln;
wr = __conn_write(link, buf, ln + sizeof(sxmplv2_head_t)); 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)); rd = __conn_read(link, head, sizeof(sxmplv2_head_t));
if(rd < 0) goto __fail2; if(rd < 0) goto __fail3;
if(head->opcode != SXE_SUCCESS) { if(head->opcode != SXE_SUCCESS) {
r = head->opcode; r = head->opcode;
goto __fail2; goto __fail3;
} }
/* since V2.1 syncronization should be done here */ /* 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 */ /* write a message */
head->payload_length = ln; head->payload_length = ln;
wr = __conn_write(link, buf, ln + sizeof(sxmplv2_head_t)); 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)); rd = __conn_read(link, head, sizeof(sxmplv2_head_t));
if(rd < 0) goto __fail2; if(rd < 0) goto __fail3;
if(head->opcode != SXE_SUCCESS) goto __fail2; if(head->opcode != SXE_SUCCESS) goto __fail3;
if(!head->payload_length) { if(!head->payload_length) {
sync_state++; sync_state++;
continue; continue;
} }
rd = __conn_read(link, bbuf, head->payload_length); 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 */ /* perform a parsing of the desired message */
bbuf[rd] = '\0'; bbuf[rd] = '\0';
sx = parse_sexp(bbuf, rd); sx = parse_sexp(bbuf, rd);
if(!sx) { r = SXE_BADPROTO; goto __fail2; } if(!sx) { r = SXE_BADPROTO; goto __fail3; }
r = __eval_syssexp(link, sx); r = __eval_syssexp(link, sx);
if(!r) r = SXE_SUCCESS; if(!r) r = SXE_SUCCESS;
destroy_sexp(sx); destroy_sexp(sx);
@ -1263,8 +1273,8 @@ sxlink_t *sxlink_connect(sxhub_t *hub, const char *host,
head->opcode = r; head->opcode = r;
head->payload_length = 0; head->payload_length = 0;
wr = __conn_write(link, head, sizeof(sxmplv2_head_t)); wr = __conn_write(link, head, sizeof(sxmplv2_head_t));
if(wr < 0) { r = SXE_LINKERROR; goto __fail2;} if(wr < 0) { r = SXE_LINKERROR; goto __fail3;}
if(r != SXE_SUCCESS) { r = SXE_LINKERROR; goto __fail2;} if(r != SXE_SUCCESS) { r = SXE_LINKERROR; goto __fail3;}
} }
sync_state++; sync_state++;
} }

Loading…
Cancel
Save