src/ngx_pagespeed.cc
// Parse the configuration option represented by cf and add it to options,
// creating options if necessary.
Parse the configuration option represented by cf and add it to options,
creating options if necessary.
Parse the configuration option represented by cf and add it to options creating options if necessary .
char* ps_configure(ngx_conf_t* cf,
                   NgxRewriteOptions** options,
                   MessageHandler* handler,
                   net_instaweb::RewriteOptions::OptionScope option_scope) {
  ngx_uint_t n_args = cf->args->nelts - 1;
  CHECK(n_args <= NGX_PAGESPEED_MAX_ARGS);
  StringPiece args[NGX_PAGESPEED_MAX_ARGS];
  ngx_str_t* value = static_cast<ngx_str_t*>(cf->args->elts);
  ngx_uint_t i;
  for (i = 0 ; i < n_args ; i++) {
    args[i] = str_to_string_piece(value[i+1]);
  }
  if (n_args == 1) {
    if (StringCaseEqual(args[0], "on")) {
      g_gzip_setter.EnableGZipForLocation(cf);
    } else if (StringCaseEqual(args[0], "off")) {
      g_gzip_setter.SetGZipForLocation(cf, false);
    }
  }
  if (n_args == 2 && args[0].compare("gzip") == 0) {
    if (args[1].compare("on") == 0) {
      g_gzip_setter.SetGZipForLocation(cf, true);
    } else if (args[1].compare("off") == 0) {
      g_gzip_setter.SetGZipForLocation(cf, false);
    } else {
      char* error_message = string_piece_to_pool_string(
          cf->pool, StringPiece("Invalid pagespeed gzip setting"));
      return error_message;
    }
    return NGX_CONF_OK;
  }
  if (n_args == 2 &&
      (net_instaweb::StringCaseEqual("LogDir", args[0]) ||
       net_instaweb::StringCaseEqual("FileCachePath", args[0]))) {
    char* error_message = ps_init_dir(args[0], args[1], cf);
    if (error_message != NULL) {
      return error_message;
    }
  }
  ps_main_conf_t* cfg_m = static_cast<ps_main_conf_t*>(
      ngx_http_cycle_get_module_main_conf(cf->cycle, ngx_pagespeed));
  if (*options == NULL) {
    *options = new NgxRewriteOptions(cfg_m->driver_factory->thread_system());
  }
  ProcessScriptVariablesMode script_mode =
      dynamic_cast<NgxRewriteDriverFactory*>(cfg_m->driver_factory)
          ->process_script_variables();
  if (script_mode != ProcessScriptVariablesMode::kOff) {
    ngx_str_t name = ngx_string("ps_dollar");
    ngx_http_variable_t* var =
        ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE);
    if (var == NULL) {
      return const_cast<char*>(
          "Failed to add global configuration variable for '$ps_dollar'");
    }
    var->get_handler = ps_dollar;
  }
  const char* status = (*options)->ParseAndSetOptions(
      args, n_args, cf->pool, handler, cfg_m->driver_factory, option_scope, cf,
      script_mode);
  return const_cast<char*>(status);
}
char * ps_configure ( ngx_conf_t * cf , NgxRewriteOptions * * options , MessageHandler * handler , net_instaweb :: RewriteOptions :: OptionScope option_scope ) { ngx_uint_t n_args = cf -> args -> nelts - 1 ; CHECK ( n_args <= NGX_PAGESPEED_MAX_ARGS ) ; StringPiece args [ NGX_PAGESPEED_MAX_ARGS ] ; ngx_str_t * value = static_cast < ngx_str_t * > ( cf -> args -> elts ) ; ngx_uint_t i ; for ( i = 0 ; i < n_args ; i ++ ) { args [ i ] = str_to_string_piece ( value [ i + 1 ] ) ; } if ( n_args == 1 ) { if ( StringCaseEqual ( args [ 0 ] , " " ) ) { g_gzip_setter . EnableGZipForLocation ( cf ) ; } else if ( StringCaseEqual ( args [ 0 ] , " " ) ) { g_gzip_setter . SetGZipForLocation ( cf , false ) ; } } if ( n_args == 2 && args [ 0 ] . compare ( " " ) == 0 ) { if ( args [ 1 ] . compare ( " " ) == 0 ) { g_gzip_setter . SetGZipForLocation ( cf , true ) ; } else if ( args [ 1 ] . compare ( " " ) == 0 ) { g_gzip_setter . SetGZipForLocation ( cf , false ) ; } else { char * error_message = string_piece_to_pool_string ( cf -> pool , StringPiece ( " " ) ) ; return error_message ; } return NGX_CONF_OK ; } if ( n_args == 2 && ( net_instaweb :: StringCaseEqual ( " " , args [ 0 ] ) || net_instaweb :: StringCaseEqual ( " " , args [ 0 ] ) ) ) { char * error_message = ps_init_dir ( args [ 0 ] , args [ 1 ] , cf ) ; if ( error_message != NULL ) { return error_message ; } } ps_main_conf_t * cfg_m = static_cast < ps_main_conf_t * > ( ngx_http_cycle_get_module_main_conf ( cf -> cycle , ngx_pagespeed ) ) ; if ( * options == NULL ) { * options = new NgxRewriteOptions ( cfg_m -> driver_factory -> thread_system ( ) ) ; } ProcessScriptVariablesMode script_mode = dynamic_cast < NgxRewriteDriverFactory * > ( cfg_m -> driver_factory ) -> process_script_variables ( ) ; if ( script_mode != ProcessScriptVariablesMode :: kOff ) { ngx_str_t name = ngx_string ( " " ) ; ngx_http_variable_t * var = ngx_http_add_variable ( cf , & name , NGX_HTTP_VAR_CHANGEABLE ) ; if ( var == NULL ) { return const_cast < char * > ( " " ) ; } var -> get_handler = ps_dollar ; } const char * status = ( * options ) -> ParseAndSetOptions ( args , n_args , cf -> pool , handler , cfg_m -> driver_factory , option_scope , cf , script_mode ) ; return const_cast < char * > ( status ) ; }
Parse the configuration option represented by cf and add it to options,
creating options if necessary.
Parse the configuration option represented by cf and add it to options creating options if necessary .
// args[0] is always "pagespeed"; ignore it. // In ps_commands we only register 'pagespeed' as taking up to // five arguments, so this check should never fire. // safe to call if the setter is disabled // Some options require the worker process to be able to read and write to // a specific directory.  Generally the master process is root while the // worker is nobody, so we need to change permissions and create the directory // if necessary. // The directory has been prepared, but we haven't actually parsed the // directive yet.  That happens below in ParseAndSetOptions(). // To be able to use '$', we map '$ps_dollar' to '$' via a script variable. // nginx expects us to return a string literal but doesn't mark it const.