Chinaunix首页 | 论坛 | 博客
  • 博客访问: 753571
  • 博文数量: 274
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 862
  • 用 户 组: 普通用户
  • 注册时间: 2015-10-24 15:31
个人简介

不合格的程序猿

文章分类

全部博文(274)

文章存档

2019年(3)

2018年(1)

2017年(4)

2016年(160)

2015年(106)

我的朋友

分类: 服务器与存储

2016-01-04 11:29:42

原文地址:Apache 模块开发总结 作者:GilBert1987

因为项目的原因需要使用Apache 模块开发(Apache + C++),现在总结如下:
modules.c文件结构-->modules.so

点击(此处)折叠或打开

  1. module AP_MODULE_DECLARE_DATA get_service_module;

  2. 配置文件的内存结构
  3. typedef struct
  4. {
  5.     const char* dataFolder;
  6. }Service_Conf_Rec;

  7. static void *create_services_config(apr_pool_t *p, char* d)
  8. {
  9.     Service_Conf_Rec *conf = (Service_Conf_Rec *)apr_pcalloc(p, sizeof(*conf));
  10.     if(conf == NULL) return NULL;
  11.     return conf;
  12. }
  13. //读取DataFolder的参数的具体函数
  14. static const char * readDataFolder(cmd_parms *cmd, void *mconfig, const char*name)
  15. {
  16.     Service_Conf_Rec *conf = (Service_Conf_Rec*)mconfig;
  17.     conf->dataFolder = apr_pstrdup(cmd->pool, name);
  18.     return NULL;
  19. }

  20. static const command_rec services_conf[] =
  21. {
  22.     AP_INIT_TAKE1("DataFolder", readDataFolder, NULL, OR_FILEINFO, "invalid data folder"),
  23.     {NULL}
  24. };


  25. module AP_MODULE_DECLARE_DATA get_service_module = {
  26.     STANDARD20_MODULE_STUFF,
  27.     create_services_config, /* create per-dir config structures */
  28.     NULL, /* merge per-dir config structures */
  29.     NULL, /* create per-server config structures */
  30.     NULL, /* merge per-server config structures */
  31.     services_conf, /* table of config file commands */
  32.     get_service_register_hooks /* register hooks */
  33. };

  34. static void get_service_register_hooks(apr_pool_t *p)
  35. {
  36.     ap_hook_handler(get_service_handler, NULL, NULL, APR_HOOK_MIDDLE);
  37. }

  38. static int get_service_handler(request_rec *r)
  39. {
  40.     Service_Conf_Rec *conf = ap_get_module_config(r->per_dir_config, &get_service_module) ;
  41. C函数调用
  42.     //读取配置文件
  43.     //对请求进行处理-->调用ServiceApi.cpp中的函数(dlopen-->call service.so function)
  44. }

ServiceApi.cpp-->service.so

点击(此处)折叠或打开

  1. #ifndef _SERVICESAPI_H
  2. #define _SERVICESAPI_H

  3. #ifdef __cplusplus
  4. extern "C" {

  5. void Services_Init(...);
  6. void Services_Finish(...);
  7. #ifdef __cplusplus
  8. }
  9. #endif

  10. #endif



阅读(858) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~