--- libaitrpc/src/srv.c 2012/05/17 12:52:30 1.9.2.22 +++ libaitrpc/src/srv.c 2012/05/17 15:14:16 1.9.2.23 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: srv.c,v 1.9.2.22 2012/05/17 12:52:30 misho Exp $ +* $Id: srv.c,v 1.9.2.23 2012/05/17 15:14:16 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -346,13 +346,12 @@ rxBLOB(sched_task_t *task) rpc_cli_t *c = TASK_ARG(task); rpc_srv_t *s = c->cli_parent; rpc_blob_t *b; - u_char *buf = AIT_GET_BUF(&c->cli_buf); - struct tagBLOBHdr *blob = (struct tagBLOBHdr *) buf; + struct tagBLOBHdr blob; int rlen; u_short crc; - memset(buf, 0, AIT_LEN(&c->cli_buf)); - rlen = recv(TASK_FD(task), buf, AIT_LEN(&c->cli_buf), 0); + memset(&blob, 0, sizeof blob); + rlen = recv(TASK_FD(task), &blob, sizeof blob, 0); if (rlen < 1) { /* close blob connection */ schedEvent(TASK_ROOT(task), closeBLOBClient, c, 42, NULL, 0); @@ -368,9 +367,9 @@ rxBLOB(sched_task_t *task) } /* check integrity of packet */ - crc = ntohs(blob->hdr_crc); - blob->hdr_crc ^= blob->hdr_crc; - if (crc != crcFletcher16((u_short*) buf, rlen / 2)) { + crc = ntohs(blob.hdr_crc); + blob.hdr_crc ^= blob.hdr_crc; + if (crc != crcFletcher16((u_short*) &blob, rlen / 2)) { rpc_SetErr(ERPCMISMATCH, "Bad CRC BLOB packet"); schedReadSelf(task); @@ -378,58 +377,59 @@ rxBLOB(sched_task_t *task) } /* check RPC packet session info */ - if ((crc = rpc_chkPktSession(&blob->hdr_session, &s->srv_session))) { + if ((crc = rpc_chkPktSession(&blob.hdr_session, &s->srv_session))) { rpc_SetErr(ERPCMISMATCH, "Get invalid RPC session"); - blob->hdr_cmd = error; + blob.hdr_cmd = error; goto end; } /* Go to proceed packet ... */ - switch (blob->hdr_cmd) { + switch (blob.hdr_cmd) { case get: - if (!(b = rpc_srv_getBLOB(s, ntohl(blob->hdr_var)))) { - rpc_SetErr(EINVAL, "Var=%x not found", ntohl(blob->hdr_var)); - blob->hdr_cmd = no; - blob->hdr_ret = RPC_ERROR(-1); + if (!(b = rpc_srv_getBLOB(s, ntohl(blob.hdr_var)))) { + rpc_SetErr(EINVAL, "Var=%x not found", ntohl(blob.hdr_var)); + blob.hdr_cmd = no; + blob.hdr_ret = RPC_ERROR(-1); break; } else - blob->hdr_len = htonl(b->blob_len); + blob.hdr_len = htonl(b->blob_len); if (rpc_srv_blobMap(s, b) != -1) { /* deliver BLOB variable to client */ - blob->hdr_ret = htonl(rpc_srv_sendBLOB(c, b)); + blob.hdr_ret = htonl(rpc_srv_sendBLOB(c, b)); rpc_srv_blobUnmap(b); } else { - blob->hdr_cmd = error; - blob->hdr_ret = RPC_ERROR(-1); + blob.hdr_cmd = error; + blob.hdr_ret = RPC_ERROR(-1); } break; case set: - if ((b = rpc_srv_registerBLOB(s, ntohl(blob->hdr_len)))) { + if ((b = rpc_srv_registerBLOB(s, ntohl(blob.hdr_len)))) { /* set new BLOB variable for reply :) */ - blob->hdr_var = htonl(b->blob_var); + blob.hdr_var = htonl(b->blob_var); /* receive BLOB from client */ - blob->hdr_ret = htonl(rpc_srv_recvBLOB(c, b)); + blob.hdr_ret = htonl(rpc_srv_recvBLOB(c, b)); rpc_srv_blobUnmap(b); } else { - blob->hdr_cmd = error; - blob->hdr_ret = RPC_ERROR(-1); + blob.hdr_cmd = error; + blob.hdr_ret = RPC_ERROR(-1); } break; case unset: - if (rpc_srv_unregisterBLOB(s, blob->hdr_var) == -1) { - blob->hdr_cmd = error; - blob->hdr_ret = RPC_ERROR(-1); + if (rpc_srv_unregisterBLOB(s, blob.hdr_var) == -1) { + blob.hdr_cmd = error; + blob.hdr_ret = RPC_ERROR(-1); } break; default: - rpc_SetErr(EPROCUNAVAIL, "Unsupported BLOB command %d", blob->hdr_cmd); - blob->hdr_cmd = error; - blob->hdr_ret = RPC_ERROR(-1); + rpc_SetErr(EPROCUNAVAIL, "Unsupported BLOB command %d", blob.hdr_cmd); + blob.hdr_cmd = error; + blob.hdr_ret = RPC_ERROR(-1); } end: + memcpy(AIT_ADDR(&c->cli_buf), &blob, sizeof blob); schedWrite(TASK_ROOT(task), txBLOB, TASK_ARG(task), TASK_FD(task), NULL, 0); schedReadSelf(task); return NULL;