mit hyphen
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
/***********************************************************************\
|
||||
* Virtuoso.Miranda.Plugins (Hyphen) *
|
||||
* Provides a managed wrapper for API of IM client Miranda. *
|
||||
* Copyright (C) 2006-2009 virtuoso *
|
||||
* deml.tomas@seznam.cz *
|
||||
* *
|
||||
* 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; either *
|
||||
* version 2.1 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
\***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Virtuoso.Miranda.Plugins.Native;
|
||||
using System.Threading;
|
||||
using System.Security;
|
||||
|
||||
namespace Virtuoso.Miranda.Plugins.Infrastructure.Protocols
|
||||
{
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
public static class AckBroadcaster
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private const string MS_PROTO_BROADCASTACK = "Proto/BroadcastAck";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
|
||||
private static ACKDATA BuildAckData(IntPtr pModuleName, AckType type, bool success, IntPtr contactHandle, IntPtr processHandle, IntPtr lParam)
|
||||
{
|
||||
ACKDATA ack = new ACKDATA(pModuleName, (int)type, success ? (int)AckResult.Success : (int)AckResult.Failure);
|
||||
ack.ContactHandle = contactHandle;
|
||||
ack.ProcessHandle = processHandle;
|
||||
ack.LParam = lParam;
|
||||
|
||||
return ack;
|
||||
}
|
||||
|
||||
private static unsafe int BroadcastAck(ACKDATA* ack)
|
||||
{
|
||||
return MirandaContext.Current.CallServiceUnsafe(MS_PROTO_BROADCASTACK, null, ack);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public static int BroadcastAck(string moduleName, AckType type, bool success, IntPtr contactHandle, IntPtr processHandle, IntPtr lParam)
|
||||
{
|
||||
UnmanagedStringHandle pModuleName = UnmanagedStringHandle.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
pModuleName = new UnmanagedStringHandle(moduleName, StringEncoding.Ansi);
|
||||
return BroadcastAck(pModuleName.IntPtr, type, success, contactHandle, processHandle, lParam);
|
||||
}
|
||||
finally
|
||||
{
|
||||
pModuleName.Free();
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe void BroadcastMessageAckAsync(IntPtr pModuleName, bool success, IntPtr contactHandle, int processCookie)
|
||||
{
|
||||
ACKDATA ack = BuildAckData(pModuleName, AckType.Message, success, contactHandle, (IntPtr)processCookie, IntPtr.Zero);
|
||||
ThreadPool.QueueUserWorkItem(delegate(object ackObject)
|
||||
{
|
||||
ACKDATA _ack = (ACKDATA)ackObject;
|
||||
BroadcastAck(&_ack);
|
||||
}, ack);
|
||||
}
|
||||
|
||||
public static unsafe int BroadcastAck(IntPtr pModuleName, AckType type, bool success, IntPtr contactHandle, IntPtr processHandle, IntPtr lParam)
|
||||
{
|
||||
ACKDATA ack = BuildAckData(pModuleName, type, success, contactHandle, processHandle, lParam);
|
||||
return BroadcastAck(&ack);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/***********************************************************************\
|
||||
* Virtuoso.Miranda.Plugins (Hyphen) *
|
||||
* Provides a managed wrapper for API of IM client Miranda. *
|
||||
* Copyright (C) 2006-2009 virtuoso *
|
||||
* deml.tomas@seznam.cz *
|
||||
* *
|
||||
* 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; either *
|
||||
* version 2.1 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
\***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Virtuoso.Miranda.Plugins.Infrastructure.Protocols
|
||||
{
|
||||
public enum AckType : int
|
||||
{
|
||||
Message = 0,
|
||||
Url = 1,
|
||||
File = 2,
|
||||
Chat = 3,
|
||||
AwayMessage = 4,
|
||||
AuthorizationRequest = 5,
|
||||
Added = 6,
|
||||
GetInfo = 7,
|
||||
SetInfo = 8,
|
||||
Login = 9,
|
||||
Search = 10,
|
||||
NewUser = 11,
|
||||
Status = 12,
|
||||
Contacts = 13, //send/recv of contacts
|
||||
Avatar = 14, //send/recv of avatars from a protocol
|
||||
}
|
||||
|
||||
public enum AckResult : int
|
||||
{
|
||||
Success = 0,
|
||||
Failure = 1,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/***********************************************************************\
|
||||
* Virtuoso.Miranda.Plugins (Hyphen) *
|
||||
* Provides a managed wrapper for API of IM client Miranda. *
|
||||
* Copyright (C) 2006-2009 virtuoso *
|
||||
* deml.tomas@seznam.cz *
|
||||
* *
|
||||
* 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; either *
|
||||
* version 2.1 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
\***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Virtuoso.Miranda.Plugins.Native;
|
||||
|
||||
namespace Virtuoso.Miranda.Plugins.Infrastructure.Protocols
|
||||
{
|
||||
public sealed class AckEventArgs : MirandaEventArgs
|
||||
{
|
||||
#region Properties
|
||||
|
||||
private Protocol protocol;
|
||||
public Protocol Protocol
|
||||
{
|
||||
get { return protocol; }
|
||||
}
|
||||
|
||||
private ContactInfo contact;
|
||||
public ContactInfo Contact
|
||||
{
|
||||
get { return contact; }
|
||||
}
|
||||
|
||||
private AckType type;
|
||||
public AckType Type
|
||||
{
|
||||
get { return type; }
|
||||
}
|
||||
|
||||
private AckResult result;
|
||||
public AckResult Result
|
||||
{
|
||||
get { return result; }
|
||||
}
|
||||
|
||||
private IntPtr processHandle;
|
||||
public IntPtr ProcessHandle
|
||||
{
|
||||
get { return processHandle; }
|
||||
}
|
||||
|
||||
private IntPtr lParam;
|
||||
public IntPtr LParam
|
||||
{
|
||||
get { return lParam; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region .ctors
|
||||
|
||||
public AckEventArgs() { }
|
||||
|
||||
internal unsafe static AckEventArgs FromACKDATA(IntPtr pAckData)
|
||||
{
|
||||
if (pAckData == IntPtr.Zero)
|
||||
throw new ArgumentNullException("pAckData");
|
||||
|
||||
ACKDATA ackData = *(ACKDATA*)pAckData.ToPointer();
|
||||
AckEventArgs ackArgs = new AckEventArgs();
|
||||
|
||||
ackArgs.contact = ContactInfo.FromHandle(ackData.ContactHandle);
|
||||
ackArgs.lParam = ackData.LParam;
|
||||
ackArgs.processHandle = ackData.ProcessHandle;
|
||||
ackArgs.result = (AckResult)ackData.Result;
|
||||
ackArgs.type = (AckType)ackData.Type;
|
||||
|
||||
if (ackData.ModuleName != IntPtr.Zero)
|
||||
ackArgs.protocol = MirandaContext.Current.Protocols[Translate.ToString(ackData.ModuleName, StringEncoding.Ansi)];
|
||||
|
||||
return ackArgs;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/***********************************************************************\
|
||||
* Virtuoso.Miranda.Plugins (Hyphen) *
|
||||
* Provides a managed wrapper for API of IM client Miranda. *
|
||||
* Copyright (C) 2006-2009 virtuoso *
|
||||
* deml.tomas@seznam.cz *
|
||||
* *
|
||||
* 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; either *
|
||||
* version 2.1 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
\***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Virtuoso.Miranda.Plugins.Infrastructure.Protocols
|
||||
{
|
||||
public static class AckRouter
|
||||
{
|
||||
#region Constants
|
||||
|
||||
/// <summary>
|
||||
/// Call the next service in the chain for this send operation.
|
||||
/// wParam=wParam
|
||||
/// lParam=lParam
|
||||
/// The return value should be returned immediately
|
||||
/// wParam and lParam should be passed as the parameters that your service was
|
||||
/// called with. wParam must remain untouched but lParam is a CCSDATA structure
|
||||
/// that can be copied and modified if needed.
|
||||
/// Typically, the last line of any chaining protocol function is
|
||||
/// return CallService(MS_PROTO_CHAINSEND,wParam,lParam);
|
||||
/// </summary>
|
||||
private const string MS_PROTO_CHAINSEND = "Proto/ChainSend";
|
||||
|
||||
/// <summary>
|
||||
/// Call the next service in the chain for this receive operation
|
||||
/// wParam=wParam
|
||||
/// lParam=lParam
|
||||
/// The return value should be returned immediately
|
||||
/// wParam and lParam should be passed as the parameters that your service was
|
||||
/// called with. wParam must remain untouched but lParam is a CCSDATA structure
|
||||
/// that can be copied and modified if needed.
|
||||
/// When being initiated by the network-access protocol module, wParam should be
|
||||
/// zero.
|
||||
/// Thread safety: ms_proto_chainrecv is completely thread safe since 0.1.2.0
|
||||
/// Calls to it are translated to the main thread and passed on from there. The
|
||||
/// function will not return until all callees have returned, irrepective of
|
||||
/// differences between threads the functions are in.
|
||||
/// </summary>
|
||||
private const string MS_PROTO_CHAINRECV = "Proto/ChainRecv";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
|
||||
private const string ME_PROTO_ACK = "Proto/Ack";
|
||||
private static MirandaEventHandler<AckEventArgs> AckReceivedEventHandler;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
public static event MirandaEventHandler<AckEventArgs> AckReceived
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||
add
|
||||
{
|
||||
LazyEventBinder.AttachDelegate<MirandaEventHandler<AckEventArgs>>(ref AckReceivedEventHandler, value);
|
||||
LazyEventBinder.HookMirandaEvent(ME_PROTO_ACK,
|
||||
delegate(UIntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
AckEventArgs e = AckEventArgs.FromACKDATA(lParam);
|
||||
|
||||
EventPublisher.InvokeChainCancelable<AckEventArgs>(AckReceivedEventHandler, null, e);
|
||||
return (int)CallbackResult.Success;
|
||||
});
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.Synchronized)]
|
||||
remove
|
||||
{
|
||||
LazyEventBinder.DetachDelegate<MirandaEventHandler<AckEventArgs>>(ref AckReceivedEventHandler, value);
|
||||
LazyEventBinder.UnhookMirandaEvent(ME_PROTO_ACK, AckReceivedEventHandler);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public static int ChainSend(ContactChainData chainData)
|
||||
{
|
||||
if (chainData == null)
|
||||
throw new ArgumentNullException("chainData");
|
||||
|
||||
return ChainSend(chainData.WParam, chainData.CcsDataPtr);
|
||||
}
|
||||
|
||||
public static int ChainSend(UIntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
return MirandaContext.Current.CallService(MS_PROTO_CHAINSEND, wParam, lParam);
|
||||
}
|
||||
|
||||
public static int ChainReceive(ContactChainData chainData)
|
||||
{
|
||||
if (chainData == null)
|
||||
throw new ArgumentNullException("chainData");
|
||||
|
||||
return ChainReceive(chainData.WParam, chainData.CcsDataPtr);
|
||||
}
|
||||
|
||||
public static int ChainReceive(UIntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
return MirandaContext.Current.CallService(MS_PROTO_CHAINRECV, wParam, lParam);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/***********************************************************************\
|
||||
* Virtuoso.Miranda.Plugins (Hyphen) *
|
||||
* Provides a managed wrapper for API of IM client Miranda. *
|
||||
* Copyright (C) 2006-2009 virtuoso *
|
||||
* deml.tomas@seznam.cz *
|
||||
* *
|
||||
* 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; either *
|
||||
* version 2.1 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
\***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Virtuoso.Miranda.Plugins.Native;
|
||||
|
||||
namespace Virtuoso.Miranda.Plugins.Infrastructure.Protocols
|
||||
{
|
||||
public sealed class ContactChainData
|
||||
{
|
||||
#region .ctors
|
||||
|
||||
internal unsafe ContactChainData(IntPtr pCcsData)
|
||||
{
|
||||
if (pCcsData == IntPtr.Zero)
|
||||
throw new ArgumentNullException("pCssData");
|
||||
|
||||
this.ccsDataPtr = pCcsData;
|
||||
|
||||
CCSDATA ccsData = *(CCSDATA*)pCcsData.ToPointer();
|
||||
this.contactInfo = ContactInfo.FromHandle(ccsData.ContactHandle);
|
||||
this.wParam = ccsData.WParam;
|
||||
this.lParam = ccsData.LParam;
|
||||
this.serviceName = Translate.ToString(ccsData.ServiceNamePtr, StringEncoding.Ansi);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
private ContactInfo contactInfo;
|
||||
public ContactInfo ContactInfo
|
||||
{
|
||||
get { return contactInfo; }
|
||||
}
|
||||
|
||||
private string serviceName;
|
||||
public string ServiceName
|
||||
{
|
||||
get { return serviceName; }
|
||||
}
|
||||
|
||||
private UIntPtr wParam;
|
||||
[CLSCompliant(false)]
|
||||
public UIntPtr WParam
|
||||
{
|
||||
get { return wParam; }
|
||||
}
|
||||
|
||||
private IntPtr lParam;
|
||||
public IntPtr LParam
|
||||
{
|
||||
get { return lParam; }
|
||||
}
|
||||
|
||||
private IntPtr ccsDataPtr;
|
||||
internal IntPtr CcsDataPtr
|
||||
{
|
||||
get { return ccsDataPtr; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public string GetLParamAsString(StringEncoding encoding)
|
||||
{
|
||||
return Translate.ToString(LParam, encoding);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/***********************************************************************\
|
||||
* Virtuoso.Miranda.Plugins (Hyphen) *
|
||||
* Provides a managed wrapper for API of IM client Miranda. *
|
||||
* Copyright (C) 2006-2009 virtuoso *
|
||||
* deml.tomas@seznam.cz *
|
||||
* *
|
||||
* 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; either *
|
||||
* version 2.1 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* 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 *
|
||||
* Lesser General Public License for more details. *
|
||||
\***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Virtuoso.Miranda.Plugins.Native;
|
||||
using Virtuoso.Miranda.Plugins.Resources;
|
||||
using System.Runtime.InteropServices;
|
||||
using Virtuoso.Miranda.Plugins.Helpers;
|
||||
|
||||
namespace Virtuoso.Miranda.Plugins.Infrastructure.Protocols
|
||||
{
|
||||
public sealed class ManagedProtocol : Protocol
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private const string MS_PROTO_ADDTOCONTACT = "Proto/AddToContact";
|
||||
|
||||
private bool Registered;
|
||||
|
||||
#endregion
|
||||
|
||||
#region .ctors
|
||||
|
||||
internal ManagedProtocol(string name, ProtocolType type) : base(name, type) { }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
private PROTOCOLDESCRIPTOR nativeDescriptor;
|
||||
public PROTOCOLDESCRIPTOR NativeDescriptor
|
||||
{
|
||||
get { return nativeDescriptor; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
internal void Register()
|
||||
{
|
||||
if (Registered)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
PROTOCOLDESCRIPTOR descriptor = new PROTOCOLDESCRIPTOR(Name, Type);
|
||||
UnmanagedStructHandle<PROTOCOLDESCRIPTOR> nativeHandle = UnmanagedStructHandle<PROTOCOLDESCRIPTOR>.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
nativeHandle = new UnmanagedStructHandle<PROTOCOLDESCRIPTOR>(ref descriptor);
|
||||
int result = Context.CallService(MirandaServices.MS_PROTO_REGISTERMODULE, UIntPtr.Zero, nativeHandle.IntPtr);
|
||||
|
||||
if (result != 0)
|
||||
throw new MirandaException(String.Format(TextResources.ExceptionMsg_Formatable2_MirandaServiceReturnedFailure, result.ToString()));
|
||||
|
||||
this.nativeDescriptor = descriptor;
|
||||
Registered = true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
nativeHandle.Free();
|
||||
}
|
||||
}
|
||||
|
||||
internal void Unregister()
|
||||
{
|
||||
if (!Registered)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
// Currently, nothing else to do
|
||||
}
|
||||
|
||||
public void AddToContact(ContactInfo contact)
|
||||
{
|
||||
if (contact == null)
|
||||
throw new ArgumentNullException("contact");
|
||||
|
||||
AddToContact(contact.MirandaHandle);
|
||||
}
|
||||
|
||||
public void AddToContact(IntPtr contactHandle)
|
||||
{
|
||||
int result = Context.CallService(MS_PROTO_ADDTOCONTACT, contactHandle, NativeDescriptor.Name);
|
||||
|
||||
if (result != 0)
|
||||
throw new MirandaException(String.Format(TextResources.ExceptionMsg_Formatable2_MirandaServiceReturnedFailure, MS_PROTO_ADDTOCONTACT, result.ToString()));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user