3
MediaTomb - http://www.mediatomb.cc/
5
directories.cc - this file is part of MediaTomb.
7
Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
8
Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
10
Copyright (C) 2006-2007 Gena Batyan <bgeradz@mediatomb.cc>,
11
Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
12
Leonhard Wimmer <leo@mediatomb.cc>
14
MediaTomb is free software; you can redistribute it and/or modify
15
it under the terms of the GNU General Public License version 2
16
as published by the Free Software Foundation.
18
MediaTomb is distributed in the hope that it will be useful,
19
but WITHOUT ANY WARRANTY; without even the implied warranty of
20
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
GNU General Public License for more details.
23
You should have received a copy of the GNU General Public License
24
version 2 along with MediaTomb; if not, write to the Free Software
25
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
27
$Id: directories.cc 1294 2007-05-13 16:28:24Z lww $
30
/// \file directories.cc
33
#include "autoconfig.h"
40
#include "filesystem.h"
41
#include "string_converter.h"
46
web::directories::directories() : WebRequestHandler()
50
void web::directories::process()
55
String parentID = param(_("parent_id"));
56
if (parentID == nil || parentID == "0")
57
path = _(FS_ROOT_DIRECTORY);
59
path = hex_decode_string(parentID);
61
Ref<Element> containers (new Element(_("containers")));
62
containers->addAttribute(_("ofId"), parentID);
63
containers->addAttribute(_("select_it"), param(_("select_it")));
64
containers->addAttribute(_("type"), _("f"));
65
root->appendChild(containers);
67
Ref<Filesystem> fs(new Filesystem());
69
Ref<Array<FsObject> > arr;
72
arr = fs->readDirectory(path, FS_MASK_DIRECTORIES,
77
containers->addAttribute(_("success"), _("0"));
80
containers->addAttribute(_("success"), _("1"));
83
for (int i = 0; i < arr->size(); i++)
85
Ref<FsObject> obj = arr->get(i);
87
Ref<Element> ce(new Element(_("container")));
88
String filename = obj->filename;
90
if (path.c_str()[path.length() - 1] == '/')
91
filepath = path + filename;
93
filepath = path + '/' + filename;
95
/// \todo replace hex_encode with base64_encode?
96
String id = hex_encode(filepath.c_str(), filepath.length());
97
ce->addAttribute(_("id"), id);
99
ce->addAttribute(_("childCount"), String::from(1));
101
Ref<StringConverter> f2i = StringConverter::f2i();
102
ce->setText(f2i->convert(filename));
103
containers->appendChild(ce);