/********************************************************************
* wilkinson
* 3.19VMS
* 1995/09/25 14:30
* gopher_root1:[gopher.g2.vms2_13.gopherd]ext.c,v
* Exp
*
* Paul Lindner, University of Minnesota CIS.
*
* Copyright 1991, 1992 by the Regents of the University of Minnesota
* see the file "Copyright" in the distribution for conditions of use.
*********************************************************************
* MODULE: ext.c
* These fns define mapping of file extensions to gopher objects.
*********************************************************************
* Revision History:
* ext.c,v
* Revision 3.19VMS 1995/09/25 14:30 wilkinson
* Consolodate VMS/Unix source code for server as well as client
*
* Revision 3.19 1994/09/29 19:57:45 lindner
* Less picky language and view comparisions
*
* Revision 3.18 1994/07/21 15:46:22 lindner
* Brian Coen Patch
*
* Revision 3.17 1994/07/19 20:27:35 lindner
* Use local Locale.h
*
* Revision 3.16 1994/05/02 07:41:11 lindner
* Mods to use setlocale()
*
* Revision 3.15 1994/04/26 22:43:57 lindner
* Fix for Debugmsg
*
* Revision 3.14 1994/04/25 20:49:04 lindner
* Fix for debug code
*
* Revision 3.13 1994/01/20 06:39:18 lindner
* When trying to match an extension to a file type, the server prefers
* exact matches of type & language, but will now fall back to matching
* the type in any language (acf).
*
* Revision 3.12 1993/10/27 20:35:24 lindner
* Plug memory leak
*
* Revision 3.11 1993/10/20 03:17:25 lindner
* Fixed erratic problems with extension adding. Note that the problems
* with directories not working with Gopher0 clients is due to a missing
* parameter in a strncasecmp() call.. Makes one wish ANSI C was more
* widespread...
*
* Also added regular expression code for ignore_patt:
*
* Revision 3.10 1993/10/04 06:39:31 lindner
* Fix for forward declarations
*
* Revision 3.9 1993/09/21 02:35:04 lindner
* Server now adds extensions in a case insensitive manner
*
* Revision 3.8 1993/09/18 03:30:11 lindner
* Remove memory leak
*
* Revision 3.7 1993/09/18 02:22:35 lindner
* More debugging...
*
* Revision 3.6 1993/08/19 20:25:46 lindner
* Mitra's Debug patch
*
* Revision 3.5 1993/08/03 06:03:08 lindner
* Ignored files are now ignored again
*
* Revision 3.4 1993/07/31 00:15:37 lindner
* Fixed weird extension problem
*
* Revision 3.3 1993/07/27 20:15:29 lindner
* Fixed bug where filename was less than extension
*
* Revision 3.2 1993/07/23 03:18:46 lindner
* Mods for using decoder:'s
*
* Revision 3.1.1.1 1993/02/11 18:02:51 lindner
* Gopher+1.2beta release
*
* Revision 1.3 1993/02/09 22:13:19 lindner
* many additions for multilingual gopher
*
* Revision 1.2 1993/01/30 23:56:55 lindner
* Lots of new code for gopher+ stuff.. Change everything to start with EX
*
* Revision 1.1 1992/12/10 23:13:27 lindner
* gopher 1.1 release
*
*
*********************************************************************/
#include <stdio.h>
#include "ext.h"
#include "Malloc.h"
#include "Locale.h"
#include <ctype.h>
#include "util.h"
#ifdef VMS_SERVER
#include "command.h"
#endif
#include "serverutil.h"
#include "openers.h"
#undef stat
#include "Debug.h"
#include "Dirent.h"
#include "Regex.h"
/*
* Some functions to initialize and destroy sites and extensions..
* (Needed for use with DynArrays...)
*/
for (dp = readdir(ZeDir); dp != NULL; dp = readdir(ZeDir)) {
int x;
#ifndef VMS_SERVER
x = strcasecmp(cp, dp->d_name);
#else
x = strcasecmp(cp, dp/*->d_name*/);
#endif
if (x == 0) {
/** Found an exact match **/
#ifndef VMS_SERVER
strcpy(cp, dp->d_name);
closedir(ZeDir);
#else
strcpy(cp, dp/*->d_name*/);
#endif
return(tmpfile);
}
}
/** Now check for a not so exact match.. **/
#ifndef VMS_SERVER
rewinddir(ZeDir);
#endif
for (dp = readdir(ZeDir); dp != NULL; dp = readdir(ZeDir)) {
int x;
#ifndef VMS_SERVER
x = strncasecmp(cp, dp->d_name, strlen(dp->d_name));
#else
x = strncasecmp(cp, dp/*->d_name*/, strlen(dp/*->d_name*/));
#endif
if (x==0)
/** Found a match for a possible decoder **/
#ifndef VMS_SERVER
strcpy(cp, dp->d_name);
#else
strcpy(cp, dp/*->d_name*/);
#endif
}
#ifndef VMS_SERVER
closedir(ZeDir);
#endif
/** Hmm can't seem to find it.. Let's try the decoders... **/
tmpfilelen = strlen(tmpfile);
/** Check for decoders.. **/
for (i=0; i< EXAgetNumEntries(extarr); i++) {
temp = EXAgetEntry(extarr,i);
if (EXgetExttype(temp) == EXT_DECODER) {
char decodertmp[256];
/*
* Search for a specific view extension...
* Prefers exact match of type & lang, but if it can't find one it will
* fall back to matching type in any language.
*/
/*** Second parameter, depends on which token we're using.. ***/
i=0;
while (!isspace(*inputline) && (*inputline != '\0'))
secondparm[i++] = *inputline++;