xpcom/tests/TestINIParser.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include <string.h>
michael@0 6
michael@0 7 #include "nsXPCOM.h"
michael@0 8 #include "nsINIParser.h"
michael@0 9 #include "nsIFile.h"
michael@0 10
michael@0 11 static bool
michael@0 12 StringCB(const char *aKey, const char *aValue, void* aClosure)
michael@0 13 {
michael@0 14 printf("%s=%s\n", aKey, aValue);
michael@0 15
michael@0 16 return true;
michael@0 17 }
michael@0 18
michael@0 19 static bool
michael@0 20 SectionCB(const char *aSection, void* aClosure)
michael@0 21 {
michael@0 22 nsINIParser *ini = reinterpret_cast<nsINIParser*>(aClosure);
michael@0 23
michael@0 24 printf("[%s]\n", aSection);
michael@0 25
michael@0 26 ini->GetStrings(aSection, StringCB, nullptr);
michael@0 27
michael@0 28 printf("\n");
michael@0 29
michael@0 30 return true;
michael@0 31 }
michael@0 32
michael@0 33 int main(int argc, char **argv)
michael@0 34 {
michael@0 35 if (argc < 2) {
michael@0 36 fprintf(stderr, "Usage: %s <ini-file>\n", argv[0]);
michael@0 37 return 255;
michael@0 38 }
michael@0 39
michael@0 40 nsCOMPtr<nsIFile> lf;
michael@0 41
michael@0 42 nsresult rv = NS_NewNativeLocalFile(nsDependentCString(argv[1]),
michael@0 43 true,
michael@0 44 getter_AddRefs(lf));
michael@0 45 if (NS_FAILED(rv)) {
michael@0 46 fprintf(stderr, "Error: NS_NewNativeLocalFile failed\n");
michael@0 47 return 1;
michael@0 48 }
michael@0 49
michael@0 50 nsINIParser ini;
michael@0 51 rv = ini.Init(lf);
michael@0 52 if (NS_FAILED(rv)) {
michael@0 53 fprintf(stderr, "Error: Init failed.");
michael@0 54 return 2;
michael@0 55 }
michael@0 56
michael@0 57 ini.GetSections(SectionCB, &ini);
michael@0 58
michael@0 59 return 0;
michael@0 60 }
michael@0 61

mercurial