| 1 | #ifndef MYSQL_SERVICE_BASE64_INCLUDED |
| 2 | /* Copyright (c) 2017, MariaDB |
| 3 | |
| 4 | This program is free software; you can redistribute it and/or modify |
| 5 | it under the terms of the GNU General Public License as published by |
| 6 | the Free Software Foundation; version 2 of the License. |
| 7 | |
| 8 | This program is distributed in the hope that it will be useful, |
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | GNU General Public License for more details. |
| 12 | |
| 13 | You should have received a copy of the GNU General Public License |
| 14 | along with this program; if not, write to the Free Software |
| 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 16 | |
| 17 | /** |
| 18 | @file |
| 19 | my base64 service |
| 20 | |
| 21 | Functions for base64 en- and decoding |
| 22 | */ |
| 23 | |
| 24 | #ifdef __cplusplus |
| 25 | extern "C" { |
| 26 | #endif |
| 27 | |
| 28 | #ifndef MYSQL_ABI_CHECK |
| 29 | #include <stdlib.h> |
| 30 | #endif |
| 31 | |
| 32 | /* Allow multuple chunks 'AAA= AA== AA==', binlog uses this */ |
| 33 | #define MY_BASE64_DECODE_ALLOW_MULTIPLE_CHUNKS 1 |
| 34 | |
| 35 | extern struct base64_service_st { |
| 36 | int (*base64_needed_encoded_length_ptr)(int length_of_data); |
| 37 | int (*base64_encode_max_arg_length_ptr)(void); |
| 38 | int (*base64_needed_decoded_length_ptr)(int length_of_encoded_data); |
| 39 | int (*base64_decode_max_arg_length_ptr)(); |
| 40 | int (*base64_encode_ptr)(const void *src, size_t src_len, char *dst); |
| 41 | int (*base64_decode_ptr)(const char *src, size_t src_len, |
| 42 | void *dst, const char **end_ptr, int flags); |
| 43 | } *base64_service; |
| 44 | |
| 45 | #ifdef MYSQL_DYNAMIC_PLUGIN |
| 46 | |
| 47 | #define my_base64_needed_encoded_length(A) base64_service->base64_needed_encoded_length_ptr(A) |
| 48 | #define my_base64_encode_max_arg_length() base64_service->base64_encode_max_arg_length_ptr() |
| 49 | #define my_base64_needed_decoded_length(A) base64_service->base64_needed_decoded_length_ptr(A) |
| 50 | #define my_base64_decode_max_arg_length() base64_service->base64_decode_max_arg_length_ptr() |
| 51 | #define my_base64_encode(A,B,C) base64_service->base64_encode_ptr(A,B,C) |
| 52 | #define my_base64_decode(A,B,C,D,E) base64_service->base64_decode_ptr(A,B,C,D,E) |
| 53 | |
| 54 | #else |
| 55 | |
| 56 | /* Calculate how much memory needed for dst of my_base64_encode() */ |
| 57 | int my_base64_needed_encoded_length(int length_of_data); |
| 58 | |
| 59 | /* Maximum length my_base64_encode_needed_length() can accept with no overflow. */ |
| 60 | int my_base64_encode_max_arg_length(void); |
| 61 | |
| 62 | /* Calculate how much memory needed for dst of my_base64_decode() */ |
| 63 | int my_base64_needed_decoded_length(int length_of_encoded_data); |
| 64 | |
| 65 | /* Maximum length my_base64_decode_needed_length() can accept with no overflow. */ |
| 66 | int my_base64_decode_max_arg_length(); |
| 67 | |
| 68 | /* Encode data as a my_base64 string */ |
| 69 | int my_base64_encode(const void *src, size_t src_len, char *dst); |
| 70 | |
| 71 | /* Decode a my_base64 string into data */ |
| 72 | int my_base64_decode(const char *src, size_t src_len, |
| 73 | void *dst, const char **end_ptr, int flags); |
| 74 | |
| 75 | #endif |
| 76 | |
| 77 | #ifdef __cplusplus |
| 78 | } |
| 79 | #endif |
| 80 | |
| 81 | #define MYSQL_SERVICE_BASE64_INCLUDED |
| 82 | #endif |
| 83 | |