1 //Glyn 08/05/2008 -- Function to obfuscate enctryption key generation based on username
11 Datum hkey( PG_FUNCTION_ARGS );
13 PG_FUNCTION_INFO_V1( hkey );
15 hkey( PG_FUNCTION_ARGS )
17 // variable declarations
18 char key[] = "91836zi8euwq45270";
24 // Get arguments. If we declare our function as STRICT, then this check is superfluous.
25 if( PG_ARGISNULL(0) ) {
28 uname = PG_GETARG_TEXT_P(0);
30 // Calculate string sizes.
32 unamelen = VARSIZE(uname) - VARHDRSZ;
34 // Allocate memory and set data structure size.
35 // Don't forget to add the type overhead (size of the length of the word at the start of the value) of int4 / VARHDRSZ
36 keying = (text *)palloc( keylen + unamelen + VARHDRSZ);
38 // VARATT_SIZEP depreciated as of 8.3
39 //VARATT_SIZEP( keying ) = keylen + unamelen + VARHDRSZ;
40 SET_VARSIZE(keying, keylen + unamelen + VARHDRSZ);
42 // Construct keying string.
43 strncpy( VARDATA(keying), key, keylen );
44 strncpy( VARDATA(keying) + keylen,
48 PG_RETURN_TEXT_P( keying );