Ask Questions & Get Answers at ibibo sawaal

113

Rank

8147

1692

26

34

How do I create a client certificate?

Asked by ram lal in Computers & Technology at   5:29 AM on December 04, 2008

Sudipta Deb's Answer

Certificates can be obtained from one of the following:

Certificate Authority (CA)
Create a client certificate request. After receiving the certificate, export it to a password-protected PKCS12 file and send the password and the file to the user. Make sure the file is securely sent. If a non-secure protocol such as e-mail, http, or ftp is used to send the file over the Internet, the certificate's security can be compromised.
Self-signed certificate
You can do this while you are waiting for a CA's certificate, which can take some time. If you think the self-signed certificate provides adequate security, you can use it permanently.

Answered at 5:48 AM on December 04, 2008

Read all answers

What are Apache Filters?

Asked by ram lal in Computers & Technology at   5:31 AM on December 04, 2008

Sudipta Deb's Answer

The Apache version 2 API was rewritten to make Apache much easier to extend. One of the major changes was the introduction of a filter API which allows you to write code which examines and possibly modifies the request data flowing into the web server from the client and the response data flowing back from the web server to the client.

This data may flow through various filters which may transform it in various ways. For example, SSL is implemented in Apache 2 as a filter which deals with the encryption of the request and the response.

Answered at 5:47 AM on December 04, 2008

Read all answers

Is filtering supported in Apache Version 1?

Asked by ram lal in Computers & Technology at   5:33 AM on December 04, 2008

Sudipta Deb's Answer

The filtering architecture discussed here was introduced in Apache 2.

Answered at 5:47 AM on December 04, 2008

Read all answers

What's the difference between an Apache "module", a "filter" and a "handler"?

Asked by ram lal in Computers & Technology at   5:32 AM on December 04, 2008

Sudipta Deb's Answer

"Module" is a general term for any code that gets linked with or loaded by Apache and uses the Apache API. "Handler" and "Filter" are 2 subdivisions of this term which describe different types of input and output processors. Simplistically:

A Handler generate the response sent back to the client. Each request will be claimed by and "handled" by a single handler.

Filters can inspect this response and optionally change the content in various ways: insert content (eg mod_include), encrypt it (mod_ssl), compress it (mod_deflate) or perhaps "chunk" the response differently.

The content generated by the Handler is exposed to the output filters using the Apache Bucket API - the filters get to see it (and operate on it) on its journey through Apache back to the client.

Handlers register with Apache during their initialisation, and may be specified in the Apache config using the AddHandler or SetHandler directives. Apache will invoke all registered handlers in turn until one "accepts" the responsibility of generating the response to the request.

Similarly, filters register with Apache during their initialisation, and may be specified in the Apache config using the AddInput/OutputFilter or SetInput/OutputFilter directives. But whereas only one handler generates the response, any number of output filters can read or modify it using the Apache Bucket API. And any number of input filters can read and modify the request before the handler sees it (again using the Bucket API).

Examples of handlers can be found in the "generators" and "mappers" subdirectory of the Apache "modules" source directory, and filters in the "filters" subdirectory.

Of course, a single module could be both a filter and a handler - it just has to register with Apache when it wants to be invoked.

Answered at 5:47 AM on December 04, 2008

Read all answers

How does the Apache process and thread architecture effect my filter?

Asked by ram lal in Computers & Technology at   5:37 AM on December 04, 2008

Sudipta Deb's Answer

Your filter code should expect to run in any of the Apache Multi-Processing Modules (MPM) environments.

Depending on how Apache has been configured, the process in which your filter is running may be one of many running the Apache server, and may have many threads running in the process. Your filter will be initialised every time a process is created, which may be quite often, again depending in Apache configuration and on server load.

With the multi-threaded MPMs, you must be aware that several threads of execution could be concurrently running in your filter, and hence use interthread locking where appropriate (see Thread Safety, and the APR Thread Mutex and Atomic operations).

But imagine you wish to share a connection pool or heavy-weight structures been instances of your filter across Apache process. In this case you can use the APR's abstraction of shared memory or "backing storage" such as disk files or external databases.

It is a common misconception to think that filters running in separate processes can somehow share static variables! These can (and are) "shared" however between threads, and sometimes access has to be appropriately controlled to prevent unexpected corruption.

Answered at 5:45 AM on December 04, 2008

Read all answers

How do I set up a filter which can both look at the request and the response?

Asked by ram lal in Computers & Technology at   5:35 AM on December 04, 2008

Sudipta Deb's Answer

In your module AP_MODULE_DECLARE_DATA structure, define a "register hooks" callback. This will be invoked as part of your module's initialisation, and gives a chance for your module to register for any of the processing hooks Apache makes available.

One of the hooks you should register for is ap_hook_insert_filter hook, something like this:


static ap_filter_rec_t * globalMyInputFilter ;
static ap_filter_rec_t * globalMyOutputFilter ;

...

static void myModuleRegisterHooks(apr_pool _t *p) {

ap_hook_insert_filter(myModule InsertFilters, NULL, NULL, APR_HOOK_MIDDLE) ;

globalMyInputFilter = ap_register_input_filter(myInp utFilterName, myInputFilter,
NULL, AP_FTYPE_RESOURCE) ;

globalMyOutputFilter = ap_register_output_filter(myOu tputFilterName, myOutputFilter,
NULL, AP_FTYPE_RESOURCE) ;

}

This will result in your function myModuleInsertFilters being invoked on each request. This code also registers the 2 filters, one input and one output, and saves the resultant pointers to Apache filter record structures, which makes the next step performed at a "per request" level more efficient...

Now, on each request, Apache will invoke your myModuleInsertFilters callback code. It has to decide whether it is interested in this request (maybe by looking at the request and configuration data), and if so, add the filters to the request.

Each filter can be associated with a "context", and by setting the same context on both filters, you make it easy for them to share data, status etc.

For example:


static void myModuleInsertFilters(request_ rec *r) {

MyPerRequestContext *ctx ;

MyPerServerConfig *myServerConfig = ap_get_module_config(r->server ->module_config,
&myFilter_module);

if(!myServerConfig->enabled) return ; // some server level enablement switch

if (.....) { // some other "are we interested?" type tests...
return ; // return without doing anything
}

ctx = apr_palloc(r->pool, sizeof(*ctx)) ; // allocate my "per request" context from the
// Apache-managed "per request" memory pool
ctx->status = 0 ; // initialise it...
....

// add the input and output handlers, sharing a context

ap_add_input_filter_handle(glo balMyInputFilter, ctx, r, r->connection) ;
ap_add_output_filter_handle(gl obalMyOutputFilter, ctx, r, r->connection) ;
}

Answered at 5:46 AM on December 04, 2008

Read all answers

What is willpower?I want some notes about that.?

Asked Anonymously in Stress at   3:40 AM on December 04, 2008

Sudipta Deb's Answer

Willpower is the ability to exert one's will over one's actions.
Willpower manifests as inner firmness, decisiveness, determination, resolution and persistence.

Answered at 5:42 AM on December 04, 2008

Read all answers

What is the Java Message Service? ?

Asked by ram lal in Computers & Technology at   5:42 AM on December 04, 2008

Sudipta Deb's Answer

The Java Message Service (JMS) API is a Java Message Oriented Middleware (MOM) API for sending messages between two or more clients. JMS is a part of the Java Platform, Enterprise Edition, and is defined by a specification developed under the Java Community Process as JSR 914.

Answered at 5:43 AM on December 04, 2008

Read all answers

How do I access the request data POSTed by the client?

Asked by ram lal in Computers & Technology at   5:39 AM on December 04, 2008

Sudipta Deb's Answer

Insert your code as an input filter and use the Bucket API to read any request data.

A common question is "what field in the request structure points to the POSTed request data?". However, there is no such field. Because the length of the POSTed data is unbounded, Apache could not store it in a data structure without limiting its length (and hence breaking HTTP standard compliant applications of the protocol) or risking denial-of-service-based on innocent-error-caused exhaustion of address space resources.

The best way to get access to POSTed data and "play nicely" in the Apache world is to use an input filter. It will also allow you to access SSL encrypted request data (assuming that your filter accesses the input bucket brigade after the SSL input filter, which it almost certainly will).

Answered at 5:44 AM on December 04, 2008

Read all answers

How do I arrange for a handler to be invoked for specific requests?

Asked by ram lal in Computers & Technology at   5:40 AM on December 04, 2008

Sudipta Deb's Answer

First up, handlers and filters are different beasts - handlers are primary content generators whereas filters can inspect and alter content (more on the differences here).

The tricky concept with handlers is that Apache invokes all registered handlers one by one until one of them accepts the responsibility of being the primary content generator. Apache points to a handler name from the request structure. This handler name can be specified by AddHandler/SetHandler directives in the Apache configuration file (see the Apache handler documentation for details).

So, the first thing a handler should do is check whether it is the "nominated" handler for this particular request, and return DECLINED if not, as soon as possible.
For example, given this configuration:

<Location /testLocation>
SetHandler my-test-handler
</Location>

then when processing a request for, say, "/testLocation/test" Apache will set the request handler field to point to the string "my-test-handler". It will then invoke each handler registered with it to see which wants to "claim" the right to generate the response.
So, imagine a module which registers from its "register hooks" entry-point like this:

static void my_module_register_hooks(apr_p ool_t *p) {
ap_hook_handler(my_module_hand ler, NULL, NULL, APR_HOOK_MIDDLE) ;
}

Apache will invoke "my_module_handler" for each and every request (unless some other handler of a higher priority (see that last parameter on the "ap_hook_handler" invocation!) is invoked first and claims the request.
So, in the "my_module_handler" you'll want to DECLINE the request (that is, leave it to some other handler) unless the request handler field specifies the "magic string" (in this case, "my-test-handler") which identifies you as the handler:

static int my_module_handler(request_rec *r) {

if (!r->handler || strcmp(r->handler, "my-test-handler"))
return DECLINED ;

// I've been nominated to handle this request!
...

return OK ; // means I've handled the request - no other handlers need be asked
}

Answered at 5:44 AM on December 04, 2008

Read all answers

Editor's Pick

Categories

sawaal signature
sawaal free visiting card