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)// Contains the definition of a few helper functions used for generating sync
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// URLs.
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "sync/engine/net/url_translator.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/port.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/escape.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using std::string;
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace syncer {
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Parameters that the server understands. (here, a-Z)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kParameterClient[] = "client";
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kParameterClientID[] = "client_id";
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(GOOGLE_CHROME_BUILD)
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kClientName[] = "Google Chrome";
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#else
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kClientName[] = "Chromium";
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // defined(GOOGLE_CHROME_BUILD)
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Convenience wrappers around CgiEscapePath().
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)string CgiEscapeString(const char* src) {
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return CgiEscapeString(string(src));
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)string CgiEscapeString(const string& src) {
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return net::EscapeUrlEncodedData(src, true);
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This method appends the query string to the sync server path.
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)string MakeSyncServerPath(const string& path, const string& query_string) {
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  string result = path;
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  result.append("?");
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  result.append(query_string);
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return result;
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)string MakeSyncQueryString(const string& client_id) {
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  string query;
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  query += kParameterClient;
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  query += "=" + CgiEscapeString(kClientName);
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  query += "&";
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  query += kParameterClientID;
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  query += "=" + CgiEscapeString(client_id);
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return query;
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace syncer
58