I have been trying to use GDB to find errors in my code. I went through the steps @MARS gave me as an answer to one of my questions. However, when I tried to list the values of my variables by using curl i...
, I received an infinite loop.
Why am I receiving an infinite loop? How can I use curl i...
with my code?
Thanks in advance.
Here are my check50 errors: http://pastebin.com/sac9tkkp
Here is my code:
bool parse(const char* line, char* abs_path, char* query)
{
const char* copy_line = line;
char* method_str = "";
int method_length = strlen(method_str);
strtok(method_str, copy_line);
char* request_str = "";
int request_length = strlen(request_str);
strtok(request_str, copy_line);
char* http_ver_str = "";
int http_ver_str_length = strlen(http_ver_str);
strtok(http_ver_str, copy_line);
char* path;
char* query_str;
int query_length;
if (request_str != NULL)
{
path = "";
strtok(path, copy_line);
query_str = "";
query_length = strlen(query);
strtok(query_str, copy_line);
}
for (int i = 0; i < method_length; i++)
{
char space[2] = " ";
const char* letter = &method_str[i];
if (strcmp(letter, space) == 0)
{
printf("this is method_str[i]: %c", method_str[i]);
error(400);
return false;
}
}
char quote = '"';
for (int c = 0; c < request_length; c++)
{
char space[2] = " ";
const char* letter2 = &request_str[c];
if (strcmp(letter2, space) == 0)
{
printf("this is request_str[c]: %c", request_str[c]);
error(400);
return false;
}
if (request_str[c] == quote)
{
printf("this is request_str[c]: %c", request_str[c]);
error(400);
return false;
}
if (c == 0)
{
if (request_str[c] != '/')
{
error(501);
return false;
}
}
}
for (int j = 0; j < http_ver_str_length; j++)
{
if (http_ver_str[j] == quote)
{
printf("This is http_ver_str[j]: %c", http_ver_str[j]);
error(400);
return false;
}
}
if (path[0] != '/')
{
printf("This is path[0]: %c", path[0]);
error(400);
return false;
}
for (int k = 0; k < query_length; k++)
{
if (query_str[k] == quote)
{
printf("This is query_str[k]: %c", query_str[k]);
error(400);
return false;
}
}
if (strcmp(method_str, "GET") != 0)
{
error(405);
return false;
}
//if (strcmp(request_str[0], '/') != 0)
//{
// error(501);
//return false;
//}
if (strcmp(http_ver_str, "HTTP/1.1") != 0)
{
error(505);
return false;
}
abs_path = path;
query = query_str;
return true;
}