From 73364127d2066a0332b2c81d03fa41217d117cf5 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 8 Jul 2015 23:03:23 -0700 Subject: [PATCH] Fix pairing with GFE 2.4.5.57+ --- Limelight/Network/DiscoveryManager.m | 2 +- Limelight/Network/DiscoveryWorker.m | 3 ++- Limelight/Network/HttpManager.h | 1 + Limelight/Network/HttpManager.m | 14 ++++++++++++++ Limelight/Network/HttpRequest.h | 3 +++ Limelight/Network/HttpRequest.m | 9 +++++++++ Limelight/Network/PairManager.m | 3 ++- Limelight/Stream/StreamManager.m | 3 ++- .../ViewControllers/MainFrameViewController.m | 3 ++- 9 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Limelight/Network/DiscoveryManager.m b/Limelight/Network/DiscoveryManager.m index 05f5b1db..de17574f 100644 --- a/Limelight/Network/DiscoveryManager.m +++ b/Limelight/Network/DiscoveryManager.m @@ -41,7 +41,7 @@ - (void) discoverHost:(NSString *)hostAddress withCallback:(void (^)(Host *, NSString*))callback { HttpManager* hMan = [[HttpManager alloc] initWithHost:hostAddress uniqueId:_uniqueId deviceName:deviceName cert:_cert]; ServerInfoResponse* serverInfoResponse = [[ServerInfoResponse alloc] init]; - [hMan executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResponse withUrlRequest:[hMan newServerInfoRequest]]]; + [hMan executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResponse withUrlRequest:[hMan newServerInfoRequest] fallbackError:401 fallbackRequest:[hMan newHttpServerInfoRequest]]]; Host* host = nil; if ([serverInfoResponse isStatusOk]) { diff --git a/Limelight/Network/DiscoveryWorker.m b/Limelight/Network/DiscoveryWorker.m index e871acac..9d9314e8 100644 --- a/Limelight/Network/DiscoveryWorker.m +++ b/Limelight/Network/DiscoveryWorker.m @@ -68,7 +68,8 @@ static const float POLL_RATE = 2.0f; // Poll every 2 seconds cert:_cert]; ServerInfoResponse* response = [[ServerInfoResponse alloc] init]; [hMan executeRequestSynchronously:[HttpRequest requestForResponse:response - withUrlRequest:[hMan newServerInfoRequest]]]; + withUrlRequest:[hMan newServerInfoRequest] + fallbackError:401 fallbackRequest:[hMan newHttpServerInfoRequest]]]; return response; } diff --git a/Limelight/Network/HttpManager.h b/Limelight/Network/HttpManager.h index b96ee47e..d72a6182 100644 --- a/Limelight/Network/HttpManager.h +++ b/Limelight/Network/HttpManager.h @@ -22,6 +22,7 @@ - (NSURLRequest*) newPairChallenge; - (NSURLRequest*) newAppListRequest; - (NSURLRequest*) newServerInfoRequest; +- (NSURLRequest*) newHttpServerInfoRequest; - (NSURLRequest*) newLaunchRequest:(NSString*)appId width:(int)width height:(int)height refreshRate:(int)refreshRate rikey:(NSString*)rikey rikeyid:(int)rikeyid; - (NSURLRequest*) newResumeRequestWithRiKey:(NSString*)riKey riKeyId:(int)riKeyId; - (NSURLRequest*) newQuitAppRequest; diff --git a/Limelight/Network/HttpManager.m b/Limelight/Network/HttpManager.m index 70bf8c79..da6f20a1 100644 --- a/Limelight/Network/HttpManager.m +++ b/Limelight/Network/HttpManager.m @@ -83,6 +83,15 @@ static const NSString* HTTPS_PORT = @"47984"; if (!_errorOccurred && request.response) { [request.response populateWithData:_requestResp]; + + // If the fallback error code was detected, issue the fallback request + if (request.response.statusCode == request.fallbackError && request.fallbackRequest != NULL) { + Log(LOG_D, @"Request failed with fallback error code: %d", request.fallbackError); + request.request = request.fallbackRequest; + request.fallbackError = 0; + request.fallbackRequest = NULL; + [self executeRequestSynchronously:request]; + } } _errorOccurred = false; } @@ -145,6 +154,11 @@ static const NSString* HTTPS_PORT = @"47984"; return [self createRequestFromString:urlString enableTimeout:TRUE]; } +- (NSURLRequest *)newHttpServerInfoRequest { + NSString* urlString = [NSString stringWithFormat:@"%@/serverinfo", _baseHTTPURL]; + return [self createRequestFromString:urlString enableTimeout:TRUE]; +} + - (NSURLRequest*) newLaunchRequest:(NSString*)appId width:(int)width height:(int)height refreshRate:(int)refreshRate rikey:(NSString*)rikey rikeyid:(int)rikeyid { NSString* urlString = [NSString stringWithFormat:@"%@/launch?uniqueid=%@&appid=%@&mode=%dx%dx%d&additionalStates=1&sops=1&rikey=%@&rikeyid=%d", _baseHTTPSURL, _uniqueId, appId, width, height, refreshRate, rikey, rikeyid]; // This blocks while the app is launching diff --git a/Limelight/Network/HttpRequest.h b/Limelight/Network/HttpRequest.h index bead208b..743b58ba 100644 --- a/Limelight/Network/HttpRequest.h +++ b/Limelight/Network/HttpRequest.h @@ -13,7 +13,10 @@ @property (nonatomic) id response; @property (nonatomic) NSURLRequest* request; +@property (nonatomic) int fallbackError; +@property (nonatomic) NSURLRequest* fallbackRequest; ++ (instancetype) requestForResponse:(id)response withUrlRequest:(NSURLRequest*)req fallbackError:(int)error fallbackRequest:(NSURLRequest*) fallbackReq; + (instancetype) requestForResponse:(id)response withUrlRequest:(NSURLRequest*)req; + (instancetype) requestWithUrlRequest:(NSURLRequest*)req; diff --git a/Limelight/Network/HttpRequest.m b/Limelight/Network/HttpRequest.m index 69298ed8..afb1c896 100644 --- a/Limelight/Network/HttpRequest.m +++ b/Limelight/Network/HttpRequest.m @@ -25,4 +25,13 @@ return request; } ++ (HttpRequest*) requestForResponse:(id)response withUrlRequest:(NSURLRequest*)req fallbackError:(int)error fallbackRequest:(NSURLRequest*) fallbackReq { + HttpRequest* request = [[HttpRequest alloc] init]; + request.request = req; + request.response = response; + request.fallbackError = error; + request.fallbackRequest = fallbackReq; + return request; +} + @end diff --git a/Limelight/Network/PairManager.m b/Limelight/Network/PairManager.m index 616bb327..82ff2b21 100644 --- a/Limelight/Network/PairManager.m +++ b/Limelight/Network/PairManager.m @@ -31,7 +31,8 @@ - (void) main { ServerInfoResponse* serverInfoResp = [[ServerInfoResponse alloc] init]; - [_httpManager executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[_httpManager newServerInfoRequest]]]; + [_httpManager executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[_httpManager newServerInfoRequest] + fallbackError:401 fallbackRequest:[_httpManager newHttpServerInfoRequest]]]; if (serverInfoResp == nil) { [_callback pairFailed:@"Unable to connect to PC"]; return; diff --git a/Limelight/Stream/StreamManager.m b/Limelight/Stream/StreamManager.m index 3308ad12..d9087c39 100644 --- a/Limelight/Stream/StreamManager.m +++ b/Limelight/Stream/StreamManager.m @@ -45,7 +45,8 @@ cert:cert]; ServerInfoResponse* serverInfoResp = [[ServerInfoResponse alloc] init]; - [hMan executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[hMan newServerInfoRequest]]]; + [hMan executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[hMan newServerInfoRequest] + fallbackError:401 fallbackRequest:[hMan newHttpServerInfoRequest]]]; NSString* currentGame = [serverInfoResp getStringTag:@"currentgame"]; NSString* pairStatus = [serverInfoResp getStringTag:@"PairStatus"]; NSString* currentClient = [serverInfoResp getStringTag:@"CurrentClient"]; diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index d797d1e8..e1886073 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -133,7 +133,8 @@ static NSArray* appList; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ HttpManager* hMan = [[HttpManager alloc] initWithHost:host.address uniqueId:_uniqueId deviceName:deviceName cert:_cert]; ServerInfoResponse* serverInfoResp = [[ServerInfoResponse alloc] init]; - [hMan executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[hMan newServerInfoRequest]]]; + [hMan executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResp withUrlRequest:[hMan newServerInfoRequest] + fallbackError:401 fallbackRequest:[hMan newHttpServerInfoRequest]]]; if (serverInfoResp == nil || ![serverInfoResp isStatusOk]) { Log(LOG_W, @"Failed to get server info: %@", serverInfoResp.statusMessage); [self hideLoadingFrame];