void *harvest_http_go_proc(void *arg) { task_t *t = (task_t *) arg; int fd = (int)TASK_DATA(t), rv; unsigned inlen, outlen; UINT32 distlen=0; C_DistillerType type; char *inbuf=NULL, *outbuf=NULL, *distbuf=NULL; if (do_http_client_receive(fd, &inlen, &inbuf) != 0) { close(fd); return (void *) 0; } if (inlen <= 0) { close(fd); return (void *) 0; } if (Clib_Lowlevel_Op(inbuf, inlen, &outbuf, &outlen) != CLIB_OK) { if (inbuf) free(inbuf); if (outbuf) free(outbuf); close(fd); return (void *) 0; } strcpy(type.string, "all/passthru"); if (Distill(&type, 0, 0, outbuf, outlen, (void**) &distbuf, &distlen) != distOk) { if (inbuf) free(inbuf); if (outbuf) free(outbuf); close(fd); return (void *) 0; } if ((rv = correct_write(fd, distbuf, distlen)) != outlen) { if (inbuf) free(inbuf); if (outbuf) free(outbuf); FreeOutputBuffer(distbuf); close(fd); return (void *) 0; } if (inbuf) free(inbuf); if (outbuf) free(outbuf); FreeOutputBuffer(distbuf); close(fd); return (void *) 0; }
void * file_go_proc(task_t *t) { FILE *htmlfile = (FILE *)(TASK_DATA(t)); C_DistillerType type; Argument ar; size_t inbufsize; UINT32 outbufsize; DistillerStatus status; char *inbuf; char *outbuf; struct stat s; /* get file size */ (void)fstat(fileno(htmlfile), &s); /* allocate input buffer */ inbufsize = s.st_size; assert(inbuf = (char *)MALLOC(inbufsize)); inbufsize = fread((void *)inbuf, sizeof(char), (size_t)inbufsize, htmlfile); fclose(htmlfile); SET_DISTILLER_TYPE(type, "text/html"); SET_ARG_ID(ar, 1); /* string that will be appended to each target URL in html file */ SET_ARG_STRING(ar, "__foo__"); /* call html distiller */ status = Distill(type, &ar, 1, (void *)inbuf, (UINT32)inbufsize, (void *)&outbuf, &outbufsize); proxy_debug_3(DBG_HTTP, "Distiller status = %d\n", (int)status); /* dump outbuf to a file */ #if 0 if (status == distOk) { assert(htmlfile = fopen("/tmp/foo", "w")); fwrite((void *)outbuf, sizeof(char), (size_t)outbufsize, htmlfile); fclose(htmlfile); } #endif FREE((void *)inbuf); FreeOutputBuffer((void *)outbuf); return (void *)0; }
/* * HTTP headers looked OK, and we were able to determine what type of * distiller was needed, so go ahead and do the distillation, returning * the results to the client. If distillation fails, return the * original content and headers to the client. * * ARGS: * i: URL (BUG::shouldn't be needed - it's currently used to * determine distiller type for "aggregator" virtual-site URLs ) * i: input to distiller (from previous "pipestage" or from server) * o: output from distiller * o: distiller type descriptor * i: argument list for distiller * * RETURNS: Distiller status for the distillation * REENTRANT: yes * SIDE EFFECTS: * If distillation succeeds, fills in new headers (for return to client) * in DistillerOutput structure * ASSUMTPIONS: * None */ static DistillerStatus do_distillation(const char *url, DistillerInput *dinp, DistillerOutput *doutp, C_DistillerType *dtype, ArgumentList *al) { DistillerStatus result = distFatalError; Argument *arg; const char *whichuser = "******"; const char *mime; int mime_len; /* * HTTP headers look OK. Extract the MIME type, figure out what * distiller to use, and dispatch to it. */ if ((arg = getArgumentFromIdInList(al, FRONT_USERID))) { whichuser = ARG_STRING(*arg); } /* * If this is the set-prefs page, be sure the user's args get munged into it * REMOVED by fox since it interferes with the "mini-httpd" worker (miniserver.pl): * this routing is now enforced by X-Route instead */ if (0 && strcasecmp(url, fe_set_prefs_url) == 0) { SET_DISTILLER_TYPE(*dtype, "transend/text/html"); } else { set_distiller_type(&dinp->metadata, (const char *)url, whichuser, dtype); } if ((mime = get_header_value(&dinp->metadata, "content-type", &mime_len, NULL, NULL)) != NULL) { strncpy(dinp->mimeType, mime, MIN(mime_len,MAX_MIMETYPE-1)); dinp->mimeType[MIN(mime_len,MAX_MIMETYPE-1)] = '\0'; } else { strcpy(dinp->mimeType, "text/html"); } result = Distill(dtype, al->arg, al->nargs, dinp, doutp); return result; }
MultipleAlignment* Align(PDBChain **chains, int numChains, int displayStatus) { int i, j; int numAlignments = numChains; MultipleAlignment** alignments = (MultipleAlignment**) malloc(numAlignments * sizeof(MultipleAlignment*)); int numAlignedAlignments = numChains * (numChains-1)/2; MultipleAlignment** alignedAlignments = (MultipleAlignment**) malloc(numAlignedAlignments * sizeof(MultipleAlignment*)); double *pairScores; int numTotalAlignments = (numChains-1) * (numChains-1); int len = 1; int d = 10; MultipleAlignment *ma; /* Indices of chains used in pairwise alignments. Simplest way to divide up work * for the first pass. */ int *indices = (int*) malloc(sizeof(int) * 2 * numTotalAlignments); /* Used for output */ char progressTemplate[64]; int backspace2 = 0; int backspace = 0; /* Keeps track of which alignment we're on. For display only. */ int count = 0; int pass = 1; for (i=0; i<numChains; i++) { alignments[i] = CreateSingleStrandAlignment(Distill(chains[i], i)); } pairScores = (double*) malloc(sizeof(double) * numChains*numChains); while (numTotalAlignments >= d) { len ++; d*=10; } /* Structure pair list. Simplest way of breaking up first pass for threading */ for (i=0; i<numChains; i++) { for (j=0; j<i; j++) { indices[count*2] = i; indices[count*2+1] = j; count++; } } count = 0; if (displayStatus) { backspace2 = fprintf(stderr, "Pass %i, ", pass); } #ifndef _OPENMP { if (displayStatus) { sprintf(progressTemplate, "Single threaded [%%%ii/%i]", len, numTotalAlignments); DisplayProgress(&backspace, progressTemplate, count); } #else #pragma omp parallel default(shared) { #pragma omp single if (displayStatus) { int threads = omp_get_num_threads(); if (threads > 1) sprintf(progressTemplate, "%i threads [%%%ii/%i]", threads, len, numTotalAlignments); else sprintf(progressTemplate, "1 thread [%%%ii/%i]", len, numTotalAlignments); DisplayProgress(&backspace, progressTemplate, count); } #pragma omp for schedule(dynamic, 1) #endif for (i=0; i<numAlignedAlignments; i++) { alignedAlignments[i] = AlignAlignments(alignments[indices[i*2]], alignments[indices[i*2+1]], 0, 0, 0); pairScores[indices[i*2]*numChains + indices[i*2+1]] = pairScores[indices[i*2+1]*numChains + indices[i*2]] = alignedAlignments[i]->score; if (displayStatus) { #ifdef _OPENMP #pragma omp critical #endif DisplayProgress(&backspace, progressTemplate, ++count); } } } free(indices); pass++; while (numAlignedAlignments) { int best = 0; int index1, index2; for (i=1; i<numAlignedAlignments; i++) { if (alignedAlignments[i]->score > alignedAlignments[best]->score) { best = i; } } ma = alignedAlignments[best]; alignedAlignments[best] = alignedAlignments[--numAlignedAlignments]; /* Remove anything containing the elements of ma from both * sets of alignments. */ index1 = ma->chains[0]->id; index2 = ma->chains[ma->numChains-1]->id; for (i=numAlignedAlignments-1; i >= 0; i--) { for (j=0; j<alignedAlignments[i]->numChains; j++) { if (alignedAlignments[i]->chains[j]->id == index1 || alignedAlignments[i]->chains[j]->id == index2) { CleanupAlignment(alignedAlignments[i]); alignedAlignments[i] = alignedAlignments[--numAlignedAlignments]; break; } } } for (i=numAlignments-1; i >= 0; i--) { for (j=0; j<alignments[i]->numChains; j++) { if (alignments[i]->chains[j]->id == index1 || alignments[i]->chains[j]->id == index2) { CleanupAlignment(alignments[i]); alignments[i] = alignments[--numAlignments]; break; } } } if (displayStatus) { backspace2 += backspace; backspace = 0; DisplayProgress(&backspace2, "Pass %i, ", pass++); DisplayProgress(&backspace, progressTemplate, count); } #ifdef _OPENMP #pragma omp parallel for default(shared) schedule(dynamic, 1) #endif /* Run all the new alignments and add ma to the list of alignments I've kept. */ for (i=numAlignments-1; i >= 0; i--) { double bestScore = 0; int best1=0, best2=0; /* Need private (thread) variables. */ int j, k; for (j=0; j<alignments[i]->numChains; j++) { for (k=0; k<ma->numChains; k++) { double score = pairScores[ma->chains[k]->id * numChains + alignments[i]->chains[j]->id]; if (score > bestScore) { bestScore = score; best1 = j; best2 = k; } } } alignedAlignments[numAlignedAlignments+i] = AlignAlignments(alignments[i], ma, best1, best2, 0); if (displayStatus) { #ifdef _OPENMP #pragma omp critical #endif DisplayProgress(&backspace, progressTemplate, ++count); } } numAlignedAlignments += numAlignments; alignments[numAlignments++] = ma; } free(pairScores); /* The only alignment left. */ ma = alignments[0]; free(alignments); free(alignedAlignments); return ma; }
void * http_go_proc(task_t *t) { int sock = (int)(TASK_DATA(t)); C_DistillerType type; Argument ar; userpref u; userkey uk; FILE *htmlfile; char filename[80]; size_t inbufsize; UINT32 outbufsize; DistillerStatus status; ssize_t filenamelen; char inbuf[64000]; char *outbuf; SET_DISTILLER_TYPE(type, "text/html"); SET_ARG_ID(ar, 1); SET_ARG_STRING(ar, "foobar"); /* read filename from the socket */ filenamelen = 0; while (filenamelen < 80) { filenamelen += read(sock, (void *)(filename+filenamelen), 1); if ((filename[filenamelen-1] == '\n') || (filename[filenamelen-1] == '\r')) break; } filename[filenamelen-1] = '\0'; proxy_debug_3(DBG_HTTP, "Filename is <%s>", filename); assert(htmlfile = fopen(filename, "r")); inbufsize = fread((void *)inbuf, sizeof(char), (size_t)64000, htmlfile); fclose(htmlfile); /* call html distiller */ status = Distill(&type, &ar, 1, (void *)inbuf, (UINT32)inbufsize, (void *)&outbuf, &outbufsize); proxy_debug_3(DBG_HTTP, "Distiller status = %d\n", (int)status); /* dump outbuf to a file */ if (status == distOk) { assert(htmlfile = fopen("/tmp/foo", "w")); fwrite((void *)outbuf, sizeof(char), (size_t)outbufsize, htmlfile); fclose(htmlfile); } /* get user preferences of this user, if possible. */ #if 0 uk = userkey_from_sock_ipaddr(sock); u = get_userprefs(uk); fprintf(stderr, "User prefs bpp=%d\n", (int)(u->bpp)); #endif return (void *)0; }