|
|
1.1 ! root 1: #include <stdio.h> ! 2: /* $Header: CHenumalias.c,v 2.0 85/11/21 07:22:29 jqj Exp $ */ ! 3: ! 4: /* contains: ! 5: * CH_EnumerateAliases ! 6: */ ! 7: ! 8: /* $Log: CHenumalias.c,v $ ! 9: * Revision 2.0 85/11/21 07:22:29 jqj ! 10: * 4.3BSD standard release ! 11: * ! 12: * Revision 1.1 85/03/26 06:26:58 jqj ! 13: * Initial revision ! 14: * ! 15: * Revision 1.1 85/03/26 06:26:58 jqj ! 16: * Initial revision ! 17: * ! 18: */ ! 19: #include <sys/types.h> ! 20: #include <netns/ns.h> ! 21: #include "Clearinghouse2_defs.h" ! 22: #include <xnscourier/CHEntries.h> ! 23: #include <xnscourier/except.h> ! 24: ! 25: /* ! 26: * This module contains the routine: ! 27: * int CH_EnumerateAliases(pattern,eachName) ! 28: * ObjectNamePattern pattern; ! 29: * NameProcedure eachName; ! 30: * where NameProcedure is a procedure of the form: ! 31: * int eachName(name) ! 32: * Object name; ! 33: */ ! 34: #define MAXPACKS 5 ! 35: ! 36: static (*ProcEachName)(); /* use: (*ProcEachName)(arg); */ ! 37: static Cardinal nullhash = 0; ! 38: static Authenticator nullagent = {{0,{0,(Unspecified*) 0}}, ! 39: {1,&nullhash}}; ! 40: static ObjectName currentname; ! 41: extern struct ns_addr *LookupCHAddr(); ! 42: ! 43: static ! 44: listObject(name) ! 45: ObjectName name; ! 46: { ! 47: printf("%s:%s:%s\n", name.object, name.domain, name.organization); ! 48: } ! 49: ! 50: static ! 51: GetObjectNames(conn) ! 52: CourierConnection *conn; ! 53: { ! 54: int count, i; ! 55: Unspecified buffer[MAXWORDS*MAXPACKS], *bp, *bufend; ! 56: StreamOfObjectName obnames; ! 57: ! 58: bufend = buffer; ! 59: bp = buffer+((MAXWORDS-1)*MAXPACKS); /* end of available space */ ! 60: while (count = BDTread(conn, (char*)bufend, ! 61: MAXWORDS*sizeof(Unspecified)) ! 62: ) { ! 63: bufend += count/sizeof(Unspecified); ! 64: if (bufend > bp) { ! 65: fprintf(stderr,"BDT read too big to fit\n"); ! 66: BDTabort(conn); ! 67: /* should clear out stuff here if we knew how much */ ! 68: } ! 69: } ! 70: bp = buffer; ! 71: while (bp < bufend) { ! 72: bp += internalize_StreamOfObject(&obnames,bp); ! 73: if (0 == (int) obnames.designator) { ! 74: for (i=0; i < obnames.nextSegment_case.segment.length; i++) { ! 75: (*ProcEachName)( ! 76: obnames.nextSegment_case.segment.sequence[i]); ! 77: } ! 78: free(obnames.nextSegment_case.segment.sequence); ! 79: } else { ! 80: for (i = 0; i < obnames.lastSegment_case.length; i++) { ! 81: (*ProcEachName)( ! 82: obnames.lastSegment_case.sequence[i]); ! 83: } ! 84: free(obnames.lastSegment_case.sequence); ! 85: return; ! 86: } ! 87: } ! 88: } ! 89: ! 90: CH_EnumerateAliases(pattern,eachName) ! 91: ObjectNamePattern pattern; ! 92: int (*eachName)(); ! 93: { ! 94: CourierConnection *conn; ! 95: extern CourierConnection *CH_GetFirstCH(); ! 96: ! 97: if (eachName != NULL) ! 98: ProcEachName = eachName; ! 99: else ! 100: ProcEachName = listObject; ! 101: if (pattern.object == NULL || ! 102: pattern.domain == NULL || ! 103: pattern.organization == NULL) ! 104: return(1); ! 105: ! 106: if ((conn = CH_GetFirstCH()) == NULL) { ! 107: fprintf(stderr,"Can't open connection to local Clearinghouse\n"); ! 108: return(1); ! 109: } ! 110: DURING { ! 111: ListAliases(conn, GetObjectNames, pattern, ! 112: BulkData1_immediateSink, nullagent); ! 113: } HANDLER { ! 114: return(Exception.Code); /* some random error */ ! 115: /* should handle WrongServer here */ ! 116: } END_HANDLER; ! 117: CourierClose(conn); ! 118: return(0); ! 119: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.