home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / XARCHIE2.TAR / procquery.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-02  |  7.2 KB  |  270 lines

  1. /*
  2.  * procquery.c : Routines for processing results from Archie
  3.  *
  4.  * Originally part of the Prospero Archie client by Cliff Neuman (bcn@isi.edu).
  5.  * Modified by Brendan Kehoe (brendan@cs.widener.edu).
  6.  * Re-modified by George Ferguson (ferguson@cs.rochester.edu).
  7.  *
  8.  * Copyright (c) 1991 by the University of Washington
  9.  *
  10.  * For copying and distribution information, please see the file
  11.  * <copyright.h>.
  12.  *
  13.  * v1.2.1 - 10/18/91 (bpk) - warning stuff
  14.  * v1.2.0 - 09/20/91 (bpk) - VMS under Multinet 3.0 too
  15.  * v1.1.1 - 08/20/91 (bpk) - took out archie_query from error msg
  16.  */
  17. #include <copyright.h>
  18. #include <stdio.h>
  19. #include <pfs.h>
  20. #include <perrno.h>
  21. #include <pmachine.h>
  22. #include <archie.h>
  23.  
  24. #ifdef NEED_TIME_H
  25. # include <time.h>
  26. #else
  27. # ifndef VMS
  28. #  include <sys/time.h>
  29. # endif
  30. #endif
  31.  
  32. extern int client_dirsrv_timeout,client_dirsrv_retry;    /* dirsend.c */
  33. extern char *progname;
  34.  
  35. #ifdef XARCHIE
  36. #include <X11/Intrinsic.h>
  37. #include "xarchie.h"
  38. #include "types.h"
  39. #include "appres.h"
  40. #include "db.h"
  41. extern Database *db;                    /* database for all queries */
  42. static HostEntry *currentHostEntry;     /* current host, this query */
  43. static LocEntry *currentLocEntry;       /* current location, this query */
  44. static int numMatches;            /* num hits this query */
  45. #endif
  46.  
  47. /*
  48.  * Functions defined here
  49.  */
  50. void display_link(), procquery();
  51.  
  52. /*
  53.  * Data defined here
  54.  */
  55. extern int pwarn, perrno;
  56. int pfs_debug;
  57. static struct tm *presenttime;
  58. static char lastpath[MAX_VPATH] = "\001";
  59. static char lasthost[MAX_VPATH] = "\001";
  60.  
  61. /*    -    -    -    -    -    -    -    -    */
  62. /*
  63.  * display_link : Prints the contents of the given virtual link. If
  64.  *    listflag is 0, then this uses last{host,path} to save state
  65.  *    between calls for a less verbose output. If listflag is non-zero
  66.  *    then all information is printed every time.
  67.  */
  68. void
  69. display_link(l,listflag)
  70. VLINK l;
  71. int listflag;
  72. {
  73.     PATTRIB     ap;
  74.     char    linkpath[MAX_VPATH];
  75.     int        dirflag = 0;
  76.     int        size = 0;
  77.     char    *modes = "";
  78.     char    archie_date[20];
  79.     char    *gt_date = "";
  80.     int        gt_year = 0;
  81.     int        gt_mon = 0;
  82.     int        gt_day = 0;
  83.     int        gt_hour = 0;
  84.     int        gt_min = 0;
  85.     
  86.     /* Initialize local buffers */
  87.     *archie_date = '\0';
  88.  
  89.     /* Remember if we're looking at a directory */
  90.     if (sindex(l->type,"DIRECTORY"))
  91.     dirflag = 1;
  92.     else
  93.     dirflag = 0;
  94.     
  95.     /* Extract the linkpath from the filename */
  96.     strcpy(linkpath,l->filename);
  97.     *(linkpath + (strlen(linkpath) - strlen(l->name) - 1)) = '\0';
  98.     
  99.     /* Is this a new host? */
  100.     if (strcmp(l->host,lasthost) != 0) {
  101. #ifdef XARCHIE
  102.     currentHostEntry = addHostEntry(l->host,db,NULL);
  103. #else
  104.     if (!listflag)
  105.         printf("\nHost %s\n\n",l->host);
  106. #endif
  107.     strcpy(lasthost,l->host);
  108.     *lastpath = '\001';
  109.     }
  110.     
  111.     /* Is this a new linkpath (location)? */
  112.     if(strcmp(linkpath,lastpath) != 0) {
  113. #ifdef XARCHIE
  114.     if (currentHostEntry == NULL)
  115.         currentHostEntry = addHostEntry("*UNKNOWN*",db,NULL);
  116.         currentLocEntry = addLocEntry((*linkpath ? linkpath : "/"),
  117.                       currentHostEntry,NULL);
  118. #else
  119.     if (!listflag)
  120.         printf("    Location: %s\n",(*linkpath ? linkpath : "/"));
  121. #endif
  122.     strcpy(lastpath,linkpath);
  123.     }
  124.     
  125.     /* Parse the attibutes of this link */
  126.     for (ap = l->lattrib; ap; ap = ap->next) {
  127.     if (strcmp(ap->aname,"SIZE") == 0) {
  128.         sscanf(ap->value.ascii,"%d",&size);
  129.     } else if(strcmp(ap->aname,"UNIX-MODES") == 0) {
  130.         modes = ap->value.ascii;
  131.     } else if(strcmp(ap->aname,"LAST-MODIFIED") == 0) {
  132.         gt_date = ap->value.ascii;
  133.         sscanf(gt_date,"%4d%2d%2d%2d%2d",>_year,
  134.            >_mon, >_day, >_hour, >_min);
  135.         if ((12 * (presenttime->tm_year + 1900 - gt_year) + 
  136.                     presenttime->tm_mon - gt_mon) > 6) 
  137.         sprintf(archie_date,"%s %2d %4d",month_sname(gt_mon),
  138.             gt_day, gt_year);
  139.         else
  140.         sprintf(archie_date,"%s %2d %02d:%02d",month_sname(gt_mon),
  141.              gt_day, gt_hour, gt_min);
  142.     }
  143.     }
  144.     
  145. #ifdef XARCHIE
  146.     /* just using linkpath buffer because it's here */
  147.     strcpy(linkpath,l->name);
  148.     if (dirflag)
  149.     strcat(linkpath,"/");
  150.     if (currentLocEntry == NULL) {
  151.     if (currentHostEntry == NULL)
  152.         currentHostEntry = addHostEntry("*UNKNOWN*",db,NULL);
  153.     currentLocEntry = addLocEntry("*UNKNOWN*",currentHostEntry,NULL);
  154.     }
  155.     (void)addFileEntry(linkpath,size,modes,archie_date,currentLocEntry,NULL);
  156.     numMatches += 1;
  157. #else
  158.     /* Print this link's information */
  159.     if (listflag)
  160.     printf("%s %6d %s %s%s\n",gt_date,size,l->host,l->filename,
  161.            (dirflag ? "/" : ""));
  162.     else
  163.     printf("      %9s %s %10d  %s  %s\n",(dirflag ? "DIRECTORY" : "FILE"),
  164.                     modes,size,archie_date,l->name);
  165. #endif
  166.  
  167.     /* Free the attibutes */
  168.     atlfree(l->lattrib);
  169.     l->lattrib = NULL;
  170. }
  171.  
  172. /*    -    -    -    -    -    -    -    -    */
  173. /*
  174.  * procquery : Process the given query and display the results. If
  175.  *    sortflag is non-zero, then the results are sorted by increasing
  176.  *    date, else by host/filename. If listflag is non-zero then each
  177.  *    entry is printed on a separate, complete line. Note that listflag
  178.  *    is ignored by xarchie.
  179.  */
  180. void
  181. procquery(host,str,max_hits,offset,query_type,sortflag,listflag)
  182. char *host,*str;
  183. int max_hits,offset;
  184. char query_type;
  185. int sortflag,listflag;
  186. {
  187.     VLINK l;
  188.     long now;
  189.     extern int rdgram_priority;
  190.  
  191.     /* initialize data structures for this query */
  192.     (void)time(&now);
  193.     presenttime = localtime(&now);
  194. #ifdef XARCHIE
  195.     /* initialize Prospero globals from appResources */
  196.     pfs_debug = appResources.debugLevel;
  197.     rdgram_priority = appResources.niceLevel;
  198.     client_dirsrv_timeout = appResources.timeout;
  199.     client_dirsrv_retry = appResources.retries;
  200.     clearDb(db);
  201.     currentHostEntry = HOST_NULL;
  202.     currentLocEntry = LOC_NULL;
  203.     numMatches = 0;
  204. #endif
  205.  
  206.     /* Do the query */
  207.     if (sortflag == 1)
  208.     l = archie_query(host,str,max_hits,offset,query_type,AQ_INVDATECMP,0);
  209.     else
  210.     l = archie_query(host,str,max_hits,offset,query_type,NULL,0);
  211.  
  212.     /* Error? */
  213.     if (perrno != PSUCCESS) {
  214. #ifdef XARCHIE
  215.     if (p_err_text[perrno]) {
  216.       if (*p_err_string)
  217.         alert2("Prospero error: %.100s - %.100s",p_err_text[perrno],
  218.             p_err_string);
  219.       else
  220.         alert1("Prospero error: %.200s",p_err_text[perrno]);
  221.     } else
  222.         alert1("Prospero error: Undefined error %d (prospero)", perrno);
  223.         status0("Ready");
  224. #else
  225.     if (p_err_text[perrno]) {
  226.         if (*p_err_string)
  227.         fprintf(stderr, "%s: failed: %s - %s\n", progname,
  228.                 p_err_text[perrno], p_err_string);
  229.         else
  230.             fprintf(stderr, "%s failed: %s\n", progname, p_err_text[perrno]);
  231.     } else
  232.         fprintf(stderr, "%s failed: Undefined error %d (prospero)", perrno);
  233. #endif
  234.     }
  235.  
  236.     /* Warning? */
  237.     if (pwarn != PNOWARN) {
  238. #ifdef XARCHIE
  239.     if (*p_warn_string)
  240.         alert2("Prospero warning: %.100s - %.100s",
  241.            p_warn_text[pwarn], p_warn_string);
  242.     else
  243.         alert1("Prospero warning: %.200s",p_warn_text[pwarn]);
  244.         status0("Ready");
  245. #else
  246.     if (*p_warn_string)
  247.         fprintf(stderr, "%s: Warning! %s - %s\n", progname,
  248.         p_warn_text[pwarn], p_warn_string);
  249.     else
  250.         fprintf(stderr, "%s: Warning! %s\n", progname, p_warn_text[pwarn]);
  251. #endif
  252.     }
  253.  
  254.  
  255.     /* Display the results */
  256. #ifdef XARCHIE
  257.     status0("Parsing");
  258. #endif
  259.     *lasthost = '\001';
  260.     *lastpath = '\001';
  261.     while (l != NULL) {
  262.     display_link(l,listflag);
  263.     l = l->next;
  264.     }
  265. #ifdef XARCHIE
  266.     displayHosts(db);
  267.     status1("Found %d matches -- Ready",numMatches);
  268. #endif
  269. }
  270.