예제 #1
0
파일: fsp.c 프로젝트: masneyb/gftp
static int
fsp_get_next_file (gftp_request * request, gftp_file * fle, int fd)
{
  fsp_protocol_data *lpd;
  struct FSP_RDENTRY dirent;
  struct FSP_RDENTRY *result;
  char *symlink;

  g_return_val_if_fail (request != NULL, GFTP_EFATAL);
  g_return_val_if_fail (request->protonum == GFTP_FSP_NUM, GFTP_EFATAL);
  g_return_val_if_fail (fle != NULL, GFTP_EFATAL);

  lpd = request->protocol_data;

  g_return_val_if_fail (lpd != NULL, GFTP_EFATAL);

  memset (fle, 0, sizeof (*fle));

  result=&dirent;

  if ( fsp_readdir_native (lpd->dir,&dirent,&result))
    {
      fsp_closedir (lpd->dir);
      lpd->dir = NULL;
      request->logging_function (gftp_logging_error, request,
                           _("Corrupted file listing from FSP server %s\n"),
                           request->directory );
      return (GFTP_EFATAL);
    }

  if ( result == NULL)
  {
      fsp_closedir (lpd->dir);
      lpd->dir = NULL;
      return 0;
  }
  
  fle->user = g_strdup (_("unknown"));
  fle->group = g_strdup (_("unknown"));
  
  /* turn FSP symlink into normal file */
  symlink=strchr(dirent.name,'\n');
  if (symlink) 
      *symlink='\0';
  fle->file = g_strdup (dirent.name);
  if (dirent.type==FSP_RDTYPE_DIR)
      fle->st_mode = S_IFDIR | 0755;
  else
      fle->st_mode = S_IFREG | 0644;
  fle->datetime = dirent.lastmod;
  fle->size = dirent.size;
  return (1);
}
예제 #2
0
파일: fsp.c 프로젝트: Efreak/elinks
static void
sort_and_display_entries(FSP_DIR *dir, const unsigned char dircolor[])
{
	/* fsp_readdir_native in fsplib 0.9 and earlier requires
	 * the third parameter to point to a non-null pointer
	 * even though it does not dereference that pointer
	 * and overwrites it with another one anyway.
	 * http://sourceforge.net/tracker/index.php?func=detail&aid=1875210&group_id=93841&atid=605738
	 * Work around the bug by using non-null &tmp.
	 * Nothing will actually read or write tmp.  */
	FSP_RDENTRY fentry, tmp, *table = NULL;
	FSP_RDENTRY *fresult = &tmp;
	int size = 0;
	int i;

	while (!fsp_readdir_native(dir, &fentry, &fresult)) {
		FSP_RDENTRY *new_table;

		if (!fresult) break;
		if (!strcmp(fentry.name, "."))
			continue;
		new_table = mem_realloc(table, (size + 1) * sizeof(*table));
		if (!new_table)
			continue;
		table = new_table;
		copy_struct(&table[size], &fentry);
		size++;
	}
	/* If size==0, then table==NULL.  According to ISO/IEC 9899:1999
	 * 7.20.5p1, the NULL must not be given to qsort.  */
	if (size > 0)
		qsort(table, size, sizeof(*table), compare);

	for (i = 0; i < size; i++) {
		display_entry(&table[i], dircolor);
	}
}