YAZ 5.37.0
unix.c
Go to the documentation of this file.
1/* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
4 */
9#if HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13#include <yaz/yconfig.h>
14
15#ifndef WIN32
16
17#include <stdio.h>
18#include <string.h>
19#include <stdlib.h>
20#include <errno.h>
21#include <time.h>
22#if HAVE_SYS_TYPES_H
23#include <sys/types.h>
24#endif
25#if HAVE_UNISTD_H
26#include <unistd.h>
27#endif
28#if HAVE_SYS_SOCKET_H
29#include <sys/socket.h>
30#endif
31#include <fcntl.h>
32#include <signal.h>
33
34#include <grp.h>
35#if HAVE_PWD_H
36#include <pwd.h>
37#endif
38
39#if HAVE_SYS_STAT_H
40#include <sys/stat.h>
41#endif
42#if HAVE_SYS_UN_H
43#include <sys/un.h>
44#endif
45
46#include <yaz/unix.h>
47#include <yaz/errno.h>
48#include <yaz/log.h>
49#include <yaz/snprintf.h>
50
51#ifndef YAZ_SOCKLEN_T
52#define YAZ_SOCKLEN_T int
53#endif
54
55static void unix_close(COMSTACK h);
56static int unix_put(COMSTACK h, char *buf, int size);
57static int unix_get(COMSTACK h, char **buf, int *bufsize);
58static int unix_connect(COMSTACK h, void *address);
59static int unix_more(COMSTACK h);
60static int unix_rcvconnect(COMSTACK h);
61static int unix_bind(COMSTACK h, void *address, int mode);
62static int unix_listen(COMSTACK h, char *raddr, int *addrlen,
63 int (*check_ip)(void *cd, const char *a, int len, int type),
64 void *cd);
65static int unix_set_blocking(COMSTACK p, int blocking);
66
68static const char *unix_addrstr(COMSTACK h);
69static void *unix_straddr(COMSTACK h, const char *str);
70
71#ifndef SUN_LEN
72#define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \
73 + strlen ((ptr)->sun_path))
74#endif
75
76/* this state is used for both SSL and straight TCP/IP */
77typedef struct unix_state
78{
79 char *altbuf; /* alternate buffer for surplus data */
80 int altsize; /* size as xmalloced */
81 int altlen; /* length of data or 0 if none */
82
83 int written; /* -1 if we aren't writing */
84 int towrite; /* to verify against user input */
85 int (*complete)(const char *buf, int len); /* length/complete. */
86 struct sockaddr_un addr; /* returned by cs_straddr */
87 int uid;
88 int gid;
89 int umask;
90 char buf[128]; /* returned by cs_addrstr */
92
93static int log_level = 0;
94
95static void unix_init (void)
96{
97 static int log_level_set = 0;
98 if (!log_level_set)
99 {
100 log_level = yaz_log_module_level("comstack");
101 log_level_set = 1;
102 }
103}
104
105/*
106 * This function is always called through the cs_create() macro.
107 * s >= 0: socket has already been established for us.
108 */
109COMSTACK unix_type(int s, int flags, int protocol, void *vp)
110{
111 COMSTACK p;
112 unix_state *state;
113 int new_socket;
114
115 unix_init();
116 if (s < 0)
117 {
118 if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
119 return 0;
120 new_socket = 1;
121 }
122 else
123 new_socket = 0;
124 if (!(p = (struct comstack *)xmalloc(sizeof(struct comstack))))
125 return 0;
126 if (!(state = (struct unix_state *)(p->cprivate =
127 xmalloc(sizeof(unix_state)))))
128 return 0;
129
130 p->flags = flags;
131 if (!(p->flags&CS_FLAGS_BLOCKING))
132 {
133 if (fcntl(s, F_SETFL, O_NONBLOCK) < 0)
134 return 0;
135#ifndef MSG_NOSIGNAL
136 signal (SIGPIPE, SIG_IGN);
137#endif
138 }
139
140 p->io_pending = 0;
141 p->iofile = s;
142 p->type = unix_type;
143 p->protocol = (enum oid_proto) protocol;
144
147 p->f_get = unix_get;
148 p->f_put = unix_put;
149 p->f_close = unix_close;
150 p->f_more = unix_more;
151 p->f_bind = unix_bind;
157
158 p->state = new_socket ? CS_ST_UNBND : CS_ST_IDLE; /* state of line */
159 p->event = CS_NONE;
160 p->cerrno = 0;
161 p->user = 0;
162
163 state->altbuf = 0;
164 state->altsize = state->altlen = 0;
165 state->towrite = state->written = -1;
166 state->complete = cs_complete_auto;
167
168 yaz_log(log_level, "Created UNIX comstack h=%p", p);
169
170 return p;
171}
172
173
174static int unix_strtoaddr_ex(const char *str, struct sockaddr_un *add)
175{
176 char *cp;
177
178 unix_init();
179 yaz_log(log_level, "unix_strtoaddr_ex %s", str ? str : "NULL");
180 add->sun_family = AF_UNIX;
181 strncpy(add->sun_path, str, sizeof(add->sun_path)-1);
182 add->sun_path[sizeof(add->sun_path)-1] = 0;
183 cp = strchr (add->sun_path, ':');
184 if (cp)
185 *cp = '\0';
186 return 1;
187}
188
189static void *unix_straddr1(COMSTACK h, const char *str, char *f)
190{
191 unix_state *sp = (unix_state *)h->cprivate;
192 char * s = f;
193 const char * file = NULL;
194
195 sp->uid = sp->gid = sp->umask = -1;
196
197 if (strchr(s, '='))
198 {
199 char *eol;
200 do
201 {
202 if ((eol = strchr(s, ',')))
203 *eol++ = '\0';
204 if (sp->uid == -1 && strncmp(s, "user=", 5) == 0)
205 {
206 char * arg = s + 5;
207 if (strspn(arg, "0123456789") == strlen(arg))
208 {
209 sp->uid = atoi(arg);
210 }
211 else
212 {
213 struct passwd * pw = getpwnam(arg);
214 if (pw == NULL)
215 {
216 yaz_log(log_level, "unix_strtoaddr1 No such user %s",
217 arg);
218 return 0;
219 }
220 sp->uid = pw->pw_uid;
221 }
222 }
223 else if (sp->gid == -1 && strncmp(s, "group=", 6) == 0)
224 {
225 char * arg = s + 6;
226 if (strspn(arg, "0123456789") == strlen(arg))
227 {
228 sp->gid = atoi(arg);
229 }
230 else
231 {
232 struct group * gr = getgrnam(arg);
233 if (gr == NULL)
234 {
235 yaz_log(log_level, "unix_strtoaddr1 No such group %s",
236 arg);
237 return 0;
238 }
239 sp->gid = gr->gr_gid;
240 }
241 }
242 else if (sp->umask == -1 && strncmp(s, "umask=", 6) == 0)
243 {
244 char * end;
245 char * arg = s + 6;
246
247 sp->umask = strtol(arg, &end, 8);
248 if (errno == EINVAL ||
249 *end)
250 {
251 yaz_log(log_level, "unix_strtoaddr1 Invalid umask %s",
252 arg);
253 return 0;
254 }
255 }
256 else if (file == NULL && strncmp(s, "file=", 5) == 0)
257 {
258 char * arg = s + 5;
259 file = arg;
260 }
261 else
262 {
263 yaz_log(log_level, "unix_strtoaddr1 "
264 "invalid or double argument %s", s);
265 return 0;
266 }
267 } while ((s = eol));
268 }
269 else
270 {
271 file = str;
272 }
273 if (!file)
274 {
275 errno = EINVAL;
276 return 0;
277 }
278
279 yaz_log(log_level, "unix_straddr1: %s", str ? str : "NULL");
280
281 if (!unix_strtoaddr_ex (file, &sp->addr))
282 return 0;
283 return &sp->addr;
284}
285
286static void *unix_straddr(COMSTACK h, const char *str)
287{
288 char *f = xstrdup(str);
289 void *vp = unix_straddr1(h, str, f);
290 xfree(f);
291 return vp;
292}
293
294struct sockaddr_un *unix_strtoaddr(const char *str)
295{
296 static struct sockaddr_un add;
297
298 yaz_log(log_level, "unix_strtoaddr %s", str ? str : "NULL");
299
300 if (!unix_strtoaddr_ex (str, &add))
301 return 0;
302 return &add;
303}
304
305static int unix_more(COMSTACK h)
306{
307 unix_state *sp = (unix_state *)h->cprivate;
308
309 return sp->altlen && (*sp->complete)(sp->altbuf, sp->altlen);
310}
311
312/*
313 * connect(2) will block (sometimes) - nothing we can do short of doing
314 * weird things like spawning subprocesses or threading or some weird junk
315 * like that.
316 */
317static int unix_connect(COMSTACK h, void *address)
318{
319 struct sockaddr_un *add = (struct sockaddr_un *)address;
320 int r;
321 int i;
322
323 yaz_log(log_level, "unix_connect h=%p", h);
324 h->io_pending = 0;
325 if (h->state != CS_ST_UNBND)
326 {
327 h->cerrno = CSOUTSTATE;
328 return -1;
329 }
330 for (i = 0; i<3; i++)
331 {
332 r = connect(h->iofile, (struct sockaddr *) add, SUN_LEN(add));
333 if (r < 0 && yaz_errno() == EAGAIN)
334 {
335#if HAVE_NANOSLEEP
336 struct timespec v;
337 v.tv_sec = 0L;
338 v.tv_nsec = i*10000000L + 1000000L; /* 1ms, 11ms, 21ms */
339 nanosleep(&v, 0);
340#else
341 sleep(1);
342#endif
343 continue;
344 }
345 else
346 break;
347 }
348 if (r < 0)
349 {
350 if (yaz_errno() == EINPROGRESS)
351 {
352 h->event = CS_CONNECT;
355 return 1;
356 }
357 h->cerrno = CSYSERR;
358 return -1;
359 }
360 h->event = CS_CONNECT;
362
363 return unix_rcvconnect (h);
364}
365
366/*
367 * nop
368 */
370{
371 yaz_log(log_level, "unix_rcvconnect h=%p", h);
372
373 if (h->state == CS_ST_DATAXFER)
374 return 0;
375 if (h->state != CS_ST_CONNECTING)
376 {
377 h->cerrno = CSOUTSTATE;
378 return -1;
379 }
380 h->event = CS_DATA;
382 return 0;
383}
384
385static int unix_bind(COMSTACK h, void *address, int mode)
386{
387 unix_state *sp = (unix_state *)h->cprivate;
388 struct sockaddr *addr = (struct sockaddr *)address;
389 const char * path = ((struct sockaddr_un *)addr)->sun_path;
390 struct stat stat_buf;
391
392 yaz_log(log_level, "unix_bind h=%p", h);
393
394 if (stat(path, &stat_buf) != -1) {
395 struct sockaddr_un socket_unix;
396 int socket_out = -1;
397
398 if (!S_ISSOCK(stat_buf.st_mode)) {
399 h->cerrno = CSYSERR;
400 yaz_set_errno(EEXIST); /* Not a socket (File exists) */
401 return -1;
402 }
403 if ((socket_out = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
404 h->cerrno = CSYSERR;
405 return -1;
406 }
407 socket_unix.sun_family = AF_UNIX;
408 strncpy(socket_unix.sun_path, path, sizeof(socket_unix.sun_path)-1);
409 socket_unix.sun_path[sizeof(socket_unix.sun_path)-1] = 0;
410 if (connect(socket_out, (struct sockaddr *) &socket_unix, SUN_LEN(&socket_unix)) < 0) {
411 if (yaz_errno() == ECONNREFUSED) {
412 yaz_log(log_level, "unix_bind socket exists but nobody is listening");
413 } else {
414 h->cerrno = CSYSERR;
415 return -1;
416 }
417 } else {
418 close(socket_out);
419 h->cerrno = CSYSERR;
420 yaz_set_errno(EADDRINUSE);
421 return -1;
422 }
423 unlink(path);
424 }
425
426 if (bind(h->iofile, (struct sockaddr *) addr, SUN_LEN((struct sockaddr_un *)addr)))
427 {
428 h->cerrno = CSYSERR;
429 return -1;
430 }
431 if (chown(path, sp->uid, sp->gid))
432 {
433 h->cerrno = CSYSERR;
434 return -1;
435 }
436 if (chmod(path, sp->umask != -1 ? sp->umask : 0666))
437 {
438 h->cerrno = CSYSERR;
439 return -1;
440 }
441 if (mode == CS_SERVER && listen(h->iofile, 100) < 0)
442 {
443 h->cerrno = CSYSERR;
444 return -1;
445 }
446 h->state = CS_ST_IDLE;
447 h->event = CS_LISTEN;
448 return 0;
449}
450
451static int unix_listen(COMSTACK h, char *raddr, int *addrlen,
452 int (*check_ip)(void *cd, const char *a, int len, int t),
453 void *cd)
454{
455 struct sockaddr_un addr;
456 YAZ_SOCKLEN_T len = sizeof(addr);
457
458 yaz_log(log_level, "unix_listen h=%p", h);
459 if (h->state != CS_ST_IDLE)
460 {
461 h->cerrno = CSOUTSTATE;
462 return -1;
463 }
464 h->newfd = accept(h->iofile, (struct sockaddr*)&addr, &len);
465 if (h->newfd < 0)
466 {
467 if (
468 yaz_errno() == EWOULDBLOCK
469#ifdef EAGAIN
470#if EAGAIN != EWOULDBLOCK
471 || yaz_errno() == EAGAIN
472#endif
473#endif
474 )
475 h->cerrno = CSNODATA;
476 else
477 h->cerrno = CSYSERR;
478 return -1;
479 }
480 if (addrlen && (size_t) (*addrlen) >= sizeof(struct sockaddr_un))
481 memcpy(raddr, &addr, *addrlen = sizeof(struct sockaddr_un));
482 else if (addrlen)
483 *addrlen = 0;
484 h->state = CS_ST_INCON;
485 return 0;
486}
487
489{
490 COMSTACK cnew;
491 unix_state *state, *st = (unix_state *)h->cprivate;
492
493 yaz_log(log_level, "unix_accept h=%p", h);
494 if (h->state == CS_ST_INCON)
495 {
496 if (!(cnew = (COMSTACK)xmalloc(sizeof(*cnew))))
497 {
498 h->cerrno = CSYSERR;
499 close(h->newfd);
500 h->newfd = -1;
501 return 0;
502 }
503 memcpy(cnew, h, sizeof(*h));
504 cnew->iofile = h->newfd;
505 cnew->io_pending = 0;
506 if (!(state = (unix_state *)
507 (cnew->cprivate = xmalloc(sizeof(unix_state)))))
508 {
509 h->cerrno = CSYSERR;
510 if (h->newfd != -1)
511 {
512 close(h->newfd);
513 h->newfd = -1;
514 }
515 return 0;
516 }
517 if (!(cnew->flags&CS_FLAGS_BLOCKING) &&
518 (fcntl(cnew->iofile, F_SETFL, O_NONBLOCK) < 0)
519 )
520 {
521 h->cerrno = CSYSERR;
522 if (h->newfd != -1)
523 {
524 close(h->newfd);
525 h->newfd = -1;
526 }
527 xfree (cnew);
528 xfree (state);
529 return 0;
530 }
531 h->newfd = -1;
532 state->altbuf = 0;
533 state->altsize = state->altlen = 0;
534 state->towrite = state->written = -1;
535 state->complete = st->complete;
536 memcpy(&state->addr, &st->addr, sizeof(state->addr));
537 cnew->state = CS_ST_ACCEPT;
538 cnew->event = CS_NONE;
539 h->state = CS_ST_IDLE;
540
541 h = cnew;
542 }
543 if (h->state == CS_ST_ACCEPT)
544 {
545 }
546 else
547 {
548 h->cerrno = CSOUTSTATE;
549 return 0;
550 }
551 h->io_pending = 0;
553 h->event = CS_DATA;
554 return h;
555}
556
557#define CS_UNIX_BUFCHUNK 4096
558
559/*
560 * Return: -1 error, >1 good, len of buffer, ==1 incomplete buffer,
561 * 0=connection closed.
562 */
563static int unix_get(COMSTACK h, char **buf, int *bufsize)
564{
565 unix_state *sp = (unix_state *)h->cprivate;
566 char *tmpc;
567 int tmpi, berlen, rest, req, tomove;
568 int hasread = 0, res;
569
570 yaz_log(log_level, "unix_get h=%p bufsize=%d", h, *bufsize);
571 if (sp->altlen) /* switch buffers */
572 {
573 yaz_log(log_level, " %d bytes in altbuf (%p )", sp->altlen,
574 sp->altbuf);
575 tmpc = *buf;
576 tmpi = *bufsize;
577 *buf = sp->altbuf;
578 *bufsize = sp->altsize;
579 hasread = sp->altlen;
580 sp->altlen = 0;
581 sp->altbuf = tmpc;
582 sp->altsize = tmpi;
583 }
584 h->io_pending = 0;
585 while (!(berlen = (*sp->complete)(*buf, hasread)))
586 {
587 if (!*bufsize)
588 {
589 if (!(*buf = (char *)xmalloc(*bufsize = CS_UNIX_BUFCHUNK)))
590 return -1;
591 }
592 else if (*bufsize - hasread < CS_UNIX_BUFCHUNK)
593 if (!(*buf =(char *)xrealloc(*buf, *bufsize *= 2)))
594 return -1;
595 res = recv(h->iofile, *buf + hasread, CS_UNIX_BUFCHUNK, 0);
596 yaz_log(log_level, " recv res=%d, hasread=%d", res, hasread);
597 if (res < 0)
598 {
599 if (yaz_errno() == EWOULDBLOCK
600#ifdef EAGAIN
601#if EAGAIN != EWOULDBLOCK
602 || yaz_errno() == EAGAIN
603#endif
604#endif
605 || yaz_errno() == EINPROGRESS
606 )
607 {
609 break;
610 }
611 else if (yaz_errno() == 0)
612 continue;
613 else
614 return -1;
615 }
616 else if (!res)
617 return hasread;
618 hasread += res;
619 }
620 yaz_log(log_level, " Out of read loop with hasread=%d, berlen=%d",
621 hasread, berlen);
622 /* move surplus buffer (or everything if we didn't get a BER rec.) */
623 if (hasread > berlen)
624 {
625 tomove = req = hasread - berlen;
626 rest = tomove % CS_UNIX_BUFCHUNK;
627 if (rest)
628 req += CS_UNIX_BUFCHUNK - rest;
629 if (!sp->altbuf)
630 {
631 if (!(sp->altbuf = (char *)xmalloc(sp->altsize = req)))
632 return -1;
633 } else if (sp->altsize < req)
634 if (!(sp->altbuf =(char *)xrealloc(sp->altbuf, sp->altsize = req)))
635 return -1;
636 yaz_log(log_level, " Moving %d bytes to altbuf(%p)", tomove,
637 sp->altbuf);
638 memcpy(sp->altbuf, *buf + berlen, sp->altlen = tomove);
639 }
640 if (berlen < CS_UNIX_BUFCHUNK - 1)
641 *(*buf + berlen) = '\0';
642 return berlen ? berlen : 1;
643}
644
645
646
647/*
648 * Returns 1, 0 or -1
649 * In nonblocking mode, you must call again with same buffer while
650 * return value is 1.
651 */
652static int unix_put(COMSTACK h, char *buf, int size)
653{
654 int res;
655 struct unix_state *state = (struct unix_state *)h->cprivate;
656
657 yaz_log(log_level, "unix_put h=%p size=%d", h, size);
658 h->io_pending = 0;
659 h->event = CS_DATA;
660 if (state->towrite < 0)
661 {
662 state->towrite = size;
663 state->written = 0;
664 }
665 else if (state->towrite != size)
666 {
667 h->cerrno = CSWRONGBUF;
668 return -1;
669 }
670 while (state->towrite > state->written)
671 {
672 if ((res =
673 send(h->iofile, buf + state->written, size -
674 state->written,
675#ifdef MSG_NOSIGNAL
676 MSG_NOSIGNAL
677#else
678 0
679#endif
680 )) < 0)
681 {
682 if (
683 yaz_errno() == EWOULDBLOCK
684#ifdef EAGAIN
685#if EAGAIN != EWOULDBLOCK
686 || yaz_errno() == EAGAIN
687#endif
688#endif
689 )
690 {
691 yaz_log(log_level, " Flow control stop");
693 return 1;
694 }
695 h->cerrno = CSYSERR;
696 return -1;
697 }
698 state->written += res;
699 yaz_log(log_level, " Wrote %d, written=%d, nbytes=%d",
700 res, state->written, size);
701 }
702 state->towrite = state->written = -1;
703 yaz_log(log_level, " Ok");
704 return 0;
705}
706
707static void unix_close(COMSTACK h)
708{
709 unix_state *sp = (struct unix_state *)h->cprivate;
710
711 yaz_log(log_level, "unix_close h=%p", h);
712 if (h->iofile != -1)
713 {
714 close(h->iofile);
715 }
716 if (sp->altbuf)
717 xfree(sp->altbuf);
718 xfree(sp);
719 xfree(h);
720}
721
722static const char *unix_addrstr(COMSTACK h)
723{
724 unix_state *sp = (struct unix_state *)h->cprivate;
725 yaz_snprintf(sp->buf, sizeof(sp->buf), "unix:%s", sp->addr.sun_path);
726 return sp->buf;
727}
728
729static int unix_set_blocking(COMSTACK p, int flags)
730{
731 unsigned long flag;
732
733 if (p->flags == flags)
734 return 1;
735 flag = fcntl(p->iofile, F_GETFL, 0);
736 if (flags & CS_FLAGS_BLOCKING)
737 flag = flag & ~O_NONBLOCK;
738 else
739 flag = flag | O_NONBLOCK;
740 if (fcntl(p->iofile, F_SETFL, flag) < 0)
741 return 0;
742 p->flags = flags;
743 return 1;
744}
745#endif /* WIN32 */
746/*
747 * Local variables:
748 * c-basic-offset: 4
749 * c-file-style: "Stroustrup"
750 * indent-tabs-mode: nil
751 * End:
752 * vim: shiftwidth=4 tabstop=8 expandtab
753 */
754
int cs_complete_auto(const char *buf, int len)
Definition comstack.c:466
#define CS_ST_ACCEPT
Definition comstack.h:59
#define CS_ST_CONNECTING
Definition comstack.h:60
#define CS_LISTEN
Definition comstack.h:68
#define CSWRONGBUF
Definition comstack.h:159
#define CS_DATA
Definition comstack.h:69
#define CSOUTSTATE
Definition comstack.h:157
#define CS_WANT_READ
Definition comstack.h:114
#define CS_NONE
Definition comstack.h:65
#define CSNODATA
Definition comstack.h:158
#define CS_CONNECT
Definition comstack.h:66
#define CS_ST_UNBND
Definition comstack.h:54
struct comstack * COMSTACK
Definition comstack.h:43
#define CS_WANT_WRITE
Definition comstack.h:115
#define CS_SERVER
Definition comstack.h:78
#define CS_FLAGS_BLOCKING
Definition comstack.h:165
#define CS_ST_DATAXFER
Definition comstack.h:58
#define CS_ST_INCON
Definition comstack.h:56
#define CS_ST_IDLE
Definition comstack.h:55
#define CSYSERR
Definition comstack.h:156
#define YAZ_SOCKLEN_T
Definition config.h:230
int yaz_errno(void)
returns errno
Definition errno.c:31
void yaz_set_errno(int v)
sets errno to value
Definition errno.c:36
Header for errno utilities.
static int log_level
Definition eventl.c:39
enum l_file_type type
Definition log.c:47
void yaz_log(int level, const char *fmt,...)
Writes log message.
Definition log.c:487
int yaz_log_module_level(const char *name)
returns level for module
Definition log.c:586
Logging utility.
oid_proto
Definition oid_util.h:45
void yaz_snprintf(char *buf, size_t size, const char *fmt,...)
Definition snprintf.c:31
Header for config file reading utilities.
int(* f_bind)(COMSTACK handle, void *address, int mode)
Definition comstack.h:76
int flags
Definition comstack.h:62
COMSTACK(* f_accept)(COMSTACK handle)
Definition comstack.h:82
void(* f_close)(COMSTACK handle)
Definition comstack.h:83
unsigned io_pending
Definition comstack.h:63
void *(* f_straddr)(COMSTACK handle, const char *str)
Definition comstack.h:85
void * user
Definition comstack.h:87
int(* f_listen)(COMSTACK h, char *raddr, int *addrlen, int(*check_ip)(void *cd, const char *a, int len, int type), void *cd)
Definition comstack.h:79
int(* f_put)(COMSTACK handle, char *buf, int size)
Definition comstack.h:71
CS_TYPE type
Definition comstack.h:48
int(* f_more)(COMSTACK handle)
Definition comstack.h:73
int state
Definition comstack.h:53
int event
Definition comstack.h:64
int newfd
Definition comstack.h:61
int(* f_set_blocking)(COMSTACK handle, int blocking)
Definition comstack.h:86
int iofile
Definition comstack.h:50
int(* f_rcvconnect)(COMSTACK handle)
Definition comstack.h:75
int cerrno
Definition comstack.h:49
int(* f_connect)(COMSTACK handle, void *address)
Definition comstack.h:74
int(* f_get)(COMSTACK handle, char **buf, int *bufsize)
Definition comstack.h:72
enum oid_proto protocol
Definition comstack.h:70
void * cprivate
Definition comstack.h:51
const char *(* f_addrstr)(COMSTACK handle)
Definition comstack.h:84
int uid
Definition unix.c:87
int towrite
Definition unix.c:84
int written
Definition unix.c:83
char * altbuf
Definition unix.c:79
int umask
Definition unix.c:89
int altlen
Definition unix.c:81
int altsize
Definition unix.c:80
int gid
Definition unix.c:88
char buf[128]
Definition unix.c:90
int(* complete)(const char *buf, int len)
Definition unix.c:85
struct sockaddr_un addr
Definition unix.c:86
static int unix_strtoaddr_ex(const char *str, struct sockaddr_un *add)
Definition unix.c:174
static int unix_rcvconnect(COMSTACK h)
Definition unix.c:369
static int unix_bind(COMSTACK h, void *address, int mode)
Definition unix.c:385
static int unix_put(COMSTACK h, char *buf, int size)
Definition unix.c:652
static void unix_close(COMSTACK h)
Definition unix.c:707
static int unix_get(COMSTACK h, char **buf, int *bufsize)
Definition unix.c:563
static COMSTACK unix_accept(COMSTACK h)
Definition unix.c:488
static void * unix_straddr(COMSTACK h, const char *str)
Definition unix.c:286
static int unix_listen(COMSTACK h, char *raddr, int *addrlen, int(*check_ip)(void *cd, const char *a, int len, int type), void *cd)
Definition unix.c:451
static int unix_connect(COMSTACK h, void *address)
Definition unix.c:317
static void * unix_straddr1(COMSTACK h, const char *str, char *f)
Definition unix.c:189
static int unix_more(COMSTACK h)
Definition unix.c:305
#define CS_UNIX_BUFCHUNK
Definition unix.c:557
#define SUN_LEN(ptr)
Definition unix.c:72
static const char * unix_addrstr(COMSTACK h)
Definition unix.c:722
static int unix_set_blocking(COMSTACK p, int blocking)
Definition unix.c:729
struct sockaddr_un * unix_strtoaddr(const char *str)
Definition unix.c:294
static void unix_init(void)
Definition unix.c:95
COMSTACK unix_type(int s, int flags, int protocol, void *vp)
Definition unix.c:109
Header for UNIX domain socket COMSTACK.
#define xstrdup(s)
utility macro which calls xstrdup_f
Definition xmalloc.h:55
#define xfree(x)
utility macro which calls xfree_f
Definition xmalloc.h:53
#define xrealloc(o, x)
utility macro which calls xrealloc_f
Definition xmalloc.h:47
#define xmalloc(x)
utility macro which calls malloc_f
Definition xmalloc.h:49
Header with fundamental macros.
static int log_level_set
Definition ztest.c:42