AxoConversation* AxoConversation::loadConversation(const string& localUser, const string& user, const string& deviceId)
{
    SQLiteStoreConv* store = SQLiteStoreConv::getStore();
    if (!store->hasConversation(user, deviceId, localUser)) {
//        cerr << "No conversation: " << localUser << ", user: "******"cannot load conversation" << endl;
        delete conv;
        return NULL;
    }
    conv->deserialize(*data);
    delete data;
    return conv;
}
示例#2
0
void SipTransport::notifyAxo(const uint8_t* data, size_t length)
{
    LOGGER(DEBUGGING, __func__, " -->");
    string info((const char*)data, length);
    /*
     * notify call back from SIP:
     *   - parse data from SIP, get name and devices
     *   - check for new devices (store->hasConversation() )
     *   - if a new device was found call appInterface_->notifyCallback(...)
     *     NOTE: the notifyCallback function in app should return ASAP, queue/trigger actions only
     *   - done
     */

    size_t found = info.find(':');
    if (found == string::npos)        // No colon? No name -> return
        return;

    string name = info.substr(0, found);
    size_t foundAt = name.find('@');
    if (foundAt != string::npos) {
        name = name.substr(0, foundAt);
    }

    string devIds = info.substr(found + 1);
    string devIdsSave(devIds);

    // This is a check if the SIP server already sent the same notify string for a name
    map<string, string>::iterator it;
    it = seenIdStringsForName.find(name);
    if (it != seenIdStringsForName.end()) {
        // Found an entry, check if device ids match, if yes -> return, already processed,
        // if no -> delete the entry, continue processing which will add the new entry.
        if (it->second == devIdsSave) {
            return;
        }
        else {
            seenIdStringsForName.erase(it);
        }
    }
    pair<map<string, string>::iterator, bool> ret;
    ret = seenIdStringsForName.insert(pair<string, string>(name, devIdsSave));
    if (!ret.second) {
        LOGGER(ERROR, "Caching of notified device ids failed: ", name, ", ", devIdsSave);
    }

    const bool isSibling = appInterface_->getOwnUser() == name;

    size_t pos = 0;
    string devId;
    SQLiteStoreConv* store = SQLiteStoreConv::getStore();

    size_t numReportedDevices = 0;
    bool newDevice = false;
    while ((pos = devIds.find(';')) != string::npos) {
        devId = devIds.substr(0, pos);
        devIds.erase(0, pos + 1);
        if (Zeros.compare(0, devId.size(), devId) == 0) {
            continue;
        }
        if (isSibling && appInterface_->getOwnDeviceId() == devId) {
            continue;
        }
        numReportedDevices++;
        if (!store->hasConversation(name, devId, appInterface_->getOwnUser())) {
            newDevice = true;
            break;
        }
    }
    list<StringUnique> devicesDb;
    store->getLongDeviceIds(name, appInterface_->getOwnUser(), devicesDb);
    size_t numKnownDevices = devicesDb.size();

    // If we saw a new device or the number of reported and known devices differs the user
    // added or removed a device, re-scan devices
    if (newDevice || numKnownDevices != numReportedDevices) {
        LOGGER(INFO, __func__, " Calling notify callback for: ", name, ", device: ", devIdsSave);
        appInterface_->notifyCallback_(AppInterface::DEVICE_SCAN, name, devIdsSave);
    }
    LOGGER(DEBUGGING, __func__, " <--");
}