Jump to content


Photo

Apache module compile error


  • Please log in to reply
No replies to this topic

#1 hausner

hausner
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 22 October 2006 - 10:19 AM

Hi Guys

Im trying to compile a fairly simple apache module but i cant seem to get it to work.

Heres the module time-cookie.c:

#include "httpd.h"
#include "util_filter.h"
#include "http_config.h"
#include "http_log.h"

/* The string which is to be replaced by the time stamp */
static char TIME_COOKIE[] = "***TIME-COOKIE***";

/* Declare the module name */
module AP_MODULE_DECLARE_DATA time_cookie;

typedef struct tc_context_ {
apr_bucket_brigade *bb;
apr_time_t timestamp;
} tc_context;

/*
This function passes in the system filter information (f)
and the bucket brigade representing content to be filtered (bb)
*/
static int time_cookie_filter(ap_filter_t *f, apr_bucket_brigade *bb)
{
tc_context *ctx = f->ctx; /* The filter context */
apr_bucket *curr_bucket;
apr_pool_t *pool = f->r->pool; /* The pool for all memory requests */
/* The buffer where we shall place the time stamp string.
APR_RFC822_DATE_LEN the fixed length of such strings */
char time_str[APR_RFC822_DATE_LEN+1];
apr_time_t timestamp;

if (ctx == NULL) {
/* The first time this filter has been invoked for this transaction */
f->ctx = ctx = apr_pcalloc(f->r->pool, sizeof(*ctx));
ctx->bb = apr_brigade_create(f->r->pool, f->c->bucket_alloc);
timestamp = apr_time_now();
ctx->timestamp = timestamp;
}
else {
/* Get the time stamp we've already set */
timestamp = ctx->timestamp;
}

/* Render the time into a string in RFC822 format */
apr_rfc822_date(time_str, timestamp);

/*
Iterate over each bucket in the brigade.
Find each "cookie" in the "kitchen" and replace with the time stamp
*/
APR_BRIGADE_FOREACH(curr_bucket, bb) {
const char *kitchen, *cookie;
apr_size_t len;

if (APR_BUCKET_IS_EOS(curr_bucket) || APR_BUCKET_IS_FLUSH(curr_bucket)) {
APR_BUCKET_REMOVE(curr_bucket);
APR_BRIGADE_INSERT_TAIL(ctx->bb, curr_bucket);
ap_pass_brigade(f->next, ctx->bb);
return APR_SUCCESS;
}
apr_bucket_read(curr_bucket, &kitchen, &len, APR_NONBLOCK_READ);
while (kitchen && strcmp(kitchen, "")) {
/* Return a poiner to the next occurrence of the cookie */
cookie = ap_strstr(kitchen, TIME_COOKIE);
if (cookie) {
/* Write the text up to the cookie, then the cookie
to the next filter in the chain
*/
ap_fwrite(f->next, ctx->bb, kitchen, cookie-kitchen);
ap_fputs(f->next, ctx->bb, time_str);
kitchen = cookie + sizeof(TIME_COOKIE) - 1;
/*
The following is an example of writing to the error log.
The message is actually not really appropriate for the error log,
but it serves as example.
*/
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, f->r,
"Replacing cookie with \"%s\"", time_str);
} else {
/* No more cookies found, so just write the rest of the
string and flag that we're done
*/
ap_fputs(f->next, ctx->bb, kitchen);
kitchen = "";
}
}
}
return APR_SUCCESS;
}

/* Register the filter function as a filter for modifying the HTTP body (content) */
static void time_cookie_register_hook(apr_pool_t *pool)
{
ap_register_output_filter("TIMECOOKIE", time_cookie_filter,
AP_FTYPE_CONTENT_SET);
}

/* Define the module data */
module AP_MODULE_DECLARE_DATA time_cookie =
{
STANDARD20_MODULE_STUFF,
NULL, /* dir config creater */
NULL, /* dir merger --- default is to override */
NULL, /* server config */
NULL, /* merge server config */
NULL, /* command apr_table_t */
time_cookie_register_hook /* register hook */
};

Taken from this site:

www-128.ibm.com/developerworks/linux/library/l-apache/?loc=dwmain

When i run the command:

[root@fedora modules]# gcc -fPIC -I$include -c time-cookie.c -o time-cookie.o

where

[root@fedora modules]# $include
-bash: /usr/local/apache/include/: is a directory

i get the following error:

In file included from /usr/local/apache/include/ap_config.h:25,
from /usr/local/apache/include/httpd.h:43,
from time-cookie.c:1:
/usr/local/apache/include/apr.h:270: error: expected â=â, â,â, â;â, âasmâ or â_attribute__â before âapr_off_tâ
In file included from /usr/local/apache/include/apr_file_io.h:29,
from /usr/local/apache/include/apr_network_io.h:26,
from /usr/local/apache/include/httpd.h:53,
from time-cookie.c:1:
/usr/local/apache/include/apr_file_info.h:204: error: expected specifier-qualifer-list before âapr_off_tâ
In file included from /usr/local/apache/include/apr_network_io.h:26,
from /usr/local/apache/include/httpd.h:53,
from time-cookie.c:1:
/usr/local/apache/include/apr_file_io.h:548: error: expected declaration specifers or â...â before âapr_off_tâ
/usr/local/apache/include/apr_file_io.h:740: error: expected declaration specifers or â...â before âapr_off_tâ
In file included from /usr/local/apache/include/httpd.h:53,
from time-cookie.c:1:
/usr/local/apache/include/apr_network_io.h:545: error: expected declaration speifiers or â...â before âapr_off_tâ
In file included from /usr/local/apache/include/apr_buckets.h:32,
from /usr/local/apache/include/httpd.h:54,
from time-cookie.c:1:
/usr/local/apache/include/apr_mmap.h:134: error: expected declaration specifier or â...â before âapr_off_tâ
/usr/local/apache/include/apr_mmap.h:161: error: expected declaration specifier or â...â before âapr_off_tâ
In file included from /usr/local/apache/include/httpd.h:54,
from time-cookie.c:1:
/usr/local/apache/include/apr_buckets.h:242: error: expected specifier-qualifie-list before âapr_off_tâ
/usr/local/apache/include/apr_buckets.h:706: error: expected declaration specifers or â...â before âapr_off_tâ
/usr/local/apache/include/apr_buckets.h:718: error: expected declaration specifers or â...â before âapr_off_tâ
/usr/local/apache/include/apr_buckets.h:754: error: expected declaration specifers or â...â before âapr_off_tâ
/usr/local/apache/include/apr_buckets.h:890: error: expected declaration specifers or â...â before âapr_off_tâ
/usr/local/apache/include/apr_buckets.h:891: error: expected declaration specifers or â...â before âapr_off_tâ
/usr/local/apache/include/apr_buckets.h:1168: error: expected declaration speciiers or â...â before âapr_off_tâ
/usr/local/apache/include/apr_buckets.h:1367: error: expected declaration speciiers or â...â before âapr_off_tâ
/usr/local/apache/include/apr_buckets.h:1381: error: expected declaration speciiers or â...â before âapr_off_tâ
/usr/local/apache/include/apr_buckets.h:1431: error: expected declaration speciiers or â...â before âapr_off_tâ
/usr/local/apache/include/apr_buckets.h:1447: error: expected declaration speciiers or â...â before âapr_off_tâ
In file included from time-cookie.c:1:
/usr/local/apache/include/httpd.h:826: error: expected specifier-qualifier-listbefore âapr_off_tâ
In file included from time-cookie.c:2:
/usr/local/apache/include/util_filter.h:142: error: expected declaration specifers or â...â before âapr_off_tâ
/usr/local/apache/include/util_filter.h:299: error: expected declaration specifers or â...â before âapr_off_tâ
time-cookie.c: In function âtime_cookie_filterâ:
time-cookie.c:50: error: expected â;â before â{â token
time-cookie.c: In function âtime_cookie_register_hookâ:
time-cookie.c:94: warning: passing argument 3 of âap_register_output_filterâ maes pointer from integer without a cast
time-cookie.c:94: error: too few arguments to function âap_register_output_filtrâ
time-cookie.c:107:3: warning: no newline at end of file

What am i doing wrong. The error does not make any sense to me.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users