Beispiel #1
0
void Client::groupChatChangeNick(const QString &host, const QString &room, const QString &nick, const Status &_s)
{
	Jid jid(room + "@" + host + "/" + nick);
	for(QValueList<GroupChat>::Iterator it = d->groupChatList.begin(); it != d->groupChatList.end(); it++) {
		GroupChat &i = *it;
		if(i.j.compare(jid, false)) {
			i.j = jid;

			Status s = _s;
			s.setIsAvailable(true);

			JT_Presence *j = new JT_Presence(rootTask());
			j->pres(jid, s);
			j->go(true);

			break;
		}
	}
}
Beispiel #2
0
void WhatsAppProto::AddChatUser(WAChatInfo *pInfo, const TCHAR *ptszJid)
{
	std::string jid((char*)_T2A(ptszJid));
	MCONTACT hContact = ContactIDToHContact(jid);
	if (hContact && !db_get_b(hContact, "CList", "NotInList", 0))
		return;

	PROTOSEARCHRESULT psr = { 0 };
	psr.cbSize = sizeof(psr);
	psr.flags = PSR_TCHAR;
	psr.id.t = (TCHAR*)ptszJid;
	psr.nick.t = GetChatUserNick(jid);

	ADDCONTACTSTRUCT acs = { 0 };
	acs.handleType = HANDLE_SEARCHRESULT;
	acs.szProto = m_szModuleName;
	acs.psr = &psr;
	CallService(MS_ADDCONTACT_SHOW, (WPARAM)pcli->hwndContactList, (LPARAM)&acs);
}
Beispiel #3
0
void Client::groupChatLeave(const QString &host, const QString &room)
{
	Jid jid(room + "@" + host);
	for(QValueList<GroupChat>::Iterator it = d->groupChatList.begin(); it != d->groupChatList.end(); it++) {
		GroupChat &i = *it;

		if(!i.j.compare(jid, false))
			continue;

		i.status = GroupChat::Closing;
		debug(QString("Client: Leaving: [%1]\n").arg(i.j.full()));

		JT_Presence *j = new JT_Presence(rootTask());
		Status s;
		s.setIsAvailable(false);
		j->pres(i.j, s);
		j->go(true);
	}
}
void jConference::handleMUCMessage (MUCRoom *room, const Message &msg, bool privateMessage)
{
	if ( privateMessage )
	{
		JID jid(room->name() + "@" + room->service() + "/" + msg.from().resource());
		m_real_parent->addMessageFrom(jid, msg, true);
	}
	else
	{
		const DelayedDelivery* dd = msg.when();
		if(msg.from().resource().empty())
			emit addSystemMessageToConference("Jabber",utils::fromStd(room->name() +
																	  "@" + room->service()),m_account_name,utils::fromStd(msg.body()),
											  dd==0?QDateTime::currentDateTime():utils::fromStamp(dd->stamp()),dd==0);
		else
			emit addMessageToConference(utils::fromStd(room->name() +
													   "@" + room->service()), m_account_name,utils::fromStd(msg.from().resource()),
										utils::fromStd(msg.body()), dd==0?QDateTime::currentDateTime():utils::fromStamp(dd->stamp()), dd!=0);
	}
}
Beispiel #5
0
void ChatClient::_q_connected()
{
    const QString domain = configuration().domain();

    // notify jid change
    emit jidChanged(jid());

    // get server time
    d->timeQueue = d->timeManager->requestTime(domain);

    // get info for root item
    const QString id = d->discoManager->requestInfo(domain);
    if (!id.isEmpty())
        d->discoQueue.append(id);

    // lookup TURN server
    debug(QString("Looking up STUN server for domain %1").arg(domain));
    d->dns.setType(QDnsLookup::SRV);
    d->dns.setName("_turn._udp." + domain);
    d->dns.lookup();
}
Beispiel #6
0
int fgbg(task_struct* head,char** argv)
{
    task_struct* node;

    if(!strcmp(argv[0],"fg") || !strcmp(argv[0],"bg"))
    {
        node = jid(head,argv[1]);
        if(node == NULL)
        {
            printf("Wrong Input!!!\n");
        }
        else
        {
            Kill(node->pid,SIGCONT);
            node->bg = ((node->bg == EXECVE_IN_BG)? EXECVE_IN_FG:EXECVE_IN_BG);
        }
        return 1;
    }

    return 0;
}
Beispiel #7
0
MCONTACT CJabberProto::DBCreateContact(const TCHAR *jid, const TCHAR *nick, BOOL temporary, BOOL stripResource)
{
	if (jid == NULL || jid[0]=='\0')
		return NULL;

	TCHAR *s = NEWTSTR_ALLOCA(jid);
	TCHAR *q = NULL, *p;
	// strip resource if present
	if ((p = _tcschr(s, '@')) != NULL)
		if ((q = _tcschr(p, '/')) != NULL)
			*q = '\0';

	if (!stripResource && q != NULL)	// so that resource is not stripped
		*q = '/';

	// We can't use JabberHContactFromJID() here because of the stripResource option
	size_t len = _tcslen(s);
	for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
		ptrT jid( getTStringA(hContact, "jid"));
		if (jid == NULL)
			continue;

		TCHAR *p = jid;
		if (p && _tcslen(p) >= len && (p[len]=='\0'||p[len]=='/') && !_tcsnicmp(p, s, len))
			return hContact;
	}

	MCONTACT hNewContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
	CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hNewContact, (LPARAM)m_szModuleName);
	setTString(hNewContact, "jid", s);
	if (nick != NULL && *nick != '\0')
		setTString(hNewContact, "Nick", nick);
	if (temporary)
		db_set_b(hNewContact, "CList", "NotOnList", 1);
	else
		SendGetVcard(s);
	debugLog(_T("Create Jabber contact jid=%s, nick=%s"), s, nick);
	DBCheckIsTransportedContact(s,hNewContact);
	return hNewContact;
}
Beispiel #8
0
void JingleClientSlots::stateChanged(cricket::Call *call, cricket::Session *session, cricket::Session::State state) 
{
	qDebug(QString("jinglevoicecaller.cpp: State changed (%1)").arg(state));
	// Why is c_str() stuff needed to make it compile on OS X ?
	Jid jid(session->remote_address().c_str());

	if (state == cricket::Session::STATE_INIT) { }
	else if (state == cricket::Session::STATE_SENTINITIATE) { 
		voiceCaller_->registerCall(jid,call);
	}
	else if (state == cricket::Session::STATE_RECEIVEDINITIATE) {
		voiceCaller_->registerCall(jid,call);
		emit voiceCaller_->incoming(jid);
	}
	else if (state == cricket::Session::STATE_SENTACCEPT) { }
	else if (state == cricket::Session::STATE_RECEIVEDACCEPT) {
		emit voiceCaller_->accepted(jid);
	}
	else if (state == cricket::Session::STATE_SENTMODIFY) { }
	else if (state == cricket::Session::STATE_RECEIVEDMODIFY) {
		qWarning(QString("jinglevoicecaller.cpp: RECEIVEDMODIFY not implemented yet (was from %1)").arg(jid.full()));
	}
	else if (state == cricket::Session::STATE_SENTREJECT) { }
	else if (state == cricket::Session::STATE_RECEIVEDREJECT) {
		voiceCaller_->removeCall(jid);
		emit voiceCaller_->rejected(jid);
	}
	else if (state == cricket::Session::STATE_SENTREDIRECT) { }
	else if (state == cricket::Session::STATE_SENTTERMINATE) {
		voiceCaller_->removeCall(jid);
		emit voiceCaller_->terminated(jid);
	}
	else if (state == cricket::Session::STATE_RECEIVEDTERMINATE) {
		voiceCaller_->removeCall(jid);
		emit voiceCaller_->terminated(jid);
	}
	else if (state == cricket::Session::STATE_INPROGRESS) {
		emit voiceCaller_->in_progress(jid);
	}
}
Beispiel #9
0
	void btnOk_OnClick(CCtrlButton*)
	{
		m_proto->m_szInviteJids.clear();

		// invite users from clist
		for (MCONTACT hContact = db_find_first(m_proto->m_szModuleName); hContact; hContact = db_find_next(hContact, m_proto->m_szModuleName)) {
			if (m_proto->isChatRoom(hContact))
				continue;

			if (HANDLE hItem = m_clc.FindContact(hContact)) {
				if (m_clc.GetCheck(hItem)) {
					ptrA jid(m_proto->getStringA(hContact, "ID"));
					if (jid != NULL)
						m_proto->m_szInviteJids.push_back((char*)jid);
				}
			}
		}

		ptrA tszText(m_entry.GetTextA());
		if (tszText != NULL)
			m_proto->m_szInviteJids.push_back(string(tszText));
	}
Beispiel #10
0
void Client::groupChatSetStatus(const QString &host, const QString &room, const Status &_s)
{
	Jid jid(room + "@" + host);
	bool found = false;
	for(QValueList<GroupChat>::ConstIterator it = d->groupChatList.begin(); it != d->groupChatList.end(); it++) {
		const GroupChat &i = *it;
		if(i.j.compare(jid, false)) {
			found = true;
			jid = i.j;
			break;
		}
	}
	if(!found)
		return;

	Status s = _s;
	s.setIsAvailable(true);

	JT_Presence *j = new JT_Presence(rootTask());
	j->pres(jid, s);
	j->go(true);
}
Beispiel #11
0
void JAccount::loadSettings()
{
	Q_D(JAccount);
	Config cfg = config();
	cfg.beginGroup("general");

	d->priority = cfg.value("priority", 15);
	d->nick = cfg.value("nick", id());
	if (cfg.hasChildKey("photoHash"))
		setAvatarHex(cfg.value("photoHash", QString()));
	d->pgpKeyId = cfg.value("pgpKeyId", QString());

	Jreen::JID jid(id());
	if (!d->client->isConnected()) {
		jid.setResource(cfg.value("resource", QLatin1String("qutIM")));
	}
	d->client->setFeatureConfig(Client::Encryption, cfg.value("encryption", Client::Auto));
	d->client->setFeatureConfig(Client::Compression, cfg.value("compression", Client::Auto));
	{
		cfg.beginGroup("bosh");
		if (cfg.value("use", false)) {
			QString host = cfg.value("host", jid.domain());
			int port = cfg.value("port", 5280);
			d->client->setConnection(new ConnectionBOSH(host, port));
		}
		cfg.endGroup();
	}
	d->client->setJID(jid);
	d->client->setPassword(cfg.value("passwd", QString(), Config::Crypted));
	if(!cfg.value("autoDetect",true)) {
		d->client->setPort(cfg.value("port", 5222));
		d->client->setServer(cfg.value("server",d->client->server()));
	}

	cfg.endGroup();
	
	emit parametersChanged(d->parameters);
}
Beispiel #12
0
INT_PTR __cdecl CJabberProto::OnJoinChat(WPARAM hContact, LPARAM)
{
	ptrT jid(getTStringA(hContact, "ChatRoomID"));
	if (jid == NULL)
		return 0;

	ptrT nick(getTStringA(hContact, "MyNick"));
	if (nick == NULL)
		if ((nick = getTStringA("Nick")) == NULL)
			return 0;

	ptrT password(getTStringA(hContact, "Password"));

	if (getWord(hContact, "Status", 0) != ID_STATUS_ONLINE) {
		TCHAR *p = _tcschr(jid, '@');
		if (p != NULL) {
			*p++ = 0;
			GroupchatJoinRoom(p, jid, nick, password);
		}
	}

	return 0;
}
bool MUCAffiliationsView::addToCurrent(const QString& j)
{	
	QModelIndex index = currentIndex();
	if (!index.isValid())
		return false;

	if (index.parent().isValid())
		index = index.parent();
		
	if (!index.parent().isValid()) {
		XMPP::Jid jid(j);
		if (!jid.isValid())
			return false;

		// TODO: Check if the user is already in the list
		
		int row = model()->rowCount(index);
		model()->insertRows(row,1,index);
		model()->setData(model()->index(row,0,index),QVariant(jid.bare()));
		return true;
	}
	return false;
}
Beispiel #14
0
// XEP-0224 support (Attention/Nudge)
INT_PTR __cdecl CJabberProto::JabberSendNudge(WPARAM wParam, LPARAM)
{
	if (!m_bJabberOnline)
		return 0;

	HANDLE hContact = (HANDLE)wParam;
	ptrT jid( getTStringA(hContact, "jid"));
	if (jid == NULL)
		return 0;

	TCHAR tszJid[JABBER_MAX_JID_LEN];
	TCHAR *szResource = ListGetBestClientResourceNamePtr(jid);
	if (szResource)
		mir_sntprintf(tszJid, SIZEOF(tszJid), _T("%s/%s"), jid, szResource);
	else
		mir_sntprintf(tszJid, SIZEOF(tszJid), _T("%s"), jid);

	JabberCapsBits jcb = GetResourceCapabilites(tszJid, FALSE);
	m_ThreadInfo->send(
		XmlNode(_T("message")) << XATTR(_T("type"), _T("headline")) << XATTR(_T("to"), tszJid)
			<< XCHILDNS(_T("attention"), JABBER_FEAT_ATTENTION));
	return 0;
}
Beispiel #15
0
bool QtLoginWindow::eventFilter(QObject *obj, QEvent *event) {
    if (obj == username_->view() && event->type() == QEvent::KeyPress) {
        QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
        if (keyEvent->key() == Qt::Key_Delete || keyEvent->key() == Qt::Key_Backspace) {
            QString jid(username_->view()->currentIndex().data().toString());
            int result = QMessageBox::question(this, tr("Remove profile"), tr("Remove the profile '%1'?").arg(jid), QMessageBox::Yes | QMessageBox::No);
            if (result == QMessageBox::Yes) {
                onPurgeSavedLoginRequest(Q2PSTRING(jid));
            }
            return true;
        }
    }
#ifdef SWIFTEN_PLATFORM_MACOSX
    // Dock clicked
    // Temporary workaround for case 501. Could be that this code is still
    // needed when Qt provides a proper fix
    if (obj == qApp && event->type() == QEvent::ApplicationActivate && !isVisible()) {
        bringToFront();
    }
#endif

    return QObject::eventFilter(obj, event);
}
void DataTransferAppImpl::login(const std::string username, const std::string password, const std::string xmpp_server_name, const int port) {
	buzz::Jid jid(username, xmpp_server_name, JID_RESOURCE);
	buzz::XmppClientSettings xclientSettings;

	if(!jid.IsValid() || jid.node() == ""){
		std::string errDesc = "Invalid JID. Node id or server name is missing.";
		LOG(LERROR) << errDesc;
		SignalLoginFailed(jid.node(), errDesc, MalformedID);
		return;
	}

	xclientSettings.set_user(jid.node());
	xclientSettings.set_resource("data");
	xclientSettings.set_host(jid.domain());
	xclientSettings.set_allow_plain(true);
	xclientSettings.set_use_tls(false);
	xclientSettings.set_server(talk_base::SocketAddress(xmpp_server_name, port));

	talk_base::InsecureCryptStringImpl pass;
	pass.password() = password;
	xclientSettings.set_pass(talk_base::CryptString(pass));

	tunnel_dt_client.SetXMPPServer(xmpp_server_name);
	pump.client() -> SignalStateChange.connect(&tunnel_dt_client, &TunnelDataTransferClient::OnStateChange);

	talk_base::ThreadManager::SetCurrent(main_thread);

	LOG(INFO) << "started doLogin"<< std::endl;

	xmppSocket = new XmppSocket(true);
	pump.DoLogin(xclientSettings, xmppSocket, NULL);

	if(!MainThread()->started()){
		MainThread()->Run();
	}
}
Beispiel #17
0
void ChatDlg::setLooks()
{
	// update the font
	QFont f;
	f.fromString(PsiOptions::instance()->getOption("options.ui.look.font.chat").toString());
	chatView()->setFont(f);
	chatEdit()->setFont(f);

	// update contact info
	status_ = -2; // sick way of making it redraw the status
	updateContact(jid(), false);

	// update the widget icon
#ifndef Q_WS_MAC
	setWindowIcon(IconsetFactory::icon("psi/start-chat").icon());
#endif

	/*QBrush brush;
	brush.setPixmap( QPixmap( LEGOPTS.chatBgImage ) );
	chatView()->setPaper(brush);
	chatView()->setStaticBackground(true);*/

	setWindowOpacity(double(qMax(MINIMUM_OPACITY, PsiOptions::instance()->getOption("options.ui.chat.opacity").toInt())) / 100);
}
Beispiel #18
0
void ELineEdit::dropEvent(QDropEvent *e)
{
	QString str = e->mimeData()->text();

	if(!str.isEmpty()) {
		Jid jid(str);
		if(!jid.isValid())
			setText(str);
		else {
			EventDlg *e = (EventDlg *)parent();
			QString name = e->jidToString(jid);

			bool hasComma = false, hasText = false;
			int len = text().length();
			while ( --len >= 0 ) {
				QChar c = text().at( len );
				if ( c == ',' ) {
					hasComma = true;
					break;
				}
				else if ( !c.isSpace() ) {
					hasText = true;
					break;
				}
			}

			if ( hasComma || !hasText )
				setText(text() + ' ' + name);
			else
				setText(text() + ", " + name);
		}
		setCursorPosition(text().length());

		repaint();
	}
}
Beispiel #19
0
bool XmlConsole::filtered(const QString& str) const
{
	if(ui_.ck_enable->isChecked()) {
		// Only do parsing if needed
		if (!ui_.le_jid->text().isEmpty() || !ui_.ck_iq->isChecked() || !ui_.ck_message->isChecked() || !ui_.ck_presence->isChecked()) {
			QDomDocument doc;
			if (!doc.setContent(str))
				return true;
			
			QDomElement e = doc.documentElement();
			if ((e.tagName() == "iq" && !ui_.ck_iq->isChecked()) || (e.tagName() == "message" && !ui_.ck_message->isChecked()) || ((e.tagName() == "presence" && !ui_.ck_presence->isChecked())))
				return true;

			if (!ui_.le_jid->text().isEmpty()) {
				Jid jid(ui_.le_jid->text());
				bool hasResource = !jid.resource().isEmpty();
				if (!jid.compare(e.attribute("to"),hasResource) && !jid.compare(e.attribute("from"),hasResource))
					return true;
			}
		}
		return false;
	}
	return true;
}
Beispiel #20
0
void UserSearchController::handleSearchResponse(std::shared_ptr<SearchPayload> resultsPayload, ErrorPayload::ref error) {
    if (error || !resultsPayload) {
        window_->setSearchError(true);
        return;
    }

    std::vector<UserSearchResult> results;

    if (resultsPayload->getForm()) {
        window_->setResultsForm(resultsPayload->getForm());
    } else {
        for (auto&& item : resultsPayload->getItems()) {
            JID jid(item.jid);
            std::map<std::string, std::string> fields;
            fields["first"] = item.first;
            fields["last"] = item.last;
            fields["nick"] = item.nick;
            fields["email"] = item.email;
            UserSearchResult result(jid, fields);
            results.push_back(result);
        }
        window_->setResults(results);
    }
}
void jConnection::loadSettings()
{
	if(m_state != StateDisconnected)
	{
		DEBUG("Try to load settings in %d state", (int)m_state);
		return;
	}
	DEBUG() << Q_FUNC_INFO;
    loadProxySettings();
    m_hosts.clear();
    QSettings settings(QSettings::defaultFormat(), QSettings::UserScope, "qutim/qutim."+m_profile_name+"/jabber."+m_account_name, "accountsettings");

    settings.beginGroup("main");
	JID jid(utils::toStd(m_account_name));

    QString server = utils::fromStd(jid.server());
    int port = settings.value("port",5222).toInt();
    m_use_dns_srv = settings.value("usedns", true).toBool();
    TLSPolicy tls_policy = TLSOptional;
    if(server=="qutim.org")
    {
		server="jabber.qutim.org";
		port = 5222;
		m_use_dns_srv = false;
    }
    bool use_sasl = settings.value("usesasl", true).toBool();
    bool compress = settings.value("compress", true).toBool();
    server = settings.value("server",server).toString();
    m_server = utils::toStd(server);
    m_port = port;
    if(!m_use_dns_srv)
    {
		if(port==-1)
			port = 5222;
		m_hosts << qMakePair( server, port );
    }
    else
	{
		static LogSink logsink;
		DNS::HostMap hosts = DNS::resolve(m_server, logsink);
		DNS::HostMap::iterator h = hosts.begin();
		for(;h!=hosts.end();h++)
		{
			QPair<QString, int> host( utils::fromStd(h->first), h->second );
			static const QRegExp valid_hostname( "(\\w+\\.)+\\w+" );
			Q_ASSERT_X(valid_hostname.isValid(),"jConnection::loadSettings()","Regexp is not valid");
			if( valid_hostname.exactMatch( host.first ) || !QHostAddress( host.first ).isNull() )
				m_hosts.append(host);
		}
		if( m_hosts.isEmpty() )
			m_hosts << qMakePair( server, 5222 );
    }
    switch(settings.value("tlspolicy",1).toInt())
    {
	case 0:
	    tls_policy = TLSDisabled;
	    break;
	case 1:
	    tls_policy = TLSOptional;
	    break;
	case 2:
	    tls_policy = TLSRequired;
	    break;
    }
	settings.endGroup();

	ClientBase *jClient = dynamic_cast<ClientBase*>(m_handler);
	if(!jClient)
	{
		DEBUG("Try to load settings, but handler is not ClientBase. Error os %d", (int)m_error);
		m_handler->handleDisconnect(this, m_error);
		if(!(jClient = dynamic_cast<ClientBase*>(m_handler)))
		{
			DEBUG("Try lo load settings, but handle disconnect go wrong");
			return;
		}
	}

    jClient->setTls(tls_policy);
    jClient->setSasl(use_sasl);
	jClient->setCompression(compress);
}
Beispiel #22
0
void TlenIqResultRoster(TlenProtocol *proto, XmlNode *iqNode)
{
	XmlNode *queryNode;
	char *type;
	char *str;

	// RECVED: roster information
	// ACTION: populate LIST_ROSTER and create contact for any new rosters
	if ((type=TlenXmlGetAttrValue(iqNode, "type")) == NULL) return;
	if ((queryNode=TlenXmlGetChild(iqNode, "query")) == NULL) return;

	if (!strcmp(type, "result")) {
		str = TlenXmlGetAttrValue(queryNode, "xmlns");
		if (str != NULL && !strcmp(str, "jabber:iq:roster")) {
			DBVARIANT dbv;
			XmlNode *itemNode, *groupNode;
			TLEN_SUBSCRIPTION sub;
			TLEN_LIST_ITEM *item;
			char *jid, *name, *nick;
			int i, oldStatus;

			for (i=0; i<queryNode->numChild; i++) {
				itemNode = queryNode->child[i];
				if (!strcmp(itemNode->name, "item")) {
					str = TlenXmlGetAttrValue(itemNode, "subscription");
					if (str == NULL) sub = SUB_NONE;
					else if (!strcmp(str, "both")) sub = SUB_BOTH;
					else if (!strcmp(str, "to")) sub = SUB_TO;
					else if (!strcmp(str, "from")) sub = SUB_FROM;
					else sub = SUB_NONE;
					//if (str != NULL && (!strcmp(str, "to") || !strcmp(str, "both"))) {
					if ((jid=TlenXmlGetAttrValue(itemNode, "jid")) != NULL) {
						if ((name=TlenXmlGetAttrValue(itemNode, "name")) != NULL)
							nick = TlenTextDecode(name);
						else
							nick = TlenLocalNickFromJID(jid);
						
						if (nick != NULL) {
							MCONTACT hContact;
							item = TlenListAdd(proto, LIST_ROSTER, jid);
							if (item->nick) mir_free(item->nick);
							item->nick = nick;
							item->subscription = sub;
							if ((hContact=TlenHContactFromJID(proto, jid)) == NULL) {
								// Received roster has a new JID.
								// Add the jid (with empty resource) to Miranda contact list.
								hContact = TlenDBCreateContact(proto, jid, nick, FALSE);
							}
							db_set_s(hContact, "CList", "MyHandle", nick);
							if (item->group) mir_free(item->group);
							if ((groupNode=TlenXmlGetChild(itemNode, "group")) != NULL && groupNode->text != NULL) {
								item->group = TlenGroupDecode(groupNode->text);
								Clist_CreateGroup(0, _A2T(item->group));
								// Don't set group again if already correct, or Miranda may show wrong group count in some case
								if (!db_get(hContact, "CList", "Group", &dbv)) {
									if (strcmp(dbv.pszVal, item->group))
										db_set_s(hContact, "CList", "Group", item->group);
									db_free(&dbv);
								}
								else db_set_s(hContact, "CList", "Group", item->group);
							}
							else {
								item->group = NULL;
								db_unset(hContact, "CList", "Group");
							}
							if (!db_get(hContact, proto->m_szModuleName, "AvatarHash", &dbv)) {
								if (item->avatarHash) mir_free(item->avatarHash);
								item->avatarHash = mir_strdup(dbv.pszVal);
								proto->debugLogA("Setting hash [%s] = %s", nick, item->avatarHash);
								db_free(&dbv);
							}
							item->avatarFormat = db_get_dw(hContact, proto->m_szModuleName, "AvatarFormat", PA_FORMAT_UNKNOWN);
						}
					}
				}
			}
			
			// Delete orphaned contacts (if roster sync is enabled)
			if (db_get_b(NULL, proto->m_szModuleName, "RosterSync", FALSE) == TRUE) {
				for (MCONTACT hContact = db_find_first(proto->m_szModuleName); hContact; ) {
					MCONTACT hNext = hContact = db_find_next(hContact, proto->m_szModuleName);
					ptrA jid( db_get_sa(hContact, proto->m_szModuleName, "jid"));
					if (jid != NULL) {
						if (!TlenListExist(proto, LIST_ROSTER, jid)) {
							proto->debugLogA("Syncing roster: deleting 0x%x", hContact);
							CallService(MS_DB_CONTACT_DELETE, hContact, 0);
						}
					}
					hContact = hNext;
				}
			}

			CLISTMENUITEM mi = { sizeof(mi) };
			mi.flags = CMIM_FLAGS;
			Menu_ModifyItem(proto->hMenuMUC, &mi);
			if (proto->hMenuChats != NULL)
				Menu_ModifyItem(proto->hMenuChats, &mi);

			proto->isOnline = TRUE;
			proto->debugLogA("Status changed via THREADSTART");
			oldStatus = proto->m_iStatus;
			TlenSendPresence(proto, proto->m_iDesiredStatus);
			ProtoBroadcastAck(proto->m_szModuleName, NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE) oldStatus, proto->m_iStatus);
		}
	}
}
Beispiel #23
0
void ChatDlg::doFile()
{
	aFile(jid());
}
Beispiel #24
0
void ChatDlg::setChatState(ChatState state)
{
	if (PsiOptions::instance()->getOption("options.messages.send-composing-events").toBool() && (sendComposingEvents_ || (contactChatState_ != XMPP::StateNone))) {
		// Don't send to offline resource
		QList<UserListItem*> ul = account()->findRelevant(jid());
		if (ul.isEmpty()) {
			sendComposingEvents_ = false;
			lastChatState_ = XMPP::StateNone;
			return;
		}

		UserListItem *u = ul.first();
		if (!u->isAvailable()) {
			sendComposingEvents_ = false;
			lastChatState_ = XMPP::StateNone;
			return;
		}

		// Transform to more privacy-enabled chat states if necessary
		if (!PsiOptions::instance()->getOption("options.messages.send-inactivity-events").toBool() && (state == XMPP::StateGone || state == XMPP::StateInactive)) {
			state = XMPP::StatePaused;
		}

		if (lastChatState_ == XMPP::StateNone && (state != XMPP::StateActive && state != XMPP::StateComposing && state != XMPP::StateGone)) {
			//this isn't a valid transition, so don't send it, and don't update laststate
			return;
		}

		// Check if we should send a message
		if (state == lastChatState_ || state == XMPP::StateActive || (lastChatState_ == XMPP::StateActive && state == XMPP::StatePaused)) {
			lastChatState_ = state;
			return;
		}

		// Build event message
		Message m(jid());
		if (sendComposingEvents_) {
			m.setEventId(eventId_);
			if (state == XMPP::StateComposing) {
				m.addEvent(ComposingEvent);
			}
			else if (lastChatState_ == XMPP::StateComposing) {
				m.addEvent(CancelEvent);
			}
		}
		if (contactChatState_ != XMPP::StateNone) {
			if (lastChatState_ != XMPP::StateGone) {
				if ((state == XMPP::StateInactive && lastChatState_ == XMPP::StateComposing) || (state == XMPP::StateComposing && lastChatState_ == XMPP::StateInactive)) {
					// First go to the paused state
					Message tm(jid());
					m.setType("chat");
					m.setChatState(XMPP::StatePaused);
					if (account()->isAvailable()) {
						account()->dj_sendMessage(m, false);
					}
				}
				m.setChatState(state);
			}
		}

		// Send event message
		if (m.containsEvents() || m.chatState() != XMPP::StateNone) {
			m.setType("chat");
			if (account()->isAvailable()) {
				account()->dj_sendMessage(m, false);
			}
		}

		// Save last state
		if (lastChatState_ != XMPP::StateGone || state == XMPP::StateActive)
			lastChatState_ = state;
	}
}
Beispiel #25
0
void ChatDlg::doSend()
{
	if (!chatEdit()->isEnabled()) {
		return;
	}

	if (chatEdit()->text().isEmpty()) {
		return;
	}

	if (chatEdit()->text() == "/clear") {
		chatEdit()->clear();
		doClear();
		return;
	}

	if (!account()->loggedIn()) {
		return;
	}

	if (warnSend_) {
		warnSend_ = false;
		int n = QMessageBox::information(this, tr("Warning"), tr(
		                                     "<p>Encryption was recently disabled by the remote contact.  "
		                                     "Are you sure you want to send this message without encryption?</p>"
		                                 ), tr("&Yes"), tr("&No"));
		if (n != 0) {
			return;
		}
	}

	Message m(jid());
	m.setType("chat");
	m.setBody(chatEdit()->text());
	m.setTimeStamp(QDateTime::currentDateTime());
	if (isEncryptionEnabled()) {
		m.setWasEncrypted(true);
	}
	m_ = m;

	// Request events
	if (PsiOptions::instance()->getOption("options.messages.send-composing-events").toBool()) {
		// Only request more events when really necessary
		if (sendComposingEvents_) {
			m.addEvent(ComposingEvent);
		}
		m.setChatState(XMPP::StateActive);
	}

	// Update current state
	setChatState(XMPP::StateActive);

	if (isEncryptionEnabled()) {
		chatEdit()->setEnabled(false);
		transid_ = account()->sendMessageEncrypted(m);
		if (transid_ == -1) {
			chatEdit()->setEnabled(true);
			chatEdit()->setFocus();
			return;
		}
	}
	else {
		aSend(m);
		doneSend();
	}

	chatEdit()->setFocus();
}
Beispiel #26
0
void ChatDlg::doInfo()
{
	aInfo(jid());
}
Beispiel #27
0
void ChatDlg::doVoice()
{
	aVoice(jid());
}
Beispiel #28
0
void ChatDlg::doHistory()
{
	aHistory(jid());
}
Beispiel #29
0
void Client::ppPresence(const Jid &j, const Status &s)
{
	if(s.isAvailable())
		debug(QString("Client: %1 is available.\n").arg(j.full()));
	else
		debug(QString("Client: %1 is unavailable.\n").arg(j.full()));

	for(QValueList<GroupChat>::Iterator it = d->groupChatList.begin(); it != d->groupChatList.end(); it++) {
		GroupChat &i = *it;

		if(i.j.compare(j, false)) {
			bool us = (i.j.resource() == j.resource() || j.resource().isEmpty()) ? true: false;

			debug(QString("for groupchat i=[%1] pres=[%2], [us=%3].\n").arg(i.j.full()).arg(j.full()).arg(us));
			switch(i.status) {
				case GroupChat::Connecting:
					if(us && s.hasError()) {
						Jid j = i.j;
						d->groupChatList.remove(it);
						groupChatError(j, s.errorCode(), s.errorString());
					}
					else {
						// don't signal success unless it is a non-error presence
						if(!s.hasError()) {
							i.status = GroupChat::Connected;
							groupChatJoined(i.j);
						}
						groupChatPresence(j, s);
					}
					break;
				case GroupChat::Connected:
					groupChatPresence(j, s);
					break;
				case GroupChat::Closing:
					if(us && !s.isAvailable()) {
						Jid j = i.j;
						d->groupChatList.remove(it);
						groupChatLeft(j);
					}
					break;
				default:
					break;
			}

			return;
		}
	}

	if(s.hasError()) {
		presenceError(j, s.errorCode(), s.errorString());
		return;
	}

	// is it me?
	if(j.compare(jid(), false)) {
		updateSelfPresence(j, s);
	}
	else {
		// update all relavent roster entries
		for(LiveRoster::Iterator it = d->roster.begin(); it != d->roster.end(); ++it) {
			LiveRosterItem &i = *it;

			if(!i.jid().compare(j, false))
				continue;

			// roster item has its own resource?
			if(!i.jid().resource().isEmpty()) {
				if(i.jid().resource() != j.resource())
					continue;
			}

			updatePresence(&i, j, s);
		}
	}
}
Beispiel #30
0
void ChatDlg::updateAvatar(const Jid& j)
{
	if (j.compare(jid(), false))
		updateAvatar();
}