Beispiel #1
0
void MT500::getData()
{
    QString line;
    int count = 0;
    QFile file("/home/administrator/Desktop/data.log");
    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        QTextStream in(&file);
        while (!in.atEnd()) {
            line = in.readLine();
            count++;
            if(count > initialCount) {
                recordCnt++;
                if(recordCnt > 500){
                    ui->DataBrowser->clear();
                    recordCnt =0;
                }
                initialCount = count;
                if(line.length() > 0) {
                    sendRaw(line.trimmed());
                    sendBase(line.trimmed(), true);
                    QByteArray msgToSend;
                    msgToSend = encode(line.trimmed());
                    sendIFLOWS(msgToSend);
                }
            }
        }
    }
    pollTimer->start(500);
}
Beispiel #2
0
void MT500::testConnection()
{
    for(int i = 0; i < 6; i++) {
        if(!ipArray[i].ip.isEmpty()){
            QString msg = "[" + QDateTime::currentDateTime().toString("MM/dd/yyyy hh:mm:ss") + "] ";
            QTcpSocket * test = new QTcpSocket;
            test->connectToHost(QHostAddress(ipArray[i].ip), ipArray[i].port);
            if(test->waitForConnected(2000)) {
                msg += ipArray[i].ip + ": Test Message Sent";
                ui->testBrowser->append("<font color=green>" + msg + "</font>");
                test->abort();
            }
            else {
                msg += ipArray[i].ip + ": Failed to Connect";
                ui->testBrowser->append("<font color=red>" + msg + "</font>");
            }
        }
    }
    if(!initial) {
        QString fips = fipsNo.trimmed().remove("VAZ");
        QString msgToSend = "A 100 " + QDateTime::currentDateTime().toString("MM/dd/yyyy hh:mm:ss") + " " + QString::number(boxGID);
        sendBase(msgToSend, true);
        sendRaw(msgToSend);
        sendRawStrtoIflows(QString(encode(msgToSend)));
    }
    else initial = false;
}
void tvNetworkControl::sendIDPacket(const QString &remoteIP, const QString &ID, const QString &name)
{
    const char packetStart[] = {
        0x00, 0x13, 0x00, 0x69, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x2e, 0x69, 0x61, 0x70, 0x70, 0x2e, 0x73,
        0x61, 0x6d, 0x73, 0x75, 0x6e, 0x67
    };

    const QByteArray remoteIPEncoded = encodeString(remoteIP);
    const QByteArray remoteIDEncoded = encodeString(ID);
    const QByteArray remoteNameEncoded = encodeString(name);

    const char payLoadStart[] = {
        0x64, 0x00
    };

    QByteArray payLoad;
    payLoad.append(QByteArray::fromRawData(payLoadStart, sizeof(payLoadStart)));
    payLoad.append(QByteArray::fromRawData(remoteIPEncoded.data(), remoteIPEncoded.size()));
    payLoad.append(QByteArray::fromRawData(remoteIDEncoded.data(), remoteIDEncoded.size()));
    payLoad.append(QByteArray::fromRawData(remoteNameEncoded.data(), remoteNameEncoded.size()));
    const qint16 payLoadSize = payLoad.size();

    QByteArray packet;
    QDataStream stream(&packet, QIODevice::WriteOnly);
    stream.writeRawData(packetStart, sizeof(packetStart));
    stream.setByteOrder(QDataStream::LittleEndian);
    stream << payLoadSize;
    stream.setByteOrder(QDataStream::BigEndian);
    stream.writeRawData(payLoad, payLoadSize);

    if (m_socket) {
        emit logText(tr("=========== <b>Send ID Datagram</b> ===========<br>%1").arg(byteArrayToHexaString(packet)));
        sendRaw(packet);
    }
}
DWORD IRCMsgThread::Run() {
	onSysMsg(L"IRCMsgThread Start");
	iStatus=IRC_NORMAL;
	IRCMsgQueue.clear();
	unsigned int bufferlen;
	std::string recvstring,msg,umsg; //TwitchIRC use MultiByte
	while(!bKillThread ) { 	
		//Receive First
		bufferlen=0;		
		memset(buffer, 0, DEFAULT_BUFLEN);
		if(TheSocketPtr->recv_data((char*)buffer, bufferlen)) { //Disconnected
			iStatus=IRC_DISCONNECTED;
			break;
		}
		recvstring=std::string(buffer,bufferlen);
		//onDebugMsg(L"%ls",from_utf8(recvstring).c_str());
		if(recvstring.compare(":tmi.twitch.tv NOTICE * :Login unsuccessful\r\n")==0 || //Twitch
		   recvstring.compare(":tmi.twitch.tv NOTICE * :Error encountered while attempting login\r\n")==0 ){ //Justin
			Sleep(100); //Wait for logging
			onSysMsg(L"Login unsuccessful");
			iStatus=IRC_WRONGLOGIN;
			break;
		}//else if(recvstring.compare(":[email protected] PRIVMSG #append :break\r\n")==0){TheSocketPtr->CloseSocket();}
		//Basic parsing: make it into a string, check for PING, if not-send for further parsing.
		std::stringstream recvstr(recvstring);
		while( recvstr.tellg() < bufferlen ) {
			std::getline(recvstr,msg,'\n');
			//Old Style
			//:[email protected] PRIVMSG #ptken :what song is this ?
			//PING LAG1967655232
			//int colon_pos = (int)msg.find(":");
			//if (msg[0] != ':' && colon_pos > 0) msg=msg.substr(colon_pos); //if an irc message begins with " ", then trim the leading spaces   
			//
			//New Style
			// @color=#FF4500;display-name=Gm470520;emotes=;mod=0;room-id=47281189;subscriber=1;turbo=0;user-id=24255667;user-type= :[email protected] PRIVMSG #tetristhegrandmaster3 :這片到底在沖三小w
			int at_pos = (int)msg.find("@");
			if (msg[0] != '@' && at_pos > 0) msg=msg.substr(at_pos); //if an irc message begins with " ", then trim the leading spaces   
			if (msg[msg.length()-1]=='\r') msg=msg.substr(0,msg.length()-1); //trim the CR: getline only trim the LF		                   
			log(from_utf8(msg), LogType(RECEIVE)); //Although log file is in UTF8....using vswprintf
			//Ping Check
			umsg=msg.substr(0,5);
			ToUpperString(umsg);
            if (!umsg.compare("PING ")) sendRaw( L"PONG " + from_utf8(msg.substr(5)) ); // respond to PINGs //Reply Immediately 
			//Then parse the message
            else parseMessage(from_utf8(msg)); 
		}
		Sleep(100);
	}
	//Determine the reason to break the loop.
	if(!bKillThread) {
		if(iStatus==IRC_DISCONNECTED) onSysMsg(L"IRCMsgThread: Disconnect Unexpectedly");
		if(iStatus==IRC_WRONGLOGIN) onSysMsg(L"IRCMsgThread: Wrong Login Information");
	}
	else iStatus=IRC_CLOSED;
	//onDebugMsg(L"[Last Buffer]%ls",from_utf8(recvstring).c_str());
	onSysMsg(L"IRCMsgThread Close");
	thread=0;
	return 0;
}
//==============================================================================
void MinosServerConnection::sendAction( XStanza *a )
{
   // use the stanza to send itself
   a->setNextId();   // only happens if no Id already

   std::string s = a->getActionMessage();
   sendRaw( s.c_str() );
}
bool HHVM_FUNCTION(fastcgi_finish_request) {
  auto context = g_context.getNoCheck();
  auto transport = context->getTransport();
  context->obFlushAll();
  String content = context->obDetachContents();
  transport->sendRaw((void*)content.data(), content.size());
  transport->onSendEnd();
  return true;
}
Beispiel #7
0
/*!
    Sends a \a command to the server.

    \warning The command must be allocated on the heap since the session
    will take ownership of the command and delete it once it has been sent.
    It is not safe to access the command after it has been sent.

    \sa sendRaw()
 */
bool IrcSession::sendCommand(IrcCommand* command)
{
    bool res = false;
    if (command)
    {
        res = sendRaw(command->toString());
        command->deleteLater();
    }
    return res;
}
Beispiel #8
0
void Socket::sendPacket(byte* data, uint32_t len)
{
	byte buf[SEND_PACKET_MAX_SIZE];

	if (mEQNet->mode >= MODE_WORLD_TO_ZONE)
	{
		// protocol opcode
		uint16_t* ptr = (uint16_t*)buf;
		*ptr = *(uint16_t*)data;

		if (len <= SEND_PACKET_NO_COMPRESSION_THRESHOLD)
		{
			// not worth compressing, but we need to add the 'not compressed' flag
			// protocol opcode + 0xa5 + everything else

			// not compressed flag
			buf[2] = 0xa5;

			// everything else
			if (len > 2)
				memcpy(buf + 3, data + 2, len - 2);

			++len; // add compressed flag
		}
		else
		{
			// do compression
			// protocol opcode + 'Z' + compressed everything else

			// compressed flag
			buf[2] = 'Z';

			// everythign else, compressed
			len -= 2;
			data += 2;
			Compression::compressBlock(mEQNet, data, len);
			memcpy(buf + 3, data, len);

			len += 3; // add protocol opcode back, plus compressed flag
		}

		data = buf;
	}

	// write crc
	// all packets are allocated with 2 extra bytes at the end to hold the CRC
	uint16_t* crc = (uint16_t*)(data + len);
	*crc = CRC::calcOutbound(data, len, getCRCKey());

	// send
	sendRaw(data, len + 2);
}
void sendCode(int repeat) {
  if (codeType == NEC) {
    if (repeat) {
      sendNEC(REPEAT, codeLen);
      printf("Sent NEC repeat\n");
    } 
    else {
      sendNEC(codeValue, codeLen);
      printf("Sent NEC ");
      printf("%X", codeValue);
    }
  } 
  else if (codeType == SONY) {
    sendSony(codeValue, codeLen);
    printf("Sent Sony ");
    printf("%X", codeValue);
  } 
  else if (codeType == RC5 || codeType == RC6) {
    if (!repeat) {
      // Flip the toggle bit for a new button press
      toggle = 1 - toggle;
    }
    // Put the toggle bit into the code to send
    codeValue = codeValue & ~(1 << (codeLen - 1));
    codeValue = codeValue | (toggle << (codeLen - 1));
    if (codeType == RC5) {
      printf("Sent RC5 ");
      printf("%X", codeValue);
      sendRC5(codeValue, codeLen);
    } 
    else {
      sendRC6(codeValue, codeLen);
      printf("Sent RC6 ");
      printf("%X\n", codeValue);
    }
  } 
  else if (codeType == UNKNOWN /* i.e. raw */) {
    // Assume 38 KHz
    sendRaw(rawCodes, codeLen, 38000);
    printf("Sent raw\n");
  }
}
Beispiel #10
0
void MT500::readData()
{
    validMsgTimer->start(1000);
    QString line;
    ba = inPort->readAll();
    msg[byteCount] = ba[0];
    byteCount++;
    if(byteCount == 4) {
        validMsgTimer->stop();
        line = decode(msg);
        if(line == "NA") {
            validMsgTimer->start(1000);
            byteCount--;
            QByteArray temp;
            temp[0] = msg[1];
            temp[1] = msg[2];
            temp[2] = msg[3];
            msg = temp;
        }
        else {
            byteCount = 0;
            recordCnt++;
            if(recordCnt > 500){
                ui->DataBrowser->clear();
                recordCnt =0;
            }
            QStringList fields = line.trimmed().split(" ");
            int gid = fields.at(1).trimmed().toInt();
            if(inFilter(boxGID, gid)) {
                sendRaw(line.trimmed());
                sendIFLOWS(msg);
                sendBase(line.trimmed(), true);
            }
            else {
                ui->DataBrowser->append("<font color=blue>"+line.trimmed()+"</font>");
                sendBase(line.trimmed(), false);
            }

        }
    }
}
void tvNetworkControl::sendKey(const QString &key)
{

#ifdef QT5
    QByteArray keyByteArray(key.toLatin1());
#else
    QByteArray keyByteArray(key.toAscii());
#endif

    keyByteArray = keyByteArray.toBase64();

    const char rawKeyPacketStart[] = {
        0x00, 0x13, 0x00, 0x69, 0x70, 0x68, 0x6f, 0x6e, 0x65, 0x2e, 0x69, 0x61, 0x70, 0x70, 0x2e, 0x73,
        0x61, 0x6d, 0x73, 0x75, 0x6e, 0x67
    };

    const char payloadStart[] = {0x00, 0x00, 0x00};

    const qint16 keySize = keyByteArray.size();
    const qint16 payloadSize = keyByteArray.size() + 5; // 5 is 3 0x00 bytes + 2 bytes for the key code size

    QByteArray keyPacket;
    QDataStream stream(&keyPacket, QIODevice::WriteOnly);
    stream.writeRawData(rawKeyPacketStart, sizeof(rawKeyPacketStart));
    stream.setByteOrder(QDataStream::LittleEndian);
    stream << payloadSize;
    stream.setByteOrder(QDataStream::BigEndian);
    stream.writeRawData(payloadStart, sizeof(payloadStart));
    stream.setByteOrder(QDataStream::LittleEndian);
    stream << keySize;
    stream.setByteOrder(QDataStream::BigEndian);
    stream.writeRawData(keyByteArray, keyByteArray.size());

    if (m_socket) {
        emit logText(tr("============ <b>Send Datagram</b> =============<br>%1").arg(byteArrayToHexaString(keyPacket)));
        sendRaw(keyPacket);
    }
}
/**
 * send a response to client
 * @param int http code
 * @param string http code text
 * @param string response
 */
void HttpJailServer::send(int code, const string &codeText, const string &response){
	string output;
	output +="HTTP/1.1 "+ Util::itos(code)+" "+codeText+"\r\n";
	if(code != 100){
		output += "Server: vpl-jail-system "+string(Util::version())+"\r\n";
		output += "Connection: close\r\n";
		output += "Content-Length: " + Util::itos(response.size()) + "\r\n";
		syslog(LOG_DEBUG,"Response Content-Length: %lu",(unsigned long)response.size());
		output += "Content-Type: text/";
		if(code==200 && response.find("<!DOCTYPE html") != 0)
			output += "xml";
		else
			output += "html";
		output += ";chartype=UTF-8\r\n\r\n";
		output += response;
	}else{
		output += "\r\n";
	}
	sendRaw(output);
	if(code != 100){ //If code != CONTINUE
		socket->close();
	}
}
  int Transceiver::packSend(byte1_t id, const byte1_t* p_data)
  {
    size_t actual_len;
    //id invalid
    if(!(actual_len = lengthByID(id)))
      return -2;
  
    Packet p;
    p.sync = 0x00;
    p.ID = id;
    p.index = _send_index++;

    memcpy(p.data, p_data, actual_len);
    //Fill the unused memory in p.data with '\0'
    memset(p.data + actual_len, '\0', sizeof(p.data) - actual_len);

    //CRC
    p.checksum = Protocol::crc16Gen(&(p.ID), 19, _crc_gen);
    //COBS
    Protocol::cobsEncode(&(p.ohb), 23, p.sync);
    
    return sendRaw((byte1_t*)(&p), sizeof(Packet));
  }
void Communicator::sendlogin() {
  long messageLen = username.length() + 2;
  char message[messageLen];
  sprintf(message, "l;%s", username.c_str());
  sendRaw(message);
}
void Communicator::sendCommand(int keys) {
  long messageLen = username.length() + 10;
  char message[messageLen];
  sprintf(message, "p;%s;%d", username.c_str(), keys);
  sendRaw(message);
}
Beispiel #16
0
vmime::size_t testSocket::sendRawNonBlocking(const vmime::byte_t* buffer, const size_t count)
{
    sendRaw(buffer, count);
    return count;
}
void IRSendRev::Send(unsigned char *idata, unsigned char ifreq)
{
    int len = idata[0];
    unsigned char start_high    = idata[1];
    unsigned char start_low     = idata[2];
    unsigned char nshort        = idata[3];
    unsigned char nlong         = idata[4];
    unsigned char datalen       = idata[5];

    unsigned int *pSt = (unsigned int *)malloc((4+datalen*16)*sizeof(unsigned int));

    if(NULL == pSt)
    {
#if __DEBUG
        Serial.println("not enough place!!\r\n");
#endif
        exit(1);
    }

#if __DEBUG
    Serial.println("begin to send ir:\r\n");
    Serial.print("ifreq = ");Serial.println(ifreq);
    Serial.print("len = ");Serial.println(len);
    Serial.print("start_high = ");Serial.println(start_high);
    Serial.print("start_low = ");Serial.println(start_low);
    Serial.print("nshort = ");Serial.println(nshort);
    Serial.print("nlong = ");Serial.println(nlong);
    Serial.print("datalen = ");Serial.println(datalen);
#endif

    pSt[0] = start_high*50;
    pSt[1] = start_low*50;

    for(int i = 0; i<datalen; i++)
    {
        for(int j = 0; j<8; j++)
        {
            if(idata[6+i] & 0x01<<(7-j))
            {
                pSt[16*i + 2*j + 2] = nshort*50;
                pSt[16*i + 2*j+3]   = nlong*50;
            }
            else
            {
                pSt[16*i + 2*j+2]   = nshort*50;
                pSt[16*i + 2*j+3]   = nshort*50;
            }
        }
    }

    pSt[2+datalen*16]   = nshort*50;
    pSt[2+datalen*16+1] = nshort*50;

#if __DEBUG
    for(int i = 0; i<4+datalen*16; i++)
    {
        Serial.print(pSt[i]);Serial.print("\t");
    }
    Serial.println();
#endif
    sendRaw(pSt, 4+datalen*16, ifreq);
    free(pSt);
    
}
void MessageQueue::send(const Packet& packet) {
	sendRaw(packet.serialize());
}
Beispiel #19
0
// See XB::sendRaw
uint8_t XB::send(XBpacket packet) {
    return sendRaw(packet.ID, packet.destAddr, packet.options, packet.length, packet.message);
}
Beispiel #20
0
void out::DepthMap::send(const ::DepthMap &image)
{
    sendRaw(port::DepthMap::variant(image));
}
Beispiel #21
0
testSocket::size_type testSocket::sendRawNonBlocking(const char* buffer, const size_type count)
{
	sendRaw(buffer, count);
	return count;
}
Beispiel #22
0
int Irc::Session::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: connected(); break;
        case 1: welcomed(); break;
        case 2: reconnecting(); break;
        case 3: disconnected(); break;
        case 4: bufferAdded((*reinterpret_cast< Irc::Buffer*(*)>(_a[1]))); break;
        case 5: bufferRemoved((*reinterpret_cast< Irc::Buffer*(*)>(_a[1]))); break;
        case 6: capabilitiesListed((*reinterpret_cast< const QStringList(*)>(_a[1]))); break;
        case 7: capabilitiesAcked((*reinterpret_cast< const QStringList(*)>(_a[1]))); break;
        case 8: capabilitiesNotAcked((*reinterpret_cast< const QStringList(*)>(_a[1]))); break;
        case 9: msgJoined((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break;
        case 10: msgParted((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break;
        case 11: msgQuit((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break;
        case 12: msgNickChanged((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break;
        case 13: msgModeChanged((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3])),(*reinterpret_cast< const QString(*)>(_a[4]))); break;
        case 14: msgTopicChanged((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break;
        case 15: msgInvited((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break;
        case 16: msgKicked((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3])),(*reinterpret_cast< const QString(*)>(_a[4]))); break;
        case 17: msgMessageReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break;
        case 18: msgNoticeReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break;
        case 19: msgCtcpRequestReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break;
        case 20: msgCtcpReplyReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break;
        case 21: msgCtcpActionReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break;
        case 22: msgNumericMessageReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< uint(*)>(_a[2])),(*reinterpret_cast< const QStringList(*)>(_a[3]))); break;
        case 23: msgUnknownMessageReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QStringList(*)>(_a[2]))); break;
        case 24: connectToServer((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< quint16(*)>(_a[2]))); break;
        case 25: connectToServer((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 26: connectToServer(); break;
        case 27: reconnectToServer(); break;
        case 28: disconnectFromServer(); break;
        case 29: { bool _r = raw((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 30: { bool _r = motd();
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 31: { bool _r = join((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 32: { bool _r = join((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 33: { bool _r = part((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 34: { bool _r = part((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 35: { bool _r = quit((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 36: { bool _r = quit();
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 37: { bool _r = names((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 38: { bool _r = list((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 39: { bool _r = list();
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 40: { bool _r = whois((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 41: { bool _r = whowas((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 42: { bool _r = mode((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 43: { bool _r = mode((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 44: { bool _r = topic((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 45: { bool _r = topic((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 46: { bool _r = invite((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 47: { bool _r = kick((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 48: { bool _r = kick((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 49: { bool _r = message((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 50: { bool _r = notice((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 51: { bool _r = ctcpAction((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 52: { bool _r = ctcpRequest((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 53: { bool _r = ctcpReply((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 54: requestCapabilities((*reinterpret_cast< const QStringList(*)>(_a[1]))); break;
        case 55: clearCapabilities(); break;
        case 56: { bool _r = sendRaw((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 57: { bool _r = cmdJoin((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 58: { bool _r = cmdJoin((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 59: { bool _r = cmdPart((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 60: { bool _r = cmdPart((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 61: { bool _r = cmdQuit((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 62: { bool _r = cmdQuit();
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 63: { bool _r = cmdNames((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 64: { bool _r = cmdList((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 65: { bool _r = cmdList();
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 66: { bool _r = cmdWhois((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 67: { bool _r = cmdMode((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 68: { bool _r = cmdMode((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 69: { bool _r = cmdTopic((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 70: { bool _r = cmdTopic((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 71: { bool _r = cmdInvite((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 72: { bool _r = cmdKick((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 73: { bool _r = cmdKick((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 74: { bool _r = cmdMessage((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 75: { bool _r = cmdNotice((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 76: { bool _r = cmdCtcpAction((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 77: { bool _r = cmdCtcpRequest((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 78: { bool _r = cmdCtcpReply((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 79: d_func()->_q_connected(); break;
        case 80: d_func()->_q_disconnected(); break;
        case 81: d_func()->_q_reconnect(); break;
        case 82: d_func()->_q_error(); break;
        case 83: d_func()->_q_state((*reinterpret_cast< QAbstractSocket::SocketState(*)>(_a[1]))); break;
        case 84: d_func()->_q_readData(); break;
        case 85: d_func()->_q_joined((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 86: d_func()->_q_parted((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break;
        case 87: d_func()->_q_quit((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break;
        case 88: d_func()->_q_nickChanged((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break;
        case 89: d_func()->_q_modeChanged((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break;
        case 90: d_func()->_q_topicChanged((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break;
        case 91: d_func()->_q_invited((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break;
        case 92: d_func()->_q_kicked((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2])),(*reinterpret_cast< const QString(*)>(_a[3]))); break;
        case 93: d_func()->_q_messageReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break;
        case 94: d_func()->_q_noticeReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break;
        case 95: d_func()->_q_ctcpRequestReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break;
        case 96: d_func()->_q_ctcpReplyReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break;
        case 97: d_func()->_q_ctcpActionReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); break;
        case 98: d_func()->_q_numericMessageReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< uint(*)>(_a[2])),(*reinterpret_cast< const QStringList(*)>(_a[3]))); break;
        case 99: d_func()->_q_unknownMessageReceived((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QStringList(*)>(_a[2]))); break;
        default: ;
        }
        _id -= 100;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QStringList*>(_v) = autoJoinChannels(); break;
        case 1: *reinterpret_cast< int*>(_v) = autoReconnectDelay(); break;
        case 2: *reinterpret_cast< QByteArray*>(_v) = encoding(); break;
        case 3: *reinterpret_cast< QString*>(_v) = host(); break;
        case 4: *reinterpret_cast< QString*>(_v) = ident(); break;
        case 5: *reinterpret_cast< QString*>(_v) = nick(); break;
        case 6: *reinterpret_cast<int*>(_v) = QFlag(options()); break;
        case 7: *reinterpret_cast< QString*>(_v) = password(); break;
        case 8: *reinterpret_cast< quint16*>(_v) = port(); break;
        case 9: *reinterpret_cast< QString*>(_v) = realName(); break;
        case 10: *reinterpret_cast< QStringList*>(_v) = supportedCapabilities(); break;
        case 11: *reinterpret_cast< QStringList*>(_v) = enabledCapabilities(); break;
        }
        _id -= 12;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setAutoJoinChannels(*reinterpret_cast< QStringList*>(_v)); break;
        case 1: setAutoReconnectDelay(*reinterpret_cast< int*>(_v)); break;
        case 2: setEncoding(*reinterpret_cast< QByteArray*>(_v)); break;
        case 3: setHost(*reinterpret_cast< QString*>(_v)); break;
        case 4: setIdent(*reinterpret_cast< QString*>(_v)); break;
        case 5: setNick(*reinterpret_cast< QString*>(_v)); break;
        case 6: setOptions(QFlag(*reinterpret_cast<int*>(_v))); break;
        case 7: setPassword(*reinterpret_cast< QString*>(_v)); break;
        case 8: setPort(*reinterpret_cast< quint16*>(_v)); break;
        case 9: setRealName(*reinterpret_cast< QString*>(_v)); break;
        }
        _id -= 12;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 12;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 12;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 12;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 12;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 12;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 12;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Beispiel #23
0
void SASLSocket::send(const string& buffer) {

	sendRaw(reinterpret_cast <const byte_t*>(buffer.data()), buffer.length());
}
Beispiel #24
0
static int
send_kstat(JNIEnv* env, jclass cls, kstat_ctl_t* kc, kstat_t* ksp)
{
    union {
        kstat_named_t knamed;
        kstat_intr_t kintr;
        kstat_timer_t ktimer;
        kstat_io_t kio;
    } *ksdata;

    char* datap;

    if (sendAttrs(env, cls,
                  ksp->ks_crtime, ksp->ks_kid, ksp->ks_module,
                  ksp->ks_instance, ksp->ks_name, ksp->ks_type, ksp->ks_class,
                  ksp->ks_snaptime) < 0)
        return -1;

    /*
     * The docs are a little light on what the semantics are when the
     * third argument is provided to kstat_read() -- all the obvious
     * options seem to lead to memory corruption.
     */
    if (kstat_read(kc, ksp, 0) < 0) {
        perror("kstat_read");
        return -1;
    }

    if (ksp->ks_type == KSTAT_TYPE_RAW)
        return sendRaw(env, cls, ksp->ks_data, ksp->ks_data_size);

    ksdata = ksp->ks_data;
    switch(ksp->ks_type) {

    case KSTAT_TYPE_INTR:
        return sendIntr(env, cls, ksdata->kintr.intrs);

    case KSTAT_TYPE_IO:
        return sendIOStat(env, cls,
                          ksdata->kio.nread, ksdata->kio.nwritten,
                          ksdata->kio.reads, ksdata->kio.writes,
                          ksdata->kio.wtime, ksdata->kio.wlentime,
                          ksdata->kio.wlastupdate,
                          ksdata->kio.rtime, ksdata->kio.rlentime,
                          ksdata->kio.rlastupdate,
                          ksdata->kio.wcnt, ksdata->kio.rcnt);

    case KSTAT_TYPE_NAMED:
    case KSTAT_TYPE_TIMER:
        /* These types have multiple data elements */

        datap = ksp->ks_data;

        for (int i = 0; i < ksp->ks_ndata; i++) {
            if (ksp->ks_type == KSTAT_TYPE_NAMED) {
                send_named_kstat(env, cls, (kstat_named_t*) datap);
                datap += sizeof (kstat_named_t);
            }
            else {
                send_timer_kstat(env, cls, (kstat_timer_t*) datap);
                datap += sizeof (kstat_timer_t);
            }
        }
        return 0;

    } /* case */
}
Beispiel #25
0
void SASLSocket::send(const string& buffer)
{
	sendRaw(buffer.data(), buffer.length());
}
Beispiel #26
0
 void
 BasicModem::send(const std::string& str)
 {
   getTask()->inf("send: %s", Streams::sanitize(str).c_str());
   sendRaw((uint8_t*)str.c_str(), str.size());
 }
Beispiel #27
0
void posixSocket::send(const vmime::string& buffer)
{
	sendRaw(buffer.data(), buffer.length());
}
bool LocalCommunication::send(QString message, QLocalSocket *socket)
{
    return sendRaw(message.toUtf8(), socket);
}
Beispiel #29
0
void SASLSocket::send(const char* str) {

	sendRaw(reinterpret_cast <const byte_t*>(str), strlen(str));
}
Beispiel #30
0
void IMAPConnection::authenticateSASL()
{
	if (!dynamicCast <security::sasl::SASLAuthenticator>(getAuthenticator()))
		throw exceptions::authentication_error("No SASL authenticator available.");

	const std::vector <string> capa = getCapabilities();
	std::vector <string> saslMechs;

	for (unsigned int i = 0 ; i < capa.size() ; ++i)
	{
		const string& x = capa[i];

		if (x.length() > 5 &&
		    (x[0] == 'A' || x[0] == 'a') &&
		    (x[1] == 'U' || x[1] == 'u') &&
		    (x[2] == 'T' || x[2] == 't') &&
		    (x[3] == 'H' || x[3] == 'h') &&
		    x[4] == '=')
		{
			saslMechs.push_back(string(x.begin() + 5, x.end()));
		}
	}

	if (saslMechs.empty())
		throw exceptions::authentication_error("No SASL mechanism available.");

	std::vector <shared_ptr <security::sasl::SASLMechanism> > mechList;

	shared_ptr <security::sasl::SASLContext> saslContext =
		make_shared <security::sasl::SASLContext>();

	for (unsigned int i = 0 ; i < saslMechs.size() ; ++i)
	{
		try
		{
			mechList.push_back
				(saslContext->createMechanism(saslMechs[i]));
		}
		catch (exceptions::no_such_mechanism&)
		{
			// Ignore mechanism
		}
	}

	if (mechList.empty())
		throw exceptions::authentication_error("No SASL mechanism available.");

	// Try to suggest a mechanism among all those supported
	shared_ptr <security::sasl::SASLMechanism> suggestedMech =
		saslContext->suggestMechanism(mechList);

	if (!suggestedMech)
		throw exceptions::authentication_error("Unable to suggest SASL mechanism.");

	// Allow application to choose which mechanisms to use
	mechList = dynamicCast <security::sasl::SASLAuthenticator>(getAuthenticator())->
		getAcceptableMechanisms(mechList, suggestedMech);

	if (mechList.empty())
		throw exceptions::authentication_error("No SASL mechanism available.");

	// Try each mechanism in the list in turn
	for (unsigned int i = 0 ; i < mechList.size() ; ++i)
	{
		shared_ptr <security::sasl::SASLMechanism> mech = mechList[i];

		shared_ptr <security::sasl::SASLSession> saslSession =
			saslContext->createSession("imap", getAuthenticator(), mech);

		saslSession->init();

		shared_ptr <IMAPCommand> authCmd;

		if (saslSession->getMechanism()->hasInitialResponse())
		{
			byte_t* initialResp = 0;
			size_t initialRespLen = 0;

			saslSession->evaluateChallenge(NULL, 0, &initialResp, &initialRespLen);

			string encodedInitialResp(saslContext->encodeB64(initialResp, initialRespLen));
			delete [] initialResp;

			if (encodedInitialResp.empty())
				authCmd = IMAPCommand::AUTHENTICATE(mech->getName(), "=");
			else
				authCmd = IMAPCommand::AUTHENTICATE(mech->getName(), encodedInitialResp);
		}
		else
		{
			authCmd = IMAPCommand::AUTHENTICATE(mech->getName());
		}

		authCmd->send(dynamicCast <IMAPConnection>(shared_from_this()));

		for (bool cont = true ; cont ; )
		{
			std::auto_ptr <IMAPParser::response> resp(m_parser->readResponse());

			if (resp->response_done() &&
			    resp->response_done()->response_tagged() &&
			    resp->response_done()->response_tagged()->resp_cond_state()->
			    	status() == IMAPParser::resp_cond_state::OK)
			{
				m_socket = saslSession->getSecuredSocket(m_socket);
				return;
			}
			else
			{
				std::vector <IMAPParser::continue_req_or_response_data*>
					respDataList = resp->continue_req_or_response_data();

				string response;
				bool hasResponse = false;

				for (unsigned int i = 0 ; i < respDataList.size() ; ++i)
				{
					if (respDataList[i]->continue_req())
					{
						response = respDataList[i]->continue_req()->resp_text()->text();
						hasResponse = true;
						break;
					}
				}

				if (!hasResponse)
				{
					cont = false;
					continue;
				}

				byte_t* challenge = 0;
				size_t challengeLen = 0;

				byte_t* resp = 0;
				size_t respLen = 0;

				try
				{
					// Extract challenge
					saslContext->decodeB64(response, &challenge, &challengeLen);

					// Prepare response
					saslSession->evaluateChallenge
						(challenge, challengeLen, &resp, &respLen);

					// Send response
					const string respB64 = saslContext->encodeB64(resp, respLen) + "\r\n";
					sendRaw(utility::stringUtils::bytesFromString(respB64), respB64.length());

					if (m_tracer)
						m_tracer->traceSendBytes(respB64.length() - 2, "SASL exchange");

					// Server capabilities may change when logged in
					invalidateCapabilities();
				}
				catch (exceptions::sasl_exception& e)
				{
					if (challenge)
					{
						delete [] challenge;
						challenge = NULL;
					}

					if (resp)
					{
						delete [] resp;
						resp = NULL;
					}

					// Cancel SASL exchange
					sendRaw(utility::stringUtils::bytesFromString("*\r\n"), 3);

					if (m_tracer)
						m_tracer->traceSend("*");
				}
				catch (...)
				{
					if (challenge)
						delete [] challenge;

					if (resp)
						delete [] resp;

					throw;
				}

				if (challenge)
					delete [] challenge;

				if (resp)
					delete [] resp;
			}
		}
	}

	throw exceptions::authentication_error
		("Could not authenticate using SASL: all mechanisms failed.");
}