Moving micasa 1.5 trunk to Novell forge.

This commit is contained in:
Cameron (Kamran) Mashayekhi
2005-10-11 19:51:00 +00:00
parent 082db33275
commit efe0a5e13c
691 changed files with 116628 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
using System;
using System.Net;
using System.Net.Sockets;
//using sscs.communication.win.NamedPipes;
namespace Novell.CASA.MiCasa.Communication
{
public interface ClientChannel
{
void Open();
int Read(byte[] buf);
byte[] Read();
int Write(byte[] buf);
void Close();
}
}

View File

@@ -0,0 +1,28 @@
using System;
namespace Novell.CASA.MiCasa.Communication
{
/// <summary>
/// Summary description for IPCClientFactory.
/// </summary>
public class IPCClientFactory
{
private IPCClientFactory()
{
}
public static ClientChannel CreateClientConnection()
{
#if LINUX
return( new UnixIPCClientChannel());
#endif
#if W32
return (new WinIPCClientChannel());
#endif
}
}
}

View File

@@ -0,0 +1,156 @@
using System;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using Novell.CASA.MiCasa.Common;
namespace Novell.CASA.MiCasa.Communication
{
/// <summary>
/// Summary description for MiCasaRequestReply.
/// </summary>
public class MiCasaRequestReply
{
//public const int VERB_GET_SECRET = 1;
//public const int VERB_SET_SECRET = 2;
//public const int VERB_GET_KEYCHAIN = 3;
//public const int VERB_GET_STORE = 4;
//public const int VERB_SET_KEYVALUE = 5;
//public const int VERB_GET_KEYVALUE = 6;
public const int VERB_SET_LINKED_KEY = 7;
public const int VERB_GET_LINKED_KEYS = 8;
public const int VERB_REMOVE_LINKED_KEY = 9;
public const int VERB_WRITE_KEY = 10;
public const int VERB_REMOVE_ALL_SECRETS = 11;
public const int VERB_LOCK_STORE = 12;
public const int VERB_UNLOCK_STORE = 13;
public const int VERB_GET_STORE_STATUS = 14;
public const int VERB_REMOVE_KEY = 15;
public const int VERB_READ_KEY = 16;
public const int VERB_GET_KEY_LIST = 17;
public const int VERB_DUMP_LINKED_KEYS = 96;
public const int VERB_CREATE_TEST_SECRETS = 97;
public const int VERB_REMOVE_TEST_SECRETS = 98;
public const int VERB_PING_MICASAD = 99;
public MiCasaRequestReply()
{
//
// TODO: Add constructor logic here
//
}
public static object Send(int verb)
{
return Send(verb, null, null, null, null);
}
public static object Send(int verb, object wo)
{
return Send(verb, null, null, null, wo);
}
public static object Send(int verb,
string sKeyChainID,
string sSecretID,
string sKeyID,
object theObject)
{
// Lengths of message fields
int MSGID_LEN = 2;
int MSG_LEN = 4;
WrappedObject request;
WrappedObject reply = null;
// open a client connection
//IInterProcessConnection clientConnection = null;
ClientChannel ipcChannel = IPCClientFactory.CreateClientConnection();
ipcChannel.Open();
try
{
// contruct and serialize the Message Object
request = new WrappedObject(verb, sKeyChainID, sSecretID, sKeyID, theObject);
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
formatter.Serialize(ms, request);
ms.Flush();
ms.Position = 0;
byte[] rawBytes = new byte[2+4+ms.Length];
byte[] t = new byte[10];
// set message id
int destIndex = 0;
ushort msgId = 20;
t = BitConverter.GetBytes((ushort)msgId);
Array.Copy(t,0,rawBytes,destIndex,MSGID_LEN);
destIndex += MSGID_LEN;
// set the object length
//Poorna
int msgLen = 2+4+(int)ms.Length;
// int msgLen = (int)ms.Length;
t = BitConverter.GetBytes(msgLen);
// t = BitConverter.GetBytes(ms.Length);
Array.Copy(t,0,rawBytes,destIndex,MSG_LEN);
destIndex += MSG_LEN;
// copy in the object
Array.Copy(ms.GetBuffer(), 0, rawBytes, destIndex, ms.Length);
//clientConnection = new ClientPipeConnection("MyPipe", ".");
//clientConnection = new ClientPipeConnection(XTIER_RPC_PIPE, ".");
//clientConnection.Connect();
// write the bytes
//clientConnection.WriteBytes(rawBytes);
ipcChannel.Write(rawBytes);
// read the bytes
//byte[] returnBuffer = clientConnection.ReadBytes();
byte[] returnBuffer = ipcChannel.Read();
if (returnBuffer != null)
{
// deserialize MessageObject
uint iMsgLen = BitConverter.ToUInt32(returnBuffer,0);
ms = new MemoryStream(returnBuffer, 4, (int)iMsgLen);
ms.Position = 0;
reply = (WrappedObject)formatter.Deserialize(ms);
if (reply.GetReturnCode() != 0)
throw new Exception(reply.GetReturnCode().ToString());
}
// close the connection
//clientConnection.Close();
ipcChannel.Close();
}
catch (Exception e1)
{
Console.WriteLine(e1.ToString());
//clientConnection.Dispose();
//throw new Exception(e1.ToString());
}
if (reply != null)
return reply.GetObject();
else
return null;
}
}
}

View File

@@ -0,0 +1,122 @@
using System;
using System.Net;
using System.IO;
using System.Net.Sockets;
using Mono.Unix;
namespace Novell.CASA.MiCasa.Communication
{
/// <summary>
/// Summary description for UnixIPCClientChannel.
/// </summary>
public class UnixIPCClientChannel : ClientChannel
{
private Socket mSocket = null;
private string socketFileName = "/tmp/.novellCASA";
private EndPoint sockEndPoint;
public UnixIPCClientChannel()
{
}
public void Open()
{
mSocket = new Socket( AddressFamily.Unix,
SocketType.Stream,
ProtocolType.IP );
if (mSocket == null) throw new Exception("could not get socket");
sockEndPoint = new UnixEndPoint(socketFileName);
mSocket.Connect(sockEndPoint);
}
public int Read(byte[] buf)
{
buf = Read();
if (buf != null)
{
Console.WriteLine("Bytes read = " + buf.Length);
return buf.Length;
}
else
return 0;
}
public byte[] Read()
{
byte[] returnBuffer = null;
int bytesRecvd = 0;
try
{
/* We need to read 'msgLen' to know how many bytes to
* allocate.
*/
byte[] msgIdBytes = new byte[2];
bytesRecvd = mSocket.Receive(msgIdBytes);
if( 0 == bytesRecvd )
{
return null;
}
byte[] msgLenBytes = new byte[4];
bytesRecvd = mSocket.Receive(msgLenBytes);
if( 0 == bytesRecvd )
{
return null;
}
uint msgLen = BitConverter.ToUInt32(msgLenBytes,0);
if( msgLen > 6 )
{
byte[] buf = new byte[msgLen - 6];
bytesRecvd = mSocket.Receive (buf);
if( 0 == bytesRecvd )
{
return null;
}
returnBuffer = new byte[msgLen];
Array.Copy(msgIdBytes,returnBuffer,2);
Array.Copy(msgLenBytes,0,returnBuffer,2,4);
Array.Copy(buf,0,returnBuffer,6,buf.Length);
return returnBuffer;
}
else
{
returnBuffer = new byte[6];
Array.Copy(msgIdBytes,returnBuffer,2);
Array.Copy(msgLenBytes,0,returnBuffer,2,4);
return returnBuffer;
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return null;
}
}
public int Write(byte[] buf)
{
try
{
mSocket.Send(buf);
Console.WriteLine("Bytes written = " + buf.Length);
return buf.Length;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return 0;
}
}
public void Close()
{
mSocket.Close();
}
}
}

View File

@@ -0,0 +1,80 @@
using System;
using AppModule.InterProcessComm;
using AppModule.NamedPipes;
namespace Novell.CASA.MiCasa.Communication
{
/// <summary>
/// Summary description for WinIPCClientChannel.
/// </summary>
public class WinIPCClientChannel : ClientChannel
{
private static IInterProcessConnection clientConnection = null;
private static string XTIER_RPC_PIPE = "SS_RPC_PIPE";
public WinIPCClientChannel()
{
}
public void Open()
{
if (clientConnection == null)
{
clientConnection = new ClientPipeConnection(XTIER_RPC_PIPE, ".");
clientConnection.Connect();
}
}
public int Read(byte[] buf)
{
buf = Read();
if (buf != null)
return 0;
else
return -1;
}
public byte[] Read()
{
byte[] returnBuffer;
try
{
returnBuffer = clientConnection.ReadBytes();
return returnBuffer;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return null;
}
}
public int Write(byte[] buf)
{
try
{
clientConnection.WriteBytes(buf);
return 0;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
return -1;
}
}
public void Close()
{
//clientConnection.Close();
//clientConnection.Dispose();
}
}
}