#ifndef NETLIB_H_LOADED #define NETLIB_H_LOADED /* ** NETLIB.H ** ** Main #include file for NETLIB. ** ** ** Copyright (c) 2008, Matthew Madison. ** ** All rights reserved. ** ** Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions ** are met: ** ** * Redistributions of source code must retain the above ** copyright notice, this list of conditions and the following ** disclaimer. ** * 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. ** * Neither the name of the copyright owner nor the names of any ** other contributors may be used to endorse or promote products ** derived from this software without specific prior written ** permission. ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "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 COPYRIGHT ** OWNER OR CONTRIBUTORS 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. ** ** MODIFICATION HISTORY: ** ** 29-Sep-1993 Madison Initial commenting. ** 31-May-1997 Madison Fix queue access. ** 07-Nov-2004 Madison IA64 support. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef __DECC #include #else #pragma builtins #endif #ifndef __NETLIB_BUILD__ #define __NETLIB_BUILD__ #endif #include "netlibdef.h" #if defined(__ALPHA) || defined(__ia64__) #pragma member_alignment save #pragma nomember_alignment #endif typedef struct { void *head, *tail; } QUEUE; typedef struct { unsigned int long1, long2; } TIME; typedef struct dsc$descriptor DESCRIP; typedef struct { unsigned short bufsiz, itmcod; void *bufadr, *retlen; } ITMLST; #if defined(__ALPHA) || defined(__ia64__) #pragma member_alignment restore #endif /* ** Handy macros */ #define OK(s) $VMS_STATUS_SUCCESS(s) #define INIT_DYNDSCPTR(str) {str->dsc$w_length = 0; str->dsc$a_pointer = (void *) 0;\ str->dsc$b_class = DSC$K_CLASS_D; str->dsc$b_dtype = DSC$K_DTYPE_T;} #define INIT_DYNDESC(str) {str.dsc$w_length = 0; str.dsc$a_pointer = (void *) 0;\ str.dsc$b_class = DSC$K_CLASS_D; str.dsc$b_dtype = DSC$K_DTYPE_T;} #define INIT_SDESC(str,len,ptr) {str.dsc$w_length=(len);str.dsc$a_pointer=(void *)(ptr);\ str.dsc$b_class=DSC$K_CLASS_S; str.dsc$b_dtype=DSC$K_DTYPE_T;} #define ITMLST_INIT(itm,c,s,a,r) {itm.bufsiz=(s); itm.itmcod=(c);\ itm.bufadr=(a); itm.retlen=(r);} #define INIT_QUEUE(que) {que.head = que.tail = &que;} #define SETARGCOUNT(x) va_count(x) #define VERIFY_CTX(x,c) {if ((x) == 0) return SS$_BADPARAM; c = *x;} #define GET_IOR(x, _ctx, _iosb, _astadr, _astprm) {unsigned int status;\ status = netlib___alloc_ior(&x);\ if (!OK(status)) return status; (x)->ctx = (_ctx);\ (x)->iosbp=(_iosb); (x)->astadr=(_astadr); (x)->astprm=(_astprm);} #define FREE_IOR(x) netlib___free_ior(x); #define GET_DNSREQ(x, _ctx, _iosb, _astadr, _astprm) {unsigned int status;\ status = netlib___alloc_dnsreq(&x);\ if (!OK(status)) return status;\ status = netlib___alloc_ior(&((x)->ior));\ if (!OK(status)) {netlib___free_dnsreq(x); return status;}\ (x)->ior->ctx = (_ctx);\ (x)->ior->iosbp=(_iosb); (x)->ior->astadr=(_astadr);\ (x)->ior->astprm=(_astprm);} #define FREE_DNSREQ(x) {netlib___free_ior(((x)->ior));netlib___free_dnsreq(x);} #if defined(__ALPHA) || defined(__ia64__) #define queue_insert(item,pred) __PAL_INSQUEL((void *)(pred),(void *)(item)) #define queue_remove(entry,addr) (__PAL_REMQUEL((void *)(entry),(void *)(addr)) >= 0) #else #define queue_insert(item,pred) _INSQUE(item,pred) #define queue_remove(entry,addr) (_REMQUE(entry,addr) != 2) #endif /* ** Generic context structure */ #ifndef __SPECCTX #define __SPECCTX void #endif struct NAMESERVER { struct NAMESERVER *flink, *blink; struct INADDRDEF addr; }; struct DOMAIN { struct DOMAIN *flink, *blink; int length; char name[1]; }; struct DNSCTX { QUEUE nsq; QUEUE domq; TIME timeout; int retry_count; unsigned int flags; unsigned short queryid; }; #define CTX_S_LINEBUF 32768 struct CTX { struct CTX *flink, *blink; TIME exptime; unsigned int flags; #define CTX_M_USER_SET_REUSEADDR (1<<0) #define CTX_M_LINE_FOUND_CR (1<<1) #define CTX_M_NO_DNS (1<<2) unsigned short chan; __SPECCTX *specctx; unsigned int specctx_size; unsigned char *linebuf, *linebufp, *lineanchor; struct dsc$descriptor *line_dsc; unsigned short *line_retlen; unsigned int line_flags; int line_remain; TIME *line_tmo; unsigned char *wlinebuf; int wlinesize; struct DNSCTX *dnsctx; }; #define SPECIOR_SPACE 64 #ifndef __SPECIOR #define __SPECIOR void * #endif #pragma nostandard struct IOR { struct IOR *flink, *blink; struct NETLIBIOSBDEF iosb; TIME timeout; struct CTX *ctx; struct NETLIBIOSBDEF *iosbp; unsigned int iorflags; #define IOR_M_IO_COMPLETED (1<<0) #define IOR_M_IO_TIMED (1<<1) #define IOR_M_IO_TIMEOUT (1<<2) void (*astadr)(); void *astprm; union { void *address; unsigned int longword; unsigned short word; } arg[8]; variant_union { unsigned char specior_space[SPECIOR_SPACE]; __SPECIOR specior; } specior_overlay; }; #pragma standard struct DNSREQ { struct DNSREQ *flink, *blink; struct IOR *ior; struct CTX *ctx; struct NAMESERVER *curns; struct DOMAIN *curdom; char *query_name; unsigned short query_namlen; unsigned int query_flags; unsigned char *query_rbuf; unsigned int query_rbufsize; unsigned int query_class; unsigned int query_type; unsigned int buflen, replylen; int retries; struct SINDEF sin; struct SINDEF rsin; unsigned char buf[1024]; }; #ifndef __NETLIB_MODULE_MEM__ #pragma nostandard globalref unsigned int netlib_synch_efn; globalref unsigned int netlib_asynch_efn; #pragma standard unsigned int netlib___alloc_ctx(struct CTX **, unsigned int); unsigned int netlib___free_ctx(struct CTX *); unsigned int netlib___alloc_ior(struct IOR **); unsigned int netlib___free_ior(struct IOR *); unsigned int netlib___alloc_dnsreq(struct DNSREQ **); unsigned int netlib___free_dnsreq(struct DNSREQ *); #endif #endif /* NETLIB_H_LOADED */