Example #1
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_output(struct httpd_state *s))
{
  PT_BEGIN(&s->outputpt);

  petsciiconv_topetscii(s->filename, sizeof(s->filename));
  s->fd = cfs_open(s->filename, CFS_READ);
  petsciiconv_toascii(s->filename, sizeof(s->filename));
  if(s->fd < 0) {
    strcpy(s->filename, "notfound.html");
    s->fd = cfs_open(s->filename, CFS_READ);
    petsciiconv_toascii(s->filename, sizeof(s->filename));
    if(s->fd < 0) {
      PT_WAIT_THREAD(&s->outputpt,
                     send_headers(s, http_header_404));
      PT_WAIT_THREAD(&s->outputpt,
                     send_string(s, "not found"));
      uip_close();
      webserver_log_file(&uip_conn->ripaddr, "404 (no notfound.html)");
      PT_EXIT(&s->outputpt);
    }
    PT_WAIT_THREAD(&s->outputpt,
		   send_headers(s, http_header_404));
    webserver_log_file(&uip_conn->ripaddr, "404 - notfound.html");
  } else {
    PT_WAIT_THREAD(&s->outputpt,
		   send_headers(s, http_header_200));
  }
  PT_WAIT_THREAD(&s->outputpt, send_file(s));
  cfs_close(s->fd);
  s->fd = -1;
  PSOCK_CLOSE(&s->sout);
  PT_END(&s->outputpt);
}
Example #2
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(telnetd_process, ev, data)
{
  PROCESS_BEGIN();
  
  shell_init();

#if TELNETD_CONF_GUI
  telnetd_gui_init();
#endif /* TELNETD_CONF_GUI */

  petsciiconv_toascii(telnetd_reject_text, strlen(telnetd_reject_text));

  tcp_listen(UIP_HTONS(23));

  while(1) {
    PROCESS_WAIT_EVENT();
    if(ev == tcpip_event) {
      telnetd_appcall(data);
    } else if(ev == PROCESS_EVENT_EXIT) {
      telnetd_quit();
    } else {
#if TELNETD_CONF_GUI
      telnetd_gui_eventhandler(ev, data);
#endif /* TELNETD_CONF_GUI */
    }
  }
  
  PROCESS_END();
}
Example #3
0
/*-----------------------------------------------------------------------------------*/
PROCESS_THREAD(wget_process, ev, data)
{
  static char name[32];
  static unsigned char i;

  PROCESS_BEGIN();

  /* Allow other processes to initialize properly. */
  for(i = 0; i < 10; ++i) {
    PROCESS_PAUSE();
  }

  fputs("Get url:", stdout);
  if(contiki_argc > 1) {
    strcpy(url, contiki_argv[1]);
    puts(url);
  } else {
    gets(url);
  }
  fputs("Save as:", stdout);
  if(contiki_argc > 2) {
    strcpy(name, contiki_argv[2]);
    puts(name);
  } else {
    gets(name);
  }
  file = cfs_open(name, CFS_WRITE);
  if(file == -1) {
    printf("Open error with '%s'\n", name);
    app_quit();
  } else {
    petsciiconv_toascii(url, sizeof(url));
    start_get();
  }

  while(1) {

    PROCESS_WAIT_EVENT();
  
    if(ev == tcpip_event) {
      webclient_appcall(data);
#if UIP_UDP
    } else if(ev == resolv_event_found) {
      /* Either found a hostname, or not. */
      if((char *)data != NULL &&
        resolv_lookup((char *)data, NULL) == RESOLV_STATUS_CACHED) {
        start_get();
      } else {
        puts("Host not found");
        app_quit();
      }
#endif /* UIP_UDP */
    }
  }

  PROCESS_END();
}
Example #4
0
/*-----------------------------------------------------------------------------------*/
PROCESS_THREAD(about_process, ev, data)
{
    unsigned char width;

    PROCESS_BEGIN();

    width = ctk_desktop_width(NULL);

    strcpy(abouturl_ascii, abouturl_petscii);
    petsciiconv_toascii(abouturl_ascii, sizeof(abouturl_ascii));

    if(width > 34) {
        ctk_dialog_new(&aboutdialog, 32, 9);
    } else {
        ctk_dialog_new(&aboutdialog, width - 2, 9);
    }
    CTK_WIDGET_ADD(&aboutdialog, &aboutlabel1);
    CTK_WIDGET_ADD(&aboutdialog, &aboutlabel2);
    CTK_WIDGET_ADD(&aboutdialog, &aboutlabel3);
    CTK_WIDGET_ADD(&aboutdialog, &aboutlabel4);
    if(width > 34) {
        CTK_WIDGET_ADD(&aboutdialog, &abouturl);
        CTK_WIDGET_SET_FLAG(&abouturl, CTK_WIDGET_FLAG_MONOSPACE);
    } else {
        CTK_WIDGET_SET_XPOS(&aboutlabel1, 0);
        CTK_WIDGET_SET_XPOS(&aboutlabel2, 0);
        CTK_WIDGET_SET_XPOS(&aboutlabel3, 0);
        CTK_WIDGET_SET_XPOS(&aboutlabel4, 0);

        CTK_WIDGET_SET_XPOS(&aboutclose, 0);
    }
    CTK_WIDGET_ADD(&aboutdialog, &aboutclose);
    CTK_WIDGET_FOCUS(&aboutdialog, &aboutclose);

    ctk_dialog_open(&aboutdialog);

    while(1) {
        PROCESS_WAIT_EVENT();
        if(ev == PROCESS_EVENT_EXIT) {
            about_quit();
            PROCESS_EXIT();
        } else if(ev == ctk_signal_button_activate) {
            if(data == (process_data_t)&aboutclose) {
                about_quit();
                PROCESS_EXIT();
            }
        } else if(ev == ctk_signal_hyperlink_activate) {
            if((struct ctk_widget *)data == (struct ctk_widget *)&abouturl) {
                about_quit();
                PROCESS_EXIT();
            }
        }
    }

    PROCESS_END();
}
Example #5
0
/*---------------------------------------------------------------------------*/
static int
buf_append(struct telnetd_buf *buf, const char *data, int len)
{
  int copylen;

  PRINTF("buf_append len %d (%d) '%.*s'\n", len, buf->ptr, len, data);
  copylen = MIN(len, buf->size - buf->ptr);
  memcpy(&buf->bufmem[buf->ptr], data, copylen);
  petsciiconv_toascii(&buf->bufmem[buf->ptr], copylen);
  buf->ptr += copylen;

  return copylen;
}
Example #6
0
/*---------------------------------------------------------------------------*/
static unsigned short
make_processes(void *p)
{
    char name[40];

    strncpy(name, ((struct process *)p)->name, 40);
    petsciiconv_toascii(name, 40);

    return snprintf((char *)uip_appdata, uip_mss(),
                    "<tr align=\"center\"><td>%p</td><td>%s</td><td>%p</td><td>%s</td></tr>\r\n",
                    p, name,
                    *((char **)&(((struct process *)p)->thread)),
                    states[9 + ((struct process *)p)->state]);
}
Example #7
0
/*---------------------------------------------------------------------------*/
static unsigned short
make_processes(void *p)
{
  static const char httpd_cgi_proc[] HTTPD_STRING_ATTR = "<tr align=\"center\"><td>%p</td><td>%s</td><td>%p</td><td>%s</td></tr>\r\n";
  char name[40],tstate[20];

  strncpy(name, PROCESS_NAME_STRING((struct process *)p), 40);
  petsciiconv_toascii(name, 40);
  httpd_strcpy(tstate,states[9 + ((struct process *)p)->state]);
  return httpd_snprintf((char *)uip_appdata, uip_mss(), httpd_cgi_proc, p, name,
//  *((char **) &(((struct process *)p)->thread)),
    * (char **)(&(((struct process *)p)->thread)), //minimal net
    tstate);
}
Example #8
0
/*static DISPATCHER_SIGHANDLER(about_sighandler, s, data)*/
EK_EVENTHANDLER(about_eventhandler, ev, data)
{
  unsigned char width;
  EK_EVENTHANDLER_ARGS(ev, data);

  if(ev == EK_EVENT_INIT) {
    width = ctk_desktop_width(NULL);
    
    strcpy(abouturl_ascii, abouturl_petscii);
    petsciiconv_toascii(abouturl_ascii, sizeof(abouturl_ascii));

    if(width > 34) {
      ctk_dialog_new(&aboutdialog, 32, 9);
    } else {
      ctk_dialog_new(&aboutdialog, width - 2, 9);
    }
    CTK_WIDGET_ADD(&aboutdialog, &aboutlabel1);
    CTK_WIDGET_ADD(&aboutdialog, &aboutlabel2);
    CTK_WIDGET_ADD(&aboutdialog, &aboutlabel3);
    CTK_WIDGET_ADD(&aboutdialog, &aboutlabel4);
    if(width > 34) {
      CTK_WIDGET_ADD(&aboutdialog, &abouturl);
      CTK_WIDGET_SET_FLAG(&abouturl, CTK_WIDGET_FLAG_MONOSPACE);
    } else {
      CTK_WIDGET_SET_XPOS(&aboutlabel1, 0);
      CTK_WIDGET_SET_XPOS(&aboutlabel2, 0);
      CTK_WIDGET_SET_XPOS(&aboutlabel3, 0);
      CTK_WIDGET_SET_XPOS(&aboutlabel4, 0);
      
      CTK_WIDGET_SET_XPOS(&aboutclose, 0);
    }
    CTK_WIDGET_ADD(&aboutdialog, &aboutclose);
    CTK_WIDGET_FOCUS(&aboutdialog, &aboutclose);
    
    /*    dispatcher_listen(ctk_signal_button_activate);
	  dispatcher_listen(ctk_signal_hyperlink_activate);*/
    ctk_dialog_open(&aboutdialog);
    
  } else if(ev == EK_EVENT_REQUEST_EXIT) {
    about_quit();
  } else if(ev == ctk_signal_button_activate) {
    if(data == (ek_data_t)&aboutclose) {
      about_quit();
    }
  } else if(ev == ctk_signal_hyperlink_activate) {
    if((struct ctk_widget *)data == (struct ctk_widget *)&abouturl) {
      about_quit();
    }
  }
}
Example #9
0
/*---------------------------------------------------------------------------*/
static void
parse_line(void)
{
  int i;
  for(i = 0; i < strlen(line); ++i) {
    line[i] &= 0x7f;
  }
  
  
  if(line[0] == '/') {
    if(strncmp(&line[1], "join", 4) == 0) {
      ircc_join(&s, &line[6]);
      ircc_text_output(&s, "Join", &line[6]);
    } else if(strncmp(&line[1], "list", 4) == 0) {
      ircc_list(&s);
      ircc_text_output(&s, "Channel list", "");
    } else if(strncmp(&line[1], "part", 4) == 0) {
      ircc_part(&s);
      ircc_text_output(&s, "Leaving channel", "");
    } else if(strncmp(&line[1], "quit", 4) == 0) {
      ircc_quit(&s);
    } else if(strncmp(&line[1], "me", 2) == 0) {
      petsciiconv_toascii(&line[4], strlen(&line[4]));
      ircc_actionmsg(&s, &line[4]);
      ircc_text_output(&s, "*", &line[4]);
    } else {
      ircc_text_output(&s, &line[1], "Not implemented");
      ircc_sent(&s);
    }
  } else {
    petsciiconv_toascii(line, sizeof(line) - 1);
    ircc_msg(&s, &line[0]);
    ircc_text_output(&s, nick, line);
  }
	   
}
Example #10
0
/*---------------------------------------------------------------------------*/
static
PT_THREAD(handle_input(struct httpd_state *s))
{
  PSOCK_BEGIN(&s->sin);

  PSOCK_READTO(&s->sin, ISO_space);
  
  if(strncmp(s->inputbuf, http_get, 4) != 0) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }
  PSOCK_READTO(&s->sin, ISO_space);

  if(s->inputbuf[0] != ISO_slash) {
    PSOCK_CLOSE_EXIT(&s->sin);
  }

#if URLCONV
  s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
  urlconv_tofilename(s->filename, s->inputbuf, sizeof(s->filename));
#else /* URLCONV */
  if(s->inputbuf[1] == ISO_space) {
    strncpy(s->filename, http_index_htm, sizeof(s->filename));
  } else {
    s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0;
    strncpy(s->filename, s->inputbuf, sizeof(s->filename));
  }
#endif /* URLCONV */

  petsciiconv_topetscii(s->filename, sizeof(s->filename));
  webserver_log_file(&uip_conn->ripaddr, s->filename);
  petsciiconv_toascii(s->filename, sizeof(s->filename));
  s->state = STATE_OUTPUT;

  while(1) {
    PSOCK_READTO(&s->sin, ISO_nl);

    if(strncmp(s->inputbuf, http_referer, 8) == 0) {
      s->inputbuf[PSOCK_DATALEN(&s->sin) - 2] = 0;
      petsciiconv_topetscii(s->inputbuf, PSOCK_DATALEN(&s->sin) - 2);
      webserver_log(s->inputbuf);
    }
  }
  
  PSOCK_END(&s->sin);
}
Example #11
0
/*-----------------------------------------------------------------------------------*/
static u8_t
processes(void)
{
  u8_t i;
  register struct dispatcher_proc *p;
  char name[40];

  p = DISPATCHER_PROCS();
  for(i = 0; i < hs->count; ++i) {
    if(p != NULL) {
      p = p->next;
    }
  }

  if(uip_acked()) {
    /* If the previously sent data has been acknowledged, we move
       forward one connection. */
    ++hs->count;
    if(p != NULL) {
      p = p->next;
    }
    if(p == NULL) {
      /* If all processes have been printed out, we are done and
	 return 1. */
      return 1;
    }
  }

  strncpy(name, p->name, 40);
  petsciiconv_toascii(name, 40);
  uip_send(uip_appdata,
	   sprintf((char *)uip_appdata,
		   "<tr align=\"center\"><td>%3d</td><td>%s</td><td>0x%04x</td><td>0x%04x</td><td>0x%04x</td></tr>\r\n",
		   p->id, name,
		   p->idle, p->signalhandler, p->uiphandler));
  return 0;
}
Example #12
0
/*-----------------------------------------------------------------------------------*/
PROCESS_THREAD(simpletelnet_process, ev, data)
{
  struct ctk_widget *w;
  int sendlen;

  PROCESS_BEGIN();
  
  ctk_window_new(&telnetwindow, TELNET_WINDOW_WIDTH, TELNET_WINDOW_HEIGHT, "Simple telnet");
  
  strcpy(telnetport, "23");
  
  CTK_WIDGET_ADD(&telnetwindow, &telnethostlabel);
  CTK_WIDGET_ADD(&telnetwindow, &telnetportlabel);
  CTK_WIDGET_ADD(&telnetwindow, &telnethosttextentry);
  CTK_WIDGET_ADD(&telnetwindow, &telnetporttextentry);
  CTK_WIDGET_ADD(&telnetwindow, &telnetconnectbutton);
  CTK_WIDGET_ADD(&telnetwindow, &telnetdisconnectbutton);
  CTK_WIDGET_ADD(&telnetwindow, &telnetlinetextentry);
  CTK_WIDGET_ADD(&telnetwindow, &telnetsendbutton);
  
  CTK_WIDGET_ADD(&telnetwindow, &telnetsep1);
  CTK_WIDGET_ADD(&telnetwindow, &telnettextarea);
  
  CTK_WIDGET_ADD(&telnetwindow, &telnetsep2);
  CTK_WIDGET_ADD(&telnetwindow, &telnetstatus);
  
  CTK_WIDGET_FOCUS(&telnetwindow, &telnethosttextentry);
  
  ctk_window_open(&telnetwindow);

  while(1) {
    PROCESS_WAIT_EVENT();
    if(ev == ctk_signal_button_activate) {
      
      w = (struct ctk_widget *)data;
      if(w == (struct ctk_widget *)&telnetsendbutton) {
	strcpy(sendline, telnetline);
	sendlen = (int)strlen(sendline);
	petsciiconv_toascii(sendline, sendlen);
	sendline[sendlen++] = ISO_CR;
	sendline[sendlen++] = ISO_NL;
	if(telnet_send(&ts_appstate, sendline, sendlen)) {
	  /* Could not send. */
	  ctk_label_set_text(&telnetstatus, "Could not send");
	  ctk_window_redraw(&telnetwindow);
	  /*      } else {*/
	  /* Could send */
	}
      } else if(w == (struct ctk_widget *)&telnetdisconnectbutton) {
	telnet_close(&ts_appstate);
	show("Closing...");
      } else if(w == (struct ctk_widget *)&telnetconnectbutton) {
	connect();
	ctk_window_redraw(&telnetwindow);
      }
#if UIP_UDP
    } else if(ev == resolv_event_found) {
      if(strcmp(data, telnethost) == 0) {
	if(resolv_lookup(telnethost) != NULL) {
	  connect();
	} else {
	  show("Host not found");
	}
      }
#endif /* UIP_UDP */
    } else if(
#if CTK_CONF_WINDOWCLOSE
	      ev == ctk_signal_window_close ||
#endif /* CTK_CONF_WINDOWCLOSE */
	      ev == PROCESS_EVENT_EXIT) {
      process_exit(&simpletelnet_process);
      ctk_window_close(&telnetwindow);
      LOADER_UNLOAD();
    } else if(ev == tcpip_event) {
      telnet_app(data);
    }
  }
  PROCESS_END();
}
Example #13
0
/* 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;
#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 || defined(WWW_CONF_WGET_EXEC)
#if CTK_CONF_WINDOWS
    /* 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 /* CTK_CONF_WINDOWS */
#endif /* WWW_CONF_WITH_WGET || WWW_CONF_WGET_EXEC */

    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 *)&gobutton ||
                    w == (struct ctk_widget *)&urlentry) {
                start_loading();
                firsty = 0;
#if WWW_CONF_HISTORY_SIZE > 0
                log_back();
#endif /* WWW_CONF_HISTORY_SIZE > 0 */
                memcpy(url, editurl, WWW_CONF_MAX_URLLEN);
                petsciiconv_toascii(url, WWW_CONF_MAX_URLLEN);
                open_url();
                CTK_WIDGET_FOCUS(&mainwindow, &gobutton);
#if WWW_CONF_HISTORY_SIZE > 0
            } else 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);
#endif /* WWW_CONF_HISTORY_SIZE > 0 */
            } 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 *)&stopbutton) {
                loading = 0;
                webclient_close();
#if WWW_CONF_WITH_WGET || defined(WWW_CONF_WGET_EXEC)
            } else if(w == (struct ctk_widget *)&wgetnobutton) {
#if CTK_CONF_WINDOWS
                ctk_dialog_close();
#else /* CTK_CONF_WINDOWS */
                clear_page();
#endif /* CTK_CONF_WINDOWS */
            } else if(w == (struct ctk_widget *)&wgetyesbutton) {
#if CTK_CONF_WINDOWS
                ctk_dialog_close();
#else /* CTK_CONF_WINDOWS */
                clear_page();
#endif /* CTK_CONF_WINDOWS */
#if WWW_CONF_WITH_WGET
                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);
#else /* WWW_CONF_WITH_WGET */
                petsciiconv_topetscii(url, sizeof(url));
                /* Clear screen */
                ctk_restore();
                WWW_CONF_WGET_EXEC(url);
                redraw_window();
                show_statustext("Cannot exec wget");
#endif /* WWW_CONF_WITH_WGET */
#endif /* WWW_CONF_WITH_WGET || WWW_CONF_WGET_EXEC */
#if WWW_CONF_FORMS
            } else {
                /* Assume form widget. */
                struct inputattrib *input = (struct inputattrib *)
                                            (((char *)w) - offsetof(struct inputattrib, widget));
                formsubmit(input->formptr);
#endif /* WWW_CONF_FORMS */
            }
        } else if(ev == ctk_signal_hyperlink_activate) {
            firsty = 0;
#if WWW_CONF_HISTORY_SIZE > 0
            log_back();
#endif /* WWW_CONF_HISTORY_SIZE > 0 */
            set_link(w->widget.hyperlink.url);
            show_url();
            open_url();
            start_loading();
            CTK_WIDGET_FOCUS(&mainwindow, &stopbutton);
        } 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);
            }
#if UIP_UDP
        } else if(ev == resolv_event_found) {
            /* Either found a hostname, or not. */
            if((char *)data != NULL &&
                    resolv_lookup((char *)data, NULL) == RESOLV_STATUS_CACHED) {
                open_url();
            } else {
                show_statustext("Host not found");
            }
#endif /* UIP_UDP */
        } else if(ev == ctk_signal_window_close ||
                  ev == PROCESS_EVENT_EXIT) {
            quit();
        }
    }
Example #14
0
File: www.c Project: 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);
}
Example #15
0
File: www.c Project: 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();
}