本文整理汇总了C++中Tlv类的典型用法代码示例。如果您正苦于以下问题:C++ Tlv类的具体用法?C++ Tlv怎么用?C++ Tlv使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tlv类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
ThreadError Tlv::GetOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset)
{
ThreadError error = kThreadError_Parse;
uint16_t offset = aMessage.GetOffset();
uint16_t end = aMessage.GetLength();
Tlv tlv;
while (offset < end)
{
aMessage.Read(offset, sizeof(Tlv), &tlv);
// skip extended TLV
if (tlv.GetLength() == kExtendedLength)
{
uint16_t length = 0;
offset += sizeof(tlv);
aMessage.Read(offset, sizeof(length), &length);
offset += sizeof(length) + HostSwap16(length);
}
else if (tlv.GetType() == aType && (offset + sizeof(tlv) + tlv.GetLength()) <= end)
{
aOffset = offset;
ExitNow(error = kThreadError_None);
}
else
{
offset += sizeof(tlv) + tlv.GetLength();
}
}
exit:
return error;
}
示例2: VerifyOrExit
void Dataset::Remove(Tlv::Type aType)
{
Tlv *tlv;
VerifyOrExit((tlv = Get(aType)) != NULL);
Remove(reinterpret_cast<uint8_t *>(tlv), sizeof(Tlv) + tlv->GetLength());
exit:
return;
}
示例3: convert
QString ICQClient::convert(const char *text, unsigned size, TlvList &tlvs, unsigned n)
{
string charset = "us-ascii";
Tlv *tlvCharset = NULL;
for (unsigned i = 0;; i++){
Tlv *tlv = tlvs[i];
if (tlv == NULL)
break;
if (tlv->Num() != n)
continue;
if (tlvCharset && (tlv->Size() < tlvCharset->Size()))
continue;
tlvCharset = tlv;
}
if (tlvCharset){
const char *type = *tlvCharset;
const char *p = strchr(type, '\"');
if (p){
p++;
char *e = strchr((char*)p, '\"');
if (e)
*e = 0;
charset = p;
}else{
charset = type;
}
}
QString res;
if (strstr(charset.c_str(), "us-ascii") || strstr(charset.c_str(), "utf")){
res = QString::fromUtf8(text, size);
}else if (strstr(charset.c_str(), "unicode")){
unsigned short *p = (unsigned short*)text;
for (unsigned i = 0; i < size - 1; i += 2, p++)
res += QChar((unsigned short)htons(*p));
}else{
QTextCodec *codec = QTextCodec::codecForName(charset.c_str());
if (codec){
res = codec->toUnicode(text, size);
}else{
res = QString::fromUtf8(text, size);
log(L_WARN, "Unknown encoding %s", charset.c_str());
}
}
return res;
}
示例4: sizeof
otError Dataset::Set(const Tlv &aTlv)
{
otError error = OT_ERROR_NONE;
uint16_t bytesAvailable = sizeof(mTlvs) - mLength;
Tlv * old = Get(aTlv.GetType());
if (old != NULL)
{
bytesAvailable += sizeof(Tlv) + old->GetLength();
}
VerifyOrExit(sizeof(Tlv) + aTlv.GetLength() <= bytesAvailable, error = OT_ERROR_NO_BUFS);
// remove old TLV
if (old != NULL)
{
Remove(reinterpret_cast<uint8_t *>(old), sizeof(Tlv) + old->GetLength());
}
// add new TLV
memcpy(mTlvs + mLength, &aTlv, sizeof(Tlv) + aTlv.GetLength());
mLength += sizeof(Tlv) + aTlv.GetLength();
mUpdateTime = TimerMilli::GetNow();
exit:
return error;
}
示例5: SuccessOrExit
otError Tlv::Get(const Message &aMessage, uint8_t aType, uint16_t aMaxLength, Tlv &aTlv)
{
otError error = OT_ERROR_NOT_FOUND;
uint16_t offset;
SuccessOrExit(error = GetOffset(aMessage, aType, offset));
aMessage.Read(offset, sizeof(Tlv), &aTlv);
if (aMaxLength > sizeof(aTlv) + aTlv.GetLength())
{
aMaxLength = sizeof(aTlv) + aTlv.GetLength();
}
aMessage.Read(offset, aMaxLength, &aTlv);
exit:
return error;
}
示例6: SuccessOrExit
ThreadError Tlv::GetTlv(const Message &aMessage, Type aType, uint16_t aMaxLength, Tlv &aTlv)
{
ThreadError error = kThreadError_Parse;
uint16_t offset;
SuccessOrExit(error = GetOffset(aMessage, aType, offset));
aMessage.Read(offset, sizeof(Tlv), &aTlv);
if (aMaxLength > sizeof(aTlv) + aTlv.GetLength())
{
aMaxLength = sizeof(aTlv) + aTlv.GetLength();
}
aMessage.Read(offset, aMaxLength, &aTlv);
exit:
return error;
}
示例7: while
Tlv *Dataset::Get(Tlv::Type aType)
{
Tlv *cur = reinterpret_cast<Tlv *>(mTlvs);
Tlv *end = reinterpret_cast<Tlv *>(mTlvs + mLength);
Tlv *rval = NULL;
while (cur < end)
{
if (cur->GetType() == aType)
{
ExitNow(rval = cur);
}
cur = cur->GetNext();
}
exit:
return rval;
}
示例8: GetOffset
otError Tlv::GetOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset)
{
otError error = OT_ERROR_NOT_FOUND;
uint16_t offset = aMessage.GetOffset();
uint16_t end = aMessage.GetLength();
Tlv tlv;
while (offset + sizeof(tlv) <= end)
{
uint32_t length = sizeof(tlv);
aMessage.Read(offset, sizeof(tlv), &tlv);
if (tlv.GetLength() != kExtendedLength)
{
length += tlv.GetLength();
}
else
{
uint16_t extLength;
VerifyOrExit(sizeof(extLength) == aMessage.Read(offset + sizeof(tlv), sizeof(extLength), &extLength));
length += sizeof(extLength) + HostSwap16(extLength);
}
VerifyOrExit(offset + length <= end);
if (tlv.GetType() == aType)
{
aOffset = offset;
ExitNow(error = OT_ERROR_NONE);
}
offset += static_cast<uint16_t>(length);
}
exit:
return error;
}
示例9: GetValueOffset
otError Tlv::GetValueOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset, uint16_t &aLength)
{
otError error = OT_ERROR_NOT_FOUND;
uint16_t offset = aMessage.GetOffset();
uint16_t end = aMessage.GetLength();
Tlv tlv;
while (offset + sizeof(tlv) <= end)
{
uint16_t length;
aMessage.Read(offset, sizeof(tlv), &tlv);
offset += sizeof(tlv);
length = tlv.GetLength();
if (length == kExtendedLength)
{
VerifyOrExit(offset + sizeof(length) <= end);
aMessage.Read(offset, sizeof(length), &length);
offset += sizeof(length);
length = HostSwap16(length);
}
VerifyOrExit(length <= end - offset);
if (tlv.GetType() == aType)
{
aOffset = offset;
aLength = length;
ExitNow(error = OT_ERROR_NONE);
}
offset += length;
}
exit:
return error;
}
示例10: while
void DatasetManager::Get(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
Tlv tlv;
uint16_t offset = aMessage.GetOffset();
uint8_t tlvs[Dataset::kMaxSize];
uint8_t length = 0;
while (offset < aMessage.GetLength())
{
aMessage.Read(offset, sizeof(tlv), &tlv);
if (tlv.GetType() == Tlv::kGet)
{
length = tlv.GetLength();
aMessage.Read(offset + sizeof(Tlv), length, tlvs);
break;
}
offset += sizeof(tlv) + tlv.GetLength();
}
SendGetResponse(aHeader, aMessageInfo, tlvs, length);
}
示例11: while
ThreadError Tlv::GetOffset(const Message &aMessage, Type aType, uint16_t &aOffset)
{
ThreadError error = kThreadError_Parse;
uint16_t offset = aMessage.GetOffset();
uint16_t end = aMessage.GetLength();
Tlv tlv;
while (offset < end)
{
aMessage.Read(offset, sizeof(Tlv), &tlv);
if (tlv.GetType() == aType && (offset + sizeof(tlv) + tlv.GetLength()) <= end)
{
aOffset = offset;
ExitNow(error = kThreadError_None);
}
offset += sizeof(tlv) + tlv.GetLength();
}
exit:
return error;
}
示例12: switch
bool Tlv::IsValid(const Tlv &aTlv)
{
bool rval = true;
switch (aTlv.GetType())
{
case Tlv::kChannel:
rval = static_cast<const ChannelTlv &>(aTlv).IsValid();
break;
case Tlv::kPanId:
rval = static_cast<const PanIdTlv &>(aTlv).IsValid();
break;
case Tlv::kExtendedPanId:
rval = static_cast<const ExtendedPanIdTlv &>(aTlv).IsValid();
break;
case Tlv::kNetworkName:
rval = static_cast<const NetworkNameTlv &>(aTlv).IsValid();
break;
case Tlv::kNetworkMasterKey:
rval = static_cast<const NetworkMasterKeyTlv &>(aTlv).IsValid();
break;
case Tlv::kPSKc:
rval = static_cast<const PSKcTlv &>(aTlv).IsValid();
break;
case Tlv::kMeshLocalPrefix:
rval = static_cast<const MeshLocalPrefixTlv &>(aTlv).IsValid();
break;
case Tlv::kSecurityPolicy:
rval = static_cast<const SecurityPolicyTlv &>(aTlv).IsValid();
break;
default:
break;
}
return rval;
}
示例13: handle_meta_info
void MetaInfoManager::handle_meta_info(SnacBuffer& snac)
{
Tlv metaReply = Tlv::fromBuffer(snac);
metaReply.seekForward( sizeof(Word) ); // data chunk size = tlv_length - 2
metaReply.seekForward( sizeof(DWord) ); // requester uin
Word type = metaReply.getLEWord(); // meta request type
metaReply.seekForward( sizeof(Word) ); // meta request id
Buffer data = metaReply.readAll();
emit metaInfoAvailable(type, data);
}
示例14: switch
void ICQClient::snac_login(unsigned short type, unsigned short)
{
unsigned long newUin;
switch (type){
case ICQ_SNACxLOGIN_ERROR:
if (data.owner.Uin.value){
m_reconnect = NO_RECONNECT;
m_socket->error_state(I18N_NOOP("Login error"), AuthError);
break;
}
// in the process of registering;
// it seems that we need to request bot protection picture;
// reconnecting to send the request.
log(L_DEBUG, "Verification required, reconnecting");
m_bVerifying = true;
m_socket->close();
m_socket->connect(getServer(), getPort(), this);
break;
case ICQ_SNACxLOGIN_REGISTER:
if (data.owner.Uin.value){
m_socket->error_state(I18N_NOOP("Registered in no register state"));
break;
}
m_socket->readBuffer.incReadPos(0x2E);
m_socket->readBuffer.unpack(newUin);
log(L_DEBUG, "Register %lu %08lX", newUin, newUin);
setUin(newUin);
setState(Connecting);
m_socket->connect(getServer(), getPort(), this);
break;
case ICQ_SNACxLOGIN_AUTHxKEYxRESPONSE:
log(L_DEBUG, "Sending MD5 key");
if (data.owner.Screen.ptr || data.owner.Uin.value){
string md5_key;
m_socket->readBuffer.unpackStr(md5_key);
snac(ICQ_SNACxFAM_LOGIN, ICQ_SNACxLOGIN_MD5xLOGIN, false, false);
if (data.owner.Uin.value){
char uin[20];
sprintf(uin, "%lu", data.owner.Uin.value);
m_socket->writeBuffer.tlv(0x0001, uin);
}else{
m_socket->writeBuffer.tlv(0x0001, data.owner.Screen.ptr);
}
string md = md5_key;
md += getContacts()->fromUnicode(NULL, getPassword());
md += "AOL Instant Messenger (SM)";
md = md5(md.c_str());
m_socket->writeBuffer.tlv(0x0025, md.c_str(), md.length());
if (data.owner.Uin.value){
m_socket->writeBuffer.tlv(0x0003, "ICQ Inc. - Product of ICQ (TM).2003b.5.56.1.3916.85");
m_socket->writeBuffer.tlv(0x0016, 0x010A);
m_socket->writeBuffer.tlv(0x0017, 0x0002);
m_socket->writeBuffer.tlv(0x0018, 0x0038);
m_socket->writeBuffer.tlv(0x0019, 0x0001);
m_socket->writeBuffer.tlv(0x001A, 0x0F4C);
m_socket->writeBuffer.tlv(0x0014, 0x00000055L);
m_socket->writeBuffer.tlv(0x000f, "en");
m_socket->writeBuffer.tlv(0x000e, "us");
}else{
m_socket->writeBuffer.tlv(0x0003, "AOL Instant Messenger, version 5.1.3036/WIN32");
m_socket->writeBuffer.tlv(0x0016, (unsigned short)0x0109);
m_socket->writeBuffer.tlv(0x0017, (unsigned short)0x0005);
m_socket->writeBuffer.tlv(0x0018, (unsigned short)0x0001);
m_socket->writeBuffer.tlv(0x0019, (unsigned short)0x0000);
m_socket->writeBuffer.tlv(0x001A, (unsigned short)0x0BDC);
m_socket->writeBuffer.tlv(0x0014, 0x000000D2L);
m_socket->writeBuffer.tlv(0x000F, "en");
m_socket->writeBuffer.tlv(0x000E, "us");
m_socket->writeBuffer.tlv(0x004A, "\x01");
}
sendPacket(true);
}
break;
case ICQ_SNACxLOGIN_LOGINxREPLY:
chn_close();
break;
case ICQ_SNACxLOGIN_REGISTERxSEND_IMG: {
m_bVerifying = false;
TlvList tlv(m_socket->readBuffer);
// currently there are 2 TLVs in SNAC(17,0D):
// type = 1: the value contains the mime type of the image (image/jpeg); ignored
// type = 2: the value contains the image itself in the binary form
Tlv* tlvImage = tlv(2);
if (!tlvImage)
break;
log(L_DEBUG, "Image length: %d bytes", tlvImage->Size());
uchar* buf = new uchar[tlvImage->Size()];
memcpy(buf, *tlvImage, tlvImage->Size());
QPixmap pict;
if (!pict.loadFromData(buf, tlvImage->Size()))
{
delete[] buf;
break;
}
delete[] buf;
log(L_DEBUG, "Received verification image");
VerifyDlg verdlg(qApp->activeWindow(), pict);
if (verdlg.exec() == QDialog::Accepted) // what to do if the user has cancelled the dialog?
{
QString verifyStr = verdlg.getVerifyString();
//.........这里部分代码省略.........
示例15: VerifyOrExit
ThreadError DatasetManager::Set(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
Tlv tlv;
Timestamp *timestamp;
uint16_t offset = aMessage.GetOffset();
Tlv::Type type;
bool isUpdateFromCommissioner = false;
bool doesAffectConnectivity = false;
StateTlv::State state = StateTlv::kAccept;
ActiveTimestampTlv activeTimestamp;
PendingTimestampTlv pendingTimestamp;
ChannelTlv channel;
CommissionerSessionIdTlv sessionId;
MeshLocalPrefixTlv meshLocalPrefix;
NetworkMasterKeyTlv masterKey;
PanIdTlv panId;
activeTimestamp.SetLength(0);
pendingTimestamp.SetLength(0);
channel.SetLength(0);
masterKey.SetLength(0);
meshLocalPrefix.SetLength(0);
panId.SetLength(0);
pendingTimestamp.SetLength(0);
sessionId.SetLength(0);
VerifyOrExit(mNetif.GetMle().GetDeviceState() == Mle::kDeviceStateLeader, state = StateTlv::kReject);
// verify that TLV data size is less than maximum TLV value size
while (offset < aMessage.GetLength())
{
aMessage.Read(offset, sizeof(tlv), &tlv);
VerifyOrExit(tlv.GetLength() <= Dataset::kMaxValueSize, state = StateTlv::kReject);
offset += sizeof(tlv) + tlv.GetLength();
}
// verify that does not overflow dataset buffer
VerifyOrExit((offset - aMessage.GetOffset()) <= Dataset::kMaxSize, state = StateTlv::kReject);
type = (strcmp(mUriSet, OPENTHREAD_URI_ACTIVE_SET) == 0 ? Tlv::kActiveTimestamp : Tlv::kPendingTimestamp);
if (Tlv::GetTlv(aMessage, Tlv::kActiveTimestamp, sizeof(activeTimestamp), activeTimestamp) != kThreadError_None)
{
ExitNow(state = StateTlv::kReject);
}
VerifyOrExit(activeTimestamp.IsValid(), state = StateTlv::kReject);
if (Tlv::GetTlv(aMessage, Tlv::kPendingTimestamp, sizeof(pendingTimestamp), pendingTimestamp) == kThreadError_None)
{
VerifyOrExit(pendingTimestamp.IsValid(), state = StateTlv::kReject);
}
// verify the request includes a timestamp that is ahead of the locally stored value
timestamp = (type == Tlv::kActiveTimestamp) ?
static_cast<Timestamp *>(&activeTimestamp) :
static_cast<Timestamp *>(&pendingTimestamp);
VerifyOrExit(mLocal.GetTimestamp() == NULL || mLocal.GetTimestamp()->Compare(*timestamp) > 0,
state = StateTlv::kReject);
// check channel
if (Tlv::GetTlv(aMessage, Tlv::kChannel, sizeof(channel), channel) == kThreadError_None)
{
VerifyOrExit(channel.IsValid() &&
channel.GetChannel() >= kPhyMinChannel &&
channel.GetChannel() <= kPhyMaxChannel,
state = StateTlv::kReject);
if (type == Tlv::kActiveTimestamp && channel.GetChannel() != mNetif.GetMac().GetChannel())
{
doesAffectConnectivity = true;
}
}
// check PAN ID
if (Tlv::GetTlv(aMessage, Tlv::kPanId, sizeof(panId), panId) == kThreadError_None &&
type == Tlv::kActiveTimestamp &&
panId.IsValid() &&
panId.GetPanId() != mNetif.GetMac().GetPanId())
{
doesAffectConnectivity = true;
}
// check mesh local prefix
if (Tlv::GetTlv(aMessage, Tlv::kMeshLocalPrefix, sizeof(meshLocalPrefix), meshLocalPrefix) == kThreadError_None &&
type == Tlv::kActiveTimestamp &&
memcmp(meshLocalPrefix.GetMeshLocalPrefix(), mNetif.GetMle().GetMeshLocalPrefix(),
meshLocalPrefix.GetLength()))
{
doesAffectConnectivity = true;
}
// check network master key
if (Tlv::GetTlv(aMessage, Tlv::kNetworkMasterKey, sizeof(masterKey), masterKey) == kThreadError_None &&
type == Tlv::kActiveTimestamp &&
memcmp(masterKey.GetNetworkMasterKey(), mNetif.GetKeyManager().GetMasterKey(NULL),
masterKey.GetLength()))
{
//.........这里部分代码省略.........