Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
3358db32
Commit
3358db32
authored
9 years ago
by
Thomas Müller
Browse files
Options
Downloads
Patches
Plain Diff
Reduce duplicate code
parent
bacf1603
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/private/ocs.php
+4
-15
4 additions, 15 deletions
lib/private/ocs.php
lib/private/ocs/exception.php
+40
-0
40 additions, 0 deletions
lib/private/ocs/exception.php
ocs/v1.php
+2
-0
2 additions, 0 deletions
ocs/v1.php
with
46 additions
and
15 deletions
lib/private/ocs.php
+
4
−
15
View file @
3358db32
...
...
@@ -28,6 +28,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
use
OCP\API
;
/**
* Class to handle open collaboration services API requests
...
...
@@ -64,8 +65,7 @@ class OC_OCS {
}
}
if
(
$data
===
false
)
{
echo
self
::
generateXml
(
''
,
'fail'
,
400
,
'Bad request. Please provide a valid '
.
$key
);
exit
();
throw
new
\OC\OCS\Exception
(
new
OC_OCS_Result
(
null
,
400
,
'Bad request. Please provide a valid '
.
$key
));
}
else
{
// NOTE: Is the raw type necessary? It might be a little risky without sanitization
if
(
$type
==
'raw'
)
return
$data
;
...
...
@@ -78,23 +78,12 @@ class OC_OCS {
}
public
static
function
notFound
()
{
if
(
$_SERVER
[
'REQUEST_METHOD'
]
==
'GET'
)
{
$method
=
'get'
;
}
elseif
(
$_SERVER
[
'REQUEST_METHOD'
]
==
'PUT'
)
{
$method
=
'put'
;
}
elseif
(
$_SERVER
[
'REQUEST_METHOD'
]
==
'POST'
)
{
$method
=
'post'
;
}
else
{
echo
(
'internal server error: method not supported'
);
exit
();
}
$format
=
self
::
readData
(
$method
,
'format'
,
'text'
,
''
);
$format
=
OC_API
::
requestedFormat
();
$txt
=
'Invalid query, please check the syntax. API specifications are here:'
.
' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services. DEBUG OUTPUT:'
.
"
\n
"
;
$txt
.
=
OC_OCS
::
getDebugOutput
();
echo
(
OC_OCS
::
generateXml
(
$format
,
'failed'
,
999
,
$txt
));
OC_API
::
respond
(
new
OC_OCS_Result
(
null
,
API
::
RESPOND_UNKNOWN_ERROR
,
$txt
),
$format
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
lib/private/ocs/exception.php
0 → 100644
+
40
−
0
View file @
3358db32
<?php
/**
* @author Bart Visscher <bartv@thisnet.nl>
* @author Björn Schießle <schiessle@owncloud.com>
* @author Christopher Schäpers <kondou@ts.unde.re>
* @author Lukas Reschke <lukas@owncloud.com>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin McCorkell <rmccorkell@karoshi.org.uk>
* @author Tom Needham <tom@owncloud.com>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace
OC\OCS
;
class
Exception
extends
\Exception
{
public
function
__construct
(
\OC_OCS_Result
$result
)
{
$this
->
result
=
$result
;
}
public
function
getResult
()
{
return
$this
->
result
;
}
}
This diff is collapsed.
Click to expand it.
ocs/v1.php
+
2
−
0
View file @
3358db32
...
...
@@ -56,5 +56,7 @@ try {
}
catch
(
MethodNotAllowedException
$e
)
{
OC_API
::
setContentType
();
OC_Response
::
setStatus
(
405
);
}
catch
(
\OC\OCS\Exception
$ex
)
{
OC_API
::
respond
(
$ex
->
getResult
(),
OC_API
::
requestedFormat
());
}
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