Lines Matching refs:ctx

51     response_context_t *ctx;
53 ctx = serf_bucket_mem_alloc(allocator, sizeof(*ctx));
54 ctx->stream = stream;
55 ctx->body = NULL;
56 ctx->headers = serf_bucket_headers_create(allocator);
57 ctx->state = STATE_STATUS_LINE;
58 ctx->chunked = 0;
59 ctx->head_req = 0;
61 serf_linebuf_init(&ctx->linebuf);
63 return serf_bucket_create(&serf_bucket_type_response, allocator, ctx);
69 response_context_t *ctx = bucket->data;
71 ctx->head_req = 1;
83 response_context_t *ctx = bucket->data;
85 if (ctx->state != STATE_STATUS_LINE) {
86 serf_bucket_mem_free(bucket->allocator, (void*)ctx->sl.reason);
89 serf_bucket_destroy(ctx->stream);
90 if (ctx->body != NULL)
91 serf_bucket_destroy(ctx->body);
92 serf_bucket_destroy(ctx->headers);
97 static apr_status_t fetch_line(response_context_t *ctx, int acceptable)
99 return serf_linebuf_fetch(&ctx->linebuf, ctx->stream, acceptable);
102 static apr_status_t parse_status_line(response_context_t *ctx,
108 /* ctx->linebuf.line should be of form: HTTP/1.1 200 OK */
109 res = apr_date_checkmask(ctx->linebuf.line, "HTTP/#.# ###*");
115 ctx->sl.version = SERF_HTTP_VERSION(ctx->linebuf.line[5] - '0',
116 ctx->linebuf.line[7] - '0');
117 ctx->sl.code = apr_strtoi64(ctx->linebuf.line + 8, &reason, 10);
125 ctx->sl.reason = serf_bstrmemdup(allocator, reason,
126 ctx->linebuf.used
127 - (reason - ctx->linebuf.line));
133 static apr_status_t fetch_headers(serf_bucket_t *bkt, response_context_t *ctx)
140 status = fetch_line(ctx, SERF_NEWLINE_ANY);
146 if (ctx->linebuf.state == SERF_LINEBUF_READY && ctx->linebuf.used) {
150 end_key = c = memchr(ctx->linebuf.line, ':', ctx->linebuf.used);
160 for(; c < ctx->linebuf.line + ctx->linebuf.used; c++)
171 ctx->headers,
172 ctx->linebuf.line, end_key - ctx->linebuf.line, 1,
173 c, ctx->linebuf.line + ctx->linebuf.used - c, 1);
187 static apr_status_t run_machine(serf_bucket_t *bkt, response_context_t *ctx)
191 switch (ctx->state) {
196 status = fetch_line(ctx, SERF_NEWLINE_ANY);
200 if (ctx->linebuf.state == SERF_LINEBUF_READY) {
202 status = parse_status_line(ctx, bkt->allocator);
207 if (ctx->sl.code == 101) {
208 ctx->body =
209 serf_bucket_barrier_create(ctx->stream, bkt->allocator);
210 ctx->state = STATE_DONE;
215 ctx->state = STATE_HEADERS;
228 status = fetch_headers(bkt, ctx);
235 if (ctx->linebuf.state == SERF_LINEBUF_READY && !ctx->linebuf.used) {
239 ctx->state = STATE_BODY;
241 ctx->body =
242 serf_bucket_barrier_create(ctx->stream, bkt->allocator);
245 v = serf_bucket_headers_get(ctx->headers, "Content-Length");
252 ctx->body = serf_bucket_response_body_create(
253 ctx->body, length, bkt->allocator);
256 v = serf_bucket_headers_get(ctx->headers, "Transfer-Encoding");
260 ctx->chunked = 1;
261 ctx->body = serf_bucket_dechunk_create(ctx->body,
265 if (!v && (ctx->sl.code == 204 || ctx->sl.code == 304)) {
266 ctx->state = STATE_DONE;
269 v = serf_bucket_headers_get(ctx->headers, "Content-Encoding");
273 ctx->body =
274 serf_bucket_deflate_create(ctx->body, bkt->allocator,
278 ctx->body =
279 serf_bucket_deflate_create(ctx->body, bkt->allocator,
284 if (ctx->head_req) {
285 ctx->state = STATE_DONE;
293 status = fetch_headers(bkt, ctx);
298 if (ctx->linebuf.state == SERF_LINEBUF_READY && !ctx->linebuf.used) {
299 ctx->state = STATE_DONE;
313 static apr_status_t wait_for_body(serf_bucket_t *bkt, response_context_t *ctx)
318 while (ctx->state != STATE_BODY) {
319 status = run_machine(bkt, ctx);
335 response_context_t *ctx = bucket->data;
337 return wait_for_body(bucket, ctx);
344 response_context_t *ctx = bkt->data;
347 if (ctx->state != STATE_STATUS_LINE) {
349 *sline = ctx->sl;
359 status = run_machine(bkt, ctx);
360 if (ctx->state == STATE_HEADERS) {
361 *sline = ctx->sl;
375 response_context_t *ctx = bucket->data;
378 rv = wait_for_body(bucket, ctx);
387 rv = serf_bucket_read(ctx->body, requested, data, len);
392 if (ctx->chunked) {
393 ctx->state = STATE_TRAILERS;
397 ctx->state = STATE_DONE;
407 response_context_t *ctx = bucket->data;
410 rv = wait_for_body(bucket, ctx);
416 return serf_bucket_readline(ctx->body, acceptable, found, data, len);
421 response_context_t *ctx = bucket->data;
430 SERF_HTTP_VERSION_MAJOR(ctx->sl.version),
431 SERF_HTTP_VERSION_MINOR(ctx->sl.version),
432 ctx->sl.code);
436 bkt = serf_bucket_simple_copy_create(ctx->sl.reason, strlen(ctx->sl.reason),
444 serf_bucket_aggregate_append(bucket, ctx->headers);
445 serf_bucket_aggregate_append(bucket, ctx->stream);
447 serf_bucket_mem_free(bucket->allocator, ctx);