15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A library to manage RLZ information for access-points shared
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// across different client applications.
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// All functions return true on success and false on error.
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This implemenation is thread safe.
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef RLZ_LIB_RLZ_LIB_H_
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define RLZ_LIB_RLZ_LIB_H_
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <stdio.h>
1603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include <string>
17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "build/build_config.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "rlz/lib/rlz_enums.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN)
23a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#define RLZ_LIB_API __cdecl
24a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#else
2503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#define RLZ_LIB_API
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
2703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Define one of
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// + RLZ_NETWORK_IMPLEMENTATION_WIN_INET: Uses win inet to send financial pings.
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// + RLZ_NETWORK_IMPLEMENTATION_CHROME_NET: Uses chrome's network stack to send
31eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch//   financial pings. rlz_lib::SetURLRequestContext() must be called before
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   any calls to SendFinancialPing().
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(RLZ_NETWORK_IMPLEMENTATION_WIN_INET) && \
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#error Exactly one of RLZ_NETWORK_IMPLEMENTATION_WIN_INET and \
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    RLZ_NETWORK_IMPLEMENTATION_CHROME_NET should be defined.
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(RLZ_NETWORK_IMPLEMENTATION_WIN_INET) && \
39c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    !defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#define RLZ_NETWORK_IMPLEMENTATION_WIN_INET
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define RLZ_NETWORK_IMPLEMENTATION_CHROME_NET
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLRequestContextGetter;
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace net
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace rlz_lib {
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// All functions return true on success and false on error.
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This implemenation is thread safe.
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Each prototype mentions the registry access requirements:
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// HKLM read:  Will work from any process and at any privilege level on Vista.
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// HKCU read:  Calls made from the SYSTEM account must pass the current user's
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//             SID as the optional 'sid' param. Can be called from low integrity
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//             process on Vista.
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// HKCU write: Calls made from the SYSTEM account must pass the current user's
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//             SID as the optional 'sid' param. Calls require at least medium
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//             integrity on Vista (e.g. Toolbar will need to use their broker)
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// HKLM write: Calls must be made from an account with admin rights. No SID
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//             need be passed when running as SYSTEM.
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Functions which do not access registry will be marked with "no restrictions".
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ScopedRlzValueStoreLock;
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The maximum length of an access points RLZ in bytes.
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const size_t kMaxRlzLength = 64;
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The maximum length of an access points RLZ in bytes.
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const size_t kMaxDccLength = 128;
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The maximum length of a CGI string in bytes.
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const size_t kMaxCgiLength = 2048;
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The maximum length of a ping response we will parse in bytes. If the response
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// is bigger, please break it up into separate calls.
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const size_t kMaxPingResponseLength = 0x4000;  // 16K
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(RLZ_NETWORK_IMPLEMENTATION_CHROME_NET)
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Set the URLRequestContextGetter used by SendFinancialPing(). The IO message
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// loop returned by this context will be used for the IO done by
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// SendFinancialPing().
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API SetURLRequestContext(net::URLRequestContextGetter* context);
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// RLZ storage functions.
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Get all the events reported by this product as a CGI string to append to
93868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// the daily ping.
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU read.
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API GetProductEventsAsCgi(Product product, char* unescaped_cgi,
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                       size_t unescaped_cgi_size);
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Records an RLZ event.
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Some events can be product-independent (e.g: First search from home page),
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// and some can be access point independent (e.g. Pack installed). However,
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product independent events must still include the product which cares about
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// that information being reported.
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU write.
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API RecordProductEvent(Product product, AccessPoint point,
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    Event event_id);
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Clear an event reported by this product. This should be called after a
1085c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// successful ping to the RLZ server.
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU write.
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API ClearProductEvent(Product product, AccessPoint point,
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   Event event_id);
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Clear all reported events and recorded stateful events of this product.
1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This should be called on complete uninstallation of the product.
1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Access: HKCU write.
1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool RLZ_LIB_API ClearAllProductEvents(Product product);
1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Clears all product-specifc state from the RLZ registry.
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Should be called during product uninstallation.
1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// This removes outstanding product events, product financial ping times,
1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// the product RLS argument (if any), and any RLZ's for access points being
1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// uninstalled with the product.
1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// access_points is an array terminated with NO_ACCESS_POINT.
1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// IMPORTANT: These are the access_points the product is removing as part
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// of the uninstallation, not necessarily all the access points passed to
1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// SendFinancialPing() and GetPingParams().
1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// access_points can be NULL if no points are being uninstalled.
1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// No return value - this is best effort. Will assert in debug mode on
1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// failed attempts.
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU write.
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void RLZ_LIB_API ClearProductState(Product product,
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   const AccessPoint* access_points);
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Get the RLZ value of the access point. If the access point is not Google, the
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// RLZ will be the empty string and the function will return false.
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU read.
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API GetAccessPointRlz(AccessPoint point, char* rlz,
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                   size_t rlz_size);
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Set the RLZ for the access-point. Fails and asserts if called when the access
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// point is not set to Google.
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// new_rlz should come from a server-response. Client applications should not
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// create their own RLZ values.
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU write.
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API SetAccessPointRlz(AccessPoint point, const char* new_rlz);
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Financial Server pinging functions.
1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// These functions deal with pinging the RLZ financial server and parsing and
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// acting upon the response. Clients should SendFinancialPing() to avoid needing
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// these functions. However, these functions allow clients to split the various
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// parts of the pinging process up as needed (to avoid firewalls, etc).
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Forms the HTTP request to send to the RLZ financial server.
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product            : The product to ping for.
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// access_points      : The access points this product affects. Array must be
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                      terminated with NO_ACCESS_POINT.
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product_signature  : The signature sent with daily pings (e.g. swg, ietb)
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product_brand      : The brand of the pinging product, if any.
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product_id         : The product-specific installation ID (can be NULL).
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product_lang       : The language for the product (used to determine cohort).
16203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// exclude_machine_id : Whether the Machine ID should be explicitly excluded
16303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)//                      based on the products privacy policy.
16403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// request            : The buffer where the function returns the HTTP request.
16503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// request_buffer_size: The size of the request buffer in bytes. The buffer
16603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)//                      size (kMaxCgiLength+1) is guaranteed to be enough.
16703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)//
16803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// Access: HKCU read.
1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool RLZ_LIB_API FormFinancialPingRequest(Product product,
1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          const AccessPoint* access_points,
1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          const char* product_signature,
1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          const char* product_brand,
1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          const char* product_id,
1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          const char* product_lang,
1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          bool exclude_machine_id,
1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          char* request,
1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          size_t request_buffer_size);
1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Pings the financial server and returns the HTTP response. This will fail
1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// if it is too early to ping the server since the last ping.
1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//
1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// If RLZ_NETWORK_IMPLEMENTATION_CHROME_NET is set, SetURLRequestContext() needs
1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// to be called before calling this function.
1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//
1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// product              : The product to ping for.
1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// request              : The HTTP request (for example, returned by
1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//                        FormFinancialPingRequest).
1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// response             : The buffer in which the HTTP response is returned.
18903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// response_buffer_size : The size of the response buffer in bytes. The buffer
19003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)//                        size (kMaxPingResponseLength+1) is enough for all
19103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)//                        legitimate server responses (any response that is
19203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)//                        bigger should be considered the same way as a general
19303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)//                        network problem).
19403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)//
19503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// Access: HKCU read.
19603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)bool RLZ_LIB_API PingFinancialServer(Product product,
19703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                                     const char* request,
19803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                                     char* response,
19903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                                     size_t response_buffer_size);
20003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Checks if a ping response is valid - ie. it has a checksum line which
2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// is the CRC-32 checksum of the message uptil the checksum. If
2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// checksum_idx is not NULL, it will get the index of the checksum, i.e. -
2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// the effective end of the message.
2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Access: No restrictions.
2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool RLZ_LIB_API IsPingResponseValid(const char* response,
2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                     int* checksum_idx);
2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Complex helpers built on top of other functions.
2115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Parses the responses from the financial server and updates product state
2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// and access point RLZ's in registry. Like ParsePingResponse(), but also
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// updates the last ping time.
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU write.
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool RLZ_LIB_API ParseFinancialPingResponse(Product product,
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                            const char* response);
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Send the ping with RLZs and events to the PSO server.
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This ping method should be called daily. (More frequent calls will fail).
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Also, if there are no events, the call will succeed only once a week.
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// If RLZ_NETWORK_IMPLEMENTATION_CHROME_NET is set, SetURLRequestContext() needs
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to be called before calling this function.
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product            : The product to ping for.
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// access_points      : The access points this product affects. Array must be
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                      terminated with NO_ACCESS_POINT.
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product_signature  : The signature sent with daily pings (e.g. swg, ietb)
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product_brand      : The brand of the pinging product, if any.
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product_id         : The product-specific installation ID (can be NULL).
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// product_lang       : The language for the product (used to determine cohort).
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// exclude_machine_id : Whether the Machine ID should be explicitly excluded
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                      based on the products privacy policy.
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns true on successful ping and response, false otherwise.
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Access: HKCU write.
238bool RLZ_LIB_API SendFinancialPing(Product product,
239                                   const AccessPoint* access_points,
240                                   const char* product_signature,
241                                   const char* product_brand,
242                                   const char* product_id,
243                                   const char* product_lang,
244                                   bool exclude_machine_id);
245
246// An alternate implementations of SendFinancialPing with the same behavior,
247// except the caller can optionally choose to skip the timing check.
248bool RLZ_LIB_API SendFinancialPing(Product product,
249                                   const AccessPoint* access_points,
250                                   const char* product_signature,
251                                   const char* product_brand,
252                                   const char* product_id,
253                                   const char* product_lang,
254                                   bool exclude_machine_id,
255                                   const bool skip_time_check);
256
257// Parses RLZ related ping response information from the server.
258// Updates stored RLZ values and clears stored events accordingly.
259// Access: HKCU write.
260bool RLZ_LIB_API ParsePingResponse(Product product, const char* response);
261
262
263// Copies the events associated with the product and the RLZ's for each access
264// point in access_points into cgi. This string can be directly appended
265// to a ping (will need an & if not first paramter).
266// access_points must be an array of AccessPoints terminated with
267// NO_ACCESS_POINT.
268// Access: HKCU read.
269bool RLZ_LIB_API GetPingParams(Product product,
270                               const AccessPoint* access_points,
271                               char* unescaped_cgi, size_t unescaped_cgi_size);
272
273#if defined(OS_WIN)
274// OEM Deal confirmation storage functions. OEM Deals are windows-only.
275
276// Makes the OEM Deal Confirmation code writable by all users on the machine.
277// This should be called before calling SetMachineDealCode from a non-admin
278// account.
279// Access: HKLM write.
280bool RLZ_LIB_API CreateMachineState(void);
281
282// Set the OEM Deal Confirmation Code (DCC). This information is used for RLZ
283// initalization.
284// Access: HKLM write, or
285// HKCU read if rlz_lib::CreateMachineState() has been sucessfully called.
286bool RLZ_LIB_API SetMachineDealCode(const char* dcc);
287
288// Get the DCC cgi argument string to append to a daily ping.
289// Should be used only by OEM deal trackers. Applications should use the
290// GetMachineDealCode method which has an AccessPoint paramter.
291// Access: HKLM read.
292bool RLZ_LIB_API GetMachineDealCodeAsCgi(char* cgi, size_t cgi_size);
293
294// Get the DCC value stored in registry.
295// Should be used only by OEM deal trackers. Applications should use the
296// GetMachineDealCode method which has an AccessPoint paramter.
297// Access: HKLM read.
298bool RLZ_LIB_API GetMachineDealCode(char* dcc, size_t dcc_size);
299
300// Parses a ping response, checks if it is valid and sets the machine DCC
301// from the response. The ping must also contain the current DCC value in
302// order to be considered valid.
303// Access: HKLM write;
304//         HKCU write if CreateMachineState() has been successfully called.
305bool RLZ_LIB_API SetMachineDealCodeFromPingResponse(const char* response);
306
307#endif
308
309// Segment RLZ persistence based on branding information.
310// All information for a given product is persisted under keys with the either
311// product's name or its access point's name.  This assumes that only
312// one instance of the product is installed on the machine, and that only one
313// product brand is associated with it.
314//
315// In some cases, a given product may be using supplementary brands.  The RLZ
316// information must be kept separately for each of these brands.  To achieve
317// this segmentation, scope all RLZ library calls that deal with supplementary
318// brands within the lifetime of an rlz_lib::ProductBranding instance.
319//
320// For example, to record events for a supplementary brand, do the following:
321//
322//  {
323//    rlz_lib::SupplementaryBranding branding("AAAA");
324//    // This call to RecordProductEvent is scoped to the AAAA brand.
325//    rlz_lib::RecordProductEvent(rlz_lib::DESKTOP, rlz_lib::GD_DESKBAND,
326//                                rlz_lib::INSTALL);
327//  }
328//
329//  // This call to RecordProductEvent is not scoped to any supplementary brand.
330//  rlz_lib::RecordProductEvent(rlz_lib::DESKTOP, rlz_lib::GD_DESKBAND,
331//                              rlz_lib::INSTALL);
332//
333// In particular, this affects the recording of stateful events and the sending
334// of financial pings.  In the former case, a stateful event recorded while
335// scoped to a supplementary brand will be recorded again when scoped to a
336// different supplementary brand (or not scoped at all).  In the latter case,
337// the time skip check is specific to each supplementary brand.
338class SupplementaryBranding {
339 public:
340  SupplementaryBranding(const char* brand);
341  ~SupplementaryBranding();
342
343  static const std::string& GetBrand();
344
345 private:
346  ScopedRlzValueStoreLock* lock_;
347};
348
349}  // namespace rlz_lib
350
351#endif  // RLZ_LIB_RLZ_LIB_H_
352