summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/bio/bss_rtcp.c
diff options
context:
space:
mode:
authorjsing <>2014-04-15 16:37:22 +0000
committerjsing <>2014-04-15 16:37:22 +0000
commitbb63ff2d125e51688213d0af9e4f785cf3865063 (patch)
tree41dd30d546977ed0c409d7de59564fa1a2e3b100 /src/lib/libcrypto/bio/bss_rtcp.c
parent90b03b7785bece7b16c6a38b7db633fcfdd9ecf4 (diff)
downloadopenbsd-bb63ff2d125e51688213d0af9e4f785cf3865063.tar.gz
openbsd-bb63ff2d125e51688213d0af9e4f785cf3865063.tar.bz2
openbsd-bb63ff2d125e51688213d0af9e4f785cf3865063.zip
First pass at applying KNF to the OpenSSL code, which almost makes it
readable. This pass is whitespace only and can readily be verified using tr and md5.
Diffstat (limited to 'src/lib/libcrypto/bio/bss_rtcp.c')
-rw-r--r--src/lib/libcrypto/bio/bss_rtcp.c294
1 files changed, 160 insertions, 134 deletions
diff --git a/src/lib/libcrypto/bio/bss_rtcp.c b/src/lib/libcrypto/bio/bss_rtcp.c
index 7dae485564..84d01e58b4 100644
--- a/src/lib/libcrypto/bio/bss_rtcp.c
+++ b/src/lib/libcrypto/bio/bss_rtcp.c
@@ -73,31 +73,32 @@
73 73
74typedef unsigned short io_channel; 74typedef unsigned short io_channel;
75/*************************************************************************/ 75/*************************************************************************/
76struct io_status { short status, count; long flags; }; 76 struct io_status { short status, count;
77 long flags;
78};
77 79
78struct rpc_msg { /* Should have member alignment inhibited */ 80 struct rpc_msg { /* Should have member alignment inhibited */
79 char channel; /* 'A'-app data. 'R'-remote client 'G'-global */ 81 char channel; /* 'A'-app data. 'R'-remote client 'G'-global */
80 char function; /* 'G'-get, 'P'-put, 'C'-confirm, 'X'-close */ 82 char function; /* 'G'-get, 'P'-put, 'C'-confirm, 'X'-close */
81 unsigned short int length; /* Amount of data returned or max to return */ 83 unsigned short int length; /* Amount of data returned or max to return */
82 char data[4092]; /* variable data */ 84 char data[4092]; /* variable data */
83}; 85};
84#define RPC_HDR_SIZE (sizeof(struct rpc_msg) - 4092) 86#define RPC_HDR_SIZE (sizeof(struct rpc_msg) - 4092)
85 87
86struct rpc_ctx { 88struct rpc_ctx {
87 int filled, pos; 89 int filled, pos;
88 struct rpc_msg msg; 90 struct rpc_msg msg;
89}; 91};
90 92
91static int rtcp_write(BIO *h,const char *buf,int num); 93static int rtcp_write(BIO *h, const char *buf, int num);
92static int rtcp_read(BIO *h,char *buf,int size); 94static int rtcp_read(BIO *h, char *buf, int size);
93static int rtcp_puts(BIO *h,const char *str); 95static int rtcp_puts(BIO *h, const char *str);
94static int rtcp_gets(BIO *h,char *str,int size); 96static int rtcp_gets(BIO *h, char *str, int size);
95static long rtcp_ctrl(BIO *h,int cmd,long arg1,void *arg2); 97static long rtcp_ctrl(BIO *h, int cmd, long arg1, void *arg2);
96static int rtcp_new(BIO *h); 98static int rtcp_new(BIO *h);
97static int rtcp_free(BIO *data); 99static int rtcp_free(BIO *data);
98 100
99static BIO_METHOD rtcp_method= 101static BIO_METHOD rtcp_method = {
100 {
101 BIO_TYPE_FD, 102 BIO_TYPE_FD,
102 "RTCP", 103 "RTCP",
103 rtcp_write, 104 rtcp_write,
@@ -108,12 +109,13 @@ static BIO_METHOD rtcp_method=
108 rtcp_new, 109 rtcp_new,
109 rtcp_free, 110 rtcp_free,
110 NULL, 111 NULL,
111 }; 112};
112 113
113BIO_METHOD *BIO_s_rtcp(void) 114BIO_METHOD
114 { 115*BIO_s_rtcp(void)
115 return(&rtcp_method); 116{
116 } 117 return (&rtcp_method);
118}
117/*****************************************************************************/ 119/*****************************************************************************/
118/* Decnet I/O routines. 120/* Decnet I/O routines.
119 */ 121 */
@@ -123,25 +125,28 @@ BIO_METHOD *BIO_s_rtcp(void)
123#pragma message disable DOLLARID 125#pragma message disable DOLLARID
124#endif 126#endif
125 127
126static int get ( io_channel chan, char *buffer, int maxlen, int *length ) 128static int get(io_channel chan, char *buffer, int maxlen, int *length)
127{ 129{
128 int status; 130 int status;
129 struct io_status iosb; 131 struct io_status iosb;
130 status = sys$qiow ( 0, chan, IO$_READVBLK, &iosb, 0, 0, 132 status = sys$qiow(0, chan, IO$_READVBLK, &iosb, 0, 0, buffer, maxlen,
131 buffer, maxlen, 0, 0, 0, 0 ); 133 0, 0, 0, 0 );
132 if ( (status&1) == 1 ) status = iosb.status; 134 if ((status & 1) == 1)
133 if ( (status&1) == 1 ) *length = iosb.count; 135 status = iosb.status;
134 return status; 136 if ((status & 1) == 1 )
137 *length = iosb.count;
138 return status;
135} 139}
136 140
137static int put ( io_channel chan, char *buffer, int length ) 141static int put(io_channel chan, char *buffer, int length)
138{ 142{
139 int status; 143 int status;
140 struct io_status iosb; 144 struct io_status iosb;
141 status = sys$qiow ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0, 145 status = sys$qiow ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0, buffer,
142 buffer, length, 0, 0, 0, 0 ); 146 length, 0, 0, 0, 0 );
143 if ( (status&1) == 1 ) status = iosb.status; 147 if ((status & 1) == 1)
144 return status; 148 status = iosb.status;
149 return status;
145} 150}
146 151
147#ifdef __DECC 152#ifdef __DECC
@@ -150,109 +155,127 @@ static int put ( io_channel chan, char *buffer, int length )
150 155
151/***************************************************************************/ 156/***************************************************************************/
152 157
153static int rtcp_new(BIO *bi) 158static int
159rtcp_new(BIO *bi)
154{ 160{
155 struct rpc_ctx *ctx; 161 struct rpc_ctx *ctx;
156 bi->init=1; 162 bi->init = 1;
157 bi->num=0; 163 bi->num = 0;
158 bi->flags = 0; 164 bi->flags = 0;
159 bi->ptr=OPENSSL_malloc(sizeof(struct rpc_ctx)); 165 bi->ptr = OPENSSL_malloc(sizeof(struct rpc_ctx));
160 ctx = (struct rpc_ctx *) bi->ptr; 166 ctx = (struct rpc_ctx *)bi->ptr;
161 ctx->filled = 0; 167 ctx->filled = 0;
162 ctx->pos = 0; 168 ctx->pos = 0;
163 return(1); 169 return (1);
164} 170}
165 171
166static int rtcp_free(BIO *a) 172static int
173rtcp_free(BIO *a)
167{ 174{
168 if (a == NULL) return(0); 175 if (a == NULL)
169 if ( a->ptr ) OPENSSL_free ( a->ptr ); 176 return (0);
177 if (a->ptr)
178 OPENSSL_free(a->ptr);
170 a->ptr = NULL; 179 a->ptr = NULL;
171 return(1); 180 return (1);
172} 181}
173 182
174static int rtcp_read(BIO *b, char *out, int outl) 183static int
184rtcp_read(BIO *b, char *out, int outl)
175{ 185{
176 int status, length; 186 int status, length;
177 struct rpc_ctx *ctx; 187 struct rpc_ctx *ctx;
178 /* 188 /*
179 * read data, return existing. 189 * read data, return existing.
180 */ 190 */
181 ctx = (struct rpc_ctx *) b->ptr; 191 ctx = (struct rpc_ctx *)b->ptr;
182 if ( ctx->pos < ctx->filled ) { 192 if (ctx->pos < ctx->filled) {
183 length = ctx->filled - ctx->pos; 193 length = ctx->filled - ctx->pos;
184 if ( length > outl ) length = outl; 194 if (length > outl)
185 memmove ( out, &ctx->msg.data[ctx->pos], length ); 195 length = outl;
186 ctx->pos += length; 196 memmove(out, &ctx->msg.data[ctx->pos], length);
187 return length; 197 ctx->pos += length;
188 } 198 return length;
189 /* 199 }
190 * Requst more data from R channel. 200 /*
191 */ 201 * Requst more data from R channel.
192 ctx->msg.channel = 'R'; 202 */
193 ctx->msg.function = 'G'; 203 ctx->msg.channel = 'R';
194 ctx->msg.length = sizeof(ctx->msg.data); 204 ctx->msg.function = 'G';
195 status = put ( b->num, (char *) &ctx->msg, RPC_HDR_SIZE ); 205 ctx->msg.length = sizeof(ctx->msg.data);
196 if ( (status&1) == 0 ) { 206 status = put(b->num, (char *)&ctx->msg, RPC_HDR_SIZE);
197 return -1; 207 if ((status & 1) == 0 ) {
198 } 208 return -1;
199 /* 209 }
200 * Read. 210 /*
201 */ 211 * Read.
202 ctx->pos = ctx->filled = 0; 212 */
203 status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length ); 213 ctx->pos = ctx->filled = 0;
204 if ( (status&1) == 0 ) length = -1; 214 status = get(b->num, (char *)&ctx->msg, sizeof(ctx->msg), &length);
205 if ( ctx->msg.channel != 'R' || ctx->msg.function != 'C' ) { 215 if ((status & 1) == 0)
206 length = -1; 216 length = -1;
207 } 217 if (ctx->msg.channel != 'R' || ctx->msg.function != 'C') {
208 ctx->filled = length - RPC_HDR_SIZE; 218 length = -1;
209 219 }
210 if ( ctx->pos < ctx->filled ) { 220 ctx->filled = length - RPC_HDR_SIZE;
211 length = ctx->filled - ctx->pos; 221
212 if ( length > outl ) length = outl; 222 if (ctx->pos < ctx->filled) {
213 memmove ( out, ctx->msg.data, length ); 223 length = ctx->filled - ctx->pos;
214 ctx->pos += length; 224 if (length > outl)
215 return length; 225 length = outl;
216 } 226 memmove(out, ctx->msg.data, length);
227 ctx->pos += length;
228 return length;
229 }
217 230
218 return length; 231 return length;
219} 232}
220 233
221static int rtcp_write(BIO *b, const char *in, int inl) 234static int
235rtcp_write(BIO *b, const char *in, int inl)
222{ 236{
223 int status, i, segment, length; 237 int status, i, segment, length;
224 struct rpc_ctx *ctx; 238 struct rpc_ctx *ctx;
225 /* 239 /*
226 * Output data, send in chunks no larger that sizeof(ctx->msg.data). 240 * Output data, send in chunks no larger that sizeof(ctx->msg.data).
227 */ 241 */
228 ctx = (struct rpc_ctx *) b->ptr; 242 ctx = (struct rpc_ctx *)b->ptr;
229 for ( i = 0; i < inl; i += segment ) { 243 for (i = 0; i < inl; i += segment) {
230 segment = inl - i; 244 segment = inl - i;
231 if ( segment > sizeof(ctx->msg.data) ) segment = sizeof(ctx->msg.data); 245 if (segment > sizeof(ctx->msg.data))
232 ctx->msg.channel = 'R'; 246 segment = sizeof(ctx->msg.data);
233 ctx->msg.function = 'P'; 247 ctx->msg.channel = 'R';
234 ctx->msg.length = segment; 248 ctx->msg.function = 'P';
235 memmove ( ctx->msg.data, &in[i], segment ); 249 ctx->msg.length = segment;
236 status = put ( b->num, (char *) &ctx->msg, segment + RPC_HDR_SIZE ); 250 memmove(ctx->msg.data, &in[i], segment);
237 if ((status&1) == 0 ) { i = -1; break; } 251 status = put(b->num, (char *) &ctx->msg,
252 segment + RPC_HDR_SIZE);
253 if ((status & 1) == 0) {
254 i = -1;
255 break;
256 }
238 257
239 status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length ); 258 status = get(b->num, (char *)&ctx->msg, sizeof(ctx->msg),
240 if ( ((status&1) == 0) || (length < RPC_HDR_SIZE) ) { i = -1; break; } 259 &length );
241 if ( (ctx->msg.channel != 'R') || (ctx->msg.function != 'C') ) { 260 if (((status&1) == 0) || (length < RPC_HDR_SIZE)) {
242 printf("unexpected response when confirming put %c %c\n", 261 i = -1;
243 ctx->msg.channel, ctx->msg.function ); 262 break;
263 }
264 if ((ctx->msg.channel != 'R') || (ctx->msg.function != 'C')) {
265 printf("unexpected response when confirming put %c %c\n",
266 ctx->msg.channel, ctx->msg.function );
244 267
268 }
245 } 269 }
246 } 270 return (i);
247 return(i);
248} 271}
249 272
250static long rtcp_ctrl(BIO *b, int cmd, long num, void *ptr) 273static long
251 { 274rtcp_ctrl(BIO *b, int cmd, long num, void *ptr)
252 long ret=1; 275{
276 long ret = 1;
253 277
254 switch (cmd) 278 switch (cmd) {
255 {
256 case BIO_CTRL_RESET: 279 case BIO_CTRL_RESET:
257 case BIO_CTRL_EOF: 280 case BIO_CTRL_EOF:
258 ret = 1; 281 ret = 1;
@@ -260,11 +283,11 @@ static long rtcp_ctrl(BIO *b, int cmd, long num, void *ptr)
260 case BIO_C_SET_FD: 283 case BIO_C_SET_FD:
261 b->num = num; 284 b->num = num;
262 ret = 1; 285 ret = 1;
263 break; 286 break;
264 case BIO_CTRL_SET_CLOSE: 287 case BIO_CTRL_SET_CLOSE:
265 case BIO_CTRL_FLUSH: 288 case BIO_CTRL_FLUSH:
266 case BIO_CTRL_DUP: 289 case BIO_CTRL_DUP:
267 ret=1; 290 ret = 1;
268 break; 291 break;
269 case BIO_CTRL_GET_CLOSE: 292 case BIO_CTRL_GET_CLOSE:
270 case BIO_CTRL_INFO: 293 case BIO_CTRL_INFO:
@@ -272,23 +295,26 @@ static long rtcp_ctrl(BIO *b, int cmd, long num, void *ptr)
272 case BIO_CTRL_PENDING: 295 case BIO_CTRL_PENDING:
273 case BIO_CTRL_WPENDING: 296 case BIO_CTRL_WPENDING:
274 default: 297 default:
275 ret=0; 298 ret = 0;
276 break; 299 break;
277 }
278 return(ret);
279 }
280
281static int rtcp_gets(BIO *bp, char *buf, int size)
282 {
283 return(0);
284 } 300 }
301 return (ret);
302}
285 303
286static int rtcp_puts(BIO *bp, const char *str) 304static int
305rtcp_gets(BIO *bp, char *buf, int size)
287{ 306{
288 int length; 307 return (0);
289 if (str == NULL) return(0);
290 length = strlen ( str );
291 if ( length == 0 ) return (0);
292 return rtcp_write ( bp,str, length );
293} 308}
294 309
310static int
311rtcp_puts(BIO *bp, const char *str)
312{
313 int length;
314 if (str == NULL)
315 return (0);
316 length = strlen(str);
317 if (length == 0)
318 return (0);
319 return rtcp_write(bp, str, length);
320}