コード例 #1
0
ファイル: cgi.c プロジェクト: kfish/fastphoto
static int
cgi_send_photo (photo_t * photo)
{
  header_content_length (photo->size);
  header_end();

  photo_put (photo);

  return 0;
}
コード例 #2
0
ファイル: simple_api.c プロジェクト: Shield-Firewall/c-icap
int ci_http_request_url(ci_request_t * req, char *buf, int buf_size)
{
   ci_headers_list_t *heads;
   const char *str, *host;
   int i, bytes; 
   /*The request must have the form:
        GET url HTTP/X.X 
   */
    if (!(heads = ci_http_request_headers(req)))
          return 0;

    if (!heads->used)
        return 0;

    str = heads->headers[0];

    if ((str = strchr(str, ' ')) == NULL) { /*Ignore method i*/
          return 0;
     }
     while (*str == ' ') /*ignore spaces*/
          str++;

     bytes = 0;
     if (*str == '/' && (host = ci_headers_value(heads,"Host"))) {
         /*Looks like a transparent proxy, we do not know the protocol lets try
           to preserve the major part of the url....
          */
         for (i=0; (i < buf_size-1) && !header_end(host[i]) && !isspace(host[i]); i++) {
             buf[i] = host[i]; 
         }
         buf += i;
         buf_size -= i;
         bytes = i;
     }

     /*copy the url...*/
     for (i=0; (i < buf_size-1) && !header_end(str[i]) && !isspace(str[i]) && str[i] != '?'; i++) {
          buf[i] = str[i]; 
     }
     buf[i] = '\0';
     bytes += i;
     return bytes;
}
コード例 #3
0
ファイル: cgi.c プロジェクト: kfish/fastphoto
static int
cgi_send (fastphoto_t * params)
{
  header_last_modified (params->in.mtime);

  if (params->nochange) {
    cgi_send_photo (&params->in);
  } else if (params->out.name) {
    cgi_send_photo (&params->out);
  } else {
    header_content_length ((off_t)params->data_size);
    header_end();

    memory_send (params);
  }

  return 0;
}
コード例 #4
0
ファイル: cgi.c プロジェクト: kfish/fastphoto
int
cgi_main (fastphoto_t * params)
{
  int err = 0;
  char * path_info;
  char * path_translated;
  char * query_string;
  char * if_modified_since;
  time_t since_time;

  httpdate_init ();

  path_info = getenv ("PATH_INFO");
  path_translated = getenv ("PATH_TRANSLATED");
  query_string = getenv ("QUERY_STRING");
  if_modified_since = getenv ("HTTP_IF_MODIFIED_SINCE");

  photo_init (&params->in, path_translated);

  if (if_modified_since != NULL) {
    int len;

    fprintf (stderr, "If-Modified-Since: %s\n", if_modified_since);

    len = strlen (if_modified_since) + 1;
    since_time = httpdate_parse (if_modified_since, len);

    if (params->in.mtime <= since_time) {
      header_not_modified();
      header_end();
      return 1;
    }
  }

  header_content_type_jpeg ();

  config_init (params);

  parse_query (params, query_string);

  if (params->x || params->y || params->scale || params->gray ||
      params->quality) {
    cache_init (params, path_info);
  } else {
    params->nochange = 1;
  }

  err = 0;
  if (!(params->nochange || params->cached)) {
    err = resize (params);
  }
  
  if (!err) {
    cgi_send (params);
  }

  if (params->out.name) {
    free (params->out.name);
  }

  return err;
}
コード例 #5
0
ファイル: cgi.c プロジェクト: seermebe7/MobileMovieTexture
int
cgi_main (OCState * state)
{
    int err = 0;
    char * path_info;
    char * path_translated;
    char * query_string;
    char * if_modified_since;
    time_t since_time, last_time;
    struct stat statbuf;
    int built_path_translated=0;

    httpdate_init ();

    path_info = getenv ("PATH_INFO");
    path_translated = getenv ("PATH_TRANSLATED");
    query_string = getenv ("QUERY_STRING");
    if_modified_since = getenv ("HTTP_IF_MODIFIED_SINCE");

    memset (state, 0, sizeof(*state));
    state->end = -1.0;
    state->do_skeleton = 1;

    if (path_translated == NULL) {
        if (path_info == NULL)
            return path_undefined ("PATH_TRANSLATED and PATH_INFO");

        path_translated = prepend_document_root (path_info);
        if (path_translated == NULL)
            return path_undefined ("PATH_TRANSLATED");

        built_path_translated = 1;
    }

    state->infilename = path_translated;

    /* Get Last-Modified time */
    if (stat (path_translated, &statbuf) == -1) {
        switch (errno) {
        case ENOENT:
            return 0;
        default:
            fprintf (stderr, "oggz-chop: %s: %s\n", path_translated, strerror(errno));
            return -1;
        }
    }

    last_time = statbuf.st_mtime;

    if (if_modified_since != NULL) {
        int len;

        fprintf (stderr, "If-Modified-Since: %s\n", if_modified_since);

        len = strlen (if_modified_since) + 1;
        since_time = httpdate_parse (if_modified_since, len);

        if (last_time <= since_time) {
            header_not_modified();
            header_end();
            return 1;
        }
    }

    header_content_type_ogg ();

    header_last_modified (last_time);

    header_accept_timeuri_ogg ();

    parse_query (state, query_string);

    header_end();

    err = 0;
    err = chop (state);

    if (built_path_translated && path_translated != NULL)
        free (path_translated);

    return err;
}