Revert changes made by mistake in the trunk.
This commit is contained in:
parent
ca2ae81cc4
commit
a1b22add5a
@ -21,17 +21,20 @@
|
|||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
|
||||||
/* This is an interface which would be implemented
|
//using sscs.communication.win.NamedPipes;
|
||||||
* by UnixCommunication and WinCommunication.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Novell.CASA.MiCasa.Communication.Server
|
|
||||||
|
namespace Novell.CASA.MiCasa.Communication
|
||||||
{
|
{
|
||||||
|
public interface ClientChannel
|
||||||
public interface Communication
|
|
||||||
{
|
{
|
||||||
void StartCommunicationEndPoint();
|
void Open();
|
||||||
void CloseCommunicationEndPoint();
|
int Read(byte[] buf);
|
||||||
|
byte[] Read();
|
||||||
|
int Write(byte[] buf);
|
||||||
|
void Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -21,32 +21,30 @@
|
|||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
/* This class would have only static methods.
|
|
||||||
*/
|
|
||||||
namespace Novell.CASA.MiCasa.Communication.Server
|
|
||||||
{
|
|
||||||
|
|
||||||
public class CommunicationFactory
|
namespace Novell.CASA.MiCasa.Communication
|
||||||
{
|
{
|
||||||
/* Make the constructor private, to avoid instances of this
|
/// <summary>
|
||||||
* class.
|
/// Summary description for IPCClientFactory.
|
||||||
*/
|
/// </summary>
|
||||||
private CommunicationFactory()
|
public class IPCClientFactory
|
||||||
|
{
|
||||||
|
private IPCClientFactory()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This method must check for platform and return
|
public static ClientChannel CreateClientConnection()
|
||||||
* an appropriate class. As of now, it assumes platform as Linux.
|
|
||||||
*/
|
|
||||||
public static Communication CreateCommunicationEndPoint()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
#if LINUX
|
#if LINUX
|
||||||
return( new UnixCommunication());
|
return( new UnixIPCClientChannel());
|
||||||
#endif
|
#endif
|
||||||
#if W32
|
#if W32
|
||||||
return (new WinCommunication());
|
return (new WinIPCClientChannel());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
191
CASA/micasad/lib/communication/MiCasaRequestReply.cs
Normal file
191
CASA/micasad/lib/communication/MiCasaRequestReply.cs
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
/***********************************************************************
|
||||||
|
*
|
||||||
|
* 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.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_RESET_MASTER_PASSWORD = 18;
|
||||||
|
public const int VERB_GET_SECRETIDS = 19;
|
||||||
|
public const int VERB_VALIDATE_DESKTOP_PWD = 20;
|
||||||
|
public const int VERB_EXPORT_SECRETS = 21;
|
||||||
|
public const int VERB_ADD_XML_SECRETS = 22;
|
||||||
|
public const int VERB_CHANGE_PERSIST_DIR = 23;
|
||||||
|
public const int VERB_CREATE_POLICY_DIR = 24;
|
||||||
|
public const int VERB_GET_CREATE_TIME = 25;
|
||||||
|
public const int VERB_GET_MODIFIED_TIME = 26;
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
ipcChannel.Close();
|
||||||
|
throw new Exception(reply.GetReturnCode().ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// close the connection
|
||||||
|
//clientConnection.Close();
|
||||||
|
ipcChannel.Close();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
//Console.WriteLine(e1.ToString());
|
||||||
|
//clientConnection.Dispose();
|
||||||
|
//throw new Exception(e1.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reply != null)
|
||||||
|
return reply.GetObject();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
52
CASA/micasad/lib/communication/SAS.Designer.cs
generated
52
CASA/micasad/lib/communication/SAS.Designer.cs
generated
@ -1,52 +0,0 @@
|
|||||||
namespace Novell.CASA.communication
|
|
||||||
{
|
|
||||||
partial class SAS
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
this.SuspendLayout();
|
|
||||||
//
|
|
||||||
// SAS
|
|
||||||
//
|
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
|
||||||
this.BackColor = System.Drawing.SystemColors.ControlDark;
|
|
||||||
this.ClientSize = new System.Drawing.Size(292, 266);
|
|
||||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
|
||||||
this.MaximizeBox = false;
|
|
||||||
this.MinimizeBox = false;
|
|
||||||
this.Name = "SAS";
|
|
||||||
this.Opacity = 0.8;
|
|
||||||
this.ShowInTaskbar = false;
|
|
||||||
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
|
|
||||||
this.ResumeLayout(false);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace Novell.CASA.communication
|
|
||||||
{
|
|
||||||
public partial class SAS: Form
|
|
||||||
{
|
|
||||||
public SAS()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
182
CASA/micasad/lib/communication/UnixIPCClientChannel.cs
Normal file
182
CASA/micasad/lib/communication/UnixIPCClientChannel.cs
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
/***********************************************************************
|
||||||
|
*
|
||||||
|
* 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.Net;
|
||||||
|
using System.IO;
|
||||||
|
using System.Net.Sockets;
|
||||||
|
using Mono.Unix;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
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);
|
||||||
|
UnixFileSystemInfo sockFileInfo = new UnixFileInfo(socketFileName);
|
||||||
|
UnixUserInfo sockFileOwner = sockFileInfo.OwnerUser;
|
||||||
|
|
||||||
|
// root is the owner of the file "/tmp/.novellCASA"
|
||||||
|
if (sockFileOwner.UserId == 0)
|
||||||
|
{
|
||||||
|
mSocket.Connect(sockEndPoint);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("not a valid miCASA service");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = null;
|
||||||
|
int bytesAvailable;
|
||||||
|
int totalBytes = 0;
|
||||||
|
int msgLencount = 0;
|
||||||
|
string bufstring = null;
|
||||||
|
|
||||||
|
// buffer for data
|
||||||
|
MemoryStream ms = new MemoryStream();
|
||||||
|
|
||||||
|
while (totalBytes < (msgLen - 6))
|
||||||
|
{
|
||||||
|
bytesAvailable = mSocket.Available;
|
||||||
|
if (0 == bytesAvailable)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
buf = new byte[bytesAvailable];
|
||||||
|
bytesRecvd = mSocket.Receive(buf);
|
||||||
|
ms.Write(buf, 0, bytesRecvd);
|
||||||
|
|
||||||
|
totalBytes = totalBytes + bytesAvailable;
|
||||||
|
}
|
||||||
|
if (totalBytes == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
byte[] finalbuf = ms.ToArray();
|
||||||
|
|
||||||
|
int returnBufferLen = msgIdBytes.Length + msgLenBytes.Length + totalBytes;
|
||||||
|
returnBuffer = new byte[returnBufferLen];
|
||||||
|
Array.Copy(msgIdBytes, returnBuffer, 2);
|
||||||
|
Array.Copy(msgLenBytes, 0, returnBuffer, 2, 4);
|
||||||
|
Array.Copy(finalbuf, 0, returnBuffer, 6, finalbuf.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
103
CASA/micasad/lib/communication/WinIPCClientChannel.cs
Normal file
103
CASA/micasad/lib/communication/WinIPCClientChannel.cs
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
/***********************************************************************
|
||||||
|
*
|
||||||
|
* 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 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,125 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
using System.Xml;
|
|
||||||
|
|
||||||
namespace Novell.CASA
|
|
||||||
{
|
|
||||||
class MethodCall
|
|
||||||
{
|
|
||||||
internal static string GetCard = "getCard";
|
|
||||||
internal static string GetSecurityToken = "getSecurityToken";
|
|
||||||
|
|
||||||
//private string m_methodname;
|
|
||||||
private Hashtable m_htParams = new Hashtable();
|
|
||||||
private ArrayList m_alReqClaims = new ArrayList();
|
|
||||||
private ArrayList m_alOptClaims = new ArrayList();
|
|
||||||
|
|
||||||
private XmlDocument m_doc = new XmlDocument();
|
|
||||||
private XmlNode m_methodCall;
|
|
||||||
private XmlNode m_methodName;
|
|
||||||
private XmlNode m_params;
|
|
||||||
private XmlNode m_param;
|
|
||||||
private XmlNode m_struct;
|
|
||||||
|
|
||||||
|
|
||||||
public MethodCall(string sMethodName)
|
|
||||||
{
|
|
||||||
//m_methodname = sMethodName;
|
|
||||||
//m_methodCall = m_doc.CreateNode(XmlNodeType.Element, "methodCall", "");
|
|
||||||
m_methodCall = m_doc.CreateElement("methodCall");
|
|
||||||
|
|
||||||
m_methodName = m_doc.CreateElement("methodName");
|
|
||||||
m_methodName.InnerText = sMethodName;
|
|
||||||
|
|
||||||
m_params = m_doc.CreateElement("params");
|
|
||||||
m_param = m_doc.CreateElement("param");
|
|
||||||
m_struct = m_doc.CreateElement("struct");
|
|
||||||
|
|
||||||
m_param.AppendChild(m_struct);
|
|
||||||
m_params.AppendChild(m_param);
|
|
||||||
|
|
||||||
m_methodCall.AppendChild(m_methodName);
|
|
||||||
m_methodCall.AppendChild(m_params);
|
|
||||||
|
|
||||||
m_doc.AppendChild(m_methodCall);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void AddMember(string sName, string sValue)
|
|
||||||
{
|
|
||||||
XmlNode nodeMember = m_doc.CreateElement("member");
|
|
||||||
|
|
||||||
XmlNode nodeName = m_doc.CreateNode(XmlNodeType.Element, "name", null);
|
|
||||||
nodeName.InnerText = sName;
|
|
||||||
|
|
||||||
XmlNode nodeValue = m_doc.CreateNode(XmlNodeType.Element, "value", null);
|
|
||||||
nodeValue.InnerText = sValue;
|
|
||||||
|
|
||||||
nodeMember.AppendChild(nodeName);
|
|
||||||
nodeMember.AppendChild(nodeValue);
|
|
||||||
|
|
||||||
m_struct.AppendChild(nodeMember);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void AddRequiredClaim(string sClaim)
|
|
||||||
{
|
|
||||||
m_alReqClaims.Add(sClaim);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddOptionalClaim(string sOptClaim)
|
|
||||||
{
|
|
||||||
m_alOptClaims.Add(sOptClaim);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal string GetXmlRpc()
|
|
||||||
{
|
|
||||||
|
|
||||||
// add claims to doc
|
|
||||||
if (m_alReqClaims.Count > 0)
|
|
||||||
{
|
|
||||||
AppendClaims("requiredclaims", m_alReqClaims);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_alOptClaims.Count > 0)
|
|
||||||
{
|
|
||||||
AppendClaims("optionalclaims", m_alOptClaims);
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_doc.InnerXml;
|
|
||||||
// return null;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void AppendClaims(string sClaimType, ArrayList al)
|
|
||||||
{
|
|
||||||
|
|
||||||
XmlNode member = m_doc.CreateNode(XmlNodeType.Element, "member", null);
|
|
||||||
XmlNode name = m_doc.CreateNode(XmlNodeType.Element, "name", null);
|
|
||||||
name.InnerText = sClaimType;
|
|
||||||
|
|
||||||
XmlNode array = m_doc.CreateElement("array");
|
|
||||||
XmlNode data = m_doc.CreateElement("data");
|
|
||||||
array.AppendChild(data);
|
|
||||||
|
|
||||||
foreach (string sClaim in al)
|
|
||||||
{
|
|
||||||
XmlNode valueNode = m_doc.CreateNode(XmlNodeType.Element, "value", null);
|
|
||||||
valueNode.InnerText = sClaim;
|
|
||||||
data.AppendChild(valueNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
member.AppendChild(name);
|
|
||||||
member.AppendChild(array);
|
|
||||||
|
|
||||||
m_struct.AppendChild(member);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,125 +0,0 @@
|
|||||||
/***********************************************************************
|
|
||||||
*
|
|
||||||
* 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.Text;
|
|
||||||
using Novell.CASA.MiCasa.Communication.Server;
|
|
||||||
|
|
||||||
class AppHandler
|
|
||||||
{
|
|
||||||
//Data
|
|
||||||
private IPCChannel clientChannel;
|
|
||||||
|
|
||||||
//Methods
|
|
||||||
internal AppHandler(IPCChannel ipcChannel)
|
|
||||||
{
|
|
||||||
clientChannel = ipcChannel;
|
|
||||||
//CSSSLogger.ExecutionTrace(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
~AppHandler()
|
|
||||||
{
|
|
||||||
//CSSSLogger.ExecutionTrace(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Starts servicing the application. This is called as soon
|
|
||||||
* as a new client connection is established.
|
|
||||||
*/
|
|
||||||
internal int ServiceApp(RequestParser reqParser)
|
|
||||||
{
|
|
||||||
SSVerb verb = null;
|
|
||||||
//CSSSLogger.ExecutionTrace(this);
|
|
||||||
|
|
||||||
while(true)
|
|
||||||
{
|
|
||||||
byte[] buf = null;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
buf = clientChannel.Read();
|
|
||||||
if( null == buf )
|
|
||||||
{
|
|
||||||
return RetCodes.SUCCESS;
|
|
||||||
}
|
|
||||||
//RequestParser reqParser = new RequestParser();
|
|
||||||
verb = reqParser.ParseRequest(buf);
|
|
||||||
//CSSSLogger.logbreak();
|
|
||||||
//CSSSLogger.DbgLog("SSCS going to sevice a :: ** " + verb.GetVerbName() + " **");
|
|
||||||
|
|
||||||
|
|
||||||
buf = verb.ProcessRequest();
|
|
||||||
if ( buf != null)
|
|
||||||
{
|
|
||||||
int retVal = clientChannel.Write(buf);
|
|
||||||
if(retVal < 0)
|
|
||||||
{
|
|
||||||
// CSSSLogger.DbgLog("Write failed");
|
|
||||||
return RetCodes.FAILURE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//There must always be something written back to client.
|
|
||||||
return RetCodes.FAILURE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// catch(CommunicationException e)
|
|
||||||
// {
|
|
||||||
// CSSSLogger.ExpLog(e.ToString());
|
|
||||||
// throw e;
|
|
||||||
// }
|
|
||||||
catch(FormatException e)
|
|
||||||
{
|
|
||||||
// CSSSLogger.ExpLog(e.ToString());
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
// CSSSLogger.ExpLog(e.ToString());
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TBD define verb specific heirarchy of exceptions catch
|
|
||||||
* (Some processing problem)
|
|
||||||
*/
|
|
||||||
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
// CSSSLogger.DbgLog("SSCS finished processing a SS Verb :: ** " + verb.GetVerbName() + " **");
|
|
||||||
// CSSSLogger.logbreak();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal class RetCodes
|
|
||||||
{
|
|
||||||
internal static int SUCCESS = 0;
|
|
||||||
internal static int FAILURE = -1;
|
|
||||||
internal static int LOAD_HIDDEN_ONLY = 1;
|
|
||||||
internal static int LOAD_ALL_EXCEPT_HIDDEN = 2;
|
|
||||||
internal static int WRITE_HIDDEN_ONLY = 3;
|
|
||||||
internal static int WRITE_ALL_EXCEPT_HIDDEN = 4;
|
|
||||||
internal static int WRITE_ALL = 5;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
/***********************************************************************
|
|
||||||
*
|
|
||||||
* 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.Net;
|
|
||||||
using System.Net.Sockets;
|
|
||||||
#if W32
|
|
||||||
using AppModule.NamedPipes;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Novell.CASA.MiCasa.Communication.Server
|
|
||||||
{
|
|
||||||
|
|
||||||
abstract class IPCChannel
|
|
||||||
{
|
|
||||||
/* This must check for the platform and return an
|
|
||||||
* appropriate IPCChannel.
|
|
||||||
*/
|
|
||||||
#if LINUX
|
|
||||||
internal static IPCChannel Create(Socket socket)
|
|
||||||
{
|
|
||||||
int platform = (int)Environment.OSVersion.Platform;
|
|
||||||
if(( platform ==4 ) || ( platform == 128 ))
|
|
||||||
return (new UnixIPCChannel(socket) ) ;
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if W32
|
|
||||||
internal static IPCChannel Create(ServerPipeConnection serverPipe)
|
|
||||||
{
|
|
||||||
return (new WinIPCChannel(serverPipe));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
abstract internal int Read(byte[] buf);
|
|
||||||
abstract internal byte[] Read();
|
|
||||||
abstract internal int Write(byte[] buf);
|
|
||||||
abstract internal void Close();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
/***********************************************************************
|
|
||||||
*
|
|
||||||
* 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.Text;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Novell.CASA.MiCasa.Communication.Server
|
|
||||||
{
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Defines the interfaces to be implemenetd by all Secret Store Verbs.
|
|
||||||
*/
|
|
||||||
public interface SSVerb
|
|
||||||
{
|
|
||||||
/* Takes in the raw bytes and sets them for a Verb,
|
|
||||||
* so that the verb will execute in the bytes given.
|
|
||||||
* TBD: In case we are able to send the byte[] through constructor,
|
|
||||||
* we can avoid this interface.
|
|
||||||
*/
|
|
||||||
|
|
||||||
void SetMessageContent(byte[] rawbytes);
|
|
||||||
|
|
||||||
/* Takes in the SecretStore Reeference and returns the correct SSVerb
|
|
||||||
*/
|
|
||||||
byte[] ProcessRequest();
|
|
||||||
|
|
||||||
//Gives the name of operation performed.Can be used in case of error.
|
|
||||||
string GetVerbName();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,88 +0,0 @@
|
|||||||
/***********************************************************************
|
|
||||||
*
|
|
||||||
* 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.Text;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* After the bytes format is finalized for Windows this class might need to
|
|
||||||
* be modified..
|
|
||||||
* Depending upon impact either a new method can be invoked after platfrom
|
|
||||||
* check or a Factory pattern can be used to redesign this class.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
namespace Novell.CASA.MiCasa.Communication.Server
|
|
||||||
{
|
|
||||||
/* This class will be used to convert raw bytes to one of the SecretStore
|
|
||||||
* Verbs. Although there is no need to have many instances,
|
|
||||||
* this class will NOT be singleton class since we
|
|
||||||
* do not want a hit on performance (synchronization, obtaining locks,
|
|
||||||
* releasing locks...etc )
|
|
||||||
* Making it singleton is not giving us any advantage versus performance.
|
|
||||||
*/
|
|
||||||
internal class RequestParser
|
|
||||||
{
|
|
||||||
Hashtable msgIdMap = new Hashtable();
|
|
||||||
|
|
||||||
internal RequestParser()
|
|
||||||
{
|
|
||||||
msgIdMap.Add(0,"casa.verbs.SelectCard");
|
|
||||||
msgIdMap.Add(1, "casa.verbs.SelectCard");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Processes the request and returns the corrrect SSverb.
|
|
||||||
* This interface works on the class member rawbytes and
|
|
||||||
* returns the result.
|
|
||||||
*/
|
|
||||||
internal SSVerb ParseRequest(byte[] rawbytes)
|
|
||||||
{
|
|
||||||
if (rawbytes == null)
|
|
||||||
throw new FormatException("Message format incorrect");
|
|
||||||
|
|
||||||
String className = GetClassName(rawbytes);
|
|
||||||
|
|
||||||
SSVerb theVerb = (SSVerb)Activator.CreateInstance(null, className ).Unwrap();
|
|
||||||
theVerb.SetMessageContent(rawbytes);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* TBD: We can send the activation params in the same call.
|
|
||||||
*/
|
|
||||||
//SSVerb theVerb = (SSVerb)Activator.CreateInstance(Type.GetType(className)).Unwrap();
|
|
||||||
|
|
||||||
return theVerb;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetClassName(byte[] ipcbytes)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Read first two bytes and get ushort
|
|
||||||
* Look up table and send class name
|
|
||||||
*/
|
|
||||||
ushort msgId = BitConverter.ToUInt16(ipcbytes,0);
|
|
||||||
return ((String)(msgIdMap[(int)msgId]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
/***********************************************************************
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
* z
|
|
||||||
***********************************************************************/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
|
|
||||||
using AppModule.InterProcessComm;
|
|
||||||
using AppModule.NamedPipes;
|
|
||||||
using Novell.CASA.MiCasa.Communication.win;
|
|
||||||
|
|
||||||
|
|
||||||
namespace Novell.CASA.MiCasa.Communication.Server
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Summary description for WinCommunication.
|
|
||||||
/// </summary>
|
|
||||||
public class WinCommunication : Server.Communication
|
|
||||||
{
|
|
||||||
|
|
||||||
public static IChannelManager PipeManager;
|
|
||||||
|
|
||||||
public WinCommunication()
|
|
||||||
{
|
|
||||||
PipeManager = new PipeManager();
|
|
||||||
PipeManager.Initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void StartCommunicationEndPoint()
|
|
||||||
{
|
|
||||||
Console.WriteLine("StartCommunctionEndPointed called");
|
|
||||||
//PipeManager = new PipeManager();
|
|
||||||
//PipeManager.Initialize();
|
|
||||||
//PipeManager.Start();
|
|
||||||
PipeManager.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CloseCommunicationEndPoint()
|
|
||||||
{
|
|
||||||
PipeManager.Stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,102 +0,0 @@
|
|||||||
/***********************************************************************
|
|
||||||
*
|
|
||||||
* 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.IO;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
using AppModule.NamedPipes;
|
|
||||||
using Novell.CASA.MiCasa.Communication.win;
|
|
||||||
|
|
||||||
namespace Novell.CASA.MiCasa.Communication.Server
|
|
||||||
{
|
|
||||||
|
|
||||||
class WinIPCChannel : IPCChannel
|
|
||||||
{
|
|
||||||
// Data
|
|
||||||
private ServerPipeConnection m_serverPipeConnection;
|
|
||||||
|
|
||||||
//Methods
|
|
||||||
public WinIPCChannel(ServerPipeConnection serverPipeConnection)
|
|
||||||
{
|
|
||||||
m_serverPipeConnection = serverPipeConnection;
|
|
||||||
}
|
|
||||||
|
|
||||||
private WinIPCChannel()
|
|
||||||
{
|
|
||||||
//CSSSLogger.DbgLog("WinIPCChannel constructor must be called with a serverPipe");
|
|
||||||
|
|
||||||
}
|
|
||||||
~WinIPCChannel()
|
|
||||||
{
|
|
||||||
// Console.WriteLine("WinIPCChannel::~~WinIPCChannel");
|
|
||||||
}
|
|
||||||
|
|
||||||
override internal byte[] Read()
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
byte[] incoming = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
incoming = m_serverPipeConnection.ReadBytes();
|
|
||||||
return incoming;
|
|
||||||
}
|
|
||||||
catch(Exception)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
//CSSSLogger.DbgLog("Exception in reading data from client" + e.ToString());
|
|
||||||
//throw new CommunicationException(e.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override internal int Read(byte[] buf)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
override internal int Write(byte[] buf)
|
|
||||||
{
|
|
||||||
|
|
||||||
int bytesSent = 0;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
m_serverPipeConnection.WriteBytes(buf);
|
|
||||||
bytesSent = buf.Length;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine(e.ToString());
|
|
||||||
}
|
|
||||||
//CSSSLogger.DbgLog("WinIPCChannel::Write - Bytes sent is {0}" +bytesSent);
|
|
||||||
return bytesSent;
|
|
||||||
|
|
||||||
}
|
|
||||||
override internal void Close()
|
|
||||||
{
|
|
||||||
//CSSSLogger.DbgLog("WinIPCChannel Closed");
|
|
||||||
//clientSocket.Close();
|
|
||||||
m_serverPipeConnection.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,73 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Specialized;
|
|
||||||
using System.Text;
|
|
||||||
using System.Net;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
using Novell.CASA.GUI;
|
|
||||||
|
|
||||||
namespace Novell.CASA.communication
|
|
||||||
{
|
|
||||||
class CMWebClient
|
|
||||||
{
|
|
||||||
private WebClient m_wc = new WebClient();
|
|
||||||
private Config m_config;
|
|
||||||
|
|
||||||
public CMWebClient(Config config)
|
|
||||||
{
|
|
||||||
m_config = config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] GetData()
|
|
||||||
{
|
|
||||||
return GetData(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] GetData(byte[] baDataToSend)
|
|
||||||
{
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string sISSAddr = m_config.GetConfigSetting("ISS_Address", "http://localhost:2020");
|
|
||||||
byte[] responseData;
|
|
||||||
|
|
||||||
if (baDataToSend != null)
|
|
||||||
{
|
|
||||||
responseData = m_wc.UploadData(sISSAddr, "POST", baDataToSend);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
responseData = m_wc.DownloadData(sISSAddr);
|
|
||||||
}
|
|
||||||
|
|
||||||
//NameValueCollection form = new NameValueCollection();
|
|
||||||
//form.Add("MyName", "MyValue");
|
|
||||||
//byte[] responseData = m_wc.UploadValues("http://buydotcom:8080/auction/innerweb.jsp", form);
|
|
||||||
return responseData;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.ToString();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
//byte[] new data = m_wc.UploadData("http://www.novell.com", "POST", responseData);
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Stream s = m_wc.OpenRead("http://buydotcom:8080/auction/innerweb.jsp");
|
|
||||||
StreamReader sr = new StreamReader(s);
|
|
||||||
string line = sr.ReadLine();
|
|
||||||
while (line != null)
|
|
||||||
{
|
|
||||||
Console.WriteLine(line);
|
|
||||||
line = sr.ReadLine();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,262 +0,0 @@
|
|||||||
/***********************************************************************
|
|
||||||
*
|
|
||||||
* 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.Text;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
using Novell.CASA.MiCasa.Communication.Server;
|
|
||||||
using Novell.CASA.GUI;
|
|
||||||
|
|
||||||
namespace casa.verbs
|
|
||||||
{
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This class is implementation of OpenSecretStore call.
|
|
||||||
* There will be one instance existing for every call made by the client.
|
|
||||||
*/
|
|
||||||
|
|
||||||
internal class SelectCard : SSVerb
|
|
||||||
{
|
|
||||||
ushort msgId = 0;
|
|
||||||
uint inMsgLen = 0;
|
|
||||||
uint outMsgLen = 0;
|
|
||||||
uint ssVersion = 0;
|
|
||||||
uint ssNameLen = 0;
|
|
||||||
private string ssName; //Name of SecretStore to open
|
|
||||||
private byte[] inBuf;
|
|
||||||
|
|
||||||
private byte[] outBuf;
|
|
||||||
int retCode = 0;
|
|
||||||
|
|
||||||
private static int MAX_SS_NAME_LEN = 256;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This method sets the class member with the byte array received.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public void SetMessageContent(byte[] ipcBytes)
|
|
||||||
{
|
|
||||||
inBuf = ipcBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This method does the actual implementation of OpenSecretStore
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
public byte[] ProcessRequest()
|
|
||||||
{
|
|
||||||
/* If an exception occurs in message format decoding,
|
|
||||||
* it is handled by AppHandler
|
|
||||||
*/
|
|
||||||
string sCardSelected = null;
|
|
||||||
byte[] baToken = null;
|
|
||||||
|
|
||||||
|
|
||||||
//parse incoming data
|
|
||||||
uint iLenIssuerUri = 0;
|
|
||||||
uint iLenRecipientUrl = 0;
|
|
||||||
uint iLenRequiredClaims = 0;
|
|
||||||
uint iLenOptionalClaims = 0;
|
|
||||||
uint iLenTokenType = 0;
|
|
||||||
uint iLenPolicy = 0;
|
|
||||||
|
|
||||||
// get issuer
|
|
||||||
string sIssueUri = null;
|
|
||||||
iLenIssuerUri = BitConverter.ToUInt32(inBuf, 6);
|
|
||||||
if (iLenIssuerUri > 0)
|
|
||||||
{
|
|
||||||
byte[] baIssuerUri = new Byte[iLenIssuerUri];
|
|
||||||
Array.Copy(inBuf, 10, baIssuerUri, 0, iLenIssuerUri);
|
|
||||||
sIssueUri = Encoding.Unicode.GetString(baIssuerUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
string sRecipientUrl = null;
|
|
||||||
iLenRecipientUrl = BitConverter.ToUInt32(inBuf, 6 + (4 + (int)iLenIssuerUri));
|
|
||||||
if (iLenRecipientUrl > 0)
|
|
||||||
{
|
|
||||||
byte[] baRecipentUrl = new byte[iLenRecipientUrl];
|
|
||||||
Array.Copy(inBuf, 10 + (4 + iLenIssuerUri), baRecipentUrl, 0, iLenRecipientUrl);
|
|
||||||
sRecipientUrl = Encoding.Unicode.GetString(baRecipentUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// get requested claims
|
|
||||||
string sClaims = null;
|
|
||||||
iLenRequiredClaims = BitConverter.ToUInt32(inBuf, 6 + (4 + (int)iLenIssuerUri) + (4 + (int)iLenRecipientUrl));
|
|
||||||
if (iLenRequiredClaims > 0)
|
|
||||||
{
|
|
||||||
byte[] baRequiredClaims = new byte[iLenRequiredClaims];
|
|
||||||
Array.Copy(inBuf, 10 + (4 + iLenIssuerUri) + (4 + iLenRecipientUrl), baRequiredClaims, 0, iLenRequiredClaims);
|
|
||||||
sClaims = Encoding.Unicode.GetString(baRequiredClaims);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get optional claims
|
|
||||||
string sOptClaims = null;
|
|
||||||
iLenOptionalClaims = BitConverter.ToUInt32(inBuf,
|
|
||||||
6 +
|
|
||||||
(4 + (int)iLenIssuerUri) +
|
|
||||||
(4 + (int)iLenRecipientUrl) +
|
|
||||||
(4 + (int)iLenRequiredClaims));
|
|
||||||
|
|
||||||
if (iLenOptionalClaims > 0)
|
|
||||||
{
|
|
||||||
byte[] baOptClaims = new byte[iLenOptionalClaims];
|
|
||||||
Array.Copy(inBuf, 10 + (4 + iLenIssuerUri) + (4 + iLenRecipientUrl) + (4 + iLenRequiredClaims), baOptClaims, 0, iLenOptionalClaims);
|
|
||||||
sOptClaims = Encoding.Unicode.GetString(baOptClaims);
|
|
||||||
}
|
|
||||||
|
|
||||||
string sTokenType = null;
|
|
||||||
iLenTokenType = BitConverter.ToUInt32(inBuf,
|
|
||||||
6 +
|
|
||||||
(4 + (int)iLenIssuerUri) +
|
|
||||||
(4 + (int)iLenRecipientUrl) +
|
|
||||||
(4 + (int)iLenRequiredClaims) +
|
|
||||||
(4 + (int)iLenOptionalClaims));
|
|
||||||
|
|
||||||
if (iLenTokenType > 0)
|
|
||||||
{
|
|
||||||
byte[] baTokenType = new byte[iLenTokenType];
|
|
||||||
Array.Copy(inBuf,
|
|
||||||
10 + (4 + iLenIssuerUri) + (4 + iLenRecipientUrl) + (4 + iLenRequiredClaims) + (4 + iLenOptionalClaims),
|
|
||||||
baTokenType,
|
|
||||||
0,
|
|
||||||
iLenTokenType);
|
|
||||||
sTokenType = Encoding.Unicode.GetString(baTokenType);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
string sPolicy = null;
|
|
||||||
iLenPolicy = BitConverter.ToUInt32(inBuf,
|
|
||||||
6 +
|
|
||||||
(4 + (int)iLenIssuerUri) +
|
|
||||||
(4 + (int)iLenRecipientUrl) +
|
|
||||||
(4 + (int)iLenRequiredClaims) +
|
|
||||||
(4 + (int)iLenOptionalClaims) +
|
|
||||||
(4 + (int)iLenTokenType));
|
|
||||||
|
|
||||||
if (iLenPolicy > 0)
|
|
||||||
{
|
|
||||||
byte[] baPolicy = new byte[iLenPolicy];
|
|
||||||
Array.Copy(inBuf,
|
|
||||||
10 + (4 + iLenIssuerUri) + (4 + iLenRecipientUrl) + (4 + iLenRequiredClaims) + (4 + iLenOptionalClaims) + (4 + iLenTokenType),
|
|
||||||
baPolicy,
|
|
||||||
0,
|
|
||||||
iLenPolicy);
|
|
||||||
sPolicy = Encoding.Unicode.GetString(baPolicy);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (true)
|
|
||||||
{
|
|
||||||
// display Card Selector
|
|
||||||
CardSelector cs = new CardSelector();
|
|
||||||
//sCardSelected = cs.DisplaySelector();
|
|
||||||
baToken = cs.GetToken();
|
|
||||||
|
|
||||||
retCode = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
msgId = BitConverter.ToUInt16(inBuf, 0);
|
|
||||||
inMsgLen = BitConverter.ToUInt32(inBuf, 2);
|
|
||||||
|
|
||||||
if (inMsgLen != inBuf.Length)
|
|
||||||
throw new FormatException(" MsgLen sent does not match the length of the message received.");
|
|
||||||
|
|
||||||
ssVersion = BitConverter.ToUInt32(inBuf, 6);
|
|
||||||
ssNameLen = BitConverter.ToUInt32(inBuf, 10);
|
|
||||||
|
|
||||||
if (ssNameLen > MAX_SS_NAME_LEN)
|
|
||||||
throw new FormatException(" SecretStore Name length exceeds length allowed");
|
|
||||||
|
|
||||||
byte[] tempArr = new byte[ssNameLen];
|
|
||||||
Array.Copy(inBuf, 14, tempArr, 0, ssNameLen);
|
|
||||||
ssName = Encoding.UTF8.GetString(tempArr);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
msgId = 0;
|
|
||||||
outMsgLen = 14;
|
|
||||||
if (baToken.Length > 0)
|
|
||||||
{
|
|
||||||
outBuf = new byte[14 + baToken.Length];
|
|
||||||
outMsgLen = 14 + (uint)baToken.Length;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
outBuf = new byte[14];
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] t = new byte[10];
|
|
||||||
|
|
||||||
t = BitConverter.GetBytes((ushort)msgId);
|
|
||||||
Array.Copy(t,0,outBuf,0,2);
|
|
||||||
|
|
||||||
t = BitConverter.GetBytes((uint)outMsgLen);
|
|
||||||
Array.Copy(t,0,outBuf,2,4);
|
|
||||||
|
|
||||||
t = BitConverter.GetBytes((uint)ssVersion);
|
|
||||||
Array.Copy(t,0,outBuf,6,4);
|
|
||||||
|
|
||||||
t = BitConverter.GetBytes(retCode);
|
|
||||||
Array.Copy(t,0,outBuf,10,4);
|
|
||||||
|
|
||||||
// copy card selected if there is one
|
|
||||||
//if (sCardSelected != null)
|
|
||||||
//{
|
|
||||||
// byte[] baCard = Encoding.ASCII.GetBytes(sCardSelected);
|
|
||||||
// Array.Copy(baCard, 0, outBuf, 14, baCard.Length);
|
|
||||||
//}
|
|
||||||
if (baToken.Length > 0)
|
|
||||||
{
|
|
||||||
Array.Copy(baToken, 0, outBuf, 14, baToken.Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
|
|
||||||
throw new FormatException("Unable to form the response " + e.ToString());
|
|
||||||
}
|
|
||||||
return outBuf;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Gives the name of operation performed. Will be used in case
|
|
||||||
* of error.
|
|
||||||
*/
|
|
||||||
public string GetVerbName()
|
|
||||||
{
|
|
||||||
return this.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,174 +0,0 @@
|
|||||||
/***********************************************************************
|
|
||||||
*
|
|
||||||
* 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.Threading;
|
|
||||||
using System.Web;
|
|
||||||
using System.IO;
|
|
||||||
using System.Configuration;
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
using AppModule.InterProcessComm;
|
|
||||||
using AppModule.NamedPipes;
|
|
||||||
|
|
||||||
using Novell.CASA.MiCasa.Communication.Server;
|
|
||||||
|
|
||||||
namespace Novell.CASA.MiCasa.Communication.win
|
|
||||||
{
|
|
||||||
|
|
||||||
public class PipeManager : IChannelManager {
|
|
||||||
|
|
||||||
public Hashtable Pipes;
|
|
||||||
|
|
||||||
private uint NumberPipes = 16;
|
|
||||||
private uint OutBuffer = 65536; //512;
|
|
||||||
private uint InBuffer = 65536; //512;
|
|
||||||
private const int MAX_READ_BYTES = 15000;
|
|
||||||
private bool _listen = true;
|
|
||||||
public bool Listen {
|
|
||||||
get {
|
|
||||||
return _listen;
|
|
||||||
}
|
|
||||||
set {
|
|
||||||
_listen=value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private int numChannels = 0;
|
|
||||||
private Hashtable _pipes = new Hashtable();
|
|
||||||
|
|
||||||
//private Thread MainThread;
|
|
||||||
private string CASA_RPC_PIPE = "\\\\.\\PIPE\\CASA_MANAGER";
|
|
||||||
private ManualResetEvent Mre;
|
|
||||||
private const int PIPE_MAX_STUFFED_TIME = 5000;
|
|
||||||
|
|
||||||
public object SyncRoot = new object();
|
|
||||||
|
|
||||||
public void Initialize() {
|
|
||||||
Pipes = Hashtable.Synchronized(_pipes);
|
|
||||||
Mre = new ManualResetEvent(false);
|
|
||||||
/*
|
|
||||||
MainThread = new Thread(new ThreadStart(Start));
|
|
||||||
MainThread.IsBackground = true;
|
|
||||||
MainThread.Name = "Main Pipe Thread";
|
|
||||||
MainThread.Start();
|
|
||||||
*/
|
|
||||||
Thread.Sleep(1000);
|
|
||||||
}
|
|
||||||
public string HandleRequest(string request) {
|
|
||||||
string returnVal;
|
|
||||||
|
|
||||||
//Form1.ActivityRef.AppendText(request + Environment.NewLine);
|
|
||||||
returnVal = "Response to: " + request;
|
|
||||||
|
|
||||||
return returnVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Start() {
|
|
||||||
try {
|
|
||||||
while (_listen) {
|
|
||||||
int[] keys = new int[Pipes.Keys.Count];
|
|
||||||
Pipes.Keys.CopyTo(keys,0);
|
|
||||||
foreach (int key in keys) {
|
|
||||||
ServerNamedPipe serverPipe = (ServerNamedPipe)Pipes[key];
|
|
||||||
if (serverPipe != null && DateTime.Now.Subtract(serverPipe.LastAction).Milliseconds > PIPE_MAX_STUFFED_TIME && serverPipe.PipeConnection.GetState() != InterProcessConnectionState.WaitingForClient) {
|
|
||||||
serverPipe.Listen = false;
|
|
||||||
serverPipe.PipeThread.Abort();
|
|
||||||
RemoveServerChannel(serverPipe.PipeConnection.NativeHandle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (numChannels <= NumberPipes) {
|
|
||||||
ServerNamedPipe pipe = new ServerNamedPipe(CASA_RPC_PIPE, OutBuffer, InBuffer, MAX_READ_BYTES);
|
|
||||||
|
|
||||||
// register all verbs with this pipe
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
pipe.Connect();
|
|
||||||
pipe.LastAction = DateTime.Now;
|
|
||||||
System.Threading.Interlocked.Increment(ref numChannels);
|
|
||||||
pipe.Start();
|
|
||||||
Pipes.Add(pipe.PipeConnection.NativeHandle, pipe);
|
|
||||||
}
|
|
||||||
catch (InterProcessIOException) {
|
|
||||||
RemoveServerChannel(pipe.PipeConnection.NativeHandle);
|
|
||||||
pipe.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Mre.Reset();
|
|
||||||
Mre.WaitOne(1000, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Exception starting server: "+e.ToString());
|
|
||||||
// Log exception
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void Stop() {
|
|
||||||
_listen = false;
|
|
||||||
Mre.Set();
|
|
||||||
try {
|
|
||||||
int[] keys = new int[Pipes.Keys.Count];
|
|
||||||
Pipes.Keys.CopyTo(keys,0);
|
|
||||||
foreach (int key in keys) {
|
|
||||||
((ServerNamedPipe)Pipes[key]).Listen = false;
|
|
||||||
}
|
|
||||||
int i = numChannels * 3;
|
|
||||||
for (int j = 0; j < i; j++) {
|
|
||||||
StopServerPipe();
|
|
||||||
}
|
|
||||||
Pipes.Clear();
|
|
||||||
Mre.Close();
|
|
||||||
Mre = null;
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
// Log exception
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void WakeUp() {
|
|
||||||
if (Mre != null) {
|
|
||||||
Mre.Set();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void StopServerPipe() {
|
|
||||||
try {
|
|
||||||
ClientPipeConnection pipe = new ClientPipeConnection(CASA_RPC_PIPE);
|
|
||||||
if (pipe.TryConnect()) {
|
|
||||||
pipe.Close();
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// Log exception
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RemoveServerChannel(object param) {
|
|
||||||
int handle = (int)param;
|
|
||||||
System.Threading.Interlocked.Decrement(ref numChannels);
|
|
||||||
Pipes.Remove(handle);
|
|
||||||
this.WakeUp();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,132 +0,0 @@
|
|||||||
/***********************************************************************
|
|
||||||
*
|
|
||||||
* 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.Threading;
|
|
||||||
using System.IO;
|
|
||||||
|
|
||||||
using AppModule.InterProcessComm;
|
|
||||||
using AppModule.NamedPipes;
|
|
||||||
|
|
||||||
using Novell.CASA.MiCasa.Communication.Server;
|
|
||||||
|
|
||||||
|
|
||||||
namespace Novell.CASA.MiCasa.Communication.win
|
|
||||||
{
|
|
||||||
|
|
||||||
public sealed class ServerNamedPipe : IDisposable {
|
|
||||||
internal Thread PipeThread;
|
|
||||||
internal ServerPipeConnection PipeConnection;
|
|
||||||
internal bool Listen = true;
|
|
||||||
internal DateTime LastAction;
|
|
||||||
private bool disposed = false;
|
|
||||||
|
|
||||||
private void PipeListener() {
|
|
||||||
CheckIfDisposed();
|
|
||||||
try {
|
|
||||||
Listen = true;
|
|
||||||
while (Listen) {
|
|
||||||
LastAction = DateTime.Now;
|
|
||||||
|
|
||||||
// Service Client (new code)
|
|
||||||
IPCChannel ipcChannel = IPCChannel.Create(PipeConnection);
|
|
||||||
AppHandler appHandler = new AppHandler(ipcChannel);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
int retVal = appHandler.ServiceApp(new RequestParser());
|
|
||||||
}
|
|
||||||
catch(Exception)
|
|
||||||
{
|
|
||||||
ipcChannel.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
LastAction = DateTime.Now;
|
|
||||||
PipeConnection.Disconnect();
|
|
||||||
if (Listen) {
|
|
||||||
Connect();
|
|
||||||
}
|
|
||||||
WinCommunication.PipeManager.WakeUp();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (System.Threading.ThreadAbortException) { }
|
|
||||||
catch (System.Threading.ThreadStateException) { }
|
|
||||||
catch (Exception) {
|
|
||||||
// Log exception
|
|
||||||
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
this.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
internal void Connect() {
|
|
||||||
CheckIfDisposed();
|
|
||||||
PipeConnection.Connect();
|
|
||||||
}
|
|
||||||
internal void Close() {
|
|
||||||
CheckIfDisposed();
|
|
||||||
this.Listen = false;
|
|
||||||
WinCommunication.PipeManager.RemoveServerChannel(this.PipeConnection.NativeHandle);
|
|
||||||
this.Dispose();
|
|
||||||
}
|
|
||||||
internal void Start() {
|
|
||||||
CheckIfDisposed();
|
|
||||||
PipeThread.Start();
|
|
||||||
}
|
|
||||||
private void CheckIfDisposed() {
|
|
||||||
if(this.disposed) {
|
|
||||||
throw new ObjectDisposedException("ServerNamedPipe");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void Dispose() {
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
private void Dispose(bool disposing) {
|
|
||||||
if(!this.disposed) {
|
|
||||||
PipeConnection.Dispose();
|
|
||||||
if (PipeThread != null) {
|
|
||||||
try {
|
|
||||||
PipeThread.Abort();
|
|
||||||
}
|
|
||||||
catch (System.Threading.ThreadAbortException) { }
|
|
||||||
catch (System.Threading.ThreadStateException) { }
|
|
||||||
catch (Exception) {
|
|
||||||
// Log exception
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
disposed = true;
|
|
||||||
}
|
|
||||||
~ServerNamedPipe() {
|
|
||||||
Dispose(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal ServerNamedPipe(string name, uint outBuffer, uint inBuffer, int maxReadBytes) {
|
|
||||||
PipeConnection = new ServerPipeConnection(name, outBuffer, inBuffer, maxReadBytes, false);
|
|
||||||
PipeThread = new Thread(new ThreadStart(PipeListener));
|
|
||||||
PipeThread.IsBackground = true;
|
|
||||||
PipeThread.Name = "Pipe Thread " + this.PipeConnection.NativeHandle.ToString();
|
|
||||||
LastAction = DateTime.Now;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user