diff options
Diffstat (limited to '')
-rw-r--r-- | share/perl/lib/OpenSim/InventoryServer.pm | 249 | ||||
-rw-r--r-- | share/perl/lib/OpenSim/InventoryServer/Config.pm | 51 | ||||
-rw-r--r-- | share/perl/lib/OpenSim/InventoryServer/InventoryManager.pm | 86 |
3 files changed, 0 insertions, 386 deletions
diff --git a/share/perl/lib/OpenSim/InventoryServer.pm b/share/perl/lib/OpenSim/InventoryServer.pm deleted file mode 100644 index 184e19a..0000000 --- a/share/perl/lib/OpenSim/InventoryServer.pm +++ /dev/null | |||
@@ -1,249 +0,0 @@ | |||
1 | package OpenSim::InventoryServer; | ||
2 | |||
3 | use strict; | ||
4 | use XML::Serializer; | ||
5 | use OpenSim::Utility; | ||
6 | use OpenSim::Config; | ||
7 | use OpenSim::InventoryServer::Config; | ||
8 | use OpenSim::InventoryServer::InventoryManager; | ||
9 | |||
10 | my $METHOD_LIST = undef; | ||
11 | |||
12 | sub 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 | ||
30 | sub _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 | |||
54 | sub _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 | |||
65 | sub _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 | |||
74 | sub _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 | |||
82 | sub _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 | |||
91 | sub _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 | |||
100 | sub _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 | ||
124 | sub _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 | |||
144 | sub _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 | |||
164 | sub _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 | |||
177 | sub _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 | |||
190 | sub _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 | ||
238 | sub _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 | |||
248 | 1; | ||
249 | |||
diff --git a/share/perl/lib/OpenSim/InventoryServer/Config.pm b/share/perl/lib/OpenSim/InventoryServer/Config.pm deleted file mode 100644 index 64dbdd1..0000000 --- a/share/perl/lib/OpenSim/InventoryServer/Config.pm +++ /dev/null | |||
@@ -1,51 +0,0 @@ | |||
1 | package OpenSim::InventoryServer::Config; | ||
2 | |||
3 | use strict; | ||
4 | |||
5 | our %SYS_SQL = ( | ||
6 | save_inventory_folder => | ||
7 | "REPLACE INTO inventoryfolders VALUES (?,?,?,?,?,?)", | ||
8 | save_inventory_item => | ||
9 | "REPLACE INTO inventoryitems VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)", | ||
10 | get_root_folder => | ||
11 | "SELECT * FROM inventoryfolders WHERE parentFolderID=? AND agentId=?", | ||
12 | get_children_folders => | ||
13 | "SELECT * FROM inventoryfolders WHERE parentFolderID=?", | ||
14 | get_user_inventory_folders => | ||
15 | "SELECT * FROM inventoryfolders WHERE agentID=?", | ||
16 | get_user_inventory_items => | ||
17 | "SELECT * FROM inventoryitems WHERE avatarID=?", | ||
18 | delete_inventory_item => | ||
19 | "DELETE FROM inventoryitems WHERE inventoryID=?", | ||
20 | move_inventory_folder => | ||
21 | "UPDATE inventoryfolders SET parentFolderID=? WHERE folderID=?", | ||
22 | ); | ||
23 | |||
24 | |||
25 | our @INVENTORYFOLDERS_COLUMNS = ( | ||
26 | "folderID", | ||
27 | "agentID", | ||
28 | "parentFolderID", | ||
29 | "folderName", | ||
30 | "type", | ||
31 | "version", | ||
32 | ); | ||
33 | |||
34 | our @INVENTORYITEMS_COLUMNS = ( | ||
35 | "inventoryID", | ||
36 | "assetID", | ||
37 | "type", | ||
38 | "parentFolderID", | ||
39 | "avatarID", | ||
40 | "inventoryName", | ||
41 | "inventoryDescription", | ||
42 | "inventoryNextPermissions", | ||
43 | "inventoryCurrentPermissions", | ||
44 | "assetType", | ||
45 | "invType", | ||
46 | "creatorID", | ||
47 | "inventoryBasePermissions", | ||
48 | "inventoryEveryOnePermissions", | ||
49 | ); | ||
50 | |||
51 | 1; | ||
diff --git a/share/perl/lib/OpenSim/InventoryServer/InventoryManager.pm b/share/perl/lib/OpenSim/InventoryServer/InventoryManager.pm deleted file mode 100644 index 97111b7..0000000 --- a/share/perl/lib/OpenSim/InventoryServer/InventoryManager.pm +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
1 | package OpenSim::InventoryServer::InventoryManager; | ||
2 | |||
3 | use strict; | ||
4 | use Carp; | ||
5 | use OpenSim::Utility; | ||
6 | use OpenSim::InventoryServer::Config; | ||
7 | |||
8 | sub saveInventoryFolder { | ||
9 | my $folder = shift; | ||
10 | my $result = &OpenSim::Utility::getSimpleResult($OpenSim::InventoryServer::Config::SYS_SQL{save_inventory_folder}, | ||
11 | $folder->{"folderID"}, | ||
12 | $folder->{"agentID"}, | ||
13 | $folder->{"parentFolderID"}, | ||
14 | $folder->{"folderName"}, | ||
15 | $folder->{"type"}, | ||
16 | $folder->{"version"}); | ||
17 | } | ||
18 | |||
19 | sub saveInventoryItem { | ||
20 | my $item = shift; | ||
21 | my $result = &OpenSim::Utility::getSimpleResult($OpenSim::InventoryServer::Config::SYS_SQL{save_inventory_item}, | ||
22 | $item->{"inventoryID"}, | ||
23 | $item->{"assetID"}, | ||
24 | $item->{"type"}, | ||
25 | $item->{"parentFolderID"}, | ||
26 | $item->{"avatarID"}, | ||
27 | $item->{"inventoryName"}, | ||
28 | $item->{"inventoryDescription"}, | ||
29 | $item->{"inventoryNextPermissions"}, | ||
30 | $item->{"inventoryCurrentPermissions"}, | ||
31 | $item->{"assetType"}, | ||
32 | $item->{"invType"}, | ||
33 | $item->{"creatorID"}, | ||
34 | $item->{"inventoryBasePermissions"}, | ||
35 | $item->{"inventoryEveryOnePermissions"}); | ||
36 | } | ||
37 | |||
38 | sub getRootFolder { | ||
39 | my $agent_id = shift; | ||
40 | my $result = &OpenSim::Utility::getSimpleResult($OpenSim::InventoryServer::Config::SYS_SQL{get_root_folder}, | ||
41 | &OpenSim::Utility::ZeroUUID(), | ||
42 | $agent_id); | ||
43 | my $count = @$result; | ||
44 | if ($count > 0) { | ||
45 | return $result->[0]; | ||
46 | } else { | ||
47 | return undef; | ||
48 | } | ||
49 | } | ||
50 | |||
51 | sub getChildrenFolders { | ||
52 | my $parent_id = shift; | ||
53 | my $result = &OpenSim::Utility::getSimpleResult($OpenSim::InventoryServer::Config::SYS_SQL{get_children_folders}, $parent_id); | ||
54 | return $result; | ||
55 | } | ||
56 | |||
57 | sub getUserInventoryFolders { | ||
58 | my $agent_id = shift; | ||
59 | my $result = &OpenSim::Utility::getSimpleResult($OpenSim::InventoryServer::Config::SYS_SQL{get_user_inventory_folders}, | ||
60 | $agent_id); | ||
61 | return $result; | ||
62 | } | ||
63 | |||
64 | sub getUserInventoryItems { | ||
65 | my $agent_id = shift; | ||
66 | my $result = &OpenSim::Utility::getSimpleResult($OpenSim::InventoryServer::Config::SYS_SQL{get_user_inventory_items}, | ||
67 | $agent_id); | ||
68 | return $result; | ||
69 | } | ||
70 | |||
71 | sub deleteInventoryItem { | ||
72 | my $item_id = shift; | ||
73 | &OpenSim::Utility::getSimpleResult($OpenSim::InventoryServer::Config::SYS_SQL{delete_inventory_item}, | ||
74 | $item_id); | ||
75 | } | ||
76 | |||
77 | sub moveInventoryFolder { | ||
78 | my $info = shift; | ||
79 | &OpenSim::Utility::getSimpleResult($OpenSim::InventoryServer::Config::SYS_SQL{move_inventory_folder}, | ||
80 | $info->{parentID}->{UUID}, # TODO: not good | ||
81 | $info->{folderID}->{UUID}, # TODO: not good UUID should be extracted in the higher level | ||
82 | ); | ||
83 | } | ||
84 | |||
85 | 1; | ||
86 | |||