| Index: chrome/installer/mac/app/request.m
|
| diff --git a/chrome/installer/mac/app/request.m b/chrome/installer/mac/app/request.m
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..65cb8e301e856564082ec3763637998b7747e575
|
| --- /dev/null
|
| +++ b/chrome/installer/mac/app/request.m
|
| @@ -0,0 +1,135 @@
|
| +// Copyright (c) 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#if !defined(__x86_64__)
|
| +#error "What are you doing?"
|
| +#endif
|
| +
|
| +#import <Foundation/Foundation.h>
|
| +#include <mach-o/arch.h>
|
| +#include "request.h"
|
| +
|
| +// NSString *omahaEndpoint = @"https://tools.google.com/service/update2";
|
| +static NSData *payload;
|
| +
|
| +NSString* getArchitecture(void) {
|
| + const NXArchInfo *arch = NXGetLocalArchInfo();
|
| + NSString *archName = [NSString stringWithUTF8String:arch->name];
|
| + return archName;
|
| +}
|
| +
|
| +NSString *getOSVersion(void) {
|
| + NSString *versionString = [[NSProcessInfo processInfo]
|
| + operatingSystemVersionString];
|
| + NSString *versionNumber = [[versionString componentsSeparatedByString:@" "]
|
| + objectAtIndex:1];
|
| + return versionNumber;
|
| +}
|
| +
|
| +// Boris (borisv) indicated that the OS version, platform, appid, and version are the user
|
| +// attributes that Omaha actually looks at. The other parameters are useful for logging purposes
|
| +// but otherwise not directly used.
|
| +NSXMLDocument *createXMLRequestBody(NSString *operatingSystem,
|
| + NSString *architecture) {
|
| + NSString *protocol = @"3.0";
|
| + NSString *keystoneVersion = @"KeystoneAgent-1.99.4.0";
|
| +
|
| + NSString *platform = @"mac";
|
| + NSString *plat_arch = [NSString stringWithFormat:@"%@_%@", operatingSystem,
|
| + architecture];
|
| +
|
| + NSString *appid = @"com.google.Chrome";
|
| + NSString *version = @"0.0.0.0";
|
| + NSString *language = @"en-us";
|
| +
|
| + NSXMLElement *root = [[NSXMLElement alloc] initWithName:@"request"];
|
| + [root addAttribute:[NSXMLNode attributeWithName:@"protocol"
|
| + stringValue:protocol]];
|
| + [root addAttribute:[NSXMLNode attributeWithName:@"version"
|
| + stringValue:keystoneVersion]];
|
| +
|
| + NSXMLElement *osChild = [[NSXMLElement alloc] initWithName:@"os"];
|
| + [osChild addAttribute:[NSXMLNode attributeWithName:@"platform"
|
| + stringValue:platform]];
|
| + [osChild addAttribute:[NSXMLNode attributeWithName:@"version"
|
| + stringValue:operatingSystem]];
|
| + [osChild addAttribute:[NSXMLNode attributeWithName:@"arch"
|
| + stringValue:architecture]];
|
| + [osChild addAttribute:[NSXMLNode attributeWithName:@"sp"
|
| + stringValue:plat_arch]];
|
| + [root addChild:osChild];
|
| +
|
| + NSXMLElement *appChild = [[NSXMLElement alloc] initWithName:@"app"];
|
| + [appChild addAttribute:[NSXMLNode attributeWithName:@"appid"
|
| + stringValue:appid]];
|
| + [appChild addAttribute:[NSXMLNode attributeWithName:@"version"
|
| + stringValue:version]];
|
| + [appChild addAttribute:[NSXMLNode attributeWithName:@"lang"
|
| + stringValue:language]];
|
| + [root addChild:appChild];
|
| +
|
| + NSXMLElement *updateChildChild = [[NSXMLElement alloc]
|
| + initWithName:@"updatecheck"];
|
| + [appChild addChild:updateChildChild];
|
| +
|
| + NSXMLDocument *requestXMLDocument = [[NSXMLDocument alloc]
|
| + initWithRootElement:root];
|
| + return requestXMLDocument;
|
| +}
|
| +
|
| +NSURLRequest* createOmahaRequest(NSXMLDocument *requestXMLBody) {
|
| + // create request
|
| + NSURL *requestURL = [NSURL URLWithString:@"https://tools.google.com/service/update2"];
|
| + NSMutableURLRequest *request = [NSMutableURLRequest
|
| + requestWithURL:requestURL];
|
| +
|
| + // populate metadata
|
| + request.HTTPMethod = @"POST";
|
| + [request addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
|
| +
|
| + // populate xml body
|
| + NSData *requestBody = [[requestXMLBody XMLString]
|
| + dataUsingEncoding:NSUTF8StringEncoding];
|
| + request.HTTPBody = requestBody;
|
| +
|
| + return request;
|
| +}
|
| +
|
| +NSData* sendRequestAndReceiveResponse(NSURLRequest *request) {
|
| +// NSData *payload = [NSData alloc];
|
| + NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration
|
| + defaultSessionConfiguration];
|
| + NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig
|
| + delegate:nil
|
| + delegateQueue:nil];
|
| +
|
| + NSURLSessionDataTask *omahaDataTask = [session dataTaskWithRequest:request
|
| + completionHandler:^(NSData *_Nullable data,
|
| + NSURLResponse *_Nullable response,
|
| + NSError *_Nullable error) {
|
| + if(error) {
|
| + NSLog(@"%@", error);
|
| + return;
|
| + }
|
| +
|
| + NSHTTPURLResponse *HTTPResponse = (NSHTTPURLResponse *)response;
|
| + if(HTTPResponse.statusCode == 200) {
|
| +// [payload initWithData:data];
|
| + payload = [[NSData alloc] initWithData:data];
|
| + } else {
|
| + NSLog(@"HTTP response: %ld", (unsigned long)HTTPResponse.statusCode);
|
| + return;
|
| + }
|
| +
|
| + return;
|
| + }];
|
| +
|
| + [omahaDataTask resume];
|
| + [session finishTasksAndInvalidate];
|
| + while([omahaDataTask state] != NSURLSessionTaskStateCompleted) {
|
| + sleep(1);
|
| + }
|
| +
|
| + return [payload autorelease];
|
| +}
|
|
|