예제 #1
0
 /**
  * コンストラクタ
  *
  * @param string $code
  * @param string $mesg
  * @param string $line
  */
 public function __construct($code, $mesg, $line = null)
 {
     ASSERT('is_null($code) || is_int($code)');
     ASSERT('is_string($mesg)');
     if ($line === null) {
         $line = "{$code} {$mesg}";
     }
     $this->_line = $line;
     $this->_code = $code;
     $this->_mesg = $mesg;
 }
예제 #2
0
 function read($fp, &$limit = PHP_INT_MAX)
 {
     while (!feof($fp) && $limit > 0) {
         $tag = Protobuf::read_varint($fp, $limit);
         if ($tag === false) {
             break;
         }
         $wire = $tag & 0x7;
         $field = $tag >> 3;
         //var_dump("Log_Content: Found $field type " . Protobuf::get_wiretype($wire) . " $limit bytes left");
         switch ($field) {
             case 1:
                 ASSERT('$wire == 2');
                 $len = Protobuf::read_varint($fp, $limit);
                 if ($len === false) {
                     throw new Exception('Protobuf::read_varint returned false');
                 }
                 if ($len > 0) {
                     $tmp = fread($fp, $len);
                 } else {
                     $tmp = '';
                 }
                 if ($tmp === false) {
                     throw new Exception("fread({$len}) returned false");
                 }
                 $this->key_ = $tmp;
                 $limit -= $len;
                 break;
             case 2:
                 ASSERT('$wire == 2');
                 $len = Protobuf::read_varint($fp, $limit);
                 if ($len === false) {
                     throw new Exception('Protobuf::read_varint returned false');
                 }
                 if ($len > 0) {
                     $tmp = fread($fp, $len);
                 } else {
                     $tmp = '';
                 }
                 if ($tmp === false) {
                     throw new Exception("fread({$len}) returned false");
                 }
                 $this->value_ = $tmp;
                 $limit -= $len;
                 break;
             default:
                 $this->_unknown[$field . '-' . Protobuf::get_wiretype($wire)][] = Protobuf::read_field($fp, $wire, $limit);
         }
     }
     if (!$this->validateRequired()) {
         throw new Exception('Required fields are missing');
     }
 }
예제 #3
0
 /**
  * ワーカーの初期化
  */
 public function init()
 {
     ASSERT(' $this->_sigset === null ');
     ASSERT(' $this->_pidlock === null ');
     // ログ
     $pid = posix_getpid();
     $this->_log("init worker [{$pid} => {$this->_pidfile}]");
     // PIDファイルをロック
     $this->_pidlock = new PidFileFlock($this->_pidfile, $pid);
     // シグナルのセット
     $this->_sigset = array(SIGTERM, SIGINT, SIGHUP, SIGUSR2);
     pcntl_sigprocmask(SIG_BLOCK, $this->_sigset);
     // シグナルの無視設定
     pcntl_signal(SIGUSR2, SIG_IGN);
 }
예제 #4
0
 function read($fp, &$limit = PHP_INT_MAX)
 {
     while (!feof($fp) && $limit > 0) {
         $tag = Protobuf::read_varint($fp, $limit);
         if ($tag === false) {
             break;
         }
         $wire = $tag & 0x7;
         $field = $tag >> 3;
         //var_dump("LogGroupList: Found $field type " . Protobuf::get_wiretype($wire) . " $limit bytes left");
         switch ($field) {
             case 1:
                 ASSERT('$wire == 2');
                 $len = Protobuf::read_varint($fp, $limit);
                 if ($len === false) {
                     throw new Exception('Protobuf::read_varint returned false');
                 }
                 $limit -= $len;
                 $this->logGroupList_[] = new LogGroup($fp, $len);
                 ASSERT('$len == 0');
                 break;
             default:
                 $this->_unknown[$field . '-' . Protobuf::get_wiretype($wire)][] = Protobuf::read_field($fp, $wire, $limit);
         }
     }
     if (!$this->validateRequired()) {
         throw new Exception('Required fields are missing');
     }
 }
 /**
  * ロガーを設定
  *
  * @param callable $logger
  */
 public function setLogger($logger)
 {
     ASSERT('is_callable($logger)');
     $this->_logger = $logger;
     return $this;
 }
예제 #6
0
 /**
  * データを送信する
  *
  * @param string $data
  *
  * @throws TransportException
  */
 public function send($data)
 {
     ASSERT(' is_resource($this->_stream) ');
     ASSERT(' is_string($data) ');
     $handler = new ErrorHandler();
     try {
         $pos = 0;
         $len = strlen($data);
         while ($pos < $len) {
             $n = fwrite($this->_stream, substr($data, $pos));
             if ($n == 0) {
                 // @codeCoverageIgnoreStart
                 throw new TransportException("fwrite(): unknown error");
                 // @codeCoverageIgnoreEnd
             }
             $pos += $n;
         }
         $handler->restore();
     } catch (\Exception $ex) {
         $handler->restore();
         throw $ex;
     }
 }
예제 #7
0
 /**
  * データを送信する
  *
  * @param string $data
  *
  * @throws TransportException
  */
 public function send($data)
 {
     ASSERT('is_resource($this->_socket)');
     ASSERT(' is_string($data) ');
     while (strlen($data)) {
         $len = @socket_send($this->_socket, $data, strlen($data), 0);
         if ($len == 0) {
             self::raiseSocketException('socket_send', $this->_socket);
         }
         $data = substr($data, $len);
     }
 }
예제 #8
0
/**
 * userid : allowed | denied : url1,url2,
 */
function CheckAccess($user, $path)
{
    global $LoginACL;
    $file = @fopen($LoginACL, "r");
    if ($file) {
        $ok = false;
        $done = false;
        while ($ln = fgets($file, 4096)) {
            // ignore comment or empty lines
            if (ereg("^ *#|^ *\$", $ln)) {
                continue;
            }
            // userid: url,url,...
            list($uid, $action, $url_list) = explode(":", $ln);
            $uid = trim($uid);
            $action = strtoupper(trim($action));
            $url_list = trim($url_list);
            if ($uid == $user || $uid == "*") {
                $a = explode(",", $url_list);
                for ($i = 0; $i < count($a); $i++) {
                    $ok = false;
                    $s = trim($a[$i]);
                    if ($action == "ALLOW") {
                        $ok = $path == "*" || ereg("^{$s}", $path);
                        if ($ok) {
                            $done = true;
                            break;
                        }
                    } else {
                        if ($action == "DENY") {
                            $ok = $path != "*" && !ereg("^{$s}", $path);
                            if (!$ok) {
                                $done = true;
                                break;
                            }
                        } else {
                            ASSERT(1, "ERROR: Invalid ACCESS CONTROL option!");
                        }
                    }
                }
            }
            if ($done) {
                break;
            }
        }
        fclose($file);
        if (!$ok) {
            LogSQL("*** ACL ACCESS DENIED (uid={$user},path={$path}) ***");
            SaguAssert($ok, "ACCESS DENIED");
        }
    }
}
 function read($fp, &$limit = PHP_INT_MAX)
 {
     while (!feof($fp) && $limit > 0) {
         $tag = Protobuf::read_varint($fp, $limit);
         if ($tag === false) {
             break;
         }
         $wire = $tag & 0x7;
         $field = $tag >> 3;
         //var_dump("Response: Found $field type " . Protobuf::get_wiretype($wire) . " $limit bytes left");
         switch ($field) {
             case 1:
                 ASSERT('$wire == 3');
                 $this->responsegroup_[] = new Response_ResponseGroup($fp, $limit);
                 break;
             default:
                 $this->_unknown[$field . '-' . Protobuf::get_wiretype($wire)][] = Protobuf::read_field($fp, $wire, $limit);
         }
     }
     if (!$this->validateRequired()) {
         throw new Exception('Required fields are missing');
     }
 }
예제 #10
0
 /**
  * RNFR/RNTO コマンドを発行する
  *
  * @param string $src
  * @param string $dst
  *
  * @throws FtpException
  * @throws TransportException
  */
 public function rename($src, $dst)
 {
     ASSERT(' is_string($src) && strlen($src) ');
     ASSERT(' is_string($dst) && strlen($dst) ');
     $resp = $this->_sendCommand("RNFR {$src}");
     if ($resp->code != 350) {
         throw new FtpException("rename(): RNFR command returned \"{$resp}\"", $resp);
     }
     $resp = $this->_sendCommand("RNTO {$dst}");
     if ($resp->code != 250) {
         throw new FtpException("rename(): RNTO command returned \"{$resp}\"", $resp);
     }
 }