File: ParseRules.cc

package info (click to toggle)
trafficserver 3.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 17,428 kB
  • sloc: cpp: 222,273; sh: 12,193; ansic: 8,967; makefile: 1,809; perl: 1,158; java: 277; lex: 124; yacc: 63; sed: 6
file content (178 lines) | stat: -rw-r--r-- 4,869 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/** @file

  A brief file description

  @section license License

  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
 */

/*************************** -*- Mod: C++ -*- ******************************

   ParseRules.h --


 ****************************************************************************/

#include "libts.h"      /* MAGIC_EDITING_TAG */

const unsigned int parseRulesCType[256] = {
#include "ParseRulesCType"
};
const char parseRulesCTypeToUpper[256] = {
#include "ParseRulesCTypeToUpper"
};
const char parseRulesCTypeToLower[256] = {
#include "ParseRulesCTypeToLower"
};

unsigned char *
ParseRules::scan_while(unsigned char *ptr, unsigned int n, uint32_t bitmask)
{
  unsigned int i;
  uint32_t *wptr;
  unsigned char *align_ptr;
  uintptr_t f_bytes, b_bytes, words, align_off;

  align_off = ((uintptr_t) ptr & 3);
  align_ptr = (unsigned char *) (((uintptr_t) ptr) & ~3);

  f_bytes = (align_off ? 4 - align_off : 0);

  words = (n - f_bytes) >> 2;

  if (words == 0) {
    for (i = 0; i < n; i++)
      if (!is_type(ptr[i], bitmask))
        return (&ptr[i]);
  } else {
    wptr = ((uint32_t *) align_ptr) + (align_off ? 1 : 0);
    switch (align_off) {
    case 1:
      if (!is_type(align_ptr[1], bitmask))
        return (&ptr[1]);
    case 2:
      if (!is_type(align_ptr[2], bitmask))
        return (&ptr[2]);
    case 3:
      if (!is_type(align_ptr[3], bitmask))
        return (&ptr[3]);
      break;
    default:
      break;
    }

    b_bytes = n - ((words << 2) + f_bytes);

    for (i = 0; i < words; i++) {
      uint32_t word = wptr[i];
      uint32_t result = (is_type(((word >> 0) & 0xFF), bitmask) &
                       is_type(((word >> 8) & 0xFF), bitmask) &
                       is_type(((word >> 16) & 0xFF), bitmask) & is_type(((word >> 24) & 0xFF), bitmask));
      if (result == 0) {
        unsigned char *cptr = (unsigned char *) &(wptr[i]);
        if (!is_type(cptr[0], bitmask))
          return (&cptr[0]);
        if (!is_type(cptr[1], bitmask))
          return (&cptr[1]);
        if (!is_type(cptr[2], bitmask))
          return (&cptr[2]);
        return (&cptr[3]);
      }
    }

    align_ptr = (unsigned char *) &(wptr[words]);

    switch (b_bytes) {
    case 1:
      if (!is_type(align_ptr[0], bitmask))
        return (&align_ptr[0]);
      break;
    case 2:
      if (!is_type(align_ptr[0], bitmask))
        return (&align_ptr[0]);
      if (!is_type(align_ptr[1], bitmask))
        return (&align_ptr[1]);
      break;
    case 3:
      if (!is_type(align_ptr[0], bitmask))
        return (&align_ptr[0]);
      if (!is_type(align_ptr[1], bitmask))
        return (&align_ptr[1]);
      if (!is_type(align_ptr[2], bitmask))
        return (&align_ptr[2]);
      break;
    default:
      break;
    }
  }
  return 0;
}


void
ParseRules::ink_tolower_buffer(char *ptr, unsigned int n)
{
  unsigned int i;

  if (n < 8) {
    for (i = 0; i < n; i++)
      ptr[i] = ParseRules::ink_tolower(ptr[i]);
  } else {
    uintptr_t fpad = 4 - ((uintptr_t) ptr & 3);
    uintptr_t words = (n - fpad) >> 2;
    uintptr_t bpad = n - fpad - (words << 2);

    switch (fpad) {
    case 3:
      *ptr = ParseRules::ink_tolower(*ptr);
      ++ptr;
    case 2:
      *ptr = ParseRules::ink_tolower(*ptr);
      ++ptr;
    case 1:
      *ptr = ParseRules::ink_tolower(*ptr);
      ++ptr;
    default:
      break;
    }

    uint32_t *wptr = (uint32_t *) ptr;
    for (i = 0; i < words; i++) {
      uint32_t word = *wptr;
      ((unsigned char *) &word)[0] = ParseRules::ink_tolower(((unsigned char *) &word)[0]);
      ((unsigned char *) &word)[1] = ParseRules::ink_tolower(((unsigned char *) &word)[1]);
      ((unsigned char *) &word)[2] = ParseRules::ink_tolower(((unsigned char *) &word)[2]);
      ((unsigned char *) &word)[3] = ParseRules::ink_tolower(((unsigned char *) &word)[3]);
      *wptr++ = word;
    }

    switch (bpad) {
    case 3:
      *ptr = ParseRules::ink_tolower(*ptr);
      ++ptr;
    case 2:
      *ptr = ParseRules::ink_tolower(*ptr);
      ++ptr;
    case 1:
      *ptr = ParseRules::ink_tolower(*ptr);
      ++ptr;
    default:
      break;
    }
  }
}