-- $Id: wfwl_functions 503 2012-12-09 01:48:29Z bhockney $
--
CREATE FUNCTION $WFWL_SCHEMA.webfwlog_ntoa (int8) RETURNS text
AS 'SELECT
	(mod((trunc ($1 / 2^24))::int4, 256))::text || ''.'' ||
	(mod((trunc ($1 / 2^16))::int4, 256))::text || ''.'' ||
	(mod((trunc ($1 / 2^ 8))::int4, 256))::text || ''.'' ||
	(mod((trunc ($1 / 2^ 0))::int8, 256::int8))::text'
LANGUAGE 'sql'
WITH (iscachable, isstrict);
--
-- Name: next_part (text)
-- Returns substring of $1 starting with character after '.' 
--
CREATE FUNCTION $WFWL_SCHEMA.next_part (text) RETURNS text
AS 'SELECT
	substring($1 from position(''.'' in $1) + 1)'
LANGUAGE 'sql'
WITH (iscachable, isstrict);
--
CREATE FUNCTION $WFWL_SCHEMA.webfwlog_aton (text) RETURNS int8
AS 'SELECT
	(substring($1 from 1 for position(''.'' in $1) -1)::int8 * 2^24)::int8
	 + (substring($WFWL_SCHEMA.next_part($1) from 1 for position(''.'' in $WFWL_SCHEMA.next_part($1)) - 1)::int8 * 2^16)::int8
	 + (substring($WFWL_SCHEMA.next_part($WFWL_SCHEMA.next_part($1)) from 1 for position(''.'' in $WFWL_SCHEMA.next_part($WFWL_SCHEMA.next_part($1))) - 1)::int8 * 2^8)::int8
	 + ($WFWL_SCHEMA.next_part($WFWL_SCHEMA.next_part($WFWL_SCHEMA.next_part($1)))::int8 * 2^0)::int8'
LANGUAGE 'sql'
WITH (iscachable, isstrict);
--
CREATE FUNCTION $WFWL_SCHEMA.webfwlog_aton (inet) RETURNS int8
AS 'SELECT
	(substring(host($1) from 1 for position(''.'' in host($1)) -1)::int8 * 2^24)::int8
	 + (substring($WFWL_SCHEMA.next_part(host($1)) from 1 for position(''.'' in $WFWL_SCHEMA.next_part(host($1))) - 1)::int8 * 2^16)::int8
	 + (substring($WFWL_SCHEMA.next_part($WFWL_SCHEMA.next_part(host($1))) from 1 for position(''.'' in $WFWL_SCHEMA.next_part($WFWL_SCHEMA.next_part(host($1)))) - 1)::int8 * 2^8)::int8
	 + ($WFWL_SCHEMA.next_part($WFWL_SCHEMA.next_part($WFWL_SCHEMA.next_part(host($1))))::int8 * 2^0)::int8'
LANGUAGE 'sql'
WITH (iscachable, isstrict);
