🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
1 messages
1 total messages Started by T. William Wells Fri, 05 Jul 1996 00:00
nnrpd spool patch
#9045
Author: T. William Wells
Date: Fri, 05 Jul 1996 00:00
176 lines
5136 bytes
The following patch allows nnrpd to spool to in.coming. In the
mode I have it set up, NNRP_SPOOL_FIRST set, it tries to spool
before attempting to write to the server. With it unset, it tries
to post via the server first and spools if that fails. I don't
like that, as it results in a long user-visible pause while
posting if the server is busy, which it generally is if one has
streaming feeds.

*** post.c.old  Tue Mar  5 22:20:48 1996
--- post.c      Fri Jul  5 03:32:12 1996
***************
*** 8,13 ****
--- 8,15 ----
  #endif  /* defined(DO_NEED_TIME) */
  #include <sys/time.h>

+ #define NNRP_SPOOL_FIRST
+
  #define FLUSH_ERROR(F)          (fflush((F)) == EOF || ferror((F)))
  #define HEADER_DELTA            20

***************
*** 670,675 ****
--- 672,732 ----
      return atoi(buff);
  }

+ STATIC int
+ Spool(article)
+     char                *article;
+ {
+     int                 fd;
+     FILE                *fp;
+     int                 i;
+     register HEADER     *hp;
+     char                temp[BUFSIZ];
+     char                buff[BUFSIZ];
+
+     umask(0);
+     while (1) {
+         sprintf(temp, "%s/nnrpXXXXXX", _PATH_SPOOLTEMP);
+         mktemp(temp);
+         if ((fd = open(temp, O_WRONLY | O_CREAT | O_EXCL, BATCHFILE_MODE)) >= 0) {
+             break;
+         }
+         if (errno != EEXIST) {
+             syslog(LOG_DEBUG, "unable to create temp: %m");
+             return (0);
+         }
+     }
+     if (!(fp = fdopen(fd, "w"))) {
+         syslog(LOG_DEBUG, "unable to fdopen: %m");
+         unlink(temp);
+         return (0);
+     }
+     for (hp = Table; hp < ENDOF(Table); hp++)
+         if (hp->Value)
+             fprintf(fp, "%s: %s\n", hp->Name, hp->Value);
+     for (i = 0; i < OtherCount; i++)
+         fprintf(fp, "%s\n", OtherHeaders[i]);
+     fprintf(fp, "\n");
+     fprintf(fp, "%s", article);
+     if (FLUSH_ERROR(fp) || fclose(fp) == EOF) {
+         syslog(LOG_DEBUG, "error writing article: %m");
+         unlink(temp);
+         return (0);
+     }
+     while (1) {
+         sprintf(buff, "%s/nnrpXXXXXX", _PATH_SPOOLNEWS);
+         mktemp(buff);
+         if (link(temp, buff) >= 0) {
+             break;
+         }
+         if (errno != EEXIST) {
+             syslog(LOG_DEBUG, "error renaming article: %m");
+             unlink(temp);
+             return (0);
+         }
+     }
+     unlink(temp);
+     return (1);
+ }

  STRING
  ARTpost(article, idbuff)
***************
*** 739,744 ****
--- 796,807 ----
      }
  #endif  /* LOCAL_MAX_ARTSIZE > 0 */

+ #if defined(NNRP_SPOOL_FIRST)
+     if (Spool(article)) {
+         return NULL;
+     }
+ #endif
+
      /* Open a local connection to the server. */
      if (RemoteMaster)
	  i = NNTPconnect(RemoteMaster, &FromServer, &ToServer, buff);
***************
*** 750,755 ****
--- 813,821 ----
  #endif  /* defined(DO_HAVE_UNIX_DOMAIN) */
      }
      if (i < 0) {
+         if (Spool(article)) {
+             return NULL;
+         }
	  if (buff[0])
	      (void)strcpy(Error, buff);
	  else
***************
*** 769,774 ****
--- 835,843 ----
      if (i == NNTP_AUTH_NEEDED_VAL) {
	  /* Send authorization. */
	  if (NNTPsendpassword(RemoteMaster, FromServer, ToServer) < 0) {
+             if (Spool(article)) {
+                 return NULL;
+             }
	      (void)sprintf(Error, "Can't authorize with %s",
		  RemoteMaster ? RemoteMaster : "innd");
	      return Error;
***************
*** 778,783 ****
--- 847,855 ----
      if (i != NNTP_SENDIT_VAL) {
	  (void)strcpy(Error, buff);
	  SendQuit(FromServer, ToServer);
+         if (Spool(article)) {
+             return NULL;
+         }
	  return Error;
      }
      if (Tracing)
***************
*** 794,799 ****
--- 866,874 ----
	  (void)sprintf(Error, CANTSEND, "headers", strerror(errno));
	  (void)fclose(FromServer);
	  (void)fclose(ToServer);
+         if (Spool(article)) {
+             return NULL;
+         }
	  return Error;
      }

***************
*** 803,808 ****
--- 878,886 ----
	  (void)sprintf(Error, CANTSEND, "article", strerror(errno));
	  (void)fclose(FromServer);
	  (void)fclose(ToServer);
+         if (Spool(article)) {
+             return NULL;
+         }
	  return Error;
      }

***************
*** 810,815 ****
--- 888,896 ----
      if (atoi(buff) != NNTP_TOOKIT_VAL) {
	  (void)strcpy(Error, buff);
	  SendQuit(FromServer, ToServer);
+         if (Spool(article)) {
+             return NULL;
+         }
	  return Error;
      }



Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads