-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader.cpp
More file actions
214 lines (189 loc) · 4.38 KB
/
Copy pathreader.cpp
File metadata and controls
214 lines (189 loc) · 4.38 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<cstdlib>
#include<string.h>
#include<sstream>
#include<ctime>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<map>
#define MAX_MESSAGE_LEN 65536
using namespace std;
typedef map<string,struct sockaddr_in> channel_type;
struct sockaddr_in server;
struct sockaddr_in recv_client;
ifstream fin[5];
class client_process
{
public:
string message;
int port;
int next_id;
int prev_id;
int state;
int message_time[10];
string msg[10];
int join_time;
int leave_time;
int upper_range;
int lower_range;
int range;
int s;
string input_file;
string config_file;
string received_msg;
int input_reader()
{
int i=0;
fin[1].open(input_file.c_str());
string line;
string t,t1;
string full_time[10];
string sec[10];
string min[10];
int mins[10],secs[10];
string message[10];
while (getline(fin[1], line)) //Read entire line from file
{
istringstream ss(line);
string minute;
char *cstr = new char[line.length() + 1];
strcpy(cstr, line.c_str());
char *token = strtok(cstr, "\t");
full_time[i]=token;
while (token != NULL) //Read splitting message and full time
{
message[i] = token;
token = strtok(NULL, "\t");
}
//----------------
char *temp = new char[full_time[i].length() + 1];
strcpy(temp,full_time[i].c_str());
char *token1 = strtok(temp, ":");
min[i]=token1;
while (token1 != NULL)
{
sec[i] = token1;
token1 = strtok(NULL, ":"); //splitting mins and secs from full time
}
//--------------------
mins[i]=atoi(min[i].c_str());
secs[i]=atoi(sec[i].c_str());
message_time[i]=(mins[i]*60)+secs[i]; //Calculating start time
msg[i]=message[i];
i++;
}
for(i=0;i<4;i++)
{
//cout<<full_time[i]<<" "<<message[i]<<" "<<message_time[i]<<endl;
}
return 0;
}
int config_reader()
{
int i=0,j=0;
fin[2].open(config_file);
string temp_range;
string temp_port;
string temp_join_time;
string temp_leave_time;
string join_hour;
string join_min;
string leave_hour;
string leave_min;
string line;
string temp_upper_range;
string temp_lower_range;
int temp_join_hour;
int temp_join_min;
int temp_leave_hour;
int temp_leave_min;
while (getline(fin[2], line))
{
istringstream ss(line);
char *cstr = new char[line.length() + 1];
strcpy(cstr, line.c_str());
char *token = strtok(cstr, ":");
while (token != NULL) //Read splitting message and full time
{
if(i==0)
{
//cerr<<token<<endl;
temp_range = token;
token = strtok(NULL, ":");
}
if(i==1)
{
//cerr<<token<<endl;
temp_port = token;
token = strtok(NULL, ":");
}
if(i==2)
{
//cerr<<token<<endl;
//temp_join_time = token;
if(join_hour =="")
{
join_hour=token;
}
if(join_hour =="join_time")
{
join_hour=token;
}
else
join_min=token;
token = strtok(NULL, ":");
//cerr<<temp_join_time<<endl;
}
j=0;
if(i==3)
{
if(leave_hour =="")
{
leave_hour=token;
}
if(leave_hour =="leave_time")
{
leave_hour=token;
}
else
leave_min=token;
token = strtok(NULL, ":");
}
}
i++;
}
char *temp = new char[temp_range.length() + 1];
strcpy(temp,temp_range.c_str());
char *token1 = strtok(temp, "-");
temp_upper_range=token1;
while (token1 != NULL)
{
temp_lower_range = token1;
token1 = strtok(NULL, ":"); //splitting mins and secs from full time
}
//------------------------------------
upper_range=atoi(temp_upper_range.c_str());
lower_range=atoi(temp_lower_range.c_str());
range=lower_range-upper_range;
port=atoi(temp_port.c_str());
temp_join_hour=atoi(join_hour.c_str());
temp_join_min=atoi(join_min.c_str());
temp_leave_hour=atoi(leave_hour.c_str());
temp_leave_min=atoi(leave_min.c_str());
join_time=(temp_join_hour*60)+temp_join_min;
leave_time=(temp_leave_hour*60)+temp_leave_min;
//cout<<range<<" "<<port<<" "<<join_time<<" "<<leave_time<<endl;
return 0;
}
void initializer();
void socket_creator();
void sender(string var1,int var2);
string receiver();
//void receiver_old();
void send_probe_request(int p);
void send_probe_ack(int p);
}client;