/* View one or more remote files through your pager. */ int CatCmd(int argc, char **argv) { int i, result, errs; LineList globFiles; LinePtr globFile; MultiLineInit(); for (i=1, errs=0; i<argc; i++) { InitLineList(&globFiles); RemoteGlob(&globFiles, argv[i], kListNoFlags); for (globFile = globFiles.first; globFile != NULL; globFile = globFile->next) { result = DoCat(globFile->line); if (result < 0) --errs; if (gXferAbortFlag == SIGINT) break; /* Don't get rest of files if you interrupted. */ if (argc > 2) MultiLinePrintF("### End of file %s ###\n", globFile->line); } DisposeLineListContents(&globFiles); } return (errs); } /* CatCmd */
int DoGetWithGlobbingAndRecursion(GetOptionsPtr gopt) { int err; LineList globFiles; LinePtr globFile; char *cp; int fType; int result; longstring rcwd; err = 0; InitLineList(&globFiles); RemoteGlob(&globFiles, gopt->rName, kListNoFlags); for (globFile = globFiles.first; globFile != NULL; globFile = globFile->next) { if (gXferAbortFlag == SIGINT) break; /* Don't get rest of files if you interrupted. */ if (gopt->recursive) { fType = RemoteFileType(globFile->line); if (fType == 'd') { if ((cp = strrchr(globFile->line, '/')) != NULL) { /* If the user said something like * "get -R /pub/a/b/c/d" we want to just write the * contents of the 'd' as a subdirectory of the local * directory, and not create ./pub, ./pub/a, etc. */ STRNCPY(rcwd, gRemoteCWD); *cp++ = '\0'; if (DoChdir(globFile->line) == 0) { GetDir(gopt, cp, gRemoteCWD, gLocalCWD); } /* Restore the directory we were in before. */ (void) DoChdir(rcwd); } else { /* Otherwise, the user gave a simple path, so it was * something like "get -R pub" */ GetDir(gopt, globFile->line, gRemoteCWD, gLocalCWD); } } else if (fType == 'l') { EPrintF("Ignoring symbolic link '%s'\n", globFile->line); } else if (fType == '-') { goto regFile; } } else { regFile: gopt->rName = globFile->line; gopt->lName = NULL; /* Make it later. */ result = DoGet(gopt); if (result < 0) err = -1; } } DisposeLineListContents(&globFiles); return (err); } /* DoGetWithGlobbingAndRecursion */
static int GetSymLinkInfo(char *dst, size_t siz, char *rLink) { LineList fileList; char *cp; int result; result = -1; *dst = '\0'; InitLineList(&fileList); ListToMemory(&fileList, "LIST", kListDirNamesOnlyMode, rLink); if (fileList.first != NULL) { cp = fileList.first->line; *cp++ = '\0'; for (cp += strlen(cp) - 1; ; cp--) { if (*cp == '\0') goto done; if ((cp[0] == '>') && (cp[-1] == '-')) break; } (void) Strncpy(dst, cp + 2, siz); result = 0; } done: DisposeLineListContents(&fileList); return (result); } /* GetSymLinkInfo */
int FTPRemoteHelp(const FTPCIPtr cip, const char *const pattern, const FTPLineListPtr llp) { int result; ResponsePtr rp; if ((cip == NULL) || (llp == NULL)) return (kErrBadParameter); if (strcmp(cip->magic, kLibraryMagic)) return (kErrBadMagic); InitLineList(llp); rp = InitResponse(); if (rp == NULL) { result = kErrMallocFailed; cip->errNo = kErrMallocFailed; FTPLogError(cip, kDontPerror, "Malloc failed.\n"); } else { if ((pattern == NULL) || (*pattern == '\0')) result = RCmd(cip, rp, "HELP"); else result = RCmd(cip, rp, "HELP %s", pattern); if (result < 0) { DoneWithResponse(cip, rp); return (result); } else if (result == 2) { if (CopyLineList(llp, &rp->msg) < 0) { result = kErrMallocFailed; cip->errNo = kErrMallocFailed; FTPLogError(cip, kDontPerror, "Malloc failed.\n"); } else { result = kNoErr; } } else { cip->errNo = kErrHELPFailed; result = kErrHELPFailed; } DoneWithResponse(cip, rp); } return (result); } /* FTPRemoteHelp */
TRACKER_CONVERTOR() { ros::NodeHandle n_private_("~"); n_private_.param("marker_topic",marker_topic_,MARKER_TOPIC); n_private_.param("tracker_topic",tracker_topic_,TRACKER_TOPIC); marker_pub_ = nh_.advertise<visualization_msgs::MarkerArray>(marker_topic_,1); tracker_sub_ = nh_.subscribe(tracker_topic_,1,&TRACKER_CONVERTOR::TrackerCallback,this); //setting color(r,g,b,a) SetColor(&color_[0],0.0,0.0,1.0,1.0); SetColor(&color_[1],1.0,1.0,1.0,1.0); InitSphereList(&marker_sphere_); InitLineList(&marker_arrow_); InitLineStrip(&marker_trj_tmp_); printf("start convert...\n"); }
/* View one or more remote files through your pager. */ int PageCmd(int argc, char **argv) { int i, result, errs; LineList globFiles; LinePtr globFile; char *pagerProg; if (STREQ(argv[1], "-b") && (gWinInit > 0) && (argc > 2)) { /* A hack to let you use the built-in pager like you * can with the lpage command. */ pagerProg = NULL; /* Use built-in */ i = 2; } else { if (gPager[0] == '\0') { EPrintF("You haven't specified a program to use as a pager.\n"); EPrintF("You can set this from the preferences screen (prefs command).\n"); return -1; } pagerProg = gPager; i = 1; } for (errs=0; i<argc; i++) { InitLineList(&globFiles); RemoteGlob(&globFiles, argv[i], kListNoFlags); for (globFile = globFiles.first; globFile != NULL; globFile = globFile->next) { if (pagerProg == NULL) result = DoCat(globFile->line); else result = DoPage(globFile->line); if (result < 0) --errs; if (gXferAbortFlag == SIGINT) break; /* Don't get rest of files if you interrupted. */ } DisposeLineListContents(&globFiles); } return (errs); } /* PageCmd */
int RGlobCmd(int argc, char **argv) { LineList globFiles; LinePtr globFile; int i; MultiLineInit(); for (i=1; i<argc; i++) { InitLineList(&globFiles); RemoteGlob(&globFiles, argv[i], kListNoFlags); for (globFile = globFiles.first; globFile != NULL; globFile = globFile->next) { MultiLinePrintF("%s\n", globFile->line); } DisposeLineListContents(&globFiles); } return (0); } /* RGlobCmd */
int RemoteFileType(char *fName) { LineList fileList; char *cp; int result; int i; result = 0; InitLineList(&fileList); ListToMemory(&fileList, "LIST", kListDirNamesOnlyMode, fName); if (fileList.first != NULL) { cp = fileList.first->line; /* Do a quick check and see if it looks like a unix ls line. */ for (i=1; i<=3; i++) if ((cp[i] != 'r') && (cp[i] != 'w') && (cp[i] != 'x') && (cp[i] != '-')) goto done; result = (int) cp[0]; } done: DisposeLineListContents(&fileList); return (result); } /* RemoteFileType */
int FTPRemoteGlob(FTPCIPtr cip, FTPLineListPtr fileList, const char *pattern, int doGlob) { char *cp; const char *lsflags; FTPLinePtr lp; int result; if (cip == NULL) return (kErrBadParameter); if (strcmp(cip->magic, kLibraryMagic)) return (kErrBadMagic); if (fileList == NULL) return (kErrBadParameter); InitLineList(fileList); if ((pattern == NULL) || (pattern[0] == '\0')) return (kErrBadParameter); /* Note that we do attempt to use glob characters even if the remote * host isn't UNIX. Most non-UNIX remote FTP servers look for UNIX * style wildcards. */ if ((doGlob == 1) && (GLOBCHARSINSTR(pattern))) { /* Use NLST, which lists files one per line. */ lsflags = ""; /* Optimize for "NLST *" case which is same as "NLST". */ if (strcmp(pattern, "*") == 0) { pattern = ""; lsflags = (cip->hasNLST_a == kCommandNotAvailable) ? "" : "-a"; } else if (strcmp(pattern, "**") == 0) { /* Hack; Lets you try "NLST -a" if you're daring. */ /* Need to use "NLST -a" whenever possible, * because wu-ftpd doesn't do NLST right, IMHO. * (It doesn't include directories in the NLST * if you do "NLST /the/dir" without -a.) */ pattern = ""; lsflags = (cip->hasNLST_a == kCommandNotAvailable) ? "" : "-a"; } if ((result = FTPListToMemory2(cip, pattern, fileList, lsflags, 0, (int *) 0)) < 0) { if (*lsflags == '\0') return (result); if (strchr(lsflags, 'a') != NULL) { /* Try again, without "-a" */ cip->hasNLST_a = kCommandNotAvailable; lsflags = ""; if ((result = FTPListToMemory2(cip, pattern, fileList, lsflags, 0, (int *) 0)) < 0) { return (result); } /* else proceed */ } else { return (result); } } #if 0 DisposeLineListContents(fileList); InitLineList(fileList); AddLine(fileList, "../FAKEME1.txt"); AddLine(fileList, "../../FAKEME2.txt"); AddLine(fileList, "..\\FAKEME3.txt"); AddLine(fileList, "..\\..\\FAKEME4.txt"); AddLine(fileList, "...\\FAKEME5.txt"); AddLine(fileList, "/tmp/bad/FAKEME6.txt"); AddLine(fileList, "c:\\temp\\FAKEME7.txt"); AddLine(fileList, "foo/../FAKEME8.txt"); AddLine(fileList, "foo\\bar\\...\\FAKEME9.txt"); #endif if (fileList->first == NULL) { cip->errNo = kErrGlobNoMatch; return (kErrGlobNoMatch); } if (fileList->first == fileList->last) { #define glberr(a) (ISTRNEQ(cp, a, strlen(a))) /* If we have only one item in the list, see if it really was * an error message we would recognize. */ cp = strchr(fileList->first->line, ':'); if (cp != NULL) { if (glberr(": No such file or directory")) { (void) RemoveLine(fileList, fileList->first); cip->errNo = kErrGlobFailed; return (kErrGlobFailed); } else if (glberr(": No match")) { cip->errNo = kErrGlobNoMatch; return (kErrGlobNoMatch); } } } StripUnneccesaryGlobEntries(cip, fileList); RemoteGlobCollapse(cip, pattern, fileList); for (lp=fileList->first; lp != NULL; lp = lp->next) PrintF(cip, " Rglob [%s]\n", lp->line); } else { /* Or, if there were no globbing characters in 'pattern', then the * pattern is really just a filename. So for this case the * file list is really just a single file. */ fileList->first = fileList->last = NULL; (void) AddLine(fileList, pattern); } return (kNoErr); } /* FTPRemoteGlob */
int FTPDecodeURL( const FTPCIPtr cip, /* area pointed to may be modified */ char *const url, /* always modified */ LineListPtr cdlist, /* always modified */ char *const fn, /* always modified */ const size_t fnsize, int *const xtype, /* optional; may be modified */ int *const wantnlst /* optional; always modified */ ) { char *cp; char *hstart, *hend; char *h2start; char *at1; char portstr[32]; int port; int sc; char *lastslash; char *parsestr; char *tok; char subdir[128]; char *semi; InitLineList(cdlist); *fn = '\0'; if (wantnlst != NULL) *wantnlst = 0; if (xtype != NULL) *xtype = kTypeBinary; cp = NULL; /* shut up warnings */ #ifdef HAVE_STRCASECMP if (strncasecmp(url, "<URL:ftp://", 11) == 0) { cp = url + strlen(url) - 1; if (*cp != '>') return (kMalformedURL); /* missing closing > */ *cp = '\0'; cp = url + 11; } else if (strncasecmp(url, "ftp://", 6) == 0) { cp = url + 6; } else { return (-1); /* not a RFC 1738 URL */ } #else /* HAVE_STRCASECMP */ if (strncmp(url, "<URL:ftp://", 11) == 0) { cp = url + strlen(url) - 1; if (*cp != '>') return (kMalformedURL); /* missing closing > */ *cp = '\0'; cp = url + 11; } else if (strncmp(url, "ftp://", 6) == 0) { cp = url + 6; } else { return (-1); /* not a RFC 1738 URL */ } #endif /* HAVE_STRCASECMP */ /* //<user>:<password>@<host>:<port>/<url-path> */ at1 = NULL; for (hstart = cp; ; cp++) { if (*cp == '@') { if (at1 == NULL) at1 = cp; else return (kMalformedURL); } else if ((*cp == '\0') || (*cp == '/')) { hend = cp; break; } } sc = *hend; *hend = '\0'; if (at1 == NULL) { /* no user or password */ h2start = hstart; } else { *at1 = '\0'; cp = strchr(hstart, ':'); if (cp == NULL) { /* whole thing is the user name then */ URLCopyToken(cip->user, sizeof(cip->user), hstart, (size_t) (at1 - hstart)); } else if (strchr(cp + 1, ':') != NULL) { /* Too many colons */ return (kMalformedURL); } else { URLCopyToken(cip->user, sizeof(cip->user), hstart, (size_t) (cp - hstart)); URLCopyToken(cip->pass, sizeof(cip->pass), cp + 1, (size_t) (at1 - (cp + 1))); } *at1 = '@'; h2start = at1 + 1; } cp = strchr(h2start, ':'); if (cp == NULL) { /* whole thing is the host then */ URLCopyToken(cip->host, sizeof(cip->host), h2start, (size_t) (hend - h2start)); } else if (strchr(cp + 1, ':') != NULL) { /* Too many colons */ return (kMalformedURL); } else { URLCopyToken(cip->host, sizeof(cip->host), h2start, (size_t) (cp - h2start)); URLCopyToken(portstr, sizeof(portstr), cp + 1, (size_t) (hend - (cp + 1))); port = atoi(portstr); if (port > 0) cip->port = port; } *hend = (char) sc; if ((*hend == '\0') || ((*hend == '/') && (hend[1] == '\0'))) { /* no path, okay */ return (0); } lastslash = strrchr(hend, '/'); if (lastslash == NULL) { /* no path, okay */ return (0); } *lastslash = '\0'; if ((semi = strchr(lastslash + 1, ';')) != NULL) { *semi++ = '\0'; #ifdef HAVE_STRCASECMP if (strcasecmp(semi, "type=i") == 0) { if (xtype != NULL) *xtype = kTypeBinary; } else if (strcasecmp(semi, "type=a") == 0) { if (xtype != NULL) *xtype = kTypeAscii; } else if (strcasecmp(semi, "type=b") == 0) { if (xtype != NULL) *xtype = kTypeBinary; } else if (strcasecmp(semi, "type=d") == 0) { if (wantnlst != NULL) { *wantnlst = 1; if (xtype != NULL) *xtype = kTypeAscii; } else { /* You didn't want these. */ return (kMalformedURL); } } #else /* HAVE_STRCASECMP */ if (strcmp(semi, "type=i") == 0) { if (xtype != NULL) *xtype = kTypeBinary; } else if (strcmp(semi, "type=a") == 0) { if (xtype != NULL) *xtype = kTypeAscii; } else if (strcmp(semi, "type=b") == 0) { if (xtype != NULL) *xtype = kTypeBinary; } else if (strcmp(semi, "type=d") == 0) { if (wantnlst != NULL) { *wantnlst = 1; if (xtype != NULL) *xtype = kTypeAscii; } else { /* You didn't want these. */ return (kMalformedURL); } } #endif /* HAVE_STRCASECMP */ } URLCopyToken(fn, fnsize, lastslash + 1, strlen(lastslash + 1)); for (parsestr = hend; (tok = strtok(parsestr, "/")) != NULL; parsestr = NULL) { URLCopyToken(subdir, sizeof(subdir), tok, strlen(tok)); (void) AddLine(cdlist, subdir); } *lastslash = '/'; return (kNoErr); } /* FTPDecodeURL */
int GetDir(GetOptionsPtr gopt, char *dName, char *rRoot, char *lRoot) { LineList dirFiles; LinePtr dirFile; char *rd; /* Remote directory path. */ char *ld; /* Local directory path. */ char *rf; /* Complete remote pathname for an item. */ char *lf; /* Complete local pathname for an item. */ char *sl; /* What a symlink points to. */ char *iName; int fType; rd = NULL; ld = NULL; rf = NULL; lf = NULL; if ((rd = StrDup(rRoot)) == NULL) goto fail; if ((rd = PtrCatSlash(rd, dName)) == NULL) goto fail; if ((ld = StrDup(lRoot)) == NULL) goto fail; if ((ld = PtrCatSlash(ld, dName)) == NULL) goto fail; /* Create this directory on the local host first. */ if (MkDirs(ld)) { EPrintF("Could not create directory '%s.'\n", ld); goto fail; } /* Get the names of all files and subdirs. */ InitLineList(&dirFiles); GetFileList(&dirFiles, rd); /* Get all the files first. */ for (dirFile = dirFiles.first; dirFile != NULL; dirFile = dirFile->next) { fType = (int) dirFile->line[0]; if ((fType == '-') || (fType == 'l')) { iName = dirFile->line + 1; if ((rf = StrDup(rd)) == NULL) goto fail; if ((rf = PtrCatSlash(rf, iName)) == NULL) goto fail; if ((lf = StrDup(ld)) == NULL) goto fail; if ((lf = PtrCatSlash(lf, iName)) == NULL) goto fail; if (fType == '-') { gopt->rName = rf; gopt->lName = lf; DoGet(gopt); } else { #ifdef HAVE_SYMLINK sl = (char *) malloc(SZ(512)); if (sl != NULL) { if (GetSymLinkInfo(sl, SZ(512), rf) == 0) (void) symlink(sl, lf); free(sl); } #endif /* HAVE_SYMLINK */ } free(rf); free(lf); rf = NULL; lf = NULL; } if (gXferAbortFlag == SIGINT) break; /* Don't get rest of files if you interrupted. */ } /* Now get subdirectories. */ for (dirFile = dirFiles.first; dirFile != NULL; dirFile = dirFile->next) { if (gXferAbortFlag == SIGINT) break; /* Don't get rest of files if you interrupted. */ fType = (int) dirFile->line[0]; if (fType == 'd') { iName = dirFile->line + 1; if (GetDir(gopt, iName, rd, ld) < 0) break; } } free(ld); free(rd); DisposeLineListContents(&dirFiles); return (0); fail: if (rd != NULL) free(rd); if (ld != NULL) free(ld); if (rf != NULL) free(rf); if (lf != NULL) free(lf); return (-1); } /* GetDir */