Esempio n. 1
0
void WebServer::processConnection(char *buff, int *bufflen)
{
  m_client = m_server.available();

  if (m_client) {
    m_readingContent = false;
    buff[0] = 0;
    ConnectionType requestType = INVALID;
#if WEBDUINO_SERIAL_DEBUGGING > 1
    Serial.println("*** checking request ***");
#endif
    getRequest(requestType, buff, bufflen);
#if WEBDUINO_SERIAL_DEBUGGING > 1
    Serial.print("*** requestType = ");
    Serial.print((int)requestType);
    Serial.println(", request = \"");
    Serial.print(buff);
    Serial.println("\" ***");
#endif
    processHeaders();
#if WEBDUINO_SERIAL_DEBUGGING > 1
    Serial.println("*** headers complete ***");
#endif

    int urlPrefixLen = strlen(m_urlPrefix);
    if (strcmp(buff, "/robots.txt") == 0)
    {
      noRobots(requestType);
    }
    else if (requestType == INVALID ||
             strncmp(buff, m_urlPrefix, urlPrefixLen) != 0 ||
             !dispatchCommand(requestType, buff + urlPrefixLen,
                              (*bufflen) >= 0))
    {
      m_failureCmd(*this, requestType, buff, (*bufflen) >= 0);
    }

#if WEBDUINO_SERIAL_DEBUGGING > 1
    Serial.println("*** stopping connection ***");
#endif
    m_client.stop();
  }
}
Esempio n. 2
0
void WebServer::processConnection(char *buff, int *bufflen) {
	int urlPrefixLen = strlen(m_urlPrefix);

	m_client = m_server.available();

	if (m_client) {
		m_readingContent = false;
		buff[0] = 0;
		ConnectionType requestType = INVALID;
		getRequest(requestType, buff, bufflen);

		// don't even look further at invalid requests.
		// this is done to prevent Webduino from hanging
		// - when there are illegal requests,
		// - when someone contacts it through telnet rather than proper HTTP,
		// - etc.
		if (requestType != INVALID) {
			processHeaders();

			if (strcmp(buff, "/robots.txt") == 0) {
				noRobots(requestType);
			} else if (strcmp(buff, "/favicon.ico") == 0) {
				favicon(requestType);
			}
		}
		if (requestType == INVALID || strncmp(buff, m_urlPrefix, urlPrefixLen) != 0
				|| !dispatchCommand(requestType, buff + urlPrefixLen, (*bufflen) >= 0)) {
			m_failureCmd(*this, requestType, buff, (*bufflen) >= 0);
		}
		reset();
		if(this->finalCommand != NULL){
			this->finalCommand(requestType, this->currentCollection, this->currentModel);
			this->finalCommand = NULL;
		}

	}
}