/core/externals/update-engine/Core/KSPlistServer.h

http://macfuse.googlecode.com/ · C Header · 152 lines · 10 code · 6 blank · 136 comment · 0 complexity · a0ed1aee9ff8f414a77b52c39f25d132 MD5 · raw file

  1. // Copyright 2008 Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import <Foundation/Foundation.h>
  15. #import "KSServer.h"
  16. // KSPlistServer
  17. //
  18. // This concrete KSServer subclass is designed to read a specially formatted
  19. // XML Plist, and based on the "rules" in that plist, will create the necessary
  20. // KSUpdateInfo objects (KSUpdateInfo instances describe an update that needs to
  21. // be installed).
  22. //
  23. // The "trick" to this class is that each Rule contains an NSPredicate-
  24. // compatible "Predicate" string. Each predicate will be evaluated against a
  25. // specific object that provides access to useful system/product version info.
  26. // If the Predicate evaluates to true, then the update in the rule is applied,
  27. // otherwise, it's discarded.
  28. //
  29. // == Plist Format ==
  30. //
  31. // The fetched plist must have a top-level key named "Rules" with a value that
  32. // is a array of individual rules. Each Rule itself must be a dictionary with
  33. // the following required keys and value types (IMPORTANT: case *is* important):
  34. //
  35. // - ProductID (string) : The unique identifier for the product (same as the
  36. // product ID used in the ticket).
  37. // - Predicate (string) : Any NSPredicate compatible string that determines
  38. // whether the update described by the current rule
  39. // should be applied. More details below.
  40. // - Codebase (string) : The URL where the update should be downloaded from.
  41. // This URL must reference a disk image (DMG).
  42. // - Hash (string) : The Base64-encoded SHA-1 hash of the file at
  43. // the "Codebase" URL.
  44. // An easy way to calculate this is with the command:
  45. // openssl sha1 -binary dmg-filename | openssl base64
  46. // - Size (string) : The size in bytes of the file at the "Codebase" URL.
  47. //
  48. // The Predicate enables lots of flexibility and configurability. The string
  49. // specified for the predicate will be converted into an NSPredicate and run
  50. // against an NSDictionary with two attributes:
  51. //
  52. // - SystemVersion : This gives the predicate access to version information
  53. // about the current OS. The value of this key is the
  54. // contents of the file:
  55. // /System/Library/CoreServices/SystemVersion.plist
  56. // - Ticket : This gives the predicate access to the product's
  57. // (determined by the ProductID key) currently installed
  58. // version information via its corresponding KSTicket.
  59. //
  60. // == Example Plist 1 ==
  61. //
  62. // This plist contains one rule whose predicate says to install the update at
  63. // "Codebase" if the currently installed version is not version 1.1. This rule
  64. // may work for a product whose current version is 1.1 and all versions that are
  65. // not 1.1 should be "upgraded" to version 1.1.
  66. //
  67. // <?xml version="1.0" encoding="UTF-8"?>
  68. // <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
  69. // "https://www.apple.com/DTDs/PropertyList-1.0.dtd">
  70. // <plist version="1.0">
  71. // <dict>
  72. // <key>Rules</key>
  73. // <array>
  74. // <dict>
  75. // <key>ProductID</key>
  76. // <string>com.google.Foo</string>
  77. // <key>Predicate</key>
  78. // <string>Ticket.version != '1.1'</string>
  79. // <key>Codebase</key>
  80. // <string>https://www.google.com/engine/Foo.dmg</string>
  81. // <key>Hash</key>
  82. // <string>somehash=</string>
  83. // <key>Size</key>
  84. // <string>123456</string>
  85. // </dict>
  86. // </array>
  87. // </dict>
  88. // </plist>
  89. //
  90. //
  91. // == Example Plist 2 ==
  92. //
  93. // This plist lists two rules for two different products (Foo and Bar). The
  94. // Foo product will only ever apply to Tiger machines because the predicate
  95. // looks for "SystemVersion.ProductVersion beginswith '10.4'". The Bar product
  96. // only targets Leopard systems because its predicate includes a similar check
  97. // for a system version beginning with '10.5'. The rest of this plist should be
  98. // pretty straight forward.
  99. //
  100. // <?xml version="1.0" encoding="UTF-8"?>
  101. // <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
  102. // "https://www.apple.com/DTDs/PropertyList-1.0.dtd">
  103. // <plist version="1.0">
  104. // <dict>
  105. // <key>Rules</key>
  106. // <array>
  107. // <dict>
  108. // <key>ProductID</key>
  109. // <string>com.google.Foo</string>
  110. // <key>Predicate</key>
  111. // <string>SystemVersion.ProductVersion beginswith '10.4' AND Ticket.version != '1.1'</string>
  112. // <key>Codebase</key>
  113. // <string>https://www.google.com/engine/Foo.dmg</string>
  114. // <key>Hash</key>
  115. // <string>somehash=</string>
  116. // <key>Size</key>
  117. // <string>123456</string>
  118. // </dict>
  119. // <dict>
  120. // <key>ProductID</key>
  121. // <string>com.google.Bar</string>
  122. // <key>Predicate</key>
  123. // <string>SystemVersion.ProductVersion beginswith '10.5' AND Ticket.version != '1.1'</string>
  124. // <key>Codebase</key>
  125. // <string>https://www.google.com/engine/Bar.dmg</string>
  126. // <key>Hash</key>
  127. // <string>somehash=</string>
  128. // <key>Size</key>
  129. // <string>123456</string>
  130. // </dict>
  131. // </array>
  132. // </dict>
  133. // </plist>
  134. //
  135. @interface KSPlistServer : KSServer {
  136. @private
  137. NSArray *tickets_;
  138. NSDictionary *systemVersion_;
  139. }
  140. // Returns an autoreleased instance that will create requests to the given URL.
  141. + (id)serverWithURL:(NSURL *)url;
  142. // Returns the tickets that were last passed to -requestsForTickets:. Because
  143. // this class retains the tickets passed to -requestsForTickets:, it's not safe
  144. // to reuse this class--only use each instance once.
  145. - (NSArray *)tickets;
  146. @end