예제 #1
0
파일: mod_psgi.c 프로젝트: mattn/mod_psgi
static int output_body_sendfile(request_rec *r, const char *path)
{
    apr_file_t *fd;
    apr_status_t status;
    apr_size_t len, nbytes;
    apr_finfo_t finfo;
    int rc;

    status = apr_file_open(&fd, path, APR_READ|APR_BINARY, APR_OS_DEFAULT, r->pool);
    if (status != APR_SUCCESS) {
        return HTTP_INTERNAL_SERVER_ERROR;
    }

    apr_file_info_get(&finfo, APR_FINFO_NORM, fd);
    len = finfo.size;

    status = ap_send_fd(fd, r, 0, len, &nbytes);
    apr_file_close(fd);

    if (status == APR_SUCCESS) {
        ap_set_content_length(r, nbytes);
        rc = OK;
    } else {
        rc = HTTP_INTERNAL_SERVER_ERROR;
    }

    return rc;
}
예제 #2
0
파일: mod_twms.c 프로젝트: nasajpl/tiledwms
static int twms_handler(request_rec *r)

{
  twms_dir_conf *dcfg;
  const char *data;
  const char *val;
  apr_table_t *tab;
  apr_file_t *fh;
  apr_size_t nsend;
  apr_finfo_t info;


  if ((r->method_number != M_GET )||(r->args==0)) return DECLINED;
  data=r->args;
  // scfg=ap_get_module_config(r->server->module_config,&twms_module);
  dcfg=ap_get_module_config(r->per_dir_config,&twms_module);
  if (!dcfg) return DECLINED; // Does this ever happen?

  if (!ap_strstr(data,"GetTileService")) return DECLINED;
  // Do we have a config for this directory

//  ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"TWMS_handler: args %s, path %s scfg %x dcfg %x dir %s conf %s",
//    data,r->parsed_uri.path,scfg,dcfg,dcfg->path,dcfg->Config);
  if (!dcfg->Config) return DECLINED;


  // This is overkill here, but it works
  tab=apr_table_make(r->pool,0);

  while (*data && (val=ap_getword(r->pool, &data, '&'))) {
    char *key=apr_pstrdup(r->pool,ap_getword(r->pool, &val, '='));
    char *ival=apr_pstrdup(r->pool,val);
    ap_unescape_url(key);ap_unescape_url(ival);
    apr_table_merge(tab,key,ival);
  }

  if (!(val=apr_table_get(tab,"request"))) return DECLINED;
  if (apr_strnatcmp(val,"GetTileService")) return DECLINED;

  if (APR_SUCCESS!=apr_file_open(&fh,apr_pstrcat(r->pool,dcfg->path,dcfg->Config,0),
      APR_READ,APR_OS_DEFAULT,r->pool)) {
    ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"TWMS file can't be read");
    return HTTP_CONFLICT;
  }
  ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"TWMS Sending GTS file");
  apr_file_info_get(&info,APR_FINFO_SIZE,fh);

  ap_set_content_type(r,"text/xml");
  ap_send_fd(fh,r,0,info.size,&nsend);

  apr_file_close(fh);
  return OK;
}
예제 #3
0
파일: mod_mbox.c 프로젝트: mpercy/mod_mbox
// sendfile() the given filename to the remote.
// TODO: Add support for caching the fd instead of opening it every time.
apr_status_t mbox_send_include_file(request_rec *r, const char* include_fname) {
    const char *include_fname_abs = resolve_rel_path(r, include_fname);
    apr_file_t* file = NULL;
    apr_finfo_t finfo;
    LOG_RETURN_NOT_SUCCESS(open_for_sendfile(r, include_fname_abs,
                                              &file, &finfo),
                            APLOG_WARNING, r,
                            "open_for_sendfile", include_fname_abs);
    apr_size_t bytes_sent = 0;
    LOG_RETURN_NOT_SUCCESS(ap_send_fd(file, r, 0, finfo.size, &bytes_sent),
                            APLOG_WARNING, r,
                            "ap_send_fd", finfo.name);
    return apr_file_close(file);
}
예제 #4
0
static int asis_handler(request_rec *r)
{
    FILE *f;
    const char *location;

    r->allowed |= (1 << M_GET);
    if (r->method_number != M_GET)
	return DECLINED;
    if (r->finfo.st_mode == 0) {
	ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r,
		    "File does not exist: %s", r->filename);
	return NOT_FOUND;
    }

    f = ap_pfopen(r->pool, r->filename, "r");

    if (f == NULL) {
	ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
		    "file permissions deny server access: %s", r->filename);
	return FORBIDDEN;
    }

    ap_scan_script_header_err(r, f, NULL);
    location = ap_table_get(r->headers_out, "Location");

    if (location && location[0] == '/' &&
	((r->status == HTTP_OK) || ap_is_HTTP_REDIRECT(r->status))) {

	ap_pfclose(r->pool, f);

	/* Internal redirect -- fake-up a pseudo-request */
	r->status = HTTP_OK;

	/* This redirect needs to be a GET no matter what the original
	 * method was.
	 */
	r->method = ap_pstrdup(r->pool, "GET");
	r->method_number = M_GET;

	ap_internal_redirect_handler(location, r);
	return OK;
    }

    ap_send_http_header(r);
    if (!r->header_only)
	ap_send_fd(f, r);

    ap_pfclose(r->pool, f);
    return OK;
}
예제 #5
0
static int read_response(request_rec* r, char* res_id)
{
	apr_file_t* fd;
	apr_status_t rv = 0;
	apr_size_t bytes_sent;
	apr_finfo_t fi;
	char res_fn[256];
	const char *res_content;
	const char *res_status;
	int rc = 0;
	
	/***** For Http Header ******/
	rc = GetHttpHeader(res_id, "Content-type", &res_content);
	if(rc == DSO_NO_MATCH) {// in case without maching key
		//true = success, false = failure
		res_content = "text/xml";
	}
 	if (rc == EXIT_FAILURE) {
		ap_log_error(APLOG_MARK, APLOG_EMERG, rv, NULL, 
			"*** mod_err *** : GetHttpHeader(res_id)");
		return HTTP_INTERNAL_SERVER_ERROR;
	}
	r->content_type = (char *) apr_pstrdup(r->pool, res_content);

#ifdef DEBUG
	ap_log_error(APLOG_MARK, APLOG_NOTICE, rv, NULL, 
		"*** mod *** : GetHttpHeader header = %s", res_content);
#endif

	rc = GetHttpHeader(res_id, "status", &res_status);
	if(rc == DSO_NO_MATCH) {// in the case without maching key
		res_status = "200";
	}
 	if (rc == EXIT_FAILURE) {
		ap_log_error(APLOG_MARK, APLOG_EMERG, rv, NULL, 
			"*** mod_err *** : GetHttpHeader(req_id)");
		return HTTP_INTERNAL_SERVER_ERROR;
	}		
		
	r->status = atoi(res_status);

#ifdef DEBUG
	ap_log_error(APLOG_MARK, APLOG_NOTICE, rv, NULL, 
		"*** mod *** : GetHttpHeader header = %s", res_status);
#endif

	/***** For Http Body ******/
	rc = GetFileName(res_id, res_fn);
 	if (rc == EXIT_FAILURE) {
		ap_log_error(APLOG_MARK, APLOG_EMERG, rv, NULL, 
			"*** mod_err *** : GetFileName(res_id)");
		return HTTP_INTERNAL_SERVER_ERROR;
	}		

#ifdef DEBUG
	ap_log_error(APLOG_MARK, APLOG_NOTICE, rv, NULL,
		"*** mod *** : GetFileName res_fn = %s", res_fn);
#endif

	rv = apr_file_open(&fd, res_fn, APR_READ, -1, r->pool);
	if (rv != APR_SUCCESS) {
		ap_log_error(APLOG_MARK, APLOG_EMERG, rv, NULL, 
			"*** mod_err *** : apr_file_open");
		return HTTP_INTERNAL_SERVER_ERROR;
	}

	/****** Get file size of response message ******/
	rv = apr_stat(&fi, res_fn, APR_FINFO_SIZE, r->pool);
	if (rv != APR_SUCCESS) {
		ap_log_error(APLOG_MARK, APLOG_EMERG, rv, NULL, 
			"*** mod_err *** : apr_stat");
		return HTTP_INTERNAL_SERVER_ERROR;
	}

#ifdef DEBUG
	ap_log_error(APLOG_MARK, APLOG_NOTICE, rv, NULL, 
		"*** mod *** : apr_stat res_size = %ld", (apr_off_t)fi.size);
#endif

	WriteLog(9,"send to client start");
	/* send the file with size if known */
	if (r->proto_num <1001) ap_set_content_length(r,fi.size);
	rv = ap_send_fd(fd, r, 0, ((fi.size > 0) ? fi.size : -1), &bytes_sent);
	if (rv != APR_SUCCESS) {
		ap_log_error(APLOG_MARK, APLOG_EMERG, rv, NULL, 
			"*** mod_err *** : ap_send_fd");
		return HTTP_INTERNAL_SERVER_ERROR;
	}

	/* Must not file close
	rv = apr_file_close(fd);
	*/
	
	return EXIT_SUCCESS;
}