/** * util.c * * Copyright (C) 2003, 2004 Bojan Smojver, Rexursive * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public Licence as published by the Free * Software Foundation; either version 2 of the Licence, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public Licence for * more details. * * You should have received a copy of the GNU General Public Licence along * with this program; if not, write to the Free Software Foundation, Inc., 59 * Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as two special exceptions, Bojan Smojver, Rexursive, gives * permission to: * * 1. Link, both statically and dynamically, the code of this program with * Apache HTTP Server, Apache Portable Runtime and Apache Portable Runtime * Utility Library from Apache Software Foundation (or with modified versions * of the above, that use the same licence - Apache Software Licence 1.1, 2.0 * or any later version), and distribute linked combinations including the * program and the above software from Apache Software Foundation. You must * obey the GNU General Public Licence in all respects for all of the code * used other than Apache HTTP Server, Apache Portable Runtime and Apache * Portable Runtime Utility Library. * * 2. Dynamically link any shared library with this program at run-time, * through the interface of SpinApplication/SpinAppEntry or LoadModule * run-time configuration directives of Apache HTTP Server, as provided by * this program or Apache HTTP Server itself, regardless of licensing terms of * those shared libraries. You must obey the GNU General Public Licence in all * respects for all of the code used other than that of those shared * libraries. * * If you modify this file, you may extend these exceptions to your version of * the file, but you are not obligated to do so. If you do not wish to do so, * delete one or both of these exception statements from your version. * */ #include "private.h" /* scanner and parser utility functions */ static apr_status_t extra_destroy(void *extra_v){ rxv_spin_extra_t *extra=(rxv_spin_extra_t *)extra_v; if(extra->buf){ free(extra->buf); extra->buf=NULL; } return APR_SUCCESS; } rxv_spin_extra_t *rxv_spin_extra_create(apr_pool_t *pool, apr_bucket_alloc_t *balloc){ rxv_spin_extra_t *extra; rxv_spin_context_t *ctx; apr_bucket_brigade *bb; if(!(extra=apr_pcalloc(pool,sizeof(*extra)))) return NULL; extra->tail=apr_pcalloc(pool,sizeof(*extra->tail)*RXV_SPIN_MAX_DEPTH*2); extra->loop=apr_pcalloc(pool,sizeof(*extra->loop)*RXV_SPIN_MAX_DEPTH); extra->nest=apr_pcalloc(pool,sizeof(*extra->nest)*RXV_SPIN_MAX_DEPTH); extra->boff=apr_pcalloc(pool,sizeof(*extra->boff)*RXV_SPIN_MAX_DEPTH); if(!(extra->tail && extra->loop && extra->nest && extra->boff)) return NULL; extra->pool=pool; extra->row=1; extra->col=0; if(!(ctx=apr_pcalloc(pool,sizeof(*ctx)))) return NULL; extra->ctx=ctx; ctx->pool=pool; if(!(ctx->data=apr_pcalloc(pool,sizeof(*ctx->data)))) return NULL; ctx->data->size=1; ctx->data->type=RXV_SPIN_DATA_RWS; if(!(ctx->data->cols=apr_hash_make(pool))) return NULL; if(!(ctx->guts=apr_pcalloc(pool,sizeof(rxv_spin_guts_t)))) return NULL; if(!(bb=apr_brigade_create(pool,balloc))) return NULL; extra->brigade=bb; apr_pool_cleanup_register(pool,extra,extra_destroy,apr_pool_cleanup_null); return extra; } /* private thread data structure, including memory pool */ rxv_spin_private_t *rxv_spin_private_create(apr_pool_t *pool){ rxv_spin_private_t *private; apr_pool_t *tpool; if(apr_pool_create(&tpool,pool)!=APR_SUCCESS) return NULL; if(!((private=apr_pcalloc(tpool,sizeof(*private))) && (private->cache=apr_hash_make(tpool)) && (private->dso=apr_hash_make(tpool)) && (private->cpool=rxv_spin_cpool_create(tpool)))){ apr_pool_destroy(tpool); return NULL; } private->pool=tpool; return private; }