aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/share/perl/lib/OpenSim/InventoryServer.pm
diff options
context:
space:
mode:
authorAdam Frisby2008-03-25 16:29:54 +0000
committerAdam Frisby2008-03-25 16:29:54 +0000
commit8c05b81d6860d8e0da4098cc6f59f630d7c53037 (patch)
tree3325e09660ee8ad5a12cc19c8da6c4bd8bff5c21 /share/perl/lib/OpenSim/InventoryServer.pm
parent* On Ray casting. Now returning the face normal of the collision face. (diff)
downloadopensim-SC-8c05b81d6860d8e0da4098cc6f59f630d7c53037.zip
opensim-SC-8c05b81d6860d8e0da4098cc6f59f630d7c53037.tar.gz
opensim-SC-8c05b81d6860d8e0da4098cc6f59f630d7c53037.tar.bz2
opensim-SC-8c05b81d6860d8e0da4098cc6f59f630d7c53037.tar.xz
* Committing Lulurun's Cgi/Perl implementation of the UGAI servers.
* I love you long time.
Diffstat (limited to 'share/perl/lib/OpenSim/InventoryServer.pm')
-rw-r--r--share/perl/lib/OpenSim/InventoryServer.pm249
1 files changed, 249 insertions, 0 deletions
diff --git a/share/perl/lib/OpenSim/InventoryServer.pm b/share/perl/lib/OpenSim/InventoryServer.pm
new file mode 100644
index 0000000..184e19a
--- /dev/null
+++ b/share/perl/lib/OpenSim/InventoryServer.pm
@@ -0,0 +1,249 @@
1package OpenSim::InventoryServer;
2
3use strict;
4use XML::Serializer;
5use OpenSim::Utility;
6use OpenSim::Config;
7use OpenSim::InventoryServer::Config;
8use OpenSim::InventoryServer::InventoryManager;
9
10my $METHOD_LIST = undef;
11
12sub getHandlerList {
13 if (!$METHOD_LIST) {
14 my %list = (
15 "GetInventory" => \&_get_inventory,
16 "CreateInventory" => \&_create_inventory,
17 "NewFolder" => \&_new_folder,
18 "MoveFolder" => \&_move_folder,
19 "NewItem" => \&_new_item,
20 "DeleteItem" => \&_delete_item,
21 "RootFolders" => \&_root_folders,
22 );
23 $METHOD_LIST = \%list;
24 }
25 return $METHOD_LIST;
26}
27
28# #################
29# Handlers
30sub _get_inventory {
31 my $post_data = shift;
32 my $uuid = &_get_uuid($post_data);
33 my $inventry_folders = &OpenSim::InventoryServer::InventoryManager::getUserInventoryFolders($uuid);
34 my @response_folders = ();
35 foreach (@$inventry_folders) {
36 my $folder = &_convert_to_response_folder($_);
37 push @response_folders, $folder;
38 }
39 my $inventry_items = &OpenSim::InventoryServer::InventoryManager::getUserInventoryItems($uuid);
40 my @response_items = ();
41 foreach (@$inventry_items) {
42 my $item = &_convert_to_response_item($_);
43 push @response_items, $item;
44 }
45 my $response_obj = {
46 Folders => { InventoryFolderBase => \@response_folders },
47 AllItems => { InventoryItemBase => \@response_items },
48 UserID => { UUID => $uuid },
49 };
50 my $serializer = new XML::Serializer( $response_obj, "InventoryCollection");
51 return $serializer->to_formatted(XML::Serializer::WITH_HEADER); # TODO:
52}
53
54sub _create_inventory {
55 my $post_data = shift;
56 my $uuid = &_get_uuid($post_data);
57 my $InventoryFolders = &_create_default_inventory($uuid);
58 foreach (@$InventoryFolders) {
59 &OpenSim::InventoryServer::InventoryManager::saveInventoryFolder($_);
60 }
61 my $serializer = new XML::Serializer("true", "boolean");
62 return $serializer->to_formatted(XML::Serializer::WITH_HEADER); # TODO:
63}
64
65sub _new_folder {
66 my $post_data = shift;
67 my $request_obj = &OpenSim::Utility::XML2Obj($post_data);
68 my $folder = &_convert_to_db_folder($request_obj);
69 &OpenSim::InventoryServer::InventoryManager::saveInventoryFolder($folder);
70 my $serializer = new XML::Serializer("true", "boolean");
71 return $serializer->to_formatted(XML::Serializer::WITH_HEADER); # TODO:
72}
73
74sub _move_folder {
75 my $post_data = shift;
76 my $request_info = &OpenSim::Utility::XML2Obj($post_data);
77 &OpenSim::InventoryServer::InventoryManager::moveInventoryFolder($request_info);
78 my $serializer = new XML::Serializer("true", "boolean");
79 return $serializer->to_formatted(XML::Serializer::WITH_HEADER); # TODO:
80}
81
82sub _new_item {
83 my $post_data = shift;
84 my $request_obj = &OpenSim::Utility::XML2Obj($post_data);
85 my $item = &_convert_to_db_item($request_obj);
86 &OpenSim::InventoryServer::InventoryManager::saveInventoryItem($item);
87 my $serializer = new XML::Serializer("true", "boolean");
88 return $serializer->to_formatted(XML::Serializer::WITH_HEADER); # TODO:
89}
90
91sub _delete_item {
92 my $post_data = shift;
93 my $request_obj = &OpenSim::Utility::XML2Obj($post_data);
94 my $item_id = $request_obj->{inventoryID}->{UUID};
95 &OpenSim::InventoryServer::InventoryManager::deleteInventoryItem($item_id);
96 my $serializer = new XML::Serializer("true", "boolean");
97 return $serializer->to_formatted(XML::Serializer::WITH_HEADER); # TODO:
98}
99
100sub _root_folders {
101 my $post_data = shift;
102 my $uuid = &_get_uuid($post_data);
103 my $response = undef;
104 my $inventory_root_folder = &OpenSim::InventoryServer::InventoryManager::getRootFolder($uuid);
105 if ($inventory_root_folder) {
106 my $root_folder_id = $inventory_root_folder->{folderID};
107 my $root_folder = &_convert_to_response_folder($inventory_root_folder);
108 my $root_folders = &OpenSim::InventoryServer::InventoryManager::getChildrenFolders($root_folder_id);
109 my @folders = ($root_folder);
110 foreach(@$root_folders) {
111 my $folder = &_convert_to_response_folder($_);
112 push @folders, $folder;
113 }
114 $response = { InventoryFolderBase => \@folders };
115 } else {
116 $response = ""; # TODO: need better failed message
117 }
118 my $serializer = new XML::Serializer($response, "ArrayOfInventoryFolderBase");
119 return $serializer->to_formatted(XML::Serializer::WITH_HEADER); # TODO:
120}
121
122# #################
123# subfunctions
124sub _convert_to_db_item {
125 my $item = shift;
126 my $ret = {
127 inventoryID => $item->{inventoryID}->{UUID},
128 assetID => $item->{assetID}->{UUID},
129 assetType => $item->{assetType},
130 invType => $item->{invType},
131 parentFolderID => $item->{parentFolderID}->{UUID},
132 avatarID => $item->{avatarID}->{UUID},
133 creatorID => $item->{creatorsID}->{UUID}, # TODO: human error ???
134 inventoryName => $item->{inventoryName},
135 inventoryDescription => $item->{inventoryDescription} || "",
136 inventoryNextPermissions => $item->{inventoryNextPermissions},
137 inventoryCurrentPermissions => $item->{inventoryCurrentPermissions},
138 inventoryBasePermissions => $item->{inventoryBasePermissions},
139 inventoryEveryOnePermissions => $item->{inventoryEveryOnePermissions},
140 };
141 return $ret;
142}
143
144sub _convert_to_response_item {
145 my $item = shift;
146 my $ret = {
147 inventoryID => { UUID => $item->{inventoryID} },
148 assetID => { UUID => $item->{assetID} },
149 assetType => $item->{assetType},
150 invType => $item->{invType},
151 parentFolderID => { UUID => $item->{parentFolderID} },
152 avatarID => { UUID => $item->{avatarID} },
153 creatorsID => { UUID => $item->{creatorID} }, # TODO: human error ???
154 inventoryName => $item->{inventoryName},
155 inventoryDescription => $item->{inventoryDescription} || "",
156 inventoryNextPermissions => $item->{inventoryNextPermissions},
157 inventoryCurrentPermissions => $item->{inventoryCurrentPermissions},
158 inventoryBasePermissions => $item->{inventoryBasePermissions},
159 inventoryEveryOnePermissions => $item->{inventoryEveryOnePermissions},
160 };
161 return $ret;
162}
163
164sub _convert_to_db_folder {
165 my $folder = shift;
166 my $ret = {
167 folderName => $folder->{name},
168 agentID => $folder->{agentID}->{UUID},
169 parentFolderID => $folder->{parentID}->{UUID},
170 folderID => $folder->{folderID}->{UUID},
171 type => $folder->{type},
172 version => $folder->{version},
173 };
174 return $ret;
175}
176
177sub _convert_to_response_folder {
178 my $folder = shift;
179 my $ret = {
180 name => $folder->{folderName},
181 agentID => { UUID => $folder->{agentID} },
182 parentID => { UUID => $folder->{parentFolderID} },
183 folderID => { UUID => $folder->{folderID} },
184 type => $folder->{type},
185 version => $folder->{version},
186 };
187 return $ret;
188}
189
190sub _create_default_inventory {
191 my $uuid = shift;
192
193 my @InventoryFolders = ();
194 my $root_folder_id = &OpenSim::Utility::GenerateUUID();
195
196 push @InventoryFolders, {
197 "folderID" => $root_folder_id,
198 "agentID" => $uuid,
199 "parentFolderID" => &OpenSim::Utility::ZeroUUID(),
200 "folderName" => "My Inventory",
201 "type" => 8,
202 "version" => 1,
203 };
204
205 push @InventoryFolders, {
206 "folderID" => &OpenSim::Utility::GenerateUUID(),
207 "agentID" => $uuid,
208 "parentFolderID" => $root_folder_id,
209 "folderName" => "Textures",
210 "type" => 0,
211 "version" => 1,
212 };
213
214 push @InventoryFolders, {
215 "folderID" => &OpenSim::Utility::GenerateUUID(),
216 "agentID" => $uuid,
217 "parentFolderID" => $root_folder_id,
218 "folderName" => "Objects",
219 "type" => 6,
220 "version" => 1,
221 };
222
223 push @InventoryFolders, {
224 "folderID" => &OpenSim::Utility::GenerateUUID(),
225 "agentID" => $uuid,
226 "parentFolderID" => $root_folder_id,
227 "folderName" => "Clothes",
228 "type" => 5,
229 "version" => 1,
230 };
231
232 return \@InventoryFolders;
233}
234
235
236# #################
237# Utilities
238sub _get_uuid {
239 my $data = shift;
240 if ($data =~ /<guid\s*>([^<]+)<\/guid>/) {
241 return $1;
242 } else {
243 Carp::croak("can not find uuid: $data");
244 }
245}
246
247
2481;
249