Esempio n. 1
0
int main(int argc, char *argv[])
{
	char *hostname = "localhost"; //host to use if none supplied
	char *service = "ftp", filename[50] = "";    //defaulto service port
	char user[50] = "", pass[50] = "", path[50] = "";
	int cmd, connectfd;
	/*User has to give hostname as a cmd line argument */

	if(argc==2)
		hostname = argv[1];
	else
	{
		fprintf(stderr, "usage: ./4_HW2_Q1_client.exe [hostname]\n");
		exit(1);
	}

	//strcpy(service, "4000");

	connectfd = connectTCP(hostname, service);

	printf("Authenticating...\n");
	printf("Enter user name: ");
	scanf("%s", user);
	printf("Enter password: "******"%s", pass);

	auth_user (connectfd, user, pass);

	//	printf("Enter file name: ");
	//	scanf("%s", filename);

	while(1)
	{
		printf("Commands supported.\n100:RETR\n200:STOR\n300:MKDIR\n400:END\n600:DELETEFILE\nEnter command: ");
		//bzero(&cmd, sizeof(cmd));
		scanf("%d", &cmd);
		// fgets(,sizeof Buff,stdin);

		switch(cmd)
		{
			case STOREFILE: 
				printf("Enter file name: ");
				scanf("%s", filename);
				storefile(connectfd,filename);
				break;
			case REQUESTFILE:
				printf("Enter file name: ");
				scanf("%s", filename);
				readfile(connectfd,filename); 	
				break;
			case MKDIR:
				printf("Enter Dir name: ");
				scanf("%s", path);
				makedir(connectfd, path);
				break;
			case DELETEFILE:
				printf("Enter file name: ");
                        	scanf("%s", filename);
		//		printf("Enter path name: ");
          //              	scanf("%s", path);

			deletefile(connectfd,filename,path);
			break;
			case LIST:
				//printf("Enter path name: ");
				//scanf("%s", path);
				//listdir(connectfd, path);
				break;
			case END:
				cmd = htons(END);
				if((writen(connectfd,(char *)&cmd,sizeof(cmd))) < 0)
				{
					printf("client: write error: %s\n", strerror(errno)); 
					exit(0);
				} 
				printf("client: shutting down...\n");
				exit(0);
			default:
				//bzero(&cmd, sizeof(cmd));
				printf("Command not implemented!\n");	
		}
		printf("\n\n");
	}
	exit(0);
}
Esempio n. 2
0
void SSE::genPlainIndex(string directoryPath) {
	cout << "[PATH] " << directoryPath << endl;

	/* OPTIONAL: Print progress */
	int fileSum = 0, fileCount = -1;
	for(boost::filesystem::recursive_directory_iterator end, dir(directoryPath); dir != end; ++dir) {
		if(boost::filesystem::is_regular(dir->status())) {
			fileSum++;
		}
	}

	double SKETime = 0;
	double filestoreTime = 0;
	double plainIndexTime = 0;

	clock_t startTime = clock();
	for(boost::filesystem::recursive_directory_iterator end, dir(directoryPath); dir != end; ++dir) {
//		string fileName = boost::filesystem::canonical(dir->path()).string();
		
		string fileName = dir->path().string();


		if((dir->path().filename()).compare(".DS_Store") == 0){
//			cout << "Ignoring file " << dir->path().filename() << endl;
			continue;
		}

		if(boost::filesystem::is_regular(dir->status())) {
			fileCount++;
//		cout << "[FILE] " << fileName << "--->" << fileCount << endl;
			uint64_t docID = getDocNameHash(boost::lexical_cast<string>(fileCount));
			
			CLEAR_BIT(docID, 0);
			
			/* Put file contents, FileStore is responsible for enryption and decryption of data files*/

			clock_t startTime = clock();
			double cryptoduration = 0;
			storefile(fileName, docID, cryptoduration);
			SKETime += cryptoduration;
			filestoreTime += (double)(clock()-startTime)/(double)CLOCKS_PER_SEC;

			ifstream input(fileName.c_str());

//			char charsToRemove[] = "~!@#$%^&*()_+-=[]{};:'\"\\|?/<>,.";

			boost::char_separator<char> sep(" ~!#$%^&*()+=[]{};:'\"\\|?/<>,");
			string getcontent;
			boost::tokenizer<boost::char_separator<char> > tok(getcontent);
			while(getline(input, getcontent)) {
//				cout << getcontent << endl;
//				for(unsigned int i = 0; i < strlen(charsToRemove); i++)
//					getcontent.erase(std::remove(getcontent.begin(), getcontent.end(), charsToRemove[i]), getcontent.end());
//				cout << getcontent << endl;
				tok.assign(getcontent.begin(), getcontent.end());
				for(boost::tokenizer<boost::char_separator<char> >::iterator beg = tok.begin(); beg != tok.end(); ++beg) {
					string keyword(*beg);
					// OPTIONAL: convert keywords to lower case
					std::transform(keyword.begin(), keyword.end(), keyword.begin(), ::tolower);
//					cout << "[KWRD] " << keyword << endl;
					// Possible optimization: memorize docID of fileName
					// add keyword --> fileName to the map
//					map[keyword].insert(docID);
					map[keyword].insert(fileCount);
				}
			}
			input.close();
		}
		else {
//			// it's a directory
			cout << "[DIR] [" << (int)((double)fileCount/(double)fileSum*100) << "%] " << fileName << endl;
		}
	}
	cout << "[DONE] Number of keywords: " << map.size() << std::endl;

	plainIndexTime = (double)(clock()-startTime)/(double)CLOCKS_PER_SEC - filestoreTime;
	cout << "Plain index gen took " << plainIndexTime << " seconds." << endl;
	cout << "SKE took " << SKETime << " seconds." << endl;

	// OPTIONAL: Estimate map size
	uint64_t mapSize = 0;
	uint64_t fileKeywordPairs = 0;
	for(unordered_map<string, unordered_set<docid_t> , stringhash>::iterator itmap = map.begin(); itmap != map.end(); ++itmap) {
		const string & keyword = itmap->first;
//		mapSize += keyword.size();
		unordered_set<docid_t> & set = itmap->second;
		for(unordered_set<docid_t>::iterator itset = set.begin(); itset != set.end(); ++itset) {
			docid_t documentId = *itset;
			mapSize += 4;
			fileKeywordPairs++;
		}
	}
	cout << "[DONE] Estimated map size: " << mapSize << endl;
	cout << "File keyword pairs are: " << fileKeywordPairs << endl;
	// TODO: copy all documents to DocumentStore, rename each file to its docId
}