Move some code stubs
This commit is contained in:
parent
c93ff49861
commit
0e533afb4d
151
iban.cpp
151
iban.cpp
|
@ -30,13 +30,6 @@ extern "C"
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
PG_MODULE_MAGIC;
|
|
||||||
|
|
||||||
using Iban = char;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Specification {
|
class Specification {
|
||||||
public:
|
public:
|
||||||
Specification(std::string structure, size_t length)
|
Specification(std::string structure, size_t length)
|
||||||
|
@ -120,7 +113,7 @@ static bool iso7064Mod97_10(std::string iban) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* parse the bban structure used to configure each iban specification and returns a matching regular expression.
|
* Parse the IBAN structure used to configure each iban specification and returns a matching regular expression.
|
||||||
* a structure is composed of blocks of 3 characters (one letter and 2 digits). each block represents
|
* a structure is composed of blocks of 3 characters (one letter and 2 digits). each block represents
|
||||||
* a logical group in the typical representation of the bban. for each group, the letter indicates which characters
|
* a logical group in the typical representation of the bban. for each group, the letter indicates which characters
|
||||||
* are allowed in this group and the following 2-digits number tells the length of the group.
|
* are allowed in this group and the following 2-digits number tells the length of the group.
|
||||||
|
@ -362,7 +355,7 @@ Validate::Validate() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Separate CXX and C logic to minimize unexpected or malformed symbols due to
|
* Separate CXX and C logic to minimize unexpected or malformed symbols due to
|
||||||
* language conversions. Also catch all exceptions the std++ can throw since
|
* language conversions. Also demark all exceptions the std++ can throw since
|
||||||
* PostgreSQL is not able to handle them.
|
* PostgreSQL is not able to handle them.
|
||||||
*
|
*
|
||||||
* @param {string} iban
|
* @param {string} iban
|
||||||
|
@ -403,78 +396,84 @@ bool account_validate_str(char *iban) {
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
/**************************************************************************
|
|
||||||
* Input/Output functions
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
PG_FUNCTION_INFO_V1(ibanin);
|
PG_MODULE_MAGIC;
|
||||||
|
|
||||||
Datum
|
typedef char Iban;
|
||||||
ibanin(PG_FUNCTION_ARGS) {
|
|
||||||
char *inputText = PG_GETARG_CSTRING(0);
|
|
||||||
|
|
||||||
if (!account_validate_str(inputText))
|
/**************************************************************************
|
||||||
ereport(ERROR,
|
* Input/Output functions
|
||||||
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
**************************************************************************/
|
||||||
errmsg("invalid iban format for value: \"%s\"",
|
|
||||||
inputText)));
|
|
||||||
|
|
||||||
PG_RETURN_TEXT_P(cstring_to_text(inputText));
|
PG_FUNCTION_INFO_V1(ibanin);
|
||||||
}
|
|
||||||
|
|
||||||
/* Convert type output */
|
Datum
|
||||||
|
ibanin(PG_FUNCTION_ARGS) {
|
||||||
|
char *inputText = PG_GETARG_CSTRING(0);
|
||||||
|
|
||||||
PG_FUNCTION_INFO_V1(ibanout);
|
if (!account_validate_str(inputText))
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
|
||||||
|
errmsg("invalid iban format for value: \"%s\"",
|
||||||
|
inputText)));
|
||||||
|
|
||||||
Datum
|
PG_RETURN_TEXT_P(cstring_to_text(inputText));
|
||||||
ibanout(PG_FUNCTION_ARGS) {
|
|
||||||
Iban *iban = (Iban *) PG_GETARG_DATUM(0);
|
|
||||||
|
|
||||||
PG_RETURN_CSTRING(TextDatumGetCString(iban));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Binary Input/Output functions
|
|
||||||
**************************************************************************/
|
|
||||||
|
|
||||||
PG_FUNCTION_INFO_V1(ibanrecv);
|
|
||||||
|
|
||||||
Datum
|
|
||||||
ibanrecv(PG_FUNCTION_ARGS) {
|
|
||||||
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
|
|
||||||
text *result;
|
|
||||||
Iban *str;
|
|
||||||
int nbytes;
|
|
||||||
|
|
||||||
str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
|
|
||||||
|
|
||||||
result = cstring_to_text_with_len(str, nbytes);
|
|
||||||
pfree(str);
|
|
||||||
PG_RETURN_TEXT_P(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
PG_FUNCTION_INFO_V1(ibansend);
|
|
||||||
|
|
||||||
Datum
|
|
||||||
ibansend(PG_FUNCTION_ARGS) {
|
|
||||||
text *t = PG_GETARG_TEXT_PP(0);
|
|
||||||
StringInfoData buf;
|
|
||||||
|
|
||||||
pq_begintypsend(&buf);
|
|
||||||
pq_sendtext(&buf, VARDATA_ANY(t), VARSIZE_ANY_EXHDR(t));
|
|
||||||
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Manually verify a text */
|
|
||||||
|
|
||||||
PG_FUNCTION_INFO_V1(iban_validate);
|
|
||||||
|
|
||||||
Datum
|
|
||||||
iban_validate(PG_FUNCTION_ARGS) {
|
|
||||||
text *iban = PG_GETARG_TEXT_P(0);
|
|
||||||
|
|
||||||
bool result = account_validate_text(iban);
|
|
||||||
|
|
||||||
PG_RETURN_BOOL(result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Convert type output */
|
||||||
|
|
||||||
|
PG_FUNCTION_INFO_V1(ibanout);
|
||||||
|
|
||||||
|
Datum
|
||||||
|
ibanout(PG_FUNCTION_ARGS) {
|
||||||
|
Iban *iban = (Iban *) PG_GETARG_DATUM(0);
|
||||||
|
|
||||||
|
PG_RETURN_CSTRING(TextDatumGetCString(iban));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Binary Input/Output functions
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
PG_FUNCTION_INFO_V1(ibanrecv);
|
||||||
|
|
||||||
|
Datum
|
||||||
|
ibanrecv(PG_FUNCTION_ARGS) {
|
||||||
|
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
|
||||||
|
text *result;
|
||||||
|
Iban *str;
|
||||||
|
int nbytes;
|
||||||
|
|
||||||
|
str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
|
||||||
|
|
||||||
|
result = cstring_to_text_with_len(str, nbytes);
|
||||||
|
pfree(str);
|
||||||
|
PG_RETURN_TEXT_P(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
PG_FUNCTION_INFO_V1(ibansend);
|
||||||
|
|
||||||
|
Datum
|
||||||
|
ibansend(PG_FUNCTION_ARGS) {
|
||||||
|
text *t = PG_GETARG_TEXT_PP(0);
|
||||||
|
StringInfoData buf;
|
||||||
|
|
||||||
|
pq_begintypsend(&buf);
|
||||||
|
pq_sendtext(&buf, VARDATA_ANY(t), VARSIZE_ANY_EXHDR(t));
|
||||||
|
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Manually verify a text */
|
||||||
|
|
||||||
|
PG_FUNCTION_INFO_V1(iban_validate);
|
||||||
|
|
||||||
|
Datum
|
||||||
|
iban_validate(PG_FUNCTION_ARGS) {
|
||||||
|
text *iban = PG_GETARG_TEXT_P(0);
|
||||||
|
|
||||||
|
bool result = account_validate_text(iban);
|
||||||
|
|
||||||
|
PG_RETURN_BOOL(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // extern "C"
|
||||||
|
|
Loading…
Reference in New Issue