From 608fefe4a5fd29858b424e54ee3ca45adab39802 Mon Sep 17 00:00:00 2001 From: Vadim Saranov Date: Fri, 2 Oct 2026 11:04:41 +0300 Subject: [PATCH] jsonrpc: normalize indentation in netstringsRead() The function mixed tabs and spaces and carried trailing whitespace; re-indent it to two spaces, as the rest of the file. No functional change -- git diff -w is empty. Signed-off-by: Vadim Saranov --- apps/jsonrpc/RpcPeer.cpp | 160 +++++++++++++++++++-------------------- 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/apps/jsonrpc/RpcPeer.cpp b/apps/jsonrpc/RpcPeer.cpp index 7f61ff9e..83fbcb0f 100644 --- a/apps/jsonrpc/RpcPeer.cpp +++ b/apps/jsonrpc/RpcPeer.cpp @@ -185,88 +185,88 @@ int JsonrpcNetstringsConnection::netstringsRead() { if (!in_msg) { while (true) { if (rcvd_size > MAX_NS_LEN_SIZE) { - DBG("closing connection [%p/%d]: oversize length\n", this, fd); - close(); - return REMOVE; + DBG("closing connection [%p/%d]: oversize length\n", this, fd); + close(); + return REMOVE; } // reading length ssize_t r=read(fd,&msgbuf[rcvd_size],1); if (!r) { - DBG("closing connection [%p/%d] on peer hangup\n", this, fd); - close(); - return REMOVE; + DBG("closing connection [%p/%d] on peer hangup\n", this, fd); + close(); + return REMOVE; } - if ((r<0 && errno == EAGAIN) || - (r<0 && errno == EWOULDBLOCK)) - return CONTINUE; - + if ((r<0 && errno == EAGAIN) || + (r<0 && errno == EWOULDBLOCK)) + return CONTINUE; + if (r != 1) { - INFO("socket error on connection [%p/%d]: %s\n", - this, fd, strerror(errno)); - close(); - return REMOVE; + INFO("socket error on connection [%p/%d]: %s\n", + this, fd, strerror(errno)); + close(); + return REMOVE; } - + DBG("received '%c'\n", msgbuf[rcvd_size]); if (msgbuf[rcvd_size] == ':') { - msgbuf[rcvd_size] = '\0'; - if (str2int(std::string(msgbuf, rcvd_size), msg_size)) { - ERROR("Protocol error decoding size '%s'\n", msgbuf); - close(); - return REMOVE; - } - // received len - switch to receive msg mode - if (msg_size > MAX_RPC_MSG_SIZE - 2) { - // ensure there is enough room in msgbuf for the message body, - // the ',' separator and the terminating '\0' - ERROR("Protocol error on connection [%p/%d]: message size %u too large\n", - this, fd, msg_size); - close(); - return REMOVE; - } - in_msg = true; - rcvd_size = read(fd,msgbuf,msg_size+1); - // DBG("received '%.*s'\n", rcvd_size, msgbuf); - - if (rcvd_size == msg_size+1) { - if (msgbuf[msg_size] == ',') { - msgbuf[msg_size+1] = '\0'; - return DISPATCH; - } - INFO("Protocol error on connection [%p/%d]: netstring not terminated with ','\n", - this, fd); - close(); - return REMOVE; - } - - if (!rcvd_size) { - DBG("closing connection [%p/%d] on peer hangup\n", this, fd); - close(); - return REMOVE; - } - - if ((rcvd_size<0 && errno == EAGAIN) || - (rcvd_size<0 && errno == EWOULDBLOCK)) - return CONTINUE; // necessary? - - if (rcvd_size<0) { - INFO("socket error on connection [%p/%d]: %s\n", - this, fd, strerror(errno)); - close(); - return REMOVE; - } - - return CONTINUE; - } + msgbuf[rcvd_size] = '\0'; + if (str2int(std::string(msgbuf, rcvd_size), msg_size)) { + ERROR("Protocol error decoding size '%s'\n", msgbuf); + close(); + return REMOVE; + } + // received len - switch to receive msg mode + if (msg_size > MAX_RPC_MSG_SIZE - 2) { + // ensure there is enough room in msgbuf for the message body, + // the ',' separator and the terminating '\0' + ERROR("Protocol error on connection [%p/%d]: message size %u too large\n", + this, fd, msg_size); + close(); + return REMOVE; + } + in_msg = true; + rcvd_size = read(fd,msgbuf,msg_size+1); + // DBG("received '%.*s'\n", rcvd_size, msgbuf); + + if (rcvd_size == msg_size+1) { + if (msgbuf[msg_size] == ',') { + msgbuf[msg_size+1] = '\0'; + return DISPATCH; + } + INFO("Protocol error on connection [%p/%d]: netstring not terminated with ','\n", + this, fd); + close(); + return REMOVE; + } + + if (!rcvd_size) { + DBG("closing connection [%p/%d] on peer hangup\n", this, fd); + close(); + return REMOVE; + } + + if ((rcvd_size<0 && errno == EAGAIN) || + (rcvd_size<0 && errno == EWOULDBLOCK)) + return CONTINUE; // necessary? + + if (rcvd_size<0) { + INFO("socket error on connection [%p/%d]: %s\n", + this, fd, strerror(errno)); + close(); + return REMOVE; + } + + return CONTINUE; + } if (msgbuf[rcvd_size] < '0' || msgbuf[rcvd_size] > '9') { - INFO("Protocol error on connection [%p/%d]: invalid character in size\n", - this, fd); - close(); - return REMOVE; + INFO("Protocol error on connection [%p/%d]: invalid character in size\n", + this, fd); + close(); + return REMOVE; } - + rcvd_size++; } } else { @@ -274,14 +274,14 @@ int JsonrpcNetstringsConnection::netstringsRead() { if (r>0) { rcvd_size += r; DBG("msgbuf='%.*s'\n", msg_size+1,msgbuf); - if (rcvd_size == msg_size+1) { - DBG("msg_size = %d, rcvd_size = %d, <%c> \n", msg_size, rcvd_size, msgbuf[msg_size-1]); - if (msgbuf[msg_size] == ',') - return DISPATCH; - INFO("Protocol error on connection [%p/%d]: netstring not terminated with ','\n", - this, fd); - close(); - return REMOVE; + if (rcvd_size == msg_size+1) { + DBG("msg_size = %d, rcvd_size = %d, <%c> \n", msg_size, rcvd_size, msgbuf[msg_size-1]); + if (msgbuf[msg_size] == ',') + return DISPATCH; + INFO("Protocol error on connection [%p/%d]: netstring not terminated with ','\n", + this, fd); + close(); + return REMOVE; } return CONTINUE; } @@ -292,12 +292,12 @@ int JsonrpcNetstringsConnection::netstringsRead() { return REMOVE; } - if ((r<0 && errno == EAGAIN) || - (r<0 && errno == EWOULDBLOCK)) + if ((r<0 && errno == EAGAIN) || + (r<0 && errno == EWOULDBLOCK)) return CONTINUE; // necessary? INFO("socket error on connection [%p/%d]: %s\n", - this, fd, strerror(errno)); + this, fd, strerror(errno)); close(); return REMOVE; }