FreeRDP
mfreerdp.c
1 
21 #include <freerdp/config.h>
22 
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <errno.h>
27 #include <pthread.h>
28 #include <signal.h>
29 #include <sys/time.h>
30 
31 #include <CoreGraphics/CGEvent.h>
32 
33 #include <winpr/crt.h>
34 #include <winpr/wtsapi.h>
35 #include <winpr/assert.h>
36 
37 #include <freerdp/freerdp.h>
38 #include <freerdp/constants.h>
39 #include <freerdp/channels/wtsvc.h>
40 #include <freerdp/channels/channels.h>
41 #include <freerdp/server/server-common.h>
42 
43 #include "mfreerdp.h"
44 #include "mf_peer.h"
45 
46 #include <freerdp/log.h>
47 #define TAG SERVER_TAG("mac")
48 
49 static void mf_server_main_loop(freerdp_listener* instance)
50 {
51  WINPR_ASSERT(instance);
52  WINPR_ASSERT(instance->GetEventHandles);
53  WINPR_ASSERT(instance->CheckFileDescriptor);
54 
55  while (1)
56  {
57  DWORD status;
58  HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
59  DWORD count = instance->GetEventHandles(instance, handles, ARRAYSIZE(handles));
60 
61  if (count == 0)
62  {
63  WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
64  break;
65  }
66 
67  status = WaitForMultipleObjects(count, handles, FALSE, INFINITE);
68  if (status == WAIT_FAILED)
69  {
70  WLog_ERR(TAG, "WaitForMultipleObjects failed");
71  break;
72  }
73 
74  if (instance->CheckFileDescriptor(instance) != TRUE)
75  {
76  break;
77  }
78  }
79 
80  instance->Close(instance);
81 }
82 
83 int main(int argc, char* argv[])
84 {
85  freerdp_server_warn_unmaintained(argc, argv);
86  mf_server_info info = { .key = "server.key", .cert = "server.crt" };
87 
88  freerdp_listener* instance;
89 
90  signal(SIGPIPE, SIG_IGN);
91 
92  WTSRegisterWtsApiFunctionTable(FreeRDP_InitWtsApi());
93 
94  if (!(instance = freerdp_listener_new()))
95  return 1;
96 
97  instance->info = &info;
98  instance->PeerAccepted = mf_peer_accepted;
99 
100  if (instance->Open(instance, NULL, 3389))
101  {
102  mf_server_main_loop(instance);
103  }
104 
105  freerdp_listener_free(instance);
106 
107  return 0;
108 }