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 / errno.c < prev    next >
C/C++ Source or Header  |  2007-07-28  |  8KB  |  199 lines

  1. /* errno.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. static const char *gErrList[kErrLast - kErrFirst + 2] = {
  14.     "gethostname() failed",                        /* -100 */
  15.     "hostname does not include domain name",            /* -101 */
  16.     "could not set linger mode",                    /* -102 */
  17.     "could not set type of service",                /* -103 */
  18.     "could not enable out-of-band data inline",            /* -104 */
  19.     "unknown host",                            /* -105 */
  20.     "could not get a new stream socket",                /* -106 */
  21.     "could not duplicate a socket",                    /* -107 */
  22.     "fdopen for reading failed",                    /* -108 */
  23.     "fdopen for writing failed",                    /* -109 */
  24.     "getsockname failed",                        /* -110 */
  25.     "could not bind the data socket",                /* -111 */
  26.     "could not listen on the data socket",                /* -112 */
  27.     "passive mode failed",                        /* -113 */
  28.     "server sent bogus port number",                /* -114 */
  29.     "could not connect data socket",                /* -115 */
  30.     "could not accept data socket",                    /* -116 */
  31.     "could not set restart point",                    /* -117 */
  32.     "could not connect to remote host",                /* -118 */
  33.     "could not connect to remote host, but can try again",        /* -119 */
  34.     "remote host refused connection",                /* -120 */
  35.     "bad transfer type",                        /* -121 */
  36.     "invalid directory parameter",                    /* -122 */
  37.     "malloc failed",                        /* -123 */
  38.     "PWD failed",                            /* -124 */
  39.     "remote chdir failed",                        /* -125 */
  40.     "remote rmdir failed",                        /* -126 */
  41.     "bad line list",                        /* -127 */
  42.     "unimplemented option",                        /* -128 */
  43.     "unimplemented function",                    /* -129 */
  44.     "remote directory listing failed",                /* -130 */
  45.     "could not retrieve remote file",                /* -131 */
  46.     "could not send file to remote host",                /* -132 */
  47.     "file write error",                        /* -133 */
  48.     "file read error",                        /* -134 */
  49.     "socket write error",                        /* -135 */
  50.     "socket read error",                        /* -136 */
  51.     "could not open file",                        /* -137 */
  52.     "bad magic number in FTP library structure",            /* -138 */
  53.     "bad parameter given to library",                /* -139 */
  54.     "remote mkdir failed",                        /* -140 */
  55.     "remote cd .. failed",                        /* -141 */
  56.     "remote chmod failed",                        /* -142 */
  57.     "remote umask failed",                        /* -143 */
  58.     "remote delete failed",                        /* -144 */
  59.     "remote file size inquiry failed",                /* -145 */
  60.     "remote file timestamp inquiry failed",                /* -146 */
  61.     "remote transfer type change failed",                /* -147 */
  62.     "file size inquiries not understood by remote server",        /* -148 */
  63.     "file timestamp inquiries not understood by remote server",    /* -149 */
  64.     "could not rename remote file",                    /* -150 */
  65.     "could not do remote wildcard expansion",            /* -151 */
  66.     "could not set keepalive option",                /* -152 */
  67.     "remote host disconnected during login",            /* -153 */
  68.     "username was not accepted for login",                /* -154 */
  69.     "username and/or password was not accepted for login",        /* -155 */
  70.     "login failed",                            /* -156 */
  71.     "invalid reply from server",                    /* -157 */
  72.     "remote host closed control connection",            /* -158 */
  73.     "not connected",                        /* -159 */
  74.     "could not start data transfer",                /* -160 */
  75.     "data transfer failed",                        /* -161 */
  76.     "PORT failed",                            /* -162 */
  77.     "PASV failed",                            /* -163 */
  78.     "UTIME failed",                            /* -164 */
  79.     "utime requests not understood by remote server",        /* -165 */
  80.     "HELP failed",                            /* -166 */
  81.     "file deletion on local host failed",                /* -167 */
  82.     "lseek failed",                            /* -168 */
  83.     "data transfer aborted by local user",                /* -169 */
  84.     "SYMLINK failed",                        /* -170 */
  85.     "symlink requests not understood by remote server",        /* -171 */
  86.     "no match",                            /* -172 */
  87.     "server features request failed",                /* -173 */
  88.     "no valid files were specified",                /* -174 */
  89.     "file transfer buffer has not been allocated",            /* -175 */
  90.     "will not overwrite local file with older remote file",        /* -176 */
  91.     "will not overwrite remote file with older local file",        /* -177 */
  92.     "local file appears to be the same as the remote file, download is not necessary",    /* -178 */
  93.     "could not get extended directory information (MLSD)",        /* -179 */
  94.     "could not get extended file or directory information (MLST)",    /* -180 */
  95.     "could not parse extended file or directory information",    /* -181 */
  96.     "server does not support extended file or directory information",    /* -182 */
  97.     "server does not support extended directory information",    /* -183 */
  98.     "could not get information about specified file",        /* -184 */
  99.     "server does not support file or directory information",    /* -185 */
  100.     "could not get directory information about specified file",    /* -186 */
  101.     "server does not support directory information",        /* -187 */
  102.     "no such file or directory",                    /* -188 */
  103.     "server provides no way to determine file existence",        /* -189 */
  104.     "item exists, but cannot tell if it is a file or directory",    /* -190 */
  105.     "not a directory",                        /* -191 */
  106.     "directory recursion limit reached",                /* -192 */
  107.     "timed out while waiting for server response",            /* -193 */
  108.     "data transfer timed out",                    /* -194 */
  109.     "canceled by user",                        /* -195 */
  110.     "no remote host was specified",                    /* -196 */
  111.     "remote file appears to be the same as the local file, upload is not necessary",    /* -197 */
  112.     "data connection did not originate from same IP address as control connection to server",    /* -198 */
  113.     "data connection did not originate from correct port number",    /* -199 */
  114.     "internal error: bug in library code detected",            /* -200 */
  115.     "remote server does not support setting a RESTart point",    /* -201 */
  116.     "miscellaneous error occurred while trying to open the host",     /* -202 */
  117.     "miscellaneous error occurred while trying to login to the host", /* -203 */
  118.     "ascii seek error",                        /* -204 */
  119.     "you have encountered a bug that we have not fixed yet, sorry!",/* -205 */
  120.     NULL,                                
  121. };
  122.  
  123. int gLibNcFTP_Uses_Me_To_Quiet_Variable_Unused_Warnings = 0;
  124.  
  125. const char *
  126. FTPStrError(int e)
  127. {
  128.     if (e == kErrGeneric) {
  129.         return ("miscellaneous error");
  130.     } else if (e == kNoErr) {
  131.         return ("no error");
  132.     } else {
  133.         if (e < 0)
  134.             e = -e;
  135.         if ((e >= kErrFirst) && (e <= kErrLast)) {
  136.             return (gErrList[e - kErrFirst]);
  137.         }
  138.     }
  139.     return ("unrecognized error number");
  140. }    /* FTPStrError */
  141.  
  142.  
  143.  
  144.  
  145. char *
  146. FTPStrError2(const FTPCIPtr cip, int e, char *const dst, const size_t dstsize, int eerr)
  147. {
  148.     FTPLinePtr lp;
  149.  
  150.     if ((dst == NULL) || (dstsize == 0))
  151.         return NULL;
  152.  
  153.     if ((e == eerr) && (e != kNoErr)) {
  154.         (void) Strncpy(dst, "Server said:", dstsize);
  155.         for (lp = cip->lastFTPCmdResultLL.first; lp != NULL; lp = lp->next) {
  156.             (void) Strncat(dst, " ", dstsize);
  157.             (void) Strncat(dst, lp->line, dstsize);
  158.         }
  159.     } else {
  160.         (void) Strncpy(dst, FTPStrError(e), dstsize);
  161.     }
  162.     return (dst);
  163. }    /* FTPStrError2 */
  164.  
  165.  
  166.  
  167.  
  168. void
  169. FTPPerror(const FTPCIPtr cip, const int err, const int eerr, const char *const s1, const char *const s2)
  170. {
  171.     if (err != kNoErr) {
  172.         if (err == eerr) {
  173.             if ((s2 == NULL) || (s2[0] == '\0')) {
  174.                 if ((s1 == NULL) || (s1[0] == '\0')) { 
  175.                     (void) fprintf(stderr, "server said: %s\n", cip->lastFTPCmdResultStr);
  176.                 } else {
  177.                     (void) fprintf(stderr, "%s: server said: %s\n", s1, cip->lastFTPCmdResultStr);
  178.                 }
  179.             } else if ((s1 == NULL) || (s1[0] == '\0')) { 
  180.                 (void) fprintf(stderr, "%s: server said: %s\n", s2, cip->lastFTPCmdResultStr);
  181.             } else {
  182.                 (void) fprintf(stderr, "%s %s: server said: %s\n", s1, s2, cip->lastFTPCmdResultStr);
  183.             }
  184.         } else {
  185.             if ((s2 == NULL) || (s2[0] == '\0')) {
  186.                 if ((s1 == NULL) || (s1[0] == '\0')) { 
  187.                     (void) fprintf(stderr, "%s.\n", FTPStrError(err));
  188.                 } else {
  189.                     (void) fprintf(stderr, "%s: %s.\n", s1, FTPStrError(err));
  190.                 }
  191.             } else if ((s1 == NULL) || (s1[0] == '\0')) { 
  192.                 (void) fprintf(stderr, "%s: %s.\n", s2, FTPStrError(err));
  193.             } else {
  194.                 (void) fprintf(stderr, "%s %s: %s.\n", s1, s2, FTPStrError(err));
  195.             }
  196.         }
  197.     }
  198. }    /* FTPPerror */
  199.