From: mitra@pandora.sf.ca.us (Mitra)
Subject: Patch to support remote users in Gopher 1.1
Organization: Pandora Systems
Date: Thu, 17 Dec 1992 01:38:40 GMT
X-Newsreader: TIN [version 1.1 PL6]


Most of Pandora's users are accessing us remotely via dialup links, 
several of Gopher's features work great for locally connected users, 
but not for remote users.  

This patch introduces a new option for 
the client "-r" which means the user is remote. If so then binary
files will be offered to the user via a downloader.

This patch also allows for intelligent pager's which support
things like Download and Mail and so doesnt duplicate this material 
inside gopher. I'd hope that any site with remote users is using 
such a pager rather than More.

Finally it fixes one last problem with SCO UNIX sites in that zcat
is not in /usr/ucb on those sites. 

This patch should be applicable without the previous (SCO_UNIX) one 
but if you havent applied that one you'll need to hand patch
-DREMOTEUSER (in the first hunk) into the INCLUDES a few lines 
down from it. 

Again, I hope these find their way into the next release.

-Mitra
mitra@pandora.sf.ca.us   
Technical Director: Pandora Systems
=========================================================

diff -c -r -b gopher1.1/Makefile.config gopher1.1+/Makefile.config
*** gopher1.1/Makefile.config	Wed Dec 16 16:54:26 1992
--- gopher1.1+/Makefile.config	Tue Dec 15 12:54:53 1992
***************
*** 182,188 ****
  
  
  # This is a horrible place to do this, but better than hacking Makefiles
! LOCALINCLUDES = -DM_SCOUNIX -UM_XENIX
  
  #-----------------------------------------------------------------
  # Stuff that follows shouldn't be changed
--- 182,188 ----
  
  
  # This is a horrible place to do this, but better than hacking Makefiles
! LOCALINCLUDES = -DREMOTEUSER -DM_SCOUNIX -UM_XENIX
  
  #-----------------------------------------------------------------
  # Stuff that follows shouldn't be changed
diff -c -r -b gopher1.1/conf.h gopher1.1+/conf.h
*** gopher1.1/conf.h	Fri Dec 11 11:02:04 1992
--- gopher1.1+/conf.h	Wed Dec 16 17:19:29 1992
***************
*** 63,68 ****
--- 63,75 ----
  #define PRINTER_COMMAND "lp"
  #endif
  
+ #if defined(REMOTEUSER)
+ #define PAGER_COMMAND "Page"
+ #endif
+ 
+ #if defined(M_SCOUNIX)
+ #define ZCATCMD "/usr/bin/zcat"
+ #endif
  
  /*
   * Now set the parameters, only if not set above... 
***************
*** 99,104 ****
--- 106,117 ----
  #define IMAGE_COMMAND "xloadimage -fork"
  #endif
  
+ /* This is a generic file download command on our system, write your 
+    own - or replace this with kermit or xmodem or something */
+ #ifndef DOWNLOAD_COMMAND
+ #define DOWNLOAD_COMMAND "fileupdn -su -b"
+ #endif
+ 
  /****************** gopherd configuration ***********************/
  
  /*
***************
*** 116,120 ****
--- 129,135 ----
  
  /*==============Ftp parameters to be edited in===============*/
  #define LIST            "/tmp/gftp+"            /* Temp list file prefix */
+ #ifndef ZCATCMD
  #define ZCATCMD         "/usr/ucb/zcat"
+ #endif
  
diff -c -r -b gopher1.1/gopher/globals.h gopher1.1+/gopher/globals.h
*** gopher1.1/gopher/globals.h	Thu Dec 10 15:32:32 1992
--- gopher1.1+/gopher/globals.h	Wed Dec 16 17:21:53 1992
***************
*** 24,30 ****
--- 24,34 ----
   *
   *********************************************************************/
  
+ #ifdef REMOTEUSER
+ #define MAXRESP      10                  /* Max size of a response list*/
+ #else
  #define MAXRESP      9                  /* Max size of a response list*/
+ #endif
  #define WHOLELINE 80                   /* Used in ourutil.c */
  
  /*
***************
*** 56,61 ****
--- 60,66 ----
  EXTERN String    *TN3270Command;
  EXTERN String    *MIMECommand;
  EXTERN String    *ImageCommand;
+ EXTERN String    *DownloadCommand;
  
  EXTERN boolean   ChangedDefs INIT(FALSE);
  
***************
*** 63,68 ****
--- 68,74 ----
  EXTERN int       iLevel INIT(0);
  EXTERN BOOLEAN   SecureMode INIT(FALSE);
  EXTERN BOOLEAN   DEBUG INIT(FALSE);
+ EXTERN BOOLEAN   RemoteUser INIT(FALSE);
  
  EXTERN GopherDirObj *CurrentDir INIT(NULL);
  EXTERN GopherDirObj *OldDirs[30];  /** Should be a stack... **/
diff -c -r -b gopher1.1/gopher/gopher.c gopher1.1+/gopher/gopher.c
*** gopher1.1/gopher/gopher.c	Fri Dec 11 11:53:45 1992
--- gopher1.1+/gopher/gopher.c	Wed Dec 16 17:23:01 1992
***************
*** 316,322 ****
--- 316,394 ----
  }
  
  
+ #ifdef REMOTEUSER
  /**
+ *** remote file takes a gopher file thing, writes it to a file
+ *** and passes it to the downloader
+ **/
+ 
+ void
+ remotefile(ZeGopher)
+   GopherStruct *ZeGopher;
+ {
+      int i=0, iLength, sockfd;
+      char *tmpfilename;
+      FILE *tmpfile;
+      char inputline[512];
+      char outputline[512];
+      char sTmp[5];
+      int twirlcounter=0;
+ 
+      sTmp[0] = '\0';
+ 
+      /** Open a temporary file **/
+ 
+      Gopenfile = tmpfilename = tempnam("/tmp","gopher");
+ 
+      if ((tmpfile = fopen(tmpfilename, "w")) == NULL)
+ 	  fprintf(stderr, "Couldn't make a tmp file!\n"), exit(-1);
+ 
+ 
+      /** Send out the request **/
+ 
+      if ((sockfd = GSconnect(ZeGopher)) <0) {
+ 	  check_sock(sockfd, GSgetHost(ZeGopher), GSgetPort(ZeGopher));
+ 	  return;
+      }
+ 
+      writestring(sockfd, GSgetPath(ZeGopher));
+      writestring(sockfd, "\r\n");
+ 
+      /*** Case here on the object type,  Get it line-by-line for text,
+           binary mode if it's supported. ***/
+ 
+      { /*** Read the file - this could be a routine itself ****/
+ 	  char buf[BUFSIZE]; int cc = 0;
+ 	  int counter = 0;
+ 
+ 	  while ( (cc = read( sockfd, buf, BUFSIZE )) > 0 ) {
+ 	       counter += cc;
+ 	       
+ 	       if (write(fileno(tmpfile), buf, cc ) <=0)
+ 		    CursesErrorMsg("Problems Writing File");
+ 	       twirl();
+ 	  }
+ 	  if ( cc < 0 )
+ 	       CursesErrorMsg( "Warning! File may be corrupt!");
+ 	  else {
+ 	       CursesErrorMsg( "File received successfully" );
+ 	  }
+ 	  close( sockfd );
+      }
+      downloadfile(tmpfilename,GSgetTitle(ZeGopher));
+ 
+      /** Good little clients clean up after themselves..**/
+ 
+      if (unlink(tmpfilename)!=0)
+ 	  fprintf(stderr, "Couldn't unlink!!!\n"), exit(-1);
+ 
+      CURenter(CursesScreen);
+      Gopenfile = NULL;
+ 
+      return;
+ }
+ #endif
+ /**
  *** Show file takes a gopher text thing, writes it to a file
  *** and passes it to your favorite pager.
  **/
***************
*** 729,734 ****
--- 801,809 ----
       EditorCommand   = STRnew();
       MIMECommand     = STRnew();
       ImageCommand    = STRnew();
+ #ifdef REMOTEUSER
+      DownloadCommand = STRnew();
+ #endif
  
       /** get defaults from the rc file **/
  
***************
*** 763,769 ****
--- 838,848 ----
  
  
  static char *GlobalOptions[] =  
+ #ifdef REMOTEUSER
+ {"Pager Command", "Print Command", "Telnet Command", "Sound Command", "Mail Command", "3270 Emulator Command", "MIME pager", "Image Viewer", "Download Command", NULL};
+ #else
  {"Pager Command", "Print Command", "Telnet Command", "Sound Command", "Mail Command", "3270 Emulator Command", "MIME pager", "Image Viewer", NULL};
+ #endif
  
  
  void
***************
*** 782,788 ****
       if (inited == FALSE) {
  	  int i; 
  
! 	  for (i=0; i< 8; i++) {
  	       Responses[i] = (char *) malloc(sizeof(char) * MAXSTR);
  	  }
  	  Responses[i] = NULL;
--- 861,867 ----
       if (inited == FALSE) {
  	  int i; 
  
! 	  for (i=0; i< MAXRESP-1; i++) {
  	       Responses[i] = (char *) malloc(sizeof(char) * MAXSTR);
  	  }
  	  Responses[i] = NULL;
***************
*** 798,803 ****
--- 877,885 ----
       strcpy(Responses[5], STRget(TN3270Command));
       strcpy(Responses[6], STRget(MIMECommand));
       strcpy(Responses[7], STRget(ImageCommand));
+ #ifdef REMOTEUSER
+      strcpy(Responses[8], STRget(DownloadCommand));
+ #endif
       
       if (CURRequest(CursesScreen, "Options", GlobalOptions, Responses) == 0) {
  
***************
*** 809,814 ****
--- 891,899 ----
  	  STRset(TN3270Command, Responses[5]);
  	  STRset(MIMECommand, Responses[6]);
  	  STRset(ImageCommand, Responses[7]);
+ #ifdef REMOTEUSER
+ 	  STRset(DownloadCommand, Responses[8]);
+ #endif
  	  
  	  ChangedDefs = TRUE;
       }
***************
*** 854,860 ****
--- 939,949 ----
  
       sTmp[0] = '\0';
  
+ #ifdef REMOTEUSER
+      while ((c = getopt(argc, argv, "Dsbrp:t:")) != -1)
+ #else
       while ((c = getopt(argc, argv, "Dsbp:t:")) != -1)
+ #endif
  	  switch (c) {
  	  case 's':
  	       SecureMode = TRUE;
***************
*** 870,875 ****
--- 959,969 ----
  	  case 'D':
  	       DEBUG = TRUE;
  	       break;
+ #ifdef REMOTEUSER
+ 	  case 'r':
+ 	       RemoteUser = TRUE;
+ 	       break;
+ #endif
  	  case 'b':
  	       Bkmarksfirst = TRUE;
  	       break;
***************
*** 1336,1341 ****
--- 1430,1445 ----
  
       case A_GIF:
       case A_IMAGE:
+ #ifdef REMOTEUSER
+ 	  Draw_Status("Receiving Information...");
+ 	  refresh();
+ 	  if (RemoteUser)
+ 		remotefile(ZeGopher);
+ 	  else
+ 		showfile(ZeGopher);
+ 	  break;
+ 
+ #endif
       case A_MIME:
       case A_FILE:
  	  Draw_Status("Receiving Information...");
***************
*** 1346,1351 ****
--- 1450,1463 ----
       case A_MACHEX:
       case A_PCBIN:
       case A_UNIXBIN:
+ #ifdef REMOTEUSER
+ 	if (RemoteUser) {
+ 		Draw_Status("Receiving Information...");
+ 		refresh();
+ 		remotefile(ZeGopher);
+ 	}
+ 	else
+ #endif
  	  if (!SecureMode)
  	       getfile(ZeGopher);
  	  else
diff -c -r -b gopher1.1/gopher/gopherrc.c gopher1.1+/gopher/gopherrc.c
*** gopher1.1/gopher/gopherrc.c	Fri Dec 11 11:53:20 1992
--- gopher1.1+/gopher/gopherrc.c	Tue Dec 15 12:46:50 1992
***************
*** 122,127 ****
--- 122,132 ----
  	  else if (strncasecmp(inputline, "Imagecmd: ", 10) == 0) {
  	       STRset(ImageCommand, inputline+10);
  	  }
+ #ifdef REMOTEUSER
+ 	  else if (strncasecmp(inputline, "Downloadcmd: ", 13) == 0) {
+ 	       STRset(DownloadCommand, inputline+13);
+ 	  }
+ #endif
  
       }
  
***************
*** 139,144 ****
--- 144,152 ----
       STRset(TN3270Command, TN3270_COMMAND);
       STRset(MIMECommand, MIME_COMMAND);
       STRset(ImageCommand, IMAGE_COMMAND);
+ #ifdef REMOTEUSER
+      STRset(DownloadCommand, DOWNLOAD_COMMAND);
+ #endif
  }     
  
  
***************
*** 175,180 ****
--- 183,193 ----
       
       if (getenv("GOPHER_IMAGE") != NULL)
  	  STRset(ImageCommand, getenv("GOPHER_IMAGE"));
+ 
+ #ifdef REMOTEUSER
+      if (getenv("GOPHER_DOWNLOAD") != NULL)
+ 	  STRset(DownloadCommand, getenv("GOPHER_DOWNLOAD"));
+ #endif
  }
  
  
***************
*** 234,239 ****
--- 247,256 ----
       writestring(rcfile, STRget(MIMECommand));
       writestring(rcfile, "\nImagecmd: ");
       writestring(rcfile, STRget(ImageCommand));
+ #ifdef  REMOTEUSER
+      writestring(rcfile, "\nDownloadcmd: ");
+      writestring(rcfile, STRget(DownloadCommand));
+ #endif
       
       if (BookmarkDir != NULL) {
  	  writestring(rcfile, "\nbookmarks:\n");
diff -c -r -b gopher1.1/gopher/ourutils.c gopher1.1+/gopher/ourutils.c
*** gopher1.1/gopher/ourutils.c	Fri Dec 11 13:20:13 1992
--- gopher1.1+/gopher/ourutils.c	Tue Dec 15 12:46:51 1992
***************
*** 52,57 ****
--- 52,76 ----
  	return(c);
  }
  
+ #ifdef REMOTEUSER
+ downloadfile(Filename, Realname)
+ /* Copied from display_image*/
+   char *Filename, *Realname;
+ {
+      char downloadcmd[512];
+      FILE *Image;
+      
+      strcpy(downloadcmd, STRget(DownloadCommand));
+      strcat(downloadcmd, " ");
+      strcat(downloadcmd, Filename);
+      if (DEBUG)
+ 	fprintf(stderr,"Downloading: %s",Filename, Realname);
+      CURexit(CursesScreen);
+      system(downloadcmd);
+      CURenter(CursesScreen);
+ 
+ }     
+ #endif
  display_image(Filename, Realname)
    char *Filename, *Realname;
  {
***************
*** 368,374 ****
  	  system(command);
       else
  	  Ourpager(Filename);
! 
       printf("Press <RETURN> to continue");
  
       if (!SecureMode)
--- 387,396 ----
  	  system(command);
       else
  	  Ourpager(Filename);
! #ifndef REMOTEUSER
! /* Decent pagers give a prompt at the end of the file 
!    and also give the user mailing, saving and printing options 
!    dont repeat here */
       printf("Press <RETURN> to continue");
  
       if (!SecureMode)
***************
*** 441,446 ****
--- 463,469 ----
  	  }
       }
       
+ #endif
       
       tputs(CURgetCLS(CursesScreen),1,outchar);
       fflush(stdout);
Newsgroups: comp.infosystems.gopher