void FunctionsTreeWidget::deleteFolder(QTreeWidgetItem *item) { if (item == NULL) return; QList<QTreeWidgetItem*> childrenList; for (int i = 0; i < item->childCount(); i++) childrenList.append(item->child(i)); QListIterator <QTreeWidgetItem*> it(childrenList); while (it.hasNext() == true) { QTreeWidgetItem *child = it.next(); quint32 fid = child->data(COL_NAME, Qt::UserRole).toUInt(); if (fid != Function::invalidId()) { m_doc->deleteFunction(fid); delete child; } else deleteFolder(child); } QString name = item->text(COL_PATH); if (m_foldersMap.contains(name)) m_foldersMap.remove(name); delete item; }
void CloneThread::run() { QStringList files; QStringList absoluteSourceFiles; QStringList absoluteDestinationFiles; quint64 totalSize; // Searching { emit OnProgressChanged(tr("Searching..."), 0, 0); if (!getFiles(files)) { return; } if (!getAbsolutePaths(files, absoluteSourceFiles, absoluteDestinationFiles)) { return; } printLists(files, absoluteSourceFiles, absoluteDestinationFiles); } // Calculating { emit OnProgressChanged(tr("Calculating..."), 0, 0); totalSize = getTotalSize(absoluteSourceFiles); if (mTerminated) { return; } qDebug() << "Total size: " << totalSize; } // Deleting { emit OnProgressChanged(tr("Deleting old folder..."), 0, 0); if (!deleteFolder(mDestinationPath)) { return; } } // Cloning { if (!cloneFiles(absoluteSourceFiles, absoluteDestinationFiles, totalSize)) { return; } } }
int main(int argc,char *argv[]) { if (argc >= 2) { // Get the filename as the last file struct stat sb; int ret = stat(argv[argc-1],&sb); // If target doesn't exist if (ret < 0) { printf("\nERROR: The specified target does not seem to exist. Exiting..."); return -1; } // Process arguments int passes, isFile, isRecursive; passes = 3; isFile = S_ISDIR(sb.st_mode) ? 0 : 1; isRecursive = 0; // Store target char * wipeTarget = argv[argc-1]; int c; while ((c = getopt(argc, argv, "kasrp:")) != -1) { switch(c) { case 'p': passes = toInt(optarg); printf("\nocwiper is set for %d passes.",passes); break; case 'r': case 's': isRecursive = 1; case 'a': forceFiles = 1; case 'k': keepFiles = 1; } } if (!isFile) { deleteFolder(wipeTarget,passes,isRecursive); } else { deleteFile(wipeTarget,passes); } } else { printf("\nocwiper %s by Michael Cowell (2015)\n",VERSION); printf("\n\nUsage:\tocwiper [-p passes] [-k] [-q] [-a] [-r] target"); printf("\n\n\t-p passes\tWipe with X passes. (default is 5)"); printf("\n\t-k\t\tKeep File after shredding"); printf("\n\t-a\t\tRemove read-only attribute. (EXPERIMENTAL)"); printf("\n\t-r\t\tRecurse subdirectories"); } return 0; }
bool PosixFileSystem::deleteFolder( const String& _path ) { DIR *pdir = NULL; pdir = opendir ( _path.c_str() ); if (pdir == NULL) // if pdir wasn't initialised correctly { return false; // return false to say "we couldn't do it" } struct dirent *pent = NULL; int counter = 1; // use this to skip the first TWO which cause an infinite loop (and eventually, stack overflow) while (pent = readdir (pdir)) // while there is still something in the directory to list { if (counter > 2) { if (pent == NULL) // if pent has not been initialised correctly { return false; // we couldn't do it } // otherwise, it was initialised correctly, so let's delete the file~ String filename = _path; filename += "/"; filename += String( pent->d_name ); //if (IsDirectory(filename) == true) //{ // deleteFolder(filename); //} //else // it's a file, we can use remove //{ // remove( filename.c_str() ); //} if( deleteFile( filename ) == false ) // oops maybe that was a directory { if( deleteFolder( filename ) == false ) // some shit happened { return false; } } } counter++; } // finally, let's clean up closedir( pdir ); // close the directory if ( rmdir( _path.c_str() ) == false ) { return false; // delete the directory } return true; }
bool CloneThread::deleteFolder(const QString &folder) { QDir folderDir(folder); if (!folderDir.exists()) { return true; } QFileInfoList files = folderDir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot); for (int i=0; i<files.length(); ++i) { QString filePath = files.at(i).absoluteFilePath(); if (files.at(i).isDir()) { if (!deleteFolder(filePath)) { return false; } } else { qDebug() << "Deleting:" << filePath; if (!QFile::remove(filePath)) { mError = tr("Impossible to remove file: %1").arg(QDir::toNativeSeparators(filePath)); qCritical() << "Error:" << mError; return false; } } } qDebug() << "Deleting folder:" << folder; if (!QDir().rmdir(folder)) { mError = tr("Impossible to remove folder: %1").arg(QDir::toNativeSeparators(folder)); qCritical() << "Error:" << mError; return false; } return !mTerminated; }
bool PlaylistsInFoldersProxy::removeRows( int row, int count, const QModelIndex &parent ) { DEBUG_BLOCK bool result; debug() << "in parent " << parent << "remove " << count << " starting at row " << row; if( !parent.isValid() ) { QModelIndex folderIdx = index( row, 0, QModelIndex() ); if( isGroup( folderIdx ) ) { deleteFolder( folderIdx ); return true; } //is a playlist not in a folder QModelIndex childIdx = mapToSource( index( row, 0, m_rootIndex ) ); result = sourceModel()->removeRows( childIdx.row(), count, m_rootIndex ); if( result ) { beginRemoveRows( parent, row, row + count - 1 ); endRemoveRows(); } return result; } if( isGroup( parent ) ) { result = true; for( int i = row; i < row + count; i++ ) { QModelIndex childIdx = mapToSource( index( i, 0, parent ) ); //set success to false if removeRows returns false result = sourceModel()->removeRow( childIdx.row(), QModelIndex() ) ? result : false; } return result; } //removing a track from a playlist beginRemoveRows( parent, row, row + count - 1 ); QModelIndex originalIdx = mapToSource( parent ); result = sourceModel()->removeRows( row, count, originalIdx ); endRemoveRows(); return result; }
void deleteFolder(const QString& folder) { if (folder.contains(":")) { QDir dir(folder); QStringList folderList = dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name); QStringList fileList = dir.entryList(QDir::Files | QDir::NoDotAndDotDot | QDir::Hidden, QDir::Name); for (int i = 0; i < fileList.size(); ++i) { QFile::remove(folder + "/" + fileList[i]); } for (int i = 0; i < folderList.size(); ++i) { deleteFolder(folder + "/" + folderList[i]); } dir.rmdir(folder); } }
TestRenderServer::TestRenderServer(QWidget *parent) : QWidget(parent), ui(new Ui::TestRenderServer) { ui->setupUi(this); connect(ui->hostLineEdit, SIGNAL(textChanged(QString)), SLOT(activateUploadButton())); connect(ui->nameFolderLineEdit, SIGNAL(textChanged(QString)), SLOT(activateUploadButton())); connect(ui->userNameLineEdit, SIGNAL(textChanged(QString)), SLOT(activateUploadButton())); connect(ui->passwordLineEdit, SIGNAL(textChanged(QString)), SLOT(activateUploadButton())); connect(ui->sceneLineEdit, SIGNAL(textChanged(QString)), SLOT(activateRenderButton())); connect(ui->uploadFolderPushButton, SIGNAL(clicked()), SLOT(uploadFolder())); connect(ui->deletePushButton, SIGNAL(clicked()), SLOT(deleteFolder())); connect(ui->renderPushButton, SIGNAL(clicked()), SLOT(askRender())); link = NULL; serverPath = ""; resultRender = false; }
void deleteFolder(char folder[], int passes, int recursive) { // Handle top folder DIR* dir; struct dirent *ent; if ( (dir = opendir(folder)) != NULL) { while ( (ent = readdir(dir)) != NULL) { // Delete only the top level char * fullPath = malloc(PATH_MAX); sprintf(fullPath,"%s/%s",folder,ent->d_name); if (!recursive) { if (ent->d_type != DT_DIR) { deleteFile(fullPath,passes); } } else { if (!isEqual(ent->d_name,".") && !isEqual(ent->d_name,"..")) { if (ent->d_type == DT_DIR) { deleteFolder(fullPath,passes,recursive); } else { deleteFile(fullPath,passes); } } } free(fullPath); } closedir(dir); if (!keepFiles) { rmdir(folder); if (errno == ENOTEMPTY) { printf("\nWARNING: UNABLE TO DELETE FOLDER AS FILE(S) MIGHT STILL EXIST."); } } } }
/** * \brief Parse parameters * * Read Parameter from scheduler. * Process line elements. * * \param Parm the parameter string * \param userId * \param userPerm permission level the user has * * \return 0: yes, can is deleted; * 1: can not be deleted; * -1: failure; * -2: does not exist * **/ int readAndProcessParameter (char *Parm, int userId, int userPerm) { char *L; int rc=0; /* assume no data */ int Type=0; /* 0=undefined; 1=delete; 2=list */ int Target=0; /* 0=undefined; 1=upload; 2=license; 3=folder */ const char s[2] = " "; char *token; char a[15]; long fd[2]; int i = 0, len = 0; if (!Parm) { return(-1); } if (Verbose > 1) fprintf(stderr,"DEBUG: Line='%s'\n",Parm); /* process the string. */ L = Parm; while(isspace(L[0])) L++; /** Get the type of command: delete or list **/ if (!strncasecmp(L,"DELETE",6) && isspace(L[6])) { Type=1; /* delete */ L+=6; } else if (!strncasecmp(L,"LIST",4) && isspace(L[4])) { Type=2; /* list */ L+=4; } while(isspace(L[0])) L++; /** Get the target **/ if (!strncasecmp(L,"UPLOAD",6) && (isspace(L[6]) || !L[6])) { Target=1; /* upload */ L+=6; } else if (!strncasecmp(L,"LICENSE",7) && (isspace(L[7]) || !L[7])) { Target=2; /* license */ L+=7; } else if (!strncasecmp(L,"FOLDER",6) && (isspace(L[6]) || !L[6])) { Target=3; /* folder */ L+=6; } len = strlen(L); memcpy(a, L,len); token = strtok(a, s); while( token != NULL ) { fd[i] = atol(token); token = strtok(NULL, s); i++; } /* Handle the request */ if ((Type==1) && (Target==1)) { rc = deleteUpload(fd[0], userId, userPerm); } else if ((Type==1) && (Target==3)) { rc = deleteFolder(fd[1],fd[0], userId, userPerm); } else if (((Type==2) && (Target==1)) || ((Type==2) && (Target==2))) { rc = listUploads(0, PERM_ADMIN); } else if ((Type==2) && (Target==3)) { rc = listFolders(userId, userPerm); } else { LOG_ERROR("Unknown command: '%s'\n",Parm); } return rc; } /* readAndProcessParameter() */
KJotsMain::KJotsMain(const char* name) : KTopLevelWidget( name ) { //create widgets f_main = new QFrame( this, "Frame_0" ); f_main->move(0, 28); f_main->setMinimumSize( 500, 180 ); f_main->setFrameStyle( 0 ); f_text = new QFrame( f_main, "Frame_1" ); f_text->setGeometry( 8, 72, 452, 45 ); f_text->setFrameStyle( 50 ); f_labels = new QFrame( f_main, "Frame_2" ); f_labels->setMinimumSize( 436, 24 ); f_labels->setFrameStyle( 0 ); menubar = new KMenuBar( this, "MenuBar_1" ); // KMenubar is not a FRAME!!! (sven) //menubar->setFrameStyle( 34 ); //menubar->setLineWidth( 2 ); s_bar = new QScrollBar( f_main, "ScrollBar_1" ); s_bar->setMinimumSize( 452, 16 ); s_bar->setOrientation( QScrollBar::Horizontal ); me_text = new MyMultiEdit( f_text, "me_text" ); me_text->setMinimumSize( 436, 30 ); me_text->insertLine( "" ); l_folder = new QLabel( f_labels, "Label_4" ); l_folder->setMinimumSize( 68, 20 ); l_folder->setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); l_folder->setText( "" ); le_subject = new QLineEdit( f_labels, "le_subject" ); le_subject->setMinimumSize( 56, 20 ); le_subject->setText( "" ); le_subject->setFocusPolicy(QWidget::ClickFocus); bg_top = new MyButtonGroup( f_main, "ButtonGroup_2" ); bg_top->setMinimumSize( 452, 32 ); bg_top->setFrameStyle( 49 ); bg_top->setTitle( "" ); bg_top->setAlignment( 1 ); bg_top->lower(); this->setMinimumSize(500, 211); KConfig *config = KApplication::getKApplication()->getConfig(); config->setGroup("kjots"); entrylist.setAutoDelete(TRUE); button_list.setAutoDelete(TRUE); folderOpen = FALSE; entrylist.append(new TextEntry); confdiag = NULL; subj_list = new SubjList; connect( this, SIGNAL(folderChanged(QList<TextEntry> *)), subj_list, SLOT(rebuildList( QList<TextEntry> *)) ); connect( this, SIGNAL(entryMoved(int)), subj_list, SLOT( select(int)) ); connect( subj_list, SIGNAL(entryMoved(int)), this, SLOT( barMoved(int)) ); connect( le_subject, SIGNAL(textChanged(const char *)), subj_list, SLOT(entryChanged(const char*)) ); me_text->setEnabled(FALSE); le_subject->setEnabled(FALSE); current = 0; connect( s_bar, SIGNAL(valueChanged(int)), this, SLOT(barMoved(int)) ); top2bottom = new QGridLayout( f_main, 4, 1, 4 ); top2bottom->addWidget( f_text, 0, 0, AlignCenter ); top2bottom->setRowStretch( 0, 1 ); top2bottom->addWidget( s_bar, 1, 0, AlignCenter ); top2bottom->addWidget( bg_top, 2, 0, AlignCenter ); top2bottom->addWidget( f_labels, 3, 0, AlignCenter ); top2bottom->activate(); labels_layout = new QGridLayout( f_labels, 1, 2, 0 ); labels_layout->addWidget( l_folder, 0, 0, AlignVCenter | AlignLeft ); labels_layout->addWidget( le_subject, 0, 1, AlignVCenter | AlignLeft ); labels_layout->setColStretch( 1, 1 ); labels_layout->activate(); QFont font_label(l_folder->fontInfo().family()); font_label.setBold(TRUE); l_folder->setFont(font_label); f_text_layout = new QGridLayout( f_text, 2, 1, 4 ); f_text_layout->addWidget( me_text, 0, 0, AlignCenter ); f_text_layout->setRowStretch( 0, 1 ); f_text_layout->activate(); s_bar->setRange(0,0); s_bar->setValue(0); s_bar->setSteps(1,1); bg_top->setExclusive(TRUE); me_text->setFocusPolicy(QWidget::StrongFocus); // read hotlist config->readListEntry( "Hotlist", hotlist ); while( hotlist.count() > HOT_LIST_SIZE ) hotlist.removeLast(); // read list of folders config->readListEntry( "Folders", folder_list ); QString temp; folders = new QPopupMenu; int i = 0; QPushButton *temp_button; for( temp = folder_list.first(); !temp.isEmpty(); temp = folder_list.next(), i++ ) { folders->insertItem(temp, i); if( hotlist.contains(temp) ) { temp_button = new QPushButton(temp, bg_top); temp_button->setFocusPolicy(QWidget::ClickFocus); temp_button->setToggleButton(TRUE); temp_button->setFixedSize(BUTTON_WIDTH,24); bg_top->insert(temp_button, i); button_list.append(temp_button); } } unique_id = i+1; connect( folders, SIGNAL(activated(int)), this, SLOT(openFolder(int)) ); connect( bg_top, SIGNAL(clicked(int)), this, SLOT(openFolder(int)) ); updateConfiguration(); // creat keyboard shortcuts // CTRL+Key_J := previous page // CTRL+Key_K := next page // CTRL+Key_L := show subject list // CTRL+Key_A := add new page // CTRL+Key_M := move focus keys = new KAccel( this ); keys->insertStdItem( KAccel::New, klocale->translate("New Book") ); keys->connectItem( KAccel::New, this, SLOT(createFolder()) ); keys->connectItem( KAccel::Save , this, SLOT(saveFolder()) ); keys->connectItem( KAccel::Quit, qApp, SLOT(quit()) ); keys->connectItem( KAccel::Cut , me_text, SLOT(cut()) ); keys->connectItem( KAccel::Copy , me_text, SLOT(copyText()) ); keys->connectItem( KAccel::Paste , me_text, SLOT(paste()) ); keys->insertItem(i18n("PreviousPage"), "PreviousPage", CTRL+Key_J); keys->insertItem(i18n("NextPage"), "NextPage", CTRL+Key_K); keys->insertItem(i18n("ShowSubjectList"), "ShowSubjectList", CTRL+Key_L); keys->insertItem(i18n("AddNewPage"), "AddNewPage", CTRL+Key_A); keys->insertItem(i18n("MoveFocus"), "MoveFocus", CTRL+Key_M); keys->insertItem(i18n("CopySelection"), "CopySelection", CTRL+Key_Y); keys->connectItem( "PreviousPage", this, SLOT(prevEntry()) ); keys->connectItem( "NextPage", this, SLOT(nextEntry()) ); keys->connectItem( "ShowSubjectList", this, SLOT(toggleSubjList()) ); keys->connectItem( "AddNewPage", this, SLOT(newEntry()) ); keys->connectItem( "MoveFocus", this, SLOT(moveFocus()) ); keys->connectItem( "CopySelection", this, SLOT(copySelection()) ); keys->readSettings(); // create menu int id; QPopupMenu *file = new QPopupMenu; id = file->insertItem(klocale->translate("&New Book"), this, SLOT(createFolder())); keys->changeMenuAccel(file, id, KAccel::New); file->insertSeparator(); id = file->insertItem(klocale->translate("Save current book"), this, SLOT(saveFolder()) ); keys->changeMenuAccel(file, id, KAccel::Save); id = file->insertItem(klocale->translate("Save book to ascii file"), this, SLOT(writeBook()) ); id = file->insertItem(klocale->translate("Save page to ascii file"), this, SLOT(writePage()) ); file->insertSeparator(); id = file->insertItem(klocale->translate("Delete current book"), this, SLOT(deleteFolder()) ); file->insertSeparator(); id = file->insertItem(klocale->translate("&Quit"), qApp, SLOT( quit() )); keys->changeMenuAccel(file, id, KAccel::Quit); QPopupMenu *edit_menu = new QPopupMenu; id = edit_menu->insertItem(klocale->translate("C&ut"),me_text, SLOT(cut())); keys->changeMenuAccel(edit_menu, id, KAccel::Cut); id = edit_menu->insertItem(klocale->translate("&Copy") , me_text, SLOT(copyText()) ); keys->changeMenuAccel(edit_menu, id, KAccel::Copy); id = edit_menu->insertItem(klocale->translate("&Paste"), me_text, SLOT(paste())); keys->changeMenuAccel(edit_menu, id, KAccel::Paste); edit_menu->insertSeparator(); id = edit_menu->insertItem(klocale->translate("&New Page"), this, SLOT(newEntry()) ); keys->changeMenuAccel(edit_menu, id, "AddNewPage"); id = edit_menu->insertItem(klocale->translate("&Delete Page"), this, SLOT(deleteEntry()) ); QPopupMenu *options = new QPopupMenu; options->insertItem(klocale->translate("&Config"), this, SLOT(configure()) ); options->insertItem(klocale->translate("Configure &Keys"), this, SLOT(configureKeys()) ); QPopupMenu *hotlist = new QPopupMenu; hotlist->insertItem(klocale->translate("Add current book to hotlist"), this, SLOT(addToHotlist()) ); hotlist->insertItem(klocale->translate("Remove current book from hotlist"), this, SLOT(removeFromHotlist()) ); menubar->insertItem( klocale->translate("&File"), file ); menubar->insertItem( klocale->translate("&Edit"), edit_menu ); menubar->insertItem( klocale->translate("Hot&list"), hotlist ); menubar->insertItem( klocale->translate("&Options"), options ); menubar->insertItem( klocale->translate("&Books"), folders ); menubar->insertSeparator(); QString about = "KJots 0.3.1\n\r(C) "; about += (QString) klocale->translate("by") + " Christoph Neerfeld\n\[email protected]"; menubar->insertItem( klocale->translate("&Help"), KApplication::getKApplication()->getHelpMenu(TRUE, about ) ); config->setGroup("kjots"); // create toolbar toolbar = new KToolBar(this); QPixmap temp_pix; temp_pix = global_pix_loader->loadIcon("filenew.xpm"); toolbar->insertButton(temp_pix, 0, SIGNAL(clicked()), this, SLOT(newEntry()), TRUE, i18n("New")); temp_pix = global_pix_loader->loadIcon("filedel.xpm"); toolbar->insertButton(temp_pix, 1, SIGNAL(clicked()), this, SLOT(deleteEntry()), TRUE, i18n("Delete")); temp_pix = global_pix_loader->loadIcon("back.xpm"); toolbar->insertButton(temp_pix, 2, SIGNAL(clicked()), this, SLOT(prevEntry()), TRUE, i18n("Previous")); temp_pix = global_pix_loader->loadIcon("forward.xpm"); toolbar->insertButton(temp_pix, 3, SIGNAL(clicked()), this, SLOT(nextEntry()), TRUE, i18n("Next")); toolbar->insertSeparator(); temp_pix = global_pix_loader->loadIcon("openbook.xpm"); toolbar->insertButton(temp_pix, 4, SIGNAL(clicked()), this, SLOT(toggleSubjList()), TRUE, i18n("Subject List")); toolbar->insertSeparator(); temp_pix = global_pix_loader->loadIcon("exit.xpm"); toolbar->setBarPos( (KToolBar::BarPosition) config->readNumEntry("ToolBarPos") ); addToolBar(toolbar); setView(f_main, FALSE); setMenu(menubar); enableToolBar(KToolBar::Show); QString last_folder = config->readEntry("LastOpenFolder"); int nr; if( (nr = folder_list.find(last_folder)) >= 0 ) openFolder(nr); int width, height; width = config->readNumEntry("Width"); height = config->readNumEntry("Height"); if( width < minimumSize().width() ) width = minimumSize().width(); if( height < minimumSize().height() ) height = minimumSize().height(); resize(width, height); }
main(int argc, char * argv[]) { int sockfd; char buffer[BUFSIZE+1]; char x [BUFSIZE+1]; struct sockaddr_in serv_addr; if(argc <=1) { printf("How to use: %s remoteIPaddress [example./ client 127.0.0.1]\n", argv[0]); exit(1); } bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons (SERV_TCP_PORT); inet_pton (AF_INET, argv[1], &serv_addr.sin_addr); if((sockfd= socket(AF_INET, SOCK_STREAM,0))<0) { perror("Client: socket() error\n"); exit(1); } if(connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr))<0){ perror("Client: connect() error\n"); exit(1); } int count=0; while(count==0) { printf("\n[ 1.Send file. 2.Download 3.delete file 4.create folder 5.delete folder 6.copy folder 7. exit]\n"); fgets(buffer,1024,stdin); send (sockfd, buffer, BUFSIZE,0); int choose; choose = atoi(buffer); if(choose == 1){ /* Send File to Server */ printf("[Client] Select the File you which to send to your directory.\n 1.aaa.txt 2.bbb.txt 3.ccc.txt\n"); fgets(buffer,1024,stdin); send (sockfd, buffer, BUFSIZE,0); int option; option = atoi(buffer); if(option==1) { char* fs_name ="/home/junjeck/client/aaa.txt"; char sdbuf[BUFSIZE]; printf("[Client] Sending aaa.txt to the Server... \n"); FILE *fs = fopen(fs_name, "r"); bzero(sdbuf, BUFSIZE); int fs_block_sz; while((fs_block_sz = fread(sdbuf, sizeof(char), BUFSIZE, fs)) > 0) { if(send(sockfd, sdbuf, fs_block_sz, 0) < 0) { fprintf(stderr, "ERROR: Failed to send file aaa.txt. (errno = )\n"); exit(1); } bzero(sdbuf, BUFSIZE); } printf("[Client] Sending aaa.txt to the Server... \n"); printf("Ok File aaa.txt from Client was Sent!\n File are saved in Server\n"); fclose(fs); count=0; }//end option 1 else if(option==2) { char* fs_name ="/home/junjeck/client/bbb.txt"; char sdbuf[BUFSIZE]; printf("[Client] Sending aaa.txt to the Server... \n"); FILE *fs = fopen(fs_name, "r"); bzero(sdbuf, BUFSIZE); int fs_block_sz; while((fs_block_sz = fread(sdbuf, sizeof(char), BUFSIZE, fs)) > 0) { if(send(sockfd, sdbuf, fs_block_sz, 0) < 0) { fprintf(stderr, "ERROR: Failed to send file aaa.txt. (errno = )\n"); exit(1); } bzero(sdbuf, BUFSIZE); } printf("[Client] Sending bbb.txt to the Server... \n"); printf("Ok File bbb.txt from Client was Sent!\n File are saved in Server\n"); fclose(fs); count=0; }//end option 2 else if(option==3) { char* fs_name ="/home/junjeck/client/ccc.txt"; char sdbuf[BUFSIZE]; printf("[Client] Sending aaa.txt to the Server... \n"); FILE *fs = fopen(fs_name, "r"); bzero(sdbuf, BUFSIZE); int fs_block_sz; while((fs_block_sz = fread(sdbuf, sizeof(char), BUFSIZE, fs)) > 0) { if(send(sockfd, sdbuf, fs_block_sz, 0) < 0) { fprintf(stderr, "ERROR: Failed to send file aaa.txt. (errno = )\n"); exit(1); } bzero(sdbuf, BUFSIZE); } printf("[Client] Sending ccc.txt to the Server... \n"); printf("Ok File ccc.txt from Client was Sent!\n File are saved in Server\n"); fclose(fs); count=0; }//end option 3 //fs_name =strtok(buffer,""); //char* name = malloc(strlen(fs_name)+strlen(filename) + 2); //sprintf(name,"%s%s", fs_name, filename); count=0; }//end choose 1 else if (choose == 2) { /*Receive File from Server */ printf("Please select the File need to Dowload.\n1.chan 2.jun\n"); fgets(buffer,1024,stdin); send(sockfd, buffer, BUFSIZE,0); int option2; option2=atoi(buffer); //printf("Please Write the Filename to Store File:\n"); //gets(buffer); //char* name = malloc(strlen(fr_name)+strlen(buffer) + 2); //sprintf(name,"%s%s", fr_name, buffer); if(option2==1) { char* fr_name = "/home/junjeck/client/chan.txt"; FILE *fr = fopen(fr_name, "a"); if(fr == NULL) { //strcpy(buffer, "0"); //send(new_sockfd, buffer, BUFSIZE, 0); printf("File chan.txt Cannot be opened file on server.\n"); return (0); } bzero(buffer, BUFSIZE); int fr_block_sz = 0; while((fr_block_sz = recv(sockfd, buffer, BUFSIZE, 0)) > 0) { int write_sz = fwrite(buffer, sizeof(char), fr_block_sz, fr); if(write_sz < fr_block_sz) { error("File write failed on server.\n"); } bzero(buffer, BUFSIZE); if (fr_block_sz == 0 || fr_block_sz != 512) { break; } } if(fr_block_sz < 0) { if (errno == EAGAIN) { printf("recv() timed out.\n"); } else { fprintf(stderr, "recv() failed due to errno = %d\n", errno); exit(1); } } printf("Ok Received from Server!! File are stored in Folder clientFile!!\n"); fclose(fr); count=0; }//end option1 else if(option2==2) { char* fr_name = "/home/junjeck/client/jun.txt"; FILE *fr = fopen(fr_name, "a"); if(fr == NULL) { //strcpy(buffer, "0"); //send(new_sockfd, buffer, BUFSIZE, 0); printf("File %s Cannot be opened file on server.\n", fr_name); return (0); } bzero(buffer, BUFSIZE); int fr_block_sz = 0; while((fr_block_sz = recv(sockfd, buffer, BUFSIZE, 0)) > 0) { int write_sz = fwrite(buffer, sizeof(char), fr_block_sz, fr); if(write_sz < fr_block_sz) { error("File write failed on server.\n"); } bzero(buffer, BUFSIZE); if (fr_block_sz == 0 || fr_block_sz != 512) { break; } } if(fr_block_sz < 0) { if (errno == EAGAIN) { printf("recv() timed out.\n"); } else { fprintf(stderr, "recv() failed due to errno = %d\n", errno); exit(1); } } printf("Ok Received from Server!! File are stored in Folder clientFile!!\n"); fclose(fr); count=0; }//end option2 count=0; }//end if choose 2 else if(choose == 3) { deleteFile(sockfd); count = 0; }else if(choose == 4) { createFolder(sockfd); count=0; } else if(choose == 5) { deleteFolder(sockfd); count=0; } else if(choose==6) { copyFolder(sockfd); count=0; } else if(choose == 7){ count=1; } else { printf("Make Sure You are Enter Valid Number"); count=0; //recv(sockfd, buffer, BUFSIZE,0);//receive meassage from server //printf("Message received from server: %s\n", buffer); } }//while (strlen(buffer)!=2 && buffer[0]!='q'); close (sockfd); }
/** * \brief main function for the delagent * * There are 2 ways to use the delagent agent: * 1. Command Line :: delete/list upload/folder/license from the command line * 2. Agent Based :: run from the scheduler * * \htmlonly <pre> * +-----------------------+ * | Command Line Analysis | * +-----------------------+ * </pre> \endhtmlonly * List or delete uploads. * - -h :: help (print this message), then exit. * - -i :: Initialize the DB * - -u :: List uploads IDs. * - -U # :: Delete upload ID. * - -f :: List folder IDs. * - -F # :: Delete folder ID and all uploads under this folder. * - -T :: TEST -- do not update the DB or delete any files (just pretend). * - -v :: Verbose (-vv for more verbose). * - -V :: print the version info, then exit. * - -c SYSCONFDIR :: Specify the directory for the system configuration. * - --user # :: user name * - --password # :: password * * \htmlonly <pre> * +----------------------+ * | Agent Based Analysis | * +----------------------+ * </pre> \endhtmlonly * * To run the delagent as an agent * - -s :: Run from the scheduler * * * \param argc the number of command line arguments * \param argv the command line arguments * \return 0 on a successful program execution */ int main (int argc, char *argv[]) { int c; int listProj=0, listFolder=0; long delUpload=0, delFolder=0, delFolderParent=0; int scheduler=0; /* should it run from the scheduler? */ int gotArg=0; char *agentDesc = "Deletes upload. Other list/delete options available from the command line."; char *commitHash; char *version; char agentRev[myBUFSIZ]; int optionIndex = 0; char *userName = NULL; char *password = NULL; int userId = -1; int userPerm = -1; int returnedCode = 0; fo_scheduler_connect(&argc, argv, &pgConn); static struct option long_options[] = { {"user", required_argument, 0, 'n'}, {"password", required_argument, 0, 'p'}, {0, 0, 0, 0} }; while ((c = getopt_long (argc, argv, "n:p:ifF:lL:sTuU:P:vVc:h", long_options, &optionIndex)) != -1) { switch (c) { case 'n': userName = optarg; break; case 'p': password = optarg; break; case 'i': PQfinish(pgConn); return(0); case 'f': listFolder=1; gotArg=1; break; case 'F': delFolder=atol(optarg); gotArg=1; break; case 'P': delFolderParent=atol(optarg); gotArg=1; break; case 's': scheduler=1; gotArg=1; break; case 'T': Test++; break; case 'u': listProj=1; gotArg=1; break; case 'U': delUpload=atol(optarg); gotArg=1; break; case 'v': Verbose++; break; case 'c': gotArg=1; break; /* handled by fo_scheduler_connect() */ case 'V': printf("%s", BuildVersion); PQfinish(pgConn); return(0); default: usage(argv[0]); exitNow(-1); } } if (!gotArg) { usage(argv[0]); exitNow(-1); } if (scheduler != 1) { if (0 != authentication(userName, password, &userId, &userPerm)) { LOG_FATAL("User name or password is invalid.\n"); exitNow(-1); } commitHash = fo_sysconfig("delagent", "COMMIT_HASH"); version = fo_sysconfig("delagent", "VERSION"); sprintf(agentRev, "%s.%s", version, commitHash); /* Get the Agent Key from the DB */ fo_GetAgentKey(pgConn, basename(argv[0]), 0, agentRev, agentDesc); if (listProj) { returnedCode = listUploads(userId, userPerm); } if (returnedCode < 0) { return returnedCode; } if (listFolder) { returnedCode = listFolders(userId, userPerm); } if (returnedCode < 0) { return returnedCode; } alarm(60); /* from this point on, handle the alarm */ if (delUpload) { returnedCode = deleteUpload(delUpload, userId, userPerm); writeMessageAfterDelete("upload", delUpload, userName, returnedCode); } if (delFolder) { returnedCode = deleteFolder(delFolder, delFolderParent, userId, userPerm); writeMessageAfterDelete("folder", delFolder, userName, returnedCode); } } else { /* process from the scheduler */ doSchedulerTasks(); } exitNow(0); return(returnedCode); } /* main() */