Skip to content

Commit

Permalink
NFreeRDP: added connection dialog, updated rdpSettings bindings, fix …
Browse files Browse the repository at this point in the history
…calling convention
  • Loading branch information
awakecoding committed Sep 3, 2012
1 parent da2f7ce commit 4f3ad30
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 10 deletions.
14 changes: 11 additions & 3 deletions FreeRDP/Core/RDP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace FreeRDP
{
public unsafe class RDP
{
[DllImport("libfreerdp", CallingConvention=CallingConvention.Cdecl)]
[DllImport("libfreerdp", CallingConvention = CallingConvention.Cdecl)]
public static extern void freerdp_context_new(freerdp* instance);

[DllImport("libfreerdp", CallingConvention = CallingConvention.Cdecl)]
Expand Down Expand Up @@ -60,7 +60,9 @@ public unsafe class RDP

[DllImport("libfreerdp", CallingConvention = CallingConvention.Cdecl)]
public static extern void freerdp_input_send_extended_mouse_event(IntPtr input, UInt16 flags, UInt16 x, UInt16 y);


private static int winsock = -1;

public int Port { get { return (int) settings->port; } set { settings->port = (UInt32) value; } }
public int Width { get { return (int) settings->width; } set { settings->width = (UInt32) value; } }
public int Height { get { return (int) settings->height; } set { settings->height = (UInt32) value; } }
Expand Down Expand Up @@ -89,6 +91,9 @@ public unsafe class RDP

public RDP()
{
if (winsock == -1)
winsock = Tcp.WSAStartup();

handle = freerdp_new();

iUpdate = null;
Expand Down Expand Up @@ -131,7 +136,7 @@ private IntPtr GetNativeAnsiString(string str)
ASCIIEncoding strEncoder = new ASCIIEncoding();

int size = strEncoder.GetByteCount(str);
IntPtr pStr = Memory.Zalloc(size);
IntPtr pStr = Memory.Zalloc(size + 1);
byte[] buffer = strEncoder.GetBytes(str);
Marshal.Copy(buffer, 0, pStr, size);

Expand Down Expand Up @@ -175,6 +180,7 @@ bool PreConnect(freerdp* instance)
}

settings->rfxCodec = 1;
settings->rfxCodecOnly = 1;
settings->fastpathOutput = 1;
settings->colorDepth = 32;
settings->frameAcknowledge = 0;
Expand Down Expand Up @@ -223,11 +229,13 @@ public bool Disconnect()

private bool Authenticate(freerdp* instance, IntPtr username, IntPtr password, IntPtr domain)
{
Console.WriteLine("Authenticate");
return true;
}

private bool VerifyCertificate(freerdp* instance, IntPtr subject, IntPtr issuer, IntPtr fingerprint)
{
Console.WriteLine("VerifyCertificate");
return true;
}

Expand Down
16 changes: 16 additions & 0 deletions FreeRDP/Core/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public unsafe struct rdpSettings
[FieldOffset(28 * 8)] public UInt32 encryptionLevel;
[FieldOffset(29 * 8)] public int authentication;
[FieldOffset(30 * 8)] public UInt32 negotiationFlags;
[FieldOffset(31 * 8)] public int negotiateSecurity;

/* Connection Settings */
[FieldOffset(48 * 8)] public UInt32 port;
Expand All @@ -61,6 +62,16 @@ public unsafe struct rdpSettings
[FieldOffset(61 * 8)] public IntPtr passwordCookie;
[FieldOffset(62 * 8)] public IntPtr kerberosKDC;
[FieldOffset(63 * 8)] public IntPtr kerberosRealm;
[FieldOffset(64 * 8)] public int tsGateway;
[FieldOffset(65 * 8)] public IntPtr tsgHostname;
[FieldOffset(66 * 8)] public IntPtr tsgUsername;
[FieldOffset(67 * 8)] public IntPtr tsgPassword;
[FieldOffset(68 * 8)] public int local;
[FieldOffset(69 * 8)] public int authenticationOnly;
[FieldOffset(70 * 8)] public int fromStandardInput;
[FieldOffset(71 * 8)] public int sendConnectionPdu;
[FieldOffset(72 * 8)] public UInt32 preconnectionId;
[FieldOffset(73 * 8)] public IntPtr preconnectionBlob;

/* User Interface Parameters */
[FieldOffset(80 * 8)] public int softwareGdi;
Expand Down Expand Up @@ -151,6 +162,11 @@ public unsafe struct rdpSettings
[FieldOffset(283 * 8)] public UInt32 nsCodecId;
[FieldOffset(284 * 8)] public UInt32 rfxCodecMode;
[FieldOffset(285 * 8)] public int frameAcknowledge;
[FieldOffset(286 * 8)] public int jpegCodec;
[FieldOffset(287 * 8)] public UInt32 jpegCodecId;
[FieldOffset(288 * 8)] public UInt32 jpegQuality;
[FieldOffset(289 * 8)] public UInt32 v3CodecId;
[FieldOffset(290 * 8)] public int rfxCodecOnly;

/* Recording */
[FieldOffset(296 * 8)] public int dumpRfx;
Expand Down
22 changes: 22 additions & 0 deletions FreeRDP/Core/Update/PrimaryUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,27 +467,49 @@ public unsafe class PrimaryUpdate
private rdpUpdate* update;
private rdpPrimaryUpdate* primary;

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void DstBltDelegate(rdpContext* context, DstBltOrder* dstBlt);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void PatBltDelegate(rdpContext* context, PatBltOrder* patBlt);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void ScrBltDelegate(rdpContext* context, ScrBltOrder* scrBlt);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void OpaqueRectDelegate(rdpContext* context, OpaqueRectOrder* opaqueRect);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void DrawNineGridDelegate(rdpContext* context, DrawNineGridOrder* drawNineGrid);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void MultiDstBltDelegate(rdpContext* context, MultiDstBltOrder* multiDstBlt);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void MultiPatBltDelegate(rdpContext* context, MultiPatBltOrder* multiPatBlt);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void MultiScrBltDelegate(rdpContext* context, MultiScrBltOrder* multiScrBlt);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void MultiOpaqueRectDelegate(rdpContext* context, MultiOpaqueRectOrder* multiOpaqueRect);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void MultiDrawNineGridDelegate(rdpContext* context, MultiDrawNineGridOrder* multiDrawNineGrid);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void LineToDelegate(rdpContext* context, LineToOrder* lineTo);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void PolylineDelegate(rdpContext* context, PolylineOrder* polyline);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void MemBltDelegate(rdpContext* context, MemBltOrder* memBlt);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void Mem3BltDelegate(rdpContext* context, Mem3BltOrder* mem3Blt);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void SaveBitmapDelegate(rdpContext* context, SaveBitmapOrder* saveBitmap);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void GlyphIndexDelegate(rdpContext* context, GlyphIndexOrder* glyphIndex);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void FastIndexDelegate(rdpContext* context, FastIndexOrder* fastIndex);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void FastGlyphDelegate(rdpContext* context, FastGlyphOrder* fastGlyph);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void PolygonSCDelegate(rdpContext* context, PolygonSCOrder* polygonSC);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void PolygonCBDelegate(rdpContext* context, PolygonCBOrder* polygonCB);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void EllipseSCDelegate(rdpContext* context, EllipseSCOrder* ellipseSC);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void EllipseCBDelegate(rdpContext* context, EllipseCBOrder* ellipseCB);

private DstBltDelegate DstBlt;
Expand Down
10 changes: 10 additions & 0 deletions FreeRDP/Core/Update/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,28 @@ public unsafe class Update
private rdpContext* context;
private rdpUpdate* update;

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void BeginPaintDelegate(rdpContext* context);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void EndPaintDelegate(rdpContext* context);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void SetBoundsDelegate(rdpContext* context, rdpBounds* bounds);
delegate void SynchronizeDelegate(rdpContext* context);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void DesktopResizeDelegate(rdpContext* context);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void BitmapUpdateDelegate(rdpContext* context, BitmapUpdate* bitmap);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void PaletteDelegate(rdpContext* context, PaletteUpdate* palette);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void PlaySoundDelegate(rdpContext* context, PlaySoundUpdate* playSound);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void RefreshRectDelegate(rdpContext* context, byte count, IntPtr areas);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void SuppressOutputDelegate(rdpContext* context, byte allow, IntPtr area);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void SurfaceBitsDelegate(rdpContext* context, SurfaceBits* surfaceBits);

private BeginPaintDelegate BeginPaint;
Expand Down
1 change: 1 addition & 0 deletions FreeRDP/FreeRDP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<Compile Include="Core\Graphics\Graphics.cs" />
<Compile Include="Core\Input.cs" />
<Compile Include="Locale\Keyboard.cs" />
<Compile Include="Utils\Tcp.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
Expand Down
8 changes: 2 additions & 6 deletions FreeRDP/Utils/Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace FreeRDP
{
public unsafe class Memory
public unsafe static class Memory
{
[DllImport("libfreerdp", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr xmalloc(UIntPtr size);
Expand All @@ -35,11 +35,7 @@ public unsafe class Memory

[DllImport("libfreerdp", CallingConvention = CallingConvention.Cdecl)]
public static extern void xfree(IntPtr ptr);

public Memory()
{
}


public static IntPtr Malloc(int size)
{
UIntPtr size_t = new UIntPtr((ulong) size);
Expand Down
44 changes: 44 additions & 0 deletions FreeRDP/Utils/Tcp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Tcp Utils
*
* Copyright 2012 Marc-Andre Moreau <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using System;
using System.Runtime.InteropServices;

namespace FreeRDP
{
public unsafe static class Tcp
{
[DllImport("libfreerdp", CallingConvention = CallingConvention.Cdecl)]
public static extern int freerdp_wsa_startup();

[DllImport("libfreerdp", CallingConvention = CallingConvention.Cdecl)]
public static extern int freerdp_wsa_cleanup();

public static int WSAStartup()
{
return freerdp_wsa_startup();
}

public static int WSACleanup()
{
return freerdp_wsa_cleanup();
}
}
}

1 change: 0 additions & 1 deletion NFreeRDP/NFreeRDP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
<Compile Include="ConnectionDialog.Designer.cs">
<DependentUpon>ConnectionDialog.cs</DependentUpon>
</Compile>
<Compile Include="ConnectionDialogTest.cs" />
<Compile Include="ConnectionSettings.cs" />
<Compile Include="MainWindow.cs">
<SubType>Form</SubType>
Expand Down
2 changes: 2 additions & 0 deletions NFreeRDP/RdpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public void Connect(ConnectionSettings settings)
rdp.SetUpdateInterface(this);
rdp.SetPrimaryUpdateInterface(this);

this.settings = settings;

rdp.Connect(settings.hostname, settings.port,
settings.username, settings.domain, settings.password);

Expand Down

0 comments on commit 4f3ad30

Please sign in to comment.