forked from voipmonitor/sniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manager.h
98 lines (91 loc) · 2.53 KB
/
manager.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
#ifndef MANAGER_H
#define MANAGER_H
#include <string>
#include <vector>
#include <queue>
#ifndef HAVE_SSH
typedef void* ssh_channel;
#endif
void *manager_client(void *dummy);
void *manager_server(void *dummy);
void *manager_ssh(void *dummy);
class ManagerClientThread {
public:
ManagerClientThread(int client, const char *type, const char *command, int commandLength = 0);
virtual ~ManagerClientThread() {}
void run();
bool isFinished() { return(finished); }
virtual bool parseCommand() = 0;
virtual void onCall(int sipResponseNum, const char *callerName, const char *callerNum, const char *calledNum,
unsigned int sipSaddr, unsigned int sipDaddr) {}
protected:
void lock_responses() {
while(__sync_lock_test_and_set(&this->_sync_responses, 1));
}
void unlock_responses() {
__sync_lock_release(&this->_sync_responses);
}
protected:
int client;
string type;
string command;
bool finished;
std::queue<string> responses;
private:
volatile int _sync_responses;
};
class ManagerClientThread_screen_popup : public ManagerClientThread {
public:
struct RegexReplace {
RegexReplace(const char *pattern, const char *replace) {
this->pattern = pattern;
this->replace = replace;
}
string pattern;
string replace;
};
public:
ManagerClientThread_screen_popup(int client, const char *command, int commandLength = 0);
bool parseCommand();
void onCall(int sipResponseNum, const char *callerName, const char *callerNum, const char *calledNum,
unsigned int sipSaddr, unsigned int sipDaddr);
private:
bool parseUserPassword();
bool isNumericId(const char *id);
private:
string username;
string name;
string dest_number;
bool allow_change_settings;
string profile_name;
bool auto_popup;
bool show_ip;
string popup_on;
bool non_numeric_caller_id;
vector<RegexReplace> regex_replace_calling_number;
vector<string> regex_check_calling_number;
ListIP_wb src_ip;
string app_launch;
string app_launch_args_or_url;
string popup_title;
};
class ManagerClientThreads {
public:
ManagerClientThreads();
void add(ManagerClientThread *clientThread);
void onCall(int sipResponseNum, const char *callerName, const char *callerNum, const char *calledNum,
unsigned int sipSaddr, unsigned int sipDaddr);
void cleanup();
int getCount();
private:
void lock_client_threads() {
while(__sync_lock_test_and_set(&this->_sync_client_threads, 1));
}
void unlock_client_threads() {
__sync_lock_release(&this->_sync_client_threads);
}
private:
std::vector<ManagerClientThread*> clientThreads;
volatile int _sync_client_threads;
};
#endif