2002-08-14 22:31:59 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2002-08-14 22:31:59 +00:00
|
|
|
|
2009-03-17 21:20:02 +00:00
|
|
|
#ifndef nsPluginManifestLineReader_h_
|
|
|
|
#define nsPluginManifestLineReader_h_
|
2002-08-14 22:31:59 +00:00
|
|
|
|
|
|
|
#include "nspr.h"
|
|
|
|
#include "nsDebug.h"
|
|
|
|
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#define PLUGIN_REGISTRY_FIELD_DELIMITER '|'
|
|
|
|
#else
|
|
|
|
#define PLUGIN_REGISTRY_FIELD_DELIMITER ':'
|
|
|
|
#endif
|
|
|
|
|
2002-08-22 22:59:43 +00:00
|
|
|
#define PLUGIN_REGISTRY_END_OF_LINE_MARKER '$'
|
|
|
|
|
2002-08-26 21:20:31 +00:00
|
|
|
class nsPluginManifestLineReader
|
2002-08-14 22:31:59 +00:00
|
|
|
{
|
2009-03-17 21:20:02 +00:00
|
|
|
public:
|
2002-08-26 21:20:31 +00:00
|
|
|
nsPluginManifestLineReader() {mBase = mCur = mNext = mLimit = 0;}
|
|
|
|
~nsPluginManifestLineReader() { if (mBase) delete[] mBase; mBase=0;}
|
2009-03-17 21:20:02 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
char* Init(uint32_t flen)
|
2002-08-14 22:31:59 +00:00
|
|
|
{
|
2009-03-17 21:20:02 +00:00
|
|
|
mBase = mCur = mNext = new char[flen + 1];
|
|
|
|
if (mBase) {
|
|
|
|
mLimit = mBase + flen;
|
|
|
|
*mLimit = 0;
|
|
|
|
}
|
|
|
|
mLength = 0;
|
|
|
|
return mBase;
|
2002-08-14 22:31:59 +00:00
|
|
|
}
|
2009-03-17 21:20:02 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool NextLine()
|
2002-08-14 22:31:59 +00:00
|
|
|
{
|
2009-03-17 21:20:02 +00:00
|
|
|
if (mNext >= mLimit)
|
2011-09-30 06:02:59 +00:00
|
|
|
return false;
|
2009-03-17 21:20:02 +00:00
|
|
|
|
|
|
|
mCur = mNext;
|
|
|
|
mLength = 0;
|
|
|
|
|
|
|
|
char *lastDelimiter = 0;
|
|
|
|
while(mNext < mLimit) {
|
|
|
|
if (IsEOL(*mNext)) {
|
|
|
|
if (lastDelimiter) {
|
|
|
|
if (lastDelimiter && *(mNext - 1) != PLUGIN_REGISTRY_END_OF_LINE_MARKER)
|
2011-09-30 06:02:59 +00:00
|
|
|
return false;
|
2009-03-17 21:20:02 +00:00
|
|
|
*lastDelimiter = '\0';
|
|
|
|
} else {
|
|
|
|
*mNext = '\0';
|
|
|
|
}
|
2002-08-22 22:59:43 +00:00
|
|
|
|
2009-03-17 21:20:02 +00:00
|
|
|
for (++mNext; mNext < mLimit; ++mNext) {
|
|
|
|
if (!IsEOL(*mNext))
|
|
|
|
break;
|
|
|
|
}
|
2011-09-30 06:02:59 +00:00
|
|
|
return true;
|
2002-08-14 22:31:59 +00:00
|
|
|
}
|
2009-03-17 21:20:02 +00:00
|
|
|
if (*mNext == PLUGIN_REGISTRY_FIELD_DELIMITER)
|
|
|
|
lastDelimiter = mNext;
|
|
|
|
++mNext;
|
|
|
|
++mLength;
|
|
|
|
}
|
2011-09-30 06:02:59 +00:00
|
|
|
return false;
|
2002-08-14 22:31:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ParseLine(char** chunks, int maxChunks)
|
|
|
|
{
|
2009-03-17 21:20:02 +00:00
|
|
|
NS_ASSERTION(mCur && maxChunks && chunks, "bad call to ParseLine");
|
|
|
|
int found = 0;
|
|
|
|
chunks[found++] = mCur;
|
|
|
|
|
|
|
|
if (found < maxChunks) {
|
|
|
|
for (char* cur = mCur; *cur; cur++) {
|
|
|
|
if (*cur == PLUGIN_REGISTRY_FIELD_DELIMITER) {
|
|
|
|
*cur = 0;
|
|
|
|
chunks[found++] = cur + 1;
|
|
|
|
if (found == maxChunks)
|
|
|
|
break;
|
|
|
|
}
|
2002-08-14 22:31:59 +00:00
|
|
|
}
|
2009-03-17 21:20:02 +00:00
|
|
|
}
|
|
|
|
return found;
|
2002-08-14 22:31:59 +00:00
|
|
|
}
|
|
|
|
|
2009-03-17 21:20:02 +00:00
|
|
|
char* LinePtr() { return mCur; }
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t LineLength() { return mLength; }
|
2002-08-14 22:31:59 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsEOL(char c) {return c == '\n' || c == '\r';}
|
2002-08-14 22:31:59 +00:00
|
|
|
|
|
|
|
char* mBase;
|
2009-03-17 21:20:02 +00:00
|
|
|
private:
|
2002-08-14 22:31:59 +00:00
|
|
|
char* mCur;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mLength;
|
2002-08-14 22:31:59 +00:00
|
|
|
char* mNext;
|
|
|
|
char* mLimit;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|