示例#1
0
/* open a link */
void init_ethmac()
{
    /* initialize the packet rx buffer */
    init_packet();

    /* open ethernet port and wait for connection requests
       keep trying forever */
    while (!open_link());
}
示例#2
0
文件: www.c 项目: EDAyele/ptunes
/*-----------------------------------------------------------------------------------*/
static void
formsubmit(struct formattribs *attribs)
{
  unsigned char i, j;
  register char *urlptr, *valueptr;
  register struct formattribs *faptr;

  urlptr = &tmpurl[0];

  strncpy(urlptr, attribs->formaction, WWW_CONF_MAX_URLLEN);
  tmpurl[WWW_CONF_MAX_URLLEN] = 0;
  urlptr += strlen(urlptr);
  *urlptr = ISO_questionmark;
  ++urlptr;
  
  /* Construct an URL by finding all input field forms with the same
     formname as the current submit button, and add the submit button
     URL stuff as well. */
  for(i = 0; i < pagewidgetptr; ++i) {
    if(urlptr - &tmpurl[0] >= WWW_CONF_MAX_URLLEN) {
      break;
    }

    faptr = &pagewidgetattribs[i].form;
    
    if(strcmp(attribs->formaction, faptr->formaction) == 0 &&
       strcmp(attribs->formname, faptr->formname) == 0 &&
       (faptr->inputtype == FORMINPUTTYPE_INPUTFIELD ||
	faptr == attribs)) {

      /* Copy the name of the input field into the URL and append a
	 questionmark. */
      strncpy(urlptr, faptr->inputname, WWW_CONF_MAX_URLLEN - strlen(tmpurl));
      tmpurl[WWW_CONF_MAX_URLLEN] = 0;
      urlptr += strlen(urlptr);
      *urlptr = ISO_eq;
      ++urlptr;

      /* Convert and copy the contents of the input field to the URL
	 and append an ampersand. */
      valueptr = pagewidgets[i].widget.textentry.text;
      petsciiconv_toascii(valueptr, WWW_CONF_MAX_INPUTVALUELEN);
      for(j = 0; j < WWW_CONF_MAX_INPUTVALUELEN; ++j) {
	if(urlptr - &tmpurl[0] >= WWW_CONF_MAX_URLLEN) {
	  break;
	}
	*urlptr = *valueptr;
	if(*urlptr == ISO_space) {
	  *urlptr = ISO_plus;
	}
	if(*urlptr == 0) {
	  break;
	}
	++urlptr;
	++valueptr;
      }
      
      *urlptr = ISO_ampersand;
      ++urlptr;
    }
  }
  --urlptr;
  *urlptr = 0;
  log_back();
  open_link(tmpurl);
}
示例#3
0
文件: www.c 项目: EDAyele/ptunes
/* www_process():
 *
 * The program's signal dispatcher function. Is called whenever a signal arrives.
 */
PROCESS_THREAD(www_process, ev, data)
{
  static struct ctk_widget *w;
  static unsigned char i;
#if WWW_CONF_WITH_WGET
  static char *argptr;
#endif /* WWW_CONF_WITH_WGET */

  w = (struct ctk_widget *)data;

  PROCESS_BEGIN();
  
  /* Create the main window. */
  memset(webpage, 0, sizeof(webpage));
  ctk_window_new(&mainwindow, WWW_CONF_WEBPAGE_WIDTH,
		 WWW_CONF_WEBPAGE_HEIGHT+5, "Web browser");
  make_window();
#ifdef WWW_CONF_HOMEPAGE
  strncpy(editurl, WWW_CONF_HOMEPAGE, sizeof(editurl));
#endif /* WWW_CONF_HOMEPAGE */
  CTK_WIDGET_FOCUS(&mainwindow, &urlentry);
  
#if WWW_CONF_WITH_WGET
  /* Create download dialog.*/
  ctk_dialog_new(&wgetdialog, 38, 7);
  CTK_WIDGET_ADD(&wgetdialog, &wgetlabel1);
  CTK_WIDGET_ADD(&wgetdialog, &wgetlabel2);
  CTK_WIDGET_ADD(&wgetdialog, &wgetnobutton);
  CTK_WIDGET_ADD(&wgetdialog, &wgetyesbutton);
#endif /* WWW_CONF_WITH_WGET */

  ctk_window_open(&mainwindow);
  
  while(1) {

    PROCESS_WAIT_EVENT();
    
    if(ev == tcpip_event) {
      webclient_appcall(data);
    } else if(ev == ctk_signal_widget_activate) {
      if(w == (struct ctk_widget *)&backbutton) {
	firsty = 0;
	start_loading();
	
	--history_last;
	if(history_last > WWW_CONF_HISTORY_SIZE) {
	  history_last = WWW_CONF_HISTORY_SIZE - 1;
	}
	memcpy(url, history[(int)history_last], WWW_CONF_MAX_URLLEN);
	open_url();
	CTK_WIDGET_FOCUS(&mainwindow, &backbutton);
      } else if(w == (struct ctk_widget *)&downbutton) {
	firsty = pagey + WWW_CONF_WEBPAGE_HEIGHT - 4;
	start_loading();
	open_url();
	CTK_WIDGET_FOCUS(&mainwindow, &downbutton);
      } else if(w == (struct ctk_widget *)&gobutton ||
		w == (struct ctk_widget *)&urlentry) {
	start_loading();
	firsty = 0;
	
	log_back();
	memcpy(url, editurl, WWW_CONF_MAX_URLLEN);
	petsciiconv_toascii(url, WWW_CONF_MAX_URLLEN);
	open_url();
	CTK_WIDGET_FOCUS(&mainwindow, &gobutton);
      } else if(w == (struct ctk_widget *)&stopbutton) {
	loading = 0;
	webclient_close();
#if WWW_CONF_WITH_WGET
      } else if(w == (struct ctk_widget *)&wgetnobutton) {
	ctk_dialog_close();
      } else if(w == (struct ctk_widget *)&wgetyesbutton) {
	ctk_dialog_close();
	quit();
	argptr = arg_alloc((char)WWW_CONF_MAX_URLLEN);
	if(argptr != NULL) {
	  strncpy(argptr, url, WWW_CONF_MAX_URLLEN);
	}
	program_handler_load("wget.prg", argptr);
#endif /* WWW_CONF_WITH_WGET */
#if WWW_CONF_FORMS
      } else {
	/* Check form buttons */
	for(i = 0; i < pagewidgetptr; ++i) {
	  if(&pagewidgets[i] == w) {
	    formsubmit(&pagewidgetattribs[i].form);
	    /*	  show_statustext(pagewidgetattribs[i].form.formaction);*/
	    /*	  PRINTF(("Formaction %s formname %s inputname %s\n",
		  pagewidgetattribs[i].form.formaction,
		  pagewidgetattribs[i].form.formname,
		  pagewidgetattribs[i].form.inputname));*/
	    break;
	  }
	}
#endif /* WWW_CONF_FORMS */
      }
    } else if(ev == ctk_signal_hyperlink_activate) {
      firsty = 0;
      log_back();
      open_link(w->widget.hyperlink.url);
      CTK_WIDGET_FOCUS(&mainwindow, &stopbutton);
      /*    ctk_window_open(&mainwindow);*/
    } else if(ev == ctk_signal_hyperlink_hover) {
      if(CTK_WIDGET_TYPE((struct ctk_widget *)data) ==
	 CTK_WIDGET_HYPERLINK) {
	strncpy(statustexturl, w->widget.hyperlink.url,
		sizeof(statustexturl));
	petsciiconv_topetscii(statustexturl, sizeof(statustexturl));
	show_statustext(statustexturl);
      }
    } else if(ev == resolv_event_found) {
      /* Either found a hostname, or not. */
      if((char *)data != NULL &&
	 resolv_lookup((char *)data) != NULL) {
	open_url();
      } else {
	show_statustext("Host not found.");
      }
    } else if(ev == ctk_signal_window_close ||
	      ev == PROCESS_EVENT_EXIT) {
      quit();
    }
  }
  PROCESS_END();
}
示例#4
0
static void
add_link(struct sfs_fs *sfs, struct cache_inode *current, const char *filename, ino_t real) {
    struct cache_inode *file = alloc_cache_inode(sfs, real, 0, SFS_TYPE_LINK);
    open_link(sfs, file, filename);
    add_entry(sfs, current, file, filename);
}
示例#5
0
void update_links( void )
{
  char_data*            ch;
  link_data*          link;
  text_data*       receive;
  fd_set          read_set;
  fd_set         write_set;
  fd_set          exec_set;
  struct timeval     start;  
  struct timeval   timeout;  

  gettimeofday( &start, NULL );

  timeout.tv_sec  = 1;
  timeout.tv_usec = 0;

  FD_ZERO( &read_set );
  FD_ZERO( &write_set );
  FD_ZERO( &exec_set );

  FD_SET( socket_one, &read_set );
  FD_SET( socket_two, &read_set );

  for( link = link_list; link != NULL; link = link->next ) {
    FD_SET( link->channel, &read_set  );
    FD_SET( link->channel, &write_set );
    FD_SET( link->channel, &exec_set );
    }

  if( (int) select( FD_SETSIZE, &read_set, &write_set, &exec_set,
    &timeout ) < 0 ) 
    panic( "Update links: select" );

  if( FD_ISSET( socket_one, &read_set ) )
    open_link( socket_one );

  if( FD_ISSET( socket_two, &read_set ) )
    open_link( socket_two );

  for( link = link_list; link != NULL; link = link_next ) {
    link_next = link->next;
  
    if( FD_ISSET( link->channel, &exec_set ) ) {
      write( link->player );
      close_socket( link );
      continue;
      }
  
    if( FD_ISSET( link->channel, &read_set ) ) {
      link->idle = 0;
      if( link->player != NULL )
        link->player->timer = current_time;
      if( !read_link( link ) ) {
        write( link->player );
        close_socket( link );
        continue;
        }
      }

    if( link->idle++ > 10000 && link->connected != CON_PLAYING ) {
      send( link, "\n\r\n\r-- CONNECTION TIMEOUT --\n\r" );
      close_socket( link, TRUE );
      }
    }

  pulse_time[ TIME_READ_INPUT ] = stop_clock( start );  
  gettimeofday( &start, NULL );

  for( link = link_list; link != NULL; link = link_next ) {
    link_next = link->next;
    if( link->command = ( ( receive = link->receive ) != NULL ) ) {
      ampersand( receive );
      link->receive  = receive->next;
      link->idle     = 0; 
      if( link->connected == CON_PLAYING ) {
        stop_idling( ch = link->character );
        interpret( link->character, receive->message.text );
        }  
      else
        nanny( link, receive->message.text );
      delete receive;
      }
    }

  pulse_time[ TIME_COMMANDS ] = stop_clock( start );  
  gettimeofday( &start, NULL );

  for( link = link_list; link != NULL; link = link_next ) {
    link_next = link->next;
    if( link->idle%25 == 0 && FD_ISSET( link->channel, &write_set )
      && !process_output( link ) ) {
      write( link->player );
      close_socket( link );
      }
    }  
  
  pulse_time[ TIME_WRITE_OUTPUT ] = stop_clock( start );  

  return;
}
int main ( void ) {
    char* line;
    time_t* led_flash_timer;
    time_t* reboot_timer;
    socket_t* socket = socket0_g;
    int reboot_stage = 0;
    
    /* Turn off all LEDs as a starting point */
    led_clear();

    /* this must be first, because all the other init functions call malloc */
    init_malloc();
        
    /* Initialize current time and some timers */
    init_current_time();
    led_flash_timer = init_timer();
    set_timer(led_flash_timer, 500);    
    reboot_timer = init_timer();
    
        
    /* receive packet buffer */
    rx_packet_g = malloc(sizeof(packet_t));
    
    /* socket init */
    socket0_g = init_socket(0);
    socket1_g = init_socket(1);
        
    /* open ethernet port and wait for connection requests 
       keep trying forever */
    while (!open_link());
        
    /* infinite loop. Everything is timer, interrupt and queue driven from here on down */
    while (1) {
        
        /* Flash a heartbeat LED */
        if (timer_expired(led_flash_timer)) {
            led_flip(0);
            set_timer(led_flash_timer, 500);
            }
            
            
        /* Check for newly downloaded tftp file. Add to all tx buffers */
        /* Has a file been uploaded via tftp ? */
        if (udp_file_g != NULL) {
            /* Notify telnet clients that file has been received */
            if (udp_file_g->ready) {
                udp_file_g->ready = 0;
                telnet_broadcast("Received file %s, %d bytes, linux %d\r\n",
                    udp_file_g->filename, udp_file_g->total_bytes, udp_file_g->linux_boot);
                if (process_file(socket0_g) == 0)
                    /* Disconnect in 1 second */
                    set_timer(reboot_timer, 1000);
                else
                    telnet_broadcast("Not an elf file\r\n");
                }
            }
            
            
        /* reboot timer expired */
        if (timer_expired(reboot_timer)) {
            /* First stage of reboot sequence is to nicely disconnect */
            if (reboot_stage == 0) {
                set_timer(reboot_timer, 1000);
                reboot_stage = 1;
                socket0_g->tcp_disconnect = 1;
                socket1_g->tcp_disconnect = 1;
                } 
            else {
            /* Second stage of reboot sequence is to turn off ethmac and then jump to restart vector */
                close_link();
                reboot();
                }
            }


        /* Poll both sockets in turn for activity */
        if (socket == socket0_g)
            socket = socket1_g;
        else
            socket = socket0_g;
            
            
        /* Check if any tcp packets need to be re-transmitted */
        tcp_retransmit(socket);


        /* Handle exit command */
        if (socket->tcp_disconnect && socket->tcp_connection_state == TCP_OPEN) {
            tcp_disconnect(socket);
            }
            

        /* Reset connection */
        if (socket->tcp_reset) {
            socket->tcp_connection_state = TCP_CLOSED;
            socket->telnet_connection_state = TELNET_CLOSED;
            socket->telnet_options_sent = 0;
            tcp_reply(socket, NULL, 0);
            socket->tcp_reset = 0;
            }
                     
        
        /* Send telnet options */             
        if (socket->tcp_connection_state == TCP_OPEN && !socket->telnet_options_sent){
            telnet_options(socket);
            socket->telnet_options_sent = 1;
            }
            
        /* telnet connection open 
           Communicate with client */
        else if (socket->telnet_connection_state == TELNET_OPEN) {
            /* Send telnet greeting */
            if (!socket->telnet_sent_opening_message){
                put_line (socket->telnet_txbuf, "Amber Processor Boot Loader\r\n> ");
                socket->telnet_sent_opening_message = 1;
                }
                
            /* Parse telnet rx buffer */
            if (get_line(socket->telnet_rxbuf, &line)) 
                parse_command (socket, line);

            /* Transmit text from telnet tx buffer */
            telnet_tx(socket, socket->telnet_txbuf);
        }
    }
}