<commit_before><?php
/**********************************************************\
|                                                          |
|                          hprose                          |
|                                                          |
| Official WebSite: http://www.hprose.com/                 |
|                   http://www.hprose.org/                 |
|                                                          |
\**********************************************************/

/**********************************************************\
 *                                                        *
 * JSONRPCServiceFilter.php                               *
 *                                                        *
 * json rpc service filter class for php5.                *
 *                                                        *
 * LastModified: Oct 14, 2014                             *
 * Author: <NAME> <<EMAIL>>                  *
 *                                                        *
\**********************************************************/

class JSONRPCServiceFilter implements HproseFilter {
    function inputFilter($data, $context) {
        if ($data !== "" && $data{0} === '{') {
            $context->userdata->format = "jsonrpc";
            $request = json_decode($data);
            if (isset($request->id)) {
                $context->userdata->id = $request->id;
            }
            else {
                $context->userdata->id = NULL;
            }
            if (isset($request->version)) {
                $context->userdata->version = $request->version;            
            }
            else if (isset($request->jsonrpc)) {
                $context->userdata->version = $request->jsonrpc;            
            }
            else {
                $context->userdata->version = "1.0";
            }
            $data = "";
            if (isset($request->method)) {
                $data = HproseTags::TagCall . hprose_serialize_string($request->method);
                if (isset($request->params)) {
                    $data .= hprose_serialize_list($request->params, true);
                }
            }
            $data .= HproseTags::TagEnd;
        }
        return $data;
    }

    function outputFilter($data, $context) {
        if (isset($context->userdata->format) && $context->userdata->format === "jsonrpc") {        
            $response = new stdClass();
            $response->id = $context->userdata->id;
            if ($context->userdata->version != "2.0") {
                if ($context->userdata->version == "1.1") {
                    $response->version = "1.1";
                }
                $response->result = NULL;
                $response->error = NULL;
            }
            else {
                $response->jsonrpc = "2.0";
            }
            $stream = new HproseStringStream($data);
            if ($data !== "") {
                while (($tag = $stream->getc()) !== HproseTags::TagEnd) {
                    switch ($tag) {
                        case HproseTags::TagResult:
                            $response->result = &hprose_unserialize_with_stream($stream);
                            break;
                        case HproseTags::TagError:
                            $lasterror = error_get_last();
                            $response->error = array("code" => $lasterror["type"], "message" => hprose_unserialize_with_stream($stream));
                            break;
                        case HproseTags::TagFunctions:
                            $response->result = &hprose_unserialize_with_stream($stream);
                            break;
                        default:
                            return json_encode($response);
                            break;
                    }
                }
            }
            $data = json_encode($response);
        }
        return $data;
    }
}

?><commit_msg>Update JSONRPCServiceFilter<commit_after><?php
/**********************************************************\
|                                                          |
|                          hprose                          |
|                                                          |
| Official WebSite: http://www.hprose.com/                 |
|                   http://www.hprose.org/                 |
|                                                          |
\**********************************************************/

/**********************************************************\
 *                                                        *
 * JSONRPCServiceFilter.php                               *
 *                                                        *
 * json rpc service filter class for php5.                *
 *                                                        *
 * LastModified: Oct 15, 2014                             *
 * Author: <NAME> <<EMAIL>>                  *
 *                                                        *
\**********************************************************/

class JSONRPCServiceFilter implements HproseFilter {
    function inputFilter($data, $context) {
        if ($data !== "" && $data{0} === '{') {
            $context->userdata->format = "jsonrpc";
            $request = json_decode($data);
            if (isset($request->id)) {
                $context->userdata->id = $request->id;
            }
            else {
                $context->userdata->id = NULL;
            }
            if (isset($request->version)) {
                $context->userdata->version = $request->version;            
            }
            else if (isset($request->jsonrpc)) {
                $context->userdata->version = $request->jsonrpc;            
            }
            else {
                $context->userdata->version = "1.0";
            }
            $data = "";
            if (isset($request->method)) {
                $data = HproseTags::TagCall . hprose_serialize_string($request->method);
                if (isset($request->params)) {
                    $data .= hprose_serialize_list($request->params, true);
                }
            }
            $data .= HproseTags::TagEnd;
        }
        return $data;
    }

    function outputFilter($data, $context) {
        if (isset($context->userdata->format) && $context->userdata->format === "jsonrpc") {        
            $response = new stdClass();
            $response->id = $context->userdata->id;
            if ($context->userdata->version != "2.0") {
                if ($context->userdata->version == "1.1") {
                    $response->version = "1.1";
                }
                $response->result = NULL;
                $response->error = NULL;
            }
            else {
                $response->jsonrpc = "2.0";
            }
            if ($data !== "") {
                $stream = new HproseStringStream($data);
                while (($tag = $stream->getc()) !== HproseTags::TagEnd) {
                    switch ($tag) {
                        case HproseTags::TagResult:
                            $response->result = &hprose_unserialize_with_stream($stream);
                            break;
                        case HproseTags::TagError:
                            $lasterror = error_get_last();
                            $response->error = array("code" => $lasterror["type"], "message" => hprose_unserialize_with_stream($stream));
                            break;
                        case HproseTags::TagFunctions:
                            $response->result = &hprose_unserialize_with_stream($stream);
                            break;
                        default:
                            return json_encode($response);
                            break;
                    }
                }
            }
            $data = json_encode($response);
        }
        return $data;
    }
}

?>
{'fraction_non_alphanumeric': 0.17183591795897948, 'fraction_numerical': 0.004502251125562781, 'mean_word_length': 1.0153729838709677, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '900246', 'n_tokens_mistral': 1798, 'n_tokens_neox': 1714, 'n_words': 271}