xpcom/ds/nsManifestLineReader.h

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 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsManifestLineReader_h__
michael@0 7 #define nsManifestLineReader_h__
michael@0 8
michael@0 9 #include "nspr.h"
michael@0 10 #include "nsDebug.h"
michael@0 11
michael@0 12 class nsManifestLineReader
michael@0 13 {
michael@0 14 public:
michael@0 15 nsManifestLineReader() : mBase(nullptr) {}
michael@0 16 ~nsManifestLineReader() {}
michael@0 17
michael@0 18 void Init(char* base, uint32_t flen)
michael@0 19 {
michael@0 20 mBase = mCur = mNext = base;
michael@0 21 mLength = 0;
michael@0 22 mLimit = base + flen;
michael@0 23 }
michael@0 24
michael@0 25 bool NextLine()
michael@0 26 {
michael@0 27 if(mNext >= mLimit)
michael@0 28 return false;
michael@0 29
michael@0 30 mCur = mNext;
michael@0 31 mLength = 0;
michael@0 32
michael@0 33 while(mNext < mLimit)
michael@0 34 {
michael@0 35 if(IsEOL(*mNext))
michael@0 36 {
michael@0 37 *mNext = '\0';
michael@0 38 for(++mNext; mNext < mLimit; ++mNext)
michael@0 39 if(!IsEOL(*mNext))
michael@0 40 break;
michael@0 41 return true;
michael@0 42 }
michael@0 43 ++mNext;
michael@0 44 ++mLength;
michael@0 45 }
michael@0 46 return false;
michael@0 47 }
michael@0 48
michael@0 49 int ParseLine(char** chunks, int* lengths, int maxChunks)
michael@0 50 {
michael@0 51 NS_ASSERTION(mCur && maxChunks && chunks, "bad call to ParseLine");
michael@0 52 int found = 0;
michael@0 53 chunks[found++] = mCur;
michael@0 54
michael@0 55 if(found < maxChunks)
michael@0 56 {
michael@0 57 char *lastchunk = mCur;
michael@0 58 int *lastlength = lengths;
michael@0 59 for(char* cur = mCur; *cur; cur++)
michael@0 60 {
michael@0 61 if(*cur == ',')
michael@0 62 {
michael@0 63 *cur = 0;
michael@0 64 // always fill in the previous chunk's length
michael@0 65 *lastlength++ = cur - lastchunk;
michael@0 66 chunks[found++] = lastchunk = cur+1;
michael@0 67 if(found == maxChunks)
michael@0 68 break;
michael@0 69 }
michael@0 70 }
michael@0 71 // crazy pointer math - calculate the length of the final chunk
michael@0 72 *lastlength = (mCur + mLength) - lastchunk;
michael@0 73 }
michael@0 74 return found;
michael@0 75 }
michael@0 76
michael@0 77 char* LinePtr() {return mCur;}
michael@0 78 uint32_t LineLength() {return mLength;}
michael@0 79
michael@0 80 bool IsEOL(char c) {return c == '\n' || c == '\r';}
michael@0 81 private:
michael@0 82 char* mCur;
michael@0 83 uint32_t mLength;
michael@0 84 char* mNext;
michael@0 85 char* mBase;
michael@0 86 char* mLimit;
michael@0 87 };
michael@0 88
michael@0 89 #endif

mercurial