Пример #1
0
/*
 =======================================================================================================================
 =======================================================================================================================
 */
static PT_THREAD(handle_input (struct httpd_state *s))
{
	PSOCK_BEGIN(&s->sin);

	PSOCK_READTO(&s->sin, ISO_space);

	if(strncmp(s->inputbuf, http_get, 4) != 0)
	{
		PSOCK_CLOSE_EXIT(&s->sin);
	}

	PSOCK_READTO(&s->sin, ISO_space);

	if(s->inputbuf[0] != ISO_slash)
	{
		PSOCK_CLOSE_EXIT(&s->sin);
	}

	if(s->inputbuf[1] == ISO_space)
	{
		strncpy(s->filename, http_index_html, sizeof(s->filename));
	}
	else
	{
		s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;

		/* Process any form input being sent to the server. */
		{
			/*
			 * extern void vApplicationProcessFormInput( char *pcInputString, long
			 * xInputLength ); £
			 * vApplicationProcessFormInput( s->inputbuf, PSOCK_DATALEN(&s->sin) );
			 */
		}

		strncpy(s->filename, &s->inputbuf[0], sizeof(s->filename));
	}

	/* httpd_log_file(uip_conn->ripaddr, s->filename); */
	s->state = STATE_OUTPUT;

	while(1)
	{
		PSOCK_READTO(&s->sin, ISO_nl);

		if(strncmp(s->inputbuf, http_referer, 8) == 0)
		{
			s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;

			/* httpd_log(&s->inputbuf[9]); */
		}
	}

	PSOCK_END(&s->sin);
}
/*---------------------------------------------------------------------------*/
static PT_THREAD( handle_input ( struct httpd_state *s ) )
{
	PSOCK_BEGIN( &s->sin );
	( void ) PT_YIELD_FLAG;
	PSOCK_READTO( &s->sin, ISO_space );

	if( strncmp(s->inputbuf, http_get, 4) != 0 )
	{
		PSOCK_CLOSE_EXIT( &s->sin );
	}

	PSOCK_READTO( &s->sin, ISO_space );

	if( s->inputbuf[0] != ISO_slash )
	{
		PSOCK_CLOSE_EXIT( &s->sin );
	}

	if( s->inputbuf[1] == ISO_space )
	{
		strncpy( s->filename, http_index_html, sizeof(s->filename) );
	}
	else
	{
		s->inputbuf[PSOCK_DATALEN( &s->sin ) - 1] = 0;
		
		/* Process any form input being sent to the server. */
		#if UIP_CONF_PROCESS_HTTPD_FORMS == 1
		{
			extern void vApplicationProcessFormInput( char *pcInputString );
			vApplicationProcessFormInput( s->inputbuf );
		}
		#endif
		
		strncpy( s->filename, &s->inputbuf[0], sizeof(s->filename) );
	}

	/*  httpd_log_file(uip_conn->ripaddr, s->filename);*/
	s->state = STATE_OUTPUT;

	while( 1 )
	{
		PSOCK_READTO( &s->sin, ISO_nl );

		if( strncmp(s->inputbuf, http_referer, 8) == 0 )
		{
			s->inputbuf[PSOCK_DATALEN( &s->sin ) - 2] = 0;

			/*      httpd_log(&s->inputbuf[9]);*/
		}
	}

	PSOCK_END( &s->sin );
}
Пример #3
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_input(struct httpd_state *s))
{
  char *LEDptr;

  PSOCK_BEGIN(&s->sin);

  PSOCK_READTO(&s->sin, ISO_space);

  
  if(strncmp(s->inputbuf, http_get, 4) == 0) {

  PSOCK_READTO(&s->sin, ISO_space);

  if(s->inputbuf[0] != ISO_slash) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }

  if(s->inputbuf[1] == ISO_space) {
    strncpy(s->filename, http_index_html, sizeof(s->filename));
  } else {
    s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
    strncpy(s->filename, &s->inputbuf[0], sizeof(s->filename));
  }

  // Renesas ++
  LEDptr = strstr(s->inputbuf, "LEDA");

  if (LEDptr !=NULL)
  {
      strncpy(LEDbuf, (const char *)(LEDptr), sizeof(LEDbuf));
      LEDflag = 1;
  }
  // End of Renesas ++

  /*  httpd_log_file(uip_conn->ripaddr, s->filename);*/

  s->state = STATE_OUTPUT;

  while(1) {
	PSOCK_READTO(&s->sin, ISO_nl);

    if(strncmp(s->inputbuf, http_referer, 8) == 0) {
	  s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
	  /*      httpd_log(&s->inputbuf[9]);*/
	}
    }
  }else {
  PSOCK_CLOSE_EXIT(&s->sin);
  }
  
  PSOCK_END(&s->sin);
}
Пример #4
0
static int handle_connection(struct webserver_state *s) {
  PSOCK_BEGIN(&s->p);
  
  /* the incoming GET request will have the following format:
   * GET / HTTP/1.1 ....
   * we have to parse this string to determine the resource being requested
   * if the requested resource is not the root webpage ('/') then,
   * GET /<resource name> HTTP/1.1 ....
   * we should parse the specific resource and react appropriately
   */
  
  // read incoming data until we read a space character
  PSOCK_READTO(&s->p, ISO_space);
  
  // parse the data to determine if it was a GET request
  if(strncmp(s->inputbuf, http_get, 4) != 0) {
    PSOCK_CLOSE_EXIT(&s->p);
  }
  
  // continue reading until the next space character
  PSOCK_READTO(&s->p, ISO_space);
  
  // determine the requested resource
  // in this case, we check if the request was for the '/' root page
  // AKA index.html
  if(s->inputbuf[0] != ISO_slash) {
    // request for unknown webpage, close and exit
    PSOCK_CLOSE_EXIT(&s->p);
  }
  
  // This is the web page served by the webserver
  PSOCK_SEND_STR(&s->p, "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\r\n");
  PSOCK_SEND_STR(&s->p, "<HTML>\r\n<HEAD>\r\n\t<META http-equiv=\"Content-type\" content=\"text/html;charset=UTF-8\">\r\n\t<TITLE>Arduino WiShield 2.0</TITLE>\r\n");
  PSOCK_SEND_STR(&s->p, "\t<STYLE type=\"text/css\">\r\n\t\tP,H1 {text-align: center;}\r\n\t</STYLE>\r\n</HEAD>\r\n<BODY>\r\n");
  PSOCK_SEND_STR(&s->p, "\t<H1>Hello World!! I am an Arduino with a WiShield 2.0</H1>\r\n\t<P><A href=\"T\">Toggle LED</A></P>\r\n");
  
  if(s->inputbuf[1] != ISO_space) {
    // request for a resource
    if(s->inputbuf[1] != ISO_T) {
      // not supported
      PSOCK_SEND_STR(&s->p, "\t<P>Request not supported</P>\r\n");
    } else {
      PSOCK_SEND_STR(&s->p, "\t<P>TOGGLE LED command received</P>\r\n");
      // Toggle WiShield 2.0 Led status
      digitalWrite(9, !digitalRead(9));
    }
  }
  
  PSOCK_SEND_STR(&s->p, "</BODY>\r\n</HTML>");
  PSOCK_CLOSE(&s->p);
  PSOCK_END(&s->p);
}
Пример #5
0
/*---------------------------------------------------------------------------*/
static int
handle_connection(struct psock *p)
{
    PSOCK_BEGIN(p);
    struct conn_state *s;
    s->state = send1;

    PSOCK_SEND_STR(p, "Connection Request");

    while(1) {
        if(s->state == send1)
        {
            memset(buffer,0,sizeof(buffer));
            PSOCK_READTO(p, '\n');
            printf("Got: %s", buffer);
            printf("Server is Authenticated \n");
            s->state = send2;

        }
        if(s->state == send2)
        {
            PSOCK_SEND_STR(p,"certificate\n");
            s->state = send3;
        }
        if(s->state == send3)
        {
            memset(buffer,0,sizeof(buffer));
            PSOCK_READTO(p, '\n');
            printf("Got: %s", buffer);
            printf("I received servers shared key \n");
            s->state = send4;
        }
        if(s->state == send4)
        {
            printf("I accepted servers shared key \n");
            s->state = send5;
            PSOCK_SEND_STR(p,"shared key accepted\n");
        }
        if(s->state == send5)
        {
            memset(buffer,0,sizeof(buffer));
            PSOCK_READTO(p, '\n');
            printf("Got : %s", buffer);
            printf("Secure Connection Established\n");
            PSOCK_SEND_STR(p,"Connected\n");
            printf("Connected Sent\n");
        }

    }

    PSOCK_END(p);
}
Пример #6
0
static
PT_THREAD(handle_input(struct httpd_state *s))
{
  PSOCK_BEGIN(&s->sin);

  PSOCK_READTO(&s->sin, ISO_space);

  if(strncmp(s->inputbuf, http_get, 4) == 0) {
    s->request_type = REQUEST_TYPE_GET;
  } else if(strncmp(s->inputbuf, http_put, 4) == 0) {
    s->request_type = REQUEST_TYPE_PUT;
  } else if(strncmp(s->inputbuf, http_post, 5) == 0) {
    s->request_type = REQUEST_TYPE_POST;
  } else if(strncmp(s->inputbuf, http_delete, 7) == 0) {
    s->request_type = REQUEST_TYPE_DELETE;
  } else {
    PSOCK_CLOSE_EXIT(&s->sin);
  }
  PSOCK_READTO(&s->sin, ISO_space);

  if(s->inputbuf[0] != ISO_slash) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }
  s->query = NULL;
#if URLCONV
  s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
  urlconv_tofilename(s->filename, &s->query, s->inputbuf, sizeof(s->filename));
  if(s->filename[1] == 0) {
    strncpy(s->filename, http_index_html, sizeof(s->filename));
  }
#else /* URLCONV */
  if(s->inputbuf[1] == ISO_space) {
    strncpy(s->filename, http_index_html, sizeof(s->filename));
  } else {
    s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
    strncpy(s->filename, s->inputbuf, sizeof(s->filename));
  }
#endif /* URLCONV */
  if(s->query) {
    LOG6LBR_6ADDR(DEBUG, &uip_conn->ripaddr, "Request for '%s?%s' from ", s->filename, s->query);
  } else {
    LOG6LBR_6ADDR(DEBUG, &uip_conn->ripaddr, "Request for '%s' from ", s->filename);
  }

  s->state = STATE_OUTPUT;

  while(1) {
    PSOCK_READTO(&s->sin, ISO_nl);
  }

  PSOCK_END(&s->sin);
}
Пример #7
0
static
PT_THREAD(handle_input(struct httpd_state *s))
{

  PSOCK_BEGIN(&s->sin); 

  PSOCK_READTO(&s->sin, ISO_space);

  if(httpd_strncmp(s->inputbuf, httpd_get, 4) != 0) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }
  PSOCK_READTO(&s->sin, ISO_space);

  if(s->inputbuf[0] != ISO_slash) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }

  if(s->inputbuf[1] == ISO_space) {
    httpd_strcpy(s->filename, httpd_indexfn);
  } else {
    s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
    strncpy(s->filename, &s->inputbuf[0], sizeof(s->filename));
{
    /* Look for ?, if found strip file name and send any following text to the LCD */
    uint8_t i;
    for (i=0;i<sizeof(s->inputbuf);i++) {
      if (s->inputbuf[i]=='?') {
        raven_lcd_show_text(&s->inputbuf[i]);
        if (i<sizeof(s->filename)) s->filename[i]=0;
 //     s->inputbuf[i]=0; //allow multiple beeps with multiple ?'s
      }
      if (s->inputbuf[i]==0) break;
    }
}
  }

  webserver_log_file(&uip_conn->ripaddr, s->filename);

  s->state = STATE_OUTPUT;

  while(1) {
    PSOCK_READTO(&s->sin, ISO_nl);

    if(httpd_strncmp(s->inputbuf, httpd_ref, 8) == 0) {
      s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
      petsciiconv_topetscii(s->inputbuf, PSOCK_DATALEN(&s->sin) - 2);
      webserver_log(s->inputbuf);
    }
  }
  PSOCK_END(&s->sin);
}
Пример #8
0
/*---------------------------------------------------------------------------*/
static PT_THREAD (handle_input (struct httpd_state *s))
{
  PSOCK_BEGIN (&s->sin);

  PSOCK_READTO (&s->sin, ISO_space);

  if (strncmp (s->inputbuf, http_get, 4) != 0)
    PSOCK_CLOSE_EXIT (&s->sin);
  
  PSOCK_READTO (&s->sin, ISO_space);

  if (s->inputbuf [0] != ISO_slash)
    PSOCK_CLOSE_EXIT (&s->sin);

  if (s->inputbuf [1] == ISO_space)
    strncpy (s->filename, http_index_html, sizeof (s->filename));
  else 
  {
    char *c;

    s->inputbuf [PSOCK_DATALEN (&s->sin) - 1] = 0;

    if ((c = strstr (s->inputbuf, "?")))
      *c++ = '\0';

    strncpy (s->filename, &s->inputbuf [0], sizeof (s->filename));

    if (!strcmp (s->filename, "/led.shtml"))
    {
      if (c && strstr (c, "LED2=1"))
        GPIO0_FIOCLR = GPIO_IO_P11;
      else
        GPIO0_FIOSET = GPIO_IO_P11;
    }
  }

  s->state = STATE_OUTPUT;

  while (1) 
  {
    PSOCK_READTO (&s->sin, ISO_nl);

    if (strncmp (s->inputbuf, http_referer, 8) == 0)
      s->inputbuf [PSOCK_DATALEN (&s->sin) - 2] = 0;
  }

  PSOCK_END (&s->sin);
}
Пример #9
0
static int hello_world_appcall(void)
{
    struct tcp_hello_appstate *s = &(uip_conn->appstate.tcp_hello);

    if(uip_connected()) {
      PSOCK_INIT(&s->p, s->inputbuffer, sizeof(s->inputbuffer));
    }

    PSOCK_BEGIN(&s->p);
    PSOCK_SEND_STR(&s->p, "Hello. What is your name?\n");
    PSOCK_READTO(&s->p, '\n');
    strncpy(s->name, s->inputbuffer, sizeof(s->name));
    s->name[strlen(s->name)-2] = 0;
    PSOCK_SEND_STR(&s->p, "Hello ");
    PSOCK_SEND_STR(&s->p, s->name);
    PSOCK_SEND_STR(&s->p, " !\n");
    sprintf(s->name, "r %d/%d", nrf_link_get_rx_packets(), nrf_link_get_rx_dropped());
    PSOCK_SEND_STR(&s->p, s->name);
    PSOCK_SEND_STR(&s->p, " ");
    sprintf(s->name, "t %d/%d", nrf_link_get_tx_packets(), nrf_link_get_tx_dropped());
    PSOCK_SEND_STR(&s->p, s->name);
    PSOCK_SEND_STR(&s->p, "\n\r");
    PSOCK_CLOSE(&s->p);
    PSOCK_END(&s->p);
}
Пример #10
0
static
PT_THREAD(handle_connection(struct psock *p))
{
  static int seq_id = 1;
  
  PSOCK_BEGIN(p);
  
  while(1){
  
    PSOCK_READTO(p, '\r');
    
    buf[PSOCK_DATALEN(p)-1] = '\0';
    PRINTF("Server received: %s", buf);
    PRINTF("\r\nFrom ");
    PRINT6ADDR(&UIP_IP_BUF->srcipaddr);
    PRINTF("\r\n");    
    
    PRINTF("Responding with message: ");
    sprintf((char*)buf, "Hello from the server! (%d)\r", seq_id++);
    PRINTF("%s\r\n", buf);
    PSOCK_SEND_STR(p, (char*)buf);
  
  }  
  
  PSOCK_END(p);
    
}
Пример #11
0
static int handle_connection(struct webserver_state *s)
{
	PSOCK_BEGIN(&s->p);

	// the incoming GET request will have the following format:
	// GET / HTTP/1.1 ....
	// we have to parse this string to determine the resource being requested
	// if the requested resource is not the root webpage ('/') then,
	// GET /<resource name> HTTP/1.1 ....
	// we should parse the specific resource and react appropriately

	// read incoming data until we read a space character
	PSOCK_READTO(&s->p, ISO_space);

	// parse the data to determine if it was a GET request
	if(strncmp(s->inputbuf, http_get, 4) != 0) {
		PSOCK_CLOSE_EXIT(&s->p);
	}

	// continue reading until the next space character
	PSOCK_READTO(&s->p, ISO_space);

	// determine the requested resource
	// in this case, we check if the request was for the '/' root page
	// AKA index.html
	if(s->inputbuf[0] != ISO_slash) {
		// request for unknown webpage, close and exit
		PSOCK_CLOSE_EXIT(&s->p);
	}

	if(s->inputbuf[1] != ISO_space) {
		// request for unavailable resource
		// not supported, modify to add support for additional resources
		PSOCK_CLOSE_EXIT(&s->p);
	}

	lockstate = lockstate+1;

        PSOCK_SEND_STR(&s->p, "HTTP/1.1 200 OK\r\n");
	PSOCK_SEND_STR(&s->p, "Content-Type: text/html\r\n");
	PSOCK_SEND_STR(&s->p, "\r\n");
	PSOCK_SEND_STR(&s->p, "Hello World, I am WiShield");
	PSOCK_SEND_STR(&s->p, "<center><h1>Hello World!! I am Matt's WiShield.  Find me in webserver.c under PSOCK_SEND_STR.</h1></center>");
        PSOCK_GENERATOR_SEND(&s->p, fill_buf, 0);
	PSOCK_CLOSE(&s->p);
	PSOCK_END(&s->p);
}
Пример #12
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_input(struct httpd_state *s))
{
  PSOCK_BEGIN(&s->sin);

  PSOCK_READTO(&s->sin, ISO_space);
  
  if(strncmp(s->inputbuf, http_get, 4) != 0) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }
  PSOCK_READTO(&s->sin, ISO_space);

  if(s->inputbuf[0] != ISO_slash) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }

#if URLCONV
  s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
  urlconv_tofilename(s->filename, s->inputbuf, sizeof(s->filename));
#else /* URLCONV */
  if(s->inputbuf[1] == ISO_space) {
    strncpy(s->filename, http_index_htm, sizeof(s->filename));
  } else {
    s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
    strncpy(s->filename, s->inputbuf, sizeof(s->filename));
  }
#endif /* URLCONV */

  petsciiconv_topetscii(s->filename, sizeof(s->filename));
  webserver_log_file(&uip_conn->ripaddr, s->filename);
  petsciiconv_toascii(s->filename, sizeof(s->filename));
  s->state = STATE_OUTPUT;

  while(1) {
    PSOCK_READTO(&s->sin, ISO_nl);

    if(strncmp(s->inputbuf, http_referer, 8) == 0) {
      s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
      petsciiconv_topetscii(s->inputbuf, PSOCK_DATALEN(&s->sin) - 2);
      webserver_log(s->inputbuf);
    }
  }
  
  PSOCK_END(&s->sin);
}
Пример #13
0
static int handle_connection(struct socket_app_state *s)
{
  PSOCK_BEGIN(&s->p);
  PSOCK_READTO(&s->p, '\n');
  memcpy(buffer,s->inputbuffer,PSOCK_DATALEN(&s->p));
  memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
  PSOCK_SEND_STR(&s->p, outBuffer);
  PSOCK_END(&s->p);
}
Пример #14
0
int handle_connection(webserver_state* s) {
  PSOCK_BEGIN(&s->p);

  // Read HTTP verb (e.g. GET/POST) - and ignore it.
  PSOCK_READTO(&s->p, ' ');
  // Read requested path (up to next space)
  PSOCK_READTO(&s->p, ' ');

  RESPOND_STR(s, "HTTP/1.1 200 OK\r\n");
  RESPOND_STR(s, "Content-Type: text/plain\r\n");
  RESPOND_STR(s, "\r\n");

  if (STR_EQ(s->inputbuf, "/ ")) {
    // no-op, just for testing
    RESPOND_STR(s, "test");
  } else if (STR_EQ(s->inputbuf, "/comcast ")) {
    room.watchComcast();
    RESPOND_STR(s, "comcast");
  } else if (STR_EQ(s->inputbuf, "/dvd ")) {
    room.watchDvd();
    RESPOND_STR(s, "dvd");
  } else if (STR_EQ(s->inputbuf, "/roku ")) {
    room.streamRoku();
    RESPOND_STR(s, "roku");
  } else if (STR_EQ(s->inputbuf, "/ps3 ")) {
    room.playPlaystation();
    RESPOND_STR(s, "ps3");
  } else if (STR_EQ(s->inputbuf, "/cd ")) {
    room.listenCd();
    RESPOND_STR(s, "cd");
  } else if (STR_EQ(s->inputbuf, "/off ")) {
    room.allOff();
    RESPOND_STR(s, "off");
  } else if (STR_EQ(s->inputbuf, "/reset ")) {
    room.forceReset();
    RESPOND_STR(s, "reset");
  } else {
    RESPOND_STR(s, "unknown");
  }

  RESPOND_STR(s, "\r\n");
  PSOCK_CLOSE(&s->p);
  PSOCK_END(&s->p);
}
Пример #15
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_input(struct httpd_state *s))
{
  PSOCK_BEGIN(&s->sin);

  PSOCK_READTO(&s->sin, ISO_space);

  // GET Request
  if(!strncmp(s->inputbuf, http_get, 4)) {
  //PSOCK_CLOSE_EXIT(&s->sin);
		s->method = GET;
  } else {
		s->method = POST;
  }
  PSOCK_READTO(&s->sin, ISO_space);

  if(s->inputbuf[0] != ISO_slash) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }

#if URLCONV
  s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
  urlconv_tofilename(s->filename, s->inputbuf, sizeof(s->filename));
#else /* URLCONV */
    s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
    strncpy(s->filename, s->inputbuf, sizeof(s->filename));
#endif /* URLCONV */

  //webserver_log_file(&uip_conn->ripaddr, s->filename);

  s->state = STATE_OUTPUT;

  while(1) {
    PSOCK_READTO(&s->sin, ISO_nl);
#if 0
    if(strncmp(s->inputbuf, http_referer, 8) == 0) {
      s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
      webserver_log(s->inputbuf);
    }
#endif
  }

  PSOCK_END(&s->sin);
}
Пример #16
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_input(struct httpd_state *s))
{
  PSOCK_BEGIN(&s->sin);

  PSOCK_READTO(&s->sin, ISO_space);
	//printf("http 1: %s\r\n", s->inputbuf);
  if(strncmp(s->inputbuf, http_get, 4) != 0) {
	
    PSOCK_CLOSE_EXIT(&s->sin);
  }
  PSOCK_READTO(&s->sin, ISO_space);
  //printf("http 2: %s\r\n", s->inputbuf);

  if(s->inputbuf[0] != ISO_slash) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }

  if(s->inputbuf[1] == ISO_space) {
    strncpy(s->filename, http_index_html, sizeof(s->filename));
  } else {
    s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
    strncpy(s->filename, &s->inputbuf[0], sizeof(s->filename));
  }

  //*  
   //httpd_log_file(uip_conn->ripaddr, s->filename);
  //*/
  
  s->state = STATE_OUTPUT;

  while(1) {
    PSOCK_READTO(&s->sin, ISO_nl);

    if(strncmp(s->inputbuf, http_referer, 8) == 0) {
      s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
      /*      httpd_log(&s->inputbuf[9]);*/
    }
  }
  
  PSOCK_END(&s->sin);
  //nEth = 0;
}
Пример #17
0
static uint16_t handle_connection(struct simple_httpd_state *s)
{
	PSOCK_BEGIN(&s->p);

	int comp;

	// the incoming GET request will have the following format:
	// GET / HTTP/1.1 ....
	// we have to parse this string to determine the resource being requested
	// if the requested resource is not the root webpage ('/') then,
	// GET /<resource name> HTTP/1.1 ....
	// we should parse the specific resource and react appropriately

	// read incoming data until we read a space character
	PSOCK_READTO(&s->p, ISO_space);

	// parse the data to determine if it was a GET request
	if((comp = strncmp_P((const char *)(s->inputbuf), (const char *)http_get, 4)) != 0)
	{
		PSOCK_CLOSE_EXIT(&s->p);
	}

	// continue reading until the next space character
	PSOCK_READTO(&s->p, ISO_space);

	// determine the requested resource
	// in this case, we check if the request was for the '/' root page
	// AKA index.html
	if(s->inputbuf[0] != ISO_slash){
		PSOCK_CLOSE_EXIT(&s->p);				// request for unknown webpage, close and exit
	}

	// not supported, modify to add support for additional resources
	if(s->inputbuf[1] != ISO_space){
		PSOCK_CLOSE_EXIT(&s->p);				// request for unavailable resource, close and exit
	}

	PSOCK_GENERATOR_SEND(&s->p, fill_buf, 0); 	// generate the web page response with fill_buf from PSTR variable

	PSOCK_CLOSE(&s->p);
	PSOCK_END(&s->p);
}
Пример #18
0
/*
 * A protosocket always requires a protothread. The protothread
 * contains the code that uses the protosocket. We define the
 * protothread here.
 */
static
PT_THREAD(handle_connection(struct psock *p))
{
  /*
   * A protosocket's protothread must start with a PSOCK_BEGIN(), with
   * the protosocket as argument.
   *
   * Remember that the same rules as for protothreads apply: do NOT
   * use local variables unless you are very sure what you are doing!
   * Local (stack) variables are not preserved when the protothread
   * blocks.
   */
  PSOCK_BEGIN(p);

  /*
   * We start by sending out a welcoming message. The message is sent
   * using the PSOCK_SEND_STR() function that sends a null-terminated
   * string.
   */
  PSOCK_SEND_STR(p, "Welcome, please type something and press return.\n");
  
  /*
   * Next, we use the PSOCK_READTO() function to read incoming data
   * from the TCP connection until we get a newline character. The
   * number of bytes that we actually keep is dependant of the length
   * of the input buffer that we use. Since we only have a 10 byte
   * buffer here (the buffer[] array), we can only remember the first
   * 10 bytes received. The rest of the line up to the newline simply
   * is discarded.
   */
  PSOCK_READTO(p, '\n');
  
  /*
   * And we send back the contents of the buffer. The PSOCK_DATALEN()
   * function provides us with the length of the data that we've
   * received. Note that this length will not be longer than the input
   * buffer we're using.
   */
  PSOCK_SEND_STR(p, "Got the following data: ");
  PSOCK_SEND(p, buffer, PSOCK_DATALEN(p));
  PSOCK_SEND_STR(p, "Good bye!\r\n");

  /*
   * We close the protosocket.
   */
  PSOCK_CLOSE(p);

  /*
   * And end the protosocket's protothread.
   */
  PSOCK_END(p);
}
Пример #19
0
static int handle_connection(struct socket_app_state *s)
{
  PSOCK_BEGIN(&s->p);
  
  while(1){
     PSOCK_READTO(&s->p, '\n');
     strin = s->inputbuffer;
     memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
     PSOCK_SEND_STR(&s->p, strout);
  }
  PSOCK_CLOSE(&s->p);
  PSOCK_END(&s->p);
}
Пример #20
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_input(struct httpd_state *s))
{
  PSOCK_BEGIN(&s->sin);

  PSOCK_READTO(&s->sin, ' ');
  
  if(strncmp(s->inputbuf, "GET ", 4) != 0) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }
  PSOCK_READTO(&s->sin, ' ');

  if(s->inputbuf[0] != '/') {
    PSOCK_CLOSE_EXIT(&s->sin);
  }

  if(s->inputbuf[1] == ' ') {
    strncpy(s->filename, "index.html", sizeof(s->filename));
  } else {
    s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
    strncpy(s->filename, &s->inputbuf[1], sizeof(s->filename));
  }

  //  webserver_log_file(&uip_conn->ripaddr, s->filename);
  libputs_arch(s->filename);
  s->state = STATE_OUTPUT;

  while(1) {
    PSOCK_READTO(&s->sin, '\n');

    if(strncmp(s->inputbuf, "Referer:", 8) == 0) {
      s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
      libputs_arch(&s->inputbuf[9]);
      //      webserver_log(&s->inputbuf[9]);
    }
  }
  
  PSOCK_END(&s->sin);
}
Пример #21
0
static
PT_THREAD(handle_input(struct httpd_state *s))
{

  PSOCK_BEGIN(&s->sin); 

  PSOCK_READTO(&s->sin, ISO_space);

  if(httpd_strncmp(s->inputbuf, httpd_get, 4) != 0) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }
  PSOCK_READTO(&s->sin, ISO_space);

  if(s->inputbuf[0] != ISO_slash) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }

  if(s->inputbuf[1] == ISO_space) {
    httpd_strcpy(s->filename, httpd_indexfn);
  } else {
    s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
    strncpy(s->filename, &s->inputbuf[0], sizeof(s->filename));
  }

  webserver_log_file(&uip_conn->ripaddr, s->filename);

  s->state = STATE_OUTPUT;

  while(1) {
    PSOCK_READTO(&s->sin, ISO_nl);

    if(httpd_strncmp(s->inputbuf, httpd_ref, 8) == 0) {
      s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
      petsciiconv_topetscii(s->inputbuf, PSOCK_DATALEN(&s->sin) - 2);
      webserver_log(s->inputbuf);
    }
  }
  PSOCK_END(&s->sin);
}
Пример #22
0
/*
 * This is the protosocket function that handles the communication. A
 * protosocket function must always return an int, but must never
 * explicitly return - all return statements are hidden in the PSOCK
 * macros.
 */
static int handle_connection(struct socket_app_state *s)
{
  PSOCK_BEGIN(&s->p);

  PSOCK_SEND_STR(&s->p, "Hello. What is you name?\n");
  PSOCK_READTO(&s->p, '\n');
  PSOCK_SEND_STR(&s->p, "Hello ");
  PSOCK_SEND_STR(&s->p, s->inputbuffer);
  memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
  PSOCK_CLOSE(&s->p);

  PSOCK_END(&s->p);
}
Пример #23
0
static
PT_THREAD(handle_connection(struct psock *p))
{
  PSOCK_BEGIN(p);
  //PSOCK_SEND_STR(p, "Type something!\n");
  leds_on(LEDS_RED);
  PSOCK_READTO(p, '\n');
  printf("RX=%s", buf);
  //PSOCK_SEND_STR(p, "Got: ");
  //PSOCK_SEND(p, buf, PSOCK_DATALEN(p));
  //PSOCK_SEND_STR(p, "EOL\r\n");
  //PSOCK_CLOSE(p);
  PSOCK_END(p);
}
Пример #24
0
 /*
  * This is the protosocket function that handles the communication. A
  * protosocket function must always return an int, but must never
  * explicitly return - all return statements are hidden in the PSOCK
  * macros.
  */
 static int
 handle_connection(struct hello_world_state *s)
 {
   PSOCK_BEGIN(&p);
 
   PSOCK_SEND_STR(&p, "Hello. What is your name?\n");
   PSOCK_READTO(&p, '\n');
   strncpy(s->name, s->inputbuffer, sizeof(s->name));
   PSOCK_SEND_STR(&p, "Hello ");
   PSOCK_SEND_STR(&p, s->name);
   PSOCK_CLOSE(&p);
   
   PSOCK_END(&p);
 }
Пример #25
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_input(struct httpd_state *s))
{
  PSOCK_BEGIN(&s->sin);

  PSOCK_READTO(&s->sin, ISO_space);
  
  if(strncmp(s->inputbuf, http_get, 4) != 0) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }
  PSOCK_READTO(&s->sin, ISO_space);

  if(s->inputbuf[0] != ISO_slash) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }

  if(s->inputbuf[1] == ISO_space) {
    strncpy(s->filename, http_index_html, sizeof(s->filename));
  } else {
    s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
    strncpy(s->filename, &s->inputbuf[0], sizeof(s->filename));
  }

  libputs_arch(s->filename);
  
  s->state = STATE_OUTPUT;

  while(1) {
    PSOCK_READTO(&s->sin, ISO_nl);

    if(strncmp(s->inputbuf, http_referer, 8) == 0) {
      s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
    }
  }
  
  PSOCK_END(&s->sin);
}
Пример #26
0
static
PT_THREAD(handle_emu_in(struct httpd_state *s, RoverAction last)) {
	static int c = 0;
	PSOCK_BEGIN(&s->sin);
	
	f(8, "Input______________ ", &c);
	PSOCK_READTO(&s->sin, 0xFF);
	f(8, "Input ", &c);
	//int len = PSOCK_DATALEN(&s->sin)-1;
	// Report the data we got
	gotData(last, s->inputbuf);
	s->state = STATE_WAITING;
	
	PSOCK_END(&s->sin);
}
Пример #27
0
/*
 * This is the protosocket function that handles the communication. A
 * protosocket function must always return an int, but must never
 * explicitly return - all return statements are hidden in the PSOCK
 * macros.
 */
static int handle_connection(struct socket_app_state *s){
  PSOCK_BEGIN(&s->p);
  while(1){
	PSOCK_READTO(&s->p, '\n');
	if(*s->inputbuffer=='q'){
		PSOCK_SEND_STR(&s->p, "\n");
		break;
	}
	handleCommand(s->inputbuffer, s->outputbuffer);
	memset(s->inputbuffer, 0x00, SOCKET_BUFFER_LENGTH);
	PSOCK_SEND_STR(&s->p, s->outputbuffer);
  }
  PSOCK_CLOSE(&s->p);
  PSOCK_END(&s->p);
}
Пример #28
0
/*---------------------------------------------------------------------------*/
static int
handle_connection(struct psock *p)
{
  PSOCK_BEGIN(p);

  PSOCK_SEND_STR(p, "GET / HTTP/1.0\r\n");
  PSOCK_SEND_STR(p, "Server: Contiki example protosocket client\r\n");
  PSOCK_SEND_STR(p, "\r\n");

  while(1) {
    PSOCK_READTO(p, '\n');
    printf("Got: %s", buffer);
  }
  
  PSOCK_END(p);
}
Пример #29
0
/* -------------------------------------------------------------------------- */
static PT_THREAD(handle_connection(struct psock *p))
{
    // So, as always let's start
    PSOCK_BEGIN(p);

    // Let's send a hello world
    PSOCK_SEND_STR(p, "Welcome, please type something and press return.\n");

    // Let's block this thread untile a new line is received
    PSOCK_READTO(p, '\n');

    // And what we receive, we send it back, MUAHAHA
    PSOCK_SEND_STR(p, "Got the following data: ");
    PSOCK_SEND(p, buffer, PSOCK_DATALEN(p));
    PSOCK_SEND_STR(p, "Good bye!\r\n");

    // Finally close the socket
    PSOCK_CLOSE(p);

    // The End...
    PSOCK_END(p);
}
Пример #30
0
/*
 * This is the protosocket function that handles the communication. A
 * protosocket function must always return an int, but must never
 * explicitly return - all return statements are hidden in the PSOCK
 * macros.
 */
static int handle_connection(struct socket_app_state *s)
{
  PSOCK_BEGIN(&s->p);

  PSOCK_SEND_STR(&s->p, "Hello. Mowayduino ready\n");
  PSOCK_READTO(&s->p, '\n');
  if (s->inputbuffer[0] == 'r')
  {
    red = 1;
    green = 0;
    blue = 0;
    PSOCK_SEND_STR(&s->p, s->inputbuffer);
    memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
  }
  else if (s->inputbuffer[0] == 'g')
  {
    red = 0;
    green = 1;
    blue = 0;
    PSOCK_SEND_STR(&s->p, s->inputbuffer);
    memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
  }
  else if (s->inputbuffer[0] == 'b')
  {
    red = 0;
    green = 0;
    blue = 1;
    PSOCK_SEND_STR(&s->p, s->inputbuffer);
    memset(s->inputbuffer, 0x00, sizeof(s->inputbuffer));
  }

  if (s->inputbuffer[0] == 'q')
  {
    PSOCK_CLOSE(&s->p);
    PSOCK_END(&s->p);
  }  
}