void CJString:: print(std::ostream &os) const { if (! isPrimitive()) os << "[String: '" << encodeText() << "']"; else os << "'" << encodeText() << "'"; }
void DccChatWindow::ownAction(const QString & text) { if(m_pSlaveThread) { QString szTmpBuffer; //see bug ticket #220 if(KVI_OPTION_BOOL(KviOption_boolStripMircColorsInUserMessages)) { szTmpBuffer = KviControlCodes::stripControlBytes(text); } else { szTmpBuffer = text; } QByteArray szData = encodeText(szTmpBuffer); const char * d = szData.data(); if(!d) return; KviCString buf(KviCString::Format, "%cACTION %s%c\r\n", 0x01, d, 0x01); m_pSlaveThread->sendRawData(buf.ptr(), buf.len()); output(KVI_OUT_ACTION, "%Q %Q", &(m_pDescriptor->szLocalNick), &szTmpBuffer); } else { output(KVI_OUT_SYSTEMWARNING, __tr2qs_ctx("Can't send data: no active connection", "dcc")); } }
void KviQueryWindow::ownAction(const QString & szBuffer) { if(!connection()) { outputNoFmt(KVI_OUT_SYSTEMWARNING,__tr2qs("This query has no active targets, no message sent")); } else { if(szBuffer.isEmpty()) return; QString szTmpBuffer; //see bug ticket #220 if(KVI_OPTION_BOOL(KviOption_boolStripMircColorsInUserMessages)) szTmpBuffer = KviControlCodes::stripControlBytes(szBuffer); else szTmpBuffer = szBuffer; QByteArray szBuffer = encodeText(szTmpBuffer); QString sz = windowName(); if(sz.isEmpty()) return; if(KVS_TRIGGER_EVENT_2_HALTED(KviEvent_OnMeAction,this,szTmpBuffer,sz)) return; if(!connection()->sendFmtData("PRIVMSG %s :%cACTION %s%c", connection()->encodeText(sz).data(),0x01,szBuffer.data(),0x01)) return; output(KVI_OUT_ACTION,"\r!nc\r%Q\r %Q",&(connection()->currentNickName()),&szTmpBuffer); m_pUserListView->userAction(connection()->currentNickName(),KVI_USERACTION_ACTION); } }
void SecretsManager::setMasterPassword(const QString &masterPassword) { if (!masterPassword.isEmpty()) { m_EncodedMasterPassword = encodeText(masterPassword, m_PasswordForMasterPassword); m_MasterPasswordHash = getPasswordHash(masterPassword); } else { m_EncodedMasterPassword.clear(); m_MasterPasswordHash.clear(); } }
QString SecretsManager::encodePassword(const QString &password) const { QString encodedPassword; if (!password.isEmpty()) { QString key = getKeyForEncryption(); encodedPassword = encodeText(password, key); } return encodedPassword; }
Window::Window(QWidget *parent) : QMainWindow(parent), ui(new Ui::Window) { clipboard = QApplication::clipboard(); ui->setupUi(this); abtdlg = new AboutDialog(this); connect(ui->bCopy, SIGNAL(clicked()), this, SLOT(copyText())); connect(ui->bPaste, SIGNAL(clicked()), this, SLOT(pasteText())); connect(ui->bEncode, SIGNAL(clicked()), this, SLOT(encodeText())); connect(ui->bDecode, SIGNAL(clicked()), this, SLOT(decodeText())); connect(ui->bmd5, SIGNAL(clicked()), this, SLOT(getmd5())); connect(ui->bAbout, SIGNAL(clicked()), abtdlg, SLOT(show())); connect(ui->bExit, SIGNAL(clicked()), qApp, SLOT(quit())); }
/** * Set attributes of the node that represents this class * in the XMI document. * @param doc the xmi document * @param blockElement the xmi element holding the attributes */ void TextBlock::setAttributesOnNode(QDomDocument & doc, QDomElement & blockElement) { Q_UNUSED(doc); QString endLine = UMLApp::app()->commonPolicy()->getNewLineEndingChars(); blockElement.setAttribute("tag",getTag()); // only write these if different from defaults if (getIndentationLevel()) blockElement.setAttribute("indentLevel", QString::number(getIndentationLevel())); if (!m_text.isEmpty()) blockElement.setAttribute("text", encodeText(m_text, endLine)); if (!getWriteOutText()) blockElement.setAttribute("writeOutText", getWriteOutText()?"true":"false"); if (!canDelete()) blockElement.setAttribute("canDelete", canDelete()?"true":"false"); }
lString8 ChangeInfo::toString() { lString8 buf; buf << START_TAG << "\n"; buf << FILE_TAG << "=" << encodeText(_fileName) << "\n"; buf << ACTION_TAG << "=" << (_deleted ? ACTION_DELETE_TAG : ACTION_UPDATE_TAG) << "\n"; buf << TIMESTAMP_TAG << "=" << fmt::decimal(_timestamp * 1000) << "\n"; if (_bookmark) { buf << TYPE_TAG << "=" << fmt::decimal(_bookmark->getType()) << "\n"; buf << START_POS_TAG << "=" << encodeText(_bookmark->getStartPos()) << "\n"; buf << END_POS_TAG << "=" << encodeText(_bookmark->getEndPos()) << "\n"; buf << PERCENT_TAG << "=" << fmt::decimal(_bookmark->getPercent()) << "\n"; buf << SHORTCUT_TAG << "=" << fmt::decimal(_bookmark->getShortcut()) << "\n"; buf << TITLE_TEXT_TAG << "=" << encodeText(_bookmark->getTitleText()) << "\n"; buf << POS_TEXT_TAG << "=" << encodeText(_bookmark->getPosText()) << "\n"; buf << COMMENT_TEXT_TAG << "=" << encodeText(_bookmark->getCommentText()) << "\n"; } buf << END_TAG << "\n"; return buf; }
QString SecretsManager::recodePassword(const QString &encodedPassword, const QString &oldMasterPassword, const QString &newMasterPassword) const { QString decodedPassword = decodeText(encodedPassword, oldMasterPassword); QString newEncodedPassword = encodeText(decodedPassword, newMasterPassword); return newEncodedPassword; }
void DccChatWindow::ownMessage(const QString & text, bool bUserFeedback) { if(!m_pSlaveThread) { output(KVI_OUT_SYSTEMWARNING, __tr2qs_ctx("Can't send data: no active connection", "dcc")); return; } QByteArray szData = encodeText(text); const char * d = szData.data(); if(!d) return; #ifdef COMPILE_CRYPT_SUPPORT if(cryptSessionInfo()) { if(cryptSessionInfo()->m_bDoEncrypt) { if(*d != KviControlCodes::CryptEscape) { KviCString encrypted; cryptSessionInfo()->m_pEngine->setMaxEncryptLen(-1); switch(cryptSessionInfo()->m_pEngine->encrypt(d, encrypted)) { case KviCryptEngine::Encrypted: { KviCString buf(KviCString::Format, "%s\r\n", encrypted.ptr()); m_pSlaveThread->sendRawData(buf.ptr(), buf.len()); if(bUserFeedback) g_pMainWindow->firstConsole()->outputPrivmsg(this, KVI_OUT_OWNPRIVMSGCRYPTED, m_pDescriptor->szLocalNick.toUtf8().data(), m_pDescriptor->szLocalUser.toUtf8().data(), m_pDescriptor->szLocalHost.toUtf8().data(), text, KviConsoleWindow::NoNotifications); } break; case KviCryptEngine::Encoded: { KviCString buf(KviCString::Format, "%s\r\n", encrypted.ptr()); m_pSlaveThread->sendRawData(buf.ptr(), buf.len()); if(bUserFeedback) { QString encr = decodeText(encrypted.ptr()); g_pMainWindow->firstConsole()->outputPrivmsg(this, KVI_OUT_OWNPRIVMSG, m_pDescriptor->szLocalNick.toUtf8().data(), m_pDescriptor->szLocalUser.toUtf8().data(), m_pDescriptor->szLocalHost.toUtf8().data(), encr, KviConsoleWindow::NoNotifications); } } break; default: // also case KviCryptEngine::EncryptError { QString szErr = cryptSessionInfo()->m_pEngine->lastError(); output(KVI_OUT_SYSTEMERROR, __tr2qs_ctx("The encryption engine was not able to encrypt the current message (%Q): %Q, no data was sent to the remote end", "dcc"), &text, &szErr); } break; } return; } else { d++; //eat the escape code KviCString buf(KviCString::Format, "%s\r\n", d); QString tmp = text.right(text.length() - 1); m_pSlaveThread->sendRawData(buf.ptr(), buf.len()); if(bUserFeedback) g_pMainWindow->firstConsole()->outputPrivmsg(this, KVI_OUT_OWNPRIVMSG, m_pDescriptor->szLocalNick.toUtf8().data(), m_pDescriptor->szLocalUser.toUtf8().data(), m_pDescriptor->szLocalHost.toUtf8().data(), tmp, KviConsoleWindow::NoNotifications); return; } } } #endif KviCString buf(KviCString::Format, "%s\r\n", d); m_pSlaveThread->sendRawData(buf.ptr(), buf.len()); if(bUserFeedback) g_pMainWindow->firstConsole()->outputPrivmsg(this, KVI_OUT_OWNPRIVMSG, m_pDescriptor->szLocalNick.toUtf8().data(), m_pDescriptor->szLocalUser.toUtf8().data(), m_pDescriptor->szLocalHost.toUtf8().data(), text, KviConsoleWindow::NoNotifications); }
CFX_WideString CBC_PDF417HighLevelEncoder::encodeHighLevel( CFX_WideString wideMsg, Compaction compaction, int32_t& e) { CFX_ByteString bytes; CBC_UtilCodingConvert::UnicodeToUTF8(wideMsg, bytes); CFX_WideString msg; int32_t len = bytes.GetLength(); for (int32_t i = 0; i < len; i++) { FX_WCHAR ch = (FX_WCHAR)(bytes.GetAt(i) & 0xff); if (ch == '?' && bytes.GetAt(i) != '?') { e = BCExceptionCharactersOutsideISO88591Encoding; return CFX_WideString(); } msg += ch; } CFX_ByteArray byteArr; for (int32_t k = 0; k < bytes.GetLength(); k++) { byteArr.Add(bytes.GetAt(k)); } CFX_WideString sb; len = msg.GetLength(); int32_t p = 0; int32_t textSubMode = SUBMODE_ALPHA; if (compaction == TEXT) { encodeText(msg, p, len, sb, textSubMode); } else if (compaction == BYTES) { encodeBinary(&byteArr, p, byteArr.GetSize(), BYTE_COMPACTION, sb); } else if (compaction == NUMERIC) { sb += (FX_WCHAR)LATCH_TO_NUMERIC; encodeNumeric(msg, p, len, sb); } else { int32_t encodingMode = LATCH_TO_TEXT; while (p < len) { int32_t n = determineConsecutiveDigitCount(msg, p); if (n >= 13) { sb += (FX_WCHAR)LATCH_TO_NUMERIC; encodingMode = NUMERIC_COMPACTION; textSubMode = SUBMODE_ALPHA; encodeNumeric(msg, p, n, sb); p += n; } else { int32_t t = determineConsecutiveTextCount(msg, p); if (t >= 5 || n == len) { if (encodingMode != TEXT_COMPACTION) { sb += (FX_WCHAR)LATCH_TO_TEXT; encodingMode = TEXT_COMPACTION; textSubMode = SUBMODE_ALPHA; } textSubMode = encodeText(msg, p, t, sb, textSubMode); p += t; } else { int32_t b = determineConsecutiveBinaryCount(msg, &byteArr, p, e); BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR)' '); if (b == 0) { b = 1; } if (b == 1 && encodingMode == TEXT_COMPACTION) { encodeBinary(&byteArr, p, 1, TEXT_COMPACTION, sb); } else { encodeBinary(&byteArr, p, b, encodingMode, sb); encodingMode = BYTE_COMPACTION; textSubMode = SUBMODE_ALPHA; } p += b; } } } } return sb; }
void KviQueryWindow::ownAction(const QString & szBuffer) { if(!connection()) return; QString szTmpBuffer; //see bug ticket #220 if(KVI_OPTION_BOOL(KviOption_boolStripMircColorsInUserMessages)) szTmpBuffer = KviControlCodes::stripControlBytes(szBuffer); else szTmpBuffer = szBuffer; //my full mask as seen by other users QString szMyName = connection()->userInfo()->nickName(); QString szMyFullMask = szMyName + "!" + connection()->userInfo()->userName() + "@" + connection()->userInfo()->hostName(); QByteArray myFullMask = connection()->encodeText(szMyFullMask); QByteArray name = connection()->encodeText(windowName()); QByteArray data = encodeText(szTmpBuffer); /* max length of a PRIVMSG text. Max buffer length for our send is 512 byte, but we have to * remember that the server will prepend to the message our full mask and truncate the resulting * at 512 bytes again.. * So we have: * :[email protected] PRIVMSG #channel :text of message(CrLf) * [email protected]#channeltext of message * 512(rfc) -2(CrLf) -2(:) -3(spaces) -7(PRIVMSG) -8(\x01ACTION\x01) = 490 * usable bytes, excluding our full mask and the target name. */ int iMaxMsgLen = 490 - name.length() - myFullMask.length(); if(KVS_TRIGGER_EVENT_2_HALTED(KviEvent_OnMeAction, this, szTmpBuffer, windowName())) return; #ifdef COMPILE_CRYPT_SUPPORT if(cryptSessionInfo() && cryptSessionInfo()->m_bDoEncrypt) { if(szTmpBuffer[0] != KviControlCodes::CryptEscape) { KviCString szEncrypted; cryptSessionInfo()->m_pEngine->setMaxEncryptLen(iMaxMsgLen); switch(cryptSessionInfo()->m_pEngine->encrypt(data.data(), szEncrypted)) { case KviCryptEngine::Encrypted: { if(!connection()->sendFmtData("PRIVMSG %s :%cACTION %s%c", name.data(), 0x01, szEncrypted.ptr(), 0x01)) return; output(KVI_OUT_OWNACTIONCRYPTED, "\r!nc\r%Q\r %Q", &szMyName, &szTmpBuffer); } break; case KviCryptEngine::Encoded: { if(!connection()->sendFmtData("PRIVMSG %s :%cACTION %s%c", name.data(), 0x01, szEncrypted.ptr(), 0x01)) return; // ugly, but we must redecode here QString szRedecoded = decodeText(szEncrypted.ptr()); output(KVI_OUT_OWNACTIONCRYPTED, "\r!nc\r%Q\r %Q", &szMyName, &szRedecoded); } break; default: // also case KviCryptEngine::EncryptError { QString szEngineError = cryptSessionInfo()->m_pEngine->lastError(); output(KVI_OUT_SYSTEMERROR, __tr2qs("The encryption engine was unable to encrypt the current message (%Q): %Q, no data sent to the server"), &szBuffer, &szEngineError); } } userAction(szMyName, KVI_USERACTION_ACTION); return; } else { //eat the escape code szTmpBuffer.remove(0, 1); data = encodeText(szTmpBuffer); } } #endif //COMPILE_CRYPT_SUPPORT if(!connection()->sendFmtData("PRIVMSG %s :%cACTION %s%c", name.data(), 0x01, data.data(), 0x01)) return; output(KVI_OUT_OWNACTION, "\r!nc\r%Q\r %Q", &szMyName, &szTmpBuffer); m_pUserListView->userAction(szMyName, KVI_USERACTION_ACTION); }
void KviQueryWindow::ownMessage(const QString & szBuffer, bool bUserFeedback) { if(!connection()) { outputNoFmt(KVI_OUT_SYSTEMWARNING, __tr2qs("This query has no active targets, no message sent")); return; } //my full mask as seen by other users QString szTmpMask = connection()->userInfo()->nickName() + "!" + connection()->userInfo()->userName() + "@" + connection()->userInfo()->hostName(); QByteArray szMyFullMask = connection()->encodeText(szTmpMask); //target name QByteArray szName = connection()->encodeText(windowName()); //message QByteArray szData = encodeText(szBuffer); const char * pcData = szData.data(); /* max length of a PRIVMSG text. Max buffer length for our sszEnd is 512 byte, but we have to * remember that the server will prepszEnd to the message our full mask and truncate the resulting * at 512 bytes again.. * So we have: * :[email protected] PRIVMSG #channel :text of message(CrLf) * [email protected]#channeltext of message * 512(rfc) -2(CrLf) -2(:) -3(spaces) -7(PRIVMSG) = 498 * usable bytes, excluding our full mask and the target name. */ int iMaxMsgLen = 498 - szName.length() - szMyFullMask.length(); // our copy of the message QString szTmpBuffer(szBuffer); if(!pcData) return; #ifdef COMPILE_CRYPT_SUPPORT if(cryptSessionInfo()) { if(cryptSessionInfo()->m_bDoEncrypt) { if(*pcData != KviControlCodes::CryptEscape) { KviCString szEncrypted; cryptSessionInfo()->m_pEngine->setMaxEncryptLen(500 - szName.length()); switch(cryptSessionInfo()->m_pEngine->encrypt(pcData, szEncrypted)) { case KviCryptEngine::Encrypted: if(!connection()->sendFmtData("PRIVMSG %s :%s", szName.data(), szEncrypted.ptr())) return; if(bUserFeedback) m_pConsole->outputPrivmsg(this, KVI_OUT_OWNPRIVMSGCRYPTED, QString(), QString(), QString(), szBuffer, KviConsoleWindow::NoNotifications); break; case KviCryptEngine::Encoded: { if(!connection()->sendFmtData("PRIVMSG %s :%s", szName.data(), szEncrypted.ptr())) return; if(bUserFeedback) { // ugly,but we must redecode here QString szRedecoded = decodeText(szEncrypted.ptr()); m_pConsole->outputPrivmsg(this, KVI_OUT_OWNPRIVMSG, QString(), QString(), QString(), szRedecoded, KviConsoleWindow::NoNotifications); } } break; default: // also case KviCryptEngine::EncryptError { QString szEngineError = cryptSessionInfo()->m_pEngine->lastError(); output(KVI_OUT_SYSTEMERROR, __tr2qs("The encryption engine was unable to encrypt the current message (%Q): %s, no data sent to the server"), &szBuffer, &szEngineError); } break; } userAction(connection()->currentNickName(), KVI_USERACTION_PRIVMSG); return; } else { //eat the escape code pcData++; szTmpBuffer.remove(0, 1); //let the normal function do it } } } #endif if(szData.length() > iMaxMsgLen) { /* Multi message; we want to split the message, preferably on a word boundary, * and sszEnd each message part as a different PRIVMSG * Due to encoding stuff, this is frikin'time eater */ QTextEncoder * pEncoder = makeEncoder(); // our temp encoder QByteArray szTmp; // used to calculate the length of an encoded message int iPos; // contains the index where to truncate szTmpBuffer int iC; // cycles counter (debugging/profiling purpose) float fPosDiff; // optimization internal; aggressivity factor QString szCurSubString; // truncated parts as reported to the user // run until we've something remaining in the message while(szTmpBuffer.length()) { // init counters iPos = szTmpBuffer.length(); iC = 0; // first part (optimization): quickly find an high index that is _surely_lesser_ // than the correct one while(1) { iC++; szTmp = pEncoder->fromUnicode(szTmpBuffer.left(iPos)); if(szTmp.length() <= iMaxMsgLen) break; //if szTmp.length() == 0 we already have break'ed out from here, // so we can safely use it as a divisor fPosDiff = (float)iMaxMsgLen / (float)szTmp.length(); iPos = (int)(iPos * fPosDiff); // cut the string at each cycle //printf("OPTIMIZATION: fPosDiff %f, iPos %d\n", fPosDiff, iPos); } //printf("Multi message: %d optimization cyles", iC); // now, do it the simple way: increment our index until we perfectly fit into the // available space while(1) { iC++; szTmp = pEncoder->fromUnicode(szTmpBuffer.left(iPos)); // perfect match if(iPos == szTmpBuffer.length()) break; if(szTmp.length() > iMaxMsgLen) { // overflowed.. last one was the good one iPos--; szTmp = pEncoder->fromUnicode(szTmpBuffer.left(iPos)); break; } else { //there's still free space.. add another char iPos++; } } //printf(", finished at %d cycles, truncated at pos %d\n", iC, iPos); //prepare the feedback string for the user szCurSubString = szTmpBuffer.left(iPos); //sszEnd the string to the server if(connection()->sendFmtData("PRIVMSG %s :%s", szName.data(), szTmp.data())) { //feeedback the user if(bUserFeedback) m_pConsole->outputPrivmsg(this, KVI_OUT_OWNPRIVMSG, QString(), QString(), QString(), szCurSubString, KviConsoleWindow::NoNotifications); userAction(connection()->currentNickName(), KVI_USERACTION_PRIVMSG); } else { // skipped a part in this multi message.. we don't want to continue return; } // remove the sent part of the string szTmpBuffer.remove(0, iPos); //printf("Sent %d chars, %d remaining in the Qstring\n",iPos, szTmpBuffer.length()); } } else { if(connection()->sendFmtData("PRIVMSG %s :%s", szName.data(), pcData)) { if(bUserFeedback) m_pConsole->outputPrivmsg(this, KVI_OUT_OWNPRIVMSG, QString(), QString(), QString(), szTmpBuffer, KviConsoleWindow::NoNotifications); userAction(connection()->currentNickName(), KVI_USERACTION_PRIVMSG); } } }