Skip to content
Permalink
Browse files

Merge branch 'MDL-30154_20_wip' of git://github.com/grabs/moodle into…

… MOODLE_20_STABLE
  • Loading branch information...
Aparup Banerjee
Aparup Banerjee committed Nov 8, 2011
2 parents 7352bbb + 15f5066 commit 3555da1d3c39db7954e1f49b207a7aeebb4ab485
Showing with 37 additions and 10 deletions.
  1. +35 −9 lib/webdavlib.php
  2. +2 −1 repository/webdav/lib.php
@@ -797,7 +797,7 @@ function ls($path) {
if (strcmp($response['status']['status-code'],'207') == 0 ) {
// ok so far
// next there should be a Content-Type: text/xml; charset="utf-8" header line
if (preg_match('#text/xml;\s?charset=[\'\"]?utf-8[\'\"]?#i', $response['header']['Content-Type'])) {
if (preg_match('#(application|text)/xml;\s?charset=[\'\"]?utf-8[\'\"]?#i', $response['header']['Content-Type'])) {
// ok let's get the content of the xml stuff
$this->_parser = xml_parser_create_ns('UTF-8');
// forget old data...
@@ -1401,22 +1401,48 @@ private function get_respond() {
// check for a specified content-length
case preg_match('/Content\\-Length:\\s+([0-9]*)\\r\\n/',$header,$matches):
$this->_error_log('Getting data using Content-Length '. $matches[1]);
// check if we the content data size is small enough to get it as one block
if ($matches[1] <= $max_chunk_size ) {
// only read something if Content-Length is bigger than 0
if ($matches[1] > 0 ) {
$buffer = fread($this->sock, $matches[1]);
$loadsize = strlen($buffer);
//did we realy get the full length?
if ($loadsize < $matches[1]) {
$max_chunk_size = $loadsize;
do {
$mod = $max_chunk_size % ($matches[1] - strlen($buffer));
$chunk_size = ($mod == $max_chunk_size ? $max_chunk_size : $matches[1] - strlen($buffer));
$buffer .= fread($this->sock, $chunk_size);
$this->_error_log('mod: ' . $mod . ' chunk: ' . $chunk_size . ' total: ' . strlen($buffer));
} while ($mod == $max_chunk_size);
break;
} else {
break;
}
} else {
$buffer = '';
break;
}
} else {
// data is to big to handle it as one. Get it chunk per chunk...
do {
$mod = $max_chunk_size % ($matches[1] - strlen($buffer));
$chunk_size = ($mod == $max_chunk_size ? $max_chunk_size : $matches[1] - strlen($buffer));
$buffer .= fread($this->sock, $chunk_size);
$this->_error_log('mod: ' . $mod . ' chunk: ' . $chunk_size . ' total: ' . strlen($buffer));
} while ($mod == $max_chunk_size);
}
// data is to big to handle it as one. Get it chunk per chunk...
//trying to get the full length of max_chunk_size
$buffer = fread($this->sock, $max_chunk_size);
$loadsize = strlen($buffer);
if ($loadsize < $max_chunk_size) {
$max_chunk_size = $loadsize;
}
do {
$mod = $max_chunk_size % ($matches[1] - strlen($buffer));
$chunk_size = ($mod == $max_chunk_size ? $max_chunk_size : $matches[1] - strlen($buffer));
$buffer .= fread($this->sock, $chunk_size);
$this->_error_log('mod: ' . $mod . ' chunk: ' . $chunk_size . ' total: ' . strlen($buffer));
} while ($mod == $max_chunk_size);
$loadsize = strlen($buffer);
if ($loadsize < $matches[1]) {
$buffer .= fread($this->sock, $matches[1] - $loadsize);
}
break;
@@ -118,7 +118,7 @@ public function get_listing($path='', $page = '') {
}
if (!empty($v['resourcetype']) && $v['resourcetype'] == 'collection') {
// a folder
if ($path != $v['href']) {
if (ltrim($path, '/') != ltrim($v['href'], '/')) {
$matches = array();
preg_match('#(\w+)$#i', $v['href'], $matches);
if (!empty($matches[1])) {
@@ -137,6 +137,7 @@ public function get_listing($path='', $page = '') {
}
}else{
// a file
$path = rtrim($path,'/');
$title = urldecode(substr($v['href'], strpos($v['href'], $path)+strlen($path)));
$title = basename($title);
$size = !empty($v['getcontentlength'])? $v['getcontentlength']:'';

0 comments on commit 3555da1

Please sign in to comment.
You can’t perform that action at this time.