bool WebServer::dispatchCommand(ConnectionType requestType, char *verb, bool tail_complete) { // if there is no URL, i.e. we have a prefix and it's requested without a // trailing slash or if the URL is just the slash if ((verb[0] == 0) || ((verb[0] == '/') && (verb[1] == 0))) { m_defaultCmd(*this, requestType, "", tail_complete); return true; } // if the URL is just a slash followed by a question mark // we're looking at the default command with GET parameters passed if ((verb[0] == '/') && (verb[1] == '?')) { verb += 2; // skip over the "/?" part of the url m_defaultCmd(*this, requestType, verb, tail_complete); return true; } // We now know that the URL contains at least one character. And, // if the first character is a slash, there's more after it. if (verb[0] == '/') { char i; char *qm_loc; int verb_len; int qm_offset; // Skip over the leading "/", because it makes the code more // efficient and easier to understand. verb++; // Look for a "/" separating the filename part of the URL from the // id. If it's not there, compare to the whole URL. qm_loc = strchr(verb, '/'); verb_len = (qm_loc == NULL) ? strlen(verb) : (qm_loc - verb); qm_offset = (qm_loc == NULL) ? 0 : 1; for (i = 0; i < this->bindingsLenght; ++i) { if ((verb_len == strlen(bindings[i].uri)) && (strncmp(verb, bindings[i].uri, verb_len) == 0)) { // Skip over the "verb" part of the URL (and the question // mark, if present) when passing it to the "action" routine processRestReguest(requestType, verb + verb_len + qm_offset, tail_complete, bindings[i]); return true; } } // Look for a "?" separating the filename part of the URL from the // parameters. If it's not there, compare to the whole URL. qm_loc = strchr(verb, '?'); verb_len = (qm_loc == NULL) ? strlen(verb) : (qm_loc - verb); qm_offset = (qm_loc == NULL) ? 0 : 1; for (i = 0; i < m_cmdCount; ++i) { if ((verb_len == strlen(m_commands[i].verb)) && (strncmp(verb, m_commands[i].verb, verb_len) == 0)) { // Skip over the "verb" part of the URL (and the question // mark, if present) when passing it to the "action" routine m_commands[i].cmd(*this, requestType, verb + verb_len + qm_offset, tail_complete); return true; } } } return false; }
bool WebServer::dispatchCommand(ConnectionType requestType, char *verb, bool tail_complete) { if ((verb[0] == 0) || ((verb[0] == '/') && (verb[1] == 0))) { m_defaultCmd(*this, requestType, verb, tail_complete); return true; } // We now know that the URL contains at least one character. And, // if the first character is a slash, there's more after it. if (verb[0] == '/') { char i; char *qm_loc; int verb_len; int qm_offset; // Skip over the leading "/", because it makes the code more // efficient and easier to understand. verb++; // Look for a "?" separating the filename part of the URL from the // parameters. If it's not there, compare to the whole URL. qm_loc = strchr(verb, '?'); verb_len = (qm_loc == NULL) ? strlen(verb) : (qm_loc - verb); qm_offset = (qm_loc == NULL) ? 0 : 1; for (i = 0; i < m_cmdCount; ++i) { if ((verb_len == strlen(m_commands[i].verb)) && (strncmp(verb, m_commands[i].verb, verb_len) == 0)) { // Skip over the "verb" part of the URL (and the question // mark, if present) when passing it to the "action" routine m_commands[i].cmd(*this, requestType, verb + verb_len + qm_offset, tail_complete); return true; } } } return false; }