struct pipeline *textOutInit(char *fileName, char *compressType) /* Set up stdout to be HTTP text, file (if fileName is specified), or * compressed file (if both fileName and compressType are specified -- * see textOut.h for supported compression types). * Return NULL if no compression, otherwise a pipeline handle on which * textOutClose should be called when we're done writing stdout. */ { struct pipeline *compressPipeline = NULL; trimSpaces(fileName); if (isEmpty(fileName)) { printf("Content-Type: text/plain\n\n"); } else if (isEmpty(compressType) || sameWord(compressType, textOutCompressNone)) { printf("Content-Type: application/octet-stream\n"); printf("Content-Disposition: attachment; filename=%s\n\n", fileName); } else { char *suffix = getCompressSuffix(compressType); printf("Content-Type: application/x-%s\n", compressType); if (endsWith(fileName, suffix)) printf("Content-Disposition: attachment; filename=%s\n\n", fileName); else printf("Content-Disposition: attachment; filename=%s%s\n\n", fileName, suffix); /* Send the Content header uncompressed! */ fflush(stdout); /* Make sure no environment variables interfere with compressor. */ cleanEnvVars(compressType); /* Redirect stdout to compressor pipeline object. */ compressPipeline = pipelineOpen1(getCompressor(compressType), pipelineWrite, NULL, NULL); if (-1 == dup2(pipelineFd(compressPipeline), STDOUT_FILENO)) errnoAbort("dup2(pipelineFd %d, stdout %d) failed in textOpen()", pipelineFd(compressPipeline), STDOUT_FILENO); } pushWarnHandler(textOutWarnHandler); pushAbortHandler(textOutAbortHandler); return(compressPipeline); }
void gsSendToDM() /* upload the generated file to DM */ { // This is now run via fork/exec as a separate background process. char *trashFileName = cartUsualString(cart, "gsTemp", ""); char *fileName = cartUsualString(cart, hgtaOutFileName, ""); // adjust upload name based on compression and existing extension char *compressType = cartUsualString(cart, hgtaCompressType, textOutCompressNone); if (!(isEmpty(compressType) || sameWord(compressType, textOutCompressNone))) { char *suffix = getCompressSuffix(compressType); if (!endsWith(fileName, suffix)) fileName = addSuffix(fileName, suffix); } off_t fSize = fileSize(trashFileName); char *gsToken = cartUsualString(cart, "gsToken", NULL); char *contentType = "text/plain"; // some examples show applicaton/octet-stream char *persDir = getGsPersonalDirectory(gsToken); char *user = strrchr(persDir,'/'); ++user; char nicenumber[1024]=""; sprintWithGreekByte(nicenumber, sizeof(nicenumber), fSize); htmlOpen("Uploading Output to GenomeSpace"); printf("Name: %s<br>\n", fileName); printf("Size: %s<br>\n", nicenumber); printf("Progress: 0%%<br>\n"); printf("You can remain on this page and monitor upload progress.<br>\n"); printf("Otherwise, feel free to continue working, and your output will appear in GenomeSpace when the upload is complete.<br>\n"); printf("<br>\n"); printf("<FORM ACTION=\"/cgi-bin/hgTables\" METHOD=GET>\n" "<INPUT TYPE=SUBMIT NAME=\"%s\" VALUE=\"Back\" >\n" "<INPUT TYPE=SUBMIT NAME=\"Refresh\" VALUE=\"Refresh\" onclick='window.location=window.location;return false;' >" "</FORM>\n" , hgtaDoMainPage); puts("<script type=\"text/JavaScript\">"); puts("<!--"); puts("setTimeout(\"location = location;\",5000);"); puts("-->"); puts("</script>"); htmlClose(); fflush(stdout); // MD5 COMPUTE unsigned char md5[16]; /* Keep the md5 checksum here. */ md5ForFile(trashFileName,md5); char *hexMd5 = md5ToHex(md5); char *base64Md5 = base64Encode((char*)md5, 16); char *s3UploadUrl = gsUploadUrl(gsToken, user, fileName, fSize, base64Md5, contentType); char *s3Response = gsS3Upload(s3UploadUrl, trashFileName, fSize, base64Md5, hexMd5, contentType, TRUE, fileName); if (sameString(s3Response,"")) { // Reset global flags before drawing brand new page webHeadAlreadyOutputed = FALSE; webInTextMode = FALSE; includedResourceFiles = NULL; htmlWarnBoxSetUpAlready=FALSE; htmlOpen("Uploaded Output to GenomeSpace"); printf("Name: %s<br>\n", fileName); printf("Size: %s<br>\n", nicenumber); printf("Output has been successfully uploaded.<br>\n"); printf("<br>"); printf("<FORM ACTION=\"/cgi-bin/hgTables\" METHOD=GET>\n" "<INPUT TYPE=SUBMIT NAME=\"%s\" VALUE=\"Back\" ></FORM>\n" , hgtaDoMainPage); htmlClose(); fflush(stdout); } //printf("s3UploadUrl [%s]", s3UploadUrl); //printf("<br>"); //printf("s3Response [%s]", s3Response); //printf("<br>"); exit(0); // CANNOT RETURN }
struct pipeline *textOutInit(char *fileName, char *compressType, int *saveStdout) /* Set up stdout to be HTTP text, file (if fileName is specified), or * compressed file (if both fileName and compressType are specified -- * see textOut.h for supported compression types). * Return NULL if no compression, otherwise a pipeline handle on which * textOutClose should be called when we're done writing stdout. */ { struct pipeline *compressPipeline = NULL; // if path contains a slash, we are outputting to a local file boolean outToFile = (strchr(fileName, '/') != NULL); if (outToFile) { FILE *f; f = fopen(fileName, "w"); /* We want to capture stdout output to a file */ fflush(stdout); int tempOut = dup(STDOUT_FILENO); if (saveStdout) *saveStdout = tempOut; dup2(fileno(f),STDOUT_FILENO); /* closes STDOUT before setting it again */ fclose(f); } trimSpaces(fileName); if (isEmpty(fileName)) { printf("Content-Type: text/plain\n\n"); } else if (isEmpty(compressType) || sameWord(compressType, textOutCompressNone)) { if (!outToFile) { printf("Content-Type: application/octet-stream\n"); printf("Content-Disposition: attachment; filename=%s\n\n", fileName); } } else { if (!outToFile) { char *suffix = getCompressSuffix(compressType); printf("Content-Type: application/x-%s\n", compressType); if (endsWith(fileName, suffix)) printf("Content-Disposition: attachment; filename=%s\n\n", fileName); else printf("Content-Disposition: attachment; filename=%s%s\n\n", fileName, suffix); /* Send the Content header uncompressed! */ fflush(stdout); } /* Make sure no environment variables interfere with compressor. */ cleanEnvVars(compressType); /* Redirect stdout to compressor pipeline object. */ compressPipeline = pipelineOpen1(getCompressor(compressType), pipelineWrite, NULL, NULL); if (-1 == dup2(pipelineFd(compressPipeline), STDOUT_FILENO)) errnoAbort("dup2(pipelineFd %d, stdout %d) failed in textOpen()", pipelineFd(compressPipeline), STDOUT_FILENO); } pushWarnHandler(textOutWarnHandler); pushAbortHandler(textOutAbortHandler); return(compressPipeline); }