Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool parse(const char* line, char* abs_path, char* query)
- {
- char forwardSlash = '/';
- char* requestPath = strchr(line, forwardSlash);
- char queryChar = '?';
- char* queryString = strrchr(line, queryChar);
- unsigned int lineLength = strlen(line);
- query[0] = '\0';
- //check if the HTTP version in a request is 1.1
- char* httpVersion = strstr(line,"HTTP/1.1");
- if (httpVersion == NULL)
- {
- error (505);
- return false;
- }
- // iterates through line character by character
- for (int i = 0; i < lineLength; i++)
- {
- if (line[i] == forwardSlash)
- {
- strcpy(abs_path,requestPath);
- }
- if (line[i] == queryChar)
- {
- strcpy(query, queryString);
- }
- }
- // Check if the request-target has a forward slash
- if (abs_path[0] != '/')
- {
- error(501);
- return false;
- }
- // Check if the request-target does not contain a speech mark
- else if (strstr(line, "\"") != NULL )
- {
- error(400);
- return false;
- }
- // Check if the request method is GET
- char* method = strstr(line,"GET");
- if (strncmp(line, method,sizeof(3)) != 0 )
- {
- error (405);
- return false;
- }
- error(501);
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement