firedns/0000755000175000017500000000000010514662051011226 5ustar useruserfiredns/firemake.noinstall0000644000175000017500000000002110013014330014710 0ustar userusertester benchmark firedns/configure0000755000175000017500000000521210023637416013137 0ustar useruser#!/bin/sh #configure - FireMake configuratin script #Copyright (C) 2002 Ian Gulliver # #This program is free software; you can redistribute it and/or modify #it under the terms of version 2 of the GNU General Public License as #published by the Free Software Foundation. # #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. # #You should have received a copy of the GNU General Public License #along with this program; if not, write to the Free Software #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA VERSION="1.9.9" ECHO=echo if test -f /usr/ucb/echo; then ECHO=/usr/ucb/echo fi disp() { if test ! "$LASTN" = "1"; then $ECHO -n "$PREPEND" 1>&2 fi LASTN="0" $ECHO "$1" 1>&2 } dispn() { if test ! "$LASTN" = "1"; then $ECHO -n "$PREPEND" 1>&2 fi LASTN="1" $ECHO -n "$1" 1>&2 } module() { test -f firemake/$1 } PHASES="library init config header makefile" disp "FireMake v$VERSION starting...."; disp disp "= Starting dependency check =" for MODULE in `ls firemake`; do REQ=`grep "^#require " firemake/$MODULE 2>/dev/null | cut -d ' ' -f 2`; if test "$?" = "0"; then # module has requirements, check that these modules exist for FILE in $REQ; do if test ! -f firemake/$FILE; then disp " Module $MODULE requires module $FILE which is not present; aborting" exit 1; fi done fi done disp "= Done with dependency check =" disp for PHASE in $PHASES; do disp "= Starting $PHASE phase =" case "$PHASE" in init) exec > /dev/null ;; config) exec > /dev/null ;; header) exec > firemake.h ;; makefile) exec > Makefile ;; esac NEWDATA="1" while test "$NEWDATA" = "1"; do NEWDATA="0" for MODULE in `ls firemake`; do $ECHO "$DID " | grep " ${PHASE}_${MODULE} " > /dev/null if test ! "$?" = "0"; then grep "^#phase $PHASE" firemake/$MODULE > /dev/null 2>/dev/null if test "$?" = "0"; then SAT="1" DEPS=`grep "^#after ${PHASE}_" firemake/$MODULE | cut -d ' ' -f 2`; if test "$?" = "0"; then #runtime dependencies for DEP in $DEPS; do $ECHO "$DID " | grep " ${DEP} " > /dev/null if test ! "$?" = "0"; then SAT="0" fi done fi if test "$SAT" = "1"; then # dependencies satisfied PREPEND=" " . firemake/$MODULE unset PREPEND DID="$DID ${PHASE}_${MODULE}" NEWDATA="1" fi fi fi done done disp "= Done with $PHASE phase =" disp done disp "Finished configuring. Now just run \"make\"" firedns/fdnsmxlist.c0000644000175000017500000000072510013014330013552 0ustar useruser#include #include #include "firedns.h" int main(int argc, char **argv) { struct firedns_mxlist *iter; if (argc != 2) { fprintf(stderr,"usage: %s \n",argv[0]); return 2; } iter = firedns_resolvemxlist(argv[1]); if (iter == NULL) return 1; while (iter != NULL) { printf("%7s (%05d) %s:%d\n",firedns_mx_name[iter->protocol],iter->priority,iter->name,firedns_mx_port[iter->protocol]); iter = iter->next; } return 0; } firedns/firestring/0000755000175000017500000000000010023641030013367 5ustar useruserfiredns/firestring/firemake.noinstall0000644000175000017500000000000707505674730017124 0ustar userusertester firedns/firestring/configure0000755000175000017500000000521210023637416015313 0ustar useruser#!/bin/sh #configure - FireMake configuratin script #Copyright (C) 2002 Ian Gulliver # #This program is free software; you can redistribute it and/or modify #it under the terms of version 2 of the GNU General Public License as #published by the Free Software Foundation. # #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. # #You should have received a copy of the GNU General Public License #along with this program; if not, write to the Free Software #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA VERSION="1.9.9" ECHO=echo if test -f /usr/ucb/echo; then ECHO=/usr/ucb/echo fi disp() { if test ! "$LASTN" = "1"; then $ECHO -n "$PREPEND" 1>&2 fi LASTN="0" $ECHO "$1" 1>&2 } dispn() { if test ! "$LASTN" = "1"; then $ECHO -n "$PREPEND" 1>&2 fi LASTN="1" $ECHO -n "$1" 1>&2 } module() { test -f firemake/$1 } PHASES="library init config header makefile" disp "FireMake v$VERSION starting...."; disp disp "= Starting dependency check =" for MODULE in `ls firemake`; do REQ=`grep "^#require " firemake/$MODULE 2>/dev/null | cut -d ' ' -f 2`; if test "$?" = "0"; then # module has requirements, check that these modules exist for FILE in $REQ; do if test ! -f firemake/$FILE; then disp " Module $MODULE requires module $FILE which is not present; aborting" exit 1; fi done fi done disp "= Done with dependency check =" disp for PHASE in $PHASES; do disp "= Starting $PHASE phase =" case "$PHASE" in init) exec > /dev/null ;; config) exec > /dev/null ;; header) exec > firemake.h ;; makefile) exec > Makefile ;; esac NEWDATA="1" while test "$NEWDATA" = "1"; do NEWDATA="0" for MODULE in `ls firemake`; do $ECHO "$DID " | grep " ${PHASE}_${MODULE} " > /dev/null if test ! "$?" = "0"; then grep "^#phase $PHASE" firemake/$MODULE > /dev/null 2>/dev/null if test "$?" = "0"; then SAT="1" DEPS=`grep "^#after ${PHASE}_" firemake/$MODULE | cut -d ' ' -f 2`; if test "$?" = "0"; then #runtime dependencies for DEP in $DEPS; do $ECHO "$DID " | grep " ${DEP} " > /dev/null if test ! "$?" = "0"; then SAT="0" fi done fi if test "$SAT" = "1"; then # dependencies satisfied PREPEND=" " . firemake/$MODULE unset PREPEND DID="$DID ${PHASE}_${MODULE}" NEWDATA="1" fi fi fi done done disp "= Done with $PHASE phase =" disp done disp "Finished configuring. Now just run \"make\"" firedns/firestring/firemake.version0000644000175000017500000000000710023637416016573 0ustar useruser0.9.12 firedns/firestring/firemake.libraries0000644000175000017500000000003407505674730017075 0ustar useruserlibfirestring: firestring.o firedns/firestring/tester.c0000644000175000017500000002720410023637416015063 0ustar useruser#include #include #include #include #include #include #include "firemake.h" #include "firestring.h" void error_handler() { fprintf(stderr,"Error handler functions properly\n"); } int main() { char buffer[1024]; long long i = 1024; struct firestring_estr_t out, in; struct firestring_conf_t *value; int f; firestring_estr_alloc(&out,1000); firestring_estr_alloc(&in,200); firestring_estr_sprintf(&out,"-5551212: '%d'\n",-5551212); write(1,out.s,out.l); firestring_snprintf(buffer,1024,"8675309: '%d'\n",8675309); printf("%s",buffer); firestring_snprintf(buffer,1024,"-5551212: '%d'\n",-5551212); printf("%s",buffer); firestring_snprintf(buffer,1024,"3: '%d'\n",3); printf("%s",buffer); firestring_snprintf(buffer,1024,"0: '%d'\n",0); printf("%s",buffer); firestring_snprintf(buffer,1024,"%%3d (3): '%3d'\n",3); printf("%s",buffer); firestring_snprintf(buffer,1024,"%%3d (0): '%3d'\n",0); printf("%s",buffer); firestring_snprintf(buffer,1024,"5.9382: '%f'\n",5.9382); printf("%s",buffer); firestring_snprintf(buffer,1024,"-5.9382: '%f'\n",-5.9382); printf("%s",buffer); firestring_snprintf(buffer,1024,"%%10f (-5.9382): '%10f'\n",-5.9382); printf("%s",buffer); firestring_snprintf(buffer,1024,"%%010f (-5.9382): '%010f'\n",-5.9382); printf("%s",buffer); firestring_snprintf(buffer,1024,"%%4f (-5.9382): '%4f'\n",-5.9382); printf("%s",buffer); firestring_snprintf(buffer,1024,"%%4f (5.9382): '%4f'\n",5.9382); printf("%s",buffer); firestring_snprintf(buffer,1024,"38: '%d'\n",38); printf("%s",buffer); firestring_snprintf(buffer,1024,"%%03d (1): '%03d'\n",1); printf("%s",buffer); firestring_snprintf(buffer,1024,"%%050d (-123456): '%050d'\n",-123456); printf("%s",buffer); firestring_snprintf(buffer,1024,"%%010d (-123456): '%010d'\n",-123456); printf("%s",buffer); firestring_snprintf(buffer,1024,"%%50d (-123456): '%50d'\n",-123456); printf("%s",buffer); firestring_snprintf(buffer,1024,"%%s %%d %%s %%d %%s %%s: %s %d %s %d %s %s\n","foo",2002,"bar",38,"fluffernutter","humbug"); printf("%s",buffer); firestring_snprintf(buffer,1024,"the cow says moo: '%s'\n","the cow says moo"); printf("%s",buffer); firestring_snprintf(buffer,1024,"(null): '%s'\n",NULL); printf("%s",buffer); firestring_snprintf(buffer,1024,"long long bah: %g %s\n",i,"bah"); printf("%s",buffer); firestring_snprintf(buffer,5,"%d",1234); printf("5,1234: '%s'\n",buffer); firestring_snprintf(buffer,5,"%d",12345); printf("5,12345: '%s'\n",buffer); firestring_snprintf(buffer,6,"%s","foobar"); printf("6,foobar: '%s'\n",buffer); firestring_snprintf(buffer,7,"%s","foobar"); printf("7,foobar: '%s'\n",buffer); printf("'aardvark'/'zebra': %d\n",firestring_strcasecmp("aardvark","zebra")); printf("'zebra'/'aardvark': %d\n",firestring_strcasecmp("zebra","aardvark")); printf("'zebra'/'zebra': %d\n",firestring_strcasecmp("zebra","zebra")); printf("'zebra'/'zebra1': %d\n",firestring_strcasecmp("zebra","zebra1")); printf("'zebra1'/'zebra': %d\n",firestring_strcasecmp("zebra1","zebra")); printf("'zebra1'/'zebra' [5]: %d\n",firestring_strncasecmp("zebra1","zebra",5)); printf("'zebra1'/'zebra' [6]: %d\n",firestring_strncasecmp("zebra1","zebra",6)); printf("'zebra'/'zebra1' [6]: %d\n",firestring_strncasecmp("zebra","zebra1",6)); firestring_estr_strcpy(&in,"zebra"); firestring_estr_strcpy(&out,"zebra"); printf("'zebra' (e) in 'zebra': %ld\n",firestring_estr_estrstr(&in,&out,0)); firestring_estr_strcpy(&in,"ZeBrA"); firestring_estr_strcpy(&out,"zebra"); printf("'zebra' (e) in 'ZeBrA': %ld\n",firestring_estr_estrstr(&in,&out,0)); firestring_estr_strcpy(&in,"virus.exe"); firestring_estr_strcpy(&out,".exe"); printf("'.exe' (e) in 'virus.exe': %ld\n",firestring_estr_estrstr(&in,&out,0)); firestring_estr_strcpy(&in,"virus.exe.scr"); firestring_estr_strcpy(&out,".exe"); printf("'.exe' (e) in 'virus.exe.scr': %ld\n",firestring_estr_estrstr(&in,&out,0)); firestring_estr_strcpy(&in,"zebra"); firestring_estr_strcpy(&out,"zebra"); printf("'zebra' (ei) in 'zebra': %ld\n",firestring_estr_estristr(&in,&out,0)); firestring_estr_strcpy(&in,"ZeBrA"); firestring_estr_strcpy(&out,"zebra"); printf("'zebra' (ei) in 'ZeBrA': %ld\n",firestring_estr_estristr(&in,&out,0)); firestring_estr_strcpy(&in,"virus.exe"); firestring_estr_strcpy(&out,".exe"); printf("'.exe' (ei) in 'virus.exe': %ld\n",firestring_estr_estristr(&in,&out,0)); firestring_estr_strcpy(&in,"vIrUs.eXe"); firestring_estr_strcpy(&out,".exe"); printf("'.exe' (ei) in 'vIrUs.eXe': %ld\n",firestring_estr_estristr(&in,&out,0)); firestring_estr_strcpy(&in,"virus.exe.scr"); firestring_estr_strcpy(&out,".exe"); printf("'.exe' (ei) in 'virus.exe.scr': %ld\n",firestring_estr_estristr(&in,&out,0)); firestring_estr_strcpy(&in,"ViRuS.ExE.ScR"); firestring_estr_strcpy(&out,".exe"); printf("'.exe' (ei) in 'ViRuS.ExE.ScR': %ld\n",firestring_estr_estristr(&in,&out,0)); firestring_estr_strcpy(&in,"virus.exe"); printf("'.exe' in 'virus.exe': %ld\n",firestring_estr_strstr(&in,".exe",0)); firestring_estr_strcpy(&in,"ViRuS.ExE"); printf("'.exe' (i) in 'ViRuS.ExE': %ld\n",firestring_estr_stristr(&in,".exe",0)); firestring_estr_strcpy(&in,"ViRuS.ExE"); firestring_estr_strcpy(&out,".bat"); printf("'.bat' on the end of 'ViRuS.ExE': %d\n",firestring_estr_eends(&in,&out)); firestring_estr_strcpy(&in,"ViRuS.ExE"); firestring_estr_strcpy(&out,".exe"); printf("'.exe' on the end of 'ViRuS.ExE': %d\n",firestring_estr_eends(&in,&out)); firestring_estr_strcpy(&in,"ViRuS.ExE"); firestring_estr_strcpy(&out,"tbear"); printf("'tbear' on the start of 'ViRuS.ExE': %d\n",firestring_estr_estarts(&in,&out)); firestring_estr_strcpy(&in,"ViRuS.ExE"); firestring_estr_strcpy(&out,"virus"); printf("'virus' on the start of 'ViRuS.ExE': %d\n",firestring_estr_estarts(&in,&out)); firestring_estr_strcpy(&in,"\r.\r\n"); firestring_estr_strcpy(&out,".\r\n"); printf("'.\\r\\n' on the start of '\\r.\\r\\n': %d\n",firestring_estr_eends(&in,&out)); firestring_estr_strcpy(&in,"testuser1"); firestring_estr_base64_encode(&out,&in); firestring_estr_0(&out); printf("base64_encode('testuser1'): %s\n",out.s); firestring_estr_strcpy(&in,"testuser12"); firestring_estr_base64_encode(&out,&in); firestring_estr_0(&out); printf("base64_encode('testuser12'): %s\n",out.s); firestring_estr_strcpy(&in,"testuser123"); firestring_estr_base64_encode(&out,&in); firestring_estr_0(&out); printf("base64_encode('testuser123'): %s\n",out.s); firestring_estr_strcpy(&in,"dGVzdHVzZXIx"); firestring_estr_base64_decode(&out,&in); firestring_estr_0(&out); printf("base64_decode('dGVzdHVzZXIx'): %s\n",out.s); firestring_estr_strcpy(&in,"dGVzdHVzZXIxMg=="); firestring_estr_base64_decode(&out,&in); firestring_estr_0(&out); printf("base64_decode('dGVzdHVzZXIxMg=='): %s\n",out.s); firestring_estr_strcpy(&in,"dGVzdHVzZXIxMjM="); firestring_estr_base64_decode(&out,&in); firestring_estr_0(&out); printf("base64_decode('dGVzdHVzZXIxMjM='): %s\n",out.s); firestring_estr_strcpy(&in,"dGVzdHVzZXI\nxMjM="); firestring_estr_base64_decode(&in,&in); firestring_estr_0(&in); printf("base64_decode('dGVzdHVzZXI\\nxMjM=') -- in place: %s\n",in.s); firestring_estr_strcpy(&in,"Aladdin:open sesame"); firestring_estr_base64_encode(&out,&in); firestring_estr_0(&out); printf("base64_encode('Aladdin:open sesame'): %s\n",out.s); firestring_estr_strcpy(&in,"QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); firestring_estr_base64_decode(&out,&in); firestring_estr_0(&out); printf("base64_decode('QWxhZGRpbjpvcGVuIHNlc2FtZQ=='): %s\n",out.s); firestring_estr_strcpy(&in,"QWxhZGRpbjpvcGVuIHNlc2FtZQ=="); firestring_estr_base64_decode(&in,&in); firestring_estr_0(&in); printf("base64_decode('QWxhZGRpbjpvcGVuIHNlc2FtZQ==') -- in place: %s\n",in.s); firestring_estr_strcpy(&in,"QWxhZGRpbjpvcGVuIHNlc2FtZQ=\n="); firestring_estr_base64_decode(&in,&in); firestring_estr_0(&in); printf("base64_decode('QWxhZGRpbjpvcGVuIHNlc2FtZQ=\\n=') -- in place: %s\n",in.s); firestring_estr_strcpy(&in,"QWxhZGRpbjpvcGVuIHNlc2FtZQ== "); firestring_estr_base64_decode(&in,&in); firestring_estr_0(&in); printf("base64_decode('QWxhZGRpbjpvcGVuIHNlc2FtZQ== ') -- in place: %s\n",in.s); f = open("/dev/urandom",O_RDONLY); if (f == -1) { perror("open"); exit(1); } if (read(f,in.s,200) != 200) { perror("read"); exit(1); } in.l = 200; firestring_estr_base64_encode(&out,&in); firestring_estr_0(&out); printf("base64_encode(random data): %s\n",out.s); firestring_estr_strcpy(&in,"test of xml decode"); firestring_estr_xml_decode(&out,&in); firestring_estr_0(&out); printf("xml_decode('test of xml decode'): %s\n",out.s); firestring_estr_strcpy(&in,"test of xml decode & foo"); firestring_estr_xml_decode(&out,&in); firestring_estr_0(&out); printf("xml_decode('test of xml decode & foo'): %s\n",out.s); firestring_estr_strcpy(&in,"test of xml decode & foo"); firestring_estr_xml_decode(&in,&in); firestring_estr_0(&in); printf("xml_decode('test of xml decode & foo') -- in place: %s\n",in.s); firestring_estr_strcpy(&in,""there is no spoon & the cat's in the cradle""); firestring_estr_xml_decode(&out,&in); firestring_estr_0(&out); printf("xml_decode('"there is no spoon & the cat's in the cradle"'): %s\n",out.s); firestring_estr_strcpy(&in," U ©"); firestring_estr_xml_decode(&out,&in); firestring_estr_0(&out); printf("xml_decode(' U ©'): %s\n",out.s); firestring_estr_strcpy(&in,""there is no spoon & the cat's in the cradle""); firestring_estr_xml_decode(&out,&in); firestring_estr_0(&out); printf("xml_decode('"there is no spoon & the cat's in the cradle"'): %s\n",out.s); firestring_estr_strcpy(&in," U ©"); firestring_estr_xml_decode(&out,&in); firestring_estr_0(&out); printf("xml_decode(' U ©'): %s\n",out.s); firestring_estr_strcpy(&in,"\"there is no spoon & the cat's <> in the cradle\""); firestring_estr_xml_encode(&out,&in); firestring_estr_0(&out); printf("xml_encode('\"there is no spoon & the cat's <> in the cradle\"'): %s\n",out.s); firestring_estr_strcpy(&in,"\"test of {replaceme} replace function {replaceme}\""); firestring_estr_replace(&out,&in,&(struct firestring_estr_t) { "REPLACED", 8, 8 },&(struct firestring_estr_t) { "{replaceme}", 11, 11 }); firestring_printf("replace('test of {replaceme} replace function {replaceme}\"','REPLACED','{replaceme}'): '%e'\n",&out); firestring_estr_strcpy(&in,"\"test of {replaceme} replace function {replaceme}\""); firestring_estr_replace(&out,&in,&(struct firestring_estr_t) { "REPLACED123456", 14, 14 },&(struct firestring_estr_t) { "{replaceme}", 11, 11 }); firestring_printf("replace('test of {replaceme} replace function {replaceme}\"','REPLACED123456','{replaceme}'): '%e'\n",&out); value = firestring_conf_parse("/tmp/firestring.conf"); printf("firestring_conf_parse('/tmp/firestring.conf') -- testvar: %s\n",value == NULL ? "failed" : firestring_conf_find(value,"testvar")); printf("firestring_conf_parse('/tmp/firestring.conf') -- testvar2: %s\n",value == NULL ? "failed" : firestring_conf_find(value,"testvar2")); { char *target_user = NULL; while ((target_user = firestring_conf_find_next(value,"target_user",target_user)) != NULL) printf("firestring_conf_find_next('target_user'): %s\n",target_user); } firestring_printf("firestring_printf() test\n"); firestring_fprintf(stderr,"firestring_fprintf() test\n"); firestring_estr_strcpy(&in,"this is an estr"); firestring_printf("test: %e\n",&in); firestring_printf("time: %t\n",time(NULL)); firestring_set_error_handler(error_handler); firestring_malloc(-1); firestring_estr_free(&in); firestring_estr_free(&out); return 0; } firedns/firestring/README0000644000175000017500000000204707713510327014272 0ustar useruserFireString Library ------------------ (c) 2000 Ian Gulliver under the GNU Public License, Version 2. See GPL for more details. Parts of this library are taken from dstr and dconf, part of LibD: * Copyright (C) 2001-2002 Andres Salomon From libfirestring(3): "libfirestring is a string handling library that provides maximum length aware string handling functions to programs. Several functions provide saner interfaces than the standard libc functions. libfirestring also provides functions that are in most libc's but not provided for by ANSI C, enabling programmers to write ANSI C-compliant code while using such safe functions (strcasecmp, strncasecmp, snprintf). "libfirestring also includes functions for dealing with reading configuration files in an easy to program fashion." This library uses long long, which is part of the C99 standard (previously a GNU extension). Your compiler needs to support this in order for FireString to work. If you have questions or comments, you can reach me at ian@penguinhosting.net. firedns/firestring/firestring.c0000644000175000017500000011241010023361144015713 0ustar useruser/* firestring.c - FireString replacement string functions Copyright (C) 2000 Ian Gulliver This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Parts of this library are taken from dstr and dconf, part of LibD: * Copyright (C) 2001-2002 Andres Salomon */ #define _FIRESTRING_C #include #include #include #include #include #include #include #include #include #include "firemake.h" #include "firestring.h" #define max(a,b) (a > b ? a : b) #define min(a,b) (a < b ? a : b) static void firestring_int_errorhandler(); static const char tagstring[] = "$Id: firestring.c,v 1.107 2004/03/09 14:47:53 ian Exp $"; const char firestring_version[] = VERSION; static void (*error_handler)() = firestring_int_errorhandler; struct xml_encoding { char character; char *entity; }; static const char base64_encode_table[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' }; static const char base64_decode_table[] = { 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 0, 64, 64, 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64, 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }; static const char hex_decode_table[] = { 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 16, 16, 16, 16, 16, 16, 16, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 10, 11, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16 }; #define XML_UNSAFE "<>\"&" #define XML_WORSTCASE 6 static const struct xml_encoding xml_decode_table[] = { { '<', "<" }, { '>', ">" }, { '"', """ }, { '&', "&" }, { ' ', " " }, { '\xa1', "¡" }, { '\xa2', "¢" }, { '\xa3', "£" }, { '\xa4', "¤" }, { '\xa5', "¥" }, { '\xa6', "¦" }, { '\xa7', "§" }, { '\xa8', "¨" }, { '\xa9', "©" }, { '\xaa', "ª" }, { '\xab', "«" }, { '\xac', "¬" }, { '\xad', "­" }, { '\xae', "®" }, { '\xaf', "¯" }, { '\xb0', "°" }, { '\xb1', "±" }, { '\xb2', "²" }, { '\xb3', "³" }, { '\xb4', "´" }, { '\xb5', "µ" }, { '\xb6', "¶" }, { '\xb7', "·" }, { '\xb8', "¸" }, { '\xb9', "¹" }, { '\xba', "º" }, { '\xbb', "»" }, { '\xbc', "¼" }, { '\xbd', "½" }, { '\xbe', "¾" }, { '\xbf', "¿" }, { '\xc0', "À" }, { '\xc1', "Á" }, { '\xc2', "Â" }, { '\xc3', "Ã" }, { '\xc4', "Ä" }, { '\xc5', "Å" }, { '\xc6', "Æ" }, { '\xc7', "Ç" }, { '\xc8', "È" }, { '\xc9', "É" }, { '\xca', "Ê" }, { '\xcb', "Ë" }, { '\xcc', "Ì" }, { '\xcd', "Í" }, { '\xce', "Î" }, { '\xcf', "Ï" }, { '\xd0', "Ð" }, { '\xd1', "Ñ" }, { '\xd2', "Ò" }, { '\xd3', "Ó" }, { '\xd4', "Ô" }, { '\xd5', "Õ" }, { '\xd6', "Ö" }, { '\xd7', "×" }, { '\xd8', "Ø" }, { '\xd9', "Ù" }, { '\xda', "Ú" }, { '\xdb', "Û" }, { '\xdc', "Ü" }, { '\xdd', "Ý" }, { '\xde', "Þ" }, { '\xdf', "ß" }, { '\xe0', "à" }, { '\xe1', "á" }, { '\xe2', "â" }, { '\xe3', "ã" }, { '\xe4', "ä" }, { '\xe5', "å" }, { '\xe6', "æ" }, { '\xe7', "ç" }, { '\xe8', "è" }, { '\xe9', "é" }, { '\xea', "ê" }, { '\xeb', "ë" }, { '\xec', "ì" }, { '\xed', "í" }, { '\xee', "î" }, { '\xef', "ï" }, { '\xf0', "ð" }, { '\xf1', "ñ" }, { '\xf2', "ò" }, { '\xf3', "ó" }, { '\xf4', "ô" }, { '\xf5', "õ" }, { '\xf6', "ö" }, { '\xf7', "÷" }, { '\xf8', "ø" }, { '\xf9', "ù" }, { '\xfa', "ú" }, { '\xfb', "û" }, { '\xfc', "ü" }, { '\xfd', "ý" }, { '\xfe', "þ" }, { '\xff', "ÿ" }, { '\0', NULL } }; static void firestring_int_errorhandler() { perror("Allocation failed"); exit(EXIT_FAILURE); } void firestring_set_error_handler(void (*e)()) { error_handler = e; } void *firestring_malloc(const size_t size) { char *output; output = malloc(size); if (output == NULL) error_handler(); return output; } void *firestring_realloc(void * old, const size_t new) { char *output; output = realloc(old,new); if (output == NULL) error_handler(); return output; } char *firestring_strdup(const char * restrict const input) { /* allocate and return pointer to duplicate string */ char * restrict output; size_t s; if (input == NULL) return NULL; s = strlen(input) + 1; output = firestring_malloc(s); memcpy(output,input,s); return(output); } void firestring_strncpy(char * restrict const to, const char * restrict const from, const size_t size) { strncpy(to,from,size); to[size - 1]= '\0'; return; } void firestring_strncat(char * restrict const to, const char * restrict const from, const size_t size) { size_t l; l = strlen(to); firestring_strncpy(&to[l],from,size - l); return; } static inline int showdate(char * const dest, const int space, const time_t t) { struct tm bt; int i; if (space < 18) return -1; localtime_r(&t,&bt); i = strftime(dest,18,"%Y%m%dT%H:%M:%S",&bt); if (i != 17) return -1; return 17; } static inline int shownum_unsigned(unsigned long long m, const int padzero, int numpad, char * const numbuf, const int space) { int power; /* smallest power of 10 greater than m */ long long multiple = 1; int r; char f; int i = 0; for (power = 0; multiple <= m; power++) multiple *= 10; /* fixup 0 case, which shouldn't really display in technical terms */ power = max(power,1); multiple = max(multiple,10); f = padzero == 1 ? '0' : ' '; if (power > space || numpad > space) return -1; if (power < numpad) { numpad -= power; for (; i < numpad; i++) numbuf[i] = f; } for (;power > 0; power--) { multiple /= 10; r = m / multiple; numbuf[i++] = '0' + r; m -= r * multiple; } return i; } static inline int shownum_funsigned(const double m, const int padzero, int numpad, char * const numbuf, const int space) { char f; int i,j; f = padzero == 1 ? '0' : ' '; if (numpad > space) return -1; j = numpad; if (j == 0) j = 6; if (space < j) j = space; #ifdef HAVE_GCVT gcvt((const double) m,j,numbuf); #else numbuf[0] = '\0'; #endif i = strlen(numbuf); if (i >= numpad) return i; memmove(&numbuf[numpad - i],numbuf,i); for (i = numpad - i; i; i--) numbuf[i-1] = f; return numpad; } static inline int shownum_signed(const long long n, const int padzero, const int numpad, char * const numbuf, const int space) { unsigned long long m; int i = 0; m = (unsigned long long) (n < 0 ? n * -1 : n); if ((long long) m != n) { numbuf[0] = '-'; i = shownum_unsigned(m,padzero,numpad - 1,&numbuf[1],space - 1); if (i == -1) return -1; else return i + 1; } else return shownum_unsigned(m,padzero,numpad,numbuf,space); } static inline int shownum_fsigned(const double n, const int padzero, const int numpad, char * const numbuf, const int space) { double m; int i = 0; m = n < 0.0 ? n * -1.0 : n; if (m != n) { numbuf[0] = '-'; i = shownum_funsigned(m,padzero,numpad - 1,&numbuf[1],space - 1); if (i == -1) return -1; else return i + 1; } else return shownum_funsigned(m,padzero,numpad,numbuf,space); } long firestring_fprintf(FILE * restrict stream, const char * restrict const format, ...) { va_list ap; long o; va_start(ap,format); o = firestring_vfprintfe(stream,&ESTR_D((char *)format),ap); va_end(ap); return o; } long firestring_fprintfe(FILE * restrict stream, const struct firestring_estr_t * restrict const format, ...) { va_list ap; long o; va_start(ap,format); o = firestring_vfprintfe(stream,format,ap); va_end(ap); return o; } long firestring_printf(const char * restrict const format, ...) { va_list ap; long o; va_start(ap,format); o = firestring_vfprintfe(stdout,&ESTR_D((char *)format),ap); va_end(ap); return o; } long firestring_printfe(const struct firestring_estr_t * restrict const format, ...) { va_list ap; long o; va_start(ap,format); o = firestring_vfprintfe(stdout,format,ap); va_end(ap); return o; } long firestring_snprintf(char * restrict const out, const long size, const char * restrict const format, ...) { va_list ap; struct firestring_estr_t o; va_start(ap,format); o.s = out; o.l = 0; o.a = size - 1; firestring_estr_vsprintf(&o,format,ap); va_end(ap); firestring_estr_0(&o); return o.l; } int firestring_strncasecmp(const char * restrict const s1, const char * restrict const s2, const long n) { long s; for (s = 0; s < n; s++) { if (tolower((unsigned char) s1[s]) != tolower((unsigned char) s2[s])) { if (tolower((unsigned char) s1[s]) < tolower((unsigned char) s2[s])) return -1; else return 1; } if (s1[s] == '\0') return 0; } return 0; } int firestring_strcasecmp(const char * restrict const s1, const char * restrict const s2) { /* case-insensitive string comparison, ignores tail of longer string */ size_t s; char c1, c2; for (s = 0; (s1[s] != '\0') && (s2[s] != '\0') && (tolower((unsigned char) s1[s]) == tolower((unsigned char) s2[s])); s++); c1 = tolower((unsigned char) s1[s]); c2 = tolower((unsigned char) s2[s]); if (c1 == c2) return 0; else if (c1 < c2) return -1; else return 1; } char *firestring_concat (const char * restrict const s, ...) { const char *curr; size_t len = 0; va_list va; char * restrict ret = NULL; /* get length */ va_start(va,s); curr = s; while (curr != NULL) { len += strlen(curr); curr = va_arg(va, const char *); } va_end(va); /* allocate string */ if (len) { ret = firestring_malloc(len + 1); *ret = '\0'; } /* copy */ va_start(va,s); curr = s; while (curr != NULL) { strcat(ret,curr); curr = va_arg(va, const char *); } va_end(va); return ret; } char *firestring_chomp(char *s) { /* remove trailing whitespace */ char *end = s; if (end != NULL) { end = &s[strlen(s) - 1]; while (isspace(*end)) { *end = '\0'; if (end == s) break; end--; } } return s; } char *firestring_chug(char * s) { /* ignore frontal whitespace */ if (s != NULL) { while (isspace(*s)) s++; } return s; } char *firestring_trim(char *s) { return firestring_chug(firestring_chomp(s)); } void firestring_estr_alloc(struct firestring_estr_t * const f, const long a) { if (a + 1 > UINT_MAX) { errno = EINVAL; error_handler(); } f->s = firestring_malloc(a + 1); f->a = a; f->l = 0; } void firestring_estr_expand(struct firestring_estr_t * const f, const long a) { if (f->a >= a) return; if (a + 1 > UINT_MAX) { errno = EINVAL; error_handler(); } f->s = firestring_realloc(f->s, a + 1); f->a = a; } void firestring_estr_free(struct firestring_estr_t * const f) { if (f->s != NULL) free(f->s); f->a = 0; f->l = 0; f->s = NULL; } void firestring_estr_0(struct firestring_estr_t * const f) { if (f->s != NULL) f->s[f->l] = '\0'; } int firestring_estr_read(struct firestring_estr_t * const f, const int fd) { long i; if (f->l == f->a) return 2; i = read(fd,&f->s[f->l],f->a - f->l); if (i == -1 && errno == EAGAIN) return 0; if (i <= 0) return 1; f->l += i; return 0; } long firestring_estr_sprintf(struct firestring_estr_t * restrict const o, const char * restrict const format, ...) { va_list ap; va_start(ap,format); return firestring_estr_vsprintfe(o,&ESTR_D((char *)format),ap); } long firestring_estr_sprintfe(struct firestring_estr_t * restrict const o, const struct firestring_estr_t * restrict const format, ...) { va_list ap; va_start(ap,format); return firestring_estr_vsprintfe(o,format,ap); } long firestring_estr_vsprintf(struct firestring_estr_t * restrict const o, const char * restrict const format, va_list ap) { return firestring_estr_vsprintfe(o,&ESTR_D((char *)format),ap); } long firestring_estr_vsprintfe(struct firestring_estr_t * restrict const o, const struct firestring_estr_t * restrict const format, va_list ap) { size_t f,tl; const char *tempchr; const struct firestring_estr_t *e; int b = 0; int padzero, numpad; int m; time_t t; #define SIGNED_NUMBER(type) \ m = shownum_signed((long long) va_arg(ap,type),padzero,numpad,&o->s[o->l],o->a - o->l); \ if (m == -1) \ b = 1; \ else \ o->l += m; #define UNSIGNED_NUMBER(type) \ m = shownum_unsigned((unsigned long long) va_arg(ap,type),padzero,numpad,&o->s[o->l],o->a - o->l); \ if (m == -1) \ b = 1; \ else \ o->l += m; #define FSIGNED_NUMBER(type) \ m = shownum_fsigned((double) va_arg(ap,type),padzero,numpad,&o->s[o->l],o->a - o->l); \ if (m == -1) \ b = 1; \ else \ o->l += m; o->l = 0; for (f = 0; f < format->l && o->l < o->a && b == 0; f++) { if (format->s[f] == '%') { padzero = 0; numpad = 0; eformatcheck: switch(format->s[++f]) { case '0': if (numpad == 0 && padzero == 0) { padzero = 1; goto eformatcheck; } case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': numpad = (numpad * 10) + (format->s[f] - '0'); goto eformatcheck; case 's': tempchr = va_arg(ap,const char *); if (tempchr == NULL) tempchr = "(null)"; tl = strlen(tempchr); if (tl + o->l > o->a) b = 1; else { memcpy(&o->s[o->l],tempchr,tl); o->l += tl; } break; case 'e': e = va_arg(ap,const struct firestring_estr_t *); if (e == NULL) break; if (e->l + o->l > o->a) b = 1; else { memcpy(&o->s[o->l],e->s,e->l); o->l += e->l; } break; case 'd': /* signed int */ SIGNED_NUMBER(int) break; case 'l': /* signed long */ SIGNED_NUMBER(long) break; case 'u': /* unsigned int */ UNSIGNED_NUMBER(unsigned int) break; case 'y': /* unsigned long */ UNSIGNED_NUMBER(unsigned long) break; case 'g': /* signed long long */ SIGNED_NUMBER(long long) break; case 'o': /* unsigned long long */ UNSIGNED_NUMBER(unsigned long long) break; case 'f': /* double */ FSIGNED_NUMBER(double); break; case 't': /* time */ t = va_arg(ap,time_t); m = showdate(&o->s[o->l],o->a - o->l,t); if (m == -1) b = 1; else o->l += m; break; case '%': o->s[o->l++] = '%'; break; } } else o->s[o->l++] = format->s[f]; } return o->l; } long firestring_vfprintf(FILE *stream, const char * restrict const format, va_list ap) { return firestring_vfprintfe(stream,&ESTR_D((char *)format),ap); } long firestring_vfprintfe(FILE *stream, const struct firestring_estr_t * restrict const format, va_list ap) { size_t f,tl; const char *tempchr; const struct firestring_estr_t *e; int padzero, numpad; #define NUMSTRING_MAX 256 char numbuf[NUMSTRING_MAX]; int out = 0; int m; time_t t; #undef SIGNED_NUMBER #undef UNSIGNED_NUMBER #undef FSIGNED_NUMBER #define SIGNED_NUMBER(type) \ m = shownum_signed((long long) va_arg(ap,type),padzero,numpad,numbuf,NUMSTRING_MAX); \ out += m; \ fwrite(numbuf,m,1,stream); #define UNSIGNED_NUMBER(type) \ m = shownum_unsigned((unsigned long long) va_arg(ap,type),padzero,numpad,numbuf,NUMSTRING_MAX); \ out += m; \ fwrite(numbuf,m,1,stream); #define FSIGNED_NUMBER(type) \ m = shownum_fsigned((double) va_arg(ap,type),padzero,numpad,numbuf,NUMSTRING_MAX); \ out += m; \ fwrite(numbuf,m,1,stream); for (f = 0; f < format->l; f++) { if (format->s[f] == '%') { padzero = 0; numpad = 0; eformatcheck: switch(format->s[++f]) { case '0': if (numpad == 0 && padzero == 0) { padzero = 1; goto eformatcheck; } case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': numpad = (numpad * 10) + (format->s[f] - '0'); goto eformatcheck; case 's': tempchr = va_arg(ap,const char *); if (tempchr == NULL) tempchr = "(null)"; tl = strlen(tempchr); out += tl; fwrite(tempchr,tl,1,stream); break; case 'e': e = va_arg(ap,const struct firestring_estr_t *); if (e == NULL) break; out += e->l; fwrite(e->s,e->l,1,stream); break; case 'd': /* signed int */ SIGNED_NUMBER(int) break; case 'l': /* signed long */ SIGNED_NUMBER(long) break; case 'u': /* unsigned int */ UNSIGNED_NUMBER(unsigned int) break; case 'y': /* unsigned long */ UNSIGNED_NUMBER(unsigned long) break; case 'g': /* signed long long */ SIGNED_NUMBER(long long) break; case 'o': /* unsigned long long */ UNSIGNED_NUMBER(unsigned long long) break; case 'f': /* double */ FSIGNED_NUMBER(double); break; case 't': /* time */ t = va_arg(ap,time_t); m = showdate(numbuf,NUMSTRING_MAX,t); fwrite(numbuf,m,1,stream); out += m; break; case '%': out++; fwrite("%",1,1,stream); break; } } else { out++; fwrite(&format->s[f],1,1,stream); } } return out; } long firestring_estr_strchr(const struct firestring_estr_t * const f, const char c, const long start) { long i; for (i = start; i < f->l; i++) if (f->s[i] == c) return i; return -1; } long firestring_estr_strstr(const struct firestring_estr_t * restrict const f, const char * restrict s, const long start) { long i; long l; l = strlen(s); for (i = start; i <= f->l - l; i++) if (memcmp(&f->s[i],s,l) == 0) return i; return -1; } long firestring_estr_stristr(const struct firestring_estr_t * restrict const f, const char * restrict s, const long start) { long i; long j; long l; l = strlen(s); for (i = start; i <= f->l - l; i++) { for (j = 0; j < l; j++) if (tolower(f->s[i+j]) != tolower(s[j])) break; if (j == l) return i; } return -1; } int firestring_estr_starts(const struct firestring_estr_t * restrict const f, const char * restrict const s) { return firestring_estr_estarts(f,&ESTR_D((char *)s)); } int firestring_estr_ends(const struct firestring_estr_t * restrict const f, const char * restrict const s) { return firestring_estr_eends(f,&ESTR_D((char *)s)); } int firestring_estr_strcasecmp(const struct firestring_estr_t * restrict const f, const char * restrict const s) { long i; if (f->l != strlen(s)) return 1; for (i = 0; i < f->l; i++) if (tolower(f->s[i]) != tolower(s[i])) return 1; return 0; } int firestring_estr_strcmp(const struct firestring_estr_t * restrict const f, const char * restrict const s) { long i; if (f->l != strlen(s)) return 1; for (i = 0; i < f->l; i++) if (f->s[i] !=s[i]) return 1; return 0; } int firestring_estr_strcpy(struct firestring_estr_t * restrict const f, const char * restrict const s) { long l; l = strlen(s); if (f->a < l) return 1; f->l = l; memcpy(f->s,s,l); return 0; } int firestring_estr_astrcpy(struct firestring_estr_t * restrict const f, const char * restrict const s) { long l; l = strlen(s); firestring_estr_expand(f,f->l + l); f->l = l; memcpy(f->s,s,l); return 0; } int firestring_estr_strcat(struct firestring_estr_t * restrict const f, const char * restrict const s) { long l; l = strlen(s); if (l + f->l > f->a) return 1; memcpy(&f->s[f->l],s,l); f->l += l; return 0; } int firestring_estr_astrcat(struct firestring_estr_t * restrict const f, const char * restrict const s) { long l; l = strlen(s); firestring_estr_expand(f,f->l + l); memcpy(&f->s[f->l],s,l); f->l += l; return 0; } int firestring_estr_estrcasecmp(const struct firestring_estr_t * restrict const t, const struct firestring_estr_t * restrict const f, const long start) { long i; if (f->l != t->l - start) return 1; for (i = 0; i < f->l; i++) if (tolower(f->s[i]) != tolower(t->s[i + start])) return 1; return 0; } int firestring_estr_estrncasecmp(const struct firestring_estr_t * restrict const t, const struct firestring_estr_t * restrict const f, const long length, const long start) { long i; for (i = 0; i < length; i++) if (tolower(f->s[i]) != tolower(t->s[i + start])) return 1; return 0; } int firestring_estr_estrcpy(struct firestring_estr_t * restrict const t, const struct firestring_estr_t * restrict const f, const long start) { if (f->l - start > t->a) return 1; t->l = f->l - start; memcpy(t->s,&f->s[start],t->l); return 0; } int firestring_estr_aestrcpy(struct firestring_estr_t * restrict const t, const struct firestring_estr_t * restrict const f, const long start) { firestring_estr_expand(t,f->l - start); return firestring_estr_estrcpy(t,f,start); } int firestring_estr_munch(struct firestring_estr_t * const t, const long length) { if (length > t->l) return 1; t->l -= length; memmove(t->s,&t->s[length],t->l); return 0; } void firestring_estr_chomp(struct firestring_estr_t * const s) { /* remove trailing whitespace */ while (s->l > 0 && isspace(s->s[s->l - 1])) s->l--; } void firestring_estr_chug(struct firestring_estr_t * const s) { /* remove leading whitespace */ while (s->l > 0 && isspace(s->s[0])) { s->s++; s->l--; s->a--; } } void firestring_estr_ip_chug(struct firestring_estr_t * const s) { /* remove leading whitespace in place */ long start = 0; while (start < s->l && isspace(s->s[start])) start++; memmove(s->s,&s->s[start],s->l - start); s->l -= start; } void firestring_estr_trim(struct firestring_estr_t * const s) { firestring_estr_chug(s); firestring_estr_chomp(s); } void firestring_estr_ip_trim(struct firestring_estr_t * const s) { firestring_estr_ip_chug(s); firestring_estr_chomp(s); } int firestring_estr_estrcmp(const struct firestring_estr_t * restrict const t, const struct firestring_estr_t * restrict const f, const long start) { long i; if (f->l != t->l - start) return 1; for (i = 0; i < f->l; i++) if (f->s[i] != t->s[i + start]) return 1; return 0; } int firestring_estr_estrcat(struct firestring_estr_t * restrict const t, const struct firestring_estr_t * restrict const f, const long start) { if (f->l - start + t->l > t->a) return 1; memcpy(&t->s[t->l],&f->s[start],f->l - start); t->l += f->l - start; return 0; } int firestring_estr_aestrcat(struct firestring_estr_t * restrict const t, const struct firestring_estr_t * restrict const f, const long start) { firestring_estr_expand(t,t->l + (f->l - start)); return firestring_estr_estrcat(t,f,start); } long firestring_estr_estrstr(const struct firestring_estr_t * restrict const haystack, const struct firestring_estr_t * restrict const needle, const long start) { long i,l; l = haystack->l - needle->l; for (i = start; i <= l; i++) { if (memcmp(&haystack->s[i],needle->s,needle->l) == 0) return i; } return -1; } long firestring_estr_estristr(const struct firestring_estr_t * restrict const haystack, const struct firestring_estr_t * restrict const needle, const long start) { long i,j,l; l = haystack->l - needle->l; for (i = start; i <= l; i++) { for (j = 0; j < needle->l; j++) if (tolower(haystack->s[i+j]) != tolower(needle->s[j])) break; if (j == needle->l) return i; } return -1; } int firestring_estr_estarts(const struct firestring_estr_t * restrict const f, const struct firestring_estr_t * restrict const s) { long i; if (f->l < s->l) return 1; for (i = 0; i < s->l; i++) if (tolower(f->s[i]) != tolower(s->s[i])) return 1; return 0; } int firestring_estr_eends(const struct firestring_estr_t * restrict const f, const struct firestring_estr_t * restrict const s) { long i,t; if (f->l < s->l) return 1; t = f->l - s->l; for (i = f->l - 1; i >= t; i--) if (tolower(f->s[i]) != tolower(s->s[i - t])) return 1; return 0; } int firestring_estr_replace(struct firestring_estr_t * const dest, const struct firestring_estr_t * const source, const struct firestring_estr_t * const to, const struct firestring_estr_t * const from) { int i = 0, oldi = 0; struct firestring_estr_t tempe; dest->l = 0; while ((i = firestring_estr_estrstr(source,from,i)) != -1) { tempe.s = &source->s[oldi]; tempe.l = tempe.a = i - oldi; if (firestring_estr_estrcat(dest,&tempe,0) != 0) return 1; if (firestring_estr_estrcat(dest,to,0) != 0) return 1; i = oldi = i + from->l; } tempe.s = &source->s[oldi]; tempe.l = tempe.a = source->l - oldi; if (firestring_estr_estrcat(dest,&tempe,0) != 0) return 1; return 0; } int firestring_estr_areplace(struct firestring_estr_t * const dest, const struct firestring_estr_t * const source, const struct firestring_estr_t * const to, const struct firestring_estr_t * const from) { int i = 0, oldi = 0; struct firestring_estr_t tempe; dest->l = 0; while ((i = firestring_estr_estrstr(source,from,i)) != -1) { tempe.s = &source->s[oldi]; tempe.l = tempe.a = i - oldi; if (firestring_estr_aestrcat(dest,&tempe,0) != 0) return 1; if (firestring_estr_aestrcat(dest,to,0) != 0) return 1; i = oldi = i + from->l; } tempe.s = &source->s[oldi]; tempe.l = tempe.a = source->l - oldi; if (firestring_estr_aestrcat(dest,&tempe,0) != 0) return 1; return 0; } int firestring_estr_tolower(struct firestring_estr_t * const dest, const struct firestring_estr_t * const source, const long start) { long i; if (source->l - start > dest->a) return 1; for (i = start; i < source->l; i++) dest->s[i - start] = tolower(source->s[i]); return 0; } int firestring_estr_toupper(struct firestring_estr_t * const dest, const struct firestring_estr_t * const source, const long start) { long i; if (source->l - start > dest->a) return 1; for (i = start; i < source->l; i++) dest->s[i - start] = toupper(source->s[i]); return 0; } int firestring_hextoi(const char * const input) { char o1, o2; o1 = hex_decode_table[(int)input[0]]; if (o1 == 16) return -1; o2 = hex_decode_table[(int)input[1]]; if (o2 == 16) return -1; return (o1 << 4) | o2; } int firestring_estr_base64_encode(struct firestring_estr_t * restrict const t, const struct firestring_estr_t * restrict const f) { long i; unsigned char *s, *d; s = (unsigned char *)f->s; d = (unsigned char *)t->s; if (f->l * 4 / 3 > t->a - 4) return 1; t->l = 0; for (i = 0; i < f->l - 2; i += 3) { d[t->l++] = base64_encode_table[s[i] >> 2]; d[t->l++] = base64_encode_table[(s[i] << 4 | s[i+1] >> 4) % 64]; d[t->l++] = base64_encode_table[(s[i+1] << 2 | s[i+2] >> 6) % 64]; d[t->l++] = base64_encode_table[s[i+2] % 64]; } if (i == f->l - 1) { d[t->l++] = base64_encode_table[s[i] >> 2]; d[t->l++] = base64_encode_table[(s[i] << 4) % 64]; d[t->l++] = '='; d[t->l++] = '='; } else if (i == f->l - 2) { d[t->l++] = base64_encode_table[s[i] >> 2]; d[t->l++] = base64_encode_table[(s[i] << 4 | s[i+1] >> 4) % 64]; d[t->l++] = base64_encode_table[(s[i+1] << 2) % 64]; d[t->l++] = '='; } return 0; } int firestring_estr_base64_decode(struct firestring_estr_t * const t, const struct firestring_estr_t * const f) { long i,j,o; unsigned char tempblock[4]; if (f->l * 3 / 4 > t->a - 3) return 1; o = 0; for (i = 0; i < f->l - 3; i += 4) { for (j = 0; j < 4; j++) { tempblock[j] = (unsigned char) f->s[i + j]; if (base64_decode_table[(int)tempblock[j]] == 64) { if (++i > f->l - 4) goto base64_end; j--; continue; } } t->s[o++] = base64_decode_table[(int)tempblock[0]] << 2 | base64_decode_table[(int)tempblock[1]] >> 4; t->s[o++] = base64_decode_table[(int)tempblock[1]] << 4 | base64_decode_table[(int)tempblock[2]] >> 2; t->s[o++] = base64_decode_table[(int)tempblock[2]] << 6 | base64_decode_table[(int)tempblock[3]]; } if (tempblock[3] == '=') o--; if (tempblock[2] == '=') o--; base64_end: t->l = o; return 0; } int firestring_estr_xml_encode(struct firestring_estr_t * restrict const t, const struct firestring_estr_t * restrict const f) { long i,j,k; if (t->a < f->l * XML_WORSTCASE) return 1; t->l = 0; for (i = 0; i < f->l; i++) { if (strchr(XML_UNSAFE,f->s[i])) { for (j = 0; xml_decode_table[j].entity != NULL; j++) if (xml_decode_table[j].character == f->s[i]) break; if (xml_decode_table[j].entity == NULL) return 1; k = strlen(xml_decode_table[j].entity); memcpy(&t->s[t->l],xml_decode_table[j].entity,k); t->l += k; } else t->s[t->l++] = f->s[i]; } return 0; } int firestring_estr_xml_decode(struct firestring_estr_t * const t, const struct firestring_estr_t * const f) { long i = 0, o = 0; long j,k,l; int tempint; if (t->a < f->l) return 1; while ((j = firestring_estr_strchr(f,'&',i)) != -1) { memmove(&t->s[o],&f->s[i],j - i); o += j - i; if (f->s[j + 1] == '#') { /* numeric */ k = firestring_estr_strchr(f,';',j + 1); if (k == -1) /* unterminated entity */ return 1; if (f->s[j + 2] == 'x') { /* hex */ j += 3; for (l = j; l < k; l += 2) { tempint = firestring_hextoi(&f->s[l]); if (tempint == -1) /* invalid hex */ return 1; t->s[o++] = tempint; } } else { /* decimal */ if (k - j < 3 || k - j > 5) return 1; /* too long or too short */ t->s[o++] = (char) atoi(&f->s[j + 2]); } i = k + 1; } else { /* symbolic */ for (l = 0; xml_decode_table[l].entity != NULL; l++) { k = strlen(xml_decode_table[l].entity); if (j + l < f->l && memcmp(&f->s[j],xml_decode_table[l].entity,k) == 0) break; } if (xml_decode_table[l].entity == NULL) /* unknown entity */ return 1; t->s[o++] = xml_decode_table[l].character; i = j + strlen(xml_decode_table[l].entity); } } memmove(&t->s[o],&f->s[i],f->l - i); t->l = o + (f->l - i); return 0; } /* strip quotes, escape chars, and trailing chars from the string. */ static enum firestring_conf_parse_line_result strip_quotes(char **line) { char *s, *last_quote = NULL; int escaped = 0; if (line == NULL || *line == NULL) return FSC_MALFORMED; /* if unquoted, just strip whitespace, and nothing else */ *line = firestring_chug(firestring_chomp(*line)); if (**line != '"') return FSC_VALID; /* if quoted, strip initial quote, locate the trailing quote, and get rid of escape chars */ *line = *line + 1; for (s = *line; *s != '\0'; s++) { switch (*s) { case '\\': escaped = 1; memmove(s, s + 1, strlen(s) - 1); if (*s == '\0') s--; /* force a break from the for loop */ else if (*s == '\n') { memmove(s, s + 1, strlen(s) - 1); /* drop newline from string */ s[strlen(s) - 2] = '\0'; } else if (s[0] == '\r' && s[1] == '\n') { memmove(s, s + 2, strlen(s) - 1); /* or dos-style CRLF crap */ s[strlen(s) - 3] = '\0'; } else s[strlen(s) - 1] = '\0'; break; case '"': if (!escaped) last_quote = s; escaped = 0; break; default: escaped = 0; } } if (last_quote == NULL) return FSC_INCOMPLETE; *last_quote = '\0'; return FSC_VALID; } /* handle include keyword; the way we detect infinite include loops is to add a conf variable w/ the filename. */ static enum firestring_conf_parse_line_result keyword_include_handler(char *line, struct firestring_conf_t **conf) { char *sig; line = firestring_chug(firestring_chomp(line)); sig = firestring_concat("inside_include_handler_", line, NULL); if (firestring_conf_find(*conf, sig) == NULL) { *conf = firestring_conf_add(*conf, sig, ""); *conf = firestring_conf_parse_next(line, *conf); *conf = firestring_conf_delete(*conf, sig); } free(sig); return FSC_VALID; } enum firestring_conf_parse_line_result firestring_conf_parse_line(const char *line, const struct firestring_conf_keyword_t keywords[], struct firestring_conf_t **conf, char **context) { enum firestring_conf_parse_line_result err; char *curr, *ptr, *var = NULL, *val = NULL; int i; if (context == NULL || conf == NULL) return FSC_MALFORMED; /* prepend previous line, if it was incomplete */ curr = firestring_concat(*context ? *context : "", line, NULL); ptr = firestring_chug(curr); /* check if the line starts w/ a keyword; if so, call the callback */ for (i=0; keywords[i].keyword != NULL; i++) { if (strncmp(keywords[i].keyword, ptr, strlen(keywords[i].keyword)) == 0) { if (keywords[i].callback != NULL) err = keywords[i].callback(ptr + strlen(keywords[i].keyword), conf); else err = FSC_VALID; goto done; } } /* not a keyword; must be an assignment. split apart. */ val = strchr(ptr, '='); if (val == NULL) { err = FSC_MALFORMED; goto done; } *val++ = '\0'; var = firestring_chomp(ptr); /* and finally, strip quotes */ err = strip_quotes(&val); done: if (err == FSC_INCOMPLETE) { ptr = *context; *context = firestring_concat(*context ? *context : "", line, NULL); if (ptr) free(ptr); } else if (*context != NULL) { free(*context); *context = NULL; } if (err == FSC_VALID) { *conf = firestring_conf_add(*conf, var, val); } free(curr); return err; } static struct firestring_conf_keyword_t default_keywords[] = { { "include ", &keyword_include_handler }, { "#", NULL }, /* ignore comments */ { NULL, NULL }, }; struct firestring_conf_t *firestring_conf_parse_next(const char * const filename, struct firestring_conf_t *prev) { struct firestring_conf_t *conf = prev; char buf[512], *ctx = NULL; FILE *fp; fp = fopen(filename, "r"); if (fp != NULL) { while (fgets(buf, sizeof(buf), fp) != NULL) { firestring_conf_parse_line(buf, default_keywords, &conf, &ctx); } fclose(fp); } return conf; } struct firestring_conf_t *firestring_conf_parse(const char * const filename) { return firestring_conf_parse_next(filename, NULL); } struct firestring_conf_t *firestring_conf_add(struct firestring_conf_t * restrict const next, const char * restrict const var, const char * restrict const value) { /* insert config val in list, return new list head */ struct firestring_conf_t *conf; if (var != NULL && value != NULL) { conf = firestring_malloc(sizeof(*conf)); conf->next = next; conf->var = firestring_strdup(var); conf->value = firestring_strdup(value); } else conf = next; return conf; } struct firestring_conf_t *firestring_conf_delete(struct firestring_conf_t *conf, const char *var) { struct firestring_conf_t *prev = NULL, *head = conf; while (conf != NULL) { if (firestring_strcasecmp(conf->var, var) == 0) { free(conf->var); free(conf->value); if (prev) prev->next = conf->next; if (head == conf) head = conf->next; free(conf); break; } prev = conf; conf = conf->next; } return head; } char *firestring_conf_find(const struct firestring_conf_t * restrict config, const char * restrict const var) { /* find in list and return pointer to config val */ return firestring_conf_find_next(config,var,NULL); } char *firestring_conf_find_next(const struct firestring_conf_t * restrict config, const char * restrict const var, const char * const prev) { int canreturn = 0; if (prev == NULL) canreturn = 1; while (config != NULL) { if (firestring_strcasecmp(config->var, var) == 0) { if (canreturn == 1) return config->value; else if (config->value == prev) canreturn = 1; } config = config->next; } return NULL; } void firestring_conf_free(struct firestring_conf_t * config) { struct firestring_conf_t *next; while (config != NULL) { next = config->next; free(config->var); free(config->value); free(config); config = next; } } firedns/firestring/firemake.headers0000644000175000017500000000001507506132775016532 0ustar useruserfirestring.h firedns/firestring/man/0000755000175000017500000000000010023641030014142 5ustar useruserfiredns/firestring/man/firestring_estr_ends.30000644000175000017500000000106007705600723020466 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_ends 3 2002-06-10 .SH NAME firestring_estr_ends \- check case-insensitively if an estring ends with a string .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_ends(struct firestring_estr_t *" "estring" ", const char *" "string" ")" .SH DESCRIPTION firestring_estr_ends() checks case-insensitively if .I string appears at the end of .IR estring . .SH RETURN VALUE 0 on success; 1 on failure. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_sprintf.30000644000175000017500000000123507660766256021244 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_sprintf 3 2003-05-15 .SH NAME firestring_estr_sprintf \- .BR snprintf (3) into an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "long firestring_estr_sprintf(struct firestring_estr_t *" "out" ", const char * const " "format" ", " "..." ")" .SH DESCRIPTION firestring_estr_sprintf() behaves exactly like .BR firestring_snprintf (3) except that it writes to an estring (which contains the size internally, so size is not needed as a parameter). .SH RETURN VALUE Returns the number of bytes written to .IR out . .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_estrcat.30000644000175000017500000000135207501262747021212 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_estrcat 3 2002-06-10 .SH NAME firestring_estr_estrcat \- concatentate an estring onto another estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_estrcat(struct firestring_estr_t *" "destination" ", struct firestring_estr_t *" "source" ", int " "start" ")" .SH DESCRIPTION firestring_estr_estrcat() copys the contents of .I source from the index .I start onto the end of .IR destination , provided that there is room in .IR destination . .SH RETURN VALUE 0 if the string was copied successfully; 1 if there was insufficient space in .I destination for the copy to occur. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_ip_chug.30000644000175000017500000000107207712223277021161 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_ip_chug 3 2003-07-31 .SH NAME firestring_estr_ip_chug \- remove whitespace from the beginning of an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "void firestring_estr_ip_chug(struct firestring_estr_t *" "string" ")" .SH DESCRIPTION firestring_estr_ip_chug shortens .I string "in place" by copying data back to the beginning of the string starting at the first non-whitespace character. .SH RETURN VALUE None. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_fprintf.30000644000175000017500000000111507660766256020167 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_fprintf 3 2003-05-15 .SH NAME firestring_fprintf \- .BR fprintf (3) with extended firestring types .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "long firestring_fprintf(FILE * " stream ", const char * const " "format" ", " "..." ")" .SH DESCRIPTION firestring_fprintf() behaves exactly like .BR firestring_snprintf (3) except that it writes to the STDIO stream specified by .IR stream . .SH RETURN VALUE Returns the number of bytes written. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_strchr.30000644000175000017500000000121107501256747021047 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_strchr 3 2002-06-10 .SH NAME firestring_estr_strchr \- search for a character in an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_strchr(struct firestring_estr_t *" "estring" ", const char " "c" ", const int " "start" ")" .SH DESCRIPTION firestring_estr_strchr() searches .I estring from the index .I start to the end of the string for the character .IR c . .SH RETURN VALUE The index of the character found on success; -1 if the character did not occur in the range. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_alloc.30000644000175000017500000000115207501255004020621 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_alloc 3 2002-06-10 .SH NAME firestring_estr_alloc \- allocate space for an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "void firestring_estr_alloc(struct firestring_estr_t *" "estring" ", int " "size" ")" .SH DESCRIPTION firestring_estr_alloc() uses .BR firestring_malloc (3) to allocate .I size bytes in .IR estring . It resets the length of .I estring to 0 and stores the size with the string to facilitate safe operations later. .SH RETURN VALUE None. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_chug.30000644000175000017500000000100207452476233017430 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_chug 3 2002-03-31 .SH NAME firestring_chug \- trim excess whitespace from the beginning of a string .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "char *firestring_chug(char *" "s" ")" .SH DESCRIPTION firestring_chug() removes whitespace from the beginning of the string .I s and returns the result. .SH RETURN VALUE Returns .I s with any leading whitespace removed. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_realloc.30000644000175000017500000000144407451703045020126 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_realloc 3 2002-03-31 .SH NAME firestring_realloc \- .BR realloc (3) with internal result checking .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "void *firestring_realloc(void *" "old" ", const size_t " "new" ")" .SH DESCRIPTION firestring_realloc() acts exactly like .BR realloc (3) except that it detects realloc failures, prints an error and .BR exit (3) with exit status EXIT_FAILURE. In most programs, realloc failures are unrecoverable, and this is the preferred behaviour. .SH RETURN VALUE If firestring_realloc() returns, it .B always returns a string of .I new bytes containing the data from .I old at the beginning. It .B never returns .IR NULL. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_free.30000644000175000017500000000104407501255004020450 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_free 3 2002-06-10 .SH NAME firestring_estr_free \- free space allocated to an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "void firestring_estr_free(struct firestring_estr_t *" "estring" ")" .SH DESCRIPTION firestring_estr_free() frees any space allocated to .I estring and stores a size of 0 with the string to prevent accidental writes back to the freed space. .SH RETURN VALUE None. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_vfprintfe.30000644000175000017500000000133210023640406020472 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_vfprintfe 3 2004-03-10 .SH NAME firestring_vfprintfe \- .BR firestring_vfprintf (3) with an estring format .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "long firestring_vfprintfe(FILE * " stream ", struct firestring_estr_t *" "format" ", va_list " ap ")" .SH DESCRIPTION firestring_vfprintfe() behaves exactly like .BR firestring_vfprintf (3) except that it takes an estring format argument, so the format can contain arbitrary binary data. However, please note that user user-input data as the format string is .BR INSECURE . .SH RETURN VALUE Returns the number of bytes written. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_estrstr.30000644000175000017500000000125207501263223021240 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_estrstr 3 2002-06-10 .SH NAME firestring_estr_estrstr \- search for an estring in an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_estrstr(struct firestring_estr_t *" "haystack" ", struct firestring_estr_t *" "needle" ", const int " "start" ")" .SH DESCRIPTION firestring_estr_estrstr() searches .I haystack from the index .I start to the end of the string for the estring .IR needle . .SH RETURN VALUE The index of the beginning of the string on success; -1 if the string did not occur in the range. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_concat.30000644000175000017500000000130307452476233017755 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_concat 3 2002-03-31 .SH NAME firestring_concat \- concatenate strings .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "char *firestring_concat(const char *" "s" ", " "..." ")" .SH DESCRIPTION firestring_concat() expects a set of .IR "const char *" 's to nil-terminated strings. It returns a dynamically allocated string containing all of the input strings concatenated. .SH RETURN VALUE A pointer to a dynamically allocated string. This string should be freed by passing the pointer to .BR free (3) when the program is finished with it, to avoid memory leaks. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_strcat.30000644000175000017500000000122707504420305021033 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_strcat 3 2002-06-10 .SH NAME firestring_estr_strcat \- concatenate a string onto an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_strcat(struct firestring_estr_t *" "estring" ", const char *" "string" ")" .SH DESCRIPTION firestring_estr_strcat() copys the contents of .I string onto the end of .IR estring , provided that there is room in .IR estring . .SH RETURN VALUE 0 if the string was copied successfully; 1 if there was insufficient space in .I estring for the copy to occur. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_strcasecmp.30000644000175000017500000000107207501260174021700 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_strcasecmp 3 2002-06-10 .SH NAME firestring_estr_strcasecmp \- compare an estring and a string case-insensitively .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_strcasecmp(struct firestring_estr_t *" "estring" ", const char *" "string" ")" .SH DESCRIPTION firestring_estr_strcasecmp() compares .I estring and .I string case-insensitively. .SH RETURN VALUE 0 if the strings match; 1 if they do not. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_vfprintf.30000644000175000017500000000122107705600723020335 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_vfprintf 3 2003-05-15 .SH NAME firestring_vfprintf \- .BR vfprintf (3) with extended firestring types .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "long firestring_vfprintf(FILE * " stream ", const char * const " "format" ", va_list " ap ")" .SH DESCRIPTION firestring_vfprintf() behaves exactly like .BR firestring_snprintf (3) except that it writes to the STDIO stream specified by .IR stream and accepts a stdarg object instead of a list of arguments. .SH RETURN VALUE Returns the number of bytes written. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_strncat.30000644000175000017500000000146107451703045020162 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_strncat 3 2002-03-31 .SH NAME firestring_strncat \- .BR strncat (3) with slightly saner semantics .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "void firestring_strncat(char * const " "to" ", const char * const " "from" ", const size_t " "size" ")" .SH DESCRIPTION firestring_strncpy() acts like .BR strncat (3) except that .I to will always contain a trailing nil, even if the function runs out of space and the .I size argument is the maximum size of all of .IR to , not just the amount of space remaining in it. In simpler terms, firestring_strncat() appends the string .I from to .IR to , where .I to is a buffer of .I size bytes. .SH RETURN VALUE Always succeeds. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_aestrcat.30000644000175000017500000000123107706774115021353 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_estrcat 3 2003-07-21 .SH NAME firestring_estr_aestrcat \- concatentate an estring onto another estring, expanding the destination if necessary .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_aestrcat(struct firestring_estr_t *" "destination" ", struct firestring_estr_t *" "source" ", int " "start" ")" .SH DESCRIPTION firestring_estr_aestrcat() copys the contents of .I source from the index .I start onto the end of .IR destination , expanding .I destination if necessary. .SH RETURN VALUE 0 .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_chomp.30000644000175000017500000000101307452476233017612 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_chomp 3 2002-03-31 .SH NAME firestring_chomp \- trim excess whitespace from the end of a string .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "char *firestring_chomp(char *" "s" ")" .SH DESCRIPTION firestring_chomp() removes any whitespace at the end of the string .IR s. The string is modified in place and returned as well. .SH RETURN VALUE .I s after having been modified. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_ip_trim.30000644000175000017500000000117707712223277021214 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_ip_trim 3 2003-07-31 .SH NAME firestring_estr_ip_trim \- remove whitespace from the beginning and end of an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "void firestring_estr_trim(struct firestring_estr_t *" "string" ")" .SH DESCRIPTION firestring_estr_trim removes whitespace from the beginning and end of .IR string . It uses .IR firestring_estr_ip_chug (3) instead of .IR firestring_estr_chug (3), so the resulting estring can still be freed normally. .SH RETURN VALUE None. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_vsprintf.30000644000175000017500000000134407660766256021433 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_vsprintf 3 2003-05-15 .SH NAME firestring_estr_vsprintf \- .BR snprintf (3) into an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "long firestring_estr_vsprintf(struct firestring_estr_t *" "out" ", const char * const " "format" ", va_list " ap ")" .SH DESCRIPTION firestring_estr_vsprintf() behaves exactly like .BR firestring_snprintf (3) except that it writes to an estring (which contains the size internally, so size is not needed as a parameter), and it takes an stdarg object instead of a list of arguments. .SH RETURN VALUE Returns the number of bytes written to .IR out . .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_printfe.30000644000175000017500000000126610023640406020144 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_printfe 3 2004-03-10 .SH NAME firestring_printfe \- .BR firestring_printf (3) with an estring format .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "long firestring_printfe(struct firestring_estr_t *" "format" ", " "..." ")" .SH DESCRIPTION firestring_printfe() behaves exactly like .BR firestring_printf (3) except that it takes an estring format argument, so the format can contain arbitrary binary data. However, please note that user user-input data as the format string is .BR INSECURE . .SH RETURN VALUE Returns the number of bytes written. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_conf_delete.30000644000175000017500000000134607660766255020773 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_conf_delete 3 2002-03-31 .SH NAME firestring_conf_delete \- remove an entry from a configuration structure .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "struct firestring_conf_t *firestring_conf_delete(struct firestring_conf_t *" "conf" ", const char *" "var" ")" .SH DESCRIPTION firestring_conf_delete() removes the entry named .I var from the configuration structure .IR conf . This function is provided to allow programs to manually remove configuration settings. .SH RETURN VALUE Returns a new pointer for the configuration structure. This pointer should be used in all future operations. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_estrcmp.30000644000175000017500000000102307505117574021216 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_estrcmp 3 2002-06-10 .SH NAME firestring_estr_estrcmp \- compare two estrings .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_estrcmp(struct firestring_estr_t *" "estring1" ", struct firestring_estr_t *" "estring1" ")" .SH DESCRIPTION firestring_estr_estrcmp() compares .I estring1 and .IR estring2 . .SH RETURN VALUE 0 if the strings match; 1 if they do not. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_conf_add.30000644000175000017500000000141007452476233020242 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_conf_add 3 2002-03-31 .SH NAME firestring_conf_add \- add an entry to a configuration structure .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "struct firestring_conf_t *firestring_conf_add(struct firestring_conf_t *" "next" ", const char *" "var" ", const char *" "value" ")" .SH DESCRIPTION firestring_conf_add() adds an entry to the configuration structure .I next with variable name .I var and the value .IR value. This function is provided to allow programs to manually add configuration settings. .SH RETURN VALUE Returns a new pointer for the configuration structure. This pointer should be used in all future operations. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_conf_free.30000644000175000017500000000115207452616636020441 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_conf_free 3 2002-03-31 .SH NAME firestring_conf_free \- free memory used by a configuration structure .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "void firestring_conf_free(struct firestring_conf_t *" "config" ")" .SH DESCRIPTION firestring_conf_free() frees all the memory used by the configuration structure .IR config. This will cause any pointers previously returned by firestring_conf_find() or firestring_conf_find_next() to be invalid. .SH RETURN VALUE Nothing. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_aestrcpy.30000644000175000017500000000122707706774115021404 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_aestrcpy 3 2003-07-21 .SH NAME firestring_estr_aestrcpy \- copy an estring into another estring, expanding the destination if necessary .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_aestrcpy(struct firestring_estr_t *" "destination" ", struct firestring_estr_t *" "source" ", int " "start" ")" .SH DESCRIPTION firestring_estr_aestrcpy() copys the contents of .I source from the index .I start into .IR destination , expanding .I destination to fit the data if necessary. .SH RETURN VALUE 0 .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_conf_parse.30000644000175000017500000000213007564040315020614 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_conf_parse 3 2002-03-31 .SH NAME firestring_conf_parse \- read and parse a configuration file .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "struct firestring_conf_t *firestring_conf_parse(const char *" "filename" ")" .SH DESCRIPTION firestring_conf_parse() attempts to read a configuration from .I filename and parse the results into a structure that it then returns. .HP The support configuration format is fairly flexible: .br # Configuration file example .br # These are comments .br variable_name = value .br variable_name2=value .br variable_name3="quoted value" .br variable_name4="array value 1" .br variable_name4="array value 2" .P .B include as a variable name is special; it causes firestring to parse the file referenced by the value, overriding any previous values (although they are still accessible as arrays). .SH RETURN VALUE Returns a pointer to a structure containing the data read from the config file, or .I NULL if the file cannot be opened. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_astrcpy.30000644000175000017500000000107107706774115021234 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_astrcpy 3 2003-07-21 .SH NAME firestring_estr_astrcpy \- copy a string into an estring, expanding the destination if necessary .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_astrcpy(struct firestring_estr_t *" "estring" ", const char *" "string" ")" .SH DESCRIPTION firestring_estr_astrcpy() copys the contents of .I string into .IR estring , expanding .I estring if necessary. .SH RETURN VALUE 0 .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_hextoi.30000644000175000017500000000114107543171730020001 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_hextoi 3 2002-09-21 .SH NAME firestring_hextoi \- return a numerical value for a 2 digit hex string .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_hextoi(char *" "input" ")" .SH DESCRIPTION firestring_hextoi takes a string .I s with the first two characters as hex digits and converts the value to a integer. .SH RETURN VALUE Returns the hex value between 0 and 255 (inclusive), or -1 if the first two characters of .I s are not valid hex digits. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_estristr.30000644000175000017500000000132407501263223021411 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_estristr 3 2002-06-10 .SH NAME firestring_estr_estristr \- search for an estring case-insensitively in an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_estristr(struct firestring_estr_t *" "haystack" ", struct firestring_estr_t *" "needle" ", const int " "start" ")" .SH DESCRIPTION firestring_estr_estristr() searches .I haystack case-insensitively from the index .I start to the end of the string for the estring .IR needle . .SH RETURN VALUE The index of the beginning of the string on success; -1 if the string did not occur in the range. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_strstr.30000644000175000017500000000122307501257130021071 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_strstr 3 2002-06-10 .SH NAME firestring_estr_strstr \- search for a string in an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_strstr(struct firestring_estr_t *" "estring" ", const char *" "string" ", const int " "start" ")" .SH DESCRIPTION firestring_estr_strstr() searches .I estring from the index .I start to the end of the string for the string .IR string . .SH RETURN VALUE The index of the beginning of the string on success; -1 if the string did not occur in the range. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_trim.30000644000175000017500000000156307712223277020523 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_trim 3 2003-07-30 .SH NAME firestring_estr_trim \- remove whitespace from the beginning and end of an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "void firestring_estr_trim(struct firestring_estr_t *" "string" ")" .SH DESCRIPTION firestring_estr_trim removes whitespace from the beginning and end of .IR string . .SH CAVEATS This function moves the starting pointer inside .IR string . If .I string was allocated with .IR firestring_estr_alloc (3), (as opposed to constructed manually pointing inside other memory), future calls to .IR firestring_estr_free (3) will fail if this function trimmed any space from the start of the string. In these cases, use .IR firestring_estr_ip_trim (3) instead. .SH RETURN VALUE None. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_trim.30000644000175000017500000000110407712002441017441 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_trim 3 2003-07-30 .SH NAME firestring_trim \- trim excess whitespace from the start and end of a string .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "char *firestring_trim(char *" "s" ")" .SH DESCRIPTION firestring_trim() removes any whitespace at the beginning and end of the string .IR s. A new pointer to the string (as the start may have moved) is returned .SH RETURN VALUE A pointer inside .I s to the new start of the string. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_eends.30000644000175000017500000000110410023640747020627 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_eends 3 2004-03-10 .SH NAME firestring_estr_eends \- check case-insensitively if an estring ends with an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_eends(struct firestring_estr_t *" "estring" ", struct firestring_estr_t *" "needle" ")" .SH DESCRIPTION firestring_estr_eends() checks case-insensitively if .I needle appears at the end of .IR estring . .SH RETURN VALUE 0 on success; 1 on failure. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_replace.30000644000175000017500000000157407707003661021162 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_replace 3 2003-07-21 .SH NAME firestring_estr_replace \- Replace occurences of one string with another .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_replace(struct firestring_estr_t * const " dest ", const struct firestring_estr_t * const " source ", const struct firestring_estr_t * const " to ", const struct firestring_estr_t * const " from ) .SH DESCRIPTION firestring_estr_replace() copies .I source into .IR dest , replacing all instances from .I from with .IR to . If there is insufficient space in .IR dest , the function returns 1 and the contents of .I dest are undefined. .SH RETURN VALUE 0 if the replacement was successful; 1 if there was insufficient space in .I destination for the replacement to occur. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_sprintfe.30000644000175000017500000000141410016723511021360 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_sprintfe 3 2004-02-24 .SH NAME firestring_estr_sprintfe \- .BR firestring_estr_sprintf (3) with an estring format .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "long firestring_estr_sprintfe(struct firestring_estr_t *" "out" ", struct firestring_estr_t *" "format" ", " "..." ")" .SH DESCRIPTION firestring_estr_sprintfe() behaves exactly like .BR firestring_estr_snprintf (3) except that it takes an estring format argument, so the format can contain arbitrary binary data. However, please note that user user-input data as the format string is .BR INSECURE . .SH RETURN VALUE Returns the number of bytes written to .IR out . .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_malloc.30000644000175000017500000000134307451703045017752 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_malloc 3 2002-03-31 .SH NAME firestring_malloc \- .BR malloc (3) with internal result checking .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "void *firestring_malloc(const size_t " "size" ")" .SH DESCRIPTION firestring_malloc() acts exactly like .BR malloc (3) except that it detects malloc failures, prints an error and .BR exit (3) with exit status EXIT_FAILURE. In most programs, malloc failures are unrecoverable, and this is the preferred behaviour. .SH RETURN VALUE If firestring_malloc() returns, it .B always returns a new memory area of .I size bytes. It .B never returns .IR NULL. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_stristr.30000644000175000017500000000127507501257614021260 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_stristr 3 2002-06-10 .SH NAME firestring_estr_stristr \- search case-insensitively for a string in an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_stristr(struct firestring_estr_t *" "estring" ", const char *" "string" ", const int " "start" ")" .SH DESCRIPTION firestring_estr_stristr() searches .I estring case-insensitively from the index .I start to the end of the string for the string .IR string . .SH RETURN VALUE The index of the beginning of the string on success; -1 if the string did not occur in the range. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_vsprintfe.30000644000175000017500000000142610016723511021551 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_vsprintfe 3 2004-02-24 .SH NAME firestring_estr_vsprintfe \- .BR firestring_estr_vsprintf (3) with an estring format .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "long firestring_estr_vsprintfe(struct firestring_estr_t *" "out" ", struct firestring_estr_t *" "format" ", va_list " ap ")" .SH DESCRIPTION firestring_estr_vsprintfe() behaves exactly like .BR firestring_estr_vsprintf (3) except that it takes an estring format argument, so the format can contain arbitrary binary data. However, please note that user user-input data as the format string is .BR INSECURE . .SH RETURN VALUE Returns the number of bytes written to .IR out . .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_estrcpy.30000644000175000017500000000132707501262747021240 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_estrcpy 3 2002-06-10 .SH NAME firestring_estr_estrcpy \- copy an estring into another estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_estrcpy(struct firestring_estr_t *" "destination" ", struct firestring_estr_t *" "source" ", int " "start" ")" .SH DESCRIPTION firestring_estr_estrcpy() copys the contents of .I source from the index .I start into .IR destination , provided that there is room in .IR destination . .SH RETURN VALUE 0 if the string was copied successfully; 1 if there was insufficient space in .I destination for the copy to occur. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/libfirestring.30000644000175000017500000000772310023641030017102 0ustar useruser.\" (C) 2002 Ian Gulliver .TH libfirestring 3 2002-03-31 .SH NAME libfirestring \- library for safe, fast string handling .SH SYNOPSIS .B #include .br .B -lfirestring .SH DESCRIPTION libfirestring is a string handling library that provides maximum length aware string handling functions to programs. Several functions provide saner interfaces than the standard libc functions. libfirestring also provides functions that are in most libc's but not provided for by ANSI C, enabling programmers to write ANSI C-compliant code while using such safe functions (strcasecmp, strncasecmp, snprintf). libfirestring provides a set of functions for dealing with EStrings. EStrings are binary-safe objects that, when used with the firestring functions, are overflow safe, because they include allocated memory size information with them. libfirestring also includes functions for dealing with reading configuration files in an easy to program fashion. .HP Miscellaneous functions: .br .BR firestring_malloc (3) .br .BR firestring_realloc (3) .HP Starting-letter keys (for String and EString functions): .br .I n Length-safe (takes a .B size argument) .br .I e EString (length-safe and binary-safe, takes a .B struct firestring_estr_t argument) .br .I i Case-insensitive .br .I a Automatically expands EString to correct size (possible memory DoS attack in some cases) .br .I s Writes into a provided instead of to a stream .br .I f Writes into a specified stream instead of to standard output .HP Base library functions: .br .BR firestring_set_error_handler (3) .HP String functions: .br .BR firestring_strdup (3) .br .BR firestring_strncpy (3) .br .BR firestring_strncat (3) .br .BR firestring_snprintf (3) .br .BR firestring_strncasecmp (3) .br .BR firestring_strcasecmp (3) .br .BR firestring_concat (3) .br .BR firestring_chomp (3) .br .BR firestring_chug (3) .br .BR firestring_trim (3) .br .BR firestring_hextoi (3) .HP EString functions: .br .BR firestring_estr_alloc (3) .br .BR firestring_estr_expand (3) .br .BR firestring_estr_free (3) .br .BR firestring_estr_read (3) .br .BR firestring_estr_sprintf (3) .br .BR firestring_estr_sprintfe (3) .br .BR firestring_estr_vsprintf (3) .br .BR firestring_estr_vsprintfe (3) .br .BR firestring_estr_printf (3) .br .BR firestring_estr_printfe (3) .br .BR firestring_estr_fprintf (3) .br .BR firestring_estr_fprintfe (3) .br .BR firestring_estr_vfprintf (3) .br .BR firestring_estr_vfprintfe (3) .br .BR firestring_estr_strchr (3) .br .BR firestring_estr_strstr (3) .br .BR firestring_estr_stristr (3) .br .BR firestring_estr_starts (3) .br .BR firestring_estr_estarts (3) .br .BR firestring_estr_ends (3) .br .BR firestring_estr_eends (3) .br .BR firestring_estr_strcasecmp (3) .br .BR firestring_estr_strcmp (3) .br .BR firestring_estr_strcpy (3) .br .BR firestring_estr_astrcpy(3) .br .BR firestring_estr_strcat (3) .br .BR firestring_estr_astrcat(3) .br .BR firestring_estr_estrcasecmp (3) .br .BR firestring_estr_estrncasecmp (3) .br .BR firestring_estr_estrcpy (3) .br .BR firestring_estr_aestrcpy (3) .br .BR firestring_estr_estrcat (3) .br .BR firestring_estr_aestrcat (3) .br .BR firestring_estr_estrstr (3) .br .BR firestring_estr_estristr (3) .br .BR firestring_estr_replace (3) .br .BR firestring_estr_areplace (3) .br .BR firestring_estr_toupper (3) .br .BR firestring_estr_tolower (3) .br .BR firestring_estr_munch (3) .br .BR firestring_estr_chomp (3) .br .BR firestring_estr_chug (3) .br .BR firestring_estr_trim (3) .br .BR firestring_estr_0 (3) .br .BR firestring_estr_base64_encode (3) .br .BR firestring_estr_base64_decode (3) .br .BR firestring_estr_xml_encode (3) .br .BR firestring_estr_xml_decode (3) .HP Configuration file functions: .br .BR firestring_conf_parse (3) .br .BR firestring_conf_add (3) .br .BR firestring_conf_find (3) .br .BR firestring_conf_find_next (3) .br .BR firestring_conf_free (3) .SH FILES /usr/local/include/firestring.h .br /usr/local/lib/libfirestring.so .br /usr/local/lib/libfirestring.a .SH AUTHOR Ian Gulliver firedns/firestring/man/firestring_set_error_handler.30000644000175000017500000000212507707003661022204 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_set_error_handler 3 2003-07-21 .SH NAME firestring_set_error_handler \- set the function to be called on an allocation failure .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "void firestring_set_error_handler(void (*" "e" ")())" .SH DESCRIPTION firestring_set_error_handler() takes the name of a function that takes no parameters and returns void. This function will be called whenever firestring fails to allocate memory. As memory allocation failures are fatal to most programs, firestring does not return errors when functions fail to allocate memory; it simply calls this function, which it expects to call .I exit() or .I abort() or in some way terminate execution of the program. It probably is not safe to pass a function that returns, unless you have a framework in place for passing the allocation failure information back to the code calling the firestring function. The default function calls .I perror() and then .IR exit(). .SH RETURN VALUE None .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_conf_parse_next.30000644000175000017500000000133307564040347021663 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_conf_parse_next 3 2002-11-11 .SH NAME firestring_conf_parse_next \- add on to a previously parsed file .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "struct firestring_conf_t *firestring_conf_parse_next(const char *" "filename" ", struct firestring_conf_t *" "previous" ")" .SH DESCRIPTION firestring_conf_parse_next() attempts to read a configuration from .I filename and add the results to the previous values, overriding that are already set. .SH RETURN VALUE Returns a pointer to a structure containing the data read from the config file, or .I NULL if the file cannot be opened. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_chug.30000644000175000017500000000164107712223277020473 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_chug 3 2003-07-30 .SH NAME firestring_estr_chug \- remove whitespace from the beginning of an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "void firestring_estr_chug(struct firestring_estr_t *" "string" ")" .SH DESCRIPTION firestring_estr_chug shortens .I string by moving the start forward until the string begins with a non-whitespace character or is empty. .SH CAVEATS This function moves the starting pointer inside .IR string . If .I string was allocated with .IR firestring_estr_alloc (3), (as opposed to constructed manually pointing inside other memory), future calls to .IR firestring_estr_free (3) will fail if this function trimmed any space from the start of the string. In these cases, use .IR firestring_estr_ip_chug (3) instead. .SH RETURN VALUE None. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_0.30000644000175000017500000000101107501263341017663 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_0 3 2002-06-10 .SH NAME firestring_estr_0 \- append a trailing nil to an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "void firestring_estr_0(struct firestring_estr_t *" "estring" ")" .SH DESCRIPTION firestring_estr_0() appends a trailing nil ('\\0') to .I estring so that estring->s can be used in functions expecting normal C strings. .SH RETURN VALUE None. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_snprintf.30000644000175000017500000000257707660766256020377 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_snprintf 3 2003-05-15 .SH NAME firestring_snprintf \- .BR snprintf (3) provided as a replacement so programs can maintain ANSI C compliance .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "long firestring_snprintf(char * " "out" ", const size_t " "size" ", const char * const " "format" ", " "..." ")" .SH DESCRIPTION firestring_snprintf() writes a maximum of .I size bytes to .I out based on the formatting rules specified in .I format and the further arguments provided. .LP As .BR snprintf (3) is not a ANSI C function, firestring_snprintf() is provided as a replacement for programs wishing to maintain ANSI C compliance. It acts much like .BR snprintf (3), except that it only uses single-letter format tags, and only supports a subset of the common formats. .HP Formats supported: .br %s - char * .br %d - int .br %l - long .br %u - unsigned int .br %y - unsigned long .br %g - signed long long .br %o - unsigned long long .br %f - double .br %t - time_t (printed in ISO format) .br %e - struct firestring_estr_t * .LP The %s type handles NULL values by displaying the string "(null)". All numeric types support zero padding through the standard %02d format. .SH RETURN VALUE Returns the number of bytes written to .I out not including the trailing nil. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_fprintfe.30000644000175000017500000000130410023640406020303 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_fprintfe 3 2004-03-10 .SH NAME firestring_fprintfe \- .BR fprintf (3) with an estring format .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "long firestring_fprintfe(FILE * " stream ", struct firestring_estr_t *" "format" ", " "..." ")" .SH DESCRIPTION firestring_fprintfe() behaves exactly like .BR firestring_fprintf (3) except that it takes an estring format argument, so the format can contain arbitrary binary data. However, please note that user user-input data as the format string is .BR INSECURE . .SH RETURN VALUE Returns the number of bytes written. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_strcmp.30000644000175000017500000000100607501261150021034 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_strcmp 3 2002-06-10 .SH NAME firestring_estr_strcmp \- compare an estring and a string .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_strcmp(struct firestring_estr_t *" "estring" ", const char *" "string" ")" .SH DESCRIPTION firestring_estr_strcmp() compares .I estring and .IR string . .SH RETURN VALUE 0 if the strings match; 1 if they do not. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_areplace.30000644000175000017500000000134207707003661021314 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_replace 3 2003-07-21 .SH NAME firestring_estr_replace \- Replace occurences of one string with another, allocating space if needed .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_replace(struct firestring_estr_t * const " dest ", const struct firestring_estr_t * const " source ", const struct firestring_estr_t * const " to ", const struct firestring_estr_t * const " from ) .SH DESCRIPTION firestring_estr_replace() copies .I source into .IR dest , replacing all instances from .I from with .IR to . It allocates more space in .I dest if needed. .SH RETURN VALUE 0 .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_printf.30000644000175000017500000000105007660766256020017 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_printf 3 2003-05-15 .SH NAME firestring_printf \- .BR printf (3) with extended firestring types .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "long firestring_printf(const char * const " "format" ", " "..." ")" .SH DESCRIPTION firestring_printf() behaves exactly like .BR firestring_snprintf (3) except that it writes to the STDIO stream .IR stdout . .SH RETURN VALUE Returns the number of bytes written. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_strdup.30000644000175000017500000000135007451703045020022 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_strdup 3 2002-03-31 .SH NAME firestring_strdup \- .BR strdup (3) with internal result checking .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "char *firestring_strdup(const char * const " "input" ")" .SH DESCRIPTION firestring_strdup() acts exactly like .BR strdup (3) except that it detects malloc failures, prints an error and .BR exit (3) with exit status EXIT_FAILURE. In most programs, malloc failures are unrecoverable, and this is the preferred behaviour. .SH RETURN VALUE If firestring_strdup() returns, it .B always returns a copy of the string .IR input . It .B never returns .IR NULL . .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_base64_decode.30000644000175000017500000000162007564453006022131 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_base64_decode 3 2002-09-21 .SH NAME firestring_estr_base64_decode \- decode an estring encoded via base64 into another estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_base64_decode(struct firestring_estr_t *" "destination" ", struct firestring_estr_t *" "source" ")" .SH DESCRIPTION firestring_estr_base64_decode() decodes the contents of .I source using the base64 algorithm into .IR destination , provided that there is room in .IR destination . The minimum required space in destination is the length of source * 3 / 4 + 3. The buffers .I source and .I destination may be the same estring. .SH RETURN VALUE 0 if the string was decoded successfully; 1 if there was insufficient space in .I destination for the decoding to occur. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_estrncasecmp.30000644000175000017500000000124407501262311022217 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_estrncasecmp 3 2002-06-10 .SH NAME firestring_estr_estrncasecmp \- compare two estring segments case-insensitively .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_estrncasecmp(struct firestring_estr_t *" "estring1" ", struct firestring_estr_t *" "estring2" ", int " "length" ", int " "start" ")" .SH DESCRIPTION firestring_estr_estrncasecmp() compares .I lengths bytes of .I estring1 from .I start on with .I estring2 case-insensitively. .SH RETURN VALUE 0 if the string segments match; 1 if they do not. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_xml_decode.30000644000175000017500000000164307543171730021650 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_xml_decode 3 2002-09-21 .SH NAME firestring_estr_xml_decode \- decode an estring from XML quoted data into ASCII into another estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_xml_decode(struct firestring_estr_t *" "destination" ", struct firestring_estr_t *" "source" ")" .SH DESCRIPTION firestring_estr_xml_decode() decodes the contents of .I source by converting XML entities back into their ASCII/ISO equivalents. It places the output in .IR destination , provided that there is room in .IR destination . The minimum required space in destination is the length of source; in fact, they can be the same estring. .SH RETURN VALUE 0 if the string was decoded successfully; 1 if there was insufficient space in .I destination for the decoding to occur. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_astrcat.30000644000175000017500000000104307706774115021207 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_astrcat 3 2003-07-21 .SH NAME firestring_estr_astrcat \- concatenate a string onto an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_astrcat(struct firestring_estr_t *" "estring" ", const char *" "string" ")" .SH DESCRIPTION firestring_estr_astrcat() copys the contents of .I string onto the end of .IR estring , expanding .I estring if necessary. .SH RETURN VALUE 0 .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_chomp.30000644000175000017500000000100007713510327020634 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_chomp 3 2003-05-15 .SH NAME firestring_estr_chomp \- remove whitespace from the end of an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "void firestring_estr_chomp(struct firestring_estr_t *" "string" ")" .SH DESCRIPTION firestring_estr_chomp shortens .I string until the string ends with a non-whitespace character or is empty. .SH RETURN VALUE None. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_conf_find_next.30000644000175000017500000000160707455371107021475 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_conf_find_next 3 2002-03-31 .SH NAME firestring_conf_find_next \- retrieve an array value from a configuration structure .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "const char *firestring_conf_find_next(struct firestring_conf_t *" "config" ", const char *" "var" ", const char *" "prev" ")" .SH DESCRIPTION firestring_conf_find_next() retrieves a subsequent value of the variable .I var from the configuration structure .IR config. .I prev is a pointer previously returned by firestring_conf_find() or firestring_conf_find_next(). If .I prev is .IR NULL , firestring_conf_find_next() acts like firestring_conf_find(). .SH RETURN VALUE Returns a .I const char * to the next value of the variable, or .I NULL if there are no further values for .IR var . .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_starts.30000644000175000017500000000110007501257614021051 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_starts 3 2002-06-10 .SH NAME firestring_estr_starts \- check case-insensitively if an estring starts with a string .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_starts(struct firestring_estr_t *" "estring" ", const char *" "string" ")" .SH DESCRIPTION firestring_estr_starts() checks case-insensitively if .I string appears at the beginning of .IR estring . .SH RETURN VALUE 0 on success; 1 on failure. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_strncasecmp.30000644000175000017500000000130707660766256021044 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_strncasecmp 3 2003-05-15 .SH NAME firestring_strncasecmp \- .BR strncasecmp (3) provided as a replacement so programs can maintain ANSI C compliance .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_strncasecmp(const char * const " "s1" ", const char * const " "s2" ", const long " "n" ")" .SH DESCRIPTION firestring_strcasecmp() compares the first .I size bytes of .I s1 and .I s2 in a case insensitive fashion. .SH RETURN VALUE Returns .I -1 if the first .I n bytes of s1 < s2, .I 1 if the s2 segment > s1, and .I 0 if the strings segments do match. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_strcasecmp.30000644000175000017500000000115007474172741020653 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_strcasecmp 3 2002-03-31 .SH NAME firestring_strcasecmp \- .BR strcasecmp (3) provided as a replacement so programs can maintain ANSI C compliance .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_strcasecmp(const char * const " "s1" ", const char * const " "s2" ")" .SH DESCRIPTION firestring_strcasecmp() compares .I s1 and .I s2 in a case insensitive fashion. .SH RETURN VALUE Returns .I -1 if s1 < s2, .I 1 if s1 > s2, and and .I 0 if the strings match. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_strcpy.30000644000175000017500000000120507501261662021061 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_strcpy 3 2002-06-10 .SH NAME firestring_estr_strcpy \- copy a string into an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_strcpy(struct firestring_estr_t *" "estring" ", const char *" "string" ")" .SH DESCRIPTION firestring_estr_strcpy() copys the contents of .I string into .IR estring , provided that there is room in .IR estring . .SH RETURN VALUE 0 if the string was copied successfully; 1 if there was insufficient space in .I estring for the copy to occur. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_expand.30000644000175000017500000000112607543171730021020 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_expand 3 2002-09-21 .SH NAME firestring_estr_expand \- expand an estring's space to a minimum length .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "void firestring_estr_expand(struct firestring_estr_t *" "estring" ", int " "size" ")" .SH DESCRIPTION firestring_estr_expand() uses .BR firestring_realloc (3) to allocate at least .I size bytes in .IR estring . If .I estring is already this size or greater, it does nothing. .SH RETURN VALUE None. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_toupper.30000644000175000017500000000145107707006563021243 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_toupper 3 2003-07-21 .SH NAME firestring_estr_toupper \- convert all letters in an estring to upper case .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_toupper(struct firestring_estr_t *" "dest" ", struct firestring_estr_t *" "source" ", const long " start ")" .SH DESCRIPTION firestring_estr_toupper() copies the data in .I source starting at position .I start to .IR dest , replacing any lowercase characters with uppercase ones by using .IR toupper (3). .I source and .I dest can be the same string. .SH RETURN VALUE 0 if the string was copied successfully; 1 if there was insufficient space in .I destination for the copy to occur. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_base64_encode.30000644000175000017500000000150407543171730022142 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_base64_encode 3 2002-09-21 .SH NAME firestring_estr_base64_encode \- encode an estring via base64 into another estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_base64_encode(struct firestring_estr_t *" "destination" ", struct firestring_estr_t *" "source" ")" .SH DESCRIPTION firestring_estr_base64_encode() encodes the contents of .I source using the base64 algorithm into .IR destination , provided that there is room in .IR destination . The minimum required space in destination is the length of source * 4 / 3 + 4. .SH RETURN VALUE 0 if the string was encoded successfully; 1 if there was insufficient space in .I destination for the encoding to occur. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_xml_encode.30000644000175000017500000000154407543171730021662 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_xml_encode 3 2002-09-21 .SH NAME firestring_estr_xml_encode \- encode an estring into another estring for transmission inside XML data .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_xml_encode(struct firestring_estr_t *" "destination" ", struct firestring_estr_t *" "source" ")" .SH DESCRIPTION firestring_estr_xml_encode() encodes the contents of .I source by escaping characters that might trigger XML processing into .IR destination , provided that there is room in .IR destination . The minimum required space in destination is the length of source * 6. .SH RETURN VALUE 0 if the string was encoded successfully; 1 if there was insufficient space in .I destination for the encoding to occur. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_estrcasecmp.30000644000175000017500000000115207501262311022037 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_estrcasecmp 3 2002-06-10 .SH NAME firestring_estr_estrcasecmp \- compare two estrings case-insensitively .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_estrcasecmp(struct firestring_estr_t *" "estring1" ", struct firestring_estr_t *" "estring2" ", int " "start" ")" .SH DESCRIPTION firestring_estr_estrcasecmp() compares .I estring1 from .I start on with .I estring2 case-insensitively. .SH RETURN VALUE 0 if the strings match; 1 if they do not. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_conf_find.30000644000175000017500000000142307452476233020436 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_conf_find 3 2002-03-31 .SH NAME firestring_conf_find \- retrieve a value from a configuration structure .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "const char *firestring_conf_find(struct firestring_conf_t *" "config" ", const char *" "var" ")" .SH DESCRIPTION firestring_conf_find() retrieves the value of the variable .I var from the configuration structure .IR config. If there is more than one variable with the name .IR var, firestring_conf_find() returns the one with precedence (the last one added). .SH RETURN VALUE Returns a .I const char * to the value of the variable, or .I NULL if there is no variable by the name .IR var . .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_strncpy.30000644000175000017500000000111307451703045020200 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_strncpy 3 2002-03-31 .SH NAME firestring_strncpy \- .BR strncpy (3) with slightly saner semantics .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "void firestring_strncpy(char * const " "to" ", const char * const " "from" ", const size_t " "size" ")" .SH DESCRIPTION firestring_strncpy() acts like .BR strncpy (3) except that .I to will always contain a trailing nil, even if the function runs out of space. .SH RETURN VALUE Always succeeds. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_tolower.30000644000175000017500000000145107707006563021240 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_tolower 3 2003-07-21 .SH NAME firestring_estr_tolower \- convert all letters in an estring to lower case .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_tolower(struct firestring_estr_t *" "dest" ", struct firestring_estr_t *" "source" ", const long " start ")" .SH DESCRIPTION firestring_estr_tolower() copies the data in .I source starting at position .I start to .IR dest , replacing any uppercase characters with lowercase ones by using .IR tolower (3). .I source and .I dest can be the same string. .SH RETURN VALUE 0 if the string was copied successfully; 1 if there was insufficient space in .I destination for the copy to occur. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_read.30000644000175000017500000000135607501705226020456 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_read 3 2002-06-10 .SH NAME firestring_estr_read \- read from a file descriptor into an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_read(struct firestring_estr_t *" "estring" ", int " "fd" ")" .SH DESCRIPTION firestring_estr_read() .BR read (2)'s as much data as is available from .I fd and will fit in .I estring onto the end of the data that is already there. It updates the length of the string accordingly. .SH RETURN VALUE 0 on success. 1 with errno set properly if read returns an error or indicates EOF. 2 if there is no space in the buffer for further reads. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_estarts.30000644000175000017500000000112210023640747021216 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_estarts 3 2004-03-10 .SH NAME firestring_estr_estarts \- check case-insensitively if an estring starts with an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_starts(struct firestring_estr_t *" "estring" ", struct firestring_estr_t *" "needle" ")" .SH DESCRIPTION firestring_estr_starts() checks case-insensitively if .I needle appears at the beginning of .IR estring . .SH RETURN VALUE 0 on success; 1 on failure. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/man/firestring_estr_munch.30000644000175000017500000000112007660766256020662 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firestring_estr_munch 3 2003-05-15 .SH NAME firestring_estr_munch \- remove characters from the beginning of an estring .SH SYNOPSIS .B #include .br .B -lfirestring .LP .BI "int firestring_estr_munch(struct firestring_estr_t *" "string" ", const long " length ")" .SH DESCRIPTION firestring_estr_munch removes the first .I length characters from .IR string. .SH RETURN VALUE 0 on success, non-zero if there were not enough characters in the string to begin with. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfirestring (3) firedns/firestring/firemake.binaries0000644000175000017500000000003607505674730016717 0ustar userusertester: firestring.o tester.o firedns/firestring/firestring.h0000644000175000017500000002052310023361144015723 0ustar useruser/* firestring.h - FireString string function declarations Copyright (C) 2000 Ian Gulliver This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _FIRESTRING_H #define _FIRESTRING_H #include #include #include #include #ifndef _FIRESTRING_C extern const char *firestring_version; #endif #define ESTR_S(x) ((struct firestring_estr_t) { x, sizeof(x), sizeof(x) - 1 }) #define ESTR_D(x) ((struct firestring_estr_t) { x, strlen(x), strlen(x) }) struct firestring_conf_t { char *var; char *value; struct firestring_conf_t *next; }; enum firestring_conf_parse_line_result { FSC_INCOMPLETE = -1, FSC_VALID = 0, FSC_MALFORMED = 1, }; struct firestring_conf_keyword_t { const char *keyword; enum firestring_conf_parse_line_result (*callback)(char *line, struct firestring_conf_t **conf); }; struct firestring_estr_t { char *s; long a; long l; }; void firestring_set_error_handler(void (*e)()); void *firestring_malloc(const size_t size); void *firestring_realloc(void *old, const size_t new); char *firestring_strdup(const char * const input); void firestring_strncpy(char * const to, const char * const from, const size_t size); void firestring_strncat(char * const to, const char * const from, const size_t size); long firestring_printf(const char * const format, ...); long firestring_fprintf(FILE *stream, const char * const format, ...); long firestring_vfprintf(FILE *stream, const char * const format, va_list ap); long firestring_printfe(const struct firestring_estr_t * const format, ...); long firestring_fprintfe(FILE *stream, const struct firestring_estr_t * const format, ...); long firestring_vfprintfe(FILE *stream, const struct firestring_estr_t * const format, va_list ap); long firestring_snprintf(char * const out, const long size, const char * const format, ...); int firestring_strncasecmp(const char * const s1, const char * const s2, const long n); int firestring_strcasecmp(const char * const s1, const char * const s2); char *firestring_concat(const char *s, ...); char *firestring_chomp(char *s); char *firestring_chug(char *s); char *firestring_trim(char *s); int firestring_hextoi(const char * const input); /* estr functions */ void firestring_estr_alloc(struct firestring_estr_t * const f, const long a); void firestring_estr_expand(struct firestring_estr_t * const f, const long a); void firestring_estr_free(struct firestring_estr_t * const f); int firestring_estr_base64_encode(struct firestring_estr_t * const t, const struct firestring_estr_t * const f); int firestring_estr_base64_decode(struct firestring_estr_t * const t, const struct firestring_estr_t * const f); int firestring_estr_xml_encode(struct firestring_estr_t * const t, const struct firestring_estr_t * const f); int firestring_estr_xml_decode(struct firestring_estr_t * const t, const struct firestring_estr_t * const f); int firestring_estr_read(struct firestring_estr_t * const f, const int fd); long firestring_estr_sprintf(struct firestring_estr_t * const o, const char * const format, ...); long firestring_estr_vsprintf(struct firestring_estr_t * const o, const char * const format, va_list ap); long firestring_estr_sprintfe(struct firestring_estr_t * const o, const struct firestring_estr_t * const format, ...); long firestring_estr_vsprintfe(struct firestring_estr_t * const o, const struct firestring_estr_t * const format, va_list ap); long firestring_estr_strchr(const struct firestring_estr_t * const f, const char c, const long start); long firestring_estr_strstr(const struct firestring_estr_t * const f, const char * const s, const long start); long firestring_estr_stristr(const struct firestring_estr_t * const f, const char * const s, const long start); int firestring_estr_starts(const struct firestring_estr_t * const f, const char * const s); int firestring_estr_ends(const struct firestring_estr_t * const f, const char * const s); int firestring_estr_estarts(const struct firestring_estr_t * const f, const struct firestring_estr_t * const s); int firestring_estr_eends(const struct firestring_estr_t * const f, const struct firestring_estr_t * const s); int firestring_estr_strcasecmp(const struct firestring_estr_t * const f, const char * const s); int firestring_estr_strcmp(const struct firestring_estr_t * const f, const char * const s); int firestring_estr_strcpy(struct firestring_estr_t * const f, const char * const s); int firestring_estr_astrcpy(struct firestring_estr_t * const f, const char * const s); int firestring_estr_strcat(struct firestring_estr_t * const f, const char * const s); int firestring_estr_astrcat(struct firestring_estr_t * const f, const char * const s); int firestring_estr_estrcasecmp(const struct firestring_estr_t * const t, const struct firestring_estr_t * const f, const long start); int firestring_estr_estrncasecmp(const struct firestring_estr_t * const t, const struct firestring_estr_t * const f, const long length, const long start); int firestring_estr_estrcpy(struct firestring_estr_t * const t, const struct firestring_estr_t * const f, const long start); int firestring_estr_aestrcpy(struct firestring_estr_t * const t, const struct firestring_estr_t * const f, const long start); int firestring_estr_munch(struct firestring_estr_t * const t, const long length); void firestring_estr_chomp(struct firestring_estr_t * const s); void firestring_estr_chug(struct firestring_estr_t * const s); void firestring_estr_ip_chug(struct firestring_estr_t * const s); void firestring_estr_trim(struct firestring_estr_t * const s); void firestring_estr_ip_trim(struct firestring_estr_t * const s); int firestring_estr_estrcmp(const struct firestring_estr_t * const t, const struct firestring_estr_t * const f, const long start); int firestring_estr_estrcat(struct firestring_estr_t * const t, const struct firestring_estr_t * const f, const long start); int firestring_estr_aestrcat(struct firestring_estr_t * const t, const struct firestring_estr_t * const f, const long start); long firestring_estr_estrstr(const struct firestring_estr_t * const haystack, const struct firestring_estr_t * const needle, const long start); long firestring_estr_estristr(const struct firestring_estr_t * const haystack, const struct firestring_estr_t * const needle, const long start); int firestring_estr_replace(struct firestring_estr_t * const dest, const struct firestring_estr_t * const source, const struct firestring_estr_t * const to, const struct firestring_estr_t * const from); int firestring_estr_areplace(struct firestring_estr_t * const dest, const struct firestring_estr_t * const source, const struct firestring_estr_t * const to, const struct firestring_estr_t * const from); int firestring_estr_tolower(struct firestring_estr_t * const dest, const struct firestring_estr_t * const source, const long start); int firestring_estr_toupper(struct firestring_estr_t * const dest, const struct firestring_estr_t * const source, const long start); void firestring_estr_0(struct firestring_estr_t * const f); /* configuration system functions */ struct firestring_conf_t *firestring_conf_parse(const char * const filename); struct firestring_conf_t *firestring_conf_parse_next(const char * const filename, struct firestring_conf_t *prev); enum firestring_conf_parse_line_result firestring_conf_parse_line(const char *line, const struct firestring_conf_keyword_t keywords[], struct firestring_conf_t **conf, char **context); struct firestring_conf_t *firestring_conf_add(struct firestring_conf_t * const next, const char * const var, const char * const value); struct firestring_conf_t *firestring_conf_delete(struct firestring_conf_t *conf, const char *var); char *firestring_conf_find(const struct firestring_conf_t *config, const char * const var); char *firestring_conf_find_next(const struct firestring_conf_t *config, const char * const var, const char * const prev); void firestring_conf_free(struct firestring_conf_t *config); #endif firedns/firestring/firemake/0000755000175000017500000000000010023637416015167 5ustar useruserfiredns/firestring/firemake/cc0000644000175000017500000000054010013014330015455 0ustar useruser#!/bin/sh #phase init dispn "Checking for a compiler..." if test "$CC" != ""; then disp "found in environment: \"$CC\"" elif (gcc --version >/dev/null 2>/dev/null; test "$?" = "0"); then disp "found gcc" CC="gcc" elif (CC=`which cc`; test "$?" = "0" -a -x "$CC"); then disp "found cc" CC="cc" else disp "not found, unable to continue" exit 1 fi firedns/firestring/firemake/cflags0000644000175000017500000000102007660737511016354 0ustar useruser#!/bin/sh #require cc #phase init #after init_cc dispn "Attempting to determine correct CFLAGS..." if test ! "$CFLAGS" = ""; then disp "CFLAGS provided by environment: \"$CFLAGS\"" FM_CFLAGS="$CFLAGS" elif test "`basename $CC`" = "gcc"; then disp "compiler is gcc, using \"-O20 -fstrict-aliasing -funroll-loops -fexpensive-optimizations -fomit-frame-pointer\"" FM_CFLAGS="-O20 -fstrict-aliasing -funroll-loops -fexpensive-optimizations -fomit-frame-pointer" else disp "compiler is unknown, using \"-O\"" FM_CFLAGS="-O" fi firedns/firestring/firemake/binaries0000644000175000017500000000533310023637416016712 0ustar useruser#!/bin/sh #require prefix #require strip #require makefiletop #phase config #phase makefile #after makefile_makefiletop case $PHASE in config) dispn "Reading firemake.binaries..." BINARIES=`cut -d ':' -f 1 firemake.binaries 2>/dev/null` disp "done" dispn "Reading firemake.sbinaries..." SBINARIES=`cut -d ':' -f 1 firemake.sbinaries 2>/dev/null` disp "done" dispn "Reading firemake.suidbinaries..." SUIDBINARIES=`cut -d ':' -f 1 firemake.suidbinaries 2>/dev/null` FULLBINARIES="$BINARIES $SBINARIES $SUIDBINARIES" dispn "Reading firemake.noinstall..." NOINSTALL=`cat firemake.noinstall 2>/dev/null` disp "done" ;; makefile) disp "Writing binary creation entries..." for BINARY in $FULLBINARIES; do dispn " $BINARY..." DEPS="`grep \"^$BINARY:\" firemake.binaries 2>/dev/null | cut -d ':' -f 2` `grep \"^$BINARY:\" firemake.sbinaries 2>/dev/null | cut -d ':' -f 2` `grep \"^$BINARY:\" firemake.suidbinaries 2>/dev/null | cut -d ':' -f 2`" $ECHO "$BINARY: $DEPS" $ECHO " $CC $FM_CFLAGS $FM_LDFLAGS -o $BINARY $DEPS $FM_STATICLIBS $FM_LIBS" $ECHO BINARYLIST="$BINARYLIST $BINARY" BINARY_CLEANLIST="$BINARY_CLEANLIST $BINARY $DEPS" disp "done" if module dependencies; then DEPPREPEND="$PREPEND" PREPEND="$PREPEND " customdeplist "$DEPS" PREPEND="$DEPPREPEND" fi done dispn "Writing binary index entry..." $ECHO "binaries: $BINARYLIST" $ECHO disp "done" disp "Writing binary install entries..." $ECHO "install_binaries: $BINARYLIST" for BINARY in $BINARIES; do $ECHO "$NOINSTALL" | grep "^$BINARY\$" >/dev/null 2>/dev/null if test "$?" = "0"; then disp " skipping $BINARY" else dispn " $BINARY..." $ECHO " $INSTALL $BINARY \$(BINDIR) $INSTALL_USER $INSTALL_GROUP 0755" if test "$STRIP" != ""; then $ECHO " $STRIP \$(BINDIR)/$BINARY" fi disp "done" fi done for BINARY in $SBINARIES; do $ECHO "$NOINSTALL" | grep "^$BINARY\$" >/dev/null 2>/dev/null if test "$?" = "0"; then disp " skipping $BINARY" else dispn " $BINARY..." $ECHO " $INSTALL $BINARY \$(SBINDIR) $INSTALL_USER $INSTALL_GROUP 0755" if test "$STRIP" != ""; then $ECHO " $STRIP \$(SBINDIR)/$BINARY" fi disp "done" fi done for BINARY in $SUIDBINARIES; do $ECHO "$NOINSTALL" | grep "^$BINARY\$" >/dev/null 2>/dev/null if test "$?" = "0"; then disp " skipping $BINARY" else dispn " $BINARY..." $ECHO " $INSTALL $BINARY \$(BINDIR) $INSTALL_USER $INSTALL_GROUP 4755" if test "$STRIP" != ""; then $ECHO " $STRIP \$(BINDIR)/$BINARY" fi disp "done" fi done $ECHO dispn "Writing binary cleanup entry..." $ECHO "clean_binaries:" $ECHO " rm -f $BINARY_CLEANLIST" $ECHO disp "done" ;; esac firedns/firestring/firemake/gcvt0000644000175000017500000000053407777067417016103 0ustar useruser#!/bin/sh #require compiletest #require cflags #phase init #after init_cflags case $PHASE in init) dispn "Checking for gcvt()..." PROGRAM="#include int main () { char buf[16]; gcvt(1.0,8,buf); return 0; }" compile_test_wrapper "$PROGRAM" "-DHAVE_GCVT" "" "" || \ disp "not found, some functionality may be missing" ;; esac firedns/firestring/firemake/version0000644000175000017500000000054207711277061016606 0ustar useruser#!/bin/sh #require cflags #phase config dispn "Reading firemake.version..." VERSION=`cat firemake.version 2>/dev/null` if test "$?" = "0"; then disp "done, \"$VERSION\"" else disp "not found, using \"0.0.0\"" VERSION="0.0.0" fi dispn "Adding -DVERSION=\"\\\"$VERSION\\\"\" to CFLAGS..." FM_CFLAGS="$FM_CFLAGS -DVERSION=\"\\\"$VERSION\\\"\"" disp done firedns/firestring/firemake/make0000644000175000017500000000041007763175057016041 0ustar useruser#!/bin/sh #phase init dispn "Checking to see if make supports \"?=\"..." rm -f Makefile echo "PREFIX ?= /usr/local" > Makefile echo "all:" >> Makefile make >/dev/null 2>&1 if test "$?" = "0"; then disp "yes" MAKE_CONDSET="y" else disp "no" MAKE_CONDSET="n" fi firedns/firestring/firemake/headers0000644000175000017500000000072107763175057016544 0ustar useruser#!/bin/sh #require prefix #require makefiletop #phase config #phase makefile #after makefile_makefiletop case $PHASE in config) dispn "Reading firemake.headers..." HEADERS=`cat firemake.headers 2>/dev/null` disp "done" ;; makefile) dispn "Writing header installation entry..." $ECHO "install_headers:" for HEADER in $HEADERS; do $ECHO " $INSTALL $HEADER \$(INCLUDEDIR) $INSTALL_USER $INSTALL_GROUP 0644" done $ECHO disp "done" ;; esac firedns/firestring/firemake/id0000644000175000017500000000035707660737511015525 0ustar useruser#!/bin/sh #phase init dispn "Checking for id..." if /usr/xpg4/bin/id 2>/dev/null; then disp "found, /usr/xpg4/bin/id" ID="/usr/xpg4/bin/id" elif id 2>/dev/null; then disp "found, id" ID="id" else disp "not found, aborting" exit 1 fi firedns/firestring/firemake/libraries0000644000175000017500000000625310013014330017053 0ustar useruser#!/bin/sh #require prefix #require compiletest #require cflags #require version #phase init #after init_cflags #phase config #phase makefile #after makefile_makefiletop case $PHASE in init) PROGRAM="int foo() { return 0; }" dispn "Checking if your compiler supports -fPIC..." if library_test "$PROGRAM" "-fPIC" ""; then disp "yes, adding \"-fPIC\" to CFLAGS" FM_CFLAGS="$FM_CFLAGS -fPIC" else disp "no, hoping we don't need it" fi dispn "Checking if your compiler supports -shared..." if shared_test "$PROGRAM" "-shared" ""; then disp "yes, adding \"-shared\" to SHAREDFLAGS" FM_SHAREDFLAGS="$FM_SHAREDFLAGS -shared" else disp "no, hoping we don't need it" fi dispn "Checking if your compiler supports -dynamiclib -lcc_dynamic..." # this is a bad hack for Darwin if shared_test "$PROGRAM" "-dynamiclib" "-lcc_dynamic"; then disp "yes:" disp " Adding \"-dynamiclib\" to SHAREDFLAGS" FM_SHAREDFLAGS="$FM_SHAREDFLAGS -dynamiclib" disp " Adding \"-dynamiclib\" to SHAREDLIBS" FM_SHAREDLIBS="$FM_SHAREDLIBS -lcc_dynamic" else disp "no, hoping we don't need it" fi rm -f compiletest.c.* dispn "Checking for SONAME support..." if shared_test "$PROGRAM" "-Wl,-soname,testname.so.0" ""; then disp "yes" FM_SONAME="-Wl,-soname," else disp "no" FM_SONAME="" fi ;; config) dispn "Reading firemake.libraries..." LIBRARIES=`cut -d ':' -f 1 firemake.libraries 2>/dev/null` disp "done" ;; makefile) VERSION2=`$ECHO "$VERSION" | cut -d . -f 1-2` disp "Writing library creation entries..." for LIBRARY in $LIBRARIES; do dispn " $LIBRARY..." DEPS=`grep "^$LIBRARY:" firemake.libraries | cut -d ':' -f 2` $ECHO "$LIBRARY: $LIBRARY.a $LIBRARY.so.$VERSION" $ECHO $ECHO "$LIBRARY.a: $DEPS" $ECHO " rm -f $LIBRARY.a" $ECHO " ar cru $LIBRARY.a $DEPS $FM_STATICLIBS" $ECHO " ranlib $LIBRARY.a || $ECHO \"Ignore ranlib errors.\"" $ECHO if test "$FM_SONAME" != ""; then SOTEMP="$FM_SONAME$LIBRARY.so.$VERSION2" else SOTEMP="" fi $ECHO "$LIBRARY.so.$VERSION: $DEPS" $ECHO " $CC $FM_CFLAGS $FM_LDFLAGS $FM_SHAREDFLAGS $SOTEMP -o $LIBRARY.so.$VERSION $DEPS $FM_STATICLIBS $FM_LIBS $FM_SHAREDLIBS" $ECHO LIBRARYLIST="$LIRBRARYLIST $LIBRARY" LIBRARY_CLEANLIST="$LIBRARY_CLEANLIST ${LIBRARY}.a ${LIBRARY}.so.$VERSION $DEPS" disp "done" if module dependencies; then DEPPREPEND="$PREPEND" PREPEND="$PREPEND " customdeplist "$DEPS" PREPEND="$DEPPREPEND" fi done dispn "Writing library index entry..." $ECHO "libraries: $LIBRARYLIST" $ECHO disp "done" disp "Writing library install entries..." $ECHO "install_libraries: $LIBRARYLIST" for LIBRARY in $LIBRARIES; do dispn " $LIBRARY..." $ECHO " $INSTALL ${LIBRARY}.a \$(LIBDIR) $INSTALL_USER $INSTALL_GROUP 0755" $ECHO " $INSTALL ${LIBRARY}.so.$VERSION \$(LIBDIR) $INSTALL_USER $INSTALL_GROUP 0755" $ECHO " ln -sf ${LIBRARY}.so.$VERSION \$(LIBDIR)/${LIBRARY}.so.$VERSION2" $ECHO " ln -sf ${LIBRARY}.so.$VERSION \$(LIBDIR)/${LIBRARY}.so" disp "done" done $ECHO dispn "Writing library cleanup entry..." $ECHO "clean_libraries:" $ECHO " rm -f $LIBRARY_CLEANLIST" $ECHO disp "done" ;; esac firedns/firestring/firemake/man0000644000175000017500000000360207763175057015705 0ustar useruser#!/bin/sh #require makefiletop #require prefix #phase config #phase makefile #after makefile_makefiletop case $PHASE in config) dispn "Checking for manpages for section 1..." MAN1=`ls man/*.1 2>/dev/null` disp "done" dispn "Checking for manpages for section 3..." MAN3=`ls man/*.3 2>/dev/null` disp "done" dispn "Checking for manpages for section 5..." MAN5=`ls man/*.5 2>/dev/null` disp "done" dispn "Checking for manpages for section 6..." MAN6=`ls man/*.6 2>/dev/null` disp "done" dispn "Checking for manpages for section 7..." MAN7=`ls man/*.7 2>/dev/null` disp "done" dispn "Checking for manpages for section 8..." MAN8=`ls man/*.8 2>/dev/null` disp "done" ;; makefile) disp "Writing manpage installation entries..." $ECHO "install_man:" if test "$MAN1" != ""; then dispn " Section 1..." for MAN in $MAN1; do $ECHO " $INSTALL $MAN \$(MANDIR)/man1 $INSTALL_USER $INSTALL_GROUP 0644" done disp "done" fi if test "$MAN3" != ""; then dispn " Section 3..." for MAN in $MAN3; do $ECHO " $INSTALL $MAN \$(MANDIR)/man3 $INSTALL_USER $INSTALL_GROUP 0644" done disp "done" fi if test "$MAN5" != ""; then dispn " Section 5..." for MAN in $MAN5; do $ECHO " $INSTALL $MAN \$(MANDIR)/man5 $INSTALL_USER $INSTALL_GROUP 0644" done disp "done" fi if test "$MAN6" != ""; then dispn " Section 6..." for MAN in $MAN6; do $ECHO " $INSTALL $MAN \$(MANDIR)/man6 $INSTALL_USER $INSTALL_GROUP 0644" done disp "done" fi if test "$MAN7" != ""; then dispn " Section 7..." for MAN in $MAN7; do $ECHO " $INSTALL $MAN \$(MANDIR)/man7 $INSTALL_USER $INSTALL_GROUP 0644" done disp "done" fi if test "$MAN8" != ""; then dispn " Section 8..." for MAN in $MAN8; do $ECHO " $INSTALL $MAN \$(MANDIR)/man8 $INSTALL_USER $INSTALL_GROUP 0644" done disp "done" fi $ECHO ;; esac firedns/firestring/firemake/prefix0000644000175000017500000000376307763175057016437 0ustar useruser#!/bin/sh #require cflags #phase init #after init_cflags dispn "Attempting to determine correct PREFIX..." if test ! "$PREFIX" = ""; then disp "PREFIX provided by environment: \"$PREFIX\"" FM_PREFIX="$PREFIX" else disp "prefix is unknown, using \"/usr/local\"" FM_PREFIX="/usr/local" fi dispn "Attempting to determine correct BINDIR..." if test ! "$BINDIR" = ""; then disp "BINDIR provided by environment: \"$BINDIR\"" FM_BINDIRSTRICT="y" FM_BINDIR="$BINDIR" else disp "bindir is unknown, deriving from PREFIX: \"$FM_PREFIX/bin\"" FM_BINDIR="$FM_PREFIX/bin" fi dispn "Attempting to determine correct SBINDIR..." if test ! "$SBINDIR" = ""; then disp "SBINDIR provided by environment: \"$SBINDIR\"" FM_SBINDIRSTRICT="y" FM_SBINDIR="$SBINDIR" else disp "sbindir is unknown, deriving from PREFIX: \"$FM_PREFIX/sbin\"" FM_SBINDIR="$FM_PREFIX/sbin" fi dispn "Attempting to determine correct MANDIR..." if test ! "$MANDIR" = ""; then disp "MANDIR provided by environment: \"$MANDIR\"" FM_MANDIRSTRICT="y" FM_MANDIR="$MANDIR" else disp "mandir is unknown, deriving from PREFIX: \"$FM_PREFIX/man\"" FM_MANDIR="$FM_PREFIX/man" fi dispn "Attempting to determine correct CONFDIR..." if test ! "$CONFDIR" = ""; then disp "CONFDIR provided by environment: \"$CONFDIR\"" FM_CONFDIRSTRICT="y" FM_CONFDIR="$CONFDIR" else disp "confdir is unknown, deriving from PREFIX: \"$FM_PREFIX/etc\"" FM_CONFDIR="$FM_PREFIX/etc" fi dispn "Attempting to determine correct LIBDIR..." if test ! "$LIBDIR" = ""; then disp "LIBDIR provided by environment: \"$LIBDIR\"" FM_LIBDIRSTRICT="y" FM_LIBDIR="$LIBDIR" else disp "libdir is unknown, deriving from PREFIX: \"$FM_PREFIX/lib\"" FM_LIBDIR="$FM_PREFIX/lib" fi dispn "Attempting to determine correct INCLUDEDIR..." if test ! "$INCLUDEDIR" = ""; then disp "INCLUDEDIR provided by environment: \"$INCLUDEDIR\"" FM_INCLUDEDIRSTRICT="y" FM_INCLUDEDIR="$INCLUDEDIR" else disp "includedir is unknown, deriving from PREFIX: \"$FM_PREFIX/include\"" FM_INCLUDEDIR="$FM_PREFIX/include" fi firedns/firestring/firemake/makefiletop0000644000175000017500000000427507777067417017446 0ustar useruser#!/bin/sh #require prefix #require make #phase makefile dispn "Writing Makefile top entries..." if test "$MAKE_CONDSET" = "y"; then $ECHO "PREFIX ?= $FM_PREFIX" if test "$FM_MANDIRSTRICT" = "y"; then $ECHO "MANDIR ?= $FM_MANDIR" else $ECHO "MANDIR ?= \$(PREFIX)/man" fi if test "$FM_CONFDIRSTRICT" = "y"; then $ECHO "CONFDIR ?= $FM_CONFDIR" else $ECHO "CONFDIR ?= \$(PREFIX)/etc" fi if test "$FM_BINDIRSTRICT" = "y"; then $ECHO "BINDIR ?= $FM_BINDIR" else $ECHO "BINDIR ?= \$(PREFIX)/bin" fi if test "$FM_SBINDIRSTRICT" = "y"; then $ECHO "SBINDIR ?= $FM_SBINDIR" else $ECHO "SBINDIR ?= \$(PREFIX)/sbin" fi if test "$FM_LIBDIRSTRICT" = "y"; then $ECHO "LIBDIR ?= $FM_LIBDIR" else $ECHO "LIBDIR ?= \$(PREFIX)/lib" fi if test "$FM_INCLUDEDIRSTRICT" = "y"; then $ECHO "INCLUDEDIR ?= $FM_INCLUDEDIR" else $ECHO "INCLUDEDIR ?= \$(PREFIX)/include" fi else $ECHO "PREFIX = $FM_PREFIX" $ECHO "MANDIR = $FM_MANDIR" $ECHO "CONFDIR = $FM_CONFDIR" $ECHO "BINDIR = $FM_BINDIR" $ECHO "SBINDIR = $FM_SBINDIR" $ECHO "LIBDIR = $FM_LIBDIR" $ECHO "INCLUDEDIR = $FM_INCLUDEDIR" fi $ECHO $ECHO "all:" if module subdir; then # make even inside parents; brute force dependency handling for SUBDIR in $FM_SUBDIRS; do $ECHO " cd $SUBDIR && \$(MAKE) all && cd .." done fi if module binaries; then $ECHO " \$(MAKE) binaries" fi if module libraries; then $ECHO " \$(MAKE) libraries" fi $ECHO $ECHO $ECHO ".c.o:" $ECHO " $CC $FM_CFLAGS -DCONFDIR=\"\\\"\$(CONFDIR)\\\"\" -DBINDIR=\"\\\"\$(BINDIR)\\\"\" -DSBINDIR=\"\\\"\$(SBINDIR)\\\"\" -DLIBDIR=\"\\\"\$(LIBDIR)\\\"\" -DMANDIR=\"\\\"\$(MANDIR)\\\"\" -c -o \$@ \$<" $ECHO $ECHO "clean:" if module subdir; then for SUBDIR in $FM_CLEAN_SUBDIRS; do $ECHO " cd $SUBDIR && \$(MAKE) clean && cd .." done fi if module binaries; then $ECHO " \$(MAKE) clean_binaries" fi if module libraries; then $ECHO " \$(MAKE) clean_libraries" fi $ECHO $ECHO "distclean:" $ECHO " \$(MAKE) clean" if module subdir; then for SUBDIR in $FM_CLEAN_SUBDIRS; do $ECHO " cd $SUBDIR && \$(MAKE) distclean && cd .." done fi if module install; then $ECHO " \$(MAKE) clean_install" fi $ECHO " rm -f Makefile compiletest.log dependencies.log firemake.h" $ECHO disp "done" firedns/firestring/firemake/math0000644000175000017500000000065607777067417016076 0ustar useruser#!/bin/sh #require compiletest #require cflags #phase init #after init_cflags #phase header case $PHASE in init) dispn "Checking for math library..." PROGRAM="#include int main () { sin(1.0); return 0; }" compile_test_wrapper "$PROGRAM" "" "" "-lm" || \ { disp "not found, unable to continue" exit 1 } ;; header) disp "Adding \"#include \" to header" $ECHO "#include " ;; esac firedns/firestring/firemake/strip0000644000175000017500000000025507660737511016267 0ustar useruser#!/bin/sh #phase init dispn "Checking for strip..." if strip -V 2>/dev/null; then disp "found strip" STRIP="strip" else disp "not found, continuing without" STRIP="" fi firedns/firestring/firemake/compiletest0000644000175000017500000000504107777067417017466 0ustar useruser#!/bin/sh #require cc #require cflags #phase library disp "Loading compile testing helper function" rm -f compiletest.log library_test() { $ECHO "$1" > compiletest.c $ECHO " == START PROGRAM == $1 == END PROGRAM ==" >>compiletest.log $ECHO "== EXECUTING: $CC $FM_CFLAGS $2 -c -o compiletest.o compiletest.c $3 == " >>compiletest.log $CC $FM_CFLAGS $2 -c -o compiletest.o compiletest.c $3 >>compiletest.log 2>>compiletest.log if test "$?" = "0"; then rm -f compiletest.o compiletest.c $ECHO "== COMPILE OK ==" >>compiletest.log true return else rm -f compiletest.o compiletest.c $ECHO "== COMPILE FAIL ==" >>compiletest.log false return fi } shared_test() { $ECHO "$1" > compiletest.c $ECHO " == START PROGRAM == $1 == END PROGRAM ==" >>compiletest.log $ECHO "== EXECUTING: $CC $FM_CFLAGS $FM_LDFLAGS $FM_SHAREDFLAGS $2 -o compiletest.so compiletest.c $3 == " >>compiletest.log $CC $FM_CFLAGS $FM_LDFLAGS $FM_SHAREDFLAGS $2 -o compiletest.so compiletest.c $3 >>compiletest.log 2>>compiletest.log if test "$?" = "0"; then rm -f compiletest.so compiletest.c $ECHO "== COMPILE OK ==" >>compiletest.log true return else rm -f compiletest.so compiletest.c $ECHO "== COMPILE FAIL ==" >>compiletest.log false return fi } compile_test() { $ECHO "$1" > compiletest.c $ECHO " == START PROGRAM == $1 == END PROGRAM ==" >>compiletest.log $ECHO "== EXECUTING: $CC $FM_CFLAGS $FM_LDFLAGS $2 -o compiletest compiletest.c $3 == " >>compiletest.log $CC $FM_CFLAGS $FM_LDFLAGS $2 -o compiletest compiletest.c $3 >>compiletest.log 2>>compiletest.log if test "$?" = "0"; then $ECHO "== COMPILE OK ==" >>compiletest.log $ECHO "== EXECUTING: ./compiletest ==" >>compiletest.log ./compiletest >>compiletest.log 2>>compiletest.log if test "$?" = "0"; then rm -f compiletest compiletest.c $ECHO "== RUN OK ==" >>compiletest.log true return else rm -f compiletest compiletest.c $ECHO "== RUN FAIL ==" >>compiletest.log false return fi else rm -f compiletest compiletest.c $ECHO "== COMPILE FAIL ==" >>compiletest.log false return fi } compile_test_wrapper() { # Args: # $1 - Program # $2 - CFLAGS # $3 - LDFLAGS # $4 - LIBS if (compile_test "$1" "$2 $3" "$4" > /dev/null); then disp "found" if test "$2" != ""; then disp "Adding \"$2\" to CFLAGS" FM_CFLAGS="$FM_CFLAGS $2" fi if test "$3" != ""; then disp "Adding \"$3\" to LDFLAGS" FM_LDFLAGS="$FM_LDFLAGS $3" fi if test "$4" != ""; then disp "Adding \"$4\" to LIBS" FM_LIBS="$FM_LIBS $4" fi return 0 else return 1 fi } firedns/firestring/firemake/dependencies0000644000175000017500000000345107773045515017556 0ustar useruser#!/bin/sh #require cc #require cflags #phase library #phase init #after init_cflags case $PHASE in library) disp "Loading dependency helper function" rm -f dependencies.log customdeplist() { for DEP in $1; do JUNK=`$ECHO "$BUILTDEPS" | grep "$DEP"` if test "$?" != "0"; then # haven't built this one yet BUILTDEPS="$BUILTDEPS $DEP" CNAME=`echo "$DEP" | sed 's/\\.o\$/.c/'` customdeps "$CNAME" "$DEP" fi done } customdeps() { if test "$CC_DEPENDENCY" = "n"; then return fi dispn "Generating customized build rule for $1..." $ECHO "Generating dependencies with \"$CC $FM_CFLAGS -M $1\" (errors print below):" >> dependencies.log $CC $FM_CFLAGS -M $1 2>>dependencies.log if test "$?" != "0"; then disp "unable to generate dependencies; this file probably won't build. Aborting (check dependencies.log for details)" exit 1 fi $ECHO >> dependencies.log $ECHO " $CC $FM_CFLAGS -DCONFDIR=\"\\\"\$(CONFDIR)\\\"\" -DBINDIR=\"\\\"\$(BINDIR)\\\"\" -DSBINDIR=\"\\\"\$(SBINDIR)\\\"\" -DLIBDIR=\"\\\"\$(LIBDIR)\\\"\" -DMANDIR=\"\\\"\$(MANDIR)\\\"\" -c -o $2 $1" $ECHO disp "done" } ;; init) dispn "Checking for compiler dependency support..." $ECHO "#include int main() { return 0; }" > deptest.c $ECHO "Testing \"$CC $FM_CFLAGS -M deptest.c\":" >> dependencies.log DEPOUTPUT=`$CC $FM_CFLAGS -M deptest.c` RESULT="$?" $ECHO "Result is $RESULT" >> dependencies.log $ECHO "Output is: $DEPOUTPUT " >> dependencies.log if test "$RESULT" = "0"; then JUNK=`$ECHO "$DEPOUTPUT" | grep stdio` if test "$?" = "0"; then disp "found" CC_DEPENDENCY="y" else disp "found but broken, skipping" CC_DEPENDENCY="n" fi else disp "not found, skipping" CC_DEPENDENCY="n" fi rm -f deptest.c ;; esac firedns/firestring/firemake/install0000644000175000017500000000241707777067417016610 0ustar useruser#!/bin/sh #require id #require makefiletop #phase init #after init_id #phase makefile #after makefile_makefiletop case $PHASE in init) dispn "Creating installation script..." $ECHO "#!/bin/sh FILENAME="\$2/\`basename \$1\`" mkdir -p \$2 cp -f \$1 \$FILENAME chown \$3:\$4 \$FILENAME chmod \$5 \$FILENAME" > copy.sh chmod 0755 copy.sh INSTALL="./copy.sh" disp "done" dispn "Checking for installation username..." INSTALL_GROUP=`$ID -ng root` if test "$?" = "0"; then INSTALL_USER=root disp "found, \"root\"" else disp "none found, aborting" exit 1 fi dispn "Checking for installation group name..." if test "$INSTALL_GROUP" = ""; then disp "none found, aborting" exit 1 else disp "found, \"$INSTALL_GROUP\"" fi ;; makefile) dispn "Writing install entry..." $ECHO -n "install:" if module binaries; then $ECHO -n " install_binaries" fi if module libraries; then $ECHO -n " install_libraries" fi if module man; then $ECHO -n " install_man" fi if module headers; then $ECHO -n " install_headers" fi if module conf; then $ECHO -n " install_conf" fi $ECHO $ECHO disp "done" dispn "Writing install cleanup entry..." $ECHO "clean_install:" $ECHO " rm -f $INSTALL" $ECHO disp "done" ;; esac firedns/firestring/firemake/c990000644000175000017500000000157007660737511015533 0ustar useruser#!/bin/sh #require cc #require cflags #phase init #after init_cc #after init_cflags #phase header case $PHASE in init) C99="0" dispn "Checking for C99 compatible compiler..." if test "`basename $CC`" = "gcc"; then VER=`$CC --version | head -1 | cut -d ' ' -f 3` MVER=`$ECHO "$VER" | cut -d '.' -f 1` if test "$MVER" -ge "3"; then disp "gcc $VER (>= 3.0.0) found, C99 support activated" C99="1" else disp "gcc $VER (< 3.0.0) found, no C99 support" fi else disp "compiler not gcc, no C99 support" fi if test "$C99" = "1"; then disp "Adding \"-std=c99\" to CFLAGS" FM_CFLAGS="$FM_CFLAGS -std=c99" fi ;; header) if test "$C99" = "0"; then disp "Removing \"inline\" and \"restrict\" keyworks from source" $ECHO "#define inline" $ECHO "#define restrict" else disp "C99 is supported, no header changes needed" fi ;; esac firedns/firestring/GPL0000644000175000017500000004313107707502671013764 0ustar useruser GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. firedns/firemake.version0000644000175000017500000000000710023637416014417 0ustar useruser0.9.12 firedns/fdnsname.c0000644000175000017500000000106410013211376013160 0ustar useruser#include #include "firedns.h" int main(int argc, char **argv) { char *result; struct in_addr *binip; struct in6_addr *binip6; if (argc != 2) { fprintf(stderr,"usage: %s \n",argv[0]); return 2; } binip6 = firedns_aton6(argv[1]); if (binip6 == NULL) { binip = firedns_aton4(argv[1]); if (binip == NULL) { fprintf(stderr,"invalid IP address.\n"); return 2; } result = firedns_resolvename4(binip); } else result = firedns_resolvename6(binip6); if (result) { printf("%s\n",result); return 0; } return 1; } firedns/fdnsiplist.c0000644000175000017500000000061010012501442013533 0ustar useruser#include #include #include "firedns.h" int main(int argc, char **argv) { struct firedns_ip4list *iter; if (argc != 2) { fprintf(stderr,"usage: %s \n",argv[0]); return 2; } iter = firedns_resolveip4list(argv[1]); if (iter == NULL) return 1; while (iter != NULL) { printf("%s\n",firedns_ntoa4(&iter->ip)); iter = iter->next; } return 0; } firedns/benchmark.c0000644000175000017500000000233610012752457013333 0ustar useruser#include #include #include #include #include #include #include #include #include "firemake.h" #include "firedns.h" #define TESTS 10000 #define TEST_HOST "aol.com" struct timeval tv; void start_time() { if (gettimeofday(&tv,NULL) != 0) { perror("gettimeofday()"); exit(102); } } double end_time() { struct timeval end; double timetaken; if (gettimeofday(&end,NULL) != 0) { perror("gettimeofday()"); exit(102); } timetaken = end.tv_sec + end.tv_usec / 1000000.0; timetaken -= tv.tv_sec + tv.tv_usec / 1000000.0; printf("Delta seconds: %f\n",timetaken); return timetaken; } int main() { int i; double libc, fire; printf("Testing %d firedns_resolveip4list(\"%s\"):\n",TESTS,TEST_HOST); start_time(); for (i = 0; i < TESTS; i++) firedns_resolveip4list(TEST_HOST); fire = end_time(); printf("Testing %d gethostbyname(\"%s\"):\n",TESTS,TEST_HOST); start_time(); for (i = 0; i < TESTS; i++) gethostbyname(TEST_HOST); libc = end_time(); if (libc > fire) printf("Speedup: %d%%\n",(int) (((libc - fire) / libc) * 100.0)); else printf("Slowdown: %d%%\n",(int) (((fire - libc) / libc) * 100.0)); return 0; } firedns/firemake.libraries0000644000175000017500000000002607465513046014717 0ustar useruserlibfiredns: firedns.o firedns/tester.c0000644000175000017500000001522710000600523012671 0ustar useruser#include #include #include #include #include #include #include #include #include "firemake.h" #include "firedns.h" void do_firedns_aton4(char * string) { struct in_addr *inaddr4; firestring_fprintf(stderr,"taking firedns_aton4(%s): ",string); inaddr4 = firedns_aton4(string); if (inaddr4 == NULL) firestring_fprintf(stderr,"got NULL\n"); else firestring_fprintf(stderr,"%d.%d.%d.%d/%s\n",((unsigned char *)&inaddr4->s_addr)[0], ((unsigned char *)&inaddr4->s_addr)[1], ((unsigned char *)&inaddr4->s_addr)[2], ((unsigned char *)&inaddr4->s_addr)[3], firedns_ntoa4(inaddr4)); } void do_firedns_getip4(char * string) { int fd; fd_set s; int n; struct timeval tv; char *m; struct in_addr addr4; firestring_fprintf(stderr,"taking firedns_getip4(%s): ",string); fd = firedns_getip4(string); firestring_fprintf(stderr,"%d\n",fd); if (fd == -1) return; tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&s); FD_SET(fd,&s); n = select(fd + 1,&s,NULL,NULL,&tv); m = firedns_getresult(fd); if (m == NULL) firestring_fprintf(stderr,"getting result: (null)\n"); else { memcpy(&addr4,m,sizeof(struct in_addr)); firestring_fprintf(stderr,"getting result: %s\n",firedns_ntoa4(&addr4)); } } void do_firedns_getip6(char * string) { int fd; fd_set s; int n; struct timeval tv; char *m; struct in6_addr addr6; firestring_fprintf(stderr,"taking firedns_getip6(%s): ",string); fd = firedns_getip6(string); firestring_fprintf(stderr,"%d\n",fd); if (fd == -1) return; tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&s); FD_SET(fd,&s); n = select(fd + 1,&s,NULL,NULL,&tv); m = firedns_getresult(fd); if (m == NULL) firestring_fprintf(stderr,"getting result: (null)\n"); else { memcpy(&addr6,m,sizeof(struct in6_addr)); firestring_fprintf(stderr,"getting result: %s\n",firedns_ntoa6(&addr6)); } } void do_firedns_gettxt(char * string) { int fd; fd_set s; int n; struct timeval tv; char *m; firestring_fprintf(stderr,"taking firedns_gettxt(%s): ",string); fd = firedns_gettxt(string); firestring_fprintf(stderr,"%d\n",fd); if (fd == -1) return; tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&s); FD_SET(fd,&s); n = select(fd + 1,&s,NULL,NULL,&tv); m = firedns_getresult(fd); firestring_fprintf(stderr,"getting result: %s\n",m); } void do_firedns_getmx(char * string) { int fd; fd_set s; int n; struct timeval tv; char *m; firestring_fprintf(stderr,"taking firedns_getmx(%s): ",string); fd = firedns_getmx(string); firestring_fprintf(stderr,"%d\n",fd); if (fd == -1) return; tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&s); FD_SET(fd,&s); n = select(fd + 1,&s,NULL,NULL,&tv); m = firedns_getresult(fd); firestring_fprintf(stderr,"getting result: %s\n",m); } void do_firedns_getname4(char * string) { int fd; fd_set s; int n; struct timeval tv; char *m; struct in_addr *addr4; firestring_fprintf(stderr,"taking firedns_getname4(%s): ",string); addr4 = firedns_aton4(string); if (addr4 == NULL) { firestring_fprintf(stderr,"(null)\n"); return; } fd = firedns_getname4(addr4); firestring_fprintf(stderr,"%d\n",fd); if (fd == -1) return; tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&s); FD_SET(fd,&s); n = select(fd + 1,&s,NULL,NULL,&tv); m = firedns_getresult(fd); firestring_fprintf(stderr,"getting result: %s\n",m); } void do_firedns_getname6(char * string) { int fd; fd_set s; int n; struct timeval tv; char *m; struct in6_addr *addr6; firestring_fprintf(stderr,"taking firedns_getname6(%s): ",string); addr6 = firedns_aton6(string); if (addr6 == NULL) { firestring_fprintf(stderr,"(null)\n"); return; } fd = firedns_getname6(addr6); firestring_fprintf(stderr,"%d\n",fd); if (fd == -1) return; tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&s); FD_SET(fd,&s); n = select(fd + 1,&s,NULL,NULL,&tv); m = firedns_getresult(fd); firestring_fprintf(stderr,"getting result: %s\n",m); } void do_firedns_aton6(char * string) { struct in6_addr *inaddr6; firestring_fprintf(stderr,"taking firedns_aton6(%s): ",string); inaddr6 = firedns_aton6(string); if (inaddr6 == NULL) firestring_fprintf(stderr,"got NULL\n"); else fprintf(stderr,"%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n", inaddr6->s6_addr[0], inaddr6->s6_addr[1], inaddr6->s6_addr[2], inaddr6->s6_addr[3], inaddr6->s6_addr[4], inaddr6->s6_addr[5], inaddr6->s6_addr[6], inaddr6->s6_addr[7], inaddr6->s6_addr[8], inaddr6->s6_addr[9], inaddr6->s6_addr[10], inaddr6->s6_addr[11], inaddr6->s6_addr[12], inaddr6->s6_addr[13], inaddr6->s6_addr[14], inaddr6->s6_addr[15]); } void do_firedns_dnsbl_lookup(char * ip, char * string) { int fd; fd_set s; int n; struct timeval tv; char *m; struct in_addr *i; i = firedns_aton4(ip); firestring_fprintf(stderr,"taking firedns_dnsbl_lookup(%s,%s): ",ip,string); fd = firedns_dnsbl_lookup_txt(i,string); firestring_fprintf(stderr,"%d\n",fd); if (fd == -1) return; tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&s); FD_SET(fd,&s); n = select(fd + 1,&s,NULL,NULL,&tv); m = firedns_getresult(fd); firestring_fprintf(stderr,"getting result: %s\n",m); } int main() { do_firedns_aton4("1.2.3.4"); do_firedns_aton4("101.102.103.104"); do_firedns_aton4("bah"); do_firedns_aton4("1.2.3.400"); do_firedns_aton4("206.152.182.152"); do_firedns_aton4("206.152.182.152)"); do_firedns_aton4("ack started..."); do_firedns_aton6("::"); do_firedns_aton6("3ffe:b80:346:1:204:5aff:fece:7852"); do_firedns_aton6("fe80::204:5aff:fece:7852"); do_firedns_aton6("bah"); do_firedns_getip4("host.taconic.net"); do_firedns_getip4("celery.n.ml.org"); do_firedns_getip4("incandescent.mp3revolution.net"); do_firedns_getip4("dharr.stu.rpi.edu"); do_firedns_getip4("ftp.us.kernel.org"); do_firedns_getip4("cool.dk"); do_firedns_getip6("ftp.stealth.net"); do_firedns_getip6("www.ipv6.org"); do_firedns_getip6("z.ip6.int"); do_firedns_gettxt("2.0.0.127.inputs.orbz.org"); do_firedns_gettxt("2.0.0.127.outputs.orbz.org"); do_firedns_gettxt("2.0.0.127.bl.spamcop.net"); do_firedns_gettxt("2.0.0.127.relays.ordb.org"); do_firedns_getmx("spamcop.net"); do_firedns_getmx("penguinhosting.net"); do_firedns_getmx("taconic.net"); do_firedns_getmx("microsoft.com"); do_firedns_getmx("email.si"); do_firedns_getmx("cool.dk"); do_firedns_getname4("205.231.144.10"); do_firedns_getname4("208.171.237.190"); do_firedns_getname4("64.28.67.150"); do_firedns_getname4("64.90.162.91"); do_firedns_getname6("3FFE:0:1:0:0:0:C620:242"); do_firedns_getname6("2001:660:1180:1:192:134:0:49"); do_firedns_getname6("3FFE:50E:0:0:0:0:0:1"); do_firedns_dnsbl_lookup("127.0.0.2","list.dsbl.org"); return 0; } firedns/README0000644000175000017500000000111207713510327012106 0ustar useruserFireDNS Library --------------- (c) 2002 Ian Gulliver under the GNU Public License, Version 2. See GPL for more details. From libfiredns(3): libfiredns is a library for handling asynchronous DNS requests. It provides a very simple interface for sending requests and parsing reponses, as well as low-timeout blocking functions. libfiredns functions have much lower timeouts than the stock functions and tend to be faster because they send requests to all configured system nameservers at the same time. If you have questions or comments, you can reach me at ian@penguinhosting.net. firedns/firemake.headers0000644000175000017500000000001207465513046014351 0ustar useruserfiredns.h firedns/firedns.h0000644000175000017500000001154410013014330013017 0ustar useruser/* firedns.h - firedns library declarations Copyright (C) 2002 Ian Gulliver This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef _FIREDNS_H #define _FIREDNS_H #include #include #include #ifndef _FIREDNS_C extern const char firedns_version[]; extern const int firedns_mx_port[]; extern const char *firedns_mx_name[]; #endif #ifndef AF_INET6 struct in6_addr { unsigned char s6_addr[16]; }; #endif #define FIREDNS_MX_SMTP 0 #define FIREDNS_MX_QMTP 1 struct firedns_ip4list { struct in_addr ip; struct firedns_ip4list *next; }; struct firedns_ip6list { struct in6_addr ip; struct firedns_ip6list *next; }; struct firedns_mxlist { unsigned int priority; unsigned int protocol; struct firedns_ip4list *ip4list; struct firedns_ip6list *ip6list; char *cname; char *name; struct firedns_mxlist *next; }; struct firedns_txtlist { char *txt; struct firedns_txtlist *next; }; void firedns_init(); /* non-blocking functions */ struct in_addr *firedns_aton4(const char * const ipstring); struct in6_addr *firedns_aton6(const char * const ipstring); char *firedns_ntoa4(const struct in_addr * const ip); char *firedns_ntoa6(const struct in6_addr * const ip); int firedns_getip4(const char * const name); int firedns_getip4list(const char * const name); int firedns_getip6(const char * const name); int firedns_getip6list(const char * const name); int firedns_gettxt(const char * const name); int firedns_gettxtlist(const char * const name); int firedns_getmx(const char * const name); int firedns_getmxlist(const char * const name); int firedns_getname4(const struct in_addr * const ip); int firedns_getname6(const struct in6_addr * const ip); int firedns_getcname(const char * const name); int firedns_dnsbl_lookup_a(const struct in_addr * const ip, const char * const name); int firedns_dnsbl_lookup_txt(const struct in_addr * const ip, const char * const name); char *firedns_getresult(const int fd); /* buffer pass-in non-blocking functions */ struct in_addr *firedns_aton4_s(const char * const ipstring, struct in_addr * const ip); struct in6_addr *firedns_aton6_s(const char * const ipstring, struct in6_addr * const ip); char *firedns_ntoa4_s(const struct in_addr * const ip, char * const result); char *firedns_ntoa6_s(const struct in6_addr * const ip, char * const result); char *firedns_getresult_s(const int fd, char * const result); /* thread-safe functions that allocate their own buffers */ struct in_addr *firedns_aton4_r(const char * const ipstring); struct in6_addr *firedns_aton6_r(const char * const ipstring); char *firedns_ntoa4_r(const struct in_addr * const ip); char *firedns_ntoa6_r(const struct in6_addr * const ip); char *firedns_getresult_r(const int fd); /* low-timeout blocking functions */ struct in_addr *firedns_resolveip4(const char * const name); struct firedns_ip4list *firedns_resolveip4list(const char * const name); struct in6_addr *firedns_resolveip6(const char * const name); struct firedns_ip6list *firedns_resolveip6list(const char * const name); char *firedns_resolvetxt(const char * const name); struct firedns_txtlist *firedns_resolvetxtlist(const char * const name); char *firedns_resolvemx(const char * const name); struct firedns_mxlist *firedns_resolvemxlist(const char * const name); struct firedns_mxlist *firedns_resolvemxalist(const char * const name); char *firedns_resolvename4(const struct in_addr * const ip); char *firedns_resolvename6(const struct in6_addr * const ip); char *firedns_resolvecname(const char * const name); /* reentrant low-timeout blocking functions */ struct in_addr *firedns_resolveip4_r(const char * const name); struct firedns_ip4list *firedns_resolveip4list_r(const char * const name); struct in6_addr *firedns_resolveip6_r(const char * const name); struct firedns_ip6list *firedns_resolveip6list_r(const char * const name); char *firedns_resolvetxt_r(const char * const name); struct firedns_txtlist *firedns_resolvetxtlist_r(const char * const name); char *firedns_resolvemx_r(const char * const name); struct firedns_mxlist *firedns_resolvemxlist_r(const char * const name); char *firedns_resolvename4_r(const struct in_addr * const ip); char *firedns_resolvename6_r(const struct in6_addr * const ip); char *firedns_resolvecname_r(const char * const name); /* misc functions */ void firedns_free_mxalist(struct firedns_mxlist *list); #endif firedns/fdnstxt.c0000644000175000017500000000043507560015574013077 0ustar useruser#include #include "firedns.h" int main(int argc, char **argv) { char *result; if (argc != 2) { fprintf(stderr,"usage: %s \n",argv[0]); return 2; } result = firedns_resolvetxt(argv[1]); if (result) { printf("%s\n",result); return 0; } return 1; } firedns/man/0000755000175000017500000000000010016724360012000 5ustar useruserfiredns/man/fdnsip6.10000644000175000017500000000074010012752457013440 0ustar useruser.\" (C) 2004 Ian Gulliver .TH fdnsip6 1 2004-02-12 .SH NAME fdnsip6 \- resolve a hostname to an IPv6 address .SH SYNOPSIS .BI "fdnsip6 " .SH DESCRIPTION fdnsip6 will attempt to look up a single IPv6 address for .IR hostname . If one is found, it is printed to standard output and the program exits with return code 0. If not, nothing is printed and the program exits with return code 1. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/firedns_gettxt.30000644000175000017500000000143007451715051015121 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_gettxt 3 2002-03-31 .SH NAME firedns_gettxt \- Create a query to resolve a hostname's TXT record .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "int firedns_gettxt(const char * const " "name" ")" .SH DESCRIPTION firedns_gettxt() creates and sends a request to resolve the TXT record of .IR name . It returns a file descriptor that should be .IR select (2)'ed upon (read set). When the file descriptor shows ready for reading call .IR firedns_getresult (3) to retrieve the results. .SH RETURN VALUE Returns an integer file descriptor that can be used the same as any other file descriptor. Returns .I -1 on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3), .BR firedns_getresult (3), .BR select (2) firedns/man/fdnsip6list.10000644000175000017500000000102610012774171014327 0ustar useruser.\" (C) 2004 Ian Gulliver .TH fdnsip6list 1 2004-02-12 .SH NAME fdnsip6list \- resolve a hostname to a list of IPv6 addresses .SH SYNOPSIS .BI "fdnsip6list " .SH DESCRIPTION fdnsip6list will attempt to look up a list of IPv6 addresses for .IR hostname . If any are found, they are printed to standard output seperated by newlines and the program exits with return code 0. If not, nothing is printed and the program exits with return code 1. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/firedns_getcname.30000644000175000017500000000145210012736073015363 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_getcname 3 2004-02-12 .SH NAME firedns_getcname \- Create a query to resolve the canonical name of a host .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "int firedns_getcname(const char *" "name" ")" .SH DESCRIPTION firedns_getcname() creates and sends a request to resolve the canonical name (CNAME) of .IR name . It returns a file descriptor that should be .IR select (2)'ed upon (read set). When the file descriptor shows ready for reading call .IR firedns_getresult (3) to retrieve the results. .SH RETURN VALUE Returns an integer file descriptor that can be used the same as any other file descriptor. Returns .I -1 on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3), .BR firedns_getresult (3), .BR select (2) firedns/man/fdnsmxalist.10000644000175000017500000000246010016724360014420 0ustar useruser.\" (C) 2004 Ian Gulliver .TH fdnsmxalist 1 2004-02-12 .SH NAME fdnsmxalist \- resolve a list of MX records and their corresponding A records for hostname .SH SYNOPSIS .BI "fdnsmxalist [" -x "] " .SH DESCRIPTION fdnsmxalist will attempt to look up a list of MX records for .IR hostname . If any are found, they are printed to standard output seperated by newlines in the format: .IR " Protocol " ( Priority ) " hostname" : port The program then looks up lists of A and AAAA records for each MX record, and prints them to standard output, one IP per line. Lines are printed to standard output starting with "ERROR: " if any MX records have no corresponding A or AAAA records, are CNAMEs (an RFC violation), or have A or AAAA records which point to non-routable IP addresses. If the -x switch is passed on the command line, the program outputs machine-parsable XML instead of the human-readable tree. Exit codes for the program are: .IR " 0" " - Everything looks fine" .br .IR " 1" " - An MX has a non-routable IP" .br .IR " 2" " - An MX doesn't exist" .br .IR " 3" " - An MX is a CNAME" .br .IR " 4" " - An MX is an IP address" .br .IR "100" " - Invalid syntax" .br .IR "103" " - DNS timeout or host does not have MX records" .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/libfiredns.30000644000175000017500000000505010013014330014167 0ustar useruser.\" (C) 2002 Ian Gulliver .TH libfiredns 3 2004-02-12 .SH NAME libfiredns \- library for asynchronous DNS requests .SH SYNOPSIS .B #include .br .B -lfiredns .SH DESCRIPTION libfiredns is a library for handling asynchronous DNS requests. It provides a very simple interface for sending requests and parsing reponses, as well as low-timeout blocking functions. It can also be compiled to override the BIND/LIBC functions with its alternative implementations. libfiredns functions have much lower timeouts than the stock functions and tend to be faster because they send requests to all configured system nameservers at the same time. .P Any function ending in "_r" is reentrant; it is safe to be used from threaded programs, and it returns a dynamically allocated buffer which must be free()'d later. .P Any function ending in "_s" takes a buffer as a parameter that it will write to. .HP Non-network functions: .br .BR firedns_aton4 (3) .br .BR firedns_aton6 (3) .br .BR firedns_ntoa4 (3) .br .BR firedns_ntoa6 (3) .HP Non-blocking functions: .br .BR firedns_getip4 (3) .br .BR firedns_getip4list (3) .br .BR firedns_getip6 (3) .br .BR firedns_getip6list (3) .br .BR firedns_gettxt (3) .br .BR firedns_gettxtlist (3) .br .BR firedns_getmx (3) .br .BR firedns_getmxlist (3) .br .BR firedns_getname4 (3) .br .BR firedns_getname6 (3) .br .BR firedns_getcname (3) .br .BR firedns_getresult (3) .HP Blocking functions: .br .BR firedns_resolveip4 (3) .br .BR firedns_resolveip4list (3) .br .BR firedns_resolveip6 (3) .br .BR firedns_resolveip6list (3) .br .BR firedns_resolvetxt (3) .br .BR firedns_resolvetxtlist (3) .br .BR firedns_resolvemx (3) .br .BR firedns_resolvemxlist (3) .br .BR firedns_resolvemxalist (3) .br .BR firedns_resolvename4 (3) .br .BR firedns_resolvename6 (3) .br .BR firedns_resolvecname (3) .HP Miscellaneous functions: .br .BR firedns_free_mxalist (3) .SH FILES /usr/local/include/firedns.h .br /usr/local/lib/libfiredns.so .br /usr/local/lib/libfiredns.a .br /usr/local/etc/firedns.conf .br /etc/resolv.conf .SH BUGS This used to say: FireDNS is very network unfriendly. It sends queries to all nameservers in /usr/local/etc/firedns.conf or (fallback) /etc/resolv.conf at the same time. This loads the nameservers and the network much more than existing implementations but tends to get responses much faster. However, it seems that the network usage is well worth the 10 - 15% speed increase (in ideal situations) that this program can provide. If a primary nameserver is down, this speed increase is > 10000%. .SH AUTHOR Ian Gulliver firedns/man/firedns_resolvename4.30000644000175000017500000000120007503645320016200 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_resolvename4 3 2002-03-31 .SH NAME firedns_resolvename4 \- Resolve a hostname from an IPv4 address .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "char *firedns_resolvename4(const struct in_addr * " "ip" ")" .br .BI "char *firedns_resolvename4_r(const struct in_addr * " "ip" ")" .SH DESCRIPTION firedns_resolvename4() attempts to resolve the hostname of the IPv4 address .IR ip . .SH RETURN VALUE Returns a pointer to an internal static .I char * that contains a hostname of .IR ip , or .I NULL on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/firedns_getmx.30000644000175000017500000000142207451715051014727 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_getmx 3 2002-03-31 .SH NAME firedns_getmx \- Create a query to resolve a hostname's MX record .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "int firedns_getmx(const char * const " "name" ")" .SH DESCRIPTION firedns_getmx() creates and sends a request to resolve the MX record of .IR name . It returns a file descriptor that should be .IR select (2)'ed upon (read set). When the file descriptor shows ready for reading call .IR firedns_getresult (3) to retrieve the results. .SH RETURN VALUE Returns an integer file descriptor that can be used the same as any other file descriptor. Returns .I -1 on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3), .BR firedns_getresult (3), .BR select (2) firedns/man/firedns_resolveip4list.30000644000175000017500000000145010012736073016566 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_resolveip4list 3 2004-02-12 .SH NAME firedns_resolveip4list \- Resolve a list of A records of a hostname .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "struct firedns_ip4list *firedns_resolveip4list(const char * const " "name" ")" .br .BI "struct firedns_ip4list *firedns_resolveip4list_r(const char * const " "name" ")" .SH DESCRIPTION firedns_resolveip4list() attempts to resolve a list of A records for the hostname .IR name . .SH RETURN VALUE Returns a pointer to an internal static .IR "struct firedns_ip4list *". This structure is the first of a linked list. It contains: struct in_addr ip; .br struct firedns_ip4list *next; This function returns NULL on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/fdnsnamep.10000644000175000017500000000153710013202425014031 0ustar useruser.\" (C) 2004 Ian Gulliver .TH fdnsnamep 1 2004-02-13 .SH NAME fdnsnamep \- resolve an IPv4 or IPv6 address to a hostname with paranoid checking .SH SYNOPSIS .BI "fdnsname " "" .SH DESCRIPTION fdnsname will attempt to look up a single hostname for .IR "IP address" (which is an IPv4 address in dotted-quad format or an IPv6 address in colon-seperated format). If one is found, the program checks to make sure that the hostname has a corresponding A or AAAA record pointing back to the supplied IP. If so, the hostname is printed to standard output and the program exits with return code 0. If the paranoid check fails, nothing is printed and the program exits with return code 3. If no hostname is found, nothing is printed and the program exits with return code 1. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/firedns_free_mxalist.30000644000175000017500000000077410012737226016271 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_free_mxalist 3 2004-02-12 .SH NAME firedns_free_mxalist \- Free a previously returned MX/A list structure .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "void firedns_free_mxalist(struct firedns_mxalist *" "list" ")" .SH DESCRIPTION firedns_free_mxalist() frees all memory previously allocated by a call to .IR firedns_resolvemxalist (3). .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) .br .BR firedns_resolvemxalist (3) firedns/man/firedns_resolvecname.30000644000175000017500000000127210012736073016263 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_resolvecname 3 2004-02-12 .SH NAME firedns_resolvecname \- Resolve the canonical name of a host .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "char *firedns_resolvecname(const char * " "name" ")" .br .BI "char *firedns_resolvecname_r(const char * " "name" ")" .SH DESCRIPTION firedns_resolvecname() attempts to resolve the canonical name (CNAME) of .IR name . .SH RETURN VALUE Returns a pointer to an internal static .I char * that contains a CNAME .IR ip , or .I NULL if there is no such record (indicating that you already have the canonical name of the host). .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/firedns_getip6.30000644000175000017500000000143607451715051015006 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_getip6 3 2002-03-31 .SH NAME firedns_getip6 \- Create a query to resolve a hostname to an IPv6 address .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "int firedns_getip6(const char * const " "name" ")" .SH DESCRIPTION firedns_getip6() creates and sends a request to resolve .I name to an IPv6 address. It returns a file descriptor that should be .IR select (2)'ed upon (read set). When the file descriptor shows ready for reading call .IR firedns_getresult (3) to retrieve the results. .SH RETURN VALUE Returns an integer file descriptor that can be used the same as any other file descriptor. Returns .I -1 on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3), .BR firedns_getresult (3), .BR select (2) firedns/man/firedns_getip4list.30000644000175000017500000000147710012736073015677 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_getip4list 3 2004-02-12 .SH NAME firedns_getip4list \- Create a query to resolve a hostname to a list of IPv4 addresses .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "int firedns_getip4list(const char * const " "name" ")" .SH DESCRIPTION firedns_getip4list() creates and sends a request to resolve .I name to a list of IPv4 address. It returns a file descriptor that should be .IR select (2)'ed upon (read set). When the file descriptor shows ready for reading, call .IR firedns_getresult (3) to retrieve the results. .SH RETURN VALUE Returns an integer file descriptor that can be used the same as any other file descriptor. Returns .I -1 on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3), .BR firedns_getresult (3), .BR select (2) firedns/man/firedns_getip4.30000644000175000017500000000143707451715051015005 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_getip4 3 2002-03-31 .SH NAME firedns_getip4 \- Create a query to resolve a hostname to an IPv4 address .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "int firedns_getip4(const char * const " "name" ")" .SH DESCRIPTION firedns_getip4() creates and sends a request to resolve .I name to an IPv4 address. It returns a file descriptor that should be .IR select (2)'ed upon (read set). When the file descriptor shows ready for reading, call .IR firedns_getresult (3) to retrieve the results. .SH RETURN VALUE Returns an integer file descriptor that can be used the same as any other file descriptor. Returns .I -1 on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3), .BR firedns_getresult (3), .BR select (2) firedns/man/firedns_aton6.30000644000175000017500000000150507503645320014633 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_aton6 3 2002-03-31 .SH NAME firedns_aton6 \- convert a colon seperated IPv6 address to binary format .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "struct in6_addr *firedns_aton6(const char * const " "ipstring" ")" .br .BI "struct in6_addr *firedns_aton6_r(const char * const " "ipstring" ")" .br .BI "struct in6_addr *firedns_aton6_s(const char * const " "ipstring" ", struct in6_addr *" "ip" ")" .SH DESCRIPTION firedns_aton6() takes an IPv6 address in colon seperated notation in .I ipstring and returns a .I struct in6_addr containing the address in binary format. .SH RETURN VALUE Returns a .I struct in6_addr containing the IP address in binary form, or .I NULL if .I ipstring is not a valid IP. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/firedns_resolveip6.30000644000175000017500000000124307503645320015701 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_resolveip6 3 2002-03-31 .SH NAME firedns_resolveip6 \- Resolve a hostname to an IPv6 address .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "struct in6_addr *firedns_resolveip6(const char * const " "name" ")" .br .BI "struct in6_addr *firedns_resolveip6_r(const char * const " "name" ")" .SH DESCRIPTION firedns_resolveip6() attempts to resolve the hostname .I name to an IPv6 address. .SH RETURN VALUE Returns a pointer to an internal static .I struct in6_addr that contains the IP address of .I name in binary format, or .I NULL on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/fdnsname.10000644000175000017500000000111710013211376013650 0ustar useruser.\" (C) 2004 Ian Gulliver .TH fdnsname 1 2004-02-13 .SH NAME fdnsname \- resolve an IPv4 or IPv6 address to a hostname .SH SYNOPSIS .BI "fdnsname " "" .SH DESCRIPTION fdnsname will attempt to look up a single hostname for .IR "IP address" (which is an IPv4 address in dotted-quad format or an IPv6 address in colon-seperated format). If one is found, it is printed to standard output and the program exits with return code 0. If not, nothing is printed and the program exits with return code 1. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/fdnsip.10000644000175000017500000000073410012742301013340 0ustar useruser.\" (C) 2004 Ian Gulliver .TH fdnsip 1 2004-02-12 .SH NAME fdnsip \- resolve a hostname to an IPv4 address .SH SYNOPSIS .BI "fdnsip " .SH DESCRIPTION fdnsip will attempt to look up a single IPv4 address for .IR hostname . If one is found, it is printed to standard output and the program exits with return code 0. If not, nothing is printed and the program exits with return code 1. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/firedns_gettxtlist.30000644000175000017500000000145310012774171016015 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_gettxtlist 3 2004-02-12 .SH NAME firedns_gettxtlist \- Create a query to resolve a TXT record of a hostname .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "int firedns_gettxtlist(const char * const " "name" ")" .SH DESCRIPTION firedns_gettxtlist() creates and sends a request to resolve a TXT record for .IR name . It returns a file descriptor that should be .IR select (2)'ed upon (read set). When the file descriptor shows ready for reading, call .IR firedns_getresult (3) to retrieve the results. .SH RETURN VALUE Returns an integer file descriptor that can be used the same as any other file descriptor. Returns .I -1 on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3), .BR firedns_getresult (3), .BR select (2) firedns/man/firedns_aton4.30000644000175000017500000000146707503645320014640 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_aton4 3 2002-03-31 .SH NAME firedns_aton4 \- convert a dotted quad IPv4 address to binary format .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "struct in_addr *firedns_aton4(const char * const " "ipstring" ")" .br .BI "struct in_addr *firedns_aton4_r(const char * const " "ipstring" ")" .br .BI "struct in_addr *firedns_aton4_s(const char * const " "ipstring" ", struct in_addr *" "ip" ")" .SH DESCRIPTION firedns_aton4() takes an IPv4 address in dotted quad notation in .I ipstring and returns a .I struct in_addr containing the address in binary format. .SH RETURN VALUE Returns a .I struct in_addr containing the IP address in binary form, or .I NULL if .I ipstring is not a valid IP. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/fdnscname.10000644000175000017500000000074410012742301014014 0ustar useruser.\" (C) 2004 Ian Gulliver .TH fdnscname 1 2004-02-12 .SH NAME fdnscname \- resolve the canonical name of a host .SH SYNOPSIS .BI "fdnscname " "" .SH DESCRIPTION fdnsname will attempt to look up the canonical name of .IR hostname . If one is found, it is printed to standard output and the program exits with return code 0. If not, nothing is printed and the program exits with return code 1. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/firedns_resolvemxlist.30000644000175000017500000000160110013014330016476 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_resolvemxlist 3 2004-02-12 .SH NAME firedns_resolvemxlist \- Resolve a list of MX records of a hostname .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "struct firedns_mxlist *firedns_resolvemxlist(const char * const " "name" ")" .br .BI "struct firedns_mxlist *firedns_resolvemxlist_r(const char * const " "name" ")" .SH DESCRIPTION firedns_resolvemxlist() attempts to resolve a list of MX records for the hostname .IR name . .SH RETURN VALUE Returns a pointer to an internal static .IR "struct firedns_mxlist *". This structure is the first of a linked list. It contains: char *name; .br unsigned int protocol; .RI ( FIREDNS_MX_SMTP " or " FIREDNS_MX_QMTP ) .br unsigned int priority; .br struct firedns_mxlist *next; This function returns NULL on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/firedns_resolvemxalist.30000644000175000017500000000253110012774153016661 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_resolvemxalist 3 2004-02-12 .SH NAME firedns_resolvemxalist \- Resolve a list of MX records of a hostname and their corresponding A records .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "struct firedns_mxlist *firedns_resolvemxalist(const char * const " "name" ")" .SH DESCRIPTION firedns_resolvemxalist() attempts to resolve a list of MX records for the hostname .IR name . If it fails, it treats the host as having a priority 0 MX record, and attempts to resolve a list of A and AAAA records for the hostname. If the MX record lookup succeeds, it looks up the list of A and AAAA records for each MX record in parallel. It also checks for RFC-violating CNAMEs for each MX record. .SH RETURN VALUE Returns a pointer to an internal static .IR "struct firedns_mxlist *". This structure is the first of a linked list. It contains: char *name; .br char *cname; .br struct firedns_ip4list *ip4list; .br struct firedns_ip6list *ip6list; .br unsigned int protocol; .RI ( FIREDNS_MX_SMTP " or " FIREDNS_MX_QMTP ) .br unsigned int priority; .br struct firedns_mxlist *next; This function returns NULL on error. Any result return by this function should be freed with .IR firedns_free_mxalist (3). .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) .br .BR firedns_free_mxalist (3) firedns/man/firedns_ntoa6.30000644000175000017500000000136207503645320014634 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_ntoa6 3 2002-03-31 .SH NAME firedns_ntoa6 \- convert a binary format IPv6 address to a colon seperated string .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "char *firedns_ntoa6(const struct in6_addr *" "ip" ")" .br .BI "char *firedns_ntoa6_r(const struct in6_addr *" "ip" ")" .br .BI "char *firedns_ntoa6_s(const struct in6_addr *" "ip" ", char *" "result" ")" .SH DESCRIPTION firedns_ntoa6() takes an IPv6 address in binary format in .I ip and returns a .I char * of the IP in human-readable colon seperated format. .SH RETURN VALUE Returns a string containing the IP address in human-readable colon seperated format. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/fdnsspf1.10000644000175000017500000000114510012774171013610 0ustar useruser.\" (C) 2004 Ian Gulliver .TH fdnsspf1 1 2004-02-12 .SH NAME fdnsspf1 \- resolve an SPF version 1 record of a hostname .SH SYNOPSIS .BI "fdnsspf1 " .SH DESCRIPTION fdnsspf1 will attempt to look up an SPF version 1 record for .IR hostname . If one is found, it is printed to standard output and the program exits with return code 0. If more than one is found (a violation of the specification), none is found, or the DNS query fails, nothing is printed and the program exits with return code 1. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) .br http://spf.pobox.com/ firedns/man/firedns_ntoa4.30000644000175000017500000000134307503645320014631 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_ntoa4 3 2002-03-31 .SH NAME firedns_ntoa4 \- convert a binary format IPv4 address to a dotted quad string .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "char *firedns_ntoa4(const struct in_addr *" "ip" ")" .br .BI "char *firedns_ntoa4_r(const struct in_addr *" "ip" ")" .br .BI "char *firedns_ntoa4_s(const struct in_addr *" "ip" ", char *" "result" ")" .SH DESCRIPTION firedns_ntoa4() takes an IPv4 address in binary format in .I ip and returns a .I char * of the IP in human-readable dotted quad format. .SH RETURN VALUE Returns a string containing the IP address in human-readable dotted quad format. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/fdnsmx.10000644000175000017500000000072610012742301013355 0ustar useruser.\" (C) 2004 Ian Gulliver .TH fdnsmx 1 2004-02-12 .SH NAME fdnsmx \- resolve an MX record of a hostname .SH SYNOPSIS .BI "fdnsmx " .SH DESCRIPTION fdnsmx will attempt to look up a single MX record for .IR hostname . If one is found, it is printed to standard output and the program exits with return code 0. If not, nothing is printed and the program exits with return code 1. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/firedns_getmxlist.30000644000175000017500000000145007711503127015622 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_getmxlist 3 2003-07-29 .SH NAME firedns_getmxlist \- Create a query to resolve a hostname's MX record list .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "int firedns_getmxlist(const char * const " "name" ")" .SH DESCRIPTION firedns_getmxlist() creates and sends a request to resolve the MX records of .IR name . It returns a file descriptor that should be .IR select (2)'ed upon (read set). When the file descriptor shows ready for reading call .IR firedns_getresult (3) to retrieve the results. .SH RETURN VALUE Returns an integer file descriptor that can be used the same as any other file descriptor. Returns .I -1 on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3), .BR firedns_getresult (3), .BR select (2) firedns/man/firedns_getresult.30000644000175000017500000000301210013014330015572 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_getresult 3 2004-02-12 .SH NAME firedns_getresult \- Retrieve a result from a previous FireDNS query .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "char *firedns_getresult(const int " "fd" ")" .br .BI "char *firedns_getresult_r(const int " "fd" ")" .br .BI "char *firedns_getresult_s(const int " "fd" ", char *" "result" ")" .SH DESCRIPTION firedns_getresult() returns the result for the request identified by the file descriptor .IR fd . It returns .I NULL if there has been no response to the request or the response indicates failure. .SH RETURN VALUE Returns .I NULL on failure, or a pointer to the result. The return value is meant to be cast depending upon the initial request made. .HP Casts: .br firedns_getip4() - (struct in_addr *) .br firedns_getip4list() - (struct firedns_ip4list *) /* linked list */ .br firedns_getip6() - (struct in6_addr *) .br firedns_getip6list() - (struct firedns_ip6list *) /* linked list */ .br firedns_gettxt() - (char *) .br firedns_gettxtlist() - (struct firedns_txtlist *) /* linked list */ .br firedns_getmx() - (char *) .br firedns_getmxlist() - (struct firedns_mxlist *) /* linked list */ .br firedns_getname4() - (char *) .br firedns_getname6() - (char *) .br firedns_getcname() - (char *) .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3), .BR firedns_getip4 (3), .BR firedns_getip6 (3), .BR firedns_gettxt (3), .BR firedns_getmx (3), .BR firedns_getmxlist (3), .BR firedns_getname4 (3), .BR firedns_getname6 (3) firedns/man/fdnsiplist.10000644000175000017500000000102210012742301014223 0ustar useruser.\" (C) 2004 Ian Gulliver .TH fdnsiplist 1 2004-02-12 .SH NAME fdnsiplist \- resolve a hostname to a list of IPv4 addresses .SH SYNOPSIS .BI "fdnsiplist " .SH DESCRIPTION fdnsiplist will attempt to look up a list of IPv4 addresses for .IR hostname . If any are found, they are printed to standard output seperated by newlines and the program exits with return code 0. If not, nothing is printed and the program exits with return code 1. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/firedns_getname4.30000644000175000017500000000146107451715051015312 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_getname4 3 2002-03-31 .SH NAME firedns_getname4 \- Create a query to resolve an IPv4 address to a hostname .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "int firedns_getname4(const struct in_addr *" "ip" ")" .SH DESCRIPTION firedns_getname4() creates and sends a request to resolve the IPv4 address .I ip to a hostname. It returns a file descriptor that should be .IR select (2)'ed upon (read set). When the file descriptor shows ready for reading call .IR firedns_getresult (3) to retrieve the results. .SH RETURN VALUE Returns an integer file descriptor that can be used the same as any other file descriptor. Returns .I -1 on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3), .BR firedns_getresult (3), .BR select (2) firedns/man/firedns_resolvetxtlist.30000644000175000017500000000144410012774171016715 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_resolvetxtlist 3 2004-02-12 .SH NAME firedns_resolvetxtlist \- Resolve a list of TXT records of a hostname .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "struct firedns_txtlist *firedns_resolvetxtlist(const char * const " "name" ")" .br .BI "struct firedns_txtlist *firedns_resolvetxtlist_r(const char * const " "name" ")" .SH DESCRIPTION firedns_resolvetxtlist() attempts to resolve a list of TXT records for the hostname .IR name . .SH RETURN VALUE Returns a pointer to an internal static .IR "struct firedns_txtlist *". This structure is the first of a linked list. It contains: char *txt; .br struct firedns_txtlist *next; This function returns NULL on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/firedns_resolvename6.30000644000175000017500000000120207503645320016204 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_resolvename6 3 2002-03-31 .SH NAME firedns_resolvename6 \- Resolve a hostname from an IPv6 address .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "char *firedns_resolvename6(const struct in6_addr * " "ip" ")" .br .BI "char *firedns_resolvename6_r(const struct in6_addr * " "ip" ")" .SH DESCRIPTION firedns_resolvename6() attempts to resolve the hostname of the IPv6 address .IR ip . .SH RETURN VALUE Returns a pointer to an internal static .I char * that contains a hostname of .IR ip , or .I NULL on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/firedns_getname6.30000644000175000017500000000146207451715051015315 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_getname6 3 2002-03-31 .SH NAME firedns_getname6 \- Create a query to resolve an IPv6 address to a hostname .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "int firedns_getname6(const struct in6_addr *" "ip" ")" .SH DESCRIPTION firedns_getname6() creates and sends a request to resolve the IPv6 address .I ip to a hostname. It returns a file descriptor that should be .IR select (2)'ed upon (read set). When the file descriptor shows ready for reading call .IR firedns_getresult (3) to retrieve the results. .SH RETURN VALUE Returns an integer file descriptor that can be used the same as any other file descriptor. Returns .I -1 on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3), .BR firedns_getresult (3), .BR select (2) firedns/man/firedns_resolveip6list.30000644000175000017500000000145710012774171016600 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_resolveip6list 3 2004-02-12 .SH NAME firedns_resolveip6list \- Resolve a list of AAAA records of a hostname .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "struct firedns_ip6list *firedns_resolveip6list(const char * const " "name" ")" .br .BI "struct firedns_ip6list *firedns_resolveip6list_r(const char * const " "name" ")" .SH DESCRIPTION firedns_resolveip6list() attempts to resolve a list of AAAA records for the hostname .IR name . .SH RETURN VALUE Returns a pointer to an internal static .IR "struct firedns_ip6list *". This structure is the first of a linked list. It contains: struct in6_addr ip; .br struct firedns_ip6list *next; This function returns NULL on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/firedns_dnsbl_lookup.30000644000175000017500000000177307501253403016301 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_dnsbl_lookup 3 2002-03-31 .SH NAME firedns_dnsbl_lookup \- Create a query to look up an IP in a DNS-based blacklist .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "int firedns_dnsbl_lookup(const struct in_addr *" "ip" ", const char * const " "name" ")" .SH DESCRIPTION firedns_dnsbl_lookup() creates and sends a request to resolve the TXT record of the entry of .I ip in the DNS-based blacklist .IR name . It returns a file descriptor that should be .IR select (2)'ed upon (read set). When the file descriptor shows ready for reading call .IR firedns_getresult (3) to retrieve the results. The result will be a .B char * with the message from the listing server, or .B NULL if the IP address is not listed. .SH RETURN VALUE Returns an integer file descriptor that can be used the same as any other file descriptor. Returns .I -1 on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3), .BR firedns_getresult (3), .BR select (2) firedns/man/fdnstxt.10000644000175000017500000000073310012742301013546 0ustar useruser.\" (C) 2004 Ian Gulliver .TH fdnstxt 1 2004-02-12 .SH NAME fdnstxt \- resolve a TXT record of a hostname .SH SYNOPSIS .BI "fdnstxt " .SH DESCRIPTION fdnstxt will attempt to look up a single TXT record for .IR hostname . If one is found, it is printed to standard output and the program exits with return code 0. If not, nothing is printed and the program exits with return code 1. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/firedns_resolveip4.30000644000175000017500000000124007503645320015674 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_resolveip4 3 2002-03-31 .SH NAME firedns_resolveip4 \- Resolve a hostname to an IPv4 address .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "struct in_addr *firedns_resolveip4(const char * const " "name" ")" .br .BI "struct in_addr *firedns_resolveip4_r(const char * const " "name" ")" .SH DESCRIPTION firedns_resolveip4() attempts to resolve the hostname .I name to an IPv4 address. .SH RETURN VALUE Returns a pointer to an internal static .I struct in_addr that contains the IP address of .I name in binary format, or .I NULL on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/firedns_getip6list.30000644000175000017500000000147710012774171015702 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_getip6list 3 2004-02-12 .SH NAME firedns_getip6list \- Create a query to resolve a hostname to a list of IPv6 addresses .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "int firedns_getip6list(const char * const " "name" ")" .SH DESCRIPTION firedns_getip6list() creates and sends a request to resolve .I name to a list of IPv6 address. It returns a file descriptor that should be .IR select (2)'ed upon (read set). When the file descriptor shows ready for reading, call .IR firedns_getresult (3) to retrieve the results. .SH RETURN VALUE Returns an integer file descriptor that can be used the same as any other file descriptor. Returns .I -1 on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3), .BR firedns_getresult (3), .BR select (2) firedns/man/fdnsmxlist.10000644000175000017500000000111310012742301014240 0ustar useruser.\" (C) 2004 Ian Gulliver .TH fdnsmxlist 1 2004-02-12 .SH NAME fdnsmxlist \- resolve a list of MX records for hostname .SH SYNOPSIS .BI "fdnsmxlist " .SH DESCRIPTION fdnsmxlist will attempt to look up a list of MX records for .IR hostname . If any are found, they are printed to standard output seperated by newlines in the format: .IR " Protocol " ( Priority ) " hostname" : port and the program exits with return code 0. If not, nothing is printed and the program exits with return code 1. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/firedns_resolvemx.30000644000175000017500000000115207503645320015626 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_resolvemx 3 2002-03-31 .SH NAME firedns_resolvemx \- Resolve an MX record of a hostname .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "char *firedns_resolvemx(const char * const " "name" ")" .br .BI "char *firedns_resolvemx_r(const char * const " "name" ")" .SH DESCRIPTION firedns_resolvemx() attempts to resolve an MX record for the hostname .IR name . .SH RETURN VALUE Returns a pointer to an internal static .I char * that contains a MX record of .IR name , or .I NULL on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/fdnstxtlist.10000644000175000017500000000122610012774171014452 0ustar useruser.\" (C) 2004 Ian Gulliver .TH fdnstxtlist 1 2004-02-12 .SH NAME fdnstxtlist \- resolve a list of TXT records for a hostname .SH SYNOPSIS .BI "fdnstxtlist " .SH DESCRIPTION fdnstxtlist will attempt to look up a list of TXT records for .IR hostname . If any are found, they are printed to standard output seperated by newlines and the program exits with return code 0. If not, nothing is printed and the program exits with return code 1. .SH BUGS It is impossible to determine the difference between two TXT records and one TXT record containing a newline in the output. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/man/firedns_resolvetxt.30000644000175000017500000000116007503645320016020 0ustar useruser.\" (C) 2002 Ian Gulliver .TH firedns_resolvetxt 3 2002-03-31 .SH NAME firedns_resolvetxt \- Resolve a TXT record of a hostname .SH SYNOPSIS .B #include .br .B -lfiredns .LP .BI "char *firedns_resolvetxt(const char * const " "name" ")" .br .BI "char *firedns_resolvetxt_r(const char * const " "name" ")" .SH DESCRIPTION firedns_resolvetxt() attempts to resolve a TXT record for the hostname .IR name . .SH RETURN VALUE Returns a pointer to an internal static .I char * that contains a TXT record of .IR name , or .I NULL on error. .SH AUTHOR Ian Gulliver .SH SEE ALSO .BR libfiredns (3) firedns/fdnscname.c0000644000175000017500000000043710012504077013330 0ustar useruser#include #include "firedns.h" int main(int argc, char **argv) { char *result; if (argc != 2) { fprintf(stderr,"usage: %s \n",argv[0]); return 2; } result = firedns_resolvecname(argv[1]); if (result) { printf("%s\n",result); return 0; } return 1; } firedns/CREDITS0000644000175000017500000000006507464277622012267 0ustar useruserJoshua Rodd -- fix alignment issues firedns/fdnsmx.c0000644000175000017500000000047107564461455012713 0ustar useruser#include #include #include "firedns.h" int main(int argc, char **argv) { char *result; if (argc != 2) { fprintf(stderr,"usage: %s \n",argv[0]); return 2; } result = firedns_resolvemx(argv[1]); if (result != NULL) { printf("%s\n",result); return 0; } return 1; } firedns/firedns.c0000644000175000017500000013517310023637416013040 0ustar useruser/* firedns.c - firedns library Copyright (C) 2002 Ian Gulliver This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #define _FIREDNS_C #include #include #include #include #include #include #include #include #include #include #include #include #include "firemake.h" #include "firedns.h" static const char tagstring[] = "$Id: firedns.c,v 1.81 2004/03/10 15:14:35 ian Exp $"; const char firedns_version[] = VERSION; /* MXPS protocol default ports */ const int firedns_mx_port[] = { 25, 209, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; const char *firedns_mx_name[] = { "SMTP", "QMTP", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown", "Unknown" }; #define max(a,b) (a > b ? a : b) #define FDNS_MAX 8 /* max number of nameservers used */ #define FDNS_CONFIG_PREF "/etc/firedns.conf" /* preferred firedns config file */ #define FDNS_CONFIG_FBCK "/etc/resolv.conf" /* fallback config file */ #define FDNS_PORT 53 /* DNS well known port */ #define FDNS_QRY_A 1 /* name to IP address */ #define FDNS_QRY_AAAA 28 /* name to IP6 address */ #define FDNS_QRY_PTR 12 /* IP address to name */ #define FDNS_QRY_MX 15 /* name to MX */ #define FDNS_QRY_TXT 16 /* name to TXT */ #define FDNS_QRY_CNAME 5 #define FDNS_MXPS_START 12800 #define FDNS_MXPS_STOP 13055 #define FIREDNS_ALIGN (sizeof(void *) > sizeof(long) ? sizeof(void *) : sizeof(long)) #define FIREDNS_TRIES 3 #define RESULTSIZE 1024 #define min(a,b) (a < b ? a : b) static struct in_addr servers4[FDNS_MAX]; /* up to FDNS_MAX nameservers; populated by firedns_init() */ static int i4; /* actual count of nameservers; set by firedns_init() */ #ifdef HAVE_IPV6 static int i6; static struct in6_addr servers6[FDNS_MAX]; #endif static int initdone = 0; /* to ensure firedns_init() only runs once (on the first call) */ static int wantclose = 0; static int lastcreate = -1; struct s_connection { /* open DNS query */ struct s_connection *next; /* next in list */ unsigned char id[2]; /* unique ID (random number), matches header ID; both set by firedns_add_query() */ unsigned int class; unsigned int type; int want_list; int fd; /* file descriptor returned from sockets */ #ifdef HAVE_IPV6 int v6; #endif }; struct s_rr_middle { unsigned int type; unsigned int class; unsigned long ttl; unsigned int rdlength; }; #define FIREDNS_POINTER_VALUE 0xc000 static pthread_mutex_t connlist_lock = PTHREAD_MUTEX_INITIALIZER; static struct s_connection *connection_head = NULL; /* linked list of open DNS queries; populated by firedns_add_query(), decimated by firedns_getresult_s() */ struct s_header { /* DNS query header */ unsigned char id[2]; unsigned int flags1; #define FLAGS1_MASK_QR 0x80 #define FLAGS1_MASK_OPCODE 0x78 /* bitshift right 3 */ #define FLAGS1_MASK_AA 0x04 #define FLAGS1_MASK_TC 0x02 #define FLAGS1_MASK_RD 0x01 unsigned int flags2; #define FLAGS2_MASK_RA 0x80 #define FLAGS2_MASK_Z 0x70 #define FLAGS2_MASK_RCODE 0x0f unsigned int qdcount; unsigned int ancount; unsigned int nscount; unsigned int arcount; unsigned char payload[512]; /* DNS question, populated by firedns_build_query_payload() */ }; static inline void *firedns_align(void *inp) { char *p = inp; int offby = ((char *)p - (char *)0) % FIREDNS_ALIGN; if (offby != 0) return p + (FIREDNS_ALIGN - offby); else return p; } /* * These little hacks are here to avoid alignment and type sizing issues completely by doing manual copies */ static inline void firedns_fill_rr(struct s_rr_middle * restrict const rr, const unsigned char * const restrict input) { rr->type = input[0] * 256 + input[1]; rr->class = input[2] * 256 + input[3]; rr->ttl = input[4] * 16777216 + input[5] * 65536 + input[6] * 256 + input[7]; rr->rdlength = input[8] * 256 + input[9]; } static inline void firedns_fill_header(struct s_header * const restrict header, const unsigned char * const restrict input, const int l) { header->id[0] = input[0]; header->id[1] = input[1]; header->flags1 = input[2]; header->flags2 = input[3]; header->qdcount = input[4] * 256 + input[5]; header->ancount = input[6] * 256 + input[7]; header->nscount = input[8] * 256 + input[9]; header->arcount = input[10] * 256 + input[11]; memcpy(header->payload,&input[12],l); } static inline void firedns_empty_header(unsigned char * const restrict output, const struct s_header * const restrict header, const int l) { output[0] = header->id[0]; output[1] = header->id[1]; output[2] = header->flags1; output[3] = header->flags2; output[4] = header->qdcount / 256; output[5] = header->qdcount % 256; output[6] = header->ancount / 256; output[7] = header->ancount % 256; output[8] = header->nscount / 256; output[9] = header->nscount % 256; output[10] = header->arcount / 256; output[11] = header->arcount % 256; memcpy(&output[12],header->payload,l); } static inline void firedns_close(int fd) { /* close query */ if (fd == lastcreate) { wantclose = 1; return; } close(fd); return; } void firedns_init() { /* on first call only: populates servers4 (or -6) struct with up to FDNS_MAX nameserver IP addresses from /etc/firedns.conf (or /etc/resolv.conf) */ FILE *f; int i; struct in_addr addr4; char buf[1024]; #ifdef HAVE_IPV6 struct in6_addr addr6; #endif if (initdone == 1) return; #ifdef HAVE_IPV6 i6 = 0; #endif i4 = 0; initdone = 1; srand((unsigned int) time(NULL)); memset(servers4,'\0',sizeof(struct in_addr) * FDNS_MAX); #ifdef HAVE_IPV6 memset(servers6,'\0',sizeof(struct in6_addr) * FDNS_MAX); #endif /* read /etc/firedns.conf if we've got it, otherwise parse /etc/resolv.conf */ f = fopen(FDNS_CONFIG_PREF,"r"); if (f == NULL) { f = fopen(FDNS_CONFIG_FBCK,"r"); if (f == NULL) return; while (fgets(buf,1024,f) != NULL) { if (strncmp(buf,"nameserver",10) == 0) { i = 10; while (buf[i] == ' ' || buf[i] == '\t') i++; #ifdef HAVE_IPV6 /* glibc /etc/resolv.conf seems to allow ipv6 server names */ if (i6 < FDNS_MAX) { if (firedns_aton6_s(&buf[i],&addr6) != NULL) { memcpy(&servers6[i6++],&addr6,sizeof(struct in6_addr)); continue; } } #endif if (i4 < FDNS_MAX) { if (firedns_aton4_s(&buf[i],&addr4) != NULL) memcpy(&servers4[i4++],&addr4,sizeof(struct in_addr)); } } } } else { while (fgets(buf,1024,f) != NULL) { #ifdef HAVE_IPV6 if (i6 < FDNS_MAX) { if (firedns_aton6_s(buf,&addr6) != NULL) { memcpy(&servers6[i6++],&addr6,sizeof(struct in6_addr)); continue; } } #endif if (i4 < FDNS_MAX) { if (firedns_aton4_s(buf,&addr4) != NULL) memcpy(&servers4[i4++],&addr4,sizeof(struct in_addr)); } } } fclose(f); } static int firedns_send_requests(const struct s_header * restrict const h, const struct s_connection * restrict const s, const int l) { /* send DNS query */ int i; struct sockaddr_in addr4; unsigned char payload[sizeof(struct s_header)]; #ifdef HAVE_IPV6 struct sockaddr_in6 addr6; #endif firedns_empty_header(payload,h,l); #ifdef HAVE_IPV6 /* if we've got ipv6 support, an ip v6 socket, and ipv6 servers, send to them */ if (i6 > 0 && s->v6 == 1) { for (i = 0; i < i6; i++) { memset(&addr6,0,sizeof(addr6)); memcpy(&addr6.sin6_addr,&servers6[i],sizeof(addr6.sin6_addr)); addr6.sin6_family = AF_INET6; addr6.sin6_port = htons(FDNS_PORT); sendto(s->fd, payload, l + 12, 0, (struct sockaddr *) &addr6, sizeof(addr6)); } } #endif for (i = 0; i < i4; i++) { #ifdef HAVE_IPV6 /* send via ipv4-over-ipv6 if we've got an ipv6 socket */ if (s->v6 == 1) { memset(&addr6,0,sizeof(addr6)); memcpy(addr6.sin6_addr.s6_addr,"\0\0\0\0\0\0\0\0\0\0\xff\xff",12); memcpy(&addr6.sin6_addr.s6_addr[12],&servers4[i].s_addr,4); addr6.sin6_family = AF_INET6; addr6.sin6_port = htons(FDNS_PORT); sendto(s->fd, payload, l + 12, 0, (struct sockaddr *) &addr6, sizeof(addr6)); continue; } #endif /* otherwise send via standard ipv4 boringness */ memset(&addr4,0,sizeof(addr4)); memcpy(&addr4.sin_addr,&servers4[i],sizeof(addr4.sin_addr)); addr4.sin_family = AF_INET; addr4.sin_port = htons(FDNS_PORT); sendto(s->fd, payload, l + 12, 0, (struct sockaddr *) &addr4, sizeof(addr4)); } return 0; } static struct s_connection *firedns_add_query(struct s_header * restrict const h) { /* build DNS query, add to list */ struct s_connection * restrict s; s = firestring_malloc(sizeof(struct s_connection)); /* set header flags */ h->id[0] = s->id[0] = rand() % 255; /* verified by firedns_getresult_s() */ h->id[1] = s->id[1] = rand() % 255; h->flags1 = 0 | FLAGS1_MASK_RD; h->flags2 = 0; h->qdcount = 1; h->ancount = 0; h->nscount = 0; h->arcount = 0; /* turn off want_list by default */ s->want_list = 0; /* try to create ipv6 or ipv4 socket */ #ifdef HAVE_IPV6 s->v6 = 0; if (i6 > 0) { s->fd = socket(PF_INET6, SOCK_DGRAM, 0); if (s->fd != -1) { if (fcntl(s->fd, F_SETFL, O_NONBLOCK) != 0) { close(s->fd); s->fd = -1; } } if (s->fd != -1) { struct sockaddr_in6 addr6; memset(&addr6,0,sizeof(addr6)); addr6.sin6_family = AF_INET6; if (bind(s->fd,(struct sockaddr *)&addr6,sizeof(addr6)) == 0) s->v6 = 1; else close(s->fd); } } if (s->v6 == 0) { #endif s->fd = socket(PF_INET, SOCK_DGRAM, 0); if (s->fd != -1) { if (fcntl(s->fd, F_SETFL, O_NONBLOCK) != 0) { close(s->fd); s->fd = -1; } } if (s->fd != -1) { struct sockaddr_in addr; memset(&addr,0,sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = 0; addr.sin_addr.s_addr = INADDR_ANY; if (bind(s->fd,(struct sockaddr *)&addr,sizeof(addr)) != 0) { close(s->fd); s->fd = -1; } } if (s->fd == -1) { free(s); return NULL; } #ifdef HAVE_IPV6 } #endif /* create new connection object, add to linked list */ pthread_mutex_lock(&connlist_lock); s->next = connection_head; connection_head = s; if (wantclose == 1) { close(lastcreate); wantclose = 0; } lastcreate = s->fd; pthread_mutex_unlock(&connlist_lock); return s; } static int firedns_build_query_payload(const char * const name, const unsigned short rr, const unsigned short class, unsigned char * const payload) { /* populate payload with query: name= question, rr= record type */ short payloadpos; const char * tempchr, * tempchr2; unsigned short l; payloadpos = 0; tempchr2 = name; /* split name up into labels, create query */ while ((tempchr = strchr(tempchr2,'.')) != NULL) { l = tempchr - tempchr2; if (payloadpos + l + 1 > 507) return -1; payload[payloadpos++] = l; memcpy(&payload[payloadpos],tempchr2,l); payloadpos += l; tempchr2 = &tempchr[1]; } l = strlen(tempchr2); if (l) { if (payloadpos + l + 2 > 507) return -1; payload[payloadpos++] = l; memcpy(&payload[payloadpos],tempchr2,l); payloadpos += l; payload[payloadpos++] = '\0'; } if (payloadpos > 508) return -1; l = htons(rr); memcpy(&payload[payloadpos],&l,2); l = htons(class); memcpy(&payload[payloadpos + 2],&l,2); return payloadpos + 4; } struct in_addr *firedns_aton4(const char * const ipstring) { /* ascii to numeric: convert string to static 4part IP addr struct */ static struct in_addr ip; return firedns_aton4_s(ipstring,&ip); } struct in_addr *firedns_aton4_r(const char * restrict const ipstring) { /* ascii to numeric (reentrant): convert string to new 4part IP addr struct */ struct in_addr * restrict ip; ip = firestring_malloc(sizeof(struct in_addr)); if(firedns_aton4_s(ipstring,ip) == NULL) { free(ip); return NULL; } return ip; } struct in_addr *firedns_aton4_s(const char * restrict const ipstring, struct in_addr * restrict const ip) { /* ascii to numeric (buffered): convert string to given 4part IP addr struct */ unsigned char *myip; int i,part = 0; myip = (unsigned char *)ip; memset(myip,'\0',4); for (i = 0; i < 16; i++) { switch (ipstring[i]) { case '\0': if (part != 3) return NULL; return ip; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (myip[part] > 25) return NULL; myip[part] *= 10; if (myip[part] == 250 && ipstring[i] - '0' > 6) return NULL; myip[part] += ipstring[i] - '0'; break; case '.': if (part == 3) return ip; else part++; break; default: if (part == 3) return ip; else return NULL; break; } } if (part == 3) return ip; else return NULL; } struct in6_addr *firedns_aton6(const char * const ipstring) { static struct in6_addr ip; return firedns_aton6_s(ipstring,&ip); } struct in6_addr *firedns_aton6_r(const char * restrict const ipstring) { struct in6_addr * restrict ip; ip = firestring_malloc(sizeof(struct in6_addr)); if(firedns_aton6_s(ipstring,ip) == NULL) { free(ip); return NULL; } return ip; } struct in6_addr *firedns_aton6_s(const char * restrict const ipstring, struct in6_addr * restrict const ip) { /* black magic */ char instring[40]; char tempstr[5]; int i,o; int direction = 1; char *tempchr,*tempchr2;; i = strlen(ipstring); if (i > 39) return NULL; memcpy(instring,ipstring,i+1); memset(ip->s6_addr,'\0',16); tempchr2 = instring; i = 0; while (direction > 0) { if (direction == 1) { tempchr = strchr(tempchr2,':'); if (tempchr == NULL && i != 14) return NULL; if (tempchr != NULL) tempchr[0] = '\0'; o = strlen(tempchr2); if (o > 4) return NULL; strcpy(tempstr,"0000"); strcpy(&tempstr[4 - o],tempchr2); o = firestring_hextoi(tempstr); if (o == -1) return NULL; ip->s6_addr[i++] = o; o = firestring_hextoi(&tempstr[2]); if (o == -1) return NULL; ip->s6_addr[i++] = o; if (i >= 15) break; tempchr2 = tempchr + 1; if (tempchr2[0] == ':') { tempchr2++; direction = 2; i = 15; continue; } } if (direction == 2) { tempchr = strrchr(tempchr2,':'); if (tempchr == NULL) tempchr = tempchr2; else { tempchr[0] = '\0'; tempchr++; } o = strlen(tempchr); if (o > 4) return NULL; strcpy(tempstr,"0000"); strcpy(&tempstr[4 - o],tempchr); o = firestring_hextoi(&tempstr[2]); if (o == -1) return NULL; ip->s6_addr[i--] = o; o = firestring_hextoi(tempstr); if (o == -1) return NULL; ip->s6_addr[i--] = o; if (i <= 1) break; if (tempchr == tempchr2) break; } } return ip; } int firedns_getip4(const char * restrict const name) { /* build, add and send A query; retrieve result with firedns_getresult() */ struct s_header h; struct s_connection * restrict s; int l; firedns_init(); l = firedns_build_query_payload(name,FDNS_QRY_A,1,(unsigned char *)&h.payload); if (l == -1) return -1; s = firedns_add_query(&h); if (s == NULL) return -1; s->class = 1; s->type = FDNS_QRY_A; if (firedns_send_requests(&h,s,l) == -1) return -1; return s->fd; } int firedns_getip4list(const char * restrict const name) { /* build, add and send A query; retrieve result with firedns_getresult() */ struct s_header h; struct s_connection * restrict s; int l; firedns_init(); l = firedns_build_query_payload(name,FDNS_QRY_A,1,(unsigned char *)&h.payload); if (l == -1) return -1; s = firedns_add_query(&h); if (s == NULL) return -1; s->class = 1; s->type = FDNS_QRY_A; s->want_list = 1; if (firedns_send_requests(&h,s,l) == -1) return -1; return s->fd; } int firedns_getip6(const char * restrict const name) { struct s_header h; struct s_connection * restrict s; int l; firedns_init(); l = firedns_build_query_payload(name,FDNS_QRY_AAAA,1,(unsigned char *)&h.payload); if (l == -1) return -1; s = firedns_add_query(&h); if (s == NULL) return -1; s->class = 1; s->type = FDNS_QRY_AAAA; if (firedns_send_requests(&h,s,l) == -1) return -1; return s->fd; } int firedns_getip6list(const char * restrict const name) { struct s_header h; struct s_connection * restrict s; int l; firedns_init(); l = firedns_build_query_payload(name,FDNS_QRY_AAAA,1,(unsigned char *)&h.payload); if (l == -1) return -1; s = firedns_add_query(&h); if (s == NULL) return -1; s->class = 1; s->want_list = 1; s->type = FDNS_QRY_AAAA; if (firedns_send_requests(&h,s,l) == -1) return -1; return s->fd; } int firedns_gettxt(const char * restrict const name) { /* build, add and send TXT query; retrieve result with firedns_getresult() */ struct s_header h; struct s_connection * restrict s; int l; firedns_init(); l = firedns_build_query_payload(name,FDNS_QRY_TXT,1,(unsigned char *)&h.payload); if (l == -1) return -1; s = firedns_add_query(&h); if (s == NULL) return -1; s->class = 1; s->type = FDNS_QRY_TXT; if (firedns_send_requests(&h,s,l) == -1) return -1; return s->fd; } int firedns_gettxtlist(const char * restrict const name) { /* build, add and send TXT query; retrieve result with firedns_getresult() */ struct s_header h; struct s_connection * restrict s; int l; firedns_init(); l = firedns_build_query_payload(name,FDNS_QRY_TXT,1,(unsigned char *)&h.payload); if (l == -1) return -1; s = firedns_add_query(&h); if (s == NULL) return -1; s->class = 1; s->want_list = 1; s->type = FDNS_QRY_TXT; if (firedns_send_requests(&h,s,l) == -1) return -1; return s->fd; } int firedns_getmx(const char * restrict const name) { /* build, add and send MX query; retrieve result with firedns_getresult() */ struct s_header h; struct s_connection * restrict s; int l; firedns_init(); l = firedns_build_query_payload(name,FDNS_QRY_MX,1,(unsigned char *)&h.payload); if (l == -1) return -1; s = firedns_add_query(&h); if (s == NULL) return -1; s->class = 1; s->type = FDNS_QRY_MX; if (firedns_send_requests(&h,s,l) == -1) return -1; return s->fd; } int firedns_getmxlist(const char * const name) { struct s_header h; struct s_connection * restrict s; int l; firedns_init(); l = firedns_build_query_payload(name,FDNS_QRY_MX,1,(unsigned char *)&h.payload); if (l == -1) return -1; s = firedns_add_query(&h); if (s == NULL) return -1; s->class = 1; s->type = FDNS_QRY_MX; s->want_list = 1; if (firedns_send_requests(&h,s,l) == -1) return -1; return s->fd; } int firedns_getname4(const struct in_addr * restrict const ip) { /* build, add and send PTR query; retrieve result with firedns_getresult() */ char query[512]; struct s_header h; struct s_connection * restrict s; unsigned char *c; int l; firedns_init(); c = (unsigned char *)&ip->s_addr; sprintf(query,"%d.%d.%d.%d.in-addr.arpa",c[3],c[2],c[1],c[0]); l = firedns_build_query_payload(query,FDNS_QRY_PTR,1,(unsigned char *)&h.payload); if (l == -1) return -1; s = firedns_add_query(&h); if (s == NULL) return -1; s->class = 1; s->type = FDNS_QRY_PTR; if (firedns_send_requests(&h,s,l) == -1) return -1; return s->fd; } int firedns_getname6(const struct in6_addr * restrict const ip) { char query[512]; struct s_header h; struct s_connection * restrict s; int l; firedns_init(); sprintf(query,"%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.%0x.ip6.int", ip->s6_addr[15] & 0x0f, (ip->s6_addr[15] & 0xf0) >> 4, ip->s6_addr[14] & 0x0f, (ip->s6_addr[14] & 0xf0) >> 4, ip->s6_addr[13] & 0x0f, (ip->s6_addr[13] & 0xf0) >> 4, ip->s6_addr[12] & 0x0f, (ip->s6_addr[12] & 0xf0) >> 4, ip->s6_addr[11] & 0x0f, (ip->s6_addr[11] & 0xf0) >> 4, ip->s6_addr[10] & 0x0f, (ip->s6_addr[10] & 0xf0) >> 4, ip->s6_addr[9] & 0x0f, (ip->s6_addr[9] & 0xf0) >> 4, ip->s6_addr[8] & 0x0f, (ip->s6_addr[8] & 0xf0) >> 4, ip->s6_addr[7] & 0x0f, (ip->s6_addr[7] & 0xf0) >> 4, ip->s6_addr[6] & 0x0f, (ip->s6_addr[6] & 0xf0) >> 4, ip->s6_addr[5] & 0x0f, (ip->s6_addr[5] & 0xf0) >> 4, ip->s6_addr[4] & 0x0f, (ip->s6_addr[4] & 0xf0) >> 4, ip->s6_addr[3] & 0x0f, (ip->s6_addr[3] & 0xf0) >> 4, ip->s6_addr[2] & 0x0f, (ip->s6_addr[2] & 0xf0) >> 4, ip->s6_addr[1] & 0x0f, (ip->s6_addr[1] & 0xf0) >> 4, ip->s6_addr[0] & 0x0f, (ip->s6_addr[0] & 0xf0) >> 4 ); l = firedns_build_query_payload(query,FDNS_QRY_PTR,1,(unsigned char *)&h.payload); if (l == -1) return -1; s = firedns_add_query(&h); if (s == NULL) return -1; s->class = 1; s->type = FDNS_QRY_PTR; if (firedns_send_requests(&h,s,l) == -1) return -1; return s->fd; } int firedns_getcname(const char * restrict const name) { struct s_header h; struct s_connection * restrict s; int l; firedns_init(); l = firedns_build_query_payload(name,FDNS_QRY_CNAME,1,(unsigned char *)&h.payload); if (l == -1) return -1; s = firedns_add_query(&h); if (s == NULL) return -1; s->class = 1; s->type = FDNS_QRY_CNAME; if (firedns_send_requests(&h,s,l) == -1) return -1; return s->fd; } int firedns_dnsbl_lookup_a(const struct in_addr * restrict const ip, const char * restrict const name) { /* build, add and send A query to given DNSBL list; retrieve result with firedns_getresult() */ char hostname[256]; firestring_snprintf(hostname,256,"%u.%u.%u.%u.%s",(unsigned int) ((unsigned char *)&ip->s_addr)[3],(unsigned int) ((unsigned char *)&ip->s_addr)[2],(unsigned int) ((unsigned char *)&ip->s_addr)[1],(unsigned int) ((unsigned char *)&ip->s_addr)[0],name); return firedns_getip4(hostname); } int firedns_dnsbl_lookup_txt(const struct in_addr * restrict const ip, const char * restrict const name) { /* build, add and send TXT query to given DNSBL list; retrieve result with firedns_getresult() */ char hostname[256]; firestring_snprintf(hostname,256,"%u.%u.%u.%u.%s",(unsigned int) ((unsigned char *)&ip->s_addr)[3],(unsigned int) ((unsigned char *)&ip->s_addr)[2],(unsigned int) ((unsigned char *)&ip->s_addr)[1],(unsigned int) ((unsigned char *)&ip->s_addr)[0],name); return firedns_gettxt(hostname); } char *firedns_ntoa4(const struct in_addr * const ip) { /* numeric to ascii: convert 4part IP addr struct to static string */ static char result[256]; return firedns_ntoa4_s(ip,result); } char *firedns_ntoa4_r(const struct in_addr * restrict const ip) { /* numeric to ascii (reentrant): convert 4part IP addr struct to new string */ char * restrict result; result = firestring_malloc(256); return firedns_ntoa4_s(ip,result); } char *firedns_ntoa4_s(const struct in_addr * restrict const ip, char * restrict const result) { /* numeric to ascii (buffered): convert 4part IP addr struct to given string */ unsigned char *m; m = (unsigned char *)&ip->s_addr; sprintf(result,"%d.%d.%d.%d",m[0],m[1],m[2],m[3]); return result; } char *firedns_ntoa6(const struct in6_addr *ip) { static char result[256]; return firedns_ntoa6_s(ip,result); } char *firedns_ntoa6_r(const struct in6_addr * restrict ip) { char * restrict result; result = firestring_malloc(256); return firedns_ntoa6_s(ip,result); } char *firedns_ntoa6_s(const struct in6_addr * restrict const ip, char * restrict const result) { char *c; sprintf(result,"%x:%x:%x:%x:%x:%x:%x:%x", ntohs(*((unsigned short *)&ip->s6_addr[0])), ntohs(*((unsigned short *)&ip->s6_addr[2])), ntohs(*((unsigned short *)&ip->s6_addr[4])), ntohs(*((unsigned short *)&ip->s6_addr[6])), ntohs(*((unsigned short *)&ip->s6_addr[8])), ntohs(*((unsigned short *)&ip->s6_addr[10])), ntohs(*((unsigned short *)&ip->s6_addr[12])), ntohs(*((unsigned short *)&ip->s6_addr[14]))); c = strstr(result,":0:"); if (c != NULL) { memmove(c+1,c+2,strlen(c+2) + 1); c += 2; while (memcmp(c,"0:",2) == 0) memmove(c,c+2,strlen(c+2) + 1); if (memcmp(c,"0",2) == 0) *c = '\0'; if (memcmp(result,"0::",3) == 0) memmove(result,result + 1, strlen(result + 1) + 1); } return result; } char *firedns_getresult(const int fd) { /* retrieve result of DNS query */ static char result[RESULTSIZE]; return firedns_getresult_s(fd,result); } char *firedns_getresult_r(const int fd) { /* retrieve result of DNS query (reentrant) */ char *result; result = firestring_malloc(RESULTSIZE); if(firedns_getresult_s(fd,result) == NULL) { free(result); return NULL; } return result; } char *firedns_getresult_s(const int fd, char * restrict const result) { /* retrieve result of DNS query (buffered) */ struct s_header h; struct s_connection * restrict c, *prev; int l,i,q,curanswer,o; struct s_rr_middle rr; unsigned char buffer[sizeof(struct s_header)]; unsigned short p; prev = NULL; pthread_mutex_lock(&connlist_lock); c = connection_head; while (c != NULL) { /* find query in list of open queries */ if (c->fd == fd) break; prev = c; c = c->next; } if (c == NULL) { pthread_mutex_unlock(&connlist_lock); return NULL; /* query not found */ } /* query found-- pull from list: */ if (prev != NULL) prev->next = c->next; else connection_head = c->next; pthread_mutex_unlock(&connlist_lock); l = recv(c->fd,buffer,sizeof(struct s_header),0); firedns_close(c->fd); if (l < 12) { free(c); return NULL; } firedns_fill_header(&h,buffer,l - 12); if (c->id[0] != h.id[0] || c->id[1] != h.id[1]) { free(c); return NULL; /* ID mismatch */ } if ((h.flags1 & FLAGS1_MASK_QR) == 0) { free(c); return NULL; } if ((h.flags1 & FLAGS1_MASK_OPCODE) != 0) { free(c); return NULL; } if ((h.flags2 & FLAGS2_MASK_RCODE) != 0) { free(c); return NULL; } if (h.ancount < 1) { /* no sense going on if we don't have any answers */ free(c); return NULL; } /* skip queries */ i = 0; q = 0; l -= 12; while (q < h.qdcount && i < l) { if (h.payload[i] > 63) { /* pointer */ i += 6; /* skip pointer, class and type */ q++; } else { /* label */ if (h.payload[i] == 0) { q++; i += 5; /* skip nil, class and type */ } else i += h.payload[i] + 1; /* skip length and label */ } } /* &h.payload[i] should now be the start of the first response */ curanswer = 0; while (curanswer < h.ancount) { q = 0; while (q == 0 && i < l) { if (h.payload[i] > 63) { /* pointer */ i += 2; /* skip pointer */ q = 1; } else { /* label */ if (h.payload[i] == 0) { i++; q = 1; } else i += h.payload[i] + 1; /* skip length and label */ } } if (l - i < 10) { free(c); return NULL; } firedns_fill_rr(&rr,&h.payload[i]); i += 10; if (rr.type != c->type) { curanswer++; i += rr.rdlength; continue; } if (rr.class != c->class) { curanswer++; i += rr.rdlength; continue; } break; } if (curanswer == h.ancount) return NULL; if (i + rr.rdlength > l) return NULL; if (rr.rdlength > 1023) return NULL; switch (rr.type) { case FDNS_QRY_PTR: case FDNS_QRY_CNAME: o = 0; q = 0; while (q == 0 && i < l && o + 256 < 1023) { if (h.payload[i] > 63) { /* pointer */ memcpy(&p,&h.payload[i],2); i = ntohs(p) - FIREDNS_POINTER_VALUE - 12; } else { /* label */ if (h.payload[i] == 0) q = 1; else { result[o] = '\0'; if (o != 0) result[o++] = '.'; memcpy(&result[o],&h.payload[i + 1],h.payload[i]); o += h.payload[i]; i += h.payload[i] + 1; } } } result[o] = '\0'; break; case FDNS_QRY_MX: if (c->want_list) { struct firedns_mxlist *mxa = (struct firedns_mxlist *) result; /* we have to trust that this is aligned */ int g; while ((char *)mxa - (char *)result < 700) { mxa->ip4list = NULL; mxa->cname = NULL; g = i + rr.rdlength; curanswer++; mxa->priority = h.payload[i] * 256 + h.payload[i+1]; if (mxa->priority >= FDNS_MXPS_START && mxa->priority <= FDNS_MXPS_STOP) mxa->protocol = mxa->priority % 16; else mxa->protocol = FIREDNS_MX_SMTP; mxa->name = (char *)mxa + sizeof(struct firedns_mxlist); i += 2; o = 0; q = 0; while (q == 0 && i < l && o + 256 < 1023) { if (h.payload[i] > 63) { /* pointer */ memcpy(&p,&h.payload[i],2); i = ntohs(p) - FIREDNS_POINTER_VALUE - 12; } else { /* label */ if (h.payload[i] == 0) q = 1; else { mxa->name[o] = '\0'; if (o != 0) mxa->name[o++] = '.'; memcpy(&mxa->name[o],&h.payload[i + 1],h.payload[i]); o += h.payload[i]; i += h.payload[i] + 1; } } } mxa->name[o++] = '\0'; mxa->next = NULL; i = g; if (curanswer < h.ancount) { q = 0; while (q == 0 && i < l) { if (h.payload[i] > 63) { /* pointer */ i += 2; /* skip pointer */ q = 1; } else { /* label */ if (h.payload[i] == 0) { i++; q = 1; } else i += h.payload[i] + 1; /* skip length and label */ } } if (l - i < 10) { free(c); return NULL; } firedns_fill_rr(&rr,&h.payload[i]); i += 10; if (rr.type != FDNS_QRY_MX) break; if (rr.class != 1) break; mxa->next = (struct firedns_mxlist *) firedns_align((((char *) mxa) + sizeof(struct firedns_mxlist) + o)); mxa = mxa->next; } else { break; } } mxa->next = NULL; } else { i += 2; o = 0; q = 0; while (q == 0 && i < l && o + 256 < 1023) { if (h.payload[i] > 63) { /* pointer */ memcpy(&p,&h.payload[i],2); i = ntohs(p) - FIREDNS_POINTER_VALUE - 12; } else { /* label */ if (h.payload[i] == 0) q = 1; else { result[o] = '\0'; if (o != 0) result[o++] = '.'; memcpy(&result[o],&h.payload[i + 1],h.payload[i]); o += h.payload[i]; i += h.payload[i] + 1; } } } result[o] = '\0'; } break; case FDNS_QRY_TXT: if (c->want_list) { struct firedns_txtlist *txtlist = (struct firedns_txtlist *) result; /* we have to trust that this is aligned */ while ((char *)txtlist - (char *)result < 700) { if (rr.type != FDNS_QRY_TXT) break; if (rr.class != 1) break; { unsigned char *end, *trailer; int o; txtlist->txt = firedns_align(((char *)txtlist) + sizeof(struct firedns_txtlist)); trailer = &h.payload[i]; end = &h.payload[i] + rr.rdlength; o = 0; while (trailer < end) { unsigned char l; l = trailer[0]; if (trailer + l > end) { /* cheating the system */ free(c); return NULL; } memcpy(&txtlist->txt[o],&trailer[1],l); o += l; trailer += l + 1; } txtlist->txt[o] = '\0'; } if (++curanswer >= h.ancount) break; i += rr.rdlength; { /* skip next name */ q = 0; while (q == 0 && i < l) { if (h.payload[i] > 63) { /* pointer */ i += 2; /* skip pointer */ q = 1; } else { /* label */ if (h.payload[i] == 0) { i++; q = 1; } else i += h.payload[i] + 1; /* skip length and label */ } } } if (l - i < 10) { free(c); return NULL; } firedns_fill_rr(&rr,&h.payload[i]); i += 10; txtlist->next = (struct firedns_txtlist *) firedns_align(txtlist->txt + strlen(txtlist->txt) + 1); txtlist = txtlist->next; txtlist->next = NULL; } txtlist->next = NULL; break; } else { unsigned char *end, *trailer; int o = 0; trailer = &h.payload[i]; end = &h.payload[i] + rr.rdlength; while (trailer < end) { unsigned char l = trailer[0]; if (trailer + l > end) { /* cheating the system */ free(c); return NULL; } memcpy(&result[o],&trailer[1],l); o += l; trailer += l + 1; } result[o] = '\0'; } break; case FDNS_QRY_A: if (c->want_list) { struct firedns_ip4list *alist = (struct firedns_ip4list *) result; /* we have to trust that this is aligned */ while ((char *)alist - (char *)result < 700) { if (rr.type != FDNS_QRY_A) break; if (rr.class != 1) break; if (rr.rdlength != 4) { free(c); return NULL; } memcpy(&alist->ip,&h.payload[i],4); if (++curanswer >= h.ancount) break; i += rr.rdlength; { /* skip next name */ q = 0; while (q == 0 && i < l) { if (h.payload[i] > 63) { /* pointer */ i += 2; /* skip pointer */ q = 1; } else { /* label */ if (h.payload[i] == 0) { i++; q = 1; } else i += h.payload[i] + 1; /* skip length and label */ } } } if (l - i < 10) { free(c); return NULL; } firedns_fill_rr(&rr,&h.payload[i]); i += 10; alist->next = (struct firedns_ip4list *) firedns_align(((char *) alist) + sizeof(struct firedns_ip4list)); alist = alist->next; alist->next = NULL; } alist->next = NULL; break; } goto defaultcase; break; case FDNS_QRY_AAAA: if (c->want_list) { struct firedns_ip6list *alist = (struct firedns_ip6list *) result; /* we have to trust that this is aligned */ while ((char *)alist - (char *)result < 700) { if (rr.type != FDNS_QRY_AAAA) break; if (rr.class != 1) break; if (rr.rdlength != 16) { free(c); return NULL; } memcpy(&alist->ip,&h.payload[i],16); if (++curanswer >= h.ancount) break; i += rr.rdlength; { /* skip next name */ q = 0; while (q == 0 && i < l) { if (h.payload[i] > 63) { /* pointer */ i += 2; /* skip pointer */ q = 1; } else { /* label */ if (h.payload[i] == 0) { i++; q = 1; } else i += h.payload[i] + 1; /* skip length and label */ } } } if (l - i < 10) { free(c); return NULL; } firedns_fill_rr(&rr,&h.payload[i]); i += 10; alist->next = (struct firedns_ip6list *) firedns_align(((char *) alist) + sizeof(struct firedns_ip6list)); alist = alist->next; alist->next = NULL; } alist->next = NULL; break; } goto defaultcase; break; default: defaultcase: memcpy(result,&h.payload[i],rr.rdlength); result[rr.rdlength] = '\0'; break; } free(c); return result; } static inline struct in_addr *firedns_resolveip4_i(const char * restrict const name, char *(* const result)(int)) { /* immediate A query */ int fd; int t,i; struct in_addr * restrict ret; fd_set s; struct timeval tv; for (t = 0; t < FIREDNS_TRIES; t++) { fd = firedns_getip4(name); if (fd == -1) return NULL; tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&s); FD_SET(fd,&s); i = select(fd + 1,&s,NULL,NULL,&tv); ret = (struct in_addr *) result(fd); if (ret != NULL || i != 0) return ret; } return NULL; } struct in_addr *firedns_resolveip4(const char * const name) { /* immediate A query */ return firedns_resolveip4_i(name,firedns_getresult); } struct in_addr *firedns_resolveip4_r(const char * const name) { /* immediate A query (reentrant) */ return firedns_resolveip4_i(name,firedns_getresult_r); } static inline struct firedns_ip4list *firedns_resolveip4list_i(const char * restrict const name, char *(* const result)(int)) { /* immediate A query */ int fd; int t,i; struct firedns_ip4list * restrict ret; fd_set s; struct timeval tv; for (t = 0; t < FIREDNS_TRIES; t++) { fd = firedns_getip4list(name); if (fd == -1) return NULL; tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&s); FD_SET(fd,&s); i = select(fd + 1,&s,NULL,NULL,&tv); ret = (struct firedns_ip4list *) result(fd); if (ret != NULL || i != 0) return ret; } return NULL; } struct firedns_ip4list *firedns_resolveip4list(const char * const name) { /* immediate A query */ return firedns_resolveip4list_i(name,firedns_getresult); } struct firedns_ip4list *firedns_resolveip4list_r(const char * const name) { /* immediate A query (reentrant) */ return firedns_resolveip4list_i(name,firedns_getresult_r); } static inline struct in6_addr *firedns_resolveip6_i(const char * restrict const name, char *(* const result)(int)) { int fd; int t,i; struct in6_addr * restrict ret; fd_set s; struct timeval tv; for (t = 0; t < FIREDNS_TRIES; t++) { fd = firedns_getip6(name); if (fd == -1) return NULL; tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&s); FD_SET(fd,&s); i = select(fd + 1,&s,NULL,NULL,&tv); ret = (struct in6_addr *) result(fd); if (ret != NULL || i != 0) return ret; } return NULL; } struct in6_addr *firedns_resolveip6(const char * const name) { return firedns_resolveip6_i(name,firedns_getresult); } struct in6_addr *firedns_resolevip6_r(const char * const name) { return firedns_resolveip6_i(name,firedns_getresult_r); } static inline struct firedns_ip6list *firedns_resolveip6list_i(const char * restrict const name, char *(* const result)(int)) { int fd; int t,i; struct firedns_ip6list * restrict ret; fd_set s; struct timeval tv; for (t = 0; t < FIREDNS_TRIES; t++) { fd = firedns_getip6list(name); if (fd == -1) return NULL; tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&s); FD_SET(fd,&s); i = select(fd + 1,&s,NULL,NULL,&tv); ret = (struct firedns_ip6list *) result(fd); if (ret != NULL || i != 0) return ret; } return NULL; } struct firedns_ip6list *firedns_resolveip6list(const char * const name) { return firedns_resolveip6list_i(name,firedns_getresult); } struct firedns_ip6list *firedns_resolveip6list_r(const char * const name) { return firedns_resolveip6list_i(name,firedns_getresult_r); } static inline char *firedns_resolvetxt_i(const char * restrict const name, char *(* const result)(int)) { int fd; int t,i; char * restrict ret; fd_set s; struct timeval tv; for (t = 0; t < FIREDNS_TRIES; t++) { fd = firedns_gettxt(name); if (fd == -1) return NULL; tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&s); FD_SET(fd,&s); i = select(fd + 1,&s,NULL,NULL,&tv); ret = result(fd); if (ret != NULL || i != 0) return ret; } return NULL; } char *firedns_resolvetxt(const char * const name) { /* immediate TXT query */ return firedns_resolvetxt_i(name,firedns_getresult); } char *firedns_resolvetxt_r(const char * const name) { return firedns_resolvetxt_i(name,firedns_getresult_r); } static inline struct firedns_txtlist *firedns_resolvetxtlist_i(const char * restrict const name, char *(* const result)(int)) { int fd; int t,i; struct firedns_txtlist * restrict ret; fd_set s; struct timeval tv; for (t = 0; t < FIREDNS_TRIES; t++) { fd = firedns_gettxtlist(name); if (fd == -1) return NULL; tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&s); FD_SET(fd,&s); i = select(fd + 1,&s,NULL,NULL,&tv); ret = (struct firedns_txtlist *) result(fd); if (ret != NULL || i != 0) return ret; } return NULL; } struct firedns_txtlist *firedns_resolvetxtlist(const char * const name) { return firedns_resolvetxtlist_i(name,firedns_getresult); } struct firedns_txtlist *firedns_resolvetxtlist_r(const char * const name) { return firedns_resolvetxtlist_i(name,firedns_getresult_r); } static inline char *firedns_resolvemx_i(const char * restrict const name, char *(* const result)(int)) { int fd; int t,i; char * restrict ret; fd_set s; struct timeval tv; for (t = 0; t < FIREDNS_TRIES; t++) { fd = firedns_getmx(name); if (fd == -1) return NULL; tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&s); FD_SET(fd,&s); i = select(fd + 1,&s,NULL,NULL,&tv); ret = result(fd); if (ret != NULL || i != 0) return ret; } return NULL; } char *firedns_resolvemx(const char * const name) { /* immediate MX query */ return firedns_resolvemx_i(name,firedns_getresult); } char *firedns_resolvemx_r(const char * const name) { return firedns_resolvemx_i(name,firedns_getresult_r); } static inline struct firedns_mxlist *firedns_resolvemxlist_i(const char * restrict const name, char *(* const result)(int)) { int fd; int t,i; struct firedns_mxlist * restrict ret; fd_set s; struct timeval tv; for (t = 0; t < FIREDNS_TRIES; t++) { fd = firedns_getmxlist(name); if (fd == -1) return NULL; tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&s); FD_SET(fd,&s); i = select(fd + 1,&s,NULL,NULL,&tv); ret = (struct firedns_mxlist *) result(fd); if (ret != NULL || i != 0) return ret; } return NULL; } struct firedns_mxlist *firedns_resolvemxlist(const char * const name) { return firedns_resolvemxlist_i(name,firedns_getresult); } struct firedns_mxlist *firedns_resolvemxlist_r(const char * const name) { return firedns_resolvemxlist_i(name,firedns_getresult_r); } struct firedns_mxlist *firedns_resolvemxalist(const char * const name) { int t,i,n,c = 0; int cname_fd[256] = {0}; int alist_fd[256] = {0}; int a6list_fd[256] = {0}; void *ret; struct firedns_mxlist *mxlist, *iter; fd_set s; struct timeval tv; int firstround = 1; mxlist = firedns_resolvemxlist_r(name); if (mxlist == NULL) { mxlist = firestring_malloc(sizeof(struct firedns_mxlist) + strlen(name) + 1 + FIREDNS_ALIGN); mxlist->next = NULL; mxlist->cname = NULL; mxlist->ip4list = NULL; mxlist->ip6list = NULL; mxlist->protocol = FIREDNS_MX_SMTP; mxlist->priority = 0; mxlist->name = firedns_align(((char *)mxlist) + sizeof(struct firedns_mxlist)); strcpy(mxlist->name,name); } /* walk the list and allocate A space */ iter = mxlist; while (iter != NULL) { iter->ip4list = firestring_malloc(RESULTSIZE); iter->ip6list = firestring_malloc(RESULTSIZE); iter->cname = firestring_malloc(RESULTSIZE); iter = iter->next; c += 3; } /* check CNAME and A list records for each MX returned */ for (t = 0; t < FIREDNS_TRIES; t++) { iter = mxlist; n = i = 0; FD_ZERO(&s); while (iter != NULL) { if (cname_fd[i] != -1) { if (!firstround) (void) firedns_getresult(cname_fd[i]); cname_fd[i] = firedns_getcname(iter->name); if (cname_fd[i] == -1) { firedns_free_mxalist(mxlist); return NULL; } FD_SET(cname_fd[i],&s); n = max(n,cname_fd[i]); } if (alist_fd[i] != -1) { if (!firstround) (void) firedns_getresult(alist_fd[i]); alist_fd[i] = firedns_getip4list(iter->name); if (alist_fd[i] == -1) { firedns_free_mxalist(mxlist); return NULL; } FD_SET(alist_fd[i],&s); n = max(n,alist_fd[i]); } if (a6list_fd[i] != -1) { if (!firstround) (void) firedns_getresult(a6list_fd[i]); a6list_fd[i] = firedns_getip6list(iter->name); if (a6list_fd[i] == -1) { firedns_free_mxalist(mxlist); return NULL; } FD_SET(a6list_fd[i],&s); n = max(n,a6list_fd[i]); } i++; iter = iter->next; } firstround = 0; tv.tv_sec = 5; tv.tv_usec = 0; i = select(n + 1,&s,NULL,NULL,&tv); /* hack to make FIREDNS_TRIES sorta work as expected */ if (i == 0) continue; else t--; iter = mxlist; i = 0; while (iter != NULL) { if (cname_fd[i] != -1 && FD_ISSET(cname_fd[i],&s)) { ret = firedns_getresult_s(cname_fd[i],iter->cname); if (ret == NULL) { free(iter->cname); iter->cname = NULL; } cname_fd[i] = -1; c--; } if (alist_fd[i] != -1 && FD_ISSET(alist_fd[i],&s)) { ret = firedns_getresult_s(alist_fd[i],(char *)iter->ip4list); if (ret == NULL) { free(iter->ip4list); iter->ip4list = NULL; } alist_fd[i] = -1; c--; } if (a6list_fd[i] != -1 && FD_ISSET(a6list_fd[i],&s)) { ret = firedns_getresult_s(a6list_fd[i],(char *)iter->ip6list); if (ret == NULL) { free(iter->ip6list); iter->ip6list = NULL; } a6list_fd[i] = -1; c--; } i++; iter = iter->next; } if (c == 0) return mxlist; } iter = mxlist; i = 0; while (iter != NULL && c > 0) { if (cname_fd[i] != -1) { (void) firedns_getresult(cname_fd[i]); free(iter->cname); iter->cname = NULL; cname_fd[i] = -1; c--; } if (alist_fd[i] != -1) { (void) firedns_getresult(alist_fd[i]); free(iter->ip4list); iter->ip4list = NULL; alist_fd[i] = -1; c--; } if (a6list_fd[i] != -1) { (void) firedns_getresult(a6list_fd[i]); free(iter->ip6list); iter->ip6list = NULL; a6list_fd[i] = -1; c--; } i++; iter = iter->next; } free(mxlist); return NULL; } static inline char *firedns_resolvename4_i(const struct in_addr * restrict const ip, char *(* const result)(int)) { int fd; int t,i; char * restrict ret; fd_set s; struct timeval tv; for (t = 0; t < FIREDNS_TRIES; t++) { fd = firedns_getname4(ip); if (fd == -1) return NULL; tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&s); FD_SET(fd,&s); i = select(fd + 1,&s,NULL,NULL,&tv); ret = result(fd); if (ret != NULL || i != 0) return ret; } return NULL; } char *firedns_resolvename4(const struct in_addr * const ip) { /* immediate PTR query */ return firedns_resolvename4_i(ip,firedns_getresult); } char *firedns_resolvename4_r(const struct in_addr * const ip) { return firedns_resolvename4_i(ip,firedns_getresult_r); } static inline char *firedns_resolvename6_i(const struct in6_addr * restrict const ip, char *(* const result)(int)) { int fd; int t,i; char * restrict ret; fd_set s; struct timeval tv; for (t = 0; t < FIREDNS_TRIES; t++) { fd = firedns_getname6(ip); if (fd == -1) return NULL; tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&s); FD_SET(fd,&s); i = select(fd + 1,&s,NULL,NULL,&tv); ret = result(fd); if (ret != NULL || i != 0) return ret; } return NULL; } char *firedns_resolvename6(const struct in6_addr * const ip) { return firedns_resolvename6_i(ip,firedns_getresult); } char *firedns_resolvename6_r(const struct in6_addr * const ip) { return firedns_resolvename6_i(ip,firedns_getresult_r); } static inline char *firedns_resolvecname_i(const char * restrict const name, char *(* const result)(int)) { int fd; int t,i; char * restrict ret; fd_set s; struct timeval tv; for (t = 0; t < FIREDNS_TRIES; t++) { fd = firedns_getcname(name); if (fd == -1) return NULL; tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&s); FD_SET(fd,&s); i = select(fd + 1,&s,NULL,NULL,&tv); ret = result(fd); if (ret != NULL || i != 0) return ret; } return NULL; } char *firedns_resolvecname(const char * const name) { return firedns_resolvecname_i(name,firedns_getresult); } char *firedns_resolvecname_r(const char * const name) { return firedns_resolvecname_i(name,firedns_getresult_r); } void firedns_free_mxalist(struct firedns_mxlist *list) { struct firedns_mxlist *iter; iter = list; while (iter != NULL) { if (iter->cname != NULL) free(iter->cname); if (iter->ip4list != NULL) free(iter->ip4list); if (iter->ip6list != NULL) free(iter->ip6list); iter = iter->next; } free(list); } firedns/fdnstxtlist.c0000644000175000017500000000057110012771471013763 0ustar useruser#include #include #include "firedns.h" int main(int argc, char **argv) { struct firedns_txtlist *iter; if (argc != 2) { fprintf(stderr,"usage: %s \n",argv[0]); return 2; } iter = firedns_resolvetxtlist(argv[1]); if (iter == NULL) return 1; while (iter != NULL) { printf("%s\n",iter->txt); iter = iter->next; } return 0; } firedns/firemake.binaries0000644000175000017500000000074110013211376014523 0ustar userusertester: tester.o firedns.o benchmark: benchmark.o firedns.o fdnsip: fdnsip.o firedns.o fdnsip6: fdnsip6.o firedns.o fdnsiplist: fdnsiplist.o firedns.o fdnsip6list: fdnsip6list.o firedns.o fdnstxt: fdnstxt.o firedns.o fdnstxtlist: fdnstxtlist.o firedns.o fdnsname: fdnsname.o firedns.o fdnsnamep: fdnsnamep.o firedns.o fdnsmx: fdnsmx.o firedns.o fdnsmxlist: fdnsmxlist.o firedns.o fdnsmxalist: fdnsmxalist.o firedns.o fdnscname: fdnscname.o firedns.o fdnsspf1: fdnsspf1.o firedns.o firedns/fdnsip.c0000644000175000017500000000046610013014330012644 0ustar useruser#include #include "firedns.h" int main(int argc, char **argv) { struct in_addr *result; if (argc != 2) { fprintf(stderr,"usage: %s \n",argv[0]); return 2; } result = firedns_resolveip4(argv[1]); if (result) { printf("%s\n",firedns_ntoa4(result)); return 0; } return 1; } firedns/firemake/0000755000175000017500000000000010023637416013013 5ustar useruserfiredns/firemake/cc0000644000175000017500000000054010013014330013301 0ustar useruser#!/bin/sh #phase init dispn "Checking for a compiler..." if test "$CC" != ""; then disp "found in environment: \"$CC\"" elif (gcc --version >/dev/null 2>/dev/null; test "$?" = "0"); then disp "found gcc" CC="gcc" elif (CC=`which cc`; test "$?" = "0" -a -x "$CC"); then disp "found cc" CC="cc" else disp "not found, unable to continue" exit 1 fi firedns/firemake/cflags0000644000175000017500000000102007662225000014163 0ustar useruser#!/bin/sh #require cc #phase init #after init_cc dispn "Attempting to determine correct CFLAGS..." if test ! "$CFLAGS" = ""; then disp "CFLAGS provided by environment: \"$CFLAGS\"" FM_CFLAGS="$CFLAGS" elif test "`basename $CC`" = "gcc"; then disp "compiler is gcc, using \"-O20 -fstrict-aliasing -funroll-loops -fexpensive-optimizations -fomit-frame-pointer\"" FM_CFLAGS="-O20 -fstrict-aliasing -funroll-loops -fexpensive-optimizations -fomit-frame-pointer" else disp "compiler is unknown, using \"-O\"" FM_CFLAGS="-O" fi firedns/firemake/ipv60000644000175000017500000000150610023637416013624 0ustar useruser#!/bin/sh #require compiletest #require cflags #phase init #after init_cflags #phase header case $PHASE in init) dispn "Checking for IPv6 transport support..." PROGRAM="#include #include int main () { struct sockaddr_in6 addr6; addr6.sin6_family = AF_INET6; /* don't detect return code of socket(); program should do this at runtime */ socket(PF_INET6,SOCK_STREAM,0); return 0; }" FM_IPV6_SOCKET="y" compile_test_wrapper "$PROGRAM" "-DHAVE_IPV6" "" "" || \ { disp "not found, some functionality may be missing" FM_IPV6_SOCKET="n" } ;; header) if test "$FM_IPV6_SOCKET" = "y"; then disp "Adding \"#include \" to header" $ECHO "#include " disp "Adding \"#include \" to header" $ECHO "#include " fi ;; esac firedns/firemake/binaries0000644000175000017500000000533310013014330014515 0ustar useruser#!/bin/sh #require prefix #require strip #require makefiletop #phase config #phase makefile #after makefile_makefiletop case $PHASE in config) dispn "Reading firemake.binaries..." BINARIES=`cut -d ':' -f 1 firemake.binaries 2>/dev/null` disp "done" dispn "Reading firemake.sbinaries..." SBINARIES=`cut -d ':' -f 1 firemake.sbinaries 2>/dev/null` disp "done" dispn "Reading firemake.suidbinaries..." SUIDBINARIES=`cut -d ':' -f 1 firemake.suidbinaries 2>/dev/null` FULLBINARIES="$BINARIES $SBINARIES $SUIDBINARIES" dispn "Reading firemake.noinstall..." NOINSTALL=`cat firemake.noinstall 2>/dev/null` disp "done" ;; makefile) disp "Writing binary creation entries..." for BINARY in $FULLBINARIES; do dispn " $BINARY..." DEPS="`grep \"^$BINARY:\" firemake.binaries 2>/dev/null | cut -d ':' -f 2` `grep \"^$BINARY:\" firemake.sbinaries 2>/dev/null | cut -d ':' -f 2` `grep \"^$BINARY:\" firemake.suidbinaries 2>/dev/null | cut -d ':' -f 2`" $ECHO "$BINARY: $DEPS" $ECHO " $CC $FM_CFLAGS $FM_LDFLAGS -o $BINARY $DEPS $FM_STATICLIBS $FM_LIBS" $ECHO BINARYLIST="$BINARYLIST $BINARY" BINARY_CLEANLIST="$BINARY_CLEANLIST $BINARY $DEPS" disp "done" if module dependencies; then DEPPREPEND="$PREPEND" PREPEND="$PREPEND " customdeplist "$DEPS" PREPEND="$DEPPREPEND" fi done dispn "Writing binary index entry..." $ECHO "binaries: $BINARYLIST" $ECHO disp "done" disp "Writing binary install entries..." $ECHO "install_binaries: $BINARYLIST" for BINARY in $BINARIES; do $ECHO "$NOINSTALL" | grep "^$BINARY\$" >/dev/null 2>/dev/null if test "$?" = "0"; then disp " skipping $BINARY" else dispn " $BINARY..." $ECHO " $INSTALL $BINARY \$(BINDIR) $INSTALL_USER $INSTALL_GROUP 0755" if test "$STRIP" != ""; then $ECHO " $STRIP \$(BINDIR)/$BINARY" fi disp "done" fi done for BINARY in $SBINARIES; do $ECHO "$NOINSTALL" | grep "^$BINARY\$" >/dev/null 2>/dev/null if test "$?" = "0"; then disp " skipping $BINARY" else dispn " $BINARY..." $ECHO " $INSTALL $BINARY \$(SBINDIR) $INSTALL_USER $INSTALL_GROUP 0755" if test "$STRIP" != ""; then $ECHO " $STRIP \$(SBINDIR)/$BINARY" fi disp "done" fi done for BINARY in $SUIDBINARIES; do $ECHO "$NOINSTALL" | grep "^$BINARY\$" >/dev/null 2>/dev/null if test "$?" = "0"; then disp " skipping $BINARY" else dispn " $BINARY..." $ECHO " $INSTALL $BINARY \$(BINDIR) $INSTALL_USER $INSTALL_GROUP 4755" if test "$STRIP" != ""; then $ECHO " $STRIP \$(BINDIR)/$BINARY" fi disp "done" fi done $ECHO dispn "Writing binary cleanup entry..." $ECHO "clean_binaries:" $ECHO " rm -f $BINARY_CLEANLIST" $ECHO disp "done" ;; esac firedns/firemake/firestring0000644000175000017500000000251307777067417015137 0ustar useruser#!/bin/sh #require compiletest #require cflags #phase init #after init_cflags #phase header case $PHASE in init) dispn "Checking for firestring library..." PROGRAM="#include int main() { firestring_printf(\"test %e\",&ESTR_S(\"foo\")); return 0; }" compile_test_wrapper "$PROGRAM" "" "" "-lfirestring" || \ compile_test_wrapper "$PROGRAM" "-I/usr/local/include" "-L/usr/local/lib" "-lfirestring" || \ compile_test_wrapper "$PROGRAM" "-I/usr/local/include" "-L/usr/local/lib -R/usr/local/lib" "-lfirestring" || \ { if (module "subdir" && test -x firestring/configure); then subdir firestring disp "Adding -Ifirestring/ to CFLAGS" FM_CFLAGS="$FM_CFLAGS -Ifirestring/" disp "Adding firestring/libfirestring.a to STATICLIBS" FM_STATICLIBS="$FM_STATICLIBS firestring/libfirestring.a" elif (module "subdir" && test "$FM_IN_SUBDIR" = "y" && test -x ../firestring/configure); then parentdir ../firestring disp "Adding -I../firestring/ to CFLAGS" FM_CFLAGS="$FM_CFLAGS -I../firestring/" disp "Adding ../firestring/libfirestring.a to STATICLIBS" FM_STATICLIBS="$FM_STATICLIBS ../firestring/libfirestring.a" else disp "not found, unable to continue" exit 1 fi } ;; header) disp "Adding \"#include \" to header" $ECHO "#include " ;; esac firedns/firemake/version0000644000175000017500000000054207711512116014423 0ustar useruser#!/bin/sh #require cflags #phase config dispn "Reading firemake.version..." VERSION=`cat firemake.version 2>/dev/null` if test "$?" = "0"; then disp "done, \"$VERSION\"" else disp "not found, using \"0.0.0\"" VERSION="0.0.0" fi dispn "Adding -DVERSION=\"\\\"$VERSION\\\"\" to CFLAGS..." FM_CFLAGS="$FM_CFLAGS -DVERSION=\"\\\"$VERSION\\\"\"" disp done firedns/firemake/make0000644000175000017500000000041007763175057013665 0ustar useruser#!/bin/sh #phase init dispn "Checking to see if make supports \"?=\"..." rm -f Makefile echo "PREFIX ?= /usr/local" > Makefile echo "all:" >> Makefile make >/dev/null 2>&1 if test "$?" = "0"; then disp "yes" MAKE_CONDSET="y" else disp "no" MAKE_CONDSET="n" fi firedns/firemake/headers0000644000175000017500000000072107763175057014370 0ustar useruser#!/bin/sh #require prefix #require makefiletop #phase config #phase makefile #after makefile_makefiletop case $PHASE in config) dispn "Reading firemake.headers..." HEADERS=`cat firemake.headers 2>/dev/null` disp "done" ;; makefile) dispn "Writing header installation entry..." $ECHO "install_headers:" for HEADER in $HEADERS; do $ECHO " $INSTALL $HEADER \$(INCLUDEDIR) $INSTALL_USER $INSTALL_GROUP 0644" done $ECHO disp "done" ;; esac firedns/firemake/id0000644000175000017500000000035707662225000013334 0ustar useruser#!/bin/sh #phase init dispn "Checking for id..." if /usr/xpg4/bin/id 2>/dev/null; then disp "found, /usr/xpg4/bin/id" ID="/usr/xpg4/bin/id" elif id 2>/dev/null; then disp "found, id" ID="id" else disp "not found, aborting" exit 1 fi firedns/firemake/libraries0000644000175000017500000000625310013014330014677 0ustar useruser#!/bin/sh #require prefix #require compiletest #require cflags #require version #phase init #after init_cflags #phase config #phase makefile #after makefile_makefiletop case $PHASE in init) PROGRAM="int foo() { return 0; }" dispn "Checking if your compiler supports -fPIC..." if library_test "$PROGRAM" "-fPIC" ""; then disp "yes, adding \"-fPIC\" to CFLAGS" FM_CFLAGS="$FM_CFLAGS -fPIC" else disp "no, hoping we don't need it" fi dispn "Checking if your compiler supports -shared..." if shared_test "$PROGRAM" "-shared" ""; then disp "yes, adding \"-shared\" to SHAREDFLAGS" FM_SHAREDFLAGS="$FM_SHAREDFLAGS -shared" else disp "no, hoping we don't need it" fi dispn "Checking if your compiler supports -dynamiclib -lcc_dynamic..." # this is a bad hack for Darwin if shared_test "$PROGRAM" "-dynamiclib" "-lcc_dynamic"; then disp "yes:" disp " Adding \"-dynamiclib\" to SHAREDFLAGS" FM_SHAREDFLAGS="$FM_SHAREDFLAGS -dynamiclib" disp " Adding \"-dynamiclib\" to SHAREDLIBS" FM_SHAREDLIBS="$FM_SHAREDLIBS -lcc_dynamic" else disp "no, hoping we don't need it" fi rm -f compiletest.c.* dispn "Checking for SONAME support..." if shared_test "$PROGRAM" "-Wl,-soname,testname.so.0" ""; then disp "yes" FM_SONAME="-Wl,-soname," else disp "no" FM_SONAME="" fi ;; config) dispn "Reading firemake.libraries..." LIBRARIES=`cut -d ':' -f 1 firemake.libraries 2>/dev/null` disp "done" ;; makefile) VERSION2=`$ECHO "$VERSION" | cut -d . -f 1-2` disp "Writing library creation entries..." for LIBRARY in $LIBRARIES; do dispn " $LIBRARY..." DEPS=`grep "^$LIBRARY:" firemake.libraries | cut -d ':' -f 2` $ECHO "$LIBRARY: $LIBRARY.a $LIBRARY.so.$VERSION" $ECHO $ECHO "$LIBRARY.a: $DEPS" $ECHO " rm -f $LIBRARY.a" $ECHO " ar cru $LIBRARY.a $DEPS $FM_STATICLIBS" $ECHO " ranlib $LIBRARY.a || $ECHO \"Ignore ranlib errors.\"" $ECHO if test "$FM_SONAME" != ""; then SOTEMP="$FM_SONAME$LIBRARY.so.$VERSION2" else SOTEMP="" fi $ECHO "$LIBRARY.so.$VERSION: $DEPS" $ECHO " $CC $FM_CFLAGS $FM_LDFLAGS $FM_SHAREDFLAGS $SOTEMP -o $LIBRARY.so.$VERSION $DEPS $FM_STATICLIBS $FM_LIBS $FM_SHAREDLIBS" $ECHO LIBRARYLIST="$LIRBRARYLIST $LIBRARY" LIBRARY_CLEANLIST="$LIBRARY_CLEANLIST ${LIBRARY}.a ${LIBRARY}.so.$VERSION $DEPS" disp "done" if module dependencies; then DEPPREPEND="$PREPEND" PREPEND="$PREPEND " customdeplist "$DEPS" PREPEND="$DEPPREPEND" fi done dispn "Writing library index entry..." $ECHO "libraries: $LIBRARYLIST" $ECHO disp "done" disp "Writing library install entries..." $ECHO "install_libraries: $LIBRARYLIST" for LIBRARY in $LIBRARIES; do dispn " $LIBRARY..." $ECHO " $INSTALL ${LIBRARY}.a \$(LIBDIR) $INSTALL_USER $INSTALL_GROUP 0755" $ECHO " $INSTALL ${LIBRARY}.so.$VERSION \$(LIBDIR) $INSTALL_USER $INSTALL_GROUP 0755" $ECHO " ln -sf ${LIBRARY}.so.$VERSION \$(LIBDIR)/${LIBRARY}.so.$VERSION2" $ECHO " ln -sf ${LIBRARY}.so.$VERSION \$(LIBDIR)/${LIBRARY}.so" disp "done" done $ECHO dispn "Writing library cleanup entry..." $ECHO "clean_libraries:" $ECHO " rm -f $LIBRARY_CLEANLIST" $ECHO disp "done" ;; esac firedns/firemake/man0000644000175000017500000000360207763175057013531 0ustar useruser#!/bin/sh #require makefiletop #require prefix #phase config #phase makefile #after makefile_makefiletop case $PHASE in config) dispn "Checking for manpages for section 1..." MAN1=`ls man/*.1 2>/dev/null` disp "done" dispn "Checking for manpages for section 3..." MAN3=`ls man/*.3 2>/dev/null` disp "done" dispn "Checking for manpages for section 5..." MAN5=`ls man/*.5 2>/dev/null` disp "done" dispn "Checking for manpages for section 6..." MAN6=`ls man/*.6 2>/dev/null` disp "done" dispn "Checking for manpages for section 7..." MAN7=`ls man/*.7 2>/dev/null` disp "done" dispn "Checking for manpages for section 8..." MAN8=`ls man/*.8 2>/dev/null` disp "done" ;; makefile) disp "Writing manpage installation entries..." $ECHO "install_man:" if test "$MAN1" != ""; then dispn " Section 1..." for MAN in $MAN1; do $ECHO " $INSTALL $MAN \$(MANDIR)/man1 $INSTALL_USER $INSTALL_GROUP 0644" done disp "done" fi if test "$MAN3" != ""; then dispn " Section 3..." for MAN in $MAN3; do $ECHO " $INSTALL $MAN \$(MANDIR)/man3 $INSTALL_USER $INSTALL_GROUP 0644" done disp "done" fi if test "$MAN5" != ""; then dispn " Section 5..." for MAN in $MAN5; do $ECHO " $INSTALL $MAN \$(MANDIR)/man5 $INSTALL_USER $INSTALL_GROUP 0644" done disp "done" fi if test "$MAN6" != ""; then dispn " Section 6..." for MAN in $MAN6; do $ECHO " $INSTALL $MAN \$(MANDIR)/man6 $INSTALL_USER $INSTALL_GROUP 0644" done disp "done" fi if test "$MAN7" != ""; then dispn " Section 7..." for MAN in $MAN7; do $ECHO " $INSTALL $MAN \$(MANDIR)/man7 $INSTALL_USER $INSTALL_GROUP 0644" done disp "done" fi if test "$MAN8" != ""; then dispn " Section 8..." for MAN in $MAN8; do $ECHO " $INSTALL $MAN \$(MANDIR)/man8 $INSTALL_USER $INSTALL_GROUP 0644" done disp "done" fi $ECHO ;; esac firedns/firemake/prefix0000644000175000017500000000376307763175057014263 0ustar useruser#!/bin/sh #require cflags #phase init #after init_cflags dispn "Attempting to determine correct PREFIX..." if test ! "$PREFIX" = ""; then disp "PREFIX provided by environment: \"$PREFIX\"" FM_PREFIX="$PREFIX" else disp "prefix is unknown, using \"/usr/local\"" FM_PREFIX="/usr/local" fi dispn "Attempting to determine correct BINDIR..." if test ! "$BINDIR" = ""; then disp "BINDIR provided by environment: \"$BINDIR\"" FM_BINDIRSTRICT="y" FM_BINDIR="$BINDIR" else disp "bindir is unknown, deriving from PREFIX: \"$FM_PREFIX/bin\"" FM_BINDIR="$FM_PREFIX/bin" fi dispn "Attempting to determine correct SBINDIR..." if test ! "$SBINDIR" = ""; then disp "SBINDIR provided by environment: \"$SBINDIR\"" FM_SBINDIRSTRICT="y" FM_SBINDIR="$SBINDIR" else disp "sbindir is unknown, deriving from PREFIX: \"$FM_PREFIX/sbin\"" FM_SBINDIR="$FM_PREFIX/sbin" fi dispn "Attempting to determine correct MANDIR..." if test ! "$MANDIR" = ""; then disp "MANDIR provided by environment: \"$MANDIR\"" FM_MANDIRSTRICT="y" FM_MANDIR="$MANDIR" else disp "mandir is unknown, deriving from PREFIX: \"$FM_PREFIX/man\"" FM_MANDIR="$FM_PREFIX/man" fi dispn "Attempting to determine correct CONFDIR..." if test ! "$CONFDIR" = ""; then disp "CONFDIR provided by environment: \"$CONFDIR\"" FM_CONFDIRSTRICT="y" FM_CONFDIR="$CONFDIR" else disp "confdir is unknown, deriving from PREFIX: \"$FM_PREFIX/etc\"" FM_CONFDIR="$FM_PREFIX/etc" fi dispn "Attempting to determine correct LIBDIR..." if test ! "$LIBDIR" = ""; then disp "LIBDIR provided by environment: \"$LIBDIR\"" FM_LIBDIRSTRICT="y" FM_LIBDIR="$LIBDIR" else disp "libdir is unknown, deriving from PREFIX: \"$FM_PREFIX/lib\"" FM_LIBDIR="$FM_PREFIX/lib" fi dispn "Attempting to determine correct INCLUDEDIR..." if test ! "$INCLUDEDIR" = ""; then disp "INCLUDEDIR provided by environment: \"$INCLUDEDIR\"" FM_INCLUDEDIRSTRICT="y" FM_INCLUDEDIR="$INCLUDEDIR" else disp "includedir is unknown, deriving from PREFIX: \"$FM_PREFIX/include\"" FM_INCLUDEDIR="$FM_PREFIX/include" fi firedns/firemake/socket0000644000175000017500000000104607777067417014253 0ustar useruser#!/bin/sh #require compiletest #require cflags #phase init #after init_cflags #phase header case $PHASE in init) dispn "Checking to see if compiler needs -lsocket -lnsl..." PROGRAM="#include #include int main () { socket(0,0,0); return 0; }" compile_test_wrapper "$PROGRAM" "" "" "-lsocket -lnsl" || \ disp "no" ;; header) disp "Adding \"#include \" to header" $ECHO "#include " disp "Adding \"#include \" to header" $ECHO "#include " ;; esac firedns/firemake/makefiletop0000644000175000017500000000427507777067417015272 0ustar useruser#!/bin/sh #require prefix #require make #phase makefile dispn "Writing Makefile top entries..." if test "$MAKE_CONDSET" = "y"; then $ECHO "PREFIX ?= $FM_PREFIX" if test "$FM_MANDIRSTRICT" = "y"; then $ECHO "MANDIR ?= $FM_MANDIR" else $ECHO "MANDIR ?= \$(PREFIX)/man" fi if test "$FM_CONFDIRSTRICT" = "y"; then $ECHO "CONFDIR ?= $FM_CONFDIR" else $ECHO "CONFDIR ?= \$(PREFIX)/etc" fi if test "$FM_BINDIRSTRICT" = "y"; then $ECHO "BINDIR ?= $FM_BINDIR" else $ECHO "BINDIR ?= \$(PREFIX)/bin" fi if test "$FM_SBINDIRSTRICT" = "y"; then $ECHO "SBINDIR ?= $FM_SBINDIR" else $ECHO "SBINDIR ?= \$(PREFIX)/sbin" fi if test "$FM_LIBDIRSTRICT" = "y"; then $ECHO "LIBDIR ?= $FM_LIBDIR" else $ECHO "LIBDIR ?= \$(PREFIX)/lib" fi if test "$FM_INCLUDEDIRSTRICT" = "y"; then $ECHO "INCLUDEDIR ?= $FM_INCLUDEDIR" else $ECHO "INCLUDEDIR ?= \$(PREFIX)/include" fi else $ECHO "PREFIX = $FM_PREFIX" $ECHO "MANDIR = $FM_MANDIR" $ECHO "CONFDIR = $FM_CONFDIR" $ECHO "BINDIR = $FM_BINDIR" $ECHO "SBINDIR = $FM_SBINDIR" $ECHO "LIBDIR = $FM_LIBDIR" $ECHO "INCLUDEDIR = $FM_INCLUDEDIR" fi $ECHO $ECHO "all:" if module subdir; then # make even inside parents; brute force dependency handling for SUBDIR in $FM_SUBDIRS; do $ECHO " cd $SUBDIR && \$(MAKE) all && cd .." done fi if module binaries; then $ECHO " \$(MAKE) binaries" fi if module libraries; then $ECHO " \$(MAKE) libraries" fi $ECHO $ECHO $ECHO ".c.o:" $ECHO " $CC $FM_CFLAGS -DCONFDIR=\"\\\"\$(CONFDIR)\\\"\" -DBINDIR=\"\\\"\$(BINDIR)\\\"\" -DSBINDIR=\"\\\"\$(SBINDIR)\\\"\" -DLIBDIR=\"\\\"\$(LIBDIR)\\\"\" -DMANDIR=\"\\\"\$(MANDIR)\\\"\" -c -o \$@ \$<" $ECHO $ECHO "clean:" if module subdir; then for SUBDIR in $FM_CLEAN_SUBDIRS; do $ECHO " cd $SUBDIR && \$(MAKE) clean && cd .." done fi if module binaries; then $ECHO " \$(MAKE) clean_binaries" fi if module libraries; then $ECHO " \$(MAKE) clean_libraries" fi $ECHO $ECHO "distclean:" $ECHO " \$(MAKE) clean" if module subdir; then for SUBDIR in $FM_CLEAN_SUBDIRS; do $ECHO " cd $SUBDIR && \$(MAKE) distclean && cd .." done fi if module install; then $ECHO " \$(MAKE) clean_install" fi $ECHO " rm -f Makefile compiletest.log dependencies.log firemake.h" $ECHO disp "done" firedns/firemake/subdir0000644000175000017500000000115707777067417014256 0ustar useruser#!/bin/sh #require cc #require cflags #phase library disp "Loading subdirectory helper functions" subdir() { disp "local copy found, configuring:" cd $1 disp "[ENTERING CONFIGURE PROGRAM FOR $1]" FM_IN_SUBDIR="y" ./configure disp "[EXITING CONFIGURE PROGRAM FOR $1]" if (test "$?" != "0"); then disp "subdirectory configure failed, unable to continue" exit 1 fi cd .. FM_SUBDIRS="$FM_SUBDIRS $1" FM_CLEAN_SUBDIRS="$FM_CLEAN_SUBDIRS $1" } parentdir() { dispn "local copy found, adding to build..." FM_SUBDIRS="$FM_SUBDIRS $1" # don't clean parents, or we don't get all the way through clean disp "done" } firedns/firemake/strip0000644000175000017500000000025507662225000014076 0ustar useruser#!/bin/sh #phase init dispn "Checking for strip..." if strip -V 2>/dev/null; then disp "found strip" STRIP="strip" else disp "not found, continuing without" STRIP="" fi firedns/firemake/pthread0000644000175000017500000000112607777067417014411 0ustar useruser#!/bin/sh #require compiletest #require cflags #phase init #after init_cflags #phase header case $PHASE in init) dispn "Checking for pthread method..." PROGRAM="#include void *nothing(void *v) { return NULL; } int main () { pthread_t thread; pthread_create(&thread,NULL,nothing,NULL); return 0; }" compile_test_wrapper "$PROGRAM" "-pthread" "" "" || \ compile_test_wrapper "$PROGRAM" "" "" "-lpthread" || \ { disp "not found, unable to continue" exit 1 } ;; header) disp "Adding \"#include \" to header" $ECHO "#include " ;; esac firedns/firemake/compiletest0000644000175000017500000000504107777067417015312 0ustar useruser#!/bin/sh #require cc #require cflags #phase library disp "Loading compile testing helper function" rm -f compiletest.log library_test() { $ECHO "$1" > compiletest.c $ECHO " == START PROGRAM == $1 == END PROGRAM ==" >>compiletest.log $ECHO "== EXECUTING: $CC $FM_CFLAGS $2 -c -o compiletest.o compiletest.c $3 == " >>compiletest.log $CC $FM_CFLAGS $2 -c -o compiletest.o compiletest.c $3 >>compiletest.log 2>>compiletest.log if test "$?" = "0"; then rm -f compiletest.o compiletest.c $ECHO "== COMPILE OK ==" >>compiletest.log true return else rm -f compiletest.o compiletest.c $ECHO "== COMPILE FAIL ==" >>compiletest.log false return fi } shared_test() { $ECHO "$1" > compiletest.c $ECHO " == START PROGRAM == $1 == END PROGRAM ==" >>compiletest.log $ECHO "== EXECUTING: $CC $FM_CFLAGS $FM_LDFLAGS $FM_SHAREDFLAGS $2 -o compiletest.so compiletest.c $3 == " >>compiletest.log $CC $FM_CFLAGS $FM_LDFLAGS $FM_SHAREDFLAGS $2 -o compiletest.so compiletest.c $3 >>compiletest.log 2>>compiletest.log if test "$?" = "0"; then rm -f compiletest.so compiletest.c $ECHO "== COMPILE OK ==" >>compiletest.log true return else rm -f compiletest.so compiletest.c $ECHO "== COMPILE FAIL ==" >>compiletest.log false return fi } compile_test() { $ECHO "$1" > compiletest.c $ECHO " == START PROGRAM == $1 == END PROGRAM ==" >>compiletest.log $ECHO "== EXECUTING: $CC $FM_CFLAGS $FM_LDFLAGS $2 -o compiletest compiletest.c $3 == " >>compiletest.log $CC $FM_CFLAGS $FM_LDFLAGS $2 -o compiletest compiletest.c $3 >>compiletest.log 2>>compiletest.log if test "$?" = "0"; then $ECHO "== COMPILE OK ==" >>compiletest.log $ECHO "== EXECUTING: ./compiletest ==" >>compiletest.log ./compiletest >>compiletest.log 2>>compiletest.log if test "$?" = "0"; then rm -f compiletest compiletest.c $ECHO "== RUN OK ==" >>compiletest.log true return else rm -f compiletest compiletest.c $ECHO "== RUN FAIL ==" >>compiletest.log false return fi else rm -f compiletest compiletest.c $ECHO "== COMPILE FAIL ==" >>compiletest.log false return fi } compile_test_wrapper() { # Args: # $1 - Program # $2 - CFLAGS # $3 - LDFLAGS # $4 - LIBS if (compile_test "$1" "$2 $3" "$4" > /dev/null); then disp "found" if test "$2" != ""; then disp "Adding \"$2\" to CFLAGS" FM_CFLAGS="$FM_CFLAGS $2" fi if test "$3" != ""; then disp "Adding \"$3\" to LDFLAGS" FM_LDFLAGS="$FM_LDFLAGS $3" fi if test "$4" != ""; then disp "Adding \"$4\" to LIBS" FM_LIBS="$FM_LIBS $4" fi return 0 else return 1 fi } firedns/firemake/dependencies0000644000175000017500000000345107773107346015403 0ustar useruser#!/bin/sh #require cc #require cflags #phase library #phase init #after init_cflags case $PHASE in library) disp "Loading dependency helper function" rm -f dependencies.log customdeplist() { for DEP in $1; do JUNK=`$ECHO "$BUILTDEPS" | grep "$DEP"` if test "$?" != "0"; then # haven't built this one yet BUILTDEPS="$BUILTDEPS $DEP" CNAME=`echo "$DEP" | sed 's/\\.o\$/.c/'` customdeps "$CNAME" "$DEP" fi done } customdeps() { if test "$CC_DEPENDENCY" = "n"; then return fi dispn "Generating customized build rule for $1..." $ECHO "Generating dependencies with \"$CC $FM_CFLAGS -M $1\" (errors print below):" >> dependencies.log $CC $FM_CFLAGS -M $1 2>>dependencies.log if test "$?" != "0"; then disp "unable to generate dependencies; this file probably won't build. Aborting (check dependencies.log for details)" exit 1 fi $ECHO >> dependencies.log $ECHO " $CC $FM_CFLAGS -DCONFDIR=\"\\\"\$(CONFDIR)\\\"\" -DBINDIR=\"\\\"\$(BINDIR)\\\"\" -DSBINDIR=\"\\\"\$(SBINDIR)\\\"\" -DLIBDIR=\"\\\"\$(LIBDIR)\\\"\" -DMANDIR=\"\\\"\$(MANDIR)\\\"\" -c -o $2 $1" $ECHO disp "done" } ;; init) dispn "Checking for compiler dependency support..." $ECHO "#include int main() { return 0; }" > deptest.c $ECHO "Testing \"$CC $FM_CFLAGS -M deptest.c\":" >> dependencies.log DEPOUTPUT=`$CC $FM_CFLAGS -M deptest.c` RESULT="$?" $ECHO "Result is $RESULT" >> dependencies.log $ECHO "Output is: $DEPOUTPUT " >> dependencies.log if test "$RESULT" = "0"; then JUNK=`$ECHO "$DEPOUTPUT" | grep stdio` if test "$?" = "0"; then disp "found" CC_DEPENDENCY="y" else disp "found but broken, skipping" CC_DEPENDENCY="n" fi else disp "not found, skipping" CC_DEPENDENCY="n" fi rm -f deptest.c ;; esac firedns/firemake/install0000644000175000017500000000241707777067417014434 0ustar useruser#!/bin/sh #require id #require makefiletop #phase init #after init_id #phase makefile #after makefile_makefiletop case $PHASE in init) dispn "Creating installation script..." $ECHO "#!/bin/sh FILENAME="\$2/\`basename \$1\`" mkdir -p \$2 cp -f \$1 \$FILENAME chown \$3:\$4 \$FILENAME chmod \$5 \$FILENAME" > copy.sh chmod 0755 copy.sh INSTALL="./copy.sh" disp "done" dispn "Checking for installation username..." INSTALL_GROUP=`$ID -ng root` if test "$?" = "0"; then INSTALL_USER=root disp "found, \"root\"" else disp "none found, aborting" exit 1 fi dispn "Checking for installation group name..." if test "$INSTALL_GROUP" = ""; then disp "none found, aborting" exit 1 else disp "found, \"$INSTALL_GROUP\"" fi ;; makefile) dispn "Writing install entry..." $ECHO -n "install:" if module binaries; then $ECHO -n " install_binaries" fi if module libraries; then $ECHO -n " install_libraries" fi if module man; then $ECHO -n " install_man" fi if module headers; then $ECHO -n " install_headers" fi if module conf; then $ECHO -n " install_conf" fi $ECHO $ECHO disp "done" dispn "Writing install cleanup entry..." $ECHO "clean_install:" $ECHO " rm -f $INSTALL" $ECHO disp "done" ;; esac firedns/firemake/c990000644000175000017500000000157007662225000013342 0ustar useruser#!/bin/sh #require cc #require cflags #phase init #after init_cc #after init_cflags #phase header case $PHASE in init) C99="0" dispn "Checking for C99 compatible compiler..." if test "`basename $CC`" = "gcc"; then VER=`$CC --version | head -1 | cut -d ' ' -f 3` MVER=`$ECHO "$VER" | cut -d '.' -f 1` if test "$MVER" -ge "3"; then disp "gcc $VER (>= 3.0.0) found, C99 support activated" C99="1" else disp "gcc $VER (< 3.0.0) found, no C99 support" fi else disp "compiler not gcc, no C99 support" fi if test "$C99" = "1"; then disp "Adding \"-std=c99\" to CFLAGS" FM_CFLAGS="$FM_CFLAGS -std=c99" fi ;; header) if test "$C99" = "0"; then disp "Removing \"inline\" and \"restrict\" keyworks from source" $ECHO "#define inline" $ECHO "#define restrict" else disp "C99 is supported, no header changes needed" fi ;; esac firedns/fdnsmxalist.c0000644000175000017500000001003510016724360013724 0ustar useruser#include #include #include #include #include "firedns.h" #define max(a,b) (a > b ? a : b) int checkjunk(struct in_addr *ip) { unsigned char *cip = (unsigned char *)ip; if (cip[0] == 10) return 1; if (cip[0] == 172 && (cip[1] >= 16 && cip[1] <= 31)) return 1; if (cip[0] == 192 && cip[1] == 168) return 1; if (cip[0] == 192 && cip[1] == 0 && cip[2] == 2) return 1; if (cip[0] == 198 && (cip[1] == 18 || cip[1] == 19)) return 1; if (cip[0] == 127) return 1; if (cip[0] >= 224 && cip[0] <= 240) return 1; if (cip[0] == 0) return 1; return 0; } int checkjunk6(struct in6_addr *ip) { if (memcmp(ip,"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01",16) == 0) return 1; if (memcmp(ip,"\xfe\x80",2) == 0) return 1; /* FIXME: there's gotta be more of these */ return 0; } /* 0 - Everything looks good * 1 - An MX has a non-routable IP * 2 - An MX doesn't exist * 3 - An MX is a CNAME * 4 - An MX is an IP address * * 100 - Invalid syntax * 103 - DNS timeout */ int main(int argc, char **argv) { struct firedns_mxlist *iter, *list; int ret = 0; int xml = 0; if (argc == 3 && argv[1][0] == '-') { int i = 1; while (argv[1][i] != '\0') { switch (argv[1][i]) { case 'x': xml = 1; break; } i++; } argv[1] = argv[2]; argc--; } if (argc != 2) { fprintf(stderr,"usage: [-x] %s \n",argv[0]); return 100; } list = iter = firedns_resolvemxalist(argv[1]); if (iter == NULL) return 103; if (xml) printf("\n" "\n",(int)time(NULL),argv[1]); while (iter != NULL) { if (xml) printf(" \n",iter->name,firedns_mx_name[iter->protocol],iter->priority,firedns_mx_port[iter->protocol]); else printf("%7s (%05d) %s:%d\n",firedns_mx_name[iter->protocol],iter->priority,iter->name,firedns_mx_port[iter->protocol]); if (iter->cname != NULL) { if (xml) printf(" \n",iter->cname); else printf("ERROR: %s is a CNAME for %s\n",iter->name,iter->cname); ret = max(ret,3); } if (firedns_aton4(iter->name) != NULL) { if (xml) printf(" \n"); else printf("ERROR: %s is an IPv4 address\n",iter->name); ret = max(ret,4); goto wrap; } if (firedns_aton6(iter->name) != NULL) { if (xml) printf(" \n"); else printf("ERROR: %s is an IPv6 address\n",iter->name); ret = max(ret,4); goto wrap; } if (iter->ip4list == NULL && iter->ip6list == NULL) { if (xml) printf(" \n"); else printf("ERROR: %s does not exist\n",iter->name); ret = max(ret,2); } else { struct firedns_ip4list *ipiter = iter->ip4list; struct firedns_ip6list *ip6iter = iter->ip6list; while (ipiter) { if (xml) printf(" %s",firedns_ntoa4(&ipiter->ip)); else printf(" %s\n",firedns_ntoa4(&ipiter->ip)); if (checkjunk(&ipiter->ip)) { if (xml) printf("\n \n "); else printf("ERROR: %s has an IP of %s, which is non-routable\n",iter->name,firedns_ntoa4(&ipiter->ip)); ret = max(ret,1); } if (xml) printf("\n"); ipiter = ipiter->next; } while (ip6iter) { if (xml) printf(" %s",firedns_ntoa6(&ip6iter->ip)); else printf(" %s\n",firedns_ntoa6(&ip6iter->ip)); if (checkjunk6(&ip6iter->ip)) { if (xml) printf("\n \n "); else printf("ERROR: %s has an IP of %s, which is non-routable\n",iter->name,firedns_ntoa6(&ip6iter->ip)); ret = max(ret,1); } if (xml) printf("\n"); ip6iter = ip6iter->next; } } wrap: if (xml) printf(" \n"); iter = iter->next; } /* this is more to make sure freeing works than anything else */ firedns_free_mxalist(list); if (xml) printf("\n"); return ret; } firedns/fdnsip6.c0000644000175000017500000000046710012763575012760 0ustar useruser#include #include "firedns.h" int main(int argc, char **argv) { struct in6_addr *result; if (argc != 2) { fprintf(stderr,"usage: %s \n",argv[0]); return 2; } result = firedns_resolveip6(argv[1]); if (result) { printf("%s\n",firedns_ntoa6(result)); return 0; } return 1; } firedns/fdnsnamep.c0000644000175000017500000000235510023637416013354 0ustar useruser#include #include #include "firedns.h" int main(int argc, char **argv) { char *result; struct in_addr *binip; struct in6_addr *binip6; struct firedns_ip4list *ipiter; struct firedns_ip6list *ip6iter; char *local_result; if (argc != 2) { fprintf(stderr,"usage: %s \n",argv[0]); return 2; } binip6 = firedns_aton6(argv[1]); if (binip6 == NULL) { binip = firedns_aton4(argv[1]); if (binip == NULL) { fprintf(stderr,"invalid IP address.\n"); return 2; } /* IPv4 */ result = firedns_resolvename4(binip); if (result == NULL) return 1; local_result = firestring_strdup(result); ipiter = firedns_resolveip4list(result); while (ipiter != NULL) { if (memcmp(&ipiter->ip,binip,4) == 0) goto good; ipiter = ipiter->next; } free(local_result); return 3; } else { /* IPv6 */ result = firedns_resolvename6(binip6); if (result == NULL) return 1; local_result = firestring_strdup(result); ip6iter = firedns_resolveip6list(result); while (ip6iter != NULL) { if (memcmp(&ip6iter->ip,binip6,16) == 0) goto good; ip6iter = ip6iter->next; } free(local_result); return 3; } good: printf("%s\n",local_result); free(local_result); return 0; } firedns/fdnsspf1.c0000644000175000017500000000105210012772266013117 0ustar useruser#include #include #include "firedns.h" int main(int argc, char **argv) { struct firedns_txtlist *iter; char *spfrecord = NULL; if (argc != 2) { fprintf(stderr,"usage: %s \n",argv[0]); return 2; } iter = firedns_resolvetxtlist(argv[1]); if (iter == NULL) return 1; while (iter != NULL) { if (strncmp(iter->txt,"v=spf1 ",7) == 0) { if (spfrecord != NULL) return 1; spfrecord = iter->txt; } iter = iter->next; } if (spfrecord == NULL) return 1; printf("%s\n",spfrecord); return 0; } firedns/GPL0000644000175000017500000004313107711512116011576 0ustar useruser GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. firedns/fdnsip6list.c0000644000175000017500000000061010012763575013642 0ustar useruser#include #include #include "firedns.h" int main(int argc, char **argv) { struct firedns_ip6list *iter; if (argc != 2) { fprintf(stderr,"usage: %s \n",argv[0]); return 2; } iter = firedns_resolveip6list(argv[1]); if (iter == NULL) return 1; while (iter != NULL) { printf("%s\n",firedns_ntoa6(&iter->ip)); iter = iter->next; } return 0; }