error = new SapError(); $this->instrumenttype = isset($_GET['INSTRUMENT_TYPE']) ? $_GET['INSTRUMENT_TYPE'] : NULL; $this->instrumentname = isset($_GET['INSTRUMENT_NAME']) ? $_GET['INSTRUMENT_NAME'] : NULL; $this->targettype = isset($_GET['TARGET_TYPE']) ? $_GET['TARGET_TYPE'] : NULL; $this->targetname = isset($_GET['TARGET_NAME']) ? $_GET['TARGET_NAME'] : NULL; $this->starttime = isset($_GET['START_TIME']) ? $_GET['START_TIME'] : NULL; $this->stoptime = isset($_GET['STOP_TIME']) ? $_GET['STOP_TIME'] : NULL; $this->returntype = isset($_GET['RETURN_TYPE']) ? $_GET['RETURN_TYPE'] : 'votable'; $this->longitude = isset($_GET['LONGITUDE']) ? $_GET['LONGITUDE'] : NULL; $this->latitude = isset($_GET['LATITUDE']) ? $_GET['LATITUDE'] : NULL; $this->missionname = isset($_GET['MISSION_NAME']) ? $_GET['MISSION_NAME'] : NULL; $this->setRequest(); if($this->request == PdapRequest::doQuery) { $this->check(); } } /* * For now handle only RESOURCE_CLASS = METADATA, DATA_SET or IMAGE * to handle other type add else if case */ private function setRequest() { $this->resourceclass = isset($_GET['RESOURCE_CLASS']) ? $_GET['RESOURCE_CLASS'] : NULL; if(!isset($this->resourceclass)) { $this->request = PdapRequest::undefinedRequest; $this->error->add('RESOURCE_CLASS is not present.'); } else if(strcasecmp($this->resourceclass, 'METADATA') == 0) { $this->request = PdapRequest::getCapabilities; } else if(strcasecmp($this->resourceclass, 'DATA_SET') == 0) { $this->request = PdapRequest::doQuery; } else if(strcasecmp($this->resourceclass, 'IMAGE') == 0) { $this->request = PdapRequest::doQuery; } else { $this->request = PdapRequest::unknownRequest; $this->error->add('RESOURCE_CLASS is not equal to DATA_SET or METADATA.'); } } /* * check only syntax as we don't know if parameters are mandatory or not */ private function check() { if($this->starttime) { if(!preg_match("/^[0-9]{4}/", $this->starttime)) { $this->error->add('START_TIME is not a valid time.'); } } if($this->stoptime) { if(!preg_match("/^[0-9]{4}/", $this->stoptime)) { $this->error->add('STOP_TIME is not a valid time.'); } } /* check input parameter mandatory when RESSOURCE_CLASS = IMAGE */ if(strcasecmp($this->resourceclass, 'IMAGE') == 0) { if(isset($this->longitude)) { if(!$this->checkRange($this->longitude, $this->longitude_rangetype)) { $this->error->add('LONGITUDE syntax error.'); } } else { $this->error->add('LONGITUDE is not present.'); } if(isset($this->latitude)) { if(!$this->checkRange($this->latitude, $this->latitude_rangetype)) { $this->error->add('LATITUDE syntax error.'); } } else { $this->error->add('LATITUDE is not present.'); } } /* RESSOURCE_CLASS != IMAGE */ if(isset($this->longitude) && !empty($this->longitude)) { if(!$this->checkRange($this->longitude, $this->longitude_rangetype)) { $this->error->add('LONGITUDE syntax error.'); } } if(isset($this->latitude) && !empty($this->latitude)) { if(!$this->checkRange($this->latitude, $this->latitude_rangetype)) { $this->error->add('LATITUDE syntax error.'); } } } private function checkRange($range, &$rangetype) { // HACK urldecode pour passer le check quand ca vient du JS car les / deviennent des %2F et la regexp n'est plus bonne $range = urldecode($range); /* v < */ if(preg_match("/^\/(-{0,1}[0-9]+\.{0,1}[0-9]*)$/", $range, $reg)) { $rangetype = RangeType::Max; return true; } /* v > */ if(preg_match("/^(-{0,1}[0-9]+\.{0,1}[0-9]*)\/$/", $range, $reg)) { $rangetype = RangeType::Min; return true; } /* < v < */ if(preg_match("/^(-{0,1}[0-9]+\.{0,1}[0-9]*)\/(-{0,1}[0-9]+\.{0,1}[0-9]*)$/", $range, $reg)) { $rangetype = RangeType::Range; return true; } /* v = */ if(is_numeric($range)) { $rangetype = RangeType::Equality; return true; } $rangetype = RangeType::Undefined; return false; } public function hasError() { return !$this->error->isEmpty(); } public function isQueryData() { return ($this->request == TapRequest::doQuery); } public function processError($version) { return $this->error->process($version, AccessProtocol::PDAP); } public function processErrorMessage($version, $msg) { $this->error->add($msg); return $this->error->process($version, AccessProtocol::PDAP); } public function process($records = null) { switch($this->request) { case PdapRequest::doQuery: return $this->processQueryData($records); break; case PdapRequest::getCapabilities: return $this->processGetCapabilities(); break; default: break; } } abstract public function getQuery(); abstract protected function processQueryData($records); abstract protected function processGetCapabilities(); } ?>