aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/AssetPermissions.cs
diff options
context:
space:
mode:
authorDiva Canto2012-09-20 19:50:57 -0700
committerDiva Canto2012-09-20 19:50:57 -0700
commite379566e6e3bed0d7001f099a5ea8dfd648d76cf (patch)
treed3c9877c5b0e24e3d56b5ee1029324efd05beff6 /OpenSim/Framework/AssetPermissions.cs
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC_OLD-e379566e6e3bed0d7001f099a5ea8dfd648d76cf.zip
opensim-SC_OLD-e379566e6e3bed0d7001f099a5ea8dfd648d76cf.tar.gz
opensim-SC_OLD-e379566e6e3bed0d7001f099a5ea8dfd648d76cf.tar.bz2
opensim-SC_OLD-e379566e6e3bed0d7001f099a5ea8dfd648d76cf.tar.xz
Improvement over last commit: refactor the asset permissions code, so that it can be used by both the HG Asset Service and the simulator. Also renamed the config vars to something more intuitive
Diffstat (limited to 'OpenSim/Framework/AssetPermissions.cs')
-rw-r--r--OpenSim/Framework/AssetPermissions.cs81
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 @@
1using System;
2using System.Collections.Generic;
3using System.Reflection;
4
5using Nini.Config;
6using log4net;
7
8using OpenMetaverse;
9
10namespace 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}