1: #include    "parms.h"
   2: #include    "structs.h"
   3: #include    "dump.h"
   4: 
   5: #ifdef  RCSIDENT
   6: static char rcsid[] = "$Header: loadnf.c,v 1.7 85/01/18 15:41:25 notes Rel $";
   7: #endif	RCSIDENT
   8: 
   9: /*
  10:  *	loadnf(basedir, nfname, infile)
  11:  *
  12:  *	creates and loads a notesfile.  Notesfile is read in from
  13:  *	FILE *infile.  Given name "nfname" in directory "basedir".
  14:  *
  15:  */
  16: 
  17: loadnf (basedir, nfname, infile)
  18: char   *basedir;
  19: char   *nfname;
  20: FILE * infile;
  21: {
  22:     struct io_f io;
  23:     char    pathname[BUFSIZ];
  24:     struct note_f   note;
  25: 
  26:     if (buildnf (nfname, basedir, 0, 0, 0) < 0)     /* damn */
  27:     {
  28:     printf ("Unable to create notesfile %s in %s\n", nfname, basedir);
  29:     return (-1);                    /* failed right away */
  30:     }
  31:     sprintf (pathname, "%s/%s", basedir, nfname);
  32:     if (init (&io, pathname) < 0)           /* pisser */
  33:     {
  34:     printf ("Unable to open newly created notesfile %s\n", pathname);
  35:     return (-1);
  36:     }
  37: 
  38: /*
  39:  *	Well, now that we have an open notesfile, let's start
  40:  *	layering in the appropriate information from the file.
  41:  *
  42:  *	First thing in is the notesfile descriptor.
  43:  */
  44: 
  45:     locknf (&io, DSCRLOCK);             /* Ensure privacy */
  46:     getdscr (&io, &io.descr);
  47:     loaddescr (&io.descr, infile);          /* loads it */
  48:     putdscr (&io, &io.descr);               /* save it */
  49:     if (io.descr.d_plcy)                /* policy there? */
  50:     {
  51:     loadem (&io, infile, NOLOCKIT, "Noplace", DETAIL, 1);/* load */
  52:     getdscr (&io, &io.descr);           /* update descr */
  53:     getnrec (&io, io.descr.d_nnote, &note);     /* grab */
  54:     putnrec (&io, 0, &note);            /* move */
  55:     io.descr.d_nnote--;
  56:     putdscr (&io, &io.descr);           /* fix count */
  57:     }
  58: 
  59: /*
  60:  *	Now we should load the access lists. This isn't
  61:  *	perfect since this loading mechanism won't remove
  62:  *	the "Other" entries that are placed there by default.
  63:  */
  64: 
  65:     loadaccess (&io, infile);               /* load it */
  66: 
  67: /*
  68:  *	Now, load the notesfile text itself.
  69:  *	This is the easiest part.
  70:  */
  71: 
  72:     loadem (&io, infile, NOLOCKIT, "Noplace", DETAIL, -1);/* load articles */
  73: 
  74: /*
  75:  *	use closenf() instead of finish() to circumvent screwing
  76:  *	with statistics.
  77:  */
  78:     unlocknf (&io, DSCRLOCK);               /* all done */
  79:     closenf (&io);
  80:     return (0);
  81: 
  82: }
  83: 
  84: /*
  85:  *	loaddescr(&descr_f, infile)
  86:  *
  87:  *	Read an ASCII representation of the notesfile descriptor
  88:  *	and load it.
  89:  */
  90: 
  91: loaddescr (descr, infile)
  92: struct descr_f *descr;
  93: FILE * infile;
  94: {
  95:     register int    varno;              /* variable parsed */
  96:     register char  *field;              /* field data */
  97:     register int    i;
  98:     long    longval;                    /* sscanf temp */
  99:     char    line[BUFSIZ];               /* line buffer */
 100: 
 101:     while (fgets (line, sizeof line, infile) != NULL)   /* read */
 102:     {
 103:     if ((varno = rfcparse (line, descrnames)) == -1)/* nothing */
 104:         continue;                   /* ignore */
 105:     if (varno == NF_DESCRIPTOR)         /* end sentinel */
 106:         return (0);                 /* all cool */
 107:     field = index (line, ':');          /* find data */
 108:     field++;                    /* skip colon */
 109:     field++;                    /* and space */
 110:     switch (varno)                  /* parse line */
 111:     {
 112:         case NF_TITLE:
 113:         for (i = 0; i < NNLEN && *field != '\n'; i++, field++)
 114:             descr -> d_title[i] = *field;
 115:         if (i < NNLEN)
 116:             descr -> d_title[i] = '\0';     /* fill */
 117:         else
 118:             descr -> d_title[NNLEN - 1] = '\0';
 119:         break;
 120:         case NF_DIRECTOR_MESSAGE:
 121:         for (i = 0; i < DMLEN && *field != '\n'; i++, field++)
 122:             descr -> d_drmes[i] = *field;
 123:         if (i < DMLEN)
 124:             descr -> d_drmes[i] = '\0';     /* fill */
 125:         else
 126:             descr -> d_drmes[DMLEN - 1] = '\0'; /* fill */
 127:         break;
 128:         case NF_LAST_MODIFIED:
 129:         parsetime (field, &descr -> d_lastm);   /* get it */
 130:         break;
 131:         case NF_STATUS:
 132:         {
 133:             char    statname[32];       /* status token */
 134:             char   *p;              /* into token list */
 135: 
 136:             p = field;
 137:             p--;                /* get leading space */
 138:             while (*p && *p != '\n')        /* end string */
 139:             {
 140:             if (sscanf (p, "%s", statname) != 1)
 141:                 break;          /* no more tokens */
 142:             if (!strcmp (statname, "Anonymous"))
 143:                 descr -> d_stat |= ANONOK;
 144:             if (!strcmp (statname, "Open"))
 145:                 descr -> d_stat |= OPEN;
 146:             if (!strcmp (statname, "Networked"))
 147:                 descr -> d_stat |= NETWRKD;
 148:             if (!strcmp (statname, "Archive"))
 149:                 descr -> d_stat |= ISARCH;
 150:             p += strlen (statname) + 1; /* leading space */
 151:             }
 152:         }
 153:         break;
 154:         case NF_ID_SEQUENCE:
 155:         if (index (field, '@') != (char *) NULL)/* new format */
 156:         {
 157:             char    field1[100];        /* big temp */
 158:             sscanf (field, "%ld@%99s", &descr -> d_id.uniqid, field1);
 159:             field1[SYSSZ - 1] = '\0';
 160:             strcpy (descr -> d_id.sys, field1);
 161:         }
 162:         else
 163:         {
 164:             char   *pp;
 165:             pp = rindex (field, '.');       /* find last */
 166:             *pp++ = '\0';
 167:             strcpy (descr -> d_id.sys, field);
 168:             sscanf (pp, "%ld", &descr -> d_id.uniqid);
 169:         }
 170:         break;
 171:         case NF_NUMBER:
 172:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 173:             descr -> d_nfnum = longval;     /* assign */
 174:         break;
 175:         case NF_LAST_TRANSMIT:
 176:         parsetime (field, &descr -> d_lstxmit);
 177:         break;
 178:         case NF_CREATED:
 179:         parsetime (field, &descr -> d_created);
 180:         break;
 181:         case NF_LAST_USED:
 182:         parsetime (field, &descr -> d_lastuse);
 183:         break;
 184:         case NF_DAYS_USED:
 185:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 186:             descr -> d_daysused = longval;  /* assign */
 187:         break;
 188:         case NF_NOTES_WRITTEN:
 189:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 190:             descr -> d_notwrit = longval;   /* assign */
 191:         break;
 192:         case NF_NOTES_READ:
 193:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 194:             descr -> d_notread = longval;   /* assign */
 195:         break;
 196:         case NF_NOTES_TRANSMITTED:
 197:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 198:             descr -> d_notxmit = longval;   /* assign */
 199:         break;
 200:         case NF_NOTES_RECEIVED:
 201:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 202:             descr -> d_notrcvd = longval;   /* assign */
 203:         break;
 204:         case NF_NOTES_DROPPED:
 205:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 206:             descr -> d_notdrop = longval;   /* assign */
 207:         break;
 208:         case NF_RESPONSES_WRITTEN:
 209:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 210:             descr -> d_rspwrit = longval;   /* assign */
 211:         break;
 212:         case NF_RESPONSES_READ:
 213:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 214:             descr -> d_rspread = longval;   /* assign */
 215:         break;
 216:         case NF_RESPONSES_TRANSMITTED:
 217:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 218:             descr -> d_rspxmit = longval;   /* assign */
 219:         break;
 220:         case NF_RESPONSES_RECEIVED:
 221:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 222:             descr -> d_rsprcvd = longval;   /* assign */
 223:         break;
 224:         case NF_RESPONSES_DROPPED:
 225:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 226:             descr -> d_rspdrop = longval;   /* assign */
 227:         break;
 228:         case NF_ENTRIES:
 229:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 230:             descr -> entries = longval;     /* assign */
 231:         break;
 232:         case NF_WALLTIME:
 233:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 234:             descr -> walltime = longval;    /* assign */
 235:         break;
 236:         case NF_ORPHANS_RECEIVED:
 237:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 238:             descr -> d_orphans = longval;   /* assign */
 239:         break;
 240:         case NF_ORPHANS_ADOPTED:
 241:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 242:             descr -> d_adopted = longval;   /* assign */
 243:         break;
 244:         case NF_TRANSMITS:
 245:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 246:             descr -> netwrkouts = longval;  /* assign */
 247:         break;
 248:         case NF_RECEIVES:
 249:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 250:             descr -> netwrkins = longval;   /* assign */
 251:         break;
 252:         case NF_EXPIRATION_AGE:
 253:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 254:             descr -> d_archtime = longval;  /* assign */
 255:         break;
 256:         case NF_EXPIRATION_ACTION:
 257:         {
 258:             char    action[32];
 259:             sscanf (field, "%s", action);   /* get it */
 260:             if (!strcmp (action, "Archive"))
 261:             descr -> d_archkeep = KEEPYES;
 262:             if (!strcmp (action, "Delete"))
 263:             descr -> d_archkeep = KEEPNO;
 264:             if (!strcmp (action, "Default"))
 265:             descr -> d_archkeep = KEEPDFLT;
 266:             break;
 267:         }
 268:         case NF_EXPIRATION_STATUS:
 269:         {
 270:             char    action[32];
 271:             sscanf (field, "%s", action);   /* get it */
 272:             if (!strcmp (action, "On"))
 273:             descr -> d_dmesgstat = DIRON;
 274:             if (!strcmp (action, "Off"))
 275:             descr -> d_dmesgstat = DIROFF;
 276:             if (!strcmp (action, "Either"))
 277:             descr -> d_dmesgstat = DIRNOCARE;
 278:             if (!strcmp (action, "Default"))
 279:             descr -> d_dmesgstat = DIRDFLT;
 280:             break;
 281:         }
 282:         case NF_WORKING_SET_SIZE:
 283:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 284:             descr -> d_workset = longval;   /* assign */
 285:         break;
 286:         case NF_LONGEST_TEXT:
 287:         if (sscanf (field, "%ld", &longval) == 1)/* ok */
 288:             descr -> d_longnote = longval;  /* assign */
 289:         break;
 290:         case NF_POLICY_EXISTS:
 291:         if (!strncmp ("Yes", field, 3))     /* it's there */
 292:             descr -> d_plcy = TRUE;     /* it's there */
 293:         else
 294:             descr -> d_plcy = FALSE;        /* not there */
 295:         break;
 296:     }
 297:     }
 298:     return (-1);                    /* never reached */
 299: }
 300: 
 301: /*
 302:  *	loadaccess(&io, infile)
 303:  *
 304:  *	load the access list of the specified notesfile from
 305:  *	the supplied file.  Stops on the keyword "Access-End".
 306:  */
 307: 
 308: loadaccess (io, infile)
 309: struct io_f *io;
 310: FILE * infile;
 311: {
 312:     char    pline[BUFSIZ];
 313:     struct perm_f   perms[NPERMS];          /* access rights */
 314:     int     nmodes,
 315:             i;
 316:     register char  *field;
 317: 
 318:     nmodes = 0;                     /* load perms[] */
 319:     while (fgets (pline, sizeof pline, infile) != NULL)
 320:     {
 321:     if ((i = rfcparse (pline, &accessnames)) != ACCESS_RIGHT && i != (-1))
 322:         break;                  /* signals the end */
 323:     if (nmodes == NPERMS)               /* full list */
 324:         continue;
 325:     i = strlen (pline);
 326:     if (pline[i] == '\n')
 327:         pline[i] = '\0';                /* zap newline */
 328:     field = index (pline, ':');         /* find data */
 329:     field++;                    /* skip colon */
 330:     field++;                    /* and space */
 331:     if (parsemode (field, &perms[nmodes], 0) == 0)  /* worked? */
 332:         nmodes++;                   /* bump counter */
 333:     }
 334: /*
 335:  *	we break to here when we've sucked in the line
 336:  *	"NF-Access-Termination" or some such. Anyway, it's
 337:  *	after we've abused the sentinel line.
 338:  */
 339:     addmodes (io, nmodes, &perms, 0);           /* add them */
 340: }

Defined functions

loadaccess defined in line 308; used 1 times
  • in line 65
loaddescr defined in line 91; used 1 times
  • in line 47
loadnf defined in line 17; used 1 times

Defined variables

rcsid defined in line 6; never used
Last modified: 1985-01-19
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1125
Valid CSS Valid XHTML 1.0 Strict