diff --git a/integs/ConnectionMock.cpp b/integs/ConnectionMock.cpp index c01937729b..b869f8bad1 100644 --- a/integs/ConnectionMock.cpp +++ b/integs/ConnectionMock.cpp @@ -35,6 +35,7 @@ ConnectionMock::ConnectionMock() { fds[0] = -1; fds[1] = -1; + pendingChar = -1; bufferReceiveAllowed = false; } @@ -53,6 +54,7 @@ void ConnectionMock::release() bufferReceiveAllowed = false; fds[0] = -1; fds[1] = -1; + pendingChar = -1; } @@ -73,8 +75,22 @@ void ConnectionMock::allowBufferReceive(bool state) bufferReceiveAllowed = state; } -ssize_t ConnectionMock::read(void * buffer, size_t len) +ssize_t ConnectionMock::read(void * vbuffer, size_t len) { + unsigned char * buffer = (unsigned char*) vbuffer; + ssize_t baseLength = 0; + if (len && (pendingChar != -1)) { + ((char*)buffer)[0] = pendingChar; + pendingChar = -1; + len--; + buffer++; + if (len == 0) + { + return 1; + } + baseLength = 1; + } + struct msghdr msgh; struct iovec iov; @@ -133,7 +149,7 @@ ssize_t ConnectionMock::read(void * buffer, size_t len) } } } - return size; + return size + baseLength; } void ConnectionMock::expectBuffer(SharedBuffer &sb) @@ -178,6 +194,13 @@ void ConnectionMock::expect(const std::string &str) char ConnectionMock::readChar(const std::string &expected) { + if (pendingChar != -1) + { + char c = pendingChar; + pendingChar = -1; + return c; + } + char buff[1]; ssize_t rd = read(buff, 1); if (rd == 0) @@ -192,6 +215,16 @@ char ConnectionMock::readChar(const std::string &expected) return buff[0]; } +char ConnectionMock::peekChar(const std::string & expected) { + if (pendingChar != -1) + { + return pendingChar; + } + char ret = readChar(expected); + pendingChar = ret; + return ret; +} + enum XmlStatus { PRE, TAGNAME, WAIT_ATTRIB, ATTRIB, QUOTE, WAIT_CLOSE }; static std::string parseXmlFragmentFromString(const std::string &str) @@ -237,6 +270,19 @@ std::string ConnectionMock::receiveMore() return pendingData; } +std::string ConnectionMock::expectBase64() { + std::string result; + + while(true) { + char c = peekChar("base64"); + if (c == '<') break; + + result += readChar("base64"); + } + + return result; +} + void ConnectionMock::expectXml(const std::string &expected) { diff --git a/integs/ConnectionMock.h b/integs/ConnectionMock.h index 87e3bd555c..f50e56bf34 100644 --- a/integs/ConnectionMock.h +++ b/integs/ConnectionMock.h @@ -29,11 +29,14 @@ class SharedBuffer; */ class ConnectionMock { + private: int fds[2]; + int pendingChar; std::list receivedFds; bool bufferReceiveAllowed; ssize_t read(void * buff, size_t count); char readChar(const std::string &expected); + char peekChar(const std::string &expected); void release(); std::string receiveMore(); @@ -49,6 +52,7 @@ class ConnectionMock void expect(const std::string &content); void expectXml(const std::string &xml); + std::string expectBase64(); void send(const std::string &content); void send(const std::string &content, const SharedBuffer &buff); void send(const std::string &content, const SharedBuffer ** buffers); diff --git a/integs/TestIndiserverSingleDriver.cpp b/integs/TestIndiserverSingleDriver.cpp index e2cb82c0ac..757d81dd38 100644 --- a/integs/TestIndiserverSingleDriver.cpp +++ b/integs/TestIndiserverSingleDriver.cpp @@ -559,7 +559,7 @@ TEST(IndiserverSingleDriver, ForwardAttachedBlobToDriver) snoopDriver.cnx.send("Also\n"); snoopDriver.ping(); - ssize_t size = 32; + ssize_t size = 10000; driverSendAttachedBlob(fakeDriver, size); #if 0 @@ -575,8 +575,9 @@ TEST(IndiserverSingleDriver, ForwardAttachedBlobToDriver) EXPECT_GE( receivedFd.getSize(), 32); #else snoopDriver.cnx.expectXml(""); - snoopDriver.cnx.expectXml("\n"); - snoopDriver.cnx.expect("\nMDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDE="); + snoopDriver.cnx.expectXml("\n"); + std::string base64 = snoopDriver.cnx.expectBase64(); + EXPECT_EQ(base64.size(), size * 4 / 3 + 9 + (size / 800000)); snoopDriver.cnx.expectXml("\n"); snoopDriver.cnx.expectXml(""); #endif diff --git a/libs/indicore/indidevapi.c b/libs/indicore/indidevapi.c index 809daa5658..e76f3cae26 100644 --- a/libs/indicore/indidevapi.c +++ b/libs/indicore/indidevapi.c @@ -528,12 +528,11 @@ int IUSnoopBLOB(XMLEle *root, IBLOBVectorProperty *bvp) XMLAtt *fa = findXMLAtt(ep, "format"); XMLAtt *sa = findXMLAtt(ep, "size"); - XMLAtt *ec = findXMLAtt(ep, "enclen"); - if (fa && sa && ec) + if (fa && sa) { - int enclen = atoi(valuXMLAtt(ec)); - assert_mem(bp->blob = realloc(bp->blob, 3 * enclen / 4)); - bp->bloblen = from64tobits_fast(bp->blob, pcdataXMLEle(ep), enclen); + int base64datalen = pcdatalenXMLEle(ep); + assert_mem(bp->blob = realloc(bp->blob, 3 * base64datalen / 4)); + bp->bloblen = from64tobits_fast(bp->blob, pcdataXMLEle(ep), base64datalen); indi_strlcpy(bp->format, valuXMLAtt(fa), MAXINDIFORMAT); bp->size = atoi(valuXMLAtt(sa)); }