/* Copyright 2006 Garrett Rooney. * 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 #include "pwt_error.h" #include "private/error_convert.h" pwt_error_t * pwt_error_create_impl(apr_status_t err, const char *msg, apr_uint32_t line, const char *file) { apr_pool_t *pool; pwt_error_t *e; apr_pool_create(&pool, NULL); e = apr_pcalloc(pool, sizeof (*e)); e->err = err; e->msg = apr_pstrdup(pool, msg); e->line = line; e->file = apr_pstrdup(pool, file); e->pool = pool; return e; } pwt_error_t * pwt_error_createf_impl(apr_status_t err, apr_uint32_t line, const char *file, const char *fmt, ...) { apr_pool_t *pool; pwt_error_t *e; va_list ap; apr_pool_create(&pool, NULL); e = apr_pcalloc(pool, sizeof (*e)); e->err = err; va_start(ap, fmt); e->msg = apr_pvsprintf(pool, fmt, ap); va_end(ap); e->line = line; e->file = file; e->pool = pool; return e; } void pwt_error_destroy(pwt_error_t *err) { if (err && err->pool) { apr_pool_destroy(err->pool); } } static apr_status_t etl_err_to_apr_err(int err) { switch(err) { case ETL_ENOSPACE: return APR_ENOENT; case ETL_ENOENT: return APR_ENOENT; case ETL_EINVAL: return APR_EINVAL; case ETL_ENOTIMPL: return APR_ENOTIMPL; case ETL_EIO: /** XXXX: this isn't... true. */ return APR_INCOMPLETE; default: return APR_EGENERAL; } } pwt_error_t *pwt_convert_etl_err(etl_error_t *err) { if (err != ETL_SUCCESS) { pwt_error_t *p_err; p_err = pwt_error_create_impl(etl_err_to_apr_err(err->err), err->msg, err->line, err->file); etl_error_clear(err); return p_err; } else { return PWT_SUCCESS; } }