sub hook { &logMsg("In Hook1"); my ($name, $buffer, $bytesRead, $data) = @_; &logMsg("In Hook"); &logMsg("name=$name,bytesRead=$bytesRead"); if (defined $lastSeenName) { if (($name ne $lastSeenName) || ($bytesRead < $lastSeenTotal)) { $subTotal += $lastSeenTotal; } } else { $uploadSize = $ENV{'CONTENT_LENGTH'}; &logPct(0); } $lastSeenName = $name; $lastSeenTotal = $bytesRead; $fileSizeMap{$name} = $bytesRead; $totalBytes = $subTotal + $bytesRead; if ($uploadSize > 0) { my $curPct = int((100 * $totalBytes)/$uploadSize); $curPct = 98 if ($curPct > 98); &logPct($curPct); } } sub main() { readProperties(); $logFile = "/home/manish/files/temp1.log"; unlink $logFile; &logMsg("Main Method"); eval { mkpath($infoPath) }; if ($@) { &logMsg("Could not create $infoPath: $@"); $errorCode = "BAD_INFO_PATH"; } &processForm(); $ctSessionId = $paramMap{"ctSessionId"}; $uploadId = $paramMap{"uploadId"}; if (not (defined $uploadId)) { $uploadId = $ctSessionId; } if ($ctSessionId ne "0000") { &validateSession(); } &logMsg("before hook :: $ctSessionId :: $uploadId"); $cgi = new CGI(\&hook,"ctfile_upload"); $failureURL = $cgi->param('failureURL'); $successURL = $cgi->param('successURL'); my $queryParams = $ENV{'QUERY_STRING'}; $successURL = "${successURL}\?${queryParams}"; $failureURL = "${failureURL}\?${queryParams}"; my $action = $cgi->param('action'); if (defined $errorCode) { } elsif ($action eq "cancel") { $errorCode="CANCELLED"; } elsif ($action eq "overwrite") { $errorCode="OVERWRITE"; } elsif ($action eq "back") { $errorCode = "BACK"; } else { my $receiveError = $cgi->cgi_error; if ($receiveError) { &logMsg("Error receiving:$receiveError"); $errorCode = "NOT_RECEIVED"; } } if (-e "$tombstonePath/$uploadId") { $errorCode = "CANCELLED"; } if (defined $errorCode) { my @cgiParams = $cgi->param; foreach my $cgiParam (@cgiParams) { my @paramValues = $cgi->param($cgiParam); foreach my $paramValue (@paramValues) { &addField($cgiParam, $paramValue); } } } else { &logPct(99); ©Files(); &logPct(100); } if (defined $errorCode) { &logMsg("Error code = $errorCode"); &reportFailure(); } elsif (defined $recoverableErrorCode) { $errorCode = $recoverableErrorCode; &logMsg("Error code = $errorCode"); &reportFailure(); } else { &reportSuccess(); } }