예제 #1
0
파일: friendlist.c 프로젝트: jpoler/toxic
static void delete_friend(Tox *m, int32_t f_num)
{
    if (Friends.list[f_num].chatwin >= 0) {
        ToxWindow *toxwin = get_window_ptr(Friends.list[f_num].chatwin);

        if (toxwin != NULL) {
            kill_chat_window(toxwin, m);
            set_active_window(1);   /* keep friendlist focused */
        }
    }

    if (Friends.list[f_num].group_invite.key != NULL)
        free(Friends.list[f_num].group_invite.key);

    tox_del_friend(m, f_num);
    memset(&Friends.list[f_num], 0, sizeof(ToxicFriend));

    int i;

    for (i = Friends.max_idx; i > 0; --i) {
        if (Friends.list[i - 1].active)
            break;
    }

    Friends.max_idx = i;
    Friends.num_friends = tox_count_friendlist(m);
    realloc_friends(i);

    /* make sure num_selected stays within Friends.num_friends range */
    if (Friends.num_friends && Friends.num_selected == Friends.num_friends)
        --Friends.num_selected;

    store_data(m, DATA_FILE);
}
예제 #2
0
static void delete_friend(Tox *m, int32_t f_num)
{
    int i;

    if (friends[f_num].chatwin >= 0) {
        ToxWindow *toxwin = get_window_ptr(friends[f_num].chatwin);

        if (toxwin != NULL) {
            kill_chat_window(toxwin);
            set_active_window(1);   /* keep friendlist focused */
        }
    }

    tox_del_friend(m, f_num);
    memset(&friends[f_num], 0, sizeof(ToxicFriend));

    for (i = max_friends_index; i > 0; --i) {
        if (friends[i - 1].active)
            break;
    }

    max_friends_index = i;
    num_friends = tox_count_friendlist(m);

    /* make sure num_selected stays within num_friends range */
    if (num_friends && num_selected == num_friends)
        --num_selected;

    store_data(m, DATA_FILE);
}
예제 #3
0
파일: friendlist.c 프로젝트: jpoler/toxic
/* puts blocked friend back in friendlist. fnum is new friend number, bnum is blocked number */
static void friendlist_add_blocked(Tox *m, int32_t fnum, int32_t bnum)
{
    Friends.num_friends = tox_count_friendlist(m);
    realloc_friends(Friends.max_idx + 1);
    memset(&Friends.list[Friends.max_idx], 0, sizeof(ToxicFriend));

    int i;

    for (i = 0; i <= Friends.max_idx; ++i) {
        if (Friends.list[i].active)
            continue;

        Friends.list[i].num = fnum;
        Friends.list[i].active = true;
        Friends.list[i].chatwin = -1;
        Friends.list[i].status = TOX_USERSTATUS_NONE;
        Friends.list[i].logging_on = (bool) user_settings->autolog == AUTOLOG_ON;
        Friends.list[i].namelength = Blocked.list[bnum].namelength;
        update_friend_last_online(i, Blocked.list[bnum].last_on);
        memcpy(Friends.list[i].name, Blocked.list[bnum].name, Friends.list[i].namelength + 1);
        memcpy(Friends.list[i].pub_key, Blocked.list[bnum].pub_key, TOX_CLIENT_ID_SIZE);

        if (i == Friends.max_idx)
            ++Friends.max_idx;

        sort_blocklist_index();
        sort_friendlist_index();

        return;
    }
}
예제 #4
0
/* puts blocked friend back in friendlist. fnum is new friend number, bnum is blocked number */
static void friendlist_add_blocked(Tox *m, int32_t fnum, int32_t bnum)
{
    if (max_friends_index >= MAX_FRIENDS_NUM)
        return;

    int i;

    for (i = 0; i <= max_friends_index; ++i) {
        if (friends[i].active)
            continue;

        friends[i].num = fnum;
        friends[i].active = true;
        friends[i].chatwin = -1;
        friends[i].status = TOX_USERSTATUS_NONE;
        friends[i].logging_on = (bool) user_settings_->autolog == AUTOLOG_ON;
        friends[i].namelength = Blocked_Contacts.list[bnum].namelength;
        update_friend_last_online(i, Blocked_Contacts.list[bnum].last_on);
        memcpy(friends[i].name, Blocked_Contacts.list[bnum].name, friends[i].namelength + 1);
        memcpy(friends[i].pub_key, Blocked_Contacts.list[bnum].pub_key, TOX_CLIENT_ID_SIZE);

        num_friends = tox_count_friendlist(m);

        if (i == max_friends_index)
            ++max_friends_index;

        sort_blocklist_index();
        sort_friendlist_index();
        return;
    }
}
예제 #5
0
파일: main.c 프로젝트: stqism/toxic
static void load_friendlist(Tox *m)
{
    int32_t i;
    uint32_t numfriends = tox_count_friendlist(m);

    for (i = 0; i < numfriends; ++i)
        friendlist_onFriendAdded(NULL, m, i, false);
}
예제 #6
0
파일: friendlist.c 프로젝트: jpoler/toxic
void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int32_t num, bool sort)
{
    if (Friends.max_idx < 0)
        return;


    Friends.num_friends = tox_count_friendlist(m);
    realloc_friends(Friends.max_idx + 1);
    memset(&Friends.list[Friends.max_idx], 0, sizeof(ToxicFriend));

    int i;

    for (i = 0; i <= Friends.max_idx; ++i) {
        if (Friends.list[i].active)
            continue;

        Friends.list[i].num = num;
        Friends.list[i].active = true;
        Friends.list[i].chatwin = -1;
        Friends.list[i].online = false;
        Friends.list[i].status = TOX_USERSTATUS_NONE;
        Friends.list[i].logging_on = (bool) user_settings->autolog == AUTOLOG_ON;
        tox_get_client_id(m, num, (uint8_t *) Friends.list[i].pub_key);
        update_friend_last_online(i, tox_get_last_online(m, i));

        char tempname[TOX_MAX_NAME_LENGTH] = {0};
        int len = get_nick_truncate(m, tempname, num);

        if (len == -1 || tempname[0] == '\0') {
            strcpy(Friends.list[i].name, UNKNOWN_NAME);
            Friends.list[i].namelength = strlen(UNKNOWN_NAME);
        } else {    /* Enforce toxic's maximum name length */
            snprintf(Friends.list[i].name, sizeof(Friends.list[i].name), "%s", tempname);
            Friends.list[i].namelength = strlen(Friends.list[i].name);
        }

        if (i == Friends.max_idx)
            ++Friends.max_idx;

        if (sort)
            sort_friendlist_index();

        return;
    }
}
예제 #7
0
파일: core.cpp 프로젝트: tr37ion/qTox
void Core::setAvatar(uint8_t format, const QByteArray& data)
{
    if (tox_set_avatar(tox, format, (uint8_t*)data.constData(), data.size()) != 0)
    {
        qWarning() << "Core: Failed to set self avatar";
        return;
    }

    QPixmap pic;
    pic.loadFromData(data);
    Settings::getInstance().saveAvatar(pic, getSelfId().toString());
    emit selfAvatarChanged(pic);
    
    // Broadcast our new avatar!
    // according to tox.h, we need not broadcast this ourselves, but initial testing indicated elsewise
    const uint32_t friendCount = tox_count_friendlist(tox);;
    for (unsigned i=0; i<friendCount; i++)
        tox_send_avatar_info(tox, i);
}
예제 #8
0
void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int32_t num, bool sort)
{
    if (max_friends_index < 0 || max_friends_index >= MAX_FRIENDS_NUM)
        return;

    int i;

    for (i = 0; i <= max_friends_index; ++i) {
        if (!friends[i].active) {
            friends[i].num = num;
            friends[i].active = true;
            friends[i].chatwin = -1;
            friends[i].online = false;
            friends[i].status = TOX_USERSTATUS_NONE;
            friends[i].logging_on = (bool) user_settings_->autolog == AUTOLOG_ON;
            tox_get_client_id(m, num, (uint8_t *) friends[i].pub_key);
            update_friend_last_online(i, tox_get_last_online(m, i));

            char tempname[TOX_MAX_NAME_LENGTH] = {0};
            int len = get_nick_truncate(m, tempname, num);

            if (len == -1 || tempname[0] == '\0') {
                strcpy(friends[i].name, UNKNOWN_NAME);
                friends[i].namelength = strlen(UNKNOWN_NAME);
            } else {    /* Enforce toxic's maximum name length */
                friends[i].namelength = len;
                snprintf(friends[i].name, sizeof(friends[i].name), "%s", tempname);
            }

            num_friends = tox_count_friendlist(m);

            if (i == max_friends_index)
                ++max_friends_index;

            if (sort)
                sort_friendlist_index();

            return;
        }
    }
}
예제 #9
0
파일: friendlist.c 프로젝트: Jman012/toxic
static void delete_friend(Tox *m, int f_num)
{
    tox_del_friend(m, f_num);
    memset(&friends[f_num], 0, sizeof(ToxicFriend));
    
    int i;

    for (i = max_friends_index; i > 0; --i) {
        if (friends[i-1].active)
            break;
    }

    max_friends_index = i;
    num_friends = tox_count_friendlist(m);

    /* make sure num_selected stays within num_friends range */
    if (num_friends && num_selected == num_friends)
        --num_selected;

    sort_friendlist_index(m);
    store_data(m, DATA_FILE);
}
예제 #10
0
파일: friendlist.c 프로젝트: Jman012/toxic
void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int num, bool sort)
{
    if (max_friends_index < 0 || max_friends_index >= MAX_FRIENDS_NUM)
        return;

    int i;

    for (i = 0; i <= max_friends_index; ++i) {
        if (!friends[i].active) {
            friends[i].num = num;
            friends[i].active = true;
            friends[i].chatwin = -1;
            friends[i].online = false;
            friends[i].status = TOX_USERSTATUS_NONE;
            friends[i].namelength = tox_get_name(m, num, friends[i].name);
            tox_get_client_id(m, num, friends[i].pub_key);

            if (friends[i].namelength == -1 || friends[i].name[0] == '\0') {
                strcpy(friends[i].name, (uint8_t *) UNKNOWN_NAME);
                friends[i].namelength = strlen(UNKNOWN_NAME) + 1;
            } else {    /* Enforce toxic's maximum name length */
                friends[i].name[TOXIC_MAX_NAME_LENGTH] = '\0';
                friends[i].namelength = strlen(friends[i].name) + 1;
            }

            num_friends = tox_count_friendlist(m);

            if (i == max_friends_index)
                ++max_friends_index;

            if (sort)
                sort_friendlist_index(m);

            return;
        }
    }
}
예제 #11
0
파일: core.cpp 프로젝트: ReDetection/qTox
void Core::loadFriends()
{
    const uint32_t friendCount = tox_count_friendlist(tox);
    if (friendCount > 0) {
        // assuming there are not that many friends to fill up the whole stack
        int32_t *ids = new int32_t[friendCount];
        tox_get_friendlist(tox, ids, friendCount);
        uint8_t clientId[TOX_CLIENT_ID_SIZE];
        for (int32_t i = 0; i < static_cast<int32_t>(friendCount); ++i) {
            if (tox_get_client_id(tox, ids[i], clientId) == 0) {
                emit friendAdded(ids[i], CUserId::toString(clientId));

                const int nameSize = tox_get_name_size(tox, ids[i]);
                if (nameSize > 0) {
                    uint8_t *name = new uint8_t[nameSize];
                    if (tox_get_name(tox, ids[i], name) == nameSize) {
                        emit friendUsernameLoaded(ids[i], CString::toString(name, nameSize));
                    }
                    delete[] name;
                }

                const int statusMessageSize = tox_get_status_message_size(tox, ids[i]);
                if (statusMessageSize > 0) {
                    uint8_t *statusMessage = new uint8_t[statusMessageSize];
                    if (tox_get_status_message(tox, ids[i], statusMessage, statusMessageSize) == statusMessageSize) {
                        emit friendStatusMessageLoaded(ids[i], CString::toString(statusMessage, statusMessageSize));
                    }
                    delete[] statusMessage;
                }

                checkLastOnline(ids[i]);
            }

        }
        delete[] ids;
    }
}
예제 #12
0
파일: tox.c 프로젝트: Boerde/uTox
static _Bool load_save(Tox *tox)
{
    {
        uint8_t path[512], *p;
        uint32_t size;

        p = path + datapath(path);
        strcpy((char*)p, "tox_save");

        void *data = file_raw((char*)path, &size);
        if(!data) {
            p = path + datapath_old(path);
            strcpy((char*)p, "tox_save");
            data = file_raw((char*)path, &size);
            if (!data) {
                data = file_raw("tox_save", &size);
                if(!data) {
                    return 0;
                }
            }
        }

        tox_load(tox, data, size);
        free(data);
    }

    friends = tox_count_friendlist(tox);

    uint32_t i = 0;
    while(i != friends) {
        int size;
        FRIEND *f = &friend[i];
        uint8_t name[TOX_MAX_NAME_LENGTH];

        f->msg.scroll = 1.0;

        tox_get_client_id(tox, i, f->cid);

        size = tox_get_name(tox, i, name);

        friend_setname(f, name, size);

        size = tox_get_status_message_size(tox, i);
        f->status_message = malloc(size);
        tox_get_status_message(tox, i, f->status_message, size);
        f->status_length = size;

        log_read(tox, i);

        i++;
    }

    self.name_length = tox_get_self_name(tox, self.name);
    self.statusmsg_length = tox_get_self_status_message_size(tox);
    self.statusmsg = malloc(self.statusmsg_length);
    tox_get_self_status_message(tox, self.statusmsg, self.statusmsg_length);
    self.status = tox_get_self_user_status(tox);


    return 1;
}
예제 #13
0
파일: tox_test.c 프로젝트: 2mauis/toxcore
END_TEST

#define NUM_TOXES 66
#define NUM_FRIENDS 20

START_TEST(test_many_clients)
{
    long long unsigned int cur_time = time(NULL);
    Tox *toxes[NUM_TOXES];
    uint32_t i, j;
    uint32_t to_comp = 974536;

    for (i = 0; i < NUM_TOXES; ++i) {
        toxes[i] = tox_new(0);
        ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i);
        tox_callback_friend_request(toxes[i], accept_friend_request, &to_comp);
    }

    struct {
        uint16_t tox1;
        uint16_t tox2;
    } pairs[NUM_FRIENDS];

    uint8_t address[TOX_FRIEND_ADDRESS_SIZE];

    for (i = 0; i < NUM_FRIENDS; ++i) {
loop_top:
        pairs[i].tox1 = rand() % NUM_TOXES;
        pairs[i].tox2 = (pairs[i].tox1 + rand() % (NUM_TOXES - 1) + 1) % NUM_TOXES;

        for (j = 0; j < i; ++j) {
            if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2)
                goto loop_top;
        }

        tox_get_address(toxes[pairs[i].tox1], address);
        int test = tox_add_friend(toxes[pairs[i].tox2], address, (uint8_t *)"Gentoo", 7);

        if (test == TOX_FAERR_ALREADYSENT) {
            goto loop_top;
        }

        ck_assert_msg(test >= 0, "Failed to add friend error code: %i", test);
    }

    while (1) {
        uint16_t counter = 0;

        for (i = 0; i < NUM_TOXES; ++i) {
            for (j = 0; j < tox_count_friendlist(toxes[i]); ++j)
                if (tox_get_friend_connection_status(toxes[i], j) == 1)
                    ++counter;
        }

        if (counter == NUM_FRIENDS * 2) {
            break;
        }

        for (i = 0; i < NUM_TOXES; ++i) {
            tox_do(toxes[i]);
        }

        c_sleep(50);
    }

    printf("test_many_clients succeeded, took %llu seconds\n", time(NULL) - cur_time);

    for (i = 0; i < NUM_TOXES; ++i) {
        tox_kill(toxes[i]);
    }
}