void packetSocket::takeSomeEscapeSeq(const unsigned char * const buffer, size_t const length, size_t * const bytesTakenP) { /*---------------------------------------------------------------------------- Take and process some bytes from the incoming stream 'buffer', which contains 'length' bytes, assuming they are within an escape sequence. -----------------------------------------------------------------------------*/ size_t bytesTaken; bytesTaken = 0; while (this->escAccum.len < 3 && bytesTaken < length) this->escAccum.bytes[this->escAccum.len++] = buffer[bytesTaken++]; assert(this->escAccum.len <= 3); if (this->escAccum.len == 3) { if (0) { } else if (xmlrpc_memeq(this->escAccum.bytes, "NOP", 3)) { // Nothing to do } else if (xmlrpc_memeq(this->escAccum.bytes, "PKT", 3)) { this->packetAccumP = packetPtr(new packet); this->inPacket = true; } else if (xmlrpc_memeq(this->escAccum.bytes, "END", 3)) { if (this->inPacket) { this->readBuffer.push(this->packetAccumP); this->inPacket = false; this->packetAccumP = packetPtr(); } else throwf("END control word received without preceding PKT"); } else if (xmlrpc_memeq(this->escAccum.bytes, "ESC", 3)) { if (this->inPacket) this->packetAccumP->addData((const unsigned char *)ESC_STR, 1); else throwf("ESC control work received outside of a packet"); } else throwf("Invalid escape sequence 0x%02x%02x%02x read from " "stream socket under packet socket", this->escAccum.bytes[0], this->escAccum.bytes[1], this->escAccum.bytes[2]); this->inEscapeSeq = false; this->escAccum.len = 0; } *bytesTakenP = bytesTaken; }
static void processCall(const registry *const registryP, packetPtr const &callPacketP, callInfo *const callInfoP, packetPtr *const responsePacketPP) { string const callXml(reinterpret_cast<char *>(callPacketP->getBytes()), callPacketP->getLength()); string responseXml; registryP->processCall(callXml, callInfoP, &responseXml); *responsePacketPP = packetPtr(new packet(responseXml.c_str(), responseXml.length())); }