Skip to content

Commit

Permalink
fixes most (but not all) cases in #8
Browse files Browse the repository at this point in the history
when connecting to Webduino with a telnet client and typing any character, the Arduino would hang. this change catches all cases except when the first character typed is "G", "H", or "P" (the first letters of the allowed verbs) in which cases the Arduino will still hang
  • Loading branch information
tfnab committed Jan 5, 2012
1 parent b91adce commit 0d59803
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions WebServer.h
Expand Up @@ -440,6 +440,8 @@ void WebServer::processConnection()

void WebServer::processConnection(char *buff, int *bufflen)
{
int urlPrefixLen = strlen(m_urlPrefix);

m_client = m_server.available();

if (m_client) {
Expand All @@ -457,21 +459,29 @@ void WebServer::processConnection(char *buff, int *bufflen)
Serial.print(buff);
Serial.println("\" ***");
#endif
processHeaders();

// 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 WEBDUINO_SERIAL_DEBUGGING > 1
Serial.println("*** headers complete ***");
Serial.println("*** headers complete ***");
#endif

int urlPrefixLen = strlen(m_urlPrefix);
if (strcmp(buff, "/robots.txt") == 0)
{
noRobots(requestType);
}
else if (strcmp(buff, "/favicon.ico") == 0)
{
favicon(requestType);
if (strcmp(buff, "/robots.txt") == 0)
{
noRobots(requestType);
}
else if (strcmp(buff, "/favicon.ico") == 0)
{
favicon(requestType);
}
}
else if (requestType == INVALID ||
if (requestType == INVALID ||
strncmp(buff, m_urlPrefix, urlPrefixLen) != 0 ||
!dispatchCommand(requestType, buff + urlPrefixLen,
(*bufflen) >= 0))
Expand All @@ -482,7 +492,7 @@ void WebServer::processConnection(char *buff, int *bufflen)
#if WEBDUINO_SERIAL_DEBUGGING > 1
Serial.println("*** stopping connection ***");
#endif
m_client.stop();
reset();
}
}

Expand Down Expand Up @@ -627,8 +637,7 @@ int WebServer::read()
#if WEBDUINO_SERIAL_DEBUGGING
Serial.println("*** Connection timed out");
#endif
m_client.flush();
m_client.stop();
reset();
return -1;
}
}
Expand Down Expand Up @@ -659,6 +668,8 @@ void WebServer::push(int ch)
void WebServer::reset()
{
m_pushbackDepth = 0;
m_client.flush();
m_client.stop();
}

bool WebServer::expect(const char *str)
Expand Down Expand Up @@ -968,7 +979,9 @@ void WebServer::getRequest(WebServer::ConnectionType &type,
type = POST;

// if it doesn't start with any of those, we have an unknown method
// so just eat rest of header
// so just get out of here
else
return;

int ch;
while ((ch = read()) != -1)
Expand Down

1 comment on commit 0d59803

@unwiredben
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just been looking through changes, some great work here. I've merged them all over to my github branch. I'm happy to put up a 1.6 or 2.0 version on the googlecode page very soon with your and tfnab's updates.

Please sign in to comment.