/* Copyright 2006 Paul Querna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @file pwt.h * @brief Proton Web Toolkit's core header. */ #ifndef PROTON_H #define PROTON_H #include #include "pwt_version.h" #include "pwt_error.h" #include "etl_variables.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #ifndef APR_ARRAY_IDX #define APR_ARRAY_IDX(ary,i,type) (((type *)(ary)->elts)[i]) #endif typedef struct pwt_ctxt_t pwt_ctxt_t; typedef struct pwt_req_t pwt_req_t; pwt_error_t* pwt_init(pwt_ctxt_t **pwt); void pwt_cgi_write_body(pwt_ctxt_t *pwt); void pwt_cgi_write_header(pwt_ctxt_t *pwt); etl_variable_t* pwt_etl_getenv(pwt_ctxt_t *pwt); void pwt_destroy(pwt_ctxt_t **pwt); void pwt_root_set(pwt_ctxt_t *pwt, const char *path); const char* pwt_root_get(pwt_ctxt_t *pwt); char* pwt_root_relative(pwt_ctxt_t *pwt, const char *path, apr_pool_t *p); pwt_error_t* pwt_startup(pwt_ctxt_t *pwt); pwt_error_t* pwt_execute(pwt_ctxt_t *pwt); int pwt_render_template(pwt_ctxt_t *pwt, const char *tmpl); void pwt_req_init(pwt_req_t **pwr, pwt_ctxt_t *pwt); void pwt_req_destroy(pwt_req_t **pwr); pwt_error_t* pwt_req_exec(pwt_req_t *pwr); typedef int(*pwt_handler_cb)(pwt_ctxt_t* pwr, void* baton); pwt_ctxt_t *pwt_req_get_context(pwt_req_t* pwr); /** * We only have a single level Module Magic Number, * Unlike httpd, which is a two level, with compat stuff. meh. */ #define PWT_MODULE_VERSION 0xFF0001FF #define PWT_STANDARD_MODULE_STUFF \ PWT_MODULE_VERSION, \ NULL, \ __FILE__, \ NULL typedef struct pwt_module_handler_struct pwt_module_handler_t; struct pwt_module_handler_struct { const char *match; void *baton; pwt_handler_cb handler; }; typedef struct pwt_module_struct pwt_module_t; struct pwt_module_struct { /** Used to check the module's version number is compatible * with Proton's current version. */ int version; /** @private : Internal DSO handle for this module. */ void *dso_handle; /** __FILE__ from the module */ const char *name; apr_array_header_t *handlers; void (*register_func) (pwt_module_t *pmod, pwt_ctxt_t *pwt); }; #define PWT_MODULE_DECL(modname, regfunc) \ pwt_module_t modname ## _module = \ { \ PWT_STANDARD_MODULE_STUFF, \ regfunc \ }; void pwt_register_handler_default(pwt_module_t *pmod, pwt_ctxt_t *pwt, pwt_handler_cb function); void pwt_register_handler(pwt_module_t *pmod, pwt_ctxt_t *pwt, const char *match, pwt_handler_cb func_cp, void *baton); const char* pwt_route_find_module(pwt_ctxt_t *pwt, const char *name); void pwt_output_headers(pwt_ctxt_t *pwt); void pwt_set_output_headers(pwt_ctxt_t *pwt, const char *header, const char *value); void pwt_set_stream(pwt_ctxt_t *pwt, const char *fmt, ...); #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* PROTON_H */