@ -162,7 +162,7 @@ const char *httpdGetVersion(void) 
			
		
	
		
		
			
				
					
					    return  HTTPDVER ;      return  HTTPDVER ;   
			
		
	
		
		
			
				
					
					} }  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					in thttpGetBacklogSize ( const  HttpdConnData  * conn ) size_ thttpGetBacklogSize ( const  HttpdConnData  * conn )  
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					{ {  
			
		
	
		
		
			
				
					
					    HttpSendBacklogItem  * bl  =  conn - > priv - > sendBacklog ;      HttpSendBacklogItem  * bl  =  conn - > priv - > sendBacklog ;   
			
		
	
		
		
			
				
					
					    if  ( ! bl )  {  return  0 ;  }      if  ( ! bl )  {  return  0 ;  }   
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -193,6 +193,9 @@ static HttpdConnData *httpdFindConnData(ConnTypePtr conn, const char *remIp, int 
			
		
	
		
		
			
				
					
					//Retires a connection for re-use
 //Retires a connection for re-use
  
			
		
	
		
		
			
				
					
					static  void  httpdRetireConn ( HttpdConnData  * conn ) static  void  httpdRetireConn ( HttpdConnData  * conn )  
			
		
	
		
		
			
				
					
					{ {  
			
		
	
		
		
			
				
					
					    if  ( ! conn )  {   
			
		
	
		
		
			
				
					
					        return ;   
			
		
	
		
		
			
				
					
					    }   
			
		
	
		
		
			
				
					
					    if  ( conn - > priv - > sendBacklog  ! =  NULL )  {      if  ( conn - > priv - > sendBacklog  ! =  NULL )  {   
			
		
	
		
		
			
				
					
					        HttpSendBacklogItem  * i ,  * j ;          HttpSendBacklogItem  * i ,  * j ;   
			
		
	
		
		
			
				
					
					        i  =  conn - > priv - > sendBacklog ;          i  =  conn - > priv - > sendBacklog ;   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -205,14 +208,14 @@ static void httpdRetireConn(HttpdConnData *conn) 
			
		
	
		
		
			
				
					
					    if  ( conn - > post - > buff  ! =  NULL )  {  httpdPlatFree ( conn - > post - > buff ) ;  }      if  ( conn - > post - > buff  ! =  NULL )  {  httpdPlatFree ( conn - > post - > buff ) ;  }   
			
		
	
		
		
			
				
					
					    if  ( conn - > post  ! =  NULL )  {  httpdPlatFree ( conn - > post ) ;  }      if  ( conn - > post  ! =  NULL )  {  httpdPlatFree ( conn - > post ) ;  }   
			
		
	
		
		
			
				
					
					    if  ( conn - > priv  ! =  NULL )  {  httpdPlatFree ( conn - > priv ) ;  }      if  ( conn - > priv  ! =  NULL )  {  httpdPlatFree ( conn - > priv ) ;  }   
			
		
	
		
		
			
				
					
					    if  ( conn )  {  httpdPlatFree ( conn ) ;  }       httpdPlatFree ( conn ) ;   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					    for  ( int  i  =  0 ;  i  <  HTTPD_MAX_CONNECTIONS ;  i + + )  {      for  ( int  i  =  0 ;  i  <  HTTPD_MAX_CONNECTIONS ;  i + + )  {   
			
		
	
		
		
			
				
					
					        if  ( s_connData [ i ]  = =  conn )  {  s_connData [ i ]  =  NULL ;  }          if  ( s_connData [ i ]  = =  conn )  {  s_connData [ i ]  =  NULL ;  }   
			
		
	
		
		
			
				
					
					    }      }   
			
		
	
		
		
			
				
					
					} }  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					//Stupid li'l helper function that returns the value of a hex char.
 //Stupid li'l helper function that returns the value of a hex char.
  
			
		
	
		
		
			
				
					
					static  int httpdHexVal ( char  c ) static  char httpdHexVal ( char  c )  
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					{ {  
			
		
	
		
		
			
				
					
					    if  ( c  > =  ' 0 '  & &  c  < =  ' 9 ' )  {  return  c  -  ' 0 ' ;  }      if  ( c  > =  ' 0 '  & &  c  < =  ' 9 ' )  {  return  c  -  ' 0 ' ;  }   
			
		
	
		
		
			
				
					
					    if  ( c  > =  ' A '  & &  c  < =  ' F ' )  {  return  c  -  ' A '  +  10 ;  }      if  ( c  > =  ' A '  & &  c  < =  ' F ' )  {  return  c  -  ' A '  +  10 ;  }   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -227,13 +230,14 @@ static int httpdHexVal(char c) 
			
		
	
		
		
			
				
					
					int  httpdUrlDecode ( const  char  * val ,  int  valLen ,  char  * ret ,  int  retLen ) int  httpdUrlDecode ( const  char  * val ,  int  valLen ,  char  * ret ,  int  retLen )  
			
		
	
		
		
			
				
					
					{ {  
			
		
	
		
		
			
				
					
					    int  s  =  0 ,  d  =  0 ;      int  s  =  0 ,  d  =  0 ;   
			
		
	
		
		
			
				
					
					    int  esced  =  0 ,  escVal  =  0 ;      int  esced  =  0 ;   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					    char  escVal  =  0 ;   
			
		
	
		
		
			
				
					
					    while  ( s  <  valLen  & &  d  <  retLen )  {      while  ( s  <  valLen  & &  d  <  retLen )  {   
			
		
	
		
		
			
				
					
					        if  ( esced  = =  1 )  {          if  ( esced  = =  1 )  {   
			
		
	
		
		
			
				
					
					            escVal  =  httpdHexVal ( val [ s ] )  < <  4 ;              escVal  =  httpdHexVal ( val [ s ] )  < <  4 ;   
			
		
	
		
		
			
				
					
					            esced  =  2 ;              esced  =  2 ;   
			
		
	
		
		
			
				
					
					        }  else  if  ( esced  = =  2 )  {          }  else  if  ( esced  = =  2 )  {   
			
		
	
		
		
			
				
					
					            escVal  + =  httpdHexVal ( val [ s ] ) ;              escVal  | =  httpdHexVal ( val [ s ] ) ;   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					            ret [ d + + ]  =  escVal ;              ret [ d + + ]  =  escVal ;   
			
		
	
		
		
			
				
					
					            esced  =  0 ;              esced  =  0 ;   
			
		
	
		
		
			
				
					
					        }  else  if  ( val [ s ]  = =  ' % ' )  {          }  else  if  ( val [ s ]  = =  ' % ' )  {   
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -261,18 +265,18 @@ int httpdFindArg(const char *line, const char *arg, char *buff, int buffLen) 
			
		
	
		
		
			
				
					
					    const  int  arglen  =  ( int )  strlen ( arg ) ;      const  int  arglen  =  ( int )  strlen ( arg ) ;   
			
		
	
		
		
			
				
					
					    p  =  line ;      p  =  line ;   
			
		
	
		
		
			
				
					
					    while  ( p  ! =  NULL  & &  * p  ! =  ' \n '  & &  * p  ! =  ' \r '  & &  * p  ! =  0 )  {      while  ( p  ! =  NULL  & &  * p  ! =  ' \n '  & &  * p  ! =  ' \r '  & &  * p  ! =  0 )  {   
			
		
	
		
		
			
				
					
					                 router_dbg ( " findArg: %s " ,  p ) ;          router_dbg ( " findArg: %s " ,  p ) ;   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					        if  ( strstarts ( p ,  arg )  & &  p [ arglen ]  = =  ' = ' )  {          if  ( strstarts ( p ,  arg )  & &  p [ arglen ]  = =  ' = ' )  {   
			
		
	
		
		
			
				
					
					            p  + =  arglen  +  1 ;  //move p to start of value
              p  + =  arglen  +  1 ;  //move p to start of value
   
			
		
	
		
		
			
				
					
					            e  =  strstr ( p ,  " & " ) ;              e  =  strstr ( p ,  " & " ) ;   
			
		
	
		
		
			
				
					
					            if  ( e  = =  NULL )  {  e  =  p  +  strlen ( p ) ;  }              if  ( e  = =  NULL )  {  e  =  p  +  strlen ( p ) ;  }   
			
		
	
		
		
			
				
					
					                     router_dbg ( " findArg: val %s len %d " ,  p ,  ( e  -  p ) ) ;              router_dbg ( " findArg: val %s len %d " ,  p ,  ( int )   ( e  -  p ) ) ;   
			
				
				
			
		
	
		
		
			
				
					
					            return  httpdUrlDecode ( p ,  ( e  -  p ) ,  buff ,  buffLen ) ;              return  httpdUrlDecode ( p ,  ( int ) ( e  -  p ) ,  buff ,  buffLen ) ;   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					        }          }   
			
		
	
		
		
			
				
					
					        p  =  strstr ( p ,  " & " ) ;          p  =  strstr ( p ,  " & " ) ;   
			
		
	
		
		
			
				
					
					        if  ( p  ! =  NULL )  {  p  + =  1 ;  }          if  ( p  ! =  NULL )  {  p  + =  1 ;  }   
			
		
	
		
		
			
				
					
					    }      }   
			
		
	
		
		
			
				
					
					             router_error ( " Finding arg %s in %s: Not found :/ " ,  arg ,  line ) ;      router_error ( " Finding arg %s in %s: Not found :/ " ,  arg ,  line ) ;   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					    return  - 1 ;  //not found
      return  - 1 ;  //not found
   
			
		
	
		
		
			
				
					
					} }  
			
		
	
		
		
			
				
					
					
 
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -339,28 +343,28 @@ void httpdStartResponse(HttpdConnData *conn, int code) 
			
		
	
		
		
			
				
					
					                code2str ( code ) ,                  code2str ( code ) ,   
			
		
	
		
		
			
				
					
					                serverName ,                  serverName ,   
			
		
	
		
		
			
				
					
					                connStr ) ;                  connStr ) ;   
			
		
	
		
		
			
				
					
					    httpdSend ( conn ,  buff ,  l ) ;      httpdSendStrN  ( conn ,  buff ,  l ) ;   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    if  ( 0  = =  ( conn - > priv - > flags  &  HFL_NOCORS ) )  {      if  ( 0  = =  ( conn - > priv - > flags  &  HFL_NOCORS ) )  {   
			
		
	
		
		
			
				
					
					        // CORS headers
          // CORS headers
   
			
		
	
		
		
			
				
					
					        httpdSend ( conn ,  " Access-Control-Allow-Origin: * \r \n " ,  - 1 ) ;          httpdSendStr  ( conn ,  " Access-Control-Allow-Origin: * \r \n " ) ;   
			
				
				
			
		
	
		
		
			
				
					
					        httpdSend ( conn ,  " Access-Control-Allow-Methods: GET,POST,OPTIONS \r \n " ,  - 1 ) ;          httpdSendStr  ( conn ,  " Access-Control-Allow-Methods: GET,POST,OPTIONS \r \n " ) ;   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					    }      }   
			
		
	
		
		
			
				
					
					} }  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					//Send a http header.
 //Send a http header.
  
			
		
	
		
		
			
				
					
					void  httpdHeader ( HttpdConnData  * conn ,  const  char  * field ,  const  char  * val ) void  httpdHeader ( HttpdConnData  * conn ,  const  char  * field ,  const  char  * val )  
			
		
	
		
		
			
				
					
					{ {  
			
		
	
		
		
			
				
					
					    httpdSend ( conn ,  field ,  - 1 ) ;      httpdSendStr  ( conn ,  field ) ;   
			
				
				
			
		
	
		
		
			
				
					
					    httpdSend ( conn ,  " :  " ,  - 1 ) ;      httpdSendStr  ( conn ,  " :  " ) ;   
			
				
				
			
		
	
		
		
			
				
					
					    httpdSend ( conn ,  val ,  - 1 ) ;      httpdSendStr  ( conn ,  val ) ;   
			
				
				
			
		
	
		
		
			
				
					
					    httpdSend ( conn ,  " \r \n " ,  - 1 ) ;      httpdSendStr  ( conn ,  " \r \n " ) ;   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					} }  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					//Finish the headers.
 //Finish the headers.
  
			
		
	
		
		
			
				
					
					void  httpdEndHeaders ( HttpdConnData  * conn ) void  httpdEndHeaders ( HttpdConnData  * conn )  
			
		
	
		
		
			
				
					
					{ {  
			
		
	
		
		
			
				
					
					    httpdSend ( conn ,  " \r \n " ,  - 1 ) ;      httpdSendStr  ( conn ,  " \r \n " ) ;   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					    conn - > priv - > flags  | =  HFL_SENDINGBODY ;      conn - > priv - > flags  | =  HFL_SENDINGBODY ;   
			
		
	
		
		
			
				
					
					} }  
			
		
	
		
		
			
				
					
					
 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -371,8 +375,8 @@ void httpdRedirect(HttpdConnData *conn, const char *newUrl) 
			
		
	
		
		
			
				
					
					    httpdStartResponse ( conn ,  302 ) ;      httpdStartResponse ( conn ,  302 ) ;   
			
		
	
		
		
			
				
					
					    httpdHeader ( conn ,  " Location " ,  newUrl ) ;      httpdHeader ( conn ,  " Location " ,  newUrl ) ;   
			
		
	
		
		
			
				
					
					    httpdEndHeaders ( conn ) ;      httpdEndHeaders ( conn ) ;   
			
		
	
		
		
			
				
					
					    httpdSend ( conn ,  " Moved to  " ,  - 1 ) ;      httpdSendStr  ( conn ,  " Moved to  " ) ;   
			
				
				
			
		
	
		
		
			
				
					
					    httpdSend ( conn ,  newUrl ,  - 1 ) ;      httpdSendStr  ( conn ,  newUrl ) ;   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					} }  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					//Use this as a cgi function to redirect one url to another.
 //Use this as a cgi function to redirect one url to another.
  
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -392,7 +396,7 @@ static httpd_cgi_state cgiNotFound(HttpdConnData *connData) 
			
		
	
		
		
			
				
					
					    if  ( connData - > conn  = =  NULL )  {  return  HTTPD_CGI_DONE ;  }      if  ( connData - > conn  = =  NULL )  {  return  HTTPD_CGI_DONE ;  }   
			
		
	
		
		
			
				
					
					    httpdStartResponse ( connData ,  404 ) ;      httpdStartResponse ( connData ,  404 ) ;   
			
		
	
		
		
			
				
					
					    httpdEndHeaders ( connData ) ;      httpdEndHeaders ( connData ) ;   
			
		
	
		
		
			
				
					
					    httpdSend ( connData ,  " 404 File not found. " ,  - 1 ) ;      httpdSendStr  ( connData ,  " 404 File not found. " ) ;   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					    return  HTTPD_CGI_DONE ;      return  HTTPD_CGI_DONE ;   
			
		
	
		
		
			
				
					
					} }  
			
		
	
		
		
			
				
					
					
 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -406,7 +410,6 @@ httpd_cgi_state cgiRedirectToHostname(HttpdConnData *connData) 
			
		
	
		
		
			
				
					
					    static  const  char  hostFmt [ ]  =  " http://%s/ " ;      static  const  char  hostFmt [ ]  =  " http://%s/ " ;   
			
		
	
		
		
			
				
					
					    char  * buff ;      char  * buff ;   
			
		
	
		
		
			
				
					
					    int  isIP  =  0 ;      int  isIP  =  0 ;   
			
		
	
		
		
			
				
					
					    int  x ;   
			
		
	
		
		
			
				
					
					    if  ( connData - > conn  = =  NULL )  {      if  ( connData - > conn  = =  NULL )  {   
			
		
	
		
		
			
				
					
					        //Connection aborted. Clean up.
          //Connection aborted. Clean up.
   
			
		
	
		
		
			
				
					
					        return  HTTPD_CGI_DONE ;          return  HTTPD_CGI_DONE ;   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -419,7 +422,7 @@ httpd_cgi_state cgiRedirectToHostname(HttpdConnData *connData) 
			
		
	
		
		
			
				
					
					    //Quick and dirty code to see if host is an IP
      //Quick and dirty code to see if host is an IP
   
			
		
	
		
		
			
				
					
					    if  ( strlen ( connData - > hostName )  >  8 )  {      if  ( strlen ( connData - > hostName )  >  8 )  {   
			
		
	
		
		
			
				
					
					        isIP  =  1 ;          isIP  =  1 ;   
			
		
	
		
		
			
				
					
					        for  ( x  =  0 ;  x  <  strlen ( connData - > hostName ) ;  x + + )  {          for  ( size_t  x  =  0 ;  x  <  strlen ( connData - > hostName ) ;  x + + )  {   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					            if  ( connData - > hostName [ x ]  ! =  ' . '  & &  ( connData - > hostName [ x ]  <  ' 0 '  | |  connData - > hostName [ x ]  >  ' 9 ' ) )  {  isIP  =  0 ;  }              if  ( connData - > hostName [ x ]  ! =  ' . '  & &  ( connData - > hostName [ x ]  <  ' 0 '  | |  connData - > hostName [ x ]  >  ' 9 ' ) )  {  isIP  =  0 ;  }   
			
		
	
		
		
			
				
					
					        }          }   
			
		
	
		
		
			
				
					
					    }      }   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -443,10 +446,9 @@ httpd_cgi_state cgiRedirectToHostname(HttpdConnData *connData) 
			
		
	
		
		
			
				
					
					//Add data to the send buffer. len is the length of the data. If len is -1
 //Add data to the send buffer. len is the length of the data. If len is -1
  
			
		
	
		
		
			
				
					
					//the data is seen as a C-string.
 //the data is seen as a C-string.
  
			
		
	
		
		
			
				
					
					//Returns 1 for success, 0 for out-of-memory.
 //Returns 1 for success, 0 for out-of-memory.
  
			
		
	
		
		
			
				
					
					int  httpdSend ( HttpdConnData  * conn ,  const  char  * data ,  in tlen ) int  httpdSend ( HttpdConnData  * conn ,  const  uint8_t  * data ,  size_ tlen )  
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					{ {  
			
		
	
		
		
			
				
					
					    if  ( conn - > conn  = =  NULL )  {  return  0 ;  }      if  ( conn - > conn  = =  NULL )  {  return  0 ;  }   
			
		
	
		
		
			
				
					
					    if  ( len  <  0 )  {  len  =  strlen ( data ) ;  }   
			
		
	
		
		
			
				
					
					    if  ( len  = =  0 )  {  return  0 ;  }      if  ( len  = =  0 )  {  return  0 ;  }   
			
		
	
		
		
			
				
					
					    if  ( conn - > priv - > flags  &  HFL_CHUNKED  & &  conn - > priv - > flags  &  HFL_SENDINGBODY  & &  conn - > priv - > chunkHdr  = =  NULL )  {      if  ( conn - > priv - > flags  &  HFL_CHUNKED  & &  conn - > priv - > flags  &  HFL_SENDINGBODY  & &  conn - > priv - > chunkHdr  = =  NULL )  {   
			
		
	
		
		
			
				
					
					        if  ( conn - > priv - > sendBuffLen  +  len  +  6  >  HTTPD_MAX_SENDBUFF_LEN )  {  return  0 ;  }          if  ( conn - > priv - > sendBuffLen  +  len  +  6  >  HTTPD_MAX_SENDBUFF_LEN )  {  return  0 ;  }   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -464,19 +466,21 @@ int httpdSend(HttpdConnData *conn, const char *data, int len) 
			
		
	
		
		
			
				
					
					static  char  httpdHexNibble ( int  val ) static  char  httpdHexNibble ( int  val )  
			
		
	
		
		
			
				
					
					{ {  
			
		
	
		
		
			
				
					
					    val  & =  0xf ;      val  & =  0xf ;   
			
		
	
		
		
			
				
					
					    if  ( val  <  10 )  {  return  ' 0 '  +  val ;  }      if  ( val  <  10 )  {  return  ( char )  ( ' 0 '  +  val ) ;  }   
			
				
				
			
		
	
		
		
			
				
					
					    return  ' A '  +  ( val  -  10 ) ;      return  ( char )  ( ' A '  +  ( val  -  10 ) ) ;   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					} }  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					# define httpdSend_orDie(conn, data, len) do { if (!httpdSend((conn), (data), (len))) return false; } while (0) # define httpdSend_orDie(conn, data, len) do { if (!httpdSend((conn), (const uint8_t *)(data), (len))) return false; } while (0)  
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					# define httpdSendStr_orDie(conn, data) do { if (!httpdSendStr((conn), (data))) return false; } while (0)  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					/* encode for HTML. returns 0 or 1 - 1 = success */ /* encode for HTML. returns 0 or 1 - 1 = success */  
			
		
	
		
		
			
				
					
					int  httpdSend_html ( HttpdConnData  * conn ,  const  char  * data ,  in tlen ) int  httpdSend_html ( HttpdConnData  * conn ,  const  uint8_t  * data ,  ssize_ tlen )  
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					{ {  
			
		
	
		
		
			
				
					
					    int  start  =  0 ,  end  =  0 ;      int  start  =  0 ,  end  =  0 ;   
			
		
	
		
		
			
				
					
					    char c ;      uint8_t c ;   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					    if  ( conn - > conn  = =  NULL )  {  return  0 ;  }      if  ( conn - > conn  = =  NULL )  {  return  0 ;  }   
			
		
	
		
		
			
				
					
					    if  ( len  <  0 )  {  len  =  ( int )  strlen ( data ) ;  }      if  ( len  <  0 )  {  len  =  ( int )  strlen ( ( const  char  * )  data ) ;  }   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					    if  ( len  = =  0 )  {  return  0 ;  }      if  ( len  = =  0 )  {  return  0 ;  }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    for  ( end  =  0 ;  end  <  len ;  end + + )  {      for  ( end  =  0 ;  end  <  len ;  end + + )  {   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -491,10 +495,10 @@ int httpdSend_html(HttpdConnData *conn, const char *data, int len) 
			
		
	
		
		
			
				
					
					            start  =  end  +  1 ;              start  =  end  +  1 ;   
			
		
	
		
		
			
				
					
					        }          }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        if  ( c  = =  ' " ' )  httpdSend_orDie ( conn ,  " " " ,  5 ) ;          if  ( c  = =  ' " ' )  httpdSendStr _orDie ( conn ,  " " " ) ;   
			
				
				
			
		
	
		
		
			
				
					
					        else  if  ( c  = =  ' \' ' )  httpdSend_orDie ( conn ,  " ' ; " , 5 );         else  if  ( c  = =  ' \' ' )  httpdSendStr _orDie ( conn ,  " ' ; " );   
			
				
				
			
		
	
		
		
			
				
					
					        else  if  ( c  = =  ' < ' )  httpdSend_orDie ( conn ,  " < ; " , 4 );         else  if  ( c  = =  ' < ' )  httpdSendStr _orDie ( conn ,  " < ; " );   
			
				
				
			
		
	
		
		
			
				
					
					        else  if  ( c  = =  ' > ' )  httpdSend_orDie ( conn ,  " > ; " , 4 );         else  if  ( c  = =  ' > ' )  httpdSendStr _orDie ( conn ,  " > ; " );   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					    }      }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    if  ( start  <  end )  httpdSend_orDie ( conn ,  data  +  start ,  end  -  start ) ;      if  ( start  <  end )  httpdSend_orDie ( conn ,  data  +  start ,  end  -  start ) ;   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -502,12 +506,12 @@ int httpdSend_html(HttpdConnData *conn, const char *data, int len) 
			
		
	
		
		
			
				
					
					} }  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					/* encode for JS. returns 0 or 1 - 1 = success */ /* encode for JS. returns 0 or 1 - 1 = success */  
			
		
	
		
		
			
				
					
					int  httpdSend_js ( HttpdConnData  * conn ,  const  char  * data ,  in tlen ) int  httpdSend_js ( HttpdConnData  * conn ,  const  uint8_t  * data ,  ssize_ tlen )  
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					{ {  
			
		
	
		
		
			
				
					
					    int  start  =  0 ,  end  =  0 ;      int  start  =  0 ,  end  =  0 ;   
			
		
	
		
		
			
				
					
					    char c ;      uint8_t c ;   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					    if  ( conn - > conn  = =  NULL )  {  return  0 ;  }      if  ( conn - > conn  = =  NULL )  {  return  0 ;  }   
			
		
	
		
		
			
				
					
					    if  ( len  <  0 )  {  len  =  ( int )  strlen ( data ) ;  }      if  ( len  <  0 )  {  len  =  ( int )  strlen ( ( const  char  * )  data ) ;  }   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					    if  ( len  = =  0 )  {  return  0 ;  }      if  ( len  = =  0 )  {  return  0 ;  }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    for  ( end  =  0 ;  end  <  len ;  end + + )  {      for  ( end  =  0 ;  end  <  len ;  end + + )  {   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -522,13 +526,13 @@ int httpdSend_js(HttpdConnData *conn, const char *data, int len) 
			
		
	
		
		
			
				
					
					            start  =  end  +  1 ;              start  =  end  +  1 ;   
			
		
	
		
		
			
				
					
					        }          }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					        if  ( c  = =  ' " ' )  httpdSend_orDie ( conn ,  " \\ \" " ,  2 ) ;          if  ( c  = =  ' " ' )  httpdSendStr _orDie ( conn ,  " \\ \" " ) ;   
			
				
				
			
		
	
		
		
			
				
					
					        else  if  ( c  = =  ' \' ' )  httpdSend_orDie ( conn ,  " \\ ' " ,  2 ) ;          else  if  ( c  = =  ' \' ' )  httpdSendStr _orDie ( conn ,  " \\ ' " ) ;   
			
				
				
			
		
	
		
		
			
				
					
					        else  if  ( c  = =  ' \\ ' )  httpdSend_orDie ( conn ,  " \\ \\ " ,  2 ) ;          else  if  ( c  = =  ' \\ ' )  httpdSendStr _orDie ( conn ,  " \\ \\ " ) ;   
			
				
				
			
		
	
		
		
			
				
					
					        else  if  ( c  = =  ' < ' )  httpdSend_orDie ( conn ,  " \\ u003C " ,  6 ) ;          else  if  ( c  = =  ' < ' )  httpdSendStr _orDie ( conn ,  " \\ u003C " ) ;   
			
				
				
			
		
	
		
		
			
				
					
					        else  if  ( c  = =  ' > ' )  httpdSend_orDie ( conn ,  " \\ u003E " ,  6 ) ;          else  if  ( c  = =  ' > ' )  httpdSendStr _orDie ( conn ,  " \\ u003E " ) ;   
			
				
				
			
		
	
		
		
			
				
					
					        else  if  ( c  = =  ' \n ' )  httpdSend_orDie ( conn ,  " \\ n " ,  2 ) ;          else  if  ( c  = =  ' \n ' )  httpdSendStr _orDie ( conn ,  " \\ n " ) ;   
			
				
				
			
		
	
		
		
			
				
					
					        else  if  ( c  = =  ' \r ' )  httpdSend_orDie ( conn ,  " \\ r " ,  2 ) ;          else  if  ( c  = =  ' \r ' )  httpdSendStr _orDie ( conn ,  " \\ r " ) ;   
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					    }      }   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					    if  ( start  <  end )  httpdSend_orDie ( conn ,  data  +  start ,  end  -  start ) ;      if  ( start  <  end )  httpdSend_orDie ( conn ,  data  +  start ,  end  -  start ) ;   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -546,7 +550,7 @@ bool httpdFlushSendBuffer(HttpdConnData *conn) 
			
		
	
		
		
			
				
					
					    if  ( conn - > priv - > chunkHdr  ! =  NULL )  {      if  ( conn - > priv - > chunkHdr  ! =  NULL )  {   
			
		
	
		
		
			
				
					
					        //We're sending chunked data, and the chunk needs fixing up.
          //We're sending chunked data, and the chunk needs fixing up.
   
			
		
	
		
		
			
				
					
					        //Finish chunk with cr/lf
          //Finish chunk with cr/lf
   
			
		
	
		
		
			
				
					
					        httpdSend ( conn ,  " \r \n " ,  2 ) ;          httpdSendStr  ( conn ,  " \r \n " ) ;   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					        //Calculate length of chunk
          //Calculate length of chunk
   
			
		
	
		
		
			
				
					
					        len  =  ( ( & conn - > priv - > sendBuff [ conn - > priv - > sendBuffLen ] )  -  conn - > priv - > chunkHdr )  -  8 ;          len  =  ( ( & conn - > priv - > sendBuff [ conn - > priv - > sendBuffLen ] )  -  conn - > priv - > chunkHdr )  -  8 ;   
			
		
	
		
		
			
				
					
					        //Fix up chunk header to correct value
          //Fix up chunk header to correct value
   
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -687,7 +691,7 @@ static void httpdProcessRequest(HttpdConnData *conn) 
			
		
	
		
		
			
				
					
					    int  r ;      int  r ;   
			
		
	
		
		
			
				
					
					    int  i  =  0 ;      int  i  =  0 ;   
			
		
	
		
		
			
				
					
					    if  ( conn - > url  = =  NULL )  {      if  ( conn - > url  = =  NULL )  {   
			
		
	
		
		
			
				
					
					                 router_warn ( " WtF? url = NULL " ) ;          router_warn ( " WtF? url = NULL " ) ;   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					        return ;  //Shouldn't happen
          return ;  //Shouldn't happen
   
			
		
	
		
		
			
				
					
					    }      }   
			
		
	
		
		
			
				
					
					
 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -698,7 +702,7 @@ static void httpdProcessRequest(HttpdConnData *conn) 
			
		
	
		
		
			
				
					
					        httpdEndHeaders ( conn ) ;          httpdEndHeaders ( conn ) ;   
			
		
	
		
		
			
				
					
					        httpdCgiIsDone ( conn ) ;          httpdCgiIsDone ( conn ) ;   
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					                 router_dbg ( " CORS preflight resp sent. " ) ;          router_dbg ( " CORS preflight resp sent. " ) ;   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					        return ;          return ;   
			
		
	
		
		
			
				
					
					    }      }   
			
		
	
		
		
			
				
					
					
 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -708,7 +712,7 @@ static void httpdProcessRequest(HttpdConnData *conn) 
			
		
	
		
		
			
				
					
					        //Look up URL in the built-in URL table.
          //Look up URL in the built-in URL table.
   
			
		
	
		
		
			
				
					
					        while  ( builtInUrls [ i ] . url  ! =  NULL )  {          while  ( builtInUrls [ i ] . url  ! =  NULL )  {   
			
		
	
		
		
			
				
					
					            int  match  =  0 ;              int  match  =  0 ;   
			
		
	
		
		
			
				
					
					            const  char  const  * route  =  builtInUrls [ i ] . url ;              const  char  * route  =  builtInUrls [ i ] . url ;   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					            //See if there's a literal match
              //See if there's a literal match
   
			
		
	
		
		
			
				
					
					            if  ( streq ( route ,  conn - > url ) )  {  match  =  1 ;  }              if  ( streq ( route ,  conn - > url ) )  {  match  =  1 ;  }   
			
		
	
		
		
			
				
					
					            //See if there's a wildcard match (*)
              //See if there's a wildcard match (*)
   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -723,7 +727,7 @@ static void httpdProcessRequest(HttpdConnData *conn) 
			
		
	
		
		
			
				
					
					                match  =  1 ;                  match  =  1 ;   
			
		
	
		
		
			
				
					
					            }              }   
			
		
	
		
		
			
				
					
					            if  ( match )  {              if  ( match )  {   
			
		
	
		
		
			
				
					
					                         router_dbg ( " Matched route #%d, url=%s " ,  i ,  route ) ;                  router_dbg ( " Matched route #%d, url=%s " ,  i ,  route ) ;   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					                conn - > cgiData  =  NULL ;                  conn - > cgiData  =  NULL ;   
			
		
	
		
		
			
				
					
					                conn - > cgi  =  builtInUrls [ i ] . cgiCb ;                  conn - > cgi  =  builtInUrls [ i ] . cgiCb ;   
			
		
	
		
		
			
				
					
					                conn - > cgiArg  =  builtInUrls [ i ] . cgiArg ;                  conn - > cgiArg  =  builtInUrls [ i ] . cgiArg ;   
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
						
					 
					@ -735,7 +739,7 @@ static void httpdProcessRequest(HttpdConnData *conn) 
			
		
	
		
		
			
				
					
					        if  ( builtInUrls [ i ] . url  = =  NULL )  {          if  ( builtInUrls [ i ] . url  = =  NULL )  {   
			
		
	
		
		
			
				
					
					            //Drat, we're at the end of the URL table. This usually shouldn't happen. Well, just
              //Drat, we're at the end of the URL table. This usually shouldn't happen. Well, just
   
			
		
	
		
		
			
				
					
					            //generate a built-in 404 to handle this.
              //generate a built-in 404 to handle this.
   
			
		
	
		
		
			
				
					
					                     router_warn ( " %s not found. 404! " ,  conn - > url ) ;              router_warn ( " %s not found. 404! " ,  conn - > url ) ;   
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					            conn - > cgi  =  cgiNotFound ;              conn - > cgi  =  cgiNotFound ;   
			
		
	
		
		
			
				
					
					        }          }   
			
		
	
		
		
			
				
					
					
 
			
		
	
	
		
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
					@ -1075,7 +1079,7 @@ httpd_thread_handle_t *httpdInit(const HttpdBuiltInUrl *fixedUrls, struct httpd_ 
			
		
	
		
		
			
				
					
					    return  httpdPlatStart ( options ) ;      return  httpdPlatStart ( options ) ;   
			
		
	
		
		
			
				
					
					} }  
			
		
	
		
		
			
				
					
					
 
			
		
	
		
		
			
				
					
					void  httpdJoin ( httpd_thread_handle_t  *   handle ) void  httpdJoin ( httpd_thread_handle_t  * handle )  
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					{ {  
			
		
	
		
		
			
				
					
					    httpdPlatJoin ( handle ) ;      httpdPlatJoin ( handle ) ;   
			
		
	
		
		
			
				
					
					} }