在Apache服务器中设置指令时出现不兼容的指针类型错误

Incompatible pointer type error while setting directives in Apache server

本文关键字:不兼容 指针 错误 类型 服务器 Apache 设置 指令      更新时间:2023-10-16

我正试图使用位于http://httpd.apache.org/docs/2.4/developer/modguide.html.

这是我的代码:

static const command_rec example_directives[] =
{
    AP_INIT_TAKE1("exampleEnabled", example_set_enabled, NULL, ACCESS_CONF, "Enable or disable mod_privet"),
    AP_INIT_TAKE1("examplePath", example_set_path, NULL, ACCESS_CONF, "The path to whatever"),
    AP_INIT_TAKE2("exampleAction", example_set_action, NULL, ACCESS_CONF, "Special action value!"),
    { NULL }
};
Handler for directives:

/* Handler for the "exampleEnabled" directive */
const char *example_set_enabled(cmd_parms *cmd, void *cfg, const char *arg)
{
    if(!strcasecmp(arg, "on")) config.enabled = 1;
    else config.enabled = 0;
    return NULL;
}
/* Handler for the "examplePath" directive */
const char *example_set_path(cmd_parms *cmd, void *cfg, char *arg)
{
    config.path = arg;
    return NULL;
}
/* Handler for the "exampleAction" directive */
/* Let's pretend this one takes one argument (file or db), and a second (deny or allow), */
/* and we store it in a bit-wise manner. */
const char *example_set_action(cmd_parms *cmd, void *cfg, const char *arg1, const char *arg2)
{
    if(!strcasecmp(arg1, "file")) config.typeOfAction = 0x01;
    else config.typeOfAction = 0x02;
    if(!strcasecmp(arg2, "deny")) config.typeOfAction += 0x10;
    else config.typeOfAction += 0x20;
    return NULL;
}

然而,当我尝试构建时,我会得到以下错误:

错误:从不兼容的指针类型进行初始化[-Weror]AP_INIT_TAKE1("examplePath",example_set_path,NULL,ACCESS_CONF,"到任何东西的路径")

我是不是错过了什么?

感谢

example_set_path的第三个参数应该是const char *arg

#define AP_INIT_TAKE1 ( directive,  
  func,  
  mconfig,  
  where,  
  help    )     { directive, { .take1=func }, mconfig, where, TAKE1, help } 

func被定义为…

const char *(*  take1 )(cmd_parms *parms, void *mconfig, const char *w)