/** * spin.c * * Copyright (C) 2003 - 2005 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 a special exception, Bojan Smojver, Rexursive, gives * permission to dynamically link the code of this program with 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). You must * obey the GNU General Public Licence in all respects for all of the code used * other than Apache Portable Runtime and Apache Portable Runtime Utility * Library. * */ #include "private.h" #define ERRBUFSZ 80 /* cheat - we need this function for testing, but it only comes inside httpd */ char *ap_construct_url(apr_pool_t *p,const char *uri,request_rec *r){ return NULL; } int main(int argc,const char * const argv[]){ int i; size_t iter; const char *tmpl,*appl; char *errbuf; apr_pool_t *pool,*permpool; apr_file_t *sout; apr_bucket *bucket; apr_bucket_alloc_t *balloc; apr_bucket_brigade *brigade; apr_status_t astatus; apr_size_t nbytes; apr_dso_handle_t *handle=NULL; apr_dso_handle_sym_t shandle=NULL; apr_finfo_t *finfo; rxv_spin_extra_t *extra; rxv_spin_context_t *ctx; rxv_spin_cpool_t *cpool; rxv_spin_private_t *private; if(argc!=4){ fprintf(stderr,"%s: usage: spin iterations template application\n", argv[0]); exit(1); } atexit(apr_terminate); apr_app_initialize(&argc,&argv,NULL); apr_pool_create(&pool,NULL); apr_pool_create(&permpool,NULL); errbuf=apr_palloc(permpool,ERRBUFSZ+1); finfo=apr_palloc(permpool,sizeof(*finfo)); cpool=rxv_spin_cpool_create(permpool); iter=strtol(argv[1],NULL,10); tmpl=argv[2]; appl=argv[3]; private=rxv_spin_private_create(permpool); for(i=0;ictx; brigade=extra->brigade; extra->cache=private->cache; extra->used=apr_hash_make(extra->pool); extra->cacheall=0; extra->sendfile=1; ctx->cpool=cpool; astatus=apr_dso_load(&handle,appl,pool); apr_dso_error(handle,errbuf,ERRBUFSZ); if(astatus!=APR_SUCCESS){ fprintf(stderr,"error: %s\n",errbuf); apr_terminate(); exit(1); } astatus=apr_dso_sym(&shandle,handle,"rxv_spin_service"); apr_dso_error(handle,errbuf,ERRBUFSZ); if(astatus!=APR_SUCCESS){ fprintf(stderr,"error: %s\n",errbuf); apr_terminate(); exit(1); } (*((rxv_spin_service_t)shandle))(ctx); apr_stat(finfo,tmpl,APR_FINFO_MIN,ctx->pool); if((astatus=rxv_spin_file(tmpl,extra,permpool,finfo))==APR_SUCCESS){ const char *buf; apr_size_t len; apr_file_open_stdout(&sout,pool); while(!APR_BRIGADE_EMPTY(brigade)){ bucket=APR_BRIGADE_FIRST(brigade); if(APR_BUCKET_IS_FILE(bucket)){ apr_bucket_read(bucket,&buf,&len,APR_BLOCK_READ); apr_file_write(sout,buf,&len); }else if(APR_BUCKET_IS_IMMORTAL(bucket)){ char *buf=(char *)bucket->data; nbytes=bucket->length; apr_file_write(sout,buf+bucket->start,&nbytes); }else if(APR_BUCKET_IS_POOL(bucket)){ char *buf=(char *)((apr_bucket_pool *)bucket->data)->base; nbytes=bucket->length; apr_file_write(sout,buf+bucket->start,&nbytes); } else if(APR_BUCKET_IS_MMAP(bucket)){ apr_mmap_t *map=((apr_bucket_mmap *)bucket->data)->mmap; nbytes=bucket->length; apr_file_write(sout,map->mm+bucket->start,&nbytes); } apr_bucket_delete(bucket); } } else{ fprintf(stderr,"error: %s\n",extra->error); } apr_pool_clear(pool); } apr_terminate(); exit(0); }