/** * 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; }
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; }