| 688 | */ |
| 689 | |
| 690 | char * /* O - Encoded string */ |
| 691 | httpEncode64_2(char *out, /* I - String to write to */ |
| 692 | int outlen, /* I - Maximum size of output string */ |
| 693 | const char *in, /* I - String to read from */ |
| 694 | int inlen) /* I - Size of input string */ |
| 695 | { |
| 696 | char *outptr, /* Output pointer */ |
| 697 | *outend; /* End of output buffer */ |
| 698 | static const char base64[] = /* Base64 characters... */ |
| 699 | { |
| 700 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 701 | "abcdefghijklmnopqrstuvwxyz" |
| 702 | "0123456789" |
| 703 | "+/" |
| 704 | }; |
| 705 | |
| 706 | |
| 707 | /* |
| 708 | * Range check input... |
| 709 | */ |
| 710 | |
| 711 | if (!out || outlen < 1 || !in) |
| 712 | return (NULL); |
| 713 | |
| 714 | /* |
| 715 | * Convert bytes to base-64... |
| 716 | */ |
| 717 | |
| 718 | for (outptr = out, outend = out + outlen - 1; inlen > 0; in ++, inlen --) |
| 719 | { |
| 720 | /* |
| 721 | * Encode the up to 3 characters as 4 Base64 numbers... |
| 722 | */ |
| 723 | |
| 724 | if (outptr < outend) |
| 725 | *outptr ++ = base64[(in[0] & 255) >> 2]; |
| 726 | |
| 727 | if (outptr < outend) |
| 728 | { |
| 729 | if (inlen > 1) |
| 730 | *outptr ++ = base64[(((in[0] & 255) << 4) | ((in[1] & 255) >> 4)) & 63]; |
| 731 | else |
| 732 | *outptr ++ = base64[(in[0] << 4) & 63]; |
| 733 | } |
| 734 | |
| 735 | in ++; |
| 736 | inlen --; |
| 737 | if (inlen <= 0) |
| 738 | { |
| 739 | if (outptr < outend) |
| 740 | *outptr ++ = '='; |
| 741 | if (outptr < outend) |
| 742 | *outptr ++ = '='; |
| 743 | break; |
| 744 | } |
| 745 | |
| 746 | if (outptr < outend) |
| 747 | { |
no outgoing calls