11 #import <Foundation/Foundation.h>
13 #import <freerdp/gdi/gdi.h>
14 #import "ios_freerdp_ui.h"
16 #import "RDPSession.h"
19 #pragma mark Certificate authentication
21 static void ios_resize_display_buffer(mfInfo *mfi);
22 static BOOL ios_ui_authenticate_raw(freerdp *instance,
char **username,
char **password,
23 char **domain,
const char *title)
25 mfInfo *mfi = MFI_FROM_INSTANCE(instance);
26 NSMutableDictionary *params = [NSMutableDictionary
27 dictionaryWithObjectsAndKeys:(*username) ? [NSString stringWithUTF8String:*username] : @"",
29 (*password) ? [NSString stringWithUTF8String:*password] : @"",
31 (*domain) ? [NSString stringWithUTF8String:*domain] : @"",
33 [NSString stringWithUTF8String:freerdp_settings_get_string(
34 instance->context->settings,
35 FreeRDP_ServerHostname)],
39 [mfi->session performSelectorOnMainThread:@selector(sessionRequestsAuthenticationWithParams:)
43 [[mfi->session uiRequestCompleted] lock];
44 [[mfi->session uiRequestCompleted] wait];
45 [[mfi->session uiRequestCompleted] unlock];
47 if (![[params valueForKey:
@"result"] boolValue])
58 *username = _strdup([[params objectForKey:
@"username"] UTF8String]);
59 *password = _strdup([[params objectForKey:
@"password"] UTF8String]);
60 *domain = _strdup([[params objectForKey:
@"domain"] UTF8String]);
62 if (!(*username) || !(*password) || !(*domain))
73 BOOL ios_ui_authenticate(freerdp *instance,
char **username,
char **password,
char **domain)
75 return ios_ui_authenticate_raw(instance, username, password, domain,
"");
78 BOOL ios_ui_gw_authenticate(freerdp *instance,
char **username,
char **password,
char **domain)
80 return ios_ui_authenticate_raw(instance, username, password, domain,
"gateway");
83 DWORD ios_ui_verify_certificate_ex(freerdp *instance,
const char *host, UINT16 port,
84 const char *common_name,
const char *subject,
const char *issuer,
85 const char *fingerprint, DWORD flags)
88 if ([[NSUserDefaults standardUserDefaults] boolForKey:
@"security.accept_certificates"] == YES)
91 mfInfo *mfi = MFI_FROM_INSTANCE(instance);
92 NSMutableDictionary *params = [NSMutableDictionary
93 dictionaryWithObjectsAndKeys:(subject) ? [NSString stringWithUTF8String:subject] : @"",
95 (issuer) ? [NSString stringWithUTF8String:issuer] : @"",
97 (fingerprint) ? [NSString stringWithUTF8String:subject] : @"",
100 [mfi->session performSelectorOnMainThread:@selector(sessionVerifyCertificateWithParams:)
104 [[mfi->session uiRequestCompleted] lock];
105 [[mfi->session uiRequestCompleted] wait];
106 [[mfi->session uiRequestCompleted] unlock];
108 if (![[params valueForKey:
@"result"] boolValue])
117 DWORD ios_ui_verify_changed_certificate_ex(freerdp *instance,
const char *host, UINT16 port,
118 const char *common_name,
const char *subject,
119 const char *issuer,
const char *fingerprint,
120 const char *old_subject,
const char *old_issuer,
121 const char *old_fingerprint, DWORD flags)
123 return ios_ui_verify_certificate_ex(instance, host, port, common_name, subject, issuer,
128 #pragma mark Graphics updates
130 BOOL ios_ui_begin_paint(rdpContext *context)
132 rdpGdi *gdi = context->gdi;
133 gdi->primary->hdc->hwnd->invalid->null = TRUE;
137 BOOL ios_ui_end_paint(rdpContext *context)
139 mfInfo *mfi = MFI_FROM_INSTANCE(context->instance);
140 rdpGdi *gdi = context->gdi;
142 CGRectMake(gdi->primary->hdc->hwnd->invalid->x, gdi->primary->hdc->hwnd->invalid->y,
143 gdi->primary->hdc->hwnd->invalid->w, gdi->primary->hdc->hwnd->invalid->h);
145 if (!gdi->primary->hdc->hwnd->invalid->null)
146 [mfi->session performSelectorOnMainThread:@selector(setNeedsDisplayInRectAsValue:)
147 withObject:[NSValue valueWithCGRect:dirty_rect]
153 BOOL ios_ui_resize_window(rdpContext *context)
155 rdpSettings *settings;
158 if (!context || !context->settings)
161 settings = context->settings;
168 ios_resize_display_buffer(MFI_FROM_INSTANCE(context->instance));
173 #pragma mark Exported
175 static void ios_create_bitmap_context(mfInfo *mfi)
177 [mfi->session performSelectorOnMainThread:@selector(sessionBitmapContextWillChange)
180 rdpGdi *gdi = mfi->instance->context->gdi;
181 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
183 if (FreeRDPGetBytesPerPixel(gdi->dstFormat) == 2)
184 mfi->bitmap_context = CGBitmapContextCreate(
185 gdi->primary_buffer, gdi->width, gdi->height, 5, gdi->stride, colorSpace,
186 kCGBitmapByteOrder16Little | kCGImageAlphaNoneSkipFirst);
188 mfi->bitmap_context = CGBitmapContextCreate(
189 gdi->primary_buffer, gdi->width, gdi->height, 8, gdi->stride, colorSpace,
190 kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst);
192 CGColorSpaceRelease(colorSpace);
193 [mfi->session performSelectorOnMainThread:@selector(sessionBitmapContextDidChange)
198 void ios_allocate_display_buffer(mfInfo *mfi)
200 ios_create_bitmap_context(mfi);
203 void ios_resize_display_buffer(mfInfo *mfi)
206 CGContextRef old_context = mfi->bitmap_context;
207 mfi->bitmap_context = NULL;
208 CGContextRelease(old_context);
210 ios_create_bitmap_context(mfi);
FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.