Ejemplo n.º 1
0
static int less_handler(request_rec* r)
{
	struct stat info;
	struct stat lessinfo;
	char * lessfilename = NULL;
	char * command = NULL;
	int status;
	int newer = 0;
	int error = 0;
	char * errornum = NULL;

	if (!r->handler || strcmp(r->handler, "less"))
	return DECLINED;

	if (r->method_number != M_GET)
	return HTTP_METHOD_NOT_ALLOWED;

	asprintf(&lessfilename, "%s.less", r->filename);
	asprintf(&command, "lessc %s > %s", r->filename, lessfilename);

	if (!file_exists(lessfilename)){

		status = system(command);
		if(status != 0)
			return DECLINED;

	}

	if (file_exists(lessfilename)){

		if ((stat(r->filename,&info) == 0) && (stat(lessfilename,&lessinfo) == 0) && (info.st_mtime > lessinfo.st_mtime))
			status = system(command);
		
		if ((error = read_file(lessfilename)) != 1){
			ap_set_content_type(r, "text/css");
        		ap_rputs(source,r);
			free(source);
			return OK;

		} else {

			asprintf(&errornum, "%d", error);
			ap_set_content_type(r, "text/css");
        		ap_rputs(errornum,r);
			free(source);
			return OK;

		}

	}
    	
}
Ejemplo n.º 2
0
static void osrfHttpTranslatorInitHeaders(osrfHttpTranslator* trans, transport_message* msg) {
    apr_table_set(trans->apreq->headers_out, OSRF_HTTP_HEADER_FROM, msg->sender);
    apr_table_set(trans->apreq->headers_out, OSRF_HTTP_HEADER_THREAD, trans->thread);
    if(trans->multipart) {
        sprintf(contentTypeBuf, MULTIPART_CONTENT_TYPE, trans->delim);
        contentTypeBuf[79] = '\0';
        osrfLogDebug(OSRF_LOG_MARK, "content type %s : %s : %s", MULTIPART_CONTENT_TYPE,
        trans->delim, contentTypeBuf);
        ap_set_content_type(trans->apreq, contentTypeBuf);
        ap_rprintf(trans->apreq, "--%s\n", trans->delim);
    } else {
        ap_set_content_type(trans->apreq, JSON_CONTENT_TYPE);
    }
}
Ejemplo n.º 3
0
static void jsonStartDocument( struct tabix_callback_t* handler)
	{
	if(handler->jsonp_callback!=NULL)
			{
			ap_set_content_type(handler->r, MIME_TYPE_JAVASCRIPT);
			ap_rputs(handler->jsonp_callback,handler->r);
			ap_rputc('(',handler->r);
			}
	else
			{
			ap_set_content_type(handler->r, MIME_TYPE_JSON);
			}
	ap_rputs("{",handler->r);
	}
Ejemplo n.º 4
0
static int
php_apache_sapi_send_headers(sapi_headers_struct *sapi_headers)
{
	php_struct *ctx = SG(server_context);
	const char *sline = SG(sapi_headers).http_status_line;

	ctx->r->status = SG(sapi_headers).http_response_code;

	/* httpd requires that r->status_line is set to the first digit of
	 * the status-code: */
	if (sline && strlen(sline) > 12 && strncmp(sline, "HTTP/1.", 7) == 0 && sline[8] == ' ') {
		ctx->r->status_line = apr_pstrdup(ctx->r->pool, sline + 9);
		ctx->r->proto_num = 1000 + (sline[7]-'0');
		if ((sline[7]-'0') == 0) {
			apr_table_set(ctx->r->subprocess_env, "force-response-1.0", "true");
		}
	}

	/*	call ap_set_content_type only once, else each time we call it,
		configured output filters for that content type will be added */
	if (!ctx->content_type) {
		ctx->content_type = sapi_get_default_content_type();
	}
	ap_set_content_type(ctx->r, apr_pstrdup(ctx->r->pool, ctx->content_type));
	efree(ctx->content_type);
	ctx->content_type = NULL;

	return SAPI_HEADER_SENT_SUCCESSFULLY;
}
Ejemplo n.º 5
0
static int helloworld_handler(request_rec* r) {
    if ( !r->handler || strcmp(r->handler, "helloworld") ) {
        return DECLINED ;   /* none of our business */
        }
    if ( r->method_number != M_GET ) {
        return HTTP_METHOD_NOT_ALLOWED ;  /* Reject other methods */
        }
    ap_set_content_type(r, "text/html;charset=ascii") ;
    ap_rputs(
        "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n", r) ;
    ap_rputs(
        "<html><head><title>Apache HelloWorld Module</title></head>", r) ;
    ap_rputs("<body><h1>Hello World!</h1>", r) ;
    ap_rputs("<p>This is the Apache HelloWorld module!</p>", r) ;

    /* Print the headers and env */
    /* Note that the response headers and environment may be empty at
     * this point.  The CGI environment is an overhead we dispense
     * with in a module, unless another module that requires it
     * (e.g. mod_rewrite) has set it up.
     */
    printtable(r, r->headers_in, "Request Headers", "Header", "Value") ;
    printtable(r, r->headers_out, "Response Headers", "Header", "Value") ;
    printtable(r, r->subprocess_env, "Environment", "Variable", "Value") ;

    ap_rputs("</body></html>", r) ;
    return OK ;
    }
Ejemplo n.º 6
0
/** HTML handlers ***************************************************/
static void htmlStartDocument( struct tabix_callback_t* handler)
	{
	const char* region=HttpParamGet(handler->httParams,"region");

	ap_set_content_type(handler->r, MIME_TYPE_HTML);
	ap_rputs("<!doctype html>\n<html lang=\"en\">",handler->r);
	ap_rputs("<head>",handler->r);
	printDefaulthtmlHead(handler->r);
	ap_rputs("</head>",handler->r);
	ap_rputs("<body>",handler->r);
	ap_rputs("<form>"
		"<label for='format'>Format:</label> <select  id='format' name='format'>"
		"<option value='html'>html</option>"
		"<option value='json'>json</option>"
		"<option value='xml'>xml</option>"
		"<option value='text'>text</option>"
		"</select> "
		"<label for='limit'>Limit:</label> <input id='limit' name='limit' type='number' value='10'/> "
		"<label for='region'>Region:</label> <input id='region' name='region' placeholder='chrom:start-end' "
		,handler->r);
	
	if(region!=NULL)
	    {
	    ap_rputs(" value=\"",handler->r);
	    ap_xmlPuts(region,handler->r);
	    ap_rputs("\"",handler->r);
	    }

	ap_rputs("/> <input type='submit'/></form><div>",handler->r);
	}
Ejemplo n.º 7
0
static int write_http_response(mapcache_context_apache_request *ctx, mapcache_http_response *response) {
   request_rec *r = ctx->request;
   int rc;

   if(response->mtime) {
      ap_update_mtime(r, response->mtime);
      if((rc = ap_meets_conditions(r)) != OK) {
         return rc;
      }
      char *timestr = apr_palloc(r->pool, APR_RFC822_DATE_LEN);
      apr_rfc822_date(timestr, response->mtime);
      apr_table_setn(r->headers_out, "Last-Modified", timestr);
   }
   if(response->headers && !apr_is_empty_table(response->headers)) {
      const apr_array_header_t *elts = apr_table_elts(response->headers);
      int i;
      for(i=0;i<elts->nelts;i++) {
         apr_table_entry_t entry = APR_ARRAY_IDX(elts,i,apr_table_entry_t);
         if(!strcasecmp(entry.key,"Content-Type")) {
            ap_set_content_type(r,entry.val);
         } else {
            apr_table_set(r->headers_out, entry.key, entry.val);
         }
      }
   }
   if(response->data) {
      ap_set_content_length(r,response->data->size);
      ap_rwrite((void*)response->data->buf, response->data->size, r);
   }

   r->status = response->code;
   return OK;

}
Ejemplo n.º 8
0
/* This does some initial checking, like if we're running on a SSL line or not */
static int checkInitial(request_rec *r) 
{
  return OK;
  yubiauth_dir_cfg *cfg = ap_get_module_config(r->per_dir_config, &authn_yubikey_module);
  ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_DEBUG, 0, r,
                LOG_PREFIX "requireSecure: %d", cfg->requireSecure);
  /* If no securiy is wanted or scheme is already https */
    if (!cfg->requireSecure || !strncmp(ap_http_scheme(r), "https", 5)) {
      return OK;
    }
    ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
		  LOG_PREFIX "The server is configured to use HTTPS on URI: %s", r->uri);
    if(cfg->externalErrorPage == TRUE){
      /* We explicitly want that to be overridable */
      //return HTTP_BAD_REQUEST;
      return HTTP_NOT_ACCEPTABLE;
    } 
      
    /* Tell the user/admin what's going on instead of just showing BAD_REQUEST */
    ap_rputs(DOCTYPE_HTML_4_0T, r);
    ap_set_content_type(r, "text/html;");
    ap_rputs(ERROR_TEXT, r);
    ap_finalize_request_protocol(r);
    return HTTP_BAD_REQUEST;
}
Ejemplo n.º 9
0
static int write_msg(request_rec *r, msg_t *msg)
{
    ap_set_content_type(r, "application/octet-stream");
    ap_rputs(msg->data, r);

    return OK;
}
Ejemplo n.º 10
0
static int
run_slash_script(request_rec* r, void* stack_top)
{
    sl_vm_t* vm;
    slash_context_t ctx;
    sl_vm_frame_t exit_frame, exception_frame;
    char* last_slash;
    SLVAL error;
    sl_static_init();
    vm = sl_init("apache2");
    sl_gc_set_stack_top(vm->arena, stack_top);
    vm->cwd = sl_alloc_buffer(vm->arena, strlen(r->canonical_filename) + 10);
    strcpy(vm->cwd, r->canonical_filename);
    last_slash = strrchr(vm->cwd, '/');
    if(last_slash) {
        *last_slash = 0;
    }
    SL_TRY(exit_frame, SL_UNWIND_ALL, {
        SL_TRY(exception_frame, SL_UNWIND_EXCEPTION, {
            ctx.headers_sent = 0;
            ctx.vm = vm;
            ctx.r = r;
            vm->data = &ctx;
            setup_request_object(vm, r);
            setup_response_object(vm);
            ap_set_content_type(r, "text/html; charset=utf-8");
            sl_do_file(vm, r->canonical_filename);
        }, error, {
            sl_response_clear(vm);
            sl_render_error_page(vm, error);
        });
Ejemplo n.º 11
0
static int req_mime_types(lua_State *L)
{
  request_rec *r = CHECK_REQUEST_OBJECT(1);
  apr_pool_t *p = r->connection->base_server->process->pool;
  const char* resource_name = luaL_checkstring(L, 2);
  int set = lua_isnoneornil(L, 3) ? 0 : lua_toboolean(L, 3);
  apr_hash_t *mimes = NULL;
  apr_status_t rc = apr_pool_userdata_get((void**)&mimes, "mod_luaex", p);
  const char* fn, *ext, *fntmp;
  const char* type = NULL;

  if (rc == APR_SUCCESS && mimes)
  {
    if ((fn = ap_strrchr_c(resource_name, '/')) == NULL)
    {
      fn = resource_name;
    }
    else
    {
      ++fn;
    }
    /* Always drop the path leading up to the file name. */

    /* The exception list keeps track of those filename components that
     * are not associated with extensions indicating metadata.
     * The base name is always the first exception (i.e., "txt.html" has
     * a basename of "txt" even though it might look like an extension).
     * Leading dots are considered to be part of the base name (a file named
     * ".png" is likely not a png file but just a hidden file called png).
     */
    fntmp = fn;
    while (*fntmp == '.')
      fntmp++;
    fntmp = ap_strchr_c(fntmp, '.');
    if (fntmp)
    {
      fn = fntmp + 1;
      ext = apr_pstrdup(r->pool, fn);
    }
    else
    {
      ext = apr_pstrdup(r->pool, fn);
      fn += strlen(fn);
    }

    if (set && (type = apr_hash_get(mimes, ext, APR_HASH_KEY_STRING)) != NULL)
    {
      ap_set_content_type(r, (char*) type);
    }
  }
  if (type)
    lua_pushstring(L, type);
  else
    lua_pushnil(L);

  return 1;
}
Ejemplo n.º 12
0
static int document_select(request_rec *r, softbot_handler_rec *s)
{
    int rv = 0;
    uint32_t docid = 0;
    char* OID = 0;
    char* DID = 0;
    char content_type[SHORT_STRING_SIZE+1];

    OID = apr_pstrdup(r->pool, apr_table_get(s->parameters_in, "OID"));
    DID = apr_pstrdup(r->pool, apr_table_get(s->parameters_in, "DID"));

    if( (OID == NULL || strlen(OID) == 0) &&
        (DID == NULL || strlen(DID) == 0) ) {
        MSG_RECORD(&s->msg, error, "oid, did is null, get parameter exist with oid or did.");
        return FAIL;
    }

    if (canned_doc == NULL) {
        canned_doc = (char *)sb_malloc(DOCUMENT_SIZE);
        if (canned_doc == NULL) {
            MSG_RECORD(&s->msg, crit, "out of memory: %s", strerror(errno));
            return FAIL;
        }
    }
    
    if(OID != NULL) decodencpy(OID, OID, strlen(OID));

	if(DID == NULL) {
		rv = sb_run_get_docid(did_db, OID, &docid);
		if ( rv < 0 ) {                                 
			MSG_RECORD(&s->msg, error, "cannot get docid of OID[%s]", OID);
			return FAIL;
		}  

		if( rv == DOCID_NOT_REGISTERED ) {
			MSG_RECORD(&s->msg, error, "not registerd OID[%s]", OID);
			return FAIL;
		}
	} else {
		docid = atoi(DID);
	}

	rv = sb_run_cdm_get_xmldoc(cdm_db, docid, canned_doc, DOCUMENT_SIZE);
	if ( rv < 0 ) {
		MSG_RECORD(&s->msg, error, "cannot get document[%u]", docid);
		return FAIL;
	}

    snprintf( content_type, SHORT_STRING_SIZE, "text/xml; charset=%s", default_charset);
    ap_set_content_type(r, content_type);
    ap_rprintf(r, "<?xml version=\"1.0\" encoding=\"%s\"?>\n", default_charset);
    ap_rwrite(canned_doc, strlen(canned_doc), r);

    return SUCCESS;
}
Ejemplo n.º 13
0
static int papi_send_file (request_rec *r, const char *filename)
{	
	request_rec *rs = ap_sub_req_lookup_file (filename, r, NULL);
	ap_set_content_type (r, rs->content_type);
	int err = ap_run_sub_req (rs);
	if (err != OK)
		APACHE_LOG (APLOG_ERR, "Cookie_Handler: Exception handling %s (%d)",
					   filename, err);
	ap_destroy_sub_req (rs);
	return err;
}
Ejemplo n.º 14
0
static int papi_send_file_with_cookies (request_rec *r, const char *filename, const char *lcook)
{
	
	request_rec *rs = ap_sub_req_lookup_file (filename, r, NULL);
	apr_table_set (r->err_headers_out, "Set-cookie", lcook);
	ap_set_content_type (r, rs->content_type);
	int err = ap_run_sub_req (rs);
	if (err != OK)
		APACHE_LOG (APLOG_ERR, "Cookie_Handler: Exception handling %s", filename);
	ap_destroy_sub_req (rs);
	return err;
}	
/*============================================================================
 *============================================================================
 * This is the beginning of the cgi filter code moved from mod_include. This
 *   is the code required to handle the "exec" SSI directive.
 *============================================================================
 *============================================================================*/
static apr_status_t include_cgi(include_ctx_t *ctx, ap_filter_t *f,
                                apr_bucket_brigade *bb, char *s)
{
    request_rec *r = f->r;
    request_rec *rr = ap_sub_req_lookup_uri(s, r, f->next);
    int rr_status;

    if (rr->status != HTTP_OK) {
        ap_destroy_sub_req(rr);
        return APR_EGENERAL;
    }

    /* No hardwired path info or query allowed */
    if ((rr->path_info && rr->path_info[0]) || rr->args) {
        ap_destroy_sub_req(rr);
        return APR_EGENERAL;
    }
    if (rr->finfo.filetype != APR_REG) {
        ap_destroy_sub_req(rr);
        return APR_EGENERAL;
    }

    /* Script gets parameters of the *document*, for back compatibility */
    rr->path_info = r->path_info;       /* hard to get right; see mod_cgi.c */
    rr->args = r->args;

    /* Force sub_req to be treated as a CGI request, even if ordinary
     * typing rules would have called it something else.
     */
    ap_set_content_type(rr, CGI_MAGIC_TYPE);

    /* Run it. */
    rr_status = ap_run_sub_req(rr);
    if (ap_is_HTTP_REDIRECT(rr_status)) {
        const char *location = apr_table_get(rr->headers_out, "Location");

        if (location) {
            char *buffer;

            location = ap_escape_html(rr->pool, location);
            buffer = apr_pstrcat(ctx->pool, "<a href=\"", location, "\">",
                                 location, "</a>", NULL);

            APR_BRIGADE_INSERT_TAIL(bb, apr_bucket_pool_create(buffer,
                                    strlen(buffer), ctx->pool,
                                    f->c->bucket_alloc));
        }
    }

    ap_destroy_sub_req(rr);

    return APR_SUCCESS;
}
Ejemplo n.º 16
0
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;
}
Ejemplo n.º 17
0
static int foo_handler(request_rec *r)
{
	logdebug("HANDLER");
	if (!r->handler || strcmp(r->handler, "foo-handler"))
		return DECLINED;

	ap_set_content_type(r, "text/plain");
	(*nrequest)++;
	ap_rprintf(r, "Ohai from pid %u! nrequest = %d\n", getpid(), *nrequest);
	logdebugf("nrequest = %d", *nrequest);

	return OK;
}
Ejemplo n.º 18
0
static int example_handler(request_rec *r)
{
    /* First off, we need to check if this is a call for the "example" handler.
     * If it is, we accept it and do our things, it not, we simply return DECLINED,
     * and Apache will try somewhere else.
     */
    if (!r->handler || strcmp(r->handler, "example-handler")) return (DECLINED);

    ap_set_content_type(r, "text/html");   
    // The first thing we will do is write a simple "Hello, world!" back to the client.
    ap_rputs("Hello, world!<br/>", r);
    return OK;
}
Ejemplo n.º 19
0
static int thewall_handler(request_rec *r)
{
    /* First off, we need to check if this is a call for the "example" handler.
 *      * If it is, we accept it and do our things, it not, we simply return DECLINED,
 *           * and Apache will try somewhere else.
 *                */
    if (!r->handler || strcmp(r->handler, "thewall-handler")) return (DECLINED);
    
    // The first thing we will do is write a simple "Hello, world!" back to the client.
//        ap_rputs("Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come.", r);
	ap_set_content_type(r, "text/html");
	ap_rputs("<!TYPEDOC html><html><body> Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come.</body></html>", r);
        return OK;
}
Ejemplo n.º 20
0
/* A bit like mod_status: add a location:

     <Location /svn-status>
       SetHandler svn-status
     </Location>

  and then point a browser at http://server/svn-status.
*/
int dav_svn__status(request_rec *r)
{
  svn_cache__info_t *info;
  svn_string_t *text_stats;
  apr_array_header_t *lines;
  int i;

  if (r->method_number != M_GET || strcmp(r->handler, "svn-status"))
    return DECLINED;

  info = svn_cache__membuffer_get_global_info(r->pool);
  text_stats = svn_cache__format_info(info, FALSE, r->pool);
  lines = svn_cstring_split(text_stats->data, "\n", FALSE, r->pool);

  ap_set_content_type(r, "text/html; charset=ISO-8859-1");

  ap_rvputs(r,
            DOCTYPE_HTML_3_2
            "<html><head>\n"
            "<title>Apache SVN Status</title>\n"
            "</head><body>\n"
            "<h1>Apache SVN Cache Status for ",
            ap_escape_html(r->pool, ap_get_server_name(r)),
            " (via ",
            r->connection->local_ip,
            ")</h1>\n<dl>\n<dt>Server Version: ",
            ap_get_server_description(),
            "</dt>\n<dt>Current Time: ",
            ap_ht_time(r->pool, apr_time_now(), DEFAULT_TIME_FORMAT, 0),
            "</dt>\n", SVN_VA_NULL);

#if defined(WIN32) || (defined(HAVE_UNISTD_H) && defined(HAVE_GETPID))
  /* On Unix the server is generally multiple processes and this
     request only shows the status of the single process that handles
     the request. Ideally we would iterate over all processes but that
     would need some MPM support, so we settle for simply showing the
     process ID. */
  ap_rprintf(r, "<dt>Server process id: %d</dt>\n", (int)getpid());
#endif

  for (i = 0; i < lines->nelts; ++i)
    {
      const char *line = APR_ARRAY_IDX(lines, i, const char *);
      ap_rvputs(r, "<dt>", line, "</dt>\n", SVN_VA_NULL);
    }

  ap_rvputs(r, "</dl></body></html>\n", SVN_VA_NULL);

  return 0;
}
Ejemplo n.º 21
0
static int xmlDirectory( struct listngs_callback_t* handler,DIR *dir)
	{
	struct dirent *entry;
	
	ap_set_content_type(handler->r, MIME_TYPE_XML);
	ap_rputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
		"<ngs-listing git-version=\"" MOD_BIO_VERSION "\">\n",handler->r);	
	
	while((entry = readdir(dir))!=NULL)
		{
		char* concatpath=NULL;
		struct stat statbuf;
		//skip hidden files
		if(entry->d_name[0]=='.') continue;
		
		concatpath=(char*)malloc(
			strlen(handler->basedir)+
			strlen(entry->d_name)+2);
		if(concatpath==NULL) break;
		sprintf(concatpath,"%s/%s",handler->basedir,entry->d_name);
		
		if(lstat(concatpath,&statbuf)!=0)
			{
			free(concatpath);
			break;
			}

		if(S_ISDIR(statbuf.st_mode))
			{
			ap_rputs("<directory>",handler->r);
			ap_xmlPuts(entry->d_name,handler->r);
			ap_rputs("</directory>",handler->r);
			}
		else if(S_ISREG(statbuf.st_mode) && is_ngs_file(concatpath))
			{
			ap_rputs("<file>",handler->r);
			ap_xmlPuts(entry->d_name,handler->r);
			ap_rputs("</file>",handler->r);
			}
	
		free(concatpath);
		concatpath=NULL;
		}
	
	
	ap_rputs("</ngs-listing>\n",handler->r);
	return 0;
	}
Ejemplo n.º 22
0
int papi_post_handler (request_rec *r, papi_dir_config *d, const char *post)
{
	char *uri = ap_construct_url (r->pool, r->unparsed_uri, r);
	char *ptr = strchr (uri, '?');
	if (ptr) *ptr = '\0';

	papi_post_data_t *papi_post_data = apr_pcalloc (r->pool, sizeof (papi_post_data_t));
	
	curl_global_init (CURL_GLOBAL_ALL);
	CURL *curl = curl_easy_init();
	curl_easy_setopt (curl, CURLOPT_URL, uri);
	curl_easy_setopt (curl, CURLOPT_POST, 1);
	curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, papi_post_read_data);
	curl_easy_setopt (curl, CURLOPT_WRITEDATA, (void *)papi_post_data);
	
	// Copy saved header in request.
	int i;
	const apr_array_header_t *headers_in = apr_table_elts (r->headers_in);
	struct curl_slist *headers_out = NULL;
	for (i=0; i < headers_in->nelts; i++) {
		apr_table_entry_t *entry = ((apr_table_entry_t *)headers_in->elts)+i;
		char *header;
		if (!strcmp (entry->key, "Content-Length")) {
			header = apr_psprintf (r->pool, "Content-Length: %d", (int)strlen(post));
		} else {
			header = apr_pstrcat (r->pool, entry->key, ": ", entry->val, NULL);
		}
		headers_out = curl_slist_append (headers_out, header);
	}
	
	curl_easy_setopt (curl, CURLOPT_HTTPHEADER, headers_out);
	curl_easy_setopt (curl, CURLOPT_POSTFIELDS, post);
	int res = curl_easy_perform (curl);
	if (res == CURLE_OK) {
		char *ct;
		curl_easy_getinfo (curl, CURLINFO_CONTENT_TYPE, &ct);
		ap_set_content_type (r, apr_pstrdup (r->pool, ct));
	}
	curl_easy_cleanup (curl);
	curl_global_cleanup();
	
	ap_rputs (papi_post_data->data, r);
	free (papi_post_data->data);
	
	return DONE;
}
Ejemplo n.º 23
0
static int cdn_html_filter(ap_filter_t * f, apr_bucket_brigade * bb)
{
  apr_bucket *b;
  const char *buf = 0;
  apr_size_t bytes = 0;

  /* now do HTML filtering if necessary, and pass the brigade onward */
  saxctxt *ctxt = check_html_filter_init(f);
  if (!ctxt)
    return ap_pass_brigade(f->next, bb);

  for(b = APR_BRIGADE_FIRST(bb); b != APR_BRIGADE_SENTINEL(bb); b = APR_BUCKET_NEXT(b)) {
    if(APR_BUCKET_IS_EOS(b) || APR_BUCKET_IS_FLUSH(b)) {
      consume_buffer(ctxt, buf, 0, 1);
      APR_BUCKET_REMOVE(b);
      APR_BRIGADE_INSERT_TAIL(ctxt->bb, b);
      ap_pass_brigade(ctxt->f->next, ctxt->bb);
      return APR_SUCCESS;
    }

    if(apr_bucket_read(b, &buf, &bytes, APR_BLOCK_READ) == APR_SUCCESS && buf) {
      if(ctxt->parser == NULL) {

        /*
         * for now, always output utf-8; we could incorporate
         * mod_proxy_html's output transcoding with little problem if
         * necessary
         */
        ap_set_content_type(f->r, "text/html;charset=utf-8");

        if(!initialize_parser(f, ctxt, &buf, bytes)) {
          apr_status_t rv = ap_pass_brigade(ctxt->f->next, bb);
          ap_remove_output_filter(f);
          return rv;
        } else
          ap_fputs(f->next, ctxt->bb, ctxt->cfg->doctype);
      }
      consume_buffer(ctxt, buf, bytes, 0);
    }

  }

  /*ap_fflush(ctxt->f->next, ctxt->bb) ; */      /* uncomment for debug */
  apr_brigade_cleanup(bb);
  return APR_SUCCESS;
}
Ejemplo n.º 24
0
static apr_status_t ap_compile_output_filter(ap_filter_t *filter, apr_bucket_brigade *input_brigade) {
  request_rec *request = filter->r;
  if ( ! request->filename) {
    return ap_pass_brigade(filter->next, input_brigade);
  }
  const char       *resource_name;
  compile_config_t *directory_config = (compile_config_t*) ap_get_module_config(request->per_dir_config,        &compile_module);
  compile_config_t *server_config    = (compile_config_t*) ap_get_module_config(request->server->module_config, &compile_module);
  compile_config_t *config           = compile_merge_config(request->pool, server_config, directory_config);
  if (config->use_path_info) {
    resource_name = apr_pstrcat(request->pool, request->filename, request->path_info, NULL);
  } else {
    resource_name = request->filename;
  }
  const char *filename;
        char *extension;
  filename = ap_strrchr_c(resource_name, '/');
  if (filename == NULL) {
    filename = resource_name;
  } else {
    ++ filename;
  }
  extension = ap_getword(request->pool, &filename, '.');
  while (*filename && (extension = ap_getword(request->pool, &filename, '.'))) {
    if (*extension == '\0') {
      continue;
    }
    ap_str_tolower(extension);
    if (config->extension_commands != NULL) {
      const compile_extension_config_t *extension_config = NULL;
      extension_config = (compile_extension_config_t*) apr_hash_get(config->extension_commands, extension, APR_HASH_KEY_STRING);
      if (extension_config != NULL && extension_config->command_line) {
#ifdef _DEBUG
        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, request->server, "ap_compile_output_filter('%s')", apr_psprintf(request->pool, extension_config->command_line, resource_name));
#endif
        // TODO: http://svn.apache.org/repos/asf/httpd/httpd/tags/2.2.6/modules/experimental/mod_case_filter.c
        // Collect buckets, save to disk, run command line and tail-insert result
        ap_set_content_type(request, "text/html;charset=utf-8");
        break;
      }
    }
  }
  return ap_pass_brigade(filter->next, input_brigade);
}
Ejemplo n.º 25
0
static int copy_headers_out(void *vbaton, const char *key, const char *value)
{
    s_baton_t *ctx = vbaton;
    int done = 0;

    /* XXXXX: Special Treatment required for MANY other headers. fixme.*/
    switch (key[0]) {
    case 'c':
    case 'C':
        if (strcasecmp("Content-Type", key) == 0) {
            ap_set_content_type(ctx->r, value);
            done = 1;
            break;
        }
        else if (strcasecmp("Connection", key) == 0) {
            done = 1;
            break;
        }
        else if (strcasecmp("Content-Encoding", key) == 0) {
            done = 1;
            break;
        }
        else if (strcasecmp("Content-Length", key) == 0) {
            done = 1;
            break;
        }
        break;
    case 't':
    case 'T':
        if (strcasecmp("Transfer-Encoding", key) == 0) {
            done = 1;
            break;
        }
        break;
    default:
            break;
    }

    if (!done) {
        apr_table_addn(ctx->r->headers_out, key, value);
    }

    return 0;
}
Ejemplo n.º 26
0
static void accept_headers(cache_handle_t *h, request_rec *r)
{
    apr_table_t *cookie_table;
    const char *v;

    v = apr_table_get(h->resp_hdrs, "Content-Type");
    if (v) {
        ap_set_content_type(r, v);
        apr_table_unset(h->resp_hdrs, "Content-Type");
    }

    /* If the cache gave us a Last-Modified header, we can't just
     * pass it on blindly because of restrictions on future values.
     */
    v = apr_table_get(h->resp_hdrs, "Last-Modified");
    if (v) {
        ap_update_mtime(r, apr_date_parse_http(v));
        ap_set_last_modified(r);
        apr_table_unset(h->resp_hdrs, "Last-Modified");
    }

    /* The HTTP specification says that it is legal to merge duplicate
     * headers into one.  Some browsers that support Cookies don't like
     * merged headers and prefer that each Set-Cookie header is sent
     * separately.  Lets humour those browsers by not merging.
     * Oh what a pain it is.
     */
    cookie_table = apr_table_make(r->pool, 2);
    apr_table_do(set_cookie_doo_doo, cookie_table, r->err_headers_out,
                 "Set-Cookie", NULL);
    apr_table_do(set_cookie_doo_doo, cookie_table, h->resp_hdrs,
                 "Set-Cookie", NULL);
    apr_table_unset(r->err_headers_out, "Set-Cookie");
    apr_table_unset(h->resp_hdrs, "Set-Cookie");

    apr_table_overlap(r->headers_out, h->resp_hdrs,
                      APR_OVERLAP_TABLES_SET);
    apr_table_overlap(r->err_headers_out, h->resp_err_hdrs,
                      APR_OVERLAP_TABLES_SET);
    if (!apr_is_empty_table(cookie_table)) {
        r->err_headers_out = apr_table_overlay(r->pool, r->err_headers_out,
                                               cookie_table);
    }
}
/**
 * Take two sets of headers, sandwich them together, and apply the result to
 * r->headers_out.
 *
 * To complicate this, a header may be duplicated in either table. Should a
 * header exist in the top table, all matching headers will be removed from
 * the bottom table before the headers are combined. The Warning headers are
 * handled specially. Warnings are added rather than being replaced, while
 * in the case of revalidation 1xx Warnings are stripped.
 *
 * The Content-Type and Last-Modified headers are then re-parsed and inserted
 * into the request.
 */
void cache_accept_headers(cache_handle_t *h, request_rec *r, apr_table_t *top,
        apr_table_t *bottom, int revalidation)
{
    const char *v;

    if (revalidation) {
        r->headers_out = apr_table_make(r->pool, 10);
        apr_table_do(filter_header_do, r->headers_out, bottom, NULL);
    }
    else if (r->headers_out != bottom) {
        r->headers_out = apr_table_copy(r->pool, bottom);
    }
    apr_table_do(remove_header_do, r->headers_out, top, NULL);
    apr_table_do(add_header_do, r->headers_out, top, NULL);

    v = apr_table_get(r->headers_out, "Content-Type");
    if (v) {
        ap_set_content_type(r, v);
        /*
         * Also unset possible Content-Type headers in r->headers_out and
         * r->err_headers_out as they may be different to what we have received
         * from the cache.
         * Actually they are not needed as r->content_type set by
         * ap_set_content_type above will be used in the store_headers functions
         * of the storage providers as a fallback and the HTTP_HEADER filter
         * does overwrite the Content-Type header with r->content_type anyway.
         */
        apr_table_unset(r->headers_out, "Content-Type");
        apr_table_unset(r->err_headers_out, "Content-Type");
    }

    /* If the cache gave us a Last-Modified header, we can't just
     * pass it on blindly because of restrictions on future values.
     */
    v = apr_table_get(r->headers_out, "Last-Modified");
    if (v) {
        ap_update_mtime(r, apr_date_parse_http(v));
        ap_set_last_modified(r);
    }

}
Ejemplo n.º 28
0
static am_status_t set_custom_response(am_request_t *rq, const char *text, const char *cont_type) {
    request_rec *r = (request_rec *) (rq != NULL ? rq->ctx : NULL);
    if (r == NULL || !ISVALID(text)) return AM_EINVAL;
    if (rq->status == AM_INTERNAL_REDIRECT) {
        ap_internal_redirect(text, r);
        rq->status = AM_DONE;
    } else if (rq->status == AM_REDIRECT) {
        apr_table_add(r->headers_out, "Location", text);
        ap_custom_response(r, HTTP_MOVED_TEMPORARILY, text);
    } else {
        if (rq->status == AM_PDP_DONE) {
            request_rec *sr = ap_sub_req_method_uri(am_method_num_to_str(rq->method),
                    rq->post_data_url, r, NULL);

            sr->headers_in = r->headers_in;
            sr->notes = r->notes;

            am_log_debug(rq->instance_id, "set_custom_response(): issuing sub-request %s to %s",
                    sr->method, rq->post_data_url);

            ap_run_sub_req(sr);
            ap_destroy_sub_req(sr);
            rq->status = AM_DONE;

        } else {
            size_t tl = strlen(text);
            if (ISVALID(cont_type)) {
                ap_set_content_type(r, cont_type);
            }
            ap_set_content_length(r, tl);
            ap_rwrite(text, (int) tl, r);
            ap_custom_response(r,
                    am_status_value(rq->status == AM_SUCCESS ||
                    rq->status == AM_DONE ? AM_SUCCESS : rq->status), text);
            ap_rflush(r);
        }
    }
    am_log_info(rq->instance_id, "set_custom_response(): status: %s", am_strerror(rq->status));
    return AM_SUCCESS;
}
Ejemplo n.º 29
0
static int bmx_handler(request_rec *r)
{
    apr_status_t rv;
    struct bmx_objectname *query = NULL;

    /* Determine if we are the handler for this request. */
    if (r->handler && strcmp(r->handler, BMX_HANDLER)) {
        return DECLINED;
    }

    /* Disallow any method except GET */
    if (r->method_number != M_GET) {
        return DECLINED;
    }

    /* FIXME: check that the Accept: header has a mime-type we can accept */
    /* FIXME: if no valid types in Accept: header, return code 415 */
    /* FIXME: return the correct mime-type */
    ap_set_content_type(r, "text/plain");

    if (r->header_only) {
        return OK;
    }

    rv = parse_query(r, &query);
    if (rv != APR_SUCCESS) {
        ap_log_rerror(APLOG_MARK, APLOG_CRIT, rv, r, "Failed to parse query");
        return HTTP_BAD_REQUEST;
    }

    /* FIXME: allow other bmx_bean_print functions other than text/plain */
    rv = bmx_run_query_hook(r, query, bmx_bean_print_text_plain);
    if (rv != OK) {
        ap_log_rerror(APLOG_MARK, APLOG_CRIT, rv, r, "Error running "
                      "bmx_run_query_hook, BMX Query failed");
        return HTTP_INTERNAL_SERVER_ERROR;
    }

    return OK;
}
Ejemplo n.º 30
0
/**
 *	Handles the error page, when necessary.
 */
static int make_handler(request_rec *r) {
	if (!r || !r->uri)
		return HTTP_INTERNAL_SERVER_ERROR;
		
	dir_cfg* cfg=ap_get_module_config(r->per_dir_config,&make_module);
	if (strcmp(r->uri,cfg->errorURI))
		return DECLINED;
		
    ap_set_content_type(r, "text/html;charset=ascii");

	const char* make_output=apr_table_get(r->prev->notes,"make_output");
	// ap_log_rerror(APLOG_MARK,APLOG_ERR,0,r,"mod_make handler:make_output:%s",make_output);
	ap_rprintf(r,
		"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n"
		"<html><head><title>mod_make</title>"
		"<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\" />"
		"</head>"
		"<body><h1>Make Error:</h1><pre>%s</pre></body></html>",
		cfg->errorCSS,
		make_output);
		
	return OK;
}