/* Handle HTTP request for CERNVM FIND server FINDGate.c ** ** This code takes a document name and converts it into ** a VM CMS command to produce the hypertext the caller requires. ** This involves, in general, calling an EXEC file which puts ** the data onto the "stack" The stack allows the data to be read from ** stdin as though it came from the command device. ** The commands are written to return a value which is equal to the ** number of lines put onto the stack. ** ** History ** 29 May 91 Separated from daemon program - TBL ** 19 May 91 Retrieve subroutine format used. -TBL */ #define BUFFER_SIZE 4096 /* Arbitrary size for efficiency */ #include "HTUtils.h" #include "tcp.h" /* The whole mess of include files */ #include "HTTCP.h" /* Some utilities for TCP */ extern int WWW_TraceFlag; /* Control diagnostic output */ extern FILE * logfile; /* Log file output */ extern char HTClientHost[16]; /* Client name to be output */ extern int HTWriteASCII(int soc, const char * s); /* In HTDaemon.c */ /* Strip white space off a string ** ** On exit, ** Return value points to first non-white character, or to 0 if none. ** All trailing white space is overwritten with zero. */ PRIVATE char * strip(char * s) { #define SPACE(c) ((c==' ')||(c=='\t')||(c=='\n')) char * p=s; for(p=s;*p;p++); /* Find end of string */ for(p--;p>=s;p--) { if(SPACE(*p)) *p=0; /* Zap trailing blanks */ else break; } while(SPACE(*s))s++; /* Strip leading blanks */ return s; } /* Handle one message ** ------------------ ** ** On entry, ** soc A file descriptor for input and output. ** On exit, ** returns >0 Channel is still open. ** 0 End of file was found, please close file ** <0 Error found, please close file. */ /* Retrieve information ** -------------------- */ #ifdef __STDC__ int HTRetrieve(const char * arg, const char * keys, int soc) #else int HTRetrieve(arg, keys, soc) char *arg; char *keys; int soc; #endif { #define COMMAND_SIZE 255 #define MAX_LINES 10000 /* Maximum number of lines returned */ char command[COMMAND_SIZE+1]; char keywords[COMMAND_SIZE+1]; char argument[COMMAND_SIZE+1]; char buffer[BUFFER_SIZE]; char * filename; /* Pointer to filename or group list*/ char system_command[COMMAND_SIZE+1]; int lines; /* Number of lines returned by EXEC file */ /* Remove host and any punctuation. (Could use HTParse @) */ strcpy(argument, arg); filename = argument; if (argument[0]=='/') { if (argument[1]=='/') { filename = strchr(argument+2, '/'); /* Skip //host/ */ if (!filename) filename=argument+strlen(argument); } else { filename = argument+1; /* Assume root: skip slash */ } } if (!*filename) { HTWriteASCII(soc,"
Error: No document ID provided.
\n");
return 0;
}
if (keys) strcpy(keywords, keys);
else keywords[0] = 0; /* As if just "?" given (historical) */
/* Formats supported by FIND are:
**
** /FIND Help for find general index
** /FIND/ (same)
** /FIND/? (same)
** /FIND/group.disk.ft.fn Get a document from a disk- NOT INDEX
** /FIND/grouplist? Help for group index
** /FIND/grouplist?keylist Search a set of disks for keywords
** where grouplist = group+group+group.. or void
** keylist = key+key+key... (not void)
*/
if((
(0==strncmp(filename,"FIND",4))
|| (0==strncmp(filename,"find",4))
) && (
(filename[4]==0)
|| (filename[4]=='/')
|| (filename[4]=='?')
)) {
filename=filename+4;
if (*filename=='/') filename++; /* Skip first slash */
if (keys || !*filename) { /* Index access */
char *p;
while((p=strchr(filename,'+'))!=0) *p=' ';/* Remove +s */
while((p=strchr(keywords,'+'))!=0) *p=' ';/* Remove +s */
if (!*keywords) { /* If no keywords */
HTWriteASCII(soc, "
Supply keywords to search for information.
\n");
return 0;
}
sprintf(buffer, "
See also: