From 7ef12f67bff6fb48e000dffea556d770ea74f006 Mon Sep 17 00:00:00 2001 From: goisetsi Date: Sun, 30 Jul 2017 00:24:46 +0200 Subject: [PATCH 1/8] cd working --- libftp/src/environ.c | 4 +--- libftp/src/path.c | 18 ++++++++++++++++++ src/server/cd.c | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/libftp/src/environ.c b/libftp/src/environ.c index b7ac384..763a440 100644 --- a/libftp/src/environ.c +++ b/libftp/src/environ.c @@ -39,9 +39,7 @@ char *search_environ(char *curr, char *target) */ if (ft_strequ(name, target)) - { - - + { /* ** create new string with value prefixed by the '=' delimete */ diff --git a/libftp/src/path.c b/libftp/src/path.c index a0a38ae..63ec513 100644 --- a/libftp/src/path.c +++ b/libftp/src/path.c @@ -46,6 +46,15 @@ char *ft_path(char *name) ft_strdel(&home); return (joined); } + else if (!(ft_strequ(name,"./..") == 1) && !(ft_strnequ(name,"./",1) == 1)) + { + home = ft_get_environ("PWD"); + joined = ft_strjoin(home,"/"); + ft_strdel(&home); + home = ft_strjoin(joined,name); + ft_strdel(&joined); + return (home); + } } } else @@ -97,6 +106,15 @@ char *ft_lpath(char *name) ft_strdel(&home); return (joined); } + else if (!(ft_strequ(name,"./..") == 1) && !(ft_strnequ(name,"./",1) == 1)) + { + home = ft_get_environ("PWD"); + joined = ft_strjoin(home,"/"); + ft_strdel(&home); + home = ft_strjoin(joined,name); + ft_strdel(&joined); + return (home); + } } } else diff --git a/src/server/cd.c b/src/server/cd.c index da7a25b..230daea 100644 --- a/src/server/cd.c +++ b/src/server/cd.c @@ -27,7 +27,7 @@ void ft_cd(int fd, char **argv) /* ** check for Exiting Servers Home directory */ - if (!(ft_strequ(pwd, home) == 1 && ft_strequ(path, "./..") == 1)) + if (!(ft_strnequ(pwd, home,ft_strlen(pwd) - 2) == 1 && ft_strequ(path, "./..") == 1)) { /* ** removing spaces/newlines From b58441a2467de5f98bb26b7a61506d0fe063017c Mon Sep 17 00:00:00 2001 From: goisetsi Date: Sun, 30 Jul 2017 01:05:31 +0200 Subject: [PATCH 2/8] lcd --- libftp/src/path.c | 4 ++-- src/client/main.c | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libftp/src/path.c b/libftp/src/path.c index 63ec513..da7e91b 100644 --- a/libftp/src/path.c +++ b/libftp/src/path.c @@ -90,7 +90,7 @@ char *ft_lpath(char *name) { if (!ft_strchr(name, '/')) { - return (ft_path(ft_strjoin("./", name))); + return (ft_lpath(ft_strjoin("./", name))); } else if (ft_strnequ(name, "~/", 1) == 1) { @@ -121,5 +121,5 @@ char *ft_lpath(char *name) { name = ft_lpath("~"); } - return (name); + return (ft_strdup(name)); } \ No newline at end of file diff --git a/src/client/main.c b/src/client/main.c index c29f921..cd85ce5 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -54,6 +54,7 @@ int main(int argc, char **argv) /* ** we are now connected to server, display client prompt */ + ft_init_environ(); ft_display_prompt(); /* ** read from stdin From afb98b487dff1f48d358c043b964ec1acb6c33b5 Mon Sep 17 00:00:00 2001 From: goisetsi Date: Sun, 30 Jul 2017 01:12:40 +0200 Subject: [PATCH 3/8] working on freeing correctly --- src/client/lhandle_request.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/client/lhandle_request.c b/src/client/lhandle_request.c index 298f50f..903732c 100644 --- a/src/client/lhandle_request.c +++ b/src/client/lhandle_request.c @@ -26,6 +26,7 @@ int ft_lhandle_request(char *line, int sockfd) else if (ft_strequ(argv[0], "quit")) { ft_dstrdel(argv); + ft_free_environ(); exit(0); } /* From 389fd6b39cff944a1b350a75209e10264b9a4aaa Mon Sep 17 00:00:00 2001 From: Andre Date: Sun, 30 Jul 2017 01:29:46 +0200 Subject: [PATCH 4/8] removed double free, changed lcd display --- src/client/lcd.c | 6 +++--- src/client/lhandle_request.c | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/client/lcd.c b/src/client/lcd.c index c6765a5..f6f5af8 100644 --- a/src/client/lcd.c +++ b/src/client/lcd.c @@ -24,11 +24,11 @@ void ft_lcd(int fd, char **argv) */ if (!ft_wchdir(path)) { - ft_send_response("ft_p: local directory changed.", fd); + ft_send_response("ft_p: \033[0;32mlocal directory changed\n\033[0m", fd); } else { - ft_send_response("ft_p: failed to change local directory.", fd); + ft_send_response("ft_p: \033[0;31mfailed to change local directory\n\033[0m", fd); } /* ** free path @@ -38,6 +38,6 @@ void ft_lcd(int fd, char **argv) } else { - ft_send_response("ft_p: failed to change local directory.", fd); + ft_send_response("ft_p: \033[0;31mfailed to change local directory\n\033[0m", fd); } } \ No newline at end of file diff --git a/src/client/lhandle_request.c b/src/client/lhandle_request.c index 903732c..298f50f 100644 --- a/src/client/lhandle_request.c +++ b/src/client/lhandle_request.c @@ -26,7 +26,6 @@ int ft_lhandle_request(char *line, int sockfd) else if (ft_strequ(argv[0], "quit")) { ft_dstrdel(argv); - ft_free_environ(); exit(0); } /* From eccb0cf66fc681a7d06845bc944119f374f6d55a Mon Sep 17 00:00:00 2001 From: goisetsi Date: Sun, 30 Jul 2017 01:36:33 +0200 Subject: [PATCH 5/8] fully working lcd, finally --- libftp/src/path.c | 8 +++++++- src/client/lcd.c | 8 +++++--- src/client/lhandle_request.c | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/libftp/src/path.c b/libftp/src/path.c index da7e91b..923ab44 100644 --- a/libftp/src/path.c +++ b/libftp/src/path.c @@ -108,7 +108,13 @@ char *ft_lpath(char *name) } else if (!(ft_strequ(name,"./..") == 1) && !(ft_strnequ(name,"./",1) == 1)) { - home = ft_get_environ("PWD"); + home = ft_wgetcwd(); + joined = ft_strnew(ft_strlen(home)); + ft_strncpy(joined,home,ft_strlen(home) - 1); + ft_putstr(joined); + ft_strdel(&home); + home = ft_strdup(joined); + ft_strdel(&joined); joined = ft_strjoin(home,"/"); ft_strdel(&home); home = ft_strjoin(joined,name); diff --git a/src/client/lcd.c b/src/client/lcd.c index c6765a5..1c07899 100644 --- a/src/client/lcd.c +++ b/src/client/lcd.c @@ -19,16 +19,18 @@ void ft_lcd(int fd, char **argv) ** check path for ~ or - */ path = ft_lpath(argv[1]); + ft_putstr(path); + ft_putstr("\n"); /* ** attempt to chang the directory */ if (!ft_wchdir(path)) { - ft_send_response("ft_p: local directory changed.", fd); + ft_send_response("ft_p: local directory changed.\n", fd); } else { - ft_send_response("ft_p: failed to change local directory.", fd); + ft_send_response("ft_p: failed to change local directory.\n", fd); } /* ** free path @@ -38,6 +40,6 @@ void ft_lcd(int fd, char **argv) } else { - ft_send_response("ft_p: failed to change local directory.", fd); + ft_send_response("ft_p: failed to change local directory.\n", fd); } } \ No newline at end of file diff --git a/src/client/lhandle_request.c b/src/client/lhandle_request.c index 903732c..e1394e3 100644 --- a/src/client/lhandle_request.c +++ b/src/client/lhandle_request.c @@ -26,7 +26,7 @@ int ft_lhandle_request(char *line, int sockfd) else if (ft_strequ(argv[0], "quit")) { ft_dstrdel(argv); - ft_free_environ(); + // ft_free_environ(); exit(0); } /* From a0509b68ff7cbe70de35fe8b2efce77bcc72f016 Mon Sep 17 00:00:00 2001 From: goisetsi Date: Sun, 30 Jul 2017 01:37:24 +0200 Subject: [PATCH 6/8] fully working lcd, finally --- src/client/lcd.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/client/lcd.c b/src/client/lcd.c index 1c07899..5c6ea04 100644 --- a/src/client/lcd.c +++ b/src/client/lcd.c @@ -19,8 +19,6 @@ void ft_lcd(int fd, char **argv) ** check path for ~ or - */ path = ft_lpath(argv[1]); - ft_putstr(path); - ft_putstr("\n"); /* ** attempt to chang the directory */ From 6c486f5084fc053bc66aadeedc1d8baf7df9ef11 Mon Sep 17 00:00:00 2001 From: Andre Date: Sun, 30 Jul 2017 01:42:47 +0200 Subject: [PATCH 7/8] fixing conflict --- src/client/lcd.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/client/lcd.c b/src/client/lcd.c index c9c6639..5c6ea04 100644 --- a/src/client/lcd.c +++ b/src/client/lcd.c @@ -24,19 +24,11 @@ void ft_lcd(int fd, char **argv) */ if (!ft_wchdir(path)) { -<<<<<<< HEAD - ft_send_response("ft_p: \033[0;32mlocal directory changed\n\033[0m", fd); - } - else - { - ft_send_response("ft_p: \033[0;31mfailed to change local directory\n\033[0m", fd); -======= ft_send_response("ft_p: local directory changed.\n", fd); } else { ft_send_response("ft_p: failed to change local directory.\n", fd); ->>>>>>> a0509b68ff7cbe70de35fe8b2efce77bcc72f016 } /* ** free path @@ -46,10 +38,6 @@ void ft_lcd(int fd, char **argv) } else { -<<<<<<< HEAD - ft_send_response("ft_p: \033[0;31mfailed to change local directory\n\033[0m", fd); -======= ft_send_response("ft_p: failed to change local directory.\n", fd); ->>>>>>> a0509b68ff7cbe70de35fe8b2efce77bcc72f016 } } \ No newline at end of file From e26d3875e52768cf929c240b16625b5e5ea6ba28 Mon Sep 17 00:00:00 2001 From: Andre Date: Sun, 30 Jul 2017 02:19:51 +0200 Subject: [PATCH 8/8] updating prompt --- libftp/src/prompt.c | 2 +- src/client/lcd.c | 6 +++--- src/client/lhandle_request.c | 4 ---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/libftp/src/prompt.c b/libftp/src/prompt.c index f422152..677e42c 100644 --- a/libftp/src/prompt.c +++ b/libftp/src/prompt.c @@ -18,7 +18,7 @@ void ft_display_prompt(void) if (getcwd(cwd, 255)) { - ft_putstr("\033[0;35m("); + ft_putstr("\033[0;35m(\033[0m\033[0;40mLOCAL\033[0m\033[0;35m"); ft_putstr(cwd); ft_putstr(")$ \033[0m"); } diff --git a/src/client/lcd.c b/src/client/lcd.c index 5c6ea04..8d8ed22 100644 --- a/src/client/lcd.c +++ b/src/client/lcd.c @@ -24,11 +24,11 @@ void ft_lcd(int fd, char **argv) */ if (!ft_wchdir(path)) { - ft_send_response("ft_p: local directory changed.\n", fd); + ft_send_response("ft_p: \033[0;32mLOCAL directory changed\n\033[0m", fd); } else { - ft_send_response("ft_p: failed to change local directory.\n", fd); + ft_send_response("ft_p: \033[0;31mfailed to change LOCAL directory\n\033[0m", fd); } /* ** free path @@ -38,6 +38,6 @@ void ft_lcd(int fd, char **argv) } else { - ft_send_response("ft_p: failed to change local directory.\n", fd); + ft_send_response("ft_p: \033[0;31mfailed to change LOCAL directory\n\033[0m", fd); } } \ No newline at end of file diff --git a/src/client/lhandle_request.c b/src/client/lhandle_request.c index b89d88d..298f50f 100644 --- a/src/client/lhandle_request.c +++ b/src/client/lhandle_request.c @@ -26,10 +26,6 @@ int ft_lhandle_request(char *line, int sockfd) else if (ft_strequ(argv[0], "quit")) { ft_dstrdel(argv); -<<<<<<< HEAD -======= - // ft_free_environ(); ->>>>>>> a0509b68ff7cbe70de35fe8b2efce77bcc72f016 exit(0); } /*