-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathip_location.cpp
More file actions
65 lines (56 loc) · 2.02 KB
/
Copy pathip_location.cpp
File metadata and controls
65 lines (56 loc) · 2.02 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
/**
* Description
*
* @file ip_location.cpp
* @date 2014-10-09 23:56:37
* @author FightingMan <gianjason@gmail.com>
* @copyright (c) 2014 FightingMan.
*/
#include "ip_location.hpp"
namespace HPHP {
/* {{{ static Array HHVM_FUNCTION(ip_location, const String& longip) */
static Array HHVM_FUNCTION(ip_location, const String& longip) {
AATree::node *temp = s_ip_location_extension.at->search(std::string(longip.c_str()));
Array return_value = Array::Create();
if (temp) {
return_value.set(StaticString("country"), Variant(temp->key->country));
return_value.set(StaticString("province"), Variant(temp->key->province));
return_value.set(StaticString("area"), Variant(temp->key->area));
return_value.set(StaticString("city"), Variant(temp->key->city));
return_value.set(StaticString("isp"), Variant(temp->key->isp));
}
return return_value;
}
/* }}} */
/* {{{ static int64_t HHVM_FUNCTION(ip_count) */
static int64_t HHVM_FUNCTION(ip_count) {
return s_ip_location_extension.at->countnode();
}
/* }}} */
/* {{{ void ip_locationExtension::moduleInit() */
void ip_locationExtension::moduleInit() {
HHVM_FE(ip_location);
HHVM_FE(ip_count);
loadSystemlib();
}
/* }}} */
/* {{{ void ip_locationExtension::moduleLoad(const IniSetting::Map& ini, Hdf hdf) */
void ip_locationExtension::moduleLoad(const IniSetting::Map& ini, Hdf hdf) {
std::string path = hdf["ext_conf"]["ip_location"]["path"].configGetString("ip.dict");
std::ifstream fin(path);
std::string line;
at = new AATree;
while (std::getline(fin, line)) {
at->lookup(line);
}
fin.close();
}
/* }}} */
/* {{{ void ip_locationExtension::moduleShutdown() */
void ip_locationExtension::moduleShutdown() {
at->makeEmpty();
}
/* }}} */
HHVM_GET_MODULE(ip_location);
}
/* vim: set ts=4 sw=4 sts=4 tw=100 et: */