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

http://macfuse.googlecode.com/ · C Header · 232 lines · 95 code · 32 blank · 105 comment · 0 complexity · 333a8a7d178fdb5f9dc3f189e34dbb13 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. // Keys for the parameters dictionary. The values should be an NSString unless
  16. // otherwise noted.
  17. #define KSTicketProductIDKey @"ProductID"
  18. #define KSTicketVersionKey @"Version"
  19. #define KSTicketExistenceCheckerKey @"ExistenceChecker" // KSExistenceChecker
  20. #define KSTicketServerURLKey @"URL" // NSURL
  21. #define KSTicketTrustedTesterTokenKey @"TTToken"
  22. #define KSTicketCreationDateKey @"CreationDate" // NSDate
  23. #define KSTicketTagKey @"Tag"
  24. #define KSTicketTagPathKey @"TagPath"
  25. #define KSTicketTagKeyKey @"TagKey"
  26. #define KSTicketBrandPathKey @"BrandPath"
  27. #define KSTicketBrandKeyKey @"BrandKey"
  28. #define KSTicketVersionPathKey @"VersionPath"
  29. #define KSTicketVersionKeyKey @"VersionKey"
  30. @class KSExistenceChecker;
  31. // Object that encapsulates information that an application provides when
  32. // "registering" with UpdateEngine. Tickets are a central part of UpdateEngine.
  33. // UpdateEngine maintains one ticket for each registered application. Tickets
  34. // are how UpdateEngine knows what's installed.
  35. //
  36. // The creation date simply records the date the ticket was created. If a ticket
  37. // is unarchived (from a KSTicketStore), the creationDate_ will be the date the
  38. // ticket was originally created, not the date it was unarchived. You can use
  39. // the creation date to see how long the ticket has been registered. You should
  40. // preserve the creation date when you update a ticket.
  41. //
  42. @interface KSTicket : NSObject <NSCoding> {
  43. @private
  44. NSString *productID_; // guid or bundleID
  45. NSString *version_;
  46. KSExistenceChecker *existenceChecker_;
  47. NSURL *serverURL_;
  48. NSDate *creationDate_;
  49. NSString *trustedTesterToken_;
  50. NSString *tag_;
  51. NSString *tagPath_;
  52. NSString *tagKey_;
  53. NSString *brandPath_;
  54. NSString *brandKey_;
  55. NSString *versionPath_;
  56. NSString *versionKey_;
  57. }
  58. // Returns an autorelased KSTicket instance initialized with the
  59. // values contained in the parameter directory.
  60. + (KSTicket *)ticketWithParameters:(NSDictionary *)args;
  61. // Returns an autoreleased KSTicket instance initialized with the specified
  62. // arguments. All arguments are required; if any are nil, then nil is returned.
  63. + (id)ticketWithProductID:(NSString *)productid
  64. version:(NSString *)version
  65. existenceChecker:(KSExistenceChecker *)xc
  66. serverURL:(NSURL *)serverURL;
  67. // Returns an autoreleased KSTicket instance initialized with the
  68. // specified arguments, also allowing a trusted tester token to be
  69. // specified. All arguments other than the trusted tester token are
  70. // required; if any others are nil, then nil is returned.
  71. + (id)ticketWithProductID:(NSString *)productid
  72. version:(NSString *)version
  73. existenceChecker:(KSExistenceChecker *)xc
  74. serverURL:(NSURL *)serverURL
  75. trustedTesterToken:(NSString *)trustedTesterToken;
  76. // Returns an autoreleased KSTicket instance initialized with the
  77. // specified arguments, also allowing a trusted tester token and a
  78. // creation date to be specified. All arguments other than the
  79. // trusted tester token and creation date are required; if any others
  80. // are nil, then nil is returned.
  81. + (id)ticketWithProductID:(NSString *)productid
  82. version:(NSString *)version
  83. existenceChecker:(KSExistenceChecker *)xc
  84. serverURL:(NSURL *)serverURL
  85. trustedTesterToken:(NSString *)trustedTesterToken
  86. creationDate:(NSDate *)creationDate;
  87. // Returns an autoreleased KSTicket instance initialized with the
  88. // specified arguments, also allowing a trusted tester token, a
  89. // creation date, and a tag to be specified. All arguments other than
  90. // the trusted tester token, creation date, and tag are required; if
  91. // any others are nil, then nil is returned.
  92. // TODO(mdalrymple): There's too damn many of these initializers.
  93. // Pare it down to the Big Four (prodID, version, xc, url), and then
  94. // another one with all the args - either as individual arguments, or
  95. // a dict/struct packed with the extra values.
  96. + (id)ticketWithProductID:(NSString *)productid
  97. version:(NSString *)version
  98. existenceChecker:(KSExistenceChecker *)xc
  99. serverURL:(NSURL *)serverURL
  100. trustedTesterToken:(NSString *)trustedTesterToken
  101. creationDate:(NSDate *)creationDate
  102. tag:(NSString *)tag;
  103. // Designated initializer. Returns a KSTicket initialized with the
  104. // specified argument directory.
  105. - (id)initWithParameters:(NSDictionary *)args;
  106. // Returns a KSTicket initialized with the specified arguments. All
  107. // arguments are required; if any are nil, then nil is returned.
  108. - (id)initWithProductID:(NSString *)productid
  109. version:(NSString *)version
  110. existenceChecker:(KSExistenceChecker *)xc
  111. serverURL:(NSURL *)serverURL;
  112. // Returns a KSTicket initialized with the specified arguments, also
  113. // allowing a trusted tester token. All arguments other than the
  114. // trusted tester token are required; if any are nil, then nil is
  115. // returned.
  116. - (id)initWithProductID:(NSString *)productid
  117. version:(NSString *)version
  118. existenceChecker:(KSExistenceChecker *)xc
  119. serverURL:(NSURL *)serverURL
  120. trustedTesterToken:(NSString *)trustedTesterToken;
  121. // Returns a KSTicket initialized with the specified arguments, also
  122. // allowing a trusted tester token and a creation date. All arguments
  123. // other than the trusted tester token and creation date are required;
  124. // if any are nil, then nil is returned. If no creation date is
  125. // supplied, the current date and time is used.
  126. - (id)initWithProductID:(NSString *)productid
  127. version:(NSString *)version
  128. existenceChecker:(KSExistenceChecker *)xc
  129. serverURL:(NSURL *)serverURL
  130. trustedTesterToken:(NSString *)trustedTesterToken
  131. creationDate:(NSDate *)creationDate;
  132. // Returns a KSTicket initialized with the
  133. // specified arguments, also allowing a trusted tester token,
  134. // a creation date, and a tag. All arguments other than the trusted tester
  135. // token, creation date, and tag are required; if any are nil, then nil is
  136. // returned. If no creation date is supplied, the current date and
  137. // time is used.
  138. - (id)initWithProductID:(NSString *)productid
  139. version:(NSString *)version
  140. existenceChecker:(KSExistenceChecker *)xc
  141. serverURL:(NSURL *)serverURL
  142. trustedTesterToken:(NSString *)trustedTesterToken
  143. creationDate:(NSDate *)creationDate
  144. tag:(NSString *)tag;
  145. // Returns YES if ticket is equal to the ticket identified by self.
  146. - (BOOL)isEqualToTicket:(KSTicket *)ticket;
  147. // Returns the productID for this ticket.
  148. // We don't know or care if it's a GUID or BundleID
  149. - (NSString *)productID;
  150. // Returns the version stored in the ticket. You may want to use
  151. // -determineVersion if all you're interested in is "what version do I
  152. // report to the server for an update?"
  153. - (NSString *)version;
  154. // Returns the existence checker object for this ticket. This object can be used
  155. // to determine if the application represented by this ticket is still
  156. // installed.
  157. - (KSExistenceChecker *)existenceChecker;
  158. // Returns the server URL to check for updates to the application represented by
  159. // this ticket.
  160. - (NSURL *)serverURL;
  161. // Returns the date this ticket was created.
  162. - (NSDate *)creationDate;
  163. // Returns the trusted tester token, or nil if the ticket does not have one.
  164. - (NSString *)trustedTesterToken;
  165. // Returns the tag, or nil if the ticket does not have one.
  166. - (NSString *)tag;
  167. // Returns the tag path, or nil if the ticket does not have one.
  168. - (NSString *)tagPath;
  169. // Returns the tag key, or nil if the ticket does not have one.
  170. - (NSString *)tagKey;
  171. // Uses -tag, -tagPath, and -tagKey to determine what the ticket's tag is.
  172. // If -tagPath is not-nil, and points to a valid plist file, look up
  173. // a value with the -tagKey. If that exists, its description is returned.
  174. // If -tagPath is not-nil, and points to an invalid plist file, returns the
  175. // value of -tag.
  176. // If there is no tagPath, returns the value of -tag.
  177. - (NSString *)determineTag;
  178. // Returns the brand path, or nil if the ticket does not have one.
  179. - (NSString *)brandPath;
  180. // Returns the brand key, or nil if the ticket does not have one.
  181. - (NSString *)brandKey;
  182. // Uses -brandPath and -brandKey to determine what the ticket's brand code is.
  183. // If -brandPath is not-nil, and points to a valid plist file, look up
  184. // a value using the -brandKey. If that exists, its description is returned.
  185. // Returns nil if there is no brand code.
  186. - (NSString *)determineBrand;
  187. // Returns the version path, or nil if the ticket does not have one.
  188. - (NSString *)versionPath;
  189. // Returns the version key, or nil if the ticket does not have one.
  190. - (NSString *)versionKey;
  191. // Uses -version, -versionPath, and -versionKey to determine what the
  192. // ticket's version is.
  193. // If -versionPath is not-nil, and points to a valid plist file, look up
  194. // a value with the -versionKey. If that exists, its description is returned.
  195. // If it doesn't exist, -version is returned.
  196. // If -versionPath is not-nil, and points to an invalid plist file, returns
  197. // -version.
  198. // If there is no versionPath, returns -version.
  199. - (NSString *)determineVersion;
  200. @end