I think I have implemented most of the parse function in server but I don't understand character pointers well enough to finish I think. I know the strchr function finds the character in the string and returns a pointer to the rest of the string starting at that character but I don't know how to get a string that only points to the part of the string that ends in a character. I think maybe I have to copy it to an array but I'm not 100% sure on how I would do that. Or can you access character inside a pointer the same way as an array? And can you use strlen on it? here is my card code which passes too many characters into abs_path and query:
bool parse(const char* line, char* abs_path, char* query)
{
//make sure method request is get
const char* get = "GET /";
if (strncmp(get, line, 4) != 0)
{
error(405);
return false;
}
//make sure request Target begins with slash
if (strncmp(get, line, 5) != 0)
{
error(501);
return false;
}
const char* qu = '"';
const char* qm = '?';
const char* sp = ' ';
const char* sl = '/';
//separate requests Target
char *rt = strchr (line, sp);
//get absolute path path
abs_path = strchr (rt, sl);
// get query
if (strchr (rt, qm) == NULL)
query = '/0';
else
{
query = strchr (rt, qm);
}
//check for HTTP 1.1
char *rst = strchr (line, sp);
char *http = ' HTTP/1.1';
if (strstr(rst, http) == NULL)
{
error(505);
return false;
}
//check for the other thing
char *http = 'HTTP/1.1\r\n';
if (strstr(rst, http) == NULL)
{
error(505);
return false;
}
//check for quotation marks in request
if (strchr( rt, qu) != NULL)
{
error(400);
return false;
}
}