major source structure and module name changes

This commit is contained in:
soochoi
2006-06-07 16:34:19 +00:00
parent 5c75241b4b
commit 1fa6f07e83
651 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
/***********************************************************************
*
* 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;
/* This class would have only static methods.
*/
namespace sscs.communication
{
class CommunicationFactory
{
/* Make the constructor private, to avoid instances of this
* class.
*/
private CommunicationFactory()
{
}
/* This method must check for platform and return
* an appropriate class. As of now, it assumes platform as Linux.
*/
public static Communication CreateCommunicationEndPoint()
{
#if LINUX
return( new UnixCommunication());
#endif
#if W32
return (new WinCommunication());
#endif
}
}
}

View File

@@ -0,0 +1,37 @@
/***********************************************************************
*
* 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;
/* This is an interface which would be implemented
* by UnixCommunication and WinCommunication.
*/
namespace sscs.communication
{
interface Communication
{
void StartCommunicationEndPoint();
void CloseCommunicationEndPoint();
}
}

View File

@@ -0,0 +1,62 @@
/***********************************************************************
*
* 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
using sscs.common;
namespace sscs.communication
{
abstract class IPCChannel
{
/* This must check for the platform and return an
* appropriate IPCChannel.
*/
#if LINUX
internal static IPCChannel Create(Socket socket)
{
if(( (int)Environment.OSVersion.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 UserIdentifier GetIPCChannelUserId();
abstract internal int Read(byte[] buf);
abstract internal byte[] Read();
abstract internal int Write(byte[] buf);
abstract internal void Close();
}
}

View File

@@ -0,0 +1,167 @@
/***********************************************************************
*
* 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;
using Mono.Unix;
using Mono.Unix.Native;
using System.IO;
using System.Text;
using System.Threading;
using sscs.common;
using sscs.constants;
namespace sscs.communication
{
/* Platform specific class which implements
* the 'Communication' interface.
*/
class UnixCommunication : Communication
{
private Socket listeningSocket;
private Socket connectedSocket;
private string socketFileName = "/tmp/.novellCASA";
private Mono.Unix.UnixEndPoint sockEndPoint;
private ManualResetEvent eventVar = null;
//Methods
internal UnixCommunication()
{
CSSSLogger.ExecutionTrace(this);
Syscall.umask(0);
if(File.Exists(socketFileName))
{
File.Delete(socketFileName);
}
listeningSocket = new Socket( AddressFamily.Unix,
SocketType.Stream,
ProtocolType.IP );
sockEndPoint = new Mono.Unix.UnixEndPoint(socketFileName);
eventVar = new ManualResetEvent(true);
}
~UnixCommunication()
{
CSSSLogger.ExecutionTrace(this);
eventVar.Close();
CloseCommunicationEndPoint();
}
// This code executes in the listening thread.
public void StartCommunicationEndPoint()
{
CSSSLogger.ExecutionTrace(this);
try
{
UnixFileSystemInfo sockFileInfo = new UnixFileInfo(socketFileName);
UnixUserInfo sockFileOwner = sockFileInfo.OwnerUser;
// check if ROOT is the owner of the file: /tmp/.novellCASA
if (sockFileOwner.UserId != 0)
{
File.Delete(socketFileName);
}
}
catch(Exception e)
{
CSSSLogger.ExpLog(e.ToString());
}
listeningSocket.Bind(sockEndPoint);
listeningSocket.Listen(50);
while(true)
{
try
{
eventVar.Reset();
listeningSocket.BeginAccept(new AsyncCallback(ListenCb),
listeningSocket);
eventVar.WaitOne();
}
catch(Exception e)
{
CSSSLogger.ExpLog(e.ToString());
throw e;
}
}
}
public void CloseCommunicationEndPoint()
{
CSSSLogger.ExecutionTrace(this);
listeningSocket.Close();
if(File.Exists( socketFileName ))
File.Delete(socketFileName);
}
// On receipt of a new client, this method is called.
private void ListenCb (IAsyncResult state)
{
try
{
CSSSLogger.ExecutionTrace(this);
connectedSocket = ((Socket)state.AsyncState).EndAccept (state);
eventVar.Set();
ServiceClient();
}
catch(Exception e)
{
/* All resources would have been cleaned up before reaching
* here.
*/
CSSSLogger.ExpLog(e.ToString());
}
/* End of thread function */
}
private void ServiceClient()
{
CSSSLogger.ExecutionTrace(this);
IPCChannel ipcChannel = IPCChannel.Create(connectedSocket);
AppHandler appHandler = new AppHandler(ipcChannel);
try
{
int retVal = appHandler.ServiceApp();
if( retVal != RetCodes.SUCCESS )
CSSSLogger.DbgLog("Servicing client failed.");
}
catch( Exception e )
{
CSSSLogger.ExpLog(e.ToString());
}
finally
{
ipcChannel.Close();
}
}
}
}

View File

@@ -0,0 +1,166 @@
/***********************************************************************
*
* 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;
using Mono.Unix;
using System.IO;
using System.Text;
using sscs.common;
using sscs.verbs;
using sscs.constants;
namespace sscs.communication
{
class UnixIPCChannel : IPCChannel
{
// Data
private Socket clientSocket;
private UnixUserIdentifier userId;
//Methods
internal UnixIPCChannel(Socket connectedSocket)
{
CSSSLogger.ExecutionTrace(this);
clientSocket = connectedSocket;
Mono.Unix.PeerCred cred;
cred = new Mono.Unix.PeerCred(connectedSocket);
userId = new UnixUserIdentifier(cred.UserID);
}
override internal UserIdentifier GetIPCChannelUserId()
{
CSSSLogger.ExecutionTrace(this);
return userId;
}
private UnixIPCChannel()
{
CSSSLogger.ExecutionTrace(this);
}
~UnixIPCChannel()
{
CSSSLogger.ExecutionTrace(this);
clientSocket.Close();
}
override internal int Read(byte[] buf)
{
return 0;
}
override internal byte[] Read()
{
CSSSLogger.ExecutionTrace(this);
int bytesRecvd = 0;
try
{
byte[] msgIdBytes = new byte[2];
bytesRecvd = clientSocket.Receive(msgIdBytes);
if( 0 == bytesRecvd )
{
return null;
}
if( bytesRecvd < 0 ) // IPC is fine and Client had some problem
{
throw new CommunicationException("Client has not sent data.");
}
byte[] msgLenBytes = new byte[4];
bytesRecvd = clientSocket.Receive(msgLenBytes);
if( 0 == bytesRecvd )
{
return null;
}
if( bytesRecvd < 0 ) // IPC is fine and Client had some problem
{
throw new CommunicationException("Client has not sent data.");
}
byte[] bufToReturn = null;
uint msgLen = BitConverter.ToUInt32(msgLenBytes,0);
if( msgLen > 6 )
{
byte[] buf = new byte[msgLen - 6];
bytesRecvd = clientSocket.Receive (buf);
CSSSLogger.DbgLog("In " + CSSSLogger.GetExecutionPath(this) + " Bytes received is " + bytesRecvd);
if( 0 == bytesRecvd )
{
return null;
}
if( bytesRecvd < 0 ) // IPC is fine and Client had some problem
{
throw new CommunicationException("Client has not sent data.");
}
bufToReturn = new byte[msgLen];
Array.Copy(msgIdBytes,bufToReturn,2);
Array.Copy(msgLenBytes,0,bufToReturn,2,4);
Array.Copy(buf,0,bufToReturn,6,buf.Length);
return bufToReturn;
}
else
{
bufToReturn = new byte[6];
Array.Copy(msgIdBytes,bufToReturn,2);
Array.Copy(msgLenBytes,0,bufToReturn,2,4);
return bufToReturn;
}
}
catch(CommunicationException e)
{
throw e;
}
catch(Exception e)
{
CSSSLogger.ExpLog(e.ToString());
throw new CommunicationException(e.ToString());
}
}
override internal int Write(byte[] buf)
{
try
{
CSSSLogger.ExecutionTrace(this);
int bytesSent = clientSocket.Send(buf);
CSSSLogger.DbgLog("In " + CSSSLogger.GetExecutionPath(this) + " - Bytes sent is " + bytesSent);
return bytesSent;
}
catch(Exception e)
{
CSSSLogger.ExpLog(e.ToString());
return -1;
}
}
override internal void Close()
{
CSSSLogger.ExecutionTrace(this);
clientSocket.Close();
}
}
}

View File

@@ -0,0 +1,61 @@
/***********************************************************************
*
* 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 sscs.common;
using sscs.constants;
using AppModule.InterProcessComm;
using AppModule.NamedPipes;
using sscs.communication.win;
namespace sscs.communication
{
/// <summary>
/// Summary description for WinCommunication.
/// </summary>
public class WinCommunication : 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();
}
}
}

View File

@@ -0,0 +1,126 @@
/***********************************************************************
*
* 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 sscs.communication.win;
using sscs.common;
using sscs.verbs;
using sscs.constants;
namespace sscs.communication
{
class WinIPCChannel : IPCChannel
{
// Data
private ServerPipeConnection m_serverPipeConnection;
private WinUserIdentifier userId = null;
//Methods
public WinIPCChannel(ServerPipeConnection serverPipeConnection)
{
m_serverPipeConnection = serverPipeConnection;
}
override internal UserIdentifier GetIPCChannelUserId()
{
CSSSLogger.DbgLog("In WinIPCChannel::GetIPCChannelUserId");
return userId;
}
private WinIPCChannel()
{
CSSSLogger.DbgLog("WinIPCChannel constructor must be called with a serverPipe");
}
~WinIPCChannel()
{
// Console.WriteLine("WinIPCChannel::~~WinIPCChannel");
}
override internal byte[] Read()
{
int localUserIDLow = 0;
int localUserIDHigh = 0;
string sSIDString = "";
byte[] incoming = null;
try
{
incoming = m_serverPipeConnection.ReadBytes();
// get local Userid and SID
m_serverPipeConnection.GetLocalUserID(ref localUserIDLow, ref localUserIDHigh, ref sSIDString);
if (localUserIDLow != 0 || localUserIDHigh !=0)
{
userId = new WinUserIdentifier(localUserIDLow, localUserIDHigh, sSIDString);
}
return incoming;
}
catch(Exception e)
{
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)
{
}
CSSSLogger.DbgLog("WinIPCChannel::Write - Bytes sent is {0}" +bytesSent);
return bytesSent;
}
override internal void Close()
{
CSSSLogger.DbgLog("WinIPCChannel Closed");
//clientSocket.Close();
m_serverPipeConnection.Close();
}
}
}

View File

@@ -0,0 +1,167 @@
/***********************************************************************
*
* 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;
namespace sscs.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 = 5000;
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\\SS_RPC_PIPE";
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);
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();
}
}
}

View File

@@ -0,0 +1,127 @@
/***********************************************************************
*
* 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;
namespace sscs.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();
}
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;
}
}
}