home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / contrib / snntpd / msgid.main.c < prev    next >
C/C++ Source or Header  |  1992-10-30  |  2KB  |  73 lines

  1. /*
  2.  * msgid -- message ID test program
  3.  * vix 13feb91 [negative caching]
  4.  * vix 24may90 [written]
  5.  * with mods ken@sdd.hp.com 01jul90
  6.  *
  7.  * $Header: msgid.c,v 1.6 91/08/17 12:04:11 vixie Locked $
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <ctype.h>
  12. #include <string.h>
  13. #include <sys/types.h>
  14. #include <sys/time.h>
  15.  
  16. #ifdef hpux
  17. #include <sys/param.h>
  18. #include <libBSD.h>
  19. #endif
  20. #include <syslog.h>
  21.  
  22. #include "msgid.h"
  23.  
  24. #define SERVERTIMEOUT 30
  25.  
  26. char hostname[BUFSIZ];
  27.  
  28. main(argc, argv)
  29. int    argc;
  30. char    *argv[];
  31. {
  32.     register int n;
  33.     char buf[BUFSIZ], cmd[20], id[BUFSIZ];
  34.  
  35.     if (gethostname(hostname, BUFSIZ)) {
  36.         perror("hostname");
  37.         exit(1);
  38.     }
  39.     (void) printf("host: %s\n", hostname);
  40.  
  41.     if (argc != 1) {
  42.         (void) fprintf(stderr, "usage: %s\n", argv[0]);
  43.         exit(1);
  44.     }
  45.  
  46. #ifdef LOG_DAEMON
  47.     openlog("msgid-test", LOG_PID, LOG_DAEMON);
  48. #else
  49.     openlog("msgid-test", LOG_PID);
  50. #endif
  51.  
  52.     while (fputs("cmd msgid: ", stdout), fflush(stdout),
  53.          fgets(buf, BUFSIZ, stdin))
  54.         if ((n = sscanf(buf, "%[^ \t]%*[ \t]%[^\n]", cmd, id)) == 2) {
  55.             if (strcmp(cmd, "cancel") == 0)
  56.                 (void) printf("%s\n",
  57.                     (msgid(id, MCANCEL)? "failed": "ok"));
  58.             else if (strcmp(cmd, "add") == 0)
  59.                 (void) printf("%d\n", msgid(id, MADD));
  60. #ifdef notdef
  61.                 (void) printf("%sduplicate\n", 
  62.                           (msgid(id, MADD)? "": "not a "));
  63. #endif
  64.             else if (strcmp(cmd, "old") == 0)
  65.                 (void) printf("%s\n",
  66.                     (msgid(id, MOLD)? "failed": "ok"));
  67.             else
  68.                 (void) printf("possible cmds are cancel, add, and old\n");
  69.         } else
  70.             (void) printf("[%d] possible cmds are cancel, add, and old\n",
  71.                  n);
  72. }
  73.