SlideShare a Scribd company logo
Building Apache Modules



Marian HackMan Marinov       E-Mail: mm@1h.com
Founder and CEO of 1H Ltd.   Jabber: hackman@jabber.org
Apache architecture



➢ Request handling
➢ Memory handling
➢ Module architecture
Request handling
1. Just after reading the request (no parsing has been done)
2. Resolve the file name that this URI is trying to access
3. Parse the headers
4. Check access (allow/deny IP/Net/Host)
5. Check the authentication
6. Only if authenticated
7. Check and set the request MIME type
8. Generic fixups
9. Check which (module)function will handle the request
10. Do something before the actual log is called
Request handling
Apache 2.x has two additional hooks:
➢ map_to_storage – runs just before the header
  parser
  ➢ Reads the per-directory configuration
➢ insert_filter – runs just before the handlers
  ➢ Insert content filter
Apache memory pools
➢ Apache allocate memory on pools, which are shared
    across all modules within the same child
    process/thread.
➢ malloc/free is handled by Apache
➢ configuration is copied across all child processes
➢ misbehaving modules within Apache(mod_php)
➢ Apache common functions
    ➢ Apache 1.3 - palloc()
    ➢ Apaceh 2.x – palloc(), string handling
➢
Module architecture



➢ Options table
➢ Access table
➢ Authentication table
➢ Handlers table
How to start

➢ mod_example
  ➢ Apache 1.3
    src/modules/example/mod_example.c
  ➢ Apache 2.x
    modules/experimental/mod_example.c
➢ Include files
Structure of a module



➢ Includes
➢ Module name
➢ Module definition
➢ Module commands (options)
➢ Module configuration
Includes
➢ httpd.h - the main include (consider it as, stdio.h)
  ➢ conn_rec, server_rec, request_rec, apache common
    functions
➢ http_config.h - configuration
  ➢ module command definitions
  ➢ additional functions related to the apache
    configuration
➢ http_request.h - request handling functions
➢ http_protocol.h - low level direct manipulation of
 the request
Includes
➢ http_core.h - this file gives you everything that is
  actually provided by mod_core
➢ http_main.h - apache server handling
➢ http_log.h - logging facilities
  ➢ For Apache 2.0 and 2.2
     ➢ some apache common functions are moved in apr_strings.h
     ➢ in order to use the request and protocol functionality you would
       need also http_connection.h
     ➢ if you need server implementation functions you need ap_mpm.h
➢ These are not all includes that you may need in your
  modules
Module names


#ifdef APACHE2
module AP_MODULE_DECLARE_DATA
example_module;
#else
module MODULE_VAR_EXPORT example_module;
#endif
Module definition



➢ Apache 1.3
➢ Apache 2.x
Apache 1.3
module MODULE_VAR_EXPORT example_module = {
 STANDARD_MODULE_STUFF,
 NULL, /* module initializer */
 NULL, /* per-directory config creator */
 NULL, /* dir config merger */
 NULL, /* server config creator */
 NULL, /* server config merger */
 NULL, /* command table */
 NULL, /* [9] list of handlers */
 NULL, /* [2] filename-to-URI translation */
 NULL, /* [5] check/validate user_id */
Apache 1.3
     NULL, /* [6] check user_id is valid *here* */
     NULL, /* [4] check access by host address */
     NULL, /* [7] MIME type checker/setter */
     NULL, /* [8] fixups */
     NULL, /* [10] logger */
     NULL, /* [3] header parser */
     NULL, /* process initializer */
     NULL, /* process exit/cleanup */
     NULL /* [1] post read_request handling */
};
Apache 2.x
module AP_MODULE_DECLARE_DATA example_module = {
     STANDARD20_MODULE_STUFF,
     NULL, /* per-directory config creator */
     NULL, /* dir config merger */
     NULL, /* server config creator */
     NULL, /* server config merger */
     NULL, /* command table */
     NULL, /* set up other request processing hooks */
};


static void register_hooks(apr_pool_t *p) {
     static const char * const aszPost[] = { "mod_setenvif.c", NULL };
     /* 19 different processing hooks available */
}
Module initialization
➢ Apache 1.3
  ➢ startup and live
  ➢ the function is called two times
➢ Apache 2.0/2.2 module structure
  ➢ pre-config
  ➢ post-config
Creating new configuration
            directives


➢ Define them in the module configuration
 structure
➢ Define new module commands(options)
➢ Create functions to actually set the options,
 when found in the config
Module configuration structure

typedef struct {
     double        dummy_double;
     int           dummy_int;
     char          *dummy_char;
     array_header *dummy_array;
} example_conf;
Array handling
struct ip_range *net;
char *proxies[] = IP_RANGES;
pool *p;
conf->nets = ap_make_array(p, IP_RANGES_COUNT,
                                        sizeof(struct ip_range));
for (i = 0; i < IP_RANGES_COUNT; i++) {
    net = (struct ip_range *) ap_push_array(conf->nets);
    parse_ip( p, proxies[ i ], net );
}
Module commands(options)
➢ Apache 1.3
static const command_rec example_cmds[] = {
     {
          "Example",
          cmd_example,
          NULL,        /* argument to include in call */
          OR_OPTIONS,
          NO_ARGS,
          "Example directive - no arguments"
     },
     {NULL}
};
Module commands(options)
➢ Apache 2.x
static const command_rec x_cmds[] = {
     AP_INIT_NO_ARGS(
          "Example",
          cmd_example,
          NULL,        /* argument to include in call */
          OR_OPTIONS,
          "Example directive - no arguments"
     ),
     {NULL}
};
Possible arguments
➢ FLAG        => One of 'On' or 'Off'
➢ NO_ARGS     => No args at all, e.g. </Directory>
➢ RAW_ARGS => cmd_func parses command line itself
➢ TAKE1       => one argument only
➢ TAKE2       => two arguments only
➢ ITERATE     => one argument, occuring multiple times
➢ ITERATE2    => two arguments, 2nd occurs multiple times
➢ TAKE12      => one or two arguments
➢ TAKE3       => three arguments only
➢ TAKE23      => two or three arguments
➢ TAKE123     => one, two or three arguments
➢ TAKE13      => one or three arguments
Allowed locations for
        configuration directives
➢ RSRC_CONF      => *.conf outside <Directory> or <Location>
➢ ACCESS_CONF => *.conf inside <Directory> or <Location>
➢ OR_AUTHCFG) => *.conf inside <Directory> or <Location>
                and .htaccess when AllowOverride AuthConfig
➢ OR_LIMIT)      => *.conf inside <Directory> or <Location>
                and .htaccess when AllowOverride Limit
➢ OR_OPTIONS) => *.conf anywhere
                and .htaccess when AllowOverride Options
➢ OR_FILEINFO) => *.conf anywhere
                and .htaccess when AllowOverride FileInfo
➢ OR_INDEXES) => *.conf anywhere
                and .htaccess when AllowOverride Indexes
Module command handlers
static const char *set_examplecmd(cmd_parms *cmd, void *vconf, char *arg) {
      example_conf *conf = (example_conf *) vconf;
      if (cmd->path == NULL) {
            conf = (example_conf *)
                  ap_get_module_config(cmd->server->module_config, &example_module);
#ifdef DEBUG_OPTIONS
            fprintf(stderr, "mod_example: (%s:%d)Example (server)n",
                   cmd->config_file->name, cmd->config_file->line_number);
      } else {
            fprintf(stderr, "mod_example: (%s:%d)RelaxPerms (dir)n",
                   cmd->config_file->name, cmd->config_file->line_number);
#endif
      }
   conf->dummy_char = ap_pstrdup(cmd->pool, arg);
   return NULL;
}
Handling configuration directives



➢ Global vs. Vhost configuration
➢ Per directory/files/location
➢ Merge of the global and per-vhost configuration
➢ Initialization of the configuration
Logging
➢ ap_log_error(APLOG_MARK, APLOG_INFO,
                                 r->server, "Some string");
➢ ap_log_rerror(APLOG_MARK, APLOG_INFO,
                                 r, "Some string");
 ➢ Apache 2.x
    ➢ Added ap_log_cerror() for conn_rec handling
    ➢ Added ap_log_perror() for everything that is not server,
      record or connection related
    ➢ Added status code between the server and level
Writing portable modules
➢ Porting tricks
  #ifndef APACHE_RELEASE
  #define APACHE2
  #endif


➢ Apache common functions
  ➢ ap_palloc(1.3) -> apr_palloc(2.x)
Additional resources
http://httpd.apache.org/docs/2.2/developer/
Thank you




??? Questions ???

     Thank you

More Related Content

What's hot (20)

PDF
PHP 7 new engine
julien pauli
 
PDF
Configuration Surgery with Augeas
Puppet
 
PPTX
Introduction to ansible
Omid Vahdaty
 
PDF
Quick tour of PHP from inside
julien pauli
 
ODP
Php in 2013 (Web-5 2013 conference)
julien pauli
 
PPT
How PHP Works ?
Ravi Raj
 
PDF
Ansible leveraging 2.0
bcoca
 
PDF
Ansible tips & tricks
bcoca
 
PDF
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
Jumping Bean
 
PDF
Ansible - Introduction
Stephane Manciot
 
PDF
Ansible is the simplest way to automate. MoldCamp, 2015
Alex S
 
PDF
Configuration Management in Ansible
Bangladesh Network Operators Group
 
ODP
Sahul
sahul azzez m.i
 
KEY
Node.js basics
Ben Lin
 
PDF
Writing and Publishing Puppet Modules - PuppetConf 2014
Puppet
 
ODP
PHP5.5 is Here
julien pauli
 
PDF
PostgreSQL and PL/Java
Peter Eisentraut
 
PPTX
Virtualization and automation of library software/machines + Puppet
Omar Reygaert
 
PDF
Profiling php5 to php7
julien pauli
 
PHP 7 new engine
julien pauli
 
Configuration Surgery with Augeas
Puppet
 
Introduction to ansible
Omid Vahdaty
 
Quick tour of PHP from inside
julien pauli
 
Php in 2013 (Web-5 2013 conference)
julien pauli
 
How PHP Works ?
Ravi Raj
 
Ansible leveraging 2.0
bcoca
 
Ansible tips & tricks
bcoca
 
DevOpsDaysCPT Ansible Infrastrucutre as Code 2017
Jumping Bean
 
Ansible - Introduction
Stephane Manciot
 
Ansible is the simplest way to automate. MoldCamp, 2015
Alex S
 
Configuration Management in Ansible
Bangladesh Network Operators Group
 
Node.js basics
Ben Lin
 
Writing and Publishing Puppet Modules - PuppetConf 2014
Puppet
 
PHP5.5 is Here
julien pauli
 
PostgreSQL and PL/Java
Peter Eisentraut
 
Virtualization and automation of library software/machines + Puppet
Omar Reygaert
 
Profiling php5 to php7
julien pauli
 

Similar to Building apache modules (20)

PDF
Odoo command line interface
Jalal Zahid
 
PDF
Apache Cheat Sheet
JonathanThorpe7
 
PDF
Apache Hacks
Beth Skwarecki
 
PPTX
Introduction to Apache Mesos
Joe Stein
 
DOCX
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
ChereCheek752
 
PPTX
Learning Puppet basic thing
DaeHyung Lee
 
PDF
Apache2 BootCamp : Getting Started With Apache
Wildan Maulana
 
PPTX
TO Hack an ASP .NET website?
Positive Hack Days
 
PPTX
Performance all teh things
Marcus Deglos
 
PPTX
Hack ASP.NET website
Positive Hack Days
 
ODP
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...
Nagios
 
PPT
Unix kernal
Shehrevar Davierwala
 
PDF
linux installation.pdf
MuhammadShoaibHussai2
 
PDF
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
Ortus Solutions, Corp
 
PDF
Extending functionality in nginx, with modules!
Trygve Vea
 
PDF
GopherCon IL 2020 - Web Application Profiling 101
yinonavraham
 
DOC
X64服务器 lnmp服务器部署标准 new
Yiwei Ma
 
PDF
Advfs system calls & kernel interfaces
Justin Goldberg
 
PDF
SELinux Kernel Internals and Architecture - FOSS.IN/2005
James Morris
 
PDF
Tips
mclee
 
Odoo command line interface
Jalal Zahid
 
Apache Cheat Sheet
JonathanThorpe7
 
Apache Hacks
Beth Skwarecki
 
Introduction to Apache Mesos
Joe Stein
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
ChereCheek752
 
Learning Puppet basic thing
DaeHyung Lee
 
Apache2 BootCamp : Getting Started With Apache
Wildan Maulana
 
TO Hack an ASP .NET website?
Positive Hack Days
 
Performance all teh things
Marcus Deglos
 
Hack ASP.NET website
Positive Hack Days
 
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...
Nagios
 
linux installation.pdf
MuhammadShoaibHussai2
 
ITB_2023_CommandBox_Task_Runners_Brad_Wood.pdf
Ortus Solutions, Corp
 
Extending functionality in nginx, with modules!
Trygve Vea
 
GopherCon IL 2020 - Web Application Profiling 101
yinonavraham
 
X64服务器 lnmp服务器部署标准 new
Yiwei Ma
 
Advfs system calls & kernel interfaces
Justin Goldberg
 
SELinux Kernel Internals and Architecture - FOSS.IN/2005
James Morris
 
Tips
mclee
 
Ad

More from Marian Marinov (20)

PDF
How to start and then move forward in IT
Marian Marinov
 
PDF
Thinking about highly-available systems and their setup
Marian Marinov
 
PDF
Understanding your memory usage under Linux
Marian Marinov
 
PDF
How to implement PassKeys in your application
Marian Marinov
 
PDF
Dev.bg DevOps March 2024 Monitoring & Logging
Marian Marinov
 
PDF
Basic presentation of cryptography mechanisms
Marian Marinov
 
PDF
Microservices: Benefits, drawbacks and are they for me?
Marian Marinov
 
PDF
Introduction and replication to DragonflyDB
Marian Marinov
 
PDF
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Marian Marinov
 
PDF
How to successfully migrate to DevOps .pdf
Marian Marinov
 
PDF
How to survive in the work from home era
Marian Marinov
 
PDF
Managing sysadmins
Marian Marinov
 
PDF
Improve your storage with bcachefs
Marian Marinov
 
PDF
Control your service resources with systemd
Marian Marinov
 
PDF
Comparison of-foss-distributed-storage
Marian Marinov
 
PDF
Защо и как да обогатяваме знанията си?
Marian Marinov
 
PDF
Securing your MySQL server
Marian Marinov
 
PDF
Sysadmin vs. dev ops
Marian Marinov
 
PDF
DoS and DDoS mitigations with eBPF, XDP and DPDK
Marian Marinov
 
PDF
Challenges with high density networks
Marian Marinov
 
How to start and then move forward in IT
Marian Marinov
 
Thinking about highly-available systems and their setup
Marian Marinov
 
Understanding your memory usage under Linux
Marian Marinov
 
How to implement PassKeys in your application
Marian Marinov
 
Dev.bg DevOps March 2024 Monitoring & Logging
Marian Marinov
 
Basic presentation of cryptography mechanisms
Marian Marinov
 
Microservices: Benefits, drawbacks and are they for me?
Marian Marinov
 
Introduction and replication to DragonflyDB
Marian Marinov
 
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Marian Marinov
 
How to successfully migrate to DevOps .pdf
Marian Marinov
 
How to survive in the work from home era
Marian Marinov
 
Managing sysadmins
Marian Marinov
 
Improve your storage with bcachefs
Marian Marinov
 
Control your service resources with systemd
Marian Marinov
 
Comparison of-foss-distributed-storage
Marian Marinov
 
Защо и как да обогатяваме знанията си?
Marian Marinov
 
Securing your MySQL server
Marian Marinov
 
Sysadmin vs. dev ops
Marian Marinov
 
DoS and DDoS mitigations with eBPF, XDP and DPDK
Marian Marinov
 
Challenges with high density networks
Marian Marinov
 
Ad

Recently uploaded (20)

PDF
Rethinking Security Operations - SOC Evolution Journey.pdf
Haris Chughtai
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PDF
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
Top Managed Service Providers in Los Angeles
Captain IT
 
PDF
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
Women in Automation Presents: Reinventing Yourself — Bold Career Pivots That ...
DianaGray10
 
PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
Rethinking Security Operations - SOC Evolution Journey.pdf
Haris Chughtai
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
Meetup Kickoff & Welcome - Rohit Yadav, CSIUG Chairman
ShapeBlue
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
July Patch Tuesday
Ivanti
 
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Top Managed Service Providers in Los Angeles
Captain IT
 
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Women in Automation Presents: Reinventing Yourself — Bold Career Pivots That ...
DianaGray10
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 

Building apache modules

  • 1. Building Apache Modules Marian HackMan Marinov E-Mail: [email protected] Founder and CEO of 1H Ltd. Jabber: [email protected]
  • 2. Apache architecture ➢ Request handling ➢ Memory handling ➢ Module architecture
  • 3. Request handling 1. Just after reading the request (no parsing has been done) 2. Resolve the file name that this URI is trying to access 3. Parse the headers 4. Check access (allow/deny IP/Net/Host) 5. Check the authentication 6. Only if authenticated 7. Check and set the request MIME type 8. Generic fixups 9. Check which (module)function will handle the request 10. Do something before the actual log is called
  • 4. Request handling Apache 2.x has two additional hooks: ➢ map_to_storage – runs just before the header parser ➢ Reads the per-directory configuration ➢ insert_filter – runs just before the handlers ➢ Insert content filter
  • 5. Apache memory pools ➢ Apache allocate memory on pools, which are shared across all modules within the same child process/thread. ➢ malloc/free is handled by Apache ➢ configuration is copied across all child processes ➢ misbehaving modules within Apache(mod_php) ➢ Apache common functions ➢ Apache 1.3 - palloc() ➢ Apaceh 2.x – palloc(), string handling ➢
  • 6. Module architecture ➢ Options table ➢ Access table ➢ Authentication table ➢ Handlers table
  • 7. How to start ➢ mod_example ➢ Apache 1.3 src/modules/example/mod_example.c ➢ Apache 2.x modules/experimental/mod_example.c ➢ Include files
  • 8. Structure of a module ➢ Includes ➢ Module name ➢ Module definition ➢ Module commands (options) ➢ Module configuration
  • 9. Includes ➢ httpd.h - the main include (consider it as, stdio.h) ➢ conn_rec, server_rec, request_rec, apache common functions ➢ http_config.h - configuration ➢ module command definitions ➢ additional functions related to the apache configuration ➢ http_request.h - request handling functions ➢ http_protocol.h - low level direct manipulation of the request
  • 10. Includes ➢ http_core.h - this file gives you everything that is actually provided by mod_core ➢ http_main.h - apache server handling ➢ http_log.h - logging facilities ➢ For Apache 2.0 and 2.2 ➢ some apache common functions are moved in apr_strings.h ➢ in order to use the request and protocol functionality you would need also http_connection.h ➢ if you need server implementation functions you need ap_mpm.h ➢ These are not all includes that you may need in your modules
  • 11. Module names #ifdef APACHE2 module AP_MODULE_DECLARE_DATA example_module; #else module MODULE_VAR_EXPORT example_module; #endif
  • 12. Module definition ➢ Apache 1.3 ➢ Apache 2.x
  • 13. Apache 1.3 module MODULE_VAR_EXPORT example_module = { STANDARD_MODULE_STUFF, NULL, /* module initializer */ NULL, /* per-directory config creator */ NULL, /* dir config merger */ NULL, /* server config creator */ NULL, /* server config merger */ NULL, /* command table */ NULL, /* [9] list of handlers */ NULL, /* [2] filename-to-URI translation */ NULL, /* [5] check/validate user_id */
  • 14. Apache 1.3 NULL, /* [6] check user_id is valid *here* */ NULL, /* [4] check access by host address */ NULL, /* [7] MIME type checker/setter */ NULL, /* [8] fixups */ NULL, /* [10] logger */ NULL, /* [3] header parser */ NULL, /* process initializer */ NULL, /* process exit/cleanup */ NULL /* [1] post read_request handling */ };
  • 15. Apache 2.x module AP_MODULE_DECLARE_DATA example_module = { STANDARD20_MODULE_STUFF, NULL, /* per-directory config creator */ NULL, /* dir config merger */ NULL, /* server config creator */ NULL, /* server config merger */ NULL, /* command table */ NULL, /* set up other request processing hooks */ }; static void register_hooks(apr_pool_t *p) { static const char * const aszPost[] = { "mod_setenvif.c", NULL }; /* 19 different processing hooks available */ }
  • 16. Module initialization ➢ Apache 1.3 ➢ startup and live ➢ the function is called two times ➢ Apache 2.0/2.2 module structure ➢ pre-config ➢ post-config
  • 17. Creating new configuration directives ➢ Define them in the module configuration structure ➢ Define new module commands(options) ➢ Create functions to actually set the options, when found in the config
  • 18. Module configuration structure typedef struct { double dummy_double; int dummy_int; char *dummy_char; array_header *dummy_array; } example_conf;
  • 19. Array handling struct ip_range *net; char *proxies[] = IP_RANGES; pool *p; conf->nets = ap_make_array(p, IP_RANGES_COUNT, sizeof(struct ip_range)); for (i = 0; i < IP_RANGES_COUNT; i++) { net = (struct ip_range *) ap_push_array(conf->nets); parse_ip( p, proxies[ i ], net ); }
  • 20. Module commands(options) ➢ Apache 1.3 static const command_rec example_cmds[] = { { "Example", cmd_example, NULL, /* argument to include in call */ OR_OPTIONS, NO_ARGS, "Example directive - no arguments" }, {NULL} };
  • 21. Module commands(options) ➢ Apache 2.x static const command_rec x_cmds[] = { AP_INIT_NO_ARGS( "Example", cmd_example, NULL, /* argument to include in call */ OR_OPTIONS, "Example directive - no arguments" ), {NULL} };
  • 22. Possible arguments ➢ FLAG => One of 'On' or 'Off' ➢ NO_ARGS => No args at all, e.g. </Directory> ➢ RAW_ARGS => cmd_func parses command line itself ➢ TAKE1 => one argument only ➢ TAKE2 => two arguments only ➢ ITERATE => one argument, occuring multiple times ➢ ITERATE2 => two arguments, 2nd occurs multiple times ➢ TAKE12 => one or two arguments ➢ TAKE3 => three arguments only ➢ TAKE23 => two or three arguments ➢ TAKE123 => one, two or three arguments ➢ TAKE13 => one or three arguments
  • 23. Allowed locations for configuration directives ➢ RSRC_CONF => *.conf outside <Directory> or <Location> ➢ ACCESS_CONF => *.conf inside <Directory> or <Location> ➢ OR_AUTHCFG) => *.conf inside <Directory> or <Location> and .htaccess when AllowOverride AuthConfig ➢ OR_LIMIT) => *.conf inside <Directory> or <Location> and .htaccess when AllowOverride Limit ➢ OR_OPTIONS) => *.conf anywhere and .htaccess when AllowOverride Options ➢ OR_FILEINFO) => *.conf anywhere and .htaccess when AllowOverride FileInfo ➢ OR_INDEXES) => *.conf anywhere and .htaccess when AllowOverride Indexes
  • 24. Module command handlers static const char *set_examplecmd(cmd_parms *cmd, void *vconf, char *arg) { example_conf *conf = (example_conf *) vconf; if (cmd->path == NULL) { conf = (example_conf *) ap_get_module_config(cmd->server->module_config, &example_module); #ifdef DEBUG_OPTIONS fprintf(stderr, "mod_example: (%s:%d)Example (server)n", cmd->config_file->name, cmd->config_file->line_number); } else { fprintf(stderr, "mod_example: (%s:%d)RelaxPerms (dir)n", cmd->config_file->name, cmd->config_file->line_number); #endif } conf->dummy_char = ap_pstrdup(cmd->pool, arg); return NULL; }
  • 25. Handling configuration directives ➢ Global vs. Vhost configuration ➢ Per directory/files/location ➢ Merge of the global and per-vhost configuration ➢ Initialization of the configuration
  • 26. Logging ➢ ap_log_error(APLOG_MARK, APLOG_INFO, r->server, "Some string"); ➢ ap_log_rerror(APLOG_MARK, APLOG_INFO, r, "Some string"); ➢ Apache 2.x ➢ Added ap_log_cerror() for conn_rec handling ➢ Added ap_log_perror() for everything that is not server, record or connection related ➢ Added status code between the server and level
  • 27. Writing portable modules ➢ Porting tricks #ifndef APACHE_RELEASE #define APACHE2 #endif ➢ Apache common functions ➢ ap_palloc(1.3) -> apr_palloc(2.x)
  • 29. Thank you ??? Questions ??? Thank you