|
|
1.1 ! root 1: #include <stdio.h> ! 2: /* $Header: CHenumerate.c,v 2.2 87/04/01 12:42:12 jqj Exp $ */ ! 3: ! 4: /* contains: ! 5: * CH_Enumerate ! 6: */ ! 7: ! 8: /* $Log: CHenumerate.c,v $ ! 9: * Revision 2.2 87/04/01 12:42:12 jqj ! 10: * reworked wrongserver code to correspond to new GetOtherCH semantics ! 11: * ! 12: * Revision 2.1 87/03/17 09:59:08 ed ! 13: * webster changes: handle WrongServer error ! 14: * ! 15: * Revision 2.1 87/03/17 09:59:08 ed ! 16: * Handle WrongServer error from first Clearinghouse ! 17: * ! 18: * Revision 2.0 85/11/21 07:22:30 jqj ! 19: * *** empty log message *** ! 20: * ! 21: * Revision 2.0 85/11/21 07:22:30 jqj ! 22: * 4.3BSD standard release ! 23: * ! 24: * Revision 1.1 85/03/26 06:26:59 jqj ! 25: * Initial revision ! 26: * ! 27: * Revision 1.1 85/03/26 06:26:59 jqj ! 28: * Initial revision ! 29: * ! 30: */ ! 31: #include <sys/types.h> ! 32: #include <netns/ns.h> ! 33: #include "Clearinghouse2_defs.h" ! 34: #include <xnscourier/CHEntries.h> ! 35: #include <xnscourier/except.h> ! 36: ! 37: /* ! 38: * This module contains the routine: ! 39: * int CH_Enumerate(pattern,property,eachName) ! 40: * ObjectNamePattern pattern; ! 41: * Property property; ! 42: * NameProcedure eachName; ! 43: * where NameProcedure is a procedure of the form: ! 44: * int eachName(name) ! 45: * Object name; ! 46: */ ! 47: #define MAXPACKS 5 ! 48: ! 49: static (*ProcEachName)(); /* use: (*ProcEachName)(arg); */ ! 50: static Cardinal nullhash = 0; ! 51: static Authenticator nullagent = {{0,{0,(Unspecified*) 0}}, ! 52: {1,&nullhash}}; ! 53: static ObjectName currentname; ! 54: extern struct ns_addr *LookupCHAddr(); ! 55: ! 56: static ! 57: listObject(name) ! 58: ObjectName name; ! 59: { ! 60: printf("%s:%s:%s\n", name.object, name.domain, name.organization); ! 61: } ! 62: ! 63: static ! 64: GetObjects(conn) ! 65: CourierConnection *conn; ! 66: { ! 67: int count, i; ! 68: Unspecified buffer[MAXWORDS*MAXPACKS], *bp, *bufend; ! 69: StreamOfObject obnames; ! 70: ! 71: bufend = buffer; ! 72: bp = buffer+((MAXWORDS-1)*MAXPACKS); /* end of available space */ ! 73: while (count = BDTread(conn, (char*)bufend, ! 74: MAXWORDS*sizeof(Unspecified)) ! 75: ) { ! 76: bufend += count/sizeof(Unspecified); ! 77: if (bufend > bp) { ! 78: fprintf(stderr,"BDT read too big to fit\n"); ! 79: BDTabort(conn); ! 80: /* should clear out stuff here if we knew how much */ ! 81: } ! 82: } ! 83: bp = buffer; ! 84: while (bp < bufend) { ! 85: bp += internalize_StreamOfObject(&obnames,bp); ! 86: if (0 == (int) obnames.designator) { ! 87: for (i=0; i < obnames.nextSegment_case.segment.length; i++) { ! 88: currentname.object = ! 89: obnames.nextSegment_case.segment.sequence[i]; ! 90: (*ProcEachName)(currentname); ! 91: } ! 92: free(obnames.nextSegment_case.segment.sequence); ! 93: } else { ! 94: for (i = 0; i < obnames.lastSegment_case.length; i++) { ! 95: currentname.object = ! 96: obnames.lastSegment_case.sequence[i]; ! 97: (*ProcEachName)(currentname); ! 98: } ! 99: free(obnames.lastSegment_case.sequence); ! 100: return; ! 101: } ! 102: } ! 103: } ! 104: ! 105: CH_Enumerate(pattern,property,eachName) ! 106: ObjectNamePattern pattern; ! 107: Property property; ! 108: int (*eachName)(); ! 109: { ! 110: CourierConnection *conn, *ch2conn; ! 111: Clearinghouse2_ObjectName hint; /* from WrongServer errors */ ! 112: extern CourierConnection *CH_GetFirstCH(), *CH_GetOtherCH(); ! 113: int tries, retval; ! 114: ! 115: if (eachName != NULL) ! 116: ProcEachName = eachName; ! 117: else ! 118: ProcEachName = listObject; ! 119: if (pattern.object == NULL || ! 120: pattern.domain == NULL || ! 121: pattern.organization == NULL) ! 122: return(1); ! 123: currentname.domain = pattern.domain; ! 124: currentname.organization = pattern.organization; ! 125: ! 126: if ((conn = CH_GetFirstCH()) == NULL) { ! 127: fprintf(stderr,"Can't open connection to local Clearinghouse\n"); ! 128: return(1); ! 129: } ! 130: retval = -1; ! 131: for (tries = 5; tries > 0 && retval == -1; tries--) { ! 132: DURING { ! 133: ListObjects(conn, GetObjects, pattern, property, ! 134: BulkData1_immediateSink, nullagent); ! 135: retval = 0; ! 136: } HANDLER { ! 137: if (Exception.Code == REJECT_ERROR) { ! 138: if ((ch2conn = CH_GetOtherCH(conn, NULL)) == NULL) ! 139: retval = Exception.Code; ! 140: else { ! 141: CourierClose(conn); ! 142: conn = ch2conn; ! 143: } ! 144: } else if (Exception.Code == Clearinghouse2_WrongServer) { ! 145: hint = CourierErrArgs(Clearinghouse2_WrongServerArgs, hint); ! 146: if ((ch2conn = CH_GetOtherCH(conn, hint)) == NULL) ! 147: retval = 1; ! 148: else { ! 149: CourierClose(conn); ! 150: conn = ch2conn; ! 151: } ! 152: } else { ! 153: retval = Exception.Code; ! 154: } ! 155: } END_HANDLER; ! 156: } ! 157: CourierClose(conn); ! 158: return(retval); ! 159: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.