Avatar billede drakster Nybegynder
21. oktober 2006 - 17:17 Der er 2 kommentarer og
1 løsning

Kompilering af Apache modul slå fejl.

Hej Eksperter.

Jeg har et problem som jeg formoder vil være let at løse for folk som tidligere har udviklet moduler til apache.

Jeg har installeret en Apache 2.2.3 på en Fedora Core 5 dist  ganske efter bogen:

./configure prefix=/usr/local/apache
make
make install

Jeg prøver herefter at kompilere følgende lille modul:

#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 */
};


Jeg forsøger at kompilere ud fra følgende kommando:
gcc -fPIC -I$INCLUDE -c time_cookie.c -o time_cookie.o

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

Problemet er at jeg får følgende fejl:

[root@fedora modules]# gcc -fPIC -I$include -c time-cookie.c -o time-cookie.o
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

Og jeg forstår intet af det.

Er der nogen som evt. kunne komme med lidt hjælp?

Eksemplet er iøvrigt taget lige ud af følgende side:

http://www-128.ibm.com/developerworks/linux/library/l-apache/?loc=dwmain
Avatar billede drakster Nybegynder
21. oktober 2006 - 17:17 #1
Shit den røg ind under forkert kategori. Kan man flytte den eller skal jeg oprette et nyt spørgsmål?
Avatar billede leif Seniormester
21. oktober 2006 - 17:20 #2
Luk og opret nyt er løsningen
Avatar billede drakster Nybegynder
21. oktober 2006 - 17:35 #3
ok. tak for det
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester