/src/php-src/ext/uri/uriparser/src/UriIp4Base.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * uriparser - RFC 3986 URI parsing library |
3 | | * |
4 | | * Copyright (C) 2007, Weijia Song <songweijia@gmail.com> |
5 | | * Copyright (C) 2007, Sebastian Pipping <sebastian@pipping.org> |
6 | | * All rights reserved. |
7 | | * |
8 | | * Redistribution and use in source and binary forms, with or without |
9 | | * modification, are permitted provided that the following conditions |
10 | | * are met: |
11 | | * |
12 | | * 1. Redistributions of source code must retain the above |
13 | | * copyright notice, this list of conditions and the following |
14 | | * disclaimer. |
15 | | * |
16 | | * 2. Redistributions in binary form must reproduce the above |
17 | | * copyright notice, this list of conditions and the following |
18 | | * disclaimer in the documentation and/or other materials |
19 | | * provided with the distribution. |
20 | | * |
21 | | * 3. Neither the name of the copyright holder nor the names of |
22 | | * its contributors may be used to endorse or promote products |
23 | | * derived from this software without specific prior written |
24 | | * permission. |
25 | | * |
26 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
27 | | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
28 | | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
29 | | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL |
30 | | * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
31 | | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
32 | | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
33 | | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
34 | | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
35 | | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
36 | | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
37 | | * OF THE POSSIBILITY OF SUCH DAMAGE. |
38 | | */ |
39 | | |
40 | | /** |
41 | | * @file UriIp4Base.c |
42 | | * Holds code independent of the encoding pass. |
43 | | */ |
44 | | |
45 | | #ifndef URI_DOXYGEN |
46 | | # include "UriIp4Base.h" |
47 | | #endif |
48 | | |
49 | | |
50 | | |
51 | 0 | void uriStackToOctet(UriIp4Parser * parser, unsigned char * octet) { |
52 | 0 | switch (parser->stackCount) { |
53 | 0 | case 1: |
54 | 0 | *octet = parser->stackOne; |
55 | 0 | break; |
56 | | |
57 | 0 | case 2: |
58 | 0 | *octet = parser->stackOne * 10 |
59 | 0 | + parser->stackTwo; |
60 | 0 | break; |
61 | | |
62 | 0 | case 3: |
63 | 0 | *octet = parser->stackOne * 100 |
64 | 0 | + parser->stackTwo * 10 |
65 | 0 | + parser->stackThree; |
66 | 0 | break; |
67 | | |
68 | 0 | default: |
69 | 0 | ; |
70 | 0 | } |
71 | 0 | parser->stackCount = 0; |
72 | 0 | } |
73 | | |
74 | | |
75 | | |
76 | 0 | void uriPushToStack(UriIp4Parser * parser, unsigned char digit) { |
77 | 0 | switch (parser->stackCount) { |
78 | 0 | case 0: |
79 | 0 | parser->stackOne = digit; |
80 | 0 | parser->stackCount = 1; |
81 | 0 | break; |
82 | | |
83 | 0 | case 1: |
84 | 0 | parser->stackTwo = digit; |
85 | 0 | parser->stackCount = 2; |
86 | 0 | break; |
87 | | |
88 | 0 | case 2: |
89 | 0 | parser->stackThree = digit; |
90 | 0 | parser->stackCount = 3; |
91 | 0 | break; |
92 | | |
93 | 0 | default: |
94 | 0 | ; |
95 | 0 | } |
96 | 0 | } |