gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 06:12:15 25 4
gpt4 key购买 nike

我正在尝试使用“指令处理函数”部分中的示例代码在 Apache 服务器中设置指令 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;
}

但是,当我尝试构建时,出现以下错误:

错误:从不兼容的指针类型初始化 [-Werror] AP_INIT_TAKE1("examplePath", example_set_path, NULL, ACCESS_CONF, "The path to whatever")

我是不是错过了什么?

谢谢

最佳答案

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

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

函数定义为...

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

关于c++ - 在 Apache 服务器中设置指令时出现不兼容的指针类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31029516/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com