// Copyright 1999 (c) by Perforce Software, Inc. All rights reserved. // // p4wUploadLocalProcessorView: // The Upload Local File processor view. // ------------------------------------- // Includes // #include <stdlib.h> #include <string.h> #include <p4wp4.h> #include "p4wView.h" #include "p4wUploadLocalProcessorView.h" #include "p4wUploadLocalProcessorPane.h" #include "p4wClientRootPane.h" #include "p4wStrBuf.h" // // ------------------------------------- // Constructors and destructor. // p4wUploadLocalProcessorView::p4wUploadLocalProcessorView(p4wRequest & Request) : p4wView(Request), fRequest(Request) { fErrMsg = NULL; } p4wUploadLocalProcessorView::~p4wUploadLocalProcessorView() { } // ------------------------------------- // Control item render functions. // void p4wUploadLocalProcessorView::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; } } p4wUploadLocalProcessorPane uploadProcessorPane(*this, fRequest); fRequest.p4Arg( "-C" ); fRequest.p4Arg( fRequest.GetDepotPath().Text() ); fRequest.p4( "fstat", 0, 0, &uploadProcessorPane ); fRequest.p4Wait(); fPost = fRequest.GetPostData(); fPostLgth = fRequest.GetPostLgth(); fErrMsg = uploadProcessorPane.fErrMsg ? uploadProcessorPane.fErrMsg : SaveFile(uploadProcessorPane.fClientFile.Text(), uploadProcessorPane.fType.Text()); } char *p4wUploadLocalProcessorView::SaveFile(char *path, char *type) { if (!fPost) return "No data to write."; char *end = fPost + fPostLgth; if (!path || !*path) return "Unable to determine file to write."; char *p = strchr(fPost, '\n'); if (!p) return "No multipart header."; if (*(p-1) == '\r') --p; *p = '\0'; char *q = strstr(++p, "filename=\"\""); if (q) return "No file name provided, nothing to upload."; p = strstr(++p, "name=\"upfile\""); if (!p) return "Cannot find file to upload."; while (1) { p = strchr(++p, '\n'); if (!p) return "Unable to find start of upload file."; if (*++p == '\n' || (*p == '\r' && *++p == '\n')) break; } StrBuf temp; int isText = 0; int typeIsUtf16 = 0; int needsCRLF = 0; if( type ) { if (strstr(type, "text") || strstr(type, "unicode") || strstr(type, "symlink")) isText = 1; else if ( strstr(type, "utf16") ) isText = typeIsUtf16 = 1; } char bom1[3] = { 0xFF, 0xFE, '\0' }; char bom2[3] = { 0xFE, 0xFF, '\0' }; int isUtf16File = !strncmp(p+1, bom1, 2) || !strncmp(p+1, bom2, 2); int lgth = strlen(fPost); for (q = p++; 1; ) { # ifdef OS_NT if (!typeIsUtf16 || isUtf16File) { if (*++q == '\n' && *(q-1-isUtf16File) != '\r' && isText) needsCRLF = 1; } else # endif if (*++q == '\r' && *(q+1+isUtf16File) == '\n' && isText) { strcpy(q, q+1+isUtf16File); end -= 1+isUtf16File; } if (!strncmp(q, fPost, lgth)) break; # ifdef OS_NT else if (isUtf16File && *q=='\r' && *(q+1)=='\n' && !strncmp(q+2, fPost, lgth)) { q++; break; } # endif if (q == end) { if (isText) return "Unable to find end of text file to upload - should the file type be binary?"; else return "Unable to find end of binary upload file."; } } --q; if (*(q-1-isUtf16File) == '\r') q -= 1+isUtf16File; if (p == q) return "Zero length file."; # ifdef OS_NT if (needsCRLF) { int cnt = q-p; temp.Alloc(cnt * 2); char *s = p; char *t = temp.Text(); while (cnt--) { if (*s == '\n' && *(s-1-isUtf16File) != '\r') { *t++ = '\r'; if (isUtf16File) *t++ = '\0'; } *t++ = *s++; } *t++ = '\0'; *t++ = '\0'; temp.SetLength(t - temp.Text() - 2); p = temp.Text(); q = p + temp.Length(); } # endif Error e; StrBuf buf; CharSetCvt *cvt; CharSetCvt::CharSet cs; FileSys *f; StrBuf md5; f = FileSys::Create( (!isUtf16File && typeIsUtf16) ? FST_UTF16 : FST_BINARY ); f->Set( path ); if (!fRequest.isLocalRequest() && (f->Stat() & FSF_SYMLINK) && !SEC_ALLOW_CR8CHG_SYMLINKS) { delete f; return "A Symlink may not be uploaded by a remote browser."; } f->Open( FOM_WRITE, &e ); if( e.Test() ) { delete f; return "Unable to open file for write."; } f->Write( p, q-p, &e ); if(!e.Test()) f->Close( &e ); if(!e.Test()) f->Chmod( "rw", &e ); delete f; 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/p4wUploadLocalProcessorView.cpp | |||||
#1 | 8914 | Matt Attaway | Initial add of the P4Web source code |