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

📄 server.php

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PHP
📖 第 1 页 / 共 2 页
字号:
     *                          array are the procedure names used by the     *                          clients. The value is another associative array     *                          that contains up to three elements:     *                            + The 'function' element's value is the name     *                              of the function or method that gets called.     *                              To define a class' method: 'class::method'.     *                            + The 'signature' element (optional) is an     *                              array describing the return values and     *                              parameters     *                            + The 'docstring' element (optional) is a     *                              string describing what the method does     * @param int $serviceNow  should the HTTP response be sent now?     *                          (1 = yes, 0 = no)     * @param int $debug       should debug output be displayed?     *                          (1 = yes, 0 = no)     *     * @return void     */    function XML_RPC_Server($dispMap, $serviceNow = 1, $debug = 0)    {        global $HTTP_RAW_POST_DATA;        if ($debug) {            $this->debug = 1;        } else {            $this->debug = 0;        }        $this->dmap = $dispMap;        if ($serviceNow) {            $this->service();        } else {            $this->createServerPayload();            $this->createServerHeaders();        }    }    /**     * @return string  the debug information if debug debug mode is on     */    function serializeDebug()    {        global $XML_RPC_Server_debuginfo, $HTTP_RAW_POST_DATA;        if ($this->debug) {            XML_RPC_Server_debugmsg('vvv POST DATA RECEIVED BY SERVER vvv' . "\n"                                    . $HTTP_RAW_POST_DATA                                    . "\n" . '^^^ END POST DATA ^^^');        }        if ($XML_RPC_Server_debuginfo != '') {            return "<!-- PEAR XML_RPC SERVER DEBUG INFO:\n\n"                   . preg_replace('/-(?=-)/', '- ', $XML_RPC_Server_debuginfo)                   . "-->\n";        } else {            return '';        }    }    /**     * Sends the response     *     * The encoding and content-type are determined by     * XML_RPC_Message::getEncoding()     *     * @return void     *     * @uses XML_RPC_Server::createServerPayload(),     *       XML_RPC_Server::createServerHeaders()     */    function service()    {        if (!$this->server_payload) {            $this->createServerPayload();        }        if (!$this->server_headers) {            $this->createServerHeaders();        }        header($this->server_headers);        print $this->server_payload;    }    /**     * Generates the payload and puts it in the $server_payload property     *     * @return void     *     * @uses XML_RPC_Server::parseRequest(), XML_RPC_Server::$encoding,     *       XML_RPC_Response::serialize(), XML_RPC_Server::serializeDebug()     */    function createServerPayload()    {        $r = $this->parseRequest();        $this->server_payload = '<?xml version="1.0" encoding="'                              . $this->encoding . '"?>' . "\n"                              . $this->serializeDebug()                              . $r->serialize();    }    /**     * Determines the HTTP headers and puts them in the $server_headers     * property     *     * @return boolean  TRUE if okay, FALSE if $server_payload isn't set.     *     * @uses XML_RPC_Server::createServerPayload(),     *       XML_RPC_Server::$server_headers     */    function createServerHeaders()    {        if (!$this->server_payload) {            return false;        }        $this->server_headers = 'Content-Length: '                              . strlen($this->server_payload) . "\r\n"                              . 'Content-Type: text/xml;'                              . ' charset=' . $this->encoding;        return true;    }    /**     * @return array     */    function verifySignature($in, $sig)    {        for ($i = 0; $i < sizeof($sig); $i++) {            // check each possible signature in turn            $cursig = $sig[$i];            if (sizeof($cursig) == $in->getNumParams() + 1) {                $itsOK = 1;                for ($n = 0; $n < $in->getNumParams(); $n++) {                    $p = $in->getParam($n);                    // print "<!-- $p -->\n";                    if ($p->kindOf() == 'scalar') {                        $pt = $p->scalartyp();                    } else {                        $pt = $p->kindOf();                    }                    // $n+1 as first type of sig is return type                    if ($pt != $cursig[$n+1]) {                        $itsOK = 0;                        $pno = $n+1;                        $wanted = $cursig[$n+1];                        $got = $pt;                        break;                    }                }                if ($itsOK) {                    return array(1);                }            }        }        if (isset($wanted)) {            return array(0, "Wanted ${wanted}, got ${got} at param ${pno}");        } else {            $allowed = array();            foreach ($sig as $val) {                end($val);                $allowed[] = key($val);            }            $allowed = array_unique($allowed);            $last = count($allowed) - 1;            if ($last > 0) {                $allowed[$last] = 'or ' . $allowed[$last];            }            return array(0,                         'Signature permits ' . implode(', ', $allowed)                                . ' parameters but the request had '                                . $in->getNumParams());        }    }    /**     * @return object  a new XML_RPC_Response object     *     * @uses XML_RPC_Message::getEncoding(), XML_RPC_Server::$encoding     */    function parseRequest($data = '')    {        global $XML_RPC_xh, $HTTP_RAW_POST_DATA,                $XML_RPC_err, $XML_RPC_str, $XML_RPC_errxml,                $XML_RPC_defencoding, $XML_RPC_Server_dmap;        if ($data == '') {            $data = $HTTP_RAW_POST_DATA;        }        $this->encoding = XML_RPC_Message::getEncoding($data);        $parser_resource = xml_parser_create($this->encoding);        $parser = (int) $parser_resource;        $XML_RPC_xh[$parser] = array();        $XML_RPC_xh[$parser]['cm']     = 0;        $XML_RPC_xh[$parser]['isf']    = 0;        $XML_RPC_xh[$parser]['params'] = array();        $XML_RPC_xh[$parser]['method'] = '';        $XML_RPC_xh[$parser]['stack'] = array();	        $XML_RPC_xh[$parser]['valuestack'] = array();	        $plist = '';        // decompose incoming XML into request structure        xml_parser_set_option($parser_resource, XML_OPTION_CASE_FOLDING, true);        xml_set_element_handler($parser_resource, 'XML_RPC_se', 'XML_RPC_ee');        xml_set_character_data_handler($parser_resource, 'XML_RPC_cd');        if (!xml_parse($parser_resource, $data, 1)) {            // return XML error as a faultCode            $r = new XML_RPC_Response(0,                                      $XML_RPC_errxml+xml_get_error_code($parser_resource),                                      sprintf('XML error: %s at line %d',                                              xml_error_string(xml_get_error_code($parser_resource)),                                              xml_get_current_line_number($parser_resource)));            xml_parser_free($parser_resource);        } elseif ($XML_RPC_xh[$parser]['isf']>1) {            $r = new XML_RPC_Response(0,                                      $XML_RPC_err['invalid_request'],                                      $XML_RPC_str['invalid_request']                                      . ': '                                      . $XML_RPC_xh[$parser]['isf_reason']);            xml_parser_free($parser_resource);        } else {            xml_parser_free($parser_resource);            $m = new XML_RPC_Message($XML_RPC_xh[$parser]['method']);            // now add parameters in            for ($i = 0; $i < sizeof($XML_RPC_xh[$parser]['params']); $i++) {                // print '<!-- ' . $XML_RPC_xh[$parser]['params'][$i]. "-->\n";                $plist .= "$i - " . var_export($XML_RPC_xh[$parser]['params'][$i], true) . " \n";                $m->addParam($XML_RPC_xh[$parser]['params'][$i]);            }            if ($this->debug) {                XML_RPC_Server_debugmsg($plist);            }            // now to deal with the method            $methName = $XML_RPC_xh[$parser]['method'];            if (strpos($methName, 'system.') === 0) {                $dmap = $XML_RPC_Server_dmap;                $sysCall = 1;            } else {                $dmap = $this->dmap;                $sysCall = 0;            }            if (isset($dmap[$methName]['function'])                && is_string($dmap[$methName]['function'])                && strpos($dmap[$methName]['function'], '::') !== false)            {                $dmap[$methName]['function'] =                        explode('::', $dmap[$methName]['function']);            }            if (isset($dmap[$methName]['function'])                && is_callable($dmap[$methName]['function']))            {                // dispatch if exists                if (isset($dmap[$methName]['signature'])) {                    $sr = $this->verifySignature($m,                                                 $dmap[$methName]['signature'] );                }                if (!isset($dmap[$methName]['signature']) || $sr[0]) {                    // if no signature or correct signature                    if ($sysCall) {                        $r = call_user_func($dmap[$methName]['function'], $this, $m);                    } else {                        $r = call_user_func($dmap[$methName]['function'], $m);                    }                    if (!is_a($r, 'XML_RPC_Response')) {                        $r = new XML_RPC_Response(0, $XML_RPC_err['not_response_object'],                                                  $XML_RPC_str['not_response_object']);                    }                } else {                    $r = new XML_RPC_Response(0, $XML_RPC_err['incorrect_params'],                                              $XML_RPC_str['incorrect_params']                                              . ': ' . $sr[1]);                }            } else {                // else prepare error response                $r = new XML_RPC_Response(0, $XML_RPC_err['unknown_method'],                                          $XML_RPC_str['unknown_method']);            }        }        return $r;    }    /**     * Echos back the input packet as a string value     *     * @return void     *     * Useful for debugging.     */    function echoInput()    {        global $HTTP_RAW_POST_DATA;        $r = new XML_RPC_Response(0);        $r->xv = new XML_RPC_Value("'Aha said I: '" . $HTTP_RAW_POST_DATA, 'string');        print $r->serialize();    }}/* * 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 + -