1 #line 982 "../../src/builtin/snarf.m4"
2 /* -*- buffer-read-only: t -*- vi: set ro:
3    THIS FILE IS GENERATED AUTOMATICALLY.  PLEASE DO NOT EDIT.
4 */
5 #line 982
6 #ifdef HAVE_CONFIG_H
7 #line 982
8 # include <config.h>
9 #line 982
10 #endif
11 #line 982
12 #include <sys/types.h>
13 #line 982
14 
15 #line 982
16 #include "mailfromd.h"
17 #line 982
18 #include "prog.h"
19 #line 982
20 #include "builtin.h"
21 #line 982
22 
23 #line 982
24 
25 #line 1022 "../../src/builtin/snarf.m4"
26 
27 /* End of snarf.m4 */
28 #line 1 "geoip.bi"
29 /* This file is part of Mailfromd.             -*- c -*-
30    Copyright (C) 2009-2021 Sergey Poznyakoff
31 
32    This program is free software; you can redistribute it and/or modify
33    it under the terms of the GNU General Public License as published by
34    the Free Software Foundation; either version 3, or (at your option)
35    any later version.
36 
37    This program is distributed in the hope that it will be useful,
38    but WITHOUT ANY WARRANTY; without even the implied warranty of
39    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
40    GNU General Public License for more details.
41 
42    You should have received a copy of the GNU General Public License
43    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
44 
45 
46 #ifdef WITH_GEOIP
47 #line 18
48 
49 #include <GeoIP.h>
50 
51 void
52 #line 21
bi_geoip_country_code_by_addr(eval_environ_t env)53 bi_geoip_country_code_by_addr(eval_environ_t env)
54 #line 21
55 
56 #line 21
57 
58 #line 21 "geoip.bi"
59 {
60 #line 21
61 
62 #line 21
63 
64 #line 21
65 long __bi_argcnt;
66 #line 21
67 char * MFL_DATASEG ip;
68 #line 21
69         long  tlc;
70 #line 21
71 
72 #line 21
73 get_string_arg(env, 1, &ip);
74 #line 21
75         get_numeric_arg(env, 2, &tlc);
76 #line 21
77 
78 #line 21
79 get_numeric_arg(env, 0, &__bi_argcnt);
80 #line 21
81         adjust_stack(env, __bi_argcnt + 1);
82 #line 21
83 
84 #line 21
85 
86 #line 21
87 	if (builtin_module_trace(BUILTIN_IDX_geoip))
88 #line 21
89 		prog_trace(env, "geoip_country_code_by_addr %s %lu",ip, ((__bi_argcnt > 1) ? tlc : 0));;
90 
91 {
92 	GeoIP *gi = GeoIP_new(GEOIP_STANDARD);
93 	const char *ret;
94 
95 		if (!(gi != NULL))
96 #line 27
97 		(
98 #line 27
99 	env_throw_bi(env, mfe_failure, "geoip_country_code_by_addr", "GeoIP_new")
100 #line 27
101 )
102 #line 29
103 ;
104 	ret = ((__bi_argcnt > 1) ? tlc : 0) ? GeoIP_country_code3_by_addr(gi, ip)
105 		             : GeoIP_country_code_by_addr(gi, ip);
106 	GeoIP_delete(gi);
107 		if (!(ret != NULL && strcmp(ret, "N/A") != 0))
108 #line 33
109 		(
110 #line 33
111 	env_throw_bi(env, mfe_not_found, "geoip_country_code_by_addr", _("country code not found"))
112 #line 33
113 )
114 #line 35
115 ;
116 
117 #line 36
118 do {
119 #line 36
120   pushs(env, ret);
121 #line 36
122   goto endlab;
123 #line 36
124 } while (0);
125 }
126 endlab:
127 #line 38
128         env_function_cleanup_flush(env, NULL);
129 #line 38
130 	return;
131 #line 38
132 }
133 
134 void
135 #line 40
bi_geoip_country_code_by_name(eval_environ_t env)136 bi_geoip_country_code_by_name(eval_environ_t env)
137 #line 40
138 
139 #line 40
140 
141 #line 40 "geoip.bi"
142 {
143 #line 40
144 
145 #line 40
146 
147 #line 40
148 long __bi_argcnt;
149 #line 40
150 char * MFL_DATASEG name;
151 #line 40
152         long  tlc;
153 #line 40
154 
155 #line 40
156 get_string_arg(env, 1, &name);
157 #line 40
158         get_numeric_arg(env, 2, &tlc);
159 #line 40
160 
161 #line 40
162 get_numeric_arg(env, 0, &__bi_argcnt);
163 #line 40
164         adjust_stack(env, __bi_argcnt + 1);
165 #line 40
166 
167 #line 40
168 
169 #line 40
170 	if (builtin_module_trace(BUILTIN_IDX_geoip))
171 #line 40
172 		prog_trace(env, "geoip_country_code_by_name %s %lu",name, ((__bi_argcnt > 1) ? tlc : 0));;
173 
174 {
175 	GeoIP *gi = GeoIP_new(GEOIP_STANDARD);
176 	const char *ret;
177 
178 		if (!(gi != NULL))
179 #line 46
180 		(
181 #line 46
182 	env_throw_bi(env, mfe_failure, "geoip_country_code_by_name", "GeoIP_new")
183 #line 46
184 )
185 #line 48
186 ;
187 	ret = ((__bi_argcnt > 1) ? tlc : 0) ? GeoIP_country_code3_by_name(gi, name)
188 		             : GeoIP_country_code_by_name(gi, name);
189 	GeoIP_delete(gi);
190 		if (!(ret != NULL && strcmp(ret, "N/A") != 0))
191 #line 52
192 		(
193 #line 52
194 	env_throw_bi(env, mfe_not_found, "geoip_country_code_by_name", _("country code not found"))
195 #line 52
196 )
197 #line 54
198 ;
199 
200 #line 55
201 do {
202 #line 55
203   pushs(env, ret);
204 #line 55
205   goto endlab;
206 #line 55
207 } while (0);
208 }
209 endlab:
210 #line 57
211         env_function_cleanup_flush(env, NULL);
212 #line 57
213 	return;
214 #line 57
215 }
216 
217 #line 982 "../../src/builtin/snarf.m4"
218 
219 #line 982
220 
221 #line 982
222 #endif /* WITH_GEOIP */
223 #line 982
224 
225 #line 982
226 void
227 #line 982
geoip_init_builtin(void)228 geoip_init_builtin(void)
229 #line 982
230 {
231 #line 982
232 
233 #line 982
234 #ifdef WITH_GEOIP
235 #line 982
236 	pp_define("WITH_GEOIP");
237 #line 982
238 	#line 21 "geoip.bi"
239 va_builtin_install_ex("geoip_country_code_by_addr", bi_geoip_country_code_by_addr, 0, dtype_string, 2, 1, 0|0, dtype_string, dtype_number);
240 #line 40 "geoip.bi"
241 va_builtin_install_ex("geoip_country_code_by_name", bi_geoip_country_code_by_name, 0, dtype_string, 2, 1, 0|0, dtype_string, dtype_number);
242 
243 #line 982 "../../src/builtin/snarf.m4"
244 
245 #line 982
246 #endif /* WITH_GEOIP */
247 #line 982
248 }
249 #line 982 "../../src/builtin/snarf.m4"
250 
251