Example #1
0
void clientTreatment(int sock, int answerPort){
    struct sockaddr_in fromAddr;
    socklen_t fromAddrLen = sizeof fromAddr;
    char buf[1024];
    int bytes_read;
    while(1)
    {
        bytes_read = recvfrom(sock, buf, 1024, 0, (struct sockaddr *)&fromAddr, &fromAddrLen);
        char display[16] = {0};
        inet_ntop(AF_INET, &fromAddr.sin_addr.s_addr, display, sizeof display);
        buf[bytes_read-1] = '\0';
        for (int i = 0; i < 1023; ++i)
        {
            if (buf[i] == '\n'){
                buf[i] = 0;
            }
        }

        std::string tmp = std::string(buf);

        if ((buf[0] - '0' >= 3 && buf[0] - '0' <= 5) || (buf[0] - '0' == 8)){
            acceptMessage(buf[0] - '0', NULL, NULL, answerPort);
        }else if(buf[0] - '0' == 6){
            std::string from = tmp.substr(2, 24);
            struct tm time1;
            strptime(from.c_str(), "%a %b %d %X %Y", &time1);
            acceptMessage(buf[0] - '0', mktime(&time1), NULL, answerPort);
        }else if(buf[0] - '0' == 7){
            std::string from = tmp.substr(2, 24);
            struct tm time1;
            strptime(from.c_str(), "%a %b %d %X %Y", &time1);
            std::string to = tmp.substr(27, 24);
            struct tm time2;
            strptime(from.c_str(), "%a %b %d %X %Y", &time2);
            acceptMessage(buf[0] - '0', mktime(&time1), mktime(&time2), answerPort);
        }
        
        
        message msg;
        msg.type = tmp[0] - '0';
        msg.value = tmp.substr(2);
        msg.value = msg.value.substr(0, msg.value.size() - 1);

        msg.ip_adress = display;
        asctime(localtime(&msg.time));
        msg.sTime = getDate();
        messages.push_back(msg);

        tmp+=display;
        tmp+="|";
        tmp+=getDate() + "\0";
        s_lock.lock();
        file.open("log.txt", std::ios::out | std::ios::app );
        file << tmp;
        std::cout << tmp;
        file.close();
        s_lock.unlock();
    }
}
Example #2
0
::Ice::DispatchStatus
Client::CChat::___acceptMessage(::IceInternal::Incoming& __inS, const ::Ice::Current& __current)
{
    __checkMode(::Ice::Normal, __current.mode);
    ::IceInternal::BasicStream* __is = __inS.is();
    ::std::string stri;
    __is->read(stri);
    acceptMessage(stri, __current);
    return ::Ice::DispatchOK;
}
Example #3
0
 void runCurrentTest
 (
     std::string& redirectedCout,
     std::string& redirectedCerr
 )
 {            
     try
     {
         m_runningTest->reset();
         StreamRedirect coutRedir( std::cout, redirectedCout );
         StreamRedirect cerrRedir( std::cerr, redirectedCerr );
         m_runningTest->getTestCaseInfo().invoke();
         m_runningTest->ranToCompletion();
     }
     catch( TestFailureException& )
     {
         // This just means the test was aborted due to failure
     }
     catch( std::exception& ex )
     {
         acceptMessage( ex.what() );
         acceptResult( ResultWas::ThrewException );
     }
     catch( std::string& msg )
     {
         acceptMessage( msg );
         acceptResult( ResultWas::ThrewException );
     }
     catch( const char* msg )
     {
         acceptMessage( msg );
         acceptResult( ResultWas::ThrewException );
     }
     catch(...)
     {
         acceptMessage( Catch::Hub::getExceptionTranslatorRegistry().translateActiveException() );
         acceptResult( ResultWas::ThrewException );
     }
     m_info.clear();
 }
Example #4
0
	void Server::CreateConnection(asio::ip::tcp::socket socket)
	{
		//генерируем временный guid
		++connectionsCounter;
		std::string tempGuid = "TMP_" + std::to_string(connectionsCounter);
		//создаем подключение и добавляем его в список неавторизированных
		newConnections.emplace(tempGuid, std::make_shared<Connection>(*this, std::move(socket), tempGuid));
		
		//отправляем сообщение об ожидании авторизации
		JsonParser::AcceptMsgFabric acceptMessage("1.2.3");//---------------------временно
		auto strMessage = jsParser.CreateMessage(acceptMessage);
		newConnections.at(tempGuid)->WriteMessage(strMessage);

		BOOST_LOG_TRIVIAL(info) << "Add new connection " << tempGuid;
	}
Example #5
0
 void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) {
     try {
         m_runningTest->reset();
         if( m_reporter->shouldRedirectStdout() ) {
             StreamRedirect coutRedir( std::cout, redirectedCout );
             StreamRedirect cerrRedir( std::cerr, redirectedCerr );
             m_runningTest->getTestCaseInfo().invoke();
         }
         else {
             m_runningTest->getTestCaseInfo().invoke();
         }
         m_runningTest->ranToCompletion();
     }
     catch( TestFailureException& ) {
         // This just means the test was aborted due to failure
     }
     catch(...) {
         acceptMessage( getCurrentContext().getExceptionTranslatorRegistry().translateActiveException() );
         acceptResult( ResultWas::ThrewException );
     }
     m_info.clear();
 }
Example #6
0
MsgEdit::MsgEdit(QWidget *p, unsigned long uin)
        : QFrame(p),
        Uin(this, "Uin")
{
    Uin = uin;
    msg = NULL;
    tabId = -1;
    tab = NULL;
    sendEvent = NULL;
    mHistory = NULL;
    bMultiply = false;
    setWFlags(WDestructiveClose);
    QVBoxLayout *lay = new QVBoxLayout(this);
    boxSend = new QVGroupBox(this);
    lay->addWidget(boxSend);
    QFrame *frmHead = new QFrame(boxSend);
    QHBoxLayout *hLay = new QHBoxLayout(frmHead);
    btnBgColor = new CPushButton(frmHead);
    btnBgColor->setTip(i18n("Background color"));
    btnBgColor->setPixmap(Pict("bgcolor"));
    connect(btnBgColor, SIGNAL(clicked()), this, SLOT(setMsgBackgroundColor()));
    btnBgColor->hide();
    hLay->addWidget(btnBgColor);
    btnReply = new QPushButton(i18n("&Reply"), frmHead);
    btnReply->hide();
    hLay->addWidget(btnReply);
    connect(btnReply, SIGNAL(clicked()), this, SLOT(replyClick()));
    btnGrant = new QPushButton(i18n("&Grant"), frmHead);
    btnGrant->hide();
    hLay->addWidget(btnGrant);
    connect(btnGrant, SIGNAL(clicked()), this, SLOT(grantClick()));
    btnAccept = new QPushButton(i18n("&Accept"), frmHead);
    btnAccept->hide();
    hLay->addWidget(btnAccept);
    connect(btnAccept, SIGNAL(clicked()), this, SLOT(acceptMessage()));
    btnFgColor = new CPushButton(frmHead);
    btnFgColor->setTip(i18n("Text color"));
    btnFgColor->setPixmap(Pict("fgcolor"));
    connect(btnFgColor, SIGNAL(clicked()), this, SLOT(setMsgForegroundColor()));
    hLay->addSpacing(2);
    btnFgColor->hide();
    hLay->addWidget(btnFgColor);
    btnQuote = new QPushButton(i18n("&Quote"), frmHead);
    btnQuote->hide();
    hLay->addWidget(btnQuote);
    connect(btnQuote, SIGNAL(clicked()), this, SLOT(quoteClick()));
    btnRefuse = new QPushButton(i18n("&Refuse"), frmHead);
    btnRefuse->hide();
    hLay->addWidget(btnRefuse);
    declineMenu = new QPopupMenu(this);
    connect(btnRefuse, SIGNAL(clicked()), this, SLOT(refuseClick()));
    connect(declineMenu, SIGNAL(activated(int)), this, SLOT(declineMessage(int)));
    declineMenu->insertItem(reason_string(DECLINE_WITHOUT_REASON), DECLINE_WITHOUT_REASON);
    declineMenu->insertItem(reason_string(DECLINE_REASON_BUSY), DECLINE_REASON_BUSY);
    declineMenu->insertItem(reason_string(DECLINE_REASON_LATER), DECLINE_REASON_LATER);
    declineMenu->insertItem(reason_string(DECLINE_REASON_INPUT), DECLINE_REASON_INPUT);
    btnDecline = new QPushButton(i18n("&Decline"), frmHead);
    btnDecline->hide();
    btnDecline->setPopup(declineMenu);
    hLay->addWidget(btnDecline);
    btnBold = new CPushButton(frmHead);
    btnBold->setTip(i18n("Bold"));
    btnBold->setPixmap(Pict("text_bold"));
    btnBold->setToggleButton(true);
    connect(btnBold, SIGNAL(toggled(bool)), this, SLOT(setBold(bool)));
    hLay->addSpacing(2);
    btnBold->hide();
    hLay->addWidget(btnBold);
    btnForward = new QPushButton(i18n("&Forward"), frmHead);
    connect(btnForward, SIGNAL(clicked()), this, SLOT(forwardClick()));
    btnForward->hide();
    hLay->addWidget(btnForward);
    btnItalic = new CPushButton(frmHead);
    btnItalic->setTip(i18n("Italic"));
    btnItalic->setPixmap(Pict("text_italic"));
    btnItalic->setToggleButton(true);
    connect(btnItalic, SIGNAL(toggled(bool)), this, SLOT(setItalic(bool)));
    hLay->addSpacing(2);
    btnItalic->hide();
    hLay->addWidget(btnItalic);
    btnUnder = new CPushButton(frmHead);
    btnUnder->setTip(i18n("Underline"));
    btnUnder->setPixmap(Pict("text_under"));
    btnUnder->setToggleButton(true);
    connect(btnUnder, SIGNAL(toggled(bool)), this, SLOT(setUnder(bool)));
    hLay->addSpacing(2);
    btnUnder->hide();
    hLay->addWidget(btnUnder);
    btnFont = new CPushButton(frmHead);
    btnFont->setTip(i18n("Text font"));
    btnFont->setPixmap(Pict("text"));
    connect(btnFont, SIGNAL(clicked()), this, SLOT(setFont()));
    hLay->addSpacing(2);
    btnFont->hide();
    hLay->addWidget(btnFont);
#ifdef USE_SPELL
    btnSpell = new CPushButton(frmHead);
    btnSpell->setTip(i18n("Spell check"));
    btnSpell->setPixmap(Pict("spellcheck"));
    connect(btnSpell, SIGNAL(clicked()), this, SLOT(spell()));
    hLay->addSpacing(2);
    btnSpell->hide();
    hLay->addWidget(btnSpell);
#endif
    hLay->addSpacing(2);
    hLay->addStretch();
    chkClose = new QCheckBox(i18n("C&lose after send"), frmHead);
    chkClose->setChecked(pMain->CloseAfterSend());
    connect(chkClose, SIGNAL(toggled(bool)), this, SLOT(closeToggle(bool)));
    hLay->addWidget(chkClose);
    btnSend = new QPushButton(frmHead);
    connect(btnSend, SIGNAL(clicked()), this, SLOT(sendClick()));
    hLay->addWidget(btnSend);
    btnNext = new PictPushButton(frmHead);
    connect(btnNext, SIGNAL(clicked()), this, SLOT(nextClick()));
    btnNext->hide();
    hLay->addWidget(btnNext);
    phone = new QFrame(boxSend);
    phone->hide();
    QHBoxLayout *hlay = new QHBoxLayout(phone);
    QLabel *title = new QLabel(i18n("Phone:"), phone);
    hlay->addWidget(title);
    phoneEdit = new QComboBox(phone);
    phoneEdit->setEditable(true);
    phoneEdit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
    hlay->addWidget(phoneEdit);
    connect(phoneEdit, SIGNAL(textChanged(const QString&)), this, SLOT(textChanged(const QString&)));
    url   = new QFrame(boxSend);
    url->hide();
    hlay = new QHBoxLayout(url);
    title = new QLabel(i18n("URL:"), url);
    hlay->addWidget(title);
    urlEdit = new QLineEdit(url);
    hlay->addWidget(urlEdit);
    connect(urlEdit, SIGNAL(textChanged(const QString&)), this, SLOT(textChanged(const QString&)));
    file = new QFrame(boxSend);
    file->hide();
    hlay = new QHBoxLayout(file);
    title = new QLabel(i18n("File:"), file);
    hlay->addWidget(title);
    fileEdit = new EditFile(file);
    hlay->addWidget(fileEdit);
    connect(fileEdit, SIGNAL(textChanged(const QString&)), this, SLOT(textChanged(const QString&)));
    btnMultiply = new CPushButton(frmHead);
    btnMultiply->setTip(i18n("Multiply send"));
    btnMultiply->setPixmap(Pict("1rightarrow"));
    connect(btnMultiply, SIGNAL(clicked()), this, SLOT(toggleMultiply()));
    hLay->addSpacing(2);
    hLay->addWidget(btnMultiply);
    lblUsers = new QLabel(i18n("Drag users here"), boxSend);
    edit  = new EditSpell(this);
    edit->hide();
    lay->addWidget(edit);
    users = new UserTbl(this);
    users->hide();
    lay->addWidget(users);
    view  = new TextShow(this);
    view->hide();
    lay->addWidget(view);
    connect(edit, SIGNAL(textChanged()), this, SLOT(editTextChanged()));
    connect(edit, SIGNAL(currentFontChanged(const QFont&)), this, SLOT(editFontChanged(const QFont&)));
    connect(edit, SIGNAL(ctrlEnterPressed()), this, SLOT(sendClick()));
    connect(users, SIGNAL(changed()), this, SLOT(textChanged()));
    connect(pClient, SIGNAL(messageReceived(ICQMessage*)), this, SLOT(messageReceived(ICQMessage*)));
    connect(pClient, SIGNAL(event(ICQEvent*)), this, SLOT(processEvent(ICQEvent*)));
    connect(pMain, SIGNAL(chatChanged()), this, SLOT(chatChanged()));
    connect(pMain, SIGNAL(ftChanged()), this, SLOT(ftChanged()));
    setState();
    setUin(uin);
}