bool QOperParamFile::loadParam_addRow(const char *dataBuffer) { // 将数据转化为key与value,存放在map中 SOperContainer * tempContainer = (SOperContainer * )dataBuffer; quint32 Key; SOperInfoValue Value; Key=atoi(tempContainer->szOper); Value.dwOper=Key; Value.sOperName=GB2312toUtf8(tempContainer->szOperName); Value.wOperType=qFromBigEndian(tempContainer->wOperType); Value.dwNetId=atoi(tempContainer->szNetId); Value.dwSubCenter=atoi(tempContainer->szSubCenter); Value.dwStation=atoi(tempContainer->szStation); //Value.sFormOrg=tempContainer->szFormOrg; Value.wGroupId=qFromBigEndian(tempContainer->wGroupId); Value.dwOperCardID=atoi(tempContainer->szOperCardID); Value.szPassWord=QString::fromLocal8Bit(tempContainer->szPassWord); //Value.sFunRole = QString(tempContainer->szFunRole+ 16); memcpy(Value.szFunRole, tempContainer->szFunRole, sizeof(Value.szFunRole)); //--DEBUG //qDebug() << Key << ":" << Value.dwOper << Value.sOperName << Value.wOperType; m_container.addItemToTemp(Key, Value); return true; }
void Client::onRequest() { QByteArray request = m_client.readAll(); socks4request* header = reinterpret_cast<socks4request*>(request.data()); #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN const QHostAddress address(qFromBigEndian(header->address)); #else const QHostAddress address(header->address); #endif #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN const uint16_t port = qFromBigEndian(header->port); #else const uint16_t port = header->port; #endif //qDebug()<<"connection:"<<address<<"port:"<<port; m_world.connectToHost(address, port); disconnect(&m_client, &QTcpSocket::readyRead, this, &Client::onRequest); connect(&m_client, &QTcpSocket::readyRead, this, &Client::client2world); }
bool MythRAOPConnection::GetPacketType(const QByteArray &buf, uint8_t &type, uint16_t &seq, uint64_t ×tamp) { // All RAOP packets start with | 0x80/0x90 (first sync) | PACKET_TYPE | if ((uint8_t)buf[0] != 0x80 && (uint8_t)buf[0] != 0x90) { return false; } type = (char)buf[1]; // Is it first sync packet? if ((uint8_t)buf[0] == 0x90 && type == FIRSTSYNC) { return true; } if (type != FIRSTAUDIO_DATA) { type &= ~0x80; } if (type != AUDIO_DATA && type != FIRSTAUDIO_DATA && type != AUDIO_RESEND) return true; const char *ptr = buf.constData(); if (type == AUDIO_RESEND) { ptr += 4; } seq = qFromBigEndian(*(uint16_t *)(ptr + 2)); timestamp = qFromBigEndian(*(uint32_t*)(ptr + 4)); return true; }
/** * ProcessTimeResponse: * Calculate the network latency, we do not use the reference time send by itunes * instead we measure the time lapsed between the request and the response * the latency is calculated in ms */ void MythRAOPConnection::ProcessTimeResponse(const QByteArray &buf) { timeval t1, t2; const char *req = buf.constData(); t1.tv_sec = qFromBigEndian(*(uint32_t*)(req + 8)); t1.tv_usec = qFromBigEndian(*(uint32_t*)(req + 12)); gettimeofday(&t2, NULL); uint64_t time1, time2; time1 = t1.tv_sec * 1000 + t1.tv_usec / 1000; time2 = t2.tv_sec * 1000 + t2.tv_usec / 1000; LOG(VB_GENERAL, LOG_DEBUG, LOC + QString("Read back time (Local %1.%2)") .arg(t1.tv_sec).arg(t1.tv_usec)); // network latency equal time difference in ms between request and response // divide by two for approximate time of one way trip m_networkLatency = (time2 - time1) / 2; // now calculate the time difference between the client and us. // this is NTP time, where sec is in seconds, and ticks is in 1/2^32s uint32_t sec = qFromBigEndian(*(uint32_t*)(req + 24)); uint32_t ticks = qFromBigEndian(*(uint32_t*)(req + 28)); // convert ticks into ms int64_t master = NTPToLocal(sec, ticks); m_clockSkew = master - time2; }
/*! Returns a list of writing systems supported by the font according to designer supplied information in the font file. Please note that this does not guarantee support for a specific unicode point in the font. You can use the supportsCharacter() to check support for a single, specific character. \note The list is determined based on the unicode ranges and codepage ranges set in the font's OS/2 table and requires such a table to be present in the underlying font file. \sa supportsCharacter() */ QList<QFontDatabase::WritingSystem> QRawFont::supportedWritingSystems() const { QList<QFontDatabase::WritingSystem> writingSystems; if (d->isValid()) { QByteArray os2Table = fontTable("OS/2"); if (os2Table.size() > 86) { char *data = os2Table.data(); quint32 *bigEndianUnicodeRanges = reinterpret_cast<quint32 *>(data + 42); quint32 *bigEndianCodepageRanges = reinterpret_cast<quint32 *>(data + 78); quint32 unicodeRanges[4]; quint32 codepageRanges[2]; for (int i=0; i<4; ++i) { if (i < 2) codepageRanges[i] = qFromBigEndian(bigEndianCodepageRanges[i]); unicodeRanges[i] = qFromBigEndian(bigEndianUnicodeRanges[i]); } QSupportedWritingSystems ws = QPlatformFontDatabase::writingSystemsFromTrueTypeBits(unicodeRanges, codepageRanges); for (int i = 0; i < QFontDatabase::WritingSystemsCount; ++i) { if (ws.supported(QFontDatabase::WritingSystem(i))) writingSystems.append(QFontDatabase::WritingSystem(i)); } } } return writingSystems; }
void PalmdocHeader::swap() { compression = qFromBigEndian(compression); text_length = qFromBigEndian(text_length); record_count = qFromBigEndian(record_count); record_size = qFromBigEndian(record_size); encryption = qFromBigEndian(encryption); }
char* Osc::createMessageInternal( char* bp, int* length, char* address, char* format, QList<OscMessageData*> msgData ) { // do the address bp = writePaddedString( bp, length, address ); if ( bp == NULL ) return 0; // do the type bp = writePaddedString( bp, length, format ); if ( bp == NULL ) return 0; // Going to be walking the tag string, the format string and the data // skip the ',' comma bool cont = true; for( int i = 0; i < msgData.count( ); i++ ) { OscMessageData *data = msgData.at(i); if( data->omdType == OscMessageData::OmdInt ) { *length -= 4; if ( *length >= 0 ) { int v = data->i; v = qFromBigEndian( v ); *((int*)bp) = v; bp += 4; } else cont = false; } if( data->omdType == OscMessageData::OmdFloat ) { *length -= 4; if ( *length >= 0 ) { int v; *((float*)&v) = data->f; v = qFromBigEndian( v ); *((int*)bp) = v; bp += 4; } else cont = false; } if( data->omdType == OscMessageData::OmdString ) { bp = this->writePaddedString( bp, length, data->s ); if ( bp == NULL ) cont = false; } } return ( cont ) ? bp : NULL; }
void PDBHeader::swap() { attributes = qFromBigEndian(attributes); version = qFromBigEndian(version); create_date = qFromBigEndian(create_date); mod_date = qFromBigEndian(mod_date); backup_date = qFromBigEndian(backup_date); mod_number = qFromBigEndian(mod_number); appInfoID = qFromBigEndian(appInfoID); sortInfoID = qFromBigEndian(sortInfoID); uniqueIDseed = qFromBigEndian(uniqueIDseed); num_records = qFromBigEndian(num_records); }
void LedGridControllerUT::convertToRgb565() { MyMock::expectOneCallAndReturnInt(QString("open_fbdev"), 1); LedGridController *controller = LedGridController::getInstance(); quint16 bigEndianValue = controller->toRGB565(QColor(0,0,0)); QCOMPARE(qFromBigEndian(bigEndianValue), (quint16)0); bigEndianValue = controller->toRGB565(QColor(0xFF,0xFF,0xFF)); QCOMPARE(qFromBigEndian(bigEndianValue), (quint16)0xFFFF); bigEndianValue = controller->toRGB565(QColor(0x40,0x80,0xC0)); const quint16 compareValueRBMultiplier = 0x01F; //B0001_1111 const quint16 compareValueGMultiplier = 0x03F; //B0011_1111 quint16 compareValue = (0xC0*compareValueRBMultiplier)/0xFF; //blue compareValue |= (((0x40*compareValueRBMultiplier)/0xFF) << 11); //red compareValue |= (((0x80*compareValueGMultiplier)/0xFF) << 5); //green QCOMPARE(qFromBigEndian(bigEndianValue), (quint16)compareValue); }
// When we receive a packet, check to see whether it is a message or a bundle. void Osc::receivePacket( char* packet, int length, QList<OscMessage*>* oscMessageList ) { //printf( "Raw: %s, Length: %d\n", packet, length ); switch( *packet ) { case '/': // the '/' in front tells us this is an Osc message. receiveMessage( packet, length, oscMessageList ); break; case '#': // the '#' tells us this is an Osc bundle, and we check for "#bundle" just to be sure. if ( strcmp( packet, "#bundle" ) == 0 ) { // skip bundle text and timetag packet += 16; length -= 16; while ( length > 0 ) { // read the length (pretend packet is a pointer to integer) int messageLength = qFromBigEndian( *((int*)packet) ); packet += 4; length -= 4; if ( messageLength <= length ) receivePacket( packet, messageLength, oscMessageList ); length -= messageLength; packet += messageLength; } } break; default: // something we don't recognize... QString msg = QString( "Error - Osc packets must start with either a '/' (message) or '[' (bundle)."); messageInterface->messageThreadSafe( msg, MessageEvent::Error, preamble ); } }
inline T readNum(char *num, QFile &file) { file.read(num, 4); T n = *((T*)num); n = qFromBigEndian(n); return n; }
msg_ptr Msg::begin( char* headerToParse ) { quint32 lenBE = *( (quint32*) headerToParse ); quint8 flags = *( (quint8*) (headerToParse+4) ); return msg_ptr( new Msg( qFromBigEndian(lenBE), flags ) ); }
void ScriptResolver::readStdout() { qDebug() << Q_FUNC_INFO << m_proc.bytesAvailable(); if( m_msgsize == 0 ) { if( m_proc.bytesAvailable() < 4 ) return; quint32 len_nbo; m_proc.read( (char*) &len_nbo, 4 ); m_msgsize = qFromBigEndian( len_nbo ); qDebug() << Q_FUNC_INFO << "msgsize" << m_msgsize; } if( m_msgsize > 0 ) { m_msg.append( m_proc.read( m_msgsize - m_msg.length() ) ); } if( m_msgsize == (quint32) m_msg.length() ) { handleMsg( m_msg ); m_msgsize = 0; m_msg.clear(); if( m_proc.bytesAvailable() ) QTimer::singleShot( 0, this, SLOT(readStdout()) ); } }
uint32_t OsmAnd::ObfReaderUtilities::readBigEndianInt( gpb::io::CodedInputStream* cis ) { gpb::uint32 be; cis->ReadRaw(&be, sizeof(be)); auto ne = qFromBigEndian(be); return ne; }
void AbstractSocketClient::processGetTrack() { // read data quint32 strLen; if (!recv((char *)&strLen, sizeof(strLen))) { close(); return; } strLen = qFromBigEndian(strLen); if (!strLen) { close(); return; } QByteArray trackNameBuffer; trackNameBuffer.resize(strLen); if (!recv(trackNameBuffer.data(), strLen) || trackNameBuffer.contains('\0')) { close(); return; } requestTrack(QString::fromUtf8(trackNameBuffer)); }
void Common::parseHeader(const std::string &data, Address &dest, int &header_length) { char atyp = data[0]; int addrtype = static_cast<int>(atyp & ADDRESS_MASK); header_length = 0; if (addrtype == Address::HOST) { if (data.length() > 2) { uint8_t addrlen = static_cast<uint8_t>(data[1]); if (data.size() >= 2 + addrlen) { dest.setPort(qFromBigEndian(*reinterpret_cast<const uint16_t *> (data.data() + 2 + addrlen)) ); dest.setAddress(data.substr(2, addrlen)); header_length = 4 + addrlen; } } } else if (addrtype == Address::IPV4) { if (data.length() >= 7) { QHostAddress addr(qFromBigEndian(*reinterpret_cast<const uint32_t *> (data.data() + 1)) ); if (!addr.isNull()) { header_length = 7; dest.setIPAddress(addr); dest.setPort(qFromBigEndian(*reinterpret_cast<const uint16_t *> (data.data() + 5)) ); } } } else if (addrtype == Address::IPV6) { if (data.length() >= 19) { Q_IPV6ADDR ipv6_addr; memcpy(ipv6_addr.c, data.data() + 1, 16); QHostAddress addr(ipv6_addr); if (!addr.isNull()) { header_length = 19; dest.setIPAddress(addr); dest.setPort(qFromBigEndian(*reinterpret_cast<const uint16_t *> (data.data() + 17)) ); } } } }
/** createMessage Must put the "," as the first format letter */ Osc::Status Osc::createMessage( char* textMessageOriginal ) { char* textMessage = strdup( textMessageOriginal ); // try to send this message - if there's a problem somewhere, // send the existing buffer - freeing up space, then try (once) again. int count = 0; char *bp; do { count++; char* buffer = outBufferPointer; int remaining = outBufferRemaining; bp = buffer; // First message in the buffer? if ( bp == outBuffer ) { bp = createBundle( bp, &remaining, 0, 0 ); if ( bp == NULL ) return ERROR_CREATING_BUNDLE; } // remember the place we're going to store the message length int* lp = (int *)bp; bp += 4; remaining -= 4; // remember the start of the message char* mp = bp; if ( remaining > 0 ) { bp = createMessageInternal( bp, &remaining, textMessage ); } else bp = 0; if ( bp != 0 ) { // Set the size *lp = qFromBigEndian( bp - mp ); outBufferPointer = bp; outBufferRemaining = remaining; outMessageCount++; } else { sendPacket( ); } } while ( bp == 0 && count == 1 ); free( textMessage ); return ( bp != 0 ) ? OK : ERROR_SENDING_COMPLEX_MESSAGE; }
int Sample::toInt() const { if (signal->sampleSize() == 1) { if (signal->getFormat().sampleType() == QAudioFormat::SignedInt) { return constSampleData[0]; } else { return static_cast<unsigned char>(sampleData[0]); } } else if (signal->sampleSize() == 2) { if (signal->getFormat().sampleType() == QAudioFormat::SignedInt) { const short* val = reinterpret_cast<const short*>(constSampleData); if (signal->getFormat().byteOrder() == QAudioFormat::LittleEndian) { return qFromLittleEndian(*val); } else { return qFromBigEndian(*val); } } else { const unsigned short* val = reinterpret_cast<const unsigned short*>(sampleData); if (signal->getFormat().byteOrder() == QAudioFormat::LittleEndian) { return qFromLittleEndian(*val); } else { return qFromBigEndian(*val); } } } else { throw Signal::SampleSizeUnset(); } }
char* Osc::createMessageInternal( char* bp, int* length, char* address, char* format, va_list args ) { // do the address bp = writePaddedString( bp, length, address ); if ( bp == NULL ) return 0; // do the type bp = writePaddedString( bp, length, format ); if ( bp == NULL ) return 0; // Going to be walking the tag string, the format string and the data // skip the ',' comma char* fp; bool cont = true; for ( fp = format + 1; *fp && cont; fp++ ) { switch ( *fp ) { case 'i': *length -= 4; if ( *length >= 0 ) { int v = va_arg( args, int ); v = qFromBigEndian( v ); *((int*)bp) = v; bp += 4; } else cont = false; break; case 'f': *length -= 4; if ( *length >= 0 ) { int v; *((float*)&v) = (float)( va_arg( args, double ) ); v = qFromBigEndian( v ); *((int*)bp) = v; bp += 4; }
bool WebSocket::readFrame(QByteArray &buf) { unsigned char header[2]; if (!TcpSocket::recv((char *)header, 2)) return false; // int flags = header[0] >> 4; int opcode = header[0] & 0xF; int masked = header[1] >> 7; int payload_len = header[1] & 0x7f; if (payload_len == 126) { quint16 tmp; if (!TcpSocket::recv((char *)&tmp, 2)) return false; payload_len = qFromBigEndian(tmp); } else if (payload_len == 127) { // dude, that's one crazy big payload! let's bail! return false; } unsigned char mask[4] = { 0 }; if (masked) { if (!TcpSocket::recv((char *)mask, sizeof(mask))) return false; } buf.resize(payload_len); if (payload_len > 0) { if (!TcpSocket::recv(buf.data(), payload_len)) return false; } for (int i = 0; i < payload_len; ++i) buf[i] = buf[i] ^ mask[i & 3]; switch (opcode) { case 9: // got ping, send pong! sendFrame(10, buf.data(), buf.length(), true); buf.clear(); return true; case 8: // close disconnect(); buf.clear(); return false; } return true; }
bool QAllRateParamFile::loadParam_addRow(const char *dataBuffer) { SAllRateContainer *tempContainer = (SAllRateContainer * )dataBuffer; quint32 dwSta1,dwSta2; SAllRateValue value; SAllRateKey Key; dwSta1 = ArCharToInt(tempContainer->szStationIn,sizeof(tempContainer->szStationIn)); dwSta2 = ArCharToInt(tempContainer->szStationOut,sizeof(tempContainer->szStationOut)); //将数据转化为key与value并转存在map(内存)中 if (dwSta1 < dwSta2) { Key.nSta1=dwSta1; Key.nSta2=dwSta2; } else { Key.nSta1=dwSta2; Key.nSta2=dwSta1; } value.dwStationIn = atoi(tempContainer->szStationIn); value.dwStationOut = atoi(tempContainer->szStationOut); value.wStationNum = qFromBigEndian(tempContainer->wStationNum); value.sPathInfo = QString::fromLocal8Bit(tempContainer->szPathInfo); //添加解析经过收费站信息tPassStaAry if(!ParsePassStationInfo(value.sPathInfo,value.wStationNum,value.tPassStaAry)) return false; value.wCellNum = qFromBigEndian(tempContainer->wCellNum); value.dwTollDistance = qFromBigEndian(tempContainer->dwTollDistance); value.dwRealDistance = qFromBigEndian(tempContainer->dwRealDistance); value.szWayFlag = QString::fromLocal8Bit(tempContainer->szWayFlag); value.sTollInfo = QString::fromLocal8Bit(tempContainer->szTollInfo); //添加价格解析tPriceAry if(!ParseVCPrice(value.sTollInfo,value.tPriceAry)) return false; value.tmLastVer = QString::fromLocal8Bit(tempContainer->szLastVer); value.tmVerUsertime = QString::fromLocal8Bit(tempContainer->szVerUseTime); m_container.addItemToTemp(Key,value); return true; }
QString OscMessage::toString( ) { QString ret = QString( address ); int j; for( j = 0; j < data.size( ); j++ ) { ret.append( " " ); switch( data.at( j )->omdType ) { case OscMessageData::OmdBlob: { unsigned char* blob = (unsigned char*)data.at( j )->b; if( blob ) { int blob_len = *(int*)blob; // the first int should give us the length of the blob char c[6]; blob_len = qFromBigEndian( blob_len ); char buff[blob_len*6+10]; blob += 4; // step past the blob_len buff[0] = '['; buff[1] = ' '; buff[2] = '\0'; while( blob_len-- ) { sprintf( c, "%.2x ", *blob++ ); strcat( buff, c ); } strcat( buff, "]" ); ret.append( buff ); } else ret.append( "[ ]" ); break; } case OscMessageData::OmdString: ret.append( data.at( j )->s ); break; case OscMessageData::OmdInt: ret.append( QString::number(data.at( j )->i) ); break; case OscMessageData::OmdFloat: ret.append( QString::number(data.at( j )->f) ); break; } } return ret; }
void ProtocolSocket::read() { qDebug() << "Socket readable"; qint64 available; while ((available = m_socket->bytesAvailable()) >= 6) { quint16 msgLength; if (m_socket->peek(reinterpret_cast<char*>(&msgLength), sizeof(msgLength)) < 2) return; /* Message length does not include the header */ msgLength = qFromBigEndian(msgLength); if ((available - 6) < msgLength) break; QByteArray data; data.resize(msgLength + 6); qint64 re = m_socket->read(data.data(), msgLength + 6); Q_ASSERT(re == msgLength + 6); Q_UNUSED(re); if (Protocol::isReply(data[3])) { quint16 identifier = qFromBigEndian<quint16>(reinterpret_cast<const uchar*>(data.constData())+4); QHash<quint16,ProtocolCommand*>::Iterator it = pendingCommands.find(identifier); if (it != pendingCommands.end()) { (*it)->processReply(data[3], reinterpret_cast<const uchar*>(data.constData())+6, msgLength); if (Protocol::isFinal(data[3])) { /* Duplicated in socketDisconnected() */ qDebug() << "Received final reply for identifier" << identifier; emit (*it)->commandFinished(); (*it)->deleteLater(); pendingCommands.erase(it); } } } else { CommandHandler handler(user, m_socket, reinterpret_cast<const uchar*>(data.constData()), msgLength + 6); } } }
void BonjourServiceResolver::Private::bonjourResolveReply( DNSServiceRef, DNSServiceFlags, uint32_t, DNSServiceErrorType errorCode, const char*, const char* hosttarget, quint16 port, quint16 txtRecordLen, const unsigned char* pTxtRecord, void* context) { Private* const serviceResolver = static_cast< Private* >( context ); if( serviceResolver->bonjourPort != -1 || !serviceResolver->q->isResolving() ) return; if( errorCode != kDNSServiceErr_NoError ) { serviceResolver->q->error( errorCode ); return; } Q_EMIT serviceResolver->q->bonjourTXTRecordResolved(txtRecordLen, pTxtRecord); serviceResolver->bonjourPort = qFromBigEndian( port ); QHostInfo::lookupHost( QString::fromUtf8( hosttarget ), serviceResolver->q, SLOT( finishConnect( QHostInfo ) ) ); }
void SatelliteServer::incomingData( QObject *client ) { QTcpSocket *socket = static_cast<QTcpSocket*>(client); while( socket->bytesAvailable() > SATELLITE_PKGINFO_HEADER_SIZE ) { SATELLITE_PKGINFO_HEADER_TYPE header( 0 ); socket->peek( (char*)(&header), SATELLITE_PKGINFO_HEADER_SIZE ); header = qFromBigEndian( header ); if( (header >> 32) != SATELLITE_PKGINFO_MAGIC_VALUE ) { /* invalid data, flush */ socket->readAll(); #if SATELLITESERVER_DEBUG emit debug( "s:got bad data, flushing" ); #endif break; } qint64 datasize = (header & 0xFFFFFFFF) + SATELLITE_PKGINFO_CHECKSUM_SIZE + SATELLITE_PKGINFO_HEADER_SIZE; if( socket->bytesAvailable() < datasize ) { /* buffer incomplete, let the try at next signal */ #if SATELLITESERVER_DEBUG emit debug( "s:got incomplete data" ); #endif break; } QByteArray msg( socket->read( datasize ) ); #if SATELLITESERVER_DEBUG /* for debugging show raw message as hex dump */ emit debug( QByteArray("s:from client: ") + msg.toHex() ); #endif for( int i = 0; i < mClientConnections.count(); i++ ) { QTcpSocket *current = mClientConnections.at(i); if( current && (client != current) ) { current->write( msg ); } } } }
void QxtDiscoverableServicePrivate::resolveServiceCallback(DNSServiceRef service, DNSServiceFlags flags, quint32 iface, DNSServiceErrorType errCode, const char* fullname, const char* host, quint16 port, quint16 txtLen, const unsigned char* txt, void* context) #endif { Q_UNUSED(service); Q_UNUSED(txtLen); Q_UNUSED(txt); Q_UNUSED(flags); QxtDiscoverableServicePrivate* self = reinterpret_cast<QxtDiscoverableServicePrivate*>(context); QxtDiscoverableService* pub = &self->qxt_p(); if(errCode == kDNSServiceErr_NoError) { QxtDiscoverableServiceName name(fullname); pub->setServiceName(name.serviceName()); pub->setDomain(name.domain()); pub->setHost(host); pub->setPort(qFromBigEndian(port)); self->iface = iface; emit pub->resolved(fullname); } else { self->state = QxtDiscoverableService::Unknown; emit pub->resolveError((QxtDiscoverableService::ErrorCode)errCode); } }
void AbstractSocketClient::processSetRow() { quint32 newRow; if (recv((char *)&newRow, sizeof(newRow))) emit rowChanged(qFromBigEndian(newRow)); }
void QxtMDNSPrivate::avahiRecordBrowserCallback(AvahiRecordBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, uint16_t clazz, uint16_t type, const void *rdata, size_t size, AvahiLookupResultFlags flags, void *userdata) { ///@TODO Support IPv6 Q_UNUSED(interface); Q_UNUSED(protocol); Q_UNUSED(name); Q_UNUSED(clazz); Q_UNUSED(type); Q_UNUSED(size); Q_UNUSED(flags); QxtMDNSPrivate* self = static_cast<QxtMDNSPrivate*>(userdata); self->recordbrowser = b; // qDebug() << "Return thing" << md->name << name << size; switch (event) { case AVAHI_BROWSER_NEW: { //Found an entry! uint32_t ip = qFromBigEndian(*static_cast<const uint32_t*>(rdata)); if (self->sent) { QHostInfo info(self->info.lookupId()); info.setAddresses(QList<QHostAddress>() << QHostAddress(ip)); QMetaObject::invokeMethod(self->receiver, self->member, Q_ARG(QHostInfo, info)); } else { self->addresses << QHostAddress(ip); } break; } case AVAHI_BROWSER_REMOVE: { uint32_t ip = qFromBigEndian(*static_cast<const uint32_t*>(rdata)); self->addresses.removeAll(QHostAddress(ip)); break; } case AVAHI_BROWSER_CACHE_EXHAUSTED: break; case AVAHI_BROWSER_ALL_FOR_NOW: if (self->addresses.count() == 0) { self->info.setError(QHostInfo::HostNotFound); self->info.setErrorString("The host was not found."); } else { self->info.setAddresses(self->addresses); self->addresses.clear(); } QMetaObject::invokeMethod(self->receiver, self->member, Q_ARG(QHostInfo, self->info)); self->sent = true; break; case AVAHI_BROWSER_FAILURE: if (self->sent) { QHostInfo info(self->info.lookupId()); info.setError(QHostInfo::UnknownError); info.setErrorString(avahi_strerror(avahi_client_errno(self->client))); info.setAddresses(self->addresses); QMetaObject::invokeMethod(self->receiver, self->member, Q_ARG(QHostInfo, info)); } else { self->info.setError(QHostInfo::UnknownError); self->info.setErrorString(avahi_strerror(avahi_client_errno(self->client))); self->info.setAddresses(self->addresses); self->addresses.clear(); QMetaObject::invokeMethod(self->receiver, self->member, Q_ARG(QHostInfo, self->info)); self->sent = true; } break; } }
inline quint32 getUint32(int offset) const { return qFromBigEndian(*reinterpret_cast<quint32 *>(data + offset)); }
Registry::ReadResult Registry::read(QVariant &result, Key key, const QString &subkey, const QString &value) { HKEY hKey; if(RegOpenKeyEx(enumToKey(key), subkey.toStdWString().c_str(), 0, KEY_READ, &hKey) != ERROR_SUCCESS) return ReadCannotFindSubKey; DWORD size; DWORD type; std::wstring wideValue = value.toStdWString(); if(RegQueryValueEx(hKey, wideValue.c_str(), 0, &type, 0, &size) != ERROR_SUCCESS) { RegCloseKey(hKey); return ReadCannotFindValue; } switch(type) { case REG_DWORD: case REG_DWORD_BIG_ENDIAN: { qint32 value; if(RegQueryValueEx(hKey, wideValue.c_str(), 0, 0, reinterpret_cast<LPBYTE>(&value), &size) != ERROR_SUCCESS) { RegCloseKey(hKey); return ReadCannotFindValue; } if(type == REG_DWORD_BIG_ENDIAN) value = qFromBigEndian(value); result = value; } break; case REG_SZ: case REG_EXPAND_SZ: case REG_LINK: case REG_MULTI_SZ: { std::vector<wchar_t> buffer(size); if(RegQueryValueEx(hKey, wideValue.c_str(), 0, 0, reinterpret_cast<LPBYTE>(buffer.data()), &size) != ERROR_SUCCESS) { RegCloseKey(hKey); return ReadCannotFindValue; } if(type == REG_MULTI_SZ) { QStringList stringList = QString::fromWCharArray(buffer.data(), size / 2).split(QChar(L'\0'), QString::SkipEmptyParts); if(stringList.last().isEmpty()) stringList.removeLast(); result = stringList; } else result = QString::fromWCharArray(buffer.data(), size / 2); } break; case REG_BINARY: { std::vector<char> buffer(size); if(RegQueryValueEx(hKey, wideValue.c_str(), 0, 0, reinterpret_cast<LPBYTE>(buffer.data()), &size) != ERROR_SUCCESS) { RegCloseKey(hKey); return ReadCannotFindValue; } result = QByteArray::fromRawData(buffer.data(), size); } break; case REG_QWORD: { qint64 value; if(RegQueryValueEx(hKey, wideValue.c_str(), 0, 0, reinterpret_cast<LPBYTE>(&value), &size) != ERROR_SUCCESS) { RegCloseKey(hKey); return ReadCannotFindValue; } result = value; } break; case REG_NONE: default: RegCloseKey(hKey); return ReadInvalidValueType; break; } RegCloseKey(hKey); return ReadOk; }