forked from kismetwireless/kismet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrytracker.h
135 lines (102 loc) · 4.63 KB
/
entrytracker.h
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
/*
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
*/
#ifndef __ENTRYTRACKER_H__
#define __ENTRYTRACKER_H__
#include "config.h"
#include <stdio.h>
#include <stdint.h>
#include <memory>
#include <string>
#include <map>
#include <pthread.h>
#include "globalregistry.h"
#include "trackedelement.h"
#include "kis_net_microhttpd.h"
// Allocate and track named fields and give each one a custom int
class EntryTracker : public Kis_Net_Httpd_CPPStream_Handler, public LifetimeGlobal {
public:
static shared_ptr<EntryTracker> create_entrytracker(GlobalRegistry *in_globalreg) {
shared_ptr<EntryTracker> mon(new EntryTracker(in_globalreg));
in_globalreg->entrytracker = mon.get();
in_globalreg->RegisterLifetimeGlobal(mon);
in_globalreg->InsertGlobal("ENTRY_TRACKER", mon);
return mon;
}
private:
EntryTracker(GlobalRegistry *in_globalreg);
public:
virtual ~EntryTracker();
// Reserve a field name. Field names are plain strings, which can
// be used to derive namespaces later.
// Return: Registered field number, or negative on error (such as field exists with
// conflicting type)
int RegisterField(string in_name, TrackerType in_type, string in_desc);
// Reserve a field name, and return an instance. If the field ALREADY EXISTS, return
// an instance.
shared_ptr<TrackerElement> RegisterAndGetField(string in_name,
TrackerType in_type, string in_desc);
// Reserve a field name, include a builder instance of the field instead of a
// fixed type. Used for building complex types w/ storage backed by trackable
// elements.
// Returns: Registered field number, or negative on error (such as field exists with a
// static type. No checking can be performed between two fields generated by builder
// instances.)
int RegisterField(string in_name, shared_ptr<TrackerElement> in_builder,
string in_desc);
// Reserve a field name, and return an instance. If the field ALREADY EXISTS, return
// an instance.
shared_ptr<TrackerElement> RegisterAndGetField(string in_name,
shared_ptr<TrackerElement> in_builder, string in_desc);
int GetFieldId(string in_name);
string GetFieldName(int in_id);
// Get a field instance
// Return: NULL if unknown
shared_ptr<TrackerElement> GetTrackedInstance(string in_name);
shared_ptr<TrackerElement> GetTrackedInstance(int in_id);
// Register a serializer for auto-serialization based on type
void RegisterSerializer(string type, shared_ptr<TrackerElementSerializer> in_ser);
void RemoveSerializer(string type);
bool CanSerialize(string type);
bool Serialize(string type, std::ostream &stream, SharedTrackerElement elem,
TrackerElementSerializer::rename_map *name_map = NULL);
// HTTP api
virtual bool Httpd_VerifyPath(const char *path, const char *method);
virtual void Httpd_CreateStreamResponse(Kis_Net_Httpd *httpd,
Kis_Net_Httpd_Connection *connection,
const char *url, const char *method, const char *upload_data,
size_t *upload_data_size, std::stringstream &stream);
protected:
GlobalRegistry *globalreg;
pthread_mutex_t entry_mutex;
int next_field_num;
struct reserved_field {
// ID we assigned
int field_id;
// How we create it
string field_name;
TrackerType track_type;
// Or a builder instance
shared_ptr<TrackerElement> builder;
// Might as well track this for auto-doc
string field_description;
};
map<string, shared_ptr<reserved_field> > field_name_map;
typedef map<string, shared_ptr<reserved_field> >::iterator name_itr;
map<int, shared_ptr<reserved_field> > field_id_map;
typedef map<int, shared_ptr<reserved_field> >::iterator id_itr;
map<string, shared_ptr<TrackerElementSerializer> > serializer_map;
typedef map<string, shared_ptr<TrackerElementSerializer> >::iterator serial_itr;
};
#endif