/* Set the callback for status type changes. * function(int friendnumber, USERSTATUS kind) */ void tox_callback_userstatus(Tox *tox, void (*_function)(Tox *tox, int, TOX_USERSTATUS, void *), void *userdata) { Messenger *m = tox; typedef void (*function_type)(Messenger *, int, USERSTATUS, void *); function_type function = (function_type)_function; m_callback_userstatus(m, function, userdata); }
static void init_tox() { // Init core. initMessenger(); // Callbacks. m_callback_friendrequest(on_request); m_callback_friendmessage(on_message); m_callback_namechange(on_nickchange); m_callback_userstatus(on_statuschange); }
int main(int argc, char *argv[]) { if (argc < 4) { printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]); exit(0); } int c; int on = 0; initMessenger(); //if keyfiles exist if(argc > 4){ if(strncmp(argv[4], "nokey", 6) < 0){ //load_key(); } } else { load_key(); } m_callback_friendrequest(print_request); m_callback_friendmessage(print_message); m_callback_namechange(print_nickchange); m_callback_userstatus(print_statuschange); char idstring0[200]; char idstring1[32][5]; char idstring2[32][5]; uint32_t i; for(i = 0; i < 32; i++) { if(self_public_key[i] < 16) { strcpy(idstring1[i],"0"); } else { strcpy(idstring1[i], ""); } sprintf(idstring2[i], "%hhX",self_public_key[i]); } strcpy(idstring0,"[i] your ID: "); for(i=0; i<32; i++) { strcat(idstring0,idstring1[i]); strcat(idstring0,idstring2[i]); } initscr(); noecho(); raw(); getmaxyx(stdscr,y,x); new_lines(idstring0); new_lines("[i] commands: /f ID (to add friend), /m friendnumber message (to send message), /s status (to change status), /n nick (to change nickname), /q (to quit)"); 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 != -1) { bootstrap_ip_port.ip.i = resolved_address; } else { exit(1); } DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); 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(); c_sleep(1); do_refresh(); c = getch(); if (c == ERR || c == 27) continue; getmaxyx(stdscr, y, x); if (c == '\n') { line_eval(lines, line); strcpy(line, ""); } else if (c == 127) { line[strlen(line) - 1] = '\0'; } else if (isalnum(c) || ispunct(c) || c == ' ') { strcpy(line, appender(line, (char) c)); } } endwin(); return 0; }
int main(int argc, char *argv[]) { if (argc < 4) { printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]); exit(0); } if (initMessenger() == -1) { printf("initMessenger failed"); exit(0); } if (argc > 4) { if(strncmp(argv[4], "nokey", 6) < 0) { } } else { load_key(); } int nameloaded = 0; int statusloaded = 0; FILE* name_file = NULL; name_file = fopen("namefile.txt", "r"); if(name_file) { uint8_t name[MAX_NAME_LENGTH]; while (fgets(line, MAX_NAME_LENGTH, name_file) != NULL) { sscanf(line, "%s", (char*)name); } setname(name, strlen((char*)name)+1); nameloaded = 1; printf("%s\n", name); } fclose(name_file); FILE* status_file = NULL; status_file = fopen("statusfile.txt", "r"); if(status_file) { uint8_t status[MAX_USERSTATUS_LENGTH]; while (fgets(line, MAX_USERSTATUS_LENGTH, status_file) != NULL) { sscanf(line, "%s", (char*)status); } m_set_userstatus(status, strlen((char*)status)+1); statusloaded = 1; printf("%s\n", status); } fclose(status_file); m_callback_friendrequest(print_request); m_callback_friendmessage(print_message); m_callback_namechange(print_nickchange); m_callback_userstatus(print_statuschange); char idstring1[PUB_KEY_BYTES][5]; char idstring2[PUB_KEY_BYTES][5]; int i; for(i = 0; i < PUB_KEY_BYTES; i++) { if(self_public_key[i] < (PUB_KEY_BYTES/2)) strcpy(idstring1[i],"0"); else strcpy(idstring1[i], ""); sprintf(idstring2[i], "%hhX",self_public_key[i]); } strcpy(users_id,"[i] your ID: "); int j; for (j = 0; j < PUB_KEY_BYTES; j++) { strcat(users_id,idstring1[j]); strcat(users_id,idstring2[j]); } do_header(); 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); DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); int c; int on = 0; _beginthread(get_input, 0, NULL); if (nameloaded == 1) { printf("\nNickname automatically loaded"); printf("\n---------------------------------"); } if (statusloaded == 1) { printf("\nStatus automatically loaded"); printf("\n---------------------------------"); } while(1) { if (on == 1 && DHT_isconnected() == -1) { printf("\n---------------------------------"); printf("\n[i] Disconnected from the DHT"); printf("\n---------------------------------\n\n"); on = 0; } if (on == 0 && DHT_isconnected()) { printf("\n[i] Connected to DHT"); printf("\n---------------------------------\n\n"); on = 1; } doMessenger(); Sleep(1); } return 0; }
int main(int argc, char *argv[]) { if (argc < 4) { printf("[!] Usage: %s [IP] [port] [public_key] <nokey>\n", argv[0]); exit(0); } if (initMessenger() == -1) { printf("initMessenger failed"); exit(0); } if (argc > 4) { if(strncmp(argv[4], "nokey", 6) < 0) { //nothing } else { load_key(); } } m_callback_friendrequest(print_request); m_callback_friendmessage(print_message); m_callback_namechange(print_nickchange); m_callback_userstatus(print_statuschange); system("cls"); char idstring0[200]; char idstring1[32][5]; char idstring2[32][5]; uint32_t i; for(i = 0; i < 32; i++) { if(self_public_key[i] < 16) strcpy(idstring1[i],"0"); else strcpy(idstring1[i], ""); sprintf(idstring2[i], "%hhX",self_public_key[i]); } strcpy(idstring0,"\n[i] your ID: "); for (i=0; i<32; i++) { strcat(idstring0,idstring1[i]); strcat(idstring0,idstring2[i]); } printf(idstring0); do_header(); IP_Port bootstrap_ip_port; bootstrap_ip_port.port = htons(atoi(argv[2])); int resolved_address = resolve_addr(argv[1]); if (resolved_address != -1) bootstrap_ip_port.ip.i = resolved_address; else exit(1); DHT_bootstrap(bootstrap_ip_port, hex_string_to_bin(argv[3])); int c; int on = 0; _beginthread(get_input, 0, NULL); while(1) { if (on == 0 && DHT_isconnected()) { printf("\n[i] connected to DHT\n\n"); on = 1; } doMessenger(); } return 0; }
/* Set the callback for status type changes. * function(int friendnumber, USERSTATUS kind) */ void tox_callback_userstatus(void *tox, void (*function)(Messenger *tox, int, USERSTATUS, void *), void *userdata) { Messenger *m = tox; m_callback_userstatus(m, function, userdata); }
/* Set the callback for status type changes. * function(int32_t friendnumber, USERSTATUS kind) */ void tox_callback_user_status(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, void *), void *userdata) { Messenger *m = tox; m_callback_userstatus(m, function, userdata); }
int main(int argc, char *argv[]) { puts("=========== FRIENDS_TEST ==========="); /* set up the global memory */ parent_id = mmap(NULL, crypto_box_PUBLICKEYBYTES, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); child_id = mmap(NULL, crypto_box_PUBLICKEYBYTES, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); fputs("friends_test: Starting test...\n", stdout); if((child_pid = fork()) == 0) { /* child */ int i = 0; char *message = "Y-yes Mr. Watson?"; initMessenger(); Messenger_save(child_id); msync(child_id, crypto_box_PUBLICKEYBYTES, MS_SYNC); m_callback_friendrequest(child_got_request); m_callback_userstatus(child_got_statuschange); /* wait on the friend request */ while(!(request_flags & FIRST_FLAG)) do_tox(); /* wait for the status change */ while(!(request_flags & SECOND_FLAG)) do_tox(); for(i = 0; i < 6; i++) { /* send the message six times, just to be sure */ m_sendmessage(0, (uint8_t *)message, strlen(message)); do_tox(); } return 0; } /* parent */ if(atexit(cleanup) != 0) { fputs("friends_test: atexit() failed!\nFailing build...\n", stderr); kill(child_pid, SIGKILL); return -1; } msync(parent_id, crypto_box_PUBLICKEYBYTES, MS_SYNC); m_callback_userstatus(parent_confirm_status); m_callback_friendmessage(parent_confirm_message); /* hacky way to give the child time to set up */ c_sleep(50); initMessenger(); Messenger_save(parent_id); if(parent_friend_request() == -1) return -1; if(parent_wait_for_message() == -1) return -1; wait(NULL); fputs("friends_test: Build passed!\n", stdout); return 0; }
int main(int argc, char *argv[]) { int on = 0; int c = 0; int i = 0; char *filename = "data"; char idstring[200] = {0}; 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); } } } } initMessenger(); load_key(filename); m_callback_friendrequest(print_request); m_callback_friendmessage(print_message); m_callback_namechange(print_nickchange); m_callback_userstatus(print_statuschange); initscr(); noecho(); raw(); getmaxyx(stdscr, y, x); new_lines("/h for list of commands"); get_id(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(); c_sleep(1); do_refresh(); c = getch(); if (c == ERR || c == 27) continue; getmaxyx(stdscr, y, x); if (c == '\n') { line_eval(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)); } } endwin(); return 0; }