-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuserAgent.h
78 lines (64 loc) · 1.61 KB
/
userAgent.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
//
// Created by tyy on 2017/1/5.
//
#ifndef MAFIA_UA_H
#define MAFIA_UA_H
#include <string.h>
#include <ctype.h>
#include <sys/time.h>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/regex.hpp>
using namespace std;
using namespace boost::algorithm;
// A section contains the name of the product, its version and
// an optional comment.
struct Section {
string name;
string version;
vector<string> comment;
};
// A struct containing all the information that we might be
// interested from the browser.
struct Browser {
string Engine;
string EngineVersion;
string Name;
string Version;
};
struct OSInfo {
string FUllName;
string Name;
string Version;
};
// The UserAgent struct contains all the info that can be extracted
// from the User-Agent string.
struct UserAgent {
string ua;
string mozilla;
string platform;
string os;
string localization;
Browser browser;
bool bot;
bool mobile;
bool undecided;
};
bool googleBot(UserAgent& p);
void detectOS(UserAgent& p, Section& s, int slen);
void checkBot(UserAgent& p, vector<Section>& sections, int slen);
void detectBrowser(UserAgent& p, vector<Section>& sections, int slen);
void Parse(UserAgent& p, string ua, const int ua_len);
void echo_ua(UserAgent& p);
static inline int my_atoi(const char *buf) {
int i = 0;
while (!isdigit(buf[i])) i++;
return atoi(buf + i);
}
static inline void remove_rchar(char *buf) {
// remove json '\' character, ex: Mozilla\/5.0
int len = strlen(buf);
while (buf[--len] == '\\') {
buf[len] = '\0';
}
}
#endif //MAFIA_UA_H