Exemplo n.º 1
0
void Webserver::Init()
{
  writing = false;
  receivingPost = false;
  postSeen = false;
  getSeen = false;
  jsonPointer = -1;
  clientLineIsBlank = true;
  needToCloseClient = false;
  clientLinePointer = 0;
  clientLine[0] = 0;
  clientRequest[0] = 0;
  SetPassword(DEFAULT_PASSWORD);
  SetName(DEFAULT_NAME);
  //gotPassword = false;
  gcodeReadIndex = gcodeWriteIndex = 0;
  InitialisePost();
  lastTime = platform->Time();
  longWait = lastTime;
  active = true;
  gcodeReply[0] = 0;
  seq = 0;
  
  // Reinitialise the message file
  
  //platform->GetMassStorage()->Delete(platform->GetWebDir(), MESSAGE_FILE);
}
Exemplo n.º 2
0
void Display::Init()
{
  writing = false;
  receivingPost = false;
  postSeen = false;
  getSeen = false;
  jsonPointer = -1;
  clientLineIsBlank = true;
  needToCloseClient = false;
  clientLinePointer = 0;

  SetPassword(DEFAULT_PASSWORD);
  SetName(DEFAULT_NAME);
  //gotPassword = false;
  gcodeReadIndex = gcodeWriteIndex = 0;
  InitialisePost();
  lastTime = platform->Time();
  longWait = lastTime;
  active = true;
  seq = 0;
  webDebug = false;

  for (int i=0; i<=maxMenuIndex; i++){
	  menus[i] = (Menu){0, MenuItem[0]};
  }
}
Exemplo n.º 3
0
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
void Webserver::BlankLineFromClient()
{
  clientLine[clientLinePointer] = 0;
  clientLinePointer = 0;
  //ParseQualifier();
  
  //Serial.println("End of header.");
  
  // Soak up any rubbish on the end.

  char c;
  while(platform->GetNetwork()->Read(c));


  if(getSeen)
  {
    SendFile(clientRequest);
    clientRequest[0] = 0;
    return;
  }
  
  if(postSeen)
  {
    receivingPost = true;
    postSeen = false;
    return;
  }
  
  if(receivingPost)
  {
    postFile = platform->GetFileStore(platform->GetGCodeDir(), postFileName, true);
    if(postFile == NULL  || !postBoundary[0])
    {
      platform->Message(HOST_MESSAGE, "Can't open file for write or no post boundary: ");
      platform->Message(HOST_MESSAGE, postFileName);
      platform->Message(HOST_MESSAGE, "\n");
      InitialisePost();
      if(postFile != NULL)
        postFile->Close();
    }
  }
}
Exemplo n.º 4
0
// This is called when the connection has been lost.
// In particular, we must cancel any pending writes.
void Webserver::ConnectionError()
{
	  writing = false;
	  receivingPost = false;
	  postSeen = false;
	  getSeen = false;
	  jsonPointer = -1;
	  clientLineIsBlank = true;
	  needToCloseClient = false;
	  clientLinePointer = 0;
	  clientLine[0] = 0;
	  clientRequest[0] = 0;
	  gotPassword = false;
	  gcodeReadIndex = gcodeWriteIndex = 0;
	  InitialisePost();
	  lastTime = platform->Time();
	  longWait = lastTime;
	  active = true;

}
Exemplo n.º 5
0
void Webserver::Spin()
{
  //char sw[2];
  if(!active)
    return;
    
  if(writing)
  {
 //   if(inPHPFile)
 //     WritePHPByte();
 //   else
	  if (WriteBytes())		// if we wrote something
	  {
		  platform->ClassReport("Webserver", longWait);
		  return;
	  }
  }
  
  if(platform->GetNetwork()->Active())
  {
	  for(uint8_t i = 0;
		   i < 16 && (platform->GetNetwork()->Status() & (clientConnected | byteAvailable)) == (clientConnected | byteAvailable);
	  	     ++i)
	  {
		  char c;
		  platform->GetNetwork()->Read(c);
		  //SerialUSB.print(c);

		  if(receivingPost && postFile != NULL)
		  {
			  if(MatchBoundary(c))
			  {
				  //Serial.println("Got to end of file.");
				  postFile->Close();
				  SendFile(clientRequest);
				  clientRequest[0] = 0;
				  InitialisePost();
			  }
			  platform->ClassReport("Webserver", longWait);
			  return;
		  }

		  if (CharFromClient(c))
			  break;	// break if we did more than just store the character
	  }
  }
   
  if (platform->GetNetwork()->Status() & clientLive)
  {
    if(needToCloseClient)
    {
      if(platform->Time() - clientCloseTime < CLIENT_CLOSE_DELAY)
      {
    	platform->ClassReport("Webserver", longWait);
        return;
      }
      needToCloseClient = false;  
      platform->GetNetwork()->Close();
    }   
  }
  platform->ClassReport("Webserver", longWait);
}
Exemplo n.º 6
0
void Webserver::ParseClientLine()
{ 
  if(StringStartsWith(clientLine, "GET"))
  {
    ParseGetPost();
    postSeen = false;
    getSeen = true;
    if(!clientRequest[0])
      strncpy(clientRequest, INDEX_PAGE, STRING_LENGTH);
    return;
  }
  
  if(StringStartsWith(clientLine, "POST"))
  {
    ParseGetPost();
    InitialisePost();
    postSeen = true;
    getSeen = false;
    if(!clientRequest[0])
      strncpy(clientRequest, INDEX_PAGE, STRING_LENGTH);
    return;
  }
  
  int bnd;
  
  if(postSeen && ( (bnd = StringContains(clientLine, "boundary=")) >= 0) )
  {
    if(strlen(&clientLine[bnd]) >= POST_LENGTH - 4)
    {
      platform->Message(HOST_MESSAGE, "Post boundary buffer overflow.\n");
      return;
    }
    postBoundary[0] = '-';
    postBoundary[1] = '-';
    strncpy(&postBoundary[2], &clientLine[bnd], POST_LENGTH - 3);
    strncat(postBoundary, "--", POST_LENGTH);
    //Serial.print("Got boundary: ");
    //Serial.println(postBoundary);
    return;
  }
  
  if(receivingPost && StringStartsWith(clientLine, "Content-Disposition:"))
  {
    bnd = StringContains(clientLine, "filename=\"");
    if(bnd < 0)
    {
      platform->Message(HOST_MESSAGE, "Post disposition gives no filename.\n");
      return;
    }
    int i = 0;
    while(clientLine[bnd] && clientLine[bnd] != '"')
    {
      postFileName[i++] = clientLine[bnd++];
      if(i >= POST_LENGTH)
      {
        i = 0;
        platform->Message(HOST_MESSAGE, "Post filename buffer overflow.\n");
      }
    }
    postFileName[i] = 0;
    //Serial.print("Got file name: ");
    //Serial.println(postFileName);    
    return;
  }  
}