// Copyright 1999 (c) by Perforce Software, Inc. All rights reserved. // // p4wEditLocalProcessorView: // The Edit Local Text File processor view. // ------------------------------------- // Includes // #include <stdlib.h> #include <string.h> #include <p4wp4.h> #include "p4wView.h" #include "p4wEditLocalProcessorView.h" #include "p4wEditLocalProcessorPane.h" #include "p4wClientRootPane.h" #include "p4wStrBuf.h" // // ------------------------------------- // Constructors and destructor. // p4wEditLocalProcessorView::p4wEditLocalProcessorView(p4wRequest & Request) : p4wView(Request), fRequest(Request) { fErrMsg = NULL; } p4wEditLocalProcessorView::~p4wEditLocalProcessorView() { } // ------------------------------------- // Control item render functions. // void p4wEditLocalProcessorView::Render() { p4wClientRootPane clientRootPane(*this, fRequest); const char *cliArgs[] = { "-o" }; fRequest.p4("client", 1, cliArgs, &clientRootPane); fRequest.p4Wait(); if (clientRootPane.GetIsLockedAway()) { fErrMsg = "Locked client may only be used by its owner"; return; } if (!SEC_ALLOW_ALL_CLIENTS && !fRequest.isLocalRequest()) { if (strcmp(clientRootPane.GetOwner().Text(), fRequest.GetUser().Text())) { if (SEC_ALLOW_UNOWNED_CLIENTS && clientRootPane.GetOwner().Length() == 0) ; else { fErrMsg = "Client may only be used by its owner"; return; } } if (!clientRootPane.GetHost().Length() && !SEC_ALLOW_NOHOST_CLIENTS) { fErrMsg = "Clients without a Host may not be used"; return; } } p4wEditLocalProcessorPane editProcessorPane(*this, fRequest); fRequest.p4Arg( "-C" ); fRequest.p4Arg( fRequest.GetDepotPath().Text() ); fRequest.p4( "fstat", 0, 0, &editProcessorPane ); fRequest.p4Wait(); fPost = fRequest.GetPostData(); fErrMsg = editProcessorPane.fErrMsg ? editProcessorPane.fErrMsg : SaveFile(editProcessorPane.fClientFile.Text(), editProcessorPane.fFileType.Text()); } char *p4wEditLocalProcessorView::SaveFile(char *path, char *filetype) { if (!fPost) return "No data to write."; if (!path || !*path) return "Unable to determine file to write."; char *p = strstr(fPost, "Key="); if (!p) return "No security key"; p += sizeof("Key=")-1; char *q = strchr(p, '&'); if (!q) return "No security key"; *q++ = '\0'; StrBuf md5in; md5in << p; p = strstr(q, "Edit="); if (!p) p = strstr(fPost, "Edit="); if (!p) return "Unable to process file data."; p += sizeof("Edit=")-1; q = strchr(p, '&'); if (!q) return "Unable to process file data."; *q++ = '\0'; StrBuf edit; edit << p; p4wStrBuf editbuf; editbuf.UnescapeURL(edit, 1); for (p = editbuf.Text(); *p; ) { if ((*p == '\r') && (*(p+1) == '\n')) strcpy(p, p+1); else p++; } editbuf.SetLength(); Error e; StrBuf buf; CharSetCvt *cvt = NULL; CharSetCvt::CharSet cs; FileSys *f; StrBuf md5; // // If this is a utf16 filetype, we need to use // the correct type to translate it to utf8 if (filetype && !strcmp(filetype, "utf16")) { f = FileSys::Create( FST_UTF16 ); // // If we are in unicode mode, we need to translate // file from UTF-8 so that it is saved correctly } else if( fRequest.GetUnicode() ) { f = FileSys::Create( FST_UNICODE ); cs = CharSetCvt::Lookup( fRequest.GetClientApi().GetCharset().Text() ); cvt = CharSetCvt::FindCvt( cs, CharSetCvt::UTF_8 ); f->Translator( cvt ); } else { f = FileSys::Create( FST_TEXT ); } f->Set( path ); if (!fRequest.isLocalRequest() && (f->Stat() & FSF_SYMLINK) && !SEC_ALLOW_CR8CHG_SYMLINKS) { delete f; if(cvt) delete cvt; return "A Symlink may not be edited by a remote browser."; } f->Digest(&md5, &e); if(e.Test() || md5 != md5in) { delete f; if(cvt) delete cvt; return "Bad security key"; } f->WriteFile( &editbuf, &e ); if(!e.Test()) f->Chmod( "rw", &e ); delete f; if(cvt) delete cvt; if (e.Test()) return "Unable to write file."; return 0; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 12234 | Matt Attaway |
Rejigger P4Web project in preparation for official sunsetting The bin directory contains the last official builds of P4Web from the Perforce download site. P4Web is soon to be completely sunsetted; these builds are here for folks who don't want to build their own. To better handle the archived builds the source code has been moved into a separate src directory. |
||
//guest/perforce_software/p4web/Views/p4wEditLocalProcessorView.cpp | |||||
#1 | 8914 | Matt Attaway | Initial add of the P4Web source code |