Deleted Added
full compact
headers_buckets.c (253895) headers_buckets.c (262324)
1/* Copyright 2004 Justin Erenkrantz and Greg Stein
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *

--- 6 unchanged lines hidden (view full) ---

15
16#include <stdlib.h>
17
18#include <apr_general.h> /* for strcasecmp() */
19
20#include "serf.h"
21#include "serf_bucket_util.h"
22
1/* Copyright 2004 Justin Erenkrantz and Greg Stein
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *

--- 6 unchanged lines hidden (view full) ---

15
16#include <stdlib.h>
17
18#include <apr_general.h> /* for strcasecmp() */
19
20#include "serf.h"
21#include "serf_bucket_util.h"
22
23#include "serf_private.h" /* for serf__bucket_headers_remove */
23
24
25
24typedef struct header_list {
25 const char *header;
26 const char *value;
27
28 apr_size_t header_size;
29 apr_size_t value_size;
30
31 int alloc_flags;
32#define ALLOC_HEADER 0x0001 /* header lives in our allocator */
33#define ALLOC_VALUE 0x0002 /* value lives in our allocator */
34
35 struct header_list *next;
36} header_list_t;
37
38typedef struct {
39 header_list_t *list;
26typedef struct header_list {
27 const char *header;
28 const char *value;
29
30 apr_size_t header_size;
31 apr_size_t value_size;
32
33 int alloc_flags;
34#define ALLOC_HEADER 0x0001 /* header lives in our allocator */
35#define ALLOC_VALUE 0x0002 /* value lives in our allocator */
36
37 struct header_list *next;
38} header_list_t;
39
40typedef struct {
41 header_list_t *list;
42 header_list_t *last;
40
41 header_list_t *cur_read;
42 enum {
43 READ_START, /* haven't started reading yet */
44 READ_HEADER, /* reading cur_read->header */
45 READ_SEP, /* reading ": " */
46 READ_VALUE, /* reading cur_read->value */
47 READ_CRLF, /* reading "\r\n" */

--- 7 unchanged lines hidden (view full) ---

55
56serf_bucket_t *serf_bucket_headers_create(
57 serf_bucket_alloc_t *allocator)
58{
59 headers_context_t *ctx;
60
61 ctx = serf_bucket_mem_alloc(allocator, sizeof(*ctx));
62 ctx->list = NULL;
43
44 header_list_t *cur_read;
45 enum {
46 READ_START, /* haven't started reading yet */
47 READ_HEADER, /* reading cur_read->header */
48 READ_SEP, /* reading ": " */
49 READ_VALUE, /* reading cur_read->value */
50 READ_CRLF, /* reading "\r\n" */

--- 7 unchanged lines hidden (view full) ---

58
59serf_bucket_t *serf_bucket_headers_create(
60 serf_bucket_alloc_t *allocator)
61{
62 headers_context_t *ctx;
63
64 ctx = serf_bucket_mem_alloc(allocator, sizeof(*ctx));
65 ctx->list = NULL;
66 ctx->last = NULL;
63 ctx->state = READ_START;
64
65 return serf_bucket_create(&serf_bucket_type_headers, allocator, ctx);
66}
67
68void serf_bucket_headers_setx(
69 serf_bucket_t *bkt,
70 const char *header, apr_size_t header_size, int header_copy,
71 const char *value, apr_size_t value_size, int value_copy)
72{
73 headers_context_t *ctx = bkt->data;
67 ctx->state = READ_START;
68
69 return serf_bucket_create(&serf_bucket_type_headers, allocator, ctx);
70}
71
72void serf_bucket_headers_setx(
73 serf_bucket_t *bkt,
74 const char *header, apr_size_t header_size, int header_copy,
75 const char *value, apr_size_t value_size, int value_copy)
76{
77 headers_context_t *ctx = bkt->data;
74 header_list_t *iter = ctx->list;
75 header_list_t *hdr;
76
77#if 0
78 /* ### include this? */
79 if (ctx->cur_read) {
80 /* we started reading. can't change now. */
81 abort();
82 }

--- 17 unchanged lines hidden (view full) ---

100 hdr->value = serf_bstrmemdup(bkt->allocator, value, value_size);
101 hdr->alloc_flags |= ALLOC_VALUE;
102 }
103 else {
104 hdr->value = value;
105 }
106
107 /* Add the new header at the end of the list. */
78 header_list_t *hdr;
79
80#if 0
81 /* ### include this? */
82 if (ctx->cur_read) {
83 /* we started reading. can't change now. */
84 abort();
85 }

--- 17 unchanged lines hidden (view full) ---

103 hdr->value = serf_bstrmemdup(bkt->allocator, value, value_size);
104 hdr->alloc_flags |= ALLOC_VALUE;
105 }
106 else {
107 hdr->value = value;
108 }
109
110 /* Add the new header at the end of the list. */
108 while (iter && iter->next) {
109 iter = iter->next;
110 }
111 if (iter)
112 iter->next = hdr;
111 if (ctx->last)
112 ctx->last->next = hdr;
113 else
114 ctx->list = hdr;
113 else
114 ctx->list = hdr;
115
116 ctx->last = hdr;
115}
116
117void serf_bucket_headers_set(
118 serf_bucket_t *headers_bucket,
119 const char *header,
120 const char *value)
121{
122 serf_bucket_headers_setx(headers_bucket,

--- 63 unchanged lines hidden (view full) ---

186 }
187 }
188 found = found->next;
189 }
190
191 return val;
192}
193
117}
118
119void serf_bucket_headers_set(
120 serf_bucket_t *headers_bucket,
121 const char *header,
122 const char *value)
123{
124 serf_bucket_headers_setx(headers_bucket,

--- 63 unchanged lines hidden (view full) ---

188 }
189 }
190 found = found->next;
191 }
192
193 return val;
194}
195
196void serf__bucket_headers_remove(serf_bucket_t *bucket, const char *header)
197{
198 headers_context_t *ctx = bucket->data;
199 header_list_t *scan = ctx->list, *prev = NULL;
200
201 /* Find and delete all items with the same header (case insensitive) */
202 while (scan) {
203 if (strcasecmp(scan->header, header) == 0) {
204 if (prev) {
205 prev->next = scan->next;
206 } else {
207 ctx->list = scan->next;
208 }
209 if (ctx->last == scan) {
210 ctx->last = NULL;
211 }
212 } else {
213 prev = scan;
214 }
215 scan = scan->next;
216 }
217}
218
194void serf_bucket_headers_do(
195 serf_bucket_t *headers_bucket,
196 serf_bucket_headers_do_callback_fn_t func,
197 void *baton)
198{
199 headers_context_t *ctx = headers_bucket->data;
200 header_list_t *scan = ctx->list;
201

--- 230 unchanged lines hidden ---
219void serf_bucket_headers_do(
220 serf_bucket_t *headers_bucket,
221 serf_bucket_headers_do_callback_fn_t func,
222 void *baton)
223{
224 headers_context_t *ctx = headers_bucket->data;
225 header_list_t *scan = ctx->list;
226

--- 230 unchanged lines hidden ---