/**
  * Parse a line of proxy file in a string
  *
  * @param Trace  $trace trace object
  * @param string $line not including line termination characters
  * @returns array service, value and domain from parsed line, indexed by
  *                those strings or false if this is not correct proxy line
  */
 private function parseString(Trace $trace, $line)
 {
     Preconditions::checkIsString($line, 'line');
     $matches = array();
     if (!preg_match(self::PROXY_LINE_PATTERN, $line, $matches)) {
         $trace->tlog('Line did not match');
         $trace->tlogVariable('line', $line);
         throw new ParseException('Proxy file line does not match');
     }
     try {
         return new CosignServiceCookie($matches[1], $matches[2], $matches[3]);
     } catch (InvalidArgumentException $e) {
         throw new ParseException('Proxy file arguments are invalid', null, $e);
     }
 }
Ejemplo n.º 2
0
 public function post(Trace $trace, $url, $data)
 {
     $trace->tlog("Http POST");
     $trace->tlogVariable("URL", $url);
     $child = $trace->addChild("POST data");
     $child->tlogVariable("post_data", $data);
     $this->_curlSetOption(CURLOPT_URL, $url);
     $this->_curlSetOption(CURLOPT_POST, true);
     $newPost = '';
     foreach ($data as $key => $value) {
         $newPost .= urlencode($key) . '=' . urlencode($value) . '&';
     }
     $post = substr($newPost, 0, -1);
     $this->_curlSetOption(CURLOPT_POSTFIELDS, $post);
     return $this->exec($trace);
 }
Ejemplo n.º 3
0
 public function getTableDefinition(Trace $trace, DOMDocument $dom)
 {
     $trace->tlog("finding table definition element");
     $trace->tlogVariable("", $dom->saveXML());
     $element = $dom->getElementById('dataTabColGroup');
     if ($element == null) {
         throw new ParseException("Can't find table headers");
     }
     $list = $element->getElementsByTagName('col');
     $columns = array();
     foreach ($list as $node) {
         assert($node->hasAttribute('shortname'));
         $columns[] = $node->getAttribute('shortname');
     }
     $trace->tlogVariable("Parsed columns:", $columns);
     return $columns;
 }
Ejemplo n.º 4
0
 /**
  * Returns user's full name as reported by ais.
  *
  * @returns string
  */
 public function getFullUserName(Trace $trace)
 {
     $userNameParser = new AIS2UserNameParser();
     $simpleConn = $this->connection->getSimpleConnection();
     $urlMap = $this->connection->getUrlMap();
     $html = $simpleConn->request($trace->addChild('requesting AIS2 main page'), $urlMap->getStartPageUrl());
     $html = $this->convertEncoding($html);
     $username = $userNameParser->parseUserNameFromMainPage($html);
     $trace->tlogVariable('username', $username);
     return $username;
 }
Ejemplo n.º 5
0
 public function getTableData(Trace $trace, DOMDocument $dom)
 {
     $data = array();
     $trace->tlog("finding tbody element");
     $element = $dom->getElementById('dataTabBody0');
     if ($element == null) {
         throw new ParseException("Can't find table data");
     }
     foreach ($element->childNodes as $aisRow) {
         assert($aisRow->tagName == "tr");
         assert($aisRow->hasAttribute("id"));
         assert($aisRow->hasChildNodes());
         // TODO: asserty prerobit na exceptiony
         $row = array();
         $rowId = $aisRow->getAttribute("id");
         $index = StrUtil::match('@^row_([0-9]+)$@', $rowId);
         if ($index === false) {
             throw new ParseException("Unexpected row id format");
         }
         foreach ($aisRow->childNodes as $ais_td) {
             assert($ais_td->tagName == "td");
             $row[] = $this->getCellContent($ais_td);
         }
         $data[$index] = $row;
     }
     $trace->tlogVariable("data", $data);
     return $data;
 }