services/geocaching/src/base64.c
/**
 * base64_decode - Base64 decode
 * @src: Data to be decoded
 * @len: Length of the data to be decoded
 * @out_len: Pointer to output length variable
 * Returns: Allocated buffer of out_len bytes of decoded data,
 * or %NULL on failure
 *
 * Caller is responsible for freeing the returned buffer.
 */
Base64 decode
@src: Data to be decoded
@len: Length of the data to be decoded
@out_len: Pointer to output length variable
Returns: Allocated buffer of out_len bytes of decoded data,
or %NULL on failure

Caller is responsible for freeing the returned buffer.
Base64 decode @src : Data to be decoded @len : Length of the data to be decoded @out_len : Pointer to output length variable Returns : Allocated buffer of out_len bytes of decoded data or %NULL on failure Caller is responsible for freeing the returned buffer .
unsigned char * base64_decode(const unsigned char *src, size_t len,
                              size_t *out_len)
{
    unsigned char dtable[256], *out, *pos, block[4], tmp;
    size_t i, count, olen;
    int pad = 0;
    memset(dtable, 0x80, 256);
    for (i = 0; i < sizeof(base64_table) - 1; i++)
        dtable[base64_table[i]] = (unsigned char) i;
    dtable['='] = 0;
    count = 0;
    for (i = 0; i < len; i++) {
        if (dtable[src[i]] != 0x80)
            count++;
    }
    if (count == 0 || count % 4)
        return NULL;
    olen = count / 4 * 3;
    pos = out = malloc(olen);
    if (out == NULL)
        return NULL;
    count = 0;
    for (i = 0; i < len; i++) {
        tmp = dtable[src[i]];
        if (tmp == 0x80)
            continue;
        if (src[i] == '=')
            pad++;
        block[count] = tmp;
        count++;
        if (count == 4) {
            *pos++ = (block[0] << 2) | (block[1] >> 4);
            *pos++ = (block[1] << 4) | (block[2] >> 2);
            *pos++ = (block[2] << 6) | block[3];
            count = 0;
            if (pad) {
                if (pad == 1)
                    pos--;
                else if (pad == 2)
                    pos -= 2;
                else {
                    free(out);
                    return NULL;
                }
                break;
            }
        }
    }
    *out_len = pos - out;
    return out;
}
unsigned char * base64_decode ( const unsigned char * src , size_t len , size_t * out_len ) { unsigned char dtable [ 256 ] , * out , * pos , block [ 4 ] , tmp ; size_t i , count , olen ; int pad = 0 ; memset ( dtable , 0x80 , 256 ) ; for ( i = 0 ; i < sizeof ( base64_table ) - 1 ; i ++ ) dtable [ base64_table [ i ] ] = ( unsigned char ) i ; dtable [ ' ' ] = 0 ; count = 0 ; for ( i = 0 ; i < len ; i ++ ) { if ( dtable [ src [ i ] ] != 0x80 ) count ++ ; } if ( count == 0 || count % 4 ) return NULL ; olen = count / 4 * 3 ; pos = out = malloc ( olen ) ; if ( out == NULL ) return NULL ; count = 0 ; for ( i = 0 ; i < len ; i ++ ) { tmp = dtable [ src [ i ] ] ; if ( tmp == 0x80 ) continue ; if ( src [ i ] == ' ' ) pad ++ ; block [ count ] = tmp ; count ++ ; if ( count == 4 ) { * pos ++ = ( block [ 0 ] << 2 ) | ( block [ 1 ] >> 4 ) ; * pos ++ = ( block [ 1 ] << 4 ) | ( block [ 2 ] >> 2 ) ; * pos ++ = ( block [ 2 ] << 6 ) | block [ 3 ] ; count = 0 ; if ( pad ) { if ( pad == 1 ) pos -- ; else if ( pad == 2 ) pos -= 2 ; else { free ( out ) ; return NULL ; } break ; } } } * out_len = pos - out ; return out ; }
base64_decode - Base64 decode
 @src: Data to be decoded
 @len: Length of the data to be decoded
 @out_len: Pointer to output length variable
 Returns: Allocated buffer of out_len bytes of decoded data,
 or %NULL on failure
base64_decode - Base64 decode @src : Data to be decoded @len : Length of the data to be decoded @out_len : Pointer to output length variable Returns : Allocated buffer of out_len bytes of decoded data or %NULL on failure
/* Invalid padding */