1
/* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation; either version 2 of the License, or
6
* (at your option) any later version.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
* $Id: orb.pike,v 1.1.1.1 2005/02/23 14:47:21 cvs Exp $
20
constant cvs_version="$Id: orb.pike,v 1.1.1.1 2005/02/23 14:47:21 cvs Exp $";
24
#include <attributes.h>
28
object resolve_path(object uid, string path);
29
object path_to_object(string path, void|bool reslv);
30
string object_to_path(object obj);
31
object path_to_environment(string url);
35
* get detailed information about a file
37
* @param url - pathname or object-pointer for an object
38
* @return file information for the object
39
* @author Thomas Bopp (astra@upb.de)
41
array(mixed) identify_file(string|object url)
48
if ( !objectp(url) ) {
49
obj = path_to_object(url);
54
LOG("identify_file("+url+")");
56
url = object_to_path(obj);
59
if ( obj->get_object_class() & CLASS_DOCUMENT )
61
dtype = obj->query_attribute(DOC_MIME_TYPE);
62
LOG("Mime-type is " + dtype);
63
if ( !stringp(dtype) ) {
66
doctype = obj->query_attribute(DOC_TYPE);
67
if ( stringp(doctype) )
68
dtype = _TYPES->query_mime_type(doctype);
72
last_modified = obj->query_attribute(DOC_LAST_MODIFIED);
73
if ( last_modified == 0 )
74
last_modified = time();
78
last_modified = time();
83
dtype, // type of document
84
obj->get_content_size(), // size
85
last_modified, // last modified
86
obj->get_object_class(), // the class type of document
88
obj->query_sanction(_WORLDUSER)
90
LOG("Identified object=#"+obj->get_object_id()+ " from url="+url +
91
",size="+obj->get_content_size()+" array-size="+sizeof(res));
92
LOG("res="+sprintf("%O", res));
97
* Get stats of some file identified by 'f'
99
* @param string f - the filename
100
* @return file_stat information (usually an array like Stdio.File->stat())
102
mixed stat_file(string f, void|object id)
104
object obj = path_to_object(f, true);
107
return 0; // not found
111
* Get the mimetype for a given url.
113
* @param string f - the filename
114
* @return mimetype like text/plain
116
string get_mimetype(string f)
118
object obj = path_to_object(f);
120
return obj->stat()[7];
121
return "application/x-unknown";
125
* create a new directory with name "name" in "path"
127
* @param path - the path to create the directory
128
* @param name - the name for the new container
129
* @return the container-object
130
* @author Thomas Bopp (astra@upb.de)
132
object make_directory(string path, string name)
134
object obj, env, factory;
136
env = path_to_object(path);
139
obj = resolve_path(env, name);
143
factory = _Server->get_factory(CLASS_CONTAINER);
144
obj = factory->execute((["name":name,]));
147
// now move the container in the appropriate place
152
array(string) get_directory(string dir)
154
array directory = ({ });
155
object cont = path_to_object(dir, true);
156
if ( objectp(cont) ) {
157
array inv = cont->get_inventory();
161
foreach(inv, object obj) {
162
if ( objectp(obj) && obj->status() >= 0 &&
163
!(obj->get_object_class() & CLASS_USER) )
165
int cl = obj->get_object_class();
166
if ( !stringp(obj->get_identifier()) )
168
if ( cl & CLASS_EXIT || cl & CLASS_DOCUMENT ||
169
cl & CLASS_CONTAINER )
170
directory += ({ obj->get_identifier() });
179
* return the result of a directory query as a mapping filename:file_stat
181
* @param url - the container to get the directory
182
* @return the directory for the container
183
* @author Thomas Bopp (astra@upb.de)
185
mapping(string:array(int)) query_directory(string|object url)
189
mapping(string:array(int)) res;
192
LOG("query_directory...");
195
cont = path_to_object(url, true);
198
inv = cont->get_inventory();
199
for ( i = 0, sz = sizeof(inv); i < sz; i++ ) {
200
int cl = inv[i]->get_object_class();
201
if ( objectp(inv[i]) &&
202
stringp(inv[i]->get_identifier()) &&
203
strlen(inv[i]->get_identifier()) > 0 &&
204
!(cl & CLASS_USER) &&
205
(cl & CLASS_EXIT || cl & CLASS_DOCUMENT || cl & CLASS_CONTAINER ))
207
res[inv[i]->get_identifier()] = inv[i]->stat();
210
LOG("mapping:size="+sizeof(indices(res)));
215
* get the filename and path of a given path
217
* @param fname - the file name to process
218
* @return path and filename of a file
219
* @author Thomas Bopp (astra@upb.de)
221
array(string) get_filename(string fname)
224
array(string) tokens;
226
tokens = fname / "/";
227
if ( !arrayp(tokens) || (sz=sizeof(tokens)) <= 1 )
228
return ({ fname, "" });
229
return ({ tokens[sz-1], (tokens[..sz-2] * "/") + "/"});
233
* Get a path of objects (array) for a given url.
235
* @param string url - the given url
236
* @return array of objects
237
* @author <a href="mailto:astra@upb.de">Thomas Bopp</a>)
239
array(object) get_path(object obj)
241
array(object) path = ({ });
242
while ( objectp(obj) ) {
243
path = ({ obj }) + path;
244
obj = obj->get_environment();