Programming newbie question - time(null)

July 15, 2009 at 17:59:40
Specs: Linux
I have some code working now (mod_auth_mysql) and just want to add one tiny thing to it.

Something that should be super easy, but I've been messing with it for a couple of hours and can't figure it out as I'm not worth a flip in C++.

The code currently supports passing parameters to it like %a for IP address and other stuff...

I Just want to add a new parameter called %t to compare what I pass to the current UNIX time.

Here are what I think is the important parts of the code and the areas I believe it would be easy to insert what I want.

Somewhere in these areas I just need to get a time(NULL) to compare the %t I want to pass to it. I just don't know how to add it...

So below is how the code is now. I just need to know how to add the new %t parameter and make it match again the current time(NULL).

*****SNIP*****

static char * format_remote_ip(request_rec * r, char ** parm);

*****SNIP*****

typedef struct { /* User formatting patterns */
char pattern; /* Pattern to match */
char * (*func)(request_rec * r, char ** parm);
} format;

format formats[] = {{'h', format_remote_host},
{'a', format_remote_ip},

*****SNIP*****

static char * format_remote_ip(request_rec * r, char ** parm) {
return r->connection->remote_ip;
}

*****SNIP*****


See More: Programming newbie question - time(null)

Report •


#1
July 16, 2009 at 16:06:29
In case somebody is ever interested. I had some help and got
it working. Here is the code:

******* SNIP *******

static char * format_the_time(request_rec * r, char ** parm);

******* SNIP *******

typedef struct { /* User formatting patterns */
char pattern; /* Pattern to match */
char * (*func)(request_rec * r, char ** parm);
} format;

format formats[] = {{'h', format_remote_host},
{'a', format_remote_ip},
{'t', format_the_time},

******* SNIP *******

static char * format_the_time(request_rec * r, char ** parm) {
static char buffer[ 64 ];
unsigned int now = (unsigned int)time(NULL);
sprintf(buffer, "%u", now);
return buffer;
}

******* SNIP *******


Report •
Related Solutions


Ask Question