00001
00016
00017 #ifndef NET_INSTAWEB_APACHE_APACHE_CONFIG_H_
00018 #define NET_INSTAWEB_APACHE_APACHE_CONFIG_H_
00019
00020 #include "net/instaweb/rewriter/public/rewrite_options.h"
00021 #include "net/instaweb/util/public/string.h"
00022 #include "net/instaweb/util/public/string_util.h"
00023
00027 #include "httpd.h"
00028
00029 namespace net_instaweb {
00030
00033 class ApacheConfig : public RewriteOptions {
00034 public:
00035 enum RefererStatisticsOutputLevel {
00036 kFast,
00037 kSimple,
00038 kOrganized,
00039 };
00040
00041 static const char kClassName[];
00042
00043 static bool ParseRefererStatisticsOutputLevel(
00044 const StringPiece& in, RefererStatisticsOutputLevel* out);
00045
00046 explicit ApacheConfig(const StringPiece& dir);
00047 ApacheConfig();
00048 ~ApacheConfig() {}
00049
00053 StringPiece description() const { return description_; }
00054 void set_description(const StringPiece& x) { x.CopyToString(&description_); }
00055
00056 int64 file_cache_clean_interval_ms() const {
00057 return file_cache_clean_interval_ms_.value();
00058 }
00059 void set_file_cache_clean_interval_ms(int64 x) {
00060 set_option(x, &file_cache_clean_interval_ms_);
00061 }
00062 int64 file_cache_clean_size_kb() const {
00063 return file_cache_clean_size_kb_.value();
00064 }
00065 void set_file_cache_clean_size_kb(int64 x) {
00066 set_option(x, &file_cache_clean_size_kb_);
00067 }
00068 int64 lru_cache_byte_limit() const {
00069 return lru_cache_byte_limit_.value();
00070 }
00071 void set_lru_cache_byte_limit(int64 x) {
00072 set_option(x, &lru_cache_byte_limit_);
00073 }
00074 int64 lru_cache_kb_per_process() const {
00075 return lru_cache_kb_per_process_.value();
00076 }
00077 void set_lru_cache_kb_per_process(int64 x) {
00078 set_option(x, &lru_cache_kb_per_process_);
00079 }
00080 int64 fetcher_time_out_ms() const {
00081 return fetcher_time_out_ms_.value();
00082 }
00083 void set_fetcher_time_out_ms(int64 x) {
00084 set_option(x, &fetcher_time_out_ms_);
00085 }
00086 int64 slurp_flush_limit() const {
00087 return slurp_flush_limit_.value();
00088 }
00089 void set_slurp_flush_limit(int64 x) {
00090 set_option(x, &slurp_flush_limit_);
00091 }
00092 bool use_shared_mem_locking() const {
00093 return use_shared_mem_locking_.value();
00094 }
00095 void set_use_shared_mem_locking(bool x) {
00096 set_option(x, &use_shared_mem_locking_);
00097 }
00098 bool collect_referer_statistics() const {
00099 return collect_referer_statistics_.value();
00100 }
00101 void set_collect_referer_statistics(bool x) {
00102 set_option(x, &collect_referer_statistics_);
00103 }
00104 bool hash_referer_statistics() const {
00105 return hash_referer_statistics_.value();
00106 }
00107 void set_hash_referer_statistics(bool x) {
00108 set_option(x, &hash_referer_statistics_);
00109 }
00110 bool statistics_enabled() const {
00111 return statistics_enabled_.value();
00112 }
00113 void set_statistics_enabled(bool x) {
00114 set_option(x, &statistics_enabled_);
00115 }
00116 bool slurp_read_only() const {
00117 return slurp_read_only_.value();
00118 }
00119 void set_slurp_read_only(bool x) {
00120 set_option(x, &slurp_read_only_);
00121 }
00122 RefererStatisticsOutputLevel referer_statistics_output_level() const {
00123 return referer_statistics_output_level_.value();
00124 }
00125 void set_referer_statistics_output_level(RefererStatisticsOutputLevel x) {
00126 set_option(x, &referer_statistics_output_level_);
00127 }
00128 const GoogleString& file_cache_path() const {
00129 return file_cache_path_.value();
00130 }
00131 void set_file_cache_path(GoogleString x) {
00132 set_option(x, &file_cache_path_);
00133 }
00134 const GoogleString& filename_prefix() const {
00135 return filename_prefix_.value();
00136 }
00137 void set_filename_prefix(GoogleString x) {
00138 set_option(x, &filename_prefix_);
00139 }
00140 const GoogleString& slurp_directory() const {
00141 return slurp_directory_.value();
00142 }
00143 void set_slurp_directory(GoogleString x) {
00144 set_option(x, &slurp_directory_);
00145 }
00146 const GoogleString& fetcher_proxy() const {
00147 return fetcher_proxy_.value();
00148 }
00149 void set_fetcher_proxy(GoogleString x) {
00150 set_option(x, &fetcher_proxy_);
00151 }
00152
00155 bool test_proxy() const {
00156 return test_proxy_.value();
00157 }
00158 void set_test_proxy(bool x) {
00159 set_option(x, &test_proxy_);
00160 }
00161
00163 bool slurping_enabled() const {
00164 return !slurp_directory().empty();
00165 }
00166
00167 bool slurping_enabled_read_only() const {
00168 return slurping_enabled() && slurp_read_only();
00169 }
00170
00172 virtual RewriteOptions* Clone() const;
00173
00176 static const ApacheConfig* DynamicCast(const RewriteOptions* instance);
00177 static ApacheConfig* DynamicCast(RewriteOptions* instance);
00178
00180 virtual const char* class_name() const;
00181
00182 protected:
00183 template<class T> class ApacheOption : public OptionTemplateBase<T> {
00184 public:
00185 ApacheOption() {}
00186
00188 virtual bool SetFromString(const GoogleString& value_string) {
00189 T value;
00190 bool success = ApacheConfig::ParseFromString(value_string, &value);
00191 if (success) {
00192 this->set(value);
00193 }
00194 return success;
00195 }
00196
00197 virtual GoogleString Signature(const Hasher* hasher) const {
00198 return ApacheConfig::OptionSignature(this->value(), hasher);
00199 }
00200
00201 virtual GoogleString ToString() const {
00202 return ApacheConfig::ToString(this->value());
00203 }
00204
00205 private:
00206 DISALLOW_COPY_AND_ASSIGN(ApacheOption);
00207 };
00208
00209 private:
00210 void Init();
00211
00212 static bool ParseFromString(const GoogleString& value_string,
00213 RefererStatisticsOutputLevel* value) {
00214 return ParseRefererStatisticsOutputLevel(value_string, value);
00215 }
00216
00217 static GoogleString OptionSignature(RefererStatisticsOutputLevel x,
00218 const Hasher* hasher) {
00221 return IntegerToString(x);
00222 }
00223
00224 static GoogleString ToString(RefererStatisticsOutputLevel x) {
00227 return IntegerToString(x);
00228 }
00229
00230 GoogleString description_;
00231 RewriteOptions options_;
00232
00233 Option<GoogleString> fetcher_proxy_;
00234 Option<GoogleString> file_cache_path_;
00235 Option<GoogleString> filename_prefix_;
00236 Option<GoogleString> slurp_directory_;
00237
00238 ApacheOption<RefererStatisticsOutputLevel> referer_statistics_output_level_;
00239
00240 Option<bool> collect_referer_statistics_;
00241 Option<bool> hash_referer_statistics_;
00242 Option<bool> statistics_enabled_;
00243 Option<bool> test_proxy_;
00244 Option<bool> use_shared_mem_locking_;
00245 Option<bool> slurp_read_only_;
00246
00247 Option<int64> fetcher_time_out_ms_;
00248 Option<int64> file_cache_clean_interval_ms_;
00249 Option<int64> file_cache_clean_size_kb_;
00250 Option<int64> lru_cache_byte_limit_;
00251 Option<int64> lru_cache_kb_per_process_;
00252 Option<int64> slurp_flush_limit_;
00253
00254 DISALLOW_COPY_AND_ASSIGN(ApacheConfig);
00255 };
00256
00257 }
00258
00259 #endif ///< NET_INSTAWEB_APACHE_APACHE_CONFIG_H_