1: #include "parms.h" 2: #include "structs.h" 3: #include "net.h" 4: #ifdef FASTSEQ 5: #include <sys/types.h> 6: #include <sys/stat.h> 7: #endif FASTSEQ 8: 9: #ifdef RCSIDENT 10: static char rcsid[] = "$Header: nfsend.c,v 1.7.0.1 85/08/04 12:16:32 notes Rel $"; 11: #endif RCSIDENT 12: 13: /* 14: * nfsend will send the notes/responses to a new site that 15: * that site has not seen (at least as far as we are concerned) 16: * This means that we send them the ones that we received later 17: * then the last time we sent them, and also that were not 18: * written there nor were routed through there. 19: * 20: * Also, a logfile is maintained of the network transmissions made. 21: * 22: * Returns: -1 if the notefile is not a networked notefile 23: * else count of articles sent 24: * 25: * Original Coding: Ray Essick December 1981 26: */ 27: 28: static struct io_f io; 29: static struct note_f note; 30: static struct resp_f rsprec; 31: static int ncount, 32: rcount, /* how many of each sent */ 33: num, 34: rrecnum, 35: roffset, 36: respnum; 37: static FILE * log, 38: *zfile; /* logfile stuff */ 39: static struct when_f entered; 40: static char line[DATELEN]; /* formatted date */ 41: static char fn[WDLEN]; /* network log */ 42: static char scrfile[WDLEN]; /* scratch file */ 43: static char sendtime[DATELEN]; /* current time */ 44: static struct when_f xsendtime; /* raw current time */ 45: static int traffic; /* if new traffic */ 46: static int opened; /* for FASTSEQ */ 47: 48: nfsend (tosite, nfname, dmpfile, usetime, sendhim, proto) 49: char *tosite, /* destination site */ 50: *nfname, /* notefile sending */ 51: *dmpfile; /* temp file */ 52: { 53: 54: traffic = 0; /* idle */ 55: opened = 0; /* FASTSEQ idle */ 56: strcpy (scrfile, ""); /* mark as unused */ 57: rcount = ncount = 0; /* count sent */ 58: gettime (&xsendtime); 59: sprdate (&xsendtime, sendtime); /* format xmit time */ 60: sprintf (Seqname, "Sy:%s", tosite); /* sequencer name */ 61: 62: 63: #ifdef FASTSEQ 64: { 65: struct when_f whenvec; 66: char NoteFile[WDLEN]; 67: struct stat StatBuf; 68: 69: if (nfname[0] == '/') /* absolute pathname */ 70: { 71: getlast (&io.stime, rindex (nfname, '/') + 1, usetime, Seqname); 72: sprintf (NoteFile, "%s/%s", nfname, TEXT); 73: } 74: else /* relative to Mstdir */ 75: { 76: getlast (&io.stime, nfname, usetime, Seqname); 77: sprintf (NoteFile, "%s/%s/%s", Mstdir, nfname, TEXT); 78: } 79: if (stat (NoteFile, &StatBuf) >= 0) 80: { 81: maketime (&whenvec, (long) StatBuf.st_mtime); 82: if (inorder (&whenvec, &io.stime)) 83: { 84: return (0); /* nothing new */ 85: } 86: } 87: } 88: #endif FASTSEQ 89: 90: if (init (&io, nfname) < 0) 91: { 92: printf ("Couldn't open %s, try again later\n", nfname); 93: fflush (stdout); 94: return (-1); 95: } 96: 97: opened++; /* nfsenddone will close */ 98: 99: getperms (&io, 1, tosite); /* grab system name */ 100: if (!allow (&io, READOK)) /* read permission? */ 101: { 102: printf ("Site %s has no read permission for %s\n", 103: tosite, nfname); 104: fflush (stdout); 105: return (-1); /* and go back */ 106: } 107: 108: if ((io.descr.d_stat & NETWRKD) == 0) 109: { 110: printf ("Notefile %s is not networked\n", nfname); 111: fflush (stdout); 112: return (-1); 113: } 114: 115: 116: gettime (&entered); /* for seq. update */ 117: getlast (&io.stime, io.nf, usetime, Seqname); /* grab the time */ 118: 119: if (!inorder (&io.stime, &io.descr.d_lastm)) /* something new */ 120: { /* idle notesfile */ 121: #ifdef FASTSEQ 122: /* 123: * update the sequencer so the next pass through will be 124: * caught by the FASTSEQ test which just stats the file. 125: */ 126: fixlast (&entered, io.nf, NORMSEQ, Seqname); /* update sequencer */ 127: #endif FASTSEQ 128: return (0); 129: } 130: /* 131: * reach here only if we have potential traffic 132: * and permission to send it. 133: */ 134: traffic++; /* forces seq update */ 135: 136: x ((zfile = fopen (dmpfile, "w")) == NULL, "nfsend: scratch"); 137: strcpy (scrfile, dmpfile); /* save scratch name */ 138: num = 0; /* start at the beginning */ 139: while ((num = nxtnote (&io, num, &io.stime)) != -1) 140: { 141: getnrec (&io, num, ¬e); /* grab the header */ 142: if (!strcmp (note.n_from, tosite) && !(sendhim & SENDHIS)) 143: goto doresps; /* they sent it to us */ 144: if (!strcmp (note.n_id.sys, tosite) && !(sendhim & SENDHIS)) 145: goto doresps; /* written there */ 146: if (inorder (&io.stime, ¬e.n_rcvd) == 0) 147: goto doresps; /* only modified */ 148: if ((note.n_stat & FRMNEWS) && !(sendhim & SENDNEWS))/* DO NOT send news */ 149: goto doresps; /* causes uniqid probs */ 150: #ifdef notdef 151: /* 152: * we want to send foster parents so they will have a title on 153: * the remote end. 154: */ 155: if (note.n_stat & ORPHND) /* no foster parents */ 156: goto doresps; /* should have copy */ 157: #endif notdef 158: dmpnote (&io, ¬e, num, zfile, NODETAIL, proto);/* dump to output */ 159: ncount++; /* bump count of sent articles */ 160: io.nnotxmit++; /* and global stats */ 161: 162: doresps: /* process the responses */ 163: respnum = 0; 164: while ((respnum = nxtresp (&io, num, respnum, &io.stime)) != -1) 165: { 166: if (lrsp (&io, num, respnum, &rsprec, &roffset, &rrecnum) == -1) 167: break; /* no response */ 168: if (!strcmp (rsprec.r_id[roffset].sys, tosite) && !(sendhim & SENDHIS)) 169: continue; /* written there */ 170: if (!strcmp (rsprec.r_from[roffset], tosite) && !(sendhim & SENDHIS)) 171: continue; /* came through there */ 172: if ((rsprec.r_stat[roffset] & FRMNEWS) && !(sendhim & SENDNEWS)) 173: continue; /* never forward NEWS(I) stuff */ 174: dmprsp (&io, ¬e, num, zfile, respnum, NODETAIL, proto); 175: rcount++; 176: io.nrspxmit++; /* and global stats */ 177: } 178: } 179: fclose (zfile); /* and the dumping file */ 180: return (ncount + rcount); 181: } 182: 183: /* 184: * nfsendone fixes up the sequencer entry for the system/notesfile 185: * pair. The sequencer is only updated if the transmission 186: * was successful (as determined by the retval parameter. 187: * 188: * Thanks to Malcolm Slaney for this one. 189: */ 190: 191: nfsendone (nfname, tosite, queuestat, sendstat) 192: char *tosite; /* Name of site */ 193: char *nfname; /* Name of notesfile */ 194: int queuestat; /* Unix return value */ 195: { 196: 197: /* 198: * Traffic is non-zero if something happened in that notesfile 199: * If nothing at all happened, we save the bother of updating 200: * since it doesn't save us any scanning time later. 201: * (and not updating does save us a little time now) 202: * 203: * We check queuestat because we don't want to update the 204: * sequencer file if we know that the transmission failed. 205: */ 206: if (traffic && (!queuestat)) /* only if non-idle */ 207: { 208: fixlast (&entered, io.nf, NORMSEQ, Seqname); /* update sequencer */ 209: } 210: 211: /* 212: * Update statistics only on successful non-empty transmissions. 213: * We don't do any statistics for empty transmissions 214: */ 215: #ifdef STATS 216: if ((!queuestat) && (sendstat > 0)) /* if it worked */ 217: { /* and sent */ 218: locknf (&io, DSCRLOCK); 219: getdscr (&io, &io.descr); 220: gettime (&io.descr.d_lstxmit); /* mark as sent now */ 221: if (ncount + rcount > 0) /* only if sent stuff */ 222: io.descr.netwrkouts++; /* increment xmits */ 223: putdscr (&io, &io.descr); 224: unlocknf (&io, DSCRLOCK); 225: } 226: #endif STATS 227: 228: if (opened) /* did init(&io,nf) */ 229: finish (&io); /* so close it */ 230: /* 231: * Now log everything that happened 232: */ 233: 234: sprdate (&io.stime, line); 235: sprintf (fn, "%s/%s/%s", Mstdir, UTILITY, NETLOG); /* logging */ 236: if (sendstat >= 0) /* no bizarre errors */ 237: { 238: if (ncount + rcount) /* log only if sending */ 239: { 240: x ((log = fopen (fn, "a")) == NULL, "nfsend: bad net log file"); 241: fprintf (log, "%s: %s send (%3d,%3d) to %-10s at %s\n", 242: nfname, queuestat ? "Fail" : "Did", ncount, rcount, 243: tosite, sendtime); 244: x (fclose (log) == EOF, "nfsend: trouble fclosing log file"); 245: printf ("%-14s: %4s send (%3d,%3d) to %s since %s\n", 246: nfname, queuestat ? "Fail" : "Did", ncount, rcount, 247: tosite, line); 248: } 249: else 250: { 251: printf ("%-14s: No new notes since %s\n", nfname, line); 252: } 253: fflush (stdout); /* force it out */ 254: 255: } 256: 257: if (strcmp (scrfile, "") != 0) /* contains a name */ 258: { 259: unlink (scrfile); /* don't leave droppings */ 260: } 261: 262: }