45 #define MAX_USERNAMELEN 16
46 #define MAX_PASSWORDLEN 16
47 #define MAX_HOSTNAMELEN 32
50 #define FILES_WIDTH FTP_CONF_WIDTH
51 #define MAX_FILENAMELEN FTP_CONF_WIDTH
53 #define FILES_WIDTH 16
54 #define MAX_FILENAMELEN 16
57 #ifdef FTP_CONF_HEIGHT
58 #define FILES_HEIGHT FTP_CONF_HEIGHT
60 #define FILES_HEIGHT 18
63 PROCESS(ftp_process,
"FTP client");
65 AUTOSTART_PROCESSES(&ftp_process);
67 static void *connection;
73 static struct ctk_label localtextlabel =
74 {
CTK_LABEL(1, 0, FILES_WIDTH, 1,
"Local files")};
75 static struct ctk_label remotetextlabel =
77 FILES_WIDTH, 1,
"Remote files")};
79 static char leftptr[FILES_HEIGHT];
80 static struct ctk_label leftptrlabel =
81 {
CTK_LABEL(0, 1, 1, FILES_HEIGHT, leftptr)};
82 static char midptr[FILES_HEIGHT];
83 static struct ctk_label midptrlabel =
84 {
CTK_LABEL(1 + FILES_WIDTH, 1, 1, FILES_HEIGHT, midptr)};
85 static char rightptr[FILES_HEIGHT];
86 static struct ctk_label rightptrlabel =
87 {
CTK_LABEL(1 + FILES_WIDTH + 1 + FILES_WIDTH, 1,
88 1, FILES_HEIGHT, rightptr)};
90 static char localfiles[FILES_WIDTH * FILES_HEIGHT];
91 static struct ctk_label localfileslabel =
93 FILES_WIDTH, FILES_HEIGHT, localfiles)};
94 static char remotefiles[FILES_WIDTH * FILES_HEIGHT];
95 static struct ctk_label remotefileslabel =
97 FILES_WIDTH, FILES_HEIGHT, remotefiles)};
99 static struct ctk_button reloadbutton =
100 {
CTK_BUTTON(0, 1 + FILES_HEIGHT, 6,
"Reload")};
103 static struct ctk_button connectionbutton =
104 {
CTK_BUTTON(8, 1 + FILES_HEIGHT, 13,
"Connection...")};
105 static struct ctk_button quitbutton =
106 {
CTK_BUTTON(1 + FILES_WIDTH + 1 + FILES_WIDTH - 5,
107 1 + FILES_HEIGHT, 4,
"Quit")};
110 static struct ctk_label usagetextlabel =
111 {
CTK_LABEL(9, 1 + FILES_HEIGHT, 24, 1,
"<up><down><space><enter>")};
113 static struct ctk_label usagetextlabel =
115 39, 1,
"Keys: <up> <down> <space> <enter> <'u'>")};
117 static struct ctk_button quitbutton =
118 {
CTK_BUTTON(1 + FILES_WIDTH + 1 + FILES_WIDTH - 4,
119 1 + FILES_HEIGHT, 4,
"Quit")};
122 static char statustext[3 + FILES_WIDTH * 2 + 1];
123 static struct ctk_label statuslabel =
124 {
CTK_LABEL(0, FILES_HEIGHT + 2, 3 + FILES_WIDTH * 2, 1, statustext)};
129 static char remotefilename[MAX_FILENAMELEN + 1];
130 static char localfilename[MAX_FILENAMELEN + 1];
133 static struct ctk_label downloadlabel =
134 {
CTK_LABEL(6, 1, 13, 1,
"Download file")};
135 static struct ctk_label uploadlabel =
137 static struct ctk_label localfilenametextlabel =
138 {
CTK_LABEL(2, 3, 15, 1,
"Local filename")};
139 static struct ctk_label localfilenamelabel =
141 static struct ctk_textentry localfilenameentry =
142 {
CTK_TEXTENTRY(2, 5, 16, 1, localfilename,
sizeof(localfilename) - 1)};
143 static struct ctk_label remotefilenametextlabel =
144 {
CTK_LABEL(2, 7, 15, 1,
"Remote filename")};
145 static struct ctk_label remotefilenamelabel =
146 {
CTK_LABEL(3, 9, 16, 1, remotefilename)};
147 static struct ctk_textentry remotefilenameentry =
148 {
CTK_TEXTENTRY(2, 9, 16, 1, remotefilename,
sizeof(remotefilename) - 1)};
149 static struct ctk_button downloadbutton =
153 static struct ctk_button cancelbutton =
157 static char hostname[MAX_HOSTNAMELEN + 1];
158 static char username[MAX_USERNAMELEN + 1];
159 static char password[MAX_PASSWORDLEN + 1];
162 static struct ctk_label serverlabel =
164 static struct ctk_textentry serverentry =
167 static struct ctk_button anonymousbutton =
169 static struct ctk_label userlabel =
171 static struct ctk_textentry userentry =
172 {
CTK_TEXTENTRY(0, 5, 16, 1, username,
sizeof(username) - 1)};
173 static struct ctk_label passwordlabel =
175 static struct ctk_textentry passwordentry =
176 {
CTK_TEXTENTRY(0, 8, 16, 1, password,
sizeof(password) - 1)};
178 static struct ctk_button connectbutton =
181 static struct ctk_button closeconnectionbutton =
184 static struct ctk_button closebutton =
188 static struct cfs_dir dir;
189 static struct cfs_dirent dirent;
191 static unsigned char localfileptr = 0;
192 static unsigned char remotefileptr = 0;
193 static unsigned char ptractive;
194 static unsigned char ptrstate;
195 #define PTRSTATE_LOCALFILES 0
196 #define PTRSTATE_REMOTEFILES 1
197 static unsigned char localptr, remoteptr;
203 make_uploaddialog(
void)
206 ctk_dialog_new(&dialog, 24, 13);
224 make_downloaddialog(
void)
227 ctk_dialog_new(&dialog, 24, 13);
244 show_statustext(
char *text1,
char *text2)
248 len = (int)strlen(text1);
249 if(len <
sizeof(statustext)) {
250 strncpy(statustext, text1,
sizeof(statustext));
251 strncpy(statustext + len, text2,
sizeof(statustext) - len);
278 rightptr[remoteptr] =
' ';
279 midptr[remoteptr] =
' ';
280 leftptr[localptr] =
' ';
281 midptr[localptr] =
' ';
287 if(ptrstate == PTRSTATE_LOCALFILES) {
288 rightptr[remoteptr] =
' ';
289 midptr[remoteptr] =
' ';
290 leftptr[localptr] =
'>';
291 midptr[localptr] =
'<';
293 leftptr[localptr] =
' ';
294 midptr[localptr] =
' ';
295 rightptr[remoteptr] =
'<';
296 midptr[remoteptr] =
'>';
307 memset(localfiles, 0,
sizeof(localfiles));
314 start_loadremote(
void)
316 memset(remotefiles, 0,
sizeof(remotefiles));
321 ftpc_list(connection);
325 make_connectionwindow(
void)
328 ctk_dialog_new(&connectionwindow, 25, 11);
343 if(connection ==
NULL) {
359 uip_ipaddr_t *ipaddrptr;
365 memset(statustext, 0,
sizeof(statustext));
366 memset(remotefiles, 0,
sizeof(remotefiles));
367 memset(localfiles, 0,
sizeof(localfiles));
368 memset(leftptr, 0,
sizeof(leftptr));
369 memset(midptr, 0,
sizeof(midptr));
370 memset(rightptr, 0,
sizeof(rightptr));
372 ptrstate = PTRSTATE_REMOTEFILES;
373 localptr = remoteptr = 0;
378 3 + FILES_WIDTH * 2, 3 + FILES_HEIGHT,
410 make_connectionwindow();
418 if(ev == PROCESS_EVENT_CONTINUE) {
420 localfileptr < FILES_HEIGHT) {
421 strncpy(&localfiles[localfileptr * FILES_WIDTH],
422 dirent.name, FILES_WIDTH);
429 }
else if(ev == PROCESS_EVENT_EXIT) {
436 if((
char *)data !=
NULL &&
438 connection = ftpc_connect(ipaddrptr,
UIP_HTONS(21));
439 show_statustext(
"Connecting to ", hostname);
441 show_statustext(
"Host not found: ", hostname);
445 #
if CTK_CONF_WINDOWCLOSE
448 data == (process_data_t)&window) {
451 if((
struct ctk_button *)data == &quitbutton) {
453 }
else if((
struct ctk_button *)data == &cancelbutton) {
461 }
else if((
struct ctk_button *)data == &downloadbutton) {
472 show_statustext(
"Downloading ", remotefilename);
473 ftpc_get(connection, remotefilename);
475 show_statustext(
"Could not create ", localfilename);
477 }
else if((
struct ctk_button *)data == &reloadbutton) {
480 }
else if((
struct ctk_button *)data == &connectionbutton) {
482 make_connectionwindow();
483 ctk_dialog_open(&connectionwindow);
484 }
else if((
struct ctk_button *)data == &closebutton) {
488 }
else if((
struct ctk_button *)data == &anonymousbutton) {
489 strcpy(username,
"anonymous");
490 strcpy(password,
"contiki@ftp");
494 }
else if((
struct ctk_button *)data == &closeconnectionbutton) {
497 ftpc_close(connection);
499 }
else if((
struct ctk_button *)data == &connectbutton) {
512 resolv_query(hostname);
513 show_statustext(
"Resolving host ", hostname);
516 connection = ftpc_connect(ipaddrptr,
UIP_HTONS(21));
517 show_statustext(
"Connecting to ", hostname);
519 connection = ftpc_connect(&ipaddr,
UIP_HTONS(21));
520 show_statustext(
"Connecting to ", hostname);
524 connection = ftpc_connect(&ipaddr,
UIP_HTONS(21));
525 show_statustext(
"Connecting to ", hostname);
533 if(ptrstate == PTRSTATE_LOCALFILES) {
534 ptrstate = PTRSTATE_REMOTEFILES;
536 ptrstate = PTRSTATE_LOCALFILES;
540 if(ptrstate == PTRSTATE_LOCALFILES) {
551 if(ptrstate == PTRSTATE_LOCALFILES) {
552 if(localptr < FILES_HEIGHT - 1) {
556 if(remoteptr < FILES_HEIGHT - 1) {
561 if(ptrstate == PTRSTATE_LOCALFILES) {
562 strncpy(localfilename,
563 &localfiles[localptr * FILES_WIDTH], FILES_WIDTH);
564 strncpy(remotefilename,
565 &localfiles[localptr * FILES_WIDTH], FILES_WIDTH);
569 ctk_dialog_open(&dialog);
575 strncpy(localfilename,
576 &remotefiles[remoteptr * FILES_WIDTH], FILES_WIDTH);
577 strncpy(remotefilename,
578 &remotefiles[remoteptr * FILES_WIDTH], FILES_WIDTH);
579 ftpc_cwd(connection, remotefilename);
584 ftpc_cdup(connection);
599 strcpy(statustext,
"Connection closed");
607 strcpy(statustext,
"Connection reset");
615 strcpy(statustext,
"Connection timed out");
633 ftpc_list_file(
char *filename)
635 if(remotefileptr < FILES_HEIGHT && filename !=
NULL) {
636 strncpy(&remotefiles[remotefileptr * FILES_WIDTH], filename, FILES_WIDTH);
641 if(filename ==
NULL) {
642 strcpy(statustext,
"Connected");
648 ftpc_cwd_done(
unsigned short status)
650 if(status == FTPC_COMPLETED ||
655 make_downloaddialog();
657 ctk_dialog_open(&dialog);
666 ftpc_connected(
void *connection)
668 strcpy(statustext,
"Loading remote directory");
675 ftpc_data(uint8_t *data, uint16_t len)
678 show_statustext(
"Download complete",
"");
682 cfs_write(fd, data, len);
#define CTK_WIDGET_ADD(win, widg)
Add a widget to a window.
process_event_t ctk_signal_window_close
Emitted when a window is closed.
char ctk_arch_key_t
The keyboard character type of the system.
Hostname is fresh and usable.
void ctk_window_open(CC_REGISTER_ARG struct ctk_window *w)
Open a window, or bring window to front if already open.
int cfs_open(const char *name, int flags)
Open a file.
#define CTK_WIDGET_FOCUS(win, widg)
Set focus to a widget.
void ctk_window_close(struct ctk_window *w)
Close a window if it is open.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define CFS_WRITE
Specify that cfs_open() should open a file for writing.
#define CTK_TEXTENTRY(x, y, w, h, text, len)
Instantiating macro for the ctk_textentry widget.
#define NULL
The null pointer.
#define UIP_HTONS(n)
Convert 16-bit quantity from host byte order to network byte order.
int cfs_readdir(struct cfs_dir *dir, struct cfs_dirent *record)
Read a directory entry.
#define uiplib_ipaddrconv
Convert a textual representation of an IP address to a numerical representation.
int process_post(struct process *p, process_event_t ev, process_data_t data)
Post an asynchronous event.
#define CTK_LABEL(x, y, w, h, text)
Instantiating macro for the ctk_label widget.
process_event_t ctk_signal_keypress
Emitted for every key being pressed.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
void ctk_window_new(struct ctk_window *window, unsigned char w, unsigned char h, char *title)
Create a new window.
CCIF process_event_t resolv_event_found
Event that is broadcasted when a DNS name has been resolved.
#define LOADER_UNLOAD()
Unload a program from memory.
void cfs_closedir(struct cfs_dir *dir)
Close a directory opened with cfs_opendir().
#define PROCESS_WAIT_EVENT()
Wait for an event to be posted to the process.
#define PROCESS(name, strname)
Declare a process.
process_event_t ctk_signal_widget_activate
Emitted when a widget is activated (pressed).
process_event_t tcpip_event
The uIP event.
int cfs_opendir(struct cfs_dir *dir, const char *name)
Open a directory for reading directory entries.
#define CTK_BUTTON(x, y, w, text)
Instantiating macro for the ctk_button widget.
Representation of a CTK window.
#define CTK_WIDGET_REDRAW(widg)
Add a widget to the redraw queue.
uIP DNS resolver code header file.
void process_exit(struct process *p)
Cause a process to exit.
void cfs_close(int fd)
Close an open file.