Lines Matching refs:ctx

68     frame_context_t *ctx;
70 ctx = serf_bucket_mem_alloc(allocator, sizeof(*ctx));
71 ctx->type = 0;
72 ctx->open = 0;
73 ctx->channel = channel;
74 ctx->phrase = "CLOSED";
75 ctx->headers = serf_bucket_headers_create(allocator);
77 return serf_bucket_create(&serf_bucket_type_bwtp_frame, allocator, ctx);
85 frame_context_t *ctx;
87 ctx = serf_bucket_mem_alloc(allocator, sizeof(*ctx));
88 ctx->type = 0;
89 ctx->open = 1;
90 ctx->channel = channel;
91 ctx->phrase = uri;
92 ctx->headers = serf_bucket_headers_create(allocator);
94 return serf_bucket_create(&serf_bucket_type_bwtp_frame, allocator, ctx);
102 frame_context_t *ctx;
104 ctx = serf_bucket_mem_alloc(allocator, sizeof(*ctx));
105 ctx->type = 0;
106 ctx->open = 0;
107 ctx->channel = channel;
108 ctx->phrase = phrase;
109 ctx->headers = serf_bucket_headers_create(allocator);
111 return serf_bucket_create(&serf_bucket_type_bwtp_frame, allocator, ctx);
119 frame_context_t *ctx;
121 ctx = serf_bucket_mem_alloc(allocator, sizeof(*ctx));
122 ctx->type = 1;
123 ctx->open = 0;
124 ctx->channel = channel;
125 ctx->phrase = "MESSAGE";
126 ctx->headers = serf_bucket_headers_create(allocator);
128 return serf_bucket_create(&serf_bucket_type_bwtp_frame, allocator, ctx);
135 frame_context_t *ctx = bucket->data;
137 return ctx->channel;
140 incoming_context_t *ctx = bucket->data;
142 return ctx->channel;
152 frame_context_t *ctx = bucket->data;
154 return ctx->type;
157 incoming_context_t *ctx = bucket->data;
159 return ctx->type;
169 frame_context_t *ctx = bucket->data;
171 return ctx->phrase;
174 incoming_context_t *ctx = bucket->data;
176 return ctx->phrase;
186 frame_context_t *ctx = bucket->data;
188 return ctx->headers;
191 incoming_context_t *ctx = bucket->data;
193 return ctx->headers;
221 frame_context_t *ctx = bucket->data;
228 req_len = apr_snprintf(ctx->req_line, sizeof(ctx->req_line),
230 (ctx->type ? "BWM" : "BWH"),
231 ctx->channel, calc_header_size(ctx->headers),
232 (ctx->open ? "OPEN " : ""),
233 ctx->phrase);
234 new_bucket = serf_bucket_simple_copy_create(ctx->req_line, req_len,
246 serf_bucket_aggregate_append(bucket, ctx->headers);
251 serf_bucket_mem_free(bucket->allocator, ctx);
317 incoming_context_t *ctx;
319 ctx = serf_bucket_mem_alloc(allocator, sizeof(*ctx));
320 ctx->stream = stream;
321 ctx->body = NULL;
322 ctx->headers = serf_bucket_headers_create(allocator);
323 ctx->state = STATE_STATUS_LINE;
324 ctx->length = 0;
325 ctx->channel = -1;
326 ctx->phrase = NULL;
328 serf_linebuf_init(&ctx->linebuf);
330 return serf_bucket_create(&serf_bucket_type_bwtp_incoming_frame, allocator, ctx);
335 incoming_context_t *ctx = bucket->data;
337 if (ctx->state != STATE_STATUS_LINE && ctx->phrase) {
338 serf_bucket_mem_free(bucket->allocator, (void*)ctx->phrase);
341 serf_bucket_destroy(ctx->stream);
342 if (ctx->body != NULL)
343 serf_bucket_destroy(ctx->body);
344 serf_bucket_destroy(ctx->headers);
349 static apr_status_t fetch_line(incoming_context_t *ctx, int acceptable)
351 return serf_linebuf_fetch(&ctx->linebuf, ctx->stream, acceptable);
354 static apr_status_t parse_status_line(incoming_context_t *ctx,
360 /* ctx->linebuf.line should be of form: BW* */
361 res = apr_date_checkmask(ctx->linebuf.line, "BW*");
367 if (ctx->linebuf.line[2] == 'H') {
368 ctx->type = 0;
370 else if (ctx->linebuf.line[2] == 'M') {
371 ctx->type = 1;
374 ctx->type = -1;
377 ctx->channel = apr_strtoi64(ctx->linebuf.line + 3, &reason, 16);
384 ctx->length = apr_strtoi64(reason, &reason, 16);
387 if (reason - ctx->linebuf.line < ctx->linebuf.used) {
392 ctx->phrase = serf_bstrmemdup(allocator, reason,
393 ctx->linebuf.used
394 - (reason - ctx->linebuf.line));
396 ctx->phrase = NULL;
403 static apr_status_t fetch_headers(serf_bucket_t *bkt, incoming_context_t *ctx)
410 status = fetch_line(ctx, SERF_NEWLINE_ANY);
416 if (ctx->linebuf.state == SERF_LINEBUF_READY && ctx->linebuf.used) {
420 end_key = c = memchr(ctx->linebuf.line, ':', ctx->linebuf.used);
433 ctx->headers,
434 ctx->linebuf.line, end_key - ctx->linebuf.line, 1,
435 c, ctx->linebuf.line + ctx->linebuf.used - c, 1);
449 static apr_status_t run_machine(serf_bucket_t *bkt, incoming_context_t *ctx)
453 switch (ctx->state) {
458 status = fetch_line(ctx, SERF_NEWLINE_ANY);
462 if (ctx->linebuf.state == SERF_LINEBUF_READY && ctx->linebuf.used) {
464 status = parse_status_line(ctx, bkt->allocator);
468 if (ctx->length) {
469 ctx->body =
470 serf_bucket_barrier_create(ctx->stream, bkt->allocator);
471 ctx->body = serf_bucket_limit_create(ctx->body, ctx->length,
473 if (!ctx->type) {
474 ctx->state = STATE_HEADERS;
476 ctx->state = STATE_BODY;
479 ctx->state = STATE_DONE;
493 status = fetch_headers(ctx->body, ctx);
500 if (ctx->linebuf.state == SERF_LINEBUF_READY && !ctx->linebuf.used) {
502 ctx->state = STATE_DONE;
518 static apr_status_t wait_for_body(serf_bucket_t *bkt, incoming_context_t *ctx)
523 while (ctx->state != STATE_BODY) {
524 status = run_machine(bkt, ctx);
540 incoming_context_t *ctx = bucket->data;
542 return wait_for_body(bucket, ctx);
549 incoming_context_t *ctx = bucket->data;
552 rv = wait_for_body(bucket, ctx);
561 rv = serf_bucket_read(ctx->body, requested, data, len);
563 ctx->state = STATE_DONE;
572 incoming_context_t *ctx = bucket->data;
575 rv = wait_for_body(bucket, ctx);
581 return serf_bucket_readline(ctx->body, acceptable, found, data, len);