OSCam/fr/XML API

Aus Streamboard Wiki
Wechseln zu: Navigation, Suche

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

ÄNDERUNG - CHANGE - MODIFICATIONS - MODIFICA svn4835:03/19/2011

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-Stati, 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. Hier ist der entsprechende Thread im Forum: http://www.streamboard.tv/wbb2/thread.php?threadid=30478 .

Ü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

<?php
# OSCam XML API example in PHP
# 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
);
# END USER SETUP *******************************************

# define constants *****************************************
foreach($_CONSTANTS as $key => $val) {
    if(is_array($_CONSTANTS[$key])) $$key = $val;
    else define($key, $val);
}
# save memory...
unset($_CONSTANTS);

# private vars *********************************************
define('PART_NAME', 'part');

# 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;
    }
}

# OUTPUT-EXAMPLES ******************************************
$oc = new OSCam;

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

echo NL.'<h1>XML status content:</h1>'.NL;
echo '<pre>'.htmlspecialchars($xml).'</pre>';

echo NL.'<h1>Number of readers:</h1>'.NL;
$t = $oc->getStatusNumOfType($xml, 'r');
echo '<pre>'.$t.'</pre>';

echo NL.'<h1>Number of active clients:</h1>'.NL;
$t = $oc->getStatusNumOfType($xml, 'c');
echo '<pre>'.$t.'</pre>';

?>


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

LanguageDE S.png Deutsch LanguageEN S.png English LanguageFR S.png Français LanguageIT S.png Italiano