<commit_before>// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cloud_print/gcp20/prototype/printer.h"

#include <stdio.h>
#include <string>
#include <vector>

#include "base/bind.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/format_macros.h"
#include "base/guid.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "cloud_print/gcp20/prototype/command_line_reader.h"
#include "cloud_print/gcp20/prototype/local_settings.h"
#include "cloud_print/gcp20/prototype/service_parameters.h"
#include "cloud_print/gcp20/prototype/special_io.h"
#include "cloud_print/version.h"
#include "net/base/net_util.h"
#include "net/base/url_util.h"

const char kPrinterStatePathDefault[] = "printer_state.json";

namespace {

const uint16 kHttpPortDefault = 10101;
const uint32 kTtlDefault = 60*60;  // in seconds

const char kServiceType[] = "_privet._tcp.local";
const char kSecondaryServiceType[] = "_printer._sub._privet._tcp.local";
const char kServiceNamePrefixDefault[] = "first_gcp20_device";
const char kServiceDomainNameDefault[] = "my-privet-device.local";

const char kPrinterName[] = "Google GCP2.0 Prototype";
const char kPrinterDescription[] = "Printer emulator";

const char kUserConfirmationTitle[] = "Confirm registration: type 'y' if you "
                                      "agree and any other to discard\n";
const int kUserConfirmationTimeout = 30;  // in seconds
const int kRegistrationTimeout = 60;  // in seconds
const int kReconnectTimeout = 5;  // in seconds

const double kTimeToNextAccessTokenUpdate = 0.8;  // relatively to living time.

const char kCdd[] =
"{"
"  'version': '1.0',"
"  'printer': {"
"    'supported_content_type': ["
"      {"
"        'content_type': 'application/pdf'"
"      },"
"      {"
"        'content_type': 'image/pwg-raster'"
"      },"
"      {"
"        'content_type': 'image/jpeg'"
"      }"
"    ],"
"    'color': {"
"     'option': ["
"        {"
"          'is_default': true,"
"          'type': 'STANDARD_COLOR',"
"          'vendor_id': 'CMYK'"
"        },"
"        {"
"          'is_default': false,"
"          'type': 'STANDARD_MONOCHROME',"
"          'vendor_id': 'Gray'"
"        }"
"      ]"
"    },"
"    'dpi': {"
"       'option': [ {"
"          'horizontal_dpi': 300,"
"          'is_default': true,"
"          'vertical_dpi': 300"
"       }, {"
"          'horizontal_dpi': 600,"
"          'is_default': false,"
"          'vertical_dpi': 600"
"       } ]"
"    },"
"    'duplex': {"
"       'option': [ {"
"          'is_default': true,"
"          'type': 'NO_DUPLEX'"
"       }, {"
"          'is_default': false,"
"          'type': 'SHORT_EDGE'"
"       }, {"
"          'is_default': false,"
"          'type': 'LONG_EDGE'"
"       } ]"
"    },"
"    'media_size': {"
"       'option': [ {"
"          'custom_display_name': 'A4',"
"          'height_microns': 297000,"
"          'is_continuous_feed': false,"
"          'is_default': false,"
"          'name': 'A4',"
"          'width_microns': 210000"
"       }, {"
"          'custom_display_name': 'Letter',"
"          'height_microns': 279400,"
"          'is_continuous_feed': false,"
"          'is_default': true,"
"          'name': 'LETTER',"
"          'width_microns': 215900"
"       } ]"
"    },"
"    'page_orientation': {"
"       'option': [ {"
"          'is_default': true,"
"          'type': 'PORTRAIT'"
"       }, {"
"          'is_default': false,"
"          'type': 'LANDSCAPE'"
"       } ]"
"    },"
"    'reverse_order': {"
"      'default': false"
"    }"
"  }"
"}";

// Returns local IP address number of first interface found (except loopback).
// Return value is empty if no interface found. Possible interfaces names are
// "eth0", "wlan0" etc. If interface name is empty, function will return IP
// address of first interface found.
net::IPAddressNumber GetLocalIp(const std::string& interface_name,<commit_msg>Fixed CDD. "custom_display_name" must be set only if the "name" field is CUSTOM. Removed optional values.<commit_after>// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cloud_print/gcp20/prototype/printer.h"

#include <stdio.h>
#include <string>
#include <vector>

#include "base/bind.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/format_macros.h"
#include "base/guid.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "cloud_print/gcp20/prototype/command_line_reader.h"
#include "cloud_print/gcp20/prototype/local_settings.h"
#include "cloud_print/gcp20/prototype/service_parameters.h"
#include "cloud_print/gcp20/prototype/special_io.h"
#include "cloud_print/version.h"
#include "net/base/net_util.h"
#include "net/base/url_util.h"

const char kPrinterStatePathDefault[] = "printer_state.json";

namespace {

const uint16 kHttpPortDefault = 10101;
const uint32 kTtlDefault = 60*60;  // in seconds

const char kServiceType[] = "_privet._tcp.local";
const char kSecondaryServiceType[] = "_printer._sub._privet._tcp.local";
const char kServiceNamePrefixDefault[] = "first_gcp20_device";
const char kServiceDomainNameDefault[] = "my-privet-device.local";

const char kPrinterName[] = "Google GCP2.0 Prototype";
const char kPrinterDescription[] = "Printer emulator";

const char kUserConfirmationTitle[] = "Confirm registration: type 'y' if you "
                                      "agree and any other to discard\n";
const int kUserConfirmationTimeout = 30;  // in seconds
const int kRegistrationTimeout = 60;  // in seconds
const int kReconnectTimeout = 5;  // in seconds

const double kTimeToNextAccessTokenUpdate = 0.8;  // relatively to living time.

const char kCdd[] =
"{"
"  'version': '1.0',"
"  'printer': {"
"    'supported_content_type': ["
"      {"
"        'content_type': 'application/pdf'"
"      },"
"      {"
"        'content_type': 'image/pwg-raster'"
"      },"
"      {"
"        'content_type': 'image/jpeg'"
"      }"
"    ],"
"    'color': {"
"     'option': ["
"        {"
"          'is_default': true,"
"          'type': 'STANDARD_COLOR'"
"        },"
"        {"
"          'type': 'STANDARD_MONOCHROME'"
"        }"
"      ]"
"    },"
"    'media_size': {"
"       'option': [ {"
"          'height_microns': 297000,"
"          'name': 'ISO_A4',"
"          'width_microns': 210000"
"       }, {"
"          'custom_display_name': 'Letter',"
"          'height_microns': 279400,"
"          'is_default': true,"
"          'name': 'NA_LETTER',"
"          'width_microns': 215900"
"       } ]"
"    },"
"    'page_orientation': {"
"       'option': [ {"
"          'is_default': true,"
"          'type': 'PORTRAIT'"
"       }, {"
"          'type': 'LANDSCAPE'"
"       } ]"
"    },"
"    'reverse_order': {"
"      'default': false"
"    }"
"  }"
"}";

// Returns local IP address number of first interface found (except loopback).
// Return value is empty if no interface found. Possible interfaces names are
// "eth0", "wlan0" etc. If interface name is empty, function will return IP
// address of first interface found.
net::IPAddressNumber GetLocalIp(const std::string& interface_name,
{'fraction_non_alphanumeric': 0.16159895150720838, 'fraction_numerical': 0.01926605504587156, 'mean_word_length': 2.885437881873727, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7376172', 'n_tokens_mistral': 2684, 'n_tokens_neox': 2541, 'n_words': 552}