Exemple #1
0
/*---------------------------------------------------------------------------*/
static void
next_scriptstate(struct httpd_state *s)
{
  PGM_P p;
  p = strchr_P(s->scriptptr, ISO_nl) + 1;
  s->scriptlen -= (unsigned short)(p - s->scriptptr);
  s->scriptptr = p;
}
/*---------------------------------------------------------------------------*/
static
PT_THREAD(file_stats(struct httpd_state *s, char *ptr))
{

  PSOCK_BEGIN(&s->sout);

  //while (pgm_read_byte(ptr++)!=' ') {};	//skip to "/filename" after the script invokation
  PSOCK_GENERATOR_SEND(&s->sout, generate_file_stats, (void *) (strchr_P(ptr, ' ') + 1));
  
  PSOCK_END(&s->sout);
}
Exemple #3
0
void LLAPSerial::processMessage(){
	//if (LLAP.cMessage[0] != 'a') return; //not needed as already checked
	if( checkId ) {
	  if (cMessage[1] != deviceId[0]) return;
	  if (cMessage[2] != deviceId[1]) return;
	}
	// now we have LLAP.cMessage[3] to LLAP.cMessage[11] as the actual message
	if (0 == strncmp_P(&cMessage[3],PSTR("HELLO----"),9)) {
		_Serial->print(cMessage);	// echo the message
	} else if (0 == strncmp_P(&cMessage[3],PSTR("CHDEVID"),7)) {
	  if (strchr_P(PSTR("-#@?\\*ABCDEFGHIJKLMNOPQRSTUVWXYZ"), cMessage[10]) != 0 && strchr_P(PSTR("-#@?\\*ABCDEFGHIJKLMNOPQRSTUVWXYZ"), cMessage[11]) != 0)
	  {
		deviceId[0] = cMessage[10];
		deviceId[1] = cMessage[11];
		_Serial->print(cMessage);	// echo the message
	  }
	} else {
		sMessage = String(&cMessage[3]); // let the main program deal with it
		bMsgReceived = true;
	}
}
Exemple #4
0
/* Appends an label to an dns packet at ptr.
* label is stored in PROGMEM
*/
uint8_t *
append_label(uint8_t *ptr, PGM_P label)
{
  uint8_t *nlabel;
  if (label) {
    do {
      uint8_t len;
      /* Copy until next '.' */
      nlabel = (uint8_t *)strchr_P(label, '.');

      if (nlabel == NULL) len = strlen_P(label);
      else len = nlabel - (uint8_t *)label;
      
      *ptr = len;
      memcpy_P(++ptr, label, len);
      ptr += len;
      label += len + 1;
    } while (nlabel);
  }
  *ptr++ = 0;
  return ptr;
}
Exemple #5
0
/* A helper function for unescape(). */
static int
scanhexdigits (unsigned char *dp, int nd, unsigned int *cp)
{
  static const prog_char digits[] PROGMEM = "0123456789abcdefABCDEF";
  int i;
  unsigned int d;

  *cp = 0;
  for (i = 0; i < nd; i += 1)
    {
      d = strchr_P (digits, dp[i]) - digits;
      if (d < 16)
	;
      else if (d < 22)
	d -= 6;
      else
	return 0;

      *cp <<= 4;
      *cp += d;
    }

  return 1;
}
Exemple #6
0
static void
escape_global_method (JSVirtualMachine *vm, JSBuiltinInfo *builtin_info,
		      void *instance_context, JSNode *result_return,
		      JSNode *args)
{
  unsigned char *dp;
  unsigned int n, i;
  JSNode *source;
  JSNode source_n;
  static const prog_char charset[] PROGMEM =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@*_+-./";

  if (args->u.vinteger != 1)
    {
      sprintf (vm->error, b_core_string_2);
      js_vm_error (vm);
    }
  if (args[1].type == JS_STRING)
    source = &args[1];
  else
    {
      /* Convert the argument to string. */
      js_vm_to_string (vm, &args[1], &source_n);
      source = &source_n;
    }

  /*
   * Allocate the result string, Let's guess that we need at least
   * <source->u.vstring->len> bytes of data.
   */
  n = source->u.vstring->len;
  dp = source->u.vstring->data;
  js_vm_make_string (vm, result_return, NULL, n);
  result_return->u.vstring->len = 0;

  /*
   * Scan for characters requiring escapes.
   */
  for (i = 0; i < n; i += 1)
    {
      unsigned int c = dp[i];

      if (strchr_P (charset, c))
	EMIT_TO_RESULT (c);
      else if (c > 0xFF)
	{
	  unsigned char buf[6];

	  sprintf (buf, "%04x", c);
	  EMIT_TO_RESULT ('%');
	  EMIT_TO_RESULT ('u');
	  EMIT_TO_RESULT (buf[0]);
	  EMIT_TO_RESULT (buf[1]);
	  EMIT_TO_RESULT (buf[2]);
	  EMIT_TO_RESULT (buf[3]);
      }
    else
      {
	unsigned char buf[4];
	sprintf (buf, "%02x", c);

	EMIT_TO_RESULT ('%');
	EMIT_TO_RESULT (buf[0]);
	EMIT_TO_RESULT (buf[1]);
      }
    }
}
Exemple #7
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_script(struct httpd_state *s))
{


  PGM_P ptr;
  
  PT_BEGIN(&s->scriptpt);


  while(s->file.len > 0) {

    /* Check if we should start executing a script. */
    if(pgm_read_byte_near(s->file.data) == ISO_percent &&
       pgm_read_byte_near(s->file.data + 1) == ISO_bang) {
      s->scriptptr = s->file.data + 3;
      s->scriptlen = s->file.len - 3;

      if(pgm_read_byte_near(s->scriptptr - 1) == ISO_colon) {

            strncpy_P(s->tmp_str, s->scriptptr + 1, sizeof(s->tmp_str) -1);
			if(httpd_fs_open(s->tmp_str, &s->file) ||
				httpd_fs_open(s->tmp_str + 1 , &s->file)) {
				PT_WAIT_THREAD(&s->scriptpt, 
           send_file(s));
			} else {
            // could not open the file.
			}

      } else {
            strncpy_P(s->tmp_str, s->scriptptr, sizeof(s->tmp_str) -1);
			((s->tmp_str)[sizeof(s->tmp_str) - 1]) = '\0';
					PT_WAIT_THREAD(&s->scriptpt, 
           httpd_cgi(s->tmp_str)(s, s->tmp_str));
      }
      next_scriptstate(s);
      
      /* The script is over, so we reset the pointers and continue
    	 sending the rest of the file. */
      s->file.data = s->scriptptr;
      s->file.len = s->scriptlen;
    } else {
      /* See if we find the start of script marker in the block of HTML
	        to be sent. */

      if(s->file.len > uip_mss()) {
	      s->len = uip_mss();
      } else {
	      s->len = s->file.len;
      }

      if(pgm_read_byte_near(s->file.data) == ISO_percent) {
	      ptr = strchr_P(s->file.data + 1, ISO_percent);

      } else {
	      ptr = strchr_P(s->file.data, ISO_percent);

      }

      if(ptr != NULL &&
      	 ptr != s->file.data) {
        	s->len = (int)(ptr - s->file.data);
        	if(s->len >= uip_mss()) {
        	  s->len = uip_mss();
      	}
      }

      PT_WAIT_THREAD(&s->scriptpt, send_part_of_file(s));

      s->file.data += s->len;
      s->file.len -= s->len;
      
    }
  }
  
  PT_END(&s->scriptpt);


	/*
  PGM_P ptr;
  
  PT_BEGIN(&s->scriptpt);

  while(s->file.len > 0) {
    // Check if we should start executing a script.
    if( (pgm_read_byte(s->file.data) == ISO_percent) &&
        (pgm_read_byte(s->file.data + 1) == ISO_bang)) {
      s->scriptptr = s->file.data + 3;
      s->scriptlen = s->file.len - 3;

      if(pgm_read_byte(s->scriptptr - 1) == ISO_colon) {
          strncpy_P(s->tmp_str, s->scriptptr + 1, sizeof(s->tmp_str) -1);
        if (httpd_fs_open(s->tmp_str, &s->file))
        {
	        PT_WAIT_THREAD(&s->scriptpt, send_file(s));
        }
      } else {
	    PT_WAIT_THREAD(&s->scriptpt,
		       httpd_cgi(s->scriptptr)(s, s->scriptptr));
      }

      next_scriptstate(s);
      
      // The script is over, so we reset the pointers and continue
	  // sending the rest of the file.
      s->file.data = s->scriptptr;
      s->file.len = s->scriptlen;
    } else {
      // See if we find the start of script marker in the block of HTML
	  //   to be sent. 

      if(s->file.len > uip_mss()) {
        s->len = uip_mss();
      } else {
        s->len = s->file.len;
      }

      if(pgm_read_byte(s->file.data) == ISO_percent) {
        ptr = strchr_P(s->file.data + 1, ISO_percent);
      } else {
        ptr = strchr_P(s->file.data, ISO_percent);
      }

      if(ptr != NULL &&
	     ptr != s->file.data) {
        s->len = (int)(ptr - s->file.data);

        if(s->len >= uip_mss()) {
            s->len = uip_mss();
        }
      }

      PT_WAIT_THREAD(&s->scriptpt, send_part_of_file(s));
      s->file.data += s->len;
      s->file.len -= s->len;
    }
  }
  
  PT_END(&s->scriptpt);
  */
}
Exemple #8
0
bool parseDelim(char c)
{
    if (c == 0 || strchr_P(parseDelimiters, c))
	return true;
    return false;
}