cmds.c (79971) | cmds.c (98247) |
---|---|
1/* $NetBSD: cmds.c,v 1.90 2000/08/01 22:47:25 lukem Exp $ */ | 1/* $NetBSD: cmds.c,v 1.98 2002/06/05 10:20:46 lukem Exp $ */ |
2 3/*- | 2 3/*- |
4 * Copyright (c) 1996-2000 The NetBSD Foundation, Inc. | 4 * Copyright (c) 1996-2002 The NetBSD Foundation, Inc. |
5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Luke Mewburn. 9 * 10 * This code is derived from software contributed to The NetBSD Foundation 11 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 12 * NASA Ames Research Center. --- 497 unchanged lines hidden (view full) --- 510 (void)xsignal(SIGINT, oldintr); 511 mflag = 0; 512} 513 514void 515reget(int argc, char *argv[]) 516{ 517 | 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Luke Mewburn. 9 * 10 * This code is derived from software contributed to The NetBSD Foundation 11 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 12 * NASA Ames Research Center. --- 497 unchanged lines hidden (view full) --- 510 (void)xsignal(SIGINT, oldintr); 511 mflag = 0; 512} 513 514void 515reget(int argc, char *argv[]) 516{ 517 |
518 (void)getit(argc, argv, 1, "r+w"); | 518 (void)getit(argc, argv, 1, "r+"); |
519} 520 521void 522get(int argc, char *argv[]) 523{ 524 | 519} 520 521void 522get(int argc, char *argv[]) 523{ 524 |
525 (void)getit(argc, argv, 0, restart_point ? "r+w" : "w" ); | 525 (void)getit(argc, argv, 0, restart_point ? "r+" : "w" ); |
526} 527 528/* 529 * Receive one file. | 526} 527 528/* 529 * Receive one file. |
530 * If restartit is 1, restart the xfer always. 531 * If restartit is -1, restart the xfer only if the remote file is newer. |
|
530 */ 531int 532getit(int argc, char *argv[], int restartit, const char *mode) 533{ | 532 */ 533int 534getit(int argc, char *argv[], int restartit, const char *mode) 535{ |
534 int loc = 0; 535 int rval = 0; 536 char *remfile, *locfile, *olocfile; | 536 int loc, rval; 537 char *remfile, *locfile, *olocfile; |
537 | 538 |
539 loc = rval = 0; |
|
538 if (argc == 2) { 539 argc++; 540 argv[2] = argv[1]; 541 loc++; 542 } 543 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "remote-file"))) 544 goto usage; 545 if ((argc < 3 && !another(&argc, &argv, "local-file")) || argc > 3) { --- 88 unchanged lines hidden (view full) --- 634 635/* 636 * Get multiple files. 637 */ 638void 639mget(int argc, char *argv[]) 640{ 641 sigfunc oldintr; | 540 if (argc == 2) { 541 argc++; 542 argv[2] = argv[1]; 543 loc++; 544 } 545 if (argc == 0 || (argc == 1 && !another(&argc, &argv, "remote-file"))) 546 goto usage; 547 if ((argc < 3 && !another(&argc, &argv, "local-file")) || argc > 3) { --- 88 unchanged lines hidden (view full) --- 636 637/* 638 * Get multiple files. 639 */ 640void 641mget(int argc, char *argv[]) 642{ 643 sigfunc oldintr; |
642 int ch, ointer; 643 char *cp, *tp, *tp2, tmpbuf[MAXPATHLEN]; | 644 int ointer; 645 char *cp, *tp; 646 int restartit; |
644 645 if (argc == 0 || 646 (argc == 1 && !another(&argc, &argv, "remote-files"))) { 647 fprintf(ttyout, "usage: %s remote-files\n", argv[0]); 648 code = -1; 649 return; 650 } 651 mname = argv[0]; 652 mflag = 1; | 647 648 if (argc == 0 || 649 (argc == 1 && !another(&argc, &argv, "remote-files"))) { 650 fprintf(ttyout, "usage: %s remote-files\n", argv[0]); 651 code = -1; 652 return; 653 } 654 mname = argv[0]; 655 mflag = 1; |
656 restart_point = 0; 657 restartit = 0; 658 if (strcmp(argv[0], "mreget") == 0) { 659 if (! features[FEAT_REST_STREAM]) { 660 fprintf(ttyout, 661 "Restart is not supported by the remote server.\n"); 662 return; 663 } 664 restartit = 1; 665 } |
|
653 oldintr = xsignal(SIGINT, mintr); 654 if (sigsetjmp(jabort, 1)) 655 mabort(); 656 while ((cp = remglob(argv, proxy, NULL)) != NULL) { 657 if (*cp == '\0' || !connected) { 658 mflag = 0; 659 continue; 660 } | 666 oldintr = xsignal(SIGINT, mintr); 667 if (sigsetjmp(jabort, 1)) 668 mabort(); 669 while ((cp = remglob(argv, proxy, NULL)) != NULL) { 670 if (*cp == '\0' || !connected) { 671 mflag = 0; 672 continue; 673 } |
661 if (mflag && confirm(argv[0], cp)) { 662 tp = cp; 663 if (mcase) { 664 for (tp2 = tmpbuf; (ch = *tp++) != 0; ) 665 *tp2++ = isupper(ch) ? tolower(ch) : ch; 666 *tp2 = '\0'; 667 tp = tmpbuf; 668 } 669 if (ntflag) { 670 tp = dotrans(tp); 671 } 672 if (mapflag) { 673 tp = domap(tp); 674 } 675 recvrequest("RETR", tp, cp, "w", 676 tp != cp || !interactive, 1); 677 if (!mflag && fromatty) { 678 ointer = interactive; 679 interactive = 1; 680 if (confirm("Continue with", "mget")) { 681 mflag++; 682 } 683 interactive = ointer; 684 } | 674 if (! mflag || !confirm(argv[0], cp)) 675 continue; 676 tp = cp; 677 if (mcase) 678 tp = docase(tp); 679 if (ntflag) 680 tp = dotrans(tp); 681 if (mapflag) 682 tp = domap(tp); 683 if (restartit) { 684 struct stat stbuf; 685 686 if (stat(tp, &stbuf) == 0) 687 restart_point = stbuf.st_size; 688 else 689 warn("stat %s", tp); |
685 } | 690 } |
691 recvrequest("RETR", tp, cp, restart_point ? "r+" : "w", 692 tp != cp || !interactive, 1); 693 restart_point = 0; 694 if (!mflag && fromatty) { 695 ointer = interactive; 696 interactive = 1; 697 if (confirm("Continue with", "mget")) 698 mflag++; 699 interactive = ointer; 700 } |
|
686 } 687 (void)xsignal(SIGINT, oldintr); 688 mflag = 0; 689} 690 691/* 692 * Read list of filenames from a local file and get those 693 */ --- 12 unchanged lines hidden (view full) --- 706 fp = fopen(argv[1], "r"); 707 if (fp == NULL) { 708 fprintf(ttyout, "Cannot open source file %s\n", argv[1]); 709 code = -1; 710 return; 711 } 712 713 argv[0] = "get"; | 701 } 702 (void)xsignal(SIGINT, oldintr); 703 mflag = 0; 704} 705 706/* 707 * Read list of filenames from a local file and get those 708 */ --- 12 unchanged lines hidden (view full) --- 721 fp = fopen(argv[1], "r"); 722 if (fp == NULL) { 723 fprintf(ttyout, "Cannot open source file %s\n", argv[1]); 724 code = -1; 725 return; 726 } 727 728 argv[0] = "get"; |
714 mode = restart_point ? "r+w" : "w"; | 729 mode = restart_point ? "r+" : "w"; |
715 716 for (; 717 (buf = fparseln(fp, NULL, NULL, "\0\0\0", 0)) != NULL; 718 free(buf)) { 719 if (buf[0] == '\0') 720 continue; 721 argv[1] = buf; 722 (void)getit(argc, argv, 0, mode); --- 383 unchanged lines hidden (view full) --- 1106lcd(int argc, char *argv[]) 1107{ 1108 char buf[MAXPATHLEN]; 1109 char *locdir; 1110 1111 code = -1; 1112 if (argc == 1) { 1113 argc++; | 730 731 for (; 732 (buf = fparseln(fp, NULL, NULL, "\0\0\0", 0)) != NULL; 733 free(buf)) { 734 if (buf[0] == '\0') 735 continue; 736 argv[1] = buf; 737 (void)getit(argc, argv, 0, mode); --- 383 unchanged lines hidden (view full) --- 1121lcd(int argc, char *argv[]) 1122{ 1123 char buf[MAXPATHLEN]; 1124 char *locdir; 1125 1126 code = -1; 1127 if (argc == 1) { 1128 argc++; |
1114 argv[1] = home; | 1129 argv[1] = localhome; |
1115 } 1116 if (argc != 2) { 1117 fprintf(ttyout, "usage: %s [local-directory]\n", argv[0]); 1118 return; 1119 } 1120 if ((locdir = globulize(argv[1])) == NULL) 1121 return; 1122 if (chdir(locdir) < 0) --- 178 unchanged lines hidden (view full) --- 1301 * Get a directory listing of multiple remote files. 1302 */ 1303void 1304mls(int argc, char *argv[]) 1305{ 1306 sigfunc oldintr; 1307 int ointer, i; 1308 int dolist; | 1130 } 1131 if (argc != 2) { 1132 fprintf(ttyout, "usage: %s [local-directory]\n", argv[0]); 1133 return; 1134 } 1135 if ((locdir = globulize(argv[1])) == NULL) 1136 return; 1137 if (chdir(locdir) < 0) --- 178 unchanged lines hidden (view full) --- 1316 * Get a directory listing of multiple remote files. 1317 */ 1318void 1319mls(int argc, char *argv[]) 1320{ 1321 sigfunc oldintr; 1322 int ointer, i; 1323 int dolist; |
1309 char mode[1], *dest, *odest; | 1324 char *mode, *dest, *odest; |
1310 1311 if (argc == 0) 1312 goto usage; 1313 if (argc < 2 && !another(&argc, &argv, "remote-files")) 1314 goto usage; 1315 if (argc < 3 && !another(&argc, &argv, "local-file")) { 1316 usage: 1317 fprintf(ttyout, "usage: %s remote-files local-file\n", argv[0]); --- 10 unchanged lines hidden (view full) --- 1328 } 1329 dolist = strcmp(argv[0], "mls"); 1330 mname = argv[0]; 1331 mflag = 1; 1332 oldintr = xsignal(SIGINT, mintr); 1333 if (sigsetjmp(jabort, 1)) 1334 mabort(); 1335 for (i = 1; mflag && i < argc-1 && connected; i++) { | 1325 1326 if (argc == 0) 1327 goto usage; 1328 if (argc < 2 && !another(&argc, &argv, "remote-files")) 1329 goto usage; 1330 if (argc < 3 && !another(&argc, &argv, "local-file")) { 1331 usage: 1332 fprintf(ttyout, "usage: %s remote-files local-file\n", argv[0]); --- 10 unchanged lines hidden (view full) --- 1343 } 1344 dolist = strcmp(argv[0], "mls"); 1345 mname = argv[0]; 1346 mflag = 1; 1347 oldintr = xsignal(SIGINT, mintr); 1348 if (sigsetjmp(jabort, 1)) 1349 mabort(); 1350 for (i = 1; mflag && i < argc-1 && connected; i++) { |
1336 *mode = (i == 1) ? 'w' : 'a'; | 1351 mode = (i == 1) ? "w" : "a"; |
1337 recvrequest(dolist ? "LIST" : "NLST", dest, argv[i], mode, 1338 0, 0); 1339 if (!mflag && fromatty) { 1340 ointer = interactive; 1341 interactive = 1; 1342 if (confirm("Continue with", argv[0])) { 1343 mflag ++; 1344 } --- 270 unchanged lines hidden (view full) --- 1615 usage: 1616 fprintf(ttyout, "usage: %s mode remote-file\n", argv[0]); 1617 code = -1; 1618 return; 1619 } 1620 (void)command("SITE CHMOD %s %s", argv[1], argv[2]); 1621} 1622 | 1352 recvrequest(dolist ? "LIST" : "NLST", dest, argv[i], mode, 1353 0, 0); 1354 if (!mflag && fromatty) { 1355 ointer = interactive; 1356 interactive = 1; 1357 if (confirm("Continue with", argv[0])) { 1358 mflag ++; 1359 } --- 270 unchanged lines hidden (view full) --- 1630 usage: 1631 fprintf(ttyout, "usage: %s mode remote-file\n", argv[0]); 1632 code = -1; 1633 return; 1634 } 1635 (void)command("SITE CHMOD %s %s", argv[1], argv[2]); 1636} 1637 |
1638#define COMMAND_1ARG(argc, argv, cmd) \ 1639 if (argc == 1) \ 1640 command(cmd); \ 1641 else \ 1642 command(cmd " %s", argv[1]) 1643 |
|
1623void 1624do_umask(int argc, char *argv[]) 1625{ 1626 int oldverbose = verbose; 1627 1628 if (argc == 0) { 1629 fprintf(ttyout, "usage: %s [umask]\n", argv[0]); 1630 code = -1; 1631 return; 1632 } 1633 verbose = 1; | 1644void 1645do_umask(int argc, char *argv[]) 1646{ 1647 int oldverbose = verbose; 1648 1649 if (argc == 0) { 1650 fprintf(ttyout, "usage: %s [umask]\n", argv[0]); 1651 code = -1; 1652 return; 1653 } 1654 verbose = 1; |
1634 (void)command(argc == 1 ? "SITE UMASK" : "SITE UMASK %s", argv[1]); | 1655 COMMAND_1ARG(argc, argv, "SITE UMASK"); |
1635 verbose = oldverbose; 1636} 1637 1638void 1639idlecmd(int argc, char *argv[]) 1640{ 1641 int oldverbose = verbose; 1642 1643 if (argc < 1 || argc > 2) { 1644 fprintf(ttyout, "usage: %s [seconds]\n", argv[0]); 1645 code = -1; 1646 return; 1647 } 1648 verbose = 1; | 1656 verbose = oldverbose; 1657} 1658 1659void 1660idlecmd(int argc, char *argv[]) 1661{ 1662 int oldverbose = verbose; 1663 1664 if (argc < 1 || argc > 2) { 1665 fprintf(ttyout, "usage: %s [seconds]\n", argv[0]); 1666 code = -1; 1667 return; 1668 } 1669 verbose = 1; |
1649 (void)command(argc == 1 ? "SITE IDLE" : "SITE IDLE %s", argv[1]); | 1670 COMMAND_1ARG(argc, argv, "SITE IDLE"); |
1650 verbose = oldverbose; 1651} 1652 1653/* 1654 * Ask the other side for help. 1655 */ 1656void 1657rmthelp(int argc, char *argv[]) 1658{ 1659 int oldverbose = verbose; 1660 1661 if (argc == 0) { 1662 fprintf(ttyout, "usage: %s\n", argv[0]); 1663 code = -1; 1664 return; 1665 } 1666 verbose = 1; | 1671 verbose = oldverbose; 1672} 1673 1674/* 1675 * Ask the other side for help. 1676 */ 1677void 1678rmthelp(int argc, char *argv[]) 1679{ 1680 int oldverbose = verbose; 1681 1682 if (argc == 0) { 1683 fprintf(ttyout, "usage: %s\n", argv[0]); 1684 code = -1; 1685 return; 1686 } 1687 verbose = 1; |
1667 (void)command(argc == 1 ? "HELP" : "HELP %s", argv[1]); | 1688 COMMAND_1ARG(argc, argv, "HELP"); |
1668 verbose = oldverbose; 1669} 1670 1671/* 1672 * Terminate session and exit. 1673 * May be called with 0, NULL. 1674 */ 1675/*VARARGS*/ --- 111 unchanged lines hidden (view full) --- 1787 pswitch(0); 1788 (void)xsignal(SIGINT, oldintr); 1789 code = -1; 1790 return; 1791 } 1792 cmdpos = strcspn(line, " \t"); 1793 if (cmdpos > 0) /* remove leading "proxy " from input buffer */ 1794 memmove(line, line + cmdpos + 1, strlen(line) - cmdpos + 1); | 1689 verbose = oldverbose; 1690} 1691 1692/* 1693 * Terminate session and exit. 1694 * May be called with 0, NULL. 1695 */ 1696/*VARARGS*/ --- 111 unchanged lines hidden (view full) --- 1808 pswitch(0); 1809 (void)xsignal(SIGINT, oldintr); 1810 code = -1; 1811 return; 1812 } 1813 cmdpos = strcspn(line, " \t"); 1814 if (cmdpos > 0) /* remove leading "proxy " from input buffer */ 1815 memmove(line, line + cmdpos + 1, strlen(line) - cmdpos + 1); |
1816 argv[1] = c->c_name; |
|
1795 (*c->c_handler)(argc-1, argv+1); 1796 if (connected) { 1797 proxflag = 1; 1798 } 1799 else { 1800 proxflag = 0; 1801 } 1802 pswitch(0); --- 619 unchanged lines hidden (view full) --- 2422rmtstatus(int argc, char *argv[]) 2423{ 2424 2425 if (argc == 0) { 2426 fprintf(ttyout, "usage: %s [remote-file]\n", argv[0]); 2427 code = -1; 2428 return; 2429 } | 1817 (*c->c_handler)(argc-1, argv+1); 1818 if (connected) { 1819 proxflag = 1; 1820 } 1821 else { 1822 proxflag = 0; 1823 } 1824 pswitch(0); --- 619 unchanged lines hidden (view full) --- 2444rmtstatus(int argc, char *argv[]) 2445{ 2446 2447 if (argc == 0) { 2448 fprintf(ttyout, "usage: %s [remote-file]\n", argv[0]); 2449 code = -1; 2450 return; 2451 } |
2430 (void)command(argc > 1 ? "STAT %s" : "STAT" , argv[1]); | 2452 COMMAND_1ARG(argc, argv, "STAT"); |
2431} 2432 2433/* 2434 * Get file if modtime is more recent than current file 2435 */ 2436void 2437newer(int argc, char *argv[]) 2438{ --- 59 unchanged lines hidden (view full) --- 2498 pager = xmalloc(len); 2499 pager[0] = '|'; 2500 (void)strlcpy(pager + 1, p, len - 1); 2501 2502 ohash = hash; 2503 orestart_point = restart_point; 2504 overbose = verbose; 2505 hash = restart_point = verbose = 0; | 2453} 2454 2455/* 2456 * Get file if modtime is more recent than current file 2457 */ 2458void 2459newer(int argc, char *argv[]) 2460{ --- 59 unchanged lines hidden (view full) --- 2520 pager = xmalloc(len); 2521 pager[0] = '|'; 2522 (void)strlcpy(pager + 1, p, len - 1); 2523 2524 ohash = hash; 2525 orestart_point = restart_point; 2526 overbose = verbose; 2527 hash = restart_point = verbose = 0; |
2506 recvrequest("RETR", pager, argv[1], "r+w", 1, 0); | 2528 recvrequest("RETR", pager, argv[1], "r+", 1, 0); |
2507 hash = ohash; 2508 restart_point = orestart_point; 2509 verbose = overbose; 2510 (void)free(pager); 2511} 2512 2513/* 2514 * Set the socket send or receive buffer size. --- 128 unchanged lines hidden (view full) --- 2643 return; 2644 } 2645 if (! features[FEAT_MLST]) { 2646 fprintf(ttyout, 2647 "MLST is not supported by the remote server.\n"); 2648 return; 2649 } 2650 verbose = 1; /* If we aren't verbose, this doesn't do anything! */ | 2529 hash = ohash; 2530 restart_point = orestart_point; 2531 verbose = overbose; 2532 (void)free(pager); 2533} 2534 2535/* 2536 * Set the socket send or receive buffer size. --- 128 unchanged lines hidden (view full) --- 2665 return; 2666 } 2667 if (! features[FEAT_MLST]) { 2668 fprintf(ttyout, 2669 "MLST is not supported by the remote server.\n"); 2670 return; 2671 } 2672 verbose = 1; /* If we aren't verbose, this doesn't do anything! */ |
2651 (void)command(argc == 1 ? "MLST" : "MLST %s", argv[1]); | 2673 COMMAND_1ARG(argc, argv, "MLST"); |
2652 verbose = oldverbose; 2653} 2654 2655void 2656opts(int argc, char *argv[]) 2657{ 2658 int oldverbose = verbose; 2659 2660 if (argc < 2 || argc > 3) { 2661 fprintf(ttyout, "usage: %s command [options]\n", argv[0]); 2662 code = -1; 2663 return; 2664 } 2665 if (! features[FEAT_FEAT]) { 2666 fprintf(ttyout, 2667 "OPTS is not supported by the remote server.\n"); 2668 return; 2669 } 2670 verbose = 1; /* If we aren't verbose, this doesn't do anything! */ | 2674 verbose = oldverbose; 2675} 2676 2677void 2678opts(int argc, char *argv[]) 2679{ 2680 int oldverbose = verbose; 2681 2682 if (argc < 2 || argc > 3) { 2683 fprintf(ttyout, "usage: %s command [options]\n", argv[0]); 2684 code = -1; 2685 return; 2686 } 2687 if (! features[FEAT_FEAT]) { 2688 fprintf(ttyout, 2689 "OPTS is not supported by the remote server.\n"); 2690 return; 2691 } 2692 verbose = 1; /* If we aren't verbose, this doesn't do anything! */ |
2671 (void)command(argc == 2 ? "OPTS %s" : "OPTS %s %s", argv[1], argv[2]); | 2693 if (argc == 2) 2694 command("OPTS %s", argv[1]); 2695 else 2696 command("OPTS %s %s", argv[1], argv[2]); |
2672 verbose = oldverbose; 2673} | 2697 verbose = oldverbose; 2698} |