Computing.Net > Forums > Programming > Programming newbie question - time(null)

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Programming newbie question - time(null)

Reply to Message Icon

Name: CPLUSNEWB
Date: July 15, 2009 at 17:59:40 Pacific
OS: Linux
Subcategory: C/C++
Comment:

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*****



Sponsored Link
Ads by Google

Response Number 1
Name: CPLUSNEWB
Date: July 16, 2009 at 16:06:29 Pacific
Reply:

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 *******


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Programming newbie question - time(null)

QBasic newbie question www.computing.net/answers/programming/qbasic-newbie-question/7211.html

hm just a few questions www.computing.net/answers/programming/hm-just-a-few-questions/13257.html

Batch File Question - Newbie www.computing.net/answers/programming/batch-file-question-newbie/15511.html