本文整理汇总了C++中QByteArray::duplicate方法的典型用法代码示例。如果您正苦于以下问题:C++ QByteArray::duplicate方法的具体用法?C++ QByteArray::duplicate怎么用?C++ QByteArray::duplicate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QByteArray
的用法示例。
在下文中一共展示了QByteArray::duplicate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: certRSAKeyValue
int FLDigiDoc::certRSAKeyValue(const QString &certfile, QByteArray &modResult,
QByteArray &expResult)
{
int err = ERR_OK;
unsigned char buf2[1024 * sizeof(unsigned char)], *buf1 = 0;
unsigned char buf22[1024 * sizeof(unsigned char)], *buf11 = 0;
int len2, len1;
EVP_PKEY *pubKey;
len1 = 512;
buf1 = (unsigned char *) malloc(len1);
memset(buf1, 0, len1);
buf11 = (unsigned char *) malloc(len1);
memset(buf11, 0, len1);
err = ReadPublicKey(&pubKey, certfile.latin1());
// FIXME
// modulus
len1 = BN_bn2bin(pubKey->pkey.rsa->n, buf1);
// in version 1.1 we output modulus as it is
// starting from 1.2 we convert it to big-endian
// len2 = sizeof(buf2);
// memset(buf2, 0, len2);
// encode(buf1, len1, buf2, &len2);
// printf("Old modulus: %s\n", buf2);
// if (!strcmp(pSigDoc->szFormatVer, DIGIDOC_XML_1_1_VER)) {
// swapBytes((byte *)buf1, len1);
// }
len2 = sizeof(buf2);
memset(buf2, 0, len2);
encode(buf1, len1, buf2, &len2);
modResult.duplicate((const char *)buf2, len2);
// exponent
memset(buf11, 0, len1);
len1 = BN_bn2bin(pubKey->pkey.rsa->e, buf11);
len2 = sizeof(buf22);
memset(buf22, 0, len2);
encode(buf11, len1, buf22, &len2);
expResult.duplicate((const char *)buf22, len2);
EVP_PKEY_free(pubKey);
free(buf1);
free(buf11);
return err;
}
示例2: klfFmt
KLF_EXPORT QByteArray klfFmt(const char * fmt, va_list pp)
{
static const int bufferSize = 8192;
char buffer[bufferSize];
int len;
#if defined(_BSD_SOURCE) || _XOPEN_SOURCE >= 500 || defined(_ISOC99_SOURCE)
// stdio.h provided vsnprintf()
len = vsnprintf(buffer, bufferSize, fmt, pp);
if (len >= bufferSize) {
// output was truncated
qWarning("%s(): output from format string \"%s\" was truncated from %d to %d bytes.",
KLF_FUNC_NAME, fmt, len, (bufferSize-1));
len = bufferSize-1;
}
#else
len = vsprintf(buffer, fmt, pp);
#endif
if (len < 0) {
qWarning("%s(): vs(n)printf() failed for format \"%s\"", KLF_FUNC_NAME, fmt);
return QByteArray();
}
// create a QByteArray
QByteArray data;
#ifdef KLFBACKEND_QT4
data = QByteArray(buffer, len);
#else
data.duplicate(buffer, len);
#endif
return data;
}
示例3: certSerialNumber
int FLDigiDoc::certSerialNumber(const QString &certfile, QByteArray &serialResult)
{
int bLen = 512;
char buf[bLen * sizeof(char)];
int err = GetCertSerialNumber(buf, bLen, certfile.latin1());
serialResult.duplicate((const char *) buf, bLen);
return err;
}
示例4: data
QVariant QMYSQLResult::data( int field )
{
if ( !isSelect() || field >= (int) d->fieldTypes.count() ) {
qWarning( "QMYSQLResult::data: column %d out of range", field );
return QVariant();
}
QString val( d->row[field] );
switch ( d->fieldTypes.at( field ) ) {
case QVariant::LongLong:
return QVariant( val.toLongLong() );
case QVariant::ULongLong:
return QVariant( val.toULongLong() );
case QVariant::Int:
return QVariant( val.toInt() );
case QVariant::UInt:
return QVariant( val.toUInt() );
case QVariant::Double:
return QVariant( val.toDouble() );
case QVariant::Date:
if ( val.isEmpty() ) {
return QVariant( QDate() );
} else {
return QVariant( QDate::fromString( val, Qt::ISODate ) );
}
case QVariant::Time:
if ( val.isEmpty() ) {
return QVariant( QTime() );
} else {
return QVariant( QTime::fromString( val, Qt::ISODate ) );
}
case QVariant::DateTime:
if ( val.isEmpty() )
return QVariant( QDateTime() );
if ( val.length() == 14u )
// TIMESTAMPS have the format yyyyMMddhhmmss
val.insert(4, "-").insert(7, "-").insert(10, 'T').insert(13, ':').insert(16, ':');
return QVariant( QDateTime::fromString( val, Qt::ISODate ) );
case QVariant::ByteArray: {
unsigned long* fl = mysql_fetch_lengths( d->result );
QByteArray ba;
ba.duplicate( d->row[field], fl[field] );
return QVariant( ba );
}
default:
case QVariant::String:
case QVariant::CString:
return QVariant( val );
}
#ifdef QT_CHECK_RANGE
qWarning("QMYSQLResult::data: unknown data type");
#endif
return QVariant();
}
示例5: sha1
QByteArray sha1(const char *str, int size)
{
unsigned char digest[20];
SHA_CTX ctx;
if (size < 0)
size = strlen(str);
SHA1_Init(&ctx);
SHA1_Update(&ctx, str, size);
SHA1_Final(digest, &ctx);
QByteArray ba;
ba.duplicate((char*)digest, sizeof(digest));
return ba;
}
示例6: md5
QByteArray md5(const char *str, int size)
{
MD5_CTX c;
unsigned char md[MD5_DIGEST_LENGTH];
if (size < 0)
size = strlen(str);
MD5_Init(&c);
MD5_Update(&c, str, size);
MD5_Final(md, &c);
QByteArray ba;
ba.duplicate((char*)md, sizeof(md));
return ba;
}
示例7: certDigest
int FLDigiDoc::certDigest(const QString &certfile, QByteArray &digestResult)
{
int err = ERR_OK, len1;
char buf1[1024 * sizeof(char)];
X509 *pCert = 0;
DigiDocMemBuf mbuf;
mbuf.pMem = 0;
mbuf.nLen = 0;
err = ReadCertificate(&pCert, certfile.latin1());
if (!err && pCert) {
len1 = sizeof(buf1);
buf1[0] = 0;
err = ddocCertGetDigest(pCert, &mbuf);
encode((const byte *) mbuf.pMem, mbuf.nLen, (byte *) buf1, &len1);
digestResult.duplicate((const char *) buf1, len1);
ddocMemBuf_free(&mbuf);
}
if (pCert) {
X509_free(pCert);
pCert = 0;
}
return err;
}
示例8: talking
void cSpeech::talking(int s, QString speech) // PC speech
{
/*
Unicode speech format
byte = char, short = char[2], int = char[4], wchar = char[2] = unicode character
Message Sent By Client:
0xAD - Unicode Speech Request
BYTE cmd(0xAD)
short msgsize 1, 2
byte type(0 = say, 2 = emote, 8 = whisper, 9 = yell) 3
short color 4, 5
short font 6, 7
BYTE[4] lang(null terminated, "enu " for US english.) 8, 9, 10, 11
wchar[?] text(null terminated, ?=(msgsize - 12)/2) 13
Message Sent By Server:
0xAE - Unicode Speech Message
BYTE cmd(0xAE) 0
short msgsize 1, 2
BYTE[4] ser(ser of speaker, all 0xFF if none) 3, 4, 5, 6
BYTE[2] model(id of speaker, all 0xFF if none)7, 8
BYTE type 9
short color 10, 11
short font 12, 13
BYTE[4] language(same as before) 14, 15, 16, 17
BYTE[30] speaker's name(normal chars, not wchars) 18 - 48
WCHAR[?] text(null terminated, ?=(msgsize - 48)/2
Importnat note regarding 0xAD: since 2.0.7 clients send between lang and text 0...10 bytes. (we can ignore them safely)
Those bytes get cut out in network.cpp correctly, so the buffer THIS functions sees is actualy what is written above.
The actual data the client sends is differently though.
Just noted this to prevent from debugging if somebody finds out client data doesn't fit to this description (LB)
*/
//char nonuni[512];
unsigned char talk2[19];
QByteArray unicodetext;
char lang[4];
char name[50] = {0,}; // it **IS** important to 0 out the remaining gaps
P_CHAR pc_currchar = currchar[s];
// strcpy(nonuni, speech.latin1());
// len+font+color+type = same postion for non unicode and unicode speech packets
// but 8 ... x DIFFER a lot for unicode and non unicode packets !!!
strncpy(name, pc_currchar->name.c_str(), 50);
char speech_type = buffer[s][3];
UI16 speech_color = ShortFromCharPtr(&buffer[s][4]);
char speech_fontbyte1 = buffer[s][6];
char speech_fontbyte2 = buffer[s][7];
int ucl = ( speech.length() * 2 ) + 2;
int tl = ucl + 48 ;
if (pc_currchar->unicode)
{
lang[0]=buffer[s][8];
lang[1]=buffer[s][9];
lang[2]=buffer[s][10];
lang[3]=buffer[s][11];
unicodetext.duplicate( (char*)&buffer[s][12], ucl );
}
else
{
lang[0]='E';
lang[1]='N';
lang[2]='U';
lang[3]=0;
char2wchar(speech.latin1()); // we are sending unicode response no matter if the speech request was non unicode or not
// so convert to uni-text in case of non unicode
unicodetext.duplicate( (char*)&temp, ucl );
}
/*
clConsole.send("speech: %s\n",nonuni);
clConsole.send("unicode speech:\n");
for ( a=0; a < tl-48; a++) clConsole.send("%02i ",unicodetext[a]);
clConsole.send("\n");*/
//// Very important: do not use buffer[s][] anymore in this function !!!!
//// unicode text that gets send is in unicodetext, nonunicode text for normal string processing in non uni code
// string punt(nonuni);
if (InputSpeech(speech, pc_currchar, s)) // handle things like renaming or describing an item
return;
if (pc_currchar->squelched) // not allowed to talk
{
sysmessage(s, "You have been squelched.");
return;
}
//.........这里部分代码省略.........
示例9: elementToVariant
//.........这里部分代码省略.........
#endif
v = QVariant(sp);
ok = true;
}
else if (e.tagName() == "cursor")
{
if (e.hasAttribute("shape"))
v = QVariant(QCursor(e.attribute("shape").toInt(&ok, 10)));
else
qWarning("%s element without value!", (const char*)e.tagName());
}
else if (e.tagName() == "stringlist")
{
QDomNodeList stringNodeList = e.elementsByTagName("string");
QStringList stringList;
QDomElement stringElement;
for (uint i = 0; i < stringNodeList.length(); i++)
{
stringElement = stringNodeList.item(i).toElement();
if (!stringElement.hasAttribute("value"))
{
qWarning("%s element in %s without value! Ignoring!",
(const char*)stringElement.tagName(),
(const char*)e.tagName());
continue;
}
stringList.append(e.attribute("value"));
}
v = stringList;
ok = true;
}
else if (e.tagName() == "uint64")
{
QString value = e.attribute("value");
// borrowed more or less from Qt 3.2 (since we have to support older)
uint64_t val = 0;
const QChar* p = value.unicode();
int l = value.length();
const uint64_t max_mult = UINT64_MAX / 16;
if (!p)
{
qWarning("Invalid value for tag: %s", (const char*)e.tagName());
return false;
}
while ( l && p->isSpace() ) // skip leading space
l--,p++;
if ( !l )
return false;
if ( *p == '+' )
l--,p++;
if ( !l || !ok_in_hex(*p) )
return false;
while ( l && ok_in_hex(*p) )
{
l--;
uint dv;
if ( p->isDigit() )
dv = p->digitValue();
else
{
if ( *p >= 'a' && *p <= 'f' )
dv = *p - 'a' + 10;
else
dv = *p - 'A' + 10;
}
if ( val > max_mult || (val == max_mult && dv > UINT64_MAX % 16) )
return false;
val = 16 * val + dv;
p++;
}
QByteArray ba;
ba.duplicate((const char*)&val, sizeof(uint64_t));
v = ba;
ok = true;
}
else if (e.tagName() == "list")
{
qWarning("Unimplemented tag: %s", (const char*)e.tagName());
}
else if (e.tagName() == "map")
{
qWarning("Unimplemented tag: %s", (const char*)e.tagName());
}
else
{
qWarning("Unknown tag: %s", (const char*)e.tagName());
}
return ok;
}