Lines Matching refs:dict_tcp

1 /*	$NetBSD: dict_tcp.c,v 1.2 2017/02/14 01:16:49 christos Exp $	*/
5 /* dict_tcp 3
9 /* #include <dict_tcp.h>
100 #include <dict_tcp.h>
119 static int dict_tcp_connect(DICT_TCP *dict_tcp)
127 if ((fd = inet_connect(dict_tcp->dict.name, NON_BLOCKING, DICT_TCP_TMOUT)) < 0) {
128 msg_warn("connect to TCP map %s: %m", dict_tcp->dict.name);
131 dict_tcp->fp = vstream_fdopen(fd, O_RDWR);
132 vstream_control(dict_tcp->fp,
139 if (dict_tcp->raw_buf == 0) {
140 dict_tcp->raw_buf = vstring_alloc(10);
141 dict_tcp->hex_buf = vstring_alloc(10);
148 static void dict_tcp_disconnect(DICT_TCP *dict_tcp)
150 (void) vstream_fclose(dict_tcp->fp);
151 dict_tcp->fp = 0;
158 DICT_TCP *dict_tcp = (DICT_TCP *) dict;
183 if (dict_tcp->fp != 0 || dict_tcp_connect(dict_tcp) == 0) {
190 hex_quote(dict_tcp->hex_buf, key);
191 vstream_fprintf(dict_tcp->fp, "get %s\n", STR(dict_tcp->hex_buf));
193 msg_info("%s: send: get %s", myname, STR(dict_tcp->hex_buf));
194 last_ch = vstring_get_nonl_bound(dict_tcp->hex_buf, dict_tcp->fp,
204 dict_tcp->dict.name);
207 dict_tcp->dict.name, DICT_TCP_MAXLEN);
208 dict_tcp_disconnect(dict_tcp);
223 msg_info("%s: recv: %s", myname, STR(dict_tcp->hex_buf));
229 if (start = STR(dict_tcp->hex_buf),
232 || !hex_unquote(dict_tcp->raw_buf, start + 4)) {
234 dict_tcp->dict.name, printable(STR(dict_tcp->hex_buf), '_'));
235 dict_tcp_disconnect(dict_tcp);
246 dict_tcp->dict.name, printable(STR(dict_tcp->hex_buf), '_'));
247 dict_tcp_disconnect(dict_tcp);
252 myname, printable(STR(dict_tcp->hex_buf), '_'));
253 dict_tcp_disconnect(dict_tcp);
258 myname, printable(STR(dict_tcp->hex_buf), '_'));
263 myname, printable(STR(dict_tcp->raw_buf), '_'));
264 RETURN(DICT_ERR_NONE, STR(dict_tcp->raw_buf));
272 DICT_TCP *dict_tcp = (DICT_TCP *) dict;
274 if (dict_tcp->fp)
275 (void) vstream_fclose(dict_tcp->fp);
276 if (dict_tcp->raw_buf)
277 vstring_free(dict_tcp->raw_buf);
278 if (dict_tcp->hex_buf)
279 vstring_free(dict_tcp->hex_buf);
289 DICT_TCP *dict_tcp;
307 dict_tcp = (DICT_TCP *) dict_alloc(DICT_TYPE_TCP, map, sizeof(*dict_tcp));
308 dict_tcp->fp = 0;
309 dict_tcp->raw_buf = dict_tcp->hex_buf = 0;
310 dict_tcp->dict.lookup = dict_tcp_lookup;
311 dict_tcp->dict.close = dict_tcp_close;
312 dict_tcp->dict.flags = dict_flags | DICT_FLAG_PATTERN;
314 dict_tcp->dict.fold_buf = vstring_alloc(10);
316 return (DICT_DEBUG (&dict_tcp->dict));