From e066a752caab9634391f6335ae1829fe6ddac55c Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Tue, 7 Aug 2012 09:15:25 -0400 Subject: [PATCH] Start building URL-Validation related funcitons Signed-off-by: Mike Rylander --- Open-ILS/src/sql/Pg/076.functions.url_verify.sql | 38 ++++++++++++++++++++++ .../sql/Pg/upgrade/YYYY.functions.url_verify.sql | 22 +++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 Open-ILS/src/sql/Pg/076.functions.url_verify.sql create mode 100644 Open-ILS/src/sql/Pg/upgrade/YYYY.functions.url_verify.sql diff --git a/Open-ILS/src/sql/Pg/076.functions.url_verify.sql b/Open-ILS/src/sql/Pg/076.functions.url_verify.sql new file mode 100644 index 0000000000..056cde3341 --- /dev/null +++ b/Open-ILS/src/sql/Pg/076.functions.url_verify.sql @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2012 Equinox Software, Inc. + * Mike Rylander + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +BEGIN; + +CREATE OR REPLACE FUNCTION url_verify.parse_url (url_in TEXT) RETURNS url_verify.url AS $$ + +use Rose::URI; + +my $url_in = shift; +my $url = Rose::URI->new($url_in); + +my %parts = map { $_ => $url->$_ } qw/scheme username password host port path query fragment/; + +$parts{full_url} = $url_in; +($parts{domain} = $parts{host}) =~ s/^[^.]+\.//; +($parts{tld} = $parts{domain}) =~ s/(?:[^.]+\.)+//; +($parts{page} = $parts{path}) =~ s#(?:[^/]*/)+##; + +return \%parts; + +$$ LANGUAGE PLPERLU; + +COMMIT; + diff --git a/Open-ILS/src/sql/Pg/upgrade/YYYY.functions.url_verify.sql b/Open-ILS/src/sql/Pg/upgrade/YYYY.functions.url_verify.sql new file mode 100644 index 0000000000..2087794714 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/YYYY.functions.url_verify.sql @@ -0,0 +1,22 @@ +BEGIN; + +CREATE OR REPLACE FUNCTION url_verify.parse_url (url_in TEXT) RETURNS url_verify.url AS $$ + +use Rose::URI; + +my $url_in = shift; +my $url = Rose::URI->new($url_in); + +my %parts = map { $_ => $url->$_ } qw/scheme username password host port path query fragment/; + +$parts{full_url} = $url_in; +($parts{domain} = $parts{host}) =~ s/^[^.]+\.//; +($parts{tld} = $parts{domain}) =~ s/(?:[^.]+\.)+//; +($parts{page} = $parts{path}) =~ s#(?:[^/]*/)+##; + +return \%parts; + +$$ LANGUAGE PLPERLU; + +COMMIT; + -- 2.11.0