1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
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.
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 ***** */
43 static char szDefaultString
[] = PROFILE_DEFAULT_STRING
;
45 static BOOL
isTrueNumericValue(LPSTR szString
)
47 char szPrefix
[] = PROFILE_NUMERIC_PREFIX
;
48 return (strncmp(szString
, szPrefix
, strlen(szPrefix
)) == 0);
51 static LPSTR
convertStringToLPSTR(LPSTR szString
)
56 if(isTrueNumericValue(szString
))
58 char szPrefix
[] = PROFILE_NUMERIC_PREFIX
;
59 return (LPSTR
)atol(szString
+ strlen(szPrefix
));
65 DWORD
convertStringToLPSTR1(DWORD
* pdw1
)
70 DWORD dwRet
= (isTrueNumericValue((LPSTR
)(*pdw1
)) ? (fTNV1
) : 0);
72 *pdw1
= (DWORD
)convertStringToLPSTR((LPSTR
)(*pdw1
));
77 DWORD
convertStringToLPSTR2(DWORD
* pdw1
, DWORD
* pdw2
)
79 if((pdw1
== NULL
) || (pdw2
== NULL
))
82 DWORD dwRet
= (isTrueNumericValue((LPSTR
)(*pdw1
)) ? (fTNV1
) : 0)
83 | (isTrueNumericValue((LPSTR
)(*pdw2
)) ? (fTNV2
) : 0);
85 *pdw1
= (DWORD
)convertStringToLPSTR((LPSTR
)(*pdw1
));
86 *pdw2
= (DWORD
)convertStringToLPSTR((LPSTR
)(*pdw2
));
91 DWORD
convertStringToLPSTR3(DWORD
* pdw1
, DWORD
* pdw2
, DWORD
* pdw3
)
93 if((pdw1
== NULL
) || (pdw2
== NULL
) || (pdw3
== NULL
))
96 DWORD dwRet
= (isTrueNumericValue((LPSTR
)(*pdw1
)) ? (fTNV1
) : 0)
97 | (isTrueNumericValue((LPSTR
)(*pdw2
)) ? (fTNV2
) : 0)
98 | (isTrueNumericValue((LPSTR
)(*pdw3
)) ? (fTNV3
) : 0);
100 *pdw1
= (DWORD
)convertStringToLPSTR((LPSTR
)(*pdw1
));
101 *pdw2
= (DWORD
)convertStringToLPSTR((LPSTR
)(*pdw2
));
102 *pdw3
= (DWORD
)convertStringToLPSTR((LPSTR
)(*pdw3
));
107 // converts numeric value represented by string to DWORD
108 static DWORD
convertStringToDWORD(LPSTR szString
)
113 if(strcmp(szString
, szDefaultString
) == 0)
114 return DEFAULT_DWARG_VALUE
;
116 return (DWORD
)atol(szString
);
119 void convertStringToDWORD1(DWORD
* pdw1
)
123 *pdw1
= convertStringToDWORD((LPSTR
)(*pdw1
));
126 void convertStringToDWORD2(DWORD
* pdw1
, DWORD
* pdw2
)
128 if((pdw1
== NULL
) || (pdw2
== NULL
))
130 *pdw1
= convertStringToDWORD((LPSTR
)(*pdw1
));
131 *pdw2
= convertStringToDWORD((LPSTR
)(*pdw2
));
134 void convertStringToDWORD3(DWORD
* pdw1
, DWORD
* pdw2
, DWORD
* pdw3
)
136 if((pdw1
== NULL
) || (pdw2
== NULL
) || (pdw3
== NULL
))
138 *pdw1
= convertStringToDWORD((LPSTR
)(*pdw1
));
139 *pdw2
= convertStringToDWORD((LPSTR
)(*pdw2
));
140 *pdw3
= convertStringToDWORD((LPSTR
)(*pdw3
));
143 void convertStringToDWORD4(DWORD
* pdw1
, DWORD
* pdw2
, DWORD
* pdw3
, DWORD
* pdw4
)
145 if((pdw1
== NULL
) || (pdw2
== NULL
) || (pdw3
== NULL
) || (pdw4
== NULL
))
148 *pdw1
= convertStringToDWORD((LPSTR
)(*pdw1
));
149 *pdw2
= convertStringToDWORD((LPSTR
)(*pdw2
));
150 *pdw3
= convertStringToDWORD((LPSTR
)(*pdw3
));
151 *pdw4
= convertStringToDWORD((LPSTR
)(*pdw4
));
154 static NPBool
convertStringToBOOL(LPSTR szString
)
159 if(isTrueNumericValue(szString
))
161 char szPrefix
[] = PROFILE_NUMERIC_PREFIX
;
162 return (NPBool
)atol(szString
+ strlen(szPrefix
));
166 NPBool npb
= (stricmp(szString
, "TRUE") == 0) ? TRUE
: FALSE
;
171 DWORD
convertStringToBOOL1(DWORD
* pdw1
)
176 DWORD dwRet
= (isTrueNumericValue((LPSTR
)(*pdw1
)) ? (fTNV1
) : 0);
178 *pdw1
= (DWORD
)convertStringToBOOL((LPSTR
)(*pdw1
));
183 static NPReason
convertStringToNPReason(LPSTR szString
)
188 if(isTrueNumericValue(szString
))
190 char szPrefix
[] = PROFILE_NUMERIC_PREFIX
;
191 return (NPReason
)atol(szString
+ strlen(szPrefix
));
195 if(stricmp(ENTRY_NPRES_DONE
, szString
) == 0)
197 else if(stricmp(ENTRY_NPRES_NETWORK_ERR
, szString
) == 0)
198 return NPRES_NETWORK_ERR
;
199 else if(stricmp(ENTRY_NPRES_USER_BREAK
, szString
) == 0)
200 return NPRES_USER_BREAK
;
206 DWORD
convertStringToNPReason1(DWORD
* pdw1
)
211 *pdw1
= (DWORD
)convertStringToNPReason((LPSTR
)(*pdw1
));
216 static NPNVariable
convertStringToNPNVariable(LPSTR szString
)
219 return (NPNVariable
)0;
221 if(isTrueNumericValue(szString
))
223 char szPrefix
[] = PROFILE_NUMERIC_PREFIX
;
224 return (NPNVariable
)atol(szString
+ strlen(szPrefix
));
228 if(stricmp(ENTRY_NPNVXDISPLAY
, szString
) == 0)
230 else if(stricmp(ENTRY_NPNVXTAPPCONTEXT
, szString
) == 0)
231 return NPNVxtAppContext
;
232 else if(stricmp(ENTRY_NPNVNETSCAPEWINDOW
, szString
) == 0)
233 return NPNVnetscapeWindow
;
234 else if(stricmp(ENTRY_NPNVJAVASCRIPTENABLEDBOOL
, szString
) == 0)
235 return NPNVjavascriptEnabledBool
;
236 else if(stricmp(ENTRY_NPNVASDENABLEDBOOL
, szString
) == 0)
237 return NPNVasdEnabledBool
;
238 else if(stricmp(ENTRY_NPNVISOFFLINEBOOL
, szString
) == 0)
239 return NPNVisOfflineBool
;
241 return (NPNVariable
)0;
245 DWORD
convertStringToNPNVariable1(DWORD
* pdw1
)
250 DWORD dwRet
= (isTrueNumericValue((LPSTR
)(*pdw1
)) ? (fTNV1
) : 0);
252 *pdw1
= (DWORD
)convertStringToNPNVariable((LPSTR
)(*pdw1
));
257 static NPPVariable
convertStringToNPPVariable(LPSTR szString
)
260 return (NPPVariable
)0;
262 if(isTrueNumericValue(szString
))
264 char szPrefix
[] = PROFILE_NUMERIC_PREFIX
;
265 return (NPPVariable
)atol(szString
+ strlen(szPrefix
));
269 if(stricmp(ENTRY_NPPVPLUGINNAMESTRING
, szString
) == 0)
270 return NPPVpluginNameString
;
271 else if(stricmp(ENTRY_NPPVPLUGINDESCRIPTIONSTRING
, szString
) == 0)
272 return NPPVpluginDescriptionString
;
273 else if(stricmp(ENTRY_NPPVPLUGINWINDOWBOOL
, szString
) == 0)
274 return NPPVpluginWindowBool
;
275 else if(stricmp(ENTRY_NPPVPLUGINTRANSPARENTBOOL
, szString
) == 0)
276 return NPPVpluginTransparentBool
;
277 else if(stricmp(ENTRY_NPPVPLUGINKEEPLIBRARYINMEMORY
, szString
) == 0)
278 return NPPVpluginKeepLibraryInMemory
;
279 else if(stricmp(ENTRY_NPPVPLUGINWINDOWSIZE
, szString
) == 0)
280 return NPPVpluginWindowSize
;
282 return (NPPVariable
)0;
286 DWORD
convertStringToNPPVariable1(DWORD
* pdw1
)
291 DWORD dwRet
= (isTrueNumericValue((LPSTR
)(*pdw1
)) ? (fTNV1
) : 0);
293 *pdw1
= (DWORD
)convertStringToNPPVariable((LPSTR
)(*pdw1
));
298 NPByteRange
* convertStringToNPByteRangeList(LPSTR szString
)
300 NPByteRange
**brNextFromPrev
, *brList
= 0;
302 int offset
= -1, len
= -1;
304 while (EOF
!= sscanf((const char*)p
, "%d-%d", &offset
, &len
)) {
305 if (offset
== -1 || len
== -1)
307 NPByteRange
*brCurr
= new NPByteRange
;
308 brCurr
->offset
= offset
;
309 brCurr
->length
= len
;
314 *brNextFromPrev
= brCurr
;
316 brNextFromPrev
= &brCurr
->next
;
318 if (!(p
= strchr(p
, ',')))
320 while(*(++p
) == ' '); // cut off white spaces