bool SimObjBase::checkAttrs() { // added by yahara@tome (2011/02/22) // TODO: strange codes; it should be modified: by inamura on 2013-12-29 #define DEFINE_ATTR_STRING(NAME, TOKEN) (char *)TOKEN, #define DEFINE_ATTR_DOUBLE(NAME, TOKEN) (char *)TOKEN, #define DEFINE_ATTR_BOOL(NAME, TOKEN) (char *)TOKEN, // modified by inamura on 2013-12-29 // TODO: The above three definitions will be used to extract just attribution string from SimObjBaseAttrs.h // This way is too dangerous. by inamura static char *namesForAgent[] = { (char *)"name", (char *)"class", #include "SimObjBaseAttrs.h" }; static char *namesForEntities[] = { (char *)"name", (char *)"class", #define NO_AGENT_ATTRS #include "SimObjBaseAttrs.h" #undef NO_AGENT_ATTRS }; char **names = isAgent()? namesForAgent: namesForEntities; const char *myname = name(); bool b = true; for (int i=0; i<ARY_SIZE(names); i++) { const char *attrname = names[i]; if (hasAttr(attrname) == NULL) { b = false; LOG_ERR(("%s : no attribute \"%s\"", myname? myname:"noname", attrname)); } } return b; #undef DEFINE_ATTR_DOUBLE #undef DEFINE_ATTR_BOOL }
void JabberClient::contactInfo(void *_data, unsigned long &curStatus, unsigned &style, const char *&statusIcon, string *icons) { JabberUserData *data = (JabberUserData*)_data; const CommandDef *def = protocol()->statusList(); for (; def->text; def++){ if (def->id == data->Status) break; } if ((def == NULL) || (def->text == NULL)) return; if (data->Status > curStatus){ curStatus = data->Status; if (icons && statusIcon){ string iconSave = *icons; *icons = statusIcon; if (iconSave.length()){ *icons += ","; *icons += iconSave; } } statusIcon = def->icon; }else{ if (statusIcon){ if (icons){ if (icons->length()) *icons += ","; *icons += def->icon; } }else{ statusIcon = def->icon; } } if (((data->Subscribe & SUBSCRIBE_TO) == 0) && !isAgent(data->ID)) style |= CONTACT_UNDERLINE; }
void JabberClient::auth_request(const char *jid, unsigned type, const char *text, bool bCreate) { Contact *contact; JabberUserData *data = findContact(jid, NULL, false, contact); if (isAgent(jid)){ switch (type){ case MessageAuthRequest:{ if (data == NULL) data = findContact(jid, NULL, true, contact); m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID << "\" type=\"subscribed\"></presence>"; sendPacket(); m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID << "\" type=\"subscribe\"><status>" << "</status></presence>"; sendPacket(); Event e(EventContactChanged, contact); e.process(); return; } case MessageAuthGranted:{ if (data == NULL) data = findContact(jid, NULL, true, contact); Event e(EventContactChanged, contact); e.process(); return; } } } if ((data == NULL) && bCreate){ data = findContact(jid, NULL, true, contact); contact->setTemporary(CONTACT_TEMP); } if (data == NULL) return; AuthMessage msg(type); msg.setContact(contact->id()); msg.setClient(dataName(data).c_str()); msg.setFlags(MESSAGE_RECEIVED); if (text) msg.setText(unquoteString(QString::fromUtf8(text))); Event e(EventMessageReceived, &msg); e.process(); }
bool JabberClient::canSend(unsigned type, void *_data) { if ((_data == NULL) || (getState() != Connected)) return false; JabberUserData *data = (JabberUserData*)_data; switch (type){ case MessageGeneric: return true; case MessageAuthRequest: return ((data->Subscribe & SUBSCRIBE_TO) == 0) && !isAgent(data->ID); case MessageAuthGranted: return ((data->Subscribe & SUBSCRIBE_FROM) == 0) && !isAgent(data->ID); case MessageAuthRefused: return (data->Subscribe & SUBSCRIBE_FROM) && !isAgent(data->ID); case MessageJabberOnline: return isAgent(data->ID) && (data->Status == STATUS_OFFLINE); case MessageJabberOffline: return isAgent(data->ID) && (data->Status != STATUS_OFFLINE); } return false; }
bool JabberClient::send(Message *msg, void *_data) { if (getState() != Connected) return false; JabberUserData *data = (JabberUserData*)_data; switch (msg->type()){ case MessageAuthRefused:{ string grp; Group *group = NULL; Contact *contact = getContacts()->contact(msg->contact()); if (contact && contact->getGroup()) group = getContacts()->group(contact->getGroup()); if (group) grp = group->getName().utf8(); listRequest(data, data->Name, grp.c_str(), false); if (data->Subscribe & SUBSCRIBE_FROM){ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID; m_socket->writeBuffer << "\" type=\"unsubscribed\"><status>" << (const char*)(quoteString(msg->getPlainText(), false).utf8()) << "</status></presence>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } } case MessageGeneric:{ Contact *contact = getContacts()->contact(msg->contact()); if ((contact == NULL) || (data == NULL)) return false; m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<message to=\"" << data->ID; m_socket->writeBuffer << "\"><body>" << (const char*)msg->getPlainText().utf8() << "</body></message>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } case MessageAuthRequest:{ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID; m_socket->writeBuffer << "\" type=\"subscribe\"><status>" << (const char*)(quoteString(msg->getPlainText(), false).utf8()) << "</status></presence>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } case MessageAuthGranted:{ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID; m_socket->writeBuffer << "\" type=\"subscribed\"></presence>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } case MessageJabberOnline: if (isAgent(data->ID) && (data->Status == STATUS_OFFLINE)){ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID << "\"></presence>"; sendPacket(); delete msg; return true; } break; case MessageJabberOffline: if (isAgent(data->ID) && (data->Status != STATUS_OFFLINE)){ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID << "\" type=\"unavailable\"></presence>"; sendPacket(); delete msg; return true; } break; } return false; }
void JabberClient::contactInfo(void *_data, unsigned long &curStatus, unsigned &style, const char *&statusIcon, string *icons) { JabberUserData *data = (JabberUserData*)_data; const CommandDef *def = protocol()->statusList(); for (; def->text; def++){ if (def->id == data->Status) break; } if ((def == NULL) || (def->text == NULL)) return; const char *dicon = def->icon; if (getProtocolIcons()){ char *host = strchr(data->ID, '@'); if (host){ string h = host + 1; char *p = strchr((char*)(h.c_str()), '.'); if (p) *p = 0; if (strcmp(h.c_str(), "icq") == 0){ switch (data->Status){ case STATUS_ONLINE: dicon = "ICQ_online"; break; case STATUS_OFFLINE: dicon = "ICQ_offline"; break; case STATUS_AWAY: dicon = "ICQ_away"; break; case STATUS_NA: dicon = "ICQ_na"; break; case STATUS_DND: dicon = "ICQ_dnd"; break; case STATUS_FFC: dicon = "ICQ_ffc"; break; } }else if (strcmp(h.c_str(), "aim") == 0){ switch (data->Status){ case STATUS_ONLINE: dicon = "AIM_online"; break; case STATUS_OFFLINE: dicon = "AIM_offline"; break; case STATUS_AWAY: dicon = "AIM_away"; break; } }else if (strcmp(h.c_str(), "msn") == 0){ switch (data->Status){ case STATUS_ONLINE: dicon = "MSN_online"; break; case STATUS_OFFLINE: dicon = "MSN_offline"; break; case STATUS_AWAY: dicon = "MSN_away"; break; case STATUS_NA: dicon = "MSN_na"; break; case STATUS_DND: dicon = "MSN_dnd"; break; } } } } if (data->Status > curStatus){ curStatus = data->Status; if (statusIcon && icons){ string iconSave = *icons; *icons = statusIcon; if (iconSave.length()) addIcon(icons, iconSave.c_str(), statusIcon); } statusIcon = dicon; }else{ if (statusIcon){ addIcon(icons, dicon, statusIcon); }else{ statusIcon = dicon; } } if (((data->Subscribe & SUBSCRIBE_TO) == 0) && !isAgent(data->ID)) style |= CONTACT_UNDERLINE; if (icons && data->TypingId && *data->TypingId) addIcon(icons, "typing", statusIcon); }
bool JabberClient::send(Message *msg, void *_data) { if ((getState() != Connected) || (_data == NULL)) return false; JabberUserData *data = (JabberUserData*)_data; switch (msg->type()){ case MessageAuthRefused:{ string grp; Group *group = NULL; Contact *contact = getContacts()->contact(msg->contact()); if (contact && contact->getGroup()) group = getContacts()->group(contact->getGroup()); if (group) grp = group->getName().utf8(); listRequest(data, data->Name, grp.c_str(), false); if (data->Subscribe & SUBSCRIBE_FROM){ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID; m_socket->writeBuffer << "\" type=\"unsubscribed\"><status>" << (const char*)(quoteString(msg->getPlainText(), false).utf8()) << "</status></presence>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } } case MessageGeneric:{ Contact *contact = getContacts()->contact(msg->contact()); if ((contact == NULL) || (data == NULL)) return false; m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<message type=\"chat\" to=\"" << data->ID; m_socket->writeBuffer << "\"><body>" << (const char*)msg->getPlainText().utf8() << "</body>"; if (data->richText){ char bgColor[8]; sprintf(bgColor, "%06X", msg->getBackground() & 0xFFFFFF); m_socket->writeBuffer << "<html xmlns='http://jabber.org/protocol/xhtml-im'>" << "<body bgcolor=\"#" << bgColor << "\">" << removeImages(msg->getRichText()).utf8() << "</body></html>"; } m_socket->writeBuffer << "</message>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } case MessageAuthRequest:{ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID; m_socket->writeBuffer << "\" type=\"subscribe\"><status>" << (const char*)(quoteString(msg->getPlainText(), false).utf8()) << "</status></presence>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } case MessageAuthGranted:{ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID; m_socket->writeBuffer << "\" type=\"subscribed\"></presence>"; sendPacket(); if ((msg->getFlags() & MESSAGE_NOHISTORY) == 0){ msg->setClient(dataName(data).c_str()); Event e(EventSent, msg); e.process(); } Event e(EventMessageSent, msg); e.process(); delete msg; return true; } case MessageJabberOnline: if (isAgent(data->ID) && (data->Status == STATUS_OFFLINE)){ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID << "\"></presence>"; sendPacket(); delete msg; return true; } break; case MessageJabberOffline: if (isAgent(data->ID) && (data->Status != STATUS_OFFLINE)){ m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<presence to=\"" << data->ID << "\" type=\"unavailable\"></presence>"; sendPacket(); delete msg; return true; } break; case MessageTypingStart: if (getTyping()){ data->composeId = ++m_msg_id; string msg_id = "msg"; msg_id += number(data->composeId); m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<message to=\"" << data->ID << "\"><x xmlns='jabber:x:event'><composing/><id>" << msg_id.c_str() << "</id></x></message>"; sendPacket(); delete msg; return true; } break; case MessageTypingStop: if (getTyping()){ if (data->composeId == 0) return false; string msg_id = "msg"; msg_id += number(data->composeId); m_socket->writeBuffer.packetStart(); m_socket->writeBuffer << "<message to=\"" << data->ID << "\"><x xmlns='jabber:x:event'><id>" << msg_id.c_str() << "</id></x></message>"; sendPacket(); delete msg; return true; } break; } return false; }