diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 181cd51b8f..322f926759 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -47,6 +47,7 @@ phutil_register_library_map(array( 'AphrontWebpageResponse' => 'aphront/response/webpage', 'ConduitAPIMethod' => 'applications/conduit/method/base', 'ConduitAPIRequest' => 'applications/conduit/protocol/request', + 'ConduitAPI_conduit_connect_Method' => 'applications/conduit/method/conduit/connect', 'ConduitAPI_differential_creatediff_Method' => 'applications/conduit/method/differential/creatediff', 'ConduitAPI_file_upload_Method' => 'applications/conduit/method/file/upload', 'ConduitException' => 'applications/conduit/protocol/exception', @@ -148,6 +149,7 @@ phutil_register_library_map(array( 'AphrontSideNavView' => 'AphrontView', 'AphrontTableView' => 'AphrontView', 'AphrontWebpageResponse' => 'AphrontResponse', + 'ConduitAPI_conduit_connect_Method' => 'ConduitAPIMethod', 'ConduitAPI_differential_creatediff_Method' => 'ConduitAPIMethod', 'ConduitAPI_file_upload_Method' => 'ConduitAPIMethod', 'DifferentialChangeset' => 'DifferentialDAO', diff --git a/src/applications/conduit/controller/api/PhabricatorConduitAPIController.php b/src/applications/conduit/controller/api/PhabricatorConduitAPIController.php index c259cf4551..e3bd8e0e5a 100644 --- a/src/applications/conduit/controller/api/PhabricatorConduitAPIController.php +++ b/src/applications/conduit/controller/api/PhabricatorConduitAPIController.php @@ -55,7 +55,7 @@ class PhabricatorConduitAPIController if (isset($_REQUEST['params']) && is_array($_REQUEST['params'])) { $params_post = $request->getArr('params'); foreach ($params_post as $key => $value) { - $params_post[$key] = json_decode($value); + $params_post[$key] = json_decode($value, true); } $params = $params_post; } else { @@ -63,7 +63,7 @@ class PhabricatorConduitAPIController if (!strlen($params_json)) { $params = array(); } else { - $params = json_decode($params_json); + $params = json_decode($params_json, true); if (!is_array($params)) { throw new Exception( "Invalid parameter information was passed to method ". diff --git a/src/applications/conduit/method/conduit/connect/ConduitAPI_conduit_connect_Method.php b/src/applications/conduit/method/conduit/connect/ConduitAPI_conduit_connect_Method.php new file mode 100644 index 0000000000..daa12ac7bc --- /dev/null +++ b/src/applications/conduit/method/conduit/connect/ConduitAPI_conduit_connect_Method.php @@ -0,0 +1,88 @@ + 'required string', + 'clientVersion' => 'required int', + 'clientDescription' => 'optional string', + 'user' => 'optional string', + ); + } + + public function defineReturnType() { + return 'dict'; + } + + public function defineErrorTypes() { + return array( + "ERR-BAD-VERSION" => + "Client/server version mismatch. Update your client.", + "ERR-UNKNOWN-CLIENT" => + "Client is unknown.", + "ERR-UPDATE-ARC" => + "Arcanist is now open source! Update your scripts/aliases to use ". + "'/home/engshare/devtools/arcanist/bin/arc' if you're running from ". + "a Facebook host, or see ". + " for ". + "laptop instructions.", + ); + } + + protected function execute(ConduitAPIRequest $request) { + + $client = $request->getValue('client'); + $client_version = (int)$request->getValue('clientVersion'); + $client_description = (string)$request->getValue('clientDescription'); + + // Log the connection, regardless of the outcome of checks below. + $connection = new PhabricatorConduitConnectionLog(); + $connection->setClient($client); + $connection->setClientVersion($client_version); + $connection->setClientDescription($client_description); + $connection->setUsername((string)$request->getValue('user')); + $connection->save(); + + switch ($client) { + case 'arc': + $server_version = 2; + switch ($client_version) { + case 1: + throw new ConduitException('ERR-UPDATE-ARC'); + case $server_version: + break; + default: + throw new ConduitException('ERR-BAD-VERSION'); + } + break; + default: + throw new ConduitException('ERR-UNKNOWN-CLIENT'); + } + + return array( + 'connectionID' => $connection->getID(), + ); + } + +} diff --git a/src/applications/conduit/method/conduit/connect/__init__.php b/src/applications/conduit/method/conduit/connect/__init__.php new file mode 100644 index 0000000000..5d3459f000 --- /dev/null +++ b/src/applications/conduit/method/conduit/connect/__init__.php @@ -0,0 +1,14 @@ +