diff options
Diffstat (limited to 'src/lib/libcrypto/bio/bss_sock.c')
-rw-r--r-- | src/lib/libcrypto/bio/bss_sock.c | 194 |
1 files changed, 98 insertions, 96 deletions
diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c index eb2965970c..f6d3bf7365 100644 --- a/src/lib/libcrypto/bio/bss_sock.c +++ b/src/lib/libcrypto/bio/bss_sock.c | |||
@@ -79,8 +79,7 @@ static int sock_new(BIO *h); | |||
79 | static int sock_free(BIO *data); | 79 | static int sock_free(BIO *data); |
80 | int BIO_sock_should_retry(int s); | 80 | int BIO_sock_should_retry(int s); |
81 | 81 | ||
82 | static BIO_METHOD methods_sockp= | 82 | static BIO_METHOD methods_sockp = { |
83 | { | ||
84 | BIO_TYPE_SOCKET, | 83 | BIO_TYPE_SOCKET, |
85 | "socket", | 84 | "socket", |
86 | sock_write, | 85 | sock_write, |
@@ -91,152 +90,155 @@ static BIO_METHOD methods_sockp= | |||
91 | sock_new, | 90 | sock_new, |
92 | sock_free, | 91 | sock_free, |
93 | NULL, | 92 | NULL, |
94 | }; | 93 | }; |
95 | 94 | ||
96 | BIO_METHOD *BIO_s_socket(void) | 95 | BIO_METHOD |
97 | { | 96 | *BIO_s_socket(void) |
98 | return(&methods_sockp); | 97 | { |
99 | } | 98 | return (&methods_sockp); |
99 | } | ||
100 | 100 | ||
101 | BIO *BIO_new_socket(int fd, int close_flag) | 101 | BIO |
102 | { | 102 | *BIO_new_socket(int fd, int close_flag) |
103 | { | ||
103 | BIO *ret; | 104 | BIO *ret; |
104 | 105 | ||
105 | ret=BIO_new(BIO_s_socket()); | 106 | ret = BIO_new(BIO_s_socket()); |
106 | if (ret == NULL) return(NULL); | 107 | if (ret == NULL) |
107 | BIO_set_fd(ret,fd,close_flag); | 108 | return (NULL); |
108 | return(ret); | 109 | BIO_set_fd(ret, fd, close_flag); |
109 | } | 110 | return (ret); |
111 | } | ||
110 | 112 | ||
111 | static int sock_new(BIO *bi) | 113 | static int |
112 | { | 114 | sock_new(BIO *bi) |
113 | bi->init=0; | 115 | { |
114 | bi->num=0; | 116 | bi->init = 0; |
115 | bi->ptr=NULL; | 117 | bi->num = 0; |
116 | bi->flags=0; | 118 | bi->ptr = NULL; |
117 | return(1); | 119 | bi->flags = 0; |
118 | } | 120 | return (1); |
121 | } | ||
119 | 122 | ||
120 | static int sock_free(BIO *a) | 123 | static int |
121 | { | 124 | sock_free(BIO *a) |
122 | if (a == NULL) return(0); | 125 | { |
123 | if (a->shutdown) | 126 | if (a == NULL) |
124 | { | 127 | return (0); |
125 | if (a->init) | 128 | if (a->shutdown) { |
126 | { | 129 | if (a->init) { |
127 | shutdown(a->num, SHUT_RDWR); | 130 | shutdown(a->num, SHUT_RDWR); |
128 | close(a->num); | 131 | close(a->num); |
129 | } | ||
130 | a->init=0; | ||
131 | a->flags=0; | ||
132 | } | 132 | } |
133 | return(1); | 133 | a->init = 0; |
134 | a->flags = 0; | ||
134 | } | 135 | } |
135 | 136 | return (1); | |
136 | static int sock_read(BIO *b, char *out, int outl) | 137 | } |
137 | { | ||
138 | int ret=0; | ||
139 | 138 | ||
140 | if (out != NULL) | 139 | static int |
141 | { | 140 | sock_read(BIO *b, char *out, int outl) |
141 | { | ||
142 | int ret = 0; | ||
143 | |||
144 | if (out != NULL) { | ||
142 | errno = 0; | 145 | errno = 0; |
143 | ret=read(b->num,out,outl); | 146 | ret = read(b->num, out, outl); |
144 | BIO_clear_retry_flags(b); | 147 | BIO_clear_retry_flags(b); |
145 | if (ret <= 0) | 148 | if (ret <= 0) { |
146 | { | ||
147 | if (BIO_sock_should_retry(ret)) | 149 | if (BIO_sock_should_retry(ret)) |
148 | BIO_set_retry_read(b); | 150 | BIO_set_retry_read(b); |
149 | } | ||
150 | } | 151 | } |
151 | return(ret); | ||
152 | } | 152 | } |
153 | return (ret); | ||
154 | } | ||
153 | 155 | ||
154 | static int sock_write(BIO *b, const char *in, int inl) | 156 | static int |
155 | { | 157 | sock_write(BIO *b, const char *in, int inl) |
158 | { | ||
156 | int ret; | 159 | int ret; |
157 | 160 | ||
158 | errno = 0; | 161 | errno = 0; |
159 | ret=write(b->num,in,inl); | 162 | ret = write(b->num, in, inl); |
160 | BIO_clear_retry_flags(b); | 163 | BIO_clear_retry_flags(b); |
161 | if (ret <= 0) | 164 | if (ret <= 0) { |
162 | { | ||
163 | if (BIO_sock_should_retry(ret)) | 165 | if (BIO_sock_should_retry(ret)) |
164 | BIO_set_retry_write(b); | 166 | BIO_set_retry_write(b); |
165 | } | ||
166 | return(ret); | ||
167 | } | 167 | } |
168 | return (ret); | ||
169 | } | ||
168 | 170 | ||
169 | static long sock_ctrl(BIO *b, int cmd, long num, void *ptr) | 171 | static long |
170 | { | 172 | sock_ctrl(BIO *b, int cmd, long num, void *ptr) |
171 | long ret=1; | 173 | { |
174 | long ret = 1; | ||
172 | int *ip; | 175 | int *ip; |
173 | 176 | ||
174 | switch (cmd) | 177 | switch (cmd) { |
175 | { | ||
176 | case BIO_C_SET_FD: | 178 | case BIO_C_SET_FD: |
177 | sock_free(b); | 179 | sock_free(b); |
178 | b->num= *((int *)ptr); | 180 | b->num= *((int *)ptr); |
179 | b->shutdown=(int)num; | 181 | b->shutdown = (int)num; |
180 | b->init=1; | 182 | b->init = 1; |
181 | break; | 183 | break; |
182 | case BIO_C_GET_FD: | 184 | case BIO_C_GET_FD: |
183 | if (b->init) | 185 | if (b->init) { |
184 | { | 186 | ip = (int *)ptr; |
185 | ip=(int *)ptr; | 187 | if (ip != NULL) |
186 | if (ip != NULL) *ip=b->num; | 188 | *ip = b->num; |
187 | ret=b->num; | 189 | ret = b->num; |
188 | } | 190 | } else |
189 | else | 191 | ret = -1; |
190 | ret= -1; | ||
191 | break; | 192 | break; |
192 | case BIO_CTRL_GET_CLOSE: | 193 | case BIO_CTRL_GET_CLOSE: |
193 | ret=b->shutdown; | 194 | ret = b->shutdown; |
194 | break; | 195 | break; |
195 | case BIO_CTRL_SET_CLOSE: | 196 | case BIO_CTRL_SET_CLOSE: |
196 | b->shutdown=(int)num; | 197 | b->shutdown = (int)num; |
197 | break; | 198 | break; |
198 | case BIO_CTRL_DUP: | 199 | case BIO_CTRL_DUP: |
199 | case BIO_CTRL_FLUSH: | 200 | case BIO_CTRL_FLUSH: |
200 | ret=1; | 201 | ret = 1; |
201 | break; | 202 | break; |
202 | default: | 203 | default: |
203 | ret=0; | 204 | ret = 0; |
204 | break; | 205 | break; |
205 | } | ||
206 | return(ret); | ||
207 | } | 206 | } |
207 | return (ret); | ||
208 | } | ||
208 | 209 | ||
209 | static int sock_puts(BIO *bp, const char *str) | 210 | static int |
210 | { | 211 | sock_puts(BIO *bp, const char *str) |
211 | int n,ret; | 212 | { |
213 | int n, ret; | ||
212 | 214 | ||
213 | n=strlen(str); | 215 | n = strlen(str); |
214 | ret=sock_write(bp,str,n); | 216 | ret = sock_write(bp, str, n); |
215 | return(ret); | 217 | return (ret); |
216 | } | 218 | } |
217 | 219 | ||
218 | int BIO_sock_should_retry(int i) | 220 | int |
219 | { | 221 | BIO_sock_should_retry(int i) |
222 | { | ||
220 | int err; | 223 | int err; |
221 | 224 | ||
222 | if ((i == 0) || (i == -1)) | 225 | if ((i == 0) || (i == -1)) { |
223 | { | 226 | err = errno; |
224 | err=errno; | ||
225 | 227 | ||
226 | #if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */ | 228 | #if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */ |
227 | if ((i == -1) && (err == 0)) | 229 | if ((i == -1) && (err == 0)) |
228 | return(1); | 230 | return (1); |
229 | #endif | 231 | #endif |
230 | 232 | ||
231 | return(BIO_sock_non_fatal_error(err)); | 233 | return (BIO_sock_non_fatal_error(err)); |
232 | } | ||
233 | return(0); | ||
234 | } | 234 | } |
235 | return (0); | ||
236 | } | ||
235 | 237 | ||
236 | int BIO_sock_non_fatal_error(int err) | 238 | int |
237 | { | 239 | BIO_sock_non_fatal_error(int err) |
238 | switch (err) | 240 | { |
239 | { | 241 | switch (err) { |
240 | #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_NETWARE) | 242 | #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_NETWARE) |
241 | # if defined(WSAEWOULDBLOCK) | 243 | # if defined(WSAEWOULDBLOCK) |
242 | case WSAEWOULDBLOCK: | 244 | case WSAEWOULDBLOCK: |
@@ -284,12 +286,12 @@ int BIO_sock_non_fatal_error(int err) | |||
284 | #ifdef EALREADY | 286 | #ifdef EALREADY |
285 | case EALREADY: | 287 | case EALREADY: |
286 | #endif | 288 | #endif |
287 | return(1); | 289 | return (1); |
288 | /* break; */ | 290 | /* break; */ |
289 | default: | 291 | default: |
290 | break; | 292 | break; |
291 | } | ||
292 | return(0); | ||
293 | } | 293 | } |
294 | return (0); | ||
295 | } | ||
294 | 296 | ||
295 | #endif /* #ifndef OPENSSL_NO_SOCK */ | 297 | #endif /* #ifndef OPENSSL_NO_SOCK */ |