diff --git a/opentrafficshaper/utils.pm b/opentrafficshaper/utils.pm index 0b3bafc18efcb7bbe6ae869ae54f240b6bc0517b..1c4b3bf8b57bdcaeddafa376d98a0078d47e292c 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