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