| 3572 | |
| 3573 | |
| 3574 | dsc* evlEncodeDecode64(thread_db* tdbb, bool encodeFlag, const SysFunction* function, const NestValueArray& args, impure_value* impure) |
| 3575 | { |
| 3576 | const dsc* arg = EVL_expr(tdbb, tdbb->getRequest(), args[0]); |
| 3577 | if (!arg) // return NULL if value is NULL |
| 3578 | return NULL; |
| 3579 | |
| 3580 | UCharBuffer in; |
| 3581 | if (arg->isBlob()) |
| 3582 | { |
| 3583 | AutoPtr<blb> blob(blb::open2(tdbb, tdbb->getRequest()->req_transaction, reinterpret_cast<const bid*>(arg->dsc_address), |
| 3584 | sizeof(streamBpb), streamBpb)); |
| 3585 | |
| 3586 | UCHAR buf[4096]; |
| 3587 | in.clear(); |
| 3588 | for(;;) |
| 3589 | { |
| 3590 | const unsigned l = blob->BLB_get_data(tdbb, buf, sizeof buf, false); |
| 3591 | if (!l) |
| 3592 | break; |
| 3593 | in.append(buf, l); |
| 3594 | } |
| 3595 | |
| 3596 | blob->BLB_close(tdbb); |
| 3597 | blob.release(); |
| 3598 | } |
| 3599 | else |
| 3600 | { |
| 3601 | unsigned len; |
| 3602 | const UCHAR* ptr = CVT_get_bytes(arg, len); |
| 3603 | in.assign(ptr, len); |
| 3604 | } |
| 3605 | |
| 3606 | UCharBuffer out; |
| 3607 | unsigned long outLen = encodeFlag ? encodeLen(in.getCount()) + 1 : decodeLen(in.getCount()); |
| 3608 | auto* func = encodeFlag ? base64_encode : base64_decode; |
| 3609 | tomCheck(func(in.begin(), in.getCount(), out.getBuffer(outLen), &outLen), |
| 3610 | Arg::Gds(encodeFlag ? isc_tom_encode : isc_tom_decode) << "BASE64"); |
| 3611 | out.resize(outLen); |
| 3612 | |
| 3613 | dsc result; |
| 3614 | unsigned len = encodeLen(arg->getStringLength()); |
| 3615 | if (arg->isBlob() || (encodeFlag && len > MAX_VARY_COLUMN_SIZE)) |
| 3616 | { |
| 3617 | AutoPtr<blb> blob(blb::create2(tdbb, tdbb->getRequest()->req_transaction, &impure->vlu_misc.vlu_bid, |
| 3618 | sizeof(streamBpb), streamBpb)); |
| 3619 | blob->BLB_put_data(tdbb, out.begin(), out.getCount()); |
| 3620 | blob->BLB_close(tdbb); |
| 3621 | blob.release(); |
| 3622 | |
| 3623 | result.makeBlob(encodeFlag ? isc_blob_text : isc_blob_untyped, encodeFlag ? ttype_ascii : ttype_binary, |
| 3624 | (ISC_QUAD*)&impure->vlu_misc.vlu_bid); |
| 3625 | } |
| 3626 | else |
| 3627 | result.makeText(out.getCount(), encodeFlag ? ttype_ascii : ttype_binary, const_cast<UCHAR*>(out.begin())); |
| 3628 | |
| 3629 | EVL_make_value(tdbb, &result, impure); |
| 3630 | return &impure->vlu_desc; |
| 3631 | } |
no test coverage detected