| 569 | */ |
| 570 | |
| 571 | char * /* O - Decoded string */ |
| 572 | httpDecode64_2(char *out, /* I - String to write to */ |
| 573 | int *outlen, /* IO - Size of output string */ |
| 574 | const char *in) /* I - String to read from */ |
| 575 | { |
| 576 | int pos; /* Bit position */ |
| 577 | unsigned base64; /* Value of this character */ |
| 578 | char *outptr, /* Output pointer */ |
| 579 | *outend; /* End of output buffer */ |
| 580 | |
| 581 | |
| 582 | /* |
| 583 | * Range check input... |
| 584 | */ |
| 585 | |
| 586 | if (!out || !outlen || *outlen < 1 || !in) |
| 587 | return (NULL); |
| 588 | |
| 589 | if (!*in) |
| 590 | { |
| 591 | *out = '\0'; |
| 592 | *outlen = 0; |
| 593 | |
| 594 | return (out); |
| 595 | } |
| 596 | |
| 597 | /* |
| 598 | * Convert from base-64 to bytes... |
| 599 | */ |
| 600 | |
| 601 | for (outptr = out, outend = out + *outlen - 1, pos = 0; *in != '\0'; in ++) |
| 602 | { |
| 603 | /* |
| 604 | * Decode this character into a number from 0 to 63... |
| 605 | */ |
| 606 | |
| 607 | if (*in >= 'A' && *in <= 'Z') |
| 608 | base64 = (unsigned)(*in - 'A'); |
| 609 | else if (*in >= 'a' && *in <= 'z') |
| 610 | base64 = (unsigned)(*in - 'a' + 26); |
| 611 | else if (*in >= '0' && *in <= '9') |
| 612 | base64 = (unsigned)(*in - '0' + 52); |
| 613 | else if (*in == '+') |
| 614 | base64 = 62; |
| 615 | else if (*in == '/') |
| 616 | base64 = 63; |
| 617 | else if (*in == '=') |
| 618 | break; |
| 619 | else |
| 620 | continue; |
| 621 | |
| 622 | /* |
| 623 | * Store the result in the appropriate chars... |
| 624 | */ |
| 625 | |
| 626 | switch (pos) |
| 627 | { |
| 628 | case 0 : |
no outgoing calls