From 3aedf7f43922c2edf482337f9468c8e3430a9cf9 Mon Sep 17 00:00:00 2001
From: Nigel Kukard <nkukard@lbsd.net>
Date: Wed, 15 Jan 2014 21:22:57 +0000
Subject: [PATCH] Added a function to parse keypair strings

---
 opentrafficshaper/utils.pm | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/opentrafficshaper/utils.pm b/opentrafficshaper/utils.pm
index 0b3bafc..1c4b3bf 100644
--- a/opentrafficshaper/utils.pm
+++ b/opentrafficshaper/utils.pm
@@ -39,6 +39,7 @@ our (@ISA,@EXPORT,@EXPORT_OK);
 @EXPORT_OK = qw(
 	parseFormContent
 	parseURIQuery
+	parseKeyPairString
 );
 
 
@@ -264,5 +265,28 @@ sub booleanize
 }
 
 
+# Function to parse a keypair string and return a hash
+sub parseKeyPairString
+{
+	my $str = shift;
+
+
+	my %res;
+	# Grab components
+	my @keyPairs = split(/\s+/,$str);
+	# Loop with the components in sets of name & value
+	foreach my $item (@keyPairs) {
+		my ($name,$value) = split(/=/,$item);
+		# Unescape name value pair
+		$value =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
+		# Add to hash
+		$res{$name}->{'value'} = $value;
+		push(@{$res{$name}->{'values'}},$value);
+	}
+
+	return \%res;
+}
+
+
 1;
 # vim: ts=4
-- 
GitLab