/* upload files to server */ int upload_files(SSL *ssl,int order) { int n; int fd; SFT_PACK pack; SFT_DATA data; char filename[FILENAME_SIZE]; char *line = NULL; int file_size; bzero(filename,sizeof(filename)); /* scan local and server files */ scan_all(ssl); /* get file name*/ //sftfile_get_name(filename,"Upload"); line = readline("Upload file name>>"); strncpy(filename,line,FILENAME_SIZE); free(line); /* open the local file */ fd = sftfile_open(filename,O_RDONLY); if(fd < 0) { return -1; } file_size = sftfile_get_size(filename); cut_path(filename); sprintf(data.file_attr.name,"%s/%s",LOGIN_USER.name,filename); data.file_attr.size = file_size; //strcpy(data.file_attr.name,filename); /* package data and send */ sftpack_wrap(&pack,order,ASK,"\0"); pack.data = data; strcpy(pack.buf,LOGIN_USER.name); sftpack_send(ssl,&pack); #if 1 /* get respond */ n = sftpack_recv_ack(ssl,order); if(n == ACCEPT) { sftfile_send(ssl,order,fd,file_size); n = sftpack_recv_ack(ssl,order); if(n == FINISH) { printf("upload %s to sever succeed,total %0.1fKB\n", filename,(float)file_size/1024); list_server(ssl,CSCS,LOGIN_USER.name,"-xF"); divline_ui(); } else { printf("upload %s failure!\n",filename); } } else fprintf(stderr,"request upload failure!\n"); #endif close(fd); return 0; }
Window::Window(QWidget *parent) : QWidget(parent) { //Font kinds in the window QFont font_kind1("Calibri", 14); QFont font_kind2("Calibri", 26); QFont font_kind3("Calibri", 48); //Everything for scaning perticular directory ask_dir = new QLabel("You want to scan only one particular directory?"); funny_joke = new QLabel("We have the solution specially for you!"); ask_dir->setFont(font_kind1); funny_joke->setFont(font_kind1); //Space to enter the name of the directory, which you want to scan line = new QLineEdit; line->setText("Ener full name of the directory"); line->selectAll(); line->setFont(font_kind1); //"Scan it" button scanit = new QPushButton("&Scan it"); scanit->setFont(font_kind2); //Passive-defence switch passive_def = new QCheckBox ("Passive defenсe"); passive_def->setFont(font_kind2); //"Scan all" button scanall = new QPushButton("&Scan all"); scanall->setFont(font_kind3); //LayOut layout1 = new QVBoxLayout; layout1->addWidget(ask_dir); layout1->addWidget(funny_joke); layout2 = new QVBoxLayout; layout2->addWidget(line); layout2->addWidget(scanit); layout3 = new QHBoxLayout; layout3->addLayout(layout2); layout3->addWidget(scanall); layout4 = new QVBoxLayout; layout4->addLayout(layout1); layout4->addLayout(layout3); layout4->addWidget(passive_def); layout4->addStretch(); //Window's head name and other features setWindowTitle("Antivirus v 2.0"); setMinimumSize(650, 200); setLayout(layout4); //Signal-slot connection connect(scanit,SIGNAL(clicked()),this,SLOT(scan_dir()),Qt::DirectConnection); connect(scanall,SIGNAL(clicked()),this,SLOT(scan_all()),Qt::DirectConnection); connect(passive_def,SIGNAL(toggled(bool)),this,SLOT(pass_def()),Qt::DirectConnection); }
/* download server's file */ int download_files(SSL *ssl,int order) { int size; int ack,fd; char filename[FILENAME_SIZE]; char localname[FILENAME_SIZE]; SFT_PACK pack; SFT_DATA data; /* scan local and server files */ scan_all(ssl); sftfile_userdir(DOWNLOAD_DIR); bzero(localname,sizeof(localname)); /* input filename on server to download */ sftfile_get_name(filename,"Download"); if(strstr(filename,"..")!=NULL) { fprintf(stderr,"filename error: deny contain '..'\n"); return -1; } //sprintf(serv_path,"%s/%s",LOGIN_USER.name,filename); sprintf(data.file_attr.name,"%s/%s",LOGIN_USER.name,filename); cut_path(filename); sprintf(localname,"%s%s",DOWNLOAD_DIR,filename); /*send file information to server */ sftpack_wrap(&pack,order,ASK,""); pack.data = data; sftpack_send(ssl,&pack); /* receive server respond */ sftpack_recv(ssl,&pack); ack =pack.ack; if(ack == ACCEPT) { size = pack.data.file_attr.size; fd = sftfile_open(localname,O_CREAT | O_TRUNC | O_RDWR); if(sftfile_recv(ssl,order,fd,size) == 0) { //size = sftfile_get_size(localname); printf("Downlad %s succeed\n",filename); list_client(DOWNLOAD_DIR," --color=auto "); divline_ui(); } else { printf("Download %s failure!\n",filename); return -1; } } return 0; }
int scan_main(SSL *ssl) { int order; system("clear"); order = Mlist(); switch(order) { case CSCL: scan_local_files();break; case CSCS: scan_serv_files(ssl,order);break; case CSCLS: scan_all(ssl);break; default: fprintf(stderr,"No such option!\n"); return -1; } return 0; }
static void traverse_all( void ) { int any_new; SaveQueue *q; unsigned i; int (*scan_all)( SaveQueue *q ); do { any_new = 0; for (i=0; i<NUM_CLASS_MODES; i++) { q = &image_modes[i].queue; scan_all = image_modes[i].queue_scanner; if (scan_all( q )) any_new = 1; } } while (any_new); }