File: IocPropertyInfoPool.cs

package info (click to toggle)
keepass2 2.57%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 14,520 kB
  • sloc: cs: 120,930; xml: 6,271; cpp: 322; sh: 53; makefile: 42
file content (122 lines) | stat: -rw-r--r-- 3,961 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
  KeePass Password Safe - The Open-Source Password Manager
  Copyright (C) 2003-2024 Dominik Reichl <dominik.reichl@t-online.de>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

using KeePassLib.Resources;
using KeePassLib.Utility;

namespace KeePassLib.Serialization
{
	public static class IocKnownProtocols
	{
		public static readonly string Http = "HTTP";
		public static readonly string Https = "HTTPS";
		public static readonly string WebDav = "WebDAV";
		public static readonly string Ftp = "FTP";
	}

	public static class IocKnownProperties
	{
		public static readonly string Timeout = "Timeout";
		public static readonly string PreAuth = "PreAuth";

		public static readonly string UserAgent = "UserAgent";
		public static readonly string Expect100Continue = "Expect100Continue";

		public static readonly string Passive = "Passive";
	}

	public static class IocPropertyInfoPool
	{
		private static List<IocPropertyInfo> m_l = null;
		public static IEnumerable<IocPropertyInfo> PropertyInfos
		{
			get { EnsureInitialized(); return m_l; }
		}

		private static void EnsureInitialized()
		{
			if(m_l != null) return;

			string strGen = KLRes.General;
			string strHttp = IocKnownProtocols.Http;
			string strHttps = IocKnownProtocols.Https;
			string strWebDav = IocKnownProtocols.WebDav;
			string strFtp = IocKnownProtocols.Ftp;

			string[] vGen = new string[] { strGen };
			string[] vHttp = new string[] { strHttp, strHttps, strWebDav };
			string[] vFtp = new string[] { strFtp };

			m_l = new List<IocPropertyInfo>
			{
				new IocPropertyInfo(IocKnownProperties.Timeout,
					typeof(long), KLRes.Timeout + " [ms]", vGen),
				new IocPropertyInfo(IocKnownProperties.PreAuth,
					typeof(bool), KLRes.PreAuth, vGen),

				new IocPropertyInfo(IocKnownProperties.UserAgent,
					typeof(string), KLRes.UserAgent, vHttp),
				new IocPropertyInfo(IocKnownProperties.Expect100Continue,
					typeof(bool), KLRes.Expect100Continue, vHttp),

				new IocPropertyInfo(IocKnownProperties.Passive,
					typeof(bool), KLRes.Passive, vFtp)

				// new IocPropertyInfo("Test", typeof(bool),
				//	"Long long long long long long long long long long long long long long long long long long long long",
				//	new string[] { "Proto 1/9", "Proto 2/9", "Proto 3/9", "Proto 4/9", "Proto 5/9",
				//	"Proto 6/9", "Proto 7/9", "Proto 8/9", "Proto 9/9" }));
			};
		}

		public static IocPropertyInfo Get(string strName)
		{
			if(string.IsNullOrEmpty(strName)) { Debug.Assert(false); return null; }

			EnsureInitialized();
			foreach(IocPropertyInfo pi in m_l)
			{
				if(pi.Name.Equals(strName, StrUtil.CaseIgnoreCmp))
					return pi;
			}

			return null;
		}

		public static bool Add(IocPropertyInfo pi)
		{
			if(pi == null) { Debug.Assert(false); return false; }

			// Name must be non-empty
			string strName = pi.Name;
			if(string.IsNullOrEmpty(strName)) { Debug.Assert(false); return false; }

			IocPropertyInfo piEx = Get(strName); // Ensures initialized
			if(piEx != null) { Debug.Assert(false); return false; } // Exists already

			m_l.Add(pi);
			return true;
		}
	}
}