So, as I said a few days ago, I'm trying to make a login script using CGI-C on a Apache server.
My form is submitting two variables to Test.cgi: username and password (pattern 2 to 40 characters only) using the POST method.
here is my code so far:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *lengthy;
int figures;
char somelimit[512];
lengthy = getenv("CONTENT_LENGTH");
figures = atoi(lengthy);
fgets(somelimit, figures, stdin);
printf("Content-type: text/html
");
printf("%s
", somelimit);
return 0;
}
Q. How do I extract username and password values from stdin? A normal return I'm getting in the above case is "username=xyz&password=xyz12" how do I process this?
Q.I want to limit what I read from CONTENT_LENGTH header, in-case of a malformed CONTENT-LENGTH header.
what type of Data is this header returning? I know it is supposed to return a "Decimal no of Octets". Valid values are 0 or more. I want to take 1 to X, where X is the upper limit, considering I have two variables, username/password, both limited to 40 characters each in html form.
I tried int[] and char[], instead of the pointer. Why can't I convert it directly with something like:
int some[1024];
some = atoi(gentenv("CONTENT_LENGTH"));
why is atoi considered unsafe?
Q. How do I take only the stdin to contain only US-ASCII characters, to avoid malformed message-body.
I'm a C Newbie, so please go easy :)
PS: Please don't recommend any frameworks/web-servers, etc.
Edit:I just realized that perhaps I asked too many questions. Sorry about that. I'm going to fix this post to make it cohesive and well bounded. Please stand by.
Edit2: This is the final question, no more edits. I will accept an answer which at least answers 2 out of 3 questions above.
See Question&Answers more detail:
os