G_MODULE_EXPORT gboolean on_encrypt_button_clicked(GtkButton *button, gtk_widgets_t *data) { gtk_widget_show(data->progress_dialog); set_progress_button((GtkButton *)data->progress_cancel_button, true); set_progress_button((GtkButton *)data->progress_close_button, false); set_progress_bar((GtkProgressBar *)data->progress_bar_total, 0.0f); set_progress_bar((GtkProgressBar *)data->progress_bar_current, 0.0f); gtk_widget_show(data->progress_bar_current); if (_raw) { if (button == (GtkButton *)data->raw_encrypt_button) _encrypted = false; else if (button == (GtkButton *)data->raw_decrypt_button) _encrypted = true; } gui_process(data); return (void)button, TRUE; }
void *gui_listener_thread() { int sock,errno; int fromlen, cnt; struct sockaddr_un listen_addr; struct sockaddr_un from_name; sock = socket(AF_UNIX, SOCK_DGRAM, 0); char buf[300]; unsigned int req_type; // the GUI request type fprintf(stderr, "Just for fun, in sync_ioctl\n"); // printf("TEst"); if (sock < 0) { printf("socket failure %d\n", errno); close(sock); exit(1); } listen_addr.sun_family = AF_UNIX; strcpy(listen_addr.sun_path, SK_GUI_ADDRESS1); unlink(SK_GUI_ADDRESS1); if (bind(sock, (struct sockaddr *) &listen_addr, sizeof(struct sockaddr_un)) < 0) { printf("bind failure %d\n", errno); close(sock); exit(1); } while(1) { cnt = recvfrom(sock, buf, sizeof(buf), 0, &from_name, &fromlen); if (cnt < 0) { printf("recvfrom failure %d\n", errno); close(sock); exit(1); } buf[cnt] = '\0'; /* assure null byte */ from_name.sun_path[fromlen] = '\0'; printf("Get msg from Daemon %s \n",buf); switch((unsigned int) buf[0]) { // char *filepath_tmp,*file_name; // int f_size_tmp; // char **plugins = NULL; // char delims[] = "/"; // // char *port; // int i =0; int port_num; int file_len=0; int bytes_sent=0; int msg_len; int protocol; char dest_ip[30]; char file_name[50]; char byte_sent_hex[20]; char file_len_hex[20]; for(i=0;i<20;i++) { byte_sent_hex[i] = 0; file_len_hex[i] = 0; } /** msg format: bytes description 0 msg_type(can be GUI_MSG_PROGRESS_NOTIFY or else) 1 msg_length (the total length of this msg) 2-3 port (2 is high, 3 is low) 4-19 dest_ip (char) 20-27 bytes sent 28-35 file length 36-end file name **/ case 1: //GUI_MSG_PROGRESS_NOTIFY, to update progress bar port_num = 256*((unsigned char)buf[2]) + (unsigned char)buf[3]; msg_len = (unsigned int)buf[1]; printf("msg_len = %d bytes_sent= %d file_len = %d,port_num = %d \n",msg_len,bytes_sent,file_len,port_num); // sprintf(file_name,"%s",""); for(i=36;i<msg_len;i++) { //if( (buf[i]>'A'&&buf[i]<'Z') || (buf[i]>'a'&& buf[i]<'z') || (buf[i]>'0' &&buf[i]<'9') || buf[i]=='.') file_name[i-36] = buf[i]; //else //break; // strcat(file_name,(char)buf[i]); } file_name[msg_len-36]=0; // strncpy(file_name,buf+36,msg_len-36); // for(i=0;i<8;i++) { byte_sent_hex[i] = buf[i+20]; file_len_hex[i] = buf[i+28]; } bytes_sent = strtol(byte_sent_hex, NULL, 16); file_len = strtol(file_len_hex, NULL, 16); printf("byte_sent_hex is %s,decimal value is %d\n",byte_sent_hex,bytes_sent); printf("file_len_hex is %s,decimal value is %d\n",file_len_hex,file_len); printf("file name is %s \n",file_name); // // sprintf(dest_ip,"%s",""); // // for(i=4;i<=19;i++) // // { // // dest_ip[i-4] = buf[i];//strcat(dest_ip,buf[i]); // // } // dest_ip[15] =0; // printf("dest_ip %s \n",dest_ip); set_progress_bar(bytes_sent,file_name,file_len,port_num); break; case 2: // tell daemon which mode to use(tcp/udp) break; case 3: // reserved break; case 4: // reservced break; } //printf("Request received from GUI, its string is %s, its type is %d\n",buf, (unsigned int) buf[0]); } close(sock); }
inline static void gui_display(crypto_t *c, gtk_widgets_t *data) { cli_bps_t bps[BPS]; memset(bps, 0x00, BPS * sizeof( cli_bps_t )); int b = 0; while (c->status == STATUS_INIT || c->status == STATUS_RUNNING) { gtk_main_iteration_do(FALSE); #ifndef _WIN32 struct timespec s = { 0, MILLION }; nanosleep(&s, NULL); #else Sleep(1); #endif if (c->status == STATUS_INIT) continue; double pc = (PERCENT * c->total.offset + PERCENT * c->current.offset / c->current.size) / c->total.size; if (c->total.offset == c->total.size) pc = PERCENT * c->total.offset / c->total.size; set_progress_bar((GtkProgressBar *)data->progress_bar_total, pc); if (c->total.size == 1) gtk_widget_hide(data->progress_bar_current); else set_progress_bar((GtkProgressBar *)data->progress_bar_current, PERCENT * c->current.offset / c->current.size); struct timeval tv; gettimeofday(&tv, NULL); bps[b].time = tv.tv_sec * MILLION + tv.tv_usec; bps[b].bytes = c->current.offset; double val = cli_calc_bps(bps); b++; if (b >= BPS) b = 0; char *bps_label = NULL; if (isnan(val) || val == 0.0f) asprintf(&bps_label, "---.- B/s"); else { if (val < THOUSAND) asprintf(&bps_label, "%5.1f B/s", val); else if (val < MILLION) asprintf(&bps_label, "%5.1f KB/s", val / KILOBYTE); else if (val < THOUSAND_MILLION) asprintf(&bps_label, "%5.1f MB/s", val / MEGABYTE); else if (val < BILLION) asprintf(&bps_label, "%5.1f GB/s", val / GIGABYTE); else asprintf(&bps_label, "---.- B/s"); //asprintf(&bps_label, "%5.1f TB/s", val / TERABYTE); } gtk_label_set_text((GtkLabel *)data->progress_label, bps_label); free(bps_label); } return; }
static void *gui_process(void *d) { gtk_widgets_t *data = d; char *source = _filename_utf8(gtk_file_chooser_get_filename((GtkFileChooser *)data->open_dialog)); char *output = _filename_utf8(gtk_file_chooser_get_filename((GtkFileChooser *)data->save_dialog)); if (!source || !output) *_status = STATUS_FAILED_IO; uint8_t *key = NULL; size_t length = 0; switch (_key_source) { case KEY_SOURCE_FILE: { char *k = _filename_utf8(gtk_file_chooser_get_filename((GtkFileChooser *)data->key_dialog)); length = 0; key = (uint8_t *)strdup(k); g_free(k); } break; case KEY_SOURCE_PASSWORD: { const char *k = gtk_entry_get_text((GtkEntry *)data->password_entry); length = strlen(k); key = (uint8_t *)strndup(k, length); } break; } int c = gtk_combo_box_get_active((GtkComboBox *)data->crypto_combo); int h = gtk_combo_box_get_active((GtkComboBox *)data->hash_combo); int m = gtk_combo_box_get_active((GtkComboBox *)data->mode_combo); const char **ciphers = list_of_ciphers(); const char **hashes = list_of_hashes(); const char **modes = list_of_modes(); crypto_t *x; if (_encrypted) x = decrypt_init(source, output, ciphers[c - 1], hashes[h - 1], modes[m - 1], key, length, _raw); else x = encrypt_init(source, output, ciphers[c - 1], hashes[h - 1], modes[m - 1], key, length, _raw, _compress, _follow, _version); _status = &x->status; g_free(source); g_free(output); free(key); if (x->status == STATUS_INIT) execute(x); gui_display(x, data); if (x->status == STATUS_SUCCESS) { set_progress_bar((GtkProgressBar *)data->progress_bar_total, PERCENT); set_progress_bar((GtkProgressBar *)data->progress_bar_current, PERCENT); } set_status_bar((GtkStatusbar *)data->status_bar, status(x)); set_progress_button((GtkButton *)data->progress_cancel_button, false); set_progress_button((GtkButton *)data->progress_close_button, true); deinit(&x); return NULL; }