Exemplo n.º 1
0
int read_cgi_input(JSContext *cx, llist* entries, const char *uploadDir)
{
  char *input;
  int status;

  if (!uploadDir)
  {
    uploadDir = getenv("CGI_UPLOADDIR");
    if (!uploadDir)
      uploadDir = getenv("TMPDIR");
    if (!uploadDir)
      uploadDir = "/tmp";
  }

  strncpy(UPLOADDIR, uploadDir, sizeof(UPLOADDIR));
  UPLOADDIR[sizeof(UPLOADDIR) - 1] = (char)0;

  /* check for form upload.  this needs to be first, because the
     standard way of checking for POST data is inadequate.  If you
     are uploading a 100 MB file, you are unlikely to have a buffer
     in memory large enough to store the raw data for parsing.
     Instead, parse_form_encoded parses stdin directly.

     In the future, I may modify parse_CGI_encoded so that it also
     parses POST directly from stdin.  I'm undecided on this issue,
     because doing so will make parse_CGI_encoded less general. */
  if ((CONTENT_TYPE != NULL) &&
      (strstr(CONTENT_TYPE,"multipart/form-data") != NULL) )
    return parse_form_encoded(entries);

  /* get the input */
  if (REQUEST_METHOD == NULL)
    input = get_DEBUG(cx);
  else if (!strcmp(REQUEST_METHOD,"POST"))
    input = get_POST(cx);
  else if (!strcmp(REQUEST_METHOD,"GET"))
    input = get_GET();
  else { /* error: invalid request method */
    gpsee_fprintf(cx, stderr, "caught by cgihtml: REQUEST_METHOD invalid\n");
    exit(1);
  }
  /* parse the input */
  if (input == NULL)
    return 0;
  status = parse_CGI_encoded(entries,input);
  free(input);
  return status;
}
Exemplo n.º 2
0
int read_cgi_input(llist* entries)
{
	char *input;
	int status;

	/* check for form upload.  this needs to be first, because the
	standard way of checking for POST data is inadequate.  If you
	are uploading a 100 MB file, you are unlikely to have a buffer
	in memory large enough to store the raw data for parsing.
	Instead, parse_form_encoded parses stdin directly.

	In the future, I may modify parse_CGI_encoded so that it also
	parses POST directly from stdin.  I'm undecided on this issue,
	because doing so will make parse_CGI_encoded less general. */
	if ((CONTENT_TYPE != NULL) &&
		(strstr(CONTENT_TYPE,"multipart/form-data") != NULL) )
		return parse_form_encoded(entries);

	/* get the input */
	if (REQUEST_METHOD == NULL)
		input = get_DEBUG();
	else if (!strcmp(REQUEST_METHOD,"POST"))
		input = get_POST();
	else if (!strcmp(REQUEST_METHOD,"GET"))
		input = get_GET();
	else { /* error: invalid request method */
		fprintf(stderr,"caught by cgihtml: REQUEST_METHOD invalid\n");
		exit(1);
	}
	/* parse the input */
	if (input == NULL)
		return 0;
	status = parse_CGI_encoded(entries,input);
	FREE(input);
	return status;
}