OSCam/de/XML API: Unterschied zwischen den Versionen

Aus Streamboard Wiki
Zur Navigation springen Zur Suche springen
Zeile 111: Zeile 111:
  
 
=== XML-Parsing: PHP-Beispiel ===
 
=== XML-Parsing: PHP-Beispiel ===
<?php
+
<syntaxhighlight lang="php">
# OSCam XML API example in PHP
+
<?php
# USER SETUP ***********************************************
+
# OSCam XML API example in PHP
$_CONSTANTS = array(
+
# USER SETUP ***********************************************
    'OSCAM_URL'        => 'http://127.0.0.1:4711/oscamapi.html'
+
$_CONSTANTS = array(
    ,'LOCAL_ACCESS_ONLY' => true # true = call OSCam XML API by "wget"; false = call OSCam XML API by URL - default = true
+
    'OSCAM_URL'        => 'http://127.0.0.1:4711/oscamapi.html'
    ,'NL'                => "\n" # Newline
+
  ,'LOCAL_ACCESS_ONLY' => true # true = call OSCam XML API by "wget"; false = call OSCam XML API by URL - default = true
);
+
  ,'NL'                => "\n" # Newline
# END USER SETUP *******************************************
+
);
+
# END USER SETUP *******************************************
# define constants *****************************************
+
 
foreach($_CONSTANTS as $key => $val) {
+
# define constants *****************************************
    if(is_array($_CONSTANTS[$key])) $$key = $val;
+
foreach($_CONSTANTS as $key => $val) {
    else define($key, $val);
+
    if(is_array($_CONSTANTS[$key])) $$key = $val;
}
+
    else define($key, $val);
# save memory...
+
}
unset($_CONSTANTS);
+
# save memory...
+
unset($_CONSTANTS);
# private vars *********************************************
+
 
define('PART_NAME', 'part');
+
# private vars *********************************************
+
define('PART_NAME', 'part');
# OSCam class **********************************************
+
 
class OSCam {
+
# OSCam class **********************************************
    public function getXMLfile($part) {
+
class OSCam {
        $r = null;
+
    public function getXMLfile($part) {
        if(LOCAL_ACCESS_ONLY) {
+
        $r = null;
            $r = trim(shell_exec('wget -O - "'.OSCAM_URL.'?'.PART_NAME.'='.$part.'"'));
+
        if(LOCAL_ACCESS_ONLY) {
        } else {
+
            $r = trim(shell_exec('wget -O - "'.OSCAM_URL.'?'.PART_NAME.'='.$part.'"'));
            $r = file_get_contents(OSCAM_URL.'?'.PART_NAME.'='.$part);
+
        } else {
        }
+
            $r = file_get_contents(OSCAM_URL.'?'.PART_NAME.'='.$part);
        return $r;
+
        }
    }
+
        return $r;
+
    }
    public function getStatusNumOfType(&$xml, $nType) {
+
 
        $r = 0;
+
    public function getStatusNumOfType(&$xml, $nType) {
        $x = new SimpleXMLElement($xml);
+
        $r = 0;
        foreach($x->status->client as $c) {
+
        $x = new SimpleXMLElement($xml);
            if(!empty($c['type']) && $c['type'] == $nType) $r++;
+
        foreach($x->status->client as $c) {
        }
+
            if(!empty($c['type']) && $c['type'] == $nType) $r++;
        return $r;
+
        }
    }
+
        return $r;
}
+
    }
+
}
# OUTPUT-EXAMPLES ******************************************
+
 
$oc = new OSCam;
+
# OUTPUT-EXAMPLES ******************************************
+
$oc = new OSCam;
# status
+
 
$xml = $oc-&gt;getXMLfile('status');
+
# status
+
$xml = $oc->getXMLfile('status');
echo NL.'&lt;h1&gt;XML status content:&lt;/h1&gt;'.NL;
+
 
echo '&lt;pre&gt;'.htmlspecialchars($xml).'&lt;/pre&gt;';
+
echo NL.'<h1>XML status content:</h1>'.NL;
+
echo '<pre>'.htmlspecialchars($xml).'</pre>';
echo NL.'&lt;h1&gt;Number of readers:&lt;/h1&gt;'.NL;
+
 
$t = $oc-&gt;getStatusNumOfType($xml, 'r');
+
echo NL.'<h1>Number of readers:</h1>'.NL;
echo '&lt;pre&gt;'.$t.'&lt;/pre&gt;';
+
$t = $oc->getStatusNumOfType($xml, 'r');
+
echo '<pre>'.$t.'</pre>';
echo NL.'&lt;h1&gt;Number of active clients:&lt;/h1&gt;'.NL;
+
 
$t = $oc-&gt;getStatusNumOfType($xml, 'c');
+
echo NL.'<h1>Number of active clients:</h1>'.NL;
echo '&lt;pre&gt;'.$t.'&lt;/pre&gt;';
+
$t = $oc->getStatusNumOfType($xml, 'c');
+
echo '<pre>'.$t.'</pre>';
?&gt;
+
?>
 +
</syntaxhighlight>
  
  
 
{{OSCamTranslatedLinks}}
 
{{OSCamTranslatedLinks}}

Version vom 30. Jänner 2011, 16:48 Uhr

LanguageDE S.png OSCam Übersicht LanguageEN S.png OSCam Home LanguageFR S.png OSCam Accueil LanguageIT S.png OSCam Home

XML API

Intro

OSCam beinhaltet auch eine API (Application Programming Interface), die z.B. für Imagebauer, Plugin-Entwickler, etc., von großem Nutzen sein kann. Der Zugriff auf die API erfolgt per http oder https.

Kurzum: Mit der XML API können OSCam-Informationen, wie z.B. version, starttime, uptime, ..., sowie auch OSCam-Status, ausgewertet werden.


MessageS.png Info: Die XML API ist selbst noch in der Entwicklung. Nachfolgende Informationen wurden mit OSCAM 1.00-unstable_svn build #4641 gesammelt.

Übersicht

Status ohne Log:

/oscamapi.html?part=status

Status mit Log:

/oscamapi.html?part=status&appendlog=1

Readerstatus mit EMM und LB Stats:

/oscamapi.html?part=readerstats&label=<readername>

Reader Entitlement (momentan nur cccam reader - Karten):

/oscamapi.html?part=entitlement&label=<readername>

Bei falschem Aufruf sollte überall eine auswertbare XML Fehlermeldung kommen:

<?xml version="1.0" encoding="UTF-8"?>
<oscam version="1.00-unstable_svn build #4437" starttime="2011-01-12T23:44:35+0100" uptime="124500" >
    <error>part not found</error>
</oscam> 

MessageS.png Info: Datumsangaben sind in ISO - Zeitangaben in integer Sekunden

Beispielausgaben

Status ohne Log /oscamapi.html?part=status:

<?xml version="1.0" encoding="UTF-8"?>
<oscam version="1.00-unstable_svn build #4641" starttime="2011-01-28T16:00:17+0100" uptime="643" >
    <status>
        <client type="s" name="root" protocol="server" protocolext="" au="0">
          <request caid="0000" srvid="0000" ecmtime="0" answered=""></request>
          <times login="2011-01-28T16:00:17+0100" online="643" idle="0"></times>
          <connection ip="127.0.0.1" port="0">OK</connection>
        </client>
        <client type="h" name="root" protocol="monitor" protocolext="" au="0">
          <request caid="0000" srvid="0000" ecmtime="0" answered=""></request>
          <times login="2011-01-28T16:00:17+0100" online="643" idle="0"></times>
          <connection ip="127.0.0.1" port="0">OK</connection>
        </client>
        <client type="r" name="my_reader_1" protocol="mouse" protocolext="" au="0">
          <request caid="0000" srvid="0000" ecmtime="0" answered=""></request>
          <times login="2011-01-28T16:00:17+0100" online="643" idle="630"></times>
          <connection ip="127.0.0.1" port="0">CARDOK</connection>
        </client>
        <client type="r" name="my_reader_2" protocol="mouse" protocolext="" au="0">
          <request caid="0000" srvid="0000" ecmtime="0" answered=""></request>
          <times login="2011-01-28T16:00:17+0100" online="643" idle="629"></times>
          <connection ip="127.0.0.1" port="0">CARDOK</connection>
        </client>
        <client type="r" name="my_reader_3" protocol="mouse" protocolext="" au="0">
          <request caid="0000" srvid="0000" ecmtime="0" answered=""></request>
          <times login="2011-01-28T16:00:17+0100" online="643" idle="630"></times>
          <connection ip="127.0.0.1" port="0">CARDOK</connection>
        </client>
        <client type="c" name="cccam_2" protocol="newcamd (CCcam)" protocolext="" au="0">
          <request caid="FFFE" srvid="FFFE" ecmtime="0" answered=""></request>
          <times login="2011-01-28T16:00:33+0100" online="627" idle="58"></times>
          <connection ip="127.0.0.1" port="43111">OK</connection>
        </client>
        <client type="c" name="cccam_3" protocol="newcamd (CCcam)" protocolext="" au="0">
          <request caid="1702" srvid="00CA" ecmtime="0" answered="invalid"></request>
          <times login="2011-01-28T16:00:33+0100" online="627" idle="23"></times>
          <connection ip="127.0.0.1" port="33222">OK</connection>
        </client>
        <client type="c" name="cccam_1" protocol="newcamd (CCcam)" protocolext="" au="0">
          <request caid="1702" srvid="00CA" ecmtime="1" answered="invalid"></request>
          <times login="2011-01-28T16:00:56+0100" online="604" idle="23"></times>
          <connection ip="127.0.0.1" port="40333">OK</connection>
        </client>
    </status>
    <log><![CDATA[]]></log>
</oscam>

Readerstatus mit EMM und LB Stats /oscamapi.html?part=readerstats&label=<readername>

<?xml version="1.0" encoding="UTF-8"?>
<oscam version="1.00-unstable_svn build #4641" starttime="2011-01-28T16:00:17+0100" uptime="1718" >
    <reader label="my_reader_1">
        <emmstats totalwritten="4" totalskipped="0" totalblocked="0" totalerror="0">
            <emm type="unknown" result="error">0</emm>
            <emm type="unique" result="error">0</emm>
            <emm type="shared" result="error">0</emm>
            <emm type="global" result="error">0</emm>
            <emm type="unknown" result="written">0</emm>
            <emm type="unique" result="written">0</emm>
            <emm type="shared" result="written">0</emm>
            <emm type="global" result="written">4</emm>
            <emm type="unknown" result="skipped">0</emm>
            <emm type="unique" result="skipped">0</emm>
            <emm type="shared" result="skipped">0</emm>
            <emm type="global" result="skipped">0</emm>
            <emm type="unknown" result="blocked">0</emm>
            <emm type="unique" result="blocked">0</emm>
            <emm type="shared" result="blocked">0</emm>
            <emm type="global" result="blocked">0</emm>
        </emmstats>
        <ecmstats count="1" totalecm="68" lastaccess="2011-01-28T16:28:52+0100">
            <ecm caid="1702" provid="000000" srvid="00DF" channelname="Bundesliga" avgtime="541" lasttime="543" rc="0" rcs="found" lastrequest="2011-01-28T16:28:52+0100">68</ecm>
        </ecmstats>
    </reader>
</oscam>

XML-Parsing: PHP-Beispiel

<syntaxhighlight lang="php"> <?php

  1. OSCam XML API example in PHP
  2. USER SETUP ***********************************************

$_CONSTANTS = array(

   'OSCAM_URL'         => 'http://127.0.0.1:4711/oscamapi.html'
  ,'LOCAL_ACCESS_ONLY' => true # true = call OSCam XML API by "wget"; false = call OSCam XML API by URL - default = true
  ,'NL'                => "\n" # Newline

);

  1. END USER SETUP *******************************************
  1. define constants *****************************************

foreach($_CONSTANTS as $key => $val) {

   if(is_array($_CONSTANTS[$key])) $$key = $val;
   else define($key, $val);

}

  1. save memory...

unset($_CONSTANTS);

  1. private vars *********************************************

define('PART_NAME', 'part');

  1. OSCam class **********************************************

class OSCam {

   public function getXMLfile($part) {
       $r = null;
       if(LOCAL_ACCESS_ONLY) {
           $r = trim(shell_exec('wget -O - "'.OSCAM_URL.'?'.PART_NAME.'='.$part.'"'));
       } else {
           $r = file_get_contents(OSCAM_URL.'?'.PART_NAME.'='.$part);
       }
       return $r;
   }
   public function getStatusNumOfType(&$xml, $nType) {
       $r = 0;
       $x = new SimpleXMLElement($xml);
       foreach($x->status->client as $c) {
           if(!empty($c['type']) && $c['type'] == $nType) $r++;
       }
       return $r;
   }

}

  1. OUTPUT-EXAMPLES ******************************************

$oc = new OSCam;

  1. status

$xml = $oc->getXMLfile('status');

echo NL.'

XML status content:

'.NL; echo '

'.htmlspecialchars($xml).'

'; echo NL.'

Number of readers:

'.NL;

$t = $oc->getStatusNumOfType($xml, 'r');

echo '

'.$t.'

'; echo NL.'

Number of active clients:

'.NL;

$t = $oc->getStatusNumOfType($xml, 'c');

echo '

'.$t.'

';

?> </syntaxhighlight>


Diese Seite in anderen Sprachen - This page in other languages - Cette page dans d'autres langues - Queste pagine in altre Lingue

LanguageDE S.png [[OSCam/de/{{#titleparts:OSCam/de/XML_API|3|3}}|Deutsch]] LanguageEN S.png [[OSCam/en/{{#titleparts:OSCam/de/XML_API|3|3}}|English]] LanguageFR S.png [[OSCam/fr/{{#titleparts:OSCam/de/XML_API|3|3}}|Français]] LanguageIT S.png [[OSCam/it/{{#titleparts:OSCam/de/XML_API|3|3}}|Italiano]]