Home | History | Annotate | Download | only in lib
      1 // Copyright (c) 2012 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 // Library functions related to the OEM Deal Confirmation Code.
      6 
      7 #ifndef RLZ_WIN_LIB_MACHINE_DEAL_H_
      8 #define RLZ_WIN_LIB_MACHINE_DEAL_H_
      9 
     10 #include <string>
     11 #include "rlz/lib/rlz_lib.h"
     12 
     13 namespace rlz_lib {
     14 
     15 class MachineDealCode {
     16  public:
     17   // Set the OEM Deal Confirmation Code (DCC). This information is used for RLZ
     18   // initalization. Must have write access to HKLM - SYSTEM or admin, unless
     19   // rlz_lib::CreateMachineState() has been successfully called.
     20   static bool Set(const char* dcc);
     21 
     22   // Get the OEM Deal Confirmation Code from the registry. Used to ping
     23   // the server.
     24   static bool Get(AccessPoint point,
     25                   char* dcc,
     26                   int dcc_size,
     27                   const wchar_t* sid = NULL);
     28 
     29   // Parses a ping response, checks if it is valid and sets the machine DCC
     30   // from the response. The response should also contain the current value of
     31   // the DCC to be considered valid.
     32   // Write access to HKLM (system / admin) needed, unless
     33   // rlz_lib::CreateMachineState() has been successfully called.
     34   static bool SetFromPingResponse(const char* response);
     35 
     36   // Gets the new DCC to set from a ping response. Returns true if the ping
     37   // response is valid. Sets has_new_dcc true if there is a new DCC value.
     38   static bool GetNewCodeFromPingResponse(const char* response,
     39                                          bool* has_new_dcc,
     40                                          char* new_dcc,
     41                                          int new_dcc_size);
     42 
     43   // Get the DCC cgi argument string to append to a daily or financial ping.
     44   static bool GetAsCgi(char* cgi, int cgi_size);
     45 
     46   // Get the machine code.
     47   static bool Get(char* dcc, int dcc_size);
     48 
     49  protected:
     50   // Clear the DCC value. Only for testing purposes.
     51   // Requires write access to HKLM, unless rlz_lib::CreateMachineState() has
     52   // been successfully called.
     53   static bool Clear();
     54 
     55   MachineDealCode() {}
     56   ~MachineDealCode() {}
     57 };
     58 
     59 }  // namespace rlz_lib
     60 
     61 #endif  // RLZ_WIN_LIB_MACHINE_DEAL_H_
     62