Return-Path: X-Original-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Delivered-To: apmail-httpd-modules-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5EF4EF82B for ; Sat, 11 May 2013 07:41:49 +0000 (UTC) Received: (qmail 56337 invoked by uid 500); 11 May 2013 07:41:48 -0000 Delivered-To: apmail-httpd-modules-dev-archive@httpd.apache.org Received: (qmail 56166 invoked by uid 500); 11 May 2013 07:41:48 -0000 Mailing-List: contact modules-dev-help@httpd.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: modules-dev@httpd.apache.org Delivered-To: mailing list modules-dev@httpd.apache.org Received: (qmail 56127 invoked by uid 99); 11 May 2013 07:41:47 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 11 May 2013 07:41:47 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of sorinm@gmail.com designates 209.85.212.171 as permitted sender) Received: from [209.85.212.171] (HELO mail-wi0-f171.google.com) (209.85.212.171) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 11 May 2013 07:41:40 +0000 Received: by mail-wi0-f171.google.com with SMTP id hn3so1308069wib.10 for ; Sat, 11 May 2013 00:41:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=WcA4QirTFhTgvRrEDIFrGwcR0+DZGGH/K0w/PW75VdY=; b=hocNz5IfYNUnvVgPLpthko00v+2yYTm48IOQTY0BYz5VGyxOgKFvYuYa80WxFPp3Fr 7WWbxs3Bm82JlQLV8pONG2GJM0VhLFGxCxr5+kx6ATBGZ6YQx3rj1r4/dteZk0wgYW7/ XQ2px1caneczQcM0WPexn0kzR4Ro6EHsN2FLHPMP+mGeRDk4zQ1i5W6kDgIvlUJzTg12 nmBN6Oek6cxKBQD2P+WtgblGxMXDErsXUoiC5yBRuEAbAoFaIlwuHwGnBBphpy7RQV0+ fJPV/Vevb9CRJK2LuF8vzTu48Z95WlD4z2VovHqA1DmkT+C+3j2NghqHQjmlkPfTL73O YepQ== X-Received: by 10.180.14.129 with SMTP id p1mr3085885wic.6.1368258080576; Sat, 11 May 2013 00:41:20 -0700 (PDT) Received: from ?IPv6:2a01:e35:8b73:8dd0:762f:68ff:fee5:8d8? ([2a01:e35:8b73:8dd0:762f:68ff:fee5:8d8]) by mx.google.com with ESMTPSA id ek7sm1996576wic.4.2013.05.11.00.41.19 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 11 May 2013 00:41:19 -0700 (PDT) Message-ID: <518DF619.1020405@gmail.com> Date: Sat, 11 May 2013 09:41:13 +0200 From: Sorin Manolache User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130112 Icedove/17.0.2 MIME-Version: 1.0 To: modules-dev@httpd.apache.org Subject: Re: Setting and accessing module specific directory References: <518A8CBB.1000003@gmail.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org On 2013-05-11 08:22, Sindhi Sindhi wrote: > Thankyou. > Had one more question. What is the right way of handling this - in which > location in Apache server directory should I be keeping my filter specific > files? > > As of now the XML and other files that are read by my filter are placed in > a new folder say "MyFilter" inside "httpd-2.4.4-win64\Apache24\htdocs". Is > this the right way of doing it? I think a more "elegant" solution would be to have the location configurable. For that, you define a module-specific configuration directive. (I am not familiar with apache 2.4, all my advice is based on apache 2.2, but I suppose there is a sufficient degree of backwards compatibility.) For defining configuration directives, you have to take the following steps: 1. You define one or two callback functions, create_dir_config and/or create_server_config. You put their addresses in the corresponing places in your module structure. These callback functions are called when apache starts up and they should create and return an application-specific configuration object that is opaque for apache; it sees it as a void pointer. The server-wide configuration object (created by create_server_config) contains configuration data that apply to the whole virtual host. The directory-wide configuration object (created by create_dir_config) contains configuration data that apply to a or . So, if you have a server with 3 virtual hosts, you have 3 server configuration objects per module. However you may have many more directory configuration objects, depending on your Locations and Directories. 2. You add one entry to the cmds array of your module structure for each configuration directive that you want to define. Each cmds array entry has a placeholder for your configuration directive-specific callback. The callback function is invoked by apache when it parses the configuration and it encounters the configuration directive specified by your module. 3. You define the configuration directive callback. The callback gets the arguments of the configuration directive. What the callback should do is to retrieve somehow the configuration object created by the callback in step 1 and initialise it with the arguments passed by apache (the configuration values). The directory-wide configuration object is passed in the second argument of the configuration callback. You just have to cast the void pointer to a pointer to the type of your configuration object. The server-wide configuration object is retrieved as follows: ap_get_module_config(params->server->module_config, &my_module) where params is the cmd_parms argument of the configuration directive callback and my_module is the name of your module structure object. Note that you don't need to use both a server-wide and a directory-wide configuration object. The simplest is to use a server-wide. However, a directory-wide gives you more configuration flexibility. The callbacks in steps 1-3 are not called as part of request processing. It's more an apache startup and configuration thing. Once apache starts processing the requests, it is properly configured and the values of your configuration directives are stored in the configuration objects. During request processing you'll just have to retrieve these values from the configuration objects. This is done is step 4: 4. You retrieve the configuration object of your module from the request_rec stucture. For the server-wide: MyConf *cnf = (MyConf *)ap_get_module_config(r->server->module_config, &my_module); For the directory-wide: MyConf *cnf = (MyConf *)ap_get_module_config(r->per_dir_config, &my_module); > Also, I have downloaded the 64-bit HTTP server from - > > http://www.apachelounge.com/download/win64/httpd-2.4.4-win64.zip > Is this the right official website to download Apache server? I think the official builds are downloaded from here: http://httpd.apache.org/download.cgi > > > On Wed, May 8, 2013 at 11:04 PM, Sorin Manolache wrote: > >> On 2013-05-08 17:02, Sindhi Sindhi wrote: >> >>> Hi, >>> >>> I have written a C++ Apache module that performs filtering of HTML >>> content. >>> >>> There are some XML files which are read by this filter when it does the >>> filtering. During run-time when this filter is invoked, I'd want the >>> filter >>> pick up these XML files and read them. I was thinking these XML files can >>> be placed in the server location "C:\Program >>> Files\httpd-2.4.4-win64\**Apache24\htdocs\MyFilter\". where MyFilter >>> folder >>> will contain all the XML files needed by my filter. How do I access this >>> location programatically during run-time when the filter is invoked? >>> >>> How can I get the absolute path of the server installation loacation >>> (C:\Program Files\httpd-2.4.4-win64\**Apache24\htdocs\) so that I can >>> append >>> "MyFilter\" to the same to get the location of the XML files? >>> >>> I have specified the below in httpd.conf file: >>> DocumentRoot "C:/Program Files/httpd-2.4.4-win64/**Apache24/htdocs" >>> ServerRoot "C:/Program Files/httpd-2.4.4-win64/**Apache24" >>> >>> The signature of my filter looks like this - >>> static apr_status_t myHtmlFilter(ap_filter_t *f, apr_bucket_brigade >>> *pbbIn) >>> >>> I will need the document root or server root or any other path variable >>> that I can access from my filter that will give me the absolute path >>> "C:/Program Files/httpd-2.4.4-win64/**Apache24" >>> >> >> const char *ap_server_root in http_main.h (apache 2.2. It could be similar >> in 2.4) contains the ServerRoot. >> >> ap_server_root_relative in http_config.h allows you to compose paths >> relative to the ServerRoot. >> >> Sorin >> >> >>> Thanks. >>> >>> >> >