Polarhome, production since 1999.\n\
Member of Polarhome portal.\n\
");
}
/*****************************************************************************/
/*
*/
ConanTheLibrarian ()
{
int idx;
unsigned long UnixTime;
char *cptr, *sptr;
struct tm *UnixTmPtr;
int status;
/*********/
/* begin */
/*********/
time (&UnixTime);
UnixTmPtr = localtime (&UnixTime);
if (!strftime (UnixDateTime, sizeof(UnixDateTime),
"%a, %d %b %Y %T", UnixTmPtr))
strcpy (UnixDateTime, "[error]");
if (Debug) fprintf (stdout, "UnixDateTime |%s|\n", UnixDateTime);
/* initialize anything specifically required for CGIplus */
DoHeaderInformation = DoListLibraries = DoLibraryMenu = DoSearch =
KeyNameWildcard = ExplodeHelp = ExtractHelp = ListSingle =
ErrorReported = false;
DoSearchStatistics = true;
for (idx = 0; idx < 11; idx++)
KeyWord[idx][0] = KeyWordHtml[idx][0] =
KeyName[idx][0] = KeyNameHtml[idx][0] = '\0';
CgiServerSoftwarePtr = CgiLibVar ("WWW_SERVER_SOFTWARE");
CgiRequestMethodPtr = CgiLibVar ("WWW_REQUEST_METHOD");
if (strcmp (CgiRequestMethodPtr, "GET"))
{
CgiLibResponseHeader (501, "text/html");
fprintf (stdout, "Not implemented!\n");
return;
}
CgiPathInfoPtr = CgiLibVar ("WWW_PATH_INFO");
CgiPathTranslatedPtr = CgiLibVar ("WWW_PATH_TRANSLATED");
CgiScriptNamePtr = CgiLibVar ("WWW_SCRIPT_NAME");
CgiHttpPragmaPtr = CgiLibVar ("WWW_HTTP_PRAGMA");
CgiHttpCacheControlPtr = CgiLibVar ("WWW_HTTP_CACHE_CONTROL");
CgiHttpIfModifiedSincePtr = CgiLibVar ("WWW_HTTP_IF_MODIFIED_SINCE");
CgiFormDoPtr = CgiLibVar ("WWW_FORM_DO");
CgiFormExplodePtr = CgiLibVar ("WWW_FORM_EXPLODE");
CgiFormExtractPtr = CgiLibVar ("WWW_FORM_EXTRACT");
CgiFormSinglePtr = CgiLibVar ("WWW_FORM_SINGLE");
CgiFormKeyPtr = CgiLibVar ("WWW_FORM_KEY");
CgiFormTitlePtr = CgiLibVar ("WWW_FORM_TITLE");
CgiFormSearchPtr = CgiLibVar ("WWW_FORM_SEARCH");
if (!CgiFormSearchPtr[0])
CgiFormSearchPtr = CgiLibVar ("WWW_KEY_1");
CgiFormRefererPtr = CgiLibVar ("WWW_FORM_REFERER");
if (!CgiFormRefererPtr[0])
CgiFormRefererPtr = CgiLibVar ("WWW_HTTP_REFERER");
if (CgiFormRefererPtr[0])
{
/* re-escape the URL-escaped percentages */
CgiLibUrlEncode (CgiFormRefererPtr, -1, UriReferer, -1);
CgiLibHtmlEscape (CgiFormRefererPtr, -1, HtmlReferer, -1);
}
if (VMSnok (status = TimeSetGmt ()))
{
if (status != SS$_NOLOGNAM)
{
CgiLibResponseError (FI_LI, status, CgiScriptNamePtr);
exit (SS$_NORMAL);
}
}
if (CgiHttpIfModifiedSincePtr[0])
{
if (VMSnok (HttpGmTime (CgiHttpIfModifiedSincePtr,
&IfModifiedSinceBinaryTime)))
{
if (Debug) fprintf (stdout, "If-Modified-Since: NBG!\n");
IfModifiedSinceBinaryTime[0] = IfModifiedSinceBinaryTime[0] = 0;
CgiHttpIfModifiedSincePtr = "";
}
}
/**************/
/* initialize */
/**************/
idx = 0;
if (CgiFormKeyPtr[0])
{
/*****************************************/
/* get keywords from "key=" query string */
/*****************************************/
cptr = CgiFormKeyPtr;
while (*cptr)
{
if (idx <= 10) idx++;
if (*cptr == '~') cptr++;
sptr = KeyWord[idx];
while (*cptr && *cptr != '~') *sptr++ = *cptr++;
*sptr = '\0';
CgiLibHtmlEscape (KeyWord[idx], -1, KeyWordHtml[idx], -1);
if (Debug)
fprintf (stdout, "KeyWord[idx] |%s|%s|\n",
KeyWord[idx], KeyWordHtml[idx]);
}
}
else
if (!strstr (CgiPathTranslatedPtr, ".HLB") &&
!strstr (CgiPathTranslatedPtr, ".hlb") &&
!strstr (CgiPathTranslatedPtr, ".TLB") &&
!strstr (CgiPathTranslatedPtr, ".tlb"))
{
/*******************************/
/* get keywords from path info */
/*******************************/
/* make sure the default help library is used */
CgiPathTranslatedPtr = "";
idx = 0;
/* by comparing, scan past the script component of the path */
sptr = CgiScriptNamePtr;
cptr = CgiPathInfoPtr;
while (toupper(*cptr) == toupper(*sptr)) { cptr++; sptr++; }
while (*cptr)
{
if (idx <= 10) idx++;
if (*cptr == '/') cptr++;
sptr = KeyWord[idx];
if (*cptr == '_' || *cptr == '/')
{
/*
Some other HTML help systems use an underscore for qualifiers.
This implmentation also allows two concurrent forward-slashes
so that the qualifier may be entered literally!
*/
*sptr++ = '/';
cptr++;
}
while (*cptr && *cptr != '/') *sptr++ = *cptr++;
*sptr = '\0';
CgiLibHtmlEscape (KeyWord[idx], -1, KeyWordHtml[idx], -1);
if (Debug)
fprintf (stdout, "KeyWord[idx] |%s|%s|\n",
KeyWord[idx], KeyWordHtml[idx]);
}
/* finished with the path if we've used it for keywords! */
CgiPathInfoPtr = "";
}
KeyWordCount = idx;
while (idx++ < 10) KeyWord[idx][0] = KeyWordHtml[idx][0] = '\0';
strcpy (LibraryPathInfo, CgiPathInfoPtr);
/* isolate the directory component of the path */
strcpy (LibraryDirPath, CgiPathInfoPtr);
for (cptr = LibraryDirPath; *cptr; cptr++);
if (cptr > LibraryDirPath) cptr--;
while (cptr > LibraryDirPath && *cptr != '/') cptr--;
if (*cptr == '/') cptr++;
*cptr = '\0';
if (Debug) fprintf (stdout, "|%s|\n", LibraryDirPath);
strcpy (LibrarySpec, CgiPathTranslatedPtr);
for (sptr = LibrarySpec; *sptr && *sptr != '*' && *sptr != '%'; sptr++);
if (*sptr) DoListLibraries = true;
switch (toupper(CgiFormDoPtr[0]))
{
case 'H' : DoHeaderInformation = true; break;
case 'L' : DoListLibraries = true; break;
case 'M' : DoLibraryMenu = true; break;
case 'S' : DoSearch = true; break;
default :
for (cptr = CgiPathTranslatedPtr; *cptr; cptr++)
if (*cptr == '*' || *cptr == '%') DoListLibraries = true;
}
if (CgiFormExplodePtr[0])
ExplodeHelp = true;
else
ExplodeHelp = false;
if (CgiFormExtractPtr[0])
ExtractHelp = true;
else
ExtractHelp = false;
if (CgiFormSinglePtr[0] || CliListSingle)
ListSingle = true;
else
ListSingle = false;
if (CgiFormSearchPtr[0])
{
DoSearch = true;
SearchStringLength = strlen(CgiFormSearchPtr);
CgiLibHtmlEscape (CgiFormSearchPtr, -1, HtmlSearchString, -1);
}
if (DoSearch && !CgiFormSearchPtr[0])
{
CgiLibResponseError (FI_LI, 0, "Search string not supplied.");
return;
}
if (!KeyWord[1][0])
{
/* no module keyname supplied, wildcard to list all modules */
strcpy (KeyWord[1], "*");
KeyNameWildcard = true;
}
else
{
/* check for a wildcard in the keyname, list all modules if there is */
for (sptr = KeyWord[1]; *sptr && *sptr != '*' && *sptr != '%'; sptr++);
if (*sptr) KeyNameWildcard = true;
}
LibraryTitle[0] = '\0';
if (!CgiPathTranslatedPtr[0]) CgiFormTitlePtr = "VMS Help";
if (CgiFormTitlePtr[0]) strcpy (LibraryTitle, CgiFormTitlePtr);
if (LibraryTitle[0])
CgiLibHtmlEscape (LibraryTitle, -1, HtmlLibraryTitle, -1);
else
{
sprintf (LibraryTitle, "Library %s", LibraryPathInfo);
CgiLibHtmlEscape (LibraryTitle, -1, HtmlLibraryTitle, -1);
}
if (Debug) fprintf (stdout, "LibraryTitle |%s|\n", LibraryTitle);
CgiLibUrlEncode (LibraryTitle, -1, UriFormTitle, -1);
CgiLibHtmlEscape (LibraryTitle, -1, HtmlFormTitle, -1);
/***********/
/* process */
/***********/
if (DoListLibraries)
ListLibraries ();
else
if (DoLibraryMenu)
LibraryMenu ();
else
Librarian ();
}
/****************************************************************************/
/*
Search for library files according to the the supplied specification (defaults
to help libraries; SYS$HELP:*.HLB). Display the name of each library in lower
case as a list item.
*/
ListLibraries ()
{
boolean SupportedLibraryType;
int len, status,
FileCount = 0;
char *cptr, *sptr;
char ResFileName [ODS_MAX_FILE_NAME_LENGTH+1],
ExpFileName [ODS_MAX_FILE_NAME_LENGTH+1],
String [2048],
UrlEncoded [ODS_MAX_FILE_NAME_LENGTH+64+1];
struct FAB FileFab;
#ifdef ODS_EXTENDED
struct NAML FileNaml;
#endif /* ODS_EXTENDED */
struct NAM FileNam;
if (Debug) fprintf (stdout, "ListLibraries()\n");
/* if no library specifcation provided then default to help libraries */
if (!LibrarySpec[0]) strcpy (LibrarySpec, "SYS$HELP:*.HLB;0");
FileFab = cc$rms_fab;
FileFab.fab$l_fop = FAB$V_NAM;
FileFab.fab$l_nam = &FileNam;
#ifdef ODS_EXTENDED
if (OdsExtended)
{
FileFab.fab$l_fna = (char*)-1;
FileFab.fab$b_fns = 0;
FileFab.fab$l_nam = (struct namdef*)&FileNaml;
ENAMEL_RMS_NAML(FileNaml)
FileNaml.naml$l_long_filename = LibrarySpec;
FileNaml.naml$l_long_filename_size = strlen(LibrarySpec);
FileNaml.naml$l_long_expand = ExpFileName;
FileNaml.naml$l_long_expand_alloc = sizeof(ExpFileName)-1;
FileNaml.naml$l_long_result = ResFileName;
FileNaml.naml$l_long_result_alloc = sizeof(ResFileName)-1;
}
else
#endif /* ODS_EXTENDED */
{
FileFab.fab$l_fna = LibrarySpec;
FileFab.fab$b_fns = strlen(LibrarySpec);
FileFab.fab$l_nam = &FileNam;
FileNam = cc$rms_nam;
FileNam.nam$l_esa = ExpFileName;
FileNam.nam$b_ess = ODS2_MAX_FILE_NAME_LENGTH;
FileNam.nam$l_rsa = ResFileName;
FileNam.nam$b_rss = ODS2_MAX_FILE_NAME_LENGTH;
}
if (VMSnok (status = sys$parse (&FileFab, 0, 0)))
{
CgiLibResponseError (FI_LI, status, HtmlLibraryTitle);
return (SS$_NORMAL);
}
BeginPage (LibraryPathInfo, LibraryPathInfo);
while (VMSok (status = sys$search (&FileFab, 0, 0)))
{
if (!FileCount++) fprintf (stdout, "\n");
/* ignore directories if the file type includes them (numeric ".DIR") */
#ifdef ODS_EXTENDED
if (OdsExtended)
{
if (strsame(FileNaml.naml$l_long_type+1, "DIR;", 4)) continue;
}
else
#endif /* ODS_EXTENDED */
if (strsame(FileNam.nam$l_type+1, "DIR;", 4)) continue;
#ifdef ODS_EXTENDED
if (OdsExtended)
{
if (strsame (FileNaml.naml$l_long_type+1, "HLB;", 4) ||
strsame (FileNaml.naml$l_long_type+1, "TLB;", 4))
SupportedLibraryType = true;
else
SupportedLibraryType = false;
}
else
#endif /* ODS_EXTENDED */
{
if (strsame (FileNam.nam$l_type+1, "HLB;", 4) ||
strsame (FileNam.nam$l_type+1, "TLB;", 4))
SupportedLibraryType = true;
else
SupportedLibraryType = false;
}
sptr = String;
strcpy (sptr, "- ");
sptr += 4;
if (SupportedLibraryType)
{
#ifdef ODS_EXTENDED
if (OdsExtended)
{
CgiLibUrlEncode (LibraryDirPath, -1, UrlEncoded, -1);
sptr += sprintf (sptr, "",
UriFormTitle, UriReferer);
}
/* if there was wildcard in the file type then include it */
#ifdef ODS_EXTENDED
if (OdsExtended)
{
if (FileNaml.naml$l_fnb & NAM$M_WILD_TYPE)
*(char*)FileNaml.naml$l_long_ver = '\0';
else
*(char*)FileNaml.naml$l_long_type = '\0';
cptr = (char*)FileNaml.naml$l_long_name;
while (*cptr) *sptr++ = tolower(*cptr++);
*sptr = '\0';
if (FileNaml.naml$l_fnb & NAM$M_WILD_TYPE)
*(char*)FileNaml.naml$l_long_ver = ';';
else
*(char*)FileNaml.naml$l_long_type = '.';
}
else
#endif /* ODS_EXTENDED */
{
if (FileNam.nam$l_fnb & NAM$M_WILD_TYPE)
*(char*)FileNam.nam$l_ver = '\0';
else
*(char*)FileNam.nam$l_type = '\0';
cptr = (char*)FileNam.nam$l_name;
while (*cptr) *sptr++ = tolower(*cptr++);
*sptr = '\0';
if (FileNam.nam$l_fnb & NAM$M_WILD_TYPE)
*(char*)FileNam.nam$l_ver = ';';
else
*(char*)FileNam.nam$l_type = '.';
}
if (SupportedLibraryType)
{
strcpy (sptr, "");
sptr += 4;
}
*sptr++ = '\n';
*sptr = '\0';
fprintf (stdout, "%s", String);
}
if (FileCount)
fprintf (stdout, "
\n");
else
fprintf (stdout, "No files found.\n");
if (status == RMS$_FNF || status == RMS$_NMF) status = SS$_NORMAL;
if (VMSnok (status))
{
CgiLibResponseError (FI_LI, status, HtmlLibraryTitle);
return (SS$_NORMAL);
}
if (ErrorReported) return (status);
fprintf (stdout, "\n");
ButtonBar (2);
fprintf (stdout, "\n\n");
return (status);
}
/*****************************************************************************/
/*
For the specified library file provide a menu of four services; librarian,
searching, library header and help.
*/
LibraryMenu ()
{
char *cptr, *sptr;
char UrlEncoded [ODS_MAX_FILE_NAME_LENGTH+64+1];
/*********/
/* begin */
/*********/
if (Debug) fprintf (stdout, "LibraryMenu() |%s|\n", LibrarySpec);
strcpy (LibraryTitle, LibraryPathInfo);
CgiLibHtmlEscape (LibraryPathInfo, -1, HtmlLibraryTitle, -1);
CgiLibUrlEncode (LibraryTitle, -1, UriFormTitle, -1);
CgiLibHtmlEscape (LibraryTitle, -1, HtmlFormTitle, -1);
BeginPage (LibraryTitle, HtmlLibraryTitle);
CgiLibUrlEncode (LibraryPathInfo, -1, UrlEncoded, -1);
fprintf (stdout,
"
\n\
\n",
CgiScriptNamePtr, UrlEncoded, UriFormTitle, UriReferer,
CgiScriptNamePtr, UrlEncoded, UriFormTitle, UriReferer,
CgiScriptNamePtr, UrlEncoded,
HtmlReferer, HtmlFormTitle);
if (ErrorReported) return;
ButtonBar (2);
fprintf (stdout, "\
\n\n");
}
/*****************************************************************************/
/*
Initialise library control. Open the library specified by LibrarySpec. Get
header information from the library so its internal format can be determined
(help or text, other are not supported). Call ProcessLibrary() to perform the
requested access according to the library type.
*/
Librarian ()
{
int status;
unsigned long Function = LBR$C_READ,
Length;
char *cptr;
char String [1024];
$DESCRIPTOR (LibrarySpecDsc, "");
static struct dsc$descriptor_s
LibraryDefDsc = { sizeof(DEFAULT_LIBRARY)-1, DSC$K_DTYPE_T,
DSC$K_CLASS_S, DEFAULT_LIBRARY },
LibraryNameDsc = { sizeof(LibraryName)-1, DSC$K_DTYPE_T,
DSC$K_CLASS_S, LibraryName };
/****************************************/
/* initialize, open library, get header */
/****************************************/
if (Debug) fprintf (stdout, "Librarian()\n");
if (VMSnok (status = lbr$ini_control (&LibraryIndex, &Function, 0, 0)))
{
CgiLibResponseError (FI_LI, status, HtmlLibraryTitle);
return (SS$_NORMAL);
}
LibrarySpecDsc.dsc$w_length = strlen(LibrarySpec);
LibrarySpecDsc.dsc$a_pointer = LibrarySpec;
if (VMSnok (status = lbr$open (&LibraryIndex,
&LibrarySpecDsc,
0,
&LibraryDefDsc,
0,
&LibraryNameDsc,
&Length)))
{
if (Debug) fprintf (stdout, "lib$open() %%X%08.08X\n", status);
CgiLibResponseError (FI_LI, status, HtmlLibraryTitle);
return (SS$_NORMAL);
}
/* terminate, removing the trailing version number */
LibraryName[Length] = '\0';
for (cptr = LibraryName; *cptr && *cptr != ';'; cptr++);
*cptr = '\0';
if (Debug) fprintf (stdout, "LibraryName |%s|\n", LibraryName);
if (VMSnok (status = lbr$get_header (&LibraryIndex, &LibraryHeader)))
{
CgiLibResponseError (FI_LI, status, HtmlLibraryTitle);
return (SS$_NORMAL);
}
if (CgiHttpIfModifiedSincePtr[0])
{
if (VMSnok (ModifiedSince (&IfModifiedSinceBinaryTime,
&LibraryHeader.lhi$l_updtim)))
{
/* library has not been modified since the date/time, don't send */
status = lbr$close (&LibraryIndex);
return (SS$_NORMAL);
}
}
HttpGmTimeString (LastModifiedGmDateTime, &LibraryHeader.lhi$l_updtim);
/*******************/
/* process library */
/*******************/
if (DoHeaderInformation)
HeaderInformation ();
else
if (LibraryHeader.lhi$l_type == LBR$C_TYP_TXT)
{
if (DoSearch)
SearchTextLibraryModules ();
else
if (KeyNameWildcard)
ListTextLibraryModules ();
else
OpenTextLibraryModule ();
}
else
if (LibraryHeader.lhi$l_type == LBR$C_TYP_HLP)
{
if (DoSearch)
SearchHelpLibraryModules ();
else
if (KeyNameWildcard)
ListHelpLibraryModules ();
else
OpenHelpLibraryModule ();
}
else
{
sprintf (String,
"Library type %d not supported. (Only HELP and TEXT libraries are valid)",
LibraryHeader.lhi$l_type);
CgiLibResponseError (FI_LI, 0, String);
return (SS$_NORMAL);
}
status = lbr$close (&LibraryIndex);
return (SS$_NORMAL);
}
/*****************************************************************************/
/*
Provide selected library header information.
*/
HeaderInformation ()
{
static char *LibraryTypes[] =
{ "Unknown", "VAX Object", "Macro", "Help", "Text",
"VAX Sharable Image", "NCS",
"Alpha Object", "Alpha Sharable Image", "?" };
static $DESCRIPTOR (CreatedFaoDsc,
"Created: | !%D |
\n");
static $DESCRIPTOR (RevisedFaoDsc,
"Revised: | !%D |
\n");
unsigned short Length;
char String [1024];
$DESCRIPTOR (StringDsc, String);
/*********/
/* begin */
/*********/
BeginPage (LibraryTitle, LibraryTitle);
fprintf (stdout,
"\n\
\n");
if (LibraryHeader.lhi$l_type > 8) LibraryHeader.lhi$l_type = 9;
fprintf (stdout, "Type: | %s |
\n",
LibraryTypes[LibraryHeader.lhi$l_type]);
fprintf (stdout, "Creator: | %-*s |
\n",
*(char*)LibraryHeader.lhi$t_lbrver, (char*)LibraryHeader.lhi$t_lbrver+1);
fprintf (stdout, "Format: | %d.%d |
\n",
LibraryHeader.lhi$l_majorid, LibraryHeader.lhi$l_minorid);
sys$fao (&CreatedFaoDsc, &Length, &StringDsc, &LibraryHeader.lhi$l_credat);
String[Length] = '\0';
fprintf (stdout, "%s", String);
sys$fao (&RevisedFaoDsc, &Length, &StringDsc, &LibraryHeader.lhi$l_updtim);
String[Length] = '\0';
fprintf (stdout, "%s", String);
if (LibraryHeader.lhi$l_libstatus)
fprintf (stdout,
"Status: | OK |
\n");
else
fprintf (stdout,
"Status: | \
PROBLEM |
\n");
fprintf (stdout, "
\n");
if (ErrorReported) return;
fprintf (stdout, "
\n");
ButtonBar (2);
fprintf (stdout, "\n\n");
}
/*****************************************************************************/
/*
*/
int ListHelpLibraryModules ()
{
int status;
char *cptr, *sptr;
char KeyName [256],
String [1024];
$DESCRIPTOR (KeyNameDsc, KeyName);
if (Debug) fprintf (stdout, "ListHelpLibraryModules()\n");
cptr = KeyName;
for (sptr = KeyWord[1]; *sptr; *cptr++ = toupper(*sptr++));
*cptr = '\0';
KeyNameDsc.dsc$w_length = cptr - KeyName;
BeginPage (LibraryTitle, HtmlLibraryTitle);
fprintf (stdout,
"\n\
\n",
CgiScriptNamePtr, CgiPathInfoPtr,
HtmlReferer, HtmlFormTitle);
fflush (stdout);
IndexNumber = 1;
if (VMSnok (status = lbr$get_index (&LibraryIndex,
&IndexNumber,
&ListHelpModule,
&KeyNameDsc)))
{
if (Debug) fprintf (stdout, "lib$get_index() %%X%08.08X\n", status);
CgiLibResponseError (FI_LI, status, HtmlLibraryTitle);
return (SS$_NORMAL);
}
fprintf (stdout, "\n");
if (ErrorReported) return (status);
fprintf (stdout, "
\n");
ButtonBar (2);
fprintf (stdout, "