CASA/c_policy/SynchPol.cs
2006-02-01 17:48:29 +00:00

482 lines
12 KiB
C#

/***********************************************************************
*
* Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1
* of the License.
*
* This library 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
* Library Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, Novell, Inc.
*
* To contact Novell about this file by physical or electronic mail,
* you may find current contact information at www.novell.com.
*
***********************************************************************/
using System;
using System.Collections;
using System.Xml;
using System.Xml.Serialization;
namespace Novell.CASA.CASAPolicy
{
public enum StoreKeyType
{
KW_KEY = 1,
GK_KEY,
MZ_KEY,
FX_KEY,
CASA_KEY
}
abstract public class LinkKey
{
protected StoreKeyType keyType;
public StoreKeyType KeyType
{
get
{
return keyType;
}
}
protected string storeName;
public string StoreName
{
get
{
return storeName;
}
set
{
storeName = value;
}
}
protected string storeId;
public string StoreId
{
get
{
return storeId;
}
set
{
storeId = value;
}
}
protected string secretId;
public string SecretId
{
get
{
return secretId;
}
set
{
secretId = value;
}
}
protected string keyId;
public string KeyId
{
get
{
return keyId;
}
set
{
keyId = value;
}
}
abstract public void AppendToDoc(XmlDocument doc, XmlElement linkKeyElem);
abstract public void Dump();
}
public class KWLinkKey : LinkKey
{
string folderId;
public string FolderId
{
get
{
return folderId;
}
set
{
folderId = value;
}
}
public KWLinkKey(string wallet, string folder,string secret,string key)
{
keyType = StoreKeyType.KW_KEY;
storeName = XmlConsts.KwalletStoreName;
storeId = wallet;
folderId = folder;
secretId = secret;
keyId = key;
}
public override void Dump()
{
Console.WriteLine("StoreName = " + storeName + " StoreId = " + storeId + " FolderId = " + folderId + " SecretId = " + secretId + " Key = " + keyId);
}
public override void AppendToDoc(XmlDocument doc, XmlElement linkKeyElem)
{
XmlAttribute attr;
try
{
attr = doc.CreateAttribute(XmlConsts.StoreNameAttr);
attr.Value = storeName;
linkKeyElem.SetAttributeNode(attr);
attr = doc.CreateAttribute(XmlConsts.StoreIdAttr);
attr.Value = storeId;
linkKeyElem.SetAttributeNode(attr);
attr = doc.CreateAttribute(XmlConsts.FolderIdAttr);
attr.Value = folderId;
linkKeyElem.SetAttributeNode(attr);
attr = doc.CreateAttribute(XmlConsts.SecretIdAttr);
attr.Value = secretId;
linkKeyElem.SetAttributeNode(attr);
attr = doc.CreateAttribute(XmlConsts.KeyAttr);
attr.Value = keyId;
linkKeyElem.SetAttributeNode(attr);
}
catch(Exception e)
{
//Console.WriteLine(e.ToString());
}
}
}
public class GKLinkKey : LinkKey
{
public GKLinkKey(string keyring, string secret, string key)
{
keyType = StoreKeyType.GK_KEY;
storeName = XmlConsts.GnomeKeyringStoreName;
storeId = keyring;
secretId = secret;
keyId = key;
}
public override void Dump()
{
Console.WriteLine("StoreName = " + storeName + " StoreId = " + storeId + " SecretId = " + secretId + " Key = " + keyId);
}
public override void AppendToDoc(XmlDocument doc, XmlElement linkKeyElem)
{
XmlAttribute attr;
try
{
attr = doc.CreateAttribute(XmlConsts.StoreNameAttr);
attr.Value = storeName;
linkKeyElem.SetAttributeNode(attr);
attr = doc.CreateAttribute(XmlConsts.StoreIdAttr);
attr.Value = storeId;
linkKeyElem.SetAttributeNode(attr);
attr = doc.CreateAttribute(XmlConsts.SecretIdAttr);
attr.Value = secretId;
linkKeyElem.SetAttributeNode(attr);
attr = doc.CreateAttribute(XmlConsts.KeyAttr);
attr.Value = keyId;
linkKeyElem.SetAttributeNode(attr);
}
catch(Exception e)
{
//Console.WriteLine(e.ToString());
}
}
}
public class MZLinkKey : LinkKey
{
public MZLinkKey(string profile, string url, string key)
{
keyType = StoreKeyType.MZ_KEY;
storeName = XmlConsts.MozillaStoreName;
storeId = profile;
secretId = url;
keyId = key;
}
public override void Dump()
{
Console.WriteLine("StoreName = " + storeName + " StoreId = " + storeId + " SecretId = " + secretId + " Key = " + keyId);
}
public override void AppendToDoc(XmlDocument doc, XmlElement linkKeyElem)
{
XmlAttribute attr;
try
{
attr = doc.CreateAttribute(XmlConsts.StoreNameAttr);
attr.Value = storeName;
linkKeyElem.SetAttributeNode(attr);
attr = doc.CreateAttribute(XmlConsts.StoreIdAttr);
attr.Value = storeId;
linkKeyElem.SetAttributeNode(attr);
attr = doc.CreateAttribute(XmlConsts.SecretIdAttr);
attr.Value = secretId;
linkKeyElem.SetAttributeNode(attr);
attr = doc.CreateAttribute(XmlConsts.KeyAttr);
attr.Value = keyId;
linkKeyElem.SetAttributeNode(attr);
}
catch(Exception e)
{
//Console.WriteLine(e.ToString());
}
}
}
public class FXLinkKey : LinkKey
{
public FXLinkKey(string profile,string url,string key)
{
keyType = StoreKeyType.FX_KEY;
storeName = XmlConsts.FirefoxStoreName;
storeId = profile;
secretId = url;
keyId = key;
}
public override void Dump()
{
Console.WriteLine("StoreName = " + storeName + " StoreId = " + storeId + " SecretId = " + secretId + " Key = " + keyId);
}
public override void AppendToDoc(XmlDocument doc, XmlElement linkKeyElem)
{
XmlAttribute attr;
try
{
attr = doc.CreateAttribute(XmlConsts.StoreNameAttr);
attr.Value = storeName;
linkKeyElem.SetAttributeNode(attr);
attr = doc.CreateAttribute(XmlConsts.StoreIdAttr);
attr.Value = storeId;
linkKeyElem.SetAttributeNode(attr);
attr = doc.CreateAttribute(XmlConsts.SecretIdAttr);
attr.Value = secretId;
linkKeyElem.SetAttributeNode(attr);
attr = doc.CreateAttribute(XmlConsts.KeyAttr);
attr.Value = keyId;
linkKeyElem.SetAttributeNode(attr);
}
catch(Exception e)
{
//Console.WriteLine(e.ToString());
}
}
}
public class CASALinkKey : LinkKey
{
public CASALinkKey(string secret, string key)
{
storeName = XmlConsts.MicasaStoreName;
secretId = secret;
keyId = key;
}
public override void Dump()
{
Console.WriteLine("StoreName = " + storeName + "SecretId = " + secretId + "Key = " + keyId);
}
public override void AppendToDoc(XmlDocument doc, XmlElement linkKeyElem)
{
XmlAttribute attr;
try
{
attr = doc.CreateAttribute(XmlConsts.StoreNameAttr);
attr.Value = storeName;
linkKeyElem.SetAttributeNode(attr);
attr = doc.CreateAttribute(XmlConsts.SecretIdAttr);
attr.Value = secretId;
linkKeyElem.SetAttributeNode(attr);
attr = doc.CreateAttribute(XmlConsts.KeyAttr);
attr.Value = keyId;
linkKeyElem.SetAttributeNode(attr);
}
catch(Exception e)
{
//Console.WriteLine(e.ToString());
}
}
}
public class Link
{
ArrayList linkKeys;
public ArrayList LinkKeys
{
get
{
return linkKeys;
}
}
public Link(ArrayList linkList)
{
linkKeys = linkList;
}
public void Dump()
{
IEnumerator etor = linkKeys.GetEnumerator();
while(etor.MoveNext())
{
((LinkKey)(etor.Current)).Dump();
}
}
public void AppendToDoc(XmlDocument doc, XmlElement linkElem)
{
try
{
IEnumerator enumerator = linkKeys.GetEnumerator();
while(enumerator.MoveNext())
{
XmlElement linkKeyElem = doc.CreateElement(XmlConsts.LinkKeyNode);
((LinkKey)(enumerator.Current)).AppendToDoc(doc,linkKeyElem);
linkElem.AppendChild(linkKeyElem);
}
}
catch(Exception e)
{
//Console.WriteLine(e.ToString());
}
}
}
public class LinkGroup
{
ArrayList links;
public ArrayList Links
{
get
{
return links;
}
}
public LinkGroup(ArrayList linksList)
{
links = linksList;
}
public void Dump()
{
IEnumerator enumerator = links.GetEnumerator();
while(enumerator.MoveNext())
{
Console.WriteLine("Link");
((Link)(enumerator.Current)).Dump();
}
}
internal void AppendToDoc(XmlDocument doc, XmlElement synchPolElem)
{
try
{
XmlElement linkGroupElem = doc.CreateElement(XmlConsts.LinkGroupNode);
synchPolElem.AppendChild(linkGroupElem);
IEnumerator enumerator = links.GetEnumerator();
while(enumerator.MoveNext())
{
XmlElement linkElem = doc.CreateElement(XmlConsts.LinkNode);
((Link)(enumerator.Current)).AppendToDoc(doc,linkElem);
linkGroupElem.AppendChild(linkElem);
}
}
catch(Exception e)
{
//Console.WriteLine(e.ToString());
}
}
}
public class SynchPol: CASAPol
{
ArrayList linkGroups;
public ArrayList LinkGroups
{
get
{
return linkGroups;
}
}
public SynchPol( ArrayList grps)
{
policyType = CASAPolType.SYNCH_POL;
linkGroups = grps;
}
public override void DumpPol()
{
Console.WriteLine("\nSynch Policy");
IEnumerator grpEtor = linkGroups.GetEnumerator();
while(grpEtor.MoveNext())
{
Console.WriteLine("\nLink Group\n");
((LinkGroup)(grpEtor.Current)).Dump();
} //end of while grpEtor
}
internal override void AppendToDoc(XmlDocument doc)
{
string xPath = "";
try
{
xPath = "//" + XmlConsts.CASAPolicyNode;
XmlNode rootElem = doc.SelectSingleNode(xPath);
XmlElement synchPolElem = doc.CreateElement(XmlConsts.SynchPolicyNode);
rootElem.AppendChild(synchPolElem);
IEnumerator enumerator = linkGroups.GetEnumerator();
while(enumerator.MoveNext())
{
((LinkGroup)(enumerator.Current)).AppendToDoc(doc,synchPolElem);
// linkGroups[i].AppendToDoc(doc);
}
}
catch(Exception e)
{
//Console.WriteLine(e.ToString());
}
}
}
}