Back to index

enigmail  1.4.3
nsEnigContentHandler.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public
00005  * License Version 1.1 (the "MPL"); you may not use this file
00006  * except in compliance with the MPL. You may obtain a copy of
00007  * the MPL at http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the MPL is distributed on an "AS
00010  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
00011  * implied. See the MPL for the specific language governing
00012  * rights and limitations under the MPL.
00013  *
00014  * The Original Code is Enigmail.
00015  *
00016  * The Initial Developer of the Original Code is Ramalingam Saravanan.
00017  * Portions created by Ramalingam Saravanan <sarava@sarava.net> are
00018  * Copyright (C) 2002 Ramalingam Saravanan. All Rights Reserved.
00019  *
00020  * Contributor(s):
00021  * Patrick Brunschwig <patrick@mozilla-enigmail.org>
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  * ***** END LICENSE BLOCK ***** */
00035 
00036 
00037 
00038 // Logging of debug output
00039 // The following define statement should occur before any include statements
00040 #define FORCE_PR_LOG       /* Allow logging even in release build */
00041 
00042 #include "enigmail.h"
00043 #include "pgpmime.h"
00044 #include "nsEnigContentHandler.h"
00045 #include "mimedummy.h"
00046 #include "mimeenig.h"
00047 #include "nspr.h"
00048 #include "plstr.h"
00049 #include "nsCOMPtr.h"
00050 #include "nsStringAPI.h"
00051 #include "nsNetUtil.h"
00052 #include "nsIThread.h"
00053 #include "nsIMimeObjectClassAccess.h"
00054 #include "nsMsgMimeCID.h"
00055 
00056 MimeContainerClass* mimeContainerClassP = NULL;
00057 
00058 #ifdef PR_LOGGING
00059 PRLogModuleInfo* gEnigContentHandlerLog = NULL;
00060 #endif
00061 
00062 #define ERROR_LOG(args)    PR_LOG(gEnigContentHandlerLog,PR_LOG_ERROR,args)
00063 #define WARNING_LOG(args)  PR_LOG(gEnigContentHandlerLog,PR_LOG_WARNING,args)
00064 #define DEBUG_LOG(args)    PR_LOG(gEnigContentHandlerLog,PR_LOG_DEBUG,args)
00065 
00066 static NS_DEFINE_CID(kMimeObjectClassAccessCID, NS_MIME_OBJECT_CLASS_ACCESS_CID);
00067 
00068 
00069 // nsEnigContentHandler implementation
00070 
00071 // nsISupports implementation
00072 NS_IMPL_THREADSAFE_ISUPPORTS1(nsEnigContentHandler,
00073                               nsIMimeContentTypeHandler)
00074 
00075 
00076 // nsEnigContentHandler implementation
00077 nsEnigContentHandler::nsEnigContentHandler()
00078   : mContentType("")
00079 {
00080   nsresult rv;
00081 
00082   NS_INIT_ISUPPORTS();
00083 
00084 #ifdef PR_LOGGING
00085   if (gEnigContentHandlerLog == nsnull) {
00086     gEnigContentHandlerLog = PR_NewLogModule("nsEnigContentHandler");
00087   }
00088 #endif
00089 
00090 #ifdef FORCE_PR_LOG
00091   nsCOMPtr<nsIThread> myThread;
00092   rv = ENIG_GET_THREAD(myThread);
00093   DEBUG_LOG(("nsEnigContentHandler:: <<<<<<<<< CTOR(%p): myThread=%p\n",
00094          this, myThread.get()));
00095 #endif
00096 }
00097 
00098 
00099 nsEnigContentHandler::~nsEnigContentHandler()
00100 {
00101   nsresult rv;
00102 #ifdef FORCE_PR_LOG
00103   nsCOMPtr<nsIThread> myThread;
00104   rv = ENIG_GET_THREAD(myThread);
00105   DEBUG_LOG(("nsEnigContentHandler:: >>>>>>>>> DTOR(%p): myThread=%p\n",
00106          this, myThread.get()));
00107 #endif
00108 
00109 }
00110 
00111 
00113 // nsIMimeContentTypeHandler methods:
00115 
00116 NS_IMETHODIMP
00117 nsEnigContentHandler::GetContentType(char **contentType)
00118 {
00119   DEBUG_LOG(("nsEnigContenthandler::GetContentType: \n"));
00120   return NS_ERROR_NOT_IMPLEMENTED;
00121 }
00122 
00123 NS_IMETHODIMP
00124 nsEnigContentHandler::CreateContentTypeHandlerClass(
00125                                     const char *content_type,
00126                                     contentTypeHandlerInitStruct *initStruct,
00127                                     MimeObjectClass **objClass)
00128 {
00129   DEBUG_LOG(("nsEnigContenthandler::CreateContentTypeHandlerClass: %s\n", content_type));
00130 
00131 #ifdef EM_OLD_MIME
00132   mContentType = content_type;
00133 
00134   *objClass = NULL;
00135 
00136   if (!PL_strcasecmp(content_type, APPLICATION_XENIGMAIL_DUMMY)) {
00137     // application/x-enigmail-dummy
00138 
00139     if (!mimeContainerClassP) {
00140       nsresult rv;
00141 
00142       nsCOMPtr<nsIMimeObjectClassAccess> mimeObjectClassAccess(do_CreateInstance(kMimeObjectClassAccessCID, &rv));
00143       if (NS_FAILED(rv))
00144         return rv;
00145 
00146       rv = mimeObjectClassAccess->GetmimeContainerClass((void **) &mimeContainerClassP);
00147       if (NS_FAILED(rv))
00148         return rv;
00149 
00150       // Set superclass by hand
00151       MimeObjectClass *clazz = (MimeObjectClass *) &mimeDummyClass;
00152       clazz->superclass = (MimeObjectClass *) mimeContainerClassP;
00153     }
00154 
00155     *objClass = (MimeObjectClass *) &mimeDummyClass;
00156 
00157     initStruct->force_inline_display = PR_FALSE;
00158 
00159     return NS_OK;
00160   }
00161 
00162   if (!PL_strcasecmp(content_type, MULTIPART_ENCRYPTED)) {
00163     // multipart/encrypted
00164 
00165     if (!mimeContainerClassP || !mimeEncryptedClassP)
00166       return NS_ERROR_FAILURE;
00167 
00168     *objClass = (MimeObjectClass *) &mimeEncryptedEnigClass;
00169 
00170     initStruct->force_inline_display = PR_FALSE;
00171 
00172     return NS_OK;
00173   }
00174 
00175   if (!PL_strcasecmp(content_type, APPLICATION_PGP)) {
00176     // application/pgp
00177 
00178     if (!mimeContainerClassP || !mimeEncryptedClassP)
00179       return NS_ERROR_FAILURE;
00180 
00181     *objClass = (MimeObjectClass *) &mimeEncryptedEnigClass;
00182 
00183     initStruct->force_inline_display = PR_FALSE;
00184 
00185     return NS_OK;
00186   }
00187 
00188   return NS_ERROR_FAILURE;
00189 #else
00190   DEBUG_LOG(("nsEnigContenthandler::CreateContentTypeHandlerClass: with nsIPgpMime\n"));
00191 
00192   return NS_OK;
00193 #endif
00194 }