/* * 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/paul_goffin/apache1.3.6/src/modules/perforce/mod_webkeep2.cc#2 $ */ /* * 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 | |
---|---|---|---|---|---|
#2 | 174 | paul_goffin |
Adopting Raymonds latest versions. Fixes directory listing problem. |
||
#1 | 169 | paul_goffin |
Added the Apache directory structure to raymond wiker's webkeeper update. (So novices like me can find where to put the stuff!) Inlcuded the mods to the Apache Configuration.tmpl and main Makefile to actually make it build. (The Makefile needs to use "CPP" instead of "CC" to do the final link with the g++ libraries.) This isn't put in by "configure", so you need to edit Makefile (or replace it with the one in this submission if you're building just a standard apache with webkeeper) after the configure process. (This Makefile includes the change, so you can just "diff" it.) Also had to change the include in mod_webkeeper2.cc to "" style from <> style. This version built (and running) on Redhat Linux 5.2 (x86). |
||
//guest/raymond_wiker/webkeeper/mod_webkeep2.cc | |||||
#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. |