Exemple #1
0
void DBusHandler::statusChanged(uint state, QVariantList info)
{
    Status status;
    status.State = state;
    switch (state) {
    case WicdState::NOT_CONNECTED:
        status.Info.append("");
        break;
    case WicdState::CONNECTING:
        status.Info.append(info.at(0).toString());//"wired" or "wireless"
        if (info.at(0).toString() == "wireless")
            status.Info.append(info.at(1).toString());//None if wired, essid if wireless
        break;
    case WicdState::WIRED:
        status.Info.append(info.at(0).toString());//IP Adresss
        break;
    case WicdState::WIRELESS:
        status.Info.append(info.at(0).toString());//IP Adresss
        status.Info.append(info.at(1).toString());//essid
        status.Info.append(info.at(2).toString());//signal strength
        status.Info.append(info.at(3).toString());//internal networkid
        status.Info.append(info.at(4).toString());//bitrate
        break;
    case WicdState::SUSPENDED:
        status.Info.append("");
        break;
    default:
        break;
    }
    emit statusChange(status);
}
status_t MSNConnection::HandleFLN(Command *command) {
	// Contact went offline
	LOG(kProtocolName, liDebug, "C %lX: Processing FLN", this);
	
	BMessage statusChange(msnmsgStatusChanged);
	statusChange.AddString("passport", command->Param(0) );
	statusChange.AddInt8("status", otOffline);
	fManMsgr.SendMessage(&statusChange);
	
	return B_OK;
};
status_t MSNConnection::HandleNLN( Command * command ) {
//	XXX - We should probably look at the caps and nick	
	BString statusStr = command->Param(0);
	BString passport = command->Param(1);
	BString friendly = command->Param(2);
	BString caps = command->Param(3);

	buddymap *buddies = fManager->BuddyList();
	buddymap::iterator it = buddies->find(passport);
	Buddy *buddy;
	if (it == buddies->end()) {
		buddy = new Buddy(passport.String());
		buddies->insert(std::pair<BString, Buddy*>(passport, buddy));
	} else {
		buddy = it->second;
	};
	
	online_types status = otOffline;
	
	if (statusStr == "NLN") status = otOnline;
	if (statusStr == "BSY") status = otBusy;
	if (statusStr == "IDL") status = otIdle;
	if (statusStr == "BRB") status = otBRB;
	if (statusStr == "AWY") status = otAway;
	if (statusStr == "PHN") status = otPhone;
	if (statusStr == "LUN") status = otLunch;

	buddy->Status(status);
	buddy->Capabilities(atol(caps.String()));
	buddy->FriendlyName(friendly.String());

	if (command->Params() > 4) {
		BString obj = command->Param(4, true);
		buddy->DisplayPicture(new MSNObject(obj.String(), obj.Length()));
	};
	
	BMessage statusChange(msnmsgStatusChanged);
	statusChange.AddString("passport", passport);
	statusChange.AddInt8("status", (int8)status);
	
	fManMsgr.SendMessage(&statusChange);
	return B_OK;
}
status_t MSNConnection::HandleCHG(Command * command) {
	// Own status changed
	LOG(kProtocolName, liDebug, "C %lX: Processing CHG", this);
	
	BString status = command->Param(0);
	
	BMessage statusChange(msnmsgOurStatusChanged);
	
	if ( status == "NLN" ) {
		statusChange.AddInt8("status", otOnline);
	} else
	if ( status == "AWY" ) {
		statusChange.AddInt8("status", otAway);
	} else {
		LOG(kProtocolName, liDebug, "C %lX: Unknown status: %s", this, status.String() );
		statusChange.what = 0; // so we don't send the message.
	}
	
	if ( statusChange.what )
		fManMsgr.SendMessage(&statusChange);
	
	return B_OK;
};
std::string UserStatusChangeRequest(
    uint8_t seq,
    opendnp3::KeyChangeMethod keyChangeMethod,
    opendnp3::UserOperation userOperation,
    uint32_t statusChangeSeqNum,
    uint16_t userRole,
    uint16_t userRoleExpDays,
    const std::string& userName,
    const std::string& userPublicKeyHex,
    const std::string& certificationDataHex
)
{
	Buffer buffer(DEFAULT_MAX_APDU_SIZE);
	APDURequest apdu(buffer.GetWSlice());
	apdu.SetControl(AppControlField(true, true, false, false, seq));
	apdu.SetFunction(FunctionCode::AUTH_REQUEST);

	RSlice name(reinterpret_cast<const uint8_t*>(userName.c_str()), static_cast<uint32_t>(userName.size()));
	HexSequence userPublicKeyBuffer(userPublicKeyHex);
	HexSequence certificationDataBuffer(certificationDataHex);

	Group120Var10 statusChange(
	    keyChangeMethod,
	    userOperation,
	    statusChangeSeqNum,
	    userRole,
	    userRoleExpDays,
	    name,
	    userPublicKeyBuffer.ToRSlice(),
	    certificationDataBuffer.ToRSlice()
	);


	apdu.GetWriter().WriteFreeFormat(statusChange);

	return ToHex(apdu.ToRSlice());
}
CcomStatus::CcomStatus(QWidget * parent):QDockWidget(tr("通信状态"), parent)
{
    QVBoxLayout *vLayout;
    QHBoxLayout *hLayout;
    QWidget *widget;
    QLabel *progressLabel;
    QLabel *paraLabel, *statusLabel;
    QLabel *nameLabel;

    widget = new QWidget(this);
    vLayout = new QVBoxLayout(widget);
    hLayout = new QHBoxLayout(widget);

    nameLabel = new QLabel(tr("通信屏幕:"));
    screenNameEdit = new QLineEdit(widget);
    screenNameEdit->setFocusPolicy(Qt::NoFocus);

    //udiskListDialog = new CudiskListDialog(this);

    hLayout->addWidget(nameLabel);
    hLayout->addWidget(screenNameEdit);
    vLayout->addLayout(hLayout);

    paraLabel = new QLabel(tr("通信参数:"),widget);
    paraEdit = new QTextEdit(widget);
    paraEdit->setFixedHeight(50);
    paraEdit->setFocusPolicy(Qt::NoFocus);

    statusLabel = new QLabel(tr("通信状态:"),widget);

    statusEdit = new QTextEdit(widget);
    statusEdit->setFixedHeight(150); //通信状态
    statusEdit->setFocusPolicy(Qt::NoFocus);

    progressLabel = new QLabel(tr("进度"),widget);
    progressBar = new QProgressBar(widget);//QProgressDialog()
    progressBar->setMaximum(100);
    progressBar->setValue(0);

    hLayout = new QHBoxLayout(widget);
    hLayout->addWidget(progressLabel);
    hLayout->addWidget(progressBar);

    progressList = new QListView(widget);
    //progressList->setFixedSize(100,100);
    progressList->setFixedHeight(100);
    comThread = new CcomThread(this);

    vLayout->addWidget(paraLabel);
    vLayout->addWidget(paraEdit);
    vLayout->addWidget(statusLabel);
    vLayout->addWidget(statusEdit);
    vLayout->addWidget(progressList);
    vLayout->addLayout(hLayout);
    //vLayout->addWidget(statusEdit);
    //vLayout->addWidget(progressBar);

    clrButton = new QPushButton(tr("清空"), widget);
    hideButton = new QPushButton(tr("隐藏"), widget);
    hLayout = new QHBoxLayout(widget);
    //hLayout ->addStretch(10);
    hLayout ->addWidget(clrButton);
    hLayout ->addWidget(hideButton);
    vLayout->addLayout(hLayout);

    vLayout->addStretch(10);
    widget->setLayout(vLayout);

    widget->setFixedWidth(200);
    setWidget(widget);
    connect(this->comThread, SIGNAL(comProgressChanged(int)), this, SLOT(progressChange(int)));
    connect(this->comThread, SIGNAL(comStatusChanged(QString)), this, SLOT(statusChange(QString)));
    connect(this->comThread, SIGNAL(comEnd(bool)), this, SLOT(comEnd(bool)));
    connect(this->clrButton, SIGNAL(clicked()), this->statusEdit, SLOT(clear()));
    connect(this->clrButton, SIGNAL(clicked()), this->paraEdit, SLOT(clear()));
    connect(this->clrButton, SIGNAL(clicked()), this->screenNameEdit, SLOT(clear()));
    connect(this->clrButton, SIGNAL(clicked()), this->progressBar, SLOT(reset()));

    connect(this->hideButton, SIGNAL(clicked()), this, SLOT(hideSlot()));
    //connect(this, SIGNAL(comStart()), this->comth)
    //connect(this, SIGNAL(Start()), this, SLOT(comStart()));
    //QObject::connect(port, SIGNAL(readyRead()), this, SLOT(receive()));
    progressList->setVisible(false);
}
status_t MSNConnection::HandleUSR( Command * command ) {
	LOG(kProtocolName, liDebug, "C %lX: Processing USR", this);
	status_t result = B_ERROR;

	if (strcmp(command->Param(0), "OK") == 0) {
		Progress("MSN Login", "MSN: Logged in!", 1.0);
		
		GoOnline();
		
		BMessage statusChange(msnmsgOurStatusChanged);
		statusChange.AddInt8("status", fState);
		fManMsgr.SendMessage(&statusChange);

		/*
		 * Depending on the server protocol, server location and the
		 * account being used (non-hotmail/msn acc), the server will not
		 * respond on the PRP MFN command and our connection will break.
		 * Michael
		 */
		BString passport(fManager->Passport());
		
		if ((B_ERROR != passport.FindFirst("@hotmail")) || (B_ERROR != passport.FindFirst("@msn"))) {
			LOG(kProtocolName, liDebug, "Sending PRP MSN command" );
			
			Command *rea = new Command("PRP");
			rea->AddParam("MFN");
			rea->AddParam(fManager->DisplayName(), true);
			Send(rea);
		} else {
			LOG(kProtocolName, liDebug, "Not sending PRP MSN command!");
		};
		
		fManager->Handler()->ContactList(&fContacts);
				
		Command *adl = new Command("ADL");
		
		std::list<BString> contacts;
		std::map<BString, std::list<BString> > domainUsers;
		
		fManager->Handler()->ContactList(&contacts);
		
		// Make our contact list into a list by domain
		for (std::list<BString>::iterator iIt = contacts.begin(); iIt != contacts.end(); iIt++) {
			BString user;
			BString domain;
			
			if (SplitEmail((*iIt).String(), user, domain) == B_OK) {			
				std::map<BString, std::list<BString> >::iterator dIt = domainUsers.find(domain);
				if (dIt == domainUsers.end()) {
					std::list<BString> users;
					users.push_back(user);
					
					domainUsers[domain] = users;
				} else {
					dIt->second.push_back(user);
				};
			};
		};

		BString payload = "<ml l=\"1\">";

		// Package each contact by domain
		for (std::map<BString, std::list<BString> >::iterator dIt = domainUsers.begin(); dIt != domainUsers.end(); dIt++) {
			payload << "<d n=\"" << dIt->first << "\">";
		
			for (std::list<BString>::iterator uIt = dIt->second.begin(); uIt != dIt->second.end(); uIt++) {
				payload << "<c n=\"" << (*uIt) <<  "\" l=\"3\" t=\"1\" />";
			};
			
			payload << "</d>";
		};
		
		payload << "</ml>";
		adl->AddPayload(payload.String());
		
		Send(adl);
		
		Command *chg = new Command("CHG");
		chg->AddParam("NLN");
		BString caps = "";
		caps << kOurCaps;
		chg->AddParam( caps.String() );
		Send(chg);

		result = B_OK;
	} else {
		BString URI = command->Param(2);
		BString nonce = command->Param(3);
		BString authResp = "";
		BString authToken = "";

		SSO *auth = new SSO(NULL, fManager->Passport(), fManager->Password(), URI.String(),
			nonce.String());

		result = auth->Response(authToken, authResp);

		if (result == B_OK) {
			Command *reply = new Command("USR");
			reply->AddParam("SSO");
			reply->AddParam("S");
			reply->AddParam(authToken.String());
			reply->AddParam(authResp.String());
			
			reply->Debug();
			
			Send(reply);
		};

	};
	
	return result;
}