static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) { (void) userdata; if (length == 7 && memcmp("gentoo", data, 7) == 0) { ck_assert(tox_friend_add_norequest(m, public_key, NULL) != (uint32_t) ~0); } }
/** * Accept a friend request. Remove and free the request. */ bool twc_friend_request_accept(struct t_twc_friend_request *request) { TOX_ERR_FRIEND_ADD err; tox_friend_add_norequest(request->profile->tox, request->tox_id, &err); twc_friend_request_remove(request); return err == TOX_ERR_FRIEND_ADD_OK; }
/* cause I'm shameless */ void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) { if (*((uint32_t *)userdata) != 974536) return; if (length == 7 && memcmp("Gentoo", data, 7) == 0) { tox_friend_add_norequest(m, public_key, 0); } }
static void cb_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) { TOX_ERR_FRIEND_ADD err; tox_friend_add_norequest(m, public_key, &err); if (err != TOX_ERR_FRIEND_ADD_OK) fprintf(stderr, "tox_friend_add_norequest failed (error %d)\n", err); save_data(m, DATA_FILE); }
void accept_friend_request(Tox *tox, const uint8_t *public_key, const uint8_t *message, size_t length, void *userdata) { unsigned char tox_printable_id[TOX_ADDRESS_SIZE * 2 + 1]; int32_t friendnumber; TOX_ERR_FRIEND_ADD friend_add_error; log_printf(L_DEBUG, "Got friend request\n"); if(use_shared_secret) { if(!message) { log_printf(L_WARNING, "Friend sent NULL message - not accepting request"); return; } if(message[length - 1] != '\0') { log_printf(L_WARNING, "Message of size %u is not NULL terminated - not accepting request", length); return; } if(strncmp(message, shared_secret, TOX_MAX_FRIEND_REQUEST_LENGTH-1)) { log_printf(L_WARNING, "Received shared secret \"%s\" differs from our shared secret - not accepting request", message); return; } } memset(tox_printable_id, '\0', sizeof(tox_printable_id)); id_to_string(tox_printable_id, public_key); if(server_whitelist_mode) { allowed_toxid etmp, *found = NULL; memcpy(etmp.toxid, public_key, TOX_PUBLIC_KEY_SIZE); LL_SEARCH(allowed_toxids, found, &etmp, allowed_toxid_cmp); if(!found) { log_printf(L_WARNING, "Rejected friend request from non-whitelisted friend %s", tox_printable_id); return; } log_printf(L_DEBUG, "Friend %s passed whitelist check", tox_printable_id); } friendnumber = tox_friend_add_norequest(tox, public_key, &friend_add_error); if(friend_add_error != TOX_ERR_FRIEND_ADD_OK) { log_printf(L_WARNING, "Could not add friend: err %u", friend_add_error); return; } log_printf(L_INFO, "Accepted friend request from %s as %d\n", tox_printable_id, friendnumber); }
void Core::acceptFriendRequest(const ToxPk& friendPk) { // TODO: error handling uint32_t friendId = tox_friend_add_norequest(tox, friendPk.getBytes(), nullptr); if (friendId == std::numeric_limits<uint32_t>::max()) { emit failedToAddFriend(friendPk); } else { profile.saveToxSave(); emit friendAdded(friendId, friendPk); } }
void Core::acceptFriendRequest(const QString& userId) { uint32_t friendId = tox_friend_add_norequest(tox, CUserId(userId).data(), nullptr); if (friendId == std::numeric_limits<uint32_t>::max()) { emit failedToAddFriend(userId); } else { saveConfiguration(); emit friendAdded(friendId, userId); } }
/* removes friend from blocklist, puts back in friendlist */ static void unblock_friend(Tox *m, uint32_t bnum) { if (Blocked.num_blocked <= 0) return; TOX_ERR_FRIEND_ADD err; uint32_t friendnum = tox_friend_add_norequest(m, (uint8_t *) Blocked.list[bnum].pub_key, &err); if (err != TOX_ERR_FRIEND_ADD_OK) { line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to unblock friend (error %d)", err); return; } friendlist_add_blocked(m, friendnum, bnum); delete_blocked_friend(bnum); sort_blocklist_index(); sort_friendlist_index(); }
static void handle_friend_request( Tox *tox, const uint8_t *public_key, const uint8_t *message, size_t length, void *user_data) { // Accept the friend request: TOX_ERR_FRIEND_ADD err_friend_add; printf ("[tox] Friend request %s\n[tox] ", message); print_tox_address (public_key); int child = tox_friend_add_norequest (tox, public_key, &err_friend_add); // // int child = tox_friend_add (t, friend_address, himsg, strlen (himsg), &err); // int child = tox_friend_add_norequest(t, friend_address, &err); // char *himsg = "hi there"; // int child = tox_friend_add (tox, public_key, himsg, strlen (himsg), &err_friend_add); printf ("child %d %d\n", child, err_friend_add); /* if (err_friend_add != TOX_ERR_FRIEND_ADD_OK) { fprintf(stderr, "unable to add friend: %d\n", err_friend_add); } */ }
/* command functions */ void cmd_accept(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) { if (argc < 1) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Request ID required."); return; } int req = atoi(argv[1]); if ((req == 0 && strcmp(argv[1], "0")) || req < 0 || req > MAX_FRIEND_REQUESTS) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending friend request with that ID."); return; } if (!FrndRequests.request[req].active) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending friend request with that ID."); return; } TOX_ERR_FRIEND_ADD err; uint32_t friendnum = tox_friend_add_norequest(m, FrndRequests.request[req].key, &err); if (err != TOX_ERR_FRIEND_ADD_OK) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to add friend (error %d\n)", err); return; } else { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Friend request accepted."); on_friendadded(m, friendnum, true); } memset(&FrndRequests.request[req], 0, sizeof(struct friend_request)); int i; for (i = FrndRequests.max_idx; i > 0; --i) { if (FrndRequests.request[i - 1].active) break; } FrndRequests.max_idx = i; --FrndRequests.num_requests; }
static void addfriend(Tox *t) { const char *himsg = "hihihi"; // 4A06ABE7C9846F227A173B788802B4E5FEE3A0BAE1D5F449FF50C09089C88B20676C0EB625F8 const uint8_t friend_address[38] = { 0x4a, 0x06, 0xab, 0xe7, 0xc9, 0x84, 0x6f, 0x22, 0x7a, 0x17, 0x3b, 0x78, 0x88, 0x02, 0xb4, 0xe5, 0xfe, 0xe3, 0xa0, 0xba, 0xe1, 0xd5, 0xf4, 0x49, 0xff, 0x50, 0xc0, 0x90, 0x89, 0xc8, 0x8b, 0x20, 0x67, 0x6c, 0x0e, 0xb6, 0x25, 0xf8 }; TOX_ERR_FRIEND_ADD err; // int child = tox_friend_add (t, friend_address, himsg, strlen (himsg), &err); int child = tox_friend_add_norequest(t, friend_address, &err); printf ("SENDING HI TO %d\n", child); tox_friend_send_message(t, child, TOX_MESSAGE_TYPE_NORMAL, "hi", 2, &err); printf ("TOX ADD %d\n", err); printf ("FRIEND IS %d\n", child); // printf ("UDP %d\n", tox_self_get_udp_port(t, NULL)); //printf ("TDP %d\n", tox_self_get_tcp_port(t, NULL)); }
static void test_set_status_message(void) { printf("initialising 2 toxes\n"); uint32_t index[] = { 1, 2 }; const time_t cur_time = time(nullptr); Tox *const tox1 = tox_new_log(nullptr, nullptr, &index[0]); Tox *const tox2 = tox_new_log(nullptr, nullptr, &index[1]); ck_assert_msg(tox1 && tox2, "failed to create 2 tox instances"); printf("tox1 adds tox2 as friend, tox2 adds tox1\n"); uint8_t public_key[TOX_PUBLIC_KEY_SIZE]; tox_self_get_public_key(tox2, public_key); tox_friend_add_norequest(tox1, public_key, nullptr); tox_self_get_public_key(tox1, public_key); tox_friend_add_norequest(tox2, public_key, nullptr); printf("bootstrapping tox2 off tox1\n"); uint8_t dht_key[TOX_PUBLIC_KEY_SIZE]; tox_self_get_dht_id(tox1, dht_key); const uint16_t dht_port = tox_self_get_udp_port(tox1, nullptr); tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr); while (tox_self_get_connection_status(tox1) == TOX_CONNECTION_NONE || tox_self_get_connection_status(tox2) == TOX_CONNECTION_NONE) { tox_iterate(tox1, nullptr); tox_iterate(tox2, nullptr); c_sleep(ITERATION_INTERVAL); } printf("toxes are online, took %ld seconds\n", time(nullptr) - cur_time); const time_t con_time = time(nullptr); while (tox_friend_get_connection_status(tox1, 0, nullptr) != TOX_CONNECTION_UDP || tox_friend_get_connection_status(tox2, 0, nullptr) != TOX_CONNECTION_UDP) { tox_iterate(tox1, nullptr); tox_iterate(tox2, nullptr); c_sleep(ITERATION_INTERVAL); } printf("tox clients connected took %ld seconds\n", time(nullptr) - con_time); TOX_ERR_SET_INFO err_n; tox_callback_friend_status_message(tox2, status_callback); bool ret = tox_self_set_status_message(tox1, (const uint8_t *)STATUS_MESSAGE, sizeof(STATUS_MESSAGE), &err_n); ck_assert_msg(ret && err_n == TOX_ERR_SET_INFO_OK, "tox_self_set_status_message failed because %u\n", err_n); bool status_updated = false; while (!status_updated) { tox_iterate(tox1, nullptr); tox_iterate(tox2, &status_updated); c_sleep(ITERATION_INTERVAL); } ck_assert_msg(tox_friend_get_status_message_size(tox2, 0, nullptr) == sizeof(STATUS_MESSAGE), "status message length not correct"); uint8_t cmp_status[sizeof(STATUS_MESSAGE)]; tox_friend_get_status_message(tox2, 0, cmp_status, nullptr); ck_assert_msg(memcmp(cmp_status, STATUS_MESSAGE, sizeof(STATUS_MESSAGE)) == 0, "status message not correct"); printf("test_set_status_message succeeded, took %ld seconds\n", time(nullptr) - cur_time); tox_kill(tox1); tox_kill(tox2); }
void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) { if (length == 7 && memcmp("gentoo", data, 7) == 0) { tox_friend_add_norequest(m, public_key, 0); } }
int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); Tox *const tox1 = tox_new_log(nullptr, nullptr, nullptr); Tox *const tox2 = tox_new_log(nullptr, nullptr, nullptr); printf("bootstrapping tox2 off tox1\n"); uint8_t dht_key[TOX_PUBLIC_KEY_SIZE]; tox_self_get_dht_id(tox1, dht_key); const uint16_t dht_port = tox_self_get_udp_port(tox1, nullptr); tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr); struct test_data to_compare = {{0}}; uint8_t public_key[TOX_PUBLIC_KEY_SIZE]; tox_self_get_public_key(tox1, public_key); tox_friend_add_norequest(tox2, public_key, nullptr); tox_self_get_public_key(tox2, public_key); tox_friend_add_norequest(tox1, public_key, nullptr); uint8_t reference_name[TOX_MAX_NAME_LENGTH] = { 0 }; uint8_t reference_status[TOX_MAX_STATUS_MESSAGE_LENGTH] = { 0 }; set_random(tox1, tox_self_set_name, TOX_MAX_NAME_LENGTH); set_random(tox2, tox_self_set_name, TOX_MAX_NAME_LENGTH); set_random(tox1, tox_self_set_status_message, TOX_MAX_STATUS_MESSAGE_LENGTH); set_random(tox2, tox_self_set_status_message, TOX_MAX_STATUS_MESSAGE_LENGTH); tox_self_get_name(tox2, reference_name); tox_self_get_status_message(tox2, reference_status); tox_callback_friend_name(tox1, namechange_callback); tox_callback_friend_status_message(tox1, statuschange_callback); while (true) { if (tox_self_get_connection_status(tox1) && tox_self_get_connection_status(tox2) && tox_friend_get_connection_status(tox1, 0, nullptr) == TOX_CONNECTION_UDP) { printf("Connected.\n"); break; } tox_iterate(tox1, &to_compare); tox_iterate(tox2, nullptr); c_sleep(tox_iteration_interval(tox1)); } while (true) { if (to_compare.received_name && to_compare.received_status_message) { printf("Exchanged names and status messages.\n"); break; } tox_iterate(tox1, &to_compare); tox_iterate(tox2, nullptr); c_sleep(tox_iteration_interval(tox1)); } size_t save_size = tox_get_savedata_size(tox1); VLA(uint8_t, savedata, save_size); tox_get_savedata(tox1, savedata); struct Tox_Options *const options = tox_options_new(nullptr); tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE); tox_options_set_savedata_data(options, savedata, save_size); Tox *const tox_to_compare = tox_new_log(options, nullptr, nullptr); tox_friend_get_name(tox_to_compare, 0, to_compare.name, nullptr); tox_friend_get_status_message(tox_to_compare, 0, to_compare.status_message, nullptr); ck_assert_msg(memcmp(reference_name, to_compare.name, TOX_MAX_NAME_LENGTH) == 0, "incorrect name: should be all zeroes"); ck_assert_msg(memcmp(reference_status, to_compare.status_message, TOX_MAX_STATUS_MESSAGE_LENGTH) == 0, "incorrect status message: should be all zeroes"); tox_options_free(options); tox_kill(tox1); tox_kill(tox2); tox_kill(tox_to_compare); return 0; }
int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); State state1 = {1}; State state2 = {2}; State state3 = {3}; // Create toxes. Tox *tox1 = tox_new_log(nullptr, nullptr, &state1.id); Tox *tox2 = tox_new_log(nullptr, nullptr, &state2.id); Tox *tox3 = tox_new_log(nullptr, nullptr, &state3.id); // tox1 <-> tox2, tox2 <-> tox3 uint8_t key[TOX_PUBLIC_KEY_SIZE]; tox_self_get_public_key(tox2, key); tox_friend_add_norequest(tox1, key, nullptr); // tox1 -> tox2 tox_self_get_public_key(tox1, key); tox_friend_add_norequest(tox2, key, nullptr); // tox2 -> tox1 tox_self_get_public_key(tox3, key); tox_friend_add_norequest(tox2, key, nullptr); // tox2 -> tox3 tox_self_get_public_key(tox2, key); tox_friend_add_norequest(tox3, key, nullptr); // tox3 -> tox2 printf("bootstrapping tox2 and tox3 off tox1\n"); uint8_t dht_key[TOX_PUBLIC_KEY_SIZE]; tox_self_get_dht_id(tox1, dht_key); const uint16_t dht_port = tox_self_get_udp_port(tox1, nullptr); tox_bootstrap(tox2, "localhost", dht_port, dht_key, nullptr); tox_bootstrap(tox3, "localhost", dht_port, dht_key, nullptr); // Connection callbacks. tox_callback_self_connection_status(tox1, handle_self_connection_status); tox_callback_self_connection_status(tox2, handle_self_connection_status); tox_callback_self_connection_status(tox3, handle_self_connection_status); tox_callback_friend_connection_status(tox1, handle_friend_connection_status); tox_callback_friend_connection_status(tox2, handle_friend_connection_status); tox_callback_friend_connection_status(tox3, handle_friend_connection_status); // Conference callbacks. tox_callback_conference_invite(tox1, handle_conference_invite); tox_callback_conference_invite(tox2, handle_conference_invite); tox_callback_conference_invite(tox3, handle_conference_invite); tox_callback_conference_connected(tox1, handle_conference_connected); tox_callback_conference_connected(tox2, handle_conference_connected); tox_callback_conference_connected(tox3, handle_conference_connected); tox_callback_conference_message(tox1, handle_conference_message); tox_callback_conference_message(tox2, handle_conference_message); tox_callback_conference_message(tox3, handle_conference_message); tox_callback_conference_peer_list_changed(tox1, handle_conference_peer_list_changed); tox_callback_conference_peer_list_changed(tox2, handle_conference_peer_list_changed); tox_callback_conference_peer_list_changed(tox3, handle_conference_peer_list_changed); // Wait for self connection. fprintf(stderr, "Waiting for toxes to come online\n"); do { tox_iterate(tox1, &state1); tox_iterate(tox2, &state2); tox_iterate(tox3, &state3); c_sleep(100); } while (!state1.self_online || !state2.self_online || !state3.self_online); fprintf(stderr, "Toxes are online\n"); // Wait for friend connection. fprintf(stderr, "Waiting for friends to connect\n"); do { tox_iterate(tox1, &state1); tox_iterate(tox2, &state2); tox_iterate(tox3, &state3); c_sleep(100); } while (!state1.friend_online || !state2.friend_online || !state3.friend_online); fprintf(stderr, "Friends are connected\n"); { // Create new conference, tox1 is the founder. Tox_Err_Conference_New err; state1.conference = tox_conference_new(tox1, &err); state1.joined = true; ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "failed to create a conference: err = %d", err); fprintf(stderr, "Created conference: id = %u\n", state1.conference); } { // Invite friend. Tox_Err_Conference_Invite err; tox_conference_invite(tox1, 0, state1.conference, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "failed to invite a friend: err = %d", err); state1.invited_next = true; fprintf(stderr, "tox1 invited tox2\n"); } fprintf(stderr, "Waiting for invitation to arrive\n"); do { tox_iterate(tox1, &state1); tox_iterate(tox2, &state2); tox_iterate(tox3, &state3); c_sleep(100); } while (!state1.joined || !state2.joined || !state3.joined); fprintf(stderr, "Invitations accepted\n"); fprintf(stderr, "Waiting for peers to come online\n"); do { tox_iterate(tox1, &state1); tox_iterate(tox2, &state2); tox_iterate(tox3, &state3); c_sleep(100); } while (state1.peers == 0 || state2.peers == 0 || state3.peers == 0); fprintf(stderr, "All peers are online\n"); { fprintf(stderr, "tox1 sends a message to the group: \"hello!\"\n"); Tox_Err_Conference_Send_Message err; tox_conference_send_message(tox1, state1.conference, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)"hello!", 7, &err); if (err != TOX_ERR_CONFERENCE_SEND_MESSAGE_OK) { fprintf(stderr, "ERROR: %d\n", err); exit(EXIT_FAILURE); } } fprintf(stderr, "Waiting for messages to arrive\n"); do { tox_iterate(tox1, &state1); tox_iterate(tox2, &state2); tox_iterate(tox3, &state3); c_sleep(100); } while (!state2.received || !state3.received); fprintf(stderr, "Messages received. Test complete.\n"); tox_kill(tox3); tox_kill(tox2); tox_kill(tox1); return 0; }
int main(int argc, char *argv[]) { Tox *tox1 = tox_new_log(0, 0, 0); Tox *tox2 = tox_new_log(0, 0, 0); struct test_data to_compare = { { 0 } }; uint8_t public_key[TOX_PUBLIC_KEY_SIZE]; tox_self_get_public_key(tox1, public_key); tox_friend_add_norequest(tox2, public_key, NULL); tox_self_get_public_key(tox2, public_key); tox_friend_add_norequest(tox1, public_key, NULL); uint8_t reference_name[TOX_MAX_NAME_LENGTH] = { 0 }; uint8_t reference_status[TOX_MAX_STATUS_MESSAGE_LENGTH] = { 0 }; set_random(tox1, tox_self_set_name, TOX_MAX_NAME_LENGTH); set_random(tox2, tox_self_set_name, TOX_MAX_NAME_LENGTH); set_random(tox1, tox_self_set_status_message, TOX_MAX_STATUS_MESSAGE_LENGTH); set_random(tox2, tox_self_set_status_message, TOX_MAX_STATUS_MESSAGE_LENGTH); tox_self_get_name(tox2, reference_name); tox_self_get_status_message(tox2, reference_status); tox_callback_friend_name(tox1, namechange_callback); tox_callback_friend_status_message(tox1, statuschange_callback); while (true) { if (tox_self_get_connection_status(tox1) && tox_self_get_connection_status(tox2) && tox_friend_get_connection_status(tox1, 0, 0) == TOX_CONNECTION_UDP) { printf("Connected.\n"); break; } tox_iterate(tox1, &to_compare); tox_iterate(tox2, NULL); c_sleep(tox_iteration_interval(tox1)); } while (true) { if (to_compare.received_name && to_compare.received_status_message) { printf("Exchanged names and status messages.\n"); break; } tox_iterate(tox1, &to_compare); tox_iterate(tox2, NULL); c_sleep(tox_iteration_interval(tox1)); } size_t save_size = tox_get_savedata_size(tox1); VLA(uint8_t, savedata, save_size); tox_get_savedata(tox1, savedata); struct Tox_Options *options = tox_options_new(NULL); tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE); tox_options_set_savedata_data(options, savedata, save_size); Tox *tox_to_compare = tox_new(options, 0); tox_friend_get_name(tox_to_compare, 0, to_compare.name, 0); tox_friend_get_status_message(tox_to_compare, 0, to_compare.status_message, 0); assert(memcmp(reference_name, to_compare.name, TOX_MAX_NAME_LENGTH) == 0); assert(memcmp(reference_status, to_compare.status_message, TOX_MAX_STATUS_MESSAGE_LENGTH) == 0); tox_options_free(options); tox_kill(tox1); tox_kill(tox2); tox_kill(tox_to_compare); return 0; }