BadVPN – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /** |
2 | * @file DummyPRFileDesc.c |
||
3 | * @author Ambroz Bizjak <ambrop7@gmail.com> |
||
4 | * |
||
5 | * @section LICENSE |
||
6 | * |
||
7 | * Redistribution and use in source and binary forms, with or without |
||
8 | * modification, are permitted provided that the following conditions are met: |
||
9 | * 1. Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * 2. Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * 3. Neither the name of the author nor the |
||
15 | * names of its contributors may be used to endorse or promote products |
||
16 | * derived from this software without specific prior written permission. |
||
17 | * |
||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
||
19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
28 | */ |
||
29 | |||
30 | #include <stdlib.h> |
||
31 | #include <string.h> |
||
32 | #include <limits.h> |
||
33 | |||
34 | #include <prerror.h> |
||
35 | #include <prmem.h> |
||
36 | |||
37 | #include <misc/debug.h> |
||
38 | #include <misc/offset.h> |
||
39 | |||
40 | #include <nspr_support/DummyPRFileDesc.h> |
||
41 | |||
42 | #ifndef NDEBUG |
||
43 | int dummyprfiledesc_initialized = 0; |
||
44 | #endif |
||
45 | PRDescIdentity dummyprfiledesc_identity; |
||
46 | |||
47 | static PRStatus method_close (PRFileDesc *fd) |
||
48 | { |
||
49 | return PR_SUCCESS; |
||
50 | } |
||
51 | |||
52 | static PRStatus method_getpeername (PRFileDesc *fd, PRNetAddr *addr) |
||
53 | { |
||
54 | PR_SetError(PR_UNKNOWN_ERROR, 0); |
||
55 | return PR_FAILURE; |
||
56 | } |
||
57 | |||
58 | static PRIntn _PR_InvalidIntn (void) |
||
59 | { |
||
60 | ASSERT(0) |
||
61 | PR_SetError(PR_INVALID_METHOD_ERROR, 0); |
||
62 | return -1; |
||
63 | } |
||
64 | |||
65 | static PRInt16 _PR_InvalidInt16 (void) |
||
66 | { |
||
67 | ASSERT(0) |
||
68 | PR_SetError(PR_INVALID_METHOD_ERROR, 0); |
||
69 | return -1; |
||
70 | } |
||
71 | |||
72 | static PRInt32 _PR_InvalidInt32 (void) |
||
73 | { |
||
74 | ASSERT(0) |
||
75 | PR_SetError(PR_INVALID_METHOD_ERROR, 0); |
||
76 | return -1; |
||
77 | } |
||
78 | |||
79 | static PRInt64 _PR_InvalidInt64 (void) |
||
80 | { |
||
81 | ASSERT(0) |
||
82 | PR_SetError(PR_INVALID_METHOD_ERROR, 0); |
||
83 | return -1; |
||
84 | } |
||
85 | |||
86 | static PROffset32 _PR_InvalidOffset32 (void) |
||
87 | { |
||
88 | ASSERT(0) |
||
89 | PR_SetError(PR_INVALID_METHOD_ERROR, 0); |
||
90 | return -1; |
||
91 | } |
||
92 | |||
93 | static PROffset64 _PR_InvalidOffset64 (void) |
||
94 | { |
||
95 | ASSERT(0) |
||
96 | PR_SetError(PR_INVALID_METHOD_ERROR, 0); |
||
97 | return -1; |
||
98 | } |
||
99 | |||
100 | static PRStatus _PR_InvalidStatus (void) |
||
101 | { |
||
102 | ASSERT(0) |
||
103 | PR_SetError(PR_INVALID_METHOD_ERROR, 0); |
||
104 | return PR_FAILURE; |
||
105 | } |
||
106 | |||
107 | static PRFileDesc *_PR_InvalidDesc (void) |
||
108 | { |
||
109 | ASSERT(0) |
||
110 | PR_SetError(PR_INVALID_METHOD_ERROR, 0); |
||
111 | return NULL; |
||
112 | } |
||
113 | |||
114 | static PRIOMethods methods = { |
||
115 | (PRDescType)0, |
||
116 | method_close, |
||
117 | (PRReadFN)_PR_InvalidInt32, |
||
118 | (PRWriteFN)_PR_InvalidInt32, |
||
119 | (PRAvailableFN)_PR_InvalidInt32, |
||
120 | (PRAvailable64FN)_PR_InvalidInt64, |
||
121 | (PRFsyncFN)_PR_InvalidStatus, |
||
122 | (PRSeekFN)_PR_InvalidOffset32, |
||
123 | (PRSeek64FN)_PR_InvalidOffset64, |
||
124 | (PRFileInfoFN)_PR_InvalidStatus, |
||
125 | (PRFileInfo64FN)_PR_InvalidStatus, |
||
126 | (PRWritevFN)_PR_InvalidInt32, |
||
127 | (PRConnectFN)_PR_InvalidStatus, |
||
128 | (PRAcceptFN)_PR_InvalidDesc, |
||
129 | (PRBindFN)_PR_InvalidStatus, |
||
130 | (PRListenFN)_PR_InvalidStatus, |
||
131 | (PRShutdownFN)_PR_InvalidStatus, |
||
132 | (PRRecvFN)_PR_InvalidInt32, |
||
133 | (PRSendFN)_PR_InvalidInt32, |
||
134 | (PRRecvfromFN)_PR_InvalidInt32, |
||
135 | (PRSendtoFN)_PR_InvalidInt32, |
||
136 | (PRPollFN)_PR_InvalidInt16, |
||
137 | (PRAcceptreadFN)_PR_InvalidInt32, |
||
138 | (PRTransmitfileFN)_PR_InvalidInt32, |
||
139 | (PRGetsocknameFN)_PR_InvalidStatus, |
||
140 | method_getpeername, |
||
141 | (PRReservedFN)_PR_InvalidIntn, |
||
142 | (PRReservedFN)_PR_InvalidIntn, |
||
143 | (PRGetsocketoptionFN)_PR_InvalidStatus, |
||
144 | (PRSetsocketoptionFN)_PR_InvalidStatus, |
||
145 | (PRSendfileFN)_PR_InvalidInt32, |
||
146 | (PRConnectcontinueFN)_PR_InvalidStatus, |
||
147 | (PRReservedFN)_PR_InvalidIntn, |
||
148 | (PRReservedFN)_PR_InvalidIntn, |
||
149 | (PRReservedFN)_PR_InvalidIntn, |
||
150 | (PRReservedFN)_PR_InvalidIntn |
||
151 | }; |
||
152 | |||
153 | int DummyPRFileDesc_GlobalInit (void) |
||
154 | { |
||
155 | ASSERT(!dummyprfiledesc_initialized) |
||
156 | |||
157 | if ((dummyprfiledesc_identity = PR_GetUniqueIdentity("DummyPRFileDesc")) == PR_INVALID_IO_LAYER) { |
||
158 | return 0; |
||
159 | } |
||
160 | |||
161 | #ifndef NDEBUG |
||
162 | dummyprfiledesc_initialized = 1; |
||
163 | #endif |
||
164 | |||
165 | return 1; |
||
166 | } |
||
167 | |||
168 | void DummyPRFileDesc_Create (PRFileDesc *prfd) |
||
169 | { |
||
170 | ASSERT(dummyprfiledesc_initialized) |
||
171 | |||
172 | memset(prfd, 0, sizeof(*prfd)); |
||
173 | prfd->methods = &methods; |
||
174 | prfd->secret = NULL; |
||
175 | prfd->identity = dummyprfiledesc_identity; |
||
176 | } |