Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pve-manager
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
pve-manager
Commits
27d5f5ea
Commit
27d5f5ea
authored
May 02, 2014
by
Dietmar Maurer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move formater registration to HTTPServer
parent
23e0c0ba
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
88 deletions
+59
-88
API2.pm
PVE/API2.pm
+7
-7
HTTPServer.pm
PVE/HTTPServer.pm
+52
-2
REST.pm
PVE/REST.pm
+0
-79
No files found.
PVE/API2.pm
View file @
27d5f5ea
...
...
@@ -4,7 +4,7 @@ use strict;
use
warnings
;
use
PVE::
pvecfg
;
use
PVE::
REST
;
use
PVE::
HTTPServer
;
use
PVE::
RESTHandler
;
use
HTTP::
Status
;
use
JSON
;
...
...
@@ -151,7 +151,7 @@ my $prepare_response_data = sub {
$res
->
{
data
}
=
$new
;
};
PVE::
REST
::
register_formater
('
json
',
sub
{
PVE::
HTTPServer
::
register_formater
('
json
',
sub
{
my
(
$res
,
$data
,
$param
,
$path
,
$auth
)
=
@_
;
my
$nocomp
=
0
;
...
...
@@ -166,7 +166,7 @@ PVE::REST::register_formater('json', sub {
});
PVE::
REST
::
register_formater
('
extjs
',
sub
{
PVE::
HTTPServer
::
register_formater
('
extjs
',
sub
{
my
(
$res
,
$data
,
$param
,
$path
,
$auth
)
=
@_
;
my
$nocomp
=
0
;
...
...
@@ -180,7 +180,7 @@ PVE::REST::register_formater('extjs', sub {
return
(
$raw
,
$ct
,
$nocomp
);
});
PVE::
REST
::
register_formater
('
htmljs
',
sub
{
PVE::
HTTPServer
::
register_formater
('
htmljs
',
sub
{
my
(
$res
,
$data
,
$param
,
$path
,
$auth
)
=
@_
;
my
$nocomp
=
0
;
...
...
@@ -197,7 +197,7 @@ PVE::REST::register_formater('htmljs', sub {
});
PVE::
REST
::
register_formater
('
spiceconfig
',
sub
{
PVE::
HTTPServer
::
register_formater
('
spiceconfig
',
sub
{
my
(
$res
,
$data
,
$param
,
$path
,
$auth
)
=
@_
;
my
$nocomp
=
0
;
...
...
@@ -220,7 +220,7 @@ PVE::REST::register_formater('spiceconfig', sub {
return
(
$raw
,
$ct
,
$nocomp
);
});
PVE::
REST
::
register_formater
('
png
',
sub
{
PVE::
HTTPServer
::
register_formater
('
png
',
sub
{
my
(
$res
,
$data
,
$param
,
$path
,
$auth
)
=
@_
;
my
$nocomp
=
1
;
...
...
@@ -245,7 +245,7 @@ PVE::REST::register_formater('png', sub {
return
(
$raw
,
$ct
,
$nocomp
);
});
PVE::
REST
::
register_formater
('
html
',
sub
{
PVE::
HTTPServer
::
register_formater
('
html
',
sub
{
my
(
$res
,
$data
,
$param
,
$path
,
$auth
)
=
@_
;
my
$nocomp
=
0
;
...
...
PVE/HTTPServer.pm
View file @
27d5f5ea
...
...
@@ -55,6 +55,56 @@ sub split_abs_uri {
return
wantarray
?
(
$rel_uri
,
$format
)
:
$rel_uri
;
}
# generic formater support
my
$formater_hash
=
{};
sub
register_formater
{
my
(
$format
,
$func
)
=
@_
;
die
"
formater '
$format
' already defined
"
if
$formater_hash
->
{
$format
};
$formater_hash
->
{
$format
}
=
{
func
=>
$func
,
};
}
sub
get_formater
{
my
(
$format
)
=
@_
;
return
undef
if
!
$format
;
my
$info
=
$formater_hash
->
{
$format
};
return
undef
if
!
$info
;
return
$info
->
{
func
};
}
my
$login_formater_hash
=
{};
sub
register_login_formater
{
my
(
$format
,
$func
)
=
@_
;
die
"
login formater '
$format
' already defined
"
if
$login_formater_hash
->
{
$format
};
$login_formater_hash
->
{
$format
}
=
{
func
=>
$func
,
};
}
sub
get_login_formater
{
my
(
$format
)
=
@_
;
return
undef
if
!
$format
;
my
$info
=
$login_formater_hash
->
{
$format
};
return
undef
if
!
$info
;
return
$info
->
{
func
};
}
# server implementation
sub
log_request
{
my
(
$self
,
$reqstate
)
=
@_
;
...
...
@@ -446,7 +496,7 @@ sub handle_api2_request {
my
(
$rel_uri
,
$format
)
=
split_abs_uri
(
$path
);
my
$formater
=
PVE::REST::
get_formater
(
$format
);
my
$formater
=
get_formater
(
$format
);
if
(
!
defined
(
$formater
))
{
$self
->
error
(
$reqstate
,
HTTP_NOT_IMPLEMENTED
,
"
no such uri
$rel_uri
,
$format
");
...
...
@@ -964,7 +1014,7 @@ sub unshift_read_header {
if
(
my
$err
=
$@
)
{
# always delay unauthorized calls by 3 seconds
my
$delay
=
3
;
if
(
my
$formater
=
PVE::REST::
get_login_formater
(
$format
))
{
if
(
my
$formater
=
get_login_formater
(
$format
))
{
my
(
$raw
,
$ct
,
$nocomp
)
=
&
$formater
(
$path
,
$auth
);
my
$resp
;
if
(
ref
(
$raw
)
&&
(
ref
(
$raw
)
eq
'
HTTP::Response
'))
{
...
...
PVE/REST.pm
View file @
27d5f5ea
...
...
@@ -199,83 +199,4 @@ sub rest_handler {
return
$resp
;
}
# generic formater support
my
$formater_hash
=
{};
sub
register_formater
{
my
(
$format
,
$func
)
=
@_
;
die
"
formater '
$format
' already defined
"
if
$formater_hash
->
{
$format
};
$formater_hash
->
{
$format
}
=
{
func
=>
$func
,
};
}
sub
get_formater
{
my
(
$format
)
=
@_
;
return
undef
if
!
$format
;
my
$info
=
$formater_hash
->
{
$format
};
return
undef
if
!
$info
;
return
$info
->
{
func
};
}
my
$login_formater_hash
=
{};
sub
register_login_formater
{
my
(
$format
,
$func
)
=
@_
;
die
"
login formater '
$format
' already defined
"
if
$login_formater_hash
->
{
$format
};
$login_formater_hash
->
{
$format
}
=
{
func
=>
$func
,
};
}
sub
get_login_formater
{
my
(
$format
)
=
@_
;
return
undef
if
!
$format
;
my
$info
=
$login_formater_hash
->
{
$format
};
return
undef
if
!
$info
;
return
$info
->
{
func
};
}
sub
register_page_formater
{
my
(
%
config
)
=
@_
;
my
$base_handler_class
=
$config
{
base_handler_class
}
||
die
"
missing base_handler_class
";
my
$format
=
$config
{
format
}
||
die
"
missing format
";
die
"
format '
$format
' is not registered
"
if
!
$formater_hash
->
{
$format
};
my
$path
=
$config
{
path
}
||
die
"
missing path
";
my
$method
=
$config
{
method
}
||
die
"
missing method
";
my
$code
=
$config
{
code
}
||
die
"
missing formater code
";
my
$uri_param
=
{};
my
(
$handler
,
$info
)
=
$base_handler_class
->
find_handler
(
$method
,
$path
,
$uri_param
);
die
"
unabe to find handler for '
$method
:
$path
'
"
if
!
(
$handler
&&
$info
);
die
"
duplicate formater for '
$method
:
$path
'
"
if
$info
->
{
formater
}
&&
$info
->
{
formater
}
->
{
$format
};
$info
->
{
formater
}
->
{
$format
}
=
$code
;
}
1
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment