Beispiel #1
0
void
httpd_handle_404 (void)
{
    if (uip_acked ()) {
	uip_close ();
	return;
    }

    PASTE_RESET ();
    PASTE_P (httpd_header_404);
    PASTE_P (httpd_header_length);
    PASTE_LEN_P (httpd_body_404);
    PASTE_P (httpd_header_end);
    PASTE_P (httpd_body_404);
    PASTE_SEND ();
}
void
httpd_handle_websocket (void)
{
    if (uip_acked ()) {
	uip_close ();
	return;
    }

    PASTE_RESET ();
    PASTE_P (httpd_header_opt);
    //PASTE_P (httpd_header_length);
    //PASTE_LEN_P (httpd_body_opt);
    PASTE_P (httpd_header_end);
    //PASTE_P (httpd_body_opt);
    PASTE_SEND ();
}
Beispiel #3
0
void
soap_paste_result (soap_context_t *ctx)
{
  PASTE_P (soap_xml_start);
  PASTE_P (soap_xml_envelope);

  if (ctx->error)
    PASTE_P (soap_xml_fault);
  else
    {
      uint8_t type = ctx->args[0].type;
      SOAP_DEBUG ("type = %d\n", type);

      PASTE_PF (soap_xml_result_start, ctx->rpc.name,
		pgm_read_word(&soap_type_table[type]));

      switch (type)
	{
	case SOAP_TYPE_INT:
	  PASTE_PF (PSTR("%d"), ctx->args[0].u.d_int);
	  break;

	case SOAP_TYPE_STRING:
	  strcat (uip_appdata, ctx->args[0].u.d_string);
	  break;

	case SOAP_TYPE_UINT32:
	  PASTE_PF (PSTR("%lu"), ctx->args[0].u.d_uint32);
	  break;

	default:
	  SOAP_DEBUG ("invalid soap-type assigned to result.\n");
	}

      PASTE_PF (soap_xml_result_end, ctx->rpc.name);
    }

  PASTE_P (soap_xml_end);
}
Beispiel #4
0
static void
httpd_handle_vfs_send_header (void)
{
    PASTE_RESET ();
    PASTE_P (httpd_header_200);

    vfs_size_t len = vfs_size (STATE->u.vfs.fd);
    if (len > 0) {
	/* send content-length header */
	PASTE_P (httpd_header_length);
	PASTE_LEN (len);
    }

    /* Check whether the file is gzip compressed. */
    unsigned char buf[READ_AHEAD_LEN];
#ifndef VFS_TEENSY
    if (VFS_HAVE_FUNC (STATE->u.vfs.fd, fseek)) {
#endif	/* not VFS_TEENSY, inlined files are always gzip'd */
	/* Rewind stream first, might be a rexmit */
	vfs_rewind (STATE->u.vfs.fd);

	vfs_read (STATE->u.vfs.fd, buf, READ_AHEAD_LEN);
	vfs_rewind (STATE->u.vfs.fd);
#ifndef VFS_TEENSY
    } else
	goto no_gzip;

    if (buf[0] == 0x1f && buf[1] == 0x8b)
#endif	/* not VFS_TEENSY, inlined files are always gzip'd */
	PASTE_P (httpd_header_gzip);

#ifdef MIME_SUPPORT
    PASTE_PF (PSTR ("Content-Type: %S\n\n"), httpd_mimetype_detect (buf));
    PASTE_SEND ();
    return;
#endif	/* MIME_SUPPORT */
#ifndef VFS_TEENSY
no_gzip:
#endif	/* not VFS_TEENSY, inlined files are always gzip'd */
    if (STATE->u.vfs.content_type == 'X')
	PASTE_P (httpd_header_ct_xhtml);
    else if (STATE->u.vfs.content_type == 'S')
	PASTE_P (httpd_header_ct_css);
    else
	PASTE_P (httpd_header_ct_html);

    PASTE_SEND ();
}
Beispiel #5
0
void
httpd_handle_solometer (void)
{
  static int8_t i = 0;
  static uint8_t cont_send = 0, parsing = 0;
  uint16_t mss,page_size;
  static uip_ipaddr_t hostaddr, dnsserver;
  //char *buf;
  static uint16_t ppos;
  uint16_t lpos,wslen;
  uint8_t p_par,pct,send_packet,buf[64];

  uip_gethostaddr(&hostaddr);
#ifdef DNS_SUPPORT
  eeprom_restore(dns_server, &dnsserver, IPADDR_LEN);
#endif

  #define NUM_PAR 16
  PARAM p[NUM_PAR] = {
	      {PR_U8,"%u",(uint8_t *)&hostaddr},
	      {PR_U8,"%u",((uint8_t *)&hostaddr)+1},
	      {PR_U8,"%u",((uint8_t *)&hostaddr)+2},
	      {PR_U8,"%u",((uint8_t *)&hostaddr)+3},
	      {PR_U8,"%u",&WRID[0]},
	      {PR_STRING,"%s",post_cookie},
	      {PR_STRING,"%s",post_hostname},
	      {PR_U8,"%u",(uint8_t *)&post_hostip},
	      {PR_U8,"%u",((uint8_t *)&post_hostip)+1},
	      {PR_U8,"%u",((uint8_t *)&post_hostip)+2},
	      {PR_U8,"%u",((uint8_t *)&post_hostip)+3},
	      {PR_STRING,"%s",post_scriptname},
	      {PR_U8,"%u",(uint8_t *)&dnsserver},
	      {PR_U8,"%u",((uint8_t *)&dnsserver)+1},
	      {PR_U8,"%u",((uint8_t *)&dnsserver)+2},
	      {PR_U8,"%u",((uint8_t *)&dnsserver)+3}
  };

  //debug_printf("Handle_solometer called.\n");
  mss = uip_mss();
  if(mss > 400)
    mss = 400;
  wslen = strlen_P(website);
  
  if (uip_newdata()) {
    /* We've received new data (maybe even the first time).  We'll
      receive something like this:
      GET /solometer[?...]
    */
    /* Make sure it's zero-terminated, so we can safely use strstr */
    char *ptr = (char *)uip_appdata;
    ptr[uip_len] = 0;

    //debug_printf("Newdata: ---------\n%s\n-----------\n",ptr);

    if(strncasecmp_P (uip_appdata, PSTR ("GET /solometer"),14) == 0) {
      //debug_printf("This is the GET request header...\n");
      ptr = strstr_P (uip_appdata, PSTR("?")) + 1;
      if(!ptr || *ptr == 0) {
	//debug_printf("This is a request only. Send page.\n");
	i = 0;
      } else {
	//debug_printf("This is a set operation. Parsing...\n");
	i = solometer_parse(ptr);
      }
      //debug_printf("Setze Parsing auf 1.\n");
      parsing = 1;
    }
    
    if (parsing == 1) {
      // Do not start answering until all packets have arrived
      //debug_printf("Parsing = 1\n");
      ptr = strstr_P (uip_appdata, PSTR("\r\n\r\n"));
      if (ptr) {
	//debug_printf("Setze Parsing auf 2.\n");
	parsing = 2;
      } else {
	//debug_printf("Double NL not found. Waiting...\n");
	return;
      }
    }
    
    if (parsing == 2) {
      //debug_printf("Parsing = 2. Sende Antwort.\n");
      PASTE_RESET ();
      if(i || mss < 200) {
	PASTE_P (httpd_header_500_smt);
	cont_send = 0;
      } else {
	page_size = wslen);
	for(i=0;i<NUM_PAR;i++)
	  if(p[i].typ == PR_STRING)
	    page_size += sprintf(buf,p[i].s2,p[i].s3);
	  else
	    page_size += sprintf(buf,p[i].s2,*(uint8_t *)p[i].s3);
	PASTE_P (p1);
	sprintf(uip_appdata+uip_len,"%u\n",page_size);
	PASTE_P (p2);
	cont_send = 1;
	ppos = 0;
      }
      //debug_printf("%d: %s\n",cont_send,uip_appdata);
      PASTE_SEND ();
      parsing = 0;
      return;
    }
  }