~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/rewriter/public/resource_namer.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2010 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
 
//
15
 
// Author: jmarantz@google.com (Joshua Marantz)
16
 
 
17
 
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_NAMER_H_
18
 
#define NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_NAMER_H_
19
 
 
20
 
#include "base/logging.h"
21
 
#include "net/instaweb/util/public/basictypes.h"
22
 
#include "net/instaweb/util/public/string.h"
23
 
#include "net/instaweb/util/public/string_util.h"
24
 
 
25
 
namespace net_instaweb {
26
 
 
27
 
class Hasher;
28
 
 
29
 
// Encapsulates the naming of resource URL leafs.  The class holds the context
30
 
// of a single resource, and is not intended for re-use.  We could, of course,
31
 
// add a Clear(), but it is a stateful class.
32
 
class ResourceNamer {
33
 
 public:
34
 
  // This determines the overhead imposed on each URL by the ResourceNamer
35
 
  // syntax, such as separators.
36
 
  static const int kOverhead;
37
 
 
38
 
  ResourceNamer() {}
39
 
  ~ResourceNamer() {}
40
 
 
41
 
  // Encoding and decoding in various formats.
42
 
 
43
 
  // Decodes an entire resource name (NAME.pagespeed[.EXPT].ID.HASH[|SIG].EXT),
44
 
  // placing the result in the fields in this encoder.
45
 
  bool Decode(const StringPiece& encoded_string, int hash_length,
46
 
              int signature_length);
47
 
 
48
 
  // Calls Decode() passing values of -1, -1 for hash and signature lengths.
49
 
  // Hash and signature outputs from this must not be used.
50
 
  bool DecodeIgnoreHashAndSignature(StringPiece encoded_string);
51
 
 
52
 
  // Encodes the fields in this encoder into an absolute url, with the
53
 
  // trailing portion "NAME.pagespeed[.(EXPT|PsolOpts)].ID.HASH[.SIG].EXT".
54
 
  GoogleString Encode() const;
55
 
 
56
 
  // Encode a key that can used to do a lookup based on an id
57
 
  // and the name.  This key can be used to find the hash-code for a
58
 
  // resource within the origin TTL.
59
 
  //
60
 
  // The 'id' is a short code indicating which Instaweb rewriter was
61
 
  // used to generate the resource.
62
 
  GoogleString EncodeIdName() const;
63
 
 
64
 
  // Note: there is no need at this time to decode the name key.
65
 
 
66
 
  // Eventual length of name. Gets eventual hash length from passed in hasher
67
 
  // and signature_length.
68
 
  // Needed by RewriteDriver to check that filenames aren't too long.
69
 
  int EventualSize(const Hasher& hasher, int signature_length) const;
70
 
 
71
 
  // Simple getters
72
 
  StringPiece id() const { return id_; }
73
 
  StringPiece options() const { return options_; }
74
 
  StringPiece name() const { return name_; }
75
 
  StringPiece hash() const { return hash_; }
76
 
  StringPiece ext() const { return ext_; }
77
 
  StringPiece experiment() const { return experiment_; }
78
 
  StringPiece signature() const { return signature_; }
79
 
 
80
 
  bool has_experiment() const { return !experiment_.empty(); }
81
 
  bool has_options() const { return !options_.empty(); }
82
 
 
83
 
  // Simple setters
84
 
  void set_id(const StringPiece& p) { p.CopyToString(&id_); }
85
 
  void set_options(const StringPiece& opts) { opts.CopyToString(&options_); }
86
 
  void set_name(const StringPiece& n) { n.CopyToString(&name_); }
87
 
  void set_hash(const StringPiece& h) { h.CopyToString(&hash_); }
88
 
  void set_ext(const StringPiece& e) {
89
 
    // TODO(jmaessen): Remove check after transitioning to undotted extensions
90
 
    // everywhere.
91
 
    CHECK(e.empty() || e[0] != '.');
92
 
    e.CopyToString(&ext_);
93
 
  }
94
 
  void set_experiment(const StringPiece& e) { e.CopyToString(&experiment_); }
95
 
  void set_signature(const StringPiece& s) { s.CopyToString(&signature_); }
96
 
 
97
 
  // Other setter-like operations
98
 
  void ClearHash() { hash_.clear(); }
99
 
  void CopyFrom(const ResourceNamer& other);
100
 
 
101
 
  // Utility functions
102
 
 
103
 
  // Name suitable for debugging and logging
104
 
  GoogleString PrettyName() const {return  InternalEncode(); }
105
 
 
106
 
 private:
107
 
  GoogleString InternalEncode() const;
108
 
  bool LegacyDecode(const StringPiece& encoded_string);
109
 
 
110
 
  GoogleString id_;
111
 
  GoogleString options_;
112
 
  GoogleString name_;
113
 
  GoogleString hash_;
114
 
  GoogleString ext_;
115
 
  GoogleString experiment_;
116
 
  GoogleString signature_;
117
 
 
118
 
  DISALLOW_COPY_AND_ASSIGN(ResourceNamer);
119
 
};
120
 
 
121
 
}  // namespace net_instaweb
122
 
 
123
 
#endif  // NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_NAMER_H_