-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
86 lines (76 loc) · 2.59 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* File: main.cpp
* Author: Michal Lisicki
*
* Created on January 17, 2012, 12:33 PM
*/
#include <cstdlib>
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include "PacketHandler/Packet.h"
#include "Connection.h"
#include "ApplicationManager.h"
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
char* filename = NULL;
bool chat=false;
for(int i=0; i<argc; i++) {
if(strcmp(argv[i],"-c")==0 && i+1<argc)
filename = argv[i+1];
else if(strcmp(argv[i],"--chat")==0)
chat=true;
}
if(argc<=2 || filename==NULL) {
fprintf(stderr, "Wrong number of arguments\n");
fprintf(stderr, "\nUsage: steganoproxy -c configuration_file.xml [--chat]\n");
exit(EXIT_FAILURE);
}
if(chat) {
std::string message = "";
ConnectionConfiguration cconf = ApplicationManager::getInstance().loadConfigurationFromFile(filename);
cconf.outputToFile = false;
Connection* conn = new Connection(cconf);
pthread_t connectionThread = conn->init();
std::cout << "Type a message to start chatting" << std::endl;
while (!(message=="quit")) {
std::cout << "> ";
cin >> message;
conn->getOutputStream() << message;
conn->write();
std::cout << std::endl;
}
std::cout << "Closing connection" << std::endl;
pthread_join( connectionThread, NULL);
} else {
std::string fileToSendName="";
ConnectionConfiguration cconf = ApplicationManager::getInstance().loadConfigurationFromFile(filename);
cconf.outputToFile = true;
Connection* conn = new Connection(cconf);
pthread_t connectionThread = conn->init();
while (!(fileToSendName=="quit")) {
ifstream fileToSend;
std::cout << "File to send (type path): " << std::endl;
cin >> fileToSendName;
fileToSend.open(fileToSendName);
if(fileToSend.is_open()) {
while ( !fileToSend.eof() ) {
char s = fileToSend.get();
if(fileToSend.good())
conn->getOutputStream() << s;
}
conn->write();
fileToSend.close();
} else {
std::cout << "No such file. Try again or type 'quit' to finish." << std::endl;
}
}
std::cout << "Closing connection" << std::endl;
pthread_join( connectionThread, NULL);
}
return 0;
}