--- libaitrpc/src/blob.c 2012/11/13 09:22:10 1.10 +++ libaitrpc/src/blob.c 2013/05/26 20:24:52 1.12.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: blob.c,v 1.10 2012/11/13 09:22:10 misho Exp $ +* $Id: blob.c,v 1.12.2.1 2013/05/26 20:24:52 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 +Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -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; @@ -81,7 +81,7 @@ again: return NULL; } - blob = io_malloc(sizeof(rpc_blob_t)); + blob = e_malloc(sizeof(rpc_blob_t)); if (!blob) { LOGERR; close(f); @@ -92,7 +92,7 @@ again: blob->blob_data = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, f, 0); if (blob->blob_data == MAP_FAILED) { LOGERR; - io_free(blob); + e_free(blob); close(f); unlink(szFName); return 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]; @@ -293,9 +293,6 @@ rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t hdr.hdr_var = 0; hdr.hdr_ret = 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,13 +328,6 @@ 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) { if (ntohl(hdr.hdr_len) != AIT_LEN(var)) { @@ -356,7 +346,7 @@ rpc_cli_sendBLOB(rpc_cli_t * __restrict cli, ait_val_t * * @cli = Client instance * @var = BLOB variable - * @data = BLOB data, must be io_free after use! + * @data = BLOB data, must be e_free after use! * return: -1 error, 0 ok, 1 remote error */ int @@ -372,7 +362,7 @@ rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t return -1; } - *data = io_malloc(AIT_LEN(var)); + *data = e_malloc(AIT_LEN(var)); if (!*data) { LOGERR; return -1; @@ -386,9 +376,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; @@ -396,13 +383,13 @@ rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t if ((ret = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) == -1 || pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { LOGERR; - io_free(*data); + e_free(*data); *data = NULL; return -1; } if (send(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) { LOGERR; - io_free(*data); + e_free(*data); *data = NULL; return -1; } @@ -413,14 +400,14 @@ rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t if ((len = poll(&pfd, 1, DEF_RPC_TIMEOUT * 1000)) < 1 || pfd.revents & (POLLERR | POLLHUP | POLLNVAL)) { LOGERR; - io_free(*data); + e_free(*data); *data = NULL; return -1; } if ((len = recv(cli->cli_sock, pos, ret, 0)) == -1) { LOGERR; - io_free(*data); + e_free(*data); *data = NULL; return -1; } @@ -433,29 +420,20 @@ rpc_cli_recvBLOB(rpc_cli_t * __restrict cli, ait_val_t LOGERR; else rpc_SetErr(ETIMEDOUT, "Timeout reached! Server not respond"); - io_free(*data); + e_free(*data); *data = NULL; return 1; } if (recv(cli->cli_sock, &hdr, sizeof hdr, 0) == -1) { LOGERR; - io_free(*data); + e_free(*data); *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"); - io_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"); - io_free(*data); + e_free(*data); *data = NULL; return 1; } @@ -489,9 +467,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 +495,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; } @@ -536,10 +504,10 @@ rpc_cli_delBLOB(rpc_cli_t * __restrict cli, ait_val_t * * @cli = Client instance * @var = BLOB variable - * @data = BLOB data, must be io_free after use! + * @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;