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); m = initMessenger(); /* 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); cleanupMessenger(m); return number_failed; }
int main(int argc, char *argv[]) { char *user_config_dir = get_user_config_dir(); int config_err = 0; f_loadfromfile = 1; int f_flag = 0; int i = 0; for (i = 0; i < argc; ++i) { if (argv[i] == NULL) break; else if (argv[i][0] == '-') { if (argv[i][1] == 'f') { if (argv[i + 1] != NULL) DATA_FILE = strdup(argv[i + 1]); else f_flag = -1; } else if (argv[i][1] == 'n') { f_loadfromfile = 0; } } } if (DATA_FILE == NULL ) { config_err = create_user_config_dir(user_config_dir); if (config_err) { DATA_FILE = strdup("data"); SRVLIST_FILE = strdup("../../other/DHTservers"); } else { DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1); strcpy(DATA_FILE, user_config_dir); strcat(DATA_FILE, CONFIGDIR); strcat(DATA_FILE, "data"); SRVLIST_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("DHTservers") + 1); strcpy(SRVLIST_FILE, user_config_dir); strcat(SRVLIST_FILE, CONFIGDIR); strcat(SRVLIST_FILE, "DHTservers"); } } free(user_config_dir); init_term(); Messenger *m = init_tox(); ToxWindow *prompt = init_windows(m); if (f_loadfromfile) load_data(m, DATA_FILE); if (f_flag == -1) { attron(COLOR_PAIR(3) | A_BOLD); wprintw(prompt->window, "You passed '-f' without giving an argument.\n" "defaulting to 'data' for a keyfile...\n"); attroff(COLOR_PAIR(3) | A_BOLD); } if (config_err) { attron(COLOR_PAIR(3) | A_BOLD); wprintw(prompt->window, "Unable to determine configuration directory.\n" "defaulting to 'data' for a keyfile...\n"); attroff(COLOR_PAIR(3) | A_BOLD); } while (true) { /* Update tox */ do_tox(m, prompt); /* Draw */ draw_active_window(m); } cleanupMessenger(m); free(DATA_FILE); free(SRVLIST_FILE); return 0; }
int main(int argc, char *argv[]) { if (argc < 4 && argc != 2) { printf("usage %s ip port public_key (of the DHT bootstrap node)\n or\n %s Save.bak\n", argv[0], argv[0]); exit(0); } m = initMessenger(); if ( !m ) { fputs("Failed to allocate messenger datastructure\n", stderr); exit(0); } if (argc > 3) { IP_Port bootstrap_ip_port; bootstrap_ip_port.port = htons(atoi(argv[2])); bootstrap_ip_port.ip.i = inet_addr(argv[1]); DHT_bootstrap(m->dht, bootstrap_ip_port, hex_string_to_bin(argv[3])); } else { FILE *file = fopen(argv[1], "rb"); if ( file == NULL ) { 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_id[128]; printf("\nEnter the address of the friend you wish to add (38 bytes HEX format):\n"); if (scanf("%s", temp_id) != 1) { return 1; } int num = m_addfriend(m, hex_string_to_bin(temp_id), (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); perror("Initialization"); while (1) { uint8_t name[128]; getname(m, num, name); printf("%s\n", name); m_sendmessage(m, num, (uint8_t *)"Test", 5); doMessenger(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); } cleanupMessenger(m); }
/* Run this before closing shop. * Free all datastructures. */ void tox_kill(void *tox) { Messenger *m = tox; cleanupMessenger(m); }
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 = initMessenger(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_id[128]; printf("\nEnter the address of the friend you wish to add (38 bytes HEX format):\n"); if (scanf("%s", temp_id) != 1) { return 1; } int num = m_addfriend(m, hex_string_to_bin(temp_id), (uint8_t *)"Install Gentoo", sizeof("Install Gentoo")); perror("Initialization"); while (1) { uint8_t name[128]; getname(m, num, name); printf("%s\n", name); m_sendmessage(m, num, (uint8_t *)"Test", 5); doMessenger(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); } cleanupMessenger(m); }
int main(int argc, char *argv[]) { int on = 0; int c = 0; int i = 0; char *filename = "data"; char idstring[200] = {0}; Messenger *m; if (argc < 4) { printf("[!] Usage: %s [IP] [port] [public_key] <keyfile>\n", argv[0]); exit(0); } for (i = 0; i < argc; i++) { if (argv[i] == NULL) { break; } else if (argv[i][0] == '-') { if (argv[i][1] == 'h') { print_help(); exit(0); } else if (argv[i][1] == 'f') { if (argv[i + 1] != NULL) filename = argv[i + 1]; else { fputs("[!] you passed '-f' without giving an argument!\n", stderr); } } } } m = initMessenger(); if ( !m ) { fputs("Failed to allocate Messenger datastructure", stderr); exit(0); } load_key(m, filename); m_callback_friendrequest(m, print_request, NULL); m_callback_friendmessage(m, print_message, NULL); m_callback_namechange(m, print_nickchange, NULL); m_callback_statusmessage(m, print_statuschange, NULL); initscr(); noecho(); raw(); getmaxyx(stdscr, y, x); new_lines("/h for list of commands"); get_id(m, idstring); new_lines(idstring); strcpy(line, ""); IP_Port bootstrap_ip_port; bootstrap_ip_port.port = htons(atoi(argv[2])); int resolved_address = resolve_addr(argv[1]); if (resolved_address != 0) bootstrap_ip_port.ip.i = resolved_address; else exit(1); unsigned char *binary_string = hex_string_to_bin(argv[3]); DHT_bootstrap(bootstrap_ip_port, binary_string); free(binary_string); nodelay(stdscr, TRUE); while (true) { if (on == 0 && DHT_isconnected()) { new_lines("[i] connected to DHT\n[i] define username with /n"); on = 1; } doMessenger(m); c_sleep(1); do_refresh(); c = getch(); if (c == ERR || c == 27) continue; getmaxyx(stdscr, y, x); if (c == '\n') { line_eval(m, line); strcpy(line, ""); } else if (c == 8 || c == 127) { line[strlen(line) - 1] = '\0'; } else if (isalnum(c) || ispunct(c) || c == ' ') { strcpy(line, appender(line, (char) c)); } } cleanupMessenger(m); endwin(); return 0; }