void InvocationUpnp::WriteRequest(const Uri& aUri) { Sws<1024> writeBuffer(iSocket); WriterHttpRequest writerRequest(writeBuffer); Bwh body; try { Endpoint endpoint(aUri.Port(), aUri.Host()); TUint timeout = iCpStack.Env().InitParams()->TcpConnectTimeoutMs(); iSocket.Connect(endpoint, timeout); } catch (NetworkTimeout&) { iInvocation.SetError(Error::eSocket, Error::eCodeTimeout, Error::kDescriptionSocketTimeout); THROW(NetworkTimeout); } try { InvocationBodyWriter::Write(iInvocation, body); WriteHeaders(writerRequest, aUri, body.Bytes()); writeBuffer.Write(body); writeBuffer.WriteFlush(); } catch (WriterError) { iInvocation.SetError(Error::eHttp, Error::kCodeUnknown, Error::kDescriptionUnknown); THROW(WriterError); } }
static void RandomiseUdn(Bwh& aUdn) { aUdn.Grow(aUdn.Bytes() + 1 + Ascii::kMaxUintStringBytes + 1); aUdn.Append('-'); Bws<Ascii::kMaxUintStringBytes> buf; NetworkInterface* nif = Stack::NetworkInterfaceList().CurrentInterface(); TUint max = nif->Address(); delete nif; (void)Ascii::AppendDec(buf, Random(max)); aUdn.Append(buf); aUdn.PtrZ(); }
void OpenHome::TestFramework::RandomiseUdn(Environment& aEnv, Bwh& aUdn) { aUdn.Grow(aUdn.Bytes() + 1 + Ascii::kMaxUintStringBytes + 1); aUdn.Append('-'); Bws<Ascii::kMaxUintStringBytes> buf; std::vector<NetworkAdapter*>* subnetList = aEnv.NetworkAdapterList().CreateSubnetList(); TUint max = (subnetList->size() > 0? (*subnetList)[0]->Address() : UINT_MAX); aEnv.NetworkAdapterList().DestroySubnetList(subnetList); (void)Ascii::AppendDec(buf, aEnv.Random(max)); aUdn.Append(buf); aUdn.PtrZ(); }
static void RandomiseUdn(Bwh& aUdn) { aUdn.Grow(aUdn.Bytes() + 1 + Ascii::kMaxUintStringBytes + 1); aUdn.Append('-'); Bws<Ascii::kMaxUintStringBytes> buf; std::vector<NetworkAdapter*>* subnetList = Stack::NetworkAdapterList().CreateSubnetList(); TUint max = (*subnetList)[0]->Address(); TUint seed = DviStack::ServerUpnp().Port((*subnetList)[0]->Address()); SetRandomSeed(seed); Stack::NetworkAdapterList().DestroySubnetList(subnetList); (void)Ascii::AppendDec(buf, Random(max)); aUdn.Append(buf); aUdn.PtrZ(); }
static void RandomiseUdn(Bwh& aUdn) { aUdn.Grow(aUdn.Bytes() + 1 + Ascii::kMaxUintStringBytes + 1); aUdn.Append('-'); Bws<Ascii::kMaxUintStringBytes> buf; NetworkAdapter* nif = Stack::NetworkAdapterList().CurrentAdapter(kAdapterCookie); TUint max = nif->Address(); TUint seed = DviStack::ServerUpnp().Port(nif->Address()); SetRandomSeed(seed); nif->RemoveRef(kAdapterCookie); (void)Ascii::AppendDec(buf, Random(max)); aUdn.Append(buf); aUdn.PtrZ(); }
static void RandomiseUdn(std::string& aUdn) { Bwh udn; udn.Grow((TUint)aUdn.length() + 1 + Ascii::kMaxUintStringBytes + 1); Brn buf((const TByte*)aUdn.c_str(), (TUint)aUdn.length()); udn.Append(buf); udn.Append('-'); Bws<Ascii::kMaxUintStringBytes> addr; std::vector<NetworkAdapter*>* subnetList = gEnv->NetworkAdapterList().CreateSubnetList(); TUint max = (*subnetList)[0]->Address(); TUint seed = gDvStack->ServerUpnp().Port((*subnetList)[0]->Address()); SetRandomSeed(seed); gEnv->NetworkAdapterList().DestroySubnetList(subnetList); (void)Ascii::AppendDec(addr, Random(max)); udn.Append(addr); udn.PtrZ(); aUdn.assign((const char*)udn.Ptr(), udn.Bytes()); }
void InvocationUpnp::ReadResponse() { OutputProcessorUpnp outputProcessor; HttpHeaderContentLength headerContentLength; HttpHeaderTransferEncoding headerTransferEncoding; Bwh entity; iReaderResponse.AddHeader(headerContentLength); iReaderResponse.AddHeader(headerTransferEncoding); iReaderResponse.Read(kResponseTimeoutMs); const HttpStatus& status = iReaderResponse.Status(); if (status != HttpStatus::kOk) { LOG2(kService, kError, "InvocationUpnp::ReadResponse, http error %u ", status.Code()); LOG2(kService, kError, status.Reason()); LOG2(kService, kError, "\n"); if (status != HttpStatus::kInternalServerError) { iInvocation.SetError(Error::eHttp, status.Code(), status.Reason()); THROW(HttpError); } } if (headerTransferEncoding.IsChunked()) { ReaderHttpChunked dechunker(iReadBuffer); dechunker.Read(); dechunker.TransferTo(entity); } else { TUint length = headerContentLength.ContentLength(); if (length != 0) { Bwh buf(length); while (length > 0) { TUint readBytes = (length<kMaxReadBytes? length : kMaxReadBytes); buf.Append(iReadBuffer.Read(readBytes)); length -= readBytes; } buf.TransferTo(entity); } else { // no content length - read until connection closed by server try { for (;;) { Brn buf = iReadBuffer.Read(kMaxReadBytes); entity.Grow(entity.Bytes() + kMaxReadBytes); entity.Append(buf); } } catch (ReaderError&) { Brn snaffle = iReadBuffer.Snaffle(); entity.Grow(entity.Bytes() + snaffle.Bytes()); entity.Append(snaffle); } } } if (status == HttpStatus::kInternalServerError) { Brn envelope = XmlParserBasic::Find("Envelope", entity); Brn body = XmlParserBasic::Find("Body", envelope); Brn fault = XmlParserBasic::Find("Fault", body); Brn detail = XmlParserBasic::Find("detail", fault); Brn code = XmlParserBasic::Find("errorCode", detail); Brn description = XmlParserBasic::Find("errorDescription", detail); iInvocation.SetError(Error::eUpnp, Ascii::Uint(code), description); THROW(HttpError); } const Invocation::VectorArguments& outArgs = iInvocation.OutputArguments(); const TUint count = (TUint)outArgs.size(); Brn envelope = XmlParserBasic::Find("Envelope", entity); Brn body = XmlParserBasic::Find("Body", envelope); const Brn responseTagTrailer("Response"); const Brx& actionName = iInvocation.Action().Name(); TUint len = actionName.Bytes() + responseTagTrailer.Bytes(); Bwh responseTag(len); responseTag.Append(actionName); responseTag.Append(responseTagTrailer); Brn response = XmlParserBasic::Find(responseTag, body); for (TUint i=0; i<count; i++) { const Brx& name = outArgs[i]->Parameter().Name(); Brn value = XmlParserBasic::Find(name, response); outArgs[i]->ProcessOutput(outputProcessor, value); } }
Bwh::Bwh(const Bwh& aBuf) : Bwx(aBuf.Bytes(), aBuf.Bytes()) { iPtr = (TByte*)malloc(aBuf.Bytes()); Replace(aBuf); }