forked from kismetwireless/kismet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevicetracker_httpd.cc
More file actions
829 lines (631 loc) · 27.7 KB
/
Copy pathdevicetracker_httpd.cc
File metadata and controls
829 lines (631 loc) · 27.7 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
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
/*
This file is part of Kismet
Kismet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Kismet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Kismet; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include <memory>
#include <stdio.h>
#include <time.h>
#include <list>
#include <map>
#include <vector>
#include "kismet_algorithm.h"
#include <string>
#include <sstream>
#include <pthread.h>
#include "globalregistry.h"
#include "util.h"
#include "configfile.h"
#include "messagebus.h"
#include "packetchain.h"
#include "devicetracker.h"
#include "packet.h"
#include "gpstracker.h"
#include "alertracker.h"
#include "manuf.h"
#include "entrytracker.h"
#include "devicetracker_component.h"
#include "json_adapter.h"
#include "structured.h"
#include "kismet_json.h"
#include "base64.h"
// HTTP interfaces
bool device_tracker::httpd_verify_path(const char *path, const char *method) {
if (strcmp(method, "GET") == 0) {
// Simple fixed URLS
std::string stripped = httpd_strip_suffix(path);
// Explicit compare for .ekjson because it doesn't serialize the
// same way
if (strcmp(path, "/devices/all_devices.ekjson") == 0)
return true;
// Split URL and process
std::vector<std::string> tokenurl = str_tokenize(path, "/");
if (tokenurl.size() < 2)
return false;
if (tokenurl[1] == "devices") {
if (tokenurl.size() < 3)
return false;
// Do a by-key lookup and return the device or the device path
if (tokenurl[2] == "by-key") {
if (tokenurl.size() < 5) {
return false;
}
device_key key(tokenurl[3]);
if (key.get_error())
return false;
if (!httpd_can_serialize(tokenurl[4]))
return false;
auto tmi = fetch_device(key);
if (tmi == NULL)
return false;
std::string target = httpd_strip_suffix(tokenurl[4]);
if (target == "device") {
// Try to find the exact field
if (tokenurl.size() > 5) {
std::vector<std::string>::const_iterator first = tokenurl.begin() + 5;
std::vector<std::string>::const_iterator last = tokenurl.end();
std::vector<std::string> fpath(first, last);
if (tmi->get_child_path(fpath) == NULL) {
return false;
}
}
return true;
}
return false;
} else if (tokenurl[2] == "by-mac") {
if (tokenurl.size() < 5)
return false;
if (!httpd_can_serialize(tokenurl[4]))
return false;
mac_addr mac = mac_addr(tokenurl[3]);
if (mac.error) {
return false;
}
{
local_shared_locker devlock(&devicelist_mutex);
if (tracked_mac_multimap.count(mac) > 0)
return true;
}
return false;
} else if (tokenurl[2] == "last-time") {
if (tokenurl.size() < 5) {
return false;
}
long lastts;
if (sscanf(tokenurl[3].c_str(), "%ld", &lastts) != 1) {
return false;
}
// Explicit catch of ekjson
if (tokenurl[4] == "devices.ekjson")
return true;
return httpd_can_serialize(tokenurl[4]);
}
}
} else if (strcmp(method, "POST") == 0) {
// Split URL and process
std::vector<std::string> tokenurl = str_tokenize(path, "/");
if (tokenurl.size() < 2)
return false;
if (tokenurl[1] == "devices") {
if (tokenurl.size() < 4) {
return false;
} else if (tokenurl[2] == "last-time") {
if (tokenurl.size() < 5) {
return false;
}
long lastts;
if (sscanf(tokenurl[3].c_str(), "%ld", &lastts) != 1) {
fprintf(stderr, "debug - unable to parse ts\n");
return false;
}
return httpd_can_serialize(tokenurl[4]);
} else if (tokenurl[2] == "by-key") {
if (tokenurl.size() < 5) {
return false;
}
device_key key(tokenurl[3]);
if (key.get_error())
return false;
if (!httpd_can_serialize(tokenurl[4]))
return false;
if (fetch_device(key) == NULL)
return false;
std::string target = httpd_strip_suffix(tokenurl[4]);
if (target == "device") {
return true;
}
if (target == "set_name") {
return true;
}
if (target == "set_tag") {
return true;
}
} else if (tokenurl[2] == "by-mac") {
if (tokenurl.size() < 5)
return false;
if (!httpd_can_serialize(tokenurl[4]))
return false;
mac_addr mac = mac_addr(tokenurl[3]);
if (mac.error) {
return false;
}
{
local_shared_locker listlocker(&devicelist_mutex);
if (tracked_mac_multimap.count(mac) > 0)
return true;
}
return false;
}
}
}
return false;
}
int device_tracker::httpd_create_stream_response(
kis_net_httpd *httpd __attribute__((unused)),
kis_net_httpd_connection *connection,
const char *path, const char *method, const char *upload_data,
size_t *upload_data_size) {
// fmt::print(stderr, "createstreamresponse path {}\n", path);
if (strcmp(method, "GET") != 0) {
return MHD_YES;
}
// Allocate our buffer aux
kis_net_httpd_buffer_stream_aux *saux =
(kis_net_httpd_buffer_stream_aux *) connection->custom_extension;
buffer_handler_ostringstream_buf *streambuf =
new buffer_handler_ostringstream_buf(saux->get_rbhandler());
std::ostream stream(streambuf);
// Set our cleanup function
saux->set_aux(streambuf,
[](kis_net_httpd_buffer_stream_aux *aux) {
if (aux->aux != NULL)
delete((buffer_handler_ostringstream_buf *) (aux->aux));
});
// Set our sync function which is called by the webserver side before we
// clean up...
saux->set_sync([](kis_net_httpd_buffer_stream_aux *aux) {
if (aux->aux != NULL) {
((buffer_handler_ostringstream_buf *) aux->aux)->pubsync();
}
});
if (strcmp(path, "/devices/all_devices.ekjson") == 0) {
// Instantiate a manual serializer
json_adapter::serializer serial;
auto fw = std::make_shared<devicetracker_function_worker>(
[&stream, &serial](device_tracker *, std::shared_ptr<kis_tracked_device_base> d) -> bool {
serial.serialize(d, stream);
stream << "\n";
// Return false because we're not building a list, we're serializing
// per element
return false;
}, nullptr);
do_readonly_device_work(fw);
return MHD_YES;
}
std::string stripped = httpd_strip_suffix(path);
// fmt::print(stderr, "tokenizing path {}\n", path);
std::vector<std::string> tokenurl = str_tokenize(path, "/");
// fmt::print(stderr, "path {} tokenized to size {}\n", path, tokenurl.size());
if (tokenurl.size() < 2) {
return MHD_YES;
}
if (tokenurl[1] == "devices") {
if (tokenurl.size() < 5)
return MHD_YES;
if (tokenurl[2] == "by-key") {
if (tokenurl.size() < 5) {
_MSG_ERROR("HTTP request for {}; invalid by-key URI", path);
stream << "Invalid by-key URI\n";
connection->httpcode = 500;
return MHD_YES;
}
if (!httpd_can_serialize(tokenurl[4])) {
_MSG_ERROR("HTTP request for {}; can't actually serialize.", path);
connection->httpcode = 500;
return MHD_YES;
}
device_key key(tokenurl[3]);
auto dev = fetch_device(key);
if (dev == nullptr) {
_MSG_ERROR("HTTP request for {}; invalid device key {}", path, tokenurl[3]);
stream << "Invalid device key\n";
connection->httpcode = 500;
return MHD_YES;
}
std::string target = httpd_strip_suffix(tokenurl[4]);
if (target == "device") {
// Try to find the exact field
if (tokenurl.size() > 5) {
std::vector<std::string>::const_iterator first = tokenurl.begin() + 5;
std::vector<std::string>::const_iterator last = tokenurl.end();
std::vector<std::string> fpath(first, last);
local_shared_locker devlocker(&(dev->device_mutex));
shared_tracker_element sub = dev->get_child_path(fpath);
if (sub == nullptr) {
_MSG_ERROR("HTTP request for {}; could not map child path to a device record node.", path);
stream << "Invalid sub-key path\n";
connection->httpcode = 500;
return MHD_YES;
}
// Set the mime component of the url
connection->mime_url = tokenurl[4];
Globalreg::globalreg->entrytracker->serialize(httpd->get_suffix(tokenurl[4]), stream, sub, NULL);
return MHD_YES;
}
Globalreg::globalreg->entrytracker->serialize(httpd->get_suffix(tokenurl[4]), stream, dev, NULL);
// fmt::print(stderr, "Wrote data for key {}", key);
return MHD_YES;
} else {
stream << "<h1>Server error</h1>Unhandled by-key target.";
connection->httpcode = 500;
return MHD_YES;
}
} else if (tokenurl[2] == "by-mac") {
if (tokenurl.size() < 5)
return MHD_YES;
if (!httpd_can_serialize(tokenurl[4]))
return MHD_YES;
local_shared_locker lock(&devicelist_mutex);
mac_addr mac = mac_addr(tokenurl[3]);
if (mac.error) {
return MHD_YES;
}
auto devvec = std::make_shared<tracker_element_vector>();
const auto& mmp = tracked_mac_multimap.equal_range(mac);
for (auto mmpi = mmp.first; mmpi != mmp.second; ++mmpi) {
devvec->push_back(mmpi->second);
}
Globalreg::globalreg->entrytracker->serialize(httpd->get_suffix(tokenurl[4]), stream, devvec, NULL);
return MHD_YES;
} else if (tokenurl[2] == "last-time") {
if (tokenurl.size() < 5)
return MHD_YES;
// Is the timestamp an int?
long lastts;
if (sscanf(tokenurl[3].c_str(), "%ld", &lastts) != 1)
return MHD_YES;
// If it's negative, subtract from the current ts
if (lastts < 0) {
time_t now = time(0);
lastts = now + lastts;
}
if (!httpd_can_serialize(tokenurl[4]))
return MHD_YES;
std::shared_ptr<tracker_element_vector> devvec;
auto fw = std::make_shared<devicetracker_function_worker>(
[devvec, lastts](device_tracker *,
std::shared_ptr<kis_tracked_device_base> d) -> bool {
if (d->get_last_time() <= lastts)
return false;
return true;
}, nullptr);
do_readonly_device_work(fw);
devvec = fw->GetMatchedDevices();
Globalreg::globalreg->entrytracker->serialize(httpd->get_suffix(tokenurl[4]), stream, devvec, NULL);
return MHD_YES;
}
}
return MHD_YES;
}
int device_tracker::httpd_post_complete(kis_net_httpd_connection *concls) {
// Split URL and process
std::vector<std::string> tokenurl = str_tokenize(concls->url, "/");
auto saux = (kis_net_httpd_buffer_stream_aux *) concls->custom_extension;
auto streambuf = new buffer_handler_ostringstream_buf(saux->get_rbhandler());
std::ostream stream(streambuf);
saux->set_aux(streambuf,
[](kis_net_httpd_buffer_stream_aux *aux) {
if (aux->aux != NULL)
delete((buffer_handler_ostringstream_buf *) (aux->aux));
});
// Set our sync function which is called by the webserver side before we
// clean up...
saux->set_sync([](kis_net_httpd_buffer_stream_aux *aux) {
if (aux->aux != NULL) {
((buffer_handler_ostringstream_buf *) aux->aux)->pubsync();
}
});
// All URLs are at least /devices/by-foo/y/x
if (tokenurl.size() < 4) {
stream << "Invalid request";
concls->httpcode = 400;
return MHD_YES;
}
// Common structured API data
shared_structured structdata;
// Summarization vector
std::vector<SharedElementSummary> summary_vec;
// Wrapper, if any
std::string wrapper_name;
// Rename cache generated during simplification
auto rename_map = std::make_shared<tracker_element_serializer::rename_map>();
shared_structured regexdata;
time_t post_ts = 0;
try {
if (concls->variable_cache.find("json") !=
concls->variable_cache.end()) {
structdata =
std::make_shared<structured_json>(concls->variable_cache["json"]->str());
} else {
// fprintf(stderr, "debug - missing data\n");
throw structured_data_exception("Missing data; expected command dictionary in json= field");
}
} catch(const structured_data_exception& e) {
stream << "Invalid request: ";
stream << e.what();
concls->httpcode = 400;
return MHD_YES;
}
try {
if (structdata->has_key("fields")) {
shared_structured fields = structdata->get_structured_by_key("fields");
structured_data::structured_vec fvec = fields->as_vector();
for (const auto& i : fvec) {
if (i->is_string()) {
auto s = std::make_shared<tracker_element_summary>(i->as_string());
summary_vec.push_back(s);
} else if (i->is_array()) {
structured_data::string_vec mapvec = i->as_string_vector();
if (mapvec.size() != 2) {
// fprintf(stderr, "debug - malformed rename pair\n");
stream << "Invalid request: Expected field, rename";
concls->httpcode = 400;
return MHD_YES;
}
auto s =
std::make_shared<tracker_element_summary>(mapvec[0], mapvec[1]);
summary_vec.push_back(s);
}
}
}
// Get the wrapper, if one exists, default to empty if it doesn't
wrapper_name = structdata->key_as_string("wrapper", "");
if (structdata->has_key("regex")) {
regexdata = structdata->get_structured_by_key("regex");
}
if (structdata->has_key("last_time")) {
int64_t rawt = structdata->key_as_number("last_time");
if (rawt < 0)
post_ts = time(0) + rawt;
else
post_ts = rawt;
}
} catch(const structured_data_exception& e) {
stream << "Invalid request: Malformed command dictionary, ";
stream << e.what();
concls->httpcode = 400;
return MHD_YES;
}
try {
if (tokenurl[1] == "devices") {
if (tokenurl[2] == "by-mac") {
if (tokenurl.size() < 5) {
stream << "Invalid request: Invalid URI\n";
concls->httpcode = 400;
return MHD_YES;
}
local_demand_locker lock(&devicelist_mutex);
if (!httpd_can_serialize(tokenurl[4])) {
stream << "Invalid request: Cannot find serializer for file type\n";
concls->httpcode = 400;
return MHD_YES;
}
mac_addr mac = mac_addr(tokenurl[3]);
if (mac.error) {
stream << "Invalid request: Invalid MAC address\n";
concls->httpcode = 400;
return MHD_YES;
}
lock.lock();
if (tracked_mac_multimap.count(mac) == 0) {
stream << "Invalid request: Could not find device by MAC\n";
concls->httpcode = 400;
return MHD_YES;
}
lock.unlock();
std::string target = httpd_strip_suffix(tokenurl[4]);
if (target == "devices") {
auto devvec = std::make_shared<tracker_element_vector>();
lock.lock();
auto mmp = tracked_mac_multimap.equal_range(mac);
lock.unlock();
for (auto mmpi = mmp.first; mmpi != mmp.second; ++mmpi)
devvec->push_back(summarize_single_tracker_element(mmpi->second, summary_vec, rename_map));
Globalreg::globalreg->entrytracker->serialize(httpd->get_suffix(tokenurl[4]), stream,
devvec, rename_map);
return MHD_YES;
}
stream << "Invalid request";
concls->httpcode = 400;
return MHD_YES;
} else if (tokenurl[2] == "by-key") {
if (tokenurl.size() < 5) {
stream << "Invalid request: Invalid URI";
concls->httpcode = 400;
return MHD_YES;
}
if (!httpd_can_serialize(tokenurl[4])) {
stream << "Invalid request: Cannot serialize field type";
concls->httpcode = 400;
return MHD_YES;
}
device_key key(tokenurl[3]);
auto dev = fetch_device(key);
if (dev == NULL) {
stream << "Invalid request: No device with that key";
concls->httpcode = 400;
return MHD_YES;
}
std::string target = httpd_strip_suffix(tokenurl[4]);
if (target == "device") {
local_shared_locker devlock(&(dev->device_mutex));
auto simple =
summarize_single_tracker_element(dev, summary_vec, rename_map);
Globalreg::globalreg->entrytracker->serialize(httpd->get_suffix(tokenurl[4]),
stream, simple, rename_map);
return MHD_YES;
}
if (target == "set_name") {
std::string name;
// Must have a session to set the name
if (!httpd->has_valid_session(concls))
throw std::runtime_error("login required");
if (!structdata->has_key("username"))
throw std::runtime_error("expected username in command dictionary");
name = structdata->key_as_string("username");
set_device_user_name(dev, name);
stream << "OK";
return MHD_YES;
}
if (target == "set_tag") {
std::string tag, content;
if (!httpd->has_valid_session(concls))
throw std::runtime_error("login required");
if (!structdata->has_key("tagname"))
throw std::runtime_error("expected tagname in command dictionary");
if (!structdata->has_key("tagvalue"))
throw std::runtime_error("expected tagvalue in command dictionary");
tag = structdata->key_as_string("tagname");
content = structdata->key_as_string("tagvalue");
set_device_tag(dev, tag, content);
stream << "OK";
return MHD_YES;
}
} else if (tokenurl[2] == "last-time") {
// We don't lock the device list since we use workers
if (tokenurl.size() < 5) {
stream << "Invalid request";
concls->httpcode = 400;
return MHD_YES;
}
// Is the timestamp an int?
long lastts;
if (sscanf(tokenurl[3].c_str(), "%ld", &lastts) != 1 ||
!httpd_can_serialize(tokenurl[4])) {
stream << "Invalid request";
concls->httpcode = 400;
return MHD_YES;
}
// If it's negative, subtract from the current ts
if (lastts < 0) {
time_t now = time(0);
lastts = now + lastts;
}
// Rename cache generated during simplification
auto rename_map = std::make_shared<tracker_element_serializer::rename_map>();
// List of devices that pass the timestamp filter
std::shared_ptr<tracker_element_vector> timedevs;
// List of devices that pass the regex filter
auto regexdevs = std::make_shared<tracker_element_vector>();
auto tw = std::make_shared<devicetracker_function_worker>(
[lastts](device_tracker *, std::shared_ptr<kis_tracked_device_base> d) -> bool {
if (d->get_last_time() <= lastts)
return false;
return true;
}, nullptr);
do_readonly_device_work(tw);
timedevs = tw->GetMatchedDevices();
if (regexdata != NULL) {
auto worker = std::make_shared<devicetracker_pcre_worker>(regexdata);
do_readonly_device_work(worker, timedevs);
regexdevs = worker->GetMatchedDevices();
} else {
regexdevs = timedevs;
}
// Final devices being simplified and sent out
auto outdevs = std::make_shared<tracker_element_vector>();
for (const auto& rei : *regexdevs) {
auto rd = std::static_pointer_cast<kis_tracked_device_base>(rei);
local_shared_locker lock(&rd->device_mutex);
outdevs->push_back(summarize_single_tracker_element(rd, summary_vec, rename_map));
}
Globalreg::globalreg->entrytracker->serialize(httpd->get_suffix(tokenurl[4]), stream,
outdevs, rename_map);
return MHD_YES;
}
}
} catch(const std::exception& e) {
stream << "Invalid request: ";
stream << e.what();
concls->httpcode = 400;
return MHD_YES;
}
stream << "OK";
return MHD_YES;
}
unsigned int device_tracker::multimac_endp_handler(std::ostream& stream, const std::string& uri,
shared_structured structured, kis_net_httpd_connection::variable_cache_map& variable_cache) {
try {
auto ret_devices = std::make_shared<tracker_element_vector>();
auto macs = std::vector<mac_addr>{};
if (!structured->has_key("devices"))
throw std::runtime_error("Missing 'devices' key in command dictionary");
auto maclist = structured->get_structured_by_key("devices")->as_vector();
for (auto m : maclist) {
mac_addr ma{m->as_string()};
if (ma.error)
throw std::runtime_error(fmt::format("Invalid MAC address '{}' in 'devices' list",
kishttpd::escape_html(m->as_string())));
macs.push_back(ma);
}
// Duplicate the mac index so that we're 'immune' to things changing it under us; because we
// may have quite a number of devices in our query list, this is safest.
local_demand_locker l(&devicelist_mutex);
l.lock();
auto immutable_copy =
std::multimap<mac_addr, std::shared_ptr<kis_tracked_device_base>>{tracked_mac_multimap};
l.unlock();
// Pull all the devices out of the list
for (auto m : macs) {
const auto& mi = immutable_copy.equal_range(m);
for (auto msi = mi.first; msi != mi.second; ++msi)
ret_devices->push_back(msi->second);
}
// Summarize it all at once
auto rename_map = std::make_shared<tracker_element_serializer::rename_map>();
auto output =
kishttpd::summarize_with_structured(ret_devices, structured, rename_map);
Globalreg::globalreg->entrytracker->serialize(kishttpd::get_suffix(uri), stream, output, rename_map);
return 200;
} catch (const std::exception& e) {
stream << "Invalid request: " << e.what() << "\n";
return 500;
}
stream << "Unhandled request\n";
return 500;
}
std::shared_ptr<tracker_element> device_tracker::all_phys_endp_handler() {
auto ret_vec =
std::make_shared<tracker_element_vector>();
for (auto i : phy_handler_map) {
auto tracked_phy =
std::make_shared<tracker_element_map>(phy_phyentry_id);
auto tracked_name =
std::make_shared<tracker_element_string>(phy_phyname_id, i.second->fetch_phy_name());
auto tracked_id =
std::make_shared<tracker_element_uint32>(phy_phyid_id, i.second->fetch_phy_id());
auto tracked_dev_count =
std::make_shared<tracker_element_uint64>(phy_devices_count_id);
auto tracked_packet_count =
std::make_shared<tracker_element_uint64>(phy_packets_count_id, phy_packets[i.second->fetch_phy_id()]);
auto pv_key = phy_view_map.find(i.second->fetch_phy_id());
if (pv_key != phy_view_map.end())
tracked_dev_count->set(pv_key->second->get_list_sz());
tracked_phy->insert(tracked_name);
tracked_phy->insert(tracked_id);
tracked_phy->insert(tracked_dev_count);
tracked_phy->insert(tracked_packet_count);
ret_vec->push_back(tracked_phy);
}
return ret_vec;
}