diff options
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r-- | OpenSim/Framework/AssetPermissions.cs | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/OpenSim/Framework/AssetPermissions.cs b/OpenSim/Framework/AssetPermissions.cs new file mode 100644 index 0000000..d276def --- /dev/null +++ b/OpenSim/Framework/AssetPermissions.cs | |||
@@ -0,0 +1,81 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Reflection; | ||
4 | |||
5 | using Nini.Config; | ||
6 | using log4net; | ||
7 | |||
8 | using OpenMetaverse; | ||
9 | |||
10 | namespace OpenSim.Framework | ||
11 | { | ||
12 | public class AssetPermissions | ||
13 | { | ||
14 | private static readonly ILog m_log = | ||
15 | LogManager.GetLogger( | ||
16 | MethodBase.GetCurrentMethod().DeclaringType); | ||
17 | |||
18 | private bool[] m_DisallowExport, m_DisallowImport; | ||
19 | private string[] m_AssetTypeNames; | ||
20 | |||
21 | public AssetPermissions(IConfig config) | ||
22 | { | ||
23 | Type enumType = typeof(AssetType); | ||
24 | m_AssetTypeNames = Enum.GetNames(enumType); | ||
25 | for (int i = 0; i < m_AssetTypeNames.Length; i++) | ||
26 | m_AssetTypeNames[i] = m_AssetTypeNames[i].ToLower(); | ||
27 | int n = Enum.GetValues(enumType).Length; | ||
28 | m_DisallowExport = new bool[n]; | ||
29 | m_DisallowImport = new bool[n]; | ||
30 | |||
31 | LoadPermsFromConfig(config, "DisallowExport", m_DisallowExport); | ||
32 | LoadPermsFromConfig(config, "DisallowImport", m_DisallowImport); | ||
33 | |||
34 | } | ||
35 | |||
36 | private void LoadPermsFromConfig(IConfig assetConfig, string variable, bool[] bitArray) | ||
37 | { | ||
38 | string perms = assetConfig.GetString(variable, String.Empty); | ||
39 | string[] parts = perms.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); | ||
40 | foreach (string s in parts) | ||
41 | { | ||
42 | int index = Array.IndexOf(m_AssetTypeNames, s.Trim().ToLower()); | ||
43 | if (index >= 0) | ||
44 | bitArray[index] = true; | ||
45 | else | ||
46 | m_log.WarnFormat("[Asset Permissions]: Invalid AssetType {0}", s); | ||
47 | } | ||
48 | |||
49 | } | ||
50 | |||
51 | public bool AllowedExport(sbyte type) | ||
52 | { | ||
53 | string assetTypeName = ((AssetType)type).ToString(); | ||
54 | |||
55 | int index = Array.IndexOf(m_AssetTypeNames, assetTypeName.ToLower()); | ||
56 | if (index >= 0 && m_DisallowExport[index]) | ||
57 | { | ||
58 | m_log.DebugFormat("[Asset Permissions]: Export denied: configuration does not allow export of AssetType {0}", assetTypeName); | ||
59 | return false; | ||
60 | } | ||
61 | |||
62 | return true; | ||
63 | } | ||
64 | |||
65 | public bool AllowedImport(sbyte type) | ||
66 | { | ||
67 | string assetTypeName = ((AssetType)type).ToString(); | ||
68 | |||
69 | int index = Array.IndexOf(m_AssetTypeNames, assetTypeName.ToLower()); | ||
70 | if (index >= 0 && m_DisallowImport[index]) | ||
71 | { | ||
72 | m_log.DebugFormat("[Asset Permissions]: Import denied: configuration does not allow import of AssetType {0}", assetTypeName); | ||
73 | return false; | ||
74 | } | ||
75 | |||
76 | return true; | ||
77 | } | ||
78 | |||
79 | |||
80 | } | ||
81 | } | ||