LiveJournalUserData *LiveJournalClient::findContact(const char *user, Contact *&contact, bool bCreate, bool bJoin)
{
    ContactList::ContactIterator it;
    while ((contact = ++it) != NULL) {
        LiveJournalUserData *data;
        ClientDataIterator itc(contact->clientData, this);
        while ((data = (LiveJournalUserData*)(++itc)) != NULL) {
            if (!strcmp(data->User.ptr, user))
                return data;
        }
    }
    if (!bCreate)
        return NULL;
    QString sname = QString::fromUtf8(user);
    if (bJoin) {
        it.reset();
        while ((contact = ++it) != NULL) {
            if (contact->getName().lower() == sname.lower())
                break;;
        }
    }
    if (contact == NULL) {
        contact = getContacts()->contact(0, true);
        contact->setName(sname);
    }
    LiveJournalUserData *data = (LiveJournalUserData*)(contact->clientData.createData(this));
    set_str(&data->User.ptr, user);
    Event e(EventContactChanged, contact);
    e.process();
    return data;
}
Beispiel #2
0
void YahooClient::loadList(const char *str)
{
    Contact *contact;
    ContactList::ContactIterator it;
    while ((contact = ++it) != NULL) {
        YahooUserData *data;
        ClientDataIterator itd(contact->clientData, this);
        while ((data = (YahooUserData*)(++itd)) != NULL) {
            data->bChecked.bValue = (contact->getGroup() == 0);
        }
    }
    if (str) {
        string s = str;
        while (!s.empty()) {
            string line = getToken(s, '\n');
            string grp = getToken(line, ':');
            if (line.empty()) {
                line = grp;
                grp = "";
            }
            while (!line.empty()) {
                string id = getToken(line, ',');
                Contact *contact;
                YahooUserData *data = findContact(id.c_str(), grp.c_str(), contact, false);
                data->bChecked.bValue = true;
            }
        }
    }
    it.reset();
    list<Contact*> forRemove;
    while ((contact = ++it) != NULL) {
        YahooUserData *data;
        ClientDataIterator itd(contact->clientData, this);
        list<YahooUserData*> dataForRemove;
        bool bChanged = false;
        while ((data = (YahooUserData*)(++itd)) != NULL) {
            if (!data->bChecked.bValue) {
                dataForRemove.push_back(data);
                bChanged = true;
            }
        }
        if (!bChanged)
            continue;
        for (list<YahooUserData*>::iterator it = dataForRemove.begin(); it != dataForRemove.end(); ++it)
            contact->clientData.freeData(*it);
        if (contact->clientData.size()) {
            Event e(EventContactChanged, contact);
            e.process();
        } else {
            forRemove.push_back(contact);
        }
    }
    for (list<Contact*>::iterator itr = forRemove.begin(); itr != forRemove.end(); ++itr)
        delete *itr;
}
Beispiel #3
0
YahooUserData *YahooClient::findContact(const char *id, const char *grpname, Contact *&contact, bool bSend)
{
    ContactList::ContactIterator it;
    while ((contact = ++it) != NULL) {
        YahooUserData *data;
        ClientDataIterator itd(contact->clientData);
        while ((data = (YahooUserData*)(++itd)) != NULL) {
            if (data->Login.ptr && !strcmp(id, data->Login.ptr))
                return data;
        }
    }
    it.reset();
    while ((contact = ++it) != NULL) {
        if (contact->getName() == id) {
            YahooUserData *data = (YahooUserData*)contact->clientData.createData(this);
            set_str(&data->Login.ptr, id);
            set_str(&data->Group.ptr, grpname);
            Event e(EventContactChanged, contact);
            e.process();
            return data;
        }
    }
    if (grpname == NULL)
        return NULL;
    Group *grp = NULL;
    if (*grpname) {
        ContactList::GroupIterator it;
        while ((grp = ++it) != NULL)
            if (grp->getName() == QString::fromLocal8Bit(grpname))
                break;
        if (grp == NULL) {
            grp = getContacts()->group(0, true);
            grp->setName(QString::fromLocal8Bit(grpname));
            Event e(EventGroupChanged, grp);
            e.process();
        }
    }
    if (grp == NULL)
        grp = getContacts()->group(0);
    contact = getContacts()->contact(0, true);
    YahooUserData *data = (YahooUserData*)(contact->clientData.createData(this));
    set_str(&data->Login.ptr, id);
    contact->setName(id);
    contact->setGroup(grp->id());
    Event e(EventContactChanged, contact);
    e.process();
    if (bSend)
        addBuddy(data);
    return data;
}
Beispiel #4
0
JabberUserData *JabberClient::findContact(const char *alias, const char *name, bool bCreate, Contact *&contact)
{
    char *resource = NULL;
    char *p = strchr((char*)alias, '@');
    if (p){
        p = strchr(p, '/');
        if (p){
            *p = 0;
            resource = p + 1;
        }
    }
    ContactList::ContactIterator it;
    while ((contact = ++it) != NULL){
        JabberUserData *data;
        ClientDataIterator it(contact->clientData, this);
        while ((data = (JabberUserData*)(++it)) != NULL){
            if (strcmp(data->ID, alias))
                continue;
            if (resource)
                set_str(&data->Resource, resource);
            if (name)
                set_str(&data->Name, name);
            return data;
        }
    }
    if (!bCreate)
        return NULL;
    it.reset();
    QString sname;
    if (name && *name){
        sname = QString::fromUtf8(name).lower();
    }else{
        sname = QString::fromUtf8(alias).lower();
        int pos = sname.find('@');
        if (pos > 0)
            sname = sname.left(pos);
    }
    while ((contact = ++it) != NULL){
        if (contact->getName().lower() == sname.lower()){
            JabberUserData *data = (JabberUserData*)(contact->clientData.createData(this));
            set_str(&data->ID, alias);
            if (resource)
                set_str(&data->Resource, resource);
            if (name)
                set_str(&data->Name, name);
            info_request(data);
            Event e(EventContactChanged, contact);
            e.process();
            return data;
        }
    }
    contact = getContacts()->contact(0, true);
    JabberUserData *data = (JabberUserData*)(contact->clientData.createData(this));
    set_str(&data->ID, alias);
    if (resource)
        set_str(&data->Resource, resource);
    if (name)
        set_str(&data->Name, name);
    contact->setName(sname);
    info_request(data);
    Event e(EventContactChanged, contact);
    e.process();
    return data;
}
Beispiel #5
0
JabberUserData *JabberClient::findContact(const char *alias, const char *host, const char *name, bool bCreate, Contact *&contact)
{
    char *resource = NULL;
    char *p = strchr((char*)alias, '@');
    if (p){
        *p = 0;
        host = p + 1;
        p = strchr((char*)host, '/');
        if (p){
            *p = 0;
            resource = p + 1;
        }
    }
    if (host == NULL)
        host = data.owner.VHost;
    ContactList::ContactIterator it;
    while ((contact = ++it) != NULL){
        JabberUserData *data;
        ClientDataIterator it(contact->clientData, this);
        while ((data = (JabberUserData*)(++it)) != NULL){
            if (strcmp(data->ID, alias) || strcmp(data->VHost, host))
                continue;
            if (resource)
                set_str(&data->Resource, resource);
            if (name)
                set_str(&data->Name, name);
            return data;
        }
    }
    if (!bCreate)
        return NULL;
    it.reset();
    while ((contact = ++it) != NULL){
        QString name = QString::fromUtf8(alias).lower();
        if (name && *name)
            name = QString::fromUtf8(name).lower();
        QString cname = contact->getName().lower();
        if (contact->getName().lower() == name){
            JabberUserData *data = (JabberUserData*)(contact->clientData.createData(this));
            set_str(&data->ID, alias);
            set_str(&data->VHost, host);
            if (resource)
                set_str(&data->Resource, resource);
            if (name)
                set_str(&data->Name, name);
            info_request(data);
            Event e(EventContactChanged, contact);
            e.process();
            return data;
        }
    }
    contact = getContacts()->contact(0, true);
    JabberUserData *data = (JabberUserData*)(contact->clientData.createData(this));
    set_str(&data->ID, alias);
    set_str(&data->VHost, host);
    if (resource)
        set_str(&data->Resource, resource);
    if (name)
        set_str(&data->Name, name);
    contact->setName(QString::fromUtf8(alias));
    if (name && *name)
        contact->setName(QString::fromUtf8(name));
    info_request(data);
    Event e(EventContactChanged, contact);
    e.process();
    return data;
}
void *ForwardPlugin::processEvent(Event *e)
{
    if (e->type() == EventMessageReceived){
        Message *msg = (Message*)(e->param());
        if (msg->type() == MessageStatus)
            return NULL;
        QString text = msg->getPlainText();
        if (text.isEmpty())
            return NULL;
        if (msg->type() == MessageSMS){
            SMSMessage *sms = static_cast<SMSMessage*>(msg);
            QString phone = sms->getPhone();
            bool bMyPhone = false;
            ForwardUserData *data = (ForwardUserData*)(getContacts()->getUserData(user_data_id));
            if (data->Phone.ptr)
                bMyPhone = ContactList::cmpPhone(phone.toUtf8(), data->Phone.ptr);
            if (!bMyPhone){
                Group *grp;
                ContactList::GroupIterator it;
                while ((grp = ++it) != NULL){
                    data = (ForwardUserData*)(grp->userData.getUserData(user_data_id, false));
                    if (data && data->Phone.ptr){
                        bMyPhone = ContactList::cmpPhone(phone.toUtf8(), data->Phone.ptr);
                        break;
                    }
                }
            }
            if (!bMyPhone){
                Contact *contact;
                ContactList::ContactIterator it;
                while ((contact = ++it) != NULL){
                    data = (ForwardUserData*)(contact->userData.getUserData(user_data_id, false));
                    if (data && data->Phone.ptr){
                        bMyPhone = ContactList::cmpPhone(phone.toUtf8(), data->Phone.ptr);
                        break;
                    }
                }
            }
            if (bMyPhone){
                int n = text.find(": ");
                if (n > 0){
                    QString name = text.left(n);
                    QString msg_text = text.mid(n + 2);
                    Contact *contact;
                    ContactList::ContactIterator it;
                    while ((contact = ++it) != NULL){
                        if (contact->getName() == name){
                            Message *msg = new Message(MessageGeneric);
                            msg->setContact(contact->id());
                            msg->setText(msg_text);
                            void *data;
                            ClientDataIterator it(contact->clientData);
                            while ((data = ++it) != NULL){
                                if (it.client()->send(msg, data))
                                    break;
                            }
                            if (data == NULL)
                                delete msg;
                            return e->param();
                        }
                    }
                }
            }
        }
        Contact *contact = getContacts()->contact(msg->contact());
        if (contact == NULL)
            return NULL;
        ForwardUserData *data = (ForwardUserData*)(contact->getUserData(user_data_id));
        if ((data == NULL) || (data->Phone.ptr == NULL) || (*data->Phone.ptr == 0))
            return NULL;
        unsigned status = core->getManualStatus();
        if ((status == STATUS_AWAY) || (status == STATUS_NA)){
            text = contact->getName() + ": " + text;
            unsigned flags = MESSAGE_NOHISTORY;
            if (data->Send1st.bValue)
                flags |= MESSAGE_1ST_PART;
            if (data->Translit.bValue)
                flags |= MESSAGE_TRANSLIT;
            SMSMessage *m = new SMSMessage;
            m->setPhone(QString::fromUtf8(data->Phone.ptr));
            m->setText(text);
            m->setFlags(flags);
            unsigned i;
            for (i = 0; i < getContacts()->nClients(); i++){
                Client *client = getContacts()->getClient(i);
                if (client->send(m, NULL))
                    break;
            }
            if (i >= getContacts()->nClients())
                delete m;
        }
    }
    return NULL;
}
Beispiel #7
0
bool ForwardPlugin::processEvent(Event *e)
{
    if (e->type() == eEventMessageReceived){
        EventMessage *em = static_cast<EventMessage*>(e);
        Message *msg = em->msg();
        if (msg->type() == MessageStatus)
            return false;
        QString text = msg->getPlainText();
        if (text.isEmpty())
            return false;
        if (msg->type() == MessageSMS){
            SMSMessage *sms = static_cast<SMSMessage*>(msg);
            QString phone = sms->getPhone();
            bool bMyPhone;
            SIM::PropertyHubPtr data = getContacts()->getUserData("forward");
            bMyPhone = ContactList::cmpPhone(phone, data->value("Phone").toString());
            if (!bMyPhone){
                Group *grp;
                ContactList::GroupIterator it;
                while ((grp = ++it) != NULL){
                    data = grp->getUserData("forward", false);
                    if (data && !data->value("Phone").toString().isEmpty()){
                        bMyPhone = ContactList::cmpPhone(phone, data->value("Phone").toString());
                        break;
                    }
                }
            }
            if (!bMyPhone){
                Contact *contact;
                ContactList::ContactIterator it;
                while ((contact = ++it) != NULL){
                    data = contact->getUserData("forward", false);
                    if (data && !data->value("Phone").toString().isEmpty())
                    {
                        bMyPhone = ContactList::cmpPhone(phone, data->value("Phone").toString());
                        break;
                    }
                }
            }
            if (bMyPhone){
                int n = text.indexOf(": ");
                if (n > 0){
                    QString name = text.left(n);
                    QString msg_text = text.mid(n + 2);
                    Contact *contact;
                    ContactList::ContactIterator it;
                    while ((contact = ++it) != NULL){
                        if (contact->getName() == name){
                            Message *msg = new Message(MessageGeneric);
                            msg->setContact(contact->id());
                            msg->setText(msg_text);
                            void *data;
                            ClientDataIterator it(contact->clientData);
                            while ((data = ++it) != NULL){
                                if (it.client()->send(msg, data))
                                    break;
                            }
                            if (data == NULL)
                                delete msg;
                            return true;
                        }
                    }
                }
            }
        }
        Contact *contact = getContacts()->contact(msg->contact());
        if (contact == NULL)
            return false;
        SIM::PropertyHubPtr data = contact->getUserData("forward");
        if (!data || data->value("Key").toString().isEmpty())
            return false;
        CorePlugin *core = GET_CorePlugin();
        unsigned status = core->getManualStatus();
        if ((status == STATUS_AWAY) || (status == STATUS_NA)){
            text = contact->getName() + ": " + text;
            unsigned flags = MESSAGE_NOHISTORY;
            if (data->value("Send1st").toBool())
                flags |= MESSAGE_1ST_PART;
            if (data->value("Translit").toBool())
                flags |= MESSAGE_TRANSLIT;
            SMSMessage *m = new SMSMessage;
            m->setPhone(data->value("Phone").toString());
            m->setText(text);
            m->setFlags(flags);
            unsigned i;
            for (i = 0; i < getContacts()->nClients(); i++){
                Client *client = getContacts()->getClient(i);
                if (client->send(m, NULL))
                    break;
            }
            if (i >= getContacts()->nClients())
                delete m;
        }
    }
    return false;
}