⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rpc.php

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PHP
📖 第 1 页 / 共 4 页
字号:
                $type = 'string';            }            if (!array_key_exists($type, $XML_RPC_Types)) {                // XXX                // need some way to report this error            } elseif ($XML_RPC_Types[$type] == 1) {                $this->addScalar($val, $type);            } elseif ($XML_RPC_Types[$type] == 2) {                $this->addArray($val);            } elseif ($XML_RPC_Types[$type] == 3) {                $this->addStruct($val);            }        }    }    /**     * @return int  returns 1 if successful or 0 if there are problems     */    function addScalar($val, $type = 'string')    {        global $XML_RPC_Types, $XML_RPC_Boolean;        if ($this->mytype == 1) {            $this->raiseError('Scalar can have only one value',                              XML_RPC_ERROR_INVALID_TYPE);            return 0;        }        $typeof = $XML_RPC_Types[$type];        if ($typeof != 1) {            $this->raiseError("Not a scalar type (${typeof})",                              XML_RPC_ERROR_INVALID_TYPE);            return 0;        }        if ($type == $XML_RPC_Boolean) {            if (strcasecmp($val, 'true') == 0                || $val == 1                || ($val == true && strcasecmp($val, 'false')))            {                $val = 1;            } else {                $val = 0;            }        }        if ($this->mytype == 2) {            // we're adding to an array here            $ar = $this->me['array'];            $ar[] = new XML_RPC_Value($val, $type);            $this->me['array'] = $ar;        } else {            // a scalar, so set the value and remember we're scalar            $this->me[$type] = $val;            $this->mytype = $typeof;        }        return 1;    }    /**     * @return int  returns 1 if successful or 0 if there are problems     */    function addArray($vals)    {        global $XML_RPC_Types;        if ($this->mytype != 0) {            $this->raiseError(                    'Already initialized as a [' . $this->kindOf() . ']',                    XML_RPC_ERROR_ALREADY_INITIALIZED);            return 0;        }        $this->mytype = $XML_RPC_Types['array'];        $this->me['array'] = $vals;        return 1;    }    /**     * @return int  returns 1 if successful or 0 if there are problems     */    function addStruct($vals)    {        global $XML_RPC_Types;        if ($this->mytype != 0) {            $this->raiseError(                    'Already initialized as a [' . $this->kindOf() . ']',                    XML_RPC_ERROR_ALREADY_INITIALIZED);            return 0;        }        $this->mytype = $XML_RPC_Types['struct'];        $this->me['struct'] = $vals;        return 1;    }    /**     * @return void     */    function dump($ar)    {        reset($ar);        foreach ($ar as $key => $val) {            echo "$key => $val<br />";            if ($key == 'array') {                foreach ($val as $key2 => $val2) {                    echo "-- $key2 => $val2<br />";                }            }        }    }    /**     * @return string  the data type of the current value     */    function kindOf()    {        switch ($this->mytype) {        case 3:            return 'struct';        case 2:            return 'array';        case 1:            return 'scalar';        default:            return 'undef';        }    }    /**     * @return string  the data in XML format     */    function serializedata($typ, $val)    {        $rs = '';        global $XML_RPC_Types, $XML_RPC_Base64, $XML_RPC_String, $XML_RPC_Boolean;        if (!array_key_exists($typ, $XML_RPC_Types)) {            // XXX            // need some way to report this error            return;        }        switch ($XML_RPC_Types[$typ]) {        case 3:            // struct            $rs .= "<struct>\n";            reset($val);            foreach ($val as $key2 => $val2) {                $rs .= "<member><name>${key2}</name>\n";                $rs .= $this->serializeval($val2);                $rs .= "</member>\n";            }            $rs .= '</struct>';            break;        case 2:            // array            $rs .= "<array>\n<data>\n";            for ($i = 0; $i < sizeof($val); $i++) {                $rs .= $this->serializeval($val[$i]);            }            $rs .= "</data>\n</array>";            break;        case 1:            switch ($typ) {            case $XML_RPC_Base64:                $rs .= "<${typ}>" . base64_encode($val) . "</${typ}>";                break;            case $XML_RPC_Boolean:                $rs .= "<${typ}>" . ($val ? '1' : '0') . "</${typ}>";                break;            case $XML_RPC_String:                $rs .= "<${typ}>" . htmlspecialchars($val). "</${typ}>";                break;            default:                $rs .= "<${typ}>${val}</${typ}>";            }        }        return $rs;    }    /**     * @return string  the data in XML format     */    function serialize()    {        return $this->serializeval($this);    }    /**     * @return string  the data in XML format     */    function serializeval($o)    {        if (!is_object($o) || empty($o->me) || !is_array($o->me)) {            return '';        }        $ar = $o->me;        reset($ar);        list($typ, $val) = each($ar);        return '<value>' .  $this->serializedata($typ, $val) .  "</value>\n";    }    /**     * @return mixed  the contents of the element requested     */    function structmem($m)    {        return $this->me['struct'][$m];    }    /**     * @return void     */    function structreset()    {        reset($this->me['struct']);    }    /**     * @return  the key/value pair of the struct's current element     */    function structeach()    {        return each($this->me['struct']);    }    /**     * @return mixed  the current value     */    function getval()    {        // UNSTABLE        global $XML_RPC_BOOLEAN, $XML_RPC_Base64;        reset($this->me);        $b = current($this->me);        // contributed by I Sofer, 2001-03-24        // add support for nested arrays to scalarval        // i've created a new method here, so as to        // preserve back compatibility        if (is_array($b)) {            foreach ($b as $id => $cont) {                $b[$id] = $cont->scalarval();            }        }        // add support for structures directly encoding php objects        if (is_object($b)) {            $t = get_object_vars($b);            foreach ($t as $id => $cont) {                $t[$id] = $cont->scalarval();            }            foreach ($t as $id => $cont) {                $b->$id = $cont;            }        }        // end contrib        return $b;    }    /**     * @return mixed     */    function scalarval()    {        global $XML_RPC_Boolean, $XML_RPC_Base64;        reset($this->me);        return current($this->me);    }    /**     * @return string     */    function scalartyp()    {        global $XML_RPC_I4, $XML_RPC_Int;        reset($this->me);        $a = key($this->me);        if ($a == $XML_RPC_I4) {            $a = $XML_RPC_Int;        }        return $a;    }    /**     * @return mixed  the struct's current element     */    function arraymem($m)    {        return $this->me['array'][$m];    }    /**     * @return int  the number of elements in the array     */    function arraysize()    {        reset($this->me);        list($a, $b) = each($this->me);        return sizeof($b);    }    /**     * Determines if the item submitted is an XML_RPC_Value object     *     * @param mixed $val  the variable to be evaluated     *     * @return bool  TRUE if the item is an XML_RPC_Value object     *     * @static     * @since Method available since Release 1.3.0     */    function isValue($val)    {        return (strtolower(get_class($val)) == 'xml_rpc_value');    }}/** * Return an ISO8601 encoded string * * While timezones ought to be supported, the XML-RPC spec says: * * "Don't assume a timezone. It should be specified by the server in its * documentation what assumptions it makes about timezones." * * This routine always assumes localtime unless $utc is set to 1, in which * case UTC is assumed and an adjustment for locale is made when encoding. * * @return string  the formatted date */function XML_RPC_iso8601_encode($timet, $utc = 0){    if (!$utc) {        $t = strftime('%Y%m%dT%H:%M:%S', $timet);    } else {        if (function_exists('gmstrftime')) {            // gmstrftime doesn't exist in some versions            // of PHP            $t = gmstrftime('%Y%m%dT%H:%M:%S', $timet);        } else {            $t = strftime('%Y%m%dT%H:%M:%S', $timet - date('Z'));        }    }    return $t;}/** * Convert a datetime string into a Unix timestamp * * While timezones ought to be supported, the XML-RPC spec says: * * "Don't assume a timezone. It should be specified by the server in its * documentation what assumptions it makes about timezones." * * This routine always assumes localtime unless $utc is set to 1, in which * case UTC is assumed and an adjustment for locale is made when encoding. * * @return int  the unix timestamp of the date submitted */function XML_RPC_iso8601_decode($idate, $utc = 0){    $t = 0;    if (ereg('([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})', $idate, $regs)) {        if ($utc) {            $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);        } else {            $t = mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);        }    }    return $t;}/** * Converts an XML_RPC_Value object into native PHP types * * @param object $XML_RPC_val  the XML_RPC_Value object to decode * * @return mixed  the PHP values */function XML_RPC_decode($XML_RPC_val){    $kind = $XML_RPC_val->kindOf();    if ($kind == 'scalar') {        return $XML_RPC_val->scalarval();    } elseif ($kind == 'array') {        $size = $XML_RPC_val->arraysize();        $arr = array();        for ($i = 0; $i < $size; $i++) {            $arr[] = XML_RPC_decode($XML_RPC_val->arraymem($i));        }        return $arr;    } elseif ($kind == 'struct') {        $XML_RPC_val->structreset();        $arr = array();        while (list($key, $value) = $XML_RPC_val->structeach()) {            $arr[$key] = XML_RPC_decode($value);        }        return $arr;    }}/** * Converts native PHP types into an XML_RPC_Value object * * @param mixed $php_val  the PHP value or variable you want encoded * * @return object  the XML_RPC_Value object */function XML_RPC_encode($php_val){    global $XML_RPC_Boolean, $XML_RPC_Int, $XML_RPC_Double, $XML_RPC_String,           $XML_RPC_Array, $XML_RPC_Struct, $XML_RPC_DateTime;    $type = gettype($php_val);    $XML_RPC_val = new XML_RPC_Value;    switch ($type) {    case 'array':        if (empty($php_val)) {            $XML_RPC_val->addArray($php_val);            break;        }        $tmp = array_diff(array_keys($php_val), range(0, count($php_val)-1));        if (empty($tmp)) {           $arr = array();           foreach ($php_val as $k => $v) {               $arr[$k] = XML_RPC_encode($v);           }           $XML_RPC_val->addArray($arr);           break;        }        // fall though if it's not an enumerated array    case 'object':        $arr = array();        foreach ($php_val as $k => $v) {            $arr[$k] = XML_RPC_encode($v);        }        $XML_RPC_val->addStruct($arr);        break;    case 'integer':        $XML_RPC_val->addScalar($php_val, $XML_RPC_Int);        break;    case 'double':        $XML_RPC_val->addScalar($php_val, $XML_RPC_Double);        break;    case 'string':    case 'NULL':        if(ereg('^[0-9]{8}\T{1}[0-9]{2}\:[0-9]{2}\:[0-9]{2}$', $php_val)) {            $XML_RPC_val->addScalar($php_val, $XML_RPC_DateTime);        } else {            $XML_RPC_val->addScalar($php_val, $XML_RPC_String);        }        break;    case 'boolean':        // Add support for encoding/decoding of booleans, since they        // are supported in PHP        // by <G_Giunta_2001-02-29>        $XML_RPC_val->addScalar($php_val, $XML_RPC_Boolean);        break;    case 'unknown type':    default:        $XML_RPC_val = false;    }    return $XML_RPC_val;}/* * Local variables: * tab-width: 4 * c-basic-offset: 4 * c-hanging-comment-ender-p: nil * End: */?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -