apache 模块开发提示错误Cant locate api module

在网上找了两个关于apache模块开发的例子代码(引用博客地址忘记,博主请原谅):如配置文件的代码如下:(提示错误Cant locate api module...)原因是由于编译c++。不是c。添加extern “C"之后便可。


//该模块的配置信息定义一个结构。
typedef struct
{
  short IsAll;
  const  char *gpfpath;
}auth_jira_conf;

//声明模块名称
extern module AP_MODULE_DECLARE_DATA pathtest_module;



// 测试用的handler实际。输出从配置文件中读入的配置信息。
static int pathtest_handler(request_rec *r)
{
   r->content_type = "text/html";
   //取conf数据
  auth_jira_conf *conf = (auth_jira_conf *)ap_get_module_config(r->per_dir_config,
    &pathtest_module);
  ap_rprintf(r, "IsAll:%d\n",conf->IsAll);
  ap_rprintf(r, "path:%s",conf->gpfpath);
   return OK;
}

static void pathtest_register_hooks(apr_pool_t *p)
{
     ap_hook_handler(pathtest_handler, NULL, NULL, APR_HOOK_MIDDLE);
}

/* 设置IsAll字段的读放法 */
static const char *set_authjira_is_all_check(cmd_parms *cmd,
                                             void *mconfig,
                                             int arg)
{
  auth_jira_conf *conf = (auth_jira_conf *) mconfig;
  conf->IsAll = arg;
  return NULL;
}
/* 读取设置某个文件的字符串方法,对于文件,判断文件是否有效 */
static const char *set_jira_group_file(cmd_parms *cmd,
                                          void *mconfig,
                                          const char *name)
{
  auth_jira_conf *conf = (auth_jira_conf *) mconfig;
  /*ap_configfile_t *f = NULL;
  apr_status_t status;

  if(strlen(name) <= 0)
    return "File can not be null.";

  status = ap_pcfg_openfile(&f, cmd->pool, name);

  if (status != APR_SUCCESS) {
    return “Can not open given  file.”;
  }
  ap_cfg_closefile(f);*/

  conf->gpfpath = apr_pstrdup(cmd->pool, name);

  return NULL;
}
/* init per dir */
static void *create_authjira_dir_config(apr_pool_t *p, char *d)
{
  auth_jira_conf *conf = (auth_jira_conf *)apr_pcalloc(p, sizeof(*conf));
  if(conf == NULL) return NULL;
  conf->gpfpath         = d;
  return conf;
}

///AP_INIT_TAKE1 ( "Configure", ( const char* ( * ) () ) uni_set_server_config, NULL, OR_ALL, "Configure" ),
//    AP_INIT_TAKE1 ( "MagicString", ( const char* ( * ) () ) uni_set_server_config, NULL, OR_ALL, "MagicString" ),
//对应的http.conf的命令读到方法。
static const command_rec authn_jira_cmds[] =
{
  AP_INIT_FLAG("IsAllCheck", ( const char* ( * ) () )set_authjira_is_all_check, NULL, OR_FILEINFO,
  "enable authSVN or not."),
  AP_INIT_TAKE1("filepath", ( const char* ( * ) () )set_jira_group_file,   NULL, OR_FILEINFO,
 "set jira group file."),
  { NULL }
};




/* Dispatch list for API hooks */
module AP_MODULE_DECLARE_DATA pathtest_module = {
    STANDARD20_MODULE_STUFF,
    create_authjira_dir_config, /* create per-dir    config structures */
    NULL,                  /* merge per-dir    config structures */
    NULL,                  /* create per-server config structures */
    NULL,                  /* merge per-server config structures */
    authn_jira_cmds,                  /* table of config file commands       */
    pathtest_register_hooks /* register hooks                      */
};



在httpd.conf中添加LoadModule pathtest_module modules/mod_pathtest.dll      
<Location /pathtest>
IsAllCheck on
filepath E:\Code\QGIS_Practice\pqsql_\mod_pathtest
SetHandler pathtest
</Location>

启动成功。

测试如下:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值