OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import <Foundation/Foundation.h> |
| 6 |
| 7 #include "OmahaXMLRequest.h" |
| 8 #include "SystemInfo.h" |
| 9 |
| 10 @implementation OmahaXMLRequest : NSObject |
| 11 |
| 12 + (NSXMLElement*)createElementWithName:(NSString*)name { |
| 13 return [[NSXMLElement alloc] initWithName:name]; |
| 14 } |
| 15 |
| 16 + (void)forElement:(NSXMLElement*)element |
| 17 AddAttribute:(NSString*)attribute |
| 18 WithValue:(NSString*)value { |
| 19 [element |
| 20 addAttribute:[NSXMLNode attributeWithName:attribute stringValue:value]]; |
| 21 } |
| 22 |
| 23 // borisv@ indicated that the OS version, platform, appid, and version are the |
| 24 // user attributes that Omaha actually looks at. The other parameters are useful |
| 25 // for logging purposes but otherwise not directly used. |
| 26 + (NSXMLDocument*)createXMLRequestBody { |
| 27 // NOTE: might be a good idea in the future to add a version# for this |
| 28 // installer |
| 29 NSString* protocol = @"3.0"; |
| 30 |
| 31 NSString* platform = @"mac"; |
| 32 NSString* operatingSystem = [SystemInfo getOSVersion]; |
| 33 NSString* architecture = [SystemInfo getArch]; |
| 34 NSString* plat_arch = |
| 35 [NSString stringWithFormat:@"%@_%@", operatingSystem, architecture]; |
| 36 |
| 37 NSString* appid = @"com.google.Chrome"; |
| 38 NSString* version = @"0.0.0.0"; |
| 39 NSString* language = @"en-us"; |
| 40 |
| 41 NSXMLElement* root = [OmahaXMLRequest createElementWithName:@"request"]; |
| 42 [OmahaXMLRequest forElement:root AddAttribute:@"protocol" WithValue:protocol]; |
| 43 |
| 44 NSXMLElement* osChild = [OmahaXMLRequest createElementWithName:@"os"]; |
| 45 [OmahaXMLRequest forElement:osChild |
| 46 AddAttribute:@"platform" |
| 47 WithValue:platform]; |
| 48 [OmahaXMLRequest forElement:osChild |
| 49 AddAttribute:@"version" |
| 50 WithValue:operatingSystem]; |
| 51 [OmahaXMLRequest forElement:osChild |
| 52 AddAttribute:@"arch" |
| 53 WithValue:architecture]; |
| 54 [OmahaXMLRequest forElement:osChild AddAttribute:@"sp" WithValue:plat_arch]; |
| 55 [root addChild:osChild]; |
| 56 |
| 57 NSXMLElement* appChild = [OmahaXMLRequest createElementWithName:@"app"]; |
| 58 [OmahaXMLRequest forElement:appChild AddAttribute:@"appid" WithValue:appid]; |
| 59 [OmahaXMLRequest forElement:appChild |
| 60 AddAttribute:@"version" |
| 61 WithValue:version]; |
| 62 [OmahaXMLRequest forElement:appChild AddAttribute:@"lang" WithValue:language]; |
| 63 [root addChild:appChild]; |
| 64 |
| 65 NSXMLElement* updateChildChild = |
| 66 [OmahaXMLRequest createElementWithName:@"updatecheck"]; |
| 67 [appChild addChild:updateChildChild]; |
| 68 |
| 69 NSXMLDocument* requestXMLDocument = |
| 70 [[NSXMLDocument alloc] initWithRootElement:root]; |
| 71 return requestXMLDocument; |
| 72 } |
| 73 |
| 74 @end |
OLD | NEW |