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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
#include "queryhandlerpentominos.h"
#include "debug.h"
#include <config.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <time.h>
#include <errno.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include "queryparser.h"
typedef struct {
in_addr_t ip;
time_t time;
pid_t pid;
unsigned short int count;
} UID;
#define SIOCGIFCONF 0x8912
QueryHandlerPentominos::QueryHandlerPentominos(Artefact &atf,
std::string patientid,
std::string user)
: QueryHandler(), artefact(atf)
{
this->patientid = patientid;
this->user = user;
}
QueryResult QueryHandlerPentominos::exec(Query &query)
{
return artefact.exec(query, patientid, user);
#if 0
time_t timestamp = time(NULL);
std::string uid = getUID("eth0");
char buf[512];
char header[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<artefact xmlns=\"http://www.aasimon.org/pentominos\"\n"
" xmlns:pentominos=\"http://www.aasimon.org/pentominos\"\n"
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
" xsi:schemaLocation=\"http://www.aasimon.org/pentominos schema.xsd\">\n";
#ifndef WITHOUT_PENTOMINOS
artefact.socket.write(header, strlen(header));
#endif
DEBUG(queryhandler, "%s", header);
sprintf(buf, " <pentominos:entry replyformat=\"xml\"\n"
" cpr=\"%s\"\n"
" operator=\"%s\"\n"
" src_addr=\"%s\"\n"
" dst_addr=\"%s\"\n"
" timestamp=\"%d\"\n"
" uid=\"%s\"/>\n",
cpr.c_str(),
"pracro",
#ifndef WITHOUT_PENTOMINOS
artefact.socket.srcaddr().c_str(),
artefact.socket.dstaddr().c_str(),
#else
"127.0.0.1",
"127.0.0.1",
#endif
(unsigned int)timestamp,
uid.c_str());
#ifndef WITHOUT_PENTOMINOS
artefact.socket.write(buf, strlen(buf));
#endif
DEBUG(queryhandler, "%s", buf);
sprintf(buf, " <pentominos:query device_id=\"%s\"\n"
" device_type=\"%s\"\n"
" filter=\"latest\"\n"
" location=\"all\"/>\n",
query.attributes["class"].c_str(),
query.attributes["class"].c_str());
#ifndef WITHOUT_PENTOMINOS
artefact.socket.write(buf, strlen(buf));
#endif
DEBUG(queryhandler, "%s", buf);
sprintf(buf, "</artefact>");
#ifndef WITHOUT_PENTOMINOS
artefact.socket.write(buf, strlen(buf));
#endif
DEBUG(queryhandler, "%s", buf);
QueryResult result;
#ifndef WITHOUT_PENTOMINOS
QueryParser parser;
ssize_t size;
while((size = artefact.socket.read(buf, sizeof(buf))) > 0) {
if(parser.parse(buf, size)) break;
}
result = parser.result;
#endif
INFO(queryhandler, "Done handling query\n");
result.print();
return result;
#endif
return QueryResult();
}
#ifdef TEST_QUERYHANDLERPENTOMINOS
int main()
{
#ifdef WITHOUT_PENTOMINOS
printf("The project need to be configured for use of Pentominos in order to run this test.\n");
return 1;
#endif
TCPSocket s;
try {
s.connect("localhost", 11108);
} catch(Exception &e) {
printf("ERROR: %s\n", e.what());
printf("A running instance of the artefact server in needed on localhost, port 11108 in order for this test to run.\n");
return 1;
}
QueryHandlerPentominos qh(s, "2003791613");
Query q1;
q1.attributes["device_id"] = "lensmeter";
q1.attributes["device_type"] = "lensmeter";
QueryResult res = qh.exec(q1);
res.print();
return 0;
}
#endif
|