TInt Log::PrintHex(FunctorMsg& aOutput, const Brx& aBrx) { Bws<kMaxPrintBytes+1> buf(kMaxPrintBytes+1); TUint split = aBrx.Bytes()/128; for(TUint k=0; k<split; k++) { TUint i=0; TUint j=0; for(i=0; i<128; i++) { buf[j++] = hexChar( (aBrx[i+(k*128)]&0xF0)>>4 ); buf[j++] = hexChar( (aBrx[i+(k*128)]&0x0F) ); } buf.SetBytes(j); buf.PtrZ(); DoPrint(aOutput, buf.Ptr()); } TUint rem = aBrx.Bytes()%128; buf.SetBytes(rem*2); TUint i=0; TUint j=0; for(i=0; i<(rem); i++) { buf[j++] = hexChar( (aBrx[i+(split*128)]&0xF0)>>4 ); buf[j++] = hexChar( (aBrx[i+(split*128)]&0x0F) ); } buf.PtrZ(); return DoPrint(aOutput, buf.Ptr()); }
TUint HeaderAcceptLanguage::ParseQualityValue(const Brx& aBuf) { if (aBuf.Bytes() == 0) { return kMaxQuality; } if (aBuf[0] == '1') { return kMaxQuality; } else if (aBuf[0] != '0') { // invalid value, ignore it return kMinQuality; } if (aBuf.Bytes() < 3 || aBuf[1] != '.' || aBuf.Bytes() > kMaxQualityChars) { // invalid value, ignore it return kMinQuality; } TUint quality = kMinQuality; TUint i; for (i=2; i<aBuf.Bytes(); i++) { if (!Ascii::IsDigit(aBuf[i])) { return 0; } quality = (quality * 10) + aBuf[i] - '0'; } for (; i<kMaxQualityChars; i++) { quality *= 10; } return quality; }
void DriverAlsa::Pimpl::Write(const Brx& aData) { int err; err = snd_pcm_writei(iHandle, aData.Ptr(), aData.Bytes() / iSampleBytes); // Handle underrun errors. if(err == -EPIPE) { err = snd_pcm_prepare(iHandle); if (err < 0) { Log::Print("DriverAlsa: failed to snd_pcm_recover with %s\n", snd_strerror(err)); ASSERTS(); } err = snd_pcm_writei(iHandle, aData.Ptr(), aData.Bytes() / iSampleBytes); } if (err < 0) { Log::Print("DriverAlsa: snd_pcm_writei() got error %s\n", snd_strerror(err)); } else { iBytesSent += aData.Bytes(); } }
void OutputProcessorDv::ProcessBinary(const Brx& aBuffer, Brh& aVal) { Bwh tmp(aBuffer.Bytes()); if (aBuffer.Bytes() > 0) { tmp.Append(aBuffer); } tmp.TransferTo(aVal); }
void DviProtocolUpnpServiceXmlWriter::GetRelatedVariableName(Bwh& aName, const Brx& aActionName, const Brx& aParameterName) { static const Brn prefix("A_ARG_TYPE_"); const TUint len = prefix.Bytes() + aActionName.Bytes() + 1 + aParameterName.Bytes(); aName.Grow(len); aName.Append(prefix); aName.Append(aActionName); aName.Append('_'); aName.Append(aParameterName); }
TBool Brx::BeginsWith(const Brx& aBrx) const { if(Bytes() >= aBrx.Bytes()) { const TByte* ptr1 = Ptr(); ASSERT(ptr1 != NULL); const TByte* ptr2 = aBrx.Ptr(); ASSERT(ptr2 != NULL); return(memcmp(ptr1, ptr2, aBrx.Bytes()) == 0); } return false; }
TBool Ascii::CaseInsensitiveEquals(const Brx& aBuffer1, const Brx& aBuffer2) { TUint bytes = aBuffer1.Bytes(); if(aBuffer2.Bytes() != bytes) { return (false); } for (TUint i = 0; i < bytes; i++) { if (!CaseInsensitiveEquals(aBuffer1[i], aBuffer2[i])) { return (false); } } return (true); }
void ProviderTestBasic::WriteFile(IDvInvocation& aInvocation, const Brx& aData, const Brx& aFileFullName) { TUint len = aFileFullName.Bytes(); char* name = (char*)malloc(len+1); (void)memcpy(name, aFileFullName.Ptr(), aFileFullName.Bytes()); name[len] = 0; FILE* fp = fopen(name, "wb"); free(name); (void)fwrite(aData.Ptr(), aData.Bytes(), 1, fp); (void)fflush(fp); (void)fclose(fp); aInvocation.StartResponse(); aInvocation.EndResponse(); }
void Bwx::ReplaceThrow(const Brx& aBuf) { if (aBuf.Bytes() > MaxBytes()) { THROW(BufferOverflow); } else { const TByte* dest = Ptr(); ASSERT(dest != NULL); const TByte* src = aBuf.Ptr(); ASSERT(src != NULL); (void)memmove(const_cast<TByte*>(dest), src, aBuf.Bytes()); iBytes = aBuf.Bytes(); } }
TBool BufferCmp::operator()(const Brx& aStr1, const Brx& aStr2) const { const TInt bytes1 = aStr1.Bytes(); const TInt bytes2 = aStr2.Bytes(); const TInt bytes = (bytes1<bytes2? bytes1 : bytes2); const TByte* ptr1 = aStr1.Ptr(); const TByte* ptr2 = aStr2.Ptr(); for (TInt i=0; i<bytes; i++) { if (*ptr1 != *ptr2) { return (*ptr1 < *ptr2); } ptr1++; ptr2++; } return (bytes1 < bytes2); }
void WriterShellResponse::Write(const Brx& aBuffer) { const TUint bytes = aBuffer.Bytes(); for (TUint i=0; i<bytes; i++) { Write(aBuffer[i]); } WriteFlush(); }
void OutputProcessorDv::ProcessString(const Brx& aBuffer, Brhz& aVal) { TUint bytes = aBuffer.Bytes(); Bwh tmp(bytes + 1); tmp.Append(aBuffer); tmp.Append((TByte)0); tmp.SetBytes(bytes); tmp.TransferTo(aVal); }
Brn WriterRingBuffer::Tail(const Brx& aBuffer, TUint aMaxBytes) { const TUint bytes = aBuffer.Bytes(); if (bytes <= aMaxBytes) return Brn(aBuffer); else return aBuffer.Split(bytes - aMaxBytes, aMaxBytes); }
void DeviceBasic::WriteResource(const Brx& aUriTail, TIpAddress /*aInterface*/, std::vector<char*>& /*aLanguageList*/, IResourceWriter& aResourceWriter) { const Brn kIndexFile("index.html"); Bwh filePath(iConfigDir); Brn file; if (aUriTail.Bytes() == 0) { file.Set(kIndexFile); } else { file.Set(aUriTail); } const TByte sep = #ifdef _WIN32 '\\'; #else '/'; #endif filePath.Grow(filePath.Bytes() + 1 + file.Bytes()+1); filePath.Append(sep); filePath.Append(file); filePath.PtrZ(); const char* path = (const char*)filePath.Ptr(); FILE* fd = fopen(path, "rb"); if (fd == NULL) { return; } static const TUint kMaxReadSize = 4096; struct stat fileStats; (void)stat(path, &fileStats); TUint bytes = (TUint)fileStats.st_size; const char* mime = NULL; for (TUint i=filePath.Bytes()-1; i>0; i--) { if (filePath[i] == '/' || filePath[i] == '\\') { break; } if (filePath[i] == '.') { const char* ext = (const char*)filePath.Split(i+1, filePath.Bytes()-i-1).Ptr(); if (strcmp(ext, "html") == 0 || strcmp(ext, "htm") == 0) { mime = kOhNetMimeTypeHtml; } break; } } aResourceWriter.WriteResourceBegin(bytes, mime); do { TByte buf[kMaxReadSize]; TUint size = (bytes<kMaxReadSize? bytes : kMaxReadSize); size_t records_read = fread(buf, size, 1, fd); ASSERT(records_read == 1); aResourceWriter.WriteResource(buf, size); bytes -= size; } while (bytes > 0); aResourceWriter.WriteResourceEnd(); (void)fclose(fd); }
void CpTopology2Group::UpdateName(const Brx& aValue) { if (aValue.Bytes() > iName.MaxBytes()) { iName.Replace(aValue.Ptr(), iName.MaxBytes()); } else { iName.Replace(aValue); } }
void CpTopology2Group::UpdateRoom(const Brx& aValue) { if (aValue.Bytes() > iRoom.MaxBytes()) { iRoom.Replace(aValue.Ptr(), iRoom.MaxBytes()); } else { iRoom.Replace(aValue); } }
TBool Brx::Equals(const Brx& aBrx) const { if(Bytes() == aBrx.Bytes()) { const TByte* dest = Ptr(); ASSERT(dest != NULL); const TByte* src = aBrx.Ptr(); ASSERT(src != NULL); return(memcmp(dest, src, Bytes()) == 0); } return false; }
void WriterBwh::Write(const Brx& aBuffer) { TInt maxBytes = iBuf.MaxBytes(); TInt reqMaxBytes = iBuf.Bytes() + aBuffer.Bytes(); if (reqMaxBytes > maxBytes) { do { maxBytes += iGranularity; } while (reqMaxBytes > maxBytes); iBuf.Grow(maxBytes); } iBuf.Append(aBuffer); }
void FileAnsii::Write(const Brx& aBuffer, TUint32 aBytes) { // IFile implementations must check write length ASSERT(aBytes); // Check we have enough bytes ASSERT(aBuffer.Bytes() >= aBytes); // Do the write TUint bytesWritten = (TUint)fwrite(aBuffer.Ptr(), 1, aBytes, iFilePtr); // throw if entire write was not performed if ( bytesWritten != aBytes ) THROW(FileWriteError); }
ArgumentBinary::ArgumentBinary(const OpenHome::Net::Parameter& aParameter, const Brx& aValue) : Argument(aParameter) { try { aParameter.ValidateBinary(aValue); if (aValue.Bytes() > 0) { iValue.Set(aValue); } } catch (ParameterValidationError&) { ValidationFailed(aParameter); } }
void PcmProcessorLe32::ProcessFragment24(const Brx& aData, TUint aNumChannels) { TByte *nData; TUint bytes; // 24 bit audio is not supported on the platform so it is converted // to signed 32 bit audio for playback. // // Accordingly we allocate room for 4 byte samples. bytes = (aData.Bytes() * 4) / 3; // If we are manually converting mono to stereo the data will double. if (iDuplicateChannel) { bytes *= 2; } nData = new TByte[bytes]; ASSERT(nData != NULL); TByte *ptr = (TByte *)(aData.Ptr() + 0); TByte *ptr1 = (TByte *)nData; TByte *endp = ptr1 + bytes; ASSERT(bytes % 2 == 0); while (ptr1 < endp) { // Store the data in little endian format. *ptr1++ = 0; *ptr1++ = *(ptr+2); *ptr1++ = *(ptr+1); *ptr1++ = *(ptr+0); if (iDuplicateChannel) { *ptr1++ = 0; *ptr1++ = *(ptr+2); *ptr1++ = *(ptr+1); *ptr1++ = *(ptr+0); } ptr += 3; } Brn fragment(nData, bytes); Flush(); iSink.Write(fragment); delete[] nData; }
void WriterHttpChunked::Write(const Brx& aBuffer) { if (iChunked) { Bws<16> count; Ascii::AppendHex(count, aBuffer.Bytes()); iBuffer.Write(count); iBuffer.Write(Http::kHeaderTerminator); iBuffer.Write(aBuffer); iBuffer.Write(Http::kHeaderTerminator); } else { iBuffer.Write(aBuffer); } }
void DviProtocolUpnpAdapterSpecificData::BonjourRegister(const TChar* aName, const Brx& aUdn, const Brx& aProtocol, const Brx& aResourceDir) { if (aName != NULL) { if (iBonjourWebPage == 0) { IMdnsProvider* mdnsProvider = iDvStack.MdnsProvider(); if (mdnsProvider != NULL) { iBonjourWebPage = new BonjourWebPage(*mdnsProvider); } } if (iBonjourWebPage != NULL) { Bwh path(aUdn.Bytes() + aProtocol.Bytes() + aResourceDir.Bytes() + 5); path.Append('/'); path.Append(aUdn); path.Append('/'); path.Append(aProtocol); path.Append('/'); path.Append(aResourceDir); path.Append('/'); path.PtrZ(); iBonjourWebPage->SetEnabled(aName, iAdapter, iServerPort, (const TChar*)path.Ptr()); } } }
void CpTopology2Source::Update(const Brx& aName, const Brx& aType, TBool aVisible) { if (aName.Bytes() > iName.MaxBytes()) { iName.Replace(aName.Ptr(), iName.MaxBytes()); } else { iName.Replace(aName); } iType.Replace(aType); iVisible = aVisible; }
TUint32 OpenHome::Os::NetworkGetHostByName(const Brx& aAddress) { TUint32 addr; const TInt len = aAddress.Bytes(); char* name = new char[len+1]; (void)memcpy(name, aAddress.Ptr(), len); name[len] = '\0'; int32_t ret = OsNetworkGetHostByName(name, &addr); delete[] name; if (ret == -1) { THROW(NetworkError); } return addr; }
void OhmSenderDriverWindows::Resend(const Brx& aFrames) { KSPROPERTY prop; prop.Set = OHSOUNDCARD_GUID; prop.Id = KSPROPERTY_OHSOUNDCARD_RESEND; prop.Flags = KSPROPERTY_TYPE_SET; DWORD returned; LPVOID ptr = (LPVOID) aFrames.Ptr(); DWORD bytes = aFrames.Bytes(); DeviceIoControl(iHandle, IOCTL_KS_PROPERTY, &prop, sizeof(KSPROPERTY), ptr, bytes, &returned, 0); }
void HttpHeaderHost::Process(const Brx& aValue) { OpenHome::Endpoint defaultEndpoint; iEndpoint = defaultEndpoint; iHost.Set(aValue); SetReceived(); try { TUint index = Ascii::IndexOf(aValue, ':'); Brn address(aValue); TUint port = 0; if (index != aValue.Bytes()) { address.Set(address.Ptr(), index); Brn portBuf = aValue.Split(index+1, aValue.Bytes()-index-1); port = Ascii::Uint(portBuf); } iEndpoint = OpenHome::Endpoint(port, address); } catch(AsciiError&) { THROW(HttpError); } catch(NetworkError&) { THROW(HttpError); } }
const Brn CommandTokens::GetNextToken(const Brx& aValue, TUint& aIndex) { const TByte* start = aValue.Ptr() + aIndex; TUint bytes = aValue.Bytes(); ASSERT(aIndex <= bytes) for (;;) { if (aIndex == bytes) { return (Brn(start, 0)); } if (*start != ' ') { break; } aIndex++; start++; } const TByte* ptr = start; aIndex++; ptr++; TUint count = 1; for (;;) { if (aIndex == bytes) { break; } if (*ptr == ' ') { break; } aIndex++; ptr++; count++; } return (Brn(start, count)); }
TInt Log::Print(FunctorMsg& aOutput, const Brx& aMessage) { TUint remaining = aMessage.Bytes(); TInt ret = 0; const TByte* ptr = aMessage.Ptr(); while (remaining > 0) { TInt len = (remaining<kMaxPrintBytes? remaining : kMaxPrintBytes); remaining -= len; TChar temp[kMaxPrintBytes+1]; Bwn msg(temp, len, kMaxPrintBytes+1); msg.Replace(ptr, len); msg.PtrZ(); ret += DoPrint(aOutput, msg.Ptr()); ptr += len; } return ret; }
void PcmProcessorLe::ProcessFragment8(const Brx& aData, TUint aNumChannels) { TByte *nData; TUint bytes; // The input data is converted from unsigned 8 bit to signed 16 bit. // to removes poor audio quality and glitches when part of a playlist // with tracks of a different bit depth. // // Accordingly the amount of data is doubled. bytes = aData.Bytes() * 2; // If we are manually converting mono to stereo the data will double. if (iDuplicateChannel) { bytes *= 2; } nData = new TByte[bytes]; ASSERT(nData != NULL); TByte *ptr = (TByte *)(aData.Ptr() + 0); TByte *ptr1 = (TByte *)nData; TByte *endp = ptr1 + bytes; while (ptr1 < endp) { // Convert U8 to S16 data in little endian format. *ptr1++ = 0x00; *ptr1++ = *ptr - 0x80; if (iDuplicateChannel) { *ptr1++ = 0x00; *ptr1++ = *ptr - 0x80; } ptr++; } Brn fragment(nData, bytes); Flush(); iSink.Write(fragment); delete[] nData; }