Пример #1
0
t_bool			do_put(t_server *s, t_user *user, char *buff)
{
  int			pos;
  int			i;
  char			**tab;

  if ((tab = str_to_wordtab(buff, " \n")) == NULL)
    return (false);
  i = 0;
  pos = user->y * s->option->width + user->x;
  while (i < 7)
    {
      if (tab[1] && strcmp(s->map[pos].stone_list[i].name, tab[1]) == 0)
	{
	  update_box_content(s, -1, pos);
	  s->map[pos].stone_list[i].nb++;
	  if (remove_stone_to_user(s, user, tab[1]) == false)
	    return (false);
	  send_ok(user->fd);
	  gc_do_put(s, user, i);
	  free_wordtab(tab);
	  return (true);
	}
      ++i;
    }
  free_wordtab(tab);
  return (false);
}
Пример #2
0
void            free_session(t_session *session)
{
  free(session->usr_name);
  free(session->usr_pwd);
  free(session->usr_short_pwd);
  free_wordtab(session->usr_env);
}
Пример #3
0
static int	_loop(int s)
{
  char		*cmd;
  char		**arr;

  my_printf(1, "ftp> ");
  cmd = get_next_line(0);
  my_printf(s, "%s\n", cmd);
  while (cmd && strncmp(cmd, "quit", 4) && strcmp(cmd, "(null)"))
    {
      arr = str_to_wordtab(cmd);
      if (arr && arr[0] && arr[1] && (!strcmp(arr[0], "get")))
	(void)my_get(arr, s, 0, NULL);
      else if (arr && arr[0] && !strcmp(arr[0], "user"))
	(void)user(s, arr, NULL, NULL);
      else
	_getlines(s);
      free(cmd);
      my_printf(1, "ftp> ");
      cmd = get_next_line(0);
      my_printf(s, "%s\n", cmd);
    }
  free_wordtab(arr);
  my_printf(1, "%s221 Goodbye.\n", cmd ? "" : "\n");
  return (0);
}
Пример #4
0
void	free_part(t_bin *bfree)
{
  if (bfree->command)
    free_wordtab(bfree->command);
  if (bfree->op)
    free(bfree->op);
  if (bfree->princ)
    free(bfree->princ);
  free(bfree);
}
Пример #5
0
int	my_pwd(char **arr, int socket, char *ignored)
{
  char	pwd[SIZE_BUFF];

  (void)arr;
  if (getcwd(pwd, SIZE_BUFF) == NULL)
    my_printf(socket, "550: %s\n", strerror(errno));
  else
    my_printf(socket, "227 \"%s/\" is the current directory\n",
	      &pwd[strlen(ignored)]);
  my_printf(socket, "%s\n", END_READ);
  free_wordtab(arr);
  return (0);
}
Пример #6
0
int		peer_fill(t_peer *peer, const char *entry)
{
  char		**peer_info;
  char		**addresses;

  peer_info = split(entry, ";");
  if (peer_info == NULL)
    return (1);
  if (count_wordtab_words(peer_info) != 3
      || peer_info[0] == '\0'
      || peer_info[1] == '\0'
      || peer_info[2] == '\0')
    {
      fprintf(stderr, "Invalid peer entry found\n");
      free_wordtab(peer_info);
      return (1);
    }
  addresses = split(peer_info[2], ",");
  if (addresses == NULL)
    {
      free_wordtab(peer_info);
      return (1);
    }
  peer->uid = peer_info[0];
  peer->name = peer_info[1];
  if (_extract_peer_addresses(peer, addresses) != 0)
    {
      free_wordtab(addresses);
      free_wordtab(peer_info);
      return (1);
    }
  free_wordtab(addresses);
  free(peer_info[2]);
  free(peer_info);
  return (0);
}
Пример #7
0
void	init_envvars(char **envp)
{
  char	**wordtab;
  int	i;

  i = 0;
  while (envp[i])
  {
    wordtab = str_to_wordtab(envp[i], '=');
    if (!wordtab)
      return ;
    my_setenv(wordtab[0], wordtab[1]);
    free_wordtab(wordtab);
    ++i;
  }
}
Пример #8
0
static void	proc_statm(t_proc *proc, char *path, t_mem *mem)
{
  char		**wordtab;
  int		fd;

  if ((fd = open(path, O_RDONLY)) == -1)
    return ;
  close(fd);
  path = my_strcat(path, "/statm");
  if (!(wordtab = one_line_parsing(path, ' ')))
    my_error("invalid /proc/[pid]/statm");
  proc->virt = (double)atol(wordtab[0]) * getpagesize() / 1024;
  proc->res = (double)atol(wordtab[1]) * getpagesize() / 1024;
  proc->shr = (double)atol(wordtab[2]) * getpagesize() / 1024;
  proc->mem = proc->res / mem->mem * 100;
  free_wordtab(wordtab);
  free(path);
}
Пример #9
0
int		read_cmd(t_client *client)
{
  char		buffer[BUFFER_SIZE];

  memset(buffer, 0, BUFFER_SIZE);
  fgets(buffer, 512, stdin);
  clean_buffer(buffer);
  if (!strlen(buffer))
  {
    return (-1);
  }
  else if (strlen(buffer) > 0 && (client->tab = my_str_to_wordtab(buffer)))
    {
      client->buffer_in = buffer;
      check_command(client, client->tab);
      free_wordtab(&(client->tab));
    }
  return (0);
}
Пример #10
0
/*
** This function looks like a main, but i'm not sure I pasted it... <3
*/
int	my_ls(char **argv, int fd, char *ignored)
{
  int	i;
  char	opt[8];

  errno = 0;
  i = 0;
  (void)argv;
  (void)ignored;
  my_printf(fd, "150 Opening ASCII mode data connection for file list\n");
  g_fd = fd;
  while (i < 8)
    opt[i++] = 0;
  (void)my_read_dir("./", opt, 0, 1);
  my_printf(fd, "226 Transfer complete\n");
  my_printf(fd, "%s\n", END_READ);
  free_wordtab(argv);
  return (0);
}
Пример #11
0
char	*my_globing(char *str)
{
  char	**table;
  char	*newstr;
  int	i;

  if (!(table = get_argv(str, " ")))
    return (NULL);
  i = 0;
  newstr = NULL;
  while (table[i])
    {
      if (func_glob(&newstr, table[i]) == EXIT_FAILURE)
	return (NULL);
      ++i;
    }
  free_wordtab(table);
  free(str);
  return (newstr);
}
Пример #12
0
int	my_cd(char **arr, int socket, char *ignored)
{
  char	*pwd;

  if (arr[1] != NULL)
    {
      if (!(pwd = _validate_pwd(arr[1], ignored)))
	my_printf(socket, "550 %s: No such file or directory\n", arr[1]);
      else if (access(pwd, F_OK) == -1)
	my_printf(socket, "550 %s/: No such file or directory\n",
		  &pwd[strlen(ignored)]);
      else if (access(pwd, R_OK) == -1)
	my_printf(socket, "550 %s/: Permission Denied\n", &pwd[strlen(ignored)]);
      else if (chdir(pwd) == -1)
	my_printf(socket, "550 %s/: %s\n", &pwd[strlen(ignored)], strerror(errno));
      else
	my_printf(socket, "250 CWD command successful\n");
      free(pwd);
    }
  my_printf(socket, "%s\n", END_READ);
  free_wordtab(arr);
  return (0);
}
Пример #13
0
int			read_client(t_server *server, t_client *client)
{
  if (!read512_socket(client->fd, client->buffer_in)
      || !strncmp("QUIT", client->buffer_in, strlen("QUIT")))
  {
#ifdef DEBUG
    fprintf(stdout, "--CLIENT DISCONNECT-- (fd: %d)\n", client->fd);
#endif
    pop_client(server->root_clients, client);
  }
  else
  {
#ifdef DEBUG
    puts_telnet(client->buffer_in);
#endif
    clean_telnet(client->buffer_in);
    if ((client->tab_cmd = my_str_to_wordtab(client->buffer_in)))
    {
      interpret_command(server, client);
      free_wordtab(&(client->tab_cmd));
    }
  }
  return (0);
}
Пример #14
0
static void	proc_stat(t_proc *proc, char *path, t_cpu *cpu)
{
  char		**wordtab;
  int		fd;

  if ((fd = open(path, O_RDONLY)) == -1)
    return ;
  close(fd);
  path = my_strcat(path, "/stat");
  if (!(wordtab = one_line_parsing(path, ' ')))
    return ;
  free(proc->pr);
  proc->cpu = (((double)atol(wordtab[13]) - proc->utime) / cpu->delta);
  proc->cpu += ((((double)atol(wordtab[14]) / sysconf(_SC_CLK_TCK)) -
		 proc->stime) / cpu->delta);
  proc->cpu *= 1000;
  proc->utime = (double)atol(wordtab[13]);
  proc->stime = (double)atol(wordtab[14]) / sysconf(_SC_CLK_TCK);
  proc->pr = my_strdup(wordtab[17]);
  proc->nice = atol(wordtab[18]);
  proc_time(proc, wordtab);
  free_wordtab(wordtab);
  free(path);
}