The strtok()
call here:
char* absolute_path = strtok(req_tar, "?");
will crop req_tar
at the ?
and make it always be equal to abs_path
.
Because of this, the following condition will never be true and you'll never extract query
:
if(strcmp(req_tar, abs_path) != 0)
query = strstr(req_tar, abs_path);
But even if that condition triggered, I don't think you understand what query
should be.
Given a line "GET /hello.php?name=Alice HTTP/1.1\r\n"
, this is what you should extract:
abs_path
should be/hello.php
query
should bename=Alice
And this query = strstr(req_tar, abs_path);
wouldn't make query
become this name=Alice
.