Exemple #1
0
AP_LUA_DECLARE(apr_status_t) ap_lua_map_handler(ap_lua_dir_cfg *cfg,
                                                 const char *file,
                                                 const char *function,
                                                 const char *pattern,
                                                 const char *scope)
{
    ap_regex_t *uri_pattern;
    apr_status_t rv;
    ap_lua_mapped_handler_spec *handler =
        apr_pcalloc(cfg->pool, sizeof(ap_lua_mapped_handler_spec));
    handler->uri_pattern = NULL;
    handler->function_name = NULL;

    uri_pattern = apr_palloc(cfg->pool, sizeof(ap_regex_t));
    if ((rv = ap_regcomp(uri_pattern, pattern, 0)) != APR_SUCCESS) {
        return rv;
    }
    handler->file_name = apr_pstrdup(cfg->pool, file);
    handler->uri_pattern = uri_pattern;
    handler->scope = apl_toscope(scope);

    handler->function_name = apr_pstrdup(cfg->pool, function);
    *(const ap_lua_mapped_handler_spec **) apr_array_push(cfg->mapped_handlers) =
        handler;
    return APR_SUCCESS;
}
Exemple #2
0
static const char * set_serverremap(cmd_parms *cmd, void *CFG, const char *args)
{
  cdn_conf *cfg = (cdn_conf *)CFG;
  server_remap_t *remap;
  unsigned int regflags = 0;
  const char *pattern, *flags;
  const char *usage = "Usage: CDNHTMLRemapURLServer pattern [flags]";

  pattern = ap_getword_conf(cmd->pool, &args);
  if(!pattern)
    return usage;
  flags = ap_getword_conf(cmd->pool, &args);
  if(flags && !*flags)
    flags = NULL;

  if(cfg->map == NULL)
    cfg->map = apr_array_make(cmd->pool, 4, sizeof(server_remap_t));
  remap = apr_array_push(cfg->map);

  regflags = AP_REG_NOSUB | FLAG(AP_REG_EXTENDED, flags, 'x') |
    FLAG(AP_REG_ICASE, flags, 'i');
  if(ap_regcomp(&(remap->regex), pattern, regflags) != 0)
    return "CDNHTMLRemapURLServer: error compiling regex";

  remap->flags |= FLAG(REMAP_FLAG_AUTH, flags, 'a') |
    FLAG(REMAP_FLAG_QSTRING_IGNORE, flags, 'q');

  return NULL;
}
Exemple #3
0
/* Change to use ap_lua_map_handler */
static int cfg_lua_map_handler(lua_State *L)
{
    ap_lua_dir_cfg *cfg = check_dir_config(L, 1);
    ap_lua_mapped_handler_spec *handler =
        apr_pcalloc(cfg->pool, sizeof(ap_lua_mapped_handler_spec));
    handler->uri_pattern = NULL;
    handler->function_name = NULL;

    luaL_checktype(L, 2, LUA_TTABLE);
    lua_getfield(L, 2, "file");
    if (lua_isstring(L, -1)) {
        const char *file = lua_tostring(L, -1);
        handler->file_name = apr_pstrdup(cfg->pool, file);
    }
    lua_pop(L, 1);

    lua_getfield(L, 2, "pattern");
    if (lua_isstring(L, -1)) {
        const char *pattern = lua_tostring(L, -1);

        ap_regex_t *uri_pattern = apr_palloc(cfg->pool, sizeof(ap_regex_t));
        if (ap_regcomp(uri_pattern, pattern, 0) != OK) {
            return luaL_error(L, "Unable to compile regular expression, '%s'",
                              pattern);
        }
        handler->uri_pattern = uri_pattern;
    }
    lua_pop(L, 1);

    lua_getfield(L, 2, "scope");
    if (lua_isstring(L, -1)) {
        const char *scope = lua_tostring(L, -1);
        handler->scope = apl_toscope(scope);
    }
    else {
        handler->scope = AP_LUA_SCOPE_ONCE;
    }
    lua_pop(L, 1);

    lua_getfield(L, 2, "func");
    if (lua_isstring(L, -1)) {
        const char *value = lua_tostring(L, -1);
        handler->function_name = apr_pstrdup(cfg->pool, value);
    }
    else {
        handler->function_name = "handle";
    }
    lua_pop(L, 1);


    *(const ap_lua_mapped_handler_spec **) apr_array_push(cfg->mapped_handlers) =
        handler;
    return 0;
}
Exemple #4
0
static const char * set_act_as_origin(cmd_parms *cmd, void *CFG, const char *args)
{
  cdn_conf *cfg = (cdn_conf *)CFG;
  act_as_origin_t *orig;
  unsigned int regflags = 0;
  const char *pattern, *flags, *exptime;
  const char *usage = "Usage: CDNActAsOrigin pattern [flags] [exptime]";

  pattern = ap_getword_conf(cmd->pool, &args);
  if(!pattern)
    return usage;
  flags = ap_getword_conf(cmd->pool, &args);
  if(flags && !*flags)
    flags = NULL;
  exptime = ap_getword_conf(cmd->pool, &args);
  if(exptime && !*exptime)
    exptime = NULL;

  if(cfg->originify == NULL)
    cfg->originify = apr_array_make(cmd->pool, 4, sizeof(act_as_origin_t));
  orig = apr_array_push(cfg->originify);

  regflags = AP_REG_NOSUB | FLAG(AP_REG_EXTENDED, flags, 'x') |
    FLAG(AP_REG_ICASE, flags, 'i');
  if(ap_regcomp(&(orig->regex), pattern, regflags) != 0)
    return "CDNActAsOrigin: error compiling regex";

  orig->flags |= FLAG(ORIGINIFY_FLAG_EXPIRE, flags, 'e') |
    FLAG(ORIGINIFY_FLAG_AUTH, flags, 'a');

  if(orig->flags & ORIGINIFY_FLAG_EXPIRE) {
    if(exptime) {
      errno = 0;
      orig->exptime = strtol(exptime, NULL, 10);
      if(errno)
        return "CDNActAsOrigin: error setting expiration time";
    } else if(cfg->default_exptime) {
      orig->exptime = cfg->default_exptime;
    } else
      return "CDNActAsOrigin: expiration flag set but no expiration time given";
  }

  return NULL;
}