예제 #1
0
bool operator==(const QCString &s1, const char *s2)
{
    if (s1.size() == 0 && !s2) {
        return TRUE;
    }
    else if (s1.size() == 0 && s2) {
        return FALSE;
    }
    return (strcmp(s1, s2) == 0);
}
예제 #2
0
/**
 * Execute a KDM/GDM remote control command.
 * @param cmd the command to execute. FIXME: undocumented yet.
 * @param buf the result buffer.
 * @return result:
 *  @li If true, the command was successfully executed.
 *   @p ret might contain addional results.
 *  @li If false and @p ret is empty, a communication error occurred
 *   (most probably KDM is not running).
 *  @li If false and @p ret is non-empty, it contains the error message
 *   from KDM.
 */
bool DM::exec(const char *cmd, QCString &buf)
{
    bool ret = false;
    int tl;
    unsigned len = 0;

    if(fd < 0)
        goto busted;

    tl = strlen(cmd);
    if(::write(fd, cmd, tl) != tl)
    {
    bust:
        ::close(fd);
        fd = -1;
    busted:
        buf.resize(0);
        return false;
    }
    if(DMType == OldKDM)
    {
        buf.resize(0);
        return true;
    }
    for(;;)
    {
        if(buf.size() < 128)
            buf.resize(128);
        else if(buf.size() < len * 2)
            buf.resize(len * 2);
        if((tl = ::read(fd, buf.data() + len, buf.size() - len)) <= 0)
        {
            if(tl < 0 && errno == EINTR)
                continue;
            goto bust;
        }
        len += tl;
        if(buf[len - 1] == '\n')
        {
            buf[len - 1] = 0;
            if(len > 2 && (buf[0] == 'o' || buf[0] == 'O') && (buf[1] == 'k' || buf[1] == 'K') && buf[2] <= 32)
                ret = true;
            break;
        }
    }
    return ret;
}
예제 #3
0
void KMail::Util::append(QByteArray &that, const QCString &str)
{
    that.detach();
    uint len1 = that.size();
    uint len2 = str.size() - 1;
    if(that.resize(len1 + len2, QByteArray::SpeedOptim))
        memcpy(that.data() + len1, str.data(), len2);
}
예제 #4
0
파일: applnk.cpp 프로젝트: opieproject/opie
/*!
  Executes the application associated with this AppLnk, with
  \a args as arguments.

  \sa exec()
*/
void AppLnk::execute(const QStringList& args) const
{
#ifdef Q_WS_QWS
    if ( !mRotation.isEmpty() ) {
  // ######## this will only work in the server
  int rot = QPEApplication::defaultRotation();
  int j = 0;
  rot = (rot+mRotation.toInt())%360;
  QCString old = getenv( "QWS_DISPLAY" ) ? getenv( "QWS_DISPLAY" ) : "Transformed";
  QString driver( old.left( ( ( j = old.find( ':' ) ) >= 0 ) ? j : old.size() ).data() );
  setenv( "QWS_DISPLAY", QString( "%1:Rot%2:0" ).arg( driver ).arg( rot ), 1 );
  invoke(args);
  setenv("QWS_DISPLAY", old.data(), 1);
    } else
#endif
  invoke(args);
}
예제 #5
0
QCString KMail::Util::lf2crlf(const QCString &src)
{
    QCString result(1 + 2 * src.size());   // maximal possible length

    QCString::ConstIterator s = src.begin();
    QCString::Iterator d = result.begin();
    // we use cPrev to make sure we insert '\r' only there where it is missing
    char cPrev = '?';
    while(*s)
    {
        if(('\n' == *s) && ('\r' != cPrev))
            *d++ = '\r';
        cPrev = *s;
        *d++ = *s++;
    }
    result.truncate(d - result.begin());   // adds trailing NUL
    return result;
}
예제 #6
0
bool BString::writeToDevice(QIODevice &device)
{
    if (!m_valid)
        return false;

    QString str = QString("%1:").
        arg(get_len());

    QCString utfString = str.utf8();

    /* Don't write null terminator */
    device.writeBlock (utfString.data(), utfString.size() - 1);

    // Output the actual data
    device.writeBlock (m_data.data(), m_data.size() - 1);

    // Done
    return true;
}
예제 #7
0
DataProtocol::DataProtocol(const QCString &pool_socket, const QCString &app_socket)
	: SlaveBase("kio_data", pool_socket, app_socket) {
#else
DataProtocol::DataProtocol() {
#endif
  kdDebug() << "DataProtocol::DataProtocol()" << endl;
}

/* --------------------------------------------------------------------- */

DataProtocol::~DataProtocol() {
  kdDebug() << "DataProtocol::~DataProtocol()" << endl;
}

/* --------------------------------------------------------------------- */

void DataProtocol::get(const KURL& url) {
  ref();
  //kdDebug() << "===============================================================================================================================================================================" << endl;
  kdDebug() << "kio_data@"<<this<<"::get(const KURL& url)" << endl ;

  DataHeader hdr;
  parseDataHeader(url,hdr);

  int size = (int)hdr.url.length();
  int data_ofs = QMIN(hdr.data_offset,size);
  // FIXME: string is copied, would be nice if we could have a reference only
  QString url_data = hdr.url.mid(data_ofs);
  QCString outData;

#ifdef TESTKIO
//  cout << "current charset: \"" << *hdr.charset << "\"" << endl;
#endif
  if (hdr.is_base64) {
    // base64 stuff is expected to contain the correct charset, so we just
    // decode it and pass it to the receiver
    KCodecs::base64Decode(url_data.local8Bit(),outData);
  } else {
    // FIXME: This is all flawed, must be reworked thoroughly
    // non encoded data must be converted to the given charset
    QTextCodec *codec = QTextCodec::codecForName(hdr.charset->latin1());
    if (codec != 0) {
      outData = codec->fromUnicode(url_data);
    } else {
      // if there is no approprate codec, just use local encoding. This
      // should work for >90% of all cases.
      outData = url_data.local8Bit();
    }/*end if*/
  }/*end if*/

  //kdDebug() << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
  //kdDebug() << "emit mimeType@"<<this << endl ;
  mimeType(hdr.mime_type);
  //kdDebug() << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
  //kdDebug() << "emit totalSize@"<<this << endl ;
  totalSize(outData.size());

  //kdDebug() << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
  //kdDebug() << "emit setMetaData@"<<this << endl ;
#if defined(TESTKIO) || defined(DATAKIOSLAVE)
  MetaData::ConstIterator it;
  for (it = hdr.attributes.begin(); it != hdr.attributes.end(); ++it) {
    setMetaData(it.key(),it.data());
  }/*next it*/
#else
  setAllMetaData(hdr.attributes);
#endif

  //kdDebug() << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << endl;
  //kdDebug() << "emit sendMetaData@"<<this << endl ;
  sendMetaData();
  //kdDebug() << "^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C^[[C" << endl;
//   kdDebug() << "(1) queue size " << dispatchQueue.size() << endl;
  // empiric studies have shown that this shouldn't be queued & dispatched
  /*DISPATCH*/(data(outData));
//   kdDebug() << "(2) queue size " << dispatchQueue.size() << endl;
  DISPATCH(data(QByteArray()));
//   kdDebug() << "(3) queue size " << dispatchQueue.size() << endl;
  DISPATCH(finished());
//   kdDebug() << "(4) queue size " << dispatchQueue.size() << endl;
  deref();
}
예제 #8
0
void KoXmlWriter::writeString( const QString& str )
{
    // cachegrind says .utf8() is where most of the time is spent
    QCString cstr = str.utf8();
    m_dev->writeBlock( cstr.data(), cstr.size() - 1 );
}
예제 #9
0
DwString KMail::Util::dwString(const QCString &str)
{
    if(!str.data())    // DwString doesn't like char*=0
        return DwString();
    return DwString(str.data(), str.size() - 1);
}
예제 #10
0
void ChatWindow::processEvent(ICQEvent *e)
{
    if (e->message() != chat) return;
    chat->bDelete = false;
    if (e->state == ICQEvent::Fail){
        if (bInit) close();
        return;
    }
    if (e->type() != EVENT_CHAT) return;
    switch (e->subType()){
    case CHAT_CONNECT:{
            CUser u(e->Uin());
            new ChatUserItem(lstUsers, u.name(), e->Uin());
            QString line = chatHeader(e->Uin()) +
                           txtChat->quoteText(i18n("Enter to chat").local8Bit()) + "<br>\n";
            txtChat->insertParagraph(line, -1);
            txtChat->scrollToBottom();
            txtChat->moveCursor(QTextEdit::MoveEnd, false);
            if (logFile){
                QCString s = line.local8Bit();
                logFile->writeBlock(s, s.length());
                logFile->flush();
            }
            bConnected = true;
            break;
        }
    case CHAT_FONT_FACE:
        if (bClientMode){
            txtChat->setBold(chat->chat->fontFace & FONT_BOLD);
            txtChat->setItalic(chat->chat->fontFace & FONT_ITALIC);
            txtChat->setUnderline(chat->chat->fontFace & FONT_UNDERLINE);
        }
        break;
    case CHAT_COLORxFG:
        if (bClientMode)
            txtChat->setColor(chatColor(chat->chat->fgColor));
        break;
    case CHAT_TEXT:
        if (!bClientMode){
            txtChat->insertParagraph(chatHeader(e->Uin()), -1);
            txtChat->scrollToBottom();
            txtChat->moveCursor(QTextEdit::MoveEnd, false);
            txtChat->setBold(chat->chat->fontFace & FONT_BOLD);
            txtChat->setItalic(chat->chat->fontFace & FONT_ITALIC);
            txtChat->setUnderline(chat->chat->fontFace & FONT_UNDERLINE);
            txtChat->setColor(chatColor(chat->chat->fgColor));
            bClientMode = true;
        }
        txtChat->insert(QString::fromLocal8Bit(e->text.c_str()), false, false);
        break;
    case CHAT_BACKSPACE:
        if (bClientMode)
            txtChat->doKeyboardAction(QTextEdit::ActionBackspace);
        break;
    case CHAT_NEWLINE:{
            QString clientString;
            if (bClientMode){
                int n = txtChat->paragraphs();
                clientString = txtChat->text(n-1);
                txtChat->removeParagraph(n-1);
                int pos = clientString.find("&gt;");
                clientString = clientString.mid(pos+4);
            }
            txtChat->insertParagraph("<br>", -1);
            txtChat->moveCursor(QTextEdit::MoveEnd, false);
            QString line = chatHeader(chat->getUin()) + MainWindow::ParseText(clientString.local8Bit(), false) + "<br>\n";
            txtChat->append(line);
            txtChat->scrollToBottom();
            txtChat->moveCursor(QTextEdit::MoveEnd, false);
            bClientMode = false;
            if (logFile){
                QCString s = line.local8Bit();
                logFile->writeBlock(s, s.size());
                logFile->flush();
            }
            break;
        }
    }
}
예제 #11
0
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
            << 0x00000000L << 0x94680000L << 0x94680000L
            << 0x00000000L << 0x00000000L << 0x00000000L
            << 0x00000000L;
            QCString pswd = getContacts()->fromUnicode(NULL, getPassword());
            unsigned short len = (unsigned short)(pswd.length() + 1);
            msg.pack(len);
            msg.pack(pswd.data(), len);
            msg << 0x94680000L << 0x00000602L;
            socket()->writeBuffer().tlv(0x0001, msg);
            socket()->writeBuffer().tlv(0x0009, verifyStr.latin1(), verifyStr.length());
            sendPacket(true);            
        }
        break;
        }
    default:
        log(L_WARN, "Unknown login foodgroup type %04X", type);
    }
}