NNTPC: Quick and dirty patch for grephistory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I found I needed a 'grephistory' command like INN has. It looked somewhat
difficult to untangle the history bits from the rest of the system, so I
added a new option (-g) to nntpcached instead. Use it like this:

	nntpcached -g messageid

NB: Messageid *without* <>. Also, it requires you to be positioned in
the directory where the history database is. Like I said, quick and
dirty :-)

The patch also corrects a very minor typo in article.c.

The patch has been generated again 1.0.2, but I believe it should work
for 1.0.3 also.

Steinar Haug, Nethelp consulting, sthaug@nethelp.no
----------------------------------------------------------------------
*** nntpcache.c.0	Fri Feb 21 22:35:41 1997
--- nntpcache.c	Thu Feb 27 11:59:42 1997
***************
*** 50,55 ****
--- 50,57 ----
  X (bool InDaemon);
  X (bool MakeHistory)
  	= FALSE;
+ X (bool grephistory)
+ 	= FALSE;
  X (void *Mbase);
  static char PidFile[MAX_PATH] = "";
  X(struct command commands[])
***************
*** 558,564 ****
  
  static void usage (char *argv0)
  {
! 	fprintf (stderr, "usage: %s [ehinrs] [-b addr:port] [-c config_file]\n", argv0);
  	exit (1);
  }
  
--- 560,566 ----
  
  static void usage (char *argv0)
  {
! 	fprintf (stderr, "usage: %s [ehinrs] [-g messageid] [-b addr:port] [-c config_file]\n", argv0);
  	exit (1);
  }
  
***************
*** 595,600 ****
--- 597,603 ----
  	char *config_file = con.configFile;
  	char *access_file = con.accessFile;
  	char *bindAddr = 0;
+ 	char *artfile;
  	struct hostent *hp;
  	bool f_swap_child = FALSE;
  	struct authent *gauth = NULL; /* stop gcc complaining */
***************
*** 613,619 ****
  \n\
  	-nntpcache development team\n");
  
! 	while ((c = getopt (argc, argv, "ehinb:rc:s")) != -1)
  		switch (c)
  		{
  		case 'a':
--- 616,622 ----
  \n\
  	-nntpcache development team\n");
  
! 	while ((c = getopt (argc, argv, "ehing:b:rc:s")) != -1)
  		switch (c)
  		{
  		case 'a':
***************
*** 631,636 ****
--- 634,645 ----
  		case 'c':
  			config_file = optarg;
  			break;
+ 		case 'g':
+ 			grephistory = TRUE;
+ 			artfile = hisGetDbz(optarg);
+ 			if (artfile)
+ 				printf("%s\n", artfile);
+ 			exit(0);
  		case 'i':
  			Daemon = FALSE;
  			break;
*** history.c.orig	Fri Feb 21 16:49:57 1997
--- history.c	Thu Feb 27 11:36:03 1997
***************
*** 24,46 ****
  	bool rebuild = FALSE;
  	if (his_fd != -1)
  		return TRUE;
! 	his_fd = open (con.historyFile, O_RDWR);
  	if (his_fd == -1)
  	{
  		loge (("missing history file '%s'", con.historyFile));
! 		rebuild = TRUE;
  	}
  	sprintf (dbdir, "%.127s.dir", con.historyFile);
  	if (stat (dbdir, &st) == -1)
  	{
  		loge (("missing history file '%s'", dbdir));
! 		rebuild = TRUE;
  	}
  	sprintf (dbpag, "%.127s.pag", con.historyFile);
  	if (stat (dbpag, &st) == -1)
  	{
  		loge (("missing history file '%s'", dbpag));
! 		rebuild = TRUE;
  	}
  	if (rebuild)
  	{
--- 24,52 ----
  	bool rebuild = FALSE;
  	if (his_fd != -1)
  		return TRUE;
! 	if (grephistory)
! 		his_fd = open (con.historyFile, O_RDONLY);
! 	else
! 		his_fd = open (con.historyFile, O_RDWR);
  	if (his_fd == -1)
  	{
  		loge (("missing history file '%s'", con.historyFile));
! 		if (!grephistory)
! 			rebuild = TRUE;
  	}
  	sprintf (dbdir, "%.127s.dir", con.historyFile);
  	if (stat (dbdir, &st) == -1)
  	{
  		loge (("missing history file '%s'", dbdir));
! 		if (!grephistory)
! 			rebuild = TRUE;
  	}
  	sprintf (dbpag, "%.127s.pag", con.historyFile);
  	if (stat (dbpag, &st) == -1)
  	{
  		loge (("missing history file '%s'", dbpag));
! 		if (!grephistory)
! 			rebuild = TRUE;
  	}
  	if (rebuild)
  	{
*** extern.h.orig	Thu Feb 27 10:23:17 1997
--- extern.h	Thu Feb 27 11:43:40 1997
***************
*** 116,121 ****
--- 116,122 ----
  extern bool Daemon ;
  extern bool InDaemon ;
  extern bool MakeHistory ;
+ extern bool grephistory ;
  extern void *Mbase ;
  extern struct command commands[] ;
  extern void Exit () ;
*** article.c.orig	Fri Feb 21 16:01:26 1997
--- article.c	Fri Feb 21 22:20:09 1997
***************
*** 192,198 ****
  		fd = open (artfile, O_WRONLY | O_EXCL | O_CREAT, 0664);
  		if (fd<0)
  		{
! 			loge (("coudln't create article %s", artfile));
  			strListFree (links);
  			return FALSE;
  		}
--- 192,198 ----
  		fd = open (artfile, O_WRONLY | O_EXCL | O_CREAT, 0664);
  		if (fd<0)
  		{
! 			loge (("couldn't create article %s", artfile));
  			strListFree (links);
  			return FALSE;
  		}


[Index of Archives]     [Yosemite]     [Yosemite Campsites]     [Bugtraq]     [Linux]     [Trn]

Powered by Linux