~ubuntu-branches/ubuntu/wily/steam/wily

« back to all changes in this revision

Viewing changes to server/modules/home.pike

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2013-10-29 19:51:18 UTC
  • mfrom: (1.1.4) (0.1.4 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131029195118-b9bxciz5hwx5z459
Tags: 1:1.0.0.39-2ubuntu1
Add an epoch to the version number as there was an unrelated steam package
in the archive with a higher version number.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2005  Thomas Bopp, Thorsten Hampel, Ludger Merkens
2
 
 *
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.
7
 
 *
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.
12
 
 *
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
16
 
 * 
17
 
 * $Id: home.pike,v 1.2 2006/06/18 13:19:18 astra Exp $
18
 
 */
19
 
 
20
 
constant cvs_version="$Id: home.pike,v 1.2 2006/06/18 13:19:18 astra Exp $";
21
 
 
22
 
inherit "/kernel/module";
23
 
 
24
 
#include <macros.h>
25
 
#include <classes.h>
26
 
#include <database.h>
27
 
#include <exception.h>
28
 
#include <attributes.h>
29
 
#include <configure.h>
30
 
 
31
 
static mapping config = ([ ]);
32
 
 
33
 
//! The home module must be located in the root-room and resolves
34
 
//! any user or group name parsed and gets the appropriate workarea
35
 
//! for it. Queried users/groups can be seen in this modules inventory
36
 
//! afterwards. This way emacs and other tools may be able to resolve
37
 
//! path, even though actually no object is really places in this container.
38
 
 
39
 
class GroupWrapper {
40
 
    object grp, home;
41
 
    void create(object g, object h) { 
42
 
        if ( !IS_PROXY(g) ) 
43
 
            THROW("GroupWrapper: Group is no proxy !", E_ERROR);
44
 
        if ( !IS_PROXY(h) ) 
45
 
            THROW("GroupWrapper: Home is no proxy !", E_ERROR);
46
 
        if ( !objectp(h) )
47
 
            h = OBJ("/home/steam");
48
 
        grp = g; home = h; 
49
 
    }
50
 
    string get_identifier() { return grp->get_identifier(); }
51
 
    int get_object_class() { return CLASS_ROOM|CLASS_CONTAINER; }
52
 
    object this() { return this_object(); }
53
 
    int status() { return 1; }
54
 
    final mixed `->(string func) 
55
 
    {
56
 
        if ( func == "get_identifier" )
57
 
            return get_identifier;
58
 
        else if ( func == "create" )
59
 
            return create;
60
 
        else if ( func == "status" )
61
 
            return status;
62
 
        else if ( func == "get_object_class" )
63
 
            return get_object_class;
64
 
        return home->get_object()[func];
65
 
    }
66
 
};
67
 
 
68
 
 
69
 
static mapping directoryCache = ([ ]);
70
 
 
71
 
string get_identifier() { return "home"; }
72
 
static void update_identifier(string name) {};
73
 
 
74
 
int get_object_class()  
75
 
76
 
    return ::get_object_class() | CLASS_CONTAINER | CLASS_ROOM;
77
 
}
78
 
 
79
 
 
80
 
bool insert_obj(object obj) 
81
 
82
 
    return true; //THROW("No Insert in home !", E_ACCESS); 
83
 
}
84
 
 
85
 
bool remove_obj(object obj) 
86
 
87
 
    return true; // THROW("No Remove in home !", E_ACCESS); 
88
 
}
89
 
 
90
 
array(object) get_inventory() 
91
 
92
 
    array(object) groups = this_user()->get_groups();
93
 
    foreach(groups, object grp) {
94
 
        if ( !directoryCache[grp->get_identifier()] )
95
 
            directoryCache[grp->get_identifier()] = 
96
 
                GroupWrapper(grp, grp->query_attribute(GROUP_WORKROOM));
97
 
    }
98
 
    if ( config["users"] != "false" )
99
 
      mount(this_user());
100
 
    return values(directoryCache); 
101
 
}
102
 
 
103
 
array(object) get_inventory_by_class(int cl) 
104
 
{
105
 
    mount(this_user());
106
 
    if ( cl & CLASS_GROUP )
107
 
        return values(directoryCache);
108
 
    else if ( cl & CLASS_ROOM )
109
 
      return values(directoryCache);
110
 
    return ({ });
111
 
}
112
 
 
113
 
array(object) get_users()
114
 
{
115
 
  return ({ });
116
 
}
117
 
 
118
 
/*
119
 
 * Get the object by its name. This function is overloaded to allow
120
 
 * the /home syntax to all directories, without having the workrooms
121
 
 * environments point there. This means the Container is actually empty,
122
 
 * but you can do cd /home/user and get somewhere.
123
 
 *  
124
 
 * @param string obj_name - the object to resolve
125
 
 * @return the object
126
 
 * @author <a href="mailto:astra@upb.de">Thomas Bopp</a>) 
127
 
 */
128
 
object get_object_byname(string obj_name)
129
 
{
130
 
    object obj, res;
131
 
 
132
 
    LOG("Getting "+ obj_name);
133
 
    if ( objectp(directoryCache[obj_name]) ) {
134
 
      if ( directoryCache[obj_name]->status() >= 0 )
135
 
        return directoryCache[obj_name];
136
 
      else
137
 
        m_delete(directoryCache, obj_name);
138
 
      return 0;
139
 
    }
140
 
    
141
 
    obj = MODULE_GROUPS->lookup(obj_name);
142
 
    if ( objectp(obj) ) {
143
 
        LOG("Found group - returning workroom !");
144
 
        res = obj->query_attribute(GROUP_WORKROOM);
145
 
    }
146
 
    else {
147
 
        obj = MODULE_USERS->lookup(obj_name);
148
 
        if ( objectp(obj) && config["users"] != "false" ) {
149
 
          if ( obj->status() >= 0 )
150
 
            res = obj->query_attribute(USER_WORKROOM);
151
 
        }
152
 
    }
153
 
    if ( objectp(res) )
154
 
        directoryCache[obj_name] = GroupWrapper(obj, res);
155
 
 
156
 
    return directoryCache[obj_name];
157
 
}
158
 
 
159
 
object mount(object grp)
160
 
{
161
 
  object wr;
162
 
  
163
 
  string name = grp->get_identifier();
164
 
  
165
 
  if ( objectp(directoryCache[name]) )
166
 
    return directoryCache[name]->home;
167
 
                              
168
 
  if ( grp->get_object_class() & CLASS_GROUP )
169
 
    wr = grp->query_attribute(GROUP_WORKROOM);
170
 
  else if ( grp->get_object_class() & CLASS_USER )
171
 
    wr = grp->query_attribute(USER_WORKROOM);
172
 
  else
173
 
      return 0;
174
 
 
175
 
  if ( !objectp(wr) || wr->status() < 0 )
176
 
    return 0;
177
 
 
178
 
  directoryCache[name] = GroupWrapper(grp, wr);
179
 
  return wr;
180
 
}
181
 
 
182
 
string contains_virtual(object obj)
183
 
{
184
 
    object creatorGroup = obj->get_creator();
185
 
    if ( creatorGroup->get_object_class() & CLASS_GROUP ) {
186
 
        return creatorGroup->get_identifier();
187
 
    }
188
 
    else if ( creatorGroup->get_object_class() & CLASS_USER ) {
189
 
        if ( creatorGroup->query_attribute(USER_WORKROOM) == obj )
190
 
            return creatorGroup->get_user_name();
191
 
    }
192
 
    return 0;
193
 
}
194
 
 
195
 
void add_paths() 
196
 
{
197
 
    get_module("filepath:url")->add_virtual_path("/home/", this());
198
 
}
199
 
 
200
 
/**
201
 
 * Called after the object is loaded. Move the object to the workroom !
202
 
 *  
203
 
 * @author <a href="mailto:astra@upb.de">Thomas Bopp</a>) 
204
 
 */
205
 
void load_module()
206
 
207
 
    if ( MODULE_OBJECTS && objectp(_ROOTROOM) && oEnvironment != _ROOTROOM ) {
208
 
        set_attribute(OBJ_NAME, "home");
209
 
        move(_ROOTROOM); 
210
 
    }
211
 
    call(add_paths, 0);
212
 
 
213
 
    //TODO:
214
 
    // simple config stuff: This is just a short ad hoc solution. Steam 2.2
215
 
    // will have a library for config file handling.
216
 
    mixed err = catch {
217
 
      string config_str = Stdio.read_file( CONFIG_DIR+"/home.cfg" );
218
 
      if ( stringp(config_str) ) {
219
 
        array lines = config_str / "\n";
220
 
        if ( arrayp(lines) ) {
221
 
          foreach ( lines, string line ) {
222
 
            string key, value;
223
 
            if ( sscanf( line, "%s=%s", key, value ) >= 2 ) {
224
 
              config[key] = value;
225
 
            }
226
 
          }
227
 
        }
228
 
      }
229
 
    };
230
 
}
231
 
 
232
 
/**
233
 
 * Get the content size of this object which does not make really
234
 
 * sense for containers.
235
 
 *  
236
 
 * @return the content size: -2 as the container can be seen as an inventory
237
 
 * @author <a href="mailto:astra@upb.de">Thomas Bopp</a>) 
238
 
 * @see stat
239
 
 */
240
 
int get_content_size()
241
 
{
242
 
    return -2;
243
 
}
244
 
 
245
 
/**
246
 
 * This function returns the stat() of this object. This has the 
247
 
 * same format as statting a file.
248
 
 *  
249
 
 * @return status array as in file_stat()
250
 
 * @author Thomas Bopp (astra@upb.de) 
251
 
 * @see get_content_size
252
 
 */
253
 
array(int) stat()
254
 
{
255
 
    int creator_id = objectp(get_creator())?get_creator()->get_object_id():0;
256
 
    
257
 
 
258
 
    return ({ 16877, get_content_size(), time(), time(), time(),
259
 
                  creator_id, creator_id, "httpd/unix-directory" });
260
 
}