Exemplo n.º 1
0
/*-----------------------------------------------------------------------------------*/
void
webclient_appcall(void)
{
  if(uip_connected()) {
    s.timer = 0;
    s.state = WEBCLIENT_STATE_STATUSLINE;
    senddata();
    webclient_connected();
    return;
  }

  if(s.state == WEBCLIENT_STATE_CLOSE) {
    webclient_closed();
    uip_abort();
    return;
  }

  if(uip_aborted()) {
    webclient_aborted();
  }
  if(uip_timedout()) {
    webclient_timedout();
  }

  
  if(uip_acked()) {
    s.timer = 0;
    acked();
  }
  if(uip_newdata()) {
    s.timer = 0;
    newdata();
  }
  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked()) {
    senddata();
  } else if(uip_poll()) {
    ++s.timer;
    if(s.timer == WEBCLIENT_TIMEOUT) {
      webclient_timedout();
      uip_abort();
      return;
    }
        /*    senddata();*/
  }

  if(uip_closed()) {
    if(s.httpflag != HTTPFLAG_MOVED) {
      /* Send NULL data to signal EOF. */
      webclient_datahandler(NULL, 0);
    } else {
      if(resolv_lookup(s.host) == NULL) {
	resolv_query(s.host);
      }
      webclient_get(s.host, s.port, s.file);
    }
  }
}
Exemplo n.º 2
0
/*-----------------------------------------------------------------------------------*/
static u16_t parse_statusline(u16_t len)
{
	char *cptr;
	char* temp;

	while(len > 0 && s.httpheaderlineptr < sizeof(s.httpheaderline)) {
		s.httpheaderline[s.httpheaderlineptr] = *(char *)uip_appdata;
		//((char *)uip_appdata)++;
		temp = (char *)uip_appdata;
		temp++;
		uip_appdata = temp;
		--len;
		if(s.httpheaderline[s.httpheaderlineptr] == ISO_nl) {

			if((strncmp(s.httpheaderline, http_11,sizeof(http_11) - 1) == 0)) {
				cptr = &(s.httpheaderline[9]);
				s.httpflag = HTTPFLAG_NONE;
				if(strncmp(cptr, http_200, sizeof(http_200) - 1) == 0) {
					/* 200 OK */
					s.httpflag = HTTPFLAG_OK;
				}
				else if(strncmp(cptr, http_301, sizeof(http_301) - 1) == 0 ||
						strncmp(cptr, http_302, sizeof(http_302) - 1) == 0) {
					/* 301 Moved permanently or 302 Found. Location: header line
					 * will contain the new location. */
					s.httpflag = HTTPFLAG_MOVED;
				}
				else {
					s.httpheaderline[s.httpheaderlineptr - 1] = 0;
				}
			}
			else {
				uip_abort();
				webclient_aborted();
				return 0;
			}

			/* We're done parsing the status line, so we reset the pointer
			 * and start parsing the HTTP headers.*/
			s.httpheaderlineptr = 0;
			s.state = WEBCLIENT_STATE_HEADERS;
			break;
		}
		else {
			++s.httpheaderlineptr;
		}
	}
	return len;
}
Exemplo n.º 3
0
/*-----------------------------------------------------------------------------------*/
void
webclient_appcall(void *state)
{
  char *dataptr;
  
  if(uip_connected()) {
    s.timer = 0;
    s.state = WEBCLIENT_STATE_STATUSLINE;
    senddata();
    webclient_connected();
    tcp_markconn(uip_conn, &s);
    return;
  }

  if(uip_timedout()) {
    webclient_timedout();
  }

  if(uip_aborted()) {
    webclient_aborted();
  }

  if(state == NULL) {
    uip_abort();
    return;
  }

  if(s.state == WEBCLIENT_STATE_CLOSE) {
    webclient_closed();
    uip_abort();
    return;
  }


  /* The acked() and newdata() functions may alter the uip_appdata
     ptr, so we need to store it in the "dataptr" variable so that we
     can restore it before the senddata() function is called. */  
  dataptr = uip_appdata;
  
  if(uip_acked()) {
    s.timer = 0;
    acked();
  }
  if(uip_newdata()) {
    s.timer = 0;
    newdata();
  }

  uip_appdata = dataptr;
  
  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked()) {
    senddata();
  } else if(uip_poll()) {
    ++s.timer;
    if(s.timer == WEBCLIENT_TIMEOUT) {
      webclient_timedout();
      uip_abort();
      return;
    }
        /*    senddata();*/
  }

  if(uip_closed()) {
    tcp_markconn(uip_conn, NULL);
    if(s.httpflag != HTTPFLAG_MOVED) {
      /* Send NULL data to signal EOF. */
      webclient_datahandler(NULL, 0);
    } else {
      /*      conn = uip_connect(uip_conn->ripaddr, s.port);
      if(conn != NULL) {
	dispatcher_markconn(conn, NULL);
	init_connection();
	}*/
#if UIP_UDP
      if(resolv_lookup(s.host) == NULL) {
	resolv_query(s.host);
      }
#endif /* UIP_UDP */
      webclient_get(s.host, s.port, s.file);
    }
  }
}