65 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
66 errmsg(
"unrecognized encoding: \"%s\"", namebuf)));
79 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
80 errmsg(
"result of encoding conversion is too large")));
88 elog(
FATAL,
"overflow - encode estimate too small");
113 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
114 errmsg(
"unrecognized encoding: \"%s\"", namebuf)));
127 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
128 errmsg(
"result of decoding conversion is too large")));
136 elog(
FATAL,
"overflow - decode estimate too small");
148 static const char hextbl[] =
"0123456789abcdef";
151 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
152 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
153 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
154 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
155 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
156 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
157 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
158 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
164 const char *end = src +
len;
168 *dst++ =
hextbl[(*src >> 4) & 0xF];
169 *dst++ =
hextbl[*src & 0xF];
172 return (uint64)
len * 2;
178 unsigned char c = (
unsigned char) *cp;
209 if (*s ==
' ' || *s ==
'\n' || *s ==
'\t' || *s ==
'\r')
216 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
217 errmsg(
"invalid hexadecimal digit: \"%.*s\"",
222 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
223 errmsg(
"invalid hexadecimal data: odd number of digits")));
226 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
227 errmsg(
"invalid hexadecimal digit: \"%.*s\"",
230 *p++ = (v1 << 4) | v2;
239 return (uint64) srclen << 1;
245 return (uint64) srclen >> 1;
253 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
256 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
257 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
258 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
259 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
260 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
261 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
262 -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
263 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1,
281 buf |= (
unsigned char) *s << (pos << 3);
306 *p++ = (pos == 0) ?
_base64[(
buf >> 6) & 0x3f] :
'=';
316 const char *srcend = src +
len,
329 if (
c ==
' ' ||
c ==
'\t' ||
c ==
'\n' ||
c ==
'\r')
343 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
344 errmsg(
"unexpected \"=\" while decoding base64 sequence")));
351 if (
c > 0 &&
c < 127)
355 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
356 errmsg(
"invalid symbol \"%.*s\" found while decoding base64 sequence",
364 *p++ = (
buf >> 16) & 255;
365 if (end == 0 || end > 1)
366 *p++ = (
buf >> 8) & 255;
367 if (end == 0 || end > 2)
376 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
377 errmsg(
"invalid base64 end sequence"),
378 errhint(
"Input data is missing padding, is truncated, or is otherwise corrupted.")));
388 return ((uint64) srclen + 2) / 3 * 4 + (uint64) srclen / (76 * 3 / 4);
394 return ((uint64) srclen * 3) >> 2;
411 #define VAL(CH) ((CH) - '0')
412 #define DIG(VAL) ((VAL) + '0')
417 const char *end = src + srclen;
423 unsigned char c = (
unsigned char) *src;
429 rp[2] =
DIG((
c >> 3) & 7);
456 const char *end = src + srclen;
464 else if (src + 3 < end &&
465 (src[1] >=
'0' && src[1] <=
'3') &&
466 (src[2] >=
'0' && src[2] <=
'7') &&
467 (src[3] >=
'0' && src[3] <=
'7'))
475 *rp++ =
val +
VAL(src[3]);
478 else if (src + 1 < end &&
491 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
492 errmsg(
"invalid input syntax for type %s",
"bytea")));
504 const char *end = src + srclen;
511 else if (*src ==
'\\')
525 const char *end = src + srclen;
532 else if (src + 3 < end &&
533 (src[1] >=
'0' && src[1] <=
'3') &&
534 (src[2] >=
'0' && src[2] <=
'7') &&
535 (src[3] >=
'0' && src[3] <=
'7'))
542 else if (src + 1 < end &&
556 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
557 errmsg(
"invalid input syntax for type %s",
"bytea")));
597 NULL, NULL, NULL, NULL
#define TextDatumGetCString(d)
#define IS_HIGHBIT_SET(ch)
static void PGresult * res
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define ereport(elevel,...)
static uint64 pg_base64_decode(const char *src, size_t len, char *dst)
static bool get_hex(const char *cp, char *out)
static uint64 hex_dec_len(const char *src, size_t srclen)
static const struct pg_encoding * pg_find_encoding(const char *name)
static uint64 pg_base64_encode(const char *src, size_t len, char *dst)
static uint64 esc_encode(const char *src, size_t srclen, char *dst)
static uint64 hex_enc_len(const char *src, size_t srclen)
Datum binary_decode(PG_FUNCTION_ARGS)
static const struct @24 enclist[]
uint64 hex_decode_safe(const char *src, size_t len, char *dst, Node *escontext)
static const char hextbl[]
uint64 hex_encode(const char *src, size_t len, char *dst)
static uint64 esc_enc_len(const char *src, size_t srclen)
static uint64 pg_base64_enc_len(const char *src, size_t srclen)
static const char _base64[]
static uint64 esc_decode(const char *src, size_t srclen, char *dst)
static uint64 esc_dec_len(const char *src, size_t srclen)
Datum binary_encode(PG_FUNCTION_ARGS)
uint64 hex_decode(const char *src, size_t len, char *dst)
static const int8 b64lookup[128]
static const int8 hexlookup[128]
static uint64 pg_base64_dec_len(const char *src, size_t srclen)
#define PG_GETARG_BYTEA_PP(n)
#define PG_GETARG_TEXT_PP(n)
#define PG_RETURN_BYTEA_P(x)
#define PG_GETARG_DATUM(n)
#define PG_RETURN_TEXT_P(x)
int pg_mblen(const char *mbstr)
int pg_strcasecmp(const char *s1, const char *s2)
uint64(* encode_len)(const char *data, size_t dlen)
uint64(* decode_len)(const char *data, size_t dlen)
uint64(* decode)(const char *data, size_t dlen, char *res)
uint64(* encode)(const char *data, size_t dlen, char *res)
#define SET_VARSIZE(PTR, len)
#define VARSIZE_ANY_EXHDR(PTR)