/* Run this at startup. * * return allocated instance of tox on success. * return 0 if there are problems. */ Tox *tox_new(Tox_Options *options) { LOGGER_INIT(LOGGER_OUTPUT_FILE, LOGGER_LEVEL); Messenger_Options m_options = {0}; if (options == NULL) { m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; } else { m_options.ipv6enabled = options->ipv6enabled; m_options.udp_disabled = options->udp_disabled; m_options.proxy_enabled = options->proxy_enabled; if (m_options.proxy_enabled) { ip_init(&m_options.proxy_info.ip_port.ip, m_options.ipv6enabled); if (m_options.ipv6enabled) m_options.proxy_info.ip_port.ip.family = AF_UNSPEC; if (!addr_resolve_or_parse_ip(options->proxy_address, &m_options.proxy_info.ip_port.ip, NULL)) return NULL; m_options.proxy_info.ip_port.port = htons(options->proxy_port); } } return new_messenger(&m_options); }
END_TEST START_TEST(test_messenger_state_saveload_encrypted) { uint8_t addr[FRIEND_ADDRESS_SIZE]; getaddress(m, addr); Messenger *m_temp = new_messenger(TOX_ENABLE_IPV6_DEFAULT); size_t size = messenger_size_encrypted(m); uint8_t buffer[size]; messenger_save_encrypted(m, buffer, "Gentoo", sizeof("Gentoo")); ck_assert_msg(messenger_load_encrypted(m_temp, buffer, size, "Ubuntu", sizeof("Ubuntu")) == -1, "Bad password didn't make the function fail."); ck_assert_msg(messenger_load_encrypted(m_temp, buffer, size, "Gentoo", sizeof("Gentoo")) == 0, "Good password didn't make the function succeed."); uint8_t addr1[FRIEND_ADDRESS_SIZE]; getaddress(m_temp, addr1); ck_assert_msg(memcmp(addr1, addr, FRIEND_ADDRESS_SIZE) == 0, "Didn't load messenger successfully"); kill_messenger(m_temp); }
int main(int argc, char *argv[]) { Suite *messenger = messenger_suite(); SRunner *test_runner = srunner_create(messenger); int number_failed = 0; friend_id = hex_string_to_bin(friend_id_str); good_id_a = hex_string_to_bin(good_id_a_str); good_id_b = hex_string_to_bin(good_id_b_str); bad_id = hex_string_to_bin(bad_id_str); /* IPv6 status from global define */ Messenger_Options options = {0}; options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; m = new_messenger(&options); /* setup a default friend and friendnum */ if (m_addfriend_norequest(m, (uint8_t *)friend_id) < 0) fputs("m_addfriend_norequest() failed on a valid ID!\n" "this was CRITICAL to the test, and the build WILL fail.\n" "the tests will continue now...\n\n", stderr); if ((friend_id_num = getfriend_id(m, (uint8_t *)friend_id)) < 0) fputs("getfriend_id() failed on a valid ID!\n" "this was CRITICAL to the test, and the build WILL fail.\n" "the tests will continue now...\n\n", stderr); srunner_run_all(test_runner, CK_NORMAL); number_failed = srunner_ntests_failed(test_runner); srunner_free(test_runner); free(friend_id); free(good_id_a); free(good_id_b); free(bad_id); kill_messenger(m); return number_failed; }
/* Run this at startup. * * return allocated instance of tox on success. * return 0 if there are problems. */ Tox *tox_new(uint8_t ipv6enabled) { return new_messenger(ipv6enabled); }
/* Run this at startup. * * return allocated instance of tox on success. * return 0 if there are problems. */ Tox *tox_new(uint8_t ipv6enabled) { LOGGER_INIT(LOGGER_OUTPUT_FILE, LOGGER_LEVEL); return new_messenger(ipv6enabled); }
int main(int argc, char *argv[]) { /* let user override default by cmdline */ uint8_t ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; /* x */ int argvoffset = cmdline_parsefor_ipv46(argc, argv, &ipv6enabled); if (argvoffset < 0) exit(1); /* with optional --ipvx, now it can be 1-4 arguments... */ if ((argc != argvoffset + 2) && (argc != argvoffset + 4)) { printf("Usage: %s [--ipv4|--ipv6] ip port public_key (of the DHT bootstrap node)\n", argv[0]); printf("or\n"); printf(" %s [--ipv4|--ipv6] Save.bak (to read Save.bak as state file)\n", argv[0]); exit(0); } m = new_messenger(ipv6enabled); if ( !m ) { fputs("Failed to allocate messenger datastructure\n", stderr); exit(0); } if (argc == argvoffset + 4) { uint16_t port = htons(atoi(argv[argvoffset + 2])); uint8_t *bootstrap_key = hex_string_to_bin(argv[argvoffset + 3]); int res = DHT_bootstrap_from_address(m->dht, argv[argvoffset + 1], ipv6enabled, port, bootstrap_key); free(bootstrap_key); if (!res) { printf("Failed to convert \"%s\" into an IP address. Exiting...\n", argv[argvoffset + 1]); exit(1); } } else { FILE *file = fopen(argv[argvoffset + 1], "rb"); if ( file == NULL ) { printf("Failed to open \"%s\" - does it exist?\n", argv[argvoffset + 1]); return 1; } int read; uint8_t buffer[128000]; read = fread(buffer, 1, 128000, file); printf("Messenger loaded: %i\n", messenger_load(m, buffer, read)); fclose(file); } m_callback_friendrequest(m, print_request, NULL); m_callback_friendmessage(m, print_message, NULL); printf("OUR ID: "); uint32_t i; uint8_t address[FRIEND_ADDRESS_SIZE]; getaddress(m, address); for (i = 0; i < FRIEND_ADDRESS_SIZE; i++) { if (address[i] < 16) printf("0"); printf("%hhX", address[i]); } setname(m, (uint8_t *)"Anon", 5); char temp_hex_id[128]; printf("\nEnter the address of the friend you wish to add (38 bytes HEX format):\n"); if (!fgets(temp_hex_id, sizeof(temp_hex_id), stdin)) exit(0); if ((strlen(temp_hex_id) > 0) && (temp_hex_id[strlen(temp_hex_id) - 1] == '\n')) temp_hex_id[strlen(temp_hex_id) - 1] = '\0'; uint8_t *bin_id = hex_string_to_bin(temp_hex_id); int num = m_addfriend(m, bin_id, (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); free(bin_id); perror("Initialization"); while (1) { uint8_t name[128]; getname(m, num, name); printf("%s\n", name); m_sendmessage(m, num, (uint8_t *)"Test", 5); do_messenger(m); c_sleep(30); FILE *file = fopen("Save.bak", "wb"); if ( file == NULL ) { return 1; } uint8_t *buffer = malloc(messenger_size(m)); messenger_save(m, buffer); size_t write_result = fwrite(buffer, 1, messenger_size(m), file); if (write_result < messenger_size(m)) { return 1; } free(buffer); fclose(file); } kill_messenger(m); }
/* Run this at startup. * * return allocated instance of tox on success. * return 0 if there are problems. */ Tox *tox_new(size_t ipv6enabled) { return new_messenger(ipv6enabled); }