示例#1
0
END_TEST

START_TEST(test_m_delfriend)
{
    ck_assert_msg((m_delfriend(m, -1) == -1),
                  "m_delfriend did NOT catch an argument of -1\n");
    ck_assert_msg((m_delfriend(m, REALLY_BIG_NUMBER) == -1),
                  "m_delfriend did NOT catch the following number: %d\n",
                  REALLY_BIG_NUMBER);
}
示例#2
0
void delete_friend()
{
    size_t len = strlen(line);
    char numstring[len-3];
    int i;
    
    for (i = 0; i < len; i++) {
        if (line[i+3] != ' ')
            numstring[i] = line[i+3];
    }
    
    int num = atoi(numstring);
    m_delfriend(num);
    --maxnumfriends;
    printf("\n\n");
}
示例#3
0
void line_eval(char* line)
{
    if(line[0] == '/') {
        char inpt_command = line[1];
        /* Add friend */
        if(inpt_command == 'f') {
            int i;
            char temp_id[128];
            for (i = 0; i < 128; i++) 
                temp_id[i] = line[i+3];
            int num = m_addfriend(hex_string_to_bin(temp_id), (uint8_t*)"Install Gentoo", sizeof("Install Gentoo"));
            if (num >= 0) {
                char numstring[100];
                sprintf(numstring, "\n[i] Friend request sent. Wait to be accepted. Friend id: %d\n\n", num);
                printf(numstring);
            }
            else if (num == -1) 
                printf("\n[i] Message is too long.\n\n");
            else if (num == -2)
                printf("\n[i] Please add a message to your friend request.\n\n");
            else if (num == -3)
                printf("\n[i] That appears to be your own ID.\n\n");
            else if (num == -4)
                printf("\n[i] Friend request already sent.\n\n");
            else if (num == -5)
                printf("\n[i] Undefined error when adding friend\n\n");
        }

        else if (inpt_command == 'r') {
            do_header();
            printf("\n\n");
        }

        else if (inpt_command == 'l') {
            int activefriends = 0;
            int i;

            for (i = 0; i <= getnumfriends(); i++)
            {
                if (m_friendstatus(i) == 4)
                    activefriends++;
            }

            printf("\n[i] Friend List | Total: %d\n\n", activefriends);

            for (i = 0; i <= getnumfriends(); i++) {
                char name[MAX_NAME_LENGTH];
                getname(i, (uint8_t*)name);
                if (m_friendstatus(i) == 4)    
                    printf("[%d] %s\n\n", i, (uint8_t*)name);
            }
        }

        else if (inpt_command == 'd') {
            size_t len = strlen(line);
            char numstring[len-3];
            int i;
            for (i = 0; i < len; i++) {
                if (line[i+3] != ' ') {
                    numstring[i] = line[i+3];
                }
            }
            int num = atoi(numstring);
            m_delfriend(num);
            printf("\n\n");
        }
        /* Send message to friend */
        else if (inpt_command == 'm') {
            size_t len = strlen(line);
            char numstring[len-3];
            char message[len-3];
            int i;
            for (i = 0; i < len; i++) {
                if (line[i+3] != ' ') {
                    numstring[i] = line[i+3];
                } else {
                    int j;
                    for (j = (i+1); j < len; j++)
                        message[j-i-1] = line[j+3];
                    break;
                }
            }
            int num = atoi(numstring);
            if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) {
                printf("\n[i] could not send message (they may be offline): %s\n", message);
            } else {
                //simply for aesthetics
                printf("\n");
            }
        }

        else if (inpt_command == 'n') {
            uint8_t name[MAX_NAME_LENGTH];
            int i = 0;
            size_t len = strlen(line);
            for (i = 3; i < len; i++) {
                if (line[i] == 0 || line[i] == '\n') break;
                name[i-3] = line[i];
            }
            name[i-3] = 0;
            setname(name, i);
            char numstring[100];
            sprintf(numstring, "\n[i] changed nick to %s\n\n", (char*)name);
            printf(numstring);

            FILE *name_file = NULL;
            name_file = fopen("namefile.txt", "w");
            fprintf(name_file, "%s", (char*)name);
            fclose(name_file);
        }

        else if (inpt_command == 's') {
            uint8_t status[MAX_USERSTATUS_LENGTH];
            int i = 0;
            size_t len = strlen(line);
            for (i = 3; i < len; i++) {
                if (line[i] == 0 || line[i] == '\n') break;
                status[i-3] = line[i];
            }
            status[i-3] = 0;
            m_set_userstatus(status, strlen((char*)status));
            char numstring[100];
            sprintf(numstring, "\n[i] changed status to %s\n\n", (char*)status);
            printf(numstring);

            FILE* status_file = NULL;
            status_file = fopen("statusfile.txt", "w");
            fprintf(status_file, "%s", (char*)status);
            fclose(status_file);
        }

        else if (inpt_command == 'a') {
            uint8_t numf = atoi(line + 3);
            char numchar[100];
            sprintf(numchar, "\n[i] friend request %u accepted\n\n", numf);
            printf(numchar);
            int num = m_addfriend_norequest(pending_requests[numf]);
            sprintf(numchar, "\n[i] added friendnumber %d\n\n", num);
            printf(numchar);
        }
        /* EXIT */
        else if (inpt_command == 'q') { 
            uint8_t status[MAX_USERSTATUS_LENGTH] = "Offline";
            m_set_userstatus(status, strlen((char*)status));
            exit(EXIT_SUCCESS);
        }
    } else {
        //nothing atm
    }
}
示例#4
0
/* Remove a friend. */
int tox_delfriend(void *tox, int friendnumber)
{
    Messenger *m = tox;
    return m_delfriend(m, friendnumber);
}
示例#5
0
文件: tox.c 项目: askielboe/toxcore
/* Remove a friend. */
int tox_del_friend(Tox *tox, int32_t friendnumber)
{
    Messenger *m = tox;
    return m_delfriend(m, friendnumber);
}