Exemplo n.º 1
0
/* deletes contact from friendlist and puts in blocklist */
void block_friend(Tox *m, uint32_t fnum)
{
    if (Friends.num_friends <= 0)
        return;

    realloc_blocklist(Blocked.max_idx + 1);
    memset(&Blocked.list[Blocked.max_idx], 0, sizeof(BlockedFriend));

    int i;

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

        Blocked.list[i].active = true;
        Blocked.list[i].num = i;
        Blocked.list[i].namelength = Friends.list[fnum].namelength;
        Blocked.list[i].last_on = Friends.list[fnum].last_online.last_on;
        memcpy(Blocked.list[i].pub_key, Friends.list[fnum].pub_key, TOX_PUBLIC_KEY_SIZE);
        memcpy(Blocked.list[i].name, Friends.list[fnum].name, Friends.list[fnum].namelength + 1);

        ++Blocked.num_blocked;

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

        delete_friend(m, fnum);
        save_blocklist(BLOCK_FILE);
        sort_blocklist_index();
        sort_friendlist_index();

        return;
    }
}
Exemplo n.º 2
0
int load_blocklist(char *path)
{
    if (path == NULL)
        return -1;

    FILE *fp = fopen(path, "rb");

    if (fp == NULL)
        return -1;

    off_t len = file_size(path);

    if (len == 0) {
        fclose(fp);
        return -1;
    }

    char data[len];

    if (fread(data, len, 1, fp) != 1) {
        fclose(fp);
        return -1;
    }

    if (len % sizeof(BlockedFriend) != 0) {
        fclose(fp);
        return -1;
    }

    int num = len / sizeof(BlockedFriend);
    Blocked.max_idx = num;
    realloc_blocklist(num);

    int i;

    for (i = 0; i < num; ++i) {
        BlockedFriend tmp;
        memset(&tmp, 0, sizeof(BlockedFriend));
        memset(&Blocked.list[i], 0, sizeof(BlockedFriend));

        memcpy(&tmp, data + i * sizeof(BlockedFriend), sizeof(BlockedFriend));
        Blocked.list[i].active = true;
        Blocked.list[i].num = i;
        Blocked.list[i].namelength = ntohs(tmp.namelength);
        memcpy(Blocked.list[i].name, tmp.name, Blocked.list[i].namelength + 1);
        memcpy(Blocked.list[i].pub_key, tmp.pub_key, TOX_PUBLIC_KEY_SIZE);

        uint8_t lastonline[sizeof(uint64_t)];
        memcpy(lastonline, &tmp.last_on, sizeof(uint64_t));
        net_to_host(lastonline, sizeof(uint64_t));
        memcpy(&Blocked.list[i].last_on, lastonline, sizeof(uint64_t));

        ++Blocked.num_blocked;
    }

    fclose(fp);
    sort_blocklist_index();

    return 0;
}
Exemplo n.º 3
0
void kill_friendlist(void)
{
    int i;

    for (i = 0; i < Friends.max_idx; ++i) {
        if (Friends.list[i].active && Friends.list[i].group_invite.key != NULL)
            free(Friends.list[i].group_invite.key);
    }

    realloc_blocklist(0);
    realloc_friends(0);
}
Exemplo n.º 4
0
void kill_friendlist(ToxWindow *self)
{
    for (size_t i = 0; i < Friends.max_idx; ++i) {
        if (Friends.list[i].active && Friends.list[i].group_invite.key != NULL) {
            free(Friends.list[i].group_invite.key);
        }
    }

    realloc_blocklist(0);
    realloc_friends(0);
    free(self->help);
    del_window(self);
}
Exemplo n.º 5
0
/* deletes contact from blocked list */
static void delete_blocked_friend(uint32_t bnum)
{
    memset(&Blocked.list[bnum], 0, sizeof(BlockedFriend));

    int i;

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

    --Blocked.num_blocked;
    Blocked.max_idx = i;
    realloc_blocklist(i);
    save_blocklist(BLOCK_FILE);

    if (Blocked.num_blocked && Blocked.num_selected == Blocked.num_blocked)
        --Blocked.num_selected;
}
Exemplo n.º 6
0
int load_blocklist(char *path)
{
    if (path == NULL)
        return -1;

    FILE *fp = fopen(path, "rb");

    if (fp == NULL)
        return -1;

    off_t len = file_size(path);

    if (len == -1) {
        fclose(fp);
        return -1;
    }

    char *data = malloc(len);

    if (data == NULL) {            
        fclose(fp);
        exit_toxic_err("Failed in load_blocklist", FATALERR_MEMORY);
    }

    if (fread(data, len, 1, fp) != 1) {
        fclose(fp);
        free(data);
        return -1;
    }

    if (len % sizeof(BlockedFriend) != 0) {
        fclose(fp);
        free(data);
        return -1;
    }

    int num = len / sizeof(BlockedFriend);
    Blocked.max_idx = num;
    realloc_blocklist(num);

    int i;

    for (i = 0; i < num; ++i) {
        memset(&Blocked.list[i], 0, sizeof(BlockedFriend));

        BlockedFriend tmp;
        memcpy(&tmp, data + i * sizeof(BlockedFriend), sizeof(BlockedFriend));
        Blocked.list[i].active = true;
        Blocked.list[i].num = i;
        Blocked.list[i].namelength = ntohs(tmp.namelength);
        memcpy(Blocked.list[i].name, tmp.name, Blocked.list[i].namelength + 1);
        memcpy(Blocked.list[i].pub_key, tmp.pub_key, TOX_CLIENT_ID_SIZE);

        uint8_t lastonline[sizeof(uint64_t)];
        memcpy(lastonline, &tmp.last_on, sizeof(uint64_t));
        net_to_host(lastonline, sizeof(uint64_t));
        memcpy(&Blocked.list[i].last_on, lastonline, sizeof(uint64_t));

        ++Blocked.num_blocked;
    }

    free(data);
    fclose(fp);
    sort_blocklist_index();

    return 0;
}