Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
opentrafficshaper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Francisco Manuel Cardoso
opentrafficshaper
Commits
8ee90d24
Commit
8ee90d24
authored
11 years ago
by
Nigel Kukard
Browse files
Options
Downloads
Patches
Plain Diff
Added some functions to determine data types
parent
265fccd6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
opentrafficshaper/utils.pm
+123
-0
123 additions, 0 deletions
opentrafficshaper/utils.pm
with
123 additions
and
0 deletions
opentrafficshaper/utils.pm
+
123
−
0
View file @
8ee90d24
...
@@ -28,6 +28,11 @@ our (@ISA,@EXPORT,@EXPORT_OK);
...
@@ -28,6 +28,11 @@ our (@ISA,@EXPORT,@EXPORT_OK);
@EXPORT
=
qw(
@EXPORT
=
qw(
prettyUndef
prettyUndef
toHex
toHex
parseFormContent
isVariable
isUsername
isIP
isNumber
)
;
)
;
@EXPORT_OK
=
qw(
@EXPORT_OK
=
qw(
)
;
)
;
...
@@ -51,5 +56,123 @@ sub toHex
...
@@ -51,5 +56,123 @@ sub toHex
return
sprintf
('
%x
',
$decimal
);
return
sprintf
('
%x
',
$decimal
);
}
}
# Parse form post data from HTTP content
sub
parseFormContent
{
my
$data
=
shift
;
my
%res
;
# Split information into name/value pairs
my
@pairs
=
split
(
/&/
,
$data
);
foreach
my
$pair
(
@pairs
)
{
my
(
$name
,
$value
)
=
split
(
/=/
,
$pair
);
$value
=~
tr/+/ /
;
$value
=~
s/%(..)/pack("C", hex($1))/
eg
;
$res
{
$name
}
=
$value
;
}
return
\
%res
;
}
# Check if variable is normal
sub
isVariable
{
my
$var
=
shift
;
# A variable cannot be undef?
if
(
!
defined
(
$var
))
{
return
undef
;
}
return
(
ref
(
$var
)
eq
"");
}
# Check if variable is a username
sub
isUsername
{
my
$var
=
shift
;
# Make sure we're not a ref
if
(
!
isVariable
(
$var
))
{
return
undef
;
}
# Lowercase it
$var
=
lc
(
$var
);
# Normal username
if
(
$var
=~
/^[a-z0-9_\-\.]+$/
)
{
return
$var
;
}
# Username with domain
if
(
$var
=~
/^[a-z0-9_\-\.]+\@[a-z0-9\-\.]+$/
)
{
return
$var
;
}
return
undef
;
}
# Check if variable is an IP
sub
isIP
{
my
$var
=
shift
;
# Make sure we're not a ref
if
(
!
isVariable
(
$var
))
{
return
undef
;
}
# Lowercase it
$var
=
lc
(
$var
);
# Normal IP
if
(
$var
=~
/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
)
{
return
$var
;
}
return
undef
;
}
# Check if variable is a number
sub
isNumber
{
my
$var
=
shift
;
# Make sure we're not a ref
if
(
!
isVariable
(
$var
))
{
return
undef
;
}
# Strip leading 0's
if
(
$var
=~
/^0*([0-9]+)$/
)
{
my
$val
=
int
(
$
1
);
# Check we not 0 or negative
if
(
$val
>
0
)
{
return
$val
;
}
# Check if we allow 0's
if
(
$val
==
0
)
{
return
$val
;
}
}
return
undef
;
}
1
;
1
;
# vim: ts=4
# vim: ts=4
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment