예제 #1
0
파일: post.php 프로젝트: hgwr/stechat
    session_name("stechat");
    session_start();
    sc_set_idstr();
    if (isset($_SESSION['prev_time']) && $_SESSION['prev_time'] + 5 > time()) {
        throw new RuntimeException('Wait a sec.');
    }
    $_SESSION['prev_time'] = time();
    foreach (array('room', 'name', 'cont') as $key) {
        if ($key != 'name' && (!isset($_POST[$key]) || trim($_POST[$key]) === '')) {
            throw new RuntimeException("'{$key}' is too short.");
        }
        if (get_magic_quotes_gpc()) {
            $_POST[$key] = stripslashes($_POST[$key]);
        }
        $o[$key] = trim($_POST[$key]);
    }
    if (strlen($o['room']) >= MAX_ROOM_LEN || strlen($o['name']) >= MAX_NAME_LEN || strlen($o['cont']) >= MAX_CONT_LEN) {
        throw new RuntimeException("Some parameters are too long.");
    }
    $_SESSION['name'] = $o['name'];
    $size = sc_add_content($o['room'], $o['name'], $_SESSION['idstr'], $o['cont']);
    if ($size < 0) {
        throw new RuntimeException("Data file is full.");
    }
} catch (RuntimeException $e) {
    $o['error'] = $e->getMessage();
}
header("Content-type: text/plain");
if (isset($o['error'])) {
    print $o['error'] . "\n";
}
예제 #2
0
파일: UtilTest.php 프로젝트: hgwr/stechat
 public function testScGetLastContents()
 {
     $room = 'njiSeDkea2';
     $name = 'foo';
     $idstr = '123';
     $content = 'Hello <b>world</b>';
     $dat_filename = sc_dat_filename($room);
     if (file_exists($dat_filename)) {
         unlink($dat_filename);
     }
     for ($i = 1; $i <= 20; $i++) {
         sc_add_content($room, $name, $idstr, $i);
     }
     $contents = sc_get_last_contents($room, 0);
     $this->assertEquals(21, sizeof($contents));
     $this->assertEquals(1, $contents[0][1]);
     $this->assertEquals(20, $contents[0][2]);
     $chat = $contents[1];
     $this->assertEquals($name, $chat[0]);
     $this->assertEquals($idstr, $chat[1]);
     $this->assertEquals("1", $chat[3]);
     $chat = $contents[sizeof($contents) - 1];
     $this->assertEquals($name, $chat[0]);
     $this->assertEquals($idstr, $chat[1]);
     $this->assertEquals("20", $chat[3]);
     for ($i = 21; $i <= MAX_MSGS_LEN + 20; $i++) {
         sc_add_content($room, $name, $idstr, $i);
     }
     $contents = sc_get_last_contents($room, 0);
     $this->assertEquals(MAX_MSGS_LEN + 1, sizeof($contents));
     $this->assertEquals(21, $contents[0][1]);
     $this->assertEquals(MAX_MSGS_LEN + 20, $contents[0][2]);
     $chat = $contents[1];
     $this->assertEquals($name, $chat[0]);
     $this->assertEquals($idstr, $chat[1]);
     $this->assertEquals("21", $chat[3]);
     $chat = $contents[sizeof($contents) - 1];
     $this->assertEquals($name, $chat[0]);
     $this->assertEquals($idstr, $chat[1]);
     $this->assertEquals("" . (MAX_MSGS_LEN + 20), $chat[3]);
 }