static void s_who(t_env *e, int cs) { int i; char *tmp; char *list; i = 0; list = NULL; while (i < e->maxfd) { if ((e->fds[i].type == FD_CLIENT) && (i != cs) && (ft_strcmp(e->fds[i].chan, e->fds[cs].chan) == '\0')) { if (list == NULL) list = ft_strijoin("- ", e->fds[i].name, "\n", 0); else list = ft_strijoind(list, "- ", e->fds[i].name, "\n", 0); } i++; } tmp = ft_strijoin(e->fds[cs].buf_write, CLEAR_LINE, "List user(s) in ", e->fds[cs].chan, ":\n", list, 0); ft_strcpy(e->fds[cs].buf_write, tmp); ft_stridel(&tmp, &list, 0); prompt_client(e, cs); }
int command_cd(int sockfd, t_data *data) { char old_path[PATH_MAX]; char *tmp; char *new_path; int ret; tmp = get_char_string(sockfd); getcwd(old_path, PATH_MAX); new_path = ft_strijoin(3, old_path, "/", tmp); free(tmp); if (chdir(new_path) == -1) { free(new_path); return (error_handling(-1, sockfd, MSG_NO_SUCH_FILE)); } tmp = getcwd(NULL, PATH_MAX); if (ft_strncmp(data->root_path, tmp, ft_strlen(data->root_path)) != 0) { chdir(old_path); ret = error_handling(-1, sockfd, MSG_CD_ACCESS_DENIED); } else ret = error_handling(0, sockfd, MSG_CD_OK); free(tmp); free(new_path); return (ret); }
void ft_error(char *s) { char *tmp; tmp = ft_strijoin("error: ", s, ".", NULL); ft_putendl_fd(tmp, 2); ft_strdel(&tmp); }
static void s_msg(t_env *e, int cs, char *name, char *msg) { int i; char *tmp; i = 0; while (i < e->maxfd) { if ((e->fds[i].type == FD_CLIENT) && (i != cs) && ft_strcmp(e->fds[i].name, name) == '\0') { tmp = ft_strijoin(e->fds[i].buf_write, CLEAR_LINE, "{ private msg } ", e->fds[cs].name, ": ", msg, "\n", 0); ft_strcpy(e->fds[i].buf_write, tmp); ft_strdel(&tmp); prompt_client(e, i); } i++; } }
static void ft_print_file(t_listd **lst, t_opts opts, t_l_len *len) { t_listd *tmp; t_item *item; char *strtmp; tmp = *lst; while (tmp) { item = tmp->data; if (item && item->type != 'd') { if (opts.l) strtmp = ft_print_item(len, item); else strtmp = ft_strijoin(item->name, "\n", 0); ft_putstr(strtmp); ft_strdel(&strtmp); } tmp = tmp->next; } }
void cmd_who(char *cmd, t_env *e, int cs) { char *trim; char **spl; char *tmp; trim = ft_strtrim(cmd); spl = ft_strsplit(trim, ' '); ft_strdel(&trim); if (ft_strlistlen(spl) == 1) { s_who(e, cs); } else { tmp = ft_strijoin(e->fds[cs].buf_write, CLEAR_LINE, "usage: /who\n", 0); ft_strcpy(e->fds[cs].buf_write, tmp); ft_strdel(&tmp); } ft_strlistdel(spl); }
void cmd_msg(char *cmd, t_env *e, int cs) { char *trim; char **spl; char *tmp; trim = ft_strtrim(cmd); spl = ft_strsplit(trim, ' '); ft_strdel(&trim); if (ft_strlistlen(spl) == 3) { s_msg(e, cs, spl[1], spl[2]); } else { tmp = ft_strijoin(e->fds[cs].buf_write, CLEAR_LINE, "usage: /msg [name] [message]\n", 0); ft_strcpy(e->fds[cs].buf_write, tmp); ft_strdel(&tmp); } ft_strlistdel(spl); }
void ft_lcd(char *dir) { char *tmp; tmp = NULL; if (dir == NULL) ft_chdir(ft_getenv("HOME")); else if (*dir == '/') ft_chdir(dir); else if (ft_strcmp(dir, "-") == 0) ft_chdir(ston_old_pwd(NULL)); else if (*dir == '~') { tmp = ft_strijoin(ft_getenv("HOME"), dir, 0); ft_chdir(tmp); ft_strdel(&tmp); } else { ft_chdir(dir); ft_strdel(&tmp); } }
/* ************************************************************************** */ #include <libft.h> #include <stdlib.h> #include "server.h" #include "prompt_client.h" #include "exist_channel.h" #include "creat_channel.h" static void s_msg_left_channel(t_env *e, int cs, char *last, char *new) { char *tmp; (void)new; tmp = ft_strijoin(e->fds[cs].buf_write, CLEAR_LINE, last, " left channel.\n", 0); ft_strcpy(e->fds[cs].buf_write, tmp); ft_strdel(&tmp); } static void s_msg_join_channel(t_env *e, int cs, char *last, char *new) { char *tmp; (void)new; tmp = ft_strijoin(e->fds[cs].buf_write, CLEAR_LINE, last, " join channel.\n", 0); ft_strcpy(e->fds[cs].buf_write, tmp); ft_strdel(&tmp); }