Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/plugins/base/nsPluginManifestLineReader.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
 * License, v. 2.0. If a copy of the MPL was not distributed with this
4
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#ifndef nsPluginManifestLineReader_h_
7
#define nsPluginManifestLineReader_h_
8
9
#include "nspr.h"
10
#include "nsDebug.h"
11
12
#ifdef XP_WIN
13
#define PLUGIN_REGISTRY_FIELD_DELIMITER '|'
14
#else
15
0
#define PLUGIN_REGISTRY_FIELD_DELIMITER ':'
16
#endif
17
18
0
#define PLUGIN_REGISTRY_END_OF_LINE_MARKER '$'
19
20
class nsPluginManifestLineReader
21
{
22
  public:
23
    nsPluginManifestLineReader()
24
      : mLength(0)
25
0
    {
26
0
      mBase = mCur = mNext = mLimit = 0;
27
0
    }
28
0
    ~nsPluginManifestLineReader() { if (mBase) delete[] mBase; mBase=0;}
29
30
    char* Init(uint32_t flen)
31
0
    {
32
0
      mBase = mCur = mNext = new char[flen + 1];
33
0
      if (mBase) {
34
0
        mLimit = mBase + flen;
35
0
        *mLimit = 0;
36
0
      }
37
0
      mLength = 0;
38
0
      return mBase;
39
0
    }
40
41
    bool NextLine()
42
0
    {
43
0
      if (mNext >= mLimit)
44
0
        return false;
45
0
46
0
      mCur = mNext;
47
0
      mLength = 0;
48
0
49
0
      char *lastDelimiter = 0;
50
0
      while(mNext < mLimit) {
51
0
        if (IsEOL(*mNext)) {
52
0
          if (lastDelimiter) {
53
0
            if (lastDelimiter && *(mNext - 1) != PLUGIN_REGISTRY_END_OF_LINE_MARKER)
54
0
              return false;
55
0
            *lastDelimiter = '\0';
56
0
          } else {
57
0
            *mNext = '\0';
58
0
          }
59
0
60
0
          for (++mNext; mNext < mLimit; ++mNext) {
61
0
            if (!IsEOL(*mNext))
62
0
              break;
63
0
          }
64
0
          return true;
65
0
        }
66
0
        if (*mNext == PLUGIN_REGISTRY_FIELD_DELIMITER)
67
0
          lastDelimiter = mNext;
68
0
        ++mNext;
69
0
        ++mLength;
70
0
      }
71
0
      return false;
72
0
    }
73
74
    int ParseLine(char** chunks, int maxChunks)
75
0
    {
76
0
      NS_ASSERTION(mCur && maxChunks && chunks, "bad call to ParseLine");
77
0
      int found = 0;
78
0
      chunks[found++] = mCur;
79
0
80
0
      if (found < maxChunks) {
81
0
        for (char* cur = mCur; *cur; cur++) {
82
0
          if (*cur == PLUGIN_REGISTRY_FIELD_DELIMITER) {
83
0
            *cur = 0;
84
0
            chunks[found++] = cur + 1;
85
0
            if (found == maxChunks)
86
0
              break;
87
0
          }
88
0
        }
89
0
      }
90
0
      return found;
91
0
    }
92
93
0
    char*       LinePtr() { return mCur; }
94
0
    uint32_t    LineLength() { return mLength; }
95
96
0
    bool        IsEOL(char c) {return c == '\n' || c == '\r';}
97
98
    char*       mBase;
99
  private:
100
    char*       mCur;
101
    uint32_t    mLength;
102
    char*       mNext;
103
    char*       mLimit;
104
};
105
106
#endif