You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Jason Funk <ja...@gmail.com> on 2011/07/12 21:29:17 UTC
Get filename out of a file bucket
This seems like it should be trival but it isn't working for
me. Relevant code snippets:
char * outfn; //apr_palloced later
> ...
> while ((b = APR_BRIGADE_FIRST(bb)) != APR_BRIGADE_SENTINEL(bb)) {
> bytes=0;
> if(APR_BUCKET_IS_FILE(b)){ //we should handle file buckets
> specially
> rv = apr_file_name_get((const char
> **)&outfn,((apr_bucket_file *)b)->fd);
> if (rv != APR_SUCCESS){
> //failed
> ....
> }else{
> //success
> ....
> }
> }else{
> rv = apr_bucket_read(b, &buf, &bytes, APR_BLOCK_READ);
> }
> ...
> }
>
If I am passed a file bucket, I don't need to read the bucket because the
only reason I'm reading the bucket is to write it to a file anyways so I
just want to switch my outfn from the temporary file I created to the file
buckets filename. I use apr_file_name_get() to get the file name but it's
just returning junk (with APR_SUCCESS return value). Outputting the
resulting file yields "Switching outfn to '0��!���!'"
What am I doing wrong?
Thanks,
Jason
Re: Get filename out of a file bucket
Posted by Jason Funk <ja...@gmail.com>.
For the sake of posterity, I will answer my own question.
I was casting my bucket into a file bucket and trying to access it. This was
incorrect. I needed to cast the data member of the bucket to the file
bucket.
Change this line:
> rv = apr_file_name_get((const char **)&outfn,((apr_bucket_file *)b)->fd);
To this:
> rv = apr_file_name_get((const char **)&outfn,((apr_bucket_file
> *)b->data)->fd);
Jason
On Tue, Jul 19, 2011 at 12:19 PM, Jason Funk <ja...@gmail.com> wrote:
> bump ;)
>
>
> On Tue, Jul 12, 2011 at 2:29 PM, Jason Funk <ja...@gmail.com> wrote:
>
>> This seems like it should be trival but it isn't working for
>> me. Relevant code snippets:
>>
>> char * outfn; //apr_palloced later
>>> ...
>>> while ((b = APR_BRIGADE_FIRST(bb)) != APR_BRIGADE_SENTINEL(bb)) {
>>> bytes=0;
>>> if(APR_BUCKET_IS_FILE(b)){ //we should handle file buckets
>>> specially
>>> rv = apr_file_name_get((const char
>>> **)&outfn,((apr_bucket_file *)b)->fd);
>>> if (rv != APR_SUCCESS){
>>> //failed
>>> ....
>>> }else{
>>> //success
>>> ....
>>> }
>>> }else{
>>> rv = apr_bucket_read(b, &buf, &bytes, APR_BLOCK_READ);
>>> }
>>> ...
>>> }
>>>
>>
>>
>> If I am passed a file bucket, I don't need to read the bucket because the
>> only reason I'm reading the bucket is to write it to a file anyways so I
>> just want to switch my outfn from the temporary file I created to the file
>> buckets filename. I use apr_file_name_get() to get the file name but it's
>> just returning junk (with APR_SUCCESS return value). Outputting the
>> resulting file yields "Switching outfn to '0��!���!'"
>>
>> What am I doing wrong?
>>
>> Thanks,
>> Jason
>>
>>
>
Re: Get filename out of a file bucket
Posted by Jason Funk <ja...@gmail.com>.
bump ;)
On Tue, Jul 12, 2011 at 2:29 PM, Jason Funk <ja...@gmail.com> wrote:
> This seems like it should be trival but it isn't working for
> me. Relevant code snippets:
>
> char * outfn; //apr_palloced later
>> ...
>> while ((b = APR_BRIGADE_FIRST(bb)) != APR_BRIGADE_SENTINEL(bb)) {
>> bytes=0;
>> if(APR_BUCKET_IS_FILE(b)){ //we should handle file buckets
>> specially
>> rv = apr_file_name_get((const char
>> **)&outfn,((apr_bucket_file *)b)->fd);
>> if (rv != APR_SUCCESS){
>> //failed
>> ....
>> }else{
>> //success
>> ....
>> }
>> }else{
>> rv = apr_bucket_read(b, &buf, &bytes, APR_BLOCK_READ);
>> }
>> ...
>> }
>>
>
>
> If I am passed a file bucket, I don't need to read the bucket because the
> only reason I'm reading the bucket is to write it to a file anyways so I
> just want to switch my outfn from the temporary file I created to the file
> buckets filename. I use apr_file_name_get() to get the file name but it's
> just returning junk (with APR_SUCCESS return value). Outputting the
> resulting file yields "Switching outfn to '0��!���!'"
>
> What am I doing wrong?
>
> Thanks,
> Jason
>
>