~ubuntu-branches/ubuntu/precise/enigmail/precise-security

« back to all changes in this revision

Viewing changes to extensions/enigmail/src/nsEnigContentHandler.cpp

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-11-12 16:36:01 UTC
  • mfrom: (0.12.15)
  • Revision ID: package-import@ubuntu.com-20121112163601-t8e8skdfi3ni9iqp
Tags: 2:1.4.6-0ubuntu0.12.04.1
* New upstream release v1.4.6
  - see LP: #1080212 for USN information
* Drop unneeded patches
  - remove debian/patches/correct-version-number.diff
  - remove debian/patches/dont_register_cids_multiple_times.diff
  - update debian/patches/series
* Support building in an objdir
  - update debian/rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ***** BEGIN LICENSE BLOCK *****
2
 
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3
 
 *
4
 
 * The contents of this file are subject to the Mozilla Public
5
 
 * License Version 1.1 (the "MPL"); you may not use this file
6
 
 * except in compliance with the MPL. You may obtain a copy of
7
 
 * the MPL at http://www.mozilla.org/MPL/
8
 
 *
9
 
 * Software distributed under the MPL is distributed on an "AS
10
 
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11
 
 * implied. See the MPL for the specific language governing
12
 
 * rights and limitations under the MPL.
13
 
 *
14
 
 * The Original Code is Enigmail.
15
 
 *
16
 
 * The Initial Developer of the Original Code is Ramalingam Saravanan.
17
 
 * Portions created by Ramalingam Saravanan <sarava@sarava.net> are
18
 
 * Copyright (C) 2002 Ramalingam Saravanan. All Rights Reserved.
19
 
 *
20
 
 * Contributor(s):
21
 
 * Patrick Brunschwig <patrick@mozilla-enigmail.org>
22
 
 *
23
 
 * Alternatively, the contents of this file may be used under the terms of
24
 
 * either the GNU General Public License Version 2 or later (the "GPL"), or
25
 
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26
 
 * in which case the provisions of the GPL or the LGPL are applicable instead
27
 
 * of those above. If you wish to allow use of your version of this file only
28
 
 * under the terms of either the GPL or the LGPL, and not to allow others to
29
 
 * use your version of this file under the terms of the MPL, indicate your
30
 
 * decision by deleting the provisions above and replace them with the notice
31
 
 * and other provisions required by the GPL or the LGPL. If you do not delete
32
 
 * the provisions above, a recipient may use your version of this file under
33
 
 * the terms of any one of the MPL, the GPL or the LGPL.
34
 
 * ***** END LICENSE BLOCK ***** */
35
 
 
36
 
 
37
 
 
38
 
// Logging of debug output
39
 
// The following define statement should occur before any include statements
40
 
#define FORCE_PR_LOG       /* Allow logging even in release build */
41
 
 
42
 
#include "enigmail.h"
43
 
#include "pgpmime.h"
44
 
#include "nsEnigContentHandler.h"
45
 
#include "mimedummy.h"
46
 
#include "mimeenig.h"
47
 
#include "nspr.h"
48
 
#include "plstr.h"
49
 
#include "nsCOMPtr.h"
50
 
#include "nsStringAPI.h"
51
 
#include "nsNetUtil.h"
52
 
#include "nsIThread.h"
53
 
#include "nsIMimeObjectClassAccess.h"
54
 
#include "nsMsgMimeCID.h"
55
 
 
56
 
MimeContainerClass* mimeContainerClassP = NULL;
57
 
 
58
 
#ifdef PR_LOGGING
59
 
PRLogModuleInfo* gEnigContentHandlerLog = NULL;
60
 
#endif
61
 
 
62
 
#define ERROR_LOG(args)    PR_LOG(gEnigContentHandlerLog,PR_LOG_ERROR,args)
63
 
#define WARNING_LOG(args)  PR_LOG(gEnigContentHandlerLog,PR_LOG_WARNING,args)
64
 
#define DEBUG_LOG(args)    PR_LOG(gEnigContentHandlerLog,PR_LOG_DEBUG,args)
65
 
 
66
 
static NS_DEFINE_CID(kMimeObjectClassAccessCID, NS_MIME_OBJECT_CLASS_ACCESS_CID);
67
 
 
68
 
 
69
 
// nsEnigContentHandler implementation
70
 
 
71
 
// nsISupports implementation
72
 
NS_IMPL_THREADSAFE_ISUPPORTS1(nsEnigContentHandler,
73
 
                              nsIMimeContentTypeHandler)
74
 
 
75
 
 
76
 
// nsEnigContentHandler implementation
77
 
nsEnigContentHandler::nsEnigContentHandler()
78
 
  : mContentType("")
79
 
{
80
 
  nsresult rv;
81
 
 
82
 
  NS_INIT_ISUPPORTS();
83
 
 
84
 
#ifdef PR_LOGGING
85
 
  if (gEnigContentHandlerLog == NULL) {
86
 
    gEnigContentHandlerLog = PR_NewLogModule("nsEnigContentHandler");
87
 
  }
88
 
#endif
89
 
 
90
 
#ifdef FORCE_PR_LOG
91
 
  nsCOMPtr<nsIThread> myThread;
92
 
  rv = ENIG_GET_THREAD(myThread);
93
 
  DEBUG_LOG(("nsEnigContentHandler:: <<<<<<<<< CTOR(%p): myThread=%p\n",
94
 
         this, myThread.get()));
95
 
#endif
96
 
}
97
 
 
98
 
 
99
 
nsEnigContentHandler::~nsEnigContentHandler()
100
 
{
101
 
  nsresult rv;
102
 
#ifdef FORCE_PR_LOG
103
 
  nsCOMPtr<nsIThread> myThread;
104
 
  rv = ENIG_GET_THREAD(myThread);
105
 
  DEBUG_LOG(("nsEnigContentHandler:: >>>>>>>>> DTOR(%p): myThread=%p\n",
106
 
         this, myThread.get()));
107
 
#endif
108
 
 
109
 
}
110
 
 
111
 
 
112
 
///////////////////////////////////////////////////////////////////////////////
113
 
// nsIMimeContentTypeHandler methods:
114
 
///////////////////////////////////////////////////////////////////////////////
115
 
 
116
 
NS_IMETHODIMP
117
 
nsEnigContentHandler::GetContentType(char **contentType)
118
 
{
119
 
  DEBUG_LOG(("nsEnigContenthandler::GetContentType: \n"));
120
 
  return NS_ERROR_NOT_IMPLEMENTED;
121
 
}
122
 
 
123
 
NS_IMETHODIMP
124
 
nsEnigContentHandler::CreateContentTypeHandlerClass(
125
 
                                    const char *content_type,
126
 
                                    contentTypeHandlerInitStruct *initStruct,
127
 
                                    MimeObjectClass **objClass)
128
 
{
129
 
  DEBUG_LOG(("nsEnigContenthandler::CreateContentTypeHandlerClass: %s\n", content_type));
130
 
 
131
 
#ifdef EM_OLD_MIME
132
 
  mContentType = content_type;
133
 
 
134
 
  *objClass = NULL;
135
 
 
136
 
  if (!PL_strcasecmp(content_type, APPLICATION_XENIGMAIL_DUMMY)) {
137
 
    // application/x-enigmail-dummy
138
 
 
139
 
    if (!mimeContainerClassP) {
140
 
      nsresult rv;
141
 
 
142
 
      nsCOMPtr<nsIMimeObjectClassAccess> mimeObjectClassAccess(do_CreateInstance(kMimeObjectClassAccessCID, &rv));
143
 
      if (NS_FAILED(rv))
144
 
        return rv;
145
 
 
146
 
      rv = mimeObjectClassAccess->GetmimeContainerClass((void **) &mimeContainerClassP);
147
 
      if (NS_FAILED(rv))
148
 
        return rv;
149
 
 
150
 
      // Set superclass by hand
151
 
      MimeObjectClass *clazz = (MimeObjectClass *) &mimeDummyClass;
152
 
      clazz->superclass = (MimeObjectClass *) mimeContainerClassP;
153
 
    }
154
 
 
155
 
    *objClass = (MimeObjectClass *) &mimeDummyClass;
156
 
 
157
 
    initStruct->force_inline_display = PR_FALSE;
158
 
 
159
 
    return NS_OK;
160
 
  }
161
 
 
162
 
  if (!PL_strcasecmp(content_type, MULTIPART_ENCRYPTED)) {
163
 
    // multipart/encrypted
164
 
 
165
 
    if (!mimeContainerClassP || !mimeEncryptedClassP)
166
 
      return NS_ERROR_FAILURE;
167
 
 
168
 
    *objClass = (MimeObjectClass *) &mimeEncryptedEnigClass;
169
 
 
170
 
    initStruct->force_inline_display = PR_FALSE;
171
 
 
172
 
    return NS_OK;
173
 
  }
174
 
 
175
 
  if (!PL_strcasecmp(content_type, APPLICATION_PGP)) {
176
 
    // application/pgp
177
 
 
178
 
    if (!mimeContainerClassP || !mimeEncryptedClassP)
179
 
      return NS_ERROR_FAILURE;
180
 
 
181
 
    *objClass = (MimeObjectClass *) &mimeEncryptedEnigClass;
182
 
 
183
 
    initStruct->force_inline_display = PR_FALSE;
184
 
 
185
 
    return NS_OK;
186
 
  }
187
 
 
188
 
  return NS_ERROR_FAILURE;
189
 
#else
190
 
  DEBUG_LOG(("nsEnigContenthandler::CreateContentTypeHandlerClass: with nsIPgpMime\n"));
191
 
 
192
 
  return NS_OK;
193
 
#endif
194
 
}