/** * * @param[in] XooNIpsXmlRpcRequest $request * @param[out] XooNIpsXmlRpcResponse $response * result of logic(success/fault, response, error) */ function execute(&$request, &$response) { // load logic instance $factory =& XooNIpsLogicFactory::getInstance(); $logic =& $factory->create($request->getMethodName()); if (!is_object($logic)) { $response->setResult(false); $error =& $response->getError(); $logic = $request->getMethodName(); $error->add(XNPERR_SERVER_ERROR, "can't create a logic of {$logic}"); return; } // $params =& $request->getParams(); $vars = array(); if (count($params) < 4) { $response->setResult(false); $error =& $response->getError(); $error->add(XNPERR_MISSING_PARAM); return false; } else { if (count($params) > 4) { $response->setResult(false); $error =& $response->getError(); $error->add(XNPERR_EXTRA_PARAM); return false; } } // // parameter 1(sessionid) $vars[0] = $params[0]; // // transform array to object // parameter 2(item structure) to XooNIpsItemCompo object // using XooNIpsTransformCompo<itemtype> $item_type_id = intval($params[1]['itemtype']); $itemtype_handler =& xoonips_getormhandler('xoonips', 'item_type'); $itemtype =& $itemtype_handler->get($item_type_id); if (!$itemtype) { $response->setResult(false); $response->setError(new XooNIpsError(XNPERR_INVALID_PARAM, "item type of {$item_type_id} is not found")); return false; } // $factory =& XooNIpsXmlRpcTransformCompoFactory::getInstance(); $trans =& $factory->create($itemtype->get('name')); $missing = array(); if (!$trans->isFilledRequired($params[1], $missing)) { $response->setResult(false); $err =& $response->getError(); foreach ($missing as $m) { $err->add(XNPERR_INCOMPLETE_PARAM, $m); } return false; } // check mulitple of each variable $fields = array(); if (!$trans->checkMultipleFields($params[1], $fields)) { $response->setResult(false); $err =& $response->getError(); foreach ($fields as $m) { $err->add(XNPERR_INCOMPLETE_PARAM, $m); } return false; } // check fields if (!$trans->checkFields($params[1], $response->getError())) { // some fields have invalid value return false; } // transform array to item object, and set it to $vars. $vars[1] = $trans->getObject($params[1]); // transform array to object // parameter 3(file structure) to XooNIpsFile object // using XooNIpsTransformFile // and write file data to temporary file $factory =& XooNIpsXmlRpcTransformFactory::getInstance(); $trans =& $factory->create('xoonips', 'file'); if (is_array($params[2])) { $vars[2] = array(); foreach ($params[2] as $p) { $fileobj = $trans->getObject($p); if (!$fileobj) { $response->setResult(false); $response->setError(new XooNIpsError(XNPERR_INVALID_PARAM, "can't get file from XML")); return false; } $tmpfile = tempnam("/tmp", "FOO"); $h = fopen($tmpfile, "wb"); if ($h) { $len = fwrite($h, $p['data']); fclose($h); } if (!$h || $len != strlen($p['data'])) { $response->setResult(false); $response->setError(new XooNIpsError(XNPERR_SERVER_ERROR, "can't write to file {$tmpfile}")); return false; } $fileobj->setFilepath($tmpfile); $vars[2][] = $fileobj; } } // parameter 4(array of remove file id) $vars[3] = $params[3]; // execute logic $xoonips_response = new XooNIpsResponse(); $logic->execute($vars, $xoonips_response); // $response->setResult($xoonips_response->getResult()); $response->setError($xoonips_response->getError()); $response->setSuccess($xoonips_response->getSuccess()); }
/** * * @param[in] XooNIpsXmlRpcRequest $request * @param[out] XooNIpsXmlRpcResponse $response result of logic(success/fault, response, error) */ function execute(&$request, &$response) { $error =& $response->getError(); // load logic instance $factory =& XooNIpsLogicFactory::getInstance(); $logic =& $factory->create($request->getMethodName()); if (!is_object($logic)) { $response->setResult(false); $error =& $response->getError(); $logic = $request->getMethodName(); $error->add(XNPERR_SERVER_ERROR, "can't create a logic of {$logic}"); return false; } // $params =& $request->getParams(); $vars = array(); if (count($params) < 5) { $response->setResult(false); $error->add(XNPERR_MISSING_PARAM); return false; } else { if (count($params) > 5) { $response->setResult(false); $error->add(XNPERR_EXTRA_PARAM); return false; } } // // parameter 1(sessionid) $vars[0] = $params[0]; // // parameter 2(itemid) $unicode =& xoonips_getutility('unicode'); $vars[1] = $unicode->decode_utf8($params[1], xoonips_get_server_charset(), 'h'); // // parameter 3(id_type) $vars[2] = $params[2]; // // parameter 4(fieldName) $vars[3] = $params[3]; // // // transform array to object // parameter 5(file structure) to XooNIpsFile object // using XooNIpsTransformFile // and write file data to temporary file $factory =& XooNIpsXmlRpcTransformFactory::getInstance(); $trans =& $factory->create('xoonips', 'file'); $fileobj = $trans->getObject($params[4]); if (!$fileobj) { $response->setResult(false); $error->add(XNPERR_INVALID_PARAM, 'can not get file from parameter #5'); return false; } $tmpfile = tempnam("/tmp", "FOO"); $h = fopen($tmpfile, "wb"); if ($h) { $len = fwrite($h, $params[4]['data']); fclose($h); } if (!$h || $len != strlen($params[4]['data'])) { $response->setResult(false); $error->add(XNPERR_SERVER_ERROR, "can't write to file {$tmpfile}"); return false; } $fileobj->setFilepath($tmpfile); $vars[4] = $fileobj; // execute logic $xoonips_response = new XooNIpsResponse(); $logic->execute($vars, $xoonips_response); // $response->setResult($xoonips_response->getResult()); $response->setError($xoonips_response->getError()); $response->setSuccess($xoonips_response->getSuccess()); }