Esempio n. 1
0
static PT_THREAD(run_hello(struct httpd_state *s, char *ptr))
{
	//NOTE:local variables are not preserved during the calls to proto socket functins
	static char hello_name[20] = "";
	PSOCK_BEGIN(&s->sout);
	//check if there are parameters passed
	if (s->param[0] && (find_key_val(s->param, hello_name, 20, "name") > 0)) {
		PSOCK_SEND_PSTR(&s->sout, PSTR("<H1>Hello "));
		PSOCK_SEND_STR(&s->sout, hello_name);
		PSOCK_SEND_PSTR(&s->sout, PSTR("</H1><br>"));
	}

	PSOCK_SEND_PSTR(&s->sout, PSTR("\
<form action=\"/hello.shtml\" method=\"get\" bgcolor=\"#808080\">\
Enter your name: <input type=\"text\" name=\"name\" size=\"10\" value=\""));

	PSOCK_SEND_STR(&s->sout, hello_name);

	PSOCK_SEND_PSTR(&s->sout, PSTR("\
\"/><br><input type = \"submit\" value=\"Send\" size=\"8\"> <input type = \"reset\"  value=\"cancel\" size=\"8\">"));
	PSOCK_END(&s->sout);
}
Esempio n. 2
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(send_headers(struct httpd_state *s, const char *statushdr))
{

  char *ptr;

  PSOCK_BEGIN(&s->sout);

  PSOCK_SEND_PSTR(&s->sout, statushdr);

  ptr = strrchr(s->filename, ISO_period);

  if(ptr == NULL) {
    PSOCK_SEND_PSTR(&s->sout, http_content_type_binary);
	PSOCK_SEND_PSTR(&s->sout, http_content_length);
	PSOCK_SEND_STR(&s->sout, s->tmp_str);
	PSOCK_SEND_PSTR(&s->sout, http_crnlcrln);
  } else if(strncmp_P( ptr,http_html, 5) == 0 ||
	        strncmp_P( ptr,http_shtml, 6) == 0) {
    PSOCK_SEND_PSTR(&s->sout, http_content_type_html);
  } else if(strncmp_P(ptr,http_css,  4) == 0) {
    PSOCK_SEND_PSTR(&s->sout, http_content_type_css);
  } else if(strncmp_P(ptr,http_png, 4) == 0) {
    PSOCK_SEND_PSTR(&s->sout, http_content_type_png);
	PSOCK_SEND_PSTR(&s->sout, http_content_length);
	PSOCK_SEND_STR(&s->sout, s->tmp_str);
	PSOCK_SEND_PSTR(&s->sout, http_crnlcrln);
  } else if(strncmp_P( ptr, http_gif, 4) == 0) {
    PSOCK_SEND_PSTR(&s->sout, http_content_type_gif);
	PSOCK_SEND_PSTR(&s->sout, http_content_length);
	PSOCK_SEND_STR(&s->sout, s->tmp_str);
	PSOCK_SEND_PSTR(&s->sout, http_crnlcrln);
  } else if(strncmp_P( ptr, http_jpg, 4) == 0) {
    PSOCK_SEND_PSTR(&s->sout, http_content_type_jpg);
	PSOCK_SEND_PSTR(&s->sout, http_content_length);
	PSOCK_SEND_STR(&s->sout, s->tmp_str);
	PSOCK_SEND_PSTR(&s->sout, http_crnlcrln);
  } else {
    PSOCK_SEND_PSTR(&s->sout, http_content_type_plain);
  }

  PSOCK_END(&s->sout);
									  												

/*  PT_BEGIN(&s->outputpt);

  char *ptr;

  //PSOCK_BEGIN(&s->sout);

  // save the current state of the file
  s->tmp_charp = s->file.data;
  s->tmp_int   = s->len;

  s->file.data = (char *) statushdr;
  s->len = strlen_P(statushdr);   
  PT_WAIT_THREAD(&s->outputpt, send_part_of_file(s));

  ptr = strrchr(s->filename, ISO_period);
  if(ptr == NULL) {
    s->file.data = (char *)http_content_type_binary;
    s->len = strlen_P(http_content_type_binary);   
    PT_WAIT_THREAD(&s->outputpt, send_part_of_file(s));
	s->len = 0; // use as flag to say, sent content lengh
  } else if(strncmp_P(ptr, http_html, 5) == 0 ||
	        strncmp_P(ptr, http_shtml, 6) == 0) {
    s->file.data = (char *)http_content_type_html;
    s->len = strlen_P(http_content_type_html);   
    PT_WAIT_THREAD(&s->outputpt, send_part_of_file(s));
  } else if(strncmp_P(ptr, http_css, 4) == 0) {
    s->file.data = (char *)http_content_type_css;
    s->len = strlen_P(http_content_type_css);   
    PT_WAIT_THREAD(&s->outputpt, send_part_of_file(s));
  } else if(strncmp_P(ptr, http_png, 4) == 0) {
    s->file.data = (char *)http_content_type_png;
    s->len = strlen_P(http_content_type_png);   
    PT_WAIT_THREAD(&s->outputpt, send_part_of_file(s));
	s->len = 0; // use as flag to say, sent content lengh
  } else if(strncmp_P(ptr, http_gif, 4) == 0) {
    s->file.data = (char *)http_content_type_gif;
    s->len = strlen_P(http_content_type_gif);   
    PT_WAIT_THREAD(&s->outputpt, send_part_of_file(s));
	s->len = 0; // use as flag to say, sent content lengh
  } else if(strncmp_P(ptr, http_jpg, 4) == 0) {
    s->file.data = (char *)http_content_type_jpg;
    s->len = strlen_P(http_content_type_jpg);   
    PT_WAIT_THREAD(&s->outputpt, send_part_of_file(s));
	s->len = 0; // use as flag to say, sent content lengh
  } else {
    s->file.data = (char *)http_content_type_plain;
    s->len = strlen_P(http_content_type_plain);   
    PT_WAIT_THREAD(&s->outputpt, send_part_of_file(s));
  }

  // ugly flag hack to send the content len
//  if (s->len == 0)
//  {
  //  s->file.data = (char *)http_content_length;
 //   s->len = strlen_P(http_content_length);
 //   PT_WAIT_THREAD(&s->outputpt, send_part_of_file(s));
    snprintf(s->str_tmp, sizeof(s->str_tmp) -1, "%d", s->tmp_int);
	PSOCK_SEND_STR(&s->sout, s->str_tmp);
	s->file.data = (char *)http_crnlcrln;
	s->len = strlen_P(http_crnlcrln);
	PT_WAIT_THREAD(&s->outputpt, send_part_of_file(s));
//  }

  // restore the state of the file
  s->file.data = s->tmp_charp;
  s->len = s->tmp_int;
  PT_END(&s->outputpt);
  */
}