Ejemplo n.º 1
0
void CSkypeProto::OnContactListChanged(const ContactRef &contact)
{
	bool result;

	contact->IsMemberOfHardwiredGroup(CContactGroup::ALL_BUDDIES, result);
	if (result)
	{
		if ( !this->contactList.contains(contact))
		{
			CContact::Ref newContact(contact);
			this->contactList.append(newContact);
			newContact.fetch();
		}
	}

	contact->IsMemberOfHardwiredGroup(CContactGroup::CONTACTS_WAITING_MY_AUTHORIZATION, result);
	if (result)
	{
		SEString data;

		uint newTS = 0;
		contact->GetPropAuthreqTimestamp(newTS);

		this->RaiseAuthRequestEvent(newTS, contact);
	}
}
Ejemplo n.º 2
0
  void FileTransferClient::ConfirmUIN()
  {
    if ( m_contact_list->exists(m_remote_uin) )
    {
      ContactRef c = (*m_contact_list)[ m_remote_uin ];
      if ( (c->getExtIP() == m_local_ext_ip && c->getLanIP() == getIP() )
	   /* They are behind the same masquerading box,
	    * and the Lan IP matches
	    */
	   || c->getExtIP() == getIP())
      {
	m_contact = c;
      }
      else
      {
	// spoofing attempt most likely
	ostringstream ostr;
	ostr << "Refusing direct connection from someone that claims to be UIN "
	     << m_remote_uin << " since their IP " << IPtoString( getIP() ) << " != " << IPtoString( c->getExtIP() );
	throw DisconnectedException( ostr.str() );
      }
      
    }
    else
    {
      // don't accept direct connections from contacts not on contact list
      throw DisconnectedException("Refusing direct connection to contact not on contact list");
    }
  }
Ejemplo n.º 3
0
void CSkypeProto::OnContactChanged(const ContactRef &contact, int prop)
{
	SEString data;
	contact->GetPropSkypename(data);
	wchar_t *sid = ::mir_utf8decodeW(data);
	MCONTACT hContact = this->GetContactBySid(sid);
	::mir_free(sid);

	SEObject *contactObj = contact.fetch();

	if (hContact)
	{
		switch(prop)
		{
		case Contact::P_AUTHREQ_TIMESTAMP:
			{
				uint newTS = 0;
				contact->GetPropAuthreqTimestamp(newTS);
				DWORD oldTS = this->getDword(hContact, "AuthTS", 0);
				if (newTS > oldTS)
					this->RaiseAuthRequestEvent(newTS, contact);
			}
			break;

		case Contact::P_AUTHREQUEST_COUNT:
			// todo: all authrequests after first should be catch here
			this->UpdateContactAuthState(hContact, contact);
			break;

		case Contact::P_AVAILABILITY:
			this->UpdateContactStatus(hContact, contact);
			this->UpdateChatUserStatus(contact);
			break;

		//case CContact::P_AVATAR_IMAGE:
		case Contact::P_AVATAR_TIMESTAMP:
			this->UpdateProfileAvatar(contactObj, hContact);
			break;

		//case CContact::P_MOOD_TEXT:
		case Contact::P_MOOD_TIMESTAMP:
			this->UpdateProfileStatusMessage(contactObj, hContact);
			break;

		case Contact::P_FULLNAME:
			this->UpdateChatUserNick(contact);
			break;

		case Contact::P_PROFILE_TIMESTAMP:
			this->UpdateProfile(contactObj, hContact);
			break;
		}
	}
}
Ejemplo n.º 4
0
  ContactRef MessageHandler::lookupMobile(const string& m) {
    ContactRef ret;
    
    if (m_contact_list->mobile_exists(m)) {
      ret = m_contact_list->lookup_mobile(m);
    } else {
      ret = ContactRef( new Contact(m) );
      ret->setMobileNo(m);
    }

    return ret;
  }
Ejemplo n.º 5
0
  ContactRef MessageHandler::lookupEmail(const string& email, const string& alias) {
    ContactRef ret;
    
    if (m_contact_list->email_exists(email)) {
      ret = m_contact_list->lookup_email(email);
    } else {
      ret = ContactRef( new Contact(alias) );
      ret->setEmail(email);
    }

    return ret;
  }
Ejemplo n.º 6
0
int CSkypeProto::OnPrebuildContactMenu(WPARAM wParam, LPARAM)
{
	MCONTACT hContact = (MCONTACT)wParam;
	if ( !hContact)
		return 0;

	if ( !this->IsOnline() || ::lstrcmpA(::GetContactProto(hContact), m_szModuleName))
		return 0;

	if ( !this->isChatRoom(hContact))
	{
		bool ctrlPressed = (::GetKeyState(VK_CONTROL) & 0x8000) != 0;
		
		bool authNeed = this->getByte(hContact, "Auth", 0) > 0;
		bool grantNeed = this->getByte(hContact, "Grant", 0) > 0;
		
		::Menu_ShowItem(CSkypeProto::contactMenuItems[CMI_AUTH_REQUEST], ctrlPressed || authNeed);
		::Menu_ShowItem(CSkypeProto::contactMenuItems[CMI_AUTH_GRANT], ctrlPressed || grantNeed);
		::Menu_ShowItem(CSkypeProto::contactMenuItems[CMI_AUTH_REVOKE], ctrlPressed || (!grantNeed && !authNeed));
		::Menu_ShowItem(CSkypeProto::contactMenuItems[CMI_HISTORY], TRUE);

		{
			SEString sid(_T2A(::db_get_wsa(hContact, this->m_szModuleName, SKYPE_SETTINGS_SID)));
			
			ContactRef contact;
			this->GetContact(sid, contact);

			bool isBlocked = false;
			contact->IsMemberOfHardwiredGroup(ContactGroup::CONTACTS_BLOCKED_BY_ME, isBlocked);
		
			CLISTMENUITEM clmi = { sizeof(clmi) };
			clmi.cbSize = sizeof(CLISTMENUITEM);
			clmi.flags = CMIM_FLAGS;
			if (isBlocked)
			{
				clmi.flags |= CMIM_NAME | CMIM_ICON | CMIF_TCHAR;
				clmi.icolibItem = CSkypeProto::GetSkinIconHandle("contact");
				clmi.ptszName = LPGENT("Unblock this person...");
			}
			else
			{
				clmi.flags |= CMIM_NAME | CMIM_ICON | CMIF_TCHAR;
				clmi.icolibItem = CSkypeProto::GetSkinIconHandle("block");
				clmi.ptszName = LPGENT("Block this person...");
			}
			::CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)CSkypeProto::contactMenuItems[CMI_BLOCK], (LPARAM)&clmi);
		}
	}

	return 0;
}
Ejemplo n.º 7
0
void CSkypeProto::UpdateContactClient(MCONTACT hContact, const ContactRef &contact)
{
	bool isMobile = false;
	contact->HasCapability(Contact::CAPABILITY_MOBILE_DEVICE, isMobile/*, true*/);

	this->setTString(hContact, "MirVer", isMobile ? L"SkypeMobile" : L"Skype");
}
Ejemplo n.º 8
0
void CSkypeProto::UpdateContactLastEventDate(MCONTACT hContact, const ContactRef &contact)
{
	uint newTS = 0;
	contact->GetPropLastusedTimestamp(newTS);
	DWORD oldTS = this->getDword(hContact, "LastEventDateTS", 0);
	if (newTS > oldTS)
		this->setDword(hContact, "LastEventDateTS", newTS);
}
Ejemplo n.º 9
0
void CSkypeProto::UpdateContactOnlineSinceTime(MCONTACT hContact, const ContactRef &contact)
{
	uint newTS = 0;
	contact->GetPropLastonlineTimestamp(newTS);
	DWORD oldTS = ::db_get_dw(hContact, this->m_szModuleName, "OnlineSinceTS", 0);
	if (newTS > oldTS)
		this->setDword(hContact, "OnlineSinceTS", newTS);
}
Ejemplo n.º 10
0
  ContactRef ContactList::add(ContactRef ct) {
    m_cmap.insert( std::make_pair(ct->getUIN(), ct) );

    // fire off signal
    UserAddedEvent uev( ct );
    //    contactlist_signal.emit( &uev );
    contactlist_signal_cb(client, signal_type,&uev );

    return ct;
  }
Ejemplo n.º 11
0
void CContactGroup::OnChange(const ContactRef& contact)
{
    // if multiple contacts added or removed
    if (!contact.present())
        return;
    String identity; 
    bool added = false;
    contact->GetIdentity(identity); 
    contact->IsMemberOf(ref(), added);  
    String mTypeName = getPropDebug(ContactGroup::P_TYPE, GetUintProp(ContactGroup::P_TYPE))[2];

    printf("CONTACTGROUP.%s contact %s was %s\n", 
               (const char*)mTypeName, 
               (const char*)identity, added ? "added" : "removed");

    if ((ContactGroup::TYPE)GetUintProp(ContactGroup::P_TYPE) == ContactGroup::CONTACTS_WAITING_MY_AUTHORIZATION) {
        printf("New auth request from %s is received\n", (const char*)identity); 
        printf("To view/accept/decline pending contact authorization request(s), use the aA account command.\n"); 
    }
}
Ejemplo n.º 12
0
  ContactRef ContactList::add(ContactRef ct) {
    m_cmap.insert( std::make_pair(ct->getUIN(), ct) );

    // fire off signal
    ContactTree::Group *gp = new ContactTree::Group();
    UserAddedEvent uev( ct, *gp );
    contactlist_signal.emit( &uev );
    delete gp;

    return ct;
  }
Ejemplo n.º 13
0
void CSkypeProto::UpdateContactAuthState(MCONTACT hContact, const ContactRef &contact)
{
	uint newTS = 0;
	contact->GetPropAuthreqTimestamp(newTS);
	DWORD oldTS = this->getDword("AuthTS", 0);
	if (newTS > oldTS)
	{
		bool result;
		if (contact->HasAuthorizedMe(result) && !result)
			this->setByte(hContact, "Auth", !result);
		else
		{
			this->delSetting(hContact, "Auth");
			if (contact->IsMemberOfHardwiredGroup(CContactGroup::ALL_BUDDIES, result) && !result)
				this->setByte(hContact, "Grant", !result);
			else
				this->delSetting(hContact, "Grant");
		}

		this->setDword(hContact, "AuthTS", newTS);
	}
}
Ejemplo n.º 14
0
void MyContactGroup::OnChange(const ContactRef& contact)
{
  ContactGroup::TYPE groupType;
  this->GetPropType(groupType);

  if (groupType == ContactGroup::SKYPE_BUDDIES)
  {
    SEString contactName;
    contact->GetPropDisplayname(contactName);

    if (!contactList.contains(contact))
    {
      contactList.append(contact);
      contact.fetch();
      printf("%s was added.\n", (const char*)contactName);
    }
    else
    {
      contactList.remove_val(contact);
      printf("%s was removed.\n", (const char*)contactName);
    };
  };
};
Ejemplo n.º 15
0
//MYCONTACTGROUP
void MyContactGroup::OnChange(const ContactRef& contact){

  ContactGroup::TYPE groupType;
  if (!GetPropType(groupType)) throw SkypeException("Can't obtain group type.\n");

  if (groupType == ContactGroup::SKYPE_BUDDIES)
  {
    SEString contactName;
    if (!contact->GetPropDisplayname(contactName)) throw SkypeException("Can't obtain contact name.\n");

    if (!contactList.contains(contact))
    {
      contactList.append(contact);
      contact.fetch();
      printf("[SKYPE]: %s was added.\n", (const char*)contactName);
    }
    else
    {
      contactList.remove_val(contact);
      printf("[SKYPE]: %s was removed.\n", (const char*)contactName);
    };
  };
}
Ejemplo n.º 16
0
void CSkypeProto::UpdateContactStatus(MCONTACT hContact, const ContactRef &contact)
{
	Contact::AVAILABILITY availability;
	contact->GetPropAvailability(availability);
	this->setWord(hContact, SKYPE_SETTINGS_STATUS, CSkypeProto::SkypeToMirandaStatus(availability));

	if (availability == Contact::SKYPEOUT)
		this->setWord(hContact, SKYPE_SETTINGS_STATUS, ID_STATUS_ONTHEPHONE);
	else
	{
		if (availability == Contact::PENDINGAUTH)
			this->setByte(hContact, "Auth", 1);
		else
			this->delSetting(hContact, "Auth");
	}
}
Ejemplo n.º 17
0
Poco::SharedPtr<ContactData>
    Util::dataFromContact(const ContactRef &contact)
{
    /* As we are only interested in some data about the Contact, let's fill
     * a small structure with everything we need and then return.
     */
    Poco::SharedPtr<ContactData> newData =
        Poco::SharedPtr<ContactData>(new ContactData);
    newData->canSMS = false;

    SEString value;

    // Get the Skype Name from the Contact.
    Contact::TYPE type;
    contact->GetPropType(type);

    switch (type) {
        case Contact::SKYPE:
            contact->GetPropSkypename(value);
            break;
        case Contact::PSTN:
            contact->GetPropPstnnumber(value);
            newData->canSMS = true;
            break;
        default:
            value = "Unrecognized";
    }

    newData->skypeName = value;

    // Get the Display Name from the Contact.
    contact->GetPropDisplayname(value);
    newData->displayName = value;

    if (!newData->canSMS) {
        // See if the contact has a mobile number set.
        contact->GetPropPhoneMobile(value);
        if (value.length() > 0)
            newData->canSMS = true;
    }

    /* Get the availability from the Contact and translate it to a readable
     * string.
     */
    Contact::AVAILABILITY availability;
    contact->GetPropAvailability(availability);
    std::pair<ContactAvailability, std::string> ret =
        convertAvailability(availability);
    newData->status = ret.first;
    newData->availability = ret.second;

    //Get the contact Avatar.
    bool hasAvatar = false;
    SEBinary rawData;

    contact->GetAvatar(hasAvatar, rawData);

    // Check if the contact has an avatar and then extract the data from it.
    if (hasAvatar)
        newData->avatar.assignRaw(rawData.data(), rawData.size());

    // Get the contact capabilities.
    contact->HasCapability(Contact::CAPABILITY_TEXT, newData->canIM);
    newData->canCall = (newData->status != Offline);
    newData->canFT = (newData->status != Offline && type == Contact::SKYPE);

    return newData;
}
Ejemplo n.º 18
0
  /**
   * Convert a MessageEvent into a UINICQSubType
   */
  UINICQSubType* MessageHandler::EventToUINICQSubType(MessageEvent *ev)
  {
    ContactRef c = ev->getContact();
    UINICQSubType *ist = NULL;

    if (ev->getType() == MessageEvent::Normal) {

      NormalMessageEvent *nv = static_cast<NormalMessageEvent*>(ev);
      ist = new NormalICQSubType( m_translator->client_to_server( nv->getMessage(), ENCODING_CONTACT_LOCALE, c ) );
	  ( static_cast<NormalICQSubType*>(ist))->setTextEncoding( (static_cast<NormalMessageEvent*>(ev))->getTextEncoding() );

    } else if (ev->getType() == MessageEvent::URL) {

      URLMessageEvent *uv = static_cast<URLMessageEvent*>(ev);
      ist = new URLICQSubType( m_translator->client_to_server( uv->getMessage(), ENCODING_CONTACT_LOCALE, c ),
			       m_translator->client_to_server( uv->getURL(),     ENCODING_CONTACT_LOCALE, c ));

    } else if (ev->getType() == MessageEvent::FileTransfer) {

      FileTransferEvent *uv = static_cast<FileTransferEvent*>(ev);
      ist = new FTICQSubType( m_translator->client_to_server( uv->getMessage(), ENCODING_CONTACT_LOCALE, c ),
						m_translator->client_to_server( uv->getDescription(),     ENCODING_CONTACT_LOCALE, c ), uv->getTotalSize());
					    
   
    } else if (ev->getType() == MessageEvent::AwayMessage) {

      ist = new AwayMsgSubType( c->getStatus() );

    } else if (ev->getType() == MessageEvent::AuthReq) {

      AuthReqEvent *uv = static_cast<AuthReqEvent*>(ev);
      ist = new AuthReqICQSubType( m_translator->client_to_server( m_self_contact->getAlias(),     ENCODING_CONTACT_LOCALE, c ),
				   m_translator->client_to_server( m_self_contact->getFirstName(), ENCODING_CONTACT_LOCALE, c ),
				   m_translator->client_to_server( m_self_contact->getLastName(),  ENCODING_CONTACT_LOCALE, c ),
				   m_translator->client_to_server( m_self_contact->getEmail(),     ENCODING_CONTACT_LOCALE, c ),
				   m_self_contact->getAuthReq(),
				   m_translator->client_to_server( uv->getMessage(),               ENCODING_CONTACT_LOCALE, c ));

    }
    else if (ev->getType() == MessageEvent::AuthAck)
    {

      AuthAckEvent *uv = static_cast<AuthAckEvent*>(ev);
      if(uv->isGranted())
        ist = new AuthAccICQSubType();
      else
        ist = new AuthRejICQSubType( m_translator->client_to_server( uv->getMessage(), ENCODING_CONTACT_LOCALE, c ) );
      
    }
    else if (ev->getType() == MessageEvent::UserAdd)
    {
      ist = new UserAddICQSubType( m_translator->client_to_server( m_self_contact->getAlias(),     ENCODING_CONTACT_LOCALE, c ),
				   m_translator->client_to_server( m_self_contact->getFirstName(), ENCODING_CONTACT_LOCALE, c ),
				   m_translator->client_to_server( m_self_contact->getLastName(),  ENCODING_CONTACT_LOCALE, c ),
				   m_translator->client_to_server( m_self_contact->getEmail(),     ENCODING_CONTACT_LOCALE, c ),
				   m_self_contact->getAuthReq() );
    }
    else if (ev->getType() == MessageEvent::Contacts)
    {
      ContactMessageEvent *cv = static_cast<ContactMessageEvent*>(ev);
      ist = new ContactICQSubType(cv->getContacts());
    }
    
    ICQMessageEvent *iev;
    if (ist != NULL && (iev = dynamic_cast<ICQMessageEvent*>(ev)) != NULL) {
      ist->setUrgent( iev->isUrgent() );
      ist->setToContactList( iev->isToContactList() );
    }
    
    return ist;
  }
Ejemplo n.º 19
0
  /*
   * This method handles:
   * - Receiving incoming messages
   * - Signalling the message
   * - Setting up the UINICQSubType for the ACK
   * (the actual ACK is sent in the caller - dependent on whether it
   *  was direct/thru server)
   */
  bool MessageHandler::handleIncoming(ICQSubType *ist, time_t t)
  {
    ContactRef contact;
    bool advanced, ack = false;

    if (ist->getType() == MSG_Type_FT)
    {
      ostringstream ostr;
      ostr << "FileTransfer request through server." <<endl;
      SignalLog( LogEvent::WARN, ostr.str() );
      //handleIncomingFT(static_cast<FTICQSubType*>(ist));
      return false;
    }
    
    UINICQSubType *uist = dynamic_cast<UINICQSubType*>(ist);
    MessageEvent *ev = ICQSubTypeToEvent(ist, contact, advanced);
    ICQMessageEvent *mev = dynamic_cast<ICQMessageEvent*>(ev);

    Status st = m_self_contact->getStatus();

    if (!advanced) {
      /* mark all non-advanced (ICQ) messages when in Occupied/DND as 'to
       * contact list', so they can be guaranteed to arrive, as they should
       * never be turned down (no ack is sent back) */
      if (mev != NULL && (st == STATUS_OCCUPIED || st == STATUS_DND))
	mev->setToContactList(true);
    }
    
    if (t == 0) t = ev->getTime();
    else ev->setTime(t);

    ev->setDelivered(true);
    // default to true - for clients that ignore this functionality

    if (ev->getType() != MessageEvent::AwayMessage) {
      messaged.emit(ev);
      contact->set_last_message_time( t );
    } else {
      contact->set_last_away_msg_check_time( t );

      ostringstream ostr;
      ostr << "Away_msg respons to: " << contact->getAlias() << endl;
      SignalLog( LogEvent::INFO, ostr.str() );
    }

    if (advanced) {
      /* All these operations only apply to advanced messages -
       * UINICQSubType messages, those that are associated to a UIN and
       * that were sent as an advanced message (through server or
       * direct, NOT offline), and consequently will the ack'ed.
       */

      /* request away message if we are not online */
      if (st != STATUS_ONLINE && advanced)
      {
	want_auto_resp.emit(mev);
	uist->setAwayMessage( m_translator->client_to_server(mev->getAwayMessage(), ENCODING_CONTACT_LOCALE, contact ) );
      }
      else
      {
	uist->setAwayMessage( "" );
      }

      /* update the UINICQSubType */
	
      uist->setACK(true);
      ack = true;
      
      if (ev->isDelivered())
      {
	/* set accept-status of ACK */
	switch(st) {
	case STATUS_ONLINE:
	  uist->setStatus(AcceptStatus_Online);
	  break;
	case STATUS_AWAY:
	  uist->setStatus(AcceptStatus_Away);
	  break;
	case STATUS_NA:
	  uist->setStatus(AcceptStatus_NA);
	  break;
	case STATUS_OCCUPIED:
	  uist->setStatus(AcceptStatus_Occ_Accept);
	  break;
	default:
	  uist->setStatus(AcceptStatus_Online);
	}
      } else {
	MessageEvent::DeliveryFailureReason r = ev->getDeliveryFailureReason();
	/* set accept-status of ACK */
	switch(r) {
	case MessageEvent::Failed_Denied:
	  uist->setStatus(AcceptStatus_Denied);
	  break;
	case MessageEvent::Failed_Occupied:
	  uist->setStatus(AcceptStatus_Occupied);
	  break;
	case MessageEvent::Failed_DND:
	  uist->setStatus(AcceptStatus_DND);
	  break;
	case MessageEvent::Failed_Ignored:
	  ack = false;
	  break;
	default:
	  uist->setStatus(AcceptStatus_Denied);
	}
      }

    }

    // delete the temporary event
    delete ev;

    // whether the message needs ack'ing
    return ack;
  }
Ejemplo n.º 20
0
/* search_result */
void WPclient::SignalSearchResultEvent(SearchResultEvent *ev) {
  meta_gen meta;

  if (search_ev == ev) {
	UIN_t uin;

    if (sesja->pend_search ==  NULL) {
      log_alert(ZONE,"No search at session");
      search_ev = NULL;
      return;
    }

    if (!ev->isExpired()) {
      //      ContactList& cl = ev->getContactList();
      
      ContactRef c = ev->getLastContactAdded();
      if (c.get() != NULL) {
        uin = c->getUIN();
        meta.nick  = (char*)c->getAlias().c_str();
        meta.first = (char*)c->getFirstName().c_str();
        meta.last  = (char*)c->getLastName().c_str();
        meta.email = (char*)c->getEmail().c_str();
        if (c->getAuthReq()) {
          meta.auth = 1;
        } else {
          meta.auth = 0;
        }


		switch (c->getStatus())
		  {
		  case STATUS_OFFLINE:
			meta.status = ICQ_STATUS_OFFLINE;
			break;
		  case STATUS_AWAY:
			meta.status = ICQ_STATUS_AWAY;
			break;
		  case STATUS_DND:
			meta.status = ICQ_STATUS_DND;
			break;
		  case STATUS_NA:
			meta.status = ICQ_STATUS_NA;
			break;
		  case STATUS_OCCUPIED:
			meta.status = ICQ_STATUS_NA;
			break;
		  case STATUS_FREEFORCHAT:
			meta.status = ICQ_STATUS_FREE_CHAT;
			break;
		  default:
			meta.status = ICQ_STATUS_ONLINE;
			break;
		  }
		
        
		log_debug(ZONE,"Search enter part");
        
        (*(meta_search_cb)sesja->pend_search->cb)
          (sesja,uin,&meta,sesja->pend_search->arg);
      }
    }
    else {
      log_alert(ZONE,"search timedout");
      uin = 0;
    }
    
    if (ev->isFinished()) {
      log_debug(ZONE,"Search send");
      (*(meta_search_cb)sesja->pend_search->cb)
        (sesja,uin,NULL,sesja->pend_search->arg);
      search_ev = NULL;
      sesja->pend_search = NULL;
    }
  }
  else {
    log_alert(ZONE,"Not our search event search_ev= %p",search_ev);
  }
}
Ejemplo n.º 21
0
void WPclient::SignalMessageAck(MessageEvent *ev) {
    if(!ev->isFinished()) return;

	unsigned int uin = 0;
    ContactRef c = ev->getContact();

	if (c->isVirtualContact())
	  uin = 0;
	else
	  uin = c->getUIN();

	if (ev->getType() == ICQ2000::MessageEvent::AwayMessage){
	  AwayMessageEvent *aev = static_cast<AwayMessageEvent*>(ev);
	  log_debug(ZONE,"Away message received");
	  sendContactPresence(uin,aev->getAwayMessage());
	  return;
	}
	
	if(!ev->isDelivered()) {
	  jid id;
	  xmlnode msg;
	  
	  switch(ev->getDeliveryFailureReason()) {
	    
	  case MessageEvent::Failed_Denied: 
	    msg = xmlnode_new_tag("message");	    
	    xmlnode_insert_cdata(xmlnode_insert_tag(msg,"body"),
							 it_convert_windows2utf8(xmlnode_pool(msg),LNG_M_ACK_IGNORE),
							 (unsigned int) -1);	    	
	    break;
	  
	  case MessageEvent::Failed_Occupied:
	    msg = xmlnode_new_tag("message");	     
	    xmlnode_insert_cdata(xmlnode_insert_tag(msg,"body"),
							 it_convert_windows2utf8(xmlnode_pool(msg),LNG_M_ACK_BUSY),
							 (unsigned int) -1);	   	
	    break;

	  case MessageEvent::Failed_DND:
	    msg = xmlnode_new_tag("message");	     
	    xmlnode_insert_cdata(xmlnode_insert_tag(msg,"body"),
							 it_convert_windows2utf8(xmlnode_pool(msg),LNG_M_ACK_DND),
							 (unsigned int) -1);	   	
				break;
	  case MessageEvent::Failed_NotConnected:
	    return;
	    msg = xmlnode_new_tag("message");	     
	    xmlnode_insert_cdata(xmlnode_insert_tag(msg,"body"),
							 it_convert_windows2utf8(xmlnode_pool(msg),LNG_M_ACK_NC),
							 (unsigned int) -1); 	
	    break;

	  case MessageEvent::Failed:
	  default:
	    msg = xmlnode_new_tag("message");	     
	    xmlnode_insert_cdata(xmlnode_insert_tag(msg,"body"),
							 it_convert_windows2utf8(xmlnode_pool(msg),LNG_M_ACK_FAIL),
							 (unsigned int) -1);	   	
	  }
	  
	  xmlnode_put_attrib(msg,"to",jid_full(sesja->id));
	  id = it_uin2jid(xmlnode_pool(msg),uin,sesja->from->server);
	  xmlnode_put_attrib(msg,"from",jid_full(id));
	  it_deliver(sesja->ti,msg);
	  return;	
	}

        /* Parsing away messages included in message acks would be nice
         * but does not work with ICQ Lite and some other clients which
         * either put in a "not supported" here or echo the last message
         * sent to them.
	ICQMessageEvent *cev = dynamic_cast<ICQMessageEvent*>(ev);
	if (cev && (cev->getAwayMessage().size())) {
	  log_debug(ZONE,"Away message received with message ack");
	  sendContactPresence(uin,cev->getAwayMessage());
	} */
}
Ejemplo n.º 22
0
void WPclient::SignalMessaged(MessageEvent *ev) {
    jid id;
    xmlnode msg;
	unsigned int uin = 0;
    ContactRef c = ev->getContact();

	if (c->isVirtualContact())
	  uin = 0;
	else
	  uin = c->getUIN();
	
    switch(ev->getType()){
    case MessageEvent::Normal: {
        NormalMessageEvent* nm=static_cast<NormalMessageEvent*>(ev);
        msg = xmlnode_new_tag("message");
        contact sc;
        bool type_chat;

        sc = it_contact_get(sesja,uin);
        if (sc)
          type_chat = sc->use_chat_msg_type;
        else
          if (sesja->ti->msg_chat)
            type_chat = true;
          else
            type_chat = false;
        
        if(type_chat)
          xmlnode_put_attrib(msg,"type","chat");
        
        log_debug(ZONE,"Message: len->%i encoding->%i text->%s",int((nm->getMessage()).length()),
                                                              int(nm->getTextEncoding()),(nm->getMessage()).c_str());
        if (nm->getTextEncoding()==2)      // UCS2BE
          xmlnode_insert_cdata(xmlnode_insert_tag(msg,"body"),
                             it_convert_ucs2utf8(xmlnode_pool(msg),
                                                 (nm->getMessage()).length(),
                                                 (nm->getMessage()).c_str()),
                             (unsigned int)-1);
        else if (nm->getTextEncoding()==8) // UTF-8
          xmlnode_insert_cdata( xmlnode_insert_tag(msg,"body") ,
                             (nm->getMessage()).c_str()     ,
                             (unsigned int)-1);
        
        else                        // 0==ASCII and 3==locale_encoded will go here.
          xmlnode_insert_cdata(xmlnode_insert_tag(msg,"body"),
                             it_convert_windows2utf8(xmlnode_pool(msg),
                                                     (nm->getMessage()).c_str()),
                             (unsigned int)-1);

	if ((ev->getTime()!=0) && ((ev->getTime()+120)<time(NULL))) {
                // if the message travels more than 2 minutes it is not online anyway. Stamp it.
    		xmlnode x;
    		char timestamp[24];
		const time_t time=ev->getTime();
		struct tm *t=gmtime(&time);

		snprintf(timestamp,24,"%04i%02i%02iT%02i:%02i:%02i",t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec);
		x=xmlnode_insert_tag(msg,"x");
		xmlnode_put_attrib(x,"xmlns","jabber:x:delay");
		xmlnode_put_attrib(x,"stamp",timestamp);
        }
        break;
    }
    case MessageEvent::URL: {
        URLMessageEvent* urlm=static_cast<URLMessageEvent*>(ev);
        msg = xmlnode_new_tag("message");

        xmlnode_insert_cdata(xmlnode_insert_tag(msg,"subject"),
                     "ICQ URL Message",(unsigned int)-1);

        /* add a message body that most clients can understand */
        xmlnode_insert_cdata(xmlnode_insert_tag(msg,"body"),
                     it_convert_windows2utf8(xmlnode_pool(msg),
                                 ("URL: "+(urlm->getURL())+"\nDescription:\n"+
                                  (urlm->getMessage())).c_str()),
                     (unsigned int)-1);

        xmlnode x = xmlnode_insert_tag(msg,"x");
        xmlnode_put_attrib(x,"xmlns",NS_XOOB);
        xmlnode_insert_cdata(xmlnode_insert_tag(x,"desc"),
                     it_convert_windows2utf8(xmlnode_pool(msg),
                                 (urlm->getMessage()).c_str()),
                     (unsigned int)-1);
        xmlnode_insert_cdata(xmlnode_insert_tag(x,"url"),
                     it_convert_windows2utf8(xmlnode_pool(msg),
                                 (urlm->getURL()).c_str()),
                     (unsigned int)-1);
        break;
    }
    case MessageEvent::AuthReq: {
	    contact cc;
        AuthReqEvent *autr = static_cast<AuthReqEvent*>(ev);

		log_debug(ZONE,"Authorization request received");

        msg = xmlnode_new_tag("presence");
        xmlnode_insert_cdata(xmlnode_insert_tag(msg,"status"),
                             it_convert_windows2utf8(xmlnode_pool(msg),
                                                     autr->getMessage().c_str()),
                             (unsigned int)-1);

        xmlnode_put_attrib(msg,"type","subscribe");

        /* add to our roster  !!!! */
        cc = it_contact_get(sesja,uin);
        if (cc == NULL)
          it_contact_add(sesja,uin);        
        break;
    }
    case MessageEvent::UserAdd: {
      contact cc;
      msg = xmlnode_new_tag("presence");
      xmlnode_put_attrib(msg,"type","subscribe");
      
      /* add to our roster  !!!! */
      cc = it_contact_get(sesja,uin);
      if (cc == NULL)
        it_contact_add(sesja,uin);
      
      log_debug(ZONE,"User added message recived");
      break;
    }
    case MessageEvent::AuthAck: {
              log_debug(ZONE,"Authorization received");

        AuthAckEvent* ackm=static_cast<AuthAckEvent*>(ev);
        msg = xmlnode_new_tag("presence");
        if(ackm->isGranted())
          xmlnode_put_attrib(msg,"type","subscribed");
        else 
          xmlnode_put_attrib(msg,"type","unsubscribed");
        break;
    }
    case MessageEvent::SMS: {
        log_debug(ZONE,"SMS received");
        SMSMessageEvent* smsm=static_cast<SMSMessageEvent*>(ev);
        
        msg = xmlnode_new_tag("message");
        string text=smsm->getMessage();
        xmlnode_insert_cdata(xmlnode_insert_tag(msg,"body"),
                     text.c_str(),text.size());
        
        xmlnode_put_attrib(msg,"to",jid_full(sesja->id));
        xmlnode_put_attrib(msg,"from",(c->getMobileNo()+
                           "@"+sesja->ti->sms_id).c_str());
        it_deliver(sesja->ti,msg);
        return;
    }
    case MessageEvent::SMS_Receipt: {
        log_debug(ZONE,"SMS receipt received");
        SMSReceiptEvent* receipt=static_cast<SMSReceiptEvent*>(ev);
        
        msg = xmlnode_new_tag("message");
        string text= LNG_SMS_MESSAGE+ 
          ( receipt->delivered() ? 
            string(LNG_SMS_DELIVERED) + receipt->getDeliveryTime() :
            LNG_SMS_NOTDELIVERED );

        xmlnode_insert_cdata(xmlnode_insert_tag(msg,"body"),
							 it_convert_windows2utf8(xmlnode_pool(msg),text.c_str()),
                             (unsigned int)-1);

        xmlnode_put_attrib(msg,"to",jid_full(sesja->id));
        xmlnode_put_attrib(msg,"from",(c->getMobileNo()+
                           "@"+sesja->ti->sms_id).c_str());
        it_deliver(sesja->ti,msg);
        return;
    }
    case MessageEvent::AwayMessage: {
          log_debug(ZONE,"Away message received");
        AwayMessageEvent *aev = static_cast<AwayMessageEvent*>(ev);
        
        sendContactPresence(aev->getContact()->getUIN(),
                            aev->getAwayMessage());
        return;
    }
    case MessageEvent::EmailEx: {
        log_debug(ZONE,"email express received");
        EmailExEvent* eeev=static_cast<EmailExEvent*>(ev);
        
        msg = xmlnode_new_tag("message");
        xmlnode_insert_cdata(xmlnode_insert_tag(msg,"body"),
                     it_convert_windows2utf8(xmlnode_pool(msg),
                                             ((eeev->getSender())+
                                              LNG_EMAIL_1 +
                                              eeev->getEmail() +
                                              LNG_EMAIL_2 +
                                              eeev->getMessage()).c_str()),
                             (unsigned int)-1);
        break;
    }
    case MessageEvent::Email: {
        log_debug(ZONE,"email message received");
        EmailMessageEvent* emev=static_cast<EmailMessageEvent*>(ev);
        
        msg = xmlnode_new_tag("message");
        xmlnode_insert_cdata(xmlnode_insert_tag(msg,"body"),
                     it_convert_windows2utf8(xmlnode_pool(msg),
                                 (emev->getMessage()).c_str()),
                     (unsigned int)-1);
        
        break;
        
    }
	
	case MessageEvent::WebPager: {
        log_debug(ZONE,"email express received");
        WebPagerEvent* ewp=static_cast<WebPagerEvent*>(ev);
        
        msg = xmlnode_new_tag("message");
        xmlnode_insert_cdata(xmlnode_insert_tag(msg,"body"),
							 it_convert_windows2utf8(xmlnode_pool(msg),
                                             (LNG_PAGER_1 +
											  (ewp->getSender())+
                                              LNG_PAGER_2 +
                                              ewp->getEmail() +
                                              LNG_PAGER_3 +
                                              ewp->getMessage()).c_str()),
                             (unsigned int)-1);
	  break;
	}

    default:
      msg = xmlnode_new_tag("message");
      char s[]="You have recived unknown message";
      xmlnode_insert_cdata(xmlnode_insert_tag(msg,"body"),s,
                   (unsigned int)-1);
      break;
    }
    
    xmlnode_put_attrib(msg,"to",jid_full(sesja->id));
    id = it_uin2jid(xmlnode_pool(msg),uin,sesja->from->server);
    xmlnode_put_attrib(msg,"from",jid_full(id));
    it_deliver(sesja->ti,msg);

    ev->setDelivered(true);
    return;    
}