--- libaitrpc/src/blob.c 2013/03/07 23:10:50 1.11 +++ libaitrpc/src/blob.c 2013/07/15 13:53:10 1.13.2.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: blob.c,v 1.11 2013/03/07 23:10:50 misho Exp $ +* $Id: blob.c,v 1.13.2.2 2013/07/15 13:53:10 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -53,7 +53,7 @@ SUCH DAMAGE. * @len = BLOB length object * return: NULL error or !=NULL allocated BLOB object */ -inline rpc_blob_t * +rpc_blob_t * rpc_srv_blobCreate(rpc_srv_t * __restrict srv, int len) { rpc_blob_t *blob = NULL; @@ -111,7 +111,7 @@ again: * @blob = Map to this BLOB element * return: -1 error or 0 ok */ -inline int +int rpc_srv_blobMap(rpc_srv_t * __restrict srv, rpc_blob_t * __restrict blob) { int f; @@ -155,7 +155,7 @@ rpc_srv_blobMap(rpc_srv_t * __restrict srv, rpc_blob_t * @blob = Mapped BLOB element * return: none */ -inline void +void rpc_srv_blobUnmap(rpc_blob_t * __restrict blob) { if (blob && blob->blob_data) { @@ -171,7 +171,7 @@ rpc_srv_blobUnmap(rpc_blob_t * __restrict blob) * @blob = Mapped BLOB element * return: -1 error or 0 ok */ -inline int +int rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_t * __restrict blob) { char szFName[MAXPATHLEN]; @@ -272,10 +272,12 @@ rpc_srv_recvBLOB(rpc_cli_t * __restrict cli, rpc_blob_ * @cli = Client instance * @var = BLOB variable * @data = BLOB data + * @tout = BLOB live on server timeout in seconds, if =NULL default timeout * return: -1 error, 0 ok, 1 remote error */ int -rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var, void * __restrict data) +rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var, void * __restrict data, + int * __restrict tout) { int ret, len; uint8_t *pos; @@ -291,11 +293,8 @@ rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t rpc_addPktSession(&hdr.hdr_session, cli->cli_parent); hdr.hdr_cmd = set; hdr.hdr_var = 0; - hdr.hdr_ret = 0; + hdr.hdr_ret = tout ? *tout : 0; hdr.hdr_len = htonl(AIT_LEN(var)); - /* calculate CRC */ - hdr.hdr_crc ^= hdr.hdr_crc; - hdr.hdr_crc = htons(crcFletcher16((u_short*) &hdr, sizeof hdr / 2)); /* send SET request */ pfd.fd = cli->cli_sock; @@ -331,21 +330,17 @@ rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t LOGERR; return 1; } - /* check CRC */ - ret = ntohs(hdr.hdr_crc); - hdr.hdr_crc ^= hdr.hdr_crc; - if (ret != crcFletcher16((u_short*) &hdr, sizeof hdr / 2)) { - rpc_SetErr(ERPCMISMATCH, "Bad CRC BLOB packet"); - return 1; - } if (hdr.hdr_cmd != error) { + AIT_SET_BLOB(var, ntohl(hdr.hdr_var), ntohl(hdr.hdr_len)); + if (ntohl(hdr.hdr_len) != AIT_LEN(var)) { + rpc_cli_delBLOB(cli, var); + AIT_NEW_BLOB(var, ntohl(hdr.hdr_len)); + rpc_SetErr(ECANCELED, "Bad return length packet"); return 1; } - - AIT_SET_BLOB(var, ntohl(hdr.hdr_var), ntohl(hdr.hdr_len)); } return hdr.hdr_cmd == error; @@ -386,9 +381,6 @@ rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t hdr.hdr_var = htonl((uint32_t) AIT_GET_BLOB(var)); hdr.hdr_ret = 0; hdr.hdr_len = 0; - /* calculate CRC */ - hdr.hdr_crc ^= hdr.hdr_crc; - hdr.hdr_crc = htons(crcFletcher16((u_short*) &hdr, sizeof hdr / 2)); /* send GET request */ pfd.fd = cli->cli_sock; @@ -443,15 +435,6 @@ rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t *data = NULL; return 1; } - /* check CRC */ - ret = ntohs(hdr.hdr_crc); - hdr.hdr_crc ^= hdr.hdr_crc; - if (ret != crcFletcher16((u_short*) &hdr, sizeof hdr / 2)) { - rpc_SetErr(ERPCMISMATCH, "Bad CRC BLOB packet"); - e_free(*data); - *data = NULL; - return 1; - } if (hdr.hdr_cmd != error) { if (ntohl(hdr.hdr_len) != AIT_LEN(var)) { rpc_SetErr(ECANCELED, "Bad return length packet"); @@ -489,9 +472,6 @@ rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t hdr.hdr_var = htonl((uint32_t) AIT_GET_BLOB(var)); hdr.hdr_ret = 0; hdr.hdr_len = 0; - /* calculate CRC */ - hdr.hdr_crc ^= hdr.hdr_crc; - hdr.hdr_crc = htons(crcFletcher16((u_short*) &hdr, sizeof hdr / 2)); /* send UNSET request */ pfd.fd = cli->cli_sock; @@ -520,13 +500,6 @@ rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t LOGERR; return 1; } - /* check CRC */ - ret = ntohs(hdr.hdr_crc); - hdr.hdr_crc ^= hdr.hdr_crc; - if (ret != crcFletcher16((u_short*) &hdr, sizeof hdr / 2)) { - rpc_SetErr(ERPCMISMATCH, "Bad CRC BLOB packet"); - return 1; - } return hdr.hdr_cmd == error; } @@ -539,7 +512,7 @@ rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t * @data = BLOB data, must be e_free after use! * return: -1 error, 0 ok, 1 remote error */ -inline int +int rpc_cli_getBLOB(rpc_cli_t * __restrict cli, ait_val_t * __restrict var, void ** __restrict data) { int ret;