revived syslog functions in the sys module.
fixed script and stream file name handling issues. added the path field to the hawk_sio_arg_t structure. the field should be set by the I/O handler if the name field is not HAWK_NULL.
This commit is contained in:
parent
40bf6910e5
commit
d2ed09fe4d
@ -1158,10 +1158,11 @@ static HAWK_INLINE int execute_hawk (int argc, hawk_bch_t* argv[])
|
||||
goto oops;
|
||||
}
|
||||
|
||||
/*const char* ocf[] = { "/dev/stdout", "/dev/stderr", NULL };*/
|
||||
rtx = hawk_rtx_openstdwithbcstr(
|
||||
awk, 0, "hawk",
|
||||
(arg.call? HAWK_NULL: arg.icf.ptr), /* console input */
|
||||
HAWK_NULL, /* console output */
|
||||
HAWK_NULL, /* ocf */ /* console output */
|
||||
arg.console_cmgr
|
||||
);
|
||||
if (rtx == HAWK_NULL)
|
||||
|
@ -85,6 +85,7 @@ libhawk_la_SOURCES = \
|
||||
fnc.c \
|
||||
htb.c \
|
||||
gem.c \
|
||||
gem-skad.c \
|
||||
hawk-prv.h \
|
||||
hawk.c \
|
||||
mb8.c \
|
||||
@ -119,6 +120,7 @@ libhawk_la_SOURCES = \
|
||||
utf8.c \
|
||||
utl-ass.c \
|
||||
utl-skad.c \
|
||||
utl-skad.h \
|
||||
utl-sort.c \
|
||||
utl-str.c \
|
||||
utl-sys.c \
|
||||
|
@ -165,16 +165,16 @@ am__libhawk_la_SOURCES_DIST = hawk.h hawk-chr.h hawk-cmn.h hawk-dir.h \
|
||||
hawk-ecs.h hawk-fmt.h hawk-gem.h hawk-htb.h hawk-rbt.h \
|
||||
hawk-pack1.h hawk-utl.h hawk-std.h hawk-tre.h hawk-unpack.h \
|
||||
arr.c chr.c dir.c ecs-imp.h ecs.c err-prv.h err.c fmt-imp.h \
|
||||
fmt.c fnc-prv.h fnc.c htb.c gem.c hawk-prv.h hawk.c mb8.c \
|
||||
misc-prv.h misc.c parse-prv.h parse.c rbt.c rec.c rio-prv.h \
|
||||
rio.c run-prv.h run.c tre-prv.h tre-ast.c tre-ast.h \
|
||||
fmt.c fnc-prv.h fnc.c htb.c gem.c gem-skad.c hawk-prv.h hawk.c \
|
||||
mb8.c misc-prv.h misc.c parse-prv.h parse.c rbt.c rec.c \
|
||||
rio-prv.h rio.c run-prv.h run.c tre-prv.h tre-ast.c tre-ast.h \
|
||||
tre-compile.c tre-compile.h tre-match-bt.c tre-match-pa.c \
|
||||
tre-match-ut.h tre-mem.c tre-mem.h tre-parse.c tre-parse.h \
|
||||
tre-stack.c tre-stack.h tre.c tree-prv.h tree.c utf16.c utf8.c \
|
||||
utl-ass.c utl-skad.c utl-sort.c utl-str.c utl-sys.c utl.c \
|
||||
val-prv.h val.c hawk-cli.h hawk-fio.h hawk-mtx.h hawk-pio.h \
|
||||
hawk-sio.h hawk-tio.h cli.c fio.c mtx.c pio.c sio.c syscall.h \
|
||||
syserr.h tio.c std-prv.h std.c imap-imp.h mod-math.c \
|
||||
utl-ass.c utl-skad.c utl-skad.h utl-sort.c utl-str.c utl-sys.c \
|
||||
utl.c val-prv.h val.c hawk-cli.h hawk-fio.h hawk-mtx.h \
|
||||
hawk-pio.h hawk-sio.h hawk-tio.h cli.c fio.c mtx.c pio.c sio.c \
|
||||
syscall.h syserr.h tio.c std-prv.h std.c imap-imp.h mod-math.c \
|
||||
mod-math.h mod-str.c mod-str.h mod-sys.c mod-sys.h
|
||||
am__objects_1 =
|
||||
@ENABLE_STATIC_MODULE_TRUE@am__objects_2 = libhawk_la-mod-math.lo \
|
||||
@ -183,10 +183,10 @@ am__objects_1 =
|
||||
am_libhawk_la_OBJECTS = $(am__objects_1) libhawk_la-arr.lo \
|
||||
libhawk_la-chr.lo libhawk_la-dir.lo libhawk_la-ecs.lo \
|
||||
libhawk_la-err.lo libhawk_la-fmt.lo libhawk_la-fnc.lo \
|
||||
libhawk_la-htb.lo libhawk_la-gem.lo libhawk_la-hawk.lo \
|
||||
libhawk_la-mb8.lo libhawk_la-misc.lo libhawk_la-parse.lo \
|
||||
libhawk_la-rbt.lo libhawk_la-rec.lo libhawk_la-rio.lo \
|
||||
libhawk_la-run.lo libhawk_la-tre-ast.lo \
|
||||
libhawk_la-htb.lo libhawk_la-gem.lo libhawk_la-gem-skad.lo \
|
||||
libhawk_la-hawk.lo libhawk_la-mb8.lo libhawk_la-misc.lo \
|
||||
libhawk_la-parse.lo libhawk_la-rbt.lo libhawk_la-rec.lo \
|
||||
libhawk_la-rio.lo libhawk_la-run.lo libhawk_la-tre-ast.lo \
|
||||
libhawk_la-tre-compile.lo libhawk_la-tre-match-bt.lo \
|
||||
libhawk_la-tre-match-pa.lo libhawk_la-tre-mem.lo \
|
||||
libhawk_la-tre-parse.lo libhawk_la-tre-stack.lo \
|
||||
@ -233,6 +233,7 @@ am__depfiles_remade = ./$(DEPDIR)/libhawk_la-arr.Plo \
|
||||
./$(DEPDIR)/libhawk_la-dir.Plo ./$(DEPDIR)/libhawk_la-ecs.Plo \
|
||||
./$(DEPDIR)/libhawk_la-err.Plo ./$(DEPDIR)/libhawk_la-fio.Plo \
|
||||
./$(DEPDIR)/libhawk_la-fmt.Plo ./$(DEPDIR)/libhawk_la-fnc.Plo \
|
||||
./$(DEPDIR)/libhawk_la-gem-skad.Plo \
|
||||
./$(DEPDIR)/libhawk_la-gem.Plo ./$(DEPDIR)/libhawk_la-hawk.Plo \
|
||||
./$(DEPDIR)/libhawk_la-htb.Plo ./$(DEPDIR)/libhawk_la-mb8.Plo \
|
||||
./$(DEPDIR)/libhawk_la-misc.Plo \
|
||||
@ -539,16 +540,16 @@ pkginclude_HEADERS = \
|
||||
pkglib_LTLIBRARIES = libhawk.la $(am__append_5)
|
||||
libhawk_la_SOURCES = $(pkginclude_HEADERS) arr.c chr.c dir.c ecs-imp.h \
|
||||
ecs.c err-prv.h err.c fmt-imp.h fmt.c fnc-prv.h fnc.c htb.c \
|
||||
gem.c hawk-prv.h hawk.c mb8.c misc-prv.h misc.c parse-prv.h \
|
||||
parse.c rbt.c rec.c rio-prv.h rio.c run-prv.h run.c tre-prv.h \
|
||||
tre-ast.c tre-ast.h tre-compile.c tre-compile.h tre-match-bt.c \
|
||||
tre-match-pa.c tre-match-ut.h tre-mem.c tre-mem.h tre-parse.c \
|
||||
tre-parse.h tre-stack.c tre-stack.h tre.c tree-prv.h tree.c \
|
||||
utf16.c utf8.c utl-ass.c utl-skad.c utl-sort.c utl-str.c \
|
||||
utl-sys.c utl.c val-prv.h val.c hawk-cli.h hawk-fio.h \
|
||||
hawk-mtx.h hawk-pio.h hawk-sio.h hawk-tio.h cli.c fio.c mtx.c \
|
||||
pio.c sio.c syscall.h syserr.h tio.c std-prv.h std.c \
|
||||
$(am__append_6)
|
||||
gem.c gem-skad.c hawk-prv.h hawk.c mb8.c misc-prv.h misc.c \
|
||||
parse-prv.h parse.c rbt.c rec.c rio-prv.h rio.c run-prv.h \
|
||||
run.c tre-prv.h tre-ast.c tre-ast.h tre-compile.c \
|
||||
tre-compile.h tre-match-bt.c tre-match-pa.c tre-match-ut.h \
|
||||
tre-mem.c tre-mem.h tre-parse.c tre-parse.h tre-stack.c \
|
||||
tre-stack.h tre.c tree-prv.h tree.c utf16.c utf8.c utl-ass.c \
|
||||
utl-skad.c utl-skad.h utl-sort.c utl-str.c utl-sys.c utl.c \
|
||||
val-prv.h val.c hawk-cli.h hawk-fio.h hawk-mtx.h hawk-pio.h \
|
||||
hawk-sio.h hawk-tio.h cli.c fio.c mtx.c pio.c sio.c syscall.h \
|
||||
syserr.h tio.c std-prv.h std.c $(am__append_6)
|
||||
libhawk_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON)
|
||||
libhawk_la_LDFLAGS = $(LDFLAGS_LIB_COMMON)
|
||||
libhawk_la_LIBADD = $(LIBADD_LIB_COMMON) $(am__append_7) \
|
||||
@ -674,6 +675,7 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-fio.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-fmt.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-fnc.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-gem-skad.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-gem.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-hawk.Plo@am__quote@ # am--include-marker
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhawk_la-htb.Plo@am__quote@ # am--include-marker
|
||||
@ -806,6 +808,13 @@ libhawk_la-gem.lo: gem.c
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhawk_la-gem.lo `test -f 'gem.c' || echo '$(srcdir)/'`gem.c
|
||||
|
||||
libhawk_la-gem-skad.lo: gem-skad.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhawk_la-gem-skad.lo -MD -MP -MF $(DEPDIR)/libhawk_la-gem-skad.Tpo -c -o libhawk_la-gem-skad.lo `test -f 'gem-skad.c' || echo '$(srcdir)/'`gem-skad.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhawk_la-gem-skad.Tpo $(DEPDIR)/libhawk_la-gem-skad.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='gem-skad.c' object='libhawk_la-gem-skad.lo' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libhawk_la-gem-skad.lo `test -f 'gem-skad.c' || echo '$(srcdir)/'`gem-skad.c
|
||||
|
||||
libhawk_la-hawk.lo: hawk.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhawk_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libhawk_la-hawk.lo -MD -MP -MF $(DEPDIR)/libhawk_la-hawk.Tpo -c -o libhawk_la-hawk.lo `test -f 'hawk.c' || echo '$(srcdir)/'`hawk.c
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhawk_la-hawk.Tpo $(DEPDIR)/libhawk_la-hawk.Plo
|
||||
@ -1260,6 +1269,7 @@ distclean: distclean-am
|
||||
-rm -f ./$(DEPDIR)/libhawk_la-fio.Plo
|
||||
-rm -f ./$(DEPDIR)/libhawk_la-fmt.Plo
|
||||
-rm -f ./$(DEPDIR)/libhawk_la-fnc.Plo
|
||||
-rm -f ./$(DEPDIR)/libhawk_la-gem-skad.Plo
|
||||
-rm -f ./$(DEPDIR)/libhawk_la-gem.Plo
|
||||
-rm -f ./$(DEPDIR)/libhawk_la-hawk.Plo
|
||||
-rm -f ./$(DEPDIR)/libhawk_la-htb.Plo
|
||||
@ -1352,6 +1362,7 @@ maintainer-clean: maintainer-clean-am
|
||||
-rm -f ./$(DEPDIR)/libhawk_la-fio.Plo
|
||||
-rm -f ./$(DEPDIR)/libhawk_la-fmt.Plo
|
||||
-rm -f ./$(DEPDIR)/libhawk_la-fnc.Plo
|
||||
-rm -f ./$(DEPDIR)/libhawk_la-gem-skad.Plo
|
||||
-rm -f ./$(DEPDIR)/libhawk_la-gem.Plo
|
||||
-rm -f ./$(DEPDIR)/libhawk_la-hawk.Plo
|
||||
-rm -f ./$(DEPDIR)/libhawk_la-htb.Plo
|
||||
|
@ -588,7 +588,7 @@ static int gem_err_bchars (hawk_fmtout_t* fmtout, const hawk_bch_t* ptr, hawk_oo
|
||||
#else
|
||||
if (len > max) len = max;
|
||||
if (len <= 0) return 1;
|
||||
HAWK_MEMCPY (&gem->errinf.msg[gem->errmsg_len], ptr, len * HAWK_SIZEOF(*ptr));
|
||||
HAWK_MEMCPY (&gem->errmsg[gem->errmsg_len], ptr, len * HAWK_SIZEOF(*ptr));
|
||||
gem->errmsg_len += len;
|
||||
#endif
|
||||
|
||||
|
404
hawk/lib/gem-skad.c
Normal file
404
hawk/lib/gem-skad.c
Normal file
@ -0,0 +1,404 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "hawk-prv.h"
|
||||
#include "utl-skad.h"
|
||||
|
||||
static int str_to_ipv4 (const hawk_ooch_t* str, hawk_oow_t len, struct in_addr* inaddr)
|
||||
{
|
||||
const hawk_ooch_t* end;
|
||||
int dots = 0, digits = 0;
|
||||
hawk_uint32_t acc = 0, addr = 0;
|
||||
hawk_ooch_t c;
|
||||
|
||||
end = str + len;
|
||||
|
||||
do
|
||||
{
|
||||
if (str >= end)
|
||||
{
|
||||
if (dots < 3 || digits == 0) return -1;
|
||||
addr = (addr << 8) | acc;
|
||||
break;
|
||||
}
|
||||
|
||||
c = *str++;
|
||||
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
if (digits > 0 && acc == 0) return -1;
|
||||
acc = acc * 10 + (c - '0');
|
||||
if (acc > 255) return -1;
|
||||
digits++;
|
||||
}
|
||||
else if (c == '.')
|
||||
{
|
||||
if (dots >= 3 || digits == 0) return -1;
|
||||
addr = (addr << 8) | acc;
|
||||
dots++; acc = 0; digits = 0;
|
||||
}
|
||||
else return -1;
|
||||
}
|
||||
while (1);
|
||||
|
||||
inaddr->s_addr = hawk_hton32(addr);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
static int str_to_ipv6 (const hawk_ooch_t* src, hawk_oow_t len, struct in6_addr* inaddr)
|
||||
{
|
||||
hawk_uint8_t* tp, * endp, * colonp;
|
||||
const hawk_ooch_t* curtok;
|
||||
hawk_ooch_t ch;
|
||||
int saw_xdigit;
|
||||
unsigned int val;
|
||||
const hawk_ooch_t* src_end;
|
||||
|
||||
src_end = src + len;
|
||||
|
||||
HAWK_MEMSET (inaddr, 0, HAWK_SIZEOF(*inaddr));
|
||||
tp = &inaddr->s6_addr[0];
|
||||
endp = &inaddr->s6_addr[HAWK_COUNTOF(inaddr->s6_addr)];
|
||||
colonp = HAWK_NULL;
|
||||
|
||||
/* Leading :: requires some special handling. */
|
||||
if (src < src_end && *src == ':')
|
||||
{
|
||||
src++;
|
||||
if (src >= src_end || *src != ':') return -1;
|
||||
}
|
||||
|
||||
curtok = src;
|
||||
saw_xdigit = 0;
|
||||
val = 0;
|
||||
|
||||
while (src < src_end)
|
||||
{
|
||||
int v1;
|
||||
|
||||
ch = *src++;
|
||||
|
||||
if (ch >= '0' && ch <= '9')
|
||||
v1 = ch - '0';
|
||||
else if (ch >= 'A' && ch <= 'F')
|
||||
v1 = ch - 'A' + 10;
|
||||
else if (ch >= 'a' && ch <= 'f')
|
||||
v1 = ch - 'a' + 10;
|
||||
else v1 = -1;
|
||||
if (v1 >= 0)
|
||||
{
|
||||
val <<= 4;
|
||||
val |= v1;
|
||||
if (val > 0xffff) return -1;
|
||||
saw_xdigit = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ch == ':')
|
||||
{
|
||||
curtok = src;
|
||||
if (!saw_xdigit)
|
||||
{
|
||||
if (colonp) return -1;
|
||||
colonp = tp;
|
||||
continue;
|
||||
}
|
||||
else if (src >= src_end)
|
||||
{
|
||||
/* a colon can't be the last character */
|
||||
return -1;
|
||||
}
|
||||
|
||||
*tp++ = (hawk_uint8_t)(val >> 8) & 0xff;
|
||||
*tp++ = (hawk_uint8_t)val & 0xff;
|
||||
saw_xdigit = 0;
|
||||
val = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ch == '.' && ((tp + HAWK_SIZEOF(struct in_addr)) <= endp) &&
|
||||
str_to_ipv4(curtok, src_end - curtok, (struct in_addr*)tp) == 0)
|
||||
{
|
||||
tp += HAWK_SIZEOF(struct in_addr*);
|
||||
saw_xdigit = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (saw_xdigit)
|
||||
{
|
||||
if (tp + HAWK_SIZEOF(hawk_uint16_t) > endp) return -1;
|
||||
*tp++ = (hawk_uint8_t)(val >> 8) & 0xff;
|
||||
*tp++ = (hawk_uint8_t)val & 0xff;
|
||||
}
|
||||
if (colonp != HAWK_NULL)
|
||||
{
|
||||
/*
|
||||
* Since some memmove()'s erroneously fail to handle
|
||||
* overlapping regions, we'll do the shift by hand.
|
||||
*/
|
||||
hawk_oow_t n = tp - colonp;
|
||||
hawk_oow_t i;
|
||||
|
||||
for (i = 1; i <= n; i++)
|
||||
{
|
||||
endp[-i] = colonp[n - i];
|
||||
colonp[n - i] = 0;
|
||||
}
|
||||
tp = endp;
|
||||
}
|
||||
|
||||
if (tp != endp) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int hawk_gem_oocharstoskad (hawk_gem_t* gem, const hawk_ooch_t* str, hawk_oow_t len, hawk_skad_t* _skad)
|
||||
{
|
||||
hawk_skad_alt_t* skad = (hawk_skad_alt_t*)_skad;
|
||||
const hawk_ooch_t* p;
|
||||
const hawk_ooch_t* end;
|
||||
hawk_oocs_t tmp;
|
||||
|
||||
p = str;
|
||||
end = str + len;
|
||||
|
||||
if (p >= end)
|
||||
{
|
||||
hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "blank address");
|
||||
return -1;
|
||||
}
|
||||
|
||||
HAWK_MEMSET (skad, 0, HAWK_SIZEOF(*skad));
|
||||
|
||||
#if defined(AF_UNIX)
|
||||
if (*p == '/' && len >= 2)
|
||||
{
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
hawk_copy_bcstr (skad->un.sun_path, HAWK_COUNTOF(skad->un.sun_path), str);
|
||||
#else
|
||||
hawk_oow_t dstlen;
|
||||
dstlen = HAWK_COUNTOF(skad->un.sun_path) - 1;
|
||||
if (hawk_gem_convutobchars(gem, p, &len, skad->un.sun_path, &dstlen) <= -1) return -1;
|
||||
skad->un.sun_path[dstlen] = '\0';
|
||||
#endif
|
||||
skad->un.sun_family = AF_UNIX;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
if (*p == '[')
|
||||
{
|
||||
/* IPv6 address */
|
||||
tmp.ptr = (hawk_ooch_t*)++p; /* skip [ and remember the position */
|
||||
while (p < end && *p != '%' && *p != ']') p++;
|
||||
|
||||
if (p >= end) goto no_rbrack;
|
||||
|
||||
tmp.len = p - tmp.ptr;
|
||||
if (*p == '%')
|
||||
{
|
||||
/* handle scope id */
|
||||
hawk_uint32_t x;
|
||||
|
||||
p++; /* skip % */
|
||||
|
||||
if (p >= end)
|
||||
{
|
||||
/* premature end */
|
||||
hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "scope id blank");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (*p >= '0' && *p <= '9')
|
||||
{
|
||||
/* numeric scope id */
|
||||
skad->in6.sin6_scope_id = 0;
|
||||
do
|
||||
{
|
||||
x = skad->in6.sin6_scope_id * 10 + (*p - '0');
|
||||
if (x < skad->in6.sin6_scope_id)
|
||||
{
|
||||
hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "scope id too large");
|
||||
return -1; /* overflow */
|
||||
}
|
||||
skad->in6.sin6_scope_id = x;
|
||||
p++;
|
||||
}
|
||||
while (p < end && *p >= '0' && *p <= '9');
|
||||
}
|
||||
else
|
||||
{
|
||||
#if 0
|
||||
TODO:
|
||||
/* interface name as a scope id? */
|
||||
const hawk_ooch_t* stmp = p;
|
||||
unsigned int index;
|
||||
do p++; while (p < end && *p != ']');
|
||||
if (hawk_nwifwcsntoindex(stmp, p - stmp, &index) <= -1) return -1;
|
||||
tmpad.u.in6.scope = index;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (p >= end || *p != ']') goto no_rbrack;
|
||||
}
|
||||
p++; /* skip ] */
|
||||
|
||||
if (str_to_ipv6(tmp.ptr, tmp.len, &skad->in6.sin6_addr) <= -1) goto unrecog;
|
||||
skad->in6.sin6_family = AF_INET6;
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
/* IPv4 address */
|
||||
tmp.ptr = (hawk_ooch_t*)p;
|
||||
while (p < end && *p != ':') p++;
|
||||
tmp.len = p - tmp.ptr;
|
||||
|
||||
if (str_to_ipv4(tmp.ptr, tmp.len, &skad->in4.sin_addr) <= -1)
|
||||
{
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
/* check if it is an IPv6 address not enclosed in [].
|
||||
* the port number can't be specified in this format. */
|
||||
if (p >= end || *p != ':')
|
||||
{
|
||||
/* without :, it can't be an ipv6 address */
|
||||
goto unrecog;
|
||||
}
|
||||
|
||||
|
||||
while (p < end && *p != '%') p++;
|
||||
tmp.len = p - tmp.ptr;
|
||||
|
||||
if (str_to_ipv6(tmp.ptr, tmp.len, &skad->in6.sin6_addr) <= -1) goto unrecog;
|
||||
|
||||
if (p < end && *p == '%')
|
||||
{
|
||||
/* handle scope id */
|
||||
hawk_uint32_t x;
|
||||
|
||||
p++; /* skip % */
|
||||
|
||||
if (p >= end)
|
||||
{
|
||||
/* premature end */
|
||||
hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "scope id blank");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (*p >= '0' && *p <= '9')
|
||||
{
|
||||
/* numeric scope id */
|
||||
skad->in6.sin6_scope_id = 0;
|
||||
do
|
||||
{
|
||||
x = skad->in6.sin6_scope_id * 10 + (*p - '0');
|
||||
if (x < skad->in6.sin6_scope_id)
|
||||
{
|
||||
hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "scope id too large");
|
||||
return -1; /* overflow */
|
||||
}
|
||||
skad->in6.sin6_scope_id = x;
|
||||
p++;
|
||||
}
|
||||
while (p < end && *p >= '0' && *p <= '9');
|
||||
}
|
||||
else
|
||||
{
|
||||
#if 0
|
||||
TODO
|
||||
/* interface name as a scope id? */
|
||||
const hawk_ooch_t* stmp = p;
|
||||
unsigned int index;
|
||||
do p++; while (p < end);
|
||||
if (hawk_nwifwcsntoindex (stmp, p - stmp, &index) <= -1) return -1;
|
||||
skad->in6.sin6_scope_id = index;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (p < end) goto unrecog; /* some gargage after the end? */
|
||||
|
||||
skad->in6.sin6_family = AF_INET6;
|
||||
return 0;
|
||||
#else
|
||||
goto unrecog;
|
||||
#endif
|
||||
}
|
||||
|
||||
skad->in4.sin_family = AF_INET;
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (p < end && *p == ':')
|
||||
{
|
||||
/* port number */
|
||||
hawk_uint32_t port = 0;
|
||||
|
||||
p++; /* skip : */
|
||||
|
||||
tmp.ptr = (hawk_ooch_t*)p;
|
||||
while (p < end && *p >= '0' && *p <= '9')
|
||||
{
|
||||
port = port * 10 + (*p - '0');
|
||||
p++;
|
||||
}
|
||||
|
||||
tmp.len = p - tmp.ptr;
|
||||
if (tmp.len <= 0 || tmp.len >= 6 ||
|
||||
port > HAWK_TYPE_MAX(hawk_uint16_t))
|
||||
{
|
||||
hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "port number blank or too large");
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
if (skad->in4.sin_family == AF_INET)
|
||||
skad->in4.sin_port = hawk_hton16(port);
|
||||
else
|
||||
skad->in6.sin6_port = hawk_hton16(port);
|
||||
#else
|
||||
skad->in4.sin_port = hawk_hton16(port);
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
unrecog:
|
||||
hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "unrecognized address");
|
||||
return -1;
|
||||
|
||||
no_rbrack:
|
||||
hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "missing right bracket");
|
||||
return -1;
|
||||
}
|
@ -1313,4 +1313,34 @@ typedef enum hawk_log_mask_t hawk_log_mask_t;
|
||||
# error Unsupported platform
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* =========================================================================
|
||||
* SOCKET ADDRESS
|
||||
* ========================================================================= */
|
||||
|
||||
#define HAWK_SIZEOF_SKAD_T 1
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN > HAWK_SIZEOF_SKAD_T)
|
||||
# undef HAWK_SIZEOF_SKAD_T
|
||||
# define HAWK_SIZEOF_SKAD_T HAWK_SIZEOF_STRUCT_SOCKADDR_IN
|
||||
#endif
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
# undef HAWK_SIZEOF_SKAD_T
|
||||
# define HAWK_SIZEOF_SKAD_T HAWK_SIZEOF_STRUCT_SOCKADDR_IN6
|
||||
#endif
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_LL > 0)
|
||||
# undef HAWK_SIZEOF_SKAD_T
|
||||
# define HAWK_SIZEOF_SKAD_T HAWK_SIZEOF_STRUCT_SOCKADDR_LL
|
||||
#endif
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_UN > 0)
|
||||
# undef HAWK_SIZEOF_SKAD_T
|
||||
# define HAWK_SIZEOF_SKAD_T HAWK_SIZEOF_STRUCT_SOCKADDR_UN
|
||||
#endif
|
||||
|
||||
struct hawk_skad_t
|
||||
{
|
||||
hawk_uint8_t data[HAWK_SIZEOF_SKAD_T];
|
||||
};
|
||||
typedef struct hawk_skad_t hawk_skad_t;
|
||||
|
||||
#endif
|
||||
|
@ -282,6 +282,13 @@ hawk_oow_t hawk_gem_fmttobcstr (
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
int hawk_gem_oocharstoskad (
|
||||
hawk_gem_t* gem,
|
||||
const hawk_ooch_t* str,
|
||||
hawk_oow_t len,
|
||||
hawk_skad_t* skad
|
||||
);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
@ -183,8 +183,8 @@ HAWK_EXPORT hawk_rtx_t* hawk_rtx_openstdwithbcstr (
|
||||
hawk_t* awk,
|
||||
hawk_oow_t xtnsize,
|
||||
const hawk_bch_t* id,
|
||||
const hawk_bch_t* icf[],
|
||||
const hawk_bch_t* ocf[],
|
||||
hawk_bch_t* icf[],
|
||||
hawk_bch_t* ocf[],
|
||||
hawk_cmgr_t* cmgr
|
||||
);
|
||||
|
||||
@ -198,8 +198,8 @@ HAWK_EXPORT hawk_rtx_t* hawk_rtx_openstdwithucstr (
|
||||
hawk_t* awk,
|
||||
hawk_oow_t xtnsize,
|
||||
const hawk_uch_t* id,
|
||||
const hawk_uch_t* icf[],
|
||||
const hawk_uch_t* ocf[],
|
||||
hawk_uch_t* icf[],
|
||||
hawk_uch_t* ocf[],
|
||||
hawk_cmgr_t* cmgr
|
||||
);
|
||||
|
||||
|
@ -353,34 +353,6 @@ typedef int (*hawk_sort_comperx_t) (
|
||||
int* cv
|
||||
);
|
||||
|
||||
|
||||
/* =========================================================================
|
||||
* SOCKET ADDRESS
|
||||
* ========================================================================= */
|
||||
#define HAWK_SIZEOF_SKAD_T 1
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN > HAWK_SIZEOF_SKAD_T)
|
||||
# undef HAWK_SIZEOF_SKAD_T
|
||||
# define HAWK_SIZEOF_SKAD_T HAWK_SIZEOF_STRUCT_SOCKADDR_IN
|
||||
#endif
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
# undef HAWK_SIZEOF_SKAD_T
|
||||
# define HAWK_SIZEOF_SKAD_T HAWK_SIZEOF_STRUCT_SOCKADDR_IN6
|
||||
#endif
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_LL > 0)
|
||||
# undef HAWK_SIZEOF_SKAD_T
|
||||
# define HAWK_SIZEOF_SKAD_T HAWK_SIZEOF_STRUCT_SOCKADDR_LL
|
||||
#endif
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_UN > 0)
|
||||
# undef HAWK_SIZEOF_SKAD_T
|
||||
# define HAWK_SIZEOF_SKAD_T HAWK_SIZEOF_STRUCT_SOCKADDR_UN
|
||||
#endif
|
||||
|
||||
struct hawk_skad_t
|
||||
{
|
||||
hawk_uint8_t data[HAWK_SIZEOF_SKAD_T];
|
||||
};
|
||||
typedef struct hawk_skad_t hawk_skad_t;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -1572,11 +1544,13 @@ HAWK_EXPORT void hawk_sub_time (
|
||||
/* =========================================================================
|
||||
* SOCKET ADDRESS
|
||||
* ========================================================================= */
|
||||
HAWK_EXPORT int hawk_oochars_to_skad (
|
||||
hawk_t* hawk,
|
||||
const hawk_ooch_t* str,
|
||||
hawk_oow_t len,
|
||||
hawk_skad_t* skad
|
||||
|
||||
HAWK_EXPORT int hawk_skad_family (
|
||||
const hawk_skad_t* skad
|
||||
);
|
||||
|
||||
HAWK_EXPORT int hawk_skad_size (
|
||||
const hawk_skad_t* skad
|
||||
);
|
||||
|
||||
/* =========================================================================
|
||||
|
@ -553,9 +553,9 @@ typedef struct hawk_sio_arg_t hawk_sio_arg_t;
|
||||
struct hawk_sio_arg_t
|
||||
{
|
||||
/**
|
||||
* [IN/OUT] name of I/O object.
|
||||
* [IN] name of I/O object.
|
||||
* It is #HAWK_NULL for the top-level stream. It points to a stream name
|
||||
* for an included stream. This can be changed by an I/O handler.
|
||||
* for an included stream.
|
||||
*/
|
||||
const hawk_ooch_t* name;
|
||||
|
||||
@ -567,6 +567,12 @@ struct hawk_sio_arg_t
|
||||
*/
|
||||
void* handle;
|
||||
|
||||
/**
|
||||
* [OUT] path name resolved of the name above. the handler must set this
|
||||
* to a proper path if the name is not #HAWK_NULL.
|
||||
*/
|
||||
hawk_ooch_t* path;
|
||||
|
||||
/**
|
||||
* [OUT] unique id set by an input handler. it is used for a single time inclusion check.
|
||||
*/
|
||||
|
@ -93,7 +93,7 @@ struct mod_ctx_t
|
||||
{
|
||||
syslog_type_t type;
|
||||
char* ident;
|
||||
// hawk_skad_t skad;
|
||||
hawk_skad_t skad;
|
||||
int syslog_opened; // has openlog() been called?
|
||||
int opt;
|
||||
int fac;
|
||||
@ -2089,18 +2089,22 @@ skip_unlink:
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
#if 0
|
||||
// TODO: add back the syslog support
|
||||
|
||||
/*
|
||||
* sys::openlog("remote://192.168.1.23:1234/test", sys::LOG_OPT_PID | sys::LOG_OPT_NDELAY, sys::LOG_FAC_LOCAL0);
|
||||
* for (i = 0; i < 10; i++) sys::writelog(sys::LOG_PRI_DEBUG, "hello world " i);
|
||||
* sys::closelog();
|
||||
*/
|
||||
static void open_remote_log_socket (hawk_rtx_t* rtx, mod_ctx_t* mctx)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
/* TODO: implement this */
|
||||
#else
|
||||
int sck, flags;
|
||||
int domain = hawk_skadfamily(&mctx->log.skad);
|
||||
int domain = hawk_skad_family(&mctx->log.skad);
|
||||
int type = SOCK_DGRAM;
|
||||
|
||||
//HAWK_ASSERT (mctx->log.sck <= -1);
|
||||
HAWK_ASSERT (mctx->log.sck <= -1);
|
||||
|
||||
#if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
|
||||
type |= SOCK_NONBLOCK;
|
||||
@ -2151,7 +2155,7 @@ static int fnc_openlog (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
hawk_oow_t ident_len;
|
||||
hawk_bch_t* mbs_ident;
|
||||
mod_ctx_t* mctx = (mod_ctx_t*)fi->mod->ctx;
|
||||
hawk_nwad_t nwad;
|
||||
hawk_skad_t skad;
|
||||
syslog_type_t log_type = SYSLOG_LOCAL;
|
||||
|
||||
ident = hawk_rtx_getvaloocstr(rtx, hawk_rtx_getarg(rtx, 0), &ident_len);
|
||||
@ -2164,19 +2168,19 @@ static int fnc_openlog (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
if (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 1), &opt) <= -1) goto done;
|
||||
if (hawk_rtx_valtoint(rtx, hawk_rtx_getarg(rtx, 2), &fac) <= -1) goto done;
|
||||
|
||||
if (hawk_comp_oocstr_limited(ident, HAWK_T("remote://"), 9, 0))
|
||||
if (hawk_comp_oocstr_limited(ident, HAWK_T("remote://"), 9, 0) == 0)
|
||||
{
|
||||
hawk_ooch_t* slash;
|
||||
/* "udp://remote-addr:remote-port/syslog-identifier" */
|
||||
/* "remote://remote-addr:remote-port/syslog-identifier" */
|
||||
|
||||
log_type = SYSLOG_REMOTE;
|
||||
actual_ident = ident + 9;
|
||||
slash = hawk_find_oochar_in_oocstr(actual_ident, '/');
|
||||
if (!slash) goto done;
|
||||
if (hawk_strntonwad(actual_ident, slash - actual_ident, &nwad) <= -1) goto done;
|
||||
if (hawk_gem_oocharstoskad (hawk_rtx_getgem(rtx), actual_ident, slash - actual_ident, &skad) <= -1) goto done;
|
||||
actual_ident = slash + 1;
|
||||
}
|
||||
else if (hawk_comp_oocstr_limited(ident, HAWK_T("local://"), 8, 0))
|
||||
else if (hawk_comp_oocstr_limited(ident, HAWK_T("local://"), 8, 0) == 0)
|
||||
{
|
||||
/* "local://syslog-identifier" */
|
||||
actual_ident = ident + 8;
|
||||
@ -2187,9 +2191,9 @@ static int fnc_openlog (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
}
|
||||
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
mbs_ident = hawk_rtx_dupbcstr(rtx, actual_ident);
|
||||
mbs_ident = hawk_rtx_dupbcstr(rtx, actual_ident, HAWK_NULL);
|
||||
#else
|
||||
mbs_ident = hawk_rtx_duputobcstr(actual_ident, str, HAWK_NULL);
|
||||
mbs_ident = hawk_rtx_duputobcstr(rtx, actual_ident, HAWK_NULL);
|
||||
#endif
|
||||
if (!mbs_ident) goto done;
|
||||
|
||||
@ -2225,7 +2229,7 @@ static int fnc_openlog (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
}
|
||||
else if (mctx->log.type == SYSLOG_REMOTE)
|
||||
{
|
||||
hawk_nwadtoskad (&nwad, &mctx->log.skad);
|
||||
mctx->log.skad = skad;
|
||||
if ((opt & LOG_NDELAY) && mctx->log.sck <= -1) open_remote_log_socket (rtx, mctx);
|
||||
}
|
||||
|
||||
@ -2337,8 +2341,6 @@ static int fnc_writelog (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
#if defined(_WIN32)
|
||||
/* TODO: implement this */
|
||||
#else
|
||||
hawk_ntime_t now;
|
||||
hawk_btime_t cnow;
|
||||
|
||||
static const hawk_bch_t* __syslog_month_names[] =
|
||||
{
|
||||
@ -2350,16 +2352,28 @@ static int fnc_writelog (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
|
||||
if (mctx->log.sck >= 0)
|
||||
{
|
||||
if (!mctx->log.dmsgbuf) mctx->log.dmsgbuf = hawk_becs_open(hawk_rtx_getmmgr(rtx), 0, 0);
|
||||
hawk_ntime_t now;
|
||||
struct tm tm, * tmx;
|
||||
time_t t;
|
||||
|
||||
if (!mctx->log.dmsgbuf) mctx->log.dmsgbuf = hawk_becs_open(hawk_rtx_getgem(rtx), 0, 0);
|
||||
if (!mctx->log.dmsgbuf) goto done;
|
||||
|
||||
if (hawk_get_time(&now) || hawk_localtime(&now, &cnow) <= -1) goto done;
|
||||
if (hawk_get_time(&now) <= -1) goto done;
|
||||
|
||||
t = now.sec;
|
||||
#if defined(HAVE_LOCALTIME_R)
|
||||
tmx = localtime_r(&t, &tm);
|
||||
#else
|
||||
tmx = localtime(&t);
|
||||
#endif
|
||||
if (!tmx) goto done;
|
||||
|
||||
if (hawk_becs_fmt(
|
||||
mctx->log.dmsgbuf, HAWK_BT("<%d>%s %02d %02d:%02d:%02d "),
|
||||
(int)(mctx->log.fac | pri),
|
||||
__syslog_month_names[cnow.mon], cnow.mday,
|
||||
cnow.hour, cnow.min, cnow.sec) == (hawk_oow_t)-1) goto done;
|
||||
__syslog_month_names[tmx->tm_mon], tmx->tm_mday,
|
||||
tmx->tm_hour, tmx->tm_min, tmx->tm_sec) == (hawk_oow_t)-1) goto done;
|
||||
|
||||
if (mctx->log.ident || (mctx->log.opt & LOG_PID))
|
||||
{
|
||||
@ -2383,8 +2397,8 @@ static int fnc_writelog (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
#endif
|
||||
|
||||
/* don't care about output failure */
|
||||
sendto (mctx->log.sck, HAWK_MBS_PTR(mctx->log.dmsgbuf), HAWK_MBS_LEN(mctx->log.dmsgbuf),
|
||||
0, (struct sockaddr*)&mctx->log.skad, hawk_skadsize(&mctx->log.skad));
|
||||
sendto (mctx->log.sck, HAWK_BECS_PTR(mctx->log.dmsgbuf), HAWK_BECS_LEN(mctx->log.dmsgbuf),
|
||||
0, (struct sockaddr*)&mctx->log.skad, hawk_skad_size(&mctx->log.skad));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -2400,7 +2414,7 @@ done:
|
||||
hawk_rtx_setretval (rtx, retv);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
||||
typedef struct fnctab_t fnctab_t;
|
||||
@ -2429,7 +2443,7 @@ static fnctab_t fnctab[] =
|
||||
{ HAWK_T("chmod"), { { 2, 2, HAWK_NULL }, fnc_chmod, 0 } },
|
||||
{ HAWK_T("close"), { { 1, 2, HAWK_NULL }, fnc_close, 0 } },
|
||||
{ HAWK_T("closedir"), { { 1, 1, HAWK_NULL }, fnc_closedir, 0 } },
|
||||
//{ HAWK_T("closelog"), { { 0, 0, HAWK_NULL }, fnc_closelog, 0 } },
|
||||
{ HAWK_T("closelog"), { { 0, 0, HAWK_NULL }, fnc_closelog, 0 } },
|
||||
{ HAWK_T("dup"), { { 1, 3, HAWK_NULL }, fnc_dup, 0 } },
|
||||
{ HAWK_T("errmsg"), { { 0, 0, HAWK_NULL }, fnc_errmsg, 0 } },
|
||||
{ HAWK_T("fork"), { { 0, 0, HAWK_NULL }, fnc_fork, 0 } },
|
||||
@ -2450,7 +2464,7 @@ static fnctab_t fnctab[] =
|
||||
{ HAWK_T("open"), { { 2, 3, HAWK_NULL }, fnc_open, 0 } },
|
||||
{ HAWK_T("opendir"), { { 1, 2, HAWK_NULL }, fnc_opendir, 0 } },
|
||||
{ HAWK_T("openfd"), { { 1, 1, HAWK_NULL }, fnc_openfd, 0 } },
|
||||
//{ HAWK_T("openlog"), { { 3, 3, HAWK_NULL }, fnc_openlog, 0 } },
|
||||
{ HAWK_T("openlog"), { { 3, 3, HAWK_NULL }, fnc_openlog, 0 } },
|
||||
{ HAWK_T("pipe"), { { 2, 3, HAWK_T("rrv") }, fnc_pipe, 0 } },
|
||||
{ HAWK_T("read"), { { 2, 3, HAWK_T("vrv") }, fnc_read, 0 } },
|
||||
{ HAWK_T("readdir"), { { 2, 2, HAWK_T("vr") }, fnc_readdir, 0 } },
|
||||
@ -2462,7 +2476,7 @@ static fnctab_t fnctab[] =
|
||||
{ HAWK_T("unlink"), { { 1, 1, HAWK_NULL }, fnc_unlink, 0 } },
|
||||
{ HAWK_T("wait"), { { 1, 3, HAWK_T("vrv") }, fnc_wait, 0 } },
|
||||
{ HAWK_T("write"), { { 2, 2, HAWK_NULL }, fnc_write, 0 } },
|
||||
//{ HAWK_T("writelog"), { { 2, 2, HAWK_NULL }, fnc_writelog, 0 } }
|
||||
{ HAWK_T("writelog"), { { 2, 2, HAWK_NULL }, fnc_writelog, 0 } }
|
||||
};
|
||||
|
||||
#if !defined(SIGHUP)
|
||||
@ -2668,11 +2682,9 @@ static int init (hawk_mod_t* mod, hawk_rtx_t* rtx)
|
||||
mod_ctx_t* mctx = (mod_ctx_t*)mod->ctx;
|
||||
rtx_data_t data;
|
||||
|
||||
#if 0
|
||||
mctx->log.type = SYSLOG_LOCAL;
|
||||
mctx->log.syslog_opened = 0;
|
||||
mctx->log.sck = -1;
|
||||
#endif
|
||||
|
||||
HAWK_MEMSET (&data, 0, HAWK_SIZEOF(data));
|
||||
if (hawk_rbt_insert(mctx->rtxtab, &rtx, HAWK_SIZEOF(rtx), &data, HAWK_SIZEOF(data)) == HAWK_NULL) return -1;
|
||||
@ -2717,7 +2729,6 @@ static void fini (hawk_mod_t* mod, hawk_rtx_t* rtx)
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
#if defined(ENABLE_SYSLOG)
|
||||
if (mctx->log.syslog_opened)
|
||||
{
|
||||
@ -2752,7 +2763,6 @@ static void fini (hawk_mod_t* mod, hawk_rtx_t* rtx)
|
||||
hawk_rtx_freemem (rtx, mctx->log.ident);
|
||||
mctx->log.ident = HAWK_NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void unload (hawk_mod_t* mod, hawk_t* awk)
|
||||
|
@ -65,35 +65,53 @@ typedef enum hawk_kwid_t hawk_kwid_t;
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int hawk_putsroocs (
|
||||
hawk_t* awk,
|
||||
int hawk_putsrcoocstr (
|
||||
hawk_t* hawk,
|
||||
const hawk_ooch_t* str
|
||||
);
|
||||
|
||||
int hawk_putsroocsn (
|
||||
hawk_t* awk,
|
||||
int hawk_putsrcoochars (
|
||||
hawk_t* hawk,
|
||||
const hawk_ooch_t* str,
|
||||
hawk_oow_t len
|
||||
);
|
||||
|
||||
const hawk_ooch_t* hawk_getgblname (
|
||||
hawk_t* awk,
|
||||
hawk_t* hawk,
|
||||
hawk_oow_t idx,
|
||||
hawk_oow_t* len
|
||||
);
|
||||
|
||||
void hawk_getkwname (
|
||||
hawk_t* awk,
|
||||
hawk_t* hawk,
|
||||
hawk_kwid_t id,
|
||||
hawk_oocs_t* s
|
||||
);
|
||||
|
||||
int hawk_initgbls (
|
||||
hawk_t* awk
|
||||
hawk_t* hawk
|
||||
);
|
||||
|
||||
hawk_ooch_t* hawk_addsionamewithuchars (
|
||||
hawk_t* hawk,
|
||||
const hawk_uch_t* ptr,
|
||||
hawk_oow_t len
|
||||
);
|
||||
|
||||
hawk_ooch_t* hawk_addsionamewithbchars (
|
||||
hawk_t* hawk,
|
||||
const hawk_bch_t* ptr,
|
||||
hawk_oow_t len
|
||||
);
|
||||
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
# define hawk_addsionamewithoochars hawk_addsionamewithuchars
|
||||
#else
|
||||
# define hawk_addsionamewithoochars hawk_addsionamewithbchars
|
||||
#endif
|
||||
|
||||
void hawk_clearsionames (
|
||||
hawk_t* awk
|
||||
hawk_t* hawk
|
||||
);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
153
hawk/lib/parse.c
153
hawk/lib/parse.c
@ -471,7 +471,7 @@ static int get_char (hawk_t* awk)
|
||||
if (awk->sio.inp->b.pos >= awk->sio.inp->b.len)
|
||||
{
|
||||
CLRERR (awk);
|
||||
n = awk->sio.inf (
|
||||
n = awk->sio.inf(
|
||||
awk, HAWK_SIO_CMD_READ, awk->sio.inp,
|
||||
awk->sio.inp->b.buf, HAWK_COUNTOF(awk->sio.inp->b.buf)
|
||||
);
|
||||
@ -487,7 +487,7 @@ static int get_char (hawk_t* awk)
|
||||
awk->sio.inp->last.c = HAWK_OOCI_EOF;
|
||||
awk->sio.inp->last.line = awk->sio.inp->line;
|
||||
awk->sio.inp->last.colm = awk->sio.inp->colm;
|
||||
awk->sio.inp->last.file = awk->sio.inp->name;
|
||||
awk->sio.inp->last.file = awk->sio.inp->path;
|
||||
awk->sio.last = awk->sio.inp->last;
|
||||
return 0;
|
||||
}
|
||||
@ -510,7 +510,7 @@ static int get_char (hawk_t* awk)
|
||||
awk->sio.inp->last.c = awk->sio.inp->b.buf[awk->sio.inp->b.pos++];
|
||||
awk->sio.inp->last.line = awk->sio.inp->line;
|
||||
awk->sio.inp->last.colm = awk->sio.inp->colm++;
|
||||
awk->sio.inp->last.file = awk->sio.inp->name;
|
||||
awk->sio.inp->last.file = awk->sio.inp->path;
|
||||
awk->sio.last = awk->sio.inp->last;
|
||||
return 0;
|
||||
}
|
||||
@ -587,9 +587,7 @@ static int parse (hawk_t* awk)
|
||||
/* see parse_fncall() for what is
|
||||
* stored into awk->tree.funs */
|
||||
nde = (hawk_nde_t*)HAWK_HTB_VPTR(p);
|
||||
|
||||
SETERR_ARG_LOC (awk, HAWK_EFUNNF, HAWK_HTB_KPTR(p), HAWK_HTB_KLEN(p), &nde->loc);
|
||||
|
||||
goto oops;
|
||||
}
|
||||
|
||||
@ -611,9 +609,7 @@ oops:
|
||||
hawk_sio_arg_t* prev;
|
||||
|
||||
/* nothing much to do about a close error */
|
||||
awk->sio.inf (
|
||||
awk, HAWK_SIO_CMD_CLOSE,
|
||||
awk->sio.inp, HAWK_NULL, 0);
|
||||
awk->sio.inf (awk, HAWK_SIO_CMD_CLOSE, awk->sio.inp, HAWK_NULL, 0);
|
||||
|
||||
prev = awk->sio.inp->prev;
|
||||
|
||||
@ -651,14 +647,79 @@ oops:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void hawk_clearsionames (hawk_t* awk)
|
||||
hawk_ooch_t* hawk_addsionamewithuchars (hawk_t* hawk, const hawk_uch_t* ptr, hawk_oow_t len)
|
||||
{
|
||||
hawk_link_t* link;
|
||||
|
||||
/* TODO: duplication check? */
|
||||
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
link = (hawk_link_t*)hawk_callocmem(hawk, HAWK_SIZEOF(*link) + HAWK_SIZEOF(hawk_uch_t) * (len + 1));
|
||||
if (!link) return HAWK_NULL;
|
||||
|
||||
hawk_copy_uchars_to_ucstr_unlimited ((hawk_uch_t*)(link + 1), ptr, len);
|
||||
#else
|
||||
hawk_oow_t bcslen, ucslen;
|
||||
|
||||
ucslen = len;
|
||||
if (hawk_convutobchars(hawk, ptr, &ucslen, HAWK_NULL, &bcslen) <= -1) return HAWK_NULL;
|
||||
|
||||
link = (hawk_link_t*)hawk_callocmem(hawk, HAWK_SIZEOF(*link) + HAWK_SIZEOF(hawk_bch_t) * (bcslen + 1));
|
||||
if (!link) return HAWK_NULL;
|
||||
|
||||
ucslen = len;
|
||||
bcslen = bcslen + 1;
|
||||
hawk_convutobchars (hawk, ptr, &ucslen, (hawk_bch_t*)(link + 1), &bcslen);
|
||||
((hawk_bch_t*)(link + 1))[bcslen] = '\0';
|
||||
#endif
|
||||
|
||||
link->link = hawk->sio_names;
|
||||
hawk->sio_names = link;
|
||||
|
||||
return (hawk_ooch_t*)(link + 1);
|
||||
}
|
||||
|
||||
hawk_ooch_t* hawk_addsionamewithbchars (hawk_t* hawk, const hawk_bch_t* ptr, hawk_oow_t len)
|
||||
{
|
||||
hawk_link_t* link;
|
||||
|
||||
/* TODO: duplication check? */
|
||||
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
hawk_oow_t bcslen, ucslen;
|
||||
|
||||
bcslen = len;
|
||||
if (hawk_convbtouchars (hawk, ptr, &bcslen, HAWK_NULL, &ucslen, 0) <= -1) return HAWK_NULL;
|
||||
|
||||
link = (hawk_link_t*)hawk_callocmem(hawk, HAWK_SIZEOF(*link) + HAWK_SIZEOF(hawk_uch_t) * (ucslen + 1));
|
||||
if (!link) return HAWK_NULL;
|
||||
|
||||
bcslen = len;
|
||||
ucslen = ucslen + 1;
|
||||
hawk_convbtouchars (hawk, ptr, &bcslen, (hawk_uch_t*)(link + 1), &ucslen, 0);
|
||||
((hawk_uch_t*)(link + 1))[ucslen] = '\0';
|
||||
|
||||
#else
|
||||
link = (hawk_link_t*)hawk_callocmem(hawk, HAWK_SIZEOF(*link) + HAWK_SIZEOF(hawk_bch_t) * (len + 1));
|
||||
if (!link) return HAWK_NULL;
|
||||
|
||||
hawk_copy_bchars_to_bcstr_unlimited ((hawk_bch_t*)(link + 1), ptr, len);
|
||||
#endif
|
||||
|
||||
link->link = hawk->sio_names;
|
||||
hawk->sio_names = link;
|
||||
|
||||
return (hawk_ooch_t*)(link + 1);
|
||||
}
|
||||
|
||||
void hawk_clearsionames (hawk_t* hawk)
|
||||
{
|
||||
hawk_link_t* cur;
|
||||
while (awk->sio_names)
|
||||
while (hawk->sio_names)
|
||||
{
|
||||
cur = awk->sio_names;
|
||||
awk->sio_names = cur->link;
|
||||
hawk_freemem (awk, cur);
|
||||
cur = hawk->sio_names;
|
||||
hawk->sio_names = cur->link;
|
||||
hawk_freemem (hawk, cur);
|
||||
}
|
||||
}
|
||||
|
||||
@ -688,6 +749,9 @@ int hawk_parse (hawk_t* awk, hawk_sio_cbs_t* sio)
|
||||
awk->sio.inf = sio->in;
|
||||
awk->sio.outf = sio->out;
|
||||
awk->sio.last.c = HAWK_OOCI_EOF;
|
||||
/*awk->sio.arg.name = HAWK_NULL;
|
||||
awk->sio.arg.handle = HAWK_NULL;
|
||||
awk->sio.arg.path = HAWK_NULL;*/
|
||||
awk->sio.arg.line = 1;
|
||||
awk->sio.arg.colm = 1;
|
||||
awk->sio.arg.pragma_trait = 0;
|
||||
@ -775,6 +839,7 @@ static int begin_include (hawk_t* awk, int once)
|
||||
{
|
||||
hawk_sio_arg_t* arg = HAWK_NULL;
|
||||
hawk_link_t* link;
|
||||
hawk_ooch_t* sio_name;
|
||||
|
||||
if (hawk_count_oocstr(HAWK_OOECS_PTR(awk->tok.name)) != HAWK_OOECS_LEN(awk->tok.name))
|
||||
{
|
||||
@ -798,27 +863,22 @@ static int begin_include (hawk_t* awk, int once)
|
||||
|
||||
/* store the include-file name into a list
|
||||
* and this list is not deleted after hawk_parse.
|
||||
* the errinfo.loc.file can point to a include_oncestring here. */
|
||||
link = (hawk_link_t*)hawk_callocmem(awk, HAWK_SIZEOF(*link) +
|
||||
HAWK_SIZEOF(*arg) + HAWK_SIZEOF(hawk_ooch_t) * (HAWK_OOECS_LEN(awk->tok.name) + 1));
|
||||
if (!link)
|
||||
* the errinfo.loc.file can point to the file name here. */
|
||||
sio_name = hawk_addsionamewithoochars(awk, HAWK_OOECS_PTR(awk->tok.name), HAWK_OOECS_LEN(awk->tok.name));
|
||||
if (!sio_name)
|
||||
{
|
||||
ADJERR_LOC (awk, &awk->ptok.loc);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
hawk_copy_oochars_to_oocstr_unlimited ((hawk_ooch_t*)(link + 1), HAWK_OOECS_PTR(awk->tok.name), HAWK_OOECS_LEN(awk->tok.name));
|
||||
link->link = awk->sio_names;
|
||||
awk->sio_names = link;
|
||||
|
||||
arg = (hawk_sio_arg_t*)hawk_callocmem(awk, HAWK_SIZEOF(*awk));
|
||||
arg = (hawk_sio_arg_t*)hawk_callocmem(awk, HAWK_SIZEOF(*arg));
|
||||
if (!arg)
|
||||
{
|
||||
ADJERR_LOC (awk, &awk->ptok.loc);
|
||||
goto oops;
|
||||
}
|
||||
|
||||
arg->name = (const hawk_ooch_t*)(link + 1);
|
||||
arg->name = sio_name;
|
||||
arg->line = 1;
|
||||
arg->colm = 1;
|
||||
|
||||
@ -6227,7 +6287,7 @@ static int skip_comment (hawk_t* awk)
|
||||
hawk_loc_t loc;
|
||||
loc.line = awk->sio.inp->line;
|
||||
loc.colm = awk->sio.inp->colm;
|
||||
loc.file = awk->sio.inp->name;
|
||||
loc.file = awk->sio.inp->path;
|
||||
SETERR_LOC (awk, HAWK_ECMTNC, &loc);
|
||||
return -1;
|
||||
}
|
||||
@ -6240,7 +6300,7 @@ static int skip_comment (hawk_t* awk)
|
||||
hawk_loc_t loc;
|
||||
loc.line = awk->sio.inp->line;
|
||||
loc.colm = awk->sio.inp->colm;
|
||||
loc.file = awk->sio.inp->name;
|
||||
loc.file = awk->sio.inp->path;
|
||||
SETERR_LOC (awk, HAWK_ECMTNC, &loc);
|
||||
return -1;
|
||||
}
|
||||
@ -6713,9 +6773,9 @@ static int deparse (hawk_t* awk)
|
||||
hawk_oow_t len;
|
||||
|
||||
len = hawk_int_to_oocstr((hawk_int_t)awk->parse.pragma.rtx_stack_limit, 10, HAWK_NULL, tmp, HAWK_COUNTOF(tmp));
|
||||
if (hawk_putsroocs(awk, HAWK_T("@pragma stack_limit ")) <= -1 ||
|
||||
hawk_putsroocsn (awk, tmp, len) <= -1 ||
|
||||
hawk_putsroocs(awk, HAWK_T(";\n")) <= -1) EXIT_DEPARSE ();
|
||||
if (hawk_putsrcoocstr(awk, HAWK_T("@pragma stack_limit ")) <= -1 ||
|
||||
hawk_putsrcoochars (awk, tmp, len) <= -1 ||
|
||||
hawk_putsrcoocstr(awk, HAWK_T(";\n")) <= -1) EXIT_DEPARSE ();
|
||||
}
|
||||
|
||||
if (awk->tree.ngbls > awk->tree.ngbls_base)
|
||||
@ -6725,44 +6785,44 @@ static int deparse (hawk_t* awk)
|
||||
HAWK_ASSERT (awk->tree.ngbls > 0);
|
||||
|
||||
hawk_getkwname (awk, HAWK_KWID_XGLOBAL, &kw);
|
||||
if (hawk_putsroocsn(awk, kw.ptr, kw.len) <= -1 || hawk_putsroocs (awk, HAWK_T(" ")) <= -1) EXIT_DEPARSE ();
|
||||
if (hawk_putsrcoochars(awk, kw.ptr, kw.len) <= -1 || hawk_putsrcoocstr (awk, HAWK_T(" ")) <= -1) EXIT_DEPARSE ();
|
||||
|
||||
for (i = awk->tree.ngbls_base; i < awk->tree.ngbls - 1; i++)
|
||||
{
|
||||
if (!(awk->opt.trait & HAWK_IMPLICIT))
|
||||
{
|
||||
/* use the actual name if no named variable is allowed */
|
||||
if (hawk_putsroocsn (awk, HAWK_ARR_DPTR(awk->parse.gbls, i), HAWK_ARR_DLEN(awk->parse.gbls, i)) <= -1) EXIT_DEPARSE ();
|
||||
if (hawk_putsrcoochars (awk, HAWK_ARR_DPTR(awk->parse.gbls, i), HAWK_ARR_DLEN(awk->parse.gbls, i)) <= -1) EXIT_DEPARSE ();
|
||||
}
|
||||
else
|
||||
{
|
||||
len = hawk_int_to_oocstr((hawk_int_t)i, 10, HAWK_T("__g"), tmp, HAWK_COUNTOF(tmp));
|
||||
HAWK_ASSERT (len != (hawk_oow_t)-1);
|
||||
if (hawk_putsroocsn (awk, tmp, len) <= -1) EXIT_DEPARSE ();
|
||||
if (hawk_putsrcoochars (awk, tmp, len) <= -1) EXIT_DEPARSE ();
|
||||
}
|
||||
|
||||
if (hawk_putsroocs (awk, HAWK_T(", ")) <= -1) EXIT_DEPARSE ();
|
||||
if (hawk_putsrcoocstr (awk, HAWK_T(", ")) <= -1) EXIT_DEPARSE ();
|
||||
}
|
||||
|
||||
if (!(awk->opt.trait & HAWK_IMPLICIT))
|
||||
{
|
||||
/* use the actual name if no named variable is allowed */
|
||||
if (hawk_putsroocsn(awk, HAWK_ARR_DPTR(awk->parse.gbls,i), HAWK_ARR_DLEN(awk->parse.gbls,i)) <= -1) EXIT_DEPARSE ();
|
||||
if (hawk_putsrcoochars(awk, HAWK_ARR_DPTR(awk->parse.gbls,i), HAWK_ARR_DLEN(awk->parse.gbls,i)) <= -1) EXIT_DEPARSE ();
|
||||
}
|
||||
else
|
||||
{
|
||||
len = hawk_int_to_oocstr((hawk_int_t)i, 10, HAWK_T("__g"), tmp, HAWK_COUNTOF(tmp));
|
||||
HAWK_ASSERT (len != (hawk_oow_t)-1);
|
||||
if (hawk_putsroocsn (awk, tmp, len) <= -1) EXIT_DEPARSE ();
|
||||
if (hawk_putsrcoochars (awk, tmp, len) <= -1) EXIT_DEPARSE ();
|
||||
}
|
||||
|
||||
if (awk->opt.trait & HAWK_CRLF)
|
||||
{
|
||||
if (hawk_putsroocs(awk, HAWK_T(";\r\n\r\n")) <= -1) EXIT_DEPARSE ();
|
||||
if (hawk_putsrcoocstr(awk, HAWK_T(";\r\n\r\n")) <= -1) EXIT_DEPARSE ();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hawk_putsroocs(awk, HAWK_T(";\n\n")) <= -1) EXIT_DEPARSE ();
|
||||
if (hawk_putsrcoocstr(awk, HAWK_T(";\n\n")) <= -1) EXIT_DEPARSE ();
|
||||
}
|
||||
}
|
||||
|
||||
@ -6780,8 +6840,8 @@ static int deparse (hawk_t* awk)
|
||||
|
||||
hawk_getkwname (awk, HAWK_KWID_BEGIN, &kw);
|
||||
|
||||
if (hawk_putsroocsn (awk, kw.ptr, kw.len) <= -1) EXIT_DEPARSE ();
|
||||
if (hawk_putsroocs (awk, HAWK_T(" ")) <= -1) EXIT_DEPARSE ();
|
||||
if (hawk_putsrcoochars (awk, kw.ptr, kw.len) <= -1) EXIT_DEPARSE ();
|
||||
if (hawk_putsrcoocstr (awk, HAWK_T(" ")) <= -1) EXIT_DEPARSE ();
|
||||
if (hawk_prnnde (awk, nde) <= -1) EXIT_DEPARSE ();
|
||||
|
||||
if (awk->opt.trait & HAWK_CRLF)
|
||||
@ -6835,8 +6895,8 @@ static int deparse (hawk_t* awk)
|
||||
|
||||
hawk_getkwname (awk, HAWK_KWID_END, &kw);
|
||||
|
||||
if (hawk_putsroocsn(awk, kw.ptr, kw.len) <= -1) EXIT_DEPARSE ();
|
||||
if (hawk_putsroocs(awk, HAWK_T(" ")) <= -1) EXIT_DEPARSE ();
|
||||
if (hawk_putsrcoochars(awk, kw.ptr, kw.len) <= -1) EXIT_DEPARSE ();
|
||||
if (hawk_putsrcoocstr(awk, HAWK_T(" ")) <= -1) EXIT_DEPARSE ();
|
||||
if (hawk_prnnde(awk, nde) <= -1) EXIT_DEPARSE ();
|
||||
|
||||
/*
|
||||
@ -6880,12 +6940,12 @@ static hawk_htb_walk_t deparse_func (hawk_htb_t* map, hawk_htb_pair_t* pair, voi
|
||||
}
|
||||
|
||||
#define PUT_S(x,str) \
|
||||
if (hawk_putsroocs(x->awk,str) <= -1) { \
|
||||
if (hawk_putsrcoocstr(x->awk,str) <= -1) { \
|
||||
x->ret = -1; return HAWK_HTB_WALK_STOP; \
|
||||
}
|
||||
|
||||
#define PUT_SX(x,str,len) \
|
||||
if (hawk_putsroocsn (x->awk, str, len) <= -1) { \
|
||||
if (hawk_putsrcoochars (x->awk, str, len) <= -1) { \
|
||||
x->ret = -1; return HAWK_HTB_WALK_STOP; \
|
||||
}
|
||||
|
||||
@ -6963,25 +7023,24 @@ static int flush_out (hawk_t* awk)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hawk_putsroocs (hawk_t* awk, const hawk_ooch_t* str)
|
||||
int hawk_putsrcoocstr (hawk_t* hawk, const hawk_ooch_t* str)
|
||||
{
|
||||
while (*str != HAWK_T('\0'))
|
||||
{
|
||||
if (put_char (awk, *str) <= -1) return -1;
|
||||
if (put_char(hawk, *str) <= -1) return -1;
|
||||
str++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hawk_putsroocsn (
|
||||
hawk_t* awk, const hawk_ooch_t* str, hawk_oow_t len)
|
||||
int hawk_putsrcoochars (hawk_t* hawk, const hawk_ooch_t* str, hawk_oow_t len)
|
||||
{
|
||||
const hawk_ooch_t* end = str + len;
|
||||
|
||||
while (str < end)
|
||||
{
|
||||
if (put_char (awk, *str) <= -1) return -1;
|
||||
if (put_char(hawk, *str) <= -1) return -1;
|
||||
str++;
|
||||
}
|
||||
|
||||
|
272
hawk/lib/std.c
272
hawk/lib/std.c
@ -159,15 +159,16 @@ typedef struct rxtn_t
|
||||
{
|
||||
struct
|
||||
{
|
||||
struct {
|
||||
const hawk_ooch_t** files;
|
||||
struct
|
||||
{
|
||||
hawk_ooch_t** files;
|
||||
hawk_oow_t index;
|
||||
hawk_oow_t count;
|
||||
} in;
|
||||
|
||||
struct
|
||||
{
|
||||
const hawk_ooch_t** files;
|
||||
hawk_ooch_t** files;
|
||||
hawk_oow_t index;
|
||||
hawk_oow_t count;
|
||||
} out;
|
||||
@ -974,28 +975,26 @@ static int open_parsestd (hawk_t* awk, hawk_sio_arg_t* arg, xtn_t* xtn, hawk_oow
|
||||
case HAWK_PARSESTD_FILEB:
|
||||
{
|
||||
hawk_sio_t* tmp;
|
||||
hawk_ooch_t* path = HAWK_NULL;
|
||||
|
||||
if (psin->u.fileb.path == HAWK_NULL || (psin->u.fileb.path[0] == '-' && psin->u.fileb.path[1] == '\0'))
|
||||
{
|
||||
/* no path name or - -> stdin */
|
||||
path = HAWK_NULL;
|
||||
tmp = open_sio_std(awk, HAWK_SIO_STDIN, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
hawk_uch_t* upath;
|
||||
upath = hawk_dupbtoucstr(awk, psin->u.fileb.path, HAWK_NULL, 1);
|
||||
if (!upath) return -1;
|
||||
tmp = open_sio(awk, upath, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH);
|
||||
hawk_freemem (awk, upath);
|
||||
#else
|
||||
tmp = open_sio(awk, psin->u.fileb.path, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH);
|
||||
#endif
|
||||
path = hawk_addsionamewithbchars(awk, psin->u.fileb.path, hawk_count_bcstr(psin->u.fileb.path));
|
||||
if (!path) return -1;
|
||||
tmp = open_sio(awk, path, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH);
|
||||
}
|
||||
if (tmp == HAWK_NULL) return -1;
|
||||
|
||||
if (index >= 1 && is_psin_file(&xtn->s.in.x[index - 1])) hawk_sio_close (arg->handle);
|
||||
|
||||
arg->handle = tmp;
|
||||
arg->path = path;
|
||||
if (psin->u.fileb.cmgr) hawk_sio_setcmgr (arg->handle, psin->u.fileb.cmgr);
|
||||
return 0;
|
||||
}
|
||||
@ -1008,29 +1007,26 @@ static int open_parsestd (hawk_t* awk, hawk_sio_arg_t* arg, xtn_t* xtn, hawk_oow
|
||||
case HAWK_PARSESTD_FILEU:
|
||||
{
|
||||
hawk_sio_t* tmp;
|
||||
hawk_ooch_t* path;
|
||||
|
||||
if (psin->u.fileu.path == HAWK_NULL || (psin->u.fileu.path[0] == '-' && psin->u.fileu.path[1] == '\0'))
|
||||
{
|
||||
/* no path name or - -> stdin */
|
||||
path = HAWK_NULL;
|
||||
tmp = open_sio_std(awk, HAWK_SIO_STDIN, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
tmp = open_sio(awk, psin->u.fileu.path, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH);
|
||||
#else
|
||||
hawk_bch_t* bpath;
|
||||
bpath = hawk_duputobcstr(awk, psin->u.fileu.path, HAWK_NULL);
|
||||
if (!bpath) return -1;
|
||||
tmp = open_sio(awk, bpath, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH);
|
||||
hawk_freemem (awk, bpath);
|
||||
#endif
|
||||
path = hawk_addsionamewithuchars(awk, psin->u.fileu.path, hawk_count_ucstr(psin->u.fileu.path));
|
||||
if (!path) return -1;
|
||||
tmp = open_sio(awk, path, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH);
|
||||
}
|
||||
if (tmp == HAWK_NULL) return -1;
|
||||
|
||||
if (index >= 1 && is_psin_file(&xtn->s.in.x[index - 1]))
|
||||
hawk_sio_close (arg->handle);
|
||||
if (index >= 1 && is_psin_file(&xtn->s.in.x[index - 1])) hawk_sio_close (arg->handle);
|
||||
|
||||
arg->handle = tmp;
|
||||
arg->path = path;
|
||||
if (psin->u.fileu.cmgr) hawk_sio_setcmgr (arg->handle, psin->u.fileu.cmgr);
|
||||
return 0;
|
||||
}
|
||||
@ -1105,41 +1101,31 @@ static hawk_ooi_t sf_in_open (hawk_t* awk, hawk_sio_arg_t* arg, xtn_t* xtn)
|
||||
{
|
||||
if (arg->prev == HAWK_NULL)
|
||||
{
|
||||
/* handle normal source input streams specified
|
||||
* to hawk_parsestd() */
|
||||
|
||||
/* handle top-level source input stream specified to hawk_parsestd() */
|
||||
hawk_ooi_t x;
|
||||
|
||||
HAWK_ASSERT (arg == &awk->sio.arg);
|
||||
|
||||
x = open_parsestd(awk, arg, xtn, 0);
|
||||
if (x >= 0)
|
||||
{
|
||||
xtn->s.in.xindex = 0; /* update the current stream index */
|
||||
/* perform some manipulation about the top-level input information */
|
||||
if (is_psin_file(&xtn->s.in.x[0]))
|
||||
{
|
||||
arg->name = hawk_sio_getpath(arg->handle);
|
||||
if (arg->name == HAWK_NULL) arg->name = sio_std_names[HAWK_SIO_STDIN].ptr;
|
||||
}
|
||||
else arg->name = HAWK_NULL;
|
||||
}
|
||||
if (x >= 0) xtn->s.in.xindex = 0; /* update the current stream index */
|
||||
|
||||
return x;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* handle the included source file - @include */
|
||||
hawk_ooch_t* xpath;
|
||||
|
||||
HAWK_ASSERT (arg->name != HAWK_NULL);
|
||||
|
||||
if (arg->prev->handle)
|
||||
{
|
||||
const hawk_ooch_t* outer;
|
||||
const hawk_ooch_t* path;
|
||||
hawk_ooch_t fbuf[64];
|
||||
hawk_ooch_t* dbuf = HAWK_NULL;
|
||||
|
||||
HAWK_ASSERT (arg->name != HAWK_NULL);
|
||||
|
||||
path = arg->name;
|
||||
if (arg->prev->handle)
|
||||
{
|
||||
const hawk_ooch_t* outer;
|
||||
|
||||
outer = hawk_sio_getpath(arg->prev->handle);
|
||||
if (outer)
|
||||
@ -1165,21 +1151,30 @@ static hawk_ooi_t sf_in_open (hawk_t* awk, hawk_sio_arg_t* arg, xtn_t* xtn)
|
||||
hawk_copy_oocstr_unlimited ((hawk_ooch_t*)path + tmplen, arg->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
arg->handle = hawk_sio_open(hawk_getgem(awk), 0, path, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH);
|
||||
|
||||
xpath = hawk_addsionamewithoochars(awk, path, hawk_count_oocstr(path));
|
||||
if (dbuf) hawk_freemem (awk, dbuf);
|
||||
}
|
||||
else
|
||||
{
|
||||
xpath = hawk_addsionamewithoochars(awk, arg->name, hawk_count_oocstr(arg->name));
|
||||
}
|
||||
if (!xpath) goto fail;
|
||||
|
||||
arg->handle = hawk_sio_open(hawk_getgem(awk), 0, xpath, HAWK_SIO_READ | HAWK_SIO_IGNOREECERR | HAWK_SIO_KEEPPATH);
|
||||
if (!arg->handle)
|
||||
{
|
||||
const hawk_ooch_t* bem = hawk_backuperrmsg(awk);
|
||||
const hawk_ooch_t* bem;
|
||||
fail:
|
||||
bem = hawk_backuperrmsg(awk);
|
||||
hawk_seterrbfmt (awk, HAWK_NULL, HAWK_EOPEN, "unable to open %js - %js", arg->name, bem);
|
||||
return -1;
|
||||
}
|
||||
|
||||
arg->path = xpath;
|
||||
/* TODO: use the system handle(file descriptor) instead of the path? */
|
||||
/*syshnd = hawk_sio_gethnd(arg->handle);*/
|
||||
fill_sio_arg_unique_id(awk, arg, path); /* ignore failure */
|
||||
fill_sio_arg_unique_id(awk, arg, xpath); /* ignore failure */
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1338,22 +1333,10 @@ static hawk_ooi_t sf_in_read (hawk_t* awk, hawk_sio_arg_t* arg, hawk_ooch_t* dat
|
||||
if (xtn->s.in.x[next].type != HAWK_PARSESTD_NULL)
|
||||
{
|
||||
/* open the next stream if available. */
|
||||
if (open_parsestd (awk, arg, xtn, next) <= -1) n = -1;
|
||||
if (open_parsestd(awk, arg, xtn, next) <= -1) n = -1;
|
||||
else
|
||||
{
|
||||
xtn->s.in.xindex = next; /* update the next to the current */
|
||||
|
||||
/* update the I/O object name */
|
||||
if (is_psin_file(&xtn->s.in.x[next]))
|
||||
{
|
||||
arg->name = hawk_sio_getpath(arg->handle);
|
||||
if (arg->name == HAWK_NULL) arg->name = sio_std_names[HAWK_SIO_STDIN].ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
arg->name = HAWK_NULL;
|
||||
}
|
||||
|
||||
arg->line = 0; /* reset the line number */
|
||||
arg->colm = 0;
|
||||
goto again;
|
||||
@ -2193,14 +2176,13 @@ static int open_rio_console (hawk_rtx_t* rtx, hawk_rio_arg_t* riod)
|
||||
}
|
||||
|
||||
sio = (file[0] == HAWK_T('-') && file[1] == HAWK_T('\0'))?
|
||||
open_sio_std_rtx (rtx, HAWK_SIO_STDOUT, HAWK_SIO_WRITE | HAWK_SIO_IGNOREECERR | HAWK_SIO_LINEBREAK):
|
||||
open_sio_rtx (rtx, file, HAWK_SIO_WRITE | HAWK_SIO_CREATE | HAWK_SIO_TRUNCATE | HAWK_SIO_IGNOREECERR);
|
||||
open_sio_std_rtx(rtx, HAWK_SIO_STDOUT, HAWK_SIO_WRITE | HAWK_SIO_IGNOREECERR | HAWK_SIO_LINEBREAK):
|
||||
open_sio_rtx(rtx, file, HAWK_SIO_WRITE | HAWK_SIO_CREATE | HAWK_SIO_TRUNCATE | HAWK_SIO_IGNOREECERR);
|
||||
if (sio == HAWK_NULL) return -1;
|
||||
|
||||
if (rxtn->c.cmgr) hawk_sio_setcmgr (sio, rxtn->c.cmgr);
|
||||
|
||||
if (hawk_rtx_setofilename (
|
||||
rtx, file, hawk_count_oocstr(file)) <= -1)
|
||||
if (hawk_rtx_setofilename(rtx, file, hawk_count_oocstr(file)) <= -1)
|
||||
{
|
||||
hawk_sio_close (sio);
|
||||
return -1;
|
||||
@ -2290,6 +2272,26 @@ static void fini_rxtn (hawk_rtx_t* rtx)
|
||||
rxtn_t* rxtn = GET_RXTN(rtx);
|
||||
/*xtn_t* xtn = (xtn_t*)GET_XTN(rtx->awk);*/
|
||||
|
||||
if (rxtn->c.in.files)
|
||||
{
|
||||
hawk_oow_t i;
|
||||
for (i = 0; rxtn->c.in.files[i]; i++) hawk_rtx_freemem(rtx, rxtn->c.in.files[i]);
|
||||
hawk_rtx_freemem (rtx, rxtn->c.in.files);
|
||||
rxtn->c.in.files = HAWK_NULL;
|
||||
rxtn->c.in.count = 0;
|
||||
rxtn->c.in.index = 0;
|
||||
}
|
||||
|
||||
if (rxtn->c.out.files)
|
||||
{
|
||||
hawk_oow_t i;
|
||||
for (i = 0; rxtn->c.out.files[i]; i++) hawk_rtx_freemem(rtx, rxtn->c.out.files[i]);
|
||||
hawk_rtx_freemem (rtx, rxtn->c.out.files);
|
||||
rxtn->c.out.files = HAWK_NULL;
|
||||
rxtn->c.out.count = 0;
|
||||
rxtn->c.out.index = 0;
|
||||
}
|
||||
|
||||
if (rxtn->cmgrtab_inited)
|
||||
{
|
||||
hawk_htb_fini (&rxtn->cmgrtab);
|
||||
@ -2297,11 +2299,9 @@ static void fini_rxtn (hawk_rtx_t* rtx)
|
||||
}
|
||||
}
|
||||
|
||||
static int build_argcv (
|
||||
hawk_rtx_t* rtx, int argc_id, int argv_id,
|
||||
const hawk_ooch_t* id, const hawk_ooch_t*const icf[])
|
||||
static int build_argcv (hawk_rtx_t* rtx, int argc_id, int argv_id, const hawk_ooch_t* id, hawk_ooch_t* icf[])
|
||||
{
|
||||
const hawk_ooch_t*const* p;
|
||||
hawk_ooch_t** p;
|
||||
hawk_oow_t argc;
|
||||
hawk_val_t* v_argc;
|
||||
hawk_val_t* v_argv;
|
||||
@ -2531,7 +2531,7 @@ static int build_environ (hawk_rtx_t* rtx, int gbl_id, env_char_t* envarr[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int make_additional_globals (hawk_rtx_t* rtx, xtn_t* xtn, const hawk_ooch_t* id, const hawk_ooch_t*const icf[])
|
||||
static int make_additional_globals (hawk_rtx_t* rtx, xtn_t* xtn, const hawk_ooch_t* id, hawk_ooch_t* icf[])
|
||||
{
|
||||
if (build_argcv(rtx, xtn->gbl_argc, xtn->gbl_argv, id, icf) <= -1 ||
|
||||
build_environ(rtx, xtn->gbl_environ, environ) <= -1) return -1;
|
||||
@ -2542,8 +2542,8 @@ static hawk_rtx_t* open_rtx_std (
|
||||
hawk_t* awk,
|
||||
hawk_oow_t xtnsize,
|
||||
const hawk_ooch_t* id,
|
||||
const hawk_ooch_t* icf[],
|
||||
const hawk_ooch_t* ocf[],
|
||||
hawk_ooch_t* icf[],
|
||||
hawk_ooch_t* ocf[],
|
||||
hawk_cmgr_t* cmgr)
|
||||
{
|
||||
hawk_rtx_t* rtx;
|
||||
@ -2622,140 +2622,162 @@ hawk_rtx_t* hawk_rtx_openstdwithbcstr (
|
||||
hawk_t* awk,
|
||||
hawk_oow_t xtnsize,
|
||||
const hawk_bch_t* id,
|
||||
const hawk_bch_t* icf[],
|
||||
const hawk_bch_t* ocf[],
|
||||
hawk_bch_t* icf[],
|
||||
hawk_bch_t* ocf[],
|
||||
hawk_cmgr_t* cmgr)
|
||||
{
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
return open_rtx_std(awk, xtnsize, id, icf, ocf, cmgr);
|
||||
#else
|
||||
hawk_rtx_t* rtx = HAWK_NULL;
|
||||
hawk_oow_t wcslen, i;
|
||||
hawk_uch_t* wid = HAWK_NULL, ** wicf = HAWK_NULL, ** wocf = HAWK_NULL;
|
||||
hawk_ooch_t* xid, ** xicf = HAWK_NULL, ** xocf = HAWK_NULL;
|
||||
|
||||
wid = hawk_dupbtoucstr(awk, id, &wcslen, 0);
|
||||
if (!wid) return HAWK_NULL;
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
xid = hawk_dupbtoucstr(awk, id, &wcslen, 0);
|
||||
if (!xid) return HAWK_NULL;
|
||||
#else
|
||||
xid = (hawk_ooch_t*)id;
|
||||
#endif
|
||||
|
||||
if (icf)
|
||||
{
|
||||
for (i = 0; icf[i]; i++) ;
|
||||
|
||||
wicf = (hawk_uch_t**)hawk_callocmem(awk, HAWK_SIZEOF(*wicf) * (i + 1));
|
||||
if (!wicf) goto done;
|
||||
xicf = (hawk_ooch_t**)hawk_callocmem(awk, HAWK_SIZEOF(*xicf) * (i + 1));
|
||||
if (!xicf) goto done;
|
||||
|
||||
for (i = 0; icf[i]; i++)
|
||||
{
|
||||
wicf[i] = hawk_dupbtoucstr(awk, icf[i], &wcslen, 0);
|
||||
if (!wicf[i]) goto done;
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
xicf[i] = hawk_dupbtoucstr(awk, icf[i], &wcslen, 0);
|
||||
#else
|
||||
xicf[i] = hawk_dupbcstr(awk, icf[i], HAWK_NULL);
|
||||
#endif
|
||||
if (!xicf[i]) goto done;
|
||||
}
|
||||
wicf[i] = HAWK_NULL;
|
||||
xicf[i] = HAWK_NULL;
|
||||
}
|
||||
|
||||
if (ocf)
|
||||
{
|
||||
for (i = 0; ocf[i]; i++) ;
|
||||
|
||||
wocf = (hawk_uch_t**)hawk_callocmem(awk, HAWK_SIZEOF(*wocf) * (i + 1));
|
||||
if (!wocf) goto done;
|
||||
xocf = (hawk_ooch_t**)hawk_callocmem(awk, HAWK_SIZEOF(*xocf) * (i + 1));
|
||||
if (!xocf) goto done;
|
||||
|
||||
for (i = 0; ocf[i]; i++)
|
||||
{
|
||||
wocf[i] = hawk_dupbtoucstr(awk, ocf[i], &wcslen, 0);
|
||||
if (!wocf[i]) goto done;
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
xocf[i] = hawk_dupbtoucstr(awk, ocf[i], &wcslen, 0);
|
||||
#else
|
||||
xocf[i] = hawk_dupucstr(awk, ocf[i], HAWK_NULL);
|
||||
#endif
|
||||
if (!xocf[i]) goto done;
|
||||
}
|
||||
wocf[i] = HAWK_NULL;
|
||||
xocf[i] = HAWK_NULL;
|
||||
}
|
||||
|
||||
rtx = open_rtx_std(awk, xtnsize, wid, (const hawk_uch_t**)wicf, (const hawk_uch_t**)wocf, cmgr);
|
||||
rtx = open_rtx_std(awk, xtnsize, xid, xicf, xocf, cmgr);
|
||||
|
||||
done:
|
||||
if (!rtx)
|
||||
{
|
||||
if (wocf)
|
||||
if (xocf)
|
||||
{
|
||||
for (i = 0; wocf[i]; i++) hawk_freemem (awk, wocf[i]);
|
||||
hawk_freemem (awk, wocf);
|
||||
for (i = 0; xocf[i]; i++) hawk_freemem (awk, xocf[i]);
|
||||
hawk_freemem (awk, xocf);
|
||||
}
|
||||
if (wicf)
|
||||
if (xicf)
|
||||
{
|
||||
for (i = 0; wicf[i]; i++) hawk_freemem (awk, wicf[i]);
|
||||
hawk_freemem (awk, wicf);
|
||||
for (i = 0; xicf[i]; i++) hawk_freemem (awk, xicf[i]);
|
||||
hawk_freemem (awk, xicf);
|
||||
}
|
||||
}
|
||||
if (wid) hawk_freemem (awk, wid);
|
||||
|
||||
#if defined(HAWK_OOCH_IS_UCH)
|
||||
hawk_freemem (awk, xid);
|
||||
#endif
|
||||
|
||||
return rtx;
|
||||
#endif
|
||||
}
|
||||
|
||||
hawk_rtx_t* hawk_rtx_openstdwithucstr (
|
||||
hawk_t* awk,
|
||||
hawk_oow_t xtnsize,
|
||||
const hawk_uch_t* id,
|
||||
const hawk_uch_t* icf[],
|
||||
const hawk_uch_t* ocf[],
|
||||
hawk_uch_t* icf[],
|
||||
hawk_uch_t* ocf[],
|
||||
hawk_cmgr_t* cmgr)
|
||||
{
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
hawk_rtx_t* rtx = HAWK_NULL;
|
||||
hawk_oow_t mbslen, i;
|
||||
hawk_bch_t* mid = HAWK_NULL, ** micf = HAWK_NULL, ** mocf = HAWK_NULL;
|
||||
hawk_ooch_t* xid, ** xicf = HAWK_NULL, ** xocf = HAWK_NULL;
|
||||
|
||||
mid = hawk_duputobcstr(awk, id, &mbslen);
|
||||
if (!mid) return HAWK_NULL;
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
xid = hawk_duputobcstr(awk, id, &mbslen);
|
||||
if (!xid) return HAWK_NULL;
|
||||
#else
|
||||
xid = (hawk_ooch_t*)id;
|
||||
#endif
|
||||
|
||||
if (icf)
|
||||
{
|
||||
for (i = 0; icf[i]; i++) ;
|
||||
|
||||
micf = (hawk_bch_t**)hawk_callocmem(awk, HAWK_SIZEOF(*micf) * (i + 1));
|
||||
if (!micf) goto done;
|
||||
xicf = (hawk_ooch_t**)hawk_callocmem(awk, HAWK_SIZEOF(*xicf) * (i + 1));
|
||||
if (!xicf) goto done;
|
||||
|
||||
for (i = 0; icf[i]; i++)
|
||||
{
|
||||
micf[i] = hawk_duputobcstr(awk, icf[i], &mbslen);
|
||||
if (!micf[i]) goto done;
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
xicf[i] = hawk_duputobcstr(awk, icf[i], &mbslen);
|
||||
#else
|
||||
xicf[i] = hawk_dupucstr(awk, icf[i], HAWK_NULL);
|
||||
#endif
|
||||
if (!xicf[i]) goto done;
|
||||
}
|
||||
micf[i] = HAWK_NULL;
|
||||
xicf[i] = HAWK_NULL;
|
||||
}
|
||||
|
||||
if (ocf)
|
||||
{
|
||||
for (i = 0; ocf[i]; i++) ;
|
||||
|
||||
mocf = (hawk_uch_t**)hawk_callocmem(awk, HAWK_SIZEOF(*mocf) * (i + 1));
|
||||
if (!mocf) goto done;
|
||||
xocf = (hawk_ooch_t**)hawk_callocmem(awk, HAWK_SIZEOF(*xocf) * (i + 1));
|
||||
if (!xocf) goto done;
|
||||
|
||||
for (i = 0; ocf[i]; i++)
|
||||
{
|
||||
mocf[i] = hawk_dupbtoucstr(awk, ocf[i], &mbslen, 0);
|
||||
if (!mocf[i]) goto done;
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
xocf[i] = hawk_dupbtoucstr(awk, ocf[i], &mbslen, 0);
|
||||
#else
|
||||
xocf[i] = hawk_dupucstr(awk, ocf[i], HAWK_NULL);
|
||||
#endif
|
||||
if (!xocf[i]) goto done;
|
||||
}
|
||||
mocf[i] = HAWK_NULL;
|
||||
xocf[i] = HAWK_NULL;
|
||||
}
|
||||
|
||||
rtx = open_rtx_std(awk, xtnsize, mid, (const hawk_bch_t**)micf, (const hawk_bch_t**)mocf, cmgr);
|
||||
rtx = open_rtx_std(awk, xtnsize, xid, xicf, xocf, cmgr);
|
||||
|
||||
done:
|
||||
if (!rtx)
|
||||
{
|
||||
if (mocf)
|
||||
if (xocf)
|
||||
{
|
||||
for (i = 0; mocf[i]; i++) hawk_freemem (awk, mocf[i]);
|
||||
hawk_freemem (awk, mocf);
|
||||
for (i = 0; xocf[i]; i++) hawk_freemem (awk, xocf[i]);
|
||||
hawk_freemem (awk, xocf);
|
||||
}
|
||||
if (micf)
|
||||
if (xicf)
|
||||
{
|
||||
for (i = 0; micf[i]; i++) hawk_freemem (awk, micf[i]);
|
||||
hawk_freemem (awk, micf);
|
||||
for (i = 0; xicf[i]; i++) hawk_freemem (awk, xicf[i]);
|
||||
hawk_freemem (awk, xicf);
|
||||
}
|
||||
}
|
||||
if (mid) hawk_freemem (awk, mid);
|
||||
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
hawk_freemem (awk, xid);
|
||||
#endif
|
||||
|
||||
return rtx;
|
||||
#else
|
||||
return open_rtx_std(awk, xtnsize, id, icf, ocf, cmgr);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int timeout_code (const hawk_ooch_t* name)
|
||||
|
@ -114,7 +114,7 @@ static const hawk_ooch_t* print_outop_str[] =
|
||||
HAWK_T("")
|
||||
};
|
||||
|
||||
#define PUT_SRCSTR(awk,str) do { if (hawk_putsroocs (awk, str) == -1) return -1; } while(0)
|
||||
#define PUT_SRCSTR(awk,str) do { if (hawk_putsrcoocstr (awk, str) == -1) return -1; } while(0)
|
||||
|
||||
#define PUT_NL(awk) do { \
|
||||
if (awk->opt.trait & HAWK_CRLF) PUT_SRCSTR (awk, HAWK_T("\r")); \
|
||||
@ -122,7 +122,7 @@ static const hawk_ooch_t* print_outop_str[] =
|
||||
} while(0)
|
||||
|
||||
#define PUT_SRCSTRN(awk,str,len) do { \
|
||||
if (hawk_putsroocsn (awk, str, len) == -1) return -1; \
|
||||
if (hawk_putsrcoochars (awk, str, len) == -1) return -1; \
|
||||
} while(0)
|
||||
|
||||
#define PRINT_TABS(awk,depth) do { \
|
||||
|
@ -25,413 +25,35 @@
|
||||
*/
|
||||
|
||||
#include <hawk-utl.h>
|
||||
#include "hawk-prv.h"
|
||||
#include "utl-skad.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#if defined(HAVE_NETINET_IN_H)
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
#if defined(HAVE_SYS_UN_H)
|
||||
# include <sys/un.h>
|
||||
#endif
|
||||
#if defined(HAVE_NETPACKET_PACKET_H)
|
||||
# include <netpacket/packet.h>
|
||||
#endif
|
||||
#if defined(HAVE_NET_IF_DL_H)
|
||||
# include <net/if_dl.h>
|
||||
#endif
|
||||
|
||||
union hawk_skad_alt_t
|
||||
int hawk_skad_family (const hawk_skad_t* _skad)
|
||||
{
|
||||
struct sockaddr sa;
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN > 0)
|
||||
struct sockaddr_in in4;
|
||||
#endif
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
struct sockaddr_in6 in6;
|
||||
#endif
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_LL > 0)
|
||||
struct sockaddr_ll ll;
|
||||
#endif
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_UN > 0)
|
||||
struct sockaddr_un un;
|
||||
#endif
|
||||
};
|
||||
typedef union hawk_skad_alt_t hawk_skad_alt_t;
|
||||
|
||||
static int str_to_ipv4 (const hawk_ooch_t* str, hawk_oow_t len, struct in_addr* inaddr)
|
||||
{
|
||||
const hawk_ooch_t* end;
|
||||
int dots = 0, digits = 0;
|
||||
hawk_uint32_t acc = 0, addr = 0;
|
||||
hawk_ooch_t c;
|
||||
|
||||
end = str + len;
|
||||
|
||||
do
|
||||
{
|
||||
if (str >= end)
|
||||
{
|
||||
if (dots < 3 || digits == 0) return -1;
|
||||
addr = (addr << 8) | acc;
|
||||
break;
|
||||
}
|
||||
|
||||
c = *str++;
|
||||
|
||||
if (c >= '0' && c <= '9')
|
||||
{
|
||||
if (digits > 0 && acc == 0) return -1;
|
||||
acc = acc * 10 + (c - '0');
|
||||
if (acc > 255) return -1;
|
||||
digits++;
|
||||
}
|
||||
else if (c == '.')
|
||||
{
|
||||
if (dots >= 3 || digits == 0) return -1;
|
||||
addr = (addr << 8) | acc;
|
||||
dots++; acc = 0; digits = 0;
|
||||
}
|
||||
else return -1;
|
||||
}
|
||||
while (1);
|
||||
|
||||
inaddr->s_addr = hawk_hton32(addr);
|
||||
return 0;
|
||||
|
||||
const hawk_skad_alt_t* skad = (const hawk_skad_alt_t*)_skad;
|
||||
HAWK_ASSERT (HAWK_SIZEOF(*_skad) >= HAWK_SIZEOF(*skad));
|
||||
return skad->sa.sa_family;
|
||||
}
|
||||
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
static int str_to_ipv6 (const hawk_ooch_t* src, hawk_oow_t len, struct in6_addr* inaddr)
|
||||
int hawk_skad_size (const hawk_skad_t* _skad)
|
||||
{
|
||||
hawk_uint8_t* tp, * endp, * colonp;
|
||||
const hawk_ooch_t* curtok;
|
||||
hawk_ooch_t ch;
|
||||
int saw_xdigit;
|
||||
unsigned int val;
|
||||
const hawk_ooch_t* src_end;
|
||||
const hawk_skad_alt_t* skad = (const hawk_skad_alt_t*)_skad;
|
||||
HAWK_ASSERT (HAWK_SIZEOF(*_skad) >= HAWK_SIZEOF(*skad));
|
||||
|
||||
src_end = src + len;
|
||||
|
||||
HAWK_MEMSET (inaddr, 0, HAWK_SIZEOF(*inaddr));
|
||||
tp = &inaddr->s6_addr[0];
|
||||
endp = &inaddr->s6_addr[HAWK_COUNTOF(inaddr->s6_addr)];
|
||||
colonp = HAWK_NULL;
|
||||
|
||||
/* Leading :: requires some special handling. */
|
||||
if (src < src_end && *src == ':')
|
||||
switch (skad->sa.sa_family)
|
||||
{
|
||||
src++;
|
||||
if (src >= src_end || *src != ':') return -1;
|
||||
}
|
||||
|
||||
curtok = src;
|
||||
saw_xdigit = 0;
|
||||
val = 0;
|
||||
|
||||
while (src < src_end)
|
||||
{
|
||||
int v1;
|
||||
|
||||
ch = *src++;
|
||||
|
||||
if (ch >= '0' && ch <= '9')
|
||||
v1 = ch - '0';
|
||||
else if (ch >= 'A' && ch <= 'F')
|
||||
v1 = ch - 'A' + 10;
|
||||
else if (ch >= 'a' && ch <= 'f')
|
||||
v1 = ch - 'a' + 10;
|
||||
else v1 = -1;
|
||||
if (v1 >= 0)
|
||||
{
|
||||
val <<= 4;
|
||||
val |= v1;
|
||||
if (val > 0xffff) return -1;
|
||||
saw_xdigit = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ch == ':')
|
||||
{
|
||||
curtok = src;
|
||||
if (!saw_xdigit)
|
||||
{
|
||||
if (colonp) return -1;
|
||||
colonp = tp;
|
||||
continue;
|
||||
}
|
||||
else if (src >= src_end)
|
||||
{
|
||||
/* a colon can't be the last character */
|
||||
return -1;
|
||||
}
|
||||
|
||||
*tp++ = (hawk_uint8_t)(val >> 8) & 0xff;
|
||||
*tp++ = (hawk_uint8_t)val & 0xff;
|
||||
saw_xdigit = 0;
|
||||
val = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ch == '.' && ((tp + HAWK_SIZEOF(struct in_addr)) <= endp) &&
|
||||
str_to_ipv4(curtok, src_end - curtok, (struct in_addr*)tp) == 0)
|
||||
{
|
||||
tp += HAWK_SIZEOF(struct in_addr*);
|
||||
saw_xdigit = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (saw_xdigit)
|
||||
{
|
||||
if (tp + HAWK_SIZEOF(hawk_uint16_t) > endp) return -1;
|
||||
*tp++ = (hawk_uint8_t)(val >> 8) & 0xff;
|
||||
*tp++ = (hawk_uint8_t)val & 0xff;
|
||||
}
|
||||
if (colonp != HAWK_NULL)
|
||||
{
|
||||
/*
|
||||
* Since some memmove()'s erroneously fail to handle
|
||||
* overlapping regions, we'll do the shift by hand.
|
||||
*/
|
||||
hawk_oow_t n = tp - colonp;
|
||||
hawk_oow_t i;
|
||||
|
||||
for (i = 1; i <= n; i++)
|
||||
{
|
||||
endp[-i] = colonp[n - i];
|
||||
colonp[n - i] = 0;
|
||||
}
|
||||
tp = endp;
|
||||
}
|
||||
|
||||
if (tp != endp) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int hawk_gem_oochars_to_skad (hawk_gem_t* gem, const hawk_ooch_t* str, hawk_oow_t len, hawk_skad_t* _skad)
|
||||
{
|
||||
hawk_skad_alt_t* skad = (hawk_skad_alt_t*)_skad;
|
||||
const hawk_ooch_t* p;
|
||||
const hawk_ooch_t* end;
|
||||
hawk_oocs_t tmp;
|
||||
|
||||
p = str;
|
||||
end = str + len;
|
||||
|
||||
if (p >= end)
|
||||
{
|
||||
hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "blank address");
|
||||
return -1;
|
||||
}
|
||||
|
||||
HAWK_MEMSET (skad, 0, HAWK_SIZEOF(*skad));
|
||||
|
||||
#if defined(AF_UNIX)
|
||||
if (*p == '/' && len >= 2)
|
||||
{
|
||||
#if defined(HAWK_OOCH_IS_BCH)
|
||||
hawk_copy_bcstr (skad->un.sun_path, HAWK_COUNTOF(skad->un.sun_path), str);
|
||||
#else
|
||||
hawk_oow_t dstlen;
|
||||
dstlen = HAWK_COUNTOF(skad->un.sun_path) - 1;
|
||||
if (hawk_gem_convutobchars(gem, p, &len, skad->un.sun_path, &dstlen) <= -1) return -1;
|
||||
skad->un.sun_path[dstlen] = '\0';
|
||||
#if defined(AF_INET) && (HAWK_SIZEOF_STRUCT_SOCKADDR_IN > 0)
|
||||
case AF_INET: return HAWK_SIZEOF(struct sockaddr_in);
|
||||
#endif
|
||||
skad->un.sun_family = AF_UNIX;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
if (*p == '[')
|
||||
{
|
||||
/* IPv6 address */
|
||||
tmp.ptr = (hawk_ooch_t*)++p; /* skip [ and remember the position */
|
||||
while (p < end && *p != '%' && *p != ']') p++;
|
||||
|
||||
if (p >= end) goto no_rbrack;
|
||||
|
||||
tmp.len = p - tmp.ptr;
|
||||
if (*p == '%')
|
||||
{
|
||||
/* handle scope id */
|
||||
hawk_uint32_t x;
|
||||
|
||||
p++; /* skip % */
|
||||
|
||||
if (p >= end)
|
||||
{
|
||||
/* premature end */
|
||||
hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "scope id blank");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (*p >= '0' && *p <= '9')
|
||||
{
|
||||
/* numeric scope id */
|
||||
skad->in6.sin6_scope_id = 0;
|
||||
do
|
||||
{
|
||||
x = skad->in6.sin6_scope_id * 10 + (*p - '0');
|
||||
if (x < skad->in6.sin6_scope_id)
|
||||
{
|
||||
hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "scope id too large");
|
||||
return -1; /* overflow */
|
||||
}
|
||||
skad->in6.sin6_scope_id = x;
|
||||
p++;
|
||||
}
|
||||
while (p < end && *p >= '0' && *p <= '9');
|
||||
}
|
||||
else
|
||||
{
|
||||
#if 0
|
||||
TODO:
|
||||
/* interface name as a scope id? */
|
||||
const hawk_ooch_t* stmp = p;
|
||||
unsigned int index;
|
||||
do p++; while (p < end && *p != ']');
|
||||
if (hawk_nwifwcsntoindex(stmp, p - stmp, &index) <= -1) return -1;
|
||||
tmpad.u.in6.scope = index;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (p >= end || *p != ']') goto no_rbrack;
|
||||
}
|
||||
p++; /* skip ] */
|
||||
|
||||
if (str_to_ipv6(tmp.ptr, tmp.len, &skad->in6.sin6_addr) <= -1) goto unrecog;
|
||||
skad->in6.sin6_family = AF_INET6;
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif
|
||||
/* IPv4 address */
|
||||
tmp.ptr = (hawk_ooch_t*)p;
|
||||
while (p < end && *p != ':') p++;
|
||||
tmp.len = p - tmp.ptr;
|
||||
|
||||
if (str_to_ipv4(tmp.ptr, tmp.len, &skad->in4.sin_addr) <= -1)
|
||||
{
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
/* check if it is an IPv6 address not enclosed in [].
|
||||
* the port number can't be specified in this format. */
|
||||
if (p >= end || *p != ':')
|
||||
{
|
||||
/* without :, it can't be an ipv6 address */
|
||||
goto unrecog;
|
||||
}
|
||||
|
||||
|
||||
while (p < end && *p != '%') p++;
|
||||
tmp.len = p - tmp.ptr;
|
||||
|
||||
if (str_to_ipv6(tmp.ptr, tmp.len, &skad->in6.sin6_addr) <= -1) goto unrecog;
|
||||
|
||||
if (p < end && *p == '%')
|
||||
{
|
||||
/* handle scope id */
|
||||
hawk_uint32_t x;
|
||||
|
||||
p++; /* skip % */
|
||||
|
||||
if (p >= end)
|
||||
{
|
||||
/* premature end */
|
||||
hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "scope id blank");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (*p >= '0' && *p <= '9')
|
||||
{
|
||||
/* numeric scope id */
|
||||
skad->in6.sin6_scope_id = 0;
|
||||
do
|
||||
{
|
||||
x = skad->in6.sin6_scope_id * 10 + (*p - '0');
|
||||
if (x < skad->in6.sin6_scope_id)
|
||||
{
|
||||
hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "scope id too large");
|
||||
return -1; /* overflow */
|
||||
}
|
||||
skad->in6.sin6_scope_id = x;
|
||||
p++;
|
||||
}
|
||||
while (p < end && *p >= '0' && *p <= '9');
|
||||
}
|
||||
else
|
||||
{
|
||||
#if 0
|
||||
TODO
|
||||
/* interface name as a scope id? */
|
||||
const hawk_ooch_t* stmp = p;
|
||||
unsigned int index;
|
||||
do p++; while (p < end);
|
||||
if (hawk_nwifwcsntoindex (stmp, p - stmp, &index) <= -1) return -1;
|
||||
skad->in6.sin6_scope_id = index;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (p < end) goto unrecog; /* some gargage after the end? */
|
||||
|
||||
skad->in6.sin6_family = AF_INET6;
|
||||
return 0;
|
||||
#else
|
||||
goto unrecog;
|
||||
#if defined(AF_INET6) && (HAWK_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
case AF_INET6: return HAWK_SIZEOF(struct sockaddr_in6);
|
||||
#endif
|
||||
}
|
||||
|
||||
skad->in4.sin_family = AF_INET;
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (p < end && *p == ':')
|
||||
{
|
||||
/* port number */
|
||||
hawk_uint32_t port = 0;
|
||||
|
||||
p++; /* skip : */
|
||||
|
||||
tmp.ptr = (hawk_ooch_t*)p;
|
||||
while (p < end && *p >= '0' && *p <= '9')
|
||||
{
|
||||
port = port * 10 + (*p - '0');
|
||||
p++;
|
||||
}
|
||||
|
||||
tmp.len = p - tmp.ptr;
|
||||
if (tmp.len <= 0 || tmp.len >= 6 ||
|
||||
port > HAWK_TYPE_MAX(hawk_uint16_t))
|
||||
{
|
||||
hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "port number blank or too large");
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
if (skad->in4.sin_family == AF_INET)
|
||||
skad->in4.sin_port = hawk_hton16(port);
|
||||
else
|
||||
skad->in6.sin6_port = hawk_hton16(port);
|
||||
#else
|
||||
skad->in4.sin_port = hawk_hton16(port);
|
||||
#if defined(AF_PACKET) && (HAWK_SIZEOF_STRUCT_SOCKADDR_LL > 0)
|
||||
case AF_PACKET: return HAWK_SIZEOF(struct sockaddr_ll);
|
||||
#endif
|
||||
#if defined(AF_UNIX) && (HAWK_SIZEOF_STRUCT_SOCKADDR_UN > 0)
|
||||
case AF_UNIX: return HAWK_SIZEOF(struct sockaddr_un);
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
unrecog:
|
||||
hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "unrecognized address");
|
||||
return -1;
|
||||
|
||||
no_rbrack:
|
||||
hawk_gem_seterrbfmt (gem, HAWK_NULL, HAWK_EINVAL, "missing right bracket");
|
||||
return -1;
|
||||
}
|
||||
|
64
hawk/lib/utl-skad.h
Normal file
64
hawk/lib/utl-skad.h
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _HAWK_UTL_SKAD_H_
|
||||
#define _HAWK_UTL_SKAD_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#if defined(HAVE_NETINET_IN_H)
|
||||
# include <netinet/in.h>
|
||||
#endif
|
||||
#if defined(HAVE_SYS_UN_H)
|
||||
# include <sys/un.h>
|
||||
#endif
|
||||
#if defined(HAVE_NETPACKET_PACKET_H)
|
||||
# include <netpacket/packet.h>
|
||||
#endif
|
||||
#if defined(HAVE_NET_IF_DL_H)
|
||||
# include <net/if_dl.h>
|
||||
#endif
|
||||
|
||||
union hawk_skad_alt_t
|
||||
{
|
||||
struct sockaddr sa;
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN > 0)
|
||||
struct sockaddr_in in4;
|
||||
#endif
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_IN6 > 0)
|
||||
struct sockaddr_in6 in6;
|
||||
#endif
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_LL > 0)
|
||||
struct sockaddr_ll ll;
|
||||
#endif
|
||||
#if (HAWK_SIZEOF_STRUCT_SOCKADDR_UN > 0)
|
||||
struct sockaddr_un un;
|
||||
#endif
|
||||
};
|
||||
typedef union hawk_skad_alt_t hawk_skad_alt_t;
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user