~ubuntu-branches/ubuntu/trusty/serf/trusty-security

« back to all changes in this revision

Viewing changes to buckets/aggregate_buckets.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter Samuelson
  • Date: 2011-06-03 03:18:07 UTC
  • mfrom: (1.2.4 upstream)
  • mto: (3.3.1 sid)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: james.westby@ubuntu.com-20110603031807-3vq82t5lzw692our
Tags: 0.7.2-1
* New upstream release.
  - patches/no-export-vars: delete, now upstream.
* New ABI:
  - patches/abi-0.x: New patch to change upstream SONAME.
  - Rename libserf-0-0 to libserf0.7.
  - Rename libserf-0-0-dev to libserf-dev while we're at it.
* Policy 3.9.1: one instance of s/Conflicts/Breaks/.
* "Upgrade" to source format 1.0.
* Add some Depends: ${misc:Depends}; thanks, Lintian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
    /* Marks if a snapshot is set. */
32
32
    int snapshot; 
 
33
    serf_bucket_aggregate_eof_t hold_open;
 
34
    void *hold_open_baton;
 
35
    /* Does this bucket own its children? !0 if yes, 0 if not. */
 
36
    int bucket_owner;
33
37
} aggregate_context_t;
34
38
 
35
39
 
49
53
    while (ctx->done != NULL) {
50
54
        next_list = ctx->done->next;
51
55
 
52
 
        serf_bucket_destroy(ctx->done->bucket);
 
56
        if (ctx->bucket_owner) {
 
57
            serf_bucket_destroy(ctx->done->bucket);
 
58
        }
53
59
        serf_bucket_mem_free(allocator, ctx->done);
54
60
 
55
61
        ctx->done = next_list;
56
62
    }
57
63
}
58
64
 
59
 
SERF_DECLARE(serf_bucket_t *) serf_bucket_aggregate_create(
 
65
void serf_bucket_aggregate_cleanup(
 
66
    serf_bucket_t *bucket, serf_bucket_alloc_t *allocator)
 
67
{
 
68
    aggregate_context_t *ctx = bucket->data;
 
69
 
 
70
    cleanup_aggregate(ctx, allocator);
 
71
}
 
72
 
 
73
static aggregate_context_t *create_aggregate(serf_bucket_alloc_t *allocator)
 
74
{
 
75
    aggregate_context_t *ctx;
 
76
 
 
77
    ctx = serf_bucket_mem_alloc(allocator, sizeof(*ctx));
 
78
 
 
79
    ctx->list = NULL;
 
80
    ctx->last = NULL;
 
81
    ctx->done = NULL;
 
82
    ctx->snapshot = 0;
 
83
    ctx->hold_open = NULL;
 
84
    ctx->hold_open_baton = NULL;
 
85
        ctx->bucket_owner = 1;
 
86
 
 
87
    return ctx;
 
88
}
 
89
 
 
90
serf_bucket_t *serf_bucket_aggregate_create(
60
91
    serf_bucket_alloc_t *allocator)
61
92
{
62
93
    aggregate_context_t *ctx;
63
94
 
64
 
    ctx = serf_bucket_mem_alloc(allocator, sizeof(*ctx));
65
 
    ctx->list = NULL;
66
 
    ctx->done = NULL;
67
 
    ctx->snapshot = 0;
 
95
    ctx = create_aggregate(allocator);
68
96
 
69
97
    return serf_bucket_create(&serf_bucket_type_aggregate, allocator, ctx);
70
98
}
71
99
 
 
100
serf_bucket_t *serf__bucket_stream_create(
 
101
    serf_bucket_alloc_t *allocator,
 
102
    serf_bucket_aggregate_eof_t fn,
 
103
    void *baton)
 
104
{
 
105
    serf_bucket_t *bucket = serf_bucket_aggregate_create(allocator);
 
106
    aggregate_context_t *ctx = bucket->data;
 
107
 
 
108
    serf_bucket_aggregate_hold_open(bucket, fn, baton);
 
109
 
 
110
    ctx->bucket_owner = 0;
 
111
 
 
112
    return bucket;
 
113
}
 
114
 
 
115
 
72
116
static void serf_aggregate_destroy_and_data(serf_bucket_t *bucket)
73
117
{
74
118
    aggregate_context_t *ctx = bucket->data;
75
119
    bucket_list_t *next_ctx;
76
120
 
77
121
    while (ctx->list) {
78
 
        serf_bucket_destroy(ctx->list->bucket);
 
122
        if (ctx->bucket_owner) {
 
123
            serf_bucket_destroy(ctx->list->bucket);
 
124
        }
79
125
        next_ctx = ctx->list->next;
80
126
        serf_bucket_mem_free(bucket->allocator, ctx->list);
81
127
        ctx->list = next_ctx;
85
131
    serf_default_destroy_and_data(bucket);
86
132
}
87
133
 
88
 
SERF_DECLARE(void) serf_bucket_aggregate_become(serf_bucket_t *bucket)
 
134
void serf_bucket_aggregate_become(serf_bucket_t *bucket)
89
135
{
90
136
    aggregate_context_t *ctx;
91
137
 
92
 
    ctx = serf_bucket_mem_alloc(bucket->allocator, sizeof(*ctx));
93
 
    ctx->list = NULL;
94
 
    ctx->last = NULL;
95
 
    ctx->done = NULL;
96
 
    ctx->snapshot = 0;
 
138
    ctx = create_aggregate(bucket->allocator);
97
139
 
98
140
    bucket->type = &serf_bucket_type_aggregate;
99
141
    bucket->data = ctx;
102
144
}
103
145
 
104
146
 
105
 
SERF_DECLARE(void) serf_bucket_aggregate_prepend(
 
147
void serf_bucket_aggregate_prepend(
106
148
    serf_bucket_t *aggregate_bucket,
107
149
    serf_bucket_t *prepend_bucket)
108
150
{
117
159
    ctx->list = new_list;
118
160
}
119
161
 
120
 
SERF_DECLARE(void) serf_bucket_aggregate_append(
 
162
void serf_bucket_aggregate_append(
121
163
    serf_bucket_t *aggregate_bucket,
122
164
    serf_bucket_t *append_bucket)
123
165
{
135
177
    */
136
178
    if (ctx->list == NULL) {
137
179
        ctx->list = new_list;
138
 
        ctx->last = new_list;
 
180
        ctx->last = new_list;
139
181
    }
140
182
    else {
141
183
        ctx->last->next = new_list;
142
 
        ctx->last = ctx->last->next;
 
184
        ctx->last = ctx->last->next;
143
185
    }
144
186
}
145
187
 
146
 
SERF_DECLARE(void) serf_bucket_aggregate_prepend_iovec(
 
188
void serf_bucket_aggregate_hold_open(serf_bucket_t *aggregate_bucket, 
 
189
                                     serf_bucket_aggregate_eof_t fn,
 
190
                                     void *baton)
 
191
{
 
192
    aggregate_context_t *ctx = aggregate_bucket->data;
 
193
    ctx->hold_open = fn;
 
194
    ctx->hold_open_baton = baton;
 
195
}
 
196
 
 
197
void serf_bucket_aggregate_prepend_iovec(
147
198
    serf_bucket_t *aggregate_bucket,
148
199
    struct iovec *vecs,
149
200
    int vecs_count)
164
215
    }
165
216
}
166
217
 
167
 
SERF_DECLARE(void) serf_bucket_aggregate_append_iovec(
 
218
void serf_bucket_aggregate_append_iovec(
168
219
    serf_bucket_t *aggregate_bucket,
169
220
    struct iovec *vecs,
170
221
    int vecs_count)
195
246
    *vecs_used = 0;
196
247
 
197
248
    if (!ctx->list) {
198
 
        return APR_EOF;
 
249
        if (ctx->hold_open) {
 
250
            return ctx->hold_open(ctx->hold_open_baton, bucket);
 
251
        }
 
252
        else {
 
253
            return APR_EOF;
 
254
        }
199
255
    }
200
256
 
201
257
    while (1) {
235
291
 
236
292
            /* If we have no more in our list, return EOF. */
237
293
            if (!ctx->list) {
238
 
                return status;
 
294
                if (ctx->hold_open) {
 
295
                    return ctx->hold_open(ctx->hold_open_baton, bucket);
 
296
                }
 
297
                else {
 
298
                    return APR_EOF;
 
299
                }
239
300
            }
240
301
 
241
302
            /* At this point, it safe to read the next bucket - if we can. */
400
461
    return ctx->snapshot;
401
462
}
402
463
 
403
 
SERF_DECLARE_DATA const serf_bucket_type_t serf_bucket_type_aggregate = {
 
464
const serf_bucket_type_t serf_bucket_type_aggregate = {
404
465
    "AGGREGATE",
405
466
    serf_aggregate_read,
406
467
    serf_aggregate_readline,