The Apache module development summary

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
Because the project reasons to use Apache module development (Apache + C++), now summarized as follows:

Modules.c file structure>modules.so
  1. module AP_MODULE_DECLARE_DATA get_service_module;

  2. Memory configuration file
  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. //The specific function of parameter DataFolder to read the
  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. The C function calls
  42.     //Read the configuration file
  43.     //The request is processed --> function call in 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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Rose at November 27, 2013 - 10:25 AM