void BOSHConnection::write(const SafeByteArray& data, bool streamRestart, bool terminate) { assert(connectionReady_); assert(!sid_.empty()); SafeByteArray safeHeader = createHTTPRequest(data, streamRestart, terminate, rid_, sid_, boshURL_).first; onBOSHDataWritten(safeHeader); writeData(safeHeader); pending_ = true; SWIFT_LOG(debug) << "write data: " << safeByteArrayToString(safeHeader) << std::endl; }
int BinHTTPInputStreamCommon::sendRequest(const XMLURL &url, const XMLNetHTTPInfo *httpInfo) { // // Constants in ASCII to send/check in the HTTP request/response // static const char *CRLF2X = "\r\n\r\n"; static const char *LF2X = "\n\n"; // The port is open and ready to go. // Build up the http GET command to send to the server. CharBuffer requestBuffer(1023, fMemoryManager); createHTTPRequest(url, httpInfo, requestBuffer); // Send the http request if(!send(requestBuffer.getRawBuffer(), requestBuffer.getLen())) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_WriteSocket, url.getURLText(), fMemoryManager); } if(httpInfo && httpInfo->fPayload) { if(!send(httpInfo->fPayload, httpInfo->fPayloadLen)) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_WriteSocket, url.getURLText(), fMemoryManager); } } // // get the response, check the http header for errors from the server. // char tmpBuf[1024]; int ret; fBuffer.reset(); while(true) { ret = receive(tmpBuf, sizeof(tmpBuf)); if(ret == -1) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, url.getURLText(), fMemoryManager); } fBuffer.append(tmpBuf, ret); fBufferPos = strstr(fBuffer.getRawBuffer(), CRLF2X); if(fBufferPos != 0) { fBufferPos += 4; *(fBufferPos - 2) = 0; break; } fBufferPos = strstr(fBuffer.getRawBuffer(), LF2X); if(fBufferPos != 0) { fBufferPos += 2; *(fBufferPos - 1) = 0; break; } } // Parse the response status char *p = strstr(fBuffer.getRawBuffer(), "HTTP"); if(p == 0) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, url.getURLText(), fMemoryManager); } p = strchr(p, chSpace); if(p == 0) { ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, url.getURLText(), fMemoryManager); } return atoi(p); }