static void h1n1DownloadPdb(char *item, char *pdbUrl, struct tempName *tmpPdb) /* uncompress PDB to trash */ { int inFd = netOpenHttpExt(pdbUrl, "GET", NULL); int inFdRedir = 0; char *pdbUrlRedir = NULL; if (!netSkipHttpHeaderLinesHandlingRedirect(inFd, pdbUrl, &inFdRedir, &pdbUrlRedir)) errAbort("Unable to access predicted 3D structure file: %s", pdbUrl); if (pdbUrlRedir != NULL) { close(inFd); inFd = inFdRedir; freez(&pdbUrlRedir); } trashDirFile(tmpPdb, "hgct", item, ".pdb"); FILE *outFh = mustOpen(tmpPdb->forCgi, "w"); struct lineFile *inLf = lineFileDecompressFd(pdbUrl, TRUE, inFd); char *line; while (lineFileNext(inLf, &line, NULL)) { fputs(line, outFh); fputc('\n', outFh); } lineFileClose(&inLf); carefulClose(&outFh); }
static void doDownload(struct sqlConnection *conn) /* Try to force user's browser to download by giving special response headers */ { int imageId = cartUsualInt(cart, hgpId, 0); char url[1024]; char *p = NULL; char dir[256]; char name[128]; char extension[64]; int w = 0, h = 0; int sd = -1; if (!visiGeneImageSize(conn, imageId, &w, &h)) imageId = 0; if (imageId == 0) { problemPage("invalid imageId",""); } else { p=visiGeneFullSizePath(conn, imageId); splitPath(p, dir, name, extension); safef(url,sizeof(url),"%s%s%s", dir, name, extension); sd = netUrlOpen(url); if (sd < 0) { problemPage("Couldn't open", url); } else { char *newUrl = NULL; int newSd = 0; /* url needed for err msgs and redirect url*/ if (netSkipHttpHeaderLinesHandlingRedirect(sd, url, &newSd, &newUrl)) { char buf[32*1024]; int readSize; if (newUrl) { freeMem(newUrl); sd = newSd; } printf("Content-Type: application/octet-stream\n"); printf("Content-Disposition: attachment; filename=%s%s\n", name, extension); printf("\n"); while ((readSize = read(sd, buf, sizeof(buf))) > 0) fwrite(buf, 1, readSize, stdout); close(sd); sd = -1; fflush(stdout); fclose(stdout); } else { problemPage("Skip http header problem", url); } freeMem(newUrl); } } }