On 01/01/2018 10:44 PM, Eric Covener wrote: > On Mon, Jan 1, 2018 at 8:37 AM, Simon Walter <simon@xxxxxxxxxx> wrote: >> I am interested in how apr_bucket_split(e, point) works. >> >> It seems that after splitting e, it still contains everything after >> point. Only when flattened is this data "removed" from e. >> >> If that is correct, then is it also correct to assume that I would need >> to use apr_bucket_read with snprintf and make a copy of the data in >> order to display it accurately? >> >> Is there another way to show the contents of buckets after they've been >> split/manipulated? >> >> I need to flatten the brigade (or flush it to a socket? that's a >> different question), but for debugging purposes, to check my logic, I am >> trying to see the contents of individual buckets. >> > > I don't think that's right. For example mod_substitute does this to > remove the pattern that matched from the input: > > #define SEDRMPATBCKT(b, offset, tmp_b, patlen) do { \ > apr_bucket_split(b, offset); \ > tmp_b = APR_BUCKET_NEXT(b); \ > apr_bucket_split(tmp_b, patlen); \ > b = APR_BUCKET_NEXT(tmp_b); \ > apr_bucket_delete(tmp_b); \ > } while (0) > > > The dump_brigade macro in .gdbinit in the source tree will help here. > You can also use the code there to add your own trace. > I see such code as the example you gave in various places. However, this bit of code (attached) shows me that I cannot simply printf the data. Again, I am probably doing something wrong.
#include <stdlib.h> #include <linux/limits.h> #include <apr-1.0/apr_buckets.h> int main(int ArgCount, char * Arg[]) { apr_initialize(); atexit(apr_terminate); apr_pool_t * Pool; apr_pool_create(&Pool, NULL); apr_bucket_alloc_t * BucketAlloc = apr_bucket_alloc_create(Pool); apr_bucket_brigade * Brigade = apr_brigade_create(Pool, BucketAlloc); char * String0 = "_ASCII_String0_!"; apr_bucket * Bucket0 = apr_bucket_immortal_create(String0, strlen(String0), BucketAlloc); APR_BRIGADE_INSERT_TAIL(Brigade, Bucket0); char * String1 = "_ASCII_String1_!"; apr_bucket * Bucket1 = apr_bucket_immortal_create(String1, strlen(String1), BucketAlloc); APR_BRIGADE_INSERT_TAIL(Brigade, Bucket1); char * String2 = "_ASCII_String2_!"; apr_bucket * Bucket2 = apr_bucket_immortal_create(String2, strlen(String2), BucketAlloc); APR_BRIGADE_INSERT_TAIL(Brigade, Bucket2); char * String3 = "_ASCII_String3_!"; apr_bucket * Bucket3 = apr_bucket_immortal_create(String3, strlen(String3), BucketAlloc); APR_BRIGADE_INSERT_TAIL(Brigade, Bucket3); apr_bucket * Index; apr_bucket * NextBucket; apr_bucket * PrevBucket; const char * TestBuffer = NULL; int Marker = 0; size_t Length = 0; for (Index = APR_BRIGADE_FIRST(Brigade); Index != APR_BRIGADE_SENTINEL(Brigade); Index = APR_BUCKET_NEXT(Index)) { printf("Marker: %d\n", Marker); if (Marker == 1) { char * String4 = "_ASCII_String4_!"; apr_bucket * Bucket4 = apr_bucket_immortal_create(String4, strlen(String4), BucketAlloc); apr_bucket_split(Index, 1); APR_BUCKET_INSERT_AFTER(Index, Bucket4); } TestBuffer = NULL; Length = 0; if (apr_bucket_read(Index, &TestBuffer, &Length, APR_BLOCK_READ) == APR_SUCCESS) { printf("CurrBucket: %s\n", TestBuffer); printf("Length: %zu\n", Length); } NextBucket = APR_BUCKET_NEXT(Index); TestBuffer = NULL; Length = 0; if (NextBucket != APR_BRIGADE_SENTINEL(Brigade) && apr_bucket_read(NextBucket, &TestBuffer, &Length, APR_BLOCK_READ) == APR_SUCCESS) { printf("NextBucket: %s\n", TestBuffer); printf("Length: %zu\n", Length); } PrevBucket = APR_BUCKET_PREV(Index); TestBuffer = NULL; if (PrevBucket != APR_BRIGADE_SENTINEL(Brigade) && apr_bucket_read(PrevBucket, &TestBuffer, &Length, APR_BLOCK_READ) == APR_SUCCESS) { printf("PrevBucket: %s\n", TestBuffer); printf("Length: %zu\n", Length); } Marker++; } char * Output = NULL; apr_size_t OutputLength; apr_brigade_pflatten(Brigade, &Output, &OutputLength, Pool); printf("output: %s\n", Output); apr_pool_destroy(Pool); }
--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx