Re: Using APR based C++ classes in Apache2 module
On Thu, May 02, 2013 at 10:07:39AM +0200, Graf L?szl? wrote: Hi Joe, I appreciate your response. I did a search on the net and I found this, two parts, How-To: http://www.codeproject.com/Articles/491909/Apache-2-x-Modules-In-Cplusplus-Part-1 http://www.codeproject.com/Articles/492398/Apache-2-x-Modules-In-Cplusplus-Part-2 I followed all the steps but at the end, when I restarted the Apache server, I got this error: httpd: Syntax error on line 521 of /home/sk/apache2/conf/httpd.conf: Cannot load modules/mod_foo.so into server: /home/sk/indian/modules/mod_foo.so: undefined symbol: foo_register_config_ptr I links to the header files into the Apache2's include folder and a No need to link the header files - what for? link to the SO into the Apache2's modules folder. Yes, and obviously it's found by the server (otherwise it wouldn't complain about it, would it? :-) Am I missing something here? No you, but your linker. Where is 'foo_register_config_ptr' defined? And before any further investigation: you don't by chance try to compile with a C++ compiler? If so, You know about name mangling? If not, it's time for some C vs. C++ readup HTH Ralf Mattes Best regards, SK
graceful dead
hello list, just a quick question: is there any Apache api to request from within a module a child process (or thread for that matter) to die? I have a module where returning 500 followed by a suicide seems to be the best way to deal with some error conditions. TIA Ralf Mattes
Re: Config File Lines not ASCII?
On Tue, 2008-12-02 at 10:41 -0800, Brian McQueen wrote: I find that I can't put ascii escape characters into lines in the config file - even if I read the out with AP_INIT_RAW_ARGS. I think you need to tell us what you mean by ascii escape characters - the character with the bit representation 0011011? To be more specific, I can put it in the config file, but when I put \n in the config file and use it elsewhere, I find that its two characters, '\' and 'n'. Hmm, \n is a string ... How can I pass in ascii escape sequencecs? Where did you get the impression that ascii attaches meaning to the backslash? That's a jolly ol' C-thing (that java and similar languages happily copy). What is happening to these strings? Nothing - bat that seems to be expected. HTH Ralf Mattes Thanks
Re: mod_proxy chaining with a .pac file
On Wed, 2008-01-23 at 22:19 +, Giovanni Donelli wrote: Are you talking about a JS lib or a code that does what I need, support for .pac proxy chaning? The later. Sorry, that library wasn't linked to from your original post, but it can be found on the wikipedia page. Here's a direct link: http://code.google.com/p/pacparser/ From browsing the documentation it looks like it does all you need. HTH RalfD As with regards with JS I was going to use the WebKit's JavaScriptCore. There _IS_ a library (C and python(?) interface) - downloadable from the google code link posted in the first message ... trivial to link into an Apache module. AFAIK it uses the mozilla JS code. Cheers, RalfD Joe
Re: mod_proxy chaining with a .pac file
On Wed, 2008-01-23 at 11:48 -0700, Joe Lewis wrote: Ralf Mattes wrote: On Wed, 2008-01-23 at 11:12 -0700, Joe Lewis wrote: Giovanni Donelli wrote: I am trying to make Apache follow the same rules as the browser Realize that the browser doesn't get the configurations for each website it visits, it only configures, then runs using the same configuration for every website. Realize that, since a .pac file is a ECMA-Script program, that configuration can (and often will) be dynamic. The proxy needs to be determined for each request. That means it should be easy to create a simple module that has a single configuration directive that points to the next proxy in the chain, something like WPADConfiguration http://secondproxyserver.example.com/my-proxy-file.pac And then just configure mod_proxy, mod_proxy_http, and create a handler that prefaces all URL's with the proxy: string, set the proxyreq setting in the request_rec to an appropriate value, and return 1 to allow mod_proxy to handle the rest of it. No - that's too simple. The module needs to run the JS function for each request and has to be able to dynamically set the proxy. Indeed - I had completely forgotten about that. Isn't there a javascript library could be connected into, or should the module be written in perl to use that? I suppose parsing the file manually would work. But I don't like reinventing wheels. There _IS_ a library (C and python(?) interface) - downloadable from the google code link posted in the first message ... trivial to link into an Apache module. AFAIK it uses the mozilla JS code. Cheers, RalfD Joe
Re: Specifying a different target directory for APXS
On Fri, 2007-12-14 at 08:07 -0500, Subra A Narayanan wrote: Hello folks, Hello folk, your problem has nothing to do with apxs. The .libs directory is created by libtool. You might want to contact the helpful dwellers on the libtool mailing list. Has anyone come across a similar situation before? Can a target folder be specified or is that not possible? Never needed to change that part of the build process. HTT Ralf Mattes Any help is greatly appreciated. Subra On Dec 13, 2007 12:05 PM, Subra A Narayanan [EMAIL PROTECTED] wrote: Hello folks, I use the following command to compile my apache module: */usr/sbin/apxs -c mod_my.c* this creates a *.libs/* folder and my mod_my.so file is generated in that folder. My question is, is it possible to specify a different target folder for my .so file? I have gone through the man page for apxs and wasn't able to find anything. thanks in advance, Subra
Re: Specifying a different target directory for APXS
On Fri, 2007-12-14 at 11:05 -0500, Subra A Narayanan wrote: Joe, Thanks for ur response. The reason I wanted to change the target directory was because my apache module is being compiled as one of the components of a much larger makefile. All the other shared libraries generated by this make file, are copied in a particular directory and hence I wanted my apache module to go in to that directory as well. As you suggested, I could copy the .so file to whatever directory I want later on, but I am not sure if such copying ig generally done in a makefile. That's the approach I would choose (I do for packaging my modules into Debian packages). Why wouldn't you copy in a Makefile? Just add another dependency: your_very_Special_path/your_module.so: your_module.slo cp .libs/your_module.so your_very_Special_path/your_module.so I did try to directly use gcc to compile my apache module so that I could specify any target directory but ran in to another issue which is detailed here = http://mail-archives.apache.org/mod_mbox/httpd-modules-dev/200711.mbox/[EMAIL PROTECTED] I didnt receive any helpful responses to that posting thats why I am trying to use apxs. I got the impression that everyone considered this a no-so-good idea HTH Ralf Mattes
Re: Strange segmentation fault
On Mon, 2007-07-30 at 20:22 +0200, Mike wrote: On Mon, Jul 30, 2007 at 06:31:58PM +0200, [EMAIL PROTECTED] wrote: Sorry I don't understand the reply. You are telling me that it should be possibile or not? I always use r-pool to allocate memory in my module, but not for libxml2. It has it's memory allocation and looking at source it uses malloc and free. So maybe it is libxml2 problem? Dream on ;-) Cheers, RalfD
Re: Strange segmentation fault
On Mon, 2007-07-30 at 16:14 +0200, [EMAIL PROTECTED] wrote: I discovered some segmentation faults in apache error log. So I wanted to understand the reason of these errors. I put these statements in my module: ap_log_perror(APLOG_MARK, APLOG_ERR, 0, r-pool, 0:[%ld] %s, (long)getpid()); and ap_log_perror(APLOG_MARK, APLOG_ERR, 0, r-pool, 1:[%ld] %s, (long)getpid(), q); where 1: is increased in each my following instructions. Then I checked my error log to see where the error was generated. In the error log I found: ... [Mon Jul 30 15:35:30 2007] [error] 5:[12172] sss [Mon Jul 30 15:35:30 2007] [error] 6:[12172] sss [Mon Jul 30 15:35:33 2007] [error] 0:[12172] [Mon Jul 30 15:35:35 2007] [error] 0:[12172] [Mon Jul 30 15:35:47 2007] [error] 0:[12172] [Mon Jul 30 15:35:48 2007] [notice] child pid 12172 exit signal Segmentation fault (11) It seems that different childs of apache uses the same pid in a few seconds ???. Children don't use PIDs - these are assigned by the operating system. Are you _shure_ your server doesn't use threads? Iff so this means that the same child reaches state '0' of your logging more than once. What does it mean? I'm using apache 2.2.4 with this configuration parameters: IfModule mpm_prefork_module StartServers100 MinSpareServers 50 MaxSpareServers 200 ServerLimit 512 MaxClients 512 MaxRequestsPerChild 256 /IfModule This only is used iff your server uses the prefork-mpm. Could you give me a hint to solve my problem? Best regards Enable core dumps and examine the core file - you might need to recompile at least your module with debugging information enabled. HTH Ralf Mattes Marco
Re: APXS question
On Sun, 2007-07-22 at 11:32 -0400, Farokh Irani wrote: I'm trying to set up a makefile using apxs to compile and link a module and I'm running into a couple of problems. If I use the following command line: apxs -ic -S CC=g++ -n mod_fancy mod_fancy.cpp config.cpp everything works fine. In my makefile, I have the following (this is a partial): mod_fancy.so: mod_fancy.o config.o apxs -i -n mod_fancy mod_fancy.o config.o Hmm - I see what you want to avoid, but the object files (as well as the shared object) are pretty much hidden from you (libtool the beast stuffs them into a '.lib' directory). There should be convenient '*.slo' file in your top level directory. %.o : %.cpp apxs -S CC=g++ -c $ Now, when I try to run make, the compile works fine, but the final install doesn't work. Here's what I get: /usr/local/apache2/bin/apxs -i -n mod_fancy mod_fancy.o config.o /usr/local/apache2/build/instdso.sh SH_LIBTOOL='/usr/local/apache2/build/libtool' mod_fancy.o /usr/local/apache2/modules /usr/local/apache2/build/libtool --mode=install cp mod_fancy.o /usr/local/apache2/modules/ cp mod_fancy.o /usr/local/apache2/modules/mod_fancy.o Warning! dlname not found in /usr/local/apache2/modules/mod_fancy.o. Assuming installing a .so rather than a libtool archive. chmod 755 /usr/local/apache2/modules/mod_fancy.so /usr/local/apache2/build/instdso.sh SH_LIBTOOL='/usr/local/apache2/build/libtool' config.o /usr/local/apache2/modules /usr/local/apache2/build/libtool --mode=install cp config.o /usr/local/apache2/modules/ cp config.o /usr/local/apache2/modules/config.o Warning! dlname not found in /usr/local/apache2/modules/config.o. Assuming installing a .so rather than a libtool archive. chmod 755 /usr/local/apache2/modules/config.so chmod: /usr/local/apache2/modules/config.so: No such file or directory apxs:Error: Command failed with rc=65536 I've tried it by using different files (ie .slo and .lo files), but I get the same error. You want to installthe '*.so' file from the '.libs' directory. But be careful: that name depends on the platform. Any ideas? I'd really rather not have apxs recompiling every single file each time. Does your compilation really take _that_ long. Looks like a severe case of premature Makefile optimization to me. Cheers, RalfD Thanks.
Re: APXS troubles
On Fri, 2007-07-20 at 12:38 +0100, Jeremy Sowden wrote: Farokh Irani wrote: On Fri, 2007-07-20 at 08:36 +0200, Mike wrote: if ($f =~ m|\.c$|) { Here, bad coder! BAD! I don't know perl at all, so those were stabs in the dark. Any pointers on that would be appreciated. Try: if( $f =~ m/\.c$|\.cpp$|\.cc$/ ) OK, I tried this and while it appears to compile and link, the symbol winds up undefined again and nm shows the a similar output as when it was linked as an empty library. I'd go for: if ( $f = ~m/\.c(c|pp){0,1}$/i ) This one doesn't compile. When I run apxs, perl complains: Use of uninitialized value in pattern match (m//) at /usr/bin/apxs2 line 361. There's a typo. It should be: if ( $f =~ m/\.c(c|pp){0,1}$/i ) Yes, sorry. This was actually caused by a stupid mail client inserting a line break during copy-n-paste. While correcting this I must somehow inadvertently have added a whitespace at the wrong point. Cheers, RalfD J. -- +0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+ www: http://www.azazel.net/ pgp: http://www.azazel.net/~azazel/js_key.asc +0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+0+
Re: APXS troubles
On Fri, 2007-07-20 at 14:39 +0200, Mike wrote: On 7/20/07, Farokh Irani [EMAIL PROTECTED] wrote: So, somewhere there is still something going on with .c vs .cpp. I'll poke at apxs a bit and see if I can figure out why, but a crash course in perl wasn't what I was looking at doing right now :) So you mean a change from *.cpp to *.c is the only real working solution? That's strange but anyway it works now... Well - from what I can observe this seems to be a bug in libtool itself (why did I expect this, given libtools poor C++ support?). The final link command emitted by apxs seems to be (my reindentation): /usr/share/apr-1.0/build/libtool --silent --mode=link \ --tag=disable-static g++ -o mod_fancy.la \ -rpath /usr/lib/apache2/modules -module -avoid-version \ config.cpp mod_fancy.cpp Note that apxs is passing source file names to libtool. This doesn't seem to work. Passing the '.libs/mod_fancy.o .libs/config.o' seems a quick fix. I wonder if it's worth the effort. NOTE: I've sucessfully compiled C++ modules, but 'I somehow always give my sorce files '*.c' extentions. HTH Ralf Mattes Kind regards.
Re: APXS troubles
On Thu, 2007-07-19 at 10:41 -0400, Farokh Irani wrote: Did you get the file OK and have you had a chance to look at it?\ Yes and yes - even so it was binhexed ... I allready replied yesterday evening - no idea why you didn't get my mail. Anyway - indeed there is a bug in APXS. Unless your input files have the extention '.c' APXS won't invoke libtool in compile mode (hence it's missing from your trace). Libtool in link mode will just create an empty library ... The easy fix is to rename the files from '*.cpp' to '*.c' (no, '*.cc' doesn't work either). If you find the time you might want to report the bug to the APXS maintainers, the important lines are these: ---*- apxs (line 351 ff.) --*-.-- if ($opt_c) { ## ## SHARED OBJECT COMPILATION ## # split files into sources and objects my @srcs = (); my @objs = (); my $f; foreach $f (@args) { if ($f =~ m|\.c$|) { Here, bad coder! BAD! push(@srcs, $f); } else { push(@objs, $f); } } HTH Ralf Mattes Thanks.
Re: APXS issue.
On Wed, 2007-07-18 at 07:23 -0400, Farokh Irani wrote: See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. -- chmod 755 /usr/local/libexec/apache22/mod_fancy.so Not neccessary - shared libs don't need to be executable. Does anyone have any ideas as to why using apxs would cause the symbol not to be exported? I'd be willing to show the code, it's not very complex, to anyone who might be able to help. Qk, fine - tar it up and mail it to me. I might have some time later today and could try to build your code. BTW, please enclose all Makefile/build magic scripts as well. Cheers, RalfD Thanks.
Re: APXS issue.
On Wed, 2007-07-18 at 07:23 -0400, Farokh Irani wrote: Our intrepid hero, [...] went through the effort of install yet another linux variant, this time FreeBSD, Most likely there's a secret army of ninja demons heading towards your place right now-FreeBSD is _not_ a linux varinat! ;-) Cheers, Ralf Mattes
Re: Debian 4 issue
On Sun, 2007-07-15 at 10:44 -0400, Farokh Irani wrote: No - you are not! You are using g++-4... which is a C++ compiler. Are you aware of C++ name mangling? Did you declare your exported symbols 'extern C'? Um, yes, already done. extern C module AP_MODULE_DECLARE_DATA fancy_module; It's the first line after the includes. Near the end of the file: You need to declare the following as C: extern C { module AP_MODULE_DECLARE_DATA fancy_module = { STANDARD20_MODULE_STUFF, create_dir_mconfig,/* create per-dir config structures*/ merge_dir_mconfig, /* merge per-dir config structures*/ NULL, /* create per-server config structures */ NULL, /* merge per-server config structures */ fancy_cmds,/* table of config file commands */ fancy_register_hooks /* register hooks */ }; } HTH RalfD
Re: a thanks and C++ new overloading
On Thu, 2007-03-29 at 08:44 -0400, Sam Carleton wrote: Folks, I want to say thank you for taking the time to help me out with getting my module up and going. It is so VERY refreshing to be developing in such a well thought out and structured environment. By day I am working in VB.Net on different small projects where the project leads attitude is: Get it done, don't make too many new modules/class because it will be too complex for me (boss) to understand when you leave. Having the structure of the apache module is the complete and total opposite and very very refreshing! It is also exposing me a little bit to how to make a module system, which I will ultimately need to do for the GUI side of my app. It is all good, very good! Thanks for directing me this way! Last night I did successfully setup a C++ new overload that takes an apache pool. (When used correctly, C++ is simply WONDERFUL!) The question is: How best to make the code reusable? What do I mean? Well, the next version of the GUI is going to be written in C++, there is going to be a lot of code that can and should be shared between the module and the GUI. I just cannot figure out how best to setup the common code to allocate memory for different locations. Any suggestions? Well, please consider all I say with a certain amount of doubt since I'm not a C++ developer (only did one C++ module, the rest was plain C) and favor C (or Obj. C) over C++, but: Since you seem to like the Apache way why not use it for the GUI as well. The memory pooling and eveything prefixed with 'apr_' is actually part of the Apache Portable Runtime which can be used independent from the Apache webserver (Subversion is a prominent example for such a project). You just need to decide whether memory pools[1] are a good fit for your GUI application. Cheers, RalfD [1] For another nice MPS have a look at: http://www.ravenbrook.com/project/mps/doc/2002-01-30/ismm2002-paper/ismm2002.html Sam
Re: a thanks and C++ new overloading
On Thu, 2007-03-29 at 10:39 -0400, Sam Carleton wrote: On 3/29/07, Ralf Mattes [EMAIL PROTECTED] wrote: Well, please consider all I say with a certain amount of doubt since I'm not a C++ developer (only did one C++ module, the rest was plain C) and favor C (or Obj. C) over C++, Interesting, Are you doing large projects in C? I know both well and simply cannot imagine developing a large system in C. Depends on what you call 'large'. I'm on Unix only and there is a certain tendency to keep things small ans simple ... :-) So - somehow most of my projects end up as small extensions, modules or plugins. I have to confess that I do the really large projects in other languages (Common Lisp if you care to ask) or often in so-called scripting languages (that's what my customers often require since I'm doing Web-related programming and their tech. people only program in the dreaded P/R languages). I know Apache is all in C, but man, I really like my objects;) Obj. C does sound interesting, can you recommend any good sites that can enlighten me more about the subject? Oh, my bookmarks for Obj.C are on my Mac (other office) but with a bit Google help you should find plenty. BTW, one _can_ do OOp in C as well - at least that's what the Gnome project tries to do. For me, C++ is just a monster - C raped and transmogrified. Iff I need a solid OO language with static typing I'd go for Objective CAML - but that's hard to sell to customers. but: Since you seem to like the Apache way why not use it for the GUI as well. The memory pooling and eveything prefixed with 'apr_' is actually part of the Apache Portable Runtime which can be used independent from the Apache webserver (Subversion is a prominent example for such a project). You just need to decide whether memory pools[1] are a good fit for your GUI application. Why not? Because I had not stop to make the obvious connection;) [1] For another nice MPS have a look at: http://www.ravenbrook.com/project/mps/doc/2002-01-30/ismm2002-paper/ismm2002.html yea, the whole memory management thing is a huge can or worms, nice to know that there is the above MPS and apache's to pick from. Seems like the rest of the world is picking Garbage Collection up - Apple seems to go the same road with Objective C (that always had interesting memory management concepts). Cheers, RalfD Sam
Re: how to get started?
On Tue, 2007-03-27 at 10:58 -0400, Sam Carleton wrote: On 3/27/07, Ralf Mattes [EMAIL PROTECTED] wrote: On Mon, 2007-03-26 at 22:05 -0400, Sam Carleton wrote: Ok folks, I am developing on Windows. I have VC6, VS2005, and Cygwin installed. I would prefer ot use VS2005, but VC6 will work, Cygwin is a last resort, VERY last resort. I first thought I would try Ralf's advice of running apxs -g -n fancy_image_handler, but I cannot find apxs on my Windows machine. Oh, I'm terribly sorry. I only recalled on my way home that you're running on Windows. Not a problem I got it worked out;) I can't comment at all on Windows development - never done it. Iff you want your module to run on Unix/Linux as well it might be a good idea to install VMWare Player and live images for Linux(Ubuntu), Solaris and NetBSD/OpenBSD. Oh, I have lots of *NIX machines to pick from, I have a OpenBSD machine (my firewall), Solaris 8, and a SuSE Linux, no need for VMWare. Good. Still - the virtual testserver thing really grew on me: I have a clearly defined build/test environment (ever been bitten by a missing library that was never detected because it happend to be installed on you test system?). There are two issues, equally big, in terms of me doing the development on anything other then Windows: 1: The GUI frontend to the system is all 100% Windows right now, even though the web side can stand on it's own, it would be a pain to have to go back to windows all the time to change the data feeding the kiosk. 2: I know the tools in Windows to do C/C++ development, been using them for over a decade now. I have never developed in *NIX, so there is most definitely a learning curve. Definitely. I'd dread to heve to learn Windows API and frameworks. The way I see it, I will make my best effort to keep the module platform neutral. I am thinking about taking the time to learn how to setup the module with, I think it is called, automake, so that I can see if I can get it to compile and run on one of the other platforms I have, but if it takes too much time, I am willing to shelve it for now, it just means there might be more work later to fix the bugs when I take the GUI cross platform. Can anyone point me to some good, quick and easy documentation to setup an automake project? You mean 'automake the BEAST' ? :-) Gosh, _that's_ a real monster. I'd start with the automake book: GNU Autoconf, Automake, and Libtool, by Tromey et al. But beware: utomake is a moving target and has changed since the book was written ... Unless you need some fancy system dependent functionality and you stick to libapr for portability you might just copy/morify the automake setup of an existing module. Cheers, Ralf Mattes Sam
Re: reference out of date?
On Tue, 2007-03-27 at 13:20 -0700, John David Duncan wrote: Hi, It's a very useful book, even though it predates apache 2. Hmm, it sure was a very useful book until recently - since it pretty much was _the_ only book on Apache module development. I was always amazed at the lack of documentation for Apache2 module developers. Go get a copy of Nick's book fast. This is the best (and only) you can get for Apache2 -- if you feel like it you might want to read parts of Writing Apache Modules .. (esp. the introduction chapters and the smallish part on C at the end) but Nick's tome is pretty much a must. If some nitts and picks with that book but there is a wealth of information in it - don't waste your time reading partially out-of-date documentation fragments from the web. Just my 0.01 € Cheers, RalfD You will need to supplement it (with a few articles on converting modules from apache 1.3 to apache 2, and with the doxygen pages for apache 2 and apr, or with Nick Kew's new book), but I still find it to be an indespensible reference to the Apache API. JD On Mar 27, 2007, at 1:04 PM, Sam Carleton wrote: Many moons ago, around 2001 I believe, I purchased the book Writing Apache Modules with Perl and C by Lincoln Stein and Doug MacEachern. I have not dug it up yet, but I am guessing that it was written for Apache 1.x. For my needs, handling basic requests, will it be out of date? Sam