Beispiel #1
0
static struct hthead *parseresp(FILE *in)
{
    struct hthead *resp;
    char *st, *p;
    
    omalloc(resp);
    resp->ver = sstrdup("HTTP/1.1");
    if(parseheaders(resp, in)) {
	freehthead(resp);
	return(NULL);
    }
    if((st = getheader(resp, "Status")) != NULL) {
	if((p = strchr(st, ' ')) != NULL) {
	    *(p++) = 0;
	    resp->code = atoi(st);
	    resp->msg = sstrdup(p);
	} else {
	    resp->code = atoi(st);
	    resp->msg = sstrdup(httpdefstatus(resp->code));
	}
	headrmheader(resp, "Status");
    } else if(getheader(resp, "Location")) {
	resp->code = 303;
	resp->msg = sstrdup("See Other");
    } else {
	resp->code = 200;
	resp->msg = sstrdup("OK");
    }
    return(resp);
}
Beispiel #2
0
// OK, we've now got all the headers read in, so we're ready to start
// on the body. But we need to see what info we can glean from the headers
// first...
void Response::BeginBody()
{

	m_Chunked = false;
	m_Length = -1;	// unknown
	m_WillClose = false;

	// using chunked encoding?
	const char* trenc = getheader( "transfer-encoding" );
	if( trenc && 0==_stricmp( trenc, "chunked") )
	{
		m_Chunked = true;
		m_ChunkLeft = -1;	// unknown
	}

	m_WillClose = CheckClose();

	// length supplied?
	const char* contentlen = getheader( "content-length" );
	if( contentlen && !m_Chunked )
	{
		m_Length = atoi( contentlen );
	}

	// check for various cases where we expect zero-length body
	if( m_Status == NO_CONTENT ||
		m_Status == NOT_MODIFIED ||
		( m_Status >= 100 && m_Status < 200 ) ||		// 1xx codes have no body
		m_Method == "HEAD" )
	{
		m_Length = 0;
	}


	// if we're not using chunked mode, and no length has been specified,
	// assume connection will close at end.
	if( !m_WillClose && !m_Chunked && m_Length == -1 )
		m_WillClose = true;



	// Invoke the user callback, if any
	if( m_Connection.m_ResponseBeginCB )
		(m_Connection.m_ResponseBeginCB)( this, m_Connection.m_UserData );

/*
	printf("---------BeginBody()--------\n");
	printf("Length: %d\n", m_Length );
	printf("WillClose: %d\n", (int)m_WillClose );
	printf("Chunked: %d\n", (int)m_Chunked );
	printf("ChunkLeft: %d\n", (int)m_ChunkLeft );
	printf("----------------------------\n");
*/
	// now start reading body data!
	if( m_Chunked )
		m_State = CHUNKLEN;
	else
		m_State = BODY;
}
Beispiel #3
0
int main (int    argc,
	  char** argv)
/* ------------------------------------------------------------------------- *
 * Driver routine.
 * ------------------------------------------------------------------------- */
{
  FILE *avgfile = 0, *fldfile = 0;
  Dump *heada   = 0, *headf   = 0;
  int  i, npts, ntot;

  getargs (argc, argv, &avgfile, &fldfile);

  /* -- Read in the average file. */

  if (fldfile) {		 /* -- Remove averages from fldfile. */
    heada = (Dump*) calloc (1, sizeof (Dump));
    headf = (Dump*) calloc (1, sizeof (Dump));

    getheader (avgfile, heada);
    getheader (fldfile, headf);

    if (heada -> np  != headf -> np  ||
	heada -> nz  != headf -> nz  ||
	heada -> nel != headf -> nel)
      message (prog, "structure of files don't match",           ERROR);

    for (i = 0; i < strlen(headf -> field); i++)
      if (!strchr (heada -> field, headf -> field[i]))
      message (prog, "average fields don't match dumped fields", ERROR);

    getdata   (avgfile, heada);
    getdata   (fldfile, headf);
    demean    (heada,   headf);
    printup   (stdout,  headf);

  } else {			 /* -- Reynolds stresses using avgfile. */
    heada = (Dump*) calloc (1, sizeof (Dump));

    getheader (avgfile, heada);
    chknames  (heada -> field);
    getdata   (avgfile, heada);
    covary    (heada);
    printup   (stdout, heada);
  }
    
  /* -- Printup. */

  return (EXIT_SUCCESS);
}
Beispiel #4
0
static int
httpheaders(HttpState *hs)
{
	char buf[2048];
	char *p;
	int i, n;

	for(;;){
		n = getheader(hs, buf, sizeof(buf));
		if(n < 0)
			return -1;
		if(n == 0)
			return 0;
		//	print("http header: '%.*s'\n", n, buf);
		for(i = 0; i < nelem(hdrtab); i++){
			n = strlen(hdrtab[i].name);
			if(cistrncmp(buf, hdrtab[i].name, n) == 0){
				/* skip field name and leading white */
				p = buf + n;
				while(*p == ' ' || *p == '\t')
					p++;
				(*hdrtab[i].fn)(hs, p);
				break;
			}
		}
	}
}
/* Load header to obtain/check data type and number of columns */
char *
cm_getheader(int *dt, int *nr, int *nc, FILE *fp)
{
	CMINFO	cmi;
						/* read header */
	cmi.dtype = DTfromHeader;
	cmi.nrows = cmi.ncols = 0;
	cmi.err = "unexpected EOF in header";
	if (getheader(fp, get_cminfo, &cmi) < 0)
		return(cmi.err);
	if (dt != NULL) {			/* get/check data type? */
		if (cmi.dtype == DTfromHeader) {
			if (*dt == DTfromHeader)
				return("missing/unknown data format in header");
		} else if (*dt == DTfromHeader)
			*dt = cmi.dtype;
		else if (*dt != cmi.dtype)
			return("unexpected data format in header");
	}
	if (nr != NULL) {			/* get/check #rows? */
		if (*nr <= 0)
			*nr = cmi.nrows;
		else if ((cmi.nrows > 0) & (*nr != cmi.nrows))
			return("unexpected row count in header");
	}
	if (nc != NULL) {			/* get/check #columns? */
		if (*nc <= 0)
			*nc = cmi.ncols;
		else if ((cmi.ncols > 0) & (*nc != cmi.ncols))
			return("unexpected column count in header");
	}
	return(NULL);
}
static void
getdim(				/* get dimensions from file */
	FILE  *fp
)
{
	int  j;
	int  c;

	getheader(fp, NULL, NULL);	/* skip header */

	switch (c = getc(fp)) {
	case '+':		/* picture */
	case '-':
		do
			putchar(c);
		while (c != '\n' && (c = getc(fp)) != EOF);
		break;
	case 1:			/* octree */
		getc(fp);
		j = 0;
		while ((c = getc(fp)) != EOF)
			if (c == 0) {
				if (++j >= 4)
					break;
				putchar(' ');
			} else {
				putchar(c);
			}
		putchar('\n');
		break;
	default:		/* ??? */
		fputs("unknown file type\n", stdout);
		break;
	}
}
Beispiel #7
0
t_cli		handle_ls(t_cli cli, t_env env, char *cmd)
{
	char			buf[PATH_MAX];
	int				id;

	buf[0] = '\0';
	if (!(cli = cli.fct_connect(cli, env, NULL)).istransferable)
		return (cli);
	send_request("LIST", cmd, cli.sock.pi.fdin);
	cli.sock.pi = ft_stream_get_protocol(cli.sock.pi, buf, PATH_MAX, PROT);
	id = getheader(buf);
	if (protocol(buf) && (id == 125 || id == 150))
	{
		cli.sock.dtp = set_dtp_stdout(cli, env);
		if ((fork() == 0))
		{
			send_sock_to_fd_crlf(cli.sock.dtp.fdin, STDOUT, PROT, CRLF);
			exit(0);
		}
		wait(NULL);
		cli.sock.pi = ft_stream_get_protocol(cli.sock.pi, buf, PATH_MAX, PROT);
		is_success(protocol(buf));
		close(cli.sock.dtp.fdin);
	}
	else
		is_success(FALSE);
	return (cli);
}
Beispiel #8
0
int
viewfile(				/* get view from file */
char  *fname,
VIEW  *vp,
RESOLU  *rp
)
{
	struct myview	mvs;
	FILE  *fp;

	if (fname == NULL || !strcmp(fname, "-"))
		fp = stdin;
	else if ((fp = fopen(fname, "r")) == NULL)
		return(-1);

	mvs.hv = vp;
	mvs.ok = 0;

	getheader(fp, gethview, &mvs);

	if (rp != NULL && !fgetsresolu(rp, fp))
		mvs.ok = 0;

	fclose(fp);

	return(mvs.ok);
}
Beispiel #9
0
int
openholo(		/* open existing holodeck file for i/o */
	char	*fname,
	int	append
)
{
	FILE	*fp;
	int	fd;
	int	hflags = 0;
	off_t	nextloc;
	int	n;
					/* open holodeck file */
	if ((fp = fopen(fname, append ? "r+" : "r")) == NULL) {
		sprintf(errmsg, "cannot open \"%s\" for %s", fname,
				append ? "appending" : "reading");
		error(SYSTEM, errmsg);
	}
					/* check header and magic number */
	if (getheader(fp, holheadline, &hflags) < 0 ||
			hflags&H_BADF || getw(fp) != HOLOMAGIC) {
		sprintf(errmsg, "file \"%s\" not in holodeck format", fname);
		error(USER, errmsg);
	}
	fd = dup(fileno(fp));			/* dup file handle */
	nextloc = ftell(fp);			/* get stdio position */
	fclose(fp);				/* done with stdio */
	for (n = 0; nextloc > 0L; n++) {	/* initialize each section */
		lseek(fd, nextloc, SEEK_SET);
		read(fd, (char *)&nextloc, sizeof(nextloc));
		hdinit(fd, NULL)->priv = hflags&H_OBST ? &obstr :
				hflags&H_OBSF ? &unobstr : (char *)NULL;
	}
	return(n);
}
Beispiel #10
0
static void
getfovimg(void)			/* load foveal sampled image */
{
	char	combuf[PATH_MAX];
	FILE	*fp;
	int	x, y;
						/* compute image size */
	fvxr = sqrt(ourview.hn2)/FOVDIA + 0.5;
	if (fvxr < 2) fvxr = 2;
	fvyr = sqrt(ourview.vn2)/FOVDIA + 0.5;
	if (fvyr < 2) fvyr = 2;
	if (!(inpres.rt & YMAJOR)) {		/* picture is rotated? */
		y = fvyr;
		fvyr = fvxr;
		fvxr = y;
	}
	if ((fovimg = (COLOR *)malloc(fvxr*fvyr*sizeof(COLOR))) == NULL)
		syserror("malloc");
	sprintf(combuf, "pfilt -1 -b -pa 0 -x %d -y %d \"%s\"", fvxr, fvyr, infn);
	if ((fp = popen(combuf, "r")) == NULL)
		syserror("popen");
	getheader(fp, NULL, NULL);	/* skip header */
	if (fgetresolu(&x, &y, fp) < 0 || (x != fvxr) | (y != fvyr))
		goto readerr;
	for (y = 0; y < fvyr; y++)
		if (freadscan(fovscan(y), fvxr, fp) < 0)
			goto readerr;
	pclose(fp);
	return;
readerr:
	fprintf(stderr, "%s: error reading from pfilt process in fovimage\n",
			progname);
	exit(1);
}
Beispiel #11
0
extern int
checkheader(
	FILE  *fin,
	char  *fmt,
	FILE  *fout
)
{
	struct check	cdat;
	char	*cp;

	cdat.fp = fout;
	cdat.fs[0] = '\0';
	if (getheader(fin, mycheck, &cdat) < 0)
		return(-1);
	if (!cdat.fs[0])
		return(0);
	for (cp = fmt; *cp; cp++)		/* check for globbing */
		if ((*cp == '?') | (*cp == '*')) {
			if (globmatch(fmt, cdat.fs)) {
				strcpy(fmt, cdat.fs);
				return(1);
			} else
				return(-1);
		}
	return(strcmp(fmt, cdat.fs) ? -1 : 1);	/* literal match */
}
Beispiel #12
0
static int hasheader(struct hthead *head, char *name, char *val)
{
    char *hd;
    
    if((hd = getheader(head, name)) == NULL)
	return(0);
    return(!strcasecmp(hd, val));
}
Beispiel #13
0
		~RequestLogger()
		{
			x0::Buffer sstr;
			sstr << hostname(in_);
			sstr << " - "; // identity as of identd
			sstr << username(in_) << ' ';
			sstr << in_->connection.worker().now().htlog_str().c_str() << " \"";
			sstr << request_line(in_) << "\" ";
			sstr << static_cast<int>(in_->status) << ' ';
			sstr << in_->bytesTransmitted() << ' ';
			sstr << '"' << getheader(in_, "Referer") << "\" ";
			sstr << '"' << getheader(in_, "User-Agent") << '"';
			sstr << '\n';

			if (log_->write(sstr.c_str(), sstr.size()) < static_cast<ssize_t>(sstr.size())) {
				in_->log(x0::Severity::error, "Could not write to accesslog target. %s", strerror(errno));
			}
		}
static void
picdebug(void)			/* put out debugging picture */
{
	static COLOR	blkcol = BLKCOLOR;
	COLOR	*scan;
	int	y, i;
	register int	x, rg;

	if (fseek(stdin, 0L, 0) == EOF) {
		fprintf(stderr, "%s: cannot seek on input picture\n", progname);
		exit(1);
	}
	getheader(stdin, NULL, NULL);		/* skip input header */
	fgetresolu(&xmax, &ymax, stdin);
						/* allocate scanline */
	scan = (COLOR *)malloc(xmax*sizeof(COLOR));
	if (scan == NULL) {
		perror(progname);
		exit(1);
	}
						/* finish debug header */
	fputformat(COLRFMT, debugfp);
	putc('\n', debugfp);
	fprtresolu(xmax, ymax, debugfp);
						/* write debug picture */
	for (y = ymax-1; y >= 0; y--) {
		if (freadscan(scan, xmax, stdin) < 0) {
			fprintf(stderr, "%s: error rereading input picture\n",
					progname);
			exit(1);
		}
		for (x = 0; x < xmax; x++) {
			rg = chartndx(x, y, &i);
			if (rg == RG_CENT) {
				if (!(1L<<i & gmtflags) || (x+y)&07) {
					copycolor(scan[x], mbRGB[i]);
					clipgamut(scan[x], bright(scan[x]),
						CGAMUT, colmin, colmax);
				} else
					copycolor(scan[x], blkcol);
			} else if (rg == RG_CORR)
				cvtcolor(scan[x], scan[x]);
			else if (rg != RG_ORIG)
				copycolor(scan[x], blkcol);
		}
		if (fwritescan(scan, xmax, debugfp) < 0) {
			fprintf(stderr, "%s: error writing debugging picture\n",
					progname);
			exit(1);
		}
	}
						/* clean up */
	fclose(debugfp);
	free((void *)scan);
}
Beispiel #15
0
		~RequestLogger()
		{
			x0::Buffer sstr;
			sstr << hostname(in_);
			sstr << " - "; // identity as of identd
			sstr << username(in_) << ' ';
			sstr << in_->connection.worker().now().htlog_str().c_str() << " \"";
			sstr << request_line(in_) << "\" ";
			sstr << static_cast<int>(in_->status) << ' ';
			sstr << in_->bytesTransmitted() << ' ';
			sstr << '"' << getheader(in_, "Referer") << "\" ";
			sstr << '"' << getheader(in_, "User-Agent") << '"';
			sstr << '\n';

			int rv = ::write(fd_, sstr.data(), sstr.size());

			if (rv < 0) {
				perror("accesslog.write");
			}
		}
Beispiel #16
0
void logmsg(eLogLevel level, std::string s)
{
   if (level < getMinLevel())
      return;

   std::string info = getheader(level);
   std::string s2=utils::replacestring(s,"\n","\n"+info);
   //boost::erase_all(s2, "\r");
   s2.erase(std::remove(s2.begin(), s2.end(), '\r'), s2.end());

   logverbatim(level,info+s2+"\n");
}
Beispiel #17
0
void handle_input(char * url, char * input){
	vector * vec = str_split(input, " ");
	CURL * curl;
	char *com, *path;
	char *data = NULL;
	upload_buffer upbuf;
	
	int perform = 1;
	
	if(vec->length < 2){
		destroy_vector(vec);
		return;
	}
	
	/* init some stuff */
	curl = curl_easy_init();
	com = vector_get(vec, 0);
	str_lower(com);
	
	/* handle specific request types */
	if(strcmp(com, "get")==0){
		prepare_get(curl);
	} else if(strcmp(com, "post")==0){
		data = prepare_post(curl);
	} else if (strcmp(com, "head")==0){
		prepare_head(curl);
	} else if (strcmp(com, "put")==0){
		data = prepare_put(curl, &upbuf);
	} else if(strcmp(com, "delete")==0) {
		prepare_delete(curl);
	} else if (strcmp(com, "setheader")==0){
		perform = 0;
		setheader(vec);
	} else if(strcmp(com, "getheader")==0){
		perform = 0;
		getheader(vec);
	} else if(strcmp(com, "delheader")==0){
		perform = 0;
		delheader(vec);
	} else perform = 0;
	
	if(perform){
		path = vector_get(vec, 1);
		perform_request(curl, url, path);
	}
	
	/* free data if needed */
	if(data != NULL)
		free(data);
	
	destroy_vector(vec);
	curl_easy_cleanup(curl);
}
Beispiel #18
0
// return true if we think server will automatically close connection
bool Response::CheckClose()
{
	if( m_Version == 11 )
	{
		// HTTP1.1
		// the connection stays open unless "connection: close" is specified.
		const char* conn = getheader( "connection" );
		if( conn && 0==_stricmp( conn, "close" ) )
			return true;
		else
			return false;
	}

	// Older HTTP
	// keep-alive header indicates persistant connection 
	if( getheader( "keep-alive" ) )
		return false;

	// TODO: some special case handling for Akamai and netscape maybe?
	// (see _check_close() in python httplib.py for details)

	return true;
}
Beispiel #19
0
__int64 JNL_HTTPGet::content_length()
{
  char *p=getheader("content-length:");
  if (!p) return 0;
  __int64 cl = myatoi64(p);
  if (cl > 0) return cl;

  // workaround for bug #1744091
  // some buggy apache servers return negative values for sizes
  // over 2gb - fix it for them
  if (cl < 0)
    return (__int64)((unsigned int)(cl));

  return 0;
}
Beispiel #20
0
int plurk_login(PLURK *ph, const char *username, const char *password)
{
	int rc;

	rc = plurk_request(ph, "/API/Users/login", IS_SSL, 3,
			"api_key", ph->apikey,
			"username", username,
			"password", password);
	if (rc)
		return rc;

	rc = getheader(ph->header, "set-cookie", ph->session);
	if (!rc)
		ph->sestate = 1;
	return rc;
}
static int
loadheader(			/* load an info. header into memory */
	FILE	*fp
)
{
	fmterr = 0; frameno = 0;
	if (headlen) {			/* free old header */
		free(headlines);
		headlen = 0;
	}
	if (getheader(fp, addhline, NULL) < 0)
		return(0);
	if (fmterr)
		return(-1);
	return(1);
}
Beispiel #22
0
/*
 * Toss one packet.
 *
 *  0  - 
 *  1  - Cannot open packet
 *  2  - Bad packet header
 *  3  - Packet is not for us
 *  4  - Bad password
 */
int TossPkt(char *fn)
{
	int		rc, count = 0; 
	static int	maxrc = 0;
	static faddr	from, to;
	FILE		*pkt;

	if (!do_quiet) {
		ftnd_colour(LIGHTGREEN, BLACK);
		printf("Tossing packet %s\n", fn);
	}

	if ((pkt = fopen(fn, "r")) == 0) {
		WriteError("$Cannot open %s", fn);
		return 1;
	}

	memset(&from, 0, sizeof(faddr));
	memset(&to,   0, sizeof(faddr));

	if (((rc = getheader(&from, &to, pkt, fn, FALSE)) != 0)) {
		WriteError("%s, aborting",
				(rc == 1)?"wrong header type":
				(rc == 2)?"bad packet header":
				(rc == 3)?"packet is not for us":
				(rc == 4)?"bad password":
				"******");
		fclose(pkt);
		return(rc);
	}

	while ((rc = getmessage(pkt, &from, &to)) == 1) {
		count++;
	}
	Syslog('+', "Messages : %d", count);

	maxrc = rc;
	if (!do_quiet)
		printf("\r                                                    \r");

	if (rc)
		Syslog('+', "End, rc=%d", maxrc);

	fclose(pkt);
	return maxrc;
}
Beispiel #23
0
static PICTURE *
openpicture(			/* open/check Radiance picture file */
	char	*fname
)
{
	FILE	*fp;
	register PICTURE	*pp;
	register char	*cp;
					/* check filename suffix */
	if (fname == NULL) return(NULL);
	for (cp = fname; *cp; cp++)
		;
	while (cp > fname && cp[-1] != '.')
		if (*--cp == '/') {
			cp = fname;
			break;
		}
	if (cp > fname && !strncmp(cp, "tif", 3))
		return(NULL);		/* assume it's a TIFF */
					/* else try opening it */
	if ((fp = fopen(fname, "r")) == NULL)
		return(NULL);
	SET_FILE_BINARY(fp);
					/* allocate struct */
	if ((pp = (PICTURE *)malloc(sizeof(PICTURE))) == NULL)
		return(NULL);		/* serious error -- should exit? */
	pp->fp = fp; pp->fmt[0] = '\0'; pp->pa = 1.;
					/* load header */
	if (getheader(fp, headline, pp) < 0) {
		closepicture(pp);
		return(NULL);
	}
	if (!pp->fmt[0])		/* assume RGBE if unspecified */
		strcpy(pp->fmt, COLRFMT);
	if (!globmatch(PICFMT, pp->fmt) || !fgetsresolu(&pp->rs, fp)) {
		closepicture(pp);	/* failed test -- close file */
		return(NULL);
	}
	rewind(fp);			/* passed test -- rewind file */
	return(pp);
}
Beispiel #24
0
int main(int argc, char *argv[]){

  extern char *progname;
  extern char *filename;
  
  FILE *fp;
  
  id3v2header *header;
  id3v2frame *frame;
  
  progname = argv[0];
  filename = argv[1];
  
  if(argc != 2){
    printf("Usage: %s filename\n", progname);
    exit(EXIT_FAILURE);
  }
  
  if((fp = fopen(filename, "r")) == NULL){
    perror(progname);
    exit(EXIT_FAILURE);
  }
  
  if((header = getheader(fp)) == NULL){
    fprintf(stderr, "%s error: not a valid MP3 file.\n", progname);
    exit(EXIT_FAILURE);
  }
  
  printheader(header);
  
  while(((frame = getframe(fp)) != NULL) && frame->body != NULL){
    printframe(frame, 1);
    free(frame->body);
    frame->body = NULL;
  }
  
  (void) fclose(fp);
  
  
  return 0;
}
Beispiel #25
0
static void
checkfile(void)			/* ready a file */
{
	register int	i;
					/* process header */
	gotview = 0;
	if (echoheader) {
		fputs(input[nfiles].name, stdout);
		fputs(":\n", stdout);
	}
	getheader(input[nfiles].fp, headline, NULL);
	if (wrongformat < 0) {
		eputs(input[nfiles].name);
		eputs(": not a Radiance picture\n");
		quit(1);
	}
	if (wrongformat > 0) {
		wputs(input[nfiles].name);
		wputs(": warning -- incompatible picture format\n");
	}
	if (!gotview || setview(&input[nfiles].vw) != NULL)
		input[nfiles].vw.type = 0;
	if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) {
		eputs(input[nfiles].name);
		eputs(": bad picture size\n");
		quit(1);
	}
	if (xmax == 0 && ymax == 0) {
		xmax = scanlen(&input[nfiles].rs);
		ymax = numscans(&input[nfiles].rs);
	} else if (scanlen(&input[nfiles].rs) != xmax ||
			numscans(&input[nfiles].rs) != ymax) {
		eputs(input[nfiles].name);
		eputs(": resolution mismatch\n");
		quit(1);
	}
					/* allocate scanlines */
	for (i = 0; i < WINSIZ; i++)
		input[nfiles].scan[i] = (COLOR *)emalloc(xmax*sizeof(COLOR));
}
Beispiel #26
0
static void
getahead(void)			/* load picture header */
{
	char	*err;

	getheader(infp, headline, NULL);
	if (lumf == NULL || !fgetsresolu(&inpres, infp)) {
		fprintf(stderr, "%s: %s: not a Radiance picture\n",
			progname, infn);
		exit(1);
	}
	if (lumf == rgblum)
		comprgb2xyzWBmat(inrgb2xyz, inprims);
	else if (mbcalfile != NULL) {
		fprintf(stderr, "%s: macbethcal only works with RGB pictures\n",
				progname);
		exit(1);
	}
	if (!gotview || ourview.type == VT_PAR ||
			(ourview.horiz <= 5.) | (ourview.vert <= 5.)) {
		ourview = stdview;
		ourview.type = VT_PER;
		if (pixaspect*inpres.yr < inpres.xr) {
			ourview.horiz = 40.0;
			ourview.vert = 2.*180./PI *
				atan(.3639702*pixaspect*inpres.yr/inpres.xr);
		} else {
			ourview.vert = 40.0;
			ourview.horiz = 2.*180./PI *
				atan(.3639702*inpres.xr/pixaspect/inpres.yr);
		}
	}
	if ((err = setview(&ourview)) != NULL) {
		fprintf(stderr, "%s: view error in picture \"%s\": %s\n",
			progname, infn, err);
		exit(1);
	}
}
Beispiel #27
0
void
copyin(register Archive_t* ap)
{
	register File_t*	f = &ap->file;

	deltabase(ap);
	while (getprologue(ap))
	{
		while (getheader(ap, f))
		{
			if (selectfile(ap, f))
				filein(ap, f);
			else
				fileskip(ap, f);
			if (ap->info)
				ap->info->checksum = ap->memsum;
			gettrailer(ap, f);
		}
		if (!getepilogue(ap))
			break;
	}
	deltaverify(ap);
}
Beispiel #28
0
static int canonreq(struct hthead *req)
{
    char *p, *p2, *r;
    int n;

    if(req->url[0] == '/') {
	replrest(req, req->url + 1);
	if((p = strchr(req->rest, '?')) != NULL)
	    *p = 0;
	return(1);
    }
    if((p = strstr(req->url, "://")) != NULL) {
	n = p - req->url;
	if(((n == 4) && !strncasecmp(req->url, "http", 4)) ||
	   ((n == 5) && !strncasecmp(req->url, "https", 5))) {
	    if(getheader(req, "host"))
		return(0);
	    p += 3;
	    if((p2 = strchr(p, '/')) == NULL) {
		headappheader(req, "Host", p);
		free(req->url);
		req->url = sstrdup("/");
	    } else {
		r = sstrdup(p2);
		*(p2++) = 0;
		headappheader(req, "Host", p);
		free(req->url);
		req->url = r;
	    }
	    replrest(req, req->url + 1);
	    if((p = strchr(req->rest, '?')) != NULL)
		*p = 0;
	    return(1);
	}
    }
    return(0);
}
Beispiel #29
0
int
main(
	int  argc,
	char  *argv[]
)
{
	int  ncolumns = 0;
	int  autolabel = 0;
	int  curcol = 0, x0 = 0, curx = 0, cury = 0, spacing = 0;
	int  xsgn, ysgn;
	char  *thislabel;
	int  an;
	SET_DEFAULT_BINARY();
	SET_FILE_BINARY(stdin);
	SET_FILE_BINARY(stdout);
	progname = argv[0];

	for (an = 1; an < argc && argv[an][0] == '-'; an++)
		switch (argv[an][1]) {
		case 'h':
			echoheader = !echoheader;
			break;
		case 'x':
			xsiz = atoi(argv[++an]);
			break;
		case 'y':
			ysiz = atoi(argv[++an]);
			break;
		case 'b':
			setcolr(bgcolr, atof(argv[an+1]),
					atof(argv[an+2]),
					atof(argv[an+3]));
			an += 3;
			break;
		case 'a':
			ncolumns = atoi(argv[++an]);
			break;
		case 's':
			spacing = atoi(argv[++an]);
			break;
		case 'o':
			curx = x0 = atoi(argv[++an]);
			cury = atoi(argv[++an]);
			break;
		case 'l':
			switch (argv[an][2]) {
			case 'a':
				autolabel++;
				break;
			case 'h':
				labelht = atoi(argv[++an]);
				break;
			case '\0':
				goto dofiles;
			default:
				goto userr;
			}
			break;
		case '\0':
		case 't':
			goto dofiles;
		default:
			goto userr;
		}
dofiles:
	newheader("RADIANCE", stdout);
	fputnow(stdout);
	for (nfile = 0; an < argc; nfile++) {
		if (nfile >= MAXFILE)
			goto toomany;
		thislabel = NULL;
		input[nfile].flags = 0;
		xsgn = ysgn = '-';
		while (an < argc && (argv[an][0] == '-' || argv[an][0] == '+'
				|| argv[an][0] == '=')) {
			switch (argv[an][1]) {
			case 't':
				checkthresh = 1;
				if (argv[an][0] == '-') {
					input[nfile].flags |= HASMIN;
					input[nfile].thmin = atof(argv[an+1]);
				} else if (argv[an][0] == '+') {
					input[nfile].flags |= HASMAX;
					input[nfile].thmax = atof(argv[an+1]);
				} else
					goto userr;
				an++;
				break;
			case 'l':
				if (strcmp(argv[an], "-l"))
					goto userr;
				thislabel = argv[++an];
				break;
			case '+':
			case '-':
			case '0':
				if (argv[an][0] != '=')
					goto userr;
				xsgn = argv[an][1];
				ysgn = argv[an][2];
				if (ysgn != '+' && ysgn != '-' && ysgn != '0')
					goto userr;
				break;
			case '\0':
				if (argv[an][0] == '-')
					goto getfile;
				goto userr;
			default:
				goto userr;
			}
			an++;
		}
getfile:
		if (argc-an < (ncolumns ? 1 : 3))
			goto userr;
		if (autolabel && thislabel == NULL)
			thislabel = argv[an];
		if (!strcmp(argv[an], "-")) {
			input[nfile].name = StandardInput;
			input[nfile].fp = stdin;
		} else {
			if (argv[an][0] == '!') {
				input[nfile].name = Command;
				input[nfile].fp = popen(argv[an]+1, "r");
			} else {
				input[nfile].name = argv[an];
				input[nfile].fp = fopen(argv[an], "r");
			}
			if (input[nfile].fp == NULL) {
				perror(argv[an]);
				quit(1);
			}
		}
		an++;
						/* get header */
		if (echoheader)
			printf("%s:\n", input[nfile].name);
		getheader(input[nfile].fp, headline, NULL);
		if (wrongformat) {
			fprintf(stderr, "%s: incompatible input format\n",
					input[nfile].name);
			quit(1);
		}
						/* get picture size */
		if (fgetresolu(&input[nfile].xres, &input[nfile].yres,
				input[nfile].fp) < 0) {
			fprintf(stderr, "%s: bad picture size\n",
					input[nfile].name);
			quit(1);
		}
		if (ncolumns > 0) {
			if (curcol >= ncolumns) {
				cury = ymax + spacing;
				curx = x0;
				curcol = 0;
			}
			input[nfile].xloc = curx;
			input[nfile].yloc = cury;
			curx += input[nfile].xres + spacing;
			curcol++;
		} else {
			input[nfile].xloc = atoi(argv[an++]);
			if (xsgn == '+')
				input[nfile].xloc -= input[nfile].xres;
			else if (xsgn == '0')
				input[nfile].xloc -= input[nfile].xres/2;
			input[nfile].yloc = atoi(argv[an++]);
			if (ysgn == '+')
				input[nfile].yloc -= input[nfile].yres;
			else if (ysgn == '0')
				input[nfile].yloc -= input[nfile].yres/2;
		}
		if (input[nfile].xloc < xmin)
			xmin = input[nfile].xloc;
		if (input[nfile].yloc < ymin)
			ymin = input[nfile].yloc;
		if (input[nfile].xloc+input[nfile].xres > xmax)
			xmax = input[nfile].xloc+input[nfile].xres;
		if (input[nfile].yloc+input[nfile].yres > ymax)
			ymax = input[nfile].yloc+input[nfile].yres;
		if (thislabel != NULL) {
			if (++nfile >= MAXFILE)
				goto toomany;
			input[nfile].name = Label;
			input[nfile].flags = 0;
			input[nfile].xres = input[nfile-1].xres;
			input[nfile].yres = labelht;
			if ((input[nfile].fp = lblopen(thislabel,
					&input[nfile].xres,
					&input[nfile].yres)) == NULL)
				goto labelerr;
			input[nfile].xloc = input[nfile-1].xloc;
			input[nfile].yloc = input[nfile-1].yloc +
					input[nfile-1].yres-input[nfile].yres;
		}
	}
	if (xsiz <= 0)
		xsiz = xmax;
	else if (xsiz > xmax)
		xmax = xsiz;
	if (ysiz <= 0)
		ysiz = ymax;
	else if (ysiz > ymax)
		ymax = ysiz;
					/* add new header info. */
	printargs(argc, argv, stdout);
	if (strcmp(ourfmt, PICFMT))
		fputformat(ourfmt, stdout);	/* print format if known */
	putchar('\n');
	fprtresolu(xsiz, ysiz, stdout);

	compos();
	
	quit(0);
userr:
	fprintf(stderr,
	"Usage: %s [-h][-x xr][-y yr][-b r g b][-a n][-s p][-o x0 y0][-la][-lh h] ",
			progname);
	fprintf(stderr, "[-t min1][+t max1][-l lab][=SS] pic1 x1 y1 ..\n");
	quit(1);
toomany:
	fprintf(stderr, "%s: only %d files and labels allowed\n",
			progname, MAXFILE);
	quit(1);
labelerr:
	fprintf(stderr, "%s: error opening label\n", progname);
	quit(1);
	return 1; /* pro forma return */
}
Beispiel #30
0
/* Load matrix from supported file type */
RMATRIX *
rmx_load(const char *fname)
{
	FILE		*fp = stdin;
	RMATRIX		dinfo;
	RMATRIX		*dnew;

	if (fname == NULL) {			/* reading from stdin? */
		fname = "<stdin>";
#ifdef _WIN32
		_setmode(fileno(stdin), _O_BINARY);
#endif
	} else {
		const char	*sp = fname;	/* check suffix */
		while (*sp)
			++sp;
		while (sp > fname && sp[-1] != '.')
			--sp;
		if (!strcasecmp(sp, "XML")) {	/* assume it's a BSDF */
			CMATRIX	*cm = cm_loadBTDF((char *)fname);
			if (cm == NULL)
				return(NULL);
			dnew = rmx_from_cmatrix(cm);
			cm_free(cm);
			return(dnew);
		}
						/* else open it ourselves */
		if ((fp = fopen(fname, "rb")) == NULL)
			return(NULL);
	}
#ifdef getc_unlocked
	flockfile(fp);
#endif
	dinfo.nrows = dinfo.ncols = dinfo.ncomp = 0;
	dinfo.dtype = DTascii;			/* assumed w/o FORMAT */
	dinfo.info = NULL;
	if (getheader(fp, get_dminfo, &dinfo) < 0) {
		fclose(fp);
		return(NULL);
	}
	if ((dinfo.nrows <= 0) | (dinfo.ncols <= 0)) {
		if (!fscnresolu(&dinfo.ncols, &dinfo.nrows, fp)) {
			fclose(fp);
			return(NULL);
		}
		if (dinfo.ncomp <= 0)
			dinfo.ncomp = 3;
		else if ((dinfo.dtype == DTrgbe) | (dinfo.dtype == DTxyze) &&
				dinfo.ncomp != 3) {
			fclose(fp);
			return(NULL);
		}
	}
	dnew = rmx_alloc(dinfo.nrows, dinfo.ncols, dinfo.ncomp);
	if (dnew == NULL) {
		fclose(fp);
		return(NULL);
	}
	dnew->info = dinfo.info;
	switch (dinfo.dtype) {
	case DTascii:
		if (!rmx_load_ascii(dnew, fp))
			goto loaderr;
		dnew->dtype = DTascii;		/* should leave double? */
		break;
	case DTfloat:
		if (!rmx_load_float(dnew, fp))
			goto loaderr;
		dnew->dtype = DTfloat;
		break;
	case DTdouble:
		if (!rmx_load_double(dnew, fp))
			goto loaderr;
		dnew->dtype = DTdouble;
		break;
	case DTrgbe:
	case DTxyze:
		if (!rmx_load_rgbe(dnew, fp))
			goto loaderr;
		dnew->dtype = dinfo.dtype;
		break;
	default:
		goto loaderr;
	}
	if (fp != stdin)
		fclose(fp);
	return(dnew);
loaderr:					/* should report error? */
	fclose(fp);
	rmx_free(dnew);
	return(NULL);
}