• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ Tlv类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中Tlv的典型用法代码示例。如果您正苦于以下问题:C++ Tlv类的具体用法?C++ Tlv怎么用?C++ Tlv使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Tlv类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:HarryMorris,项目名称:openthread,代码行数:34,代码来源:tlvs.cpp


示例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;
}
开发者ID:nodish,项目名称:openthread,代码行数:10,代码来源:dataset.cpp


示例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;
}
开发者ID:BackupTheBerlios,项目名称:sim-im-svn,代码行数:45,代码来源:icqlocation.cpp


示例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;
}
开发者ID:nodish,项目名称:openthread,代码行数:28,代码来源:dataset.cpp


示例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;
}
开发者ID:mtornblad,项目名称:openthread,代码行数:18,代码来源:tlvs.cpp


示例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;
}
开发者ID:MatthewCoppola4,项目名称:openthread,代码行数:18,代码来源:mle_tlvs.cpp


示例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;
}
开发者ID:nodish,项目名称:openthread,代码行数:19,代码来源:dataset.cpp


示例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;
}
开发者ID:mtornblad,项目名称:openthread,代码行数:39,代码来源:tlvs.cpp


示例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;
}
开发者ID:mtornblad,项目名称:openthread,代码行数:38,代码来源:tlvs.cpp


示例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);
}
开发者ID:HarryMorris,项目名称:openthread,代码行数:23,代码来源:dataset_manager.cpp


示例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;
}
开发者ID:MatthewCoppola4,项目名称:openthread,代码行数:23,代码来源:mle_tlvs.cpp


示例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;
}
开发者ID:abtink,项目名称:openthread,代码行数:44,代码来源:meshcop_tlvs.cpp


示例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);
}
开发者ID:holycheater,项目名称:qt-icq-transport,代码行数:14,代码来源:icqMetaInfoManager.cpp


示例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();
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:sim-im-svn,代码行数:101,代码来源:icqlogin.cpp


示例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()))
    {
//.........这里部分代码省略.........
开发者ID:HarryMorris,项目名称:openthread,代码行数:101,代码来源:dataset_manager.cpp


示例16: NS_ASSERT_MSG

IpcsClassifierRecord::IpcsClassifierRecord (Tlv tlv)
{
  NS_ASSERT_MSG (tlv.GetType () == CsParamVectorTlvValue::Packet_Classification_Rule, "Invalid TLV");
  ClassificationRuleVectorTlvValue* rules = ((ClassificationRuleVectorTlvValue*)(tlv.PeekValue ()));
  m_priority = 0;
  m_index = 0;
  m_tosLow = 0;
  m_tosHigh = 0;
  m_tosMask = 0;
  m_cid = 0;
  for (std::vector<Tlv*>::const_iterator iter = rules->Begin (); iter != rules->End (); ++iter)
    {
      switch ((*iter)->GetType ())
        {
        case ClassificationRuleVectorTlvValue::Priority:
          {
            m_priority = ((U8TlvValue*)((*iter)->PeekValue ()))->GetValue ();
            break;
          }
        case ClassificationRuleVectorTlvValue::ToS:
          {
            NS_FATAL_ERROR ("ToS Not implemented-- please implement and contribute a patch");
            break;
          }
        case ClassificationRuleVectorTlvValue::Protocol:
          {
            ProtocolTlvValue * list = (ProtocolTlvValue *)(*iter)->PeekValue ();
            for (std::vector<uint8_t>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
              {
                AddProtocol (*iter2);
              }
            break;
          }
        case ClassificationRuleVectorTlvValue::IP_src:
          {
            Ipv4AddressTlvValue * list = (Ipv4AddressTlvValue *)(*iter)->PeekValue ();
            for (std::vector<Ipv4AddressTlvValue::ipv4Addr>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
              {
                AddSrcAddr ((*iter2).Address, (*iter2).Mask);
              }
            break;
          }
        case ClassificationRuleVectorTlvValue::IP_dst:
          {
            Ipv4AddressTlvValue * list = (Ipv4AddressTlvValue *)(*iter)->PeekValue ();
            for (std::vector<Ipv4AddressTlvValue::ipv4Addr>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
              {
                AddDstAddr ((*iter2).Address, (*iter2).Mask);
              }
            break;
          }
        case ClassificationRuleVectorTlvValue::Port_src:
          {
            PortRangeTlvValue * list = (PortRangeTlvValue *)(*iter)->PeekValue ();
            for (std::vector<PortRangeTlvValue::PortRange>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
              {
                AddSrcPortRange ((*iter2).PortLow, (*iter2).PortHigh);
              }
            break;
          }
        case ClassificationRuleVectorTlvValue::Port_dst:
          {
            PortRangeTlvValue * list = (PortRangeTlvValue *)(*iter)->PeekValue ();
            for (std::vector<PortRangeTlvValue::PortRange>::const_iterator iter2 = list->Begin (); iter2 != list->End (); ++iter2)
              {
                AddDstPortRange ((*iter2).PortLow, (*iter2).PortHigh);
              }
            break;
          }
        case ClassificationRuleVectorTlvValue::Index:
          {
            m_index = ((U16TlvValue*)((*iter)->PeekValue ()))->GetValue ();
            break;
          }
        }
    }
}
开发者ID:shuiziliuBUPT,项目名称:HelloWorld,代码行数:77,代码来源:ipcs-classifier-record.cpp


示例17: switch

void ICQClient::snac_login(unsigned short type, unsigned short)
{
    unsigned long newUin;
    switch (type){
    case ICQ_SNACxLOGIN_ERROR:
        if (data.owner.Uin.toULong()){
            m_reconnect = NO_RECONNECT;
            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;
        socket()->close();
        socket()->connect(getServer(), getPort(), this);
        break;
    case ICQ_SNACxLOGIN_REGISTER:
        if (data.owner.Uin.toULong()){
            socket()->error_state(I18N_NOOP("Registered in no register state"));
            break;
        }
        socket()->readBuffer().incReadPos(0x2E);
        socket()->readBuffer().unpack(newUin);
        log(L_DEBUG, "Register %lu %08lX", newUin, newUin);
        setUin(newUin);
        setState(Connecting);
        socket()->connect(getServer(), getPort(), this);
        break;
    case ICQ_SNACxLOGIN_AUTHxKEYxRESPONSE:
        log(L_DEBUG, "Sending MD5 key");
        if (!data.owner.Screen.str().isEmpty() || data.owner.Uin.toULong()){
            QCString md5_key;
            socket()->readBuffer().unpackStr(md5_key);
            snac(ICQ_SNACxFOOD_LOGIN, ICQ_SNACxLOGIN_MD5xLOGIN, false, false);
            if (data.owner.Uin.toULong()){
                char uin[20];
                sprintf(uin, "%lu", data.owner.Uin.toULong());
                socket()->writeBuffer().tlv(0x0001, uin);
            }else{
                socket()->writeBuffer().tlv(0x0001, data.owner.Screen.str());
            }
            QCString md = md5_key;
            md += getContacts()->fromUnicode(NULL, getPassword());
            md += "AOL Instant Messenger (SM)";
            md = md5(md);
            socket()->writeBuffer().tlv(0x0025, md.data(), md.size());
	        if (data.owner.Uin.toULong()){
                socket()->writeBuffer().tlv(0x0003, "ICQBasic");  //ToDo: Should be updated anytime
                socket()->writeBuffer().tlv(0x0016, 0x010A); // ID Number
                socket()->writeBuffer().tlv(0x0017, 0x0014); // major
                socket()->writeBuffer().tlv(0x0018, 0x0034); // minor
                socket()->writeBuffer().tlv(0x0019, 0x0009);
                socket()->writeBuffer().tlv(0x001A, 0x0c18);
                socket()->writeBuffer().tlv(0x0014, 0x0000043dL);
                socket()->writeBuffer().tlv(0x000f, "en");
                socket()->writeBuffer().tlv(0x000e, "us");
	        }else{
                socket()->writeBuffer().tlv(0x0003, "AOL Instant Messenger, version 5.1.3036/WIN32"); //ToDo: Should be updated anytime
                socket()->writeBuffer().tlv(0x0016, (unsigned short)0x0109);
                socket()->writeBuffer().tlv(0x0017, (unsigned short)0x0005);
                socket()->writeBuffer().tlv(0x0018, (unsigned short)0x0001);
                socket()->writeBuffer().tlv(0x0019, (unsigned short)0x0000);
                socket()->writeBuffer().tlv(0x001A, (unsigned short)0x0BDC);
                socket()->writeBuffer().tlv(0x0014, 0x000000D2L);
                socket()->writeBuffer().tlv(0x000F, "en");		//Todo Send right language shortcut ;) same below
                socket()->writeBuffer().tlv(0x000E, "us");
                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(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());
        QByteArray buf = tlvImage->byteArray();
        QPixmap pict;
        if (!pict.loadFromData(buf))
            break;
        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();
            log(L_DEBUG, "User input: %s", verifyStr.latin1());
            snac(ICQ_SNACxFOOD_LOGIN, ICQ_SNACxLOGIN_REGISTERxREQ);
            ICQBuffer msg;
            msg
            << 0x00000000L << 0x28000300L << 0x00000000L
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:sim-im-svn,代码行数:101,代码来源:icqlogin.cpp



注:本文中的Tlv类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ TmpDir类代码示例发布时间:2022-05-31
下一篇:
C++ TinyGPS类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap