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

Defined functions

CH_Enumerate defined in line 93; used 1 times
GetObjects defined in line 51; used 1 times
listObject defined in line 44; used 1 times

Defined macros

MAXPACKS defined in line 35; used 2 times
Last modified: 1986-03-13
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1117
Valid CSS Valid XHTML 1.0 Strict