0

At the moment I store them in global. Is that the correct way ? I want the variable to stay with the current request and goes away after the request is finished.

For example:

int data1;
int data2;

apr_status_t my_input_filter (ap_filter_t *f, apr_bucket_brigade *bb,
    ap_input_mode_t mode, apr_read_type_e block, apr_off_t readbytes) {
    if (somecond1) data1 = xyz;
    if (somecond2 & data1 == xya) data2 = abc;

    if (somecond3 && data2 == abc) dosomething();
}

Note that the 3 cond may not happen in one go while filtering, they may appear at different moment, but with the same request.

w00d
  • 5,416
  • 12
  • 53
  • 85

1 Answers1

0

If your module runs with either the event or the multithreaded package, storing in a global variable is a bad bad bad idea.

Apache provides a notes dictionary in the request structure. Use it for storing your private data.

MJZ
  • 1,074
  • 6
  • 12
  • For input_filter, my f->r is always NULL I guess I can't use the note – w00d Dec 08 '12 at 08:00
  • Trick #2: create your own hash table indexed by connection that stores your data. Add a cleanup hook to the connection->pool to remove the hash entry when the connection dies. – MJZ Dec 08 '12 at 14:28