• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10/apache-793/httpd/modules/filters/

Lines Matching refs:ctx

86     /* set up a ready-initialised ctx to convert to enc, and insert filter */
108 xml2ctx* ctx = apr_pcalloc(r->pool, sizeof(xml2ctx));
109 ctx->flags = flags;
111 ctx->convset = convset;
112 ctx->bblen = BUFLEN;
113 ctx->buf = apr_palloc(r->pool, (apr_size_t)ctx->bblen);
115 ap_add_output_filter("xml2enc", ctx, r, r->connection);
126 static void fix_skipto(request_rec* r, xml2ctx* ctx)
130 if ((cfg->skipto != NULL) && (ctx->flags | ENC_SKIPTO)) {
132 char* p = ap_strchr(ctx->buf, '<');
141 rv = apr_brigade_partition(ctx->bbsave, (p-ctx->buf),
144 while (b = APR_BRIGADE_FIRST(ctx->bbsave), b != bstart) {
148 ctx->bytes -= (p-ctx->buf);
149 ctx->buf = p ;
165 static void sniff_encoding(request_rec* r, xml2ctx* ctx)
183 if (ctx->encoding = apr_pstrndup(r->pool, p, strcspn(p, " ;") ),
184 ctx->encoding) {
186 "Got charset %s from HTTP headers", ctx->encoding) ;
187 ctx->xml2enc = xmlParseCharEncoding(ctx->encoding);
193 if (ctx->xml2enc == XML_CHAR_ENCODING_NONE) {
194 ctx->xml2enc = xmlDetectCharEncoding((const xmlChar*)ctx->buf,
195 ctx->bytes);
196 if (HAVE_ENCODING(ctx->xml2enc)) {
199 ctx->encoding = xmlGetCharEncodingName(ctx->xml2enc);
205 if (ap_regexec(seek_meta_ctype, ctx->buf, 1, match, 0) == 0 ) {
207 rv = apr_brigade_partition(ctx->bbsave, match[0].rm_eo, &cute);
209 rv = apr_brigade_partition(ctx->bbsave, match[0].rm_so, &cutb);
212 ctx->bytes = match[0].rm_so;
213 if (ctx->encoding == NULL) {
214 p = apr_pstrndup(r->pool, ctx->buf + match[0].rm_so,
217 if (ctx->encoding = apr_pstrndup(r->pool, p+match[1].rm_so,
219 ctx->encoding) {
220 ctx->xml2enc = xmlParseCharEncoding(ctx->encoding);
221 if (HAVE_ENCODING(ctx->xml2enc))
223 "Got charset %s from HTML META", ctx->encoding) ;
236 ctx->buf[ctx->bytes] = 0;
246 if (!HAVE_ENCODING(ctx->xml2enc)) {
248 if (!ctx->encoding) {
249 ctx->encoding = cfg->default_charset?cfg->default_charset:"ISO-8859-1";
254 ctx->encoding);
255 if (apr_xlate_open(&ctx->convset, "UTF-8", ctx->encoding, r->pool)
257 ctx->xml2enc = XML_CHAR_ENCODING_UTF8 ;
261 ctx->encoding) ;
265 if (!HAVE_ENCODING(ctx->xml2enc)) {
269 ctx->xml2enc = (cfg->default_encoding == XML_CHAR_ENCODING_NONE)
272 if (ctype && ctx->encoding) {
289 xml2ctx* ctx;
290 if (!f->ctx) {
293 f->ctx = ctx = apr_pcalloc(f->r->pool, sizeof(xml2ctx));
294 ctx->xml2enc = XML_CHAR_ENCODING_NONE;
296 ctx->flags |= ENC_SKIPTO;
303 xml2ctx* ctx = f->ctx;
311 if (!ctx || !f->r->content_type) {
328 if (ctx->bbsave == NULL) {
329 ctx->bbsave = apr_brigade_create(f->r->pool,
333 APR_BRIGADE_CONCAT(ctx->bbsave, bb);
335 if (!(ctx->flags & ENC_INITIALISED)) {
340 apr_brigade_length(ctx->bbsave, 0, &ctx->bblen);
341 if ((ctx->bblen < BUF_MIN) && (ctx->bblen != -1)) {
342 APR_BRIGADE_DO(b, ctx->bbsave) {
344 ctx->flags |= ENC_SEEN_EOS;
348 if (!(ctx->flags & ENC_SEEN_EOS)) {
350 APR_BRIGADE_DO(b, ctx->bbsave) {
357 if (ctx->bblen == -1) {
358 ctx->bblen = BUFLEN-1;
362 ctx->buf = apr_palloc(f->r->pool, (apr_size_t)(ctx->bblen+1));
363 ctx->bytes = (apr_size_t)ctx->bblen;
364 rv = apr_brigade_flatten(ctx->bbsave, ctx->buf, &ctx->bytes);
366 ctx->buf[ctx->bytes] = 0;
367 sniff_encoding(f->r, ctx);
371 fix_skipto(f->r, ctx);
378 ctx->flags |= ENC_INITIALISED;
379 ap_set_module_config(f->r->request_config, &xml2enc_module, ctx);
381 if (ctx->bbnext == NULL) {
382 ctx->bbnext = apr_brigade_create(f->r->pool,
386 if (!ctx->convset) {
387 rv = ap_pass_brigade(f->next, ctx->bbsave);
388 apr_brigade_cleanup(ctx->bbsave);
393 APR_BRIGADE_CONCAT(bb, ctx->bbsave);
396 ctx->bytes = 0;
401 APR_BRIGADE_INSERT_TAIL(ctx->bbnext, b);
402 return ap_fflush(f->next, ctx->bbnext);
404 ap_fflush(f->next, ctx->bbnext);
427 rv = ap_fflush(f->next, ctx->bbnext);
428 APR_BRIGADE_CONCAT(ctx->bbsave, bb);
429 APR_BRIGADE_DO(b, ctx->bbsave) {
461 if (ctx->bytes == ctx->bblen) {
473 ctx->bytes = (apr_size_t)ctx->bblen;
474 rv = apr_xlate_conv_buffer(ctx->convset, buf+(bytes - insz),
475 &insz, ctx->buf, &ctx->bytes);
479 ctx->bblen - ctx->bytes);
481 rv2 = ap_fwrite(f->next, ctx->bbnext, ctx->buf,
482 (apr_size_t)ctx->bblen - ctx->bytes);
496 * we test ctx->bytes == ctx->bblen
509 ctx->convset = NULL;
510 rv = ap_fflush(f->next, ctx->bbnext);
515 rv = ap_pass_brigade(f->next, ctx->bbnext);
533 xml2ctx* ctx = ap_get_module_config(r->request_config, &xml2enc_module);
534 if (!ctx || !(ctx->flags & ENC_INITIALISED)) {
537 *encp = ctx->xml2enc;
538 *encoding = ctx->encoding;
539 return HAVE_ENCODING(ctx->xml2enc) ? APR_SUCCESS : APR_EGENERAL;