Lines Matching defs:ctx

82 static void clear_ctxpool(sed_filter_ctxt* ctx)
84 apr_pool_clear(ctx->tpool);
85 ctx->outbuf = NULL;
86 ctx->curoutbuf = NULL;
87 ctx->numbuckets = 0;
93 static void alloc_outbuf(sed_filter_ctxt* ctx)
95 ctx->outbuf = apr_palloc(ctx->tpool, ctx->bufsize + 1);
96 ctx->curoutbuf = ctx->outbuf;
100 * Allocate a new bucket from buf and sz and append to ctx->bb
102 static apr_status_t append_bucket(sed_filter_ctxt* ctx, char* buf, int sz)
106 if (ctx->tpool == ctx->r->pool) {
108 b = apr_bucket_pool_create(buf, sz, ctx->r->pool,
109 ctx->r->connection->bucket_alloc);
110 APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
115 ctx->r->connection->bucket_alloc);
116 APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
117 ctx->numbuckets++;
118 if (ctx->numbuckets >= MAX_TRANSIENT_BUCKETS) {
119 b = apr_bucket_flush_create(ctx->r->connection->bucket_alloc);
120 APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
121 status = ap_pass_brigade(ctx->f->next, ctx->bb);
122 apr_brigade_cleanup(ctx->bb);
123 clear_ctxpool(ctx);
131 * Flush the output data (stored in ctx->outbuf)
133 static apr_status_t flush_output_buffer(sed_filter_ctxt *ctx)
135 int size = ctx->curoutbuf - ctx->outbuf;
138 if ((ctx->outbuf == NULL) || (size <=0))
140 out = apr_palloc(ctx->tpool, size);
141 memcpy(out, ctx->outbuf, size);
142 status = append_bucket(ctx, out, size);
143 ctx->curoutbuf = ctx->outbuf;
157 sed_filter_ctxt *ctx = (sed_filter_ctxt *) dummy;
158 if (ctx->outbuf == NULL) {
159 alloc_outbuf(ctx);
161 remainbytes = ctx->bufsize - (ctx->curoutbuf - ctx->outbuf);
164 memcpy(ctx->curoutbuf, buf, remainbytes);
167 ctx->curoutbuf += remainbytes;
170 status = append_bucket(ctx, ctx->outbuf, ctx->bufsize);
172 alloc_outbuf(ctx);
175 if ((status == APR_SUCCESS) && (sz >= ctx->bufsize)) {
176 char* newbuf = apr_palloc(ctx->tpool, sz);
178 status = append_bucket(ctx, newbuf, sz);
180 if (ctx->outbuf == NULL) {
181 alloc_outbuf(ctx);
185 memcpy(ctx->curoutbuf, buf, sz);
186 ctx->curoutbuf += sz;
190 memcpy(ctx->curoutbuf, buf, sz);
191 ctx->curoutbuf += sz;
232 /* Initialize sed filter context. If successful then context is set in f->ctx
237 sed_filter_ctxt* ctx;
243 ctx = apr_pcalloc(r->pool, sizeof(sed_filter_ctxt));
244 ctx->r = r;
245 ctx->bb = NULL;
246 ctx->numbuckets = 0;
247 ctx->f = f;
248 status = sed_init_eval(&ctx->eval, sed_cfg->sed_cmds, log_sed_errf,
253 apr_pool_cleanup_register(r->pool, &ctx->eval, sed_eval_cleanup,
255 ctx->bufsize = MODSED_OUTBUF_SIZE;
257 apr_pool_create(&(ctx->tpool), r->pool);
260 ctx->tpool = r->pool;
262 alloc_outbuf(ctx);
263 f->ctx = ctx;
275 sed_filter_ctxt *ctx = f->ctx;
284 if (ctx == NULL) {
295 ctx = f->ctx;
299 ctx->bb = apr_brigade_create(f->r->pool, f->c->bucket_alloc);
305 * sed_write_output which will add the output to ctx->bb. At the end of
306 * the loop, ctx->bb is passed to the next filter in chain. At the end of
316 * If flush bucket is found then append the the flush bucket to ctx->bb
327 sed_finalize_eval(&ctx->eval, ctx);
328 status = flush_output_buffer(ctx);
330 clear_ctxpool(ctx);
334 /* Insert the eos bucket to ctx->bb brigade */
335 APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
341 status = flush_output_buffer(ctx);
343 clear_ctxpool(ctx);
346 APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
355 status = sed_eval_buffer(&ctx->eval, buf, bytes, ctx);
357 clear_ctxpool(ctx);
371 status = flush_output_buffer(ctx);
373 clear_ctxpool(ctx);
376 if (!APR_BRIGADE_EMPTY(ctx->bb)) {
377 status = ap_pass_brigade(f->next, ctx->bb);
378 apr_brigade_cleanup(ctx->bb);
380 clear_ctxpool(ctx);
393 sed_filter_ctxt *ctx = f->ctx;
406 if (!ctx) {
415 ctx = f->ctx;
416 ctx->bb = apr_brigade_create(f->r->pool, f->c->bucket_alloc);
423 * sed_write_output which will add data in ctx->bb. Do it until it have
424 * atleast one bucket bucket in ctx->bb. At the end of data eos bucket
437 while (APR_BRIGADE_EMPTY(ctx->bb)) {
454 sed_finalize_eval(&ctx->eval, ctx);
455 flush_output_buffer(ctx);
457 APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
466 status = sed_eval_buffer(&ctx->eval, buf, bytes, ctx);
469 flush_output_buffer(ctx);
476 if (!APR_BRIGADE_EMPTY(ctx->bb)) {
481 apr_brigade_partition(ctx->bb, readbytes, &b);
483 newbb = apr_brigade_split(ctx->bb, b);
484 APR_BRIGADE_CONCAT(bb, ctx->bb);
485 APR_BRIGADE_CONCAT(ctx->bb, newbb);