Move some code stubs

This commit is contained in:
Yorick de Wid 2020-10-24 23:54:50 +02:00
parent c93ff49861
commit 0e533afb4d
1 changed files with 75 additions and 76 deletions

View File

@ -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,14 +396,19 @@ bool account_validate_str(char *iban) {
extern "C" extern "C"
{ {
/**************************************************************************
PG_MODULE_MAGIC;
typedef char Iban;
/**************************************************************************
* Input/Output functions * Input/Output functions
**************************************************************************/ **************************************************************************/
PG_FUNCTION_INFO_V1(ibanin); PG_FUNCTION_INFO_V1(ibanin);
Datum Datum
ibanin(PG_FUNCTION_ARGS) { ibanin(PG_FUNCTION_ARGS) {
char *inputText = PG_GETARG_CSTRING(0); char *inputText = PG_GETARG_CSTRING(0);
if (!account_validate_str(inputText)) if (!account_validate_str(inputText))
@ -420,27 +418,27 @@ extern "C"
inputText))); inputText)));
PG_RETURN_TEXT_P(cstring_to_text(inputText)); PG_RETURN_TEXT_P(cstring_to_text(inputText));
} }
/* Convert type output */ /* Convert type output */
PG_FUNCTION_INFO_V1(ibanout); PG_FUNCTION_INFO_V1(ibanout);
Datum Datum
ibanout(PG_FUNCTION_ARGS) { ibanout(PG_FUNCTION_ARGS) {
Iban *iban = (Iban *) PG_GETARG_DATUM(0); Iban *iban = (Iban *) PG_GETARG_DATUM(0);
PG_RETURN_CSTRING(TextDatumGetCString(iban)); PG_RETURN_CSTRING(TextDatumGetCString(iban));
} }
/************************************************************************** /**************************************************************************
* Binary Input/Output functions * Binary Input/Output functions
**************************************************************************/ **************************************************************************/
PG_FUNCTION_INFO_V1(ibanrecv); PG_FUNCTION_INFO_V1(ibanrecv);
Datum Datum
ibanrecv(PG_FUNCTION_ARGS) { ibanrecv(PG_FUNCTION_ARGS) {
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
text *result; text *result;
Iban *str; Iban *str;
@ -451,30 +449,31 @@ extern "C"
result = cstring_to_text_with_len(str, nbytes); result = cstring_to_text_with_len(str, nbytes);
pfree(str); pfree(str);
PG_RETURN_TEXT_P(result); PG_RETURN_TEXT_P(result);
} }
PG_FUNCTION_INFO_V1(ibansend); PG_FUNCTION_INFO_V1(ibansend);
Datum Datum
ibansend(PG_FUNCTION_ARGS) { ibansend(PG_FUNCTION_ARGS) {
text *t = PG_GETARG_TEXT_PP(0); text *t = PG_GETARG_TEXT_PP(0);
StringInfoData buf; StringInfoData buf;
pq_begintypsend(&buf); pq_begintypsend(&buf);
pq_sendtext(&buf, VARDATA_ANY(t), VARSIZE_ANY_EXHDR(t)); pq_sendtext(&buf, VARDATA_ANY(t), VARSIZE_ANY_EXHDR(t));
PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
} }
/* Manually verify a text */ /* Manually verify a text */
PG_FUNCTION_INFO_V1(iban_validate); PG_FUNCTION_INFO_V1(iban_validate);
Datum Datum
iban_validate(PG_FUNCTION_ARGS) { iban_validate(PG_FUNCTION_ARGS) {
text *iban = PG_GETARG_TEXT_P(0); text *iban = PG_GETARG_TEXT_P(0);
bool result = account_validate_text(iban); bool result = account_validate_text(iban);
PG_RETURN_BOOL(result); PG_RETURN_BOOL(result);
}
} }
} // extern "C"