Hello,

I am trying to write a protocol module for Apache
which will encrypt data and send to-from Apache. (I
can not use mod_SSL for some reasons). My module code
builds and loads fine.
After the module is loaded, when I send a simple GET
request to my Apache server as follows
        https://localhost/cgi-bin/hello_name.exe?name=Rhino

I get the expected output from my CGI at the client
but then my client hangs waiting for more
response/data from the server.

Since this is a protocol module, it directly reads
from socket and writes to the socket. The functions
that read and write to a socket respectively are
SSCryptoRead() and SSCryptoWrite(). After I read the
data using SSCryptoRead, I insert it into the buckets
so that is passed to my content generator which is the
CGI (hello_name.exe) as shown in the URL above. Then
in the output filters, I grab the generated data and
encrypt and send it back to the client using function
SSCryptoWrite.

I doubt if my problem could be related to not
inserting and EOS bucket. But I am not sure if I am
supposed to enter an EOS bucket or Apache would do it
for me.
I am also not sure if I need so set something like
KEEP-ALIVE or CLOSE in my request or response. Since
my code is much like SSL, I tried looking up the SSL
code but I could not find anything of help. Can anyone
point me to what might be missing here? Are there any
special steps to be taken while writing a protocol
module? 

An extract of my module code is pasted below...


module AP_MODULE_DECLARE_DATA  ss_module = {
    STANDARD20_MODULE_STUFF,
    NULL,
    NULL,
    ss_config_server_create,
    NULL,
    ss_config_cmds,
    ss_register_hooks
};


static void ss_register_hooks (apr_pool_t *p) {
        ap_register_input_filter  (ss_io_filter,
ss_io_filter_input,  NULL, AP_FTYPE_CONNECTION + 5);
        ap_register_output_filter (ss_io_filter,
ss_io_filter_output, NULL, AP_FTYPE_CONNECTION + 5);
        ap_hook_post_config       (ss_init_Module,           
 NULL, NULL, APR_HOOK_MIDDLE);
        ap_hook_pre_connection   
(ss_hook_pre_connection,NULL,NULL, APR_HOOK_MIDDLE);
}

static apr_status_t ss_io_filter_input(ap_filter_t *f,
apr_bucket_brigade *bb, ap_input_mode_t mode,
apr_read_type_e block, apr_off_t readbytes) {
        .
        .
        .
        len =
SSSecureRead(inctx->filter_ctx->session_ctx->session,
buf, &len);
        if (len > 0) {
                apr_bucket *bucket =
apr_bucket_transient_create(inctx->buffer, len,
f->c->bucket_alloc);
                APR_BRIGADE_INSERT_TAIL(bb, bucket);
        }
        return APR_SUCCESS;
}

static apr_status_t ss_io_filter_output(ap_filter_t
*f, apr_bucket_brigade *bb) {
        .
        .
        .
        while (!APR_BRIGADE_EMPTY(bb)) {
                apr_bucket *bucket = APR_BRIGADE_FIRST(bb);

                if (APR_BUCKET_IS_EOS(bucket) ||
APR_BUCKET_IS_FLUSH(bucket)) {
                        if (ss_filter_out_flush(filter_ctx->pWriteptr) < 0)

                                status = outctx->rc;
                        break;
                }
                else if (AP_BUCKET_IS_EOC(bucket)) {
                        if ((status = ap_pass_brigade(f->next, bb)) !=
APR_SUCCESS) 
                                return status;
                        break;
                }
                else {
                        const char *data;
                        apr_size_t len;
                        /*Read the data from the buckets and write it to
the socket*/
                        status = apr_bucket_read(bucket, &data, &len,
rblock);
                        res =
SSCryptoWrite(filter_ctx->session_ctx->session, data,
len);
                }
        }

        return APR_SUCCESS;
}

Any suggestions/pointers would be highly appreciated.

Thanks,


Amol


 
____________________________________________________________________________________
Get your email and see which of your friends are online - Right on the New 
Yahoo.com 
(http://www.yahoo.com/preview) 

Reply via email to