You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Manish Chakravarty <ma...@gmail.com> on 2006/10/12 08:48:50 UTC
Developing C++ modules with apache 1.3.34
Hi All,
I am a newbie to Apache development. I am trying to develop a module
for apache 1.3.34 in C++. I really need to link with some C++ libs and
use C++ headers for this project.
1) How do i go about it ? Do i follow the standard Makefile approach
as outlined in the book "Writing Apache Modules with Perl and C" ?
2) The sample skeleton code (mixed C/C++) is given below. Would
someone be kind enough to go through and tell me if my approach is OK?
==========Example code =========================
#include "apache/httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_protocol.h"
#undef strtoul
//will the next line work as intended?
extern "C" module MODULE_VAR_EXPORT clickout_module;
static void co_mod_init(server_rec *s, pool *p)
{
//some module initialization stuff
}
static int co_handler(request_rec *r)
{
const char* hostname;
r->content_type = "text/html";
ap_send_http_header(r);
hostname = ap_get_remote_host(r->connection, r->per_dir_config,
REMOTE_NAME);
ap_rputs ("Some text");
return OK;
}
static handler_rec co_handlers[] =
{
{"some-hander", some_handler},
{NULL}
};
void co_proc_init(server_rec* s, pool* p)
{
// some c++ initialization functions here.
}
extern "C" { // is this extern useful here?
module MODULE_VAR_EXPORT clickout_module =
{
STANDARD_MODULE_STUFF,
co_mod_init, /** module initializer */
NULL, /** per-directory config creator */
NULL, /** dir config merger */
NULL, /** server config creator */
NULL, /** server config merger */
NULL, /** command table */
co_handlers, /** [9] content handlers */
NULL, /** [2] URI-to-filename translation */
NULL, /** [5] check/validate user_id */
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 */
co_proc_init, /** process initialization */
NULL, /** process exit/cleanup */
NULL /** [1] post read_request handling */
};
}
==========End example code ======================
Thanks in advance.!!
--
Warm Regards,
Manish Chakravarty
----
Consultant Software Developer
PH: +919886702500
http://manishchaks.net
---
RE: Developing C++ modules with apache 1.3.34
Posted by "Kratzer, James (Xetron)" <Ja...@ngc.com>.
See this threebit article on building an Apache modules using autoconf,
automake, and libtool:
http://threebit.net/tutorials/apache2_modules/tut1/tutorial1.html
You create the files configure.in and Makefile.am. In the file
Makefile.am is where you specify your cpp file like so:
libmodfoo_la_SOURCES = mod_foo.c mod_bar.cpp
Good luck
James Kratzer
-----Original Message-----
From: Manish Chakravarty [mailto:manishchaks@gmail.com]
Sent: Friday, October 13, 2006 5:59 AM
To: modules-dev@httpd.apache.org
Subject: Re: Developing C++ modules with apache 1.3.34
Could you please tell me how you do that?
when i run my ./configure
--activate-module=src/modules/mod_foo/mod_foo.cpp \
enable-module=mod_foo
it gives me the error
Configuring for Apache, Version 1.3.34
+ using installation path layout: Apache (config.layout) + activated
clickout module (modules/mod_foo/mod_foo.cpp
configure:Error: No such module named 'mod_foo'
could you please tell me how you use autoconf/libtool, or atleast
provide me pointers as to how they are used?
On 10/12/06, Kratzer, James (Xetron) <Ja...@ngc.com> wrote:
> Hi,
>
> Here is what I'm doing with Apache 2.0.
>
> I use autoconf and libtool to create my makefiles and to build my
> apache modules. I then put all of your C++ functions is a separate
> source file having a cpp extension and I wrap the c++ functions with
extern "C"
> declarations. I then call the c++ functions from the C module code.
> Works great.
>
> James Kratzer
>
> -----Original Message-----
> From: Manish Chakravarty [mailto:manishchaks@gmail.com]
> Sent: Thursday, October 12, 2006 2:49 AM
> To: modules-dev@httpd.apache.org
> Subject: Developing C++ modules with apache 1.3.34
>
> Hi All,
>
> I am a newbie to Apache development. I am trying to develop a module
> for apache 1.3.34 in C++. I really need to link with some C++ libs and
> use
> C++ headers for this project.
>
> 1) How do i go about it ? Do i follow the standard Makefile approach
> as outlined in the book "Writing Apache Modules with Perl and C" ?
>
> 2) The sample skeleton code (mixed C/C++) is given below. Would
> someone be kind enough to go through and tell me if my approach is OK?
>
> ==========Example code ========================= #include
> "apache/httpd.h"
> #include "http_config.h"
> #include "http_core.h"
> #include "http_log.h"
> #include "http_protocol.h"
>
> #undef strtoul
> //will the next line work as intended?
> extern "C" module MODULE_VAR_EXPORT clickout_module;
>
> static void co_mod_init(server_rec *s, pool *p) {
> //some module initialization stuff } static int
> co_handler(request_rec *r) {
> const char* hostname;
> r->content_type = "text/html";
> ap_send_http_header(r);
> hostname = ap_get_remote_host(r->connection, r->per_dir_config,
> REMOTE_NAME);
> ap_rputs ("Some text");
> return OK;
> }
> static handler_rec co_handlers[] =
> {
> {"some-hander", some_handler},
> {NULL}
> };
> void co_proc_init(server_rec* s, pool* p) { // some c++ initialization
> functions here.
> }
>
> extern "C" { // is this extern useful here?
> module MODULE_VAR_EXPORT clickout_module = {
> STANDARD_MODULE_STUFF,
> co_mod_init, /** module initializer */
> NULL, /** per-directory config creator */
> NULL, /** dir config merger */
> NULL, /** server config creator */
> NULL, /** server config merger */
> NULL, /** command table */
> co_handlers, /** [9] content handlers */
> NULL, /** [2] URI-to-filename translation */
> NULL, /** [5] check/validate user_id */
> 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 */
> co_proc_init, /** process initialization */
> NULL, /** process exit/cleanup */
> NULL /** [1] post read_request handling */
> };
> }
>
> ==========End example code ======================
>
> Thanks in advance.!!
>
> --
> Warm Regards,
> Manish Chakravarty
> ----
> Consultant Software Developer
> PH: +919886702500
> http://manishchaks.net
> ---
>
--
Warm Regards,
Manish Chakravarty
----
Consultant Software Developer
PH: +919886702500
http://manishchaks.net
---
Re: Developing C++ modules with apache 1.3.34
Posted by Manish Chakravarty <ma...@gmail.com>.
Could you please tell me how you do that?
when i run my ./configure --activate-module=src/modules/mod_foo/mod_foo.cpp \
enable-module=mod_foo
it gives me the error
Configuring for Apache, Version 1.3.34
+ using installation path layout: Apache (config.layout)
+ activated clickout module (modules/mod_foo/mod_foo.cpp
configure:Error: No such module named 'mod_foo'
could you please tell me how you use autoconf/libtool, or atleast
provide me pointers as to how they are used?
On 10/12/06, Kratzer, James (Xetron) <Ja...@ngc.com> wrote:
> Hi,
>
> Here is what I'm doing with Apache 2.0.
>
> I use autoconf and libtool to create my makefiles and to build my apache
> modules. I then put all of your C++ functions is a separate source file
> having a cpp extension and I wrap the c++ functions with extern "C"
> declarations. I then call the c++ functions from the C module code.
> Works great.
>
> James Kratzer
>
> -----Original Message-----
> From: Manish Chakravarty [mailto:manishchaks@gmail.com]
> Sent: Thursday, October 12, 2006 2:49 AM
> To: modules-dev@httpd.apache.org
> Subject: Developing C++ modules with apache 1.3.34
>
> Hi All,
>
> I am a newbie to Apache development. I am trying to develop a module for
> apache 1.3.34 in C++. I really need to link with some C++ libs and use
> C++ headers for this project.
>
> 1) How do i go about it ? Do i follow the standard Makefile approach as
> outlined in the book "Writing Apache Modules with Perl and C" ?
>
> 2) The sample skeleton code (mixed C/C++) is given below. Would someone
> be kind enough to go through and tell me if my approach is OK?
>
> ==========Example code ========================= #include
> "apache/httpd.h"
> #include "http_config.h"
> #include "http_core.h"
> #include "http_log.h"
> #include "http_protocol.h"
>
> #undef strtoul
> //will the next line work as intended?
> extern "C" module MODULE_VAR_EXPORT clickout_module;
>
> static void co_mod_init(server_rec *s, pool *p) {
> //some module initialization stuff
> }
> static int co_handler(request_rec *r)
> {
> const char* hostname;
> r->content_type = "text/html";
> ap_send_http_header(r);
> hostname = ap_get_remote_host(r->connection, r->per_dir_config,
> REMOTE_NAME);
> ap_rputs ("Some text");
> return OK;
> }
> static handler_rec co_handlers[] =
> {
> {"some-hander", some_handler},
> {NULL}
> };
> void co_proc_init(server_rec* s, pool* p) { // some c++ initialization
> functions here.
> }
>
> extern "C" { // is this extern useful here?
> module MODULE_VAR_EXPORT clickout_module = {
> STANDARD_MODULE_STUFF,
> co_mod_init, /** module initializer */
> NULL, /** per-directory config creator */
> NULL, /** dir config merger */
> NULL, /** server config creator */
> NULL, /** server config merger */
> NULL, /** command table */
> co_handlers, /** [9] content handlers */
> NULL, /** [2] URI-to-filename translation */
> NULL, /** [5] check/validate user_id */
> 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 */
> co_proc_init, /** process initialization */
> NULL, /** process exit/cleanup */
> NULL /** [1] post read_request handling */
> };
> }
>
> ==========End example code ======================
>
> Thanks in advance.!!
>
> --
> Warm Regards,
> Manish Chakravarty
> ----
> Consultant Software Developer
> PH: +919886702500
> http://manishchaks.net
> ---
>
--
Warm Regards,
Manish Chakravarty
----
Consultant Software Developer
PH: +919886702500
http://manishchaks.net
---
RE: Developing C++ modules with apache 1.3.34
Posted by "Kratzer, James (Xetron)" <Ja...@ngc.com>.
Hi,
Here is what I'm doing with Apache 2.0.
I use autoconf and libtool to create my makefiles and to build my apache
modules. I then put all of your C++ functions is a separate source file
having a cpp extension and I wrap the c++ functions with extern "C"
declarations. I then call the c++ functions from the C module code.
Works great.
James Kratzer
-----Original Message-----
From: Manish Chakravarty [mailto:manishchaks@gmail.com]
Sent: Thursday, October 12, 2006 2:49 AM
To: modules-dev@httpd.apache.org
Subject: Developing C++ modules with apache 1.3.34
Hi All,
I am a newbie to Apache development. I am trying to develop a module for
apache 1.3.34 in C++. I really need to link with some C++ libs and use
C++ headers for this project.
1) How do i go about it ? Do i follow the standard Makefile approach as
outlined in the book "Writing Apache Modules with Perl and C" ?
2) The sample skeleton code (mixed C/C++) is given below. Would someone
be kind enough to go through and tell me if my approach is OK?
==========Example code ========================= #include
"apache/httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_protocol.h"
#undef strtoul
//will the next line work as intended?
extern "C" module MODULE_VAR_EXPORT clickout_module;
static void co_mod_init(server_rec *s, pool *p) {
//some module initialization stuff
}
static int co_handler(request_rec *r)
{
const char* hostname;
r->content_type = "text/html";
ap_send_http_header(r);
hostname = ap_get_remote_host(r->connection, r->per_dir_config,
REMOTE_NAME);
ap_rputs ("Some text");
return OK;
}
static handler_rec co_handlers[] =
{
{"some-hander", some_handler},
{NULL}
};
void co_proc_init(server_rec* s, pool* p) { // some c++ initialization
functions here.
}
extern "C" { // is this extern useful here?
module MODULE_VAR_EXPORT clickout_module = {
STANDARD_MODULE_STUFF,
co_mod_init, /** module initializer */
NULL, /** per-directory config creator */
NULL, /** dir config merger */
NULL, /** server config creator */
NULL, /** server config merger */
NULL, /** command table */
co_handlers, /** [9] content handlers */
NULL, /** [2] URI-to-filename translation */
NULL, /** [5] check/validate user_id */
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 */
co_proc_init, /** process initialization */
NULL, /** process exit/cleanup */
NULL /** [1] post read_request handling */
};
}
==========End example code ======================
Thanks in advance.!!
--
Warm Regards,
Manish Chakravarty
----
Consultant Software Developer
PH: +919886702500
http://manishchaks.net
---