home *** CD-ROM | disk | FTP | other *** search
/ ftp.ncftp.com / ftp.ncftp.com.zip / ftp.ncftp.com / ncftp / older_versions / ncftp-3.2.2-src.tar.bz2 / ncftp-3.2.2-src.tar / ncftp-3.2.2 / libncftp / u_feat.c < prev    next >
C/C++ Source or Header  |  2007-07-29  |  4KB  |  213 lines

  1. /* u_feat.c
  2.  *
  3.  * Copyright (c) 1996-2005 Mike Gleason, NcFTP Software.
  4.  * All rights reserved.
  5.  *
  6.  */
  7.  
  8. #include "syshdrs.h"
  9. #ifdef PRAGMA_HDRSTOP
  10. #    pragma hdrstop
  11. #endif
  12.  
  13. int 
  14. StrToBoolOrInt(const char *s)
  15. {
  16.     int c;
  17.     int result;
  18.  
  19.     for (;;) {
  20.         c = *s++;
  21.         if (c == '\0')
  22.             return 0;
  23.         if (!isspace(c))
  24.             break;
  25.     }
  26.  
  27.     if (isupper(c))
  28.         c = tolower(c);
  29.     result = 0;
  30.     switch (c) {
  31.         case 'f':                   /* false */
  32.         case 'n':                   /* no */
  33.             break;
  34.         case 'o':                   /* test for "off" and "on" */
  35.             c = (int) s[1];
  36.             if (isupper(c))
  37.                 c = tolower(c);
  38.             if (c == 'f')
  39.                 break;
  40.             result = 1;
  41.             break;
  42.         case 't':                   /* true */
  43.         case 'y':                   /* yes */
  44.             result = 1;
  45.             break;
  46.         default:                   /* 1, 0, -1, other number? */
  47.             result = atoi(s - 1);
  48.     }
  49.     return result;
  50. }                               /* StrToBoolOrInt */
  51.  
  52.  
  53.  
  54.  
  55. static const char *gConnInfoOptStrings[] = {
  56.     "PASV",
  57.     "SIZE",
  58.     "MDTM",
  59.     "MDTM_set",
  60.     "REST",
  61.     "NLST_a",
  62.     "NLST_d",
  63.     "FEAT",
  64.     "MLSD",
  65.     "MLST",
  66.     "CLNT",
  67.     "HELP_SITE",
  68.     "SITE_UTIME",
  69.     "STATfileParamWorks",
  70.     "NLSTfileParamWorks",
  71.     "require20",
  72.     "allowProxyForPORT",
  73.     "doNotGetStartCWD",
  74.     NULL
  75. };
  76.  
  77. typedef enum ConnInfoOptions {
  78.     kOptPASV,
  79.     kOptSIZE,
  80.     kOptMDTM,
  81.     kOptMDTM_set,
  82.     kOptREST,
  83.     kOptNLST_a,
  84.     kOptNLST_d,
  85.     kOptFEAT,
  86.     kOptMLSD,
  87.     kOptMLST,
  88.     kOptCLNT,
  89.     kOptHELP_SITE,
  90.     kOptSITE_UTIME,
  91.     kOptSTATfileParamWorks,
  92.     kOptNLSTfileParamWorks,
  93.     kOptRequire20,
  94.     kOptAllowProxyForPORT,
  95.     kOptDoNotGetStartCWD,
  96.     kOptNumConnInfoOptions
  97. } ConnInfoOptions;
  98.  
  99.  
  100.  
  101.  
  102.  
  103. void
  104. FTPManualOverrideFeatures(const FTPCIPtr cip)
  105. {
  106.     char tokbuf[256];
  107.     char *parse;
  108.     char *context;
  109.     char *opt;
  110.     int intval;
  111.     char *charval;
  112.     const char **optlist;
  113.     ConnInfoOptions optnum;
  114.     
  115.     /* Example:
  116.      *    your_ftp_prog -o "hasPASV=1,!HELP_SITE,require20=0" ...
  117.      * Have your program set cip->manualOverrideFeatures to that option string.
  118.      */
  119.      
  120.     if ((cip->manualOverrideFeatures == NULL) || (cip->manualOverrideFeatures[0] == '\0'))
  121.         return;
  122.         
  123.     STRNCPY(tokbuf, cip->manualOverrideFeatures);
  124.     
  125.     for (   parse = tokbuf, context = NULL;
  126.         ((opt = strtokc(parse, ",;\n\t\r", &context)) != NULL);
  127.         parse = NULL)
  128.     {
  129.         intval = 1;
  130.         charval = strchr(opt, '=');
  131.         if (charval != NULL) {
  132.             *charval++ = '\0';
  133.             intval = StrToBoolOrInt(charval);
  134.         } else if (*opt == '!') {
  135.             opt++;
  136.             intval = 0;
  137.         }
  138.         if (ISTRNEQ(opt, "has", 3))
  139.             opt += 3;
  140.         if (ISTRNEQ(opt, "use", 3))
  141.             opt += 3;
  142.         if (ISTRNEQ(opt, "have", 4))
  143.             opt += 4;
  144.         if (ISTRNEQ(opt, "no", 2)) {
  145.             opt += 2;
  146.             intval = 0;
  147.         }
  148.         for (optlist = gConnInfoOptStrings, optnum = kOptPASV; *optlist != NULL; optlist++, optnum++) {
  149.             if (ISTREQ(opt, *optlist)) {
  150.                 switch (optnum) {
  151.                     case kOptPASV:
  152.                         cip->hasPASV = intval;
  153.                         break;
  154.                     case kOptSIZE:
  155.                         cip->hasSIZE = intval;
  156.                         break;
  157.                     case kOptMDTM:
  158.                         cip->hasMDTM = intval;
  159.                         break;
  160.                     case kOptMDTM_set:
  161.                         cip->hasMDTM_set = intval;
  162.                         break;
  163.                     case kOptREST:
  164.                         cip->hasREST = intval;
  165.                         break;
  166.                     case kOptNLST_a:
  167.                         cip->hasNLST_a = intval;
  168.                         break;
  169.                     case kOptNLST_d:
  170.                         cip->hasNLST_d = intval;
  171.                         break;
  172.                     case kOptFEAT:
  173.                         cip->hasFEAT = intval;
  174.                         break;
  175.                     case kOptMLSD:
  176.                         cip->hasMLSD = intval;
  177.                         break;
  178.                     case kOptMLST:
  179.                         cip->hasMLST = intval;
  180.                         break;
  181.                     case kOptCLNT:
  182.                         cip->hasCLNT = intval;
  183.                         break;
  184.                     case kOptHELP_SITE:
  185.                         cip->hasHELP_SITE = intval;
  186.                         break;
  187.                     case kOptSITE_UTIME:
  188.                         cip->hasSITE_UTIME = intval;
  189.                         break;
  190.                     case kOptSTATfileParamWorks:
  191.                         cip->STATfileParamWorks = intval;
  192.                         break;
  193.                     case kOptNLSTfileParamWorks:
  194.                         cip->NLSTfileParamWorks = intval;
  195.                         break;
  196.                     case kOptRequire20:
  197.                         cip->require20 = intval;
  198.                         break;
  199.                     case kOptAllowProxyForPORT:
  200.                         cip->allowProxyForPORT = intval;
  201.                         break;
  202.                     case kOptDoNotGetStartCWD:
  203.                         cip->doNotGetStartingWorkingDirectory = intval;
  204.                         break;
  205.                     case kOptNumConnInfoOptions:
  206.                         break;
  207.                 }
  208.                 break;    
  209.             }
  210.         }
  211.     }
  212. }
  213.