/* 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. */ #include #include "proton.h" #include "pwt_error.h" #include "private/request.h" #include "private/context.h" #include "private/error_convert.h" #include #include void pwt_req_init(pwt_req_t **pwr, pwt_ctxt_t *pwt) { pwt_req_t *m_pwr = malloc(sizeof(pwt_req_t)); /* Setup inital structure */ m_pwr->m_pwt = pwt; apr_pool_create(&m_pwr->m_pool, pwt->m_pool); *pwr = m_pwr; } void pwt_req_destroy(pwt_req_t **pwr) { pwt_req_t *m_pwr = *pwr; apr_pool_destroy(m_pwr->m_pool); free(m_pwr); *pwr = NULL; } pwt_ctxt_t *pwt_req_get_context(pwt_req_t* pwr) { return pwr->m_pwt; } pwt_error_t* pwt_req_exec(pwt_req_t *pwr) { unsigned int i = 0; pwt_module_t *module; const char *modname = NULL; pwt_module_handler_t *h; /* TODO: * parse for module * handle routes * execute */ pwr->path = getenv("REQUEST_URI"); if (pwr->path) { modname = pwt_route_match_path(pwr->m_pwt, pwr->path, strlen(pwr->path)); } else { modname = pwt_route_find_path(pwr->m_pwt, "/"); } pwr->m_pwt->m_environment = etl_hash_create(); if (!modname) { /* TODO The handler and default handler could not be found */ } else { module = apr_hash_get(pwr->m_pwt->m_modules, modname, APR_HASH_KEY_STRING); if (module) { for (i=0; ihandlers->nelts; i++) { h = APR_ARRAY_IDX(module->handlers, i, pwt_module_handler_t*); if (strcmp(h->match, "D") == 0) { h->handler(pwr->m_pwt, module); break; } } } } PWT_E_ERR(etl_template_parse_file(&pwr->m_pwt->m_template, pwr->m_pwt->etl_filename)); etl_template_execute(pwr->m_pwt->m_template, NULL, pwr->m_pwt->m_environment, pwr->m_pwt->out); return PWT_SUCCESS; } int pwt_render_template(pwt_ctxt_t *pwt, const char *tmpl) { pwt->etl_filename = apr_pstrcat(pwt->m_pool, pwt->m_conf.template_path, "/", tmpl, NULL); return 200; }