Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / modules / plugin / base / src / nsPluginsDirUtils.h
blob11b91ecd344ad751145bd60e60f2a8ff1ad0015e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsPluginsDirUtils_h___
39 #define nsPluginsDirUtils_h___
41 #include "nsPluginsDir.h"
42 #include "nsVoidArray.h"
43 #include "prmem.h"
45 ///////////////////////////////////////////////////////////////////////////////
46 // Ouput format from NPP_GetMIMEDescription: "...mime type[;version]:[extension]:[desecription];..."
47 // The ambiguity of mime description could cause the browser fail to parse the MIME types
48 // correctly.
49 // E.g. "mime type::desecription;" // correct w/o ext
50 // "mime type:desecription;" // wrong w/o ext
52 static nsresult
53 ParsePluginMimeDescription(const char *mdesc, nsPluginInfo &info)
55 nsresult rv = NS_ERROR_FAILURE;
56 if (!mdesc || !*mdesc)
57 return rv;
59 char *mdescDup = PL_strdup(mdesc); // make a dup of intput string we'll change it content
60 char anEmptyString[] = "";
61 nsAutoVoidArray tmpMimeTypeArr;
62 char delimiters[] = {':',':',';'};
63 int mimeTypeVariantCount = 0;
64 char *p = mdescDup; // make a dup of intput string we'll change it content
65 while(p) {
66 char *ptrMimeArray[] = {anEmptyString, anEmptyString, anEmptyString};
68 // It's easy to point out ptrMimeArray[0] to the string sounds like
69 // "Mime type is not specified, plugin will not function properly."
70 // and show this on "about:plugins" page, but we have to mark this particular
71 // mime type of given plugin as disable on "about:plugins" page,
72 // which feature is not implemented yet.
73 // So we'll ignore, without any warnings, an empty description strings,
74 // in other words, if after parsing ptrMimeArray[0] == anEmptyString is true.
75 // It is possible do not to registry a plugin at all if it returns
76 // an empty string on GetMIMEDescription() call,
77 // e.g. plugger returns "" if pluggerrc file is not found.
79 char *s = p;
80 int i;
81 for (i = 0; i < (int) sizeof(delimiters) && (p = PL_strchr(s, delimiters[i])); i++) {
82 ptrMimeArray[i] = s; // save start ptr
83 *p++ = 0; // overwrite delimiter
84 s = p; // move forward
86 if (i == 2)
87 ptrMimeArray[i] = s;
88 // fill out the temp array
89 // the order is important, it should be the same in for loop below
90 if (ptrMimeArray[0] != anEmptyString) {
91 tmpMimeTypeArr.AppendElement((void*) ptrMimeArray[0]);
92 tmpMimeTypeArr.AppendElement((void*) ptrMimeArray[1]);
93 tmpMimeTypeArr.AppendElement((void*) ptrMimeArray[2]);
94 mimeTypeVariantCount++;
98 // fill out info structure
99 if (mimeTypeVariantCount) {
100 info.fVariantCount = mimeTypeVariantCount;
101 // we can do these 3 mallocs at once, later on code cleanup
102 info.fMimeTypeArray = (char **)PR_Malloc(mimeTypeVariantCount * sizeof(char *));
103 info.fMimeDescriptionArray = (char **)PR_Malloc(mimeTypeVariantCount * sizeof(char *));
104 info.fExtensionArray = (char **)PR_Malloc(mimeTypeVariantCount * sizeof(char *));
106 int j,i;
107 for (j = i = 0; i < mimeTypeVariantCount; i++) {
108 // the order is important, do not change it
109 // we can get rid of PL_strdup here, later on code cleanup
110 info.fMimeTypeArray[i] = PL_strdup((char*) tmpMimeTypeArr.ElementAt(j++));
111 info.fExtensionArray[i] = PL_strdup((char*) tmpMimeTypeArr.ElementAt(j++));
112 info.fMimeDescriptionArray[i] = PL_strdup((char*) tmpMimeTypeArr.ElementAt(j++));
114 rv = NS_OK;
116 if (mdescDup)
117 PR_Free(mdescDup);
118 return rv;
121 #endif /* nsPluginsDirUtils_h___ */