home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / libnet / mkmessag.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.0 KB  |  205 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "mkutils.h"
  20. #include "mktcp.h"
  21. #include "gui.h"
  22. #include "merrors.h"
  23. #include "xpgetstr.h"
  24. /*
  25.  * hack alert: this file contains a switch statement with a gazillion cases,
  26.  * so I'd prefer to use enums instead of extern ints in this case -- erik
  27.  */
  28. #define WANT_ENUM_STRING_IDS
  29. #include "allxpstr.h"
  30.  
  31. #ifndef XP_UNIX
  32. #include <stdarg.h>
  33. #endif /* !XP_UNIX */
  34.  
  35.  
  36. /*
  37.  * This function takes an error code and associated error data
  38.  * and creates a string containing a textual description of
  39.  * what the error is and why it happened.
  40.  *
  41.  * The returned string is allocated and thus should be freed
  42.  * once it has been used.
  43.  */
  44. PUBLIC char *
  45. NET_ExplainErrorDetails (int code, ...)
  46. {
  47.   va_list args;
  48.   char *msg = 0;
  49.   int sub_error;
  50.  
  51.   va_start (args, code);
  52.  
  53.   if (IS_SSL_ERROR(code) || IS_SEC_ERROR(code)) {
  54.       const char *s = XP_GetString(code);
  55.       msg = (s ? XP_STRDUP(s) : 0);
  56.   }
  57.  
  58.   if (!msg)
  59.     switch(code) {
  60.     case MK_INTERRUPTED:
  61.     case MK_USE_FTP_INSTEAD:
  62.     case MK_USE_COPY_FROM_CACHE:
  63.     case MK_MAILTO_NOT_READY:
  64.     case MK_UNABLE_TO_LOGIN:
  65.     case MK_UNABLE_TO_CONVERT:
  66.     case MK_IMAGE_LOSSAGE:  /* image library generic error */
  67.     case MK_ERROR_SENDING_DATA_COMMAND:
  68.     case MK_OFFLINE:
  69.         msg = NULL;
  70.         break;
  71.  
  72.     case MK_REDIRECT_ATTEMPT_NOT_ALLOWED:
  73.     case MK_SERVER_TIMEOUT:
  74.     case MK_CONNECTION_TIMED_OUT:
  75.     case MK_OUT_OF_MEMORY:
  76.     case MK_TIMEBOMB_URL_PROHIBIT:
  77.     case MK_TIMEBOMB_MESSAGE:
  78.     case MK_RELATIVE_TIMEBOMB_MESSAGE:
  79.     case MK_NO_WAIS_PROXY:
  80.     case MK_CREATING_NEWSRC_FILE:
  81.     case MK_NNTP_SERVER_NOT_CONFIGURED:
  82.     case MK_NNTP_NEWSGROUP_SCAN_ERROR:
  83.     case MK_ZERO_LENGTH_FILE:
  84.     case MK_BAD_CONNECT:
  85.     case MK_UNABLE_TO_USE_PASV_FTP:
  86.     case MK_UNABLE_TO_CHANGE_FTP_MODE:
  87.     case MK_UNABLE_TO_FTP_CWD:
  88.     case MK_UNABLE_TO_SEND_PORT_COMMAND:
  89.     case MK_UNABLE_TO_ACCEPT_SOCKET:
  90.     case MK_UNABLE_TO_CONNECT2:
  91.     case MK_BAD_NNTP_CONNECTION:
  92.     case MK_NNTP_SERVER_ERROR:
  93.     case MK_SERVER_DISCONNECTED:
  94.     case MK_NEWS_ITEM_UNAVAILABLE:
  95.     case MK_UNABLE_TO_OPEN_NEWSRC:
  96.     case MK_COULD_NOT_LOGIN_TO_SMTP_SERVER:
  97.     case MK_MSG_NO_SMTP_HOST:
  98.     case MK_COULD_NOT_GET_USERS_MAIL_ADDRESS:
  99.     case MK_UNABLE_TO_CONNECT_TO_PROXY:
  100.     case MK_UNABLE_TO_LOCATE_PROXY:
  101.     case MK_DISK_FULL:
  102.     case MK_PRINT_LOSSAGE:
  103.     case MK_SECURE_NEWS_PROXY_ERROR:
  104.     case MK_SIGNATURE_TOO_LONG:
  105.     case MK_SIGNATURE_TOO_WIDE:
  106.     case MK_POP3_SERVER_ERROR:
  107.     case MK_POP3_USERNAME_UNDEFINED:
  108.     case MK_POP3_PASSWORD_UNDEFINED:
  109.     case MK_POP3_USERNAME_FAILURE:
  110.     case MK_POP3_PASSWORD_FAILURE:
  111.     case MK_POP3_NO_MESSAGES:
  112.     case MK_POP3_LIST_FAILURE:
  113.     case MK_POP3_LAST_FAILURE:
  114.     case MK_POP3_RETR_FAILURE:
  115.     case MK_POP3_DELE_FAILURE:
  116.     case MK_POP3_OUT_OF_DISK_SPACE:
  117.     case MK_POP3_MESSAGE_WRITE_ERROR:
  118.     case MK_MIME_NO_SENDER:
  119.     case MK_MIME_NO_RECIPIENTS:
  120.     case MK_MIME_NO_SUBJECT:
  121.     case MK_MIME_ERROR_WRITING_FILE:
  122.     case MK_MIME_MULTIPART_BLURB:
  123.     case MK_MSG_CANT_COPY_TO_SAME_FOLDER:
  124.     case MK_MSG_CANT_COPY_TO_QUEUE_FOLDER:
  125.     case MK_MSG_CANT_COPY_TO_QUEUE_FOLDER_OLD:
  126.     case MK_MSG_CANT_COPY_TO_DRAFTS_FOLDER:
  127.     case MK_MSG_CANT_CREATE_FOLDER:
  128.     case MK_MSG_FOLDER_ALREADY_EXISTS:
  129.     case MK_MSG_FOLDER_NOT_EMPTY:
  130.     case MK_MSG_CANT_DELETE_FOLDER:
  131.     case MK_MSG_CANT_CREATE_INBOX:
  132.     case MK_MSG_CANT_CREATE_MAIL_DIR:
  133.     case MK_MSG_NO_POP_HOST:
  134.     case MK_MSG_MESSAGE_CANCELLED:
  135.     case MK_MSG_FOLDER_UNREADABLE:
  136.     case MK_MSG_FOLDER_SUMMARY_UNREADABLE:
  137.     case MK_MSG_TMP_FOLDER_UNWRITABLE:
  138.     case MK_MSG_ID_NOT_IN_FOLDER:
  139.     case MK_MSG_NEWSRC_UNPARSABLE:
  140.     case MK_MSG_NO_RETURN_ADDRESS:
  141.     case MK_MSG_ERROR_WRITING_NEWSRC:
  142.     case MK_MSG_ERROR_WRITING_MAIL_FOLDER:
  143.     case MK_MSG_SEARCH_FAILED:
  144.     case MK_MSG_FOLDER_BUSY:
  145.         msg = XP_STRDUP(XP_GetString(code));
  146.         break;
  147.  
  148.     case MK_TCP_READ_ERROR:
  149.     case MK_TCP_WRITE_ERROR:
  150.     case MK_UNABLE_TO_CREATE_SOCKET:
  151.     case MK_UNABLE_TO_CONNECT:
  152.     case MK_HTTP_TYPE_CONFLICT:
  153.     case MK_TCP_ERROR:
  154.         sub_error = va_arg(args, int);
  155.         if (IS_SSL_ERROR(sub_error) || IS_SEC_ERROR(sub_error)) {
  156.             /*
  157.              * For SSL/SEC errors, use the message without a wrapper.
  158.              */
  159.             msg = XP_STRDUP(XP_GetString(sub_error));
  160.         } else if (code == MK_UNABLE_TO_CONNECT &&
  161.                    (sub_error == XP_ERRNO_EINVAL
  162.                     || sub_error == XP_ERRNO_EADDRINUSE)) {
  163.             /*
  164.              * With unable-to-connect errors, some errno values/strings
  165.              * are not more helpful, so just use a plain message for these.
  166.              */
  167.             msg = XP_STRDUP(XP_GetString(MK_UNABLE_TO_CONNECT2));
  168.         } else {
  169.             msg = PR_smprintf(XP_GetString(code), XP_GetString(sub_error));
  170.         }
  171.         break;
  172.  
  173.     case MK_MALFORMED_URL_ERROR:
  174.     case MK_COULD_NOT_PUT_FILE:
  175.     case MK_UNABLE_TO_LOCATE_FILE:
  176.     case MK_NNTP_AUTH_FAILED:
  177.     case MK_UNABLE_TO_LOCATE_HOST:
  178.     case MK_UNABLE_TO_LOCATE_SOCKS_HOST:
  179.     case MK_UNABLE_TO_OPEN_FILE:
  180.     case MK_UNABLE_TO_OPEN_TMP_FILE:
  181.     case MK_CONNECTION_REFUSED:
  182.     case MK_NNTP_ERROR_MESSAGE:
  183.     case MK_MSG_COULDNT_OPEN_FCC_FILE:
  184.     case MK_TIMEBOMB_WARNING_MESSAGE:
  185.     case MK_RELATIVE_TIMEBOMB_WARNING_MESSAGE:
  186.     case MK_ERROR_SENDING_FROM_COMMAND:
  187.     case MK_ERROR_SENDING_RCPT_COMMAND:
  188.     case MK_ERROR_SENDING_MESSAGE:
  189.     case MK_SMTP_SERVER_ERROR:
  190.         msg = PR_vsmprintf(XP_GetString(code), args);
  191.         break;
  192.  
  193.     case -1:
  194.     default:
  195.         msg = PR_smprintf(XP_GetString(MK_COMMUNICATIONS_ERROR), code);
  196.         break;
  197.     }
  198.  
  199.   va_end (args);
  200.  
  201.   TRACEMSG(("NET_ExplainErrorDetails generated: %s", msg ? msg : "(none)"));
  202.  
  203.   return(msg);
  204. }
  205.