2015-06-24 30 views
0

我試圖在 http://httpd.apache.org/docs/2.4/developer/modguide.html使用示例代碼中的示例代碼在Apache服務器中設置僞指令。在Apache服務器中設置僞指令時不兼容的指針類型錯誤

這裏是我的代碼:

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,「任何路徑」)

我錯過了什麼嗎?

感謝

+0

誰偷走了你的'.c'文件? :-) –

+0

它是'C'代碼還是'C++'?如果'C++',嘗試添加轉換到'const char *',如果'C',則使用'C'編譯器。 –

+1

你是否包含http_config.h? – Les

回答

1
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) 
+0

'const char * example_set_enabled(cmd_parms * cmd,void * cfg,const char * arg)'......現在是什麼? –

+1

抱歉,我的意思是example_set_path,編輯我的回答 – Les

+0

@Les ...當我更改爲const char * arg時,出現以下錯誤:函數'example_set_path'錯誤:賦值丟棄指針目標類型的'const'限定符[-Werror ] config.path = arg; – ap6491