/* * Copyright 1995, 1998 Perforce Software. * * This file is part of WebKeeper, a perforce client apache module. * * License is hereby granted to use this software and distribute it * freely, as long as this copyright notice is retained and modifications * are clearly marked. * * ALL WARRANTIES ARE HEREBY DISCLAIMED. * * $Id: //guest/raymond_wiker/webkeeper/mod_webkeep2.cc#5 $ */ /* * mod_webkeep2.cc -- C++ glue between webkeeper and Perforce Client API * * ClientUserWK sits upon the Perforce ClientApi, and webKeepPrint() * makes use of ClientUserWK. The web server Apache module mod_webkeep.c * interfaces to webKeepPrint() through webkeep.h. */ # include <clientapi.h> extern "C" { # include "mod_webkeep.h" } class ClientUserWK : public ClientUser { public: void OutputInfo( char level, char *data ) { (*printer->data)( printer, data ); } void OutputError( char *errBuf ) { (*printer->error)( printer, errBuf ); } void OutputText( char *data, int length ) { (*printer->text)( printer, data, length ); } void OutputBinary( char *data, int length ) { (*printer->text)( printer, data, length ); } WebKeepPrinter *printer; } ; static int TryPrint(ClientApi *client, char *path, WebKeepPrinter *printer) { printer->ignoreerrors = 1; printer->print = 0; printer->collectinfo = 0; printer->errorcount = 0; // is it a file? client->SetArgv(1, &path); client->Run("files"); if (printer->errorcount == 0) { // yes, it's a file printer->ignoreerrors = 0; printer->print = 1; client->SetArgv(1, &path); client->Run("print"); return 1; } else { return 0; } } static int TryIndex(ClientApi *client, char *path, char *index, WebKeepPrinter *printer) { if (index == 0 || *index == 0) { index = "index.html"; // last-resort default } char *pathcopy = new char[::strlen(path) + 1 + ::strlen(index) + 1]; ::strcpy(pathcopy, path); ::strcat(pathcopy, "/"); ::strcat(pathcopy, index); int status = TryPrint(client, pathcopy, printer); delete []pathcopy; return status; } static int TryList(ClientApi *client, char *path, WebKeepPrinter *printer) { // is it a dir? printer->ignoreerrors = 1; printer->print = 0; printer->collectinfo = 0; printer->errorcount = 0; client->SetArgv(1, &path); client->Run("dirs"); if (printer->errorcount == 0) { // yes, it's a dir char *globpath = new char[::strlen(path) + 3]; ::strcpy(globpath, path); ::strcat(globpath, "/*"); printer->collectinfo = 1; client->SetArgv(1, &globpath); client->Run("dirs"); client->SetArgv(1, &globpath); client->Run("files"); (*(printer->dir))(printer); delete[] globpath; return 1; } else { return 0; } } extern "C" int webKeepPrint( WebKeepConnect *p4, const char *path, WebKeepPrinter *printer) { Error e[1]; ClientUserWK ui; ClientApi client(&ui); int status; // Plug in API extentions: user's closure parameter and // dispatch table. ui.printer = printer; if( p4->port ) client.SetPort( p4->port ); if( p4->user ) client.SetUser( p4->user ); if( p4->pass ) client.SetPassword( p4->pass ); if( p4->client ) client.SetClient( p4->client ); // Connect. client.Init( e ); if( !e->Test() ) { char *pathcopy = new char[::strlen(path) + 1]; ::strcpy(pathcopy, path); if (pathcopy[::strlen(pathcopy) - 1] == '/') { pathcopy[::strlen(pathcopy) - 1] = 0; } status = (TryPrint(&client, pathcopy, printer) || TryIndex(&client, pathcopy, p4->indexname, printer) || TryList(&client, pathcopy, printer)); delete[] pathcopy; } client.Final( e ); if (e->Test()) { StrBuf buf; e->Fmt( &buf ); (*printer->error)(printer, buf.Text()); } if (status == 0) { (*printer->error)(printer, "Not found!"); } return status; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 173 | raymond_wiker |
Message to myself: Write down 100 times: there's a difference between new char(BUFLENGTH) and new char[BUFLENGTH] |
||
#4 | 172 | raymond_wiker |
Added default index file (index.html, but configurable) to directory indexing. Also added filtering so that deleted files are not shown. |
||
#3 | 125 | raymond_wiker |
Debugged & improved somewhat... Now includes icons for directory listing. |
||
#2 | 124 | raymond_wiker |
Added directory indexing. Next: debugging. |
||
#1 | 121 | raymond_wiker | Branched webkeeper files to own view. |