7 #if defined(HAVE_PTHREAD_H) && !defined(__LCLINT__)
11 #include <rpmio_internal.h>
19 /* =============================================================== */
20 static int ftpMkdir(const char * path, /*@unused@*/ mode_t mode)
21 /*@globals fileSystem, internalState @*/
22 /*@modifies fileSystem, internalState @*/
25 if ((rc = ftpCmd("MKD", path, NULL)) != 0)
29 sprintf(buf, " 0%o", mode);
30 (void) ftpCmd("SITE CHMOD", path, buf);
36 static int ftpChdir(const char * path)
37 /*@globals fileSystem, internalState @*/
38 /*@modifies fileSystem, internalState @*/
40 return ftpCmd("CWD", path, NULL);
43 static int ftpRmdir(const char * path)
44 /*@globals fileSystem, internalState @*/
45 /*@modifies fileSystem, internalState @*/
47 return ftpCmd("RMD", path, NULL);
50 static int ftpRename(const char * oldpath, const char * newpath)
51 /*@globals fileSystem, internalState @*/
52 /*@modifies fileSystem, internalState @*/
55 if ((rc = ftpCmd("RNFR", oldpath, NULL)) != 0)
57 return ftpCmd("RNTO", newpath, NULL);
60 static int ftpUnlink(const char * path)
61 /*@globals fileSystem, internalState @*/
62 /*@modifies fileSystem, internalState @*/
64 return ftpCmd("DELE", path, NULL);
67 /* =============================================================== */
68 /* XXX rebuilddb.c: analogues to mkdir(2)/rmdir(2). */
69 int Mkdir (const char * path, mode_t mode)
72 int ut = urlPath(path, &lpath);
76 return ftpMkdir(path, mode);
77 /*@notreached@*/ break;
78 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
87 /*@notreached@*/ break;
89 return mkdir(path, mode);
92 int Chdir (const char * path)
95 int ut = urlPath(path, &lpath);
99 return ftpChdir(path);
100 /*@notreached@*/ break;
101 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
110 /*@notreached@*/ break;
115 int Rmdir (const char * path)
118 int ut = urlPath(path, &lpath);
122 return ftpRmdir(path);
123 /*@notreached@*/ break;
124 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
133 /*@notreached@*/ break;
138 /* XXX rpmdb.c: analogue to rename(2). */
140 int Rename (const char * oldpath, const char * newpath)
142 const char *oe = NULL;
143 const char *ne = NULL;
146 /* XXX lib/install.c used to rely on this behavior. */
147 if (!strcmp(oldpath, newpath)) return 0;
149 oldut = urlPath(oldpath, &oe);
151 case URL_IS_FTP: /* XXX WRONG WRONG WRONG */
152 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
159 /*@notreached@*/ break;
162 newut = urlPath(newpath, &ne);
166 fprintf(stderr, "*** rename old %*s new %*s\n", (int)(oe - oldpath), oldpath, (int)(ne - newpath), newpath);
167 if (!(oldut == newut && oe && ne && (oe - oldpath) == (ne - newpath) &&
168 !xstrncasecmp(oldpath, newpath, (oe - oldpath))))
170 return ftpRename(oldpath, newpath);
171 /*@notreached@*/ break;
172 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
182 /*@notreached@*/ break;
184 return rename(oldpath, newpath);
187 int Link (const char * oldpath, const char * newpath)
189 const char *oe = NULL;
190 const char *ne = NULL;
193 oldut = urlPath(oldpath, &oe);
195 case URL_IS_FTP: /* XXX WRONG WRONG WRONG */
196 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
203 /*@notreached@*/ break;
206 newut = urlPath(newpath, &ne);
208 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
209 case URL_IS_FTP: /* XXX WRONG WRONG WRONG */
212 fprintf(stderr, "*** link old %*s new %*s\n", (int)(oe - oldpath), oldpath, (int)(ne - newpath), newpath);
213 if (!(oldut == newut && oe && ne && (oe - oldpath) == (ne - newpath) &&
214 !xstrncasecmp(oldpath, newpath, (oe - oldpath))))
224 /*@notreached@*/ break;
226 return link(oldpath, newpath);
229 /* XXX build/build.c: analogue to unlink(2). */
231 int Unlink(const char * path) {
233 int ut = urlPath(path, &lpath);
237 return ftpUnlink(path);
238 /*@notreached@*/ break;
239 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
248 /*@notreached@*/ break;
253 /* XXX swiped from mc-4.5.39-pre9 vfs/ftpfs.c */
255 #define g_strdup xstrdup
259 * FIXME: this is broken. It depends on mc not crossing border on month!
262 static int current_mday;
264 static int current_mon;
266 static int current_year;
268 /* Following stuff (parse_ls_lga) is used by ftpfs and extfs */
272 static char *columns [MAXCOLS]; /* Points to the string in column n */
274 static int column_ptr [MAXCOLS]; /* Index from 0 to the starting positions of the columns */
278 vfs_split_text (char *p)
279 /*@globals columns, column_ptr @*/
280 /*@modifies *p, columns, column_ptr @*/
286 for (numcols = 0; *p && numcols < MAXCOLS; numcols++){
287 while (*p == ' ' || *p == '\r' || *p == '\n'){
291 columns [numcols] = p;
292 column_ptr [numcols] = p - original;
293 while (*p && *p != ' ' && *p != '\r' && *p != '\n')
305 if (!columns [idx] || columns [idx][0] < '0' || columns [idx][0] > '9')
313 is_dos_date(/*@null@*/ const char *str)
316 if (str != NULL && strlen(str) == 8 &&
317 str[2] == str[5] && strchr("\\-/", (int)str[2]) != NULL)
324 is_week (/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
327 /*@observer@*/ static const char * week = "SunMonTueWedThuFriSat";
330 /*@-observertrans -mayaliasunique@*/
331 if (str != NULL && (pos=strstr(week, str)) != NULL) {
332 /*@=observertrans =mayaliasunique@*/
334 tim->tm_wday = (pos - week)/3;
341 is_month (/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
344 /*@observer@*/ static const char * month = "JanFebMarAprMayJunJulAugSepOctNovDec";
347 /*@-observertrans -mayaliasunique@*/
348 if (str != NULL && (pos = strstr(month, str)) != NULL) {
349 /*@=observertrans -mayaliasunique@*/
351 tim->tm_mon = (pos - month)/3;
358 is_time (/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
361 const char * p, * p2;
363 if (str != NULL && (p = strchr(str, ':')) && (p2 = strrchr(str, ':'))) {
365 if (sscanf (str, "%2d:%2d:%2d", &tim->tm_hour, &tim->tm_min, &tim->tm_sec) != 3)
368 if (sscanf (str, "%2d:%2d", &tim->tm_hour, &tim->tm_min) != 2)
377 static int is_year(/*@null@*/ const char * str, /*@out@*/ struct tm * tim)
388 if (strlen(str) != 4)
391 if (sscanf(str, "%ld", &year) != 1)
394 if (year < 1900 || year > 3000)
397 tim->tm_year = (int) (year - 1900);
403 * FIXME: this is broken. Consider following entry:
404 * -rwx------ 1 root root 1 Aug 31 10:04 2904 1234
405 * where "2904 1234" is filename. Well, this code decodes it as year :-(.
409 vfs_parse_filetype (char c)
413 case 'd': return S_IFDIR;
414 case 'b': return S_IFBLK;
415 case 'c': return S_IFCHR;
416 case 'l': return S_IFLNK;
418 #ifdef IS_IFSOCK /* And if not, we fall through to IFIFO, which is pretty close */
421 case 'p': return S_IFIFO;
422 case 'm': case 'n': /* Don't know what these are :-) */
423 case '-': case '?': return S_IFREG;
428 static int vfs_parse_filemode (const char *p)
430 { /* converts rw-rw-rw- into 0666 */
433 case 'r': res |= 0400; break;
438 case 'w': res |= 0200; break;
443 case 'x': res |= 0100; break;
444 case 's': res |= 0100 | S_ISUID; break;
445 case 'S': res |= S_ISUID; break;
450 case 'r': res |= 0040; break;
455 case 'w': res |= 0020; break;
460 case 'x': res |= 0010; break;
461 case 's': res |= 0010 | S_ISGID; break;
462 case 'l': /* Solaris produces these */
463 case 'S': res |= S_ISGID; break;
468 case 'r': res |= 0004; break;
473 case 'w': res |= 0002; break;
478 case 'x': res |= 0001; break;
479 case 't': res |= 0001 | S_ISVTX; break;
480 case 'T': res |= S_ISVTX; break;
488 static int vfs_parse_filedate(int idx, /*@out@*/ time_t *t)
490 { /* This thing parses from idx in columns[] array */
497 /* Let's setup default time values */
498 tim.tm_year = current_year;
499 tim.tm_mon = current_mon;
500 tim.tm_mday = current_mday;
504 tim.tm_isdst = -1; /* Let mktime() try to guess correct dst offset */
508 /* We eat weekday name in case of extfs */
513 if(is_month(p, &tim)){
514 /* And we expect, it followed by day number */
516 tim.tm_mday = (int)atol (columns [idx++]);
518 return 0; /* No day */
521 /* We usually expect:
524 But in case of extfs we allow these date formats:
527 Wek Mon DD hh:mm:ss YYYY
529 where Mon is Jan-Dec, DD, MM, YY two digit day, month, year,
530 YYYY four digit year, hh, mm, ss two digit hour, minute or second. */
532 /* Here just this special case with MM-DD-YY */
538 memset(d, 0, sizeof(d));
539 if (sscanf(p, "%2d-%2d-%2d", &d[0], &d[1], &d[2]) == 3){
546 /* Hmm... maybe, next time :)*/
548 /* At last, MM-DD-YY */
549 d[0]--; /* Months are zerobased */
559 return 0; /* sscanf failed */
561 return 0; /* unsupported format */
564 /* Here we expect to find time and/or year */
567 if(is_time(columns[idx], &tim) || (got_year = is_year(columns[idx], &tim))) {
570 /* This is a special case for ctime() or Mon DD YYYY hh:mm */
572 ((got_year = is_year(columns[idx], &tim)) || is_time(columns[idx], &tim)))
573 idx++; /* time & year or reverse */
574 } /* only time or date */
577 return 0; /* Nor time or date */
580 * If the date is less than 6 months in the past, it is shown without year
581 * other dates in the past or future are shown with year but without time
582 * This does not check for years before 1900 ... I don't know, how
583 * to represent them at all
586 current_mon < 6 && current_mon < tim.tm_mon &&
587 tim.tm_mon - current_mon >= 6)
591 if ((*t = mktime(&tim)) < 0)
599 vfs_parse_ls_lga (char * p, /*@out@*/ struct stat * st,
600 /*@out@*/ const char ** filename,
601 /*@out@*/ const char ** linkname)
602 /*@modifies *p, *st, *filename, *linkname @*/
604 int idx, idx2, num_cols;
608 if (strncmp (p, "total", 5) == 0)
611 p_copy = g_strdup(p);
612 /* XXX FIXME: parse out inode number from "NLST -lai ." */
613 /* XXX FIXME: parse out sizein blocks from "NLST -lais ." */
615 if ((i = vfs_parse_filetype(*(p++))) == -1)
619 if (*p == ' ') /* Notwell 4 */
622 if (strlen (p) <= 8 || p [8] != ']')
624 /* Should parse here the Notwell permissions :) */
626 if (S_ISDIR (st->st_mode))
627 st->st_mode |= (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IXUSR | S_IXGRP | S_IXOTH);
629 st->st_mode |= (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR);
633 if ((i = vfs_parse_filemode(p)) == -1)
638 /* This is for an extra ACL attribute (HP-UX) */
644 p_copy = g_strdup(p);
645 num_cols = vfs_split_text (p);
647 st->st_nlink = atol (columns [0]);
648 if (st->st_nlink < 0)
653 st->st_uid = finduid (columns [1]);
655 (void) unameToUid (columns [1], &st->st_uid);
658 st->st_uid = (uid_t) atol (columns [1]);
660 /* Mhm, the ls -lg did not produce a group field */
661 for (idx = 3; idx <= 5; idx++)
662 if (is_month(columns [idx], NULL) || is_week(columns [idx], NULL) || is_dos_date(columns[idx]))
665 if (idx == 6 || (idx == 5 && !S_ISCHR (st->st_mode) && !S_ISBLK (st->st_mode)))
668 /* We don't have gid */
669 if (idx == 3 || (idx == 4 && (S_ISCHR(st->st_mode) || S_ISBLK (st->st_mode))))
672 /* We have gid field */
674 st->st_gid = (gid_t) atol (columns [2]);
677 st->st_gid = findgid (columns [2]);
679 (void) gnameToGid (columns [1], &st->st_gid);
685 if (S_ISCHR (st->st_mode) || S_ISBLK (st->st_mode)){
688 if (!is_num (idx2) || sscanf(columns [idx2], " %d,", &maj) != 1)
691 if (!is_num (++idx2) || sscanf(columns [idx2], " %d", &min) != 1)
695 st->st_rdev = ((maj & 0xff) << 8) | (min & 0xffff00ff);
700 /* Common file size */
704 st->st_size = (size_t) atol (columns [idx2]);
710 idx = vfs_parse_filedate(idx, &st->st_mtime);
713 /* Use resulting time value */
714 st->st_atime = st->st_ctime = st->st_mtime;
717 #ifdef HAVE_ST_BLKSIZE
718 st->st_blksize = 512;
720 #ifdef HAVE_ST_BLOCKS
721 st->st_blocks = (st->st_size + 511) / 512;
724 for (i = idx + 1, idx2 = 0; i < num_cols; i++ )
725 if (strcmp (columns [i], "->") == 0){
730 if (((S_ISLNK (st->st_mode) ||
731 (num_cols == idx + 3 && st->st_nlink > 1))) /* Maybe a hardlink? (in extfs) */
738 t = g_strndup (p_copy + column_ptr [idx], column_ptr [idx2] - column_ptr [idx] - 1);
740 int nb = column_ptr [idx2] - column_ptr [idx] - 1;
742 strncpy(t, p_copy + column_ptr [idx], nb);
747 t = g_strdup (p_copy + column_ptr [idx2+1]);
749 if (t [tlen-1] == '\r' || t [tlen-1] == '\n')
751 if (t [tlen-2] == '\r' || t [tlen-2] == '\n')
757 /* Extract the filename from the string copy, not from the columns
758 * this way we have a chance of entering hidden directories like ". ."
762 *filename = g_strdup (columns [idx++]);
767 t = g_strdup (p_copy + column_ptr [idx]); idx++;
770 if (t [tlen-1] == '\r' || t [tlen-1] == '\n')
772 if (t [tlen-2] == '\r' || t [tlen-2] == '\n')
786 static int errorcount = 0;
788 if (++errorcount < 5) {
789 message_1s (1, "Could not parse:", p_copy);
790 } else if (errorcount == 5)
791 message_1s (1, "More parsing errors will be ignored.", "(sorry)" );
796 if (p_copy != p) /* Carefull! */
814 static size_t ftpBufAlloced = 0;
819 static /*@only@*/ char * ftpBuf = NULL;
821 #define alloca_strdup(_s) strcpy(alloca(strlen(_s)+1), (_s))
824 static int ftpNLST(const char * url, ftpSysCall_t ftpSysCall,
825 /*@out@*/ /*@null@*/ struct stat * st,
826 /*@out@*/ /*@null@*/ char * rlbuf, size_t rlbufsiz)
827 /*@globals ftpBufAlloced, ftpBuf,
828 fileSystem, internalState @*/
829 /*@modifies *st, *rlbuf, ftpBufAlloced, ftpBuf,
830 fileSystem, internalState @*/
834 int bufLength, moretodo;
835 const char *n, *ne, *o, *oe;
844 n = ne = o = oe = NULL;
845 (void) urlPath(url, &path);
849 switch (ftpSysCall) {
851 fd = ftpOpen(url, 0, 0, &u);
852 if (fd == NULL || u == NULL)
855 u->openError = ftpReq(fd, "LIST", path);
858 urldn = alloca_strdup(url);
860 if ((bn = strrchr(urldn, '/')) == NULL)
869 rc = ftpChdir(urldn); /* XXX don't care about CWD */
873 fd = ftpOpen(url, 0, 0, &u);
874 if (fd == NULL || u == NULL)
877 /* XXX possibly should do "NLST -lais" to get st_ino/st_blocks also */
878 u->openError = ftpReq(fd, "NLST", "-la");
880 if (bn == NULL || nbn <= 0) {
887 if (u->openError < 0) {
888 fd = fdLink(fd, "error data (ftpStat)");
893 if (ftpBufAlloced == 0 || ftpBuf == NULL) {
894 ftpBufAlloced = _url_iobuf_size;
895 ftpBuf = xcalloc(ftpBufAlloced, sizeof(ftpBuf[0]));
904 /* XXX FIXME: realloc ftpBuf if < ~128 chars remain */
905 if ((ftpBufAlloced - bufLength) < (1024+80)) {
907 assert(ftpBufAlloced < (8*1024*1024));
908 ftpBuf = xrealloc(ftpBuf, ftpBufAlloced);
910 s = se = ftpBuf + bufLength;
913 rc = fdFgets(fd, se, (ftpBufAlloced - bufLength));
918 if (ftpSysCall == DO_FTP_GLOB) { /* XXX HACK */
919 bufLength += strlen(se);
923 for (s = se; *s != '\0'; s = se) {
926 while (*se && *se != '\n') se++;
927 if (se > s && se[-1] == '\r') se[-1] = '\0';
929 /*@innerbreak@*/ break;
932 if (!strncmp(s, "total ", sizeof("total ")-1))
933 /*@innercontinue@*/ continue;
936 for (bingo = 0, n = se; n >= s; n--) {
940 /*@switchbreak@*/ break;
942 if (o || !(n[-3] == ' ' && n[-2] == '-' && n[-1] == '>')) {
943 while (*(++n) == ' ')
946 /*@switchbreak@*/ break;
948 for (o = n + 1; *o == ' '; o++)
952 /*@switchbreak@*/ break;
954 /*@switchbreak@*/ break;
957 /*@innerbreak@*/ break;
960 if (nbn != (ne - n)) /* Same name length? */
961 /*@innercontinue@*/ continue;
962 if (strncmp(n, bn, nbn)) /* Same name? */
963 /*@innercontinue@*/ continue;
966 /*@innerbreak@*/ break;
969 if (moretodo && se > s) {
970 bufLength = se - s - 1;
972 memmove(ftpBuf, s, bufLength);
978 switch (ftpSysCall) {
981 /* XXX FIXME: symlink, replace urldn/bn from [o,oe) and restart */
985 if (st == NULL || !(n && ne)) {
988 rc = ((vfs_parse_ls_lga(s, st, NULL, NULL) > 0) ? 0 : -1);
991 case DO_FTP_READLINK:
992 if (rlbuf == NULL || !(o && oe)) {
998 memcpy(rlbuf, o, rc);
1004 rc = 0; /* XXX WRONG WRONG WRONG */
1007 rc = 0; /* XXX WRONG WRONG WRONG */
1012 (void) ufdClose(fd);
1017 static const char * statstr(const struct stat * st,
1018 /*@returned@*/ /*@out@*/ char * buf)
1019 /*@modifies *buf @*/
1022 "*** dev %x ino %x mode %0o nlink %d uid %d gid %d rdev %x size %x\n",
1023 (unsigned)st->st_dev,
1024 (unsigned)st->st_ino,
1026 (unsigned)st->st_nlink,
1029 (unsigned)st->st_rdev,
1030 (unsigned)st->st_size);
1035 static int ftp_st_ino = 0xdead0000;
1037 static int ftpStat(const char * path, /*@out@*/ struct stat *st)
1038 /*@globals ftp_st_ino, fileSystem, internalState @*/
1039 /*@modifies *st, ftp_st_ino, fileSystem, internalState @*/
1043 rc = ftpNLST(path, DO_FTP_STAT, st, NULL, 0);
1044 /* XXX fts(3) needs/uses st_ino, make something up for now. */
1045 if (st->st_ino == 0)
1046 st->st_ino = ftp_st_ino++;
1048 fprintf(stderr, "*** ftpStat(%s) rc %d\n%s", path, rc, statstr(st, buf));
1052 static int ftpLstat(const char * path, /*@out@*/ struct stat *st)
1053 /*@globals ftp_st_ino, fileSystem, internalState @*/
1054 /*@modifies *st, ftp_st_ino, fileSystem, internalState @*/
1058 rc = ftpNLST(path, DO_FTP_LSTAT, st, NULL, 0);
1059 /* XXX fts(3) needs/uses st_ino, make something up for now. */
1060 if (st->st_ino == 0)
1061 st->st_ino = ftp_st_ino++;
1063 fprintf(stderr, "*** ftpLstat(%s) rc %d\n%s\n", path, rc, statstr(st, buf));
1067 static int ftpReadlink(const char * path, /*@out@*/ char * buf, size_t bufsiz)
1068 /*@globals fileSystem, internalState @*/
1069 /*@modifies *buf, fileSystem, internalState @*/
1072 rc = ftpNLST(path, DO_FTP_READLINK, NULL, buf, bufsiz);
1074 fprintf(stderr, "*** ftpReadlink(%s) rc %d\n", path, rc);
1078 struct __dirstream {
1079 int fd; /* File descriptor. */
1080 char * data; /* Directory block. */
1081 size_t allocation; /* Space allocated for the block. */
1082 size_t size; /* Total valid data in the block. */
1083 size_t offset; /* Current offset into the block. */
1084 off_t filepos; /* Position of next entry to read. */
1085 #if defined(HAVE_PTHREAD_H)
1086 pthread_mutex_t lock; /* Mutex lock for this structure. */
1090 #if !defined(DT_DIR)
1091 # define DT_UNKNOWN 0
1100 typedef struct __dirstream * FTPDIR;
1102 typedef DIR * FTPDIR;
1106 static int ftpmagicdir = 0x8440291;
1107 #define ISFTPMAGIC(_dir) (!memcmp((_dir), &ftpmagicdir, sizeof(ftpmagicdir)))
1111 static DIR * ftpOpendir(const char * path)
1112 /*@globals fileSystem, internalState @*/
1113 /*@modifies fileSystem, internalState @*/
1118 const char * s, * sb, * se;
1127 fprintf(stderr, "*** ftpOpendir(%s)\n", path);
1128 rc = ftpNLST(path, DO_FTP_GLOB, NULL, NULL, 0);
1133 * ftpBuf now contains absolute paths, newline terminated.
1134 * Calculate the number of bytes to hold the directory info.
1136 nb = sizeof(".") + sizeof("..");
1140 while ((c = *se) != '\0') {
1145 /*@switchbreak@*/ break;
1148 for (sb = se; sb > s && sb[-1] != ' '; sb--)
1154 if (*se == '\n') se++;
1157 /*@switchbreak@*/ break;
1159 /*@switchbreak@*/ break;
1163 nb += sizeof(*mydir) + sizeof(*dp) + ((ac + 1) * sizeof(*av)) + (ac + 1);
1164 mydir = xcalloc(1, nb);
1166 dp = (struct dirent *) (mydir + 1);
1167 av = (const char **) (dp + 1);
1168 dt = (char *) (av + (ac + 1));
1169 t = (char *) (dt + ac + 1);
1172 mydir->fd = ftpmagicdir;
1174 mydir->data = (char *) dp;
1176 mydir->allocation = nb;
1182 /*@-dependenttrans -unrecog@*/
1183 dt[ac] = DT_DIR; av[ac++] = t; t = stpcpy(t, "."); t++;
1184 dt[ac] = DT_DIR; av[ac++] = t; t = stpcpy(t, ".."); t++;
1185 /*@=dependenttrans =unrecog@*/
1188 while ((c = *se) != '\0') {
1193 /*@switchbreak@*/ break;
1195 /*@-dependenttrans@*/
1197 /*@=dependenttrans@*/
1203 /*@innerbreak@*/ break;
1206 /*@innerbreak@*/ break;
1209 /*@innerbreak@*/ break;
1212 /*@innerbreak@*/ break;
1215 /*@innerbreak@*/ break;
1218 /*@innerbreak@*/ break;
1221 /*@innerbreak@*/ break;
1223 dt[ac] = DT_UNKNOWN;
1224 /*@innerbreak@*/ break;
1227 for (sb = se; sb > s && sb[-1] != ' '; sb--)
1231 t = stpncpy(t, sb, (se - sb));
1233 if (*se == '\n') se++;
1236 /*@switchbreak@*/ break;
1238 /*@switchbreak@*/ break;
1244 return (DIR *) mydir;
1249 /*@dependent@*/ /*@null@*/
1250 static struct dirent * ftpReaddir(DIR * dir)
1251 /*@globals fileSystem @*/
1252 /*@modifies fileSystem @*/
1254 FTPDIR mydir = (FTPDIR)dir;
1261 if (mydir == NULL || !ISFTPMAGIC(mydir) || mydir->data == NULL) {
1262 /* XXX TODO: EBADF errno. */
1266 dp = (struct dirent *) mydir->data;
1267 av = (const char **) (dp + 1);
1269 dt = (char *) (av + (ac + 1));
1270 i = mydir->offset + 1;
1273 if (i < 0 || i >= ac || av[i] == NULL)
1279 /* XXX glob(3) uses REAL_DIR_ENTRY(dp) test on d_ino */
1281 dp->d_ino = i + 1; /* W2DO? */
1282 dp->d_reclen = 0; /* W2DO? */
1284 #if !defined(hpux) && !defined(sun)
1285 dp->d_off = 0; /* W2DO? */
1292 strncpy(dp->d_name, av[i], sizeof(dp->d_name));
1294 fprintf(stderr, "*** ftpReaddir(%p) %p \"%s\"\n", (void *)mydir, dp, dp->d_name);
1299 static int ftpClosedir(/*@only@*/ DIR * dir)
1300 /*@globals fileSystem @*/
1301 /*@modifies dir, fileSystem @*/
1303 FTPDIR mydir = (FTPDIR)dir;
1306 fprintf(stderr, "*** ftpClosedir(%p)\n", (void *)mydir);
1307 if (mydir == NULL || !ISFTPMAGIC(mydir)) {
1308 /* XXX TODO: EBADF errno. */
1311 free((void *)mydir);
1316 int Stat(const char * path, struct stat * st)
1319 int ut = urlPath(path, &lpath);
1322 fprintf(stderr, "*** Stat(%s,%p)\n", path, st);
1325 return ftpStat(path, st);
1326 /*@notreached@*/ break;
1327 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
1331 case URL_IS_UNKNOWN:
1336 /*@notreached@*/ break;
1338 return stat(path, st);
1341 int Lstat(const char * path, struct stat * st)
1344 int ut = urlPath(path, &lpath);
1347 fprintf(stderr, "*** Lstat(%s,%p)\n", path, st);
1350 return ftpLstat(path, st);
1351 /*@notreached@*/ break;
1352 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
1356 case URL_IS_UNKNOWN:
1361 /*@notreached@*/ break;
1363 return lstat(path, st);
1366 int Readlink(const char * path, char * buf, size_t bufsiz)
1369 int ut = urlPath(path, &lpath);
1373 return ftpReadlink(path, buf, bufsiz);
1374 /*@notreached@*/ break;
1375 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
1379 case URL_IS_UNKNOWN:
1384 /*@notreached@*/ break;
1386 /*@-compdef@*/ /* FIX: *buf is undefined */
1387 return readlink(path, buf, bufsiz);
1391 int Access(const char * path, int amode)
1394 int ut = urlPath(path, &lpath);
1397 fprintf(stderr, "*** Access(%s,%d)\n", path, amode);
1399 case URL_IS_FTP: /* XXX WRONG WRONG WRONG */
1400 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
1404 case URL_IS_UNKNOWN:
1409 /*@notreached@*/ break;
1411 return access(path, amode);
1414 int Glob(const char *pattern, int flags,
1415 int errfunc(const char * epath, int eerrno), glob_t *pglob)
1418 int ut = urlPath(pattern, &lpath);
1422 fprintf(stderr, "*** Glob(%s,0x%x,%p,%p)\n", pattern, (unsigned)flags, (void *)errfunc, pglob);
1427 pglob->gl_closedir = Closedir;
1428 pglob->gl_readdir = Readdir;
1429 pglob->gl_opendir = Opendir;
1430 pglob->gl_lstat = Lstat;
1431 pglob->gl_stat = Stat;
1433 flags |= GLOB_ALTDIRFUNC;
1435 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
1439 case URL_IS_UNKNOWN:
1444 /*@notreached@*/ break;
1446 return glob(pattern, flags, errfunc, pglob);
1449 void Globfree(glob_t *pglob)
1452 fprintf(stderr, "*** Globfree(%p)\n", pglob);
1456 DIR * Opendir(const char * path)
1459 int ut = urlPath(path, &lpath);
1462 fprintf(stderr, "*** Opendir(%s)\n", path);
1465 return ftpOpendir(path);
1466 /*@notreached@*/ break;
1467 case URL_IS_HTTP: /* XXX WRONG WRONG WRONG */
1471 case URL_IS_UNKNOWN:
1476 /*@notreached@*/ break;
1478 /*@-dependenttrans@*/
1479 return opendir(path);
1480 /*@=dependenttrans@*/
1483 struct dirent * Readdir(DIR * dir)
1486 fprintf(stderr, "*** Readdir(%p)\n", (void *)dir);
1487 if (dir == NULL || ISFTPMAGIC(dir))
1488 return ftpReaddir(dir);
1489 return readdir(dir);
1492 int Closedir(DIR * dir)
1495 fprintf(stderr, "*** Closedir(%p)\n", (void *)dir);
1496 if (dir == NULL || ISFTPMAGIC(dir))
1497 return ftpClosedir(dir);
1498 return closedir(dir);