Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool parse(const char* line, char* abs_path, char* query)
- {
- if (line[0] != 'G' && line[1] != 'E' && line[2] != 'T' && line[3] != ' ')
- {
- error(405);
- return false;
- }
- if (line[3] != ' ')
- {
- error(405);
- return false;
- }
- else if (line[4] != '/')
- {
- error(501);
- return false;
- }
- char* temp_path = strchr(line, '/');
- int index = 0;
- for (int length = strlen(temp_path); index < length; index++)
- {
- if (temp_path[index] == ' ')
- {
- break;
- }
- }
- strncpy(abs_path, temp_path, index);
- abs_path[index] = '\0';
- for (int i = 0, n = strlen(abs_path); i < n; i++)
- {
- if (abs_path[i] == '"')
- {
- error(400);
- return false;
- }
- if (abs_path[i] == '?')
- {
- return false;
- }
- }
- char* temp_query = strchr(line, '?');
- if (temp_query != NULL)
- {
- index = 0;
- for (int length = strlen(temp_query); index < length; index++)
- {
- if (temp_query[index] == ' ')
- {
- break;
- }
- }
- strncpy(query, temp_query, index);
- }
- char* version = strstr(line, "HTTP/1.1");
- if (version == NULL)
- {
- error(505);
- return false;
- }
- else if (line[index + 1] == 'H' && line[index + 2] == 'T' && line[index + 3] == 'T' && line[index + 4] == 'P' &&
- line[index + 5] == '/' && line[index + 6] == '1' && line[index + 7] == '.' && line[index + 8] == '0')
- {
- error(505);
- return false;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement