#define TRUNCATE
#define DUMP_WIDTH 16
-#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH-((i-(i>6?6:i)+3)/4))
+#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH - ((i - (i > 6 ? 6 : i) + 3) / 4))
-int BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u),
- void *u, const char *s, int len)
- {
+int
+BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u),
+ void *u, const char *s, int len)
+{
return BIO_dump_indent_cb(cb, u, s, len, 0);
- }
+}
-int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
- void *u, const char *s, int len, int indent)
- {
- int ret=0;
- char buf[288+1],tmp[20],str[128+1];
- int i,j,rows,trc;
+int
+BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
+ void *u, const char *s, int len, int indent)
+{
+ int ret = 0;
+ char buf[288 + 1], tmp[20], str[128 + 1];
+ int i, j, rows, trc;
unsigned char ch;
int dump_width;
- trc=0;
+ trc = 0;
#ifdef TRUNCATE
- for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--)
+ for (; (len > 0) && ((s[len - 1] == ' ') || (s[len - 1] == '\0')); len--)
trc++;
#endif
if (indent < 0)
indent = 0;
- if (indent)
- {
- if (indent > 128) indent=128;
- memset(str,' ',indent);
- }
- str[indent]='\0';
+ if (indent) {
+ if (indent > 128)
+ indent = 128;
+ memset(str, ' ', indent);
+ }
+ str[indent] = '\0';
- dump_width=DUMP_WIDTH_LESS_INDENT(indent);
- rows=(len/dump_width);
- if ((rows*dump_width)<len)
+ dump_width = DUMP_WIDTH_LESS_INDENT(indent);
+ rows = (len / dump_width);
+ if ((rows * dump_width) < len)
rows++;
- for(i=0;i<rows;i++)
- {
- buf[0]='\0'; /* start with empty string */
- BUF_strlcpy(buf,str,sizeof buf);
- (void) snprintf(tmp,sizeof tmp,"%04x - ",i*dump_width);
- BUF_strlcat(buf,tmp,sizeof buf);
- for(j=0;j<dump_width;j++)
- {
- if (((i*dump_width)+j)>=len)
- {
- BUF_strlcat(buf," ",sizeof buf);
- }
- else
- {
- ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
- (void) snprintf(tmp,sizeof tmp,"%02x%c",ch,
- j==7?'-':' ');
- BUF_strlcat(buf,tmp,sizeof buf);
- }
+ for (i = 0; i < rows; i++) {
+ buf[0] = '\0'; /* start with empty string */
+ BUF_strlcpy(buf, str, sizeof buf);
+ (void) snprintf(tmp, sizeof tmp, "%04x - ", i*dump_width);
+ BUF_strlcat(buf, tmp, sizeof buf);
+ for (j = 0; j < dump_width; j++) {
+ if (((i*dump_width) + j) >= len) {
+ BUF_strlcat(buf, " ", sizeof buf);
+ } else {
+ ch = ((unsigned char)*(s + i*dump_width + j)) & 0xff;
+ (void) snprintf(tmp, sizeof tmp, "%02x%c", ch,
+ j == 7 ? '-' : ' ');
+ BUF_strlcat(buf, tmp, sizeof buf);
}
- BUF_strlcat(buf," ",sizeof buf);
- for(j=0;j<dump_width;j++)
- {
- if (((i*dump_width)+j)>=len)
+ }
+ BUF_strlcat(buf, " ", sizeof buf);
+ for (j = 0; j < dump_width; j++) {
+ if (((i*dump_width) + j) >= len)
break;
- ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
+ ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff;
#ifndef CHARSET_EBCDIC
- (void) snprintf(tmp,sizeof tmp,"%c",
- ((ch>=' ')&&(ch<='~'))?ch:'.');
+ (void) snprintf(tmp, sizeof tmp, "%c",
+ ((ch >= ' ') && (ch <= '~')) ? ch : '.');
#else
- (void) snprintf(tmp,sizeof tmp,"%c",
- ((ch>=os_toascii[' '])&&(ch<=os_toascii['~']))
- ? os_toebcdic[ch]
- : '.');
+ (void) snprintf(tmp, sizeof tmp, "%c",
+ ((ch >= os_toascii[' ']) && (ch <= os_toascii['~']))
+ ? os_toebcdic[ch] : '.');
#endif
- BUF_strlcat(buf,tmp,sizeof buf);
- }
- BUF_strlcat(buf,"\n",sizeof buf);
+ BUF_strlcat(buf, tmp, sizeof buf);
+ }
+ BUF_strlcat(buf, "\n", sizeof buf);
/* if this is the last call then update the ddt_dump thing so
* that we will move the selection point in the debug window
*/
- ret+=cb((void *)buf,strlen(buf),u);
- }
+ ret += cb((void *)buf, strlen(buf), u);
+ }
#ifdef TRUNCATE
- if (trc > 0)
- {
- (void) snprintf(buf,sizeof buf,"%s%04x - <SPACES/NULS>\n",str,
- len+trc);
- ret+=cb((void *)buf,strlen(buf),u);
- }
-#endif
- return(ret);
+ if (trc > 0) {
+ (void) snprintf(buf, sizeof buf, "%s%04x - <SPACES/NULS>\n",
+ str, len + trc);
+ ret += cb((void *)buf, strlen(buf), u);
}
+#endif
+ return (ret);
+}
#ifndef OPENSSL_NO_FP_API
-static int write_fp(const void *data, size_t len, void *fp)
- {
+static int
+write_fp(const void *data, size_t len, void *fp)
+{
return UP_fwrite(data, len, 1, fp);
- }
-int BIO_dump_fp(FILE *fp, const char *s, int len)
- {
+}
+
+int
+BIO_dump_fp(FILE *fp, const char *s, int len)
+{
return BIO_dump_cb(write_fp, fp, s, len);
- }
-int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent)
- {
+}
+
+int
+BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent)
+{
return BIO_dump_indent_cb(write_fp, fp, s, len, indent);
- }
+}
#endif
-static int write_bio(const void *data, size_t len, void *bp)
- {
+static int
+write_bio(const void *data, size_t len, void *bp)
+{
return BIO_write((BIO *)bp, (const char *)data, len);
- }
-int BIO_dump(BIO *bp, const char *s, int len)
- {
+}
+
+int
+BIO_dump(BIO *bp, const char *s, int len)
+{
return BIO_dump_cb(write_bio, bp, s, len);
- }
-int BIO_dump_indent(BIO *bp, const char *s, int len, int indent)
- {
- return BIO_dump_indent_cb(write_bio, bp, s, len, indent);
- }
+}
+int
+BIO_dump_indent(BIO *bp, const char *s, int len, int indent)
+{
+ return BIO_dump_indent_cb(write_bio, bp, s, len, indent);
+}
#define LLONG long
#endif
-static void fmtstr (char **, char **, size_t *, size_t *,
- const char *, int, int, int);
-static void fmtint (char **, char **, size_t *, size_t *,
- LLONG, int, int, int, int);
-static void fmtfp (char **, char **, size_t *, size_t *,
- LDOUBLE, int, int, int);
-static void doapr_outch (char **, char **, size_t *, size_t *, int);
-static void _dopr(char **sbuffer, char **buffer,
- size_t *maxlen, size_t *retlen, int *truncated,
- const char *format, va_list args);
+static void fmtstr(char **, char **, size_t *, size_t *, const char *,
+ int, int, int);
+static void fmtint(char **, char **, size_t *, size_t *, LLONG, int,
+ int, int, int);
+static void fmtfp(char **, char **, size_t *, size_t *, LDOUBLE,
+ int, int, int);
+static void doapr_outch(char **, char **, size_t *, size_t *, int);
+static void _dopr(char **sbuffer, char **buffer, size_t *maxlen,
+ size_t *retlen, int *truncated, const char *format, va_list args);
/* format read states */
#define DP_S_DEFAULT 0
#define OSSL_MAX(p,q) ((p >= q) ? p : q)
static void
-_dopr(
- char **sbuffer,
- char **buffer,
- size_t *maxlen,
- size_t *retlen,
- int *truncated,
- const char *format,
- va_list args)
+_dopr(char **sbuffer, char **buffer, size_t *maxlen, size_t *retlen,
+ int *truncated, const char *format, va_list args)
{
- char ch;
- LLONG value;
- LDOUBLE fvalue;
- char *strvalue;
- int min;
- int max;
- int state;
- int flags;
- int cflags;
- size_t currlen;
-
- state = DP_S_DEFAULT;
- flags = currlen = cflags = min = 0;
- max = -1;
- ch = *format++;
-
- while (state != DP_S_DONE) {
- if (ch == '\0' || (buffer == NULL && currlen >= *maxlen))
- state = DP_S_DONE;
-
- switch (state) {
- case DP_S_DEFAULT:
- if (ch == '%')
- state = DP_S_FLAGS;
- else
- doapr_outch(sbuffer,buffer, &currlen, maxlen, ch);
- ch = *format++;
- break;
- case DP_S_FLAGS:
- switch (ch) {
- case '-':
- flags |= DP_F_MINUS;
- ch = *format++;
- break;
- case '+':
- flags |= DP_F_PLUS;
- ch = *format++;
- break;
- case ' ':
- flags |= DP_F_SPACE;
- ch = *format++;
- break;
- case '#':
- flags |= DP_F_NUM;
- ch = *format++;
- break;
- case '0':
- flags |= DP_F_ZERO;
- ch = *format++;
- break;
- default:
- state = DP_S_MIN;
- break;
- }
- break;
- case DP_S_MIN:
- if (isdigit((unsigned char)ch)) {
- min = 10 * min + char_to_int(ch);
- ch = *format++;
- } else if (ch == '*') {
- min = va_arg(args, int);
- ch = *format++;
- state = DP_S_DOT;
- } else
- state = DP_S_DOT;
- break;
- case DP_S_DOT:
- if (ch == '.') {
- state = DP_S_MAX;
- ch = *format++;
- } else
- state = DP_S_MOD;
- break;
- case DP_S_MAX:
- if (isdigit((unsigned char)ch)) {
- if (max < 0)
- max = 0;
- max = 10 * max + char_to_int(ch);
- ch = *format++;
- } else if (ch == '*') {
- max = va_arg(args, int);
- ch = *format++;
- state = DP_S_MOD;
- } else
- state = DP_S_MOD;
- break;
- case DP_S_MOD:
- switch (ch) {
- case 'h':
- cflags = DP_C_SHORT;
- ch = *format++;
- break;
- case 'l':
- if (*format == 'l') {
- cflags = DP_C_LLONG;
- format++;
- } else
- cflags = DP_C_LONG;
- ch = *format++;
- break;
- case 'q':
- cflags = DP_C_LLONG;
- ch = *format++;
- break;
- case 'L':
- cflags = DP_C_LDOUBLE;
- ch = *format++;
- break;
- default:
- break;
- }
- state = DP_S_CONV;
- break;
- case DP_S_CONV:
- switch (ch) {
- case 'd':
- case 'i':
- switch (cflags) {
- case DP_C_SHORT:
- value = (short int)va_arg(args, int);
- break;
- case DP_C_LONG:
- value = va_arg(args, long int);
- break;
- case DP_C_LLONG:
- value = va_arg(args, LLONG);
- break;
- default:
- value = va_arg(args, int);
- break;
- }
- fmtint(sbuffer, buffer, &currlen, maxlen,
- value, 10, min, max, flags);
- break;
- case 'X':
- flags |= DP_F_UP;
- /* FALLTHROUGH */
- case 'x':
- case 'o':
- case 'u':
- flags |= DP_F_UNSIGNED;
- switch (cflags) {
- case DP_C_SHORT:
- value = (unsigned short int)va_arg(args, unsigned int);
- break;
- case DP_C_LONG:
- value = (LLONG) va_arg(args,
- unsigned long int);
- break;
- case DP_C_LLONG:
- value = va_arg(args, unsigned LLONG);
- break;
- default:
- value = (LLONG) va_arg(args,
- unsigned int);
- break;
- }
- fmtint(sbuffer, buffer, &currlen, maxlen, value,
- ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),
- min, max, flags);
- break;
- case 'f':
- if (cflags == DP_C_LDOUBLE)
- fvalue = va_arg(args, LDOUBLE);
- else
- fvalue = va_arg(args, double);
- fmtfp(sbuffer, buffer, &currlen, maxlen,
- fvalue, min, max, flags);
- break;
- case 'E':
- flags |= DP_F_UP;
- case 'e':
- if (cflags == DP_C_LDOUBLE)
- fvalue = va_arg(args, LDOUBLE);
- else
- fvalue = va_arg(args, double);
- break;
- case 'G':
- flags |= DP_F_UP;
- case 'g':
- if (cflags == DP_C_LDOUBLE)
- fvalue = va_arg(args, LDOUBLE);
- else
- fvalue = va_arg(args, double);
- break;
- case 'c':
- doapr_outch(sbuffer, buffer, &currlen, maxlen,
- va_arg(args, int));
- break;
- case 's':
- strvalue = va_arg(args, char *);
- if (max < 0) {
- if (buffer)
- max = INT_MAX;
- else
- max = *maxlen;
+ char ch;
+ LLONG value;
+ LDOUBLE fvalue;
+ char *strvalue;
+ int min;
+ int max;
+ int state;
+ int flags;
+ int cflags;
+ size_t currlen;
+
+ state = DP_S_DEFAULT;
+ flags = currlen = cflags = min = 0;
+ max = -1;
+ ch = *format++;
+
+ while (state != DP_S_DONE) {
+ if (ch == '\0' || (buffer == NULL && currlen >= *maxlen))
+ state = DP_S_DONE;
+
+ switch (state) {
+ case DP_S_DEFAULT:
+ if (ch == '%')
+ state = DP_S_FLAGS;
+ else
+ doapr_outch(sbuffer, buffer, &currlen, maxlen, ch);
+ ch = *format++;
+ break;
+ case DP_S_FLAGS:
+ switch (ch) {
+ case '-':
+ flags |= DP_F_MINUS;
+ ch = *format++;
+ break;
+ case '+':
+ flags |= DP_F_PLUS;
+ ch = *format++;
+ break;
+ case ' ':
+ flags |= DP_F_SPACE;
+ ch = *format++;
+ break;
+ case '#':
+ flags |= DP_F_NUM;
+ ch = *format++;
+ break;
+ case '0':
+ flags |= DP_F_ZERO;
+ ch = *format++;
+ break;
+ default:
+ state = DP_S_MIN;
+ break;
+ }
+ break;
+ case DP_S_MIN:
+ if (isdigit((unsigned char)ch)) {
+ min = 10 * min + char_to_int(ch);
+ ch = *format++;
+ } else if (ch == '*') {
+ min = va_arg(args, int);
+ ch = *format++;
+ state = DP_S_DOT;
+ } else
+ state = DP_S_DOT;
+ break;
+ case DP_S_DOT:
+ if (ch == '.') {
+ state = DP_S_MAX;
+ ch = *format++;
+ } else
+ state = DP_S_MOD;
+ break;
+ case DP_S_MAX:
+ if (isdigit((unsigned char)ch)) {
+ if (max < 0)
+ max = 0;
+ max = 10 * max + char_to_int(ch);
+ ch = *format++;
+ } else if (ch == '*') {
+ max = va_arg(args, int);
+ ch = *format++;
+ state = DP_S_MOD;
+ } else
+ state = DP_S_MOD;
+ break;
+ case DP_S_MOD:
+ switch (ch) {
+ case 'h':
+ cflags = DP_C_SHORT;
+ ch = *format++;
+ break;
+ case 'l':
+ if (*format == 'l') {
+ cflags = DP_C_LLONG;
+ format++;
+ } else
+ cflags = DP_C_LONG;
+ ch = *format++;
+ break;
+ case 'q':
+ cflags = DP_C_LLONG;
+ ch = *format++;
+ break;
+ case 'L':
+ cflags = DP_C_LDOUBLE;
+ ch = *format++;
+ break;
+ default:
+ break;
+ }
+ state = DP_S_CONV;
+ break;
+ case DP_S_CONV:
+ switch (ch) {
+ case 'd':
+ case 'i':
+ switch (cflags) {
+ case DP_C_SHORT:
+ value = (short int)va_arg(args, int);
+ break;
+ case DP_C_LONG:
+ value = va_arg(args, long int);
+ break;
+ case DP_C_LLONG:
+ value = va_arg(args, LLONG);
+ break;
+ default:
+ value = va_arg(args, int);
+ break;
+ }
+ fmtint(sbuffer, buffer, &currlen, maxlen,
+ value, 10, min, max, flags);
+ break;
+ case 'X':
+ flags |= DP_F_UP;
+ /* FALLTHROUGH */
+ case 'x':
+ case 'o':
+ case 'u':
+ flags |= DP_F_UNSIGNED;
+ switch (cflags) {
+ case DP_C_SHORT:
+ value = (unsigned short int)va_arg(
+ args, unsigned int);
+ break;
+ case DP_C_LONG:
+ value = (LLONG)va_arg(args,
+ unsigned long int);
+ break;
+ case DP_C_LLONG:
+ value = va_arg(args, unsigned LLONG);
+ break;
+ default:
+ value = (LLONG)va_arg(args,
+ unsigned int);
+ break;
+ }
+ fmtint(sbuffer, buffer, &currlen, maxlen, value,
+ ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),
+ min, max, flags);
+ break;
+ case 'f':
+ if (cflags == DP_C_LDOUBLE)
+ fvalue = va_arg(args, LDOUBLE);
+ else
+ fvalue = va_arg(args, double);
+ fmtfp(sbuffer, buffer, &currlen, maxlen,
+ fvalue, min, max, flags);
+ break;
+ case 'E':
+ flags |= DP_F_UP;
+ case 'e':
+ if (cflags == DP_C_LDOUBLE)
+ fvalue = va_arg(args, LDOUBLE);
+ else
+ fvalue = va_arg(args, double);
+ break;
+ case 'G':
+ flags |= DP_F_UP;
+ case 'g':
+ if (cflags == DP_C_LDOUBLE)
+ fvalue = va_arg(args, LDOUBLE);
+ else
+ fvalue = va_arg(args, double);
+ break;
+ case 'c':
+ doapr_outch(sbuffer, buffer, &currlen, maxlen,
+ va_arg(args, int));
+ break;
+ case 's':
+ strvalue = va_arg(args, char *);
+ if (max < 0) {
+ if (buffer)
+ max = INT_MAX;
+ else
+ max = *maxlen;
+ }
+ fmtstr(sbuffer, buffer, &currlen, maxlen,
+ strvalue, flags, min, max);
+ break;
+ case 'p':
+ value = (long)va_arg(args, void *);
+ fmtint(sbuffer, buffer, &currlen, maxlen,
+ value, 16, min, max, flags|DP_F_NUM);
+ break;
+ case 'n': /* XXX */
+ if (cflags == DP_C_SHORT) {
+ short int *num;
+ num = va_arg(args, short int *);
+ *num = currlen;
+ } else if (cflags == DP_C_LONG) { /* XXX */
+ long int *num;
+ num = va_arg(args, long int *);
+ *num = (long int) currlen;
+ } else if (cflags == DP_C_LLONG) { /* XXX */
+ LLONG *num;
+ num = va_arg(args, LLONG *);
+ *num = (LLONG) currlen;
+ } else {
+ int *num;
+ num = va_arg(args, int *);
+ *num = currlen;
+ }
+ break;
+ case '%':
+ doapr_outch(sbuffer, buffer, &currlen, maxlen, ch);
+ break;
+ case 'w':
+ /* not supported yet, treat as next char */
+ ch = *format++;
+ break;
+ default:
+ /* unknown, skip */
+ break;
+ }
+ ch = *format++;
+ state = DP_S_DEFAULT;
+ flags = cflags = min = 0;
+ max = -1;
+ break;
+ case DP_S_DONE:
+ break;
+ default:
+ break;
}
- fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,
- flags, min, max);
- break;
- case 'p':
- value = (long)va_arg(args, void *);
- fmtint(sbuffer, buffer, &currlen, maxlen,
- value, 16, min, max, flags|DP_F_NUM);
- break;
- case 'n': /* XXX */
- if (cflags == DP_C_SHORT) {
- short int *num;
- num = va_arg(args, short int *);
- *num = currlen;
- } else if (cflags == DP_C_LONG) { /* XXX */
- long int *num;
- num = va_arg(args, long int *);
- *num = (long int) currlen;
- } else if (cflags == DP_C_LLONG) { /* XXX */
- LLONG *num;
- num = va_arg(args, LLONG *);
- *num = (LLONG) currlen;
- } else {
- int *num;
- num = va_arg(args, int *);
- *num = currlen;
- }
- break;
- case '%':
- doapr_outch(sbuffer, buffer, &currlen, maxlen, ch);
- break;
- case 'w':
- /* not supported yet, treat as next char */
- ch = *format++;
- break;
- default:
- /* unknown, skip */
- break;
- }
- ch = *format++;
- state = DP_S_DEFAULT;
- flags = cflags = min = 0;
- max = -1;
- break;
- case DP_S_DONE:
- break;
- default:
- break;
- }
- }
- *truncated = (currlen > *maxlen - 1);
- if (*truncated)
- currlen = *maxlen - 1;
- doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0');
- *retlen = currlen - 1;
- return;
+ }
+ *truncated = (currlen > *maxlen - 1);
+ if (*truncated)
+ currlen = *maxlen - 1;
+ doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0');
+ *retlen = currlen - 1;
+ return;
}
static void
-fmtstr(
- char **sbuffer,
- char **buffer,
- size_t *currlen,
- size_t *maxlen,
- const char *value,
- int flags,
- int min,
- int max)
+fmtstr(char **sbuffer, char **buffer, size_t *currlen, size_t *maxlen,
+ const char *value, int flags, int min, int max)
{
- int padlen, strln;
- int cnt = 0;
-
- if (value == 0)
- value = "<NULL>";
- for (strln = 0; value[strln]; ++strln)
- ;
- padlen = min - strln;
- if (padlen < 0)
- padlen = 0;
- if (flags & DP_F_MINUS)
- padlen = -padlen;
-
- while ((padlen > 0) && (cnt < max)) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
- --padlen;
- ++cnt;
- }
- while (*value && (cnt < max)) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, *value++);
- ++cnt;
- }
- while ((padlen < 0) && (cnt < max)) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
- ++padlen;
- ++cnt;
- }
+ int padlen, strln;
+ int cnt = 0;
+
+ if (value == 0)
+ value = "<NULL>";
+ for (strln = 0; value[strln]; ++strln)
+ ;
+ padlen = min - strln;
+ if (padlen < 0)
+ padlen = 0;
+ if (flags & DP_F_MINUS)
+ padlen = -padlen;
+
+ while ((padlen > 0) && (cnt < max)) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
+ --padlen;
+ ++cnt;
+ }
+ while (*value && (cnt < max)) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, *value++);
+ ++cnt;
+ }
+ while ((padlen < 0) && (cnt < max)) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
+ ++padlen;
+ ++cnt;
+ }
}
static void
-fmtint(
- char **sbuffer,
- char **buffer,
- size_t *currlen,
- size_t *maxlen,
- LLONG value,
- int base,
- int min,
- int max,
- int flags)
+fmtint(char **sbuffer, char **buffer, size_t *currlen, size_t *maxlen,
+ LLONG value, int base, int min, int max, int flags)
{
- int signvalue = 0;
- const char *prefix = "";
- unsigned LLONG uvalue;
- char convert[DECIMAL_SIZE(value)+3];
- int place = 0;
- int spadlen = 0;
- int zpadlen = 0;
- int caps = 0;
-
- if (max < 0)
- max = 0;
- uvalue = value;
- if (!(flags & DP_F_UNSIGNED)) {
- if (value < 0) {
- signvalue = '-';
- uvalue = -value;
- } else if (flags & DP_F_PLUS)
- signvalue = '+';
- else if (flags & DP_F_SPACE)
- signvalue = ' ';
- }
- if (flags & DP_F_NUM) {
- if (base == 8) prefix = "0";
- if (base == 16) prefix = "0x";
- }
- if (flags & DP_F_UP)
- caps = 1;
- do {
- convert[place++] =
- (caps ? "0123456789ABCDEF" : "0123456789abcdef")
- [uvalue % (unsigned) base];
- uvalue = (uvalue / (unsigned) base);
- } while (uvalue && (place < (int)sizeof(convert)));
- if (place == sizeof(convert))
- place--;
- convert[place] = 0;
-
- zpadlen = max - place;
- spadlen = min - OSSL_MAX(max, place) - (signvalue ? 1 : 0) - strlen(prefix);
- if (zpadlen < 0)
- zpadlen = 0;
- if (spadlen < 0)
- spadlen = 0;
- if (flags & DP_F_ZERO) {
- zpadlen = OSSL_MAX(zpadlen, spadlen);
- spadlen = 0;
- }
- if (flags & DP_F_MINUS)
- spadlen = -spadlen;
-
- /* spaces */
- while (spadlen > 0) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
- --spadlen;
- }
-
- /* sign */
- if (signvalue)
- doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
-
- /* prefix */
- while (*prefix) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, *prefix);
- prefix++;
- }
-
- /* zeros */
- if (zpadlen > 0) {
- while (zpadlen > 0) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
- --zpadlen;
- }
- }
- /* digits */
- while (place > 0)
- doapr_outch(sbuffer, buffer, currlen, maxlen, convert[--place]);
-
- /* left justified spaces */
- while (spadlen < 0) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
- ++spadlen;
- }
- return;
+ int signvalue = 0;
+ const char *prefix = "";
+ unsigned LLONG uvalue;
+ char convert[DECIMAL_SIZE(value) + 3];
+ int place = 0;
+ int spadlen = 0;
+ int zpadlen = 0;
+ int caps = 0;
+
+ if (max < 0)
+ max = 0;
+ uvalue = value;
+ if (!(flags & DP_F_UNSIGNED)) {
+ if (value < 0) {
+ signvalue = '-';
+ uvalue = -value;
+ } else if (flags & DP_F_PLUS)
+ signvalue = '+';
+ else if (flags & DP_F_SPACE)
+ signvalue = ' ';
+ }
+ if (flags & DP_F_NUM) {
+ if (base == 8)
+ prefix = "0";
+ if (base == 16)
+ prefix = "0x";
+ }
+ if (flags & DP_F_UP)
+ caps = 1;
+ do {
+ convert[place++] = (caps ? "0123456789ABCDEF" :
+ "0123456789abcdef")[uvalue % (unsigned) base];
+ uvalue = (uvalue / (unsigned) base);
+ } while (uvalue && (place < (int)sizeof(convert)));
+ if (place == sizeof(convert))
+ place--;
+ convert[place] = 0;
+
+ zpadlen = max - place;
+ spadlen = min - OSSL_MAX(max, place) - (signvalue ? 1 : 0) -
+ strlen(prefix);
+ if (zpadlen < 0)
+ zpadlen = 0;
+ if (spadlen < 0)
+ spadlen = 0;
+ if (flags & DP_F_ZERO) {
+ zpadlen = OSSL_MAX(zpadlen, spadlen);
+ spadlen = 0;
+ }
+ if (flags & DP_F_MINUS)
+ spadlen = -spadlen;
+
+ /* spaces */
+ while (spadlen > 0) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
+ --spadlen;
+ }
+
+ /* sign */
+ if (signvalue)
+ doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
+
+ /* prefix */
+ while (*prefix) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, *prefix);
+ prefix++;
+ }
+
+ /* zeros */
+ if (zpadlen > 0) {
+ while (zpadlen > 0) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
+ --zpadlen;
+ }
+ }
+ /* digits */
+ while (place > 0)
+ doapr_outch(sbuffer, buffer, currlen, maxlen, convert[--place]);
+
+ /* left justified spaces */
+ while (spadlen < 0) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
+ ++spadlen;
+ }
+ return;
}
static LDOUBLE
abs_val(LDOUBLE value)
{
- LDOUBLE result = value;
- if (value < 0)
- result = -value;
- return result;
+ LDOUBLE result = value;
+ if (value < 0)
+ result = -value;
+ return result;
}
static LDOUBLE
pow_10(int in_exp)
{
- LDOUBLE result = 1;
- while (in_exp) {
- result *= 10;
- in_exp--;
- }
- return result;
+ LDOUBLE result = 1;
+ while (in_exp) {
+ result *= 10;
+ in_exp--;
+ }
+ return result;
}
static long
roundv(LDOUBLE value)
{
- long intpart;
- intpart = (long) value;
- value = value - intpart;
- if (value >= 0.5)
- intpart++;
- return intpart;
+ long intpart;
+ intpart = (long) value;
+ value = value - intpart;
+ if (value >= 0.5)
+ intpart++;
+ return intpart;
}
static void
-fmtfp(
- char **sbuffer,
- char **buffer,
- size_t *currlen,
- size_t *maxlen,
- LDOUBLE fvalue,
- int min,
- int max,
- int flags)
+fmtfp(char **sbuffer, char **buffer, size_t *currlen, size_t *maxlen,
+ LDOUBLE fvalue, int min, int max, int flags)
{
- int signvalue = 0;
- LDOUBLE ufvalue;
- char iconvert[20];
- char fconvert[20];
- int iplace = 0;
- int fplace = 0;
- int padlen = 0;
- int zpadlen = 0;
- int caps = 0;
- long intpart;
- long fracpart;
- long max10;
-
- if (max < 0)
- max = 6;
- ufvalue = abs_val(fvalue);
- if (fvalue < 0)
- signvalue = '-';
- else if (flags & DP_F_PLUS)
- signvalue = '+';
- else if (flags & DP_F_SPACE)
- signvalue = ' ';
-
- intpart = (long)ufvalue;
-
- /* sorry, we only support 9 digits past the decimal because of our
- conversion method */
- if (max > 9)
- max = 9;
-
- /* we "cheat" by converting the fractional part to integer by
- multiplying by a factor of 10 */
- max10 = roundv(pow_10(max));
- fracpart = roundv(pow_10(max) * (ufvalue - intpart));
-
- if (fracpart >= max10) {
- intpart++;
- fracpart -= max10;
- }
-
- /* convert integer part */
- do {
- iconvert[iplace++] =
- (caps ? "0123456789ABCDEF"
- : "0123456789abcdef")[intpart % 10];
- intpart = (intpart / 10);
- } while (intpart && (iplace < (int)sizeof(iconvert)));
- if (iplace == sizeof iconvert)
- iplace--;
- iconvert[iplace] = 0;
-
- /* convert fractional part */
- do {
- fconvert[fplace++] =
- (caps ? "0123456789ABCDEF"
- : "0123456789abcdef")[fracpart % 10];
- fracpart = (fracpart / 10);
- } while (fplace < max);
- if (fplace == sizeof fconvert)
- fplace--;
- fconvert[fplace] = 0;
-
- /* -1 for decimal point, another -1 if we are printing a sign */
- padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
- zpadlen = max - fplace;
- if (zpadlen < 0)
- zpadlen = 0;
- if (padlen < 0)
- padlen = 0;
- if (flags & DP_F_MINUS)
- padlen = -padlen;
-
- if ((flags & DP_F_ZERO) && (padlen > 0)) {
- if (signvalue) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
- --padlen;
- signvalue = 0;
- }
- while (padlen > 0) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
- --padlen;
- }
- }
- while (padlen > 0) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
- --padlen;
- }
- if (signvalue)
- doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
-
- while (iplace > 0)
- doapr_outch(sbuffer, buffer, currlen, maxlen, iconvert[--iplace]);
-
- /*
- * Decimal point. This should probably use locale to find the correct
- * char to print out.
- */
- if (max > 0 || (flags & DP_F_NUM)) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, '.');
-
- while (fplace > 0)
- doapr_outch(sbuffer, buffer, currlen, maxlen, fconvert[--fplace]);
- }
- while (zpadlen > 0) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
- --zpadlen;
- }
-
- while (padlen < 0) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
- ++padlen;
- }
+ int signvalue = 0;
+ LDOUBLE ufvalue;
+ char iconvert[20];
+ char fconvert[20];
+ int iplace = 0;
+ int fplace = 0;
+ int padlen = 0;
+ int zpadlen = 0;
+ int caps = 0;
+ long intpart;
+ long fracpart;
+ long max10;
+
+ if (max < 0)
+ max = 6;
+ ufvalue = abs_val(fvalue);
+ if (fvalue < 0)
+ signvalue = '-';
+ else if (flags & DP_F_PLUS)
+ signvalue = '+';
+ else if (flags & DP_F_SPACE)
+ signvalue = ' ';
+
+ intpart = (long)ufvalue;
+
+ /* sorry, we only support 9 digits past the decimal because of our
+ conversion method */
+ if (max > 9)
+ max = 9;
+
+ /* we "cheat" by converting the fractional part to integer by
+ multiplying by a factor of 10 */
+ max10 = roundv(pow_10(max));
+ fracpart = roundv(pow_10(max) * (ufvalue - intpart));
+
+ if (fracpart >= max10) {
+ intpart++;
+ fracpart -= max10;
+ }
+
+ /* convert integer part */
+ do {
+ iconvert[iplace++] = (caps ? "0123456789ABCDEF" :
+ "0123456789abcdef")[intpart % 10];
+ intpart = (intpart / 10);
+ } while (intpart && (iplace < (int)sizeof(iconvert)));
+ if (iplace == sizeof iconvert)
+ iplace--;
+ iconvert[iplace] = 0;
+
+ /* convert fractional part */
+ do {
+ fconvert[fplace++] = (caps ? "0123456789ABCDEF" :
+ "0123456789abcdef")[fracpart % 10];
+ fracpart = (fracpart / 10);
+ } while (fplace < max);
+ if (fplace == sizeof fconvert)
+ fplace--;
+ fconvert[fplace] = 0;
+
+ /* -1 for decimal point, another -1 if we are printing a sign */
+ padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
+ zpadlen = max - fplace;
+ if (zpadlen < 0)
+ zpadlen = 0;
+ if (padlen < 0)
+ padlen = 0;
+ if (flags & DP_F_MINUS)
+ padlen = -padlen;
+
+ if ((flags & DP_F_ZERO) && (padlen > 0)) {
+ if (signvalue) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
+ --padlen;
+ signvalue = 0;
+ }
+ while (padlen > 0) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
+ --padlen;
+ }
+ }
+ while (padlen > 0) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
+ --padlen;
+ }
+ if (signvalue)
+ doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
+
+ while (iplace > 0)
+ doapr_outch(sbuffer, buffer, currlen, maxlen, iconvert[--iplace]);
+
+ /*
+ * Decimal point. This should probably use locale to find the correct
+ * char to print out.
+ */
+ if (max > 0 || (flags & DP_F_NUM)) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, '.');
+
+ while (fplace > 0)
+ doapr_outch(sbuffer, buffer, currlen, maxlen, fconvert[--fplace]);
+ }
+ while (zpadlen > 0) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
+ --zpadlen;
+ }
+
+ while (padlen < 0) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
+ ++padlen;
+ }
}
static void
-doapr_outch(
- char **sbuffer,
- char **buffer,
- size_t *currlen,
- size_t *maxlen,
+doapr_outch(char **sbuffer, char **buffer, size_t *currlen, size_t *maxlen,
int c)
{
- /* If we haven't at least one buffer, someone has doe a big booboo */
- assert(*sbuffer != NULL || buffer != NULL);
-
- if (buffer) {
- while (*currlen >= *maxlen) {
- if (*buffer == NULL) {
- if (*maxlen == 0)
- *maxlen = 1024;
- *buffer = OPENSSL_malloc(*maxlen);
- if (*currlen > 0) {
- assert(*sbuffer != NULL);
- memcpy(*buffer, *sbuffer, *currlen);
+ /* If we haven't at least one buffer, someone has doe a big booboo */
+ assert(*sbuffer != NULL || buffer != NULL);
+
+ if (buffer) {
+ while (*currlen >= *maxlen) {
+ if (*buffer == NULL) {
+ if (*maxlen == 0)
+ *maxlen = 1024;
+ *buffer = OPENSSL_malloc(*maxlen);
+ if (*currlen > 0) {
+ assert(*sbuffer != NULL);
+ memcpy(*buffer, *sbuffer, *currlen);
+ }
+ *sbuffer = NULL;
+ } else {
+ *maxlen += 1024;
+ *buffer = OPENSSL_realloc(*buffer, *maxlen);
+ }
}
- *sbuffer = NULL;
- } else {
- *maxlen += 1024;
- *buffer = OPENSSL_realloc(*buffer, *maxlen);
- }
+ /* What to do if *buffer is NULL? */
+ assert(*sbuffer != NULL || *buffer != NULL);
}
- /* What to do if *buffer is NULL? */
- assert(*sbuffer != NULL || *buffer != NULL);
- }
- if (*currlen < *maxlen) {
- if (*sbuffer)
- (*sbuffer)[(*currlen)++] = (char)c;
- else
- (*buffer)[(*currlen)++] = (char)c;
- }
+ if (*currlen < *maxlen) {
+ if (*sbuffer)
+ (*sbuffer)[(*currlen)++] = (char)c;
+ else
+ (*buffer)[(*currlen)++] = (char)c;
+ }
- return;
+ return;
}
/***************************************************************************/
int BIO_printf (BIO *bio, const char *format, ...)
- {
+{
va_list args;
int ret;
ret = BIO_vprintf(bio, format, args);
va_end(args);
- return(ret);
- }
+ return (ret);
+}
int BIO_vprintf (BIO *bio, const char *format, va_list args)
- {
+{
int ret;
size_t retlen;
char hugebuf[1024*2]; /* Was previously 10k, which is unreasonable
- in small-stack environments, like threads
+ in small - stack environments, like threads
or DOS programs. */
char *hugebufp = hugebuf;
size_t hugebufsize = sizeof(hugebuf);
dynbuf = NULL;
CRYPTO_push_info("doapr()");
- _dopr(&hugebufp, &dynbuf, &hugebufsize,
- &retlen, &ignored, format, args);
- if (dynbuf)
- {
- ret=BIO_write(bio, dynbuf, (int)retlen);
+ _dopr(&hugebufp, &dynbuf, &hugebufsize, &retlen, &ignored,
+ format, args);
+ if (dynbuf) {
+ ret = BIO_write(bio, dynbuf, (int)retlen);
OPENSSL_free(dynbuf);
- }
- else
- {
- ret=BIO_write(bio, hugebuf, (int)retlen);
- }
- CRYPTO_pop_info();
- return(ret);
+ } else {
+ ret = BIO_write(bio, hugebuf, (int)retlen);
}
+ CRYPTO_pop_info();
+ return (ret);
+}
/* As snprintf is not available everywhere, we provide our own implementation.
* This function has nothing to do with BIOs, but it's closely related
* to BIO_printf, and we need *some* name prefix ...
* (XXX the function should be renamed, but to what?) */
-int BIO_snprintf(char *buf, size_t n, const char *format, ...)
- {
+int
+BIO_snprintf(char *buf, size_t n, const char *format, ...)
+{
va_list args;
int ret;
ret = BIO_vsnprintf(buf, n, format, args);
va_end(args);
- return(ret);
- }
+ return (ret);
+}
-int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
- {
+int
+BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
+{
size_t retlen;
int truncated;
return -1;
else
return (retlen <= INT_MAX) ? (int)retlen : -1;
- }
+}
#endif
#if defined(OPENSSL_SYS_WINDOWS) || (defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK))
-static int wsa_init_done=0;
+static int wsa_init_done = 0;
#endif
/*
#endif
#if 0
-static unsigned long BIO_ghbn_hits=0L;
-static unsigned long BIO_ghbn_miss=0L;
+static unsigned long BIO_ghbn_hits = 0L;
+static unsigned long BIO_ghbn_miss = 0L;
#define GHBN_NUM 4
-static struct ghbn_cache_st
- {
+static struct ghbn_cache_st {
char name[129];
struct hostent *ent;
unsigned long order;
- } ghbn_cache[GHBN_NUM];
+} ghbn_cache[GHBN_NUM];
#endif
-static int get_ip(const char *str,unsigned char *ip);
+static int get_ip(const char *str, unsigned char *ip);
#if 0
static void ghbn_free(struct hostent *a);
static struct hostent *ghbn_dup(struct hostent *a);
#endif
-int BIO_get_host_ip(const char *str, unsigned char *ip)
- {
+
+int
+BIO_get_host_ip(const char *str, unsigned char *ip)
+{
int i;
int err = 1;
int locked = 0;
struct hostent *he;
- i=get_ip(str,ip);
- if (i < 0)
- {
- BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS);
+ i = get_ip(str, ip);
+ if (i < 0) {
+ BIOerr(BIO_F_BIO_GET_HOST_IP, BIO_R_INVALID_IP_ADDRESS);
goto err;
- }
+ }
/* At this point, we have something that is most probably correct
in some way, so let's init the socket. */
/* If the string actually contained an IP address, we need not do
anything more */
- if (i > 0) return(1);
+ if (i > 0)
+ return (1);
/* do a gethostbyname */
CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
locked = 1;
- he=BIO_gethostbyname(str);
- if (he == NULL)
- {
- BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_BAD_HOSTNAME_LOOKUP);
+ he = BIO_gethostbyname(str);
+ if (he == NULL) {
+ BIOerr(BIO_F_BIO_GET_HOST_IP, BIO_R_BAD_HOSTNAME_LOOKUP);
goto err;
- }
+ }
/* cast to short because of win16 winsock definition */
- if ((short)he->h_addrtype != AF_INET)
- {
- BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET);
+ if ((short)he->h_addrtype != AF_INET) {
+ BIOerr(BIO_F_BIO_GET_HOST_IP, BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET);
goto err;
- }
- for (i=0; i<4; i++)
- ip[i]=he->h_addr_list[0][i];
+ }
+ for (i = 0; i < 4; i++)
+ ip[i] = he->h_addr_list[0][i];
err = 0;
- err:
+err:
if (locked)
CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
- if (err)
- {
- ERR_add_error_data(2,"host=",str);
+ if (err) {
+ ERR_add_error_data(2, "host=", str);
return 0;
- }
- else
+ } else
return 1;
- }
+}
-int BIO_get_port(const char *str, unsigned short *port_ptr)
- {
+int
+BIO_get_port(const char *str, unsigned short *port_ptr)
+{
int i;
struct servent *s;
- if (str == NULL)
- {
- BIOerr(BIO_F_BIO_GET_PORT,BIO_R_NO_PORT_DEFINED);
- return(0);
- }
- i=atoi(str);
+ if (str == NULL) {
+ BIOerr(BIO_F_BIO_GET_PORT, BIO_R_NO_PORT_DEFINED);
+ return (0);
+ }
+ i = atoi(str);
if (i != 0)
- *port_ptr=(unsigned short)i;
- else
- {
+ *port_ptr = (unsigned short)i;
+ else {
CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME);
/* Note: under VMS with SOCKETSHR, it seems like the first
* parameter is 'char *', instead of 'const char *'
*/
#ifndef CONST_STRICT
- s=getservbyname((char *)str,"tcp");
+ s = getservbyname((char *)str, "tcp");
#else
- s=getservbyname(str,"tcp");
+ s = getservbyname(str, "tcp");
#endif
- if(s != NULL)
- *port_ptr=ntohs((unsigned short)s->s_port);
+ if (s != NULL)
+ *port_ptr = ntohs((unsigned short)s->s_port);
CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME);
- if(s == NULL)
- {
- if (strcmp(str,"http") == 0)
- *port_ptr=80;
- else if (strcmp(str,"telnet") == 0)
- *port_ptr=23;
- else if (strcmp(str,"socks") == 0)
- *port_ptr=1080;
- else if (strcmp(str,"https") == 0)
- *port_ptr=443;
- else if (strcmp(str,"ssl") == 0)
- *port_ptr=443;
- else if (strcmp(str,"ftp") == 0)
- *port_ptr=21;
- else if (strcmp(str,"gopher") == 0)
- *port_ptr=70;
+ if (s == NULL) {
+ if (strcmp(str, "http") == 0)
+ *port_ptr = 80;
+ else if (strcmp(str, "telnet") == 0)
+ *port_ptr = 23;
+ else if (strcmp(str, "socks") == 0)
+ *port_ptr = 1080;
+ else if (strcmp(str, "https") == 0)
+ *port_ptr = 443;
+ else if (strcmp(str, "ssl") == 0)
+ *port_ptr = 443;
+ else if (strcmp(str, "ftp") == 0)
+ *port_ptr = 21;
+ else if (strcmp(str, "gopher") == 0)
+ *port_ptr = 70;
#if 0
- else if (strcmp(str,"wais") == 0)
- *port_ptr=21;
-#endif
- else
- {
- SYSerr(SYS_F_GETSERVBYNAME,errno);
- ERR_add_error_data(3,"service='",str,"'");
- return(0);
- }
+ else if (strcmp(str, "wais") == 0)
+ *port_ptr = 21;
+#endif
+ else {
+ SYSerr(SYS_F_GETSERVBYNAME, errno);
+ ERR_add_error_data(3, "service = '", str, "'");
+ return (0);
}
}
- return(1);
}
+ return (1);
+}
-int BIO_sock_error(int sock)
- {
- int j,i;
+int
+BIO_sock_error(int sock)
+{
+ int j, i;
int size;
-
+
#if defined(OPENSSL_SYS_BEOS_R5)
return 0;
#endif
-
- size=sizeof(int);
+
+ size = sizeof(int);
/* Note: under Windows the third parameter is of type (char *)
* whereas under other systems it is (void *) if you don't have
* a cast it will choke the compiler: if you do have a cast then
* you can either go for (char *) or (void *).
*/
- i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(void *)&j,(void *)&size);
+ i = getsockopt(sock, SOL_SOCKET, SO_ERROR,(void *)&j,(void *)&size);
if (i < 0)
- return(1);
+ return (1);
else
- return(j);
- }
+ return (j);
+}
#if 0
-long BIO_ghbn_ctrl(int cmd, int iarg, char *parg)
- {
+long
+BIO_ghbn_ctrl(int cmd, int iarg, char *parg)
+{
int i;
char **p;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_GHBN_CTRL_HITS:
- return(BIO_ghbn_hits);
+ return (BIO_ghbn_hits);
/* break; */
case BIO_GHBN_CTRL_MISSES:
- return(BIO_ghbn_miss);
+ return (BIO_ghbn_miss);
/* break; */
case BIO_GHBN_CTRL_CACHE_SIZE:
- return(GHBN_NUM);
+ return (GHBN_NUM);
/* break; */
case BIO_GHBN_CTRL_GET_ENTRY:
- if ((iarg >= 0) && (iarg <GHBN_NUM) &&
- (ghbn_cache[iarg].order > 0))
- {
- p=(char **)parg;
- if (p == NULL) return(0);
- *p=ghbn_cache[iarg].name;
- ghbn_cache[iarg].name[128]='\0';
- return(1);
- }
- return(0);
+ if ((iarg >= 0) && (iarg < GHBN_NUM) &&
+ (ghbn_cache[iarg].order > 0)) {
+ p = (char **)parg;
+ if (p == NULL)
+ return (0);
+ *p = ghbn_cache[iarg].name;
+ ghbn_cache[iarg].name[128] = '\0';
+ return (1);
+ }
+ return (0);
/* break; */
case BIO_GHBN_CTRL_FLUSH:
- for (i=0; i<GHBN_NUM; i++)
- ghbn_cache[i].order=0;
+ for (i = 0; i < GHBN_NUM; i++)
+ ghbn_cache[i].order = 0;
break;
default:
- return(0);
- }
- return(1);
+ return (0);
}
+ return (1);
+}
#endif
#if 0
-static struct hostent *ghbn_dup(struct hostent *a)
- {
+static struct hostent
+*ghbn_dup(struct hostent *a)
+{
struct hostent *ret;
- int i,j;
+ int i, j;
MemCheck_off();
- ret=(struct hostent *)OPENSSL_malloc(sizeof(struct hostent));
- if (ret == NULL) return(NULL);
- memset(ret,0,sizeof(struct hostent));
+ ret = (struct hostent *)OPENSSL_malloc(sizeof(struct hostent));
+ if (ret == NULL)
+ return (NULL);
+ memset(ret, 0, sizeof(struct hostent));
- for (i=0; a->h_aliases[i] != NULL; i++)
+ for (i = 0; a->h_aliases[i] != NULL; i++)
;
i++;
ret->h_aliases = (char **)OPENSSL_malloc(i*sizeof(char *));
goto err;
memset(ret->h_aliases, 0, i*sizeof(char *));
- for (i=0; a->h_addr_list[i] != NULL; i++)
+ for (i = 0; a->h_addr_list[i] != NULL; i++)
;
i++;
- ret->h_addr_list=(char **)OPENSSL_malloc(i*sizeof(char *));
+ ret->h_addr_list = (char **)OPENSSL_malloc(i*sizeof(char *));
if (ret->h_addr_list == NULL)
goto err;
memset(ret->h_addr_list, 0, i*sizeof(char *));
- j=strlen(a->h_name)+1;
- if ((ret->h_name=OPENSSL_malloc(j)) == NULL) goto err;
- memcpy((char *)ret->h_name,a->h_name,j);
- for (i=0; a->h_aliases[i] != NULL; i++)
- {
- j=strlen(a->h_aliases[i])+1;
- if ((ret->h_aliases[i]=OPENSSL_malloc(j)) == NULL) goto err;
- memcpy(ret->h_aliases[i],a->h_aliases[i],j);
- }
- ret->h_length=a->h_length;
- ret->h_addrtype=a->h_addrtype;
- for (i=0; a->h_addr_list[i] != NULL; i++)
- {
- if ((ret->h_addr_list[i]=OPENSSL_malloc(a->h_length)) == NULL)
+ j = strlen(a->h_name) + 1;
+ if ((ret->h_name = OPENSSL_malloc(j)) == NULL) goto err;
+ memcpy((char *)ret->h_name, a->h_name, j);
+ for (i = 0; a->h_aliases[i] != NULL; i++) {
+ j = strlen(a->h_aliases[i]) + 1;
+ if ((ret->h_aliases[i] = OPENSSL_malloc(j)) == NULL) goto err;
+ memcpy(ret->h_aliases[i], a->h_aliases[i], j);
+ }
+ ret->h_length = a->h_length;
+ ret->h_addrtype = a->h_addrtype;
+ for (i = 0; a->h_addr_list[i] != NULL; i++) {
+ if ((ret->h_addr_list[i] = OPENSSL_malloc(a->h_length)) == NULL)
goto err;
- memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length);
- }
- if (0)
- {
-err:
+ memcpy(ret->h_addr_list[i], a->h_addr_list[i], a->h_length);
+ }
+ if (0) {
+err:
if (ret != NULL)
ghbn_free(ret);
- ret=NULL;
- }
- MemCheck_on();
- return(ret);
+ ret = NULL;
}
+ MemCheck_on();
+ return (ret);
+}
-static void ghbn_free(struct hostent *a)
- {
+static void
+ghbn_free(struct hostent *a)
+{
int i;
- if(a == NULL)
- return;
+ if (a == NULL)
+ return;
- if (a->h_aliases != NULL)
- {
- for (i=0; a->h_aliases[i] != NULL; i++)
+ if (a->h_aliases != NULL) {
+ for (i = 0; a->h_aliases[i] != NULL; i++)
OPENSSL_free(a->h_aliases[i]);
OPENSSL_free(a->h_aliases);
- }
- if (a->h_addr_list != NULL)
- {
- for (i=0; a->h_addr_list[i] != NULL; i++)
+ }
+ if (a->h_addr_list != NULL) {
+ for (i = 0; a->h_addr_list[i] != NULL; i++)
OPENSSL_free(a->h_addr_list[i]);
OPENSSL_free(a->h_addr_list);
- }
- if (a->h_name != NULL) OPENSSL_free(a->h_name);
- OPENSSL_free(a);
}
+ if (a->h_name != NULL)
+ OPENSSL_free(a->h_name);
+ OPENSSL_free(a);
+}
#endif
-struct hostent *BIO_gethostbyname(const char *name)
- {
+struct hostent
+*BIO_gethostbyname(const char *name) {
#if 1
/* Caching gethostbyname() results forever is wrong,
* so we have to let the true gethostbyname() worry about this */
#endif
#else
struct hostent *ret;
- int i,lowi=0,j;
- unsigned long low= (unsigned long)-1;
+ int i, lowi = 0, j;
+ unsigned long low = (unsigned long) - 1;
# if 0
*/
CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
# endif
- j=strlen(name);
- if (j < 128)
- {
- for (i=0; i<GHBN_NUM; i++)
- {
- if (low > ghbn_cache[i].order)
- {
- low=ghbn_cache[i].order;
- lowi=i;
- }
- if (ghbn_cache[i].order > 0)
- {
- if (strncmp(name,ghbn_cache[i].name,128) == 0)
+ j = strlen(name);
+ if (j < 128) {
+ for (i = 0; i < GHBN_NUM; i++) {
+ if (low > ghbn_cache[i].order) {
+ low = ghbn_cache[i].order;
+ lowi = i;
+ }
+ if (ghbn_cache[i].order > 0) {
+ if (strncmp(name, ghbn_cache[i].name, 128) == 0)
break;
- }
}
}
- else
- i=GHBN_NUM;
+ } else
+ i = GHBN_NUM;
if (i == GHBN_NUM) /* no hit*/
- {
+ {
BIO_ghbn_miss++;
/* Note: under VMS with SOCKETSHR, it seems like the first
* parameter is 'char *', instead of 'const char *'
*/
# ifndef CONST_STRICT
- ret=gethostbyname((char *)name);
+ ret = gethostbyname((char *)name);
# else
- ret=gethostbyname(name);
+ ret = gethostbyname(name);
# endif
if (ret == NULL)
goto end;
if (j > 128) /* too big to cache */
- {
+ {
# if 0
/* If we were trying to make this function thread-safe (which
* is bound to fail), we'd have to give up in this case
ret = NULL;
# endif
goto end;
- }
+ }
/* else add to cache */
if (ghbn_cache[lowi].ent != NULL)
ghbn_free(ghbn_cache[lowi].ent); /* XXX not thread-safe */
ghbn_cache[lowi].name[0] = '\0';
- if((ret=ghbn_cache[lowi].ent=ghbn_dup(ret)) == NULL)
- {
- BIOerr(BIO_F_BIO_GETHOSTBYNAME,ERR_R_MALLOC_FAILURE);
+ if ((ret = ghbn_cache[lowi].ent = ghbn_dup(ret)) == NULL) {
+ BIOerr(BIO_F_BIO_GETHOSTBYNAME, ERR_R_MALLOC_FAILURE);
goto end;
- }
- strncpy(ghbn_cache[lowi].name,name,128);
- ghbn_cache[lowi].order=BIO_ghbn_miss+BIO_ghbn_hits;
}
- else
- {
+ strncpy(ghbn_cache[lowi].name, name, 128);
+ ghbn_cache[lowi].order = BIO_ghbn_miss + BIO_ghbn_hits;
+ } else {
BIO_ghbn_hits++;
- ret= ghbn_cache[i].ent;
- ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits;
- }
+ ret = ghbn_cache[i].ent;
+ ghbn_cache[i].order = BIO_ghbn_miss + BIO_ghbn_hits;
+ }
end:
# if 0
CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
# endif
- return(ret);
+ return (ret);
#endif
- }
+}
-int BIO_sock_init(void)
- {
+int
+BIO_sock_init(void)
+{
#ifdef OPENSSL_SYS_WINDOWS
static struct WSAData wsa_state;
- if (!wsa_init_done)
- {
+ if (!wsa_init_done) {
int err;
-
- wsa_init_done=1;
- memset(&wsa_state,0,sizeof(wsa_state));
+
+ wsa_init_done = 1;
+ memset(&wsa_state, 0, sizeof(wsa_state));
/* Not making wsa_state available to the rest of the
* code is formally wrong. But the structures we use
* are [beleived to be] invariable among Winsock DLLs,
* while API availability is [expected to be] probed
* at run-time with DSO_global_lookup. */
- if (WSAStartup(0x0202,&wsa_state)!=0)
- {
- err=WSAGetLastError();
- SYSerr(SYS_F_WSASTARTUP,err);
- BIOerr(BIO_F_BIO_SOCK_INIT,BIO_R_WSASTARTUP);
- return(-1);
- }
+ if (WSAStartup(0x0202, &wsa_state) != 0) {
+ err = WSAGetLastError();
+ SYSerr(SYS_F_WSASTARTUP, err);
+ BIOerr(BIO_F_BIO_SOCK_INIT, BIO_R_WSASTARTUP);
+ return (-1);
}
+ }
#endif /* OPENSSL_SYS_WINDOWS */
#ifdef WATT32
extern int _watt_do_exit;
- _watt_do_exit = 0; /* don't make sock_init() call exit() */
+ _watt_do_exit = 0;
+ /* don't make sock_init() call exit() */
if (sock_init())
return (-1);
#endif
#if defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)
- WORD wVerReq;
- WSADATA wsaData;
- int err;
-
- if (!wsa_init_done)
- {
- wsa_init_done=1;
- wVerReq = MAKEWORD( 2, 0 );
- err = WSAStartup(wVerReq,&wsaData);
- if (err != 0)
- {
- SYSerr(SYS_F_WSASTARTUP,err);
- BIOerr(BIO_F_BIO_SOCK_INIT,BIO_R_WSASTARTUP);
- return(-1);
- }
+ WORD wVerReq;
+ WSADATA wsaData;
+ int err;
+
+ if (!wsa_init_done) {
+ wsa_init_done = 1;
+ wVerReq = MAKEWORD( 2, 0 );
+ err = WSAStartup(wVerReq, &wsaData);
+ if (err != 0) {
+ SYSerr(SYS_F_WSASTARTUP, err);
+ BIOerr(BIO_F_BIO_SOCK_INIT, BIO_R_WSASTARTUP);
+ return (-1);
}
+ }
#endif
- return(1);
- }
+ return (1);
+}
-void BIO_sock_cleanup(void)
- {
+void
+BIO_sock_cleanup(void)
+{
#ifdef OPENSSL_SYS_WINDOWS
- if (wsa_init_done)
- {
- wsa_init_done=0;
+ if (wsa_init_done) {
+ wsa_init_done = 0;
#if 0 /* this call is claimed to be non-present in Winsock2 */
WSACancelBlockingCall();
#endif
WSACleanup();
- }
+ }
#elif defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)
- if (wsa_init_done)
- {
- wsa_init_done=0;
- WSACleanup();
- }
-#endif
+ if (wsa_init_done) {
+ wsa_init_done = 0;
+ WSACleanup();
}
+#endif
+}
#if !defined(OPENSSL_SYS_VMS) || __VMS_VER >= 70000000
-int BIO_socket_ioctl(int fd, long type, void *arg)
- {
+int
+BIO_socket_ioctl(int fd, long type, void *arg)
+{
int i;
#ifdef __DJGPP__
- i=ioctl(fd,type,(char *)arg);
+ i = ioctl(fd, type,(char *)arg);
#else
# if defined(OPENSSL_SYS_VMS)
/* 2011-02-18 SMS.
# define ARG arg
# endif /* defined(OPENSSL_SYS_VMS) [else] */
- i=ioctl(fd,type,ARG);
+ i = ioctl(fd, type, ARG);
#endif /* __DJGPP__ */
if (i < 0)
- SYSerr(SYS_F_IOCTLSOCKET,errno);
- return(i);
- }
+ SYSerr(SYS_F_IOCTLSOCKET, errno);
+ return (i);
+}
#endif /* __VMS_VER */
/* The reason I have implemented this instead of using sscanf is because
* Visual C 1.52c gives an unresolved external when linking a DLL :-( */
-static int get_ip(const char *str, unsigned char ip[4])
- {
+static int
+get_ip(const char *str, unsigned char ip[4])
+{
unsigned int tmp[4];
- int num=0,c,ok=0;
+ int num = 0, c, ok = 0;
- tmp[0]=tmp[1]=tmp[2]=tmp[3]=0;
+ tmp[0] = tmp[1] = tmp[2] = tmp[3] = 0;
- for (;;)
- {
+ for (;;) {
c= *(str++);
- if ((c >= '0') && (c <= '9'))
- {
- ok=1;
- tmp[num]=tmp[num]*10+c-'0';
- if (tmp[num] > 255) return(0);
- }
- else if (c == '.')
- {
- if (!ok) return(-1);
- if (num == 3) return(0);
+ if ((c >= '0') && (c <= '9')) {
+ ok = 1;
+ tmp[num] = tmp[num]*10 + c-'0';
+ if (tmp[num] > 255)
+ return (0);
+ } else if (c == '.') {
+ if (!ok)
+ return (-1);
+ if (num == 3)
+ return (0);
num++;
- ok=0;
- }
- else if (c == '\0' && (num == 3) && ok)
- break;
+ ok = 0;
+ } else if (c == '\0' && (num == 3) && ok)
+ break;
else
- return(0);
- }
- ip[0]=tmp[0];
- ip[1]=tmp[1];
- ip[2]=tmp[2];
- ip[3]=tmp[3];
- return(1);
+ return (0);
}
-
-int BIO_get_accept_socket(char *host, int bind_mode)
- {
- int ret=0;
+ ip[0] = tmp[0];
+ ip[1] = tmp[1];
+ ip[2] = tmp[2];
+ ip[3] = tmp[3];
+ return (1);
+}
+
+int
+BIO_get_accept_socket(char *host, int bind_mode)
+{
+ int ret = 0;
union {
struct sockaddr sa;
struct sockaddr_in sa_in;
#if OPENSSL_USE_IPV6
struct sockaddr_in6 sa_in6;
#endif
- } server,client;
- int s=-1,cs,addrlen;
+ } server, client;
+ int s = -1, cs, addrlen;
unsigned char ip[4];
unsigned short port;
- char *str=NULL,*e;
- char *h,*p;
+ char *str = NULL, *e;
+ char *h, *p;
unsigned long l;
int err_num;
- if (BIO_sock_init() != 1) return(-1);
+ if (BIO_sock_init() != 1)
+ return (-1);
- if ((str=BUF_strdup(host)) == NULL) return(-1);
+ if ((str = BUF_strdup(host)) == NULL)
+ return (-1);
- h=p=NULL;
- h=str;
- for (e=str; *e; e++)
- {
- if (*e == ':')
- {
- p=e;
- }
- else if (*e == '/')
- {
- *e='\0';
+ h = p = NULL;
+ h = str;
+ for (e = str; *e; e++) {
+ if (*e == ':') {
+ p = e;
+ } else if (*e == '/') {
+ *e = '\0';
break;
- }
}
- if (p) *p++='\0'; /* points at last ':', '::port' is special [see below] */
- else p=h,h=NULL;
+ }
+ if (p)
+ *p++='\0'; /* points at last ':', '::port' is special [see below] */
+ else
+ p = h, h = NULL;
#ifdef EAI_FAMILY
do {
- static union { void *p;
- int (WSAAPI *f)(const char *,const char *,
- const struct addrinfo *,
- struct addrinfo **);
- } p_getaddrinfo = {NULL};
- static union { void *p;
+ static union {
+ void *p;
+ int (WSAAPI *f)(const char *, const char *,
+ const struct addrinfo *,
+ struct addrinfo **);
+ } p_getaddrinfo = {NULL};
+ static union {
+ void *p;
void (WSAAPI *f)(struct addrinfo *);
- } p_freeaddrinfo = {NULL};
- struct addrinfo *res,hint;
-
- if (p_getaddrinfo.p==NULL)
- {
- if ((p_getaddrinfo.p=DSO_global_lookup("getaddrinfo"))==NULL ||
- (p_freeaddrinfo.p=DSO_global_lookup("freeaddrinfo"))==NULL)
- p_getaddrinfo.p=(void*)-1;
- }
- if (p_getaddrinfo.p==(void *)-1) break;
-
- /* '::port' enforces IPv6 wildcard listener. Some OSes,
- * e.g. Solaris, default to IPv6 without any hint. Also
- * note that commonly IPv6 wildchard socket can service
- * IPv4 connections just as well... */
- memset(&hint,0,sizeof(hint));
- hint.ai_flags = AI_PASSIVE;
- if (h)
- {
- if (strchr(h,':'))
- {
- if (h[1]=='\0') h=NULL;
+ } p_freeaddrinfo = {NULL};
+ struct addrinfo *res, hint;
+
+ if (p_getaddrinfo.p == NULL) {
+ if ((p_getaddrinfo.p = DSO_global_lookup("getaddrinfo"))==NULL ||
+ (p_freeaddrinfo.p = DSO_global_lookup("freeaddrinfo"))==NULL)
+ p_getaddrinfo.p = (void*) - 1;
+ }
+ if (p_getaddrinfo.p == (void *) - 1) break;
+
+ /* '::port' enforces IPv6 wildcard listener. Some OSes,
+ * e.g. Solaris, default to IPv6 without any hint. Also
+ * note that commonly IPv6 wildchard socket can service
+ * IPv4 connections just as well... */
+ memset(&hint, 0, sizeof(hint));
+ hint.ai_flags = AI_PASSIVE;
+ if (h) {
+ if (strchr(h, ':')) {
+ if (h[1] == '\0')
+ h = NULL;
#if OPENSSL_USE_IPV6
- hint.ai_family = AF_INET6;
+ hint.ai_family = AF_INET6;
#else
- h=NULL;
+ h = NULL;
#endif
- }
- else if (h[0]=='*' && h[1]=='\0')
- {
- hint.ai_family = AF_INET;
- h=NULL;
+ } else if (h[0] == '*' && h[1] == '\0') {
+ hint.ai_family = AF_INET;
+ h = NULL;
}
}
- if ((*p_getaddrinfo.f)(h,p,&hint,&res)) break;
+ if ((*p_getaddrinfo.f)(h, p, &hint, &res))
+ break;
- addrlen = res->ai_addrlen<=sizeof(server) ?
- res->ai_addrlen :
- sizeof(server);
- memcpy(&server, res->ai_addr, addrlen);
+ addrlen = res->ai_addrlen <= sizeof(server) ?
+ res->ai_addrlen : sizeof(server);
+ memcpy(&server, res->ai_addr, addrlen);
- (*p_freeaddrinfo.f)(res);
- goto again;
+ (*p_freeaddrinfo.f)(res);
+ goto again;
} while (0);
#endif
- if (!BIO_get_port(p,&port)) goto err;
+ if (!BIO_get_port(p, &port))
+ goto err;
- memset((char *)&server,0,sizeof(server));
- server.sa_in.sin_family=AF_INET;
- server.sa_in.sin_port=htons(port);
+ memset((char *)&server, 0, sizeof(server));
+ server.sa_in.sin_family = AF_INET;
+ server.sa_in.sin_port = htons(port);
addrlen = sizeof(server.sa_in);
- if (h == NULL || strcmp(h,"*") == 0)
- server.sa_in.sin_addr.s_addr=INADDR_ANY;
- else
- {
- if (!BIO_get_host_ip(h,&(ip[0]))) goto err;
- l=(unsigned long)
- ((unsigned long)ip[0]<<24L)|
- ((unsigned long)ip[1]<<16L)|
- ((unsigned long)ip[2]<< 8L)|
- ((unsigned long)ip[3]);
- server.sa_in.sin_addr.s_addr=htonl(l);
- }
+ if (h == NULL || strcmp(h, "*") == 0)
+ server.sa_in.sin_addr.s_addr = INADDR_ANY;
+ else {
+ if (!BIO_get_host_ip(h, &(ip[0])))
+ goto err;
+ l = (unsigned long)
+ ((unsigned long)ip[0]<<24L)|
+ ((unsigned long)ip[1]<<16L)|
+ ((unsigned long)ip[2]<< 8L)|
+ ((unsigned long)ip[3]);
+ server.sa_in.sin_addr.s_addr = htonl(l);
+ }
again:
- s=socket(server.sa.sa_family,SOCK_STREAM,SOCKET_PROTOCOL);
- if (s == -1)
- {
- SYSerr(SYS_F_SOCKET,errno);
- ERR_add_error_data(3,"port='",host,"'");
- BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_CREATE_SOCKET);
+ s = socket(server.sa.sa_family, SOCK_STREAM, SOCKET_PROTOCOL);
+ if (s == -1) {
+ SYSerr(SYS_F_SOCKET, errno);
+ ERR_add_error_data(3, "port = '", host, "'");
+ BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, BIO_R_UNABLE_TO_CREATE_SOCKET);
goto err;
- }
+ }
#ifdef SO_REUSEADDR
- if (bind_mode == BIO_BIND_REUSEADDR)
- {
- int i=1;
+ if (bind_mode == BIO_BIND_REUSEADDR) {
+ int i = 1;
- ret=setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&i,sizeof(i));
- bind_mode=BIO_BIND_NORMAL;
- }
+ ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR,(char *)&i, sizeof(i));
+ bind_mode = BIO_BIND_NORMAL;
+ }
#endif
- if (bind(s,&server.sa,addrlen) == -1)
- {
+ if (bind(s, &server.sa, addrlen) == -1) {
#ifdef SO_REUSEADDR
- err_num=errno;
+ err_num = errno;
if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) &&
#ifdef OPENSSL_SYS_WINDOWS
/* Some versions of Windows define EADDRINUSE to
* a dummy value.
*/
- (err_num == WSAEADDRINUSE))
+ (err_num == WSAEADDRINUSE))
#else
- (err_num == EADDRINUSE))
+ (err_num == EADDRINUSE))
#endif
- {
+ {
client = server;
- if (h == NULL || strcmp(h,"*") == 0)
- {
+ if (h == NULL || strcmp(h, "*") == 0) {
#if OPENSSL_USE_IPV6
- if (client.sa.sa_family == AF_INET6)
- {
- memset(&client.sa_in6.sin6_addr,0,sizeof(client.sa_in6.sin6_addr));
- client.sa_in6.sin6_addr.s6_addr[15]=1;
- }
- else
-#endif
- if (client.sa.sa_family == AF_INET)
- {
- client.sa_in.sin_addr.s_addr=htonl(0x7F000001);
- }
- else goto err;
- }
- cs=socket(client.sa.sa_family,SOCK_STREAM,SOCKET_PROTOCOL);
- if (cs != -1)
- {
+ if (client.sa.sa_family == AF_INET6) {
+ memset(&client.sa_in6.sin6_addr, 0, sizeof(client.sa_in6.sin6_addr));
+ client.sa_in6.sin6_addr.s6_addr[15] = 1;
+ } else
+#endif
+ if (client.sa.sa_family == AF_INET) {
+ client.sa_in.sin_addr.s_addr = htonl(0x7F000001);
+ } else
+ goto err;
+ }
+ cs = socket(client.sa.sa_family, SOCK_STREAM, SOCKET_PROTOCOL);
+ if (cs != -1) {
int ii;
- ii=connect(cs,&client.sa,addrlen);
+ ii = connect(cs, &client.sa, addrlen);
close(cs);
- if (ii == -1)
- {
- bind_mode=BIO_BIND_REUSEADDR;
+ if (ii == -1) {
+ bind_mode = BIO_BIND_REUSEADDR;
close(s);
goto again;
- }
- /* else error */
}
- /* else error */
+ /* else error */
}
+ /* else error */
+ }
#endif
- SYSerr(SYS_F_BIND,err_num);
- ERR_add_error_data(3,"port='",host,"'");
- BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_BIND_SOCKET);
+ SYSerr(SYS_F_BIND, err_num);
+ ERR_add_error_data(3, "port = '", host, "'");
+ BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, BIO_R_UNABLE_TO_BIND_SOCKET);
goto err;
- }
- if (listen(s,MAX_LISTEN) == -1)
- {
- SYSerr(SYS_F_BIND,errno);
- ERR_add_error_data(3,"port='",host,"'");
- BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_LISTEN_SOCKET);
+ }
+ if (listen(s, MAX_LISTEN) == -1) {
+ SYSerr(SYS_F_BIND, errno);
+ ERR_add_error_data(3, "port = '", host, "'");
+ BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, BIO_R_UNABLE_TO_LISTEN_SOCKET);
goto err;
- }
- ret=1;
+ }
+ ret = 1;
err:
- if (str != NULL) OPENSSL_free(str);
- if ((ret == 0) && (s != -1))
- {
+ if (str != NULL)
+ OPENSSL_free(str);
+ if ((ret == 0) && (s != -1)) {
close(s);
- s= -1;
- }
- return(s);
+ s = -1;
}
+ return (s);
+}
-int BIO_accept(int sock, char **addr)
- {
- int ret=-1;
+int
+BIO_accept(int sock, char **addr)
+{
+ int ret = -1;
unsigned long l;
unsigned short port;
char *p;
struct {
- /*
- * As for following union. Trouble is that there are platforms
- * that have socklen_t and there are platforms that don't, on
- * some platforms socklen_t is int and on some size_t. So what
- * one can do? One can cook #ifdef spaghetti, which is nothing
- * but masochistic. Or one can do union between int and size_t.
- * One naturally does it primarily for 64-bit platforms where
- * sizeof(int) != sizeof(size_t). But would it work? Note that
- * if size_t member is initialized to 0, then later int member
- * assignment naturally does the job on little-endian platforms
- * regardless accept's expectations! What about big-endians?
- * If accept expects int*, then it works, and if size_t*, then
- * length value would appear as unreasonably large. But this
- * won't prevent it from filling in the address structure. The
- * trouble of course would be if accept returns more data than
- * actual buffer can accomodate and overwrite stack... That's
- * where early OPENSSL_assert comes into picture. Besides, the
- * only 64-bit big-endian platform found so far that expects
- * size_t* is HP-UX, where stack grows towards higher address.
- * <appro>
- */
- union { size_t s; int i; } len;
- union {
- struct sockaddr sa;
- struct sockaddr_in sa_in;
+ /*
+ * As for following union. Trouble is that there are platforms
+ * that have socklen_t and there are platforms that don't, on
+ * some platforms socklen_t is int and on some size_t. So what
+ * one can do? One can cook #ifdef spaghetti, which is nothing
+ * but masochistic. Or one can do union between int and size_t.
+ * One naturally does it primarily for 64-bit platforms where
+ * sizeof(int) != sizeof(size_t). But would it work? Note that
+ * if size_t member is initialized to 0, then later int member
+ * assignment naturally does the job on little-endian platforms
+ * regardless accept's expectations! What about big-endians?
+ * If accept expects int*, then it works, and if size_t*, then
+ * length value would appear as unreasonably large. But this
+ * won't prevent it from filling in the address structure. The
+ * trouble of course would be if accept returns more data than
+ * actual buffer can accomodate and overwrite stack... That's
+ * where early OPENSSL_assert comes into picture. Besides, the
+ * only 64-bit big-endian platform found so far that expects
+ * size_t* is HP-UX, where stack grows towards higher address.
+ * <appro>
+ */
+ union {
+ size_t s;
+ int i;
+ } len;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in sa_in;
#if OPENSSL_USE_IPV6
- struct sockaddr_in6 sa_in6;
+ struct sockaddr_in6 sa_in6;
#endif
} from;
} sa;
- sa.len.s=0;
- sa.len.i=sizeof(sa.from);
- memset(&sa.from,0,sizeof(sa.from));
- ret=accept(sock,&sa.from.sa,(void *)&sa.len);
- if (sizeof(sa.len.i)!=sizeof(sa.len.s) && sa.len.i==0)
- {
- OPENSSL_assert(sa.len.s<=sizeof(sa.from));
+ sa.len.s = 0;
+ sa.len.i = sizeof(sa.from);
+ memset(&sa.from, 0, sizeof(sa.from));
+ ret = accept(sock, &sa.from.sa,(void *)&sa.len);
+ if (sizeof(sa.len.i) != sizeof(sa.len.s) && sa.len.i == 0) {
+ OPENSSL_assert(sa.len.s <= sizeof(sa.from));
sa.len.i = (int)sa.len.s;
/* use sa.len.i from this point */
- }
- if (ret == -1)
- {
- if(BIO_sock_should_retry(ret)) return -2;
- SYSerr(SYS_F_ACCEPT,errno);
- BIOerr(BIO_F_BIO_ACCEPT,BIO_R_ACCEPT_ERROR);
+ }
+ if (ret == -1) {
+ if (BIO_sock_should_retry(ret)) return -2;
+ SYSerr(SYS_F_ACCEPT, errno);
+ BIOerr(BIO_F_BIO_ACCEPT, BIO_R_ACCEPT_ERROR);
goto end;
- }
+ }
- if (addr == NULL) goto end;
+ if (addr == NULL)
+ goto end;
#ifdef EAI_FAMILY
do {
- char h[NI_MAXHOST],s[NI_MAXSERV];
- size_t nl;
- static union { void *p;
- int (WSAAPI *f)(const struct sockaddr *,size_t/*socklen_t*/,
- char *,size_t,char *,size_t,int);
- } p_getnameinfo = {NULL};
- /* 2nd argument to getnameinfo is specified to
- * be socklen_t. Unfortunately there is a number
- * of environments where socklen_t is not defined.
- * As it's passed by value, it's safe to pass it
- * as size_t... <appro> */
-
- if (p_getnameinfo.p==NULL)
- {
- if ((p_getnameinfo.p=DSO_global_lookup("getnameinfo"))==NULL)
- p_getnameinfo.p=(void*)-1;
+ char h[NI_MAXHOST], s[NI_MAXSERV];
+ size_t nl;
+ static union {
+ void *p;
+ int (WSAAPI *f)(const struct sockaddr *,
+ size_t/*socklen_t*/, char *, size_t,
+ char *, size_t, int);
+ } p_getnameinfo = {NULL};
+ /* 2nd argument to getnameinfo is specified to
+ * be socklen_t. Unfortunately there is a number
+ * of environments where socklen_t is not defined.
+ * As it's passed by value, it's safe to pass it
+ * as size_t... <appro> */
+
+ if (p_getnameinfo.p == NULL) {
+ if ((p_getnameinfo.p = DSO_global_lookup("getnameinfo")) == NULL)
+ p_getnameinfo.p = (void*) - 1;
+ }
+ if (p_getnameinfo.p == (void *) - 1)
+ break;
+
+ if ((*p_getnameinfo.f)(&sa.from.sa, sa.len.i, h, sizeof(h),
+ s, sizeof(s), NI_NUMERICHOST|NI_NUMERICSERV))
+ break;
+ nl = strlen(h) + strlen(s) + 2;
+ p = *addr;
+ if (p) {
+ *p = '\0';
+ p = OPENSSL_realloc(p, nl);
+ } else {
+ p = OPENSSL_malloc(nl);
+ }
+ if (p == NULL) {
+ BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE);
+ goto end;
}
- if (p_getnameinfo.p==(void *)-1) break;
-
- if ((*p_getnameinfo.f)(&sa.from.sa,sa.len.i,h,sizeof(h),s,sizeof(s),
- NI_NUMERICHOST|NI_NUMERICSERV)) break;
- nl = strlen(h)+strlen(s)+2;
- p = *addr;
- if (p) { *p = '\0'; p = OPENSSL_realloc(p,nl); }
- else { p = OPENSSL_malloc(nl); }
- if (p==NULL)
- {
- BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE);
+ *addr = p;
+ (void) snprintf(*addr, nl, "%s:%s", h, s);
goto end;
- }
- *addr = p;
- (void) snprintf(*addr,nl,"%s:%s",h,s);
- goto end;
- } while(0);
-#endif
- if (sa.from.sa.sa_family != AF_INET) goto end;
- l=ntohl(sa.from.sa_in.sin_addr.s_addr);
- port=ntohs(sa.from.sa_in.sin_port);
- if (*addr == NULL)
- {
- if ((p=OPENSSL_malloc(24)) == NULL)
- {
- BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE);
+ } while (0);
+#endif
+ if (sa.from.sa.sa_family != AF_INET)
+ goto end;
+ l = ntohl(sa.from.sa_in.sin_addr.s_addr);
+ port = ntohs(sa.from.sa_in.sin_port);
+ if (*addr == NULL) {
+ if ((p = OPENSSL_malloc(24)) == NULL) {
+ BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE);
goto end;
- }
- *addr=p;
}
- (void) snprintf(*addr,24,"%d.%d.%d.%d:%d",
- (unsigned char)(l>>24L)&0xff,
- (unsigned char)(l>>16L)&0xff,
- (unsigned char)(l>> 8L)&0xff,
- (unsigned char)(l )&0xff,
- port);
-end:
- return(ret);
+ *addr = p;
}
+ (void) snprintf(*addr, 24, "%d.%d.%d.%d:%d",
+ (unsigned char)(l >> 24L) & 0xff, (unsigned char)(l >> 16L) & 0xff,
+ (unsigned char)(l >> 8L) & 0xff, (unsigned char)(l) & 0xff, port);
-int BIO_set_tcp_ndelay(int s, int on)
- {
- int ret=0;
+end:
+ return (ret);
+}
+
+int
+BIO_set_tcp_ndelay(int s, int on)
+{
+ int ret = 0;
#if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP))
int opt;
#ifdef SOL_TCP
- opt=SOL_TCP;
+ opt = SOL_TCP;
#else
#ifdef IPPROTO_TCP
- opt=IPPROTO_TCP;
+ opt = IPPROTO_TCP;
#endif
#endif
-
- ret=setsockopt(s,opt,TCP_NODELAY,(char *)&on,sizeof(on));
+
+ ret = setsockopt(s, opt, TCP_NODELAY,(char *)&on, sizeof(on));
#endif
- return(ret == 0);
- }
+ return (ret == 0);
+}
-int BIO_socket_nbio(int s, int mode)
- {
- int ret= -1;
+int
+BIO_socket_nbio(int s, int mode)
+{
+ int ret = -1;
int l;
- l=mode;
+ l = mode;
#ifdef FIONBIO
- ret=BIO_socket_ioctl(s,FIONBIO,&l);
+ ret = BIO_socket_ioctl(s, FIONBIO, &l);
#endif
- return(ret == 0);
- }
+ return (ret == 0);
+}
#endif
#include "cryptlib.h"
#include <openssl/bio.h>
-static int buffer_write(BIO *h, const char *buf,int num);
+static int buffer_write(BIO *h, const char *buf, int num);
static int buffer_read(BIO *h, char *buf, int size);
static int buffer_puts(BIO *h, const char *str);
static int buffer_gets(BIO *h, char *str, int size);
static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
#define DEFAULT_BUFFER_SIZE 4096
-static BIO_METHOD methods_buffer=
- {
+static BIO_METHOD methods_buffer = {
BIO_TYPE_BUFFER,
"buffer",
buffer_write,
buffer_new,
buffer_free,
buffer_callback_ctrl,
- };
+};
-BIO_METHOD *BIO_f_buffer(void)
- {
- return(&methods_buffer);
- }
+BIO_METHOD
+*BIO_f_buffer(void)
+{
+ return (&methods_buffer);
+}
-static int buffer_new(BIO *bi)
- {
+static int
+buffer_new(BIO *bi)
+{
BIO_F_BUFFER_CTX *ctx;
- ctx=(BIO_F_BUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_F_BUFFER_CTX));
- if (ctx == NULL) return(0);
- ctx->ibuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
- if (ctx->ibuf == NULL) { OPENSSL_free(ctx); return(0); }
- ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
- if (ctx->obuf == NULL) { OPENSSL_free(ctx->ibuf); OPENSSL_free(ctx); return(0); }
- ctx->ibuf_size=DEFAULT_BUFFER_SIZE;
- ctx->obuf_size=DEFAULT_BUFFER_SIZE;
- ctx->ibuf_len=0;
- ctx->ibuf_off=0;
- ctx->obuf_len=0;
- ctx->obuf_off=0;
-
- bi->init=1;
- bi->ptr=(char *)ctx;
- bi->flags=0;
- return(1);
+ ctx = (BIO_F_BUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_F_BUFFER_CTX));
+ if (ctx == NULL)
+ return (0);
+ ctx->ibuf = (char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
+ if (ctx->ibuf == NULL) {
+ OPENSSL_free(ctx);
+ return (0);
}
-
-static int buffer_free(BIO *a)
- {
+ ctx->obuf = (char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
+ if (ctx->obuf == NULL) {
+ OPENSSL_free(ctx->ibuf);
+ OPENSSL_free(ctx);
+ return (0);
+ }
+ ctx->ibuf_size = DEFAULT_BUFFER_SIZE;
+ ctx->obuf_size = DEFAULT_BUFFER_SIZE;
+ ctx->ibuf_len = 0;
+ ctx->ibuf_off = 0;
+ ctx->obuf_len = 0;
+ ctx->obuf_off = 0;
+
+ bi->init = 1;
+ bi->ptr = (char *)ctx;
+ bi->flags = 0;
+ return (1);
+}
+
+static int
+buffer_free(BIO *a)
+{
BIO_F_BUFFER_CTX *b;
- if (a == NULL) return(0);
- b=(BIO_F_BUFFER_CTX *)a->ptr;
- if (b->ibuf != NULL) OPENSSL_free(b->ibuf);
- if (b->obuf != NULL) OPENSSL_free(b->obuf);
+ if (a == NULL)
+ return (0);
+ b = (BIO_F_BUFFER_CTX *)a->ptr;
+ if (b->ibuf != NULL)
+ OPENSSL_free(b->ibuf);
+ if (b->obuf != NULL)
+ OPENSSL_free(b->obuf);
OPENSSL_free(a->ptr);
- a->ptr=NULL;
- a->init=0;
- a->flags=0;
- return(1);
- }
-
-static int buffer_read(BIO *b, char *out, int outl)
- {
- int i,num=0;
+ a->ptr = NULL;
+ a->init = 0;
+ a->flags = 0;
+ return (1);
+}
+
+static int
+buffer_read(BIO *b, char *out, int outl)
+{
+ int i, num = 0;
BIO_F_BUFFER_CTX *ctx;
- if (out == NULL) return(0);
- ctx=(BIO_F_BUFFER_CTX *)b->ptr;
+ if (out == NULL)
+ return (0);
+ ctx = (BIO_F_BUFFER_CTX *)b->ptr;
- if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
- num=0;
+ if ((ctx == NULL) || (b->next_bio == NULL))
+ return (0);
+ num = 0;
BIO_clear_retry_flags(b);
start:
- i=ctx->ibuf_len;
+ i = ctx->ibuf_len;
/* If there is stuff left over, grab it */
- if (i != 0)
- {
- if (i > outl) i=outl;
- memcpy(out,&(ctx->ibuf[ctx->ibuf_off]),i);
- ctx->ibuf_off+=i;
- ctx->ibuf_len-=i;
- num+=i;
- if (outl == i) return(num);
- outl-=i;
- out+=i;
- }
+ if (i != 0) {
+ if (i > outl)
+ i = outl;
+ memcpy(out, &(ctx->ibuf[ctx->ibuf_off]), i);
+ ctx->ibuf_off += i;
+ ctx->ibuf_len -= i;
+ num += i;
+ if (outl == i)
+ return (num);
+ outl -= i;
+ out += i;
+ }
/* We may have done a partial read. try to do more.
* We have nothing in the buffer.
* If we get an error and have read some data, just return it
* and let them retry to get the error again.
* copy direct to parent address space */
- if (outl > ctx->ibuf_size)
- {
- for (;;)
- {
- i=BIO_read(b->next_bio,out,outl);
- if (i <= 0)
- {
+ if (outl > ctx->ibuf_size) {
+ for (;;) {
+ i = BIO_read(b->next_bio, out, outl);
+ if (i <= 0) {
BIO_copy_next_retry(b);
- if (i < 0) return((num > 0)?num:i);
- if (i == 0) return(num);
- }
- num+=i;
- if (outl == i) return(num);
- out+=i;
- outl-=i;
+ if (i < 0)
+ return ((num > 0) ? num : i);
+ if (i == 0)
+ return (num);
}
+ num += i;
+ if (outl == i)
+ return (num);
+ out += i;
+ outl -= i;
}
+ }
/* else */
/* we are going to be doing some buffering */
- i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size);
- if (i <= 0)
- {
+ i = BIO_read(b->next_bio, ctx->ibuf, ctx->ibuf_size);
+ if (i <= 0) {
BIO_copy_next_retry(b);
- if (i < 0) return((num > 0)?num:i);
- if (i == 0) return(num);
- }
- ctx->ibuf_off=0;
- ctx->ibuf_len=i;
+ if (i < 0)
+ return ((num > 0) ? num : i);
+ if (i == 0)
+ return (num);
+ }
+ ctx->ibuf_off = 0;
+ ctx->ibuf_len = i;
/* Lets re-read using ourselves :-) */
goto start;
- }
+}
-static int buffer_write(BIO *b, const char *in, int inl)
- {
- int i,num=0;
+static int
+buffer_write(BIO *b, const char *in, int inl)
+{
+ int i, num = 0;
BIO_F_BUFFER_CTX *ctx;
- if ((in == NULL) || (inl <= 0)) return(0);
- ctx=(BIO_F_BUFFER_CTX *)b->ptr;
- if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
+ if ((in == NULL) || (inl <= 0))
+ return (0);
+ ctx = (BIO_F_BUFFER_CTX *)b->ptr;
+ if ((ctx == NULL) || (b->next_bio == NULL))
+ return (0);
BIO_clear_retry_flags(b);
start:
- i=ctx->obuf_size-(ctx->obuf_len+ctx->obuf_off);
+ i = ctx->obuf_size - (ctx->obuf_len + ctx->obuf_off);
/* add to buffer and return */
- if (i >= inl)
- {
- memcpy(&(ctx->obuf[ctx->obuf_off+ctx->obuf_len]),in,inl);
- ctx->obuf_len+=inl;
- return(num+inl);
- }
+ if (i >= inl) {
+ memcpy(&(ctx->obuf[ctx->obuf_off + ctx->obuf_len]), in, inl);
+ ctx->obuf_len += inl;
+ return (num + inl);
+ }
/* else */
/* stuff already in buffer, so add to it first, then flush */
- if (ctx->obuf_len != 0)
- {
+ if (ctx->obuf_len != 0) {
if (i > 0) /* lets fill it up if we can */
- {
- memcpy(&(ctx->obuf[ctx->obuf_off+ctx->obuf_len]),in,i);
- in+=i;
- inl-=i;
- num+=i;
- ctx->obuf_len+=i;
- }
+ {
+ memcpy(&(ctx->obuf[ctx->obuf_off + ctx->obuf_len]), in, i);
+ in += i;
+ inl -= i;
+ num += i;
+ ctx->obuf_len += i;
+ }
/* we now have a full buffer needing flushing */
- for (;;)
- {
- i=BIO_write(b->next_bio,&(ctx->obuf[ctx->obuf_off]),
- ctx->obuf_len);
- if (i <= 0)
- {
+ for (;;) {
+ i = BIO_write(b->next_bio, &(ctx->obuf[ctx->obuf_off]),
+ ctx->obuf_len);
+ if (i <= 0) {
BIO_copy_next_retry(b);
- if (i < 0) return((num > 0)?num:i);
- if (i == 0) return(num);
- }
- ctx->obuf_off+=i;
- ctx->obuf_len-=i;
- if (ctx->obuf_len == 0) break;
+ if (i < 0)
+ return ((num > 0) ? num : i);
+ if (i == 0)
+ return (num);
}
+ ctx->obuf_off += i;
+ ctx->obuf_len -= i;
+ if (ctx->obuf_len == 0)
+ break;
}
+ }
/* we only get here if the buffer has been flushed and we
* still have stuff to write */
- ctx->obuf_off=0;
+ ctx->obuf_off = 0;
/* we now have inl bytes to write */
- while (inl >= ctx->obuf_size)
- {
- i=BIO_write(b->next_bio,in,inl);
- if (i <= 0)
- {
+ while (inl >= ctx->obuf_size) {
+ i = BIO_write(b->next_bio, in, inl);
+ if (i <= 0) {
BIO_copy_next_retry(b);
- if (i < 0) return((num > 0)?num:i);
- if (i == 0) return(num);
- }
- num+=i;
- in+=i;
- inl-=i;
- if (inl == 0) return(num);
+ if (i < 0)
+ return ((num > 0) ? num : i);
+ if (i == 0)
+ return (num);
}
+ num += i;
+ in += i;
+ inl -= i;
+ if (inl == 0)
+ return (num);
+ }
/* copy the rest into the buffer since we have only a small
* amount left */
goto start;
- }
+}
-static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
+static long
+buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
BIO *dbio;
BIO_F_BUFFER_CTX *ctx;
- long ret=1;
- char *p1,*p2;
- int r,i,*ip;
- int ibs,obs;
+ long ret = 1;
+ char *p1, *p2;
+ int r, i, *ip;
+ int ibs, obs;
- ctx=(BIO_F_BUFFER_CTX *)b->ptr;
+ ctx = (BIO_F_BUFFER_CTX *)b->ptr;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_RESET:
- ctx->ibuf_off=0;
- ctx->ibuf_len=0;
- ctx->obuf_off=0;
- ctx->obuf_len=0;
- if (b->next_bio == NULL) return(0);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ ctx->ibuf_off = 0;
+ ctx->ibuf_len = 0;
+ ctx->obuf_off = 0;
+ ctx->obuf_len = 0;
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
case BIO_CTRL_INFO:
- ret=(long)ctx->obuf_len;
+ ret = (long)ctx->obuf_len;
break;
case BIO_C_GET_BUFF_NUM_LINES:
- ret=0;
- p1=ctx->ibuf;
- for (i=0; i<ctx->ibuf_len; i++)
- {
- if (p1[ctx->ibuf_off + i] == '\n') ret++;
- }
+ ret = 0;
+ p1 = ctx->ibuf;
+ for (i = 0; i < ctx->ibuf_len; i++) {
+ if (p1[ctx->ibuf_off + i] == '\n')
+ ret++;
+ }
break;
case BIO_CTRL_WPENDING:
- ret=(long)ctx->obuf_len;
- if (ret == 0)
- {
- if (b->next_bio == NULL) return(0);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
- }
+ ret = (long)ctx->obuf_len;
+ if (ret == 0) {
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ }
break;
case BIO_CTRL_PENDING:
- ret=(long)ctx->ibuf_len;
- if (ret == 0)
- {
- if (b->next_bio == NULL) return(0);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
- }
+ ret = (long)ctx->ibuf_len;
+ if (ret == 0) {
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ }
break;
case BIO_C_SET_BUFF_READ_DATA:
- if (num > ctx->ibuf_size)
- {
- p1=OPENSSL_malloc((int)num);
- if (p1 == NULL) goto malloc_error;
- if (ctx->ibuf != NULL) OPENSSL_free(ctx->ibuf);
- ctx->ibuf=p1;
- }
- ctx->ibuf_off=0;
- ctx->ibuf_len=(int)num;
- memcpy(ctx->ibuf,ptr,(int)num);
- ret=1;
+ if (num > ctx->ibuf_size) {
+ p1 = OPENSSL_malloc((int)num);
+ if (p1 == NULL)
+ goto malloc_error;
+ if (ctx->ibuf != NULL)
+ OPENSSL_free(ctx->ibuf);
+ ctx->ibuf = p1;
+ }
+ ctx->ibuf_off = 0;
+ ctx->ibuf_len = (int)num;
+ memcpy(ctx->ibuf, ptr,(int)num);
+ ret = 1;
break;
case BIO_C_SET_BUFF_SIZE:
- if (ptr != NULL)
- {
- ip=(int *)ptr;
- if (*ip == 0)
- {
- ibs=(int)num;
- obs=ctx->obuf_size;
- }
- else /* if (*ip == 1) */
- {
- ibs=ctx->ibuf_size;
- obs=(int)num;
- }
- }
- else
- {
- ibs=(int)num;
- obs=(int)num;
+ if (ptr != NULL) {
+ ip = (int *)ptr;
+ if (*ip == 0) {
+ ibs = (int)num;
+ obs = ctx->obuf_size;
}
- p1=ctx->ibuf;
- p2=ctx->obuf;
- if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size))
+ else /* if (*ip == 1) */
{
- p1=(char *)OPENSSL_malloc((int)num);
- if (p1 == NULL) goto malloc_error;
+ ibs = ctx->ibuf_size;
+ obs = (int)num;
}
- if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size))
- {
- p2=(char *)OPENSSL_malloc((int)num);
- if (p2 == NULL)
- {
- if (p1 != ctx->ibuf) OPENSSL_free(p1);
+ } else {
+ ibs = (int)num;
+ obs = (int)num;
+ }
+ p1 = ctx->ibuf;
+ p2 = ctx->obuf;
+ if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size)) {
+ p1 = (char *)OPENSSL_malloc((int)num);
+ if (p1 == NULL)
+ goto malloc_error;
+ }
+ if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) {
+ p2 = (char *)OPENSSL_malloc((int)num);
+ if (p2 == NULL) {
+ if (p1 != ctx->ibuf)
+ OPENSSL_free(p1);
goto malloc_error;
- }
}
- if (ctx->ibuf != p1)
- {
+ }
+ if (ctx->ibuf != p1) {
OPENSSL_free(ctx->ibuf);
- ctx->ibuf=p1;
- ctx->ibuf_off=0;
- ctx->ibuf_len=0;
- ctx->ibuf_size=ibs;
- }
- if (ctx->obuf != p2)
- {
+ ctx->ibuf = p1;
+ ctx->ibuf_off = 0;
+ ctx->ibuf_len = 0;
+ ctx->ibuf_size = ibs;
+ }
+ if (ctx->obuf != p2) {
OPENSSL_free(ctx->obuf);
- ctx->obuf=p2;
- ctx->obuf_off=0;
- ctx->obuf_len=0;
- ctx->obuf_size=obs;
- }
+ ctx->obuf = p2;
+ ctx->obuf_off = 0;
+ ctx->obuf_len = 0;
+ ctx->obuf_size = obs;
+ }
break;
case BIO_C_DO_STATE_MACHINE:
- if (b->next_bio == NULL) return(0);
+ if (b->next_bio == NULL)
+ return (0);
BIO_clear_retry_flags(b);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
BIO_copy_next_retry(b);
break;
case BIO_CTRL_FLUSH:
- if (b->next_bio == NULL) return(0);
- if (ctx->obuf_len <= 0)
- {
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ if (b->next_bio == NULL)
+ return (0);
+ if (ctx->obuf_len <= 0) {
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
- }
+ }
- for (;;)
- {
+ for (;;) {
BIO_clear_retry_flags(b);
- if (ctx->obuf_len > 0)
- {
- r=BIO_write(b->next_bio,
- &(ctx->obuf[ctx->obuf_off]),
- ctx->obuf_len);
+ if (ctx->obuf_len > 0) {
+ r = BIO_write(b->next_bio,
+ &(ctx->obuf[ctx->obuf_off]),
+ ctx->obuf_len);
#if 0
-fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len,r);
+ fprintf(stderr, "FLUSH [%3d] %3d -> %3d\n", ctx->obuf_off, ctx->obuf_len, r);
#endif
BIO_copy_next_retry(b);
- if (r <= 0) return((long)r);
- ctx->obuf_off+=r;
- ctx->obuf_len-=r;
- }
- else
- {
- ctx->obuf_len=0;
- ctx->obuf_off=0;
- ret=1;
+ if (r <= 0)
+ return ((long)r);
+ ctx->obuf_off += r;
+ ctx->obuf_len -= r;
+ } else {
+ ctx->obuf_len = 0;
+ ctx->obuf_off = 0;
+ ret = 1;
break;
- }
}
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ }
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
case BIO_CTRL_DUP:
- dbio=(BIO *)ptr;
- if ( !BIO_set_read_buffer_size(dbio,ctx->ibuf_size) ||
- !BIO_set_write_buffer_size(dbio,ctx->obuf_size))
- ret=0;
+ dbio = (BIO *)ptr;
+ if (!BIO_set_read_buffer_size(dbio, ctx->ibuf_size) ||
+ !BIO_set_write_buffer_size(dbio, ctx->obuf_size))
+ ret = 0;
break;
default:
- if (b->next_bio == NULL) return(0);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
- }
- return(ret);
-malloc_error:
- BIOerr(BIO_F_BUFFER_CTRL,ERR_R_MALLOC_FAILURE);
- return(0);
}
-
-static long buffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
- {
- long ret=1;
-
- if (b->next_bio == NULL) return(0);
- switch (cmd)
- {
+ return (ret);
+malloc_error:
+ BIOerr(BIO_F_BUFFER_CTRL, ERR_R_MALLOC_FAILURE);
+ return (0);
+}
+
+static long
+buffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
+{
+ long ret = 1;
+
+ if (b->next_bio == NULL)
+ return (0);
+ switch (cmd) {
default:
- ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
+ ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
break;
- }
- return(ret);
}
+ return (ret);
+}
-static int buffer_gets(BIO *b, char *buf, int size)
- {
+static int
+buffer_gets(BIO *b, char *buf, int size)
+{
BIO_F_BUFFER_CTX *ctx;
- int num=0,i,flag;
+ int num = 0, i, flag;
char *p;
- ctx=(BIO_F_BUFFER_CTX *)b->ptr;
+ ctx = (BIO_F_BUFFER_CTX *)b->ptr;
size--; /* reserve space for a '\0' */
BIO_clear_retry_flags(b);
- for (;;)
- {
- if (ctx->ibuf_len > 0)
- {
- p= &(ctx->ibuf[ctx->ibuf_off]);
- flag=0;
- for (i=0; (i<ctx->ibuf_len) && (i<size); i++)
- {
- *(buf++)=p[i];
- if (p[i] == '\n')
- {
- flag=1;
+ for (;;) {
+ if (ctx->ibuf_len > 0) {
+ p = &(ctx->ibuf[ctx->ibuf_off]);
+ flag = 0;
+ for (i = 0; (i < ctx->ibuf_len) && (i < size); i++) {
+ *(buf++) = p[i];
+ if (p[i] == '\n') {
+ flag = 1;
i++;
break;
- }
- }
- num+=i;
- size-=i;
- ctx->ibuf_len-=i;
- ctx->ibuf_off+=i;
- if (flag || size == 0)
- {
- *buf='\0';
- return(num);
}
}
+ num += i;
+ size -= i;
+ ctx->ibuf_len -= i;
+ ctx->ibuf_off += i;
+ if (flag || size == 0) {
+ *buf = '\0';
+ return (num);
+ }
+ }
else /* read another chunk */
- {
- i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size);
- if (i <= 0)
- {
+ {
+ i = BIO_read(b->next_bio, ctx->ibuf, ctx->ibuf_size);
+ if (i <= 0) {
BIO_copy_next_retry(b);
- *buf='\0';
- if (i < 0) return((num > 0)?num:i);
- if (i == 0) return(num);
- }
- ctx->ibuf_len=i;
- ctx->ibuf_off=0;
+ *buf = '\0';
+ if (i < 0)
+ return ((num > 0) ? num : i);
+ if (i == 0)
+ return (num);
}
+ ctx->ibuf_len = i;
+ ctx->ibuf_off = 0;
}
}
+}
-static int buffer_puts(BIO *b, const char *str)
- {
- return(buffer_write(b,str,strlen(str)));
- }
-
+static int
+buffer_puts(BIO *b, const char *str)
+{
+ return (buffer_write(b, str, strlen(str)));
+}
#include <openssl/bio.h>
#include <openssl/evp.h>
-static int linebuffer_write(BIO *h, const char *buf,int num);
+static int linebuffer_write(BIO *h, const char *buf, int num);
static int linebuffer_read(BIO *h, char *buf, int size);
static int linebuffer_puts(BIO *h, const char *str);
static int linebuffer_gets(BIO *h, char *str, int size);
/* #define DEBUG */
-static BIO_METHOD methods_linebuffer=
- {
+static BIO_METHOD methods_linebuffer = {
BIO_TYPE_LINEBUFFER,
"linebuffer",
linebuffer_write,
linebuffer_new,
linebuffer_free,
linebuffer_callback_ctrl,
- };
+};
-BIO_METHOD *BIO_f_linebuffer(void)
- {
- return(&methods_linebuffer);
- }
+BIO_METHOD
+*BIO_f_linebuffer(void)
+{
+ return (&methods_linebuffer);
+}
-typedef struct bio_linebuffer_ctx_struct
- {
+typedef struct bio_linebuffer_ctx_struct {
char *obuf; /* the output char array */
int obuf_size; /* how big is the output buffer */
int obuf_len; /* how many bytes are in it */
- } BIO_LINEBUFFER_CTX;
+} BIO_LINEBUFFER_CTX;
-static int linebuffer_new(BIO *bi)
- {
+static int
+linebuffer_new(BIO *bi)
+{
BIO_LINEBUFFER_CTX *ctx;
- ctx=(BIO_LINEBUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_LINEBUFFER_CTX));
- if (ctx == NULL) return(0);
- ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_LINEBUFFER_SIZE);
- if (ctx->obuf == NULL) { OPENSSL_free(ctx); return(0); }
- ctx->obuf_size=DEFAULT_LINEBUFFER_SIZE;
- ctx->obuf_len=0;
-
- bi->init=1;
- bi->ptr=(char *)ctx;
- bi->flags=0;
- return(1);
+ ctx = (BIO_LINEBUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_LINEBUFFER_CTX));
+ if (ctx == NULL)
+ return (0);
+ ctx->obuf = (char *)OPENSSL_malloc(DEFAULT_LINEBUFFER_SIZE);
+ if (ctx->obuf == NULL) {
+ OPENSSL_free(ctx);
+ return (0);
}
+ ctx->obuf_size = DEFAULT_LINEBUFFER_SIZE;
+ ctx->obuf_len = 0;
+
+ bi->init = 1;
+ bi->ptr = (char *)ctx;
+ bi->flags = 0;
+ return (1);
+}
-static int linebuffer_free(BIO *a)
- {
+static int
+linebuffer_free(BIO *a)
+{
BIO_LINEBUFFER_CTX *b;
- if (a == NULL) return(0);
- b=(BIO_LINEBUFFER_CTX *)a->ptr;
- if (b->obuf != NULL) OPENSSL_free(b->obuf);
+ if (a == NULL)
+ return (0);
+ b = (BIO_LINEBUFFER_CTX *)a->ptr;
+ if (b->obuf != NULL)
+ OPENSSL_free(b->obuf);
OPENSSL_free(a->ptr);
- a->ptr=NULL;
- a->init=0;
- a->flags=0;
- return(1);
- }
-
-static int linebuffer_read(BIO *b, char *out, int outl)
- {
- int ret=0;
-
- if (out == NULL) return(0);
- if (b->next_bio == NULL) return(0);
- ret=BIO_read(b->next_bio,out,outl);
+ a->ptr = NULL;
+ a->init = 0;
+ a->flags = 0;
+ return (1);
+}
+
+static int
+linebuffer_read(BIO *b, char *out, int outl)
+{
+ int ret = 0;
+
+ if (out == NULL)
+ return (0);
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_read(b->next_bio, out, outl);
BIO_clear_retry_flags(b);
BIO_copy_next_retry(b);
- return(ret);
- }
+ return (ret);
+}
-static int linebuffer_write(BIO *b, const char *in, int inl)
- {
- int i,num=0,foundnl;
+static int
+linebuffer_write(BIO *b, const char *in, int inl)
+{
+ int i, num = 0, foundnl;
BIO_LINEBUFFER_CTX *ctx;
- if ((in == NULL) || (inl <= 0)) return(0);
- ctx=(BIO_LINEBUFFER_CTX *)b->ptr;
- if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
+ if ((in == NULL) || (inl <= 0))
+ return (0);
+ ctx = (BIO_LINEBUFFER_CTX *)b->ptr;
+ if ((ctx == NULL) || (b->next_bio == NULL))
+ return (0);
BIO_clear_retry_flags(b);
- do
- {
+ do {
const char *p;
- for(p = in; p < in + inl && *p != '\n'; p++)
+ for (p = in; p < in + inl && *p != '\n'; p++)
;
- if (*p == '\n')
- {
+ if (*p == '\n') {
p++;
foundnl = 1;
- }
- else
+ } else
foundnl = 0;
/* If a NL was found and we already have text in the save
buffer, concatenate them and write */
- while ((foundnl || p - in > ctx->obuf_size - ctx->obuf_len)
- && ctx->obuf_len > 0)
- {
+ while ((foundnl || p - in > ctx->obuf_size - ctx->obuf_len) &&
+ ctx->obuf_len > 0) {
int orig_olen = ctx->obuf_len;
-
+
i = ctx->obuf_size - ctx->obuf_len;
- if (p - in > 0)
- {
- if (i >= p - in)
- {
+ if (p - in > 0) {
+ if (i >= p - in) {
memcpy(&(ctx->obuf[ctx->obuf_len]),
- in,p - in);
+ in, p - in);
ctx->obuf_len += p - in;
inl -= p - in;
num += p - in;
in = p;
- }
- else
- {
+ } else {
memcpy(&(ctx->obuf[ctx->obuf_len]),
- in,i);
+ in, i);
ctx->obuf_len += i;
inl -= i;
in += i;
num += i;
- }
}
+ }
#if 0
-BIO_write(b->next_bio, "<*<", 3);
+ BIO_write(b->next_bio, "<*<", 3);
#endif
- i=BIO_write(b->next_bio,
- ctx->obuf, ctx->obuf_len);
- if (i <= 0)
- {
+ i = BIO_write(b->next_bio, ctx->obuf, ctx->obuf_len);
+ if (i <= 0) {
ctx->obuf_len = orig_olen;
BIO_copy_next_retry(b);
-
#if 0
-BIO_write(b->next_bio, ">*>", 3);
+ BIO_write(b->next_bio, ">*>", 3);
#endif
- if (i < 0) return((num > 0)?num:i);
- if (i == 0) return(num);
- }
+ if (i < 0)
+ return ((num > 0) ? num : i);
+ if (i == 0)
+ return (num);
+ }
#if 0
-BIO_write(b->next_bio, ">*>", 3);
+ BIO_write(b->next_bio, ">*>", 3);
#endif
if (i < ctx->obuf_len)
memmove(ctx->obuf, ctx->obuf + i,
- ctx->obuf_len - i);
- ctx->obuf_len-=i;
- }
+ ctx->obuf_len - i);
+ ctx->obuf_len -= i;
+ }
/* Now that the save buffer is emptied, let's write the input
buffer if a NL was found and there is anything to write. */
- if ((foundnl || p - in > ctx->obuf_size) && p - in > 0)
- {
+ if ((foundnl || p - in > ctx->obuf_size) && p - in > 0) {
#if 0
-BIO_write(b->next_bio, "<*<", 3);
+ BIO_write(b->next_bio, "<*<", 3);
#endif
- i=BIO_write(b->next_bio,in,p - in);
- if (i <= 0)
- {
+ i = BIO_write(b->next_bio, in, p - in);
+ if (i <= 0) {
BIO_copy_next_retry(b);
#if 0
-BIO_write(b->next_bio, ">*>", 3);
+ BIO_write(b->next_bio, ">*>", 3);
#endif
- if (i < 0) return((num > 0)?num:i);
- if (i == 0) return(num);
- }
+ if (i < 0)
+ return ((num > 0) ? num : i);
+ if (i == 0)
+ return (num);
+ }
#if 0
-BIO_write(b->next_bio, ">*>", 3);
+ BIO_write(b->next_bio, ">*>", 3);
#endif
- num+=i;
- in+=i;
- inl-=i;
- }
+ num += i;
+ in += i;
+ inl -= i;
}
- while(foundnl && inl > 0);
+ } while (foundnl && inl > 0);
/* We've written as much as we can. The rest of the input buffer, if
any, is text that doesn't and with a NL and therefore needs to be
saved for the next trip. */
- if (inl > 0)
- {
+ if (inl > 0) {
memcpy(&(ctx->obuf[ctx->obuf_len]), in, inl);
ctx->obuf_len += inl;
num += inl;
- }
- return num;
}
+ return num;
+}
-static long linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
+static long
+linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
BIO *dbio;
BIO_LINEBUFFER_CTX *ctx;
- long ret=1;
+ long ret = 1;
char *p;
int r;
int obs;
- ctx=(BIO_LINEBUFFER_CTX *)b->ptr;
+ ctx = (BIO_LINEBUFFER_CTX *)b->ptr;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_RESET:
- ctx->obuf_len=0;
- if (b->next_bio == NULL) return(0);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ ctx->obuf_len = 0;
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
case BIO_CTRL_INFO:
- ret=(long)ctx->obuf_len;
+ ret = (long)ctx->obuf_len;
break;
case BIO_CTRL_WPENDING:
- ret=(long)ctx->obuf_len;
- if (ret == 0)
- {
- if (b->next_bio == NULL) return(0);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
- }
+ ret = (long)ctx->obuf_len;
+ if (ret == 0) {
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ }
break;
case BIO_C_SET_BUFF_SIZE:
- obs=(int)num;
- p=ctx->obuf;
- if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size))
- {
- p=(char *)OPENSSL_malloc((int)num);
+ obs = (int)num;
+ p = ctx->obuf;
+ if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size)) {
+ p = (char *)OPENSSL_malloc((int)num);
if (p == NULL)
goto malloc_error;
- }
- if (ctx->obuf != p)
- {
- if (ctx->obuf_len > obs)
- {
+ }
+ if (ctx->obuf != p) {
+ if (ctx->obuf_len > obs) {
ctx->obuf_len = obs;
- }
+ }
memcpy(p, ctx->obuf, ctx->obuf_len);
OPENSSL_free(ctx->obuf);
- ctx->obuf=p;
- ctx->obuf_size=obs;
- }
+ ctx->obuf = p;
+ ctx->obuf_size = obs;
+ }
break;
case BIO_C_DO_STATE_MACHINE:
- if (b->next_bio == NULL) return(0);
+ if (b->next_bio == NULL)
+ return (0);
BIO_clear_retry_flags(b);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
BIO_copy_next_retry(b);
break;
case BIO_CTRL_FLUSH:
- if (b->next_bio == NULL) return(0);
- if (ctx->obuf_len <= 0)
- {
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ if (b->next_bio == NULL)
+ return (0);
+ if (ctx->obuf_len <= 0) {
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
- }
+ }
- for (;;)
- {
+ for (;;) {
BIO_clear_retry_flags(b);
- if (ctx->obuf_len > 0)
- {
- r=BIO_write(b->next_bio,
- ctx->obuf, ctx->obuf_len);
+ if (ctx->obuf_len > 0) {
+ r = BIO_write(b->next_bio,
+ ctx->obuf, ctx->obuf_len);
#if 0
-fprintf(stderr,"FLUSH %3d -> %3d\n",ctx->obuf_len,r);
+ fprintf(stderr, "FLUSH %3d -> %3d\n", ctx->obuf_len, r);
#endif
BIO_copy_next_retry(b);
- if (r <= 0) return((long)r);
+ if (r <= 0)
+ return ((long)r);
if (r < ctx->obuf_len)
memmove(ctx->obuf, ctx->obuf + r,
- ctx->obuf_len - r);
- ctx->obuf_len-=r;
- }
- else
- {
- ctx->obuf_len=0;
- ret=1;
+ ctx->obuf_len - r);
+ ctx->obuf_len -= r;
+ } else {
+ ctx->obuf_len = 0;
+ ret = 1;
break;
- }
}
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ }
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
case BIO_CTRL_DUP:
- dbio=(BIO *)ptr;
- if ( !BIO_set_write_buffer_size(dbio,ctx->obuf_size))
- ret=0;
+ dbio = (BIO *)ptr;
+ if (!BIO_set_write_buffer_size(dbio, ctx->obuf_size))
+ ret = 0;
break;
default:
- if (b->next_bio == NULL) return(0);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
- }
- return(ret);
-malloc_error:
- BIOerr(BIO_F_LINEBUFFER_CTRL,ERR_R_MALLOC_FAILURE);
- return(0);
}
+ return (ret);
+malloc_error:
+ BIOerr(BIO_F_LINEBUFFER_CTRL, ERR_R_MALLOC_FAILURE);
+ return (0);
+}
-static long linebuffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
- {
- long ret=1;
+static long
+linebuffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
+{
+ long ret = 1;
- if (b->next_bio == NULL) return(0);
- switch (cmd)
- {
+ if (b->next_bio == NULL)
+ return (0);
+ switch (cmd) {
default:
- ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
+ ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
break;
- }
- return(ret);
}
+ return (ret);
+}
-static int linebuffer_gets(BIO *b, char *buf, int size)
- {
- if (b->next_bio == NULL) return(0);
- return(BIO_gets(b->next_bio,buf,size));
- }
-
-static int linebuffer_puts(BIO *b, const char *str)
- {
- return(linebuffer_write(b,str,strlen(str)));
- }
+static int
+linebuffer_gets(BIO *b, char *buf, int size)
+{
+ if (b->next_bio == NULL)
+ return (0);
+ return (BIO_gets(b->next_bio, buf, size));
+}
+static int
+linebuffer_puts(BIO *b, const char *str)
+{
+ return (linebuffer_write(b, str, strlen(str)));
+}
/* BIO_put and BIO_get both add to the digest,
* BIO_gets returns the digest */
-static int nbiof_write(BIO *h,const char *buf,int num);
-static int nbiof_read(BIO *h,char *buf,int size);
-static int nbiof_puts(BIO *h,const char *str);
-static int nbiof_gets(BIO *h,char *str,int size);
-static long nbiof_ctrl(BIO *h,int cmd,long arg1,void *arg2);
+static int nbiof_write(BIO *h, const char *buf, int num);
+static int nbiof_read(BIO *h, char *buf, int size);
+static int nbiof_puts(BIO *h, const char *str);
+static int nbiof_gets(BIO *h, char *str, int size);
+static long nbiof_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int nbiof_new(BIO *h);
static int nbiof_free(BIO *data);
-static long nbiof_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp);
-typedef struct nbio_test_st
- {
+static long nbiof_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
+
+typedef struct nbio_test_st {
/* only set if we sent a 'should retry' error */
int lrn;
int lwn;
- } NBIO_TEST;
+} NBIO_TEST;
-static BIO_METHOD methods_nbiof=
- {
+static BIO_METHOD methods_nbiof = {
BIO_TYPE_NBIO_TEST,
"non-blocking IO test filter",
nbiof_write,
nbiof_new,
nbiof_free,
nbiof_callback_ctrl,
- };
+};
-BIO_METHOD *BIO_f_nbio_test(void)
- {
- return(&methods_nbiof);
- }
+BIO_METHOD
+*BIO_f_nbio_test(void)
+{
+ return (&methods_nbiof);
+}
-static int nbiof_new(BIO *bi)
- {
+static int
+nbiof_new(BIO *bi)
+{
NBIO_TEST *nt;
- if (!(nt=(NBIO_TEST *)OPENSSL_malloc(sizeof(NBIO_TEST)))) return(0);
- nt->lrn= -1;
- nt->lwn= -1;
- bi->ptr=(char *)nt;
- bi->init=1;
- bi->flags=0;
- return(1);
- }
+ if (!(nt = (NBIO_TEST *)OPENSSL_malloc(sizeof(NBIO_TEST))))
+ return (0);
+ nt->lrn = -1;
+ nt->lwn = -1;
+ bi->ptr = (char *)nt;
+ bi->init = 1;
+ bi->flags = 0;
+ return (1);
+}
-static int nbiof_free(BIO *a)
- {
- if (a == NULL) return(0);
+static int
+nbiof_free(BIO *a)
+{
+ if (a == NULL)
+ return (0);
if (a->ptr != NULL)
OPENSSL_free(a->ptr);
- a->ptr=NULL;
- a->init=0;
- a->flags=0;
- return(1);
- }
-
-static int nbiof_read(BIO *b, char *out, int outl)
- {
- int ret=0;
+ a->ptr = NULL;
+ a->init = 0;
+ a->flags = 0;
+ return (1);
+}
+
+static int
+nbiof_read(BIO *b, char *out, int outl)
+{
+ int ret = 0;
#if 1
int num;
unsigned char n;
#endif
- if (out == NULL) return(0);
- if (b->next_bio == NULL) return(0);
+ if (out == NULL)
+ return (0);
+ if (b->next_bio == NULL)
+ return (0);
BIO_clear_retry_flags(b);
#if 1
- RAND_pseudo_bytes(&n,1);
- num=(n&0x07);
+ RAND_pseudo_bytes(&n, 1);
+ num = (n & 0x07);
- if (outl > num) outl=num;
+ if (outl > num)
+ outl = num;
- if (num == 0)
- {
- ret= -1;
+ if (num == 0) {
+ ret = -1;
BIO_set_retry_read(b);
- }
- else
+ } else
#endif
- {
- ret=BIO_read(b->next_bio,out,outl);
+ {
+ ret = BIO_read(b->next_bio, out, outl);
if (ret < 0)
BIO_copy_next_retry(b);
- }
- return(ret);
}
+ return (ret);
+}
-static int nbiof_write(BIO *b, const char *in, int inl)
- {
+static int
+nbiof_write(BIO *b, const char *in, int inl)
+{
NBIO_TEST *nt;
- int ret=0;
+ int ret = 0;
int num;
unsigned char n;
- if ((in == NULL) || (inl <= 0)) return(0);
- if (b->next_bio == NULL) return(0);
- nt=(NBIO_TEST *)b->ptr;
+ if ((in == NULL) || (inl <= 0))
+ return (0);
+ if (b->next_bio == NULL)
+ return (0);
+ nt = (NBIO_TEST *)b->ptr;
BIO_clear_retry_flags(b);
#if 1
- if (nt->lwn > 0)
- {
- num=nt->lwn;
- nt->lwn=0;
- }
- else
- {
- RAND_pseudo_bytes(&n,1);
- num=(n&7);
- }
+ if (nt->lwn > 0) {
+ num = nt->lwn;
+ nt->lwn = 0;
+ } else {
+ RAND_pseudo_bytes(&n, 1);
+ num = (n&7);
+ }
- if (inl > num) inl=num;
+ if (inl > num)
+ inl = num;
- if (num == 0)
- {
- ret= -1;
+ if (num == 0) {
+ ret = -1;
BIO_set_retry_write(b);
- }
- else
+ } else
#endif
- {
- ret=BIO_write(b->next_bio,in,inl);
- if (ret < 0)
- {
+ {
+ ret = BIO_write(b->next_bio, in, inl);
+ if (ret < 0) {
BIO_copy_next_retry(b);
- nt->lwn=inl;
- }
+ nt->lwn = inl;
}
- return(ret);
}
+ return (ret);
+}
-static long nbiof_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
+static long
+nbiof_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
long ret;
- if (b->next_bio == NULL) return(0);
- switch (cmd)
- {
- case BIO_C_DO_STATE_MACHINE:
+ if (b->next_bio == NULL)
+ return (0);
+ switch (cmd) {
+ case BIO_C_DO_STATE_MACHINE:
BIO_clear_retry_flags(b);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
BIO_copy_next_retry(b);
break;
case BIO_CTRL_DUP:
- ret=0L;
+ ret = 0L;
break;
default:
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
- }
- return(ret);
}
+ return (ret);
+}
-static long nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
- {
- long ret=1;
+static long
+nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
+{
+ long ret = 1;
- if (b->next_bio == NULL) return(0);
- switch (cmd)
- {
+ if (b->next_bio == NULL)
+ return (0);
+ switch (cmd) {
default:
- ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
+ ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
break;
- }
- return(ret);
- }
-
-static int nbiof_gets(BIO *bp, char *buf, int size)
- {
- if (bp->next_bio == NULL) return(0);
- return(BIO_gets(bp->next_bio,buf,size));
- }
-
-
-static int nbiof_puts(BIO *bp, const char *str)
- {
- if (bp->next_bio == NULL) return(0);
- return(BIO_puts(bp->next_bio,str));
}
+ return (ret);
+}
+static int
+nbiof_gets(BIO *bp, char *buf, int size)
+{
+ if (bp->next_bio == NULL)
+ return (0);
+ return (BIO_gets(bp->next_bio, buf, size));
+}
+static int
+nbiof_puts(BIO *bp, const char *str)
+{
+ if (bp->next_bio == NULL)
+ return (0);
+ return (BIO_puts(bp->next_bio, str));
+}
static int nullf_new(BIO *h);
static int nullf_free(BIO *data);
static long nullf_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
-static BIO_METHOD methods_nullf=
- {
+
+static BIO_METHOD methods_nullf = {
BIO_TYPE_NULL_FILTER,
"NULL filter",
nullf_write,
nullf_new,
nullf_free,
nullf_callback_ctrl,
- };
-
-BIO_METHOD *BIO_f_null(void)
- {
- return(&methods_nullf);
- }
-
-static int nullf_new(BIO *bi)
- {
- bi->init=1;
- bi->ptr=NULL;
- bi->flags=0;
- return(1);
- }
-
-static int nullf_free(BIO *a)
- {
- if (a == NULL) return(0);
+};
+
+BIO_METHOD
+*BIO_f_null(void)
+{
+ return (&methods_nullf);
+}
+
+static int
+nullf_new(BIO *bi)
+{
+ bi->init = 1;
+ bi->ptr = NULL;
+ bi->flags = 0;
+ return (1);
+}
+
+static int
+nullf_free(BIO *a)
+{
+ if (a == NULL)
+ return (0);
/* a->ptr=NULL;
a->init=0;
a->flags=0;*/
- return(1);
- }
-
-static int nullf_read(BIO *b, char *out, int outl)
- {
- int ret=0;
-
- if (out == NULL) return(0);
- if (b->next_bio == NULL) return(0);
- ret=BIO_read(b->next_bio,out,outl);
+ return (1);
+}
+
+static int
+nullf_read(BIO *b, char *out, int outl)
+{
+ int ret = 0;
+
+ if (out == NULL)
+ return (0);
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_read(b->next_bio, out, outl);
BIO_clear_retry_flags(b);
BIO_copy_next_retry(b);
- return(ret);
- }
-
-static int nullf_write(BIO *b, const char *in, int inl)
- {
- int ret=0;
-
- if ((in == NULL) || (inl <= 0)) return(0);
- if (b->next_bio == NULL) return(0);
- ret=BIO_write(b->next_bio,in,inl);
+ return (ret);
+}
+
+static int
+nullf_write(BIO *b, const char *in, int inl)
+{
+ int ret = 0;
+
+ if ((in == NULL) || (inl <= 0))
+ return (0);
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_write(b->next_bio, in, inl);
BIO_clear_retry_flags(b);
BIO_copy_next_retry(b);
- return(ret);
- }
+ return (ret);
+}
-static long nullf_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
+static long
+nullf_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
long ret;
- if (b->next_bio == NULL) return(0);
- switch(cmd)
- {
- case BIO_C_DO_STATE_MACHINE:
+ if (b->next_bio == NULL)
+ return (0);
+ switch (cmd) {
+ case BIO_C_DO_STATE_MACHINE:
BIO_clear_retry_flags(b);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
BIO_copy_next_retry(b);
break;
case BIO_CTRL_DUP:
- ret=0L;
+ ret = 0L;
break;
default:
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
- }
- return(ret);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
}
+ return (ret);
+}
-static long nullf_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
- {
- long ret=1;
+static long
+nullf_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
+{
+ long ret = 1;
- if (b->next_bio == NULL) return(0);
- switch (cmd)
- {
+ if (b->next_bio == NULL)
+ return (0);
+ switch (cmd) {
default:
- ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
+ ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
break;
- }
- return(ret);
}
-
-static int nullf_gets(BIO *bp, char *buf, int size)
- {
- if (bp->next_bio == NULL) return(0);
- return(BIO_gets(bp->next_bio,buf,size));
- }
-
-
-static int nullf_puts(BIO *bp, const char *str)
- {
- if (bp->next_bio == NULL) return(0);
- return(BIO_puts(bp->next_bio,str));
- }
-
-
+ return (ret);
+}
+
+static int
+nullf_gets(BIO *bp, char *buf, int size)
+{
+ if (bp->next_bio == NULL)
+ return (0);
+ return (BIO_gets(bp->next_bio, buf, size));
+}
+
+static int
+nullf_puts(BIO *bp, const char *str)
+{
+ if (bp->next_bio == NULL)
+ return (0);
+ return (BIO_puts(bp->next_bio, str));
+}
#define BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP 37 /* flag whether the last */
#define BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP 38 /* I/O operation tiemd out */
-
+
/* #ifdef IP_MTU_DISCOVER */
#define BIO_CTRL_DGRAM_MTU_DISCOVER 39 /* set DF bit on egress packets */
/* #endif */
#define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN))
#define BIO_cb_post(a) ((a)&BIO_CB_RETURN)
-long (*BIO_get_callback(const BIO *b)) (struct bio_st *,int,const char *,int, long,long);
-void BIO_set_callback(BIO *b,
- long (*callback)(struct bio_st *,int,const char *,int, long,long));
+long (*BIO_get_callback(const BIO *b))(struct bio_st *, int, const char *,
+ int, long, long);
+void BIO_set_callback(BIO *b,
+ long (*callback)(struct bio_st *, int, const char *, int, long, long));
char *BIO_get_callback_arg(const BIO *b);
void BIO_set_callback_arg(BIO *b, char *arg);
typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long);
-typedef struct bio_method_st
- {
+typedef struct bio_method_st {
int type;
const char *name;
int (*bwrite)(BIO *, const char *, int);
long (*ctrl)(BIO *, int, long, void *);
int (*create)(BIO *);
int (*destroy)(BIO *);
- long (*callback_ctrl)(BIO *, int, bio_info_cb *);
- } BIO_METHOD;
+ long (*callback_ctrl)(BIO *, int, bio_info_cb *);
+} BIO_METHOD;
-struct bio_st
- {
+struct bio_st {
BIO_METHOD *method;
/* bio, mode, argp, argi, argl, ret */
- long (*callback)(struct bio_st *,int,const char *,int, long,long);
+ long (*callback)(struct bio_st *, int, const char *, int, long, long);
char *cb_arg; /* first argument for the callback */
int init;
unsigned long num_write;
CRYPTO_EX_DATA ex_data;
- };
+};
DECLARE_STACK_OF(BIO)
-typedef struct bio_f_buffer_ctx_struct
- {
+typedef struct bio_f_buffer_ctx_struct {
/* Buffers are setup like this:
*
* <---------------------- size ----------------------->
int ibuf_size; /* how big is the input buffer */
int obuf_size; /* how big is the output buffer */
- char *ibuf; /* the char array */
- int ibuf_len; /* how many bytes are in it */
- int ibuf_off; /* write/read offset */
+ char *ibuf; /* the char array */
+ int ibuf_len; /* how many bytes are in it */
+ int ibuf_off; /* write/read offset */
- char *obuf; /* the char array */
- int obuf_len; /* how many bytes are in it */
- int obuf_off; /* write/read offset */
- } BIO_F_BUFFER_CTX;
+ char *obuf; /* the char array */
+ int obuf_len; /* how many bytes are in it */
+ int obuf_off; /* write/read offset */
+} BIO_F_BUFFER_CTX;
/* Prefix and suffix callback in ASN1 BIO */
typedef int asn1_ps_func(BIO *b, unsigned char **pbuf, int *plen, void *parg);
#ifndef OPENSSL_NO_SCTP
/* SCTP parameter structs */
-struct bio_dgram_sctp_sndinfo
- {
+struct bio_dgram_sctp_sndinfo {
uint16_t snd_sid;
uint16_t snd_flags;
uint32_t snd_ppid;
uint32_t snd_context;
- };
+};
-struct bio_dgram_sctp_rcvinfo
- {
+struct bio_dgram_sctp_rcvinfo {
uint16_t rcv_sid;
uint16_t rcv_ssn;
uint16_t rcv_flags;
uint32_t rcv_tsn;
uint32_t rcv_cumtsn;
uint32_t rcv_context;
- };
+};
-struct bio_dgram_sctp_prinfo
- {
+struct bio_dgram_sctp_prinfo {
uint16_t pr_policy;
uint32_t pr_value;
- };
+};
#endif
/* connect BIO stuff */
/* If you are wondering why this isn't defined, its because CONST_STRICT is
* purely a compile-time kludge to allow const to be checked.
*/
-int BIO_read_filename(BIO *b,const char *name);
+int BIO_read_filename(BIO *b, const char *name);
#else
#define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
BIO_CLOSE|BIO_FP_READ,(char *)name)
/* These two aren't currently implemented */
/* int BIO_get_ex_num(BIO *bio); */
/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */
-int BIO_set_ex_data(BIO *bio,int idx,void *data);
-void *BIO_get_ex_data(BIO *bio,int idx);
-int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
- CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
+int BIO_set_ex_data(BIO *bio, int idx, void *data);
+void *BIO_get_ex_data(BIO *bio, int idx);
+int
+BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
+CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
unsigned long BIO_number_read(BIO *bio);
unsigned long BIO_number_written(BIO *bio);
/* For BIO_f_asn1() */
-int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix,
- asn1_ps_func *prefix_free);
-int BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix,
- asn1_ps_func **pprefix_free);
-int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix,
- asn1_ps_func *suffix_free);
-int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix,
- asn1_ps_func **psuffix_free);
+int
+BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix,
+asn1_ps_func *prefix_free);
+int
+BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix,
+asn1_ps_func **pprefix_free);
+int
+BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix,
+asn1_ps_func *suffix_free);
+int
+BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix,
+asn1_ps_func **psuffix_free);
# ifndef OPENSSL_NO_FP_API
BIO_METHOD *BIO_s_file(void );
# define BIO_s_file_internal BIO_s_file
# endif
BIO * BIO_new(BIO_METHOD *type);
-int BIO_set(BIO *a,BIO_METHOD *type);
+int BIO_set(BIO *a, BIO_METHOD *type);
int BIO_free(BIO *a);
void BIO_vfree(BIO *a);
int BIO_read(BIO *b, void *data, int len);
-int BIO_gets(BIO *bp,char *buf, int size);
+int BIO_gets(BIO *bp, char *buf, int size);
int BIO_write(BIO *b, const void *data, int len);
-int BIO_puts(BIO *bp,const char *buf);
-int BIO_indent(BIO *b,int indent,int max);
-long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg);
-long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long));
-char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg);
-long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg);
-BIO * BIO_push(BIO *b,BIO *append);
+int BIO_puts(BIO *bp, const char *buf);
+int BIO_indent(BIO *b, int indent, int max);
+long BIO_ctrl(BIO *bp, int cmd, long larg, void *parg);
+long BIO_callback_ctrl(BIO *b, int cmd,
+ void (*fp)(struct bio_st *, int, const char *, int, long, long));
+char * BIO_ptr_ctrl(BIO *bp, int cmd, long larg);
+long BIO_int_ctrl(BIO *bp, int cmd, long larg, int iarg);
+BIO * BIO_push(BIO *b, BIO *append);
BIO * BIO_pop(BIO *b);
void BIO_free_all(BIO *a);
-BIO * BIO_find_type(BIO *b,int bio_type);
+BIO * BIO_find_type(BIO *b, int bio_type);
BIO * BIO_next(BIO *b);
BIO * BIO_get_retry_BIO(BIO *bio, int *reason);
int BIO_get_retry_reason(BIO *bio);
int BIO_nwrite0(BIO *bio, char **buf);
int BIO_nwrite(BIO *bio, char **buf, int num);
-long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
- long argl,long ret);
+long BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi,
+ long argl, long ret);
BIO_METHOD *BIO_s_mem(void);
BIO *BIO_new_mem_buf(void *buf, int len);
int BIO_fd_should_retry(int i);
int BIO_fd_non_fatal_error(int error);
-int BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u),
- void *u, const char *s, int len);
-int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
- void *u, const char *s, int len, int indent);
-int BIO_dump(BIO *b,const char *bytes,int len);
-int BIO_dump_indent(BIO *b,const char *bytes,int len,int indent);
+int
+BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u),
+void *u, const char *s, int len);
+int
+BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
+void *u, const char *s, int len, int indent);
+int BIO_dump(BIO *b, const char *bytes, int len);
+int BIO_dump_indent(BIO *b, const char *bytes, int len, int indent);
#ifndef OPENSSL_NO_FP_API
int BIO_dump_fp(FILE *fp, const char *s, int len);
int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent);
*/
int BIO_sock_error(int sock);
int BIO_socket_ioctl(int fd, long type, void *arg);
-int BIO_socket_nbio(int fd,int mode);
+int BIO_socket_nbio(int fd, int mode);
int BIO_get_port(const char *str, unsigned short *port_ptr);
int BIO_get_host_ip(const char *str, unsigned char *ip);
-int BIO_get_accept_socket(char *host_port,int mode);
-int BIO_accept(int sock,char **ip_port);
+int BIO_get_accept_socket(char *host_port, int mode);
+int BIO_accept(int sock, char **ip_port);
int BIO_sock_init(void );
void BIO_sock_cleanup(void);
-int BIO_set_tcp_ndelay(int sock,int turn_on);
+int BIO_set_tcp_ndelay(int sock, int turn_on);
BIO *BIO_new_socket(int sock, int close_flag);
BIO *BIO_new_dgram(int fd, int close_flag);
#ifndef OPENSSL_NO_SCTP
BIO *BIO_new_dgram_sctp(int fd, int close_flag);
int BIO_dgram_is_sctp(BIO *bio);
-int BIO_dgram_sctp_notification_cb(BIO *b,
- void (*handle_notifications)(BIO *bio, void *context, void *buf),
- void *context);
+int
+BIO_dgram_sctp_notification_cb(BIO *b,
+ void (*handle_notifications)(BIO *bio, void *context, void *buf),
+void *context);
int BIO_dgram_sctp_wait_for_dry(BIO *b);
int BIO_dgram_sctp_msg_waiting(BIO *b);
#endif
BIO *BIO_new_connect(char *host_port);
BIO *BIO_new_accept(char *host_port);
-int BIO_new_bio_pair(BIO **bio1, size_t writebuf1,
- BIO **bio2, size_t writebuf2);
+int
+BIO_new_bio_pair(BIO **bio1, size_t writebuf1,
+BIO **bio2, size_t writebuf2);
/* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints.
* Otherwise returns 0 and sets *bio1 and *bio2 to NULL.
* Size 0 uses default value.
#else
# define __bio_h__attr__(x)
#endif
-int BIO_printf(BIO *bio, const char *format, ...)
- __bio_h__attr__((__format__(__printf__,2,3)));
-int BIO_vprintf(BIO *bio, const char *format, va_list args)
- __bio_h__attr__((__format__(__printf__,2,0)));
-int BIO_snprintf(char *buf, size_t n, const char *format, ...)
- __bio_h__attr__((__format__(__printf__,3,4)));
-int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
- __bio_h__attr__((__format__(__printf__,3,0)));
+int
+BIO_printf(BIO *bio, const char *format, ...)
+__bio_h__attr__((__format__(__printf__, 2, 3)));
+int
+BIO_vprintf(BIO *bio, const char *format, va_list args)
+__bio_h__attr__((__format__(__printf__, 2, 0)));
+int
+BIO_snprintf(char *buf, size_t n, const char *format, ...)
+__bio_h__attr__((__format__(__printf__, 3, 4)));
+int
+BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
+__bio_h__attr__((__format__(__printf__, 3, 0)));
#undef __bio_h__attr__
/* BEGIN ERROR CODES */
#include <openssl/bio.h>
#include <openssl/err.h>
-long BIO_debug_callback(BIO *bio, int cmd, const char *argp,
- int argi, long argl, long ret)
- {
+long
+BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi, long argl,
+ long ret)
+{
BIO *b;
char buf[256];
char *p;
- long r=1;
+ long r = 1;
size_t p_maxlen;
if (BIO_CB_RETURN & cmd)
- r=ret;
+ r = ret;
- (void) snprintf(buf,sizeof buf,"BIO[%08lX]:",(unsigned long)bio);
- p= &(buf[14]);
+ (void) snprintf(buf, sizeof buf, "BIO[%08lX]:", (unsigned long)bio);
+ p = &(buf[14]);
p_maxlen = sizeof buf - 14;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CB_FREE:
- (void) snprintf(p,p_maxlen,"Free - %s\n",bio->method->name);
+ (void) snprintf(p, p_maxlen, "Free - %s\n", bio->method->name);
break;
case BIO_CB_READ:
if (bio->method->type & BIO_TYPE_DESCRIPTOR)
- (void) snprintf(p,p_maxlen,"read(%d,%lu) - %s fd=%d\n",
- bio->num,(unsigned long)argi,
- bio->method->name,bio->num);
+ (void) snprintf(p, p_maxlen,
+ "read(%d,%lu) - %s fd=%d\n",
+ bio->num,(unsigned long)argi,
+ bio->method->name, bio->num);
else
- (void) snprintf(p,p_maxlen,"read(%d,%lu) - %s\n",
- bio->num,(unsigned long)argi,
- bio->method->name);
+ (void) snprintf(p, p_maxlen, "read(%d,%lu) - %s\n",
+ bio->num, (unsigned long)argi, bio->method->name);
break;
case BIO_CB_WRITE:
if (bio->method->type & BIO_TYPE_DESCRIPTOR)
- (void) snprintf(p,p_maxlen,"write(%d,%lu) - %s fd=%d\n",
- bio->num,(unsigned long)argi,
- bio->method->name,bio->num);
+ (void) snprintf(p, p_maxlen,
+ "write(%d,%lu) - %s fd=%d\n",
+ bio->num, (unsigned long)argi,
+ bio->method->name, bio->num);
else
- (void) snprintf(p,p_maxlen,"write(%d,%lu) - %s\n",
- bio->num,(unsigned long)argi,
- bio->method->name);
+ (void) snprintf(p, p_maxlen, "write(%d,%lu) - %s\n",
+ bio->num, (unsigned long)argi, bio->method->name);
break;
case BIO_CB_PUTS:
- (void) snprintf(p,p_maxlen,"puts() - %s\n",bio->method->name);
+ (void) snprintf(p, p_maxlen,
+ "puts() - %s\n", bio->method->name);
break;
case BIO_CB_GETS:
- (void) snprintf(p,p_maxlen,"gets(%lu) - %s\n",(unsigned long)argi,bio->method->name);
+ (void) snprintf(p, p_maxlen, "gets(%lu) - %s\n",
+ (unsigned long)argi, bio->method->name);
break;
case BIO_CB_CTRL:
- (void) snprintf(p,p_maxlen,"ctrl(%lu) - %s\n",(unsigned long)argi,bio->method->name);
+ (void) snprintf(p, p_maxlen, "ctrl(%lu) - %s\n",
+ (unsigned long)argi, bio->method->name);
break;
case BIO_CB_RETURN|BIO_CB_READ:
- (void) snprintf(p,p_maxlen,"read return %ld\n",ret);
+ (void) snprintf(p, p_maxlen, "read return %ld\n", ret);
break;
case BIO_CB_RETURN|BIO_CB_WRITE:
- (void) snprintf(p,p_maxlen,"write return %ld\n",ret);
+ (void) snprintf(p, p_maxlen, "write return %ld\n", ret);
break;
case BIO_CB_RETURN|BIO_CB_GETS:
- (void) snprintf(p,p_maxlen,"gets return %ld\n",ret);
+ (void) snprintf(p, p_maxlen, "gets return %ld\n", ret);
break;
case BIO_CB_RETURN|BIO_CB_PUTS:
- (void) snprintf(p,p_maxlen,"puts return %ld\n",ret);
+ (void) snprintf(p, p_maxlen, "puts return %ld\n", ret);
break;
case BIO_CB_RETURN|BIO_CB_CTRL:
- (void) snprintf(p,p_maxlen,"ctrl return %ld\n",ret);
+ (void) snprintf(p, p_maxlen, "ctrl return %ld\n", ret);
break;
default:
- (void) snprintf(p,p_maxlen,"bio callback - unknown type (%d)\n",cmd);
+ (void) snprintf(p, p_maxlen,
+ "bio callback - unknown type (%d)\n", cmd);
break;
- }
+ }
- b=(BIO *)bio->cb_arg;
+ b = (BIO *)bio->cb_arg;
if (b != NULL)
- BIO_write(b,buf,strlen(buf));
+ BIO_write(b, buf, strlen(buf));
#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)
else
- fputs(buf,stderr);
+ fputs(buf, stderr);
#endif
- return(r);
- }
+ return (r);
+}
#define ERR_FUNC(func) ERR_PACK(ERR_LIB_BIO,func,0)
#define ERR_REASON(reason) ERR_PACK(ERR_LIB_BIO,0,reason)
-static ERR_STRING_DATA BIO_str_functs[]=
- {
-{ERR_FUNC(BIO_F_ACPT_STATE), "ACPT_STATE"},
-{ERR_FUNC(BIO_F_BIO_ACCEPT), "BIO_accept"},
-{ERR_FUNC(BIO_F_BIO_BER_GET_HEADER), "BIO_BER_GET_HEADER"},
-{ERR_FUNC(BIO_F_BIO_CALLBACK_CTRL), "BIO_callback_ctrl"},
-{ERR_FUNC(BIO_F_BIO_CTRL), "BIO_ctrl"},
-{ERR_FUNC(BIO_F_BIO_GETHOSTBYNAME), "BIO_gethostbyname"},
-{ERR_FUNC(BIO_F_BIO_GETS), "BIO_gets"},
-{ERR_FUNC(BIO_F_BIO_GET_ACCEPT_SOCKET), "BIO_get_accept_socket"},
-{ERR_FUNC(BIO_F_BIO_GET_HOST_IP), "BIO_get_host_ip"},
-{ERR_FUNC(BIO_F_BIO_GET_PORT), "BIO_get_port"},
-{ERR_FUNC(BIO_F_BIO_MAKE_PAIR), "BIO_MAKE_PAIR"},
-{ERR_FUNC(BIO_F_BIO_NEW), "BIO_new"},
-{ERR_FUNC(BIO_F_BIO_NEW_FILE), "BIO_new_file"},
-{ERR_FUNC(BIO_F_BIO_NEW_MEM_BUF), "BIO_new_mem_buf"},
-{ERR_FUNC(BIO_F_BIO_NREAD), "BIO_nread"},
-{ERR_FUNC(BIO_F_BIO_NREAD0), "BIO_nread0"},
-{ERR_FUNC(BIO_F_BIO_NWRITE), "BIO_nwrite"},
-{ERR_FUNC(BIO_F_BIO_NWRITE0), "BIO_nwrite0"},
-{ERR_FUNC(BIO_F_BIO_PUTS), "BIO_puts"},
-{ERR_FUNC(BIO_F_BIO_READ), "BIO_read"},
-{ERR_FUNC(BIO_F_BIO_SOCK_INIT), "BIO_sock_init"},
-{ERR_FUNC(BIO_F_BIO_WRITE), "BIO_write"},
-{ERR_FUNC(BIO_F_BUFFER_CTRL), "BUFFER_CTRL"},
-{ERR_FUNC(BIO_F_CONN_CTRL), "CONN_CTRL"},
-{ERR_FUNC(BIO_F_CONN_STATE), "CONN_STATE"},
-{ERR_FUNC(BIO_F_DGRAM_SCTP_READ), "DGRAM_SCTP_READ"},
-{ERR_FUNC(BIO_F_FILE_CTRL), "FILE_CTRL"},
-{ERR_FUNC(BIO_F_FILE_READ), "FILE_READ"},
-{ERR_FUNC(BIO_F_LINEBUFFER_CTRL), "LINEBUFFER_CTRL"},
-{ERR_FUNC(BIO_F_MEM_READ), "MEM_READ"},
-{ERR_FUNC(BIO_F_MEM_WRITE), "MEM_WRITE"},
-{ERR_FUNC(BIO_F_SSL_NEW), "SSL_new"},
-{ERR_FUNC(BIO_F_WSASTARTUP), "WSASTARTUP"},
-{0,NULL}
- };
+static ERR_STRING_DATA BIO_str_functs[]= {
+ {ERR_FUNC(BIO_F_ACPT_STATE), "ACPT_STATE"},
+ {ERR_FUNC(BIO_F_BIO_ACCEPT), "BIO_accept"},
+ {ERR_FUNC(BIO_F_BIO_BER_GET_HEADER), "BIO_BER_GET_HEADER"},
+ {ERR_FUNC(BIO_F_BIO_CALLBACK_CTRL), "BIO_callback_ctrl"},
+ {ERR_FUNC(BIO_F_BIO_CTRL), "BIO_ctrl"},
+ {ERR_FUNC(BIO_F_BIO_GETHOSTBYNAME), "BIO_gethostbyname"},
+ {ERR_FUNC(BIO_F_BIO_GETS), "BIO_gets"},
+ {ERR_FUNC(BIO_F_BIO_GET_ACCEPT_SOCKET), "BIO_get_accept_socket"},
+ {ERR_FUNC(BIO_F_BIO_GET_HOST_IP), "BIO_get_host_ip"},
+ {ERR_FUNC(BIO_F_BIO_GET_PORT), "BIO_get_port"},
+ {ERR_FUNC(BIO_F_BIO_MAKE_PAIR), "BIO_MAKE_PAIR"},
+ {ERR_FUNC(BIO_F_BIO_NEW), "BIO_new"},
+ {ERR_FUNC(BIO_F_BIO_NEW_FILE), "BIO_new_file"},
+ {ERR_FUNC(BIO_F_BIO_NEW_MEM_BUF), "BIO_new_mem_buf"},
+ {ERR_FUNC(BIO_F_BIO_NREAD), "BIO_nread"},
+ {ERR_FUNC(BIO_F_BIO_NREAD0), "BIO_nread0"},
+ {ERR_FUNC(BIO_F_BIO_NWRITE), "BIO_nwrite"},
+ {ERR_FUNC(BIO_F_BIO_NWRITE0), "BIO_nwrite0"},
+ {ERR_FUNC(BIO_F_BIO_PUTS), "BIO_puts"},
+ {ERR_FUNC(BIO_F_BIO_READ), "BIO_read"},
+ {ERR_FUNC(BIO_F_BIO_SOCK_INIT), "BIO_sock_init"},
+ {ERR_FUNC(BIO_F_BIO_WRITE), "BIO_write"},
+ {ERR_FUNC(BIO_F_BUFFER_CTRL), "BUFFER_CTRL"},
+ {ERR_FUNC(BIO_F_CONN_CTRL), "CONN_CTRL"},
+ {ERR_FUNC(BIO_F_CONN_STATE), "CONN_STATE"},
+ {ERR_FUNC(BIO_F_DGRAM_SCTP_READ), "DGRAM_SCTP_READ"},
+ {ERR_FUNC(BIO_F_FILE_CTRL), "FILE_CTRL"},
+ {ERR_FUNC(BIO_F_FILE_READ), "FILE_READ"},
+ {ERR_FUNC(BIO_F_LINEBUFFER_CTRL), "LINEBUFFER_CTRL"},
+ {ERR_FUNC(BIO_F_MEM_READ), "MEM_READ"},
+ {ERR_FUNC(BIO_F_MEM_WRITE), "MEM_WRITE"},
+ {ERR_FUNC(BIO_F_SSL_NEW), "SSL_new"},
+ {ERR_FUNC(BIO_F_WSASTARTUP), "WSASTARTUP"},
+ {0, NULL}
+};
-static ERR_STRING_DATA BIO_str_reasons[]=
- {
-{ERR_REASON(BIO_R_ACCEPT_ERROR) ,"accept error"},
-{ERR_REASON(BIO_R_BAD_FOPEN_MODE) ,"bad fopen mode"},
-{ERR_REASON(BIO_R_BAD_HOSTNAME_LOOKUP) ,"bad hostname lookup"},
-{ERR_REASON(BIO_R_BROKEN_PIPE) ,"broken pipe"},
-{ERR_REASON(BIO_R_CONNECT_ERROR) ,"connect error"},
-{ERR_REASON(BIO_R_EOF_ON_MEMORY_BIO) ,"EOF on memory BIO"},
-{ERR_REASON(BIO_R_ERROR_SETTING_NBIO) ,"error setting nbio"},
-{ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET),"error setting nbio on accepted socket"},
-{ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET),"error setting nbio on accept socket"},
-{ERR_REASON(BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET),"gethostbyname addr is not af inet"},
-{ERR_REASON(BIO_R_INVALID_ARGUMENT) ,"invalid argument"},
-{ERR_REASON(BIO_R_INVALID_IP_ADDRESS) ,"invalid ip address"},
-{ERR_REASON(BIO_R_IN_USE) ,"in use"},
-{ERR_REASON(BIO_R_KEEPALIVE) ,"keepalive"},
-{ERR_REASON(BIO_R_NBIO_CONNECT_ERROR) ,"nbio connect error"},
-{ERR_REASON(BIO_R_NO_ACCEPT_PORT_SPECIFIED),"no accept port specified"},
-{ERR_REASON(BIO_R_NO_HOSTNAME_SPECIFIED) ,"no hostname specified"},
-{ERR_REASON(BIO_R_NO_PORT_DEFINED) ,"no port defined"},
-{ERR_REASON(BIO_R_NO_PORT_SPECIFIED) ,"no port specified"},
-{ERR_REASON(BIO_R_NO_SUCH_FILE) ,"no such file"},
-{ERR_REASON(BIO_R_NULL_PARAMETER) ,"null parameter"},
-{ERR_REASON(BIO_R_TAG_MISMATCH) ,"tag mismatch"},
-{ERR_REASON(BIO_R_UNABLE_TO_BIND_SOCKET) ,"unable to bind socket"},
-{ERR_REASON(BIO_R_UNABLE_TO_CREATE_SOCKET),"unable to create socket"},
-{ERR_REASON(BIO_R_UNABLE_TO_LISTEN_SOCKET),"unable to listen socket"},
-{ERR_REASON(BIO_R_UNINITIALIZED) ,"uninitialized"},
-{ERR_REASON(BIO_R_UNSUPPORTED_METHOD) ,"unsupported method"},
-{ERR_REASON(BIO_R_WRITE_TO_READ_ONLY_BIO),"write to read only BIO"},
-{ERR_REASON(BIO_R_WSASTARTUP) ,"WSAStartup"},
-{0,NULL}
- };
+static ERR_STRING_DATA BIO_str_reasons[]= {
+ {ERR_REASON(BIO_R_ACCEPT_ERROR) , "accept error"},
+ {ERR_REASON(BIO_R_BAD_FOPEN_MODE) , "bad fopen mode"},
+ {ERR_REASON(BIO_R_BAD_HOSTNAME_LOOKUP) , "bad hostname lookup"},
+ {ERR_REASON(BIO_R_BROKEN_PIPE) , "broken pipe"},
+ {ERR_REASON(BIO_R_CONNECT_ERROR) , "connect error"},
+ {ERR_REASON(BIO_R_EOF_ON_MEMORY_BIO) , "EOF on memory BIO"},
+ {ERR_REASON(BIO_R_ERROR_SETTING_NBIO) , "error setting nbio"},
+ {ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET), "error setting nbio on accepted socket"},
+ {ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET), "error setting nbio on accept socket"},
+ {ERR_REASON(BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET), "gethostbyname addr is not af inet"},
+ {ERR_REASON(BIO_R_INVALID_ARGUMENT) , "invalid argument"},
+ {ERR_REASON(BIO_R_INVALID_IP_ADDRESS) , "invalid ip address"},
+ {ERR_REASON(BIO_R_IN_USE) , "in use"},
+ {ERR_REASON(BIO_R_KEEPALIVE) , "keepalive"},
+ {ERR_REASON(BIO_R_NBIO_CONNECT_ERROR) , "nbio connect error"},
+ {ERR_REASON(BIO_R_NO_ACCEPT_PORT_SPECIFIED), "no accept port specified"},
+ {ERR_REASON(BIO_R_NO_HOSTNAME_SPECIFIED) , "no hostname specified"},
+ {ERR_REASON(BIO_R_NO_PORT_DEFINED) , "no port defined"},
+ {ERR_REASON(BIO_R_NO_PORT_SPECIFIED) , "no port specified"},
+ {ERR_REASON(BIO_R_NO_SUCH_FILE) , "no such file"},
+ {ERR_REASON(BIO_R_NULL_PARAMETER) , "null parameter"},
+ {ERR_REASON(BIO_R_TAG_MISMATCH) , "tag mismatch"},
+ {ERR_REASON(BIO_R_UNABLE_TO_BIND_SOCKET) , "unable to bind socket"},
+ {ERR_REASON(BIO_R_UNABLE_TO_CREATE_SOCKET), "unable to create socket"},
+ {ERR_REASON(BIO_R_UNABLE_TO_LISTEN_SOCKET), "unable to listen socket"},
+ {ERR_REASON(BIO_R_UNINITIALIZED) , "uninitialized"},
+ {ERR_REASON(BIO_R_UNSUPPORTED_METHOD) , "unsupported method"},
+ {ERR_REASON(BIO_R_WRITE_TO_READ_ONLY_BIO), "write to read only BIO"},
+ {ERR_REASON(BIO_R_WSASTARTUP) , "WSAStartup"},
+ {0, NULL}
+};
#endif
-void ERR_load_BIO_strings(void)
- {
+void
+ERR_load_BIO_strings(void)
+{
#ifndef OPENSSL_NO_ERR
-
- if (ERR_func_error_string(BIO_str_functs[0].error) == NULL)
- {
- ERR_load_strings(0,BIO_str_functs);
- ERR_load_strings(0,BIO_str_reasons);
- }
-#endif
+ if (ERR_func_error_string(BIO_str_functs[0].error) == NULL) {
+ ERR_load_strings(0, BIO_str_functs);
+ ERR_load_strings(0, BIO_str_reasons);
}
+#endif
+}
#include <openssl/bio.h>
#include <openssl/stack.h>
-BIO *BIO_new(BIO_METHOD *method)
- {
- BIO *ret=NULL;
-
- ret=(BIO *)OPENSSL_malloc(sizeof(BIO));
- if (ret == NULL)
- {
- BIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE);
- return(NULL);
- }
- if (!BIO_set(ret,method))
- {
+BIO
+*BIO_new(BIO_METHOD *method)
+{
+ BIO *ret = NULL;
+
+ ret = (BIO *)OPENSSL_malloc(sizeof(BIO));
+ if (ret == NULL) {
+ BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE);
+ return (NULL);
+ }
+ if (!BIO_set(ret, method)) {
OPENSSL_free(ret);
- ret=NULL;
- }
- return(ret);
+ ret = NULL;
}
+ return (ret);
+}
-int BIO_set(BIO *bio, BIO_METHOD *method)
- {
- bio->method=method;
- bio->callback=NULL;
- bio->cb_arg=NULL;
- bio->init=0;
- bio->shutdown=1;
- bio->flags=0;
- bio->retry_reason=0;
- bio->num=0;
- bio->ptr=NULL;
- bio->prev_bio=NULL;
- bio->next_bio=NULL;
- bio->references=1;
- bio->num_read=0L;
- bio->num_write=0L;
+int
+BIO_set(BIO *bio, BIO_METHOD *method)
+{
+ bio->method = method;
+ bio->callback = NULL;
+ bio->cb_arg = NULL;
+ bio->init = 0;
+ bio->shutdown = 1;
+ bio->flags = 0;
+ bio->retry_reason = 0;
+ bio->num = 0;
+ bio->ptr = NULL;
+ bio->prev_bio = NULL;
+ bio->next_bio = NULL;
+ bio->references = 1;
+ bio->num_read = 0L;
+ bio->num_write = 0L;
CRYPTO_new_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data);
if (method->create != NULL)
- if (!method->create(bio))
- {
+ if (!method->create(bio)) {
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio,
- &bio->ex_data);
- return(0);
- }
- return(1);
- }
+ &bio->ex_data);
+ return (0);
+ }
+ return (1);
+}
-int BIO_free(BIO *a)
- {
+int
+BIO_free(BIO *a)
+{
int i;
- if (a == NULL) return(0);
+ if (a == NULL)
+ return (0);
- i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_BIO);
+ i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_BIO);
#ifdef REF_PRINT
- REF_PRINT("BIO",a);
+ REF_PRINT("BIO", a);
#endif
- if (i > 0) return(1);
+ if (i > 0)
+ return (1);
#ifdef REF_CHECK
- if (i < 0)
- {
- fprintf(stderr,"BIO_free, bad reference count\n");
+ if (i < 0) {
+ fprintf(stderr, "BIO_free, bad reference count\n");
abort();
- }
+ }
#endif
if ((a->callback != NULL) &&
- ((i=(int)a->callback(a,BIO_CB_FREE,NULL,0,0L,1L)) <= 0))
- return(i);
+ ((i = (int)a->callback(a, BIO_CB_FREE, NULL, 0, 0L, 1L)) <= 0))
+ return (i);
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data);
- if ((a->method == NULL) || (a->method->destroy == NULL)) return(1);
+ if ((a->method == NULL) || (a->method->destroy == NULL))
+ return (1);
a->method->destroy(a);
OPENSSL_free(a);
- return(1);
- }
+ return (1);
+}
-void BIO_vfree(BIO *a)
- { BIO_free(a); }
+void
+BIO_vfree(BIO *a)
+{
+ BIO_free(a);
+}
-void BIO_clear_flags(BIO *b, int flags)
- {
+void
+BIO_clear_flags(BIO *b, int flags)
+{
b->flags &= ~flags;
- }
+}
-int BIO_test_flags(const BIO *b, int flags)
- {
+int
+BIO_test_flags(const BIO *b, int flags)
+{
return (b->flags & flags);
- }
+}
-void BIO_set_flags(BIO *b, int flags)
- {
+void
+BIO_set_flags(BIO *b, int flags)
+{
b->flags |= flags;
- }
+}
-long (*BIO_get_callback(const BIO *b))(struct bio_st *,int,const char *,int, long,long)
- {
+long
+(*BIO_get_callback(const BIO *b))(struct bio_st *, int, const char *, int,
+ long, long)
+{
return b->callback;
- }
+}
-void BIO_set_callback(BIO *b, long (*cb)(struct bio_st *,int,const char *,int, long,long))
- {
+void
+BIO_set_callback(BIO *b, long (*cb)(struct bio_st *, int, const char *, int,
+ long, long))
+{
b->callback = cb;
- }
+}
-void BIO_set_callback_arg(BIO *b, char *arg)
- {
+void
+BIO_set_callback_arg(BIO *b, char *arg)
+{
b->cb_arg = arg;
- }
+}
-char * BIO_get_callback_arg(const BIO *b)
- {
+char *
+BIO_get_callback_arg(const BIO *b)
+{
return b->cb_arg;
- }
+}
-const char * BIO_method_name(const BIO *b)
- {
+const char *
+BIO_method_name(const BIO *b)
+{
return b->method->name;
- }
+}
-int BIO_method_type(const BIO *b)
- {
+int
+BIO_method_type(const BIO *b)
+{
return b->method->type;
- }
-
+}
-int BIO_read(BIO *b, void *out, int outl)
- {
+int
+BIO_read(BIO *b, void *out, int outl)
+{
int i;
- long (*cb)(BIO *,int,const char *,int,long,long);
+ long (*cb)(BIO *, int, const char *, int, long, long);
- if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL))
- {
- BIOerr(BIO_F_BIO_READ,BIO_R_UNSUPPORTED_METHOD);
- return(-2);
- }
+ if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) {
+ BIOerr(BIO_F_BIO_READ, BIO_R_UNSUPPORTED_METHOD);
+ return (-2);
+ }
- cb=b->callback;
+ cb = b->callback;
if ((cb != NULL) &&
- ((i=(int)cb(b,BIO_CB_READ,out,outl,0L,1L)) <= 0))
- return(i);
+ ((i = (int)cb(b, BIO_CB_READ, out, outl, 0L, 1L)) <= 0))
+ return (i);
- if (!b->init)
- {
- BIOerr(BIO_F_BIO_READ,BIO_R_UNINITIALIZED);
- return(-2);
- }
+ if (!b->init) {
+ BIOerr(BIO_F_BIO_READ, BIO_R_UNINITIALIZED);
+ return (-2);
+ }
- i=b->method->bread(b,out,outl);
+ i = b->method->bread(b, out, outl);
- if (i > 0) b->num_read+=(unsigned long)i;
+ if (i > 0)
+ b->num_read += (unsigned long)i;
if (cb != NULL)
- i=(int)cb(b,BIO_CB_READ|BIO_CB_RETURN,out,outl,
- 0L,(long)i);
- return(i);
- }
+ i = (int)cb(b, BIO_CB_READ|BIO_CB_RETURN, out, outl,
+ 0L, (long)i);
+ return (i);
+}
-int BIO_write(BIO *b, const void *in, int inl)
- {
+int
+BIO_write(BIO *b, const void *in, int inl)
+{
int i;
- long (*cb)(BIO *,int,const char *,int,long,long);
+ long (*cb)(BIO *, int, const char *, int, long, long);
if (b == NULL)
- return(0);
+ return (0);
- cb=b->callback;
- if ((b->method == NULL) || (b->method->bwrite == NULL))
- {
- BIOerr(BIO_F_BIO_WRITE,BIO_R_UNSUPPORTED_METHOD);
- return(-2);
- }
+ cb = b->callback;
+ if ((b->method == NULL) || (b->method->bwrite == NULL)) {
+ BIOerr(BIO_F_BIO_WRITE, BIO_R_UNSUPPORTED_METHOD);
+ return (-2);
+ }
if ((cb != NULL) &&
- ((i=(int)cb(b,BIO_CB_WRITE,in,inl,0L,1L)) <= 0))
- return(i);
+ ((i = (int)cb(b, BIO_CB_WRITE, in, inl, 0L, 1L)) <= 0))
+ return (i);
- if (!b->init)
- {
- BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITIALIZED);
- return(-2);
- }
+ if (!b->init) {
+ BIOerr(BIO_F_BIO_WRITE, BIO_R_UNINITIALIZED);
+ return (-2);
+ }
- i=b->method->bwrite(b,in,inl);
+ i = b->method->bwrite(b, in, inl);
- if (i > 0) b->num_write+=(unsigned long)i;
+ if (i > 0)
+ b->num_write += (unsigned long)i;
if (cb != NULL)
- i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl,
- 0L,(long)i);
- return(i);
- }
+ i = (int)cb(b, BIO_CB_WRITE|BIO_CB_RETURN, in, inl,
+ 0L, (long)i);
+ return (i);
+}
-int BIO_puts(BIO *b, const char *in)
- {
+int
+BIO_puts(BIO *b, const char *in)
+{
int i;
- long (*cb)(BIO *,int,const char *,int,long,long);
+ long (*cb)(BIO *, int, const char *, int, long, long);
- if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL))
- {
- BIOerr(BIO_F_BIO_PUTS,BIO_R_UNSUPPORTED_METHOD);
- return(-2);
- }
+ if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) {
+ BIOerr(BIO_F_BIO_PUTS, BIO_R_UNSUPPORTED_METHOD);
+ return (-2);
+ }
- cb=b->callback;
+ cb = b->callback;
if ((cb != NULL) &&
- ((i=(int)cb(b,BIO_CB_PUTS,in,0,0L,1L)) <= 0))
- return(i);
+ ((i = (int)cb(b, BIO_CB_PUTS, in, 0, 0L, 1L)) <= 0))
+ return (i);
- if (!b->init)
- {
- BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITIALIZED);
- return(-2);
- }
+ if (!b->init) {
+ BIOerr(BIO_F_BIO_PUTS, BIO_R_UNINITIALIZED);
+ return (-2);
+ }
- i=b->method->bputs(b,in);
+ i = b->method->bputs(b, in);
- if (i > 0) b->num_write+=(unsigned long)i;
+ if (i > 0)
+ b->num_write += (unsigned long)i;
if (cb != NULL)
- i=(int)cb(b,BIO_CB_PUTS|BIO_CB_RETURN,in,0,
- 0L,(long)i);
- return(i);
- }
+ i = (int)cb(b, BIO_CB_PUTS|BIO_CB_RETURN, in, 0, 0L, (long)i);
+ return (i);
+}
-int BIO_gets(BIO *b, char *in, int inl)
- {
+int
+BIO_gets(BIO *b, char *in, int inl)
+{
int i;
- long (*cb)(BIO *,int,const char *,int,long,long);
+ long (*cb)(BIO *, int, const char *, int, long, long);
- if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL))
- {
- BIOerr(BIO_F_BIO_GETS,BIO_R_UNSUPPORTED_METHOD);
- return(-2);
- }
+ if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL)) {
+ BIOerr(BIO_F_BIO_GETS, BIO_R_UNSUPPORTED_METHOD);
+ return (-2);
+ }
- cb=b->callback;
+ cb = b->callback;
if ((cb != NULL) &&
- ((i=(int)cb(b,BIO_CB_GETS,in,inl,0L,1L)) <= 0))
- return(i);
+ ((i = (int)cb(b, BIO_CB_GETS, in, inl, 0L, 1L)) <= 0))
+ return (i);
- if (!b->init)
- {
- BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITIALIZED);
- return(-2);
- }
+ if (!b->init) {
+ BIOerr(BIO_F_BIO_GETS, BIO_R_UNINITIALIZED);
+ return (-2);
+ }
- i=b->method->bgets(b,in,inl);
+ i = b->method->bgets(b, in, inl);
if (cb != NULL)
- i=(int)cb(b,BIO_CB_GETS|BIO_CB_RETURN,in,inl,
- 0L,(long)i);
- return(i);
- }
+ i = (int)cb(b, BIO_CB_GETS|BIO_CB_RETURN, in, inl, 0L, (long)i);
+ return (i);
+}
-int BIO_indent(BIO *b,int indent,int max)
- {
- if(indent < 0)
- indent=0;
- if(indent > max)
- indent=max;
- while(indent--)
- if(BIO_puts(b," ") != 1)
- return 0;
+int
+BIO_indent(BIO *b, int indent, int max)
+{
+ if (indent < 0)
+ indent = 0;
+ if (indent > max)
+ indent = max;
+ while (indent--)
+ if (BIO_puts(b, " ") != 1)
+ return 0;
return 1;
- }
+}
-long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg)
- {
+long
+BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg)
+{
int i;
- i=iarg;
- return(BIO_ctrl(b,cmd,larg,(char *)&i));
- }
+ i = iarg;
+ return (BIO_ctrl(b, cmd, larg,(char *)&i));
+}
-char *BIO_ptr_ctrl(BIO *b, int cmd, long larg)
- {
- char *p=NULL;
+char
+*BIO_ptr_ctrl(BIO *b, int cmd, long larg)
+{
+ char *p = NULL;
- if (BIO_ctrl(b,cmd,larg,(char *)&p) <= 0)
- return(NULL);
+ if (BIO_ctrl(b, cmd, larg,(char *)&p) <= 0)
+ return (NULL);
else
- return(p);
- }
+ return (p);
+}
-long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
- {
+long
+BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
+{
long ret;
- long (*cb)(BIO *,int,const char *,int,long,long);
+ long (*cb)(BIO *, int, const char *, int, long, long);
- if (b == NULL) return(0);
+ if (b == NULL)
+ return (0);
- if ((b->method == NULL) || (b->method->ctrl == NULL))
- {
- BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD);
- return(-2);
- }
+ if ((b->method == NULL) || (b->method->ctrl == NULL)) {
+ BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD);
+ return (-2);
+ }
- cb=b->callback;
+ cb = b->callback;
if ((cb != NULL) &&
- ((ret=cb(b,BIO_CB_CTRL,parg,cmd,larg,1L)) <= 0))
- return(ret);
+ ((ret = cb(b, BIO_CB_CTRL, parg, cmd, larg, 1L)) <= 0))
+ return (ret);
- ret=b->method->ctrl(b,cmd,larg,parg);
+ ret = b->method->ctrl(b, cmd, larg, parg);
if (cb != NULL)
- ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,parg,cmd,
- larg,ret);
- return(ret);
- }
+ ret = cb(b, BIO_CB_CTRL|BIO_CB_RETURN, parg, cmd, larg, ret);
+ return (ret);
+}
-long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long))
- {
+long
+BIO_callback_ctrl(BIO *b, int cmd,
+ void (*fp)(struct bio_st *, int, const char *, int, long, long))
+{
long ret;
- long (*cb)(BIO *,int,const char *,int,long,long);
+ long (*cb)(BIO *, int, const char *, int, long, long);
- if (b == NULL) return(0);
+ if (b == NULL)
+ return (0);
- if ((b->method == NULL) || (b->method->callback_ctrl == NULL))
- {
- BIOerr(BIO_F_BIO_CALLBACK_CTRL,BIO_R_UNSUPPORTED_METHOD);
- return(-2);
- }
+ if ((b->method == NULL) || (b->method->callback_ctrl == NULL)) {
+ BIOerr(BIO_F_BIO_CALLBACK_CTRL, BIO_R_UNSUPPORTED_METHOD);
+ return (-2);
+ }
- cb=b->callback;
+ cb = b->callback;
if ((cb != NULL) &&
- ((ret=cb(b,BIO_CB_CTRL,(void *)&fp,cmd,0,1L)) <= 0))
- return(ret);
+ ((ret = cb(b, BIO_CB_CTRL,(void *)&fp, cmd, 0, 1L)) <= 0))
+ return (ret);
- ret=b->method->callback_ctrl(b,cmd,fp);
+ ret = b->method->callback_ctrl(b, cmd, fp);
if (cb != NULL)
- ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,(void *)&fp,cmd,
- 0,ret);
- return(ret);
- }
+ ret = cb(b, BIO_CB_CTRL|BIO_CB_RETURN,(void *)&fp, cmd, 0, ret);
+ return (ret);
+}
/* It is unfortunate to duplicate in functions what the BIO_(w)pending macros
* do; but those macros have inappropriate return type, and for interfacing
* from other programming languages, C macros aren't much of a help anyway. */
-size_t BIO_ctrl_pending(BIO *bio)
- {
+size_t
+BIO_ctrl_pending(BIO *bio)
+{
return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL);
- }
+}
-size_t BIO_ctrl_wpending(BIO *bio)
- {
+size_t
+BIO_ctrl_wpending(BIO *bio)
+{
return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL);
- }
+}
/* put the 'bio' on the end of b's list of operators */
-BIO *BIO_push(BIO *b, BIO *bio)
- {
+BIO
+*BIO_push(BIO *b, BIO *bio)
+{
BIO *lb;
- if (b == NULL) return(bio);
- lb=b;
+ if (b == NULL)
+ return (bio);
+ lb = b;
while (lb->next_bio != NULL)
- lb=lb->next_bio;
- lb->next_bio=bio;
+ lb = lb->next_bio;
+ lb->next_bio = bio;
if (bio != NULL)
- bio->prev_bio=lb;
+ bio->prev_bio = lb;
/* called to do internal processing */
- BIO_ctrl(b,BIO_CTRL_PUSH,0,lb);
- return(b);
- }
+ BIO_ctrl(b, BIO_CTRL_PUSH, 0, lb);
+ return (b);
+}
/* Remove the first and return the rest */
-BIO *BIO_pop(BIO *b)
- {
+BIO
+*BIO_pop(BIO *b)
+{
BIO *ret;
- if (b == NULL) return(NULL);
- ret=b->next_bio;
+ if (b == NULL)
+ return (NULL);
+ ret = b->next_bio;
- BIO_ctrl(b,BIO_CTRL_POP,0,b);
+ BIO_ctrl(b, BIO_CTRL_POP, 0, b);
if (b->prev_bio != NULL)
- b->prev_bio->next_bio=b->next_bio;
+ b->prev_bio->next_bio = b->next_bio;
if (b->next_bio != NULL)
- b->next_bio->prev_bio=b->prev_bio;
+ b->next_bio->prev_bio = b->prev_bio;
- b->next_bio=NULL;
- b->prev_bio=NULL;
- return(ret);
- }
+ b->next_bio = NULL;
+ b->prev_bio = NULL;
+ return (ret);
+}
-BIO *BIO_get_retry_BIO(BIO *bio, int *reason)
- {
- BIO *b,*last;
+BIO
+*BIO_get_retry_BIO(BIO *bio, int *reason)
+{
+ BIO *b, *last;
- b=last=bio;
- for (;;)
- {
+ b = last = bio;
+ for (;;) {
if (!BIO_should_retry(b)) break;
- last=b;
- b=b->next_bio;
- if (b == NULL) break;
- }
- if (reason != NULL) *reason=last->retry_reason;
- return(last);
- }
+ last = b;
+ b = b->next_bio;
+ if (b == NULL)
+ break;
+ }
+ if (reason != NULL)
+ *reason = last->retry_reason;
+ return (last);
+}
-int BIO_get_retry_reason(BIO *bio)
- {
- return(bio->retry_reason);
- }
+int
+BIO_get_retry_reason(BIO *bio)
+{
+ return (bio->retry_reason);
+}
-BIO *BIO_find_type(BIO *bio, int type)
- {
- int mt,mask;
-
- if(!bio) return NULL;
- mask=type&0xff;
- do {
- if (bio->method != NULL)
- {
- mt=bio->method->type;
-
- if (!mask)
- {
- if (mt & type) return(bio);
- }
- else if (mt == type)
- return(bio);
- }
- bio=bio->next_bio;
- } while (bio != NULL);
- return(NULL);
- }
+BIO
+*BIO_find_type(BIO *bio, int type)
+{
+ int mt, mask;
+
+ if (!bio)
+ return NULL;
+ mask = type & 0xff;
+ do {
+ if (bio->method != NULL) {
+ mt = bio->method->type;
+ if (!mask) {
+ if (mt & type)
+ return (bio);
+ } else if (mt == type)
+ return (bio);
+ }
+ bio = bio->next_bio;
+ } while (bio != NULL);
+ return (NULL);
+}
-BIO *BIO_next(BIO *b)
- {
- if(!b) return NULL;
+BIO
+*BIO_next(BIO *b)
+{
+ if (!b)
+ return NULL;
return b->next_bio;
- }
+}
-void BIO_free_all(BIO *bio)
- {
+void
+BIO_free_all(BIO *bio)
+{
BIO *b;
int ref;
- while (bio != NULL)
- {
- b=bio;
- ref=b->references;
- bio=bio->next_bio;
+ while (bio != NULL) {
+ b = bio;
+ ref = b->references;
+ bio = bio->next_bio;
BIO_free(b);
/* Since ref count > 1, don't free anyone else. */
- if (ref > 1) break;
- }
+ if (ref > 1)
+ break;
}
+}
-BIO *BIO_dup_chain(BIO *in)
- {
- BIO *ret=NULL,*eoc=NULL,*bio,*new_bio;
+BIO
+*BIO_dup_chain(BIO *in)
+{
+ BIO *ret = NULL, *eoc = NULL, *bio, *new_bio;
- for (bio=in; bio != NULL; bio=bio->next_bio)
- {
- if ((new_bio=BIO_new(bio->method)) == NULL) goto err;
- new_bio->callback=bio->callback;
- new_bio->cb_arg=bio->cb_arg;
- new_bio->init=bio->init;
- new_bio->shutdown=bio->shutdown;
- new_bio->flags=bio->flags;
+ for (bio = in; bio != NULL; bio = bio->next_bio) {
+ if ((new_bio = BIO_new(bio->method)) == NULL) goto err;
+ new_bio->callback = bio->callback;
+ new_bio->cb_arg = bio->cb_arg;
+ new_bio->init = bio->init;
+ new_bio->shutdown = bio->shutdown;
+ new_bio->flags = bio->flags;
/* This will let SSL_s_sock() work with stdin/stdout */
- new_bio->num=bio->num;
+ new_bio->num = bio->num;
- if (!BIO_dup_state(bio,(char *)new_bio))
- {
+ if (!BIO_dup_state(bio,(char *)new_bio)) {
BIO_free(new_bio);
goto err;
- }
+ }
/* copy app data */
- if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_BIO, &new_bio->ex_data,
- &bio->ex_data))
+ if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_BIO,
+ &new_bio->ex_data, &bio->ex_data))
goto err;
- if (ret == NULL)
- {
- eoc=new_bio;
- ret=eoc;
- }
- else
- {
- BIO_push(eoc,new_bio);
- eoc=new_bio;
- }
+ if (ret == NULL) {
+ eoc = new_bio;
+ ret = eoc;
+ } else {
+ BIO_push(eoc, new_bio);
+ eoc = new_bio;
}
- return(ret);
+ }
+ return (ret);
err:
if (ret != NULL)
BIO_free(ret);
- return(NULL);
- }
+ return (NULL);
-void BIO_copy_next_retry(BIO *b)
- {
- BIO_set_flags(b,BIO_get_retry_flags(b->next_bio));
- b->retry_reason=b->next_bio->retry_reason;
- }
+}
-int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
- CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
- {
+void
+BIO_copy_next_retry(BIO *b)
+{
+ BIO_set_flags(b, BIO_get_retry_flags(b->next_bio));
+ b->retry_reason = b->next_bio->retry_reason;
+}
+
+int
+BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
+ CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
+{
return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_BIO, argl, argp,
- new_func, dup_func, free_func);
- }
+ new_func, dup_func, free_func);
+}
-int BIO_set_ex_data(BIO *bio, int idx, void *data)
- {
- return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data));
- }
+int
+BIO_set_ex_data(BIO *bio, int idx, void *data)
+{
+ return (CRYPTO_set_ex_data(&(bio->ex_data), idx, data));
+}
-void *BIO_get_ex_data(BIO *bio, int idx)
- {
- return(CRYPTO_get_ex_data(&(bio->ex_data),idx));
- }
+void
+*BIO_get_ex_data(BIO *bio, int idx)
+{
+ return (CRYPTO_get_ex_data(&(bio->ex_data), idx));
+}
-unsigned long BIO_number_read(BIO *bio)
+unsigned long
+BIO_number_read(BIO *bio)
{
- if(bio) return bio->num_read;
+ if (bio)
+ return bio->num_read;
return 0;
}
-unsigned long BIO_number_written(BIO *bio)
+unsigned long
+BIO_number_written(BIO *bio)
{
- if(bio) return bio->num_write;
+ if (bio)
+ return bio->num_write;
return 0;
}
#undef FIONBIO
#endif
-typedef struct bio_accept_st
- {
+typedef struct bio_accept_st {
int state;
char *param_addr;
* If 2, always use SO_REUSEADDR. */
int bind_mode;
BIO *bio_chain;
- } BIO_ACCEPT;
+} BIO_ACCEPT;
static int acpt_write(BIO *h, const char *buf, int num);
static int acpt_read(BIO *h, char *buf, int size);
#define ACPT_S_GET_ACCEPT_SOCKET 2
#define ACPT_S_OK 3
-static BIO_METHOD methods_acceptp=
- {
+static BIO_METHOD methods_acceptp = {
BIO_TYPE_ACCEPT,
"socket accept",
acpt_write,
acpt_new,
acpt_free,
NULL,
- };
+};
-BIO_METHOD *BIO_s_accept(void)
- {
- return(&methods_acceptp);
- }
+BIO_METHOD
+*BIO_s_accept(void)
+{
+ return (&methods_acceptp);
+}
-static int acpt_new(BIO *bi)
- {
+static int
+acpt_new(BIO *bi)
+{
BIO_ACCEPT *ba;
- bi->init=0;
- bi->num=-1;
- bi->flags=0;
- if ((ba=BIO_ACCEPT_new()) == NULL)
- return(0);
- bi->ptr=(char *)ba;
- ba->state=ACPT_S_BEFORE;
- bi->shutdown=1;
- return(1);
- }
-
-static BIO_ACCEPT *BIO_ACCEPT_new(void)
- {
+ bi->init = 0;
+ bi->num = -1;
+ bi->flags = 0;
+ if ((ba = BIO_ACCEPT_new()) == NULL)
+ return (0);
+ bi->ptr = (char *)ba;
+ ba->state = ACPT_S_BEFORE;
+ bi->shutdown = 1;
+ return (1);
+}
+
+static BIO_ACCEPT
+*BIO_ACCEPT_new(void)
+{
BIO_ACCEPT *ret;
- if ((ret=(BIO_ACCEPT *)OPENSSL_malloc(sizeof(BIO_ACCEPT))) == NULL)
- return(NULL);
-
- memset(ret,0,sizeof(BIO_ACCEPT));
- ret->accept_sock=-1;
- ret->bind_mode=BIO_BIND_NORMAL;
- return(ret);
- }
-
-static void BIO_ACCEPT_free(BIO_ACCEPT *a)
- {
- if(a == NULL)
- return;
-
- if (a->param_addr != NULL) OPENSSL_free(a->param_addr);
- if (a->addr != NULL) OPENSSL_free(a->addr);
- if (a->bio_chain != NULL) BIO_free(a->bio_chain);
+ if ((ret = (BIO_ACCEPT *)OPENSSL_malloc(sizeof(BIO_ACCEPT))) == NULL)
+ return (NULL);
+
+ memset(ret, 0, sizeof(BIO_ACCEPT));
+ ret->accept_sock = -1;
+ ret->bind_mode = BIO_BIND_NORMAL;
+ return (ret);
+}
+
+static void
+BIO_ACCEPT_free(BIO_ACCEPT *a)
+{
+ if (a == NULL)
+ return;
+
+ if (a->param_addr != NULL)
+ OPENSSL_free(a->param_addr);
+ if (a->addr != NULL)
+ OPENSSL_free(a->addr);
+ if (a->bio_chain != NULL)
+ BIO_free(a->bio_chain);
OPENSSL_free(a);
- }
+}
-static void acpt_close_socket(BIO *bio)
- {
+static void
+acpt_close_socket(BIO *bio)
+{
BIO_ACCEPT *c;
- c=(BIO_ACCEPT *)bio->ptr;
- if (c->accept_sock != -1)
- {
+ c = (BIO_ACCEPT *)bio->ptr;
+ if (c->accept_sock != -1) {
shutdown(c->accept_sock, SHUT_RDWR);
close(c->accept_sock);
- c->accept_sock=-1;
- bio->num=-1;
- }
+ c->accept_sock = -1;
+ bio->num = -1;
}
+}
-static int acpt_free(BIO *a)
- {
+static int
+acpt_free(BIO *a)
+{
BIO_ACCEPT *data;
- if (a == NULL) return(0);
- data=(BIO_ACCEPT *)a->ptr;
-
- if (a->shutdown)
- {
+ if (a == NULL)
+ return (0);
+ data = (BIO_ACCEPT *)a->ptr;
+
+ if (a->shutdown) {
acpt_close_socket(a);
BIO_ACCEPT_free(data);
- a->ptr=NULL;
- a->flags=0;
- a->init=0;
- }
- return(1);
+ a->ptr = NULL;
+ a->flags = 0;
+ a->init = 0;
}
-
-static int acpt_state(BIO *b, BIO_ACCEPT *c)
- {
- BIO *bio=NULL,*dbio;
- int s= -1;
+ return (1);
+}
+
+static int
+acpt_state(BIO *b, BIO_ACCEPT *c)
+{
+ BIO *bio = NULL, *dbio;
+ int s = -1;
int i;
again:
- switch (c->state)
- {
+ switch (c->state) {
case ACPT_S_BEFORE:
- if (c->param_addr == NULL)
- {
- BIOerr(BIO_F_ACPT_STATE,BIO_R_NO_ACCEPT_PORT_SPECIFIED);
- return(-1);
- }
- s=BIO_get_accept_socket(c->param_addr,c->bind_mode);
+ if (c->param_addr == NULL) {
+ BIOerr(BIO_F_ACPT_STATE, BIO_R_NO_ACCEPT_PORT_SPECIFIED);
+ return (-1);
+ }
+ s = BIO_get_accept_socket(c->param_addr, c->bind_mode);
if (s == -1)
- return(-1);
+ return (-1);
- if (c->accept_nbio)
- {
- if (!BIO_socket_nbio(s,1))
- {
+ if (c->accept_nbio) {
+ if (!BIO_socket_nbio(s, 1)) {
close(s);
- BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET);
- return(-1);
- }
+ BIOerr(BIO_F_ACPT_STATE, BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET);
+ return (-1);
}
- c->accept_sock=s;
- b->num=s;
- c->state=ACPT_S_GET_ACCEPT_SOCKET;
- return(1);
+ }
+ c->accept_sock = s;
+ b->num = s;
+ c->state = ACPT_S_GET_ACCEPT_SOCKET;
+ return (1);
/* break; */
case ACPT_S_GET_ACCEPT_SOCKET:
- if (b->next_bio != NULL)
- {
- c->state=ACPT_S_OK;
+ if (b->next_bio != NULL) {
+ c->state = ACPT_S_OK;
goto again;
- }
+ }
BIO_clear_retry_flags(b);
- b->retry_reason=0;
- i=BIO_accept(c->accept_sock,&(c->addr));
+ b->retry_reason = 0;
+ i = BIO_accept(c->accept_sock, &(c->addr));
/* -2 return means we should retry */
- if(i == -2)
- {
+ if (i == -2) {
BIO_set_retry_special(b);
- b->retry_reason=BIO_RR_ACCEPT;
+ b->retry_reason = BIO_RR_ACCEPT;
return -1;
- }
+ }
- if (i < 0) return(i);
+ if (i < 0)
+ return (i);
- bio=BIO_new_socket(i,BIO_CLOSE);
- if (bio == NULL) goto err;
+ bio = BIO_new_socket(i, BIO_CLOSE);
+ if (bio == NULL)
+ goto err;
- BIO_set_callback(bio,BIO_get_callback(b));
- BIO_set_callback_arg(bio,BIO_get_callback_arg(b));
+ BIO_set_callback(bio, BIO_get_callback(b));
+ BIO_set_callback_arg(bio, BIO_get_callback_arg(b));
- if (c->nbio)
- {
- if (!BIO_socket_nbio(i,1))
- {
- BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET);
+ if (c->nbio) {
+ if (!BIO_socket_nbio(i, 1)) {
+ BIOerr(BIO_F_ACPT_STATE, BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET);
goto err;
- }
}
+ }
/* If the accept BIO has an bio_chain, we dup it and
* put the new socket at the end. */
- if (c->bio_chain != NULL)
- {
- if ((dbio=BIO_dup_chain(c->bio_chain)) == NULL)
+ if (c->bio_chain != NULL) {
+ if ((dbio = BIO_dup_chain(c->bio_chain)) == NULL)
goto err;
- if (!BIO_push(dbio,bio)) goto err;
- bio=dbio;
- }
- if (BIO_push(b,bio) == NULL) goto err;
+ if (!BIO_push(dbio, bio)) goto err;
+ bio = dbio;
+ }
+ if (BIO_push(b, bio)
+ == NULL) goto err;
+
+ c->state = ACPT_S_OK;
+ return (1);
- c->state=ACPT_S_OK;
- return(1);
err:
if (bio != NULL)
BIO_free(bio);
else if (s >= 0)
close(s);
- return(0);
+ return (0);
/* break; */
case ACPT_S_OK:
- if (b->next_bio == NULL)
- {
- c->state=ACPT_S_GET_ACCEPT_SOCKET;
+ if (b->next_bio == NULL) {
+ c->state = ACPT_S_GET_ACCEPT_SOCKET;
goto again;
- }
- return(1);
+ }
+ return (1);
/* break; */
- default:
- return(0);
+ default:
+ return (0);
/* break; */
- }
-
}
+}
-static int acpt_read(BIO *b, char *out, int outl)
- {
- int ret=0;
+static int
+acpt_read(BIO *b, char *out, int outl)
+{
+ int ret = 0;
BIO_ACCEPT *data;
BIO_clear_retry_flags(b);
- data=(BIO_ACCEPT *)b->ptr;
+ data = (BIO_ACCEPT *)b->ptr;
- while (b->next_bio == NULL)
- {
- ret=acpt_state(b,data);
- if (ret <= 0) return(ret);
- }
+ while (b->next_bio == NULL) {
+ ret = acpt_state(b, data);
+ if (ret <= 0)
+ return (ret);
+ }
- ret=BIO_read(b->next_bio,out,outl);
+ ret = BIO_read(b->next_bio, out, outl);
BIO_copy_next_retry(b);
- return(ret);
- }
+ return (ret);
+}
-static int acpt_write(BIO *b, const char *in, int inl)
- {
+static int
+acpt_write(BIO *b, const char *in, int inl)
+{
int ret;
BIO_ACCEPT *data;
BIO_clear_retry_flags(b);
- data=(BIO_ACCEPT *)b->ptr;
+ data = (BIO_ACCEPT *)b->ptr;
- while (b->next_bio == NULL)
- {
- ret=acpt_state(b,data);
- if (ret <= 0) return(ret);
- }
+ while (b->next_bio == NULL) {
+ ret = acpt_state(b, data);
+ if (ret <= 0)
+ return (ret);
+ }
- ret=BIO_write(b->next_bio,in,inl);
+ ret = BIO_write(b->next_bio, in, inl);
BIO_copy_next_retry(b);
- return(ret);
- }
+ return (ret);
+}
-static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
+static long
+acpt_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
int *ip;
- long ret=1;
+ long ret = 1;
BIO_ACCEPT *data;
char **pp;
- data=(BIO_ACCEPT *)b->ptr;
+ data = (BIO_ACCEPT *)b->ptr;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_RESET:
- ret=0;
- data->state=ACPT_S_BEFORE;
+ ret = 0;
+ data->state = ACPT_S_BEFORE;
acpt_close_socket(b);
- b->flags=0;
+ b->flags = 0;
break;
case BIO_C_DO_STATE_MACHINE:
/* use this one to start the connection */
- ret=(long)acpt_state(b,data);
+ ret = (long)acpt_state(b, data);
break;
case BIO_C_SET_ACCEPT:
- if (ptr != NULL)
- {
- if (num == 0)
- {
- b->init=1;
+ if (ptr != NULL) {
+ if (num == 0) {
+ b->init = 1;
if (data->param_addr != NULL)
OPENSSL_free(data->param_addr);
- data->param_addr=BUF_strdup(ptr);
- }
- else if (num == 1)
- {
- data->accept_nbio=(ptr != NULL);
- }
- else if (num == 2)
- {
+ data->param_addr = BUF_strdup(ptr);
+ } else if (num == 1) {
+ data->accept_nbio = (ptr != NULL);
+ } else if (num == 2) {
if (data->bio_chain != NULL)
BIO_free(data->bio_chain);
- data->bio_chain=(BIO *)ptr;
- }
+ data->bio_chain = (BIO *)ptr;
}
+ }
break;
case BIO_C_SET_NBIO:
- data->nbio=(int)num;
+ data->nbio = (int)num;
break;
case BIO_C_SET_FD:
- b->init=1;
+ b->init = 1;
b->num= *((int *)ptr);
- data->accept_sock=b->num;
- data->state=ACPT_S_GET_ACCEPT_SOCKET;
- b->shutdown=(int)num;
- b->init=1;
+ data->accept_sock = b->num;
+ data->state = ACPT_S_GET_ACCEPT_SOCKET;
+ b->shutdown = (int)num;
+ b->init = 1;
break;
case BIO_C_GET_FD:
- if (b->init)
- {
- ip=(int *)ptr;
+ if (b->init) {
+ ip = (int *)ptr;
if (ip != NULL)
- *ip=data->accept_sock;
- ret=data->accept_sock;
- }
- else
- ret= -1;
+ *ip = data->accept_sock;
+ ret = data->accept_sock;
+ } else
+ ret = -1;
break;
case BIO_C_GET_ACCEPT:
- if (b->init)
- {
- if (ptr != NULL)
- {
- pp=(char **)ptr;
- *pp=data->param_addr;
- }
- else
- ret= -1;
- }
- else
- ret= -1;
+ if (b->init) {
+ if (ptr != NULL) {
+ pp = (char **)ptr;
+ *pp = data->param_addr;
+ } else
+ ret = -1;
+ } else
+ ret = -1;
break;
case BIO_CTRL_GET_CLOSE:
- ret=b->shutdown;
+ ret = b->shutdown;
break;
case BIO_CTRL_SET_CLOSE:
- b->shutdown=(int)num;
+ b->shutdown = (int)num;
break;
case BIO_CTRL_PENDING:
case BIO_CTRL_WPENDING:
- ret=0;
+ ret = 0;
break;
case BIO_CTRL_FLUSH:
break;
case BIO_C_SET_BIND_MODE:
- data->bind_mode=(int)num;
+ data->bind_mode = (int)num;
break;
case BIO_C_GET_BIND_MODE:
- ret=(long)data->bind_mode;
+ ret = (long)data->bind_mode;
break;
case BIO_CTRL_DUP:
/* dbio=(BIO *)ptr;
BIO_set_port(dbio,data->param_port);
if (data->param_hostname)
BIO_set_hostname(dbio,data->param_hostname);
- BIO_set_nbio(dbio,data->nbio); */
+ BIO_set_nbio(dbio,data->nbio);
+*/
break;
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
}
-
-static int acpt_puts(BIO *bp, const char *str)
- {
- int n,ret;
-
- n=strlen(str);
- ret=acpt_write(bp,str,n);
- return(ret);
- }
-
-BIO *BIO_new_accept(char *str)
- {
+ return (ret);
+}
+
+static int
+acpt_puts(BIO *bp, const char *str)
+{
+ int n, ret;
+
+ n = strlen(str);
+ ret = acpt_write(bp, str, n);
+ return (ret);
+}
+
+BIO
+*BIO_new_accept(char *str)
+{
BIO *ret;
- ret=BIO_new(BIO_s_accept());
- if (ret == NULL) return(NULL);
- if (BIO_set_accept_port(ret,str))
- return(ret);
- else
- {
+ ret = BIO_new(BIO_s_accept());
+ if (ret == NULL)
+ return (NULL);
+ if (BIO_set_accept_port(ret, str))
+ return (ret);
+ else {
BIO_free(ret);
- return(NULL);
- }
+ return (NULL);
}
+}
#endif
static int bio_make_pair(BIO *bio1, BIO *bio2);
static void bio_destroy_pair(BIO *bio);
-static BIO_METHOD methods_biop =
-{
+static BIO_METHOD methods_biop = {
BIO_TYPE_BIO,
"BIO pair",
bio_write,
NULL /* no bio_callback_ctrl */
};
-BIO_METHOD *BIO_s_bio(void)
- {
+BIO_METHOD
+*BIO_s_bio(void)
+{
return &methods_biop;
- }
+}
+
+struct bio_bio_st {
+ BIO *peer; /* NULL if buf == NULL.
+ * If peer != NULL, then peer->ptr is also a bio_bio_st,
+ * and its "peer" member points back to us.
+ * peer != NULL iff init != 0 in the BIO. */
-struct bio_bio_st
-{
- BIO *peer; /* NULL if buf == NULL.
- * If peer != NULL, then peer->ptr is also a bio_bio_st,
- * and its "peer" member points back to us.
- * peer != NULL iff init != 0 in the BIO. */
-
/* This is for what we write (i.e. reading uses peer's struct): */
- int closed; /* valid iff peer != NULL */
- size_t len; /* valid iff buf != NULL; 0 if peer == NULL */
- size_t offset; /* valid iff buf != NULL; 0 if len == 0 */
+ int closed; /* valid iff peer != NULL */
+ size_t len; /* valid iff buf != NULL; 0 if peer == NULL */
+ size_t offset; /* valid iff buf != NULL; 0 if len == 0 */
size_t size;
char *buf; /* "size" elements (if != NULL) */
size_t request; /* valid iff peer != NULL; 0 if len != 0,
- * otherwise set by peer to number of bytes
- * it (unsuccessfully) tried to read,
+ * otherwise set by peer to number of bytes
+ * it (unsuccessfully) tried to read,
* never more than buffer space (size-len) warrants. */
};
-static int bio_new(BIO *bio)
- {
+static int
+bio_new(BIO *bio)
+{
struct bio_bio_st *b;
-
+
b = OPENSSL_malloc(sizeof *b);
if (b == NULL)
return 0;
b->peer = NULL;
- b->size = 17*1024; /* enough for one TLS record (just a default) */
+ b->size = 17 * 1024; /* enough for one TLS record (just a default) */
b->buf = NULL;
bio->ptr = b;
return 1;
- }
+}
-
-static int bio_free(BIO *bio)
- {
+static int
+bio_free(BIO *bio)
+{
struct bio_bio_st *b;
if (bio == NULL)
if (b->peer)
bio_destroy_pair(bio);
-
- if (b->buf != NULL)
- {
+
+ if (b->buf != NULL) {
OPENSSL_free(b->buf);
- }
+ }
OPENSSL_free(b);
return 1;
- }
+}
-static int bio_read(BIO *bio, char *buf, int size_)
- {
+static int
+bio_read(BIO *bio, char *buf, int size_)
+{
size_t size = size_;
size_t rest;
struct bio_bio_st *b, *peer_b;
if (buf == NULL || size == 0)
return 0;
- if (peer_b->len == 0)
- {
+ if (peer_b->len == 0) {
if (peer_b->closed)
return 0; /* writer has closed, and no data is left */
- else
- {
+ else {
BIO_set_retry_read(bio); /* buffer is empty */
if (size <= peer_b->size)
peer_b->request = size;
* deliver in one write */
peer_b->request = peer_b->size;
return -1;
- }
}
+ }
/* we can read */
if (peer_b->len < size)
size = peer_b->len;
/* now read "size" bytes */
-
+
rest = size;
-
+
assert(rest > 0);
do /* one or two iterations */
- {
+ {
size_t chunk;
-
+
assert(rest <= peer_b->len);
if (peer_b->offset + rest <= peer_b->size)
chunk = rest;
/* wrap around ring buffer */
chunk = peer_b->size - peer_b->offset;
assert(peer_b->offset + chunk <= peer_b->size);
-
+
memcpy(buf, peer_b->buf + peer_b->offset, chunk);
-
+
peer_b->len -= chunk;
- if (peer_b->len)
- {
+ if (peer_b->len) {
peer_b->offset += chunk;
assert(peer_b->offset <= peer_b->size);
if (peer_b->offset == peer_b->size)
peer_b->offset = 0;
buf += chunk;
- }
- else
- {
+ } else {
/* buffer now empty, no need to advance "buf" */
assert(chunk == rest);
peer_b->offset = 0;
- }
- rest -= chunk;
}
- while (rest);
-
+ rest -= chunk;
+ } while (rest);
+
return size;
- }
+}
/* non-copying interface: provide pointer to available data in buffer
* bio_nread0: return number of available bytes
*/
/* WARNING: The non-copying interface is largely untested as of yet
* and may contain bugs. */
-static ossl_ssize_t bio_nread0(BIO *bio, char **buf)
- {
+static ossl_ssize_t
+bio_nread0(BIO *bio, char **buf)
+{
struct bio_bio_st *b, *peer_b;
ossl_ssize_t num;
-
+
BIO_clear_retry_flags(bio);
if (!bio->init)
return 0;
-
+
b = bio->ptr;
assert(b != NULL);
assert(b->peer != NULL);
peer_b = b->peer->ptr;
assert(peer_b != NULL);
assert(peer_b->buf != NULL);
-
+
peer_b->request = 0;
-
- if (peer_b->len == 0)
- {
+
+ if (peer_b->len == 0) {
char dummy;
-
+
/* avoid code duplication -- nothing available for reading */
return bio_read(bio, &dummy, 1); /* returns 0 or -1 */
- }
+ }
num = peer_b->len;
if (peer_b->size < peer_b->offset + num)
if (buf != NULL)
*buf = peer_b->buf + peer_b->offset;
return num;
- }
+}
-static ossl_ssize_t bio_nread(BIO *bio, char **buf, size_t num_)
- {
+static ossl_ssize_t
+bio_nread(BIO *bio, char **buf, size_t num_)
+{
struct bio_bio_st *b, *peer_b;
ossl_ssize_t num, available;
peer_b = b->peer->ptr;
peer_b->len -= num;
- if (peer_b->len)
- {
+ if (peer_b->len) {
peer_b->offset += num;
assert(peer_b->offset <= peer_b->size);
if (peer_b->offset == peer_b->size)
peer_b->offset = 0;
- }
- else
+ } else
peer_b->offset = 0;
return num;
- }
+}
-static int bio_write(BIO *bio, const char *buf, int num_)
- {
+static int
+bio_write(BIO *bio, const char *buf, int num_)
+{
size_t num = num_;
size_t rest;
struct bio_bio_st *b;
if (!bio->init || buf == NULL || num == 0)
return 0;
- b = bio->ptr;
+ b = bio->ptr;
+
assert(b != NULL);
assert(b->peer != NULL);
assert(b->buf != NULL);
b->request = 0;
- if (b->closed)
- {
+ if (b->closed) {
/* we already closed */
BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE);
return -1;
- }
+ }
assert(b->len <= b->size);
- if (b->len == b->size)
- {
+ if (b->len == b->size) {
BIO_set_retry_write(bio); /* buffer is full */
return -1;
- }
+ }
/* we can write */
if (num > b->size - b->len)
num = b->size - b->len;
-
+
/* now write "num" bytes */
rest = num;
-
+
assert(rest > 0);
do /* one or two iterations */
- {
+ {
size_t write_offset;
size_t chunk;
else
/* wrap around ring buffer */
chunk = b->size - write_offset;
-
+
memcpy(b->buf + write_offset, buf, chunk);
-
+
b->len += chunk;
assert(b->len <= b->size);
-
+
rest -= chunk;
buf += chunk;
- }
- while (rest);
+ } while (rest);
return num;
- }
+}
/* non-copying interface: provide pointer to region to write to
* bio_nwrite0: check how much space is available
* (example usage: bio_nwrite0(), write to buffer, bio_nwrite()
* or just bio_nwrite(), write to buffer)
*/
-static ossl_ssize_t bio_nwrite0(BIO *bio, char **buf)
- {
+static ossl_ssize_t
+bio_nwrite0(BIO *bio, char **buf)
+{
struct bio_bio_st *b;
size_t num;
size_t write_offset;
if (!bio->init)
return 0;
- b = bio->ptr;
+ b = bio->ptr;
+
assert(b != NULL);
assert(b->peer != NULL);
assert(b->buf != NULL);
b->request = 0;
- if (b->closed)
- {
+ if (b->closed) {
BIOerr(BIO_F_BIO_NWRITE0, BIO_R_BROKEN_PIPE);
return -1;
- }
+ }
assert(b->len <= b->size);
- if (b->len == b->size)
- {
+ if (b->len == b->size) {
BIO_set_retry_write(bio);
return -1;
- }
+ }
num = b->size - b->len;
write_offset = b->offset + b->len;
assert(write_offset + num <= b->size);
return num;
- }
+}
-static ossl_ssize_t bio_nwrite(BIO *bio, char **buf, size_t num_)
- {
+static ossl_ssize_t
+bio_nwrite(BIO *bio, char **buf, size_t num_)
+{
struct bio_bio_st *b;
ossl_ssize_t num, space;
assert(b->len <= b->size);
return num;
- }
+}
-static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
- {
+static long
+bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
+{
long ret;
struct bio_bio_st *b = bio->ptr;
-
+
assert(b != NULL);
- switch (cmd)
- {
- /* specific CTRL codes */
+ switch (cmd) {
+ /* specific CTRL codes */
case BIO_C_SET_WRITE_BUF_SIZE:
- if (b->peer)
- {
+ if (b->peer) {
BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE);
ret = 0;
- }
- else if (num == 0)
- {
+ } else if (num == 0) {
BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT);
ret = 0;
- }
- else
- {
+ } else {
size_t new_size = num;
- if (b->size != new_size)
- {
- if (b->buf)
- {
+ if (b->size != new_size) {
+ if (b->buf) {
OPENSSL_free(b->buf);
b->buf = NULL;
- }
- b->size = new_size;
}
- ret = 1;
+ b->size = new_size;
}
+ ret = 1;
+ }
break;
case BIO_C_GET_WRITE_BUF_SIZE:
case BIO_C_MAKE_BIO_PAIR:
{
- BIO *other_bio = ptr;
-
- if (bio_make_pair(bio, other_bio))
- ret = 1;
- else
- ret = 0;
+ BIO *other_bio = ptr;
+
+ if (bio_make_pair(bio, other_bio))
+ ret = 1;
+ else
+ ret = 0;
}
break;
-
+
case BIO_C_DESTROY_BIO_PAIR:
/* Affects both BIOs in the pair -- call just once!
* Or let BIO_free(bio1); BIO_free(bio2); do the job. */
/* prepare for non-copying read */
ret = (long) bio_nread0(bio, ptr);
break;
-
+
case BIO_C_NREAD:
/* non-copying read */
ret = (long) bio_nread(bio, ptr, (size_t) num);
break;
-
+
case BIO_C_NWRITE0:
/* prepare for non-copying write */
ret = (long) bio_nwrite0(bio, ptr);
/* non-copying write */
ret = (long) bio_nwrite(bio, ptr, (size_t) num);
break;
-
- /* standard CTRL codes follow */
+
+ /* standard CTRL codes follow */
case BIO_CTRL_RESET:
- if (b->buf != NULL)
- {
+ if (b->buf != NULL) {
b->len = 0;
b->offset = 0;
- }
+ }
ret = 0;
- break;
+ break;
+
case BIO_CTRL_GET_CLOSE:
ret = bio->shutdown;
break;
case BIO_CTRL_PENDING:
- if (b->peer != NULL)
- {
+ if (b->peer != NULL) {
struct bio_bio_st *peer_b = b->peer->ptr;
-
+
ret = (long) peer_b->len;
- }
- else
+ } else
ret = 0;
break;
case BIO_CTRL_DUP:
/* See BIO_dup_chain for circumstances we have to expect. */
{
- BIO *other_bio = ptr;
- struct bio_bio_st *other_b;
-
- assert(other_bio != NULL);
- other_b = other_bio->ptr;
- assert(other_b != NULL);
-
- assert(other_b->buf == NULL); /* other_bio is always fresh */
-
- other_b->size = b->size;
+ BIO *other_bio = ptr;
+ struct bio_bio_st *other_b;
+
+ assert(other_bio != NULL);
+ other_b = other_bio->ptr;
+ assert(other_b != NULL);
+
+ assert(other_b->buf == NULL); /* other_bio is always fresh */
+
+ other_b->size = b->size;
}
ret = 1;
case BIO_CTRL_EOF:
{
- BIO *other_bio = ptr;
-
- if (other_bio)
- {
- struct bio_bio_st *other_b = other_bio->ptr;
-
- assert(other_b != NULL);
- ret = other_b->len == 0 && other_b->closed;
- }
- else
- ret = 1;
+ BIO *other_bio = ptr;
+
+ if (other_bio) {
+ struct bio_bio_st *other_b = other_bio->ptr;
+
+ assert(other_b != NULL);
+ ret = other_b->len == 0 && other_b->closed;
+ } else
+ ret = 1;
}
break;
default:
ret = 0;
- }
- return ret;
}
+ return ret;
+}
-static int bio_puts(BIO *bio, const char *str)
- {
+static int
+bio_puts(BIO *bio, const char *str)
+{
return bio_write(bio, str, strlen(str));
- }
+}
-static int bio_make_pair(BIO *bio1, BIO *bio2)
- {
+static int
+bio_make_pair(BIO *bio1, BIO *bio2)
+{
struct bio_bio_st *b1, *b2;
assert(bio1 != NULL);
b1 = bio1->ptr;
b2 = bio2->ptr;
-
- if (b1->peer != NULL || b2->peer != NULL)
- {
+
+ if (b1->peer != NULL || b2->peer != NULL) {
BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE);
return 0;
- }
-
- if (b1->buf == NULL)
- {
+ }
+
+ if (b1->buf == NULL) {
b1->buf = OPENSSL_malloc(b1->size);
- if (b1->buf == NULL)
- {
+ if (b1->buf == NULL) {
BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
return 0;
- }
+ }
b1->len = 0;
b1->offset = 0;
- }
-
- if (b2->buf == NULL)
- {
+ }
+
+ if (b2->buf == NULL) {
b2->buf = OPENSSL_malloc(b2->size);
- if (b2->buf == NULL)
- {
+ if (b2->buf == NULL) {
BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
return 0;
- }
+ }
b2->len = 0;
b2->offset = 0;
- }
-
+ }
+
b1->peer = bio2;
b1->closed = 0;
b1->request = 0;
bio2->init = 1;
return 1;
- }
+}
-static void bio_destroy_pair(BIO *bio)
- {
+static void
+bio_destroy_pair(BIO *bio)
+{
struct bio_bio_st *b = bio->ptr;
- if (b != NULL)
- {
+ if (b != NULL) {
BIO *peer_bio = b->peer;
- if (peer_bio != NULL)
- {
+ if (peer_bio != NULL) {
struct bio_bio_st *peer_b = peer_bio->ptr;
assert(peer_b != NULL);
assert(peer_b->buf != NULL);
peer_b->len = 0;
peer_b->offset = 0;
-
+
b->peer = NULL;
bio->init = 0;
assert(b->buf != NULL);
b->len = 0;
b->offset = 0;
- }
}
}
-
+}
+
/* Exported convenience functions */
-int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1,
- BIO **bio2_p, size_t writebuf2)
- {
- BIO *bio1 = NULL, *bio2 = NULL;
- long r;
- int ret = 0;
-
- bio1 = BIO_new(BIO_s_bio());
- if (bio1 == NULL)
- goto err;
- bio2 = BIO_new(BIO_s_bio());
- if (bio2 == NULL)
- goto err;
-
- if (writebuf1)
- {
- r = BIO_set_write_buf_size(bio1, writebuf1);
- if (!r)
- goto err;
- }
- if (writebuf2)
- {
- r = BIO_set_write_buf_size(bio2, writebuf2);
- if (!r)
- goto err;
- }
-
- r = BIO_make_bio_pair(bio1, bio2);
- if (!r)
- goto err;
- ret = 1;
-
- err:
- if (ret == 0)
- {
- if (bio1)
- {
- BIO_free(bio1);
- bio1 = NULL;
- }
- if (bio2)
- {
- BIO_free(bio2);
- bio2 = NULL;
- }
- }
-
- *bio1_p = bio1;
- *bio2_p = bio2;
- return ret;
- }
-
-size_t BIO_ctrl_get_write_guarantee(BIO *bio)
- {
- return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL);
+int
+BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1, BIO **bio2_p, size_t writebuf2)
+{
+ BIO *bio1 = NULL, *bio2 = NULL;
+ long r;
+ int ret = 0;
+
+ bio1 = BIO_new(BIO_s_bio());
+ if (bio1 == NULL)
+ goto err;
+ bio2 = BIO_new(BIO_s_bio());
+ if (bio2 == NULL)
+ goto err;
+
+ if (writebuf1) {
+ r = BIO_set_write_buf_size(bio1, writebuf1);
+ if (!r)
+ goto err;
+ }
+ if (writebuf2) {
+ r = BIO_set_write_buf_size(bio2, writebuf2);
+ if (!r)
+ goto err;
}
-size_t BIO_ctrl_get_read_request(BIO *bio)
- {
- return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL);
+ r = BIO_make_bio_pair(bio1, bio2);
+ if (!r)
+ goto err;
+ ret = 1;
+
+ err:
+ if (ret == 0) {
+ if (bio1) {
+ BIO_free(bio1);
+ bio1 = NULL;
+ }
+ if (bio2) {
+ BIO_free(bio2);
+ bio2 = NULL;
+ }
}
-int BIO_ctrl_reset_read_request(BIO *bio)
- {
+ *bio1_p = bio1;
+ *bio2_p = bio2;
+ return ret;
+}
+
+size_t
+BIO_ctrl_get_write_guarantee(BIO *bio)
+{
+ return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL);
+}
+
+size_t
+BIO_ctrl_get_read_request(BIO *bio)
+{
+ return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL);
+}
+
+int
+BIO_ctrl_reset_read_request(BIO *bio)
+{
return (BIO_ctrl(bio, BIO_C_RESET_READ_REQUEST, 0, NULL) != 0);
- }
+}
/* BIO_nread0/nread/nwrite0/nwrite are available only for BIO pairs for now
* (conceivably some other BIOs could allow non-copying reads and writes too.)
*/
-int BIO_nread0(BIO *bio, char **buf)
- {
+int
+BIO_nread0(BIO *bio, char **buf)
+{
long ret;
- if (!bio->init)
- {
+ if (!bio->init) {
BIOerr(BIO_F_BIO_NREAD0, BIO_R_UNINITIALIZED);
return -2;
- }
+ }
ret = BIO_ctrl(bio, BIO_C_NREAD0, 0, buf);
if (ret > INT_MAX)
return INT_MAX;
else
return (int) ret;
- }
+}
-int BIO_nread(BIO *bio, char **buf, int num)
- {
+int
+BIO_nread(BIO *bio, char **buf, int num)
+{
int ret;
- if (!bio->init)
- {
+ if (!bio->init) {
BIOerr(BIO_F_BIO_NREAD, BIO_R_UNINITIALIZED);
return -2;
- }
+ }
ret = (int) BIO_ctrl(bio, BIO_C_NREAD, num, buf);
if (ret > 0)
bio->num_read += ret;
return ret;
- }
+}
-int BIO_nwrite0(BIO *bio, char **buf)
- {
+int
+BIO_nwrite0(BIO *bio, char **buf)
+{
long ret;
- if (!bio->init)
- {
+ if (!bio->init) {
BIOerr(BIO_F_BIO_NWRITE0, BIO_R_UNINITIALIZED);
return -2;
- }
+ }
ret = BIO_ctrl(bio, BIO_C_NWRITE0, 0, buf);
if (ret > INT_MAX)
return INT_MAX;
else
return (int) ret;
- }
+}
-int BIO_nwrite(BIO *bio, char **buf, int num)
- {
+int
+BIO_nwrite(BIO *bio, char **buf, int num)
+{
int ret;
- if (!bio->init)
- {
+ if (!bio->init) {
BIOerr(BIO_F_BIO_NWRITE, BIO_R_UNINITIALIZED);
return -2;
- }
+ }
ret = BIO_ctrl(bio, BIO_C_NWRITE, num, buf);
if (ret > 0)
bio->num_write += ret;
return ret;
- }
+}
#endif
-typedef struct bio_connect_st
- {
+typedef struct bio_connect_st {
int state;
char *param_hostname;
/* called when the connection is initially made
* callback(BIO,state,ret); The callback should return
* 'ret'. state is for compatibility with the ssl info_callback */
- int (*info_callback)(const BIO *bio,int state,int ret);
- } BIO_CONNECT;
+ int (*info_callback)(const BIO *bio, int state, int ret);
+} BIO_CONNECT;
static int conn_write(BIO *h, const char *buf, int num);
static int conn_read(BIO *h, char *buf, int size);
static int conn_state(BIO *b, BIO_CONNECT *c);
static void conn_close_socket(BIO *data);
-BIO_CONNECT *BIO_CONNECT_new(void );
+BIO_CONNECT *BIO_CONNECT_new(void);
void BIO_CONNECT_free(BIO_CONNECT *a);
-static BIO_METHOD methods_connectp=
- {
+static BIO_METHOD methods_connectp = {
BIO_TYPE_CONNECT,
"socket connect",
conn_write,
conn_new,
conn_free,
conn_callback_ctrl,
- };
+};
-static int conn_state(BIO *b, BIO_CONNECT *c)
- {
- int ret= -1,i;
+static int
+conn_state(BIO *b, BIO_CONNECT *c)
+{
+ int ret = -1, i;
unsigned long l;
- char *p,*q;
- int (*cb)(const BIO *,int,int)=NULL;
+ char *p, *q;
+ int (*cb)(const BIO *, int, int) = NULL;
if (c->info_callback != NULL)
- cb=c->info_callback;
+ cb = c->info_callback;
- for (;;)
- {
- switch (c->state)
- {
+ for (;;) {
+ switch (c->state) {
case BIO_CONN_S_BEFORE:
- p=c->param_hostname;
- if (p == NULL)
- {
- BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTNAME_SPECIFIED);
+ p = c->param_hostname;
+ if (p == NULL) {
+ BIOerr(BIO_F_CONN_STATE, BIO_R_NO_HOSTNAME_SPECIFIED);
goto exit_loop;
- }
- for ( ; *p != '\0'; p++)
- {
- if ((*p == ':') || (*p == '/')) break;
- }
+ }
+ for (; *p != '\0'; p++) {
+ if ((*p == ':') || (*p == '/'))
+ break;
+ }
i= *p;
- if ((i == ':') || (i == '/'))
- {
-
- *(p++)='\0';
- if (i == ':')
- {
- for (q=p; *q; q++)
- if (*q == '/')
- {
- *q='\0';
+ if ((i == ':') || (i == '/')) {
+ *(p++) = '\0';
+ if (i == ':') {
+ for (q = p; *q; q++)
+ if (*q == '/') {
+ *q = '\0';
break;
- }
+ }
if (c->param_port != NULL)
OPENSSL_free(c->param_port);
- c->param_port=BUF_strdup(p);
- }
+ c->param_port = BUF_strdup(p);
}
+ }
- if (c->param_port == NULL)
- {
- BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED);
- ERR_add_error_data(2,"host=",c->param_hostname);
+ if (c->param_port == NULL) {
+ BIOerr(BIO_F_CONN_STATE, BIO_R_NO_PORT_SPECIFIED);
+ ERR_add_error_data(2, "host=", c->param_hostname);
goto exit_loop;
- }
- c->state=BIO_CONN_S_GET_IP;
+ }
+ c->state = BIO_CONN_S_GET_IP;
break;
case BIO_CONN_S_GET_IP:
- if (BIO_get_host_ip(c->param_hostname,&(c->ip[0])) <= 0)
+ if (BIO_get_host_ip(c->param_hostname, &(c->ip[0])) <= 0)
goto exit_loop;
- c->state=BIO_CONN_S_GET_PORT;
+ c->state = BIO_CONN_S_GET_PORT;
break;
case BIO_CONN_S_GET_PORT:
- if (c->param_port == NULL)
- {
+ if (c->param_port == NULL) {
/* abort(); */
goto exit_loop;
- }
- else if (BIO_get_port(c->param_port,&c->port) <= 0)
+ } else if (BIO_get_port(c->param_port, &c->port) <= 0)
goto exit_loop;
- c->state=BIO_CONN_S_CREATE_SOCKET;
+ c->state = BIO_CONN_S_CREATE_SOCKET;
break;
case BIO_CONN_S_CREATE_SOCKET:
/* now setup address */
- memset((char *)&c->them,0,sizeof(c->them));
- c->them.sin_family=AF_INET;
- c->them.sin_port=htons((unsigned short)c->port);
- l=(unsigned long)
- ((unsigned long)c->ip[0]<<24L)|
- ((unsigned long)c->ip[1]<<16L)|
- ((unsigned long)c->ip[2]<< 8L)|
- ((unsigned long)c->ip[3]);
- c->them.sin_addr.s_addr=htonl(l);
- c->state=BIO_CONN_S_CREATE_SOCKET;
-
- ret=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
- if (ret == -1)
- {
- SYSerr(SYS_F_SOCKET,errno);
- ERR_add_error_data(4,"host=",c->param_hostname,
- ":",c->param_port);
- BIOerr(BIO_F_CONN_STATE,BIO_R_UNABLE_TO_CREATE_SOCKET);
+ memset((char *)&c->them, 0, sizeof(c->them));
+ c->them.sin_family = AF_INET;
+ c->them.sin_port = htons((unsigned short)c->port);
+ l = (unsigned long)
+ ((unsigned long)c->ip[0] << 24L)|
+ ((unsigned long)c->ip[1] << 16L)|
+ ((unsigned long)c->ip[2] << 8L)|
+ ((unsigned long)c->ip[3]);
+ c->them.sin_addr.s_addr = htonl(l);
+ c->state = BIO_CONN_S_CREATE_SOCKET;
+
+ ret = socket(AF_INET, SOCK_STREAM, SOCKET_PROTOCOL);
+ if (ret == -1) {
+ SYSerr(SYS_F_SOCKET, errno);
+ ERR_add_error_data(4, "host=",
+ c->param_hostname, ":", c->param_port);
+ BIOerr(BIO_F_CONN_STATE,
+ BIO_R_UNABLE_TO_CREATE_SOCKET);
goto exit_loop;
- }
- b->num=ret;
- c->state=BIO_CONN_S_NBIO;
+ }
+ b->num = ret;
+ c->state = BIO_CONN_S_NBIO;
break;
case BIO_CONN_S_NBIO:
- if (c->nbio)
- {
- if (!BIO_socket_nbio(b->num,1))
- {
- BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO);
- ERR_add_error_data(4,"host=",
- c->param_hostname,
- ":",c->param_port);
+ if (c->nbio) {
+ if (!BIO_socket_nbio(b->num, 1)) {
+ BIOerr(BIO_F_CONN_STATE,
+ BIO_R_ERROR_SETTING_NBIO);
+ ERR_add_error_data(4, "host=",
+ c->param_hostname, ":",
+ c->param_port);
goto exit_loop;
- }
}
- c->state=BIO_CONN_S_CONNECT;
+ }
+ c->state = BIO_CONN_S_CONNECT;
#if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE)
- i=1;
- i=setsockopt(b->num,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
- if (i < 0)
- {
- SYSerr(SYS_F_SOCKET,errno);
- ERR_add_error_data(4,"host=",c->param_hostname,
- ":",c->param_port);
- BIOerr(BIO_F_CONN_STATE,BIO_R_KEEPALIVE);
+ i = 1;
+ i = setsockopt(b->num, SOL_SOCKET, SO_KEEPALIVE,(char *)&i, sizeof(i));
+ if (i < 0) {
+ SYSerr(SYS_F_SOCKET, errno);
+ ERR_add_error_data(4, "host=",
+ c->param_hostname, ":", c->param_port);
+ BIOerr(BIO_F_CONN_STATE, BIO_R_KEEPALIVE);
goto exit_loop;
- }
+ }
#endif
break;
case BIO_CONN_S_CONNECT:
BIO_clear_retry_flags(b);
- ret=connect(b->num,
- (struct sockaddr *)&c->them,
- sizeof(c->them));
- b->retry_reason=0;
- if (ret < 0)
- {
- if (BIO_sock_should_retry(ret))
- {
+ ret = connect(b->num,
+ (struct sockaddr *)&c->them,
+ sizeof(c->them));
+ b->retry_reason = 0;
+ if (ret < 0) {
+ if (BIO_sock_should_retry(ret)) {
BIO_set_retry_special(b);
- c->state=BIO_CONN_S_BLOCKED_CONNECT;
- b->retry_reason=BIO_RR_CONNECT;
- }
- else
- {
- SYSerr(SYS_F_CONNECT,errno);
- ERR_add_error_data(4,"host=",
- c->param_hostname,
- ":",c->param_port);
- BIOerr(BIO_F_CONN_STATE,BIO_R_CONNECT_ERROR);
- }
- goto exit_loop;
+ c->state = BIO_CONN_S_BLOCKED_CONNECT;
+ b->retry_reason = BIO_RR_CONNECT;
+ } else {
+ SYSerr(SYS_F_CONNECT, errno);
+ ERR_add_error_data(4, "host=",
+ c->param_hostname, ":",
+ c->param_port);
+ BIOerr(BIO_F_CONN_STATE,
+ BIO_R_CONNECT_ERROR);
}
- else
- c->state=BIO_CONN_S_OK;
+ goto exit_loop;
+ } else
+ c->state = BIO_CONN_S_OK;
break;
case BIO_CONN_S_BLOCKED_CONNECT:
- i=BIO_sock_error(b->num);
- if (i)
- {
+ i = BIO_sock_error(b->num);
+ if (i) {
BIO_clear_retry_flags(b);
- SYSerr(SYS_F_CONNECT,i);
- ERR_add_error_data(4,"host=",
- c->param_hostname,
- ":",c->param_port);
- BIOerr(BIO_F_CONN_STATE,BIO_R_NBIO_CONNECT_ERROR);
- ret=0;
+ SYSerr(SYS_F_CONNECT, i);
+ ERR_add_error_data(4, "host=",
+ c->param_hostname, ":", c->param_port);
+ BIOerr(BIO_F_CONN_STATE,
+ BIO_R_NBIO_CONNECT_ERROR);
+ ret = 0;
goto exit_loop;
- }
- else
- c->state=BIO_CONN_S_OK;
+ } else
+ c->state = BIO_CONN_S_OK;
break;
case BIO_CONN_S_OK:
- ret=1;
+ ret = 1;
goto exit_loop;
default:
/* abort(); */
goto exit_loop;
- }
+ }
- if (cb != NULL)
- {
- if (!(ret=cb((BIO *)b,c->state,ret)))
+ if (cb != NULL) {
+ if (!(ret = cb((BIO *)b, c->state, ret)))
goto end;
- }
}
+ }
/* Loop does not exit */
exit_loop:
if (cb != NULL)
- ret=cb((BIO *)b,c->state,ret);
+ ret = cb((BIO *)b, c->state, ret);
end:
- return(ret);
- }
+ return (ret);
+}
-BIO_CONNECT *BIO_CONNECT_new(void)
- {
+BIO_CONNECT
+*BIO_CONNECT_new(void)
+{
BIO_CONNECT *ret;
- if ((ret=(BIO_CONNECT *)OPENSSL_malloc(sizeof(BIO_CONNECT))) == NULL)
- return(NULL);
- ret->state=BIO_CONN_S_BEFORE;
- ret->param_hostname=NULL;
- ret->param_port=NULL;
- ret->info_callback=NULL;
- ret->nbio=0;
- ret->ip[0]=0;
- ret->ip[1]=0;
- ret->ip[2]=0;
- ret->ip[3]=0;
- ret->port=0;
- memset((char *)&ret->them,0,sizeof(ret->them));
- return(ret);
- }
-
-void BIO_CONNECT_free(BIO_CONNECT *a)
- {
- if(a == NULL)
- return;
+ if ((ret = (BIO_CONNECT *)OPENSSL_malloc(sizeof(BIO_CONNECT))) == NULL)
+ return (NULL);
+ ret->state = BIO_CONN_S_BEFORE;
+ ret->param_hostname = NULL;
+ ret->param_port = NULL;
+ ret->info_callback = NULL;
+ ret->nbio = 0;
+ ret->ip[0] = 0;
+ ret->ip[1] = 0;
+ ret->ip[2] = 0;
+ ret->ip[3] = 0;
+ ret->port = 0;
+ memset((char *)&ret->them, 0, sizeof(ret->them));
+ return (ret);
+}
+
+void
+BIO_CONNECT_free(BIO_CONNECT *a)
+{
+ if (a == NULL)
+ return;
if (a->param_hostname != NULL)
OPENSSL_free(a->param_hostname);
if (a->param_port != NULL)
OPENSSL_free(a->param_port);
OPENSSL_free(a);
- }
-
-BIO_METHOD *BIO_s_connect(void)
- {
- return(&methods_connectp);
- }
-
-static int conn_new(BIO *bi)
- {
- bi->init=0;
- bi->num=-1;
- bi->flags=0;
- if ((bi->ptr=(char *)BIO_CONNECT_new()) == NULL)
- return(0);
+}
+
+BIO_METHOD
+*BIO_s_connect(void)
+{
+ return (&methods_connectp);
+}
+
+static int
+conn_new(BIO *bi)
+{
+ bi->init = 0;
+ bi->num = -1;
+ bi->flags = 0;
+ if ((bi->ptr = (char *)BIO_CONNECT_new()) == NULL)
+ return (0);
else
- return(1);
- }
+ return (1);
+}
-static void conn_close_socket(BIO *bio)
- {
+static void
+conn_close_socket(BIO *bio)
+{
BIO_CONNECT *c;
- c=(BIO_CONNECT *)bio->ptr;
- if (bio->num != -1)
- {
+ c = (BIO_CONNECT *)bio->ptr;
+ if (bio->num != -1) {
/* Only do a shutdown if things were established */
if (c->state == BIO_CONN_S_OK)
shutdown(bio->num, SHUT_RDWR);
close(bio->num);
- bio->num=-1;
- }
+ bio->num = -1;
}
+}
-static int conn_free(BIO *a)
- {
+static int
+conn_free(BIO *a)
+{
BIO_CONNECT *data;
- if (a == NULL) return(0);
- data=(BIO_CONNECT *)a->ptr;
-
- if (a->shutdown)
- {
+ if (a == NULL)
+ return (0);
+ data = (BIO_CONNECT *)a->ptr;
+
+ if (a->shutdown) {
conn_close_socket(a);
BIO_CONNECT_free(data);
- a->ptr=NULL;
- a->flags=0;
- a->init=0;
- }
- return(1);
+ a->ptr = NULL;
+ a->flags = 0;
+ a->init = 0;
}
-
-static int conn_read(BIO *b, char *out, int outl)
- {
- int ret=0;
+ return (1);
+}
+
+static int
+conn_read(BIO *b, char *out, int outl)
+{
+ int ret = 0;
BIO_CONNECT *data;
- data=(BIO_CONNECT *)b->ptr;
- if (data->state != BIO_CONN_S_OK)
- {
- ret=conn_state(b,data);
+ data = (BIO_CONNECT *)b->ptr;
+ if (data->state != BIO_CONN_S_OK) {
+ ret = conn_state(b, data);
if (ret <= 0)
- return(ret);
- }
+ return (ret);
+ }
- if (out != NULL)
- {
+ if (out != NULL) {
errno = 0;
- ret=read(b->num,out,outl);
+ ret = read(b->num, out, outl);
BIO_clear_retry_flags(b);
- if (ret <= 0)
- {
+ if (ret <= 0) {
if (BIO_sock_should_retry(ret))
BIO_set_retry_read(b);
- }
}
- return(ret);
}
+ return (ret);
+}
-static int conn_write(BIO *b, const char *in, int inl)
- {
+static int
+conn_write(BIO *b, const char *in, int inl)
+{
int ret;
BIO_CONNECT *data;
- data=(BIO_CONNECT *)b->ptr;
- if (data->state != BIO_CONN_S_OK)
- {
- ret=conn_state(b,data);
- if (ret <= 0) return(ret);
- }
+ data = (BIO_CONNECT *)b->ptr;
+ if (data->state != BIO_CONN_S_OK) {
+ ret = conn_state(b, data);
+ if (ret <= 0)
+ return (ret);
+ }
errno = 0;
- ret=write(b->num,in,inl);
+ ret = write(b->num, in, inl);
BIO_clear_retry_flags(b);
- if (ret <= 0)
- {
+ if (ret <= 0) {
if (BIO_sock_should_retry(ret))
BIO_set_retry_write(b);
- }
- return(ret);
}
+ return (ret);
+}
-static long conn_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
+static long
+conn_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
BIO *dbio;
int *ip;
const char **pptr;
- long ret=1;
+ long ret = 1;
BIO_CONNECT *data;
- data=(BIO_CONNECT *)b->ptr;
+ data = (BIO_CONNECT *)b->ptr;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_RESET:
- ret=0;
- data->state=BIO_CONN_S_BEFORE;
+ ret = 0;
+ data->state = BIO_CONN_S_BEFORE;
conn_close_socket(b);
- b->flags=0;
+ b->flags = 0;
break;
case BIO_C_DO_STATE_MACHINE:
/* use this one to start the connection */
if (data->state != BIO_CONN_S_OK)
- ret=(long)conn_state(b,data);
+ ret = (long)conn_state(b, data);
else
- ret=1;
+ ret = 1;
break;
case BIO_C_GET_CONNECT:
- if (ptr != NULL)
- {
- pptr=(const char **)ptr;
- if (num == 0)
- {
- *pptr=data->param_hostname;
-
- }
- else if (num == 1)
- {
- *pptr=data->param_port;
- }
- else if (num == 2)
- {
- *pptr= (char *)&(data->ip[0]);
- }
- else if (num == 3)
- {
- *((int *)ptr)=data->port;
- }
- if ((!b->init) || (ptr == NULL))
- *pptr="not initialized";
- ret=1;
+ if (ptr != NULL) {
+ pptr = (const char **)ptr;
+ if (num == 0) {
+ *pptr = data->param_hostname;
+
+ } else if (num == 1) {
+ *pptr = data->param_port;
+ } else if (num == 2) {
+ *pptr = (char *)&(data->ip[0]);
+ } else if (num == 3) {
+ *((int *)ptr) = data->port;
}
+ if ((!b->init) || (ptr == NULL))
+ *pptr = "not initialized";
+ ret = 1;
+ }
break;
case BIO_C_SET_CONNECT:
- if (ptr != NULL)
- {
- b->init=1;
- if (num == 0)
- {
+ if (ptr != NULL) {
+ b->init = 1;
+ if (num == 0) {
if (data->param_hostname != NULL)
OPENSSL_free(data->param_hostname);
- data->param_hostname=BUF_strdup(ptr);
- }
- else if (num == 1)
- {
+ data->param_hostname = BUF_strdup(ptr);
+ } else if (num == 1) {
if (data->param_port != NULL)
OPENSSL_free(data->param_port);
- data->param_port=BUF_strdup(ptr);
- }
- else if (num == 2)
- {
+ data->param_port = BUF_strdup(ptr);
+ } else if (num == 2) {
char buf[16];
unsigned char *p = ptr;
- (void) snprintf(buf,sizeof buf,"%d.%d.%d.%d",
- p[0],p[1],p[2],p[3]);
+ (void) snprintf(buf, sizeof buf, "%d.%d.%d.%d",
+ p[0], p[1], p[2], p[3]);
if (data->param_hostname != NULL)
OPENSSL_free(data->param_hostname);
- data->param_hostname=BUF_strdup(buf);
- memcpy(&(data->ip[0]),ptr,4);
- }
- else if (num == 3)
- {
- char buf[DECIMAL_SIZE(int)+1];
+ data->param_hostname = BUF_strdup(buf);
+ memcpy(&(data->ip[0]), ptr, 4);
+ } else if (num == 3) {
+ char buf[DECIMAL_SIZE(int) + 1];
- (void) snprintf(buf,sizeof buf,"%d",*(int *)ptr);
+ (void) snprintf(buf, sizeof buf, "%d",
+ *(int *)ptr);
if (data->param_port != NULL)
OPENSSL_free(data->param_port);
- data->param_port=BUF_strdup(buf);
+ data->param_port = BUF_strdup(buf);
data->port= *(int *)ptr;
- }
}
+ }
break;
case BIO_C_SET_NBIO:
- data->nbio=(int)num;
+ data->nbio = (int)num;
break;
case BIO_C_GET_FD:
- if (b->init)
- {
- ip=(int *)ptr;
+ if (b->init) {
+ ip = (int *)ptr;
if (ip != NULL)
- *ip=b->num;
- ret=b->num;
- }
- else
- ret= -1;
+ *ip = b->num;
+ ret = b->num;
+ } else
+ ret = -1;
break;
case BIO_CTRL_GET_CLOSE:
- ret=b->shutdown;
+ ret = b->shutdown;
break;
case BIO_CTRL_SET_CLOSE:
- b->shutdown=(int)num;
+ b->shutdown = (int)num;
break;
case BIO_CTRL_PENDING:
case BIO_CTRL_WPENDING:
- ret=0;
+ ret = 0;
break;
case BIO_CTRL_FLUSH:
break;
case BIO_CTRL_DUP:
{
- dbio=(BIO *)ptr;
- if (data->param_port)
- BIO_set_conn_port(dbio,data->param_port);
- if (data->param_hostname)
- BIO_set_conn_hostname(dbio,data->param_hostname);
- BIO_set_nbio(dbio,data->nbio);
- /* FIXME: the cast of the function seems unlikely to be a good idea */
- (void)BIO_set_info_callback(dbio,(bio_info_cb *)data->info_callback);
+ dbio = (BIO *)ptr;
+ if (data->param_port)
+ BIO_set_conn_port(dbio, data->param_port);
+ if (data->param_hostname)
+ BIO_set_conn_hostname(dbio,
+ data->param_hostname);
+ BIO_set_nbio(dbio, data->nbio);
+ /* FIXME: the cast of the function seems unlikely to be a good idea */
+ (void)BIO_set_info_callback(dbio,
+ (bio_info_cb *)data->info_callback);
}
break;
case BIO_CTRL_SET_CALLBACK:
{
#if 0 /* FIXME: Should this be used? -- Richard Levitte */
- BIOerr(BIO_F_CONN_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
- ret = -1;
+ BIOerr(BIO_F_CONN_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
+ ret = -1;
#else
- ret=0;
+ ret = 0;
#endif
}
break;
case BIO_CTRL_GET_CALLBACK:
{
- int (**fptr)(const BIO *bio,int state,int xret);
+ int (**fptr)(const BIO *bio, int state, int xret);
- fptr=(int (**)(const BIO *bio,int state,int xret))ptr;
- *fptr=data->info_callback;
+ fptr = (int (**)(const BIO *bio, int state, int xret))ptr;
+ *fptr = data->info_callback;
}
break;
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
}
+ return (ret);
+}
-static long conn_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
- {
- long ret=1;
+static long
+conn_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
+{
+ long ret = 1;
BIO_CONNECT *data;
- data=(BIO_CONNECT *)b->ptr;
+ data = (BIO_CONNECT *)b->ptr;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_SET_CALLBACK:
{
- data->info_callback=(int (*)(const struct bio_st *, int, int))fp;
+ data->info_callback = (int (*)(const struct bio_st *, int, int))fp;
}
break;
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
}
-
-static int conn_puts(BIO *bp, const char *str)
- {
- int n,ret;
-
- n=strlen(str);
- ret=conn_write(bp,str,n);
- return(ret);
- }
-
-BIO *BIO_new_connect(char *str)
- {
+ return (ret);
+}
+
+static int
+conn_puts(BIO *bp, const char *str)
+{
+ int n, ret;
+
+ n = strlen(str);
+ ret = conn_write(bp, str, n);
+ return (ret);
+}
+
+BIO
+*BIO_new_connect(char *str)
+{
BIO *ret;
- ret=BIO_new(BIO_s_connect());
- if (ret == NULL) return(NULL);
- if (BIO_set_conn_hostname(ret,str))
- return(ret);
- else
- {
+ ret = BIO_new(BIO_s_connect());
+ if (ret == NULL)
+ return (NULL);
+ if (BIO_set_conn_hostname(ret, str))
+ return (ret);
+ else {
BIO_free(ret);
- return(NULL);
- }
+ return (NULL);
}
+}
#endif
-
static int dgram_sctp_new(BIO *h);
static int dgram_sctp_free(BIO *data);
#ifdef SCTP_AUTHENTICATION_EVENT
-static void dgram_sctp_handle_auth_free_key_event(BIO *b, union sctp_notification *snp);
+static void dgram_sctp_handle_auth_free_key_event(BIO *b,
+ union sctp_notification *snp);
#endif
#endif
static void get_current_time(struct timeval *t);
-static BIO_METHOD methods_dgramp=
- {
+static BIO_METHOD methods_dgramp = {
BIO_TYPE_DGRAM,
"datagram socket",
dgram_write,
dgram_new,
dgram_free,
NULL,
- };
+};
#ifndef OPENSSL_NO_SCTP
-static BIO_METHOD methods_dgramp_sctp=
- {
+static BIO_METHOD methods_dgramp_sctp = {
BIO_TYPE_DGRAM_SCTP,
"datagram sctp socket",
dgram_sctp_write,
dgram_sctp_new,
dgram_sctp_free,
NULL,
- };
+};
#endif
-typedef struct bio_dgram_data_st
- {
+typedef struct bio_dgram_data_st {
union {
struct sockaddr sa;
struct sockaddr_in sa_in;
unsigned int mtu;
struct timeval next_timeout;
struct timeval socket_timeout;
- } bio_dgram_data;
+} bio_dgram_data;
#ifndef OPENSSL_NO_SCTP
-typedef struct bio_dgram_sctp_save_message_st
- {
- BIO *bio;
- char *data;
- int length;
- } bio_dgram_sctp_save_message;
+typedef struct bio_dgram_sctp_save_message_st {
+ BIO *bio;
+ char *data;
+ int length;
+} bio_dgram_sctp_save_message;
-typedef struct bio_dgram_sctp_data_st
- {
+typedef struct bio_dgram_sctp_data_st {
union {
struct sockaddr sa;
struct sockaddr_in sa_in;
int save_shutdown;
int peer_auth_tested;
bio_dgram_sctp_save_message saved_message;
- } bio_dgram_sctp_data;
+} bio_dgram_sctp_data;
#endif
-BIO_METHOD *BIO_s_datagram(void)
- {
- return(&methods_dgramp);
- }
+BIO_METHOD
+*BIO_s_datagram(void)
+{
+ return (&methods_dgramp);
+}
-BIO *BIO_new_dgram(int fd, int close_flag)
- {
+BIO
+*BIO_new_dgram(int fd, int close_flag)
+{
BIO *ret;
- ret=BIO_new(BIO_s_datagram());
- if (ret == NULL) return(NULL);
- BIO_set_fd(ret,fd,close_flag);
- return(ret);
- }
+ ret = BIO_new(BIO_s_datagram());
+ if (ret == NULL)
+ return (NULL);
+ BIO_set_fd(ret, fd, close_flag);
+ return (ret);
+}
-static int dgram_new(BIO *bi)
- {
+static int
+dgram_new(BIO *bi)
+{
bio_dgram_data *data = NULL;
- bi->init=0;
- bi->num=0;
+ bi->init = 0;
+ bi->num = 0;
data = OPENSSL_malloc(sizeof(bio_dgram_data));
if (data == NULL)
return 0;
memset(data, 0x00, sizeof(bio_dgram_data));
- bi->ptr = data;
+ bi->ptr = data;
- bi->flags=0;
- return(1);
- }
+ bi->flags = 0;
+ return (1);
+}
-static int dgram_free(BIO *a)
- {
+static int
+dgram_free(BIO *a)
+{
bio_dgram_data *data;
- if (a == NULL) return(0);
- if ( ! dgram_clear(a))
+ if (a == NULL)
+ return (0);
+ if (!dgram_clear(a))
return 0;
data = (bio_dgram_data *)a->ptr;
- if(data != NULL) OPENSSL_free(data);
+ if (data != NULL)
+ OPENSSL_free(data);
- return(1);
- }
+ return (1);
+}
-static int dgram_clear(BIO *a)
- {
- if (a == NULL) return(0);
- if (a->shutdown)
- {
- if (a->init)
- {
+static int
+dgram_clear(BIO *a)
+{
+ if (a == NULL)
+ return (0);
+ if (a->shutdown) {
+ if (a->init) {
shutdown(a->num, SHUT_RDWR);
close(a->num);
- }
- a->init=0;
- a->flags=0;
}
- return(1);
+ a->init = 0;
+ a->flags = 0;
}
+ return (1);
+}
-static void dgram_adjust_rcv_timeout(BIO *b)
- {
+static void
+dgram_adjust_rcv_timeout(BIO *b)
+{
#if defined(SO_RCVTIMEO)
bio_dgram_data *data = (bio_dgram_data *)b->ptr;
- union { size_t s; int i; } sz = {0};
+ union { size_t s;
+ int i;
+ } sz = {0};
/* Is a timer active? */
- if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0)
- {
+ if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) {
struct timeval timenow, timeleft;
/* Read current socket timeout */
sz.i = sizeof(timeout);
if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, &sz.i) < 0)
- { perror("getsockopt"); }
- else
- {
+ (void*)&timeout, &sz.i) < 0) {
+ perror("getsockopt");
+ } else {
data->socket_timeout.tv_sec = timeout / 1000;
data->socket_timeout.tv_usec = (timeout % 1000) * 1000;
- }
+ }
#else
sz.i = sizeof(data->socket_timeout);
- if ( getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- &(data->socket_timeout), (void *)&sz) < 0)
- { perror("getsockopt"); }
- else if (sizeof(sz.s)!=sizeof(sz.i) && sz.i==0)
- OPENSSL_assert(sz.s<=sizeof(data->socket_timeout));
+ if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
+ &(data->socket_timeout), (void *)&sz) < 0) {
+ perror("getsockopt");
+ } else if (sizeof(sz.s) != sizeof(sz.i) && sz.i == 0)
+ OPENSSL_assert(sz.s <= sizeof(data->socket_timeout));
#endif
/* Get current time */
memcpy(&timeleft, &(data->next_timeout), sizeof(struct timeval));
timeleft.tv_sec -= timenow.tv_sec;
timeleft.tv_usec -= timenow.tv_usec;
- if (timeleft.tv_usec < 0)
- {
+ if (timeleft.tv_usec < 0) {
timeleft.tv_sec--;
timeleft.tv_usec += 1000000;
- }
+ }
- if (timeleft.tv_sec < 0)
- {
+ if (timeleft.tv_sec < 0) {
timeleft.tv_sec = 0;
timeleft.tv_usec = 1;
- }
+ }
/* Adjust socket timeout if next handhake message timer
* will expire earlier.
*/
- if ((data->socket_timeout.tv_sec == 0 && data->socket_timeout.tv_usec == 0) ||
- (data->socket_timeout.tv_sec > timeleft.tv_sec) ||
- (data->socket_timeout.tv_sec == timeleft.tv_sec &&
- data->socket_timeout.tv_usec >= timeleft.tv_usec))
- {
+ if ((data->socket_timeout.tv_sec == 0 &&
+ data->socket_timeout.tv_usec == 0) ||
+ (data->socket_timeout.tv_sec > timeleft.tv_sec) ||
+ (data->socket_timeout.tv_sec == timeleft.tv_sec &&
+ data->socket_timeout.tv_usec >= timeleft.tv_usec)) {
#ifdef OPENSSL_SYS_WINDOWS
timeout = timeleft.tv_sec * 1000 + timeleft.tv_usec / 1000;
if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, sizeof(timeout)) < 0)
- { perror("setsockopt"); }
+ (void*)&timeout, sizeof(timeout)) < 0) {
+ perror("setsockopt");
+ }
#else
- if ( setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, &timeleft,
- sizeof(struct timeval)) < 0)
- { perror("setsockopt"); }
-#endif
+ if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
+ &timeleft, sizeof(struct timeval)) < 0) {
+ perror("setsockopt");
}
- }
#endif
+ }
}
+#endif
+}
-static void dgram_reset_rcv_timeout(BIO *b)
- {
+static void
+dgram_reset_rcv_timeout(BIO *b)
+{
#if defined(SO_RCVTIMEO)
bio_dgram_data *data = (bio_dgram_data *)b->ptr;
/* Is a timer active? */
- if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0)
- {
+ if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) {
#ifdef OPENSSL_SYS_WINDOWS
int timeout = data->socket_timeout.tv_sec * 1000 +
- data->socket_timeout.tv_usec / 1000;
+ data->socket_timeout.tv_usec / 1000;
if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, sizeof(timeout)) < 0)
- { perror("setsockopt"); }
+ (void*)&timeout, sizeof(timeout)) < 0) {
+ perror("setsockopt");
+ }
#else
- if ( setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, &(data->socket_timeout),
- sizeof(struct timeval)) < 0)
- { perror("setsockopt"); }
-#endif
+ if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
+ &(data->socket_timeout), sizeof(struct timeval)) < 0) {
+ perror("setsockopt");
}
#endif
}
+#endif
+}
-static int dgram_read(BIO *b, char *out, int outl)
- {
- int ret=0;
+static int
+dgram_read(BIO *b, char *out, int outl)
+{
+ int ret = 0;
bio_dgram_data *data = (bio_dgram_data *)b->ptr;
struct {
- /*
- * See commentary in b_sock.c. <appro>
- */
- union { size_t s; int i; } len;
- union {
- struct sockaddr sa;
- struct sockaddr_in sa_in;
+ /*
+ * See commentary in b_sock.c. <appro>
+ */
+ union {
+ size_t s;
+ int i;
+ } len;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in sa_in;
#if OPENSSL_USE_IPV6
- struct sockaddr_in6 sa_in6;
+ struct sockaddr_in6 sa_in6;
#endif
} peer;
} sa;
- sa.len.s=0;
- sa.len.i=sizeof(sa.peer);
+ sa.len.s = 0;
+ sa.len.i = sizeof(sa.peer);
- if (out != NULL)
- {
+ if (out != NULL) {
errno = 0;
memset(&sa.peer, 0x00, sizeof(sa.peer));
dgram_adjust_rcv_timeout(b);
- ret=recvfrom(b->num,out,outl,0,&sa.peer.sa,(void *)&sa.len);
- if (sizeof(sa.len.i)!=sizeof(sa.len.s) && sa.len.i==0)
- {
- OPENSSL_assert(sa.len.s<=sizeof(sa.peer));
+ ret = recvfrom(b->num, out, outl, 0, &sa.peer.sa,(void *)&sa.len);
+ if (sizeof(sa.len.i) != sizeof(sa.len.s) && sa.len.i == 0) {
+ OPENSSL_assert(sa.len.s <= sizeof(sa.peer));
sa.len.i = (int)sa.len.s;
- }
+ }
- if ( ! data->connected && ret >= 0)
+ if (! data->connected && ret >= 0)
BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, &sa.peer);
BIO_clear_retry_flags(b);
- if (ret < 0)
- {
- if (BIO_dgram_should_retry(ret))
- {
+ if (ret < 0) {
+ if (BIO_dgram_should_retry(ret)) {
BIO_set_retry_read(b);
data->_errno = errno;
- }
}
+ }
dgram_reset_rcv_timeout(b);
- }
- return(ret);
}
+ return (ret);
+}
-static int dgram_write(BIO *b, const char *in, int inl)
- {
+static int
+dgram_write(BIO *b, const char *in, int inl)
+{
int ret;
bio_dgram_data *data = (bio_dgram_data *)b->ptr;
errno = 0;
- if ( data->connected )
- ret=write(b->num,in,inl);
- else
- {
+ if (data->connected)
+ ret = write(b->num, in, inl);
+ else {
int peerlen = sizeof(data->peer);
if (data->peer.sa.sa_family == AF_INET)
peerlen = sizeof(data->peer.sa_in6);
#endif
#if defined(NETWARE_CLIB) && defined(NETWARE_BSDSOCK)
- ret=sendto(b->num, (char *)in, inl, 0, &data->peer.sa, peerlen);
+ ret = sendto(b->num, (char *)in, inl, 0, &data->peer.sa, peerlen);
#else
- ret=sendto(b->num, in, inl, 0, &data->peer.sa, peerlen);
+ ret = sendto(b->num, in, inl, 0, &data->peer.sa, peerlen);
#endif
- }
+ }
BIO_clear_retry_flags(b);
- if (ret <= 0)
- {
- if (BIO_dgram_should_retry(ret))
- {
- BIO_set_retry_write(b);
+ if (ret <= 0) {
+ if (BIO_dgram_should_retry(ret)) {
+ BIO_set_retry_write(b);
+
data->_errno = errno;
#if 0 /* higher layers are responsible for querying MTU, if necessary */
- if ( data->_errno == EMSGSIZE)
+ if (data->_errno == EMSGSIZE)
/* retrieve the new MTU */
- BIO_ctrl(b, BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL);
+ BIO_ctrl(b, BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL);
#endif
- }
}
- return(ret);
}
+ return (ret);
+}
-static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
- long ret=1;
+static long
+dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+ long ret = 1;
int *ip;
struct sockaddr *to = NULL;
bio_dgram_data *data = NULL;
#if OPENSSL_USE_IPV6
struct sockaddr_in6 s6;
#endif
- } addr;
+ } addr;
#endif
data = (bio_dgram_data *)b->ptr;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_RESET:
- num=0;
+ num = 0;
case BIO_C_FILE_SEEK:
- ret=0;
+ ret = 0;
break;
case BIO_C_FILE_TELL:
case BIO_CTRL_INFO:
- ret=0;
+ ret = 0;
break;
case BIO_C_SET_FD:
dgram_clear(b);
b->num= *((int *)ptr);
- b->shutdown=(int)num;
- b->init=1;
+ b->shutdown = (int)num;
+ b->init = 1;
break;
case BIO_C_GET_FD:
- if (b->init)
- {
- ip=(int *)ptr;
- if (ip != NULL) *ip=b->num;
- ret=b->num;
- }
- else
- ret= -1;
+ if (b->init) {
+ ip = (int *)ptr;
+ if (ip != NULL)
+ *ip = b->num;
+ ret = b->num;
+ } else
+ ret = -1;
break;
case BIO_CTRL_GET_CLOSE:
- ret=b->shutdown;
+ ret = b->shutdown;
break;
case BIO_CTRL_SET_CLOSE:
- b->shutdown=(int)num;
+ b->shutdown = (int)num;
break;
case BIO_CTRL_PENDING:
case BIO_CTRL_WPENDING:
- ret=0;
+ ret = 0;
break;
case BIO_CTRL_DUP:
case BIO_CTRL_FLUSH:
- ret=1;
+ ret = 1;
break;
case BIO_CTRL_DGRAM_CONNECT:
to = (struct sockaddr *)ptr;
#if 0
- if (connect(b->num, to, sizeof(struct sockaddr)) < 0)
- { perror("connect"); ret = 0; }
- else
- {
+ if (connect(b->num, to, sizeof(struct sockaddr)) < 0) {
+ perror("connect");
+ ret = 0;
+ } else {
#endif
- switch (to->sa_family)
- {
- case AF_INET:
- memcpy(&data->peer,to,sizeof(data->peer.sa_in));
- break;
+ switch (to->sa_family) {
+ case AF_INET:
+ memcpy(&data->peer, to, sizeof(data->peer.sa_in));
+ break;
#if OPENSSL_USE_IPV6
- case AF_INET6:
- memcpy(&data->peer,to,sizeof(data->peer.sa_in6));
- break;
+ case AF_INET6:
+ memcpy(&data->peer, to, sizeof(data->peer.sa_in6));
+ break;
#endif
- default:
- memcpy(&data->peer,to,sizeof(data->peer.sa));
- break;
- }
-#if 0
+ default:
+ memcpy(&data->peer, to, sizeof(data->peer.sa));
+ break;
}
+#if 0
+ }
#endif
break;
/* (Linux)kernel sets DF bit on outgoing IP packets */
#if defined(OPENSSL_SYS_LINUX) && defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DO)
addr_len = (socklen_t)sizeof(addr);
memset((void *)&addr, 0, sizeof(addr));
- if (getsockname(b->num, &addr.sa, &addr_len) < 0)
- {
+ if (getsockname(b->num, &addr.sa, &addr_len) < 0) {
ret = 0;
break;
- }
- switch (addr.sa.sa_family)
- {
+ }
+ switch (addr.sa.sa_family) {
case AF_INET:
sockopt_val = IP_PMTUDISC_DO;
- if ((ret = setsockopt(b->num, IPPROTO_IP, IP_MTU_DISCOVER,
- &sockopt_val, sizeof(sockopt_val))) < 0)
+ if ((ret = setsockopt(b->num, IPPROTO_IP,
+ IP_MTU_DISCOVER, &sockopt_val,
+ sizeof(sockopt_val))) < 0)
perror("setsockopt");
break;
#if OPENSSL_USE_IPV6 && defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DO)
case AF_INET6:
sockopt_val = IPV6_PMTUDISC_DO;
- if ((ret = setsockopt(b->num, IPPROTO_IPV6, IPV6_MTU_DISCOVER,
- &sockopt_val, sizeof(sockopt_val))) < 0)
+ if ((ret = setsockopt(b->num, IPPROTO_IPV6,
+ IPV6_MTU_DISCOVER, &sockopt_val,
+ sizeof(sockopt_val))) < 0)
perror("setsockopt");
break;
#endif
default:
ret = -1;
break;
- }
+ }
ret = -1;
#else
break;
#if defined(OPENSSL_SYS_LINUX) && defined(IP_MTU)
addr_len = (socklen_t)sizeof(addr);
memset((void *)&addr, 0, sizeof(addr));
- if (getsockname(b->num, &addr.sa, &addr_len) < 0)
- {
+ if (getsockname(b->num, &addr.sa, &addr_len) < 0) {
ret = 0;
break;
- }
+ }
sockopt_len = sizeof(sockopt_val);
- switch (addr.sa.sa_family)
- {
+ switch (addr.sa.sa_family) {
case AF_INET:
- if ((ret = getsockopt(b->num, IPPROTO_IP, IP_MTU, (void *)&sockopt_val,
- &sockopt_len)) < 0 || sockopt_val < 0)
- {
+ if ((ret = getsockopt(b->num, IPPROTO_IP, IP_MTU,
+ (void *)&sockopt_val, &sockopt_len)) < 0 ||
+ sockopt_val < 0) {
ret = 0;
- }
- else
- {
+ } else {
/* we assume that the transport protocol is UDP and no
* IP options are used.
*/
data->mtu = sockopt_val - 8 - 20;
ret = data->mtu;
- }
+ }
break;
#if OPENSSL_USE_IPV6 && defined(IPV6_MTU)
case AF_INET6:
- if ((ret = getsockopt(b->num, IPPROTO_IPV6, IPV6_MTU, (void *)&sockopt_val,
- &sockopt_len)) < 0 || sockopt_val < 0)
- {
+ if ((ret = getsockopt(b->num, IPPROTO_IPV6, IPV6_MTU,
+ (void *)&sockopt_val, &sockopt_len)) < 0 ||
+ sockopt_val < 0) {
ret = 0;
- }
- else
- {
+ } else {
/* we assume that the transport protocol is UDP and no
* IPV6 options are used.
*/
data->mtu = sockopt_val - 8 - 40;
ret = data->mtu;
- }
+ }
break;
#endif
- default:
+default:
ret = 0;
break;
- }
+ }
#else
ret = 0;
#endif
break;
case BIO_CTRL_DGRAM_GET_FALLBACK_MTU:
- switch (data->peer.sa.sa_family)
- {
- case AF_INET:
- ret = 576 - 20 - 8;
- break;
+ switch (data->peer.sa.sa_family) {
+ case AF_INET:
+ ret = 576 - 20 - 8;
+ break;
#if OPENSSL_USE_IPV6
- case AF_INET6:
+ case AF_INET6:
#ifdef IN6_IS_ADDR_V4MAPPED
- if (IN6_IS_ADDR_V4MAPPED(&data->peer.sa_in6.sin6_addr))
- ret = 576 - 20 - 8;
- else
+ if (IN6_IS_ADDR_V4MAPPED(&data->peer.sa_in6.sin6_addr))
+ ret = 576 - 20 - 8;
+ else
#endif
- ret = 1280 - 40 - 8;
- break;
+ ret = 1280 - 40 - 8;
+ break;
#endif
- default:
- ret = 576 - 20 - 8;
- break;
- }
+ default:
+ ret = 576 - 20 - 8;
+ break;
+ }
break;
case BIO_CTRL_DGRAM_GET_MTU:
return data->mtu;
case BIO_CTRL_DGRAM_SET_CONNECTED:
to = (struct sockaddr *)ptr;
- if ( to != NULL)
- {
+ if (to != NULL) {
data->connected = 1;
- switch (to->sa_family)
- {
- case AF_INET:
- memcpy(&data->peer,to,sizeof(data->peer.sa_in));
- break;
-#if OPENSSL_USE_IPV6
- case AF_INET6:
- memcpy(&data->peer,to,sizeof(data->peer.sa_in6));
- break;
-#endif
- default:
- memcpy(&data->peer,to,sizeof(data->peer.sa));
- break;
- }
- }
- else
- {
- data->connected = 0;
- memset(&(data->peer), 0x00, sizeof(data->peer));
- }
- break;
- case BIO_CTRL_DGRAM_GET_PEER:
- switch (data->peer.sa.sa_family)
- {
+ switch (to->sa_family) {
case AF_INET:
- ret=sizeof(data->peer.sa_in);
+ memcpy(&data->peer, to, sizeof(data->peer.sa_in));
break;
#if OPENSSL_USE_IPV6
case AF_INET6:
- ret=sizeof(data->peer.sa_in6);
+ memcpy(&data->peer, to, sizeof(data->peer.sa_in6));
break;
#endif
default:
- ret=sizeof(data->peer.sa);
+ memcpy(&data->peer, to, sizeof(data->peer.sa));
break;
}
- if (num==0 || num>ret)
- num=ret;
- memcpy(ptr,&data->peer,(ret=num));
+ } else {
+ data->connected = 0;
+ memset(&(data->peer), 0x00, sizeof(data->peer));
+ }
+ break;
+ case BIO_CTRL_DGRAM_GET_PEER:
+ switch (data->peer.sa.sa_family) {
+ case AF_INET:
+ ret = sizeof(data->peer.sa_in);
+ break;
+#if OPENSSL_USE_IPV6
+ case AF_INET6:
+ ret = sizeof(data->peer.sa_in6);
+ break;
+#endif
+ default:
+ ret = sizeof(data->peer.sa);
+ break;
+ }
+ if (num == 0 || num > ret)
+ num = ret;
+ memcpy(ptr, &data->peer, (ret = num));
break;
case BIO_CTRL_DGRAM_SET_PEER:
to = (struct sockaddr *) ptr;
- switch (to->sa_family)
- {
- case AF_INET:
- memcpy(&data->peer,to,sizeof(data->peer.sa_in));
- break;
+ switch (to->sa_family) {
+ case AF_INET:
+ memcpy(&data->peer, to, sizeof(data->peer.sa_in));
+ break;
#if OPENSSL_USE_IPV6
- case AF_INET6:
- memcpy(&data->peer,to,sizeof(data->peer.sa_in6));
- break;
+ case AF_INET6:
+ memcpy(&data->peer, to, sizeof(data->peer.sa_in6));
+ break;
#endif
- default:
- memcpy(&data->peer,to,sizeof(data->peer.sa));
- break;
- }
+ default:
+ memcpy(&data->peer, to, sizeof(data->peer.sa));
+ break;
+ }
break;
case BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT:
memcpy(&(data->next_timeout), ptr, sizeof(struct timeval));
case BIO_CTRL_DGRAM_SET_RECV_TIMEOUT:
#ifdef OPENSSL_SYS_WINDOWS
{
- struct timeval *tv = (struct timeval *)ptr;
- int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000;
- if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, sizeof(timeout)) < 0)
- { perror("setsockopt"); ret = -1; }
+ struct timeval *tv = (struct timeval *)ptr;
+ int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000;
+ if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
+ (void*)&timeout, sizeof(timeout)) < 0) {
+ perror("setsockopt");
+ ret = -1;
+ }
}
#else
- if ( setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, ptr,
- sizeof(struct timeval)) < 0)
- { perror("setsockopt"); ret = -1; }
+ if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, ptr,
+ sizeof(struct timeval)) < 0) {
+ perror("setsockopt");
+ ret = -1;
+ }
#endif
break;
case BIO_CTRL_DGRAM_GET_RECV_TIMEOUT:
{
- union { size_t s; int i; } sz = {0};
+ union {
+ size_t s;
+ int i;
+ } sz = {0};
#ifdef OPENSSL_SYS_WINDOWS
- int timeout;
- struct timeval *tv = (struct timeval *)ptr;
-
- sz.i = sizeof(timeout);
- if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, &sz.i) < 0)
- { perror("getsockopt"); ret = -1; }
- else
- {
- tv->tv_sec = timeout / 1000;
- tv->tv_usec = (timeout % 1000) * 1000;
- ret = sizeof(*tv);
+ int timeout;
+ struct timeval *tv = (struct timeval *)ptr;
+
+ sz.i = sizeof(timeout);
+ if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
+ (void*)&timeout, &sz.i) < 0) {
+ perror("getsockopt");
+ ret = -1;
+ } else {
+ tv->tv_sec = timeout / 1000;
+ tv->tv_usec = (timeout % 1000) * 1000;
+ ret = sizeof(*tv);
}
#else
- sz.i = sizeof(struct timeval);
- if ( getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- ptr, (void *)&sz) < 0)
- { perror("getsockopt"); ret = -1; }
- else if (sizeof(sz.s)!=sizeof(sz.i) && sz.i==0)
- {
- OPENSSL_assert(sz.s<=sizeof(struct timeval));
- ret = (int)sz.s;
- }
- else
- ret = sz.i;
+ sz.i = sizeof(struct timeval);
+ if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
+ ptr, (void *)&sz) < 0) {
+ perror("getsockopt");
+ ret = -1;
+ } else if (sizeof(sz.s)!=sizeof(sz.i) && sz.i==0) {
+ OPENSSL_assert(sz.s <= sizeof(struct timeval));
+ ret = (int)sz.s;
+ } else
+ ret = sz.i;
#endif
}
break;
case BIO_CTRL_DGRAM_SET_SEND_TIMEOUT:
#ifdef OPENSSL_SYS_WINDOWS
{
- struct timeval *tv = (struct timeval *)ptr;
- int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000;
- if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
- (void*)&timeout, sizeof(timeout)) < 0)
- { perror("setsockopt"); ret = -1; }
+ struct timeval *tv = (struct timeval *)ptr;
+ int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000;
+ if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
+ (void*)&timeout, sizeof(timeout)) < 0) {
+ perror("setsockopt");
+ ret = -1;
+ }
}
#else
- if ( setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, ptr,
- sizeof(struct timeval)) < 0)
- { perror("setsockopt"); ret = -1; }
+ if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, ptr,
+ sizeof(struct timeval)) < 0) {
+ perror("setsockopt");
+ ret = -1;
+ }
#endif
break;
case BIO_CTRL_DGRAM_GET_SEND_TIMEOUT:
{
- union { size_t s; int i; } sz = {0};
+ union {
+ size_t s;
+ int i;
+ } sz = {0};
#ifdef OPENSSL_SYS_WINDOWS
- int timeout;
- struct timeval *tv = (struct timeval *)ptr;
-
- sz.i = sizeof(timeout);
- if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
- (void*)&timeout, &sz.i) < 0)
- { perror("getsockopt"); ret = -1; }
- else
- {
- tv->tv_sec = timeout / 1000;
- tv->tv_usec = (timeout % 1000) * 1000;
- ret = sizeof(*tv);
+ int timeout;
+ struct timeval *tv = (struct timeval *)ptr;
+
+ sz.i = sizeof(timeout);
+ if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
+ (void*)&timeout, &sz.i) < 0) {
+ perror("getsockopt");
+ ret = -1;
+ } else {
+ tv->tv_sec = timeout / 1000;
+ tv->tv_usec = (timeout % 1000) * 1000;
+ ret = sizeof(*tv);
}
#else
- sz.i = sizeof(struct timeval);
- if ( getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
- ptr, (void *)&sz) < 0)
- { perror("getsockopt"); ret = -1; }
- else if (sizeof(sz.s)!=sizeof(sz.i) && sz.i==0)
- {
- OPENSSL_assert(sz.s<=sizeof(struct timeval));
- ret = (int)sz.s;
- }
- else
- ret = sz.i;
+ sz.i = sizeof(struct timeval);
+ if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
+ ptr, (void *)&sz) < 0) {
+ perror("getsockopt");
+ ret = -1;
+ } else if (sizeof(sz.s) != sizeof(sz.i) && sz.i == 0) {
+ OPENSSL_assert(sz.s <= sizeof(struct timeval));
+ ret = (int)sz.s;
+ } else
+ ret = sz.i;
#endif
}
break;
/* fall-through */
case BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP:
#ifdef OPENSSL_SYS_WINDOWS
- if ( data->_errno == WSAETIMEDOUT)
+ if (data->_errno == WSAETIMEDOUT)
#else
- if ( data->_errno == EAGAIN)
+ if (data->_errno == EAGAIN)
#endif
- {
+ {
ret = 1;
data->_errno = 0;
- }
- else
+ } else
ret = 0;
break;
#ifdef EMSGSIZE
case BIO_CTRL_DGRAM_MTU_EXCEEDED:
- if ( data->_errno == EMSGSIZE)
- {
+ if (data->_errno == EMSGSIZE) {
ret = 1;
data->_errno = 0;
- }
- else
+ } else
ret = 0;
break;
#endif
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
}
+ return (ret);
+}
-static int dgram_puts(BIO *bp, const char *str)
- {
- int n,ret;
+static int
+dgram_puts(BIO *bp, const char *str)
+{
+ int n, ret;
- n=strlen(str);
- ret=dgram_write(bp,str,n);
- return(ret);
- }
+ n = strlen(str);
+ ret = dgram_write(bp, str, n);
+ return (ret);
+}
#ifndef OPENSSL_NO_SCTP
-BIO_METHOD *BIO_s_datagram_sctp(void)
- {
- return(&methods_dgramp_sctp);
- }
+BIO_METHOD
+*BIO_s_datagram_sctp(void)
+{
+ return (&methods_dgramp_sctp);
+}
-BIO *BIO_new_dgram_sctp(int fd, int close_flag)
- {
+BIO
+*BIO_new_dgram_sctp(int fd, int close_flag)
+{
BIO *bio;
int ret, optval = 20000;
int auth_data = 0, auth_forward = 0;
#endif
#endif
- bio=BIO_new(BIO_s_datagram_sctp());
- if (bio == NULL) return(NULL);
- BIO_set_fd(bio,fd,close_flag);
+ bio = BIO_new(BIO_s_datagram_sctp());
+ if (bio == NULL)
+ return (NULL);
+ BIO_set_fd(bio, fd, close_flag);
/* Activate SCTP-AUTH for DATA and FORWARD-TSN chunks */
auth.sauth_chunk = OPENSSL_SCTP_DATA_CHUNK_TYPE;
OPENSSL_assert(ret >= 0);
for (p = (unsigned char*) authchunks->gauth_chunks;
- p < (unsigned char*) authchunks + sockopt_len;
- p += sizeof(uint8_t))
- {
- if (*p == OPENSSL_SCTP_DATA_CHUNK_TYPE) auth_data = 1;
- if (*p == OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE) auth_forward = 1;
- }
-
+ p < (unsigned char*) authchunks + sockopt_len;
+ p += sizeof(uint8_t)) {
+ if (*p == OPENSSL_SCTP_DATA_CHUNK_TYPE)
+ auth_data = 1;
+ if (*p == OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE)
+ auth_forward = 1;
+ }
+
OPENSSL_free(authchunks);
OPENSSL_assert(auth_data);
ret = setsockopt(fd, IPPROTO_SCTP, SCTP_PARTIAL_DELIVERY_POINT, &optval, sizeof(optval));
OPENSSL_assert(ret >= 0);
- return(bio);
- }
+ return (bio);
+}
-int BIO_dgram_is_sctp(BIO *bio)
- {
+int
+BIO_dgram_is_sctp(BIO *bio)
+{
return (BIO_method_type(bio) == BIO_TYPE_DGRAM_SCTP);
- }
+}
-static int dgram_sctp_new(BIO *bi)
- {
+static int
+dgram_sctp_new(BIO *bi)
+{
bio_dgram_sctp_data *data = NULL;
- bi->init=0;
- bi->num=0;
+ bi->init = 0;
+ bi->num = 0;
data = OPENSSL_malloc(sizeof(bio_dgram_sctp_data));
if (data == NULL)
return 0;
#ifdef SCTP_PR_SCTP_NONE
data->prinfo.pr_policy = SCTP_PR_SCTP_NONE;
#endif
- bi->ptr = data;
+ bi->ptr = data;
- bi->flags=0;
- return(1);
- }
+ bi->flags = 0;
+ return (1);
+}
-static int dgram_sctp_free(BIO *a)
- {
+static int
+dgram_sctp_free(BIO *a)
+{
bio_dgram_sctp_data *data;
- if (a == NULL) return(0);
- if ( ! dgram_clear(a))
+ if (a == NULL)
+ return (0);
+ if (! dgram_clear(a))
return 0;
data = (bio_dgram_sctp_data *)a->ptr;
- if(data != NULL) OPENSSL_free(data);
+ if (data != NULL)
+ OPENSSL_free(data);
- return(1);
- }
+ return (1);
+}
#ifdef SCTP_AUTHENTICATION_EVENT
-void dgram_sctp_handle_auth_free_key_event(BIO *b, union sctp_notification *snp)
- {
+void
+dgram_sctp_handle_auth_free_key_event(BIO *b, union sctp_notification *snp)
+{
int ret;
struct sctp_authkey_event* authkeyevent = &snp->sn_auth_event;
- if (authkeyevent->auth_indication == SCTP_AUTH_FREE_KEY)
- {
+ if (authkeyevent->auth_indication == SCTP_AUTH_FREE_KEY) {
struct sctp_authkeyid authkeyid;
/* delete key */
authkeyid.scact_keynumber = authkeyevent->auth_keynumber;
ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DELETE_KEY,
- &authkeyid, sizeof(struct sctp_authkeyid));
- }
+ &authkeyid, sizeof(struct sctp_authkeyid));
}
+}
#endif
-static int dgram_sctp_read(BIO *b, char *out, int outl)
- {
+static int
+dgram_sctp_read(BIO *b, char *out, int outl)
+{
int ret = 0, n = 0, i, optval;
socklen_t optlen;
bio_dgram_sctp_data *data = (bio_dgram_sctp_data *)b->ptr;
struct cmsghdr *cmsg;
char cmsgbuf[512];
- if (out != NULL)
- {
+ if (out != NULL) {
errno = 0;
- do
- {
+ do {
memset(&data->rcvinfo, 0x00, sizeof(struct bio_dgram_sctp_rcvinfo));
iov.iov_base = out;
iov.iov_len = outl;
msg.msg_flags = 0;
n = recvmsg(b->num, &msg, 0);
- if (msg.msg_controllen > 0)
- {
- for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg))
- {
+ if (msg.msg_controllen > 0) {
+ for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
if (cmsg->cmsg_level != IPPROTO_SCTP)
continue;
#ifdef SCTP_RCVINFO
- if (cmsg->cmsg_type == SCTP_RCVINFO)
- {
+ if (cmsg->cmsg_type == SCTP_RCVINFO) {
struct sctp_rcvinfo *rcvinfo;
rcvinfo = (struct sctp_rcvinfo *)CMSG_DATA(cmsg);
data->rcvinfo.rcv_tsn = rcvinfo->rcv_tsn;
data->rcvinfo.rcv_cumtsn = rcvinfo->rcv_cumtsn;
data->rcvinfo.rcv_context = rcvinfo->rcv_context;
- }
+ }
#endif
#ifdef SCTP_SNDRCV
- if (cmsg->cmsg_type == SCTP_SNDRCV)
- {
+ if (cmsg->cmsg_type == SCTP_SNDRCV) {
struct sctp_sndrcvinfo *sndrcvinfo;
sndrcvinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg);
data->rcvinfo.rcv_tsn = sndrcvinfo->sinfo_tsn;
data->rcvinfo.rcv_cumtsn = sndrcvinfo->sinfo_cumtsn;
data->rcvinfo.rcv_context = sndrcvinfo->sinfo_context;
- }
-#endif
}
+#endif
}
+ }
- if (n <= 0)
- {
+ if (n <= 0) {
if (n < 0)
ret = n;
break;
- }
+ }
- if (msg.msg_flags & MSG_NOTIFICATION)
- {
+ if (msg.msg_flags & MSG_NOTIFICATION) {
snp = (union sctp_notification*) out;
- if (snp->sn_header.sn_type == SCTP_SENDER_DRY_EVENT)
- {
+ if (snp->sn_header.sn_type == SCTP_SENDER_DRY_EVENT) {
#ifdef SCTP_EVENT
struct sctp_event event;
#else
/* If a message has been delayed until the socket
* is dry, it can be sent now.
*/
- if (data->saved_message.length > 0)
- {
+ if (data->saved_message.length > 0) {
dgram_sctp_write(data->saved_message.bio, data->saved_message.data,
- data->saved_message.length);
+ data->saved_message.length);
OPENSSL_free(data->saved_message.data);
data->saved_message.length = 0;
- }
+ }
/* disable sender dry event */
#ifdef SCTP_EVENT
i = setsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(struct sctp_event_subscribe));
OPENSSL_assert(i >= 0);
#endif
- }
+ }
#ifdef SCTP_AUTHENTICATION_EVENT
if (snp->sn_header.sn_type == SCTP_AUTHENTICATION_EVENT)
data->handle_notifications(b, data->notification_context, (void*) out);
memset(out, 0, outl);
- }
- else
+ } else
ret += n;
- }
+ }
while ((msg.msg_flags & MSG_NOTIFICATION) && (msg.msg_flags & MSG_EOR) && (ret < outl));
- if (ret > 0 && !(msg.msg_flags & MSG_EOR))
- {
+ if (ret > 0 && !(msg.msg_flags & MSG_EOR)) {
/* Partial message read, this should never happen! */
/* The buffer was too small, this means the peer sent
* max record size (2^14 + 2048 + 13)
*/
optlen = (socklen_t) sizeof(int);
- ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_PARTIAL_DELIVERY_POINT,
- &optval, &optlen);
+ ret = getsockopt(b->num, IPPROTO_SCTP,
+ SCTP_PARTIAL_DELIVERY_POINT, &optval, &optlen);
OPENSSL_assert(ret >= 0);
OPENSSL_assert(optval >= 18445);
memset(out, 0, outl);
BIO_set_retry_read(b);
return -1;
- }
+ }
BIO_clear_retry_flags(b);
- if (ret < 0)
- {
- if (BIO_dgram_should_retry(ret))
- {
+ if (ret < 0) {
+ if (BIO_dgram_should_retry(ret)) {
BIO_set_retry_read(b);
data->_errno = errno;
- }
}
+ }
/* Test if peer uses SCTP-AUTH before continuing */
- if (!data->peer_auth_tested)
- {
+ if (!data->peer_auth_tested) {
int ii, auth_data = 0, auth_forward = 0;
unsigned char *p;
struct sctp_authchunks *authchunks;
OPENSSL_assert(ii >= 0);
for (p = (unsigned char*) authchunks->gauth_chunks;
- p < (unsigned char*) authchunks + optlen;
- p += sizeof(uint8_t))
- {
- if (*p == OPENSSL_SCTP_DATA_CHUNK_TYPE) auth_data = 1;
- if (*p == OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE) auth_forward = 1;
- }
+ p < (unsigned char*) authchunks + optlen;
+ p += sizeof(uint8_t)) {
+ if (*p == OPENSSL_SCTP_DATA_CHUNK_TYPE)
+ auth_data = 1;
+ if (*p == OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE)
+ auth_forward = 1;
+ }
OPENSSL_free(authchunks);
- if (!auth_data || !auth_forward)
- {
- BIOerr(BIO_F_DGRAM_SCTP_READ,BIO_R_CONNECT_ERROR);
+ if (!auth_data || !auth_forward) {
+ BIOerr(BIO_F_DGRAM_SCTP_READ, BIO_R_CONNECT_ERROR);
return -1;
- }
+ }
data->peer_auth_tested = 1;
- }
}
- return(ret);
}
+ return (ret);
+}
-static int dgram_sctp_write(BIO *b, const char *in, int inl)
- {
+static int
+dgram_sctp_write(BIO *b, const char *in, int inl)
+{
int ret;
bio_dgram_sctp_data *data = (bio_dgram_sctp_data *)b->ptr;
struct bio_dgram_sctp_sndinfo *sinfo = &(data->sndinfo);
* socket is not dry yet, we have to save it and send it
* as soon as the socket gets dry.
*/
- if (data->save_shutdown && !BIO_dgram_sctp_wait_for_dry(b))
- {
+ if (data->save_shutdown && !BIO_dgram_sctp_wait_for_dry(b)) {
data->saved_message.bio = b;
data->saved_message.length = inl;
data->saved_message.data = OPENSSL_malloc(inl);
ret = sendmsg(b->num, &msg, 0);
BIO_clear_retry_flags(b);
- if (ret <= 0)
- {
- if (BIO_dgram_should_retry(ret))
- {
- BIO_set_retry_write(b);
+ if (ret <= 0) {
+ if (BIO_dgram_should_retry(ret)) {
+ BIO_set_retry_write(b);
+
data->_errno = errno;
- }
}
- return(ret);
}
+ return (ret);
+}
-static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
- long ret=1;
+static long
+dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+ long ret = 1;
bio_dgram_sctp_data *data = NULL;
socklen_t sockopt_len = 0;
struct sctp_authkeyid authkeyid;
data = (bio_dgram_sctp_data *)b->ptr;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_DGRAM_QUERY_MTU:
/* Set to maximum (2^14)
* and ignore user input to enable transport
/* Get active key */
sockopt_len = sizeof(struct sctp_authkeyid);
ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len);
- if (ret < 0) break;
+ if (ret < 0)
+ break;
/* Add new key */
sockopt_len = sizeof(struct sctp_authkey) + 64 * sizeof(uint8_t);
memcpy(&authkey->sca_key[0], ptr, 64 * sizeof(uint8_t));
ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_KEY, authkey, sockopt_len);
- if (ret < 0) break;
+ if (ret < 0)
+ break;
/* Reset active key */
ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY,
- &authkeyid, sizeof(struct sctp_authkeyid));
- if (ret < 0) break;
+ &authkeyid, sizeof(struct sctp_authkeyid));
+ if (ret < 0)
+ break;
break;
case BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY:
/* Get active key */
sockopt_len = sizeof(struct sctp_authkeyid);
ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len);
- if (ret < 0) break;
+ if (ret < 0)
+ break;
/* Set active key */
authkeyid.scact_keynumber = authkeyid.scact_keynumber + 1;
ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY,
- &authkeyid, sizeof(struct sctp_authkeyid));
- if (ret < 0) break;
+ &authkeyid, sizeof(struct sctp_authkeyid));
+ if (ret < 0)
+ break;
/* CCS has been sent, so remember that and fall through
* to check if we need to deactivate an old key
data->ccs_rcvd = 1;
/* CSS has been both, received and sent, so deactivate an old key */
- if (data->ccs_rcvd == 1 && data->ccs_sent == 1)
- {
+ if (data->ccs_rcvd == 1 && data->ccs_sent == 1) {
/* Get active key */
sockopt_len = sizeof(struct sctp_authkeyid);
ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len);
- if (ret < 0) break;
+ if (ret < 0)
+ break;
/* Deactivate key or delete second last key if
* SCTP_AUTHENTICATION_EVENT is not available.
#ifdef SCTP_AUTH_DEACTIVATE_KEY
sockopt_len = sizeof(struct sctp_authkeyid);
ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DEACTIVATE_KEY,
- &authkeyid, sockopt_len);
- if (ret < 0) break;
+ &authkeyid, sockopt_len);
+ if (ret < 0)
+ break;
#endif
#ifndef SCTP_AUTHENTICATION_EVENT
- if (authkeyid.scact_keynumber > 0)
- {
+ if (authkeyid.scact_keynumber > 0) {
authkeyid.scact_keynumber = authkeyid.scact_keynumber - 1;
ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DELETE_KEY,
- &authkeyid, sizeof(struct sctp_authkeyid));
- if (ret < 0) break;
- }
+ &authkeyid, sizeof(struct sctp_authkeyid));
+ if (ret < 0)
+ break;
+ }
#endif
data->ccs_rcvd = 0;
data->ccs_sent = 0;
- }
+ }
break;
case BIO_CTRL_DGRAM_SCTP_GET_SNDINFO:
/* Returns the size of the copied struct. */
/* Pass to default ctrl function to
* process SCTP unspecific commands
*/
- ret=dgram_ctrl(b, cmd, num, ptr);
+ ret = dgram_ctrl(b, cmd, num, ptr);
break;
- }
- return(ret);
}
+ return (ret);
+}
-int BIO_dgram_sctp_notification_cb(BIO *b,
- void (*handle_notifications)(BIO *bio, void *context, void *buf),
- void *context)
- {
+int
+BIO_dgram_sctp_notification_cb(BIO *b,
+ void (*handle_notifications)(BIO *bio, void *context, void *buf),
+ void *context)
+{
bio_dgram_sctp_data *data = (bio_dgram_sctp_data *) b->ptr;
- if (handle_notifications != NULL)
- {
+ if (handle_notifications != NULL) {
data->handle_notifications = handle_notifications;
data->notification_context = context;
- }
- else
+ } else
return -1;
return 0;
- }
+}
-int BIO_dgram_sctp_wait_for_dry(BIO *b)
+int
+BIO_dgram_sctp_wait_for_dry(BIO *b)
{
int is_dry = 0;
int n, sockflags, ret;
ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, &eventsize);
if (ret < 0)
return -1;
-
+
event.sctp_sender_dry_event = 1;
-
+
ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(struct sctp_event_subscribe));
#endif
if (ret < 0)
msg.msg_flags = 0;
n = recvmsg(b->num, &msg, MSG_PEEK);
- if (n <= 0)
- {
+ if (n <= 0) {
if ((n < 0) && (errno != EAGAIN) && (errno != EWOULDBLOCK))
return -1;
else
return 0;
- }
+ }
/* if we find a notification, process it and try again if necessary */
- while (msg.msg_flags & MSG_NOTIFICATION)
- {
+ while (msg.msg_flags & MSG_NOTIFICATION) {
memset(&snp, 0x00, sizeof(union sctp_notification));
iov.iov_base = (char *)&snp;
iov.iov_len = sizeof(union sctp_notification);
msg.msg_flags = 0;
n = recvmsg(b->num, &msg, 0);
- if (n <= 0)
- {
+ if (n <= 0) {
if ((n < 0) && (errno != EAGAIN) && (errno != EWOULDBLOCK))
return -1;
else
return is_dry;
- }
-
- if (snp.sn_header.sn_type == SCTP_SENDER_DRY_EVENT)
- {
+ }
+
+ if (snp.sn_header.sn_type == SCTP_SENDER_DRY_EVENT) {
is_dry = 1;
/* disable sender dry event */
#endif
if (ret < 0)
return -1;
- }
+ }
#ifdef SCTP_AUTHENTICATION_EVENT
if (snp.sn_header.sn_type == SCTP_AUTHENTICATION_EVENT)
msg.msg_flags = 0;
/* if we have seen the dry already, don't wait */
- if (is_dry)
- {
+ if (is_dry) {
sockflags = fcntl(b->num, F_GETFL, 0);
fcntl(b->num, F_SETFL, O_NONBLOCK);
- }
+ }
n = recvmsg(b->num, &msg, MSG_PEEK);
- if (is_dry)
- {
+ if (is_dry) {
fcntl(b->num, F_SETFL, sockflags);
- }
+ }
- if (n <= 0)
- {
+ if (n <= 0) {
if ((n < 0) && (errno != EAGAIN) && (errno != EWOULDBLOCK))
return -1;
else
return is_dry;
- }
}
+ }
/* read anything else */
return is_dry;
}
-int BIO_dgram_sctp_msg_waiting(BIO *b)
- {
+int
+BIO_dgram_sctp_msg_waiting(BIO *b)
+{
int n, sockflags;
union sctp_notification snp;
struct msghdr msg;
/* Check if there are any messages waiting to be read */
do
- {
+ {
memset(&snp, 0x00, sizeof(union sctp_notification));
iov.iov_base = (char *)&snp;
iov.iov_len = sizeof(union sctp_notification);
fcntl(b->num, F_SETFL, sockflags);
/* if notification, process and try again */
- if (n > 0 && (msg.msg_flags & MSG_NOTIFICATION))
- {
+ if (n > 0 && (msg.msg_flags & MSG_NOTIFICATION)) {
#ifdef SCTP_AUTHENTICATION_EVENT
if (snp.sn_header.sn_type == SCTP_AUTHENTICATION_EVENT)
dgram_sctp_handle_auth_free_key_event(b, &snp);
if (data->handle_notifications != NULL)
data->handle_notifications(b, data->notification_context, (void*) &snp);
- }
+ }
- } while (n > 0 && (msg.msg_flags & MSG_NOTIFICATION));
+ } while (n > 0 && (msg.msg_flags & MSG_NOTIFICATION));
/* Return 1 if there is a message to be read, return 0 otherwise. */
if (n > 0)
return 1;
else
return 0;
- }
+}
-static int dgram_sctp_puts(BIO *bp, const char *str)
- {
- int n,ret;
+static int
+dgram_sctp_puts(BIO *bp, const char *str)
+{
+ int n, ret;
- n=strlen(str);
- ret=dgram_sctp_write(bp,str,n);
- return(ret);
- }
+ n = strlen(str);
+ ret = dgram_sctp_write(bp, str, n);
+ return (ret);
+}
#endif
-static int BIO_dgram_should_retry(int i)
- {
+static int
+BIO_dgram_should_retry(int i)
+{
int err;
- if ((i == 0) || (i == -1))
- {
- err=errno;
+ if ((i == 0) || (i == -1)) {
+ err = errno;
#if defined(OPENSSL_SYS_WINDOWS)
/* If the socket return value (i) is -1
*/
#endif
- return(BIO_dgram_non_fatal_error(err));
- }
- return(0);
+ return (BIO_dgram_non_fatal_error(err));
}
+ return (0);
+}
-int BIO_dgram_non_fatal_error(int err)
- {
- switch (err)
- {
+int
+BIO_dgram_non_fatal_error(int err)
+{
+ switch (err) {
#if defined(OPENSSL_SYS_WINDOWS)
# if defined(WSAEWOULDBLOCK)
case WSAEWOULDBLOCK:
case EALREADY:
#endif
- return(1);
+ return (1);
/* break; */
default:
break;
- }
- return(0);
}
+ return (0);
+}
-static void get_current_time(struct timeval *t)
- {
+static void
+get_current_time(struct timeval *t) {
gettimeofday(t, NULL);
- }
+}
#endif
static int fd_free(BIO *data);
int BIO_fd_should_retry(int s);
-static BIO_METHOD methods_fdp=
- {
- BIO_TYPE_FD,"file descriptor",
+static BIO_METHOD methods_fdp = {
+ BIO_TYPE_FD, "file descriptor",
fd_write,
fd_read,
fd_puts,
fd_new,
fd_free,
NULL,
- };
+};
-BIO_METHOD *BIO_s_fd(void)
- {
- return(&methods_fdp);
- }
+BIO_METHOD
+*BIO_s_fd(void)
+{
+ return (&methods_fdp);
+}
-BIO *BIO_new_fd(int fd,int close_flag)
- {
+BIO
+*BIO_new_fd(int fd, int close_flag)
+{
BIO *ret;
- ret=BIO_new(BIO_s_fd());
- if (ret == NULL) return(NULL);
- BIO_set_fd(ret,fd,close_flag);
- return(ret);
- }
+ ret = BIO_new(BIO_s_fd());
+ if (ret == NULL)
+ return (NULL);
+ BIO_set_fd(ret, fd, close_flag);
+ return (ret);
+}
-static int fd_new(BIO *bi)
- {
- bi->init=0;
- bi->num=-1;
- bi->ptr=NULL;
+static int
+fd_new(BIO *bi)
+{
+ bi->init = 0;
+ bi->num = -1;
+ bi->ptr = NULL;
bi->flags=BIO_FLAGS_UPLINK; /* essentially redundant */
- return(1);
- }
+ return (1);
+}
-static int fd_free(BIO *a)
- {
- if (a == NULL) return(0);
- if (a->shutdown)
- {
- if (a->init)
- {
+static int
+fd_free(BIO *a)
+{
+ if (a == NULL)
+ return (0);
+ if (a->shutdown) {
+ if (a->init) {
UP_close(a->num);
- }
- a->init=0;
- a->flags=BIO_FLAGS_UPLINK;
}
- return(1);
+ a->init = 0;
+ a->flags = BIO_FLAGS_UPLINK;
}
-
-static int fd_read(BIO *b, char *out,int outl)
- {
- int ret=0;
+ return (1);
+}
- if (out != NULL)
- {
+static int
+fd_read(BIO *b, char *out, int outl)
+{
+ int ret = 0;
+
+ if (out != NULL) {
errno = 0;
- ret=UP_read(b->num,out,outl);
+ ret = UP_read(b->num, out, outl);
BIO_clear_retry_flags(b);
- if (ret <= 0)
- {
+ if (ret <= 0) {
if (BIO_fd_should_retry(ret))
BIO_set_retry_read(b);
- }
}
- return(ret);
}
+ return (ret);
+}
-static int fd_write(BIO *b, const char *in, int inl)
- {
+static int
+fd_write(BIO *b, const char *in, int inl)
+{
int ret;
errno = 0;
- ret=UP_write(b->num,in,inl);
+ ret = UP_write(b->num, in, inl);
BIO_clear_retry_flags(b);
- if (ret <= 0)
- {
+ if (ret <= 0) {
if (BIO_fd_should_retry(ret))
BIO_set_retry_write(b);
- }
- return(ret);
}
+ return (ret);
+}
-static long fd_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
- long ret=1;
+static long
+fd_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+ long ret = 1;
int *ip;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_RESET:
- num=0;
+ num = 0;
case BIO_C_FILE_SEEK:
- ret=(long)UP_lseek(b->num,num,0);
+ ret = (long)UP_lseek(b->num, num, 0);
break;
case BIO_C_FILE_TELL:
case BIO_CTRL_INFO:
- ret=(long)UP_lseek(b->num,0,1);
+ ret = (long)UP_lseek(b->num, 0, 1);
break;
case BIO_C_SET_FD:
fd_free(b);
b->num= *((int *)ptr);
- b->shutdown=(int)num;
- b->init=1;
+ b->shutdown = (int)num;
+ b->init = 1;
break;
case BIO_C_GET_FD:
- if (b->init)
- {
- ip=(int *)ptr;
- if (ip != NULL) *ip=b->num;
- ret=b->num;
- }
- else
- ret= -1;
+ if (b->init) {
+ ip = (int *)ptr;
+ if (ip != NULL)
+ *ip = b->num;
+ ret = b->num;
+ } else
+ ret = -1;
break;
case BIO_CTRL_GET_CLOSE:
- ret=b->shutdown;
+ ret = b->shutdown;
break;
case BIO_CTRL_SET_CLOSE:
- b->shutdown=(int)num;
+ b->shutdown = (int)num;
break;
case BIO_CTRL_PENDING:
case BIO_CTRL_WPENDING:
- ret=0;
+ ret = 0;
break;
case BIO_CTRL_DUP:
case BIO_CTRL_FLUSH:
- ret=1;
+ ret = 1;
break;
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
}
+ return (ret);
+}
-static int fd_puts(BIO *bp, const char *str)
- {
- int n,ret;
+static int
+fd_puts(BIO *bp, const char *str)
+{
+ int n, ret;
- n=strlen(str);
- ret=fd_write(bp,str,n);
- return(ret);
- }
+ n = strlen(str);
+ ret = fd_write(bp, str, n);
+ return (ret);
+}
-static int fd_gets(BIO *bp, char *buf, int size)
- {
- int ret=0;
- char *ptr=buf;
- char *end=buf+size-1;
+static int
+fd_gets(BIO *bp, char *buf, int size)
+{
+ int ret = 0;
+ char *ptr = buf;
+ char *end = buf + size - 1;
- while ( (ptr < end) && (fd_read(bp, ptr, 1) > 0) && (ptr[0] != '\n') )
+ while ((ptr < end) && (fd_read(bp, ptr, 1) > 0) && (ptr[0] != '\n'))
ptr++;
- ptr[0]='\0';
+ ptr[0] = '\0';
if (buf[0] != '\0')
- ret=strlen(buf);
- return(ret);
- }
+ ret = strlen(buf);
+ return (ret);
+}
-int BIO_fd_should_retry(int i)
- {
+int
+BIO_fd_should_retry(int i)
+{
int err;
- if ((i == 0) || (i == -1))
- {
- err=errno;
+ if ((i == 0) || (i == -1)) {
+ err = errno;
#if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
if ((i == -1) && (err == 0))
- return(1);
+ return (1);
#endif
- return(BIO_fd_non_fatal_error(err));
- }
- return(0);
+ return (BIO_fd_non_fatal_error(err));
}
+ return (0);
+}
-int BIO_fd_non_fatal_error(int err)
- {
- switch (err)
- {
+int
+BIO_fd_non_fatal_error(int err)
+{
+ switch (err) {
#ifdef EWOULDBLOCK
# ifdef WSAEWOULDBLOCK
#ifdef EALREADY
case EALREADY:
#endif
- return(1);
+ return (1);
/* break; */
default:
break;
- }
- return(0);
}
+ return (0);
+}
#endif
static long file_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int file_new(BIO *h);
static int file_free(BIO *data);
-static BIO_METHOD methods_filep=
- {
+
+static BIO_METHOD methods_filep = {
BIO_TYPE_FILE,
"FILE pointer",
file_write,
file_new,
file_free,
NULL,
- };
+};
-BIO *BIO_new_file(const char *filename, const char *mode)
- {
+BIO
+*BIO_new_file(const char *filename, const char *mode)
+{
BIO *ret;
- FILE *file=NULL;
+ FILE *file = NULL;
#if defined(_WIN32) && defined(CP_UTF8)
- int sz, len_0 = (int)strlen(filename)+1;
+ int sz, len_0 = (int)strlen(filename) + 1;
DWORD flags;
/*
* ERROR_NO_UNICODE_TRANSLATION, in which case we fall
* back to fopen...
*/
- if ((sz=MultiByteToWideChar(CP_UTF8,(flags=MB_ERR_INVALID_CHARS),
- filename,len_0,NULL,0))>0 ||
- (GetLastError()==ERROR_INVALID_FLAGS &&
- (sz=MultiByteToWideChar(CP_UTF8,(flags=0),
- filename,len_0,NULL,0))>0)
- )
- {
+ if ((sz = MultiByteToWideChar(CP_UTF8,(flags = MB_ERR_INVALID_CHARS),
+ filename, len_0, NULL, 0)) > 0 ||
+ (GetLastError() == ERROR_INVALID_FLAGS &&
+ (sz = MultiByteToWideChar(CP_UTF8,(flags = 0),
+ filename, len_0, NULL, 0)) > 0)) {
WCHAR wmode[8];
WCHAR *wfilename = _alloca(sz*sizeof(WCHAR));
- if (MultiByteToWideChar(CP_UTF8,flags,
- filename,len_0,wfilename,sz) &&
- MultiByteToWideChar(CP_UTF8,0,mode,strlen(mode)+1,
- wmode,sizeof(wmode)/sizeof(wmode[0])) &&
- (file=_wfopen(wfilename,wmode))==NULL &&
- (errno==ENOENT || errno==EBADF)
- ) /* UTF-8 decode succeeded, but no file, filename
+ if (MultiByteToWideChar(CP_UTF8, flags, filename, len_0,
+ wfilename, sz) && MultiByteToWideChar(CP_UTF8, 0, mode,
+ strlen(mode) + 1, wmode,
+ sizeof(wmode) / sizeof(wmode[0])) &&
+ (file = _wfopen(wfilename, wmode)) == NULL &&
+ (errno == ENOENT || errno == EBADF)
+ ) /* UTF - 8 decode succeeded, but no file, filename
* could still have been locale-ized... */
- file = fopen(filename,mode);
- }
- else if (GetLastError()==ERROR_NO_UNICODE_TRANSLATION)
- {
- file = fopen(filename,mode);
- }
+ file = fopen(filename, mode);
+ } else if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION) {
+ file = fopen(filename, mode);
+ }
#else
- file=fopen(filename,mode);
+ file = fopen(filename, mode);
+
#endif
- if (file == NULL)
- {
+ if (file == NULL) {
SYSerr(SYS_F_FOPEN, errno);
- ERR_add_error_data(5,"fopen('",filename,"','",mode,"')");
+ ERR_add_error_data(5, "fopen('", filename, "', '", mode, "')");
if (errno == ENOENT)
- BIOerr(BIO_F_BIO_NEW_FILE,BIO_R_NO_SUCH_FILE);
+ BIOerr(BIO_F_BIO_NEW_FILE, BIO_R_NO_SUCH_FILE);
else
- BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB);
- return(NULL);
- }
- if ((ret=BIO_new(BIO_s_file())) == NULL)
- {
+ BIOerr(BIO_F_BIO_NEW_FILE, ERR_R_SYS_LIB);
+ return (NULL);
+ }
+ if ((ret = BIO_new(BIO_s_file())) == NULL) {
fclose(file);
- return(NULL);
- }
-
- BIO_clear_flags(ret,BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */
- BIO_set_fp(ret,file,BIO_CLOSE);
- return(ret);
+ return (NULL);
}
-BIO *BIO_new_fp(FILE *stream, int close_flag)
- {
- BIO *ret;
-
- if ((ret=BIO_new(BIO_s_file())) == NULL)
- return(NULL);
-
- BIO_set_flags(ret,BIO_FLAGS_UPLINK); /* redundant, left for documentation puposes */
- BIO_set_fp(ret,stream,close_flag);
- return(ret);
- }
+ BIO_clear_flags(ret, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */
+ BIO_set_fp(ret, file, BIO_CLOSE);
+ return (ret);
+}
-BIO_METHOD *BIO_s_file(void)
- {
- return(&methods_filep);
- }
+BIO
+*BIO_new_fp(FILE *stream, int close_flag)
+{
+ BIO *ret;
-static int file_new(BIO *bi)
- {
- bi->init=0;
- bi->num=0;
- bi->ptr=NULL;
+ if ((ret = BIO_new(BIO_s_file())) == NULL)
+ return (NULL);
+
+ BIO_set_flags(ret, BIO_FLAGS_UPLINK); /* redundant, left for documentation puposes */
+ BIO_set_fp(ret, stream, close_flag);
+ return (ret);
+}
+
+BIO_METHOD
+*BIO_s_file(void)
+{
+ return (&methods_filep);
+}
+
+static int
+file_new(BIO *bi)
+{
+ bi->init = 0;
+ bi->num = 0;
+ bi->ptr = NULL;
bi->flags=BIO_FLAGS_UPLINK; /* default to UPLINK */
- return(1);
- }
-
-static int file_free(BIO *a)
- {
- if (a == NULL) return(0);
- if (a->shutdown)
- {
- if ((a->init) && (a->ptr != NULL))
- {
+ return (1);
+}
+
+static int
+file_free(BIO *a)
+{
+ if (a == NULL)
+ return (0);
+ if (a->shutdown) {
+ if ((a->init) && (a->ptr != NULL)) {
if (a->flags&BIO_FLAGS_UPLINK)
UP_fclose (a->ptr);
else
fclose (a->ptr);
- a->ptr=NULL;
- a->flags=BIO_FLAGS_UPLINK;
- }
- a->init=0;
+ a->ptr = NULL;
+ a->flags = BIO_FLAGS_UPLINK;
}
- return(1);
+ a->init = 0;
}
-
-static int file_read(BIO *b, char *out, int outl)
- {
- int ret=0;
+ return (1);
+}
- if (b->init && (out != NULL))
- {
+static int
+file_read(BIO *b, char *out, int outl)
+{
+ int ret = 0;
+
+ if (b->init && (out != NULL)) {
if (b->flags&BIO_FLAGS_UPLINK)
- ret=UP_fread(out,1,(int)outl,b->ptr);
+ ret = UP_fread(out, 1,(int)outl, b->ptr);
else
- ret=fread(out,1,(int)outl,(FILE *)b->ptr);
- if(ret == 0 && (b->flags&BIO_FLAGS_UPLINK)?UP_ferror((FILE *)b->ptr):ferror((FILE *)b->ptr))
- {
+ ret = fread(out, 1,(int)outl,(FILE *)b->ptr);
+ if (ret == 0 && (b->flags & BIO_FLAGS_UPLINK) ?
+ UP_ferror((FILE *)b->ptr) : ferror((FILE *)b->ptr)) {
SYSerr(SYS_F_FREAD, errno);
- BIOerr(BIO_F_FILE_READ,ERR_R_SYS_LIB);
- ret=-1;
- }
+ BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB);
+ ret = -1;
}
- return(ret);
}
+ return (ret);
+}
-static int file_write(BIO *b, const char *in, int inl)
- {
- int ret=0;
+static int
+file_write(BIO *b, const char *in, int inl)
+{
+ int ret = 0;
- if (b->init && (in != NULL))
- {
+ if (b->init && (in != NULL)) {
if (b->flags&BIO_FLAGS_UPLINK)
- ret=UP_fwrite(in,(int)inl,1,b->ptr);
+ ret = UP_fwrite(in,(int)inl, 1, b->ptr);
else
- ret=fwrite(in,(int)inl,1,(FILE *)b->ptr);
+ ret = fwrite(in,(int)inl, 1,(FILE *)b->ptr);
if (ret)
- ret=inl;
+ ret = inl;
/* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */
/* according to Tim Hudson <tjh@cryptsoft.com>, the commented
* out version above can cause 'inl' write calls under
* some stupid stdio implementations (VMS) */
- }
- return(ret);
}
-
-static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
- long ret=1;
- FILE *fp=(FILE *)b->ptr;
+ return (ret);
+}
+
+static long
+file_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+ long ret = 1;
+ FILE *fp = (FILE *)b->ptr;
FILE **fpp;
char p[4];
- switch (cmd)
- {
+ switch (cmd) {
case BIO_C_FILE_SEEK:
case BIO_CTRL_RESET:
if (b->flags&BIO_FLAGS_UPLINK)
- ret=(long)UP_fseek(b->ptr,num,0);
+ ret = (long)UP_fseek(b->ptr, num, 0);
else
- ret=(long)fseek(fp,num,0);
+ ret = (long)fseek(fp, num, 0);
break;
case BIO_CTRL_EOF:
if (b->flags&BIO_FLAGS_UPLINK)
- ret=(long)UP_feof(fp);
+ ret = (long)UP_feof(fp);
else
- ret=(long)feof(fp);
+ ret = (long)feof(fp);
break;
case BIO_C_FILE_TELL:
case BIO_CTRL_INFO:
if (b->flags&BIO_FLAGS_UPLINK)
- ret=UP_ftell(b->ptr);
+ ret = UP_ftell(b->ptr);
else
- ret=ftell(fp);
+ ret = ftell(fp);
break;
case BIO_C_SET_FILE_PTR:
file_free(b);
- b->shutdown=(int)num&BIO_CLOSE;
- b->ptr=ptr;
- b->init=1;
+ b->shutdown = (int)num&BIO_CLOSE;
+ b->ptr = ptr;
+ b->init = 1;
#if BIO_FLAGS_UPLINK!=0
#if defined(__MINGW32__) && defined(__MSVCRT__) && !defined(_IOB_ENTRIES)
#define _IOB_ENTRIES 20
#if defined(_IOB_ENTRIES)
/* Safety net to catch purely internal BIO_set_fp calls */
if ((size_t)ptr >= (size_t)stdin &&
- (size_t)ptr < (size_t)(stdin+_IOB_ENTRIES))
- BIO_clear_flags(b,BIO_FLAGS_UPLINK);
+ (size_t)ptr < (size_t)(stdin + _IOB_ENTRIES))
+ BIO_clear_flags(b, BIO_FLAGS_UPLINK);
#endif
#endif
#ifdef UP_fsetmod
#endif
{
#if defined(OPENSSL_SYS_WINDOWS)
- int fd = _fileno((FILE*)ptr);
- if (num & BIO_FP_TEXT)
- _setmode(fd,_O_TEXT);
- else
- _setmode(fd,_O_BINARY);
+ int fd = _fileno((FILE*)ptr);
+ if (num & BIO_FP_TEXT)
+ _setmode(fd, _O_TEXT);
+ else
+ _setmode(fd, _O_BINARY);
#elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB)
- int fd = fileno((FILE*)ptr);
- /* Under CLib there are differences in file modes */
- if (num & BIO_FP_TEXT)
- setmode(fd,O_TEXT);
- else
- setmode(fd,O_BINARY);
-#elif defined(OPENSSL_SYS_MSDOS)
- int fd = fileno((FILE*)ptr);
- /* Set correct text/binary mode */
- if (num & BIO_FP_TEXT)
- _setmode(fd,_O_TEXT);
- /* Dangerous to set stdin/stdout to raw (unless redirected) */
- else
- {
- if (fd == STDIN_FILENO || fd == STDOUT_FILENO)
- {
- if (isatty(fd) <= 0)
- _setmode(fd,_O_BINARY);
- }
+ int fd = fileno((FILE*)ptr);
+ /* Under CLib there are differences in file modes */
+ if (num & BIO_FP_TEXT)
+ setmode(fd, O_TEXT);
else
- _setmode(fd,_O_BINARY);
+ setmode(fd, O_BINARY);
+#elif defined(OPENSSL_SYS_MSDOS)
+ int fd = fileno((FILE*)ptr);
+ /* Set correct text/binary mode */
+ if (num & BIO_FP_TEXT)
+ _setmode(fd, _O_TEXT);
+ /* Dangerous to set stdin/stdout to raw (unless redirected) */
+ else {
+ if (fd == STDIN_FILENO || fd == STDOUT_FILENO) {
+ if (isatty(fd) <= 0)
+ _setmode(fd, _O_BINARY);
+ } else
+ _setmode(fd, _O_BINARY);
}
#elif defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN)
- int fd = fileno((FILE*)ptr);
- if (num & BIO_FP_TEXT)
- setmode(fd, O_TEXT);
- else
- setmode(fd, O_BINARY);
+ int fd = fileno((FILE*)ptr);
+ if (num & BIO_FP_TEXT)
+ setmode(fd, O_TEXT);
+ else
+ setmode(fd, O_BINARY);
#endif
}
break;
case BIO_C_SET_FILENAME:
file_free(b);
- b->shutdown=(int)num&BIO_CLOSE;
- if (num & BIO_FP_APPEND)
- {
+ b->shutdown = (int)num&BIO_CLOSE;
+ if (num & BIO_FP_APPEND) {
if (num & BIO_FP_READ)
- BUF_strlcpy(p,"a+",sizeof p);
- else BUF_strlcpy(p,"a",sizeof p);
- }
- else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE))
- BUF_strlcpy(p,"r+",sizeof p);
+ BUF_strlcpy(p, "a+", sizeof p);
+ else BUF_strlcpy(p, "a", sizeof p);
+ } else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE))
+ BUF_strlcpy(p, "r+", sizeof p);
else if (num & BIO_FP_WRITE)
- BUF_strlcpy(p,"w",sizeof p);
+ BUF_strlcpy(p, "w", sizeof p);
else if (num & BIO_FP_READ)
- BUF_strlcpy(p,"r",sizeof p);
- else
- {
- BIOerr(BIO_F_FILE_CTRL,BIO_R_BAD_FOPEN_MODE);
- ret=0;
+ BUF_strlcpy(p, "r", sizeof p);
+ else {
+ BIOerr(BIO_F_FILE_CTRL, BIO_R_BAD_FOPEN_MODE);
+ ret = 0;
break;
- }
+ }
#if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN)
if (!(num & BIO_FP_TEXT))
- strcat(p,"b");
+ strcat(p, "b");
else
- strcat(p,"t");
+ strcat(p, "t");
#endif
#if defined(OPENSSL_SYS_NETWARE)
if (!(num & BIO_FP_TEXT))
- strcat(p,"b");
+ strcat(p, "b");
else
- strcat(p,"t");
+ strcat(p, "t");
#endif
- fp=fopen(ptr,p);
- if (fp == NULL)
- {
+ fp = fopen(ptr, p);
+ if (fp == NULL) {
SYSerr(SYS_F_FOPEN, errno);
- ERR_add_error_data(5,"fopen('",ptr,"','",p,"')");
- BIOerr(BIO_F_FILE_CTRL,ERR_R_SYS_LIB);
- ret=0;
+ ERR_add_error_data(5, "fopen('", ptr, "', '", p, "')");
+ BIOerr(BIO_F_FILE_CTRL, ERR_R_SYS_LIB);
+ ret = 0;
break;
- }
- b->ptr=fp;
- b->init=1;
- BIO_clear_flags(b,BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */
+ }
+ b->ptr = fp;
+ b->init = 1;
+ BIO_clear_flags(b, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */
break;
case BIO_C_GET_FILE_PTR:
/* the ptr parameter is actually a FILE ** in this case. */
- if (ptr != NULL)
- {
- fpp=(FILE **)ptr;
- *fpp=(FILE *)b->ptr;
- }
+ if (ptr != NULL) {
+ fpp = (FILE **)ptr;
+ *fpp = (FILE *)b->ptr;
+ }
break;
case BIO_CTRL_GET_CLOSE:
- ret=(long)b->shutdown;
+ ret = (long)b->shutdown;
break;
case BIO_CTRL_SET_CLOSE:
- b->shutdown=(int)num;
+ b->shutdown = (int)num;
break;
case BIO_CTRL_FLUSH:
if (b->flags&BIO_FLAGS_UPLINK)
fflush((FILE *)b->ptr);
break;
case BIO_CTRL_DUP:
- ret=1;
+ ret = 1;
break;
case BIO_CTRL_WPENDING:
case BIO_CTRL_PUSH:
case BIO_CTRL_POP:
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
}
+ return (ret);
+}
-static int file_gets(BIO *bp, char *buf, int size)
- {
- int ret=0;
+static int
+file_gets(BIO *bp, char *buf, int size)
+{
+ int ret = 0;
- buf[0]='\0';
- if (bp->flags&BIO_FLAGS_UPLINK)
- {
- if (!UP_fgets(buf,size,bp->ptr))
+ buf[0] = '\0';
+ if (bp->flags&BIO_FLAGS_UPLINK) {
+ if (!UP_fgets(buf, size, bp->ptr))
goto err;
- }
- else
- {
- if (!fgets(buf,size,(FILE *)bp->ptr))
+ } else {
+ if (!fgets(buf, size,(FILE *)bp->ptr))
goto err;
- }
- if (buf[0] != '\0')
- ret=strlen(buf);
- err:
- return(ret);
}
+ if (buf[0] != '\0')
+ ret = strlen(buf);
+err:
+ return (ret);
+}
-static int file_puts(BIO *bp, const char *str)
- {
- int n,ret;
+static int
+file_puts(BIO *bp, const char *str)
+{
+ int n, ret;
- n=strlen(str);
- ret=file_write(bp,str,n);
- return(ret);
- }
+ n = strlen(str);
+ ret = file_write(bp, str, n);
+ return (ret);
+}
#endif /* OPENSSL_NO_STDIO */
#endif /* HEADER_BSS_FILE_C */
-
-
# if __INITIAL_POINTER_SIZE == 64
# pragma pointer_size save
# pragma pointer_size 32
- void * _malloc32 (__size_t);
+void * _malloc32 (__size_t);
# pragma pointer_size restore
# endif /* __INITIAL_POINTER_SIZE == 64 */
# endif /* __INITIAL_POINTER_SIZE && defined _ANSI_C_SOURCE */
static void xsyslog(BIO* bp, int priority, const char* string);
static void xcloselog(BIO* bp);
-static BIO_METHOD methods_slg=
- {
- BIO_TYPE_MEM,"syslog",
+static BIO_METHOD methods_slg = {
+ BIO_TYPE_MEM, "syslog",
slg_write,
NULL,
slg_puts,
slg_new,
slg_free,
NULL,
- };
+};
-BIO_METHOD *BIO_s_log(void)
- {
- return(&methods_slg);
- }
+BIO_METHOD
+*BIO_s_log(void)
+{
+ return (&methods_slg);
+}
-static int slg_new(BIO *bi)
- {
- bi->init=1;
- bi->num=0;
- bi->ptr=NULL;
+static int
+slg_new(BIO *bi)
+{
+ bi->init = 1;
+ bi->num = 0;
+ bi->ptr = NULL;
xopenlog(bi, "application", LOG_DAEMON);
- return(1);
- }
+ return (1);
+}
-static int slg_free(BIO *a)
- {
- if (a == NULL) return(0);
+static int
+slg_free(BIO *a)
+{
+ if (a == NULL)
+ return (0);
xcloselog(a);
- return(1);
- }
-
-static int slg_write(BIO *b, const char *in, int inl)
- {
- int ret= inl;
+ return (1);
+}
+
+static int
+slg_write(BIO *b, const char *in, int inl)
+{
+ int ret = inl;
char* buf;
char* pp;
int priority, i;
- static const struct
- {
+ static const struct {
int strl;
char str[10];
int log_level;
- }
- mapping[] =
- {
+ }
+ mapping[] = {
{ 6, "PANIC ", LOG_EMERG },
{ 6, "EMERG ", LOG_EMERG },
{ 4, "EMR ", LOG_EMERG },
{ 6, "DEBUG ", LOG_DEBUG },
{ 4, "DBG ", LOG_DEBUG },
{ 0, "", LOG_ERR } /* The default */
- };
+ };
- if((buf= (char *)OPENSSL_malloc(inl+ 1)) == NULL){
- return(0);
+ if ((buf = (char *)OPENSSL_malloc(inl + 1)) == NULL) {
+ return (0);
}
strncpy(buf, in, inl);
- buf[inl]= '\0';
+ buf[inl] = '\0';
i = 0;
- while(strncmp(buf, mapping[i].str, mapping[i].strl) != 0) i++;
+ while (strncmp(buf, mapping[i].str, mapping[i].strl) != 0)
+ i++;
priority = mapping[i].log_level;
pp = buf + mapping[i].strl;
xsyslog(b, priority, pp);
OPENSSL_free(buf);
- return(ret);
- }
+ return (ret);
+}
-static long slg_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
- switch (cmd)
- {
+static long
+slg_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+ switch (cmd) {
case BIO_CTRL_SET:
xcloselog(b);
xopenlog(b, ptr, num);
break;
default:
break;
- }
- return(0);
}
+ return (0);
+}
-static int slg_puts(BIO *bp, const char *str)
- {
- int n,ret;
+static int
+slg_puts(BIO *bp, const char *str)
+{
+ int n, ret;
- n=strlen(str);
- ret=slg_write(bp,str,n);
- return(ret);
- }
+ n = strlen(str);
+ ret = slg_write(bp, str, n);
+ return (ret);
+}
#if defined(OPENSSL_SYS_WIN32)
-static void xopenlog(BIO* bp, char* name, int level)
+static void
+xopenlog(BIO* bp, char* name, int level)
{
if (check_winnt())
- bp->ptr = RegisterEventSourceA(NULL,name);
+ bp->ptr = RegisterEventSourceA(NULL, name);
else
bp->ptr = NULL;
}
-static void xsyslog(BIO *bp, int priority, const char *string)
+static void
+xsyslog(BIO *bp, int priority, const char *string)
{
LPCSTR lpszStrings[2];
- WORD evtype= EVENTLOG_ERROR_TYPE;
- char pidbuf[DECIMAL_SIZE(DWORD)+4];
+ WORD evtype = EVENTLOG_ERROR_TYPE;
+ char pidbuf[DECIMAL_SIZE(DWORD) + 4];
if (bp->ptr == NULL)
return;
- switch (priority)
- {
+ switch (priority) {
case LOG_EMERG:
case LOG_ALERT:
case LOG_CRIT:
as error anyway. */
evtype = EVENTLOG_ERROR_TYPE;
break;
- }
+ }
sprintf(pidbuf, "[%u] ", GetCurrentProcessId());
lpszStrings[0] = pidbuf;
lpszStrings[1] = string;
ReportEventA(bp->ptr, evtype, 0, 1024, NULL, 2, 0,
- lpszStrings, NULL);
+ lpszStrings, NULL);
}
-
-static void xcloselog(BIO* bp)
+
+static void
+xcloselog(BIO* bp)
{
- if(bp->ptr)
+ if (bp->ptr)
DeregisterEventSource((HANDLE)(bp->ptr));
- bp->ptr= NULL;
+ bp->ptr = NULL;
}
#elif defined(OPENSSL_SYS_VMS)
static int VMS_OPC_target = LOG_DAEMON;
-static void xopenlog(BIO* bp, char* name, int level)
+static void
+xopenlog(BIO* bp, char* name, int level)
{
- VMS_OPC_target = level;
+ VMS_OPC_target = level;
+
}
-static void xsyslog(BIO *bp, int priority, const char *string)
+static void
+xsyslog(BIO *bp, int priority, const char *string)
{
struct dsc$descriptor_s opc_dsc;
char buf[10240];
unsigned int len;
- struct dsc$descriptor_s buf_dsc;
+ struct dsc$descriptor_s buf_dsc;
$DESCRIPTOR(fao_cmd, "!AZ: !AZ");
char *priority_tag;
- switch (priority)
- {
- case LOG_EMERG: priority_tag = "Emergency"; break;
- case LOG_ALERT: priority_tag = "Alert"; break;
- case LOG_CRIT: priority_tag = "Critical"; break;
- case LOG_ERR: priority_tag = "Error"; break;
- case LOG_WARNING: priority_tag = "Warning"; break;
- case LOG_NOTICE: priority_tag = "Notice"; break;
- case LOG_INFO: priority_tag = "Info"; break;
- case LOG_DEBUG: priority_tag = "DEBUG"; break;
- }
+ switch (priority) {
+ case LOG_EMERG:
+ priority_tag = "Emergency"; break;
+ case LOG_ALERT:
+ priority_tag = "Alert"; break;
+ case LOG_CRIT:
+ priority_tag = "Critical"; break;
+ case LOG_ERR:
+ priority_tag = "Error"; break;
+ case LOG_WARNING:
+ priority_tag = "Warning"; break;
+ case LOG_NOTICE:
+ priority_tag = "Notice"; break;
+ case LOG_INFO:
+ priority_tag = "Info"; break;
+ case LOG_DEBUG:
+ priority_tag = "DEBUG"; break;
+ }
buf_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
buf_dsc.dsc$b_class = DSC$K_CLASS_S;
lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string);
/* We know there's an 8-byte header. That's documented. */
- opcdef_p = OPCDEF_MALLOC( 8+ len);
+ opcdef_p = OPCDEF_MALLOC( 8 + len);
opcdef_p->opc$b_ms_type = OPC$_RQ_RQST;
memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3);
opcdef_p->opc$l_ms_rqstid = 0;
OPENSSL_free(opcdef_p);
}
-static void xcloselog(BIO* bp)
+static void
+xcloselog(BIO* bp)
{
}
#else /* Unix/Watt32 */
-static void xopenlog(BIO* bp, char* name, int level)
+static void
+xopenlog(BIO* bp, char* name, int level)
{
#ifdef WATT32 /* djgpp/DOS */
openlog(name, LOG_PID|LOG_CONS|LOG_NDELAY, level);
#endif
}
-static void xsyslog(BIO *bp, int priority, const char *string)
+static void
+xsyslog(BIO *bp, int priority, const char *string)
{
syslog(priority, "%s", string);
}
-static void xcloselog(BIO* bp)
+static void
+xcloselog(BIO* bp)
{
closelog();
}
static long mem_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int mem_new(BIO *h);
static int mem_free(BIO *data);
-static BIO_METHOD mem_method=
- {
+
+static BIO_METHOD mem_method = {
BIO_TYPE_MEM,
"memory buffer",
mem_write,
mem_new,
mem_free,
NULL,
- };
+};
/* bio->num is used to hold the value to return on 'empty', if it is
* 0, should_retry is not set */
-BIO_METHOD *BIO_s_mem(void)
- {
- return(&mem_method);
- }
+BIO_METHOD
+*BIO_s_mem(void)
+{
+ return (&mem_method);
+}
-BIO *BIO_new_mem_buf(void *buf, int len)
+BIO
+*BIO_new_mem_buf(void *buf, int len)
{
BIO *ret;
BUF_MEM *b;
size_t sz;
if (!buf) {
- BIOerr(BIO_F_BIO_NEW_MEM_BUF,BIO_R_NULL_PARAMETER);
+ BIOerr(BIO_F_BIO_NEW_MEM_BUF, BIO_R_NULL_PARAMETER);
return NULL;
}
- sz = (len<0) ? strlen(buf) : (size_t)len;
- if(!(ret = BIO_new(BIO_s_mem())) ) return NULL;
+ sz = (len < 0) ? strlen(buf) : (size_t)len;
+ if (!(ret = BIO_new(BIO_s_mem())))
+ return NULL;
b = (BUF_MEM *)ret->ptr;
b->data = buf;
b->length = sz;
return ret;
}
-static int mem_new(BIO *bi)
- {
+static int
+mem_new(BIO *bi)
+{
BUF_MEM *b;
- if ((b=BUF_MEM_new()) == NULL)
- return(0);
- bi->shutdown=1;
- bi->init=1;
- bi->num= -1;
- bi->ptr=(char *)b;
- return(1);
- }
+ if ((b = BUF_MEM_new()) == NULL)
+ return (0);
+ bi->shutdown = 1;
+ bi->init = 1;
+ bi->num = -1;
+ bi->ptr = (char *)b;
+ return (1);
+}
-static int mem_free(BIO *a)
- {
- if (a == NULL) return(0);
- if (a->shutdown)
- {
- if ((a->init) && (a->ptr != NULL))
- {
+static int
+mem_free(BIO *a)
+{
+ if (a == NULL)
+ return (0);
+ if (a->shutdown) {
+ if ((a->init) && (a->ptr != NULL)) {
BUF_MEM *b;
b = (BUF_MEM *)a->ptr;
- if(a->flags & BIO_FLAGS_MEM_RDONLY) b->data = NULL;
- BUF_MEM_free(b);
- a->ptr=NULL;
- }
+ if (a->flags & BIO_FLAGS_MEM_RDONLY)
+ b->data = NULL;
+ BUF_MEM_free(b);
+ a->ptr = NULL;
}
- return(1);
}
-
-static int mem_read(BIO *b, char *out, int outl)
- {
- int ret= -1;
+ return (1);
+}
+
+static int
+mem_read(BIO *b, char *out, int outl)
+{
+ int ret = -1;
BUF_MEM *bm;
- bm=(BUF_MEM *)b->ptr;
+ bm = (BUF_MEM *)b->ptr;
BIO_clear_retry_flags(b);
- ret=(outl >=0 && (size_t)outl > bm->length)?(int)bm->length:outl;
+ ret = (outl >=0 && (size_t)outl > bm->length) ? (int)bm->length : outl;
if ((out != NULL) && (ret > 0)) {
- memcpy(out,bm->data,ret);
- bm->length-=ret;
- if(b->flags & BIO_FLAGS_MEM_RDONLY) bm->data += ret;
+ memcpy(out, bm->data, ret);
+ bm->length -= ret;
+ if (b->flags & BIO_FLAGS_MEM_RDONLY)
+ bm->data += ret;
else {
- memmove(&(bm->data[0]),&(bm->data[ret]),bm->length);
+ memmove(&(bm->data[0]), &(bm->data[ret]), bm->length);
}
- } else if (bm->length == 0)
- {
+ } else if (bm->length == 0) {
ret = b->num;
if (ret != 0)
BIO_set_retry_read(b);
- }
- return(ret);
}
+ return (ret);
+}
-static int mem_write(BIO *b, const char *in, int inl)
- {
- int ret= -1;
+static int
+mem_write(BIO *b, const char *in, int inl)
+{
+ int ret = -1;
int blen;
BUF_MEM *bm;
- bm=(BUF_MEM *)b->ptr;
- if (in == NULL)
- {
- BIOerr(BIO_F_MEM_WRITE,BIO_R_NULL_PARAMETER);
+ bm = (BUF_MEM *)b->ptr;
+ if (in == NULL) {
+ BIOerr(BIO_F_MEM_WRITE, BIO_R_NULL_PARAMETER);
goto end;
- }
+ }
- if(b->flags & BIO_FLAGS_MEM_RDONLY) {
- BIOerr(BIO_F_MEM_WRITE,BIO_R_WRITE_TO_READ_ONLY_BIO);
+ if (b->flags & BIO_FLAGS_MEM_RDONLY) {
+ BIOerr(BIO_F_MEM_WRITE, BIO_R_WRITE_TO_READ_ONLY_BIO);
goto end;
}
BIO_clear_retry_flags(b);
- blen=bm->length;
- if (BUF_MEM_grow_clean(bm,blen+inl) != (blen+inl))
+ blen = bm->length;
+ if (BUF_MEM_grow_clean(bm, blen + inl) != (blen + inl))
goto end;
- memcpy(&(bm->data[blen]),in,inl);
- ret=inl;
+ memcpy(&(bm->data[blen]), in, inl);
+ ret = inl;
end:
- return(ret);
- }
+ return (ret);
+}
-static long mem_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
- long ret=1;
+static long
+mem_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+ long ret = 1;
char **pptr;
- BUF_MEM *bm=(BUF_MEM *)b->ptr;
+ BUF_MEM *bm = (BUF_MEM *)b->ptr;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_RESET:
- if (bm->data != NULL)
- {
+ if (bm->data != NULL) {
/* For read only case reset to the start again */
- if(b->flags & BIO_FLAGS_MEM_RDONLY)
- {
+ if (b->flags & BIO_FLAGS_MEM_RDONLY) {
bm->data -= bm->max - bm->length;
bm->length = bm->max;
- }
- else
- {
- memset(bm->data,0,bm->max);
- bm->length=0;
- }
+ } else {
+ memset(bm->data, 0, bm->max);
+ bm->length = 0;
}
+ }
break;
case BIO_CTRL_EOF:
- ret=(long)(bm->length == 0);
+ ret = (long)(bm->length == 0);
break;
case BIO_C_SET_BUF_MEM_EOF_RETURN:
- b->num=(int)num;
+ b->num = (int)num;
break;
case BIO_CTRL_INFO:
- ret=(long)bm->length;
- if (ptr != NULL)
- {
- pptr=(char **)ptr;
- *pptr=(char *)&(bm->data[0]);
- }
+ ret = (long)bm->length;
+ if (ptr != NULL) {
+ pptr = (char **)ptr;
+ *pptr = (char *)&(bm->data[0]);
+ }
break;
case BIO_C_SET_BUF_MEM:
mem_free(b);
- b->shutdown=(int)num;
- b->ptr=ptr;
+ b->shutdown = (int)num;
+ b->ptr = ptr;
break;
case BIO_C_GET_BUF_MEM_PTR:
- if (ptr != NULL)
- {
- pptr=(char **)ptr;
- *pptr=(char *)bm;
- }
+ if (ptr != NULL) {
+ pptr = (char **)ptr;
+ *pptr = (char *)bm;
+ }
break;
case BIO_CTRL_GET_CLOSE:
- ret=(long)b->shutdown;
+ ret = (long)b->shutdown;
break;
case BIO_CTRL_SET_CLOSE:
- b->shutdown=(int)num;
+ b->shutdown = (int)num;
break;
case BIO_CTRL_WPENDING:
- ret=0L;
+ ret = 0L;
break;
case BIO_CTRL_PENDING:
- ret=(long)bm->length;
+ ret = (long)bm->length;
break;
case BIO_CTRL_DUP:
case BIO_CTRL_FLUSH:
- ret=1;
+ ret = 1;
break;
case BIO_CTRL_PUSH:
case BIO_CTRL_POP:
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
}
+ return (ret);
+}
-static int mem_gets(BIO *bp, char *buf, int size)
- {
- int i,j;
- int ret= -1;
+static int
+mem_gets(BIO *bp, char *buf, int size)
+{
+ int i, j;
+ int ret = -1;
char *p;
- BUF_MEM *bm=(BUF_MEM *)bp->ptr;
+ BUF_MEM *bm = (BUF_MEM *)bp->ptr;
BIO_clear_retry_flags(bp);
- j=bm->length;
- if ((size-1) < j) j=size-1;
- if (j <= 0)
- {
- *buf='\0';
+ j = bm->length;
+ if ((size - 1) < j)
+ j = size - 1;
+ if (j <= 0) {
+ *buf = '\0';
return 0;
- }
- p=bm->data;
- for (i=0; i<j; i++)
- {
- if (p[i] == '\n')
- {
+ }
+ p = bm->data;
+ for (i = 0; i < j; i++) {
+ if (p[i] == '\n') {
i++;
break;
- }
}
+ }
/*
* i is now the max num of bytes to copy, either j or up to
* and including the first newline
*/
- i=mem_read(bp,buf,i);
- if (i > 0) buf[i]='\0';
- ret=i;
- return(ret);
- }
+ i = mem_read(bp, buf, i);
+ if (i > 0)
+ buf[i] = '\0';
+ ret = i;
+ return (ret);
+}
-static int mem_puts(BIO *bp, const char *str)
- {
- int n,ret;
+static int
+mem_puts(BIO *bp, const char *str)
+{
+ int n, ret;
- n=strlen(str);
- ret=mem_write(bp,str,n);
+ n = strlen(str);
+ ret = mem_write(bp, str, n);
/* memory semantics is that it will always work */
- return(ret);
- }
-
+ return (ret);
+}
static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int null_new(BIO *h);
static int null_free(BIO *data);
-static BIO_METHOD null_method=
- {
+
+static BIO_METHOD null_method = {
BIO_TYPE_NULL,
"NULL",
null_write,
null_new,
null_free,
NULL,
- };
+};
-BIO_METHOD *BIO_s_null(void)
- {
- return(&null_method);
- }
+BIO_METHOD
+*BIO_s_null(void)
+{
+ return (&null_method);
+}
-static int null_new(BIO *bi)
- {
- bi->init=1;
- bi->num=0;
- bi->ptr=(NULL);
- return(1);
- }
+static int
+null_new(BIO *bi)
+{
+ bi->init = 1;
+ bi->num = 0;
+ bi->ptr = (NULL);
+ return (1);
+}
-static int null_free(BIO *a)
- {
- if (a == NULL) return(0);
- return(1);
- }
-
-static int null_read(BIO *b, char *out, int outl)
- {
- return(0);
- }
+static int
+null_free(BIO *a)
+{
+ if (a == NULL)
+ return (0);
+ return (1);
+}
-static int null_write(BIO *b, const char *in, int inl)
- {
- return(inl);
- }
+static int
+null_read(BIO *b, char *out, int outl)
+{
+ return (0);
+}
+
+static int
+null_write(BIO *b, const char *in, int inl)
+{
+ return (inl);
+}
-static long null_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
- long ret=1;
+static long
+null_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+ long ret = 1;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_RESET:
case BIO_CTRL_EOF:
case BIO_CTRL_SET:
case BIO_CTRL_SET_CLOSE:
case BIO_CTRL_FLUSH:
case BIO_CTRL_DUP:
- ret=1;
+ ret = 1;
break;
case BIO_CTRL_GET_CLOSE:
case BIO_CTRL_INFO:
case BIO_CTRL_PENDING:
case BIO_CTRL_WPENDING:
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
}
+ return (ret);
+}
-static int null_gets(BIO *bp, char *buf, int size)
- {
- return(0);
- }
-
-static int null_puts(BIO *bp, const char *str)
- {
- if (str == NULL) return(0);
- return(strlen(str));
- }
+static int
+null_gets(BIO *bp, char *buf, int size)
+{
+ return (0);
+}
+static int
+null_puts(BIO *bp, const char *str)
+{
+ if (str == NULL)
+ return (0);
+ return (strlen(str));
+}
typedef unsigned short io_channel;
/*************************************************************************/
-struct io_status { short status, count; long flags; };
+ struct io_status { short status, count;
+ long flags;
+};
-struct rpc_msg { /* Should have member alignment inhibited */
- char channel; /* 'A'-app data. 'R'-remote client 'G'-global */
- char function; /* 'G'-get, 'P'-put, 'C'-confirm, 'X'-close */
- unsigned short int length; /* Amount of data returned or max to return */
- char data[4092]; /* variable data */
+ struct rpc_msg { /* Should have member alignment inhibited */
+ char channel; /* 'A'-app data. 'R'-remote client 'G'-global */
+ char function; /* 'G'-get, 'P'-put, 'C'-confirm, 'X'-close */
+ unsigned short int length; /* Amount of data returned or max to return */
+ char data[4092]; /* variable data */
};
#define RPC_HDR_SIZE (sizeof(struct rpc_msg) - 4092)
struct rpc_ctx {
- int filled, pos;
- struct rpc_msg msg;
+ int filled, pos;
+ struct rpc_msg msg;
};
-static int rtcp_write(BIO *h,const char *buf,int num);
-static int rtcp_read(BIO *h,char *buf,int size);
-static int rtcp_puts(BIO *h,const char *str);
-static int rtcp_gets(BIO *h,char *str,int size);
-static long rtcp_ctrl(BIO *h,int cmd,long arg1,void *arg2);
+static int rtcp_write(BIO *h, const char *buf, int num);
+static int rtcp_read(BIO *h, char *buf, int size);
+static int rtcp_puts(BIO *h, const char *str);
+static int rtcp_gets(BIO *h, char *str, int size);
+static long rtcp_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int rtcp_new(BIO *h);
static int rtcp_free(BIO *data);
-static BIO_METHOD rtcp_method=
- {
+static BIO_METHOD rtcp_method = {
BIO_TYPE_FD,
"RTCP",
rtcp_write,
rtcp_new,
rtcp_free,
NULL,
- };
+};
-BIO_METHOD *BIO_s_rtcp(void)
- {
- return(&rtcp_method);
- }
+BIO_METHOD
+*BIO_s_rtcp(void)
+{
+ return (&rtcp_method);
+}
/*****************************************************************************/
/* Decnet I/O routines.
*/
#pragma message disable DOLLARID
#endif
-static int get ( io_channel chan, char *buffer, int maxlen, int *length )
+static int get(io_channel chan, char *buffer, int maxlen, int *length)
{
- int status;
- struct io_status iosb;
- status = sys$qiow ( 0, chan, IO$_READVBLK, &iosb, 0, 0,
- buffer, maxlen, 0, 0, 0, 0 );
- if ( (status&1) == 1 ) status = iosb.status;
- if ( (status&1) == 1 ) *length = iosb.count;
- return status;
+ int status;
+ struct io_status iosb;
+ status = sys$qiow(0, chan, IO$_READVBLK, &iosb, 0, 0, buffer, maxlen,
+ 0, 0, 0, 0 );
+ if ((status & 1) == 1)
+ status = iosb.status;
+ if ((status & 1) == 1 )
+ *length = iosb.count;
+ return status;
}
-static int put ( io_channel chan, char *buffer, int length )
+static int put(io_channel chan, char *buffer, int length)
{
- int status;
- struct io_status iosb;
- status = sys$qiow ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0,
- buffer, length, 0, 0, 0, 0 );
- if ( (status&1) == 1 ) status = iosb.status;
- return status;
+ int status;
+ struct io_status iosb;
+ status = sys$qiow ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0, buffer,
+ length, 0, 0, 0, 0 );
+ if ((status & 1) == 1)
+ status = iosb.status;
+ return status;
}
#ifdef __DECC
/***************************************************************************/
-static int rtcp_new(BIO *bi)
+static int
+rtcp_new(BIO *bi)
{
- struct rpc_ctx *ctx;
- bi->init=1;
- bi->num=0;
+ struct rpc_ctx *ctx;
+ bi->init = 1;
+ bi->num = 0;
bi->flags = 0;
- bi->ptr=OPENSSL_malloc(sizeof(struct rpc_ctx));
- ctx = (struct rpc_ctx *) bi->ptr;
+ bi->ptr = OPENSSL_malloc(sizeof(struct rpc_ctx));
+ ctx = (struct rpc_ctx *)bi->ptr;
ctx->filled = 0;
ctx->pos = 0;
- return(1);
+ return (1);
}
-static int rtcp_free(BIO *a)
+static int
+rtcp_free(BIO *a)
{
- if (a == NULL) return(0);
- if ( a->ptr ) OPENSSL_free ( a->ptr );
+ if (a == NULL)
+ return (0);
+ if (a->ptr)
+ OPENSSL_free(a->ptr);
a->ptr = NULL;
- return(1);
+ return (1);
}
-
-static int rtcp_read(BIO *b, char *out, int outl)
+
+static int
+rtcp_read(BIO *b, char *out, int outl)
{
- int status, length;
- struct rpc_ctx *ctx;
- /*
- * read data, return existing.
- */
- ctx = (struct rpc_ctx *) b->ptr;
- if ( ctx->pos < ctx->filled ) {
- length = ctx->filled - ctx->pos;
- if ( length > outl ) length = outl;
- memmove ( out, &ctx->msg.data[ctx->pos], length );
- ctx->pos += length;
- return length;
- }
- /*
- * Requst more data from R channel.
- */
- ctx->msg.channel = 'R';
- ctx->msg.function = 'G';
- ctx->msg.length = sizeof(ctx->msg.data);
- status = put ( b->num, (char *) &ctx->msg, RPC_HDR_SIZE );
- if ( (status&1) == 0 ) {
- return -1;
- }
- /*
- * Read.
- */
- ctx->pos = ctx->filled = 0;
- status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length );
- if ( (status&1) == 0 ) length = -1;
- if ( ctx->msg.channel != 'R' || ctx->msg.function != 'C' ) {
- length = -1;
- }
- ctx->filled = length - RPC_HDR_SIZE;
-
- if ( ctx->pos < ctx->filled ) {
- length = ctx->filled - ctx->pos;
- if ( length > outl ) length = outl;
- memmove ( out, ctx->msg.data, length );
- ctx->pos += length;
- return length;
- }
+ int status, length;
+ struct rpc_ctx *ctx;
+ /*
+ * read data, return existing.
+ */
+ ctx = (struct rpc_ctx *)b->ptr;
+ if (ctx->pos < ctx->filled) {
+ length = ctx->filled - ctx->pos;
+ if (length > outl)
+ length = outl;
+ memmove(out, &ctx->msg.data[ctx->pos], length);
+ ctx->pos += length;
+ return length;
+ }
+ /*
+ * Requst more data from R channel.
+ */
+ ctx->msg.channel = 'R';
+ ctx->msg.function = 'G';
+ ctx->msg.length = sizeof(ctx->msg.data);
+ status = put(b->num, (char *)&ctx->msg, RPC_HDR_SIZE);
+ if ((status & 1) == 0 ) {
+ return -1;
+ }
+ /*
+ * Read.
+ */
+ ctx->pos = ctx->filled = 0;
+ status = get(b->num, (char *)&ctx->msg, sizeof(ctx->msg), &length);
+ if ((status & 1) == 0)
+ length = -1;
+ if (ctx->msg.channel != 'R' || ctx->msg.function != 'C') {
+ length = -1;
+ }
+ ctx->filled = length - RPC_HDR_SIZE;
+
+ if (ctx->pos < ctx->filled) {
+ length = ctx->filled - ctx->pos;
+ if (length > outl)
+ length = outl;
+ memmove(out, ctx->msg.data, length);
+ ctx->pos += length;
+ return length;
+ }
- return length;
+ return length;
}
-static int rtcp_write(BIO *b, const char *in, int inl)
+static int
+rtcp_write(BIO *b, const char *in, int inl)
{
- int status, i, segment, length;
- struct rpc_ctx *ctx;
- /*
- * Output data, send in chunks no larger that sizeof(ctx->msg.data).
- */
- ctx = (struct rpc_ctx *) b->ptr;
- for ( i = 0; i < inl; i += segment ) {
- segment = inl - i;
- if ( segment > sizeof(ctx->msg.data) ) segment = sizeof(ctx->msg.data);
- ctx->msg.channel = 'R';
- ctx->msg.function = 'P';
- ctx->msg.length = segment;
- memmove ( ctx->msg.data, &in[i], segment );
- status = put ( b->num, (char *) &ctx->msg, segment + RPC_HDR_SIZE );
- if ((status&1) == 0 ) { i = -1; break; }
+ int status, i, segment, length;
+ struct rpc_ctx *ctx;
+ /*
+ * Output data, send in chunks no larger that sizeof(ctx->msg.data).
+ */
+ ctx = (struct rpc_ctx *)b->ptr;
+ for (i = 0; i < inl; i += segment) {
+ segment = inl - i;
+ if (segment > sizeof(ctx->msg.data))
+ segment = sizeof(ctx->msg.data);
+ ctx->msg.channel = 'R';
+ ctx->msg.function = 'P';
+ ctx->msg.length = segment;
+ memmove(ctx->msg.data, &in[i], segment);
+ status = put(b->num, (char *) &ctx->msg,
+ segment + RPC_HDR_SIZE);
+ if ((status & 1) == 0) {
+ i = -1;
+ break;
+ }
- status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length );
- if ( ((status&1) == 0) || (length < RPC_HDR_SIZE) ) { i = -1; break; }
- if ( (ctx->msg.channel != 'R') || (ctx->msg.function != 'C') ) {
- printf("unexpected response when confirming put %c %c\n",
- ctx->msg.channel, ctx->msg.function );
+ status = get(b->num, (char *)&ctx->msg, sizeof(ctx->msg),
+ &length );
+ if (((status&1) == 0) || (length < RPC_HDR_SIZE)) {
+ i = -1;
+ break;
+ }
+ if ((ctx->msg.channel != 'R') || (ctx->msg.function != 'C')) {
+ printf("unexpected response when confirming put %c %c\n",
+ ctx->msg.channel, ctx->msg.function );
+ }
}
- }
- return(i);
+ return (i);
}
-static long rtcp_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
- long ret=1;
+static long
+rtcp_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+ long ret = 1;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_RESET:
case BIO_CTRL_EOF:
ret = 1;
case BIO_C_SET_FD:
b->num = num;
ret = 1;
- break;
+ break;
case BIO_CTRL_SET_CLOSE:
case BIO_CTRL_FLUSH:
case BIO_CTRL_DUP:
- ret=1;
+ ret = 1;
break;
case BIO_CTRL_GET_CLOSE:
case BIO_CTRL_INFO:
case BIO_CTRL_PENDING:
case BIO_CTRL_WPENDING:
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
- }
-
-static int rtcp_gets(BIO *bp, char *buf, int size)
- {
- return(0);
}
+ return (ret);
+}
-static int rtcp_puts(BIO *bp, const char *str)
+static int
+rtcp_gets(BIO *bp, char *buf, int size)
{
- int length;
- if (str == NULL) return(0);
- length = strlen ( str );
- if ( length == 0 ) return (0);
- return rtcp_write ( bp,str, length );
+ return (0);
}
+static int
+rtcp_puts(BIO *bp, const char *str)
+{
+ int length;
+ if (str == NULL)
+ return (0);
+ length = strlen(str);
+ if (length == 0)
+ return (0);
+ return rtcp_write(bp, str, length);
+}
static int sock_free(BIO *data);
int BIO_sock_should_retry(int s);
-static BIO_METHOD methods_sockp=
- {
+static BIO_METHOD methods_sockp = {
BIO_TYPE_SOCKET,
"socket",
sock_write,
sock_new,
sock_free,
NULL,
- };
+};
-BIO_METHOD *BIO_s_socket(void)
- {
- return(&methods_sockp);
- }
+BIO_METHOD
+*BIO_s_socket(void)
+{
+ return (&methods_sockp);
+}
-BIO *BIO_new_socket(int fd, int close_flag)
- {
+BIO
+*BIO_new_socket(int fd, int close_flag)
+{
BIO *ret;
- ret=BIO_new(BIO_s_socket());
- if (ret == NULL) return(NULL);
- BIO_set_fd(ret,fd,close_flag);
- return(ret);
- }
+ ret = BIO_new(BIO_s_socket());
+ if (ret == NULL)
+ return (NULL);
+ BIO_set_fd(ret, fd, close_flag);
+ return (ret);
+}
-static int sock_new(BIO *bi)
- {
- bi->init=0;
- bi->num=0;
- bi->ptr=NULL;
- bi->flags=0;
- return(1);
- }
+static int
+sock_new(BIO *bi)
+{
+ bi->init = 0;
+ bi->num = 0;
+ bi->ptr = NULL;
+ bi->flags = 0;
+ return (1);
+}
-static int sock_free(BIO *a)
- {
- if (a == NULL) return(0);
- if (a->shutdown)
- {
- if (a->init)
- {
+static int
+sock_free(BIO *a)
+{
+ if (a == NULL)
+ return (0);
+ if (a->shutdown) {
+ if (a->init) {
shutdown(a->num, SHUT_RDWR);
close(a->num);
- }
- a->init=0;
- a->flags=0;
}
- return(1);
+ a->init = 0;
+ a->flags = 0;
}
-
-static int sock_read(BIO *b, char *out, int outl)
- {
- int ret=0;
+ return (1);
+}
- if (out != NULL)
- {
+static int
+sock_read(BIO *b, char *out, int outl)
+{
+ int ret = 0;
+
+ if (out != NULL) {
errno = 0;
- ret=read(b->num,out,outl);
+ ret = read(b->num, out, outl);
BIO_clear_retry_flags(b);
- if (ret <= 0)
- {
+ if (ret <= 0) {
if (BIO_sock_should_retry(ret))
BIO_set_retry_read(b);
- }
}
- return(ret);
}
+ return (ret);
+}
-static int sock_write(BIO *b, const char *in, int inl)
- {
+static int
+sock_write(BIO *b, const char *in, int inl)
+{
int ret;
-
+
errno = 0;
- ret=write(b->num,in,inl);
+ ret = write(b->num, in, inl);
BIO_clear_retry_flags(b);
- if (ret <= 0)
- {
+ if (ret <= 0) {
if (BIO_sock_should_retry(ret))
BIO_set_retry_write(b);
- }
- return(ret);
}
+ return (ret);
+}
-static long sock_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
- long ret=1;
+static long
+sock_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+ long ret = 1;
int *ip;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_C_SET_FD:
sock_free(b);
b->num= *((int *)ptr);
- b->shutdown=(int)num;
- b->init=1;
+ b->shutdown = (int)num;
+ b->init = 1;
break;
case BIO_C_GET_FD:
- if (b->init)
- {
- ip=(int *)ptr;
- if (ip != NULL) *ip=b->num;
- ret=b->num;
- }
- else
- ret= -1;
+ if (b->init) {
+ ip = (int *)ptr;
+ if (ip != NULL)
+ *ip = b->num;
+ ret = b->num;
+ } else
+ ret = -1;
break;
case BIO_CTRL_GET_CLOSE:
- ret=b->shutdown;
+ ret = b->shutdown;
break;
case BIO_CTRL_SET_CLOSE:
- b->shutdown=(int)num;
+ b->shutdown = (int)num;
break;
case BIO_CTRL_DUP:
case BIO_CTRL_FLUSH:
- ret=1;
+ ret = 1;
break;
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
}
+ return (ret);
+}
-static int sock_puts(BIO *bp, const char *str)
- {
- int n,ret;
+static int
+sock_puts(BIO *bp, const char *str)
+{
+ int n, ret;
- n=strlen(str);
- ret=sock_write(bp,str,n);
- return(ret);
- }
+ n = strlen(str);
+ ret = sock_write(bp, str, n);
+ return (ret);
+}
-int BIO_sock_should_retry(int i)
- {
+int
+BIO_sock_should_retry(int i)
+{
int err;
- if ((i == 0) || (i == -1))
- {
- err=errno;
+ if ((i == 0) || (i == -1)) {
+ err = errno;
#if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
if ((i == -1) && (err == 0))
- return(1);
+ return (1);
#endif
- return(BIO_sock_non_fatal_error(err));
- }
- return(0);
+ return (BIO_sock_non_fatal_error(err));
}
+ return (0);
+}
-int BIO_sock_non_fatal_error(int err)
- {
- switch (err)
- {
+int
+BIO_sock_non_fatal_error(int err)
+{
+ switch (err) {
#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_NETWARE)
# if defined(WSAEWOULDBLOCK)
case WSAEWOULDBLOCK:
#ifdef EALREADY
case EALREADY:
#endif
- return(1);
+ return (1);
/* break; */
default:
break;
- }
- return(0);
}
+ return (0);
+}
#endif /* #ifndef OPENSSL_NO_SOCK */
#define TRUNCATE
#define DUMP_WIDTH 16
-#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH-((i-(i>6?6:i)+3)/4))
+#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH - ((i - (i > 6 ? 6 : i) + 3) / 4))
-int BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u),
- void *u, const char *s, int len)
- {
+int
+BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u),
+ void *u, const char *s, int len)
+{
return BIO_dump_indent_cb(cb, u, s, len, 0);
- }
+}
-int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
- void *u, const char *s, int len, int indent)
- {
- int ret=0;
- char buf[288+1],tmp[20],str[128+1];
- int i,j,rows,trc;
+int
+BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
+ void *u, const char *s, int len, int indent)
+{
+ int ret = 0;
+ char buf[288 + 1], tmp[20], str[128 + 1];
+ int i, j, rows, trc;
unsigned char ch;
int dump_width;
- trc=0;
+ trc = 0;
#ifdef TRUNCATE
- for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--)
+ for (; (len > 0) && ((s[len - 1] == ' ') || (s[len - 1] == '\0')); len--)
trc++;
#endif
if (indent < 0)
indent = 0;
- if (indent)
- {
- if (indent > 128) indent=128;
- memset(str,' ',indent);
- }
- str[indent]='\0';
+ if (indent) {
+ if (indent > 128)
+ indent = 128;
+ memset(str, ' ', indent);
+ }
+ str[indent] = '\0';
- dump_width=DUMP_WIDTH_LESS_INDENT(indent);
- rows=(len/dump_width);
- if ((rows*dump_width)<len)
+ dump_width = DUMP_WIDTH_LESS_INDENT(indent);
+ rows = (len / dump_width);
+ if ((rows * dump_width) < len)
rows++;
- for(i=0;i<rows;i++)
- {
- buf[0]='\0'; /* start with empty string */
- BUF_strlcpy(buf,str,sizeof buf);
- (void) snprintf(tmp,sizeof tmp,"%04x - ",i*dump_width);
- BUF_strlcat(buf,tmp,sizeof buf);
- for(j=0;j<dump_width;j++)
- {
- if (((i*dump_width)+j)>=len)
- {
- BUF_strlcat(buf," ",sizeof buf);
- }
- else
- {
- ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
- (void) snprintf(tmp,sizeof tmp,"%02x%c",ch,
- j==7?'-':' ');
- BUF_strlcat(buf,tmp,sizeof buf);
- }
+ for (i = 0; i < rows; i++) {
+ buf[0] = '\0'; /* start with empty string */
+ BUF_strlcpy(buf, str, sizeof buf);
+ (void) snprintf(tmp, sizeof tmp, "%04x - ", i*dump_width);
+ BUF_strlcat(buf, tmp, sizeof buf);
+ for (j = 0; j < dump_width; j++) {
+ if (((i*dump_width) + j) >= len) {
+ BUF_strlcat(buf, " ", sizeof buf);
+ } else {
+ ch = ((unsigned char)*(s + i*dump_width + j)) & 0xff;
+ (void) snprintf(tmp, sizeof tmp, "%02x%c", ch,
+ j == 7 ? '-' : ' ');
+ BUF_strlcat(buf, tmp, sizeof buf);
}
- BUF_strlcat(buf," ",sizeof buf);
- for(j=0;j<dump_width;j++)
- {
- if (((i*dump_width)+j)>=len)
+ }
+ BUF_strlcat(buf, " ", sizeof buf);
+ for (j = 0; j < dump_width; j++) {
+ if (((i*dump_width) + j) >= len)
break;
- ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
+ ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff;
#ifndef CHARSET_EBCDIC
- (void) snprintf(tmp,sizeof tmp,"%c",
- ((ch>=' ')&&(ch<='~'))?ch:'.');
+ (void) snprintf(tmp, sizeof tmp, "%c",
+ ((ch >= ' ') && (ch <= '~')) ? ch : '.');
#else
- (void) snprintf(tmp,sizeof tmp,"%c",
- ((ch>=os_toascii[' '])&&(ch<=os_toascii['~']))
- ? os_toebcdic[ch]
- : '.');
+ (void) snprintf(tmp, sizeof tmp, "%c",
+ ((ch >= os_toascii[' ']) && (ch <= os_toascii['~']))
+ ? os_toebcdic[ch] : '.');
#endif
- BUF_strlcat(buf,tmp,sizeof buf);
- }
- BUF_strlcat(buf,"\n",sizeof buf);
+ BUF_strlcat(buf, tmp, sizeof buf);
+ }
+ BUF_strlcat(buf, "\n", sizeof buf);
/* if this is the last call then update the ddt_dump thing so
* that we will move the selection point in the debug window
*/
- ret+=cb((void *)buf,strlen(buf),u);
- }
+ ret += cb((void *)buf, strlen(buf), u);
+ }
#ifdef TRUNCATE
- if (trc > 0)
- {
- (void) snprintf(buf,sizeof buf,"%s%04x - <SPACES/NULS>\n",str,
- len+trc);
- ret+=cb((void *)buf,strlen(buf),u);
- }
-#endif
- return(ret);
+ if (trc > 0) {
+ (void) snprintf(buf, sizeof buf, "%s%04x - <SPACES/NULS>\n",
+ str, len + trc);
+ ret += cb((void *)buf, strlen(buf), u);
}
+#endif
+ return (ret);
+}
#ifndef OPENSSL_NO_FP_API
-static int write_fp(const void *data, size_t len, void *fp)
- {
+static int
+write_fp(const void *data, size_t len, void *fp)
+{
return UP_fwrite(data, len, 1, fp);
- }
-int BIO_dump_fp(FILE *fp, const char *s, int len)
- {
+}
+
+int
+BIO_dump_fp(FILE *fp, const char *s, int len)
+{
return BIO_dump_cb(write_fp, fp, s, len);
- }
-int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent)
- {
+}
+
+int
+BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent)
+{
return BIO_dump_indent_cb(write_fp, fp, s, len, indent);
- }
+}
#endif
-static int write_bio(const void *data, size_t len, void *bp)
- {
+static int
+write_bio(const void *data, size_t len, void *bp)
+{
return BIO_write((BIO *)bp, (const char *)data, len);
- }
-int BIO_dump(BIO *bp, const char *s, int len)
- {
+}
+
+int
+BIO_dump(BIO *bp, const char *s, int len)
+{
return BIO_dump_cb(write_bio, bp, s, len);
- }
-int BIO_dump_indent(BIO *bp, const char *s, int len, int indent)
- {
- return BIO_dump_indent_cb(write_bio, bp, s, len, indent);
- }
+}
+int
+BIO_dump_indent(BIO *bp, const char *s, int len, int indent)
+{
+ return BIO_dump_indent_cb(write_bio, bp, s, len, indent);
+}
#define LLONG long
#endif
-static void fmtstr (char **, char **, size_t *, size_t *,
- const char *, int, int, int);
-static void fmtint (char **, char **, size_t *, size_t *,
- LLONG, int, int, int, int);
-static void fmtfp (char **, char **, size_t *, size_t *,
- LDOUBLE, int, int, int);
-static void doapr_outch (char **, char **, size_t *, size_t *, int);
-static void _dopr(char **sbuffer, char **buffer,
- size_t *maxlen, size_t *retlen, int *truncated,
- const char *format, va_list args);
+static void fmtstr(char **, char **, size_t *, size_t *, const char *,
+ int, int, int);
+static void fmtint(char **, char **, size_t *, size_t *, LLONG, int,
+ int, int, int);
+static void fmtfp(char **, char **, size_t *, size_t *, LDOUBLE,
+ int, int, int);
+static void doapr_outch(char **, char **, size_t *, size_t *, int);
+static void _dopr(char **sbuffer, char **buffer, size_t *maxlen,
+ size_t *retlen, int *truncated, const char *format, va_list args);
/* format read states */
#define DP_S_DEFAULT 0
#define OSSL_MAX(p,q) ((p >= q) ? p : q)
static void
-_dopr(
- char **sbuffer,
- char **buffer,
- size_t *maxlen,
- size_t *retlen,
- int *truncated,
- const char *format,
- va_list args)
+_dopr(char **sbuffer, char **buffer, size_t *maxlen, size_t *retlen,
+ int *truncated, const char *format, va_list args)
{
- char ch;
- LLONG value;
- LDOUBLE fvalue;
- char *strvalue;
- int min;
- int max;
- int state;
- int flags;
- int cflags;
- size_t currlen;
-
- state = DP_S_DEFAULT;
- flags = currlen = cflags = min = 0;
- max = -1;
- ch = *format++;
-
- while (state != DP_S_DONE) {
- if (ch == '\0' || (buffer == NULL && currlen >= *maxlen))
- state = DP_S_DONE;
-
- switch (state) {
- case DP_S_DEFAULT:
- if (ch == '%')
- state = DP_S_FLAGS;
- else
- doapr_outch(sbuffer,buffer, &currlen, maxlen, ch);
- ch = *format++;
- break;
- case DP_S_FLAGS:
- switch (ch) {
- case '-':
- flags |= DP_F_MINUS;
- ch = *format++;
- break;
- case '+':
- flags |= DP_F_PLUS;
- ch = *format++;
- break;
- case ' ':
- flags |= DP_F_SPACE;
- ch = *format++;
- break;
- case '#':
- flags |= DP_F_NUM;
- ch = *format++;
- break;
- case '0':
- flags |= DP_F_ZERO;
- ch = *format++;
- break;
- default:
- state = DP_S_MIN;
- break;
- }
- break;
- case DP_S_MIN:
- if (isdigit((unsigned char)ch)) {
- min = 10 * min + char_to_int(ch);
- ch = *format++;
- } else if (ch == '*') {
- min = va_arg(args, int);
- ch = *format++;
- state = DP_S_DOT;
- } else
- state = DP_S_DOT;
- break;
- case DP_S_DOT:
- if (ch == '.') {
- state = DP_S_MAX;
- ch = *format++;
- } else
- state = DP_S_MOD;
- break;
- case DP_S_MAX:
- if (isdigit((unsigned char)ch)) {
- if (max < 0)
- max = 0;
- max = 10 * max + char_to_int(ch);
- ch = *format++;
- } else if (ch == '*') {
- max = va_arg(args, int);
- ch = *format++;
- state = DP_S_MOD;
- } else
- state = DP_S_MOD;
- break;
- case DP_S_MOD:
- switch (ch) {
- case 'h':
- cflags = DP_C_SHORT;
- ch = *format++;
- break;
- case 'l':
- if (*format == 'l') {
- cflags = DP_C_LLONG;
- format++;
- } else
- cflags = DP_C_LONG;
- ch = *format++;
- break;
- case 'q':
- cflags = DP_C_LLONG;
- ch = *format++;
- break;
- case 'L':
- cflags = DP_C_LDOUBLE;
- ch = *format++;
- break;
- default:
- break;
- }
- state = DP_S_CONV;
- break;
- case DP_S_CONV:
- switch (ch) {
- case 'd':
- case 'i':
- switch (cflags) {
- case DP_C_SHORT:
- value = (short int)va_arg(args, int);
- break;
- case DP_C_LONG:
- value = va_arg(args, long int);
- break;
- case DP_C_LLONG:
- value = va_arg(args, LLONG);
- break;
- default:
- value = va_arg(args, int);
- break;
- }
- fmtint(sbuffer, buffer, &currlen, maxlen,
- value, 10, min, max, flags);
- break;
- case 'X':
- flags |= DP_F_UP;
- /* FALLTHROUGH */
- case 'x':
- case 'o':
- case 'u':
- flags |= DP_F_UNSIGNED;
- switch (cflags) {
- case DP_C_SHORT:
- value = (unsigned short int)va_arg(args, unsigned int);
- break;
- case DP_C_LONG:
- value = (LLONG) va_arg(args,
- unsigned long int);
- break;
- case DP_C_LLONG:
- value = va_arg(args, unsigned LLONG);
- break;
- default:
- value = (LLONG) va_arg(args,
- unsigned int);
- break;
- }
- fmtint(sbuffer, buffer, &currlen, maxlen, value,
- ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),
- min, max, flags);
- break;
- case 'f':
- if (cflags == DP_C_LDOUBLE)
- fvalue = va_arg(args, LDOUBLE);
- else
- fvalue = va_arg(args, double);
- fmtfp(sbuffer, buffer, &currlen, maxlen,
- fvalue, min, max, flags);
- break;
- case 'E':
- flags |= DP_F_UP;
- case 'e':
- if (cflags == DP_C_LDOUBLE)
- fvalue = va_arg(args, LDOUBLE);
- else
- fvalue = va_arg(args, double);
- break;
- case 'G':
- flags |= DP_F_UP;
- case 'g':
- if (cflags == DP_C_LDOUBLE)
- fvalue = va_arg(args, LDOUBLE);
- else
- fvalue = va_arg(args, double);
- break;
- case 'c':
- doapr_outch(sbuffer, buffer, &currlen, maxlen,
- va_arg(args, int));
- break;
- case 's':
- strvalue = va_arg(args, char *);
- if (max < 0) {
- if (buffer)
- max = INT_MAX;
- else
- max = *maxlen;
+ char ch;
+ LLONG value;
+ LDOUBLE fvalue;
+ char *strvalue;
+ int min;
+ int max;
+ int state;
+ int flags;
+ int cflags;
+ size_t currlen;
+
+ state = DP_S_DEFAULT;
+ flags = currlen = cflags = min = 0;
+ max = -1;
+ ch = *format++;
+
+ while (state != DP_S_DONE) {
+ if (ch == '\0' || (buffer == NULL && currlen >= *maxlen))
+ state = DP_S_DONE;
+
+ switch (state) {
+ case DP_S_DEFAULT:
+ if (ch == '%')
+ state = DP_S_FLAGS;
+ else
+ doapr_outch(sbuffer, buffer, &currlen, maxlen, ch);
+ ch = *format++;
+ break;
+ case DP_S_FLAGS:
+ switch (ch) {
+ case '-':
+ flags |= DP_F_MINUS;
+ ch = *format++;
+ break;
+ case '+':
+ flags |= DP_F_PLUS;
+ ch = *format++;
+ break;
+ case ' ':
+ flags |= DP_F_SPACE;
+ ch = *format++;
+ break;
+ case '#':
+ flags |= DP_F_NUM;
+ ch = *format++;
+ break;
+ case '0':
+ flags |= DP_F_ZERO;
+ ch = *format++;
+ break;
+ default:
+ state = DP_S_MIN;
+ break;
+ }
+ break;
+ case DP_S_MIN:
+ if (isdigit((unsigned char)ch)) {
+ min = 10 * min + char_to_int(ch);
+ ch = *format++;
+ } else if (ch == '*') {
+ min = va_arg(args, int);
+ ch = *format++;
+ state = DP_S_DOT;
+ } else
+ state = DP_S_DOT;
+ break;
+ case DP_S_DOT:
+ if (ch == '.') {
+ state = DP_S_MAX;
+ ch = *format++;
+ } else
+ state = DP_S_MOD;
+ break;
+ case DP_S_MAX:
+ if (isdigit((unsigned char)ch)) {
+ if (max < 0)
+ max = 0;
+ max = 10 * max + char_to_int(ch);
+ ch = *format++;
+ } else if (ch == '*') {
+ max = va_arg(args, int);
+ ch = *format++;
+ state = DP_S_MOD;
+ } else
+ state = DP_S_MOD;
+ break;
+ case DP_S_MOD:
+ switch (ch) {
+ case 'h':
+ cflags = DP_C_SHORT;
+ ch = *format++;
+ break;
+ case 'l':
+ if (*format == 'l') {
+ cflags = DP_C_LLONG;
+ format++;
+ } else
+ cflags = DP_C_LONG;
+ ch = *format++;
+ break;
+ case 'q':
+ cflags = DP_C_LLONG;
+ ch = *format++;
+ break;
+ case 'L':
+ cflags = DP_C_LDOUBLE;
+ ch = *format++;
+ break;
+ default:
+ break;
+ }
+ state = DP_S_CONV;
+ break;
+ case DP_S_CONV:
+ switch (ch) {
+ case 'd':
+ case 'i':
+ switch (cflags) {
+ case DP_C_SHORT:
+ value = (short int)va_arg(args, int);
+ break;
+ case DP_C_LONG:
+ value = va_arg(args, long int);
+ break;
+ case DP_C_LLONG:
+ value = va_arg(args, LLONG);
+ break;
+ default:
+ value = va_arg(args, int);
+ break;
+ }
+ fmtint(sbuffer, buffer, &currlen, maxlen,
+ value, 10, min, max, flags);
+ break;
+ case 'X':
+ flags |= DP_F_UP;
+ /* FALLTHROUGH */
+ case 'x':
+ case 'o':
+ case 'u':
+ flags |= DP_F_UNSIGNED;
+ switch (cflags) {
+ case DP_C_SHORT:
+ value = (unsigned short int)va_arg(
+ args, unsigned int);
+ break;
+ case DP_C_LONG:
+ value = (LLONG)va_arg(args,
+ unsigned long int);
+ break;
+ case DP_C_LLONG:
+ value = va_arg(args, unsigned LLONG);
+ break;
+ default:
+ value = (LLONG)va_arg(args,
+ unsigned int);
+ break;
+ }
+ fmtint(sbuffer, buffer, &currlen, maxlen, value,
+ ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),
+ min, max, flags);
+ break;
+ case 'f':
+ if (cflags == DP_C_LDOUBLE)
+ fvalue = va_arg(args, LDOUBLE);
+ else
+ fvalue = va_arg(args, double);
+ fmtfp(sbuffer, buffer, &currlen, maxlen,
+ fvalue, min, max, flags);
+ break;
+ case 'E':
+ flags |= DP_F_UP;
+ case 'e':
+ if (cflags == DP_C_LDOUBLE)
+ fvalue = va_arg(args, LDOUBLE);
+ else
+ fvalue = va_arg(args, double);
+ break;
+ case 'G':
+ flags |= DP_F_UP;
+ case 'g':
+ if (cflags == DP_C_LDOUBLE)
+ fvalue = va_arg(args, LDOUBLE);
+ else
+ fvalue = va_arg(args, double);
+ break;
+ case 'c':
+ doapr_outch(sbuffer, buffer, &currlen, maxlen,
+ va_arg(args, int));
+ break;
+ case 's':
+ strvalue = va_arg(args, char *);
+ if (max < 0) {
+ if (buffer)
+ max = INT_MAX;
+ else
+ max = *maxlen;
+ }
+ fmtstr(sbuffer, buffer, &currlen, maxlen,
+ strvalue, flags, min, max);
+ break;
+ case 'p':
+ value = (long)va_arg(args, void *);
+ fmtint(sbuffer, buffer, &currlen, maxlen,
+ value, 16, min, max, flags|DP_F_NUM);
+ break;
+ case 'n': /* XXX */
+ if (cflags == DP_C_SHORT) {
+ short int *num;
+ num = va_arg(args, short int *);
+ *num = currlen;
+ } else if (cflags == DP_C_LONG) { /* XXX */
+ long int *num;
+ num = va_arg(args, long int *);
+ *num = (long int) currlen;
+ } else if (cflags == DP_C_LLONG) { /* XXX */
+ LLONG *num;
+ num = va_arg(args, LLONG *);
+ *num = (LLONG) currlen;
+ } else {
+ int *num;
+ num = va_arg(args, int *);
+ *num = currlen;
+ }
+ break;
+ case '%':
+ doapr_outch(sbuffer, buffer, &currlen, maxlen, ch);
+ break;
+ case 'w':
+ /* not supported yet, treat as next char */
+ ch = *format++;
+ break;
+ default:
+ /* unknown, skip */
+ break;
+ }
+ ch = *format++;
+ state = DP_S_DEFAULT;
+ flags = cflags = min = 0;
+ max = -1;
+ break;
+ case DP_S_DONE:
+ break;
+ default:
+ break;
}
- fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,
- flags, min, max);
- break;
- case 'p':
- value = (long)va_arg(args, void *);
- fmtint(sbuffer, buffer, &currlen, maxlen,
- value, 16, min, max, flags|DP_F_NUM);
- break;
- case 'n': /* XXX */
- if (cflags == DP_C_SHORT) {
- short int *num;
- num = va_arg(args, short int *);
- *num = currlen;
- } else if (cflags == DP_C_LONG) { /* XXX */
- long int *num;
- num = va_arg(args, long int *);
- *num = (long int) currlen;
- } else if (cflags == DP_C_LLONG) { /* XXX */
- LLONG *num;
- num = va_arg(args, LLONG *);
- *num = (LLONG) currlen;
- } else {
- int *num;
- num = va_arg(args, int *);
- *num = currlen;
- }
- break;
- case '%':
- doapr_outch(sbuffer, buffer, &currlen, maxlen, ch);
- break;
- case 'w':
- /* not supported yet, treat as next char */
- ch = *format++;
- break;
- default:
- /* unknown, skip */
- break;
- }
- ch = *format++;
- state = DP_S_DEFAULT;
- flags = cflags = min = 0;
- max = -1;
- break;
- case DP_S_DONE:
- break;
- default:
- break;
- }
- }
- *truncated = (currlen > *maxlen - 1);
- if (*truncated)
- currlen = *maxlen - 1;
- doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0');
- *retlen = currlen - 1;
- return;
+ }
+ *truncated = (currlen > *maxlen - 1);
+ if (*truncated)
+ currlen = *maxlen - 1;
+ doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0');
+ *retlen = currlen - 1;
+ return;
}
static void
-fmtstr(
- char **sbuffer,
- char **buffer,
- size_t *currlen,
- size_t *maxlen,
- const char *value,
- int flags,
- int min,
- int max)
+fmtstr(char **sbuffer, char **buffer, size_t *currlen, size_t *maxlen,
+ const char *value, int flags, int min, int max)
{
- int padlen, strln;
- int cnt = 0;
-
- if (value == 0)
- value = "<NULL>";
- for (strln = 0; value[strln]; ++strln)
- ;
- padlen = min - strln;
- if (padlen < 0)
- padlen = 0;
- if (flags & DP_F_MINUS)
- padlen = -padlen;
-
- while ((padlen > 0) && (cnt < max)) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
- --padlen;
- ++cnt;
- }
- while (*value && (cnt < max)) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, *value++);
- ++cnt;
- }
- while ((padlen < 0) && (cnt < max)) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
- ++padlen;
- ++cnt;
- }
+ int padlen, strln;
+ int cnt = 0;
+
+ if (value == 0)
+ value = "<NULL>";
+ for (strln = 0; value[strln]; ++strln)
+ ;
+ padlen = min - strln;
+ if (padlen < 0)
+ padlen = 0;
+ if (flags & DP_F_MINUS)
+ padlen = -padlen;
+
+ while ((padlen > 0) && (cnt < max)) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
+ --padlen;
+ ++cnt;
+ }
+ while (*value && (cnt < max)) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, *value++);
+ ++cnt;
+ }
+ while ((padlen < 0) && (cnt < max)) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
+ ++padlen;
+ ++cnt;
+ }
}
static void
-fmtint(
- char **sbuffer,
- char **buffer,
- size_t *currlen,
- size_t *maxlen,
- LLONG value,
- int base,
- int min,
- int max,
- int flags)
+fmtint(char **sbuffer, char **buffer, size_t *currlen, size_t *maxlen,
+ LLONG value, int base, int min, int max, int flags)
{
- int signvalue = 0;
- const char *prefix = "";
- unsigned LLONG uvalue;
- char convert[DECIMAL_SIZE(value)+3];
- int place = 0;
- int spadlen = 0;
- int zpadlen = 0;
- int caps = 0;
-
- if (max < 0)
- max = 0;
- uvalue = value;
- if (!(flags & DP_F_UNSIGNED)) {
- if (value < 0) {
- signvalue = '-';
- uvalue = -value;
- } else if (flags & DP_F_PLUS)
- signvalue = '+';
- else if (flags & DP_F_SPACE)
- signvalue = ' ';
- }
- if (flags & DP_F_NUM) {
- if (base == 8) prefix = "0";
- if (base == 16) prefix = "0x";
- }
- if (flags & DP_F_UP)
- caps = 1;
- do {
- convert[place++] =
- (caps ? "0123456789ABCDEF" : "0123456789abcdef")
- [uvalue % (unsigned) base];
- uvalue = (uvalue / (unsigned) base);
- } while (uvalue && (place < (int)sizeof(convert)));
- if (place == sizeof(convert))
- place--;
- convert[place] = 0;
-
- zpadlen = max - place;
- spadlen = min - OSSL_MAX(max, place) - (signvalue ? 1 : 0) - strlen(prefix);
- if (zpadlen < 0)
- zpadlen = 0;
- if (spadlen < 0)
- spadlen = 0;
- if (flags & DP_F_ZERO) {
- zpadlen = OSSL_MAX(zpadlen, spadlen);
- spadlen = 0;
- }
- if (flags & DP_F_MINUS)
- spadlen = -spadlen;
-
- /* spaces */
- while (spadlen > 0) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
- --spadlen;
- }
-
- /* sign */
- if (signvalue)
- doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
-
- /* prefix */
- while (*prefix) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, *prefix);
- prefix++;
- }
-
- /* zeros */
- if (zpadlen > 0) {
- while (zpadlen > 0) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
- --zpadlen;
- }
- }
- /* digits */
- while (place > 0)
- doapr_outch(sbuffer, buffer, currlen, maxlen, convert[--place]);
-
- /* left justified spaces */
- while (spadlen < 0) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
- ++spadlen;
- }
- return;
+ int signvalue = 0;
+ const char *prefix = "";
+ unsigned LLONG uvalue;
+ char convert[DECIMAL_SIZE(value) + 3];
+ int place = 0;
+ int spadlen = 0;
+ int zpadlen = 0;
+ int caps = 0;
+
+ if (max < 0)
+ max = 0;
+ uvalue = value;
+ if (!(flags & DP_F_UNSIGNED)) {
+ if (value < 0) {
+ signvalue = '-';
+ uvalue = -value;
+ } else if (flags & DP_F_PLUS)
+ signvalue = '+';
+ else if (flags & DP_F_SPACE)
+ signvalue = ' ';
+ }
+ if (flags & DP_F_NUM) {
+ if (base == 8)
+ prefix = "0";
+ if (base == 16)
+ prefix = "0x";
+ }
+ if (flags & DP_F_UP)
+ caps = 1;
+ do {
+ convert[place++] = (caps ? "0123456789ABCDEF" :
+ "0123456789abcdef")[uvalue % (unsigned) base];
+ uvalue = (uvalue / (unsigned) base);
+ } while (uvalue && (place < (int)sizeof(convert)));
+ if (place == sizeof(convert))
+ place--;
+ convert[place] = 0;
+
+ zpadlen = max - place;
+ spadlen = min - OSSL_MAX(max, place) - (signvalue ? 1 : 0) -
+ strlen(prefix);
+ if (zpadlen < 0)
+ zpadlen = 0;
+ if (spadlen < 0)
+ spadlen = 0;
+ if (flags & DP_F_ZERO) {
+ zpadlen = OSSL_MAX(zpadlen, spadlen);
+ spadlen = 0;
+ }
+ if (flags & DP_F_MINUS)
+ spadlen = -spadlen;
+
+ /* spaces */
+ while (spadlen > 0) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
+ --spadlen;
+ }
+
+ /* sign */
+ if (signvalue)
+ doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
+
+ /* prefix */
+ while (*prefix) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, *prefix);
+ prefix++;
+ }
+
+ /* zeros */
+ if (zpadlen > 0) {
+ while (zpadlen > 0) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
+ --zpadlen;
+ }
+ }
+ /* digits */
+ while (place > 0)
+ doapr_outch(sbuffer, buffer, currlen, maxlen, convert[--place]);
+
+ /* left justified spaces */
+ while (spadlen < 0) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
+ ++spadlen;
+ }
+ return;
}
static LDOUBLE
abs_val(LDOUBLE value)
{
- LDOUBLE result = value;
- if (value < 0)
- result = -value;
- return result;
+ LDOUBLE result = value;
+ if (value < 0)
+ result = -value;
+ return result;
}
static LDOUBLE
pow_10(int in_exp)
{
- LDOUBLE result = 1;
- while (in_exp) {
- result *= 10;
- in_exp--;
- }
- return result;
+ LDOUBLE result = 1;
+ while (in_exp) {
+ result *= 10;
+ in_exp--;
+ }
+ return result;
}
static long
roundv(LDOUBLE value)
{
- long intpart;
- intpart = (long) value;
- value = value - intpart;
- if (value >= 0.5)
- intpart++;
- return intpart;
+ long intpart;
+ intpart = (long) value;
+ value = value - intpart;
+ if (value >= 0.5)
+ intpart++;
+ return intpart;
}
static void
-fmtfp(
- char **sbuffer,
- char **buffer,
- size_t *currlen,
- size_t *maxlen,
- LDOUBLE fvalue,
- int min,
- int max,
- int flags)
+fmtfp(char **sbuffer, char **buffer, size_t *currlen, size_t *maxlen,
+ LDOUBLE fvalue, int min, int max, int flags)
{
- int signvalue = 0;
- LDOUBLE ufvalue;
- char iconvert[20];
- char fconvert[20];
- int iplace = 0;
- int fplace = 0;
- int padlen = 0;
- int zpadlen = 0;
- int caps = 0;
- long intpart;
- long fracpart;
- long max10;
-
- if (max < 0)
- max = 6;
- ufvalue = abs_val(fvalue);
- if (fvalue < 0)
- signvalue = '-';
- else if (flags & DP_F_PLUS)
- signvalue = '+';
- else if (flags & DP_F_SPACE)
- signvalue = ' ';
-
- intpart = (long)ufvalue;
-
- /* sorry, we only support 9 digits past the decimal because of our
- conversion method */
- if (max > 9)
- max = 9;
-
- /* we "cheat" by converting the fractional part to integer by
- multiplying by a factor of 10 */
- max10 = roundv(pow_10(max));
- fracpart = roundv(pow_10(max) * (ufvalue - intpart));
-
- if (fracpart >= max10) {
- intpart++;
- fracpart -= max10;
- }
-
- /* convert integer part */
- do {
- iconvert[iplace++] =
- (caps ? "0123456789ABCDEF"
- : "0123456789abcdef")[intpart % 10];
- intpart = (intpart / 10);
- } while (intpart && (iplace < (int)sizeof(iconvert)));
- if (iplace == sizeof iconvert)
- iplace--;
- iconvert[iplace] = 0;
-
- /* convert fractional part */
- do {
- fconvert[fplace++] =
- (caps ? "0123456789ABCDEF"
- : "0123456789abcdef")[fracpart % 10];
- fracpart = (fracpart / 10);
- } while (fplace < max);
- if (fplace == sizeof fconvert)
- fplace--;
- fconvert[fplace] = 0;
-
- /* -1 for decimal point, another -1 if we are printing a sign */
- padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
- zpadlen = max - fplace;
- if (zpadlen < 0)
- zpadlen = 0;
- if (padlen < 0)
- padlen = 0;
- if (flags & DP_F_MINUS)
- padlen = -padlen;
-
- if ((flags & DP_F_ZERO) && (padlen > 0)) {
- if (signvalue) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
- --padlen;
- signvalue = 0;
- }
- while (padlen > 0) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
- --padlen;
- }
- }
- while (padlen > 0) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
- --padlen;
- }
- if (signvalue)
- doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
-
- while (iplace > 0)
- doapr_outch(sbuffer, buffer, currlen, maxlen, iconvert[--iplace]);
-
- /*
- * Decimal point. This should probably use locale to find the correct
- * char to print out.
- */
- if (max > 0 || (flags & DP_F_NUM)) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, '.');
-
- while (fplace > 0)
- doapr_outch(sbuffer, buffer, currlen, maxlen, fconvert[--fplace]);
- }
- while (zpadlen > 0) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
- --zpadlen;
- }
-
- while (padlen < 0) {
- doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
- ++padlen;
- }
+ int signvalue = 0;
+ LDOUBLE ufvalue;
+ char iconvert[20];
+ char fconvert[20];
+ int iplace = 0;
+ int fplace = 0;
+ int padlen = 0;
+ int zpadlen = 0;
+ int caps = 0;
+ long intpart;
+ long fracpart;
+ long max10;
+
+ if (max < 0)
+ max = 6;
+ ufvalue = abs_val(fvalue);
+ if (fvalue < 0)
+ signvalue = '-';
+ else if (flags & DP_F_PLUS)
+ signvalue = '+';
+ else if (flags & DP_F_SPACE)
+ signvalue = ' ';
+
+ intpart = (long)ufvalue;
+
+ /* sorry, we only support 9 digits past the decimal because of our
+ conversion method */
+ if (max > 9)
+ max = 9;
+
+ /* we "cheat" by converting the fractional part to integer by
+ multiplying by a factor of 10 */
+ max10 = roundv(pow_10(max));
+ fracpart = roundv(pow_10(max) * (ufvalue - intpart));
+
+ if (fracpart >= max10) {
+ intpart++;
+ fracpart -= max10;
+ }
+
+ /* convert integer part */
+ do {
+ iconvert[iplace++] = (caps ? "0123456789ABCDEF" :
+ "0123456789abcdef")[intpart % 10];
+ intpart = (intpart / 10);
+ } while (intpart && (iplace < (int)sizeof(iconvert)));
+ if (iplace == sizeof iconvert)
+ iplace--;
+ iconvert[iplace] = 0;
+
+ /* convert fractional part */
+ do {
+ fconvert[fplace++] = (caps ? "0123456789ABCDEF" :
+ "0123456789abcdef")[fracpart % 10];
+ fracpart = (fracpart / 10);
+ } while (fplace < max);
+ if (fplace == sizeof fconvert)
+ fplace--;
+ fconvert[fplace] = 0;
+
+ /* -1 for decimal point, another -1 if we are printing a sign */
+ padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
+ zpadlen = max - fplace;
+ if (zpadlen < 0)
+ zpadlen = 0;
+ if (padlen < 0)
+ padlen = 0;
+ if (flags & DP_F_MINUS)
+ padlen = -padlen;
+
+ if ((flags & DP_F_ZERO) && (padlen > 0)) {
+ if (signvalue) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
+ --padlen;
+ signvalue = 0;
+ }
+ while (padlen > 0) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
+ --padlen;
+ }
+ }
+ while (padlen > 0) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
+ --padlen;
+ }
+ if (signvalue)
+ doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue);
+
+ while (iplace > 0)
+ doapr_outch(sbuffer, buffer, currlen, maxlen, iconvert[--iplace]);
+
+ /*
+ * Decimal point. This should probably use locale to find the correct
+ * char to print out.
+ */
+ if (max > 0 || (flags & DP_F_NUM)) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, '.');
+
+ while (fplace > 0)
+ doapr_outch(sbuffer, buffer, currlen, maxlen, fconvert[--fplace]);
+ }
+ while (zpadlen > 0) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, '0');
+ --zpadlen;
+ }
+
+ while (padlen < 0) {
+ doapr_outch(sbuffer, buffer, currlen, maxlen, ' ');
+ ++padlen;
+ }
}
static void
-doapr_outch(
- char **sbuffer,
- char **buffer,
- size_t *currlen,
- size_t *maxlen,
+doapr_outch(char **sbuffer, char **buffer, size_t *currlen, size_t *maxlen,
int c)
{
- /* If we haven't at least one buffer, someone has doe a big booboo */
- assert(*sbuffer != NULL || buffer != NULL);
-
- if (buffer) {
- while (*currlen >= *maxlen) {
- if (*buffer == NULL) {
- if (*maxlen == 0)
- *maxlen = 1024;
- *buffer = OPENSSL_malloc(*maxlen);
- if (*currlen > 0) {
- assert(*sbuffer != NULL);
- memcpy(*buffer, *sbuffer, *currlen);
+ /* If we haven't at least one buffer, someone has doe a big booboo */
+ assert(*sbuffer != NULL || buffer != NULL);
+
+ if (buffer) {
+ while (*currlen >= *maxlen) {
+ if (*buffer == NULL) {
+ if (*maxlen == 0)
+ *maxlen = 1024;
+ *buffer = OPENSSL_malloc(*maxlen);
+ if (*currlen > 0) {
+ assert(*sbuffer != NULL);
+ memcpy(*buffer, *sbuffer, *currlen);
+ }
+ *sbuffer = NULL;
+ } else {
+ *maxlen += 1024;
+ *buffer = OPENSSL_realloc(*buffer, *maxlen);
+ }
}
- *sbuffer = NULL;
- } else {
- *maxlen += 1024;
- *buffer = OPENSSL_realloc(*buffer, *maxlen);
- }
+ /* What to do if *buffer is NULL? */
+ assert(*sbuffer != NULL || *buffer != NULL);
}
- /* What to do if *buffer is NULL? */
- assert(*sbuffer != NULL || *buffer != NULL);
- }
- if (*currlen < *maxlen) {
- if (*sbuffer)
- (*sbuffer)[(*currlen)++] = (char)c;
- else
- (*buffer)[(*currlen)++] = (char)c;
- }
+ if (*currlen < *maxlen) {
+ if (*sbuffer)
+ (*sbuffer)[(*currlen)++] = (char)c;
+ else
+ (*buffer)[(*currlen)++] = (char)c;
+ }
- return;
+ return;
}
/***************************************************************************/
int BIO_printf (BIO *bio, const char *format, ...)
- {
+{
va_list args;
int ret;
ret = BIO_vprintf(bio, format, args);
va_end(args);
- return(ret);
- }
+ return (ret);
+}
int BIO_vprintf (BIO *bio, const char *format, va_list args)
- {
+{
int ret;
size_t retlen;
char hugebuf[1024*2]; /* Was previously 10k, which is unreasonable
- in small-stack environments, like threads
+ in small - stack environments, like threads
or DOS programs. */
char *hugebufp = hugebuf;
size_t hugebufsize = sizeof(hugebuf);
dynbuf = NULL;
CRYPTO_push_info("doapr()");
- _dopr(&hugebufp, &dynbuf, &hugebufsize,
- &retlen, &ignored, format, args);
- if (dynbuf)
- {
- ret=BIO_write(bio, dynbuf, (int)retlen);
+ _dopr(&hugebufp, &dynbuf, &hugebufsize, &retlen, &ignored,
+ format, args);
+ if (dynbuf) {
+ ret = BIO_write(bio, dynbuf, (int)retlen);
OPENSSL_free(dynbuf);
- }
- else
- {
- ret=BIO_write(bio, hugebuf, (int)retlen);
- }
- CRYPTO_pop_info();
- return(ret);
+ } else {
+ ret = BIO_write(bio, hugebuf, (int)retlen);
}
+ CRYPTO_pop_info();
+ return (ret);
+}
/* As snprintf is not available everywhere, we provide our own implementation.
* This function has nothing to do with BIOs, but it's closely related
* to BIO_printf, and we need *some* name prefix ...
* (XXX the function should be renamed, but to what?) */
-int BIO_snprintf(char *buf, size_t n, const char *format, ...)
- {
+int
+BIO_snprintf(char *buf, size_t n, const char *format, ...)
+{
va_list args;
int ret;
ret = BIO_vsnprintf(buf, n, format, args);
va_end(args);
- return(ret);
- }
+ return (ret);
+}
-int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
- {
+int
+BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
+{
size_t retlen;
int truncated;
return -1;
else
return (retlen <= INT_MAX) ? (int)retlen : -1;
- }
+}
#endif
#if defined(OPENSSL_SYS_WINDOWS) || (defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK))
-static int wsa_init_done=0;
+static int wsa_init_done = 0;
#endif
/*
#endif
#if 0
-static unsigned long BIO_ghbn_hits=0L;
-static unsigned long BIO_ghbn_miss=0L;
+static unsigned long BIO_ghbn_hits = 0L;
+static unsigned long BIO_ghbn_miss = 0L;
#define GHBN_NUM 4
-static struct ghbn_cache_st
- {
+static struct ghbn_cache_st {
char name[129];
struct hostent *ent;
unsigned long order;
- } ghbn_cache[GHBN_NUM];
+} ghbn_cache[GHBN_NUM];
#endif
-static int get_ip(const char *str,unsigned char *ip);
+static int get_ip(const char *str, unsigned char *ip);
#if 0
static void ghbn_free(struct hostent *a);
static struct hostent *ghbn_dup(struct hostent *a);
#endif
-int BIO_get_host_ip(const char *str, unsigned char *ip)
- {
+
+int
+BIO_get_host_ip(const char *str, unsigned char *ip)
+{
int i;
int err = 1;
int locked = 0;
struct hostent *he;
- i=get_ip(str,ip);
- if (i < 0)
- {
- BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_INVALID_IP_ADDRESS);
+ i = get_ip(str, ip);
+ if (i < 0) {
+ BIOerr(BIO_F_BIO_GET_HOST_IP, BIO_R_INVALID_IP_ADDRESS);
goto err;
- }
+ }
/* At this point, we have something that is most probably correct
in some way, so let's init the socket. */
/* If the string actually contained an IP address, we need not do
anything more */
- if (i > 0) return(1);
+ if (i > 0)
+ return (1);
/* do a gethostbyname */
CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
locked = 1;
- he=BIO_gethostbyname(str);
- if (he == NULL)
- {
- BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_BAD_HOSTNAME_LOOKUP);
+ he = BIO_gethostbyname(str);
+ if (he == NULL) {
+ BIOerr(BIO_F_BIO_GET_HOST_IP, BIO_R_BAD_HOSTNAME_LOOKUP);
goto err;
- }
+ }
/* cast to short because of win16 winsock definition */
- if ((short)he->h_addrtype != AF_INET)
- {
- BIOerr(BIO_F_BIO_GET_HOST_IP,BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET);
+ if ((short)he->h_addrtype != AF_INET) {
+ BIOerr(BIO_F_BIO_GET_HOST_IP, BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET);
goto err;
- }
- for (i=0; i<4; i++)
- ip[i]=he->h_addr_list[0][i];
+ }
+ for (i = 0; i < 4; i++)
+ ip[i] = he->h_addr_list[0][i];
err = 0;
- err:
+err:
if (locked)
CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
- if (err)
- {
- ERR_add_error_data(2,"host=",str);
+ if (err) {
+ ERR_add_error_data(2, "host=", str);
return 0;
- }
- else
+ } else
return 1;
- }
+}
-int BIO_get_port(const char *str, unsigned short *port_ptr)
- {
+int
+BIO_get_port(const char *str, unsigned short *port_ptr)
+{
int i;
struct servent *s;
- if (str == NULL)
- {
- BIOerr(BIO_F_BIO_GET_PORT,BIO_R_NO_PORT_DEFINED);
- return(0);
- }
- i=atoi(str);
+ if (str == NULL) {
+ BIOerr(BIO_F_BIO_GET_PORT, BIO_R_NO_PORT_DEFINED);
+ return (0);
+ }
+ i = atoi(str);
if (i != 0)
- *port_ptr=(unsigned short)i;
- else
- {
+ *port_ptr = (unsigned short)i;
+ else {
CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME);
/* Note: under VMS with SOCKETSHR, it seems like the first
* parameter is 'char *', instead of 'const char *'
*/
#ifndef CONST_STRICT
- s=getservbyname((char *)str,"tcp");
+ s = getservbyname((char *)str, "tcp");
#else
- s=getservbyname(str,"tcp");
+ s = getservbyname(str, "tcp");
#endif
- if(s != NULL)
- *port_ptr=ntohs((unsigned short)s->s_port);
+ if (s != NULL)
+ *port_ptr = ntohs((unsigned short)s->s_port);
CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME);
- if(s == NULL)
- {
- if (strcmp(str,"http") == 0)
- *port_ptr=80;
- else if (strcmp(str,"telnet") == 0)
- *port_ptr=23;
- else if (strcmp(str,"socks") == 0)
- *port_ptr=1080;
- else if (strcmp(str,"https") == 0)
- *port_ptr=443;
- else if (strcmp(str,"ssl") == 0)
- *port_ptr=443;
- else if (strcmp(str,"ftp") == 0)
- *port_ptr=21;
- else if (strcmp(str,"gopher") == 0)
- *port_ptr=70;
+ if (s == NULL) {
+ if (strcmp(str, "http") == 0)
+ *port_ptr = 80;
+ else if (strcmp(str, "telnet") == 0)
+ *port_ptr = 23;
+ else if (strcmp(str, "socks") == 0)
+ *port_ptr = 1080;
+ else if (strcmp(str, "https") == 0)
+ *port_ptr = 443;
+ else if (strcmp(str, "ssl") == 0)
+ *port_ptr = 443;
+ else if (strcmp(str, "ftp") == 0)
+ *port_ptr = 21;
+ else if (strcmp(str, "gopher") == 0)
+ *port_ptr = 70;
#if 0
- else if (strcmp(str,"wais") == 0)
- *port_ptr=21;
-#endif
- else
- {
- SYSerr(SYS_F_GETSERVBYNAME,errno);
- ERR_add_error_data(3,"service='",str,"'");
- return(0);
- }
+ else if (strcmp(str, "wais") == 0)
+ *port_ptr = 21;
+#endif
+ else {
+ SYSerr(SYS_F_GETSERVBYNAME, errno);
+ ERR_add_error_data(3, "service = '", str, "'");
+ return (0);
}
}
- return(1);
}
+ return (1);
+}
-int BIO_sock_error(int sock)
- {
- int j,i;
+int
+BIO_sock_error(int sock)
+{
+ int j, i;
int size;
-
+
#if defined(OPENSSL_SYS_BEOS_R5)
return 0;
#endif
-
- size=sizeof(int);
+
+ size = sizeof(int);
/* Note: under Windows the third parameter is of type (char *)
* whereas under other systems it is (void *) if you don't have
* a cast it will choke the compiler: if you do have a cast then
* you can either go for (char *) or (void *).
*/
- i=getsockopt(sock,SOL_SOCKET,SO_ERROR,(void *)&j,(void *)&size);
+ i = getsockopt(sock, SOL_SOCKET, SO_ERROR,(void *)&j,(void *)&size);
if (i < 0)
- return(1);
+ return (1);
else
- return(j);
- }
+ return (j);
+}
#if 0
-long BIO_ghbn_ctrl(int cmd, int iarg, char *parg)
- {
+long
+BIO_ghbn_ctrl(int cmd, int iarg, char *parg)
+{
int i;
char **p;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_GHBN_CTRL_HITS:
- return(BIO_ghbn_hits);
+ return (BIO_ghbn_hits);
/* break; */
case BIO_GHBN_CTRL_MISSES:
- return(BIO_ghbn_miss);
+ return (BIO_ghbn_miss);
/* break; */
case BIO_GHBN_CTRL_CACHE_SIZE:
- return(GHBN_NUM);
+ return (GHBN_NUM);
/* break; */
case BIO_GHBN_CTRL_GET_ENTRY:
- if ((iarg >= 0) && (iarg <GHBN_NUM) &&
- (ghbn_cache[iarg].order > 0))
- {
- p=(char **)parg;
- if (p == NULL) return(0);
- *p=ghbn_cache[iarg].name;
- ghbn_cache[iarg].name[128]='\0';
- return(1);
- }
- return(0);
+ if ((iarg >= 0) && (iarg < GHBN_NUM) &&
+ (ghbn_cache[iarg].order > 0)) {
+ p = (char **)parg;
+ if (p == NULL)
+ return (0);
+ *p = ghbn_cache[iarg].name;
+ ghbn_cache[iarg].name[128] = '\0';
+ return (1);
+ }
+ return (0);
/* break; */
case BIO_GHBN_CTRL_FLUSH:
- for (i=0; i<GHBN_NUM; i++)
- ghbn_cache[i].order=0;
+ for (i = 0; i < GHBN_NUM; i++)
+ ghbn_cache[i].order = 0;
break;
default:
- return(0);
- }
- return(1);
+ return (0);
}
+ return (1);
+}
#endif
#if 0
-static struct hostent *ghbn_dup(struct hostent *a)
- {
+static struct hostent
+*ghbn_dup(struct hostent *a)
+{
struct hostent *ret;
- int i,j;
+ int i, j;
MemCheck_off();
- ret=(struct hostent *)OPENSSL_malloc(sizeof(struct hostent));
- if (ret == NULL) return(NULL);
- memset(ret,0,sizeof(struct hostent));
+ ret = (struct hostent *)OPENSSL_malloc(sizeof(struct hostent));
+ if (ret == NULL)
+ return (NULL);
+ memset(ret, 0, sizeof(struct hostent));
- for (i=0; a->h_aliases[i] != NULL; i++)
+ for (i = 0; a->h_aliases[i] != NULL; i++)
;
i++;
ret->h_aliases = (char **)OPENSSL_malloc(i*sizeof(char *));
goto err;
memset(ret->h_aliases, 0, i*sizeof(char *));
- for (i=0; a->h_addr_list[i] != NULL; i++)
+ for (i = 0; a->h_addr_list[i] != NULL; i++)
;
i++;
- ret->h_addr_list=(char **)OPENSSL_malloc(i*sizeof(char *));
+ ret->h_addr_list = (char **)OPENSSL_malloc(i*sizeof(char *));
if (ret->h_addr_list == NULL)
goto err;
memset(ret->h_addr_list, 0, i*sizeof(char *));
- j=strlen(a->h_name)+1;
- if ((ret->h_name=OPENSSL_malloc(j)) == NULL) goto err;
- memcpy((char *)ret->h_name,a->h_name,j);
- for (i=0; a->h_aliases[i] != NULL; i++)
- {
- j=strlen(a->h_aliases[i])+1;
- if ((ret->h_aliases[i]=OPENSSL_malloc(j)) == NULL) goto err;
- memcpy(ret->h_aliases[i],a->h_aliases[i],j);
- }
- ret->h_length=a->h_length;
- ret->h_addrtype=a->h_addrtype;
- for (i=0; a->h_addr_list[i] != NULL; i++)
- {
- if ((ret->h_addr_list[i]=OPENSSL_malloc(a->h_length)) == NULL)
+ j = strlen(a->h_name) + 1;
+ if ((ret->h_name = OPENSSL_malloc(j)) == NULL) goto err;
+ memcpy((char *)ret->h_name, a->h_name, j);
+ for (i = 0; a->h_aliases[i] != NULL; i++) {
+ j = strlen(a->h_aliases[i]) + 1;
+ if ((ret->h_aliases[i] = OPENSSL_malloc(j)) == NULL) goto err;
+ memcpy(ret->h_aliases[i], a->h_aliases[i], j);
+ }
+ ret->h_length = a->h_length;
+ ret->h_addrtype = a->h_addrtype;
+ for (i = 0; a->h_addr_list[i] != NULL; i++) {
+ if ((ret->h_addr_list[i] = OPENSSL_malloc(a->h_length)) == NULL)
goto err;
- memcpy(ret->h_addr_list[i],a->h_addr_list[i],a->h_length);
- }
- if (0)
- {
-err:
+ memcpy(ret->h_addr_list[i], a->h_addr_list[i], a->h_length);
+ }
+ if (0) {
+err:
if (ret != NULL)
ghbn_free(ret);
- ret=NULL;
- }
- MemCheck_on();
- return(ret);
+ ret = NULL;
}
+ MemCheck_on();
+ return (ret);
+}
-static void ghbn_free(struct hostent *a)
- {
+static void
+ghbn_free(struct hostent *a)
+{
int i;
- if(a == NULL)
- return;
+ if (a == NULL)
+ return;
- if (a->h_aliases != NULL)
- {
- for (i=0; a->h_aliases[i] != NULL; i++)
+ if (a->h_aliases != NULL) {
+ for (i = 0; a->h_aliases[i] != NULL; i++)
OPENSSL_free(a->h_aliases[i]);
OPENSSL_free(a->h_aliases);
- }
- if (a->h_addr_list != NULL)
- {
- for (i=0; a->h_addr_list[i] != NULL; i++)
+ }
+ if (a->h_addr_list != NULL) {
+ for (i = 0; a->h_addr_list[i] != NULL; i++)
OPENSSL_free(a->h_addr_list[i]);
OPENSSL_free(a->h_addr_list);
- }
- if (a->h_name != NULL) OPENSSL_free(a->h_name);
- OPENSSL_free(a);
}
+ if (a->h_name != NULL)
+ OPENSSL_free(a->h_name);
+ OPENSSL_free(a);
+}
#endif
-struct hostent *BIO_gethostbyname(const char *name)
- {
+struct hostent
+*BIO_gethostbyname(const char *name) {
#if 1
/* Caching gethostbyname() results forever is wrong,
* so we have to let the true gethostbyname() worry about this */
#endif
#else
struct hostent *ret;
- int i,lowi=0,j;
- unsigned long low= (unsigned long)-1;
+ int i, lowi = 0, j;
+ unsigned long low = (unsigned long) - 1;
# if 0
*/
CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME);
# endif
- j=strlen(name);
- if (j < 128)
- {
- for (i=0; i<GHBN_NUM; i++)
- {
- if (low > ghbn_cache[i].order)
- {
- low=ghbn_cache[i].order;
- lowi=i;
- }
- if (ghbn_cache[i].order > 0)
- {
- if (strncmp(name,ghbn_cache[i].name,128) == 0)
+ j = strlen(name);
+ if (j < 128) {
+ for (i = 0; i < GHBN_NUM; i++) {
+ if (low > ghbn_cache[i].order) {
+ low = ghbn_cache[i].order;
+ lowi = i;
+ }
+ if (ghbn_cache[i].order > 0) {
+ if (strncmp(name, ghbn_cache[i].name, 128) == 0)
break;
- }
}
}
- else
- i=GHBN_NUM;
+ } else
+ i = GHBN_NUM;
if (i == GHBN_NUM) /* no hit*/
- {
+ {
BIO_ghbn_miss++;
/* Note: under VMS with SOCKETSHR, it seems like the first
* parameter is 'char *', instead of 'const char *'
*/
# ifndef CONST_STRICT
- ret=gethostbyname((char *)name);
+ ret = gethostbyname((char *)name);
# else
- ret=gethostbyname(name);
+ ret = gethostbyname(name);
# endif
if (ret == NULL)
goto end;
if (j > 128) /* too big to cache */
- {
+ {
# if 0
/* If we were trying to make this function thread-safe (which
* is bound to fail), we'd have to give up in this case
ret = NULL;
# endif
goto end;
- }
+ }
/* else add to cache */
if (ghbn_cache[lowi].ent != NULL)
ghbn_free(ghbn_cache[lowi].ent); /* XXX not thread-safe */
ghbn_cache[lowi].name[0] = '\0';
- if((ret=ghbn_cache[lowi].ent=ghbn_dup(ret)) == NULL)
- {
- BIOerr(BIO_F_BIO_GETHOSTBYNAME,ERR_R_MALLOC_FAILURE);
+ if ((ret = ghbn_cache[lowi].ent = ghbn_dup(ret)) == NULL) {
+ BIOerr(BIO_F_BIO_GETHOSTBYNAME, ERR_R_MALLOC_FAILURE);
goto end;
- }
- strncpy(ghbn_cache[lowi].name,name,128);
- ghbn_cache[lowi].order=BIO_ghbn_miss+BIO_ghbn_hits;
}
- else
- {
+ strncpy(ghbn_cache[lowi].name, name, 128);
+ ghbn_cache[lowi].order = BIO_ghbn_miss + BIO_ghbn_hits;
+ } else {
BIO_ghbn_hits++;
- ret= ghbn_cache[i].ent;
- ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits;
- }
+ ret = ghbn_cache[i].ent;
+ ghbn_cache[i].order = BIO_ghbn_miss + BIO_ghbn_hits;
+ }
end:
# if 0
CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME);
# endif
- return(ret);
+ return (ret);
#endif
- }
+}
-int BIO_sock_init(void)
- {
+int
+BIO_sock_init(void)
+{
#ifdef OPENSSL_SYS_WINDOWS
static struct WSAData wsa_state;
- if (!wsa_init_done)
- {
+ if (!wsa_init_done) {
int err;
-
- wsa_init_done=1;
- memset(&wsa_state,0,sizeof(wsa_state));
+
+ wsa_init_done = 1;
+ memset(&wsa_state, 0, sizeof(wsa_state));
/* Not making wsa_state available to the rest of the
* code is formally wrong. But the structures we use
* are [beleived to be] invariable among Winsock DLLs,
* while API availability is [expected to be] probed
* at run-time with DSO_global_lookup. */
- if (WSAStartup(0x0202,&wsa_state)!=0)
- {
- err=WSAGetLastError();
- SYSerr(SYS_F_WSASTARTUP,err);
- BIOerr(BIO_F_BIO_SOCK_INIT,BIO_R_WSASTARTUP);
- return(-1);
- }
+ if (WSAStartup(0x0202, &wsa_state) != 0) {
+ err = WSAGetLastError();
+ SYSerr(SYS_F_WSASTARTUP, err);
+ BIOerr(BIO_F_BIO_SOCK_INIT, BIO_R_WSASTARTUP);
+ return (-1);
}
+ }
#endif /* OPENSSL_SYS_WINDOWS */
#ifdef WATT32
extern int _watt_do_exit;
- _watt_do_exit = 0; /* don't make sock_init() call exit() */
+ _watt_do_exit = 0;
+ /* don't make sock_init() call exit() */
if (sock_init())
return (-1);
#endif
#if defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)
- WORD wVerReq;
- WSADATA wsaData;
- int err;
-
- if (!wsa_init_done)
- {
- wsa_init_done=1;
- wVerReq = MAKEWORD( 2, 0 );
- err = WSAStartup(wVerReq,&wsaData);
- if (err != 0)
- {
- SYSerr(SYS_F_WSASTARTUP,err);
- BIOerr(BIO_F_BIO_SOCK_INIT,BIO_R_WSASTARTUP);
- return(-1);
- }
+ WORD wVerReq;
+ WSADATA wsaData;
+ int err;
+
+ if (!wsa_init_done) {
+ wsa_init_done = 1;
+ wVerReq = MAKEWORD( 2, 0 );
+ err = WSAStartup(wVerReq, &wsaData);
+ if (err != 0) {
+ SYSerr(SYS_F_WSASTARTUP, err);
+ BIOerr(BIO_F_BIO_SOCK_INIT, BIO_R_WSASTARTUP);
+ return (-1);
}
+ }
#endif
- return(1);
- }
+ return (1);
+}
-void BIO_sock_cleanup(void)
- {
+void
+BIO_sock_cleanup(void)
+{
#ifdef OPENSSL_SYS_WINDOWS
- if (wsa_init_done)
- {
- wsa_init_done=0;
+ if (wsa_init_done) {
+ wsa_init_done = 0;
#if 0 /* this call is claimed to be non-present in Winsock2 */
WSACancelBlockingCall();
#endif
WSACleanup();
- }
+ }
#elif defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)
- if (wsa_init_done)
- {
- wsa_init_done=0;
- WSACleanup();
- }
-#endif
+ if (wsa_init_done) {
+ wsa_init_done = 0;
+ WSACleanup();
}
+#endif
+}
#if !defined(OPENSSL_SYS_VMS) || __VMS_VER >= 70000000
-int BIO_socket_ioctl(int fd, long type, void *arg)
- {
+int
+BIO_socket_ioctl(int fd, long type, void *arg)
+{
int i;
#ifdef __DJGPP__
- i=ioctl(fd,type,(char *)arg);
+ i = ioctl(fd, type,(char *)arg);
#else
# if defined(OPENSSL_SYS_VMS)
/* 2011-02-18 SMS.
# define ARG arg
# endif /* defined(OPENSSL_SYS_VMS) [else] */
- i=ioctl(fd,type,ARG);
+ i = ioctl(fd, type, ARG);
#endif /* __DJGPP__ */
if (i < 0)
- SYSerr(SYS_F_IOCTLSOCKET,errno);
- return(i);
- }
+ SYSerr(SYS_F_IOCTLSOCKET, errno);
+ return (i);
+}
#endif /* __VMS_VER */
/* The reason I have implemented this instead of using sscanf is because
* Visual C 1.52c gives an unresolved external when linking a DLL :-( */
-static int get_ip(const char *str, unsigned char ip[4])
- {
+static int
+get_ip(const char *str, unsigned char ip[4])
+{
unsigned int tmp[4];
- int num=0,c,ok=0;
+ int num = 0, c, ok = 0;
- tmp[0]=tmp[1]=tmp[2]=tmp[3]=0;
+ tmp[0] = tmp[1] = tmp[2] = tmp[3] = 0;
- for (;;)
- {
+ for (;;) {
c= *(str++);
- if ((c >= '0') && (c <= '9'))
- {
- ok=1;
- tmp[num]=tmp[num]*10+c-'0';
- if (tmp[num] > 255) return(0);
- }
- else if (c == '.')
- {
- if (!ok) return(-1);
- if (num == 3) return(0);
+ if ((c >= '0') && (c <= '9')) {
+ ok = 1;
+ tmp[num] = tmp[num]*10 + c-'0';
+ if (tmp[num] > 255)
+ return (0);
+ } else if (c == '.') {
+ if (!ok)
+ return (-1);
+ if (num == 3)
+ return (0);
num++;
- ok=0;
- }
- else if (c == '\0' && (num == 3) && ok)
- break;
+ ok = 0;
+ } else if (c == '\0' && (num == 3) && ok)
+ break;
else
- return(0);
- }
- ip[0]=tmp[0];
- ip[1]=tmp[1];
- ip[2]=tmp[2];
- ip[3]=tmp[3];
- return(1);
+ return (0);
}
-
-int BIO_get_accept_socket(char *host, int bind_mode)
- {
- int ret=0;
+ ip[0] = tmp[0];
+ ip[1] = tmp[1];
+ ip[2] = tmp[2];
+ ip[3] = tmp[3];
+ return (1);
+}
+
+int
+BIO_get_accept_socket(char *host, int bind_mode)
+{
+ int ret = 0;
union {
struct sockaddr sa;
struct sockaddr_in sa_in;
#if OPENSSL_USE_IPV6
struct sockaddr_in6 sa_in6;
#endif
- } server,client;
- int s=-1,cs,addrlen;
+ } server, client;
+ int s = -1, cs, addrlen;
unsigned char ip[4];
unsigned short port;
- char *str=NULL,*e;
- char *h,*p;
+ char *str = NULL, *e;
+ char *h, *p;
unsigned long l;
int err_num;
- if (BIO_sock_init() != 1) return(-1);
+ if (BIO_sock_init() != 1)
+ return (-1);
- if ((str=BUF_strdup(host)) == NULL) return(-1);
+ if ((str = BUF_strdup(host)) == NULL)
+ return (-1);
- h=p=NULL;
- h=str;
- for (e=str; *e; e++)
- {
- if (*e == ':')
- {
- p=e;
- }
- else if (*e == '/')
- {
- *e='\0';
+ h = p = NULL;
+ h = str;
+ for (e = str; *e; e++) {
+ if (*e == ':') {
+ p = e;
+ } else if (*e == '/') {
+ *e = '\0';
break;
- }
}
- if (p) *p++='\0'; /* points at last ':', '::port' is special [see below] */
- else p=h,h=NULL;
+ }
+ if (p)
+ *p++='\0'; /* points at last ':', '::port' is special [see below] */
+ else
+ p = h, h = NULL;
#ifdef EAI_FAMILY
do {
- static union { void *p;
- int (WSAAPI *f)(const char *,const char *,
- const struct addrinfo *,
- struct addrinfo **);
- } p_getaddrinfo = {NULL};
- static union { void *p;
+ static union {
+ void *p;
+ int (WSAAPI *f)(const char *, const char *,
+ const struct addrinfo *,
+ struct addrinfo **);
+ } p_getaddrinfo = {NULL};
+ static union {
+ void *p;
void (WSAAPI *f)(struct addrinfo *);
- } p_freeaddrinfo = {NULL};
- struct addrinfo *res,hint;
-
- if (p_getaddrinfo.p==NULL)
- {
- if ((p_getaddrinfo.p=DSO_global_lookup("getaddrinfo"))==NULL ||
- (p_freeaddrinfo.p=DSO_global_lookup("freeaddrinfo"))==NULL)
- p_getaddrinfo.p=(void*)-1;
- }
- if (p_getaddrinfo.p==(void *)-1) break;
-
- /* '::port' enforces IPv6 wildcard listener. Some OSes,
- * e.g. Solaris, default to IPv6 without any hint. Also
- * note that commonly IPv6 wildchard socket can service
- * IPv4 connections just as well... */
- memset(&hint,0,sizeof(hint));
- hint.ai_flags = AI_PASSIVE;
- if (h)
- {
- if (strchr(h,':'))
- {
- if (h[1]=='\0') h=NULL;
+ } p_freeaddrinfo = {NULL};
+ struct addrinfo *res, hint;
+
+ if (p_getaddrinfo.p == NULL) {
+ if ((p_getaddrinfo.p = DSO_global_lookup("getaddrinfo"))==NULL ||
+ (p_freeaddrinfo.p = DSO_global_lookup("freeaddrinfo"))==NULL)
+ p_getaddrinfo.p = (void*) - 1;
+ }
+ if (p_getaddrinfo.p == (void *) - 1) break;
+
+ /* '::port' enforces IPv6 wildcard listener. Some OSes,
+ * e.g. Solaris, default to IPv6 without any hint. Also
+ * note that commonly IPv6 wildchard socket can service
+ * IPv4 connections just as well... */
+ memset(&hint, 0, sizeof(hint));
+ hint.ai_flags = AI_PASSIVE;
+ if (h) {
+ if (strchr(h, ':')) {
+ if (h[1] == '\0')
+ h = NULL;
#if OPENSSL_USE_IPV6
- hint.ai_family = AF_INET6;
+ hint.ai_family = AF_INET6;
#else
- h=NULL;
+ h = NULL;
#endif
- }
- else if (h[0]=='*' && h[1]=='\0')
- {
- hint.ai_family = AF_INET;
- h=NULL;
+ } else if (h[0] == '*' && h[1] == '\0') {
+ hint.ai_family = AF_INET;
+ h = NULL;
}
}
- if ((*p_getaddrinfo.f)(h,p,&hint,&res)) break;
+ if ((*p_getaddrinfo.f)(h, p, &hint, &res))
+ break;
- addrlen = res->ai_addrlen<=sizeof(server) ?
- res->ai_addrlen :
- sizeof(server);
- memcpy(&server, res->ai_addr, addrlen);
+ addrlen = res->ai_addrlen <= sizeof(server) ?
+ res->ai_addrlen : sizeof(server);
+ memcpy(&server, res->ai_addr, addrlen);
- (*p_freeaddrinfo.f)(res);
- goto again;
+ (*p_freeaddrinfo.f)(res);
+ goto again;
} while (0);
#endif
- if (!BIO_get_port(p,&port)) goto err;
+ if (!BIO_get_port(p, &port))
+ goto err;
- memset((char *)&server,0,sizeof(server));
- server.sa_in.sin_family=AF_INET;
- server.sa_in.sin_port=htons(port);
+ memset((char *)&server, 0, sizeof(server));
+ server.sa_in.sin_family = AF_INET;
+ server.sa_in.sin_port = htons(port);
addrlen = sizeof(server.sa_in);
- if (h == NULL || strcmp(h,"*") == 0)
- server.sa_in.sin_addr.s_addr=INADDR_ANY;
- else
- {
- if (!BIO_get_host_ip(h,&(ip[0]))) goto err;
- l=(unsigned long)
- ((unsigned long)ip[0]<<24L)|
- ((unsigned long)ip[1]<<16L)|
- ((unsigned long)ip[2]<< 8L)|
- ((unsigned long)ip[3]);
- server.sa_in.sin_addr.s_addr=htonl(l);
- }
+ if (h == NULL || strcmp(h, "*") == 0)
+ server.sa_in.sin_addr.s_addr = INADDR_ANY;
+ else {
+ if (!BIO_get_host_ip(h, &(ip[0])))
+ goto err;
+ l = (unsigned long)
+ ((unsigned long)ip[0]<<24L)|
+ ((unsigned long)ip[1]<<16L)|
+ ((unsigned long)ip[2]<< 8L)|
+ ((unsigned long)ip[3]);
+ server.sa_in.sin_addr.s_addr = htonl(l);
+ }
again:
- s=socket(server.sa.sa_family,SOCK_STREAM,SOCKET_PROTOCOL);
- if (s == -1)
- {
- SYSerr(SYS_F_SOCKET,errno);
- ERR_add_error_data(3,"port='",host,"'");
- BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_CREATE_SOCKET);
+ s = socket(server.sa.sa_family, SOCK_STREAM, SOCKET_PROTOCOL);
+ if (s == -1) {
+ SYSerr(SYS_F_SOCKET, errno);
+ ERR_add_error_data(3, "port = '", host, "'");
+ BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, BIO_R_UNABLE_TO_CREATE_SOCKET);
goto err;
- }
+ }
#ifdef SO_REUSEADDR
- if (bind_mode == BIO_BIND_REUSEADDR)
- {
- int i=1;
+ if (bind_mode == BIO_BIND_REUSEADDR) {
+ int i = 1;
- ret=setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&i,sizeof(i));
- bind_mode=BIO_BIND_NORMAL;
- }
+ ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR,(char *)&i, sizeof(i));
+ bind_mode = BIO_BIND_NORMAL;
+ }
#endif
- if (bind(s,&server.sa,addrlen) == -1)
- {
+ if (bind(s, &server.sa, addrlen) == -1) {
#ifdef SO_REUSEADDR
- err_num=errno;
+ err_num = errno;
if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) &&
#ifdef OPENSSL_SYS_WINDOWS
/* Some versions of Windows define EADDRINUSE to
* a dummy value.
*/
- (err_num == WSAEADDRINUSE))
+ (err_num == WSAEADDRINUSE))
#else
- (err_num == EADDRINUSE))
+ (err_num == EADDRINUSE))
#endif
- {
+ {
client = server;
- if (h == NULL || strcmp(h,"*") == 0)
- {
+ if (h == NULL || strcmp(h, "*") == 0) {
#if OPENSSL_USE_IPV6
- if (client.sa.sa_family == AF_INET6)
- {
- memset(&client.sa_in6.sin6_addr,0,sizeof(client.sa_in6.sin6_addr));
- client.sa_in6.sin6_addr.s6_addr[15]=1;
- }
- else
-#endif
- if (client.sa.sa_family == AF_INET)
- {
- client.sa_in.sin_addr.s_addr=htonl(0x7F000001);
- }
- else goto err;
- }
- cs=socket(client.sa.sa_family,SOCK_STREAM,SOCKET_PROTOCOL);
- if (cs != -1)
- {
+ if (client.sa.sa_family == AF_INET6) {
+ memset(&client.sa_in6.sin6_addr, 0, sizeof(client.sa_in6.sin6_addr));
+ client.sa_in6.sin6_addr.s6_addr[15] = 1;
+ } else
+#endif
+ if (client.sa.sa_family == AF_INET) {
+ client.sa_in.sin_addr.s_addr = htonl(0x7F000001);
+ } else
+ goto err;
+ }
+ cs = socket(client.sa.sa_family, SOCK_STREAM, SOCKET_PROTOCOL);
+ if (cs != -1) {
int ii;
- ii=connect(cs,&client.sa,addrlen);
+ ii = connect(cs, &client.sa, addrlen);
close(cs);
- if (ii == -1)
- {
- bind_mode=BIO_BIND_REUSEADDR;
+ if (ii == -1) {
+ bind_mode = BIO_BIND_REUSEADDR;
close(s);
goto again;
- }
- /* else error */
}
- /* else error */
+ /* else error */
}
+ /* else error */
+ }
#endif
- SYSerr(SYS_F_BIND,err_num);
- ERR_add_error_data(3,"port='",host,"'");
- BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_BIND_SOCKET);
+ SYSerr(SYS_F_BIND, err_num);
+ ERR_add_error_data(3, "port = '", host, "'");
+ BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, BIO_R_UNABLE_TO_BIND_SOCKET);
goto err;
- }
- if (listen(s,MAX_LISTEN) == -1)
- {
- SYSerr(SYS_F_BIND,errno);
- ERR_add_error_data(3,"port='",host,"'");
- BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET,BIO_R_UNABLE_TO_LISTEN_SOCKET);
+ }
+ if (listen(s, MAX_LISTEN) == -1) {
+ SYSerr(SYS_F_BIND, errno);
+ ERR_add_error_data(3, "port = '", host, "'");
+ BIOerr(BIO_F_BIO_GET_ACCEPT_SOCKET, BIO_R_UNABLE_TO_LISTEN_SOCKET);
goto err;
- }
- ret=1;
+ }
+ ret = 1;
err:
- if (str != NULL) OPENSSL_free(str);
- if ((ret == 0) && (s != -1))
- {
+ if (str != NULL)
+ OPENSSL_free(str);
+ if ((ret == 0) && (s != -1)) {
close(s);
- s= -1;
- }
- return(s);
+ s = -1;
}
+ return (s);
+}
-int BIO_accept(int sock, char **addr)
- {
- int ret=-1;
+int
+BIO_accept(int sock, char **addr)
+{
+ int ret = -1;
unsigned long l;
unsigned short port;
char *p;
struct {
- /*
- * As for following union. Trouble is that there are platforms
- * that have socklen_t and there are platforms that don't, on
- * some platforms socklen_t is int and on some size_t. So what
- * one can do? One can cook #ifdef spaghetti, which is nothing
- * but masochistic. Or one can do union between int and size_t.
- * One naturally does it primarily for 64-bit platforms where
- * sizeof(int) != sizeof(size_t). But would it work? Note that
- * if size_t member is initialized to 0, then later int member
- * assignment naturally does the job on little-endian platforms
- * regardless accept's expectations! What about big-endians?
- * If accept expects int*, then it works, and if size_t*, then
- * length value would appear as unreasonably large. But this
- * won't prevent it from filling in the address structure. The
- * trouble of course would be if accept returns more data than
- * actual buffer can accomodate and overwrite stack... That's
- * where early OPENSSL_assert comes into picture. Besides, the
- * only 64-bit big-endian platform found so far that expects
- * size_t* is HP-UX, where stack grows towards higher address.
- * <appro>
- */
- union { size_t s; int i; } len;
- union {
- struct sockaddr sa;
- struct sockaddr_in sa_in;
+ /*
+ * As for following union. Trouble is that there are platforms
+ * that have socklen_t and there are platforms that don't, on
+ * some platforms socklen_t is int and on some size_t. So what
+ * one can do? One can cook #ifdef spaghetti, which is nothing
+ * but masochistic. Or one can do union between int and size_t.
+ * One naturally does it primarily for 64-bit platforms where
+ * sizeof(int) != sizeof(size_t). But would it work? Note that
+ * if size_t member is initialized to 0, then later int member
+ * assignment naturally does the job on little-endian platforms
+ * regardless accept's expectations! What about big-endians?
+ * If accept expects int*, then it works, and if size_t*, then
+ * length value would appear as unreasonably large. But this
+ * won't prevent it from filling in the address structure. The
+ * trouble of course would be if accept returns more data than
+ * actual buffer can accomodate and overwrite stack... That's
+ * where early OPENSSL_assert comes into picture. Besides, the
+ * only 64-bit big-endian platform found so far that expects
+ * size_t* is HP-UX, where stack grows towards higher address.
+ * <appro>
+ */
+ union {
+ size_t s;
+ int i;
+ } len;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in sa_in;
#if OPENSSL_USE_IPV6
- struct sockaddr_in6 sa_in6;
+ struct sockaddr_in6 sa_in6;
#endif
} from;
} sa;
- sa.len.s=0;
- sa.len.i=sizeof(sa.from);
- memset(&sa.from,0,sizeof(sa.from));
- ret=accept(sock,&sa.from.sa,(void *)&sa.len);
- if (sizeof(sa.len.i)!=sizeof(sa.len.s) && sa.len.i==0)
- {
- OPENSSL_assert(sa.len.s<=sizeof(sa.from));
+ sa.len.s = 0;
+ sa.len.i = sizeof(sa.from);
+ memset(&sa.from, 0, sizeof(sa.from));
+ ret = accept(sock, &sa.from.sa,(void *)&sa.len);
+ if (sizeof(sa.len.i) != sizeof(sa.len.s) && sa.len.i == 0) {
+ OPENSSL_assert(sa.len.s <= sizeof(sa.from));
sa.len.i = (int)sa.len.s;
/* use sa.len.i from this point */
- }
- if (ret == -1)
- {
- if(BIO_sock_should_retry(ret)) return -2;
- SYSerr(SYS_F_ACCEPT,errno);
- BIOerr(BIO_F_BIO_ACCEPT,BIO_R_ACCEPT_ERROR);
+ }
+ if (ret == -1) {
+ if (BIO_sock_should_retry(ret)) return -2;
+ SYSerr(SYS_F_ACCEPT, errno);
+ BIOerr(BIO_F_BIO_ACCEPT, BIO_R_ACCEPT_ERROR);
goto end;
- }
+ }
- if (addr == NULL) goto end;
+ if (addr == NULL)
+ goto end;
#ifdef EAI_FAMILY
do {
- char h[NI_MAXHOST],s[NI_MAXSERV];
- size_t nl;
- static union { void *p;
- int (WSAAPI *f)(const struct sockaddr *,size_t/*socklen_t*/,
- char *,size_t,char *,size_t,int);
- } p_getnameinfo = {NULL};
- /* 2nd argument to getnameinfo is specified to
- * be socklen_t. Unfortunately there is a number
- * of environments where socklen_t is not defined.
- * As it's passed by value, it's safe to pass it
- * as size_t... <appro> */
-
- if (p_getnameinfo.p==NULL)
- {
- if ((p_getnameinfo.p=DSO_global_lookup("getnameinfo"))==NULL)
- p_getnameinfo.p=(void*)-1;
+ char h[NI_MAXHOST], s[NI_MAXSERV];
+ size_t nl;
+ static union {
+ void *p;
+ int (WSAAPI *f)(const struct sockaddr *,
+ size_t/*socklen_t*/, char *, size_t,
+ char *, size_t, int);
+ } p_getnameinfo = {NULL};
+ /* 2nd argument to getnameinfo is specified to
+ * be socklen_t. Unfortunately there is a number
+ * of environments where socklen_t is not defined.
+ * As it's passed by value, it's safe to pass it
+ * as size_t... <appro> */
+
+ if (p_getnameinfo.p == NULL) {
+ if ((p_getnameinfo.p = DSO_global_lookup("getnameinfo")) == NULL)
+ p_getnameinfo.p = (void*) - 1;
+ }
+ if (p_getnameinfo.p == (void *) - 1)
+ break;
+
+ if ((*p_getnameinfo.f)(&sa.from.sa, sa.len.i, h, sizeof(h),
+ s, sizeof(s), NI_NUMERICHOST|NI_NUMERICSERV))
+ break;
+ nl = strlen(h) + strlen(s) + 2;
+ p = *addr;
+ if (p) {
+ *p = '\0';
+ p = OPENSSL_realloc(p, nl);
+ } else {
+ p = OPENSSL_malloc(nl);
+ }
+ if (p == NULL) {
+ BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE);
+ goto end;
}
- if (p_getnameinfo.p==(void *)-1) break;
-
- if ((*p_getnameinfo.f)(&sa.from.sa,sa.len.i,h,sizeof(h),s,sizeof(s),
- NI_NUMERICHOST|NI_NUMERICSERV)) break;
- nl = strlen(h)+strlen(s)+2;
- p = *addr;
- if (p) { *p = '\0'; p = OPENSSL_realloc(p,nl); }
- else { p = OPENSSL_malloc(nl); }
- if (p==NULL)
- {
- BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE);
+ *addr = p;
+ (void) snprintf(*addr, nl, "%s:%s", h, s);
goto end;
- }
- *addr = p;
- (void) snprintf(*addr,nl,"%s:%s",h,s);
- goto end;
- } while(0);
-#endif
- if (sa.from.sa.sa_family != AF_INET) goto end;
- l=ntohl(sa.from.sa_in.sin_addr.s_addr);
- port=ntohs(sa.from.sa_in.sin_port);
- if (*addr == NULL)
- {
- if ((p=OPENSSL_malloc(24)) == NULL)
- {
- BIOerr(BIO_F_BIO_ACCEPT,ERR_R_MALLOC_FAILURE);
+ } while (0);
+#endif
+ if (sa.from.sa.sa_family != AF_INET)
+ goto end;
+ l = ntohl(sa.from.sa_in.sin_addr.s_addr);
+ port = ntohs(sa.from.sa_in.sin_port);
+ if (*addr == NULL) {
+ if ((p = OPENSSL_malloc(24)) == NULL) {
+ BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE);
goto end;
- }
- *addr=p;
}
- (void) snprintf(*addr,24,"%d.%d.%d.%d:%d",
- (unsigned char)(l>>24L)&0xff,
- (unsigned char)(l>>16L)&0xff,
- (unsigned char)(l>> 8L)&0xff,
- (unsigned char)(l )&0xff,
- port);
-end:
- return(ret);
+ *addr = p;
}
+ (void) snprintf(*addr, 24, "%d.%d.%d.%d:%d",
+ (unsigned char)(l >> 24L) & 0xff, (unsigned char)(l >> 16L) & 0xff,
+ (unsigned char)(l >> 8L) & 0xff, (unsigned char)(l) & 0xff, port);
-int BIO_set_tcp_ndelay(int s, int on)
- {
- int ret=0;
+end:
+ return (ret);
+}
+
+int
+BIO_set_tcp_ndelay(int s, int on)
+{
+ int ret = 0;
#if defined(TCP_NODELAY) && (defined(IPPROTO_TCP) || defined(SOL_TCP))
int opt;
#ifdef SOL_TCP
- opt=SOL_TCP;
+ opt = SOL_TCP;
#else
#ifdef IPPROTO_TCP
- opt=IPPROTO_TCP;
+ opt = IPPROTO_TCP;
#endif
#endif
-
- ret=setsockopt(s,opt,TCP_NODELAY,(char *)&on,sizeof(on));
+
+ ret = setsockopt(s, opt, TCP_NODELAY,(char *)&on, sizeof(on));
#endif
- return(ret == 0);
- }
+ return (ret == 0);
+}
-int BIO_socket_nbio(int s, int mode)
- {
- int ret= -1;
+int
+BIO_socket_nbio(int s, int mode)
+{
+ int ret = -1;
int l;
- l=mode;
+ l = mode;
#ifdef FIONBIO
- ret=BIO_socket_ioctl(s,FIONBIO,&l);
+ ret = BIO_socket_ioctl(s, FIONBIO, &l);
#endif
- return(ret == 0);
- }
+ return (ret == 0);
+}
#endif
#include "cryptlib.h"
#include <openssl/bio.h>
-static int buffer_write(BIO *h, const char *buf,int num);
+static int buffer_write(BIO *h, const char *buf, int num);
static int buffer_read(BIO *h, char *buf, int size);
static int buffer_puts(BIO *h, const char *str);
static int buffer_gets(BIO *h, char *str, int size);
static long buffer_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
#define DEFAULT_BUFFER_SIZE 4096
-static BIO_METHOD methods_buffer=
- {
+static BIO_METHOD methods_buffer = {
BIO_TYPE_BUFFER,
"buffer",
buffer_write,
buffer_new,
buffer_free,
buffer_callback_ctrl,
- };
+};
-BIO_METHOD *BIO_f_buffer(void)
- {
- return(&methods_buffer);
- }
+BIO_METHOD
+*BIO_f_buffer(void)
+{
+ return (&methods_buffer);
+}
-static int buffer_new(BIO *bi)
- {
+static int
+buffer_new(BIO *bi)
+{
BIO_F_BUFFER_CTX *ctx;
- ctx=(BIO_F_BUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_F_BUFFER_CTX));
- if (ctx == NULL) return(0);
- ctx->ibuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
- if (ctx->ibuf == NULL) { OPENSSL_free(ctx); return(0); }
- ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
- if (ctx->obuf == NULL) { OPENSSL_free(ctx->ibuf); OPENSSL_free(ctx); return(0); }
- ctx->ibuf_size=DEFAULT_BUFFER_SIZE;
- ctx->obuf_size=DEFAULT_BUFFER_SIZE;
- ctx->ibuf_len=0;
- ctx->ibuf_off=0;
- ctx->obuf_len=0;
- ctx->obuf_off=0;
-
- bi->init=1;
- bi->ptr=(char *)ctx;
- bi->flags=0;
- return(1);
+ ctx = (BIO_F_BUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_F_BUFFER_CTX));
+ if (ctx == NULL)
+ return (0);
+ ctx->ibuf = (char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
+ if (ctx->ibuf == NULL) {
+ OPENSSL_free(ctx);
+ return (0);
}
-
-static int buffer_free(BIO *a)
- {
+ ctx->obuf = (char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE);
+ if (ctx->obuf == NULL) {
+ OPENSSL_free(ctx->ibuf);
+ OPENSSL_free(ctx);
+ return (0);
+ }
+ ctx->ibuf_size = DEFAULT_BUFFER_SIZE;
+ ctx->obuf_size = DEFAULT_BUFFER_SIZE;
+ ctx->ibuf_len = 0;
+ ctx->ibuf_off = 0;
+ ctx->obuf_len = 0;
+ ctx->obuf_off = 0;
+
+ bi->init = 1;
+ bi->ptr = (char *)ctx;
+ bi->flags = 0;
+ return (1);
+}
+
+static int
+buffer_free(BIO *a)
+{
BIO_F_BUFFER_CTX *b;
- if (a == NULL) return(0);
- b=(BIO_F_BUFFER_CTX *)a->ptr;
- if (b->ibuf != NULL) OPENSSL_free(b->ibuf);
- if (b->obuf != NULL) OPENSSL_free(b->obuf);
+ if (a == NULL)
+ return (0);
+ b = (BIO_F_BUFFER_CTX *)a->ptr;
+ if (b->ibuf != NULL)
+ OPENSSL_free(b->ibuf);
+ if (b->obuf != NULL)
+ OPENSSL_free(b->obuf);
OPENSSL_free(a->ptr);
- a->ptr=NULL;
- a->init=0;
- a->flags=0;
- return(1);
- }
-
-static int buffer_read(BIO *b, char *out, int outl)
- {
- int i,num=0;
+ a->ptr = NULL;
+ a->init = 0;
+ a->flags = 0;
+ return (1);
+}
+
+static int
+buffer_read(BIO *b, char *out, int outl)
+{
+ int i, num = 0;
BIO_F_BUFFER_CTX *ctx;
- if (out == NULL) return(0);
- ctx=(BIO_F_BUFFER_CTX *)b->ptr;
+ if (out == NULL)
+ return (0);
+ ctx = (BIO_F_BUFFER_CTX *)b->ptr;
- if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
- num=0;
+ if ((ctx == NULL) || (b->next_bio == NULL))
+ return (0);
+ num = 0;
BIO_clear_retry_flags(b);
start:
- i=ctx->ibuf_len;
+ i = ctx->ibuf_len;
/* If there is stuff left over, grab it */
- if (i != 0)
- {
- if (i > outl) i=outl;
- memcpy(out,&(ctx->ibuf[ctx->ibuf_off]),i);
- ctx->ibuf_off+=i;
- ctx->ibuf_len-=i;
- num+=i;
- if (outl == i) return(num);
- outl-=i;
- out+=i;
- }
+ if (i != 0) {
+ if (i > outl)
+ i = outl;
+ memcpy(out, &(ctx->ibuf[ctx->ibuf_off]), i);
+ ctx->ibuf_off += i;
+ ctx->ibuf_len -= i;
+ num += i;
+ if (outl == i)
+ return (num);
+ outl -= i;
+ out += i;
+ }
/* We may have done a partial read. try to do more.
* We have nothing in the buffer.
* If we get an error and have read some data, just return it
* and let them retry to get the error again.
* copy direct to parent address space */
- if (outl > ctx->ibuf_size)
- {
- for (;;)
- {
- i=BIO_read(b->next_bio,out,outl);
- if (i <= 0)
- {
+ if (outl > ctx->ibuf_size) {
+ for (;;) {
+ i = BIO_read(b->next_bio, out, outl);
+ if (i <= 0) {
BIO_copy_next_retry(b);
- if (i < 0) return((num > 0)?num:i);
- if (i == 0) return(num);
- }
- num+=i;
- if (outl == i) return(num);
- out+=i;
- outl-=i;
+ if (i < 0)
+ return ((num > 0) ? num : i);
+ if (i == 0)
+ return (num);
}
+ num += i;
+ if (outl == i)
+ return (num);
+ out += i;
+ outl -= i;
}
+ }
/* else */
/* we are going to be doing some buffering */
- i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size);
- if (i <= 0)
- {
+ i = BIO_read(b->next_bio, ctx->ibuf, ctx->ibuf_size);
+ if (i <= 0) {
BIO_copy_next_retry(b);
- if (i < 0) return((num > 0)?num:i);
- if (i == 0) return(num);
- }
- ctx->ibuf_off=0;
- ctx->ibuf_len=i;
+ if (i < 0)
+ return ((num > 0) ? num : i);
+ if (i == 0)
+ return (num);
+ }
+ ctx->ibuf_off = 0;
+ ctx->ibuf_len = i;
/* Lets re-read using ourselves :-) */
goto start;
- }
+}
-static int buffer_write(BIO *b, const char *in, int inl)
- {
- int i,num=0;
+static int
+buffer_write(BIO *b, const char *in, int inl)
+{
+ int i, num = 0;
BIO_F_BUFFER_CTX *ctx;
- if ((in == NULL) || (inl <= 0)) return(0);
- ctx=(BIO_F_BUFFER_CTX *)b->ptr;
- if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
+ if ((in == NULL) || (inl <= 0))
+ return (0);
+ ctx = (BIO_F_BUFFER_CTX *)b->ptr;
+ if ((ctx == NULL) || (b->next_bio == NULL))
+ return (0);
BIO_clear_retry_flags(b);
start:
- i=ctx->obuf_size-(ctx->obuf_len+ctx->obuf_off);
+ i = ctx->obuf_size - (ctx->obuf_len + ctx->obuf_off);
/* add to buffer and return */
- if (i >= inl)
- {
- memcpy(&(ctx->obuf[ctx->obuf_off+ctx->obuf_len]),in,inl);
- ctx->obuf_len+=inl;
- return(num+inl);
- }
+ if (i >= inl) {
+ memcpy(&(ctx->obuf[ctx->obuf_off + ctx->obuf_len]), in, inl);
+ ctx->obuf_len += inl;
+ return (num + inl);
+ }
/* else */
/* stuff already in buffer, so add to it first, then flush */
- if (ctx->obuf_len != 0)
- {
+ if (ctx->obuf_len != 0) {
if (i > 0) /* lets fill it up if we can */
- {
- memcpy(&(ctx->obuf[ctx->obuf_off+ctx->obuf_len]),in,i);
- in+=i;
- inl-=i;
- num+=i;
- ctx->obuf_len+=i;
- }
+ {
+ memcpy(&(ctx->obuf[ctx->obuf_off + ctx->obuf_len]), in, i);
+ in += i;
+ inl -= i;
+ num += i;
+ ctx->obuf_len += i;
+ }
/* we now have a full buffer needing flushing */
- for (;;)
- {
- i=BIO_write(b->next_bio,&(ctx->obuf[ctx->obuf_off]),
- ctx->obuf_len);
- if (i <= 0)
- {
+ for (;;) {
+ i = BIO_write(b->next_bio, &(ctx->obuf[ctx->obuf_off]),
+ ctx->obuf_len);
+ if (i <= 0) {
BIO_copy_next_retry(b);
- if (i < 0) return((num > 0)?num:i);
- if (i == 0) return(num);
- }
- ctx->obuf_off+=i;
- ctx->obuf_len-=i;
- if (ctx->obuf_len == 0) break;
+ if (i < 0)
+ return ((num > 0) ? num : i);
+ if (i == 0)
+ return (num);
}
+ ctx->obuf_off += i;
+ ctx->obuf_len -= i;
+ if (ctx->obuf_len == 0)
+ break;
}
+ }
/* we only get here if the buffer has been flushed and we
* still have stuff to write */
- ctx->obuf_off=0;
+ ctx->obuf_off = 0;
/* we now have inl bytes to write */
- while (inl >= ctx->obuf_size)
- {
- i=BIO_write(b->next_bio,in,inl);
- if (i <= 0)
- {
+ while (inl >= ctx->obuf_size) {
+ i = BIO_write(b->next_bio, in, inl);
+ if (i <= 0) {
BIO_copy_next_retry(b);
- if (i < 0) return((num > 0)?num:i);
- if (i == 0) return(num);
- }
- num+=i;
- in+=i;
- inl-=i;
- if (inl == 0) return(num);
+ if (i < 0)
+ return ((num > 0) ? num : i);
+ if (i == 0)
+ return (num);
}
+ num += i;
+ in += i;
+ inl -= i;
+ if (inl == 0)
+ return (num);
+ }
/* copy the rest into the buffer since we have only a small
* amount left */
goto start;
- }
+}
-static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
+static long
+buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
BIO *dbio;
BIO_F_BUFFER_CTX *ctx;
- long ret=1;
- char *p1,*p2;
- int r,i,*ip;
- int ibs,obs;
+ long ret = 1;
+ char *p1, *p2;
+ int r, i, *ip;
+ int ibs, obs;
- ctx=(BIO_F_BUFFER_CTX *)b->ptr;
+ ctx = (BIO_F_BUFFER_CTX *)b->ptr;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_RESET:
- ctx->ibuf_off=0;
- ctx->ibuf_len=0;
- ctx->obuf_off=0;
- ctx->obuf_len=0;
- if (b->next_bio == NULL) return(0);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ ctx->ibuf_off = 0;
+ ctx->ibuf_len = 0;
+ ctx->obuf_off = 0;
+ ctx->obuf_len = 0;
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
case BIO_CTRL_INFO:
- ret=(long)ctx->obuf_len;
+ ret = (long)ctx->obuf_len;
break;
case BIO_C_GET_BUFF_NUM_LINES:
- ret=0;
- p1=ctx->ibuf;
- for (i=0; i<ctx->ibuf_len; i++)
- {
- if (p1[ctx->ibuf_off + i] == '\n') ret++;
- }
+ ret = 0;
+ p1 = ctx->ibuf;
+ for (i = 0; i < ctx->ibuf_len; i++) {
+ if (p1[ctx->ibuf_off + i] == '\n')
+ ret++;
+ }
break;
case BIO_CTRL_WPENDING:
- ret=(long)ctx->obuf_len;
- if (ret == 0)
- {
- if (b->next_bio == NULL) return(0);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
- }
+ ret = (long)ctx->obuf_len;
+ if (ret == 0) {
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ }
break;
case BIO_CTRL_PENDING:
- ret=(long)ctx->ibuf_len;
- if (ret == 0)
- {
- if (b->next_bio == NULL) return(0);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
- }
+ ret = (long)ctx->ibuf_len;
+ if (ret == 0) {
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ }
break;
case BIO_C_SET_BUFF_READ_DATA:
- if (num > ctx->ibuf_size)
- {
- p1=OPENSSL_malloc((int)num);
- if (p1 == NULL) goto malloc_error;
- if (ctx->ibuf != NULL) OPENSSL_free(ctx->ibuf);
- ctx->ibuf=p1;
- }
- ctx->ibuf_off=0;
- ctx->ibuf_len=(int)num;
- memcpy(ctx->ibuf,ptr,(int)num);
- ret=1;
+ if (num > ctx->ibuf_size) {
+ p1 = OPENSSL_malloc((int)num);
+ if (p1 == NULL)
+ goto malloc_error;
+ if (ctx->ibuf != NULL)
+ OPENSSL_free(ctx->ibuf);
+ ctx->ibuf = p1;
+ }
+ ctx->ibuf_off = 0;
+ ctx->ibuf_len = (int)num;
+ memcpy(ctx->ibuf, ptr,(int)num);
+ ret = 1;
break;
case BIO_C_SET_BUFF_SIZE:
- if (ptr != NULL)
- {
- ip=(int *)ptr;
- if (*ip == 0)
- {
- ibs=(int)num;
- obs=ctx->obuf_size;
- }
- else /* if (*ip == 1) */
- {
- ibs=ctx->ibuf_size;
- obs=(int)num;
- }
- }
- else
- {
- ibs=(int)num;
- obs=(int)num;
+ if (ptr != NULL) {
+ ip = (int *)ptr;
+ if (*ip == 0) {
+ ibs = (int)num;
+ obs = ctx->obuf_size;
}
- p1=ctx->ibuf;
- p2=ctx->obuf;
- if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size))
+ else /* if (*ip == 1) */
{
- p1=(char *)OPENSSL_malloc((int)num);
- if (p1 == NULL) goto malloc_error;
+ ibs = ctx->ibuf_size;
+ obs = (int)num;
}
- if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size))
- {
- p2=(char *)OPENSSL_malloc((int)num);
- if (p2 == NULL)
- {
- if (p1 != ctx->ibuf) OPENSSL_free(p1);
+ } else {
+ ibs = (int)num;
+ obs = (int)num;
+ }
+ p1 = ctx->ibuf;
+ p2 = ctx->obuf;
+ if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size)) {
+ p1 = (char *)OPENSSL_malloc((int)num);
+ if (p1 == NULL)
+ goto malloc_error;
+ }
+ if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) {
+ p2 = (char *)OPENSSL_malloc((int)num);
+ if (p2 == NULL) {
+ if (p1 != ctx->ibuf)
+ OPENSSL_free(p1);
goto malloc_error;
- }
}
- if (ctx->ibuf != p1)
- {
+ }
+ if (ctx->ibuf != p1) {
OPENSSL_free(ctx->ibuf);
- ctx->ibuf=p1;
- ctx->ibuf_off=0;
- ctx->ibuf_len=0;
- ctx->ibuf_size=ibs;
- }
- if (ctx->obuf != p2)
- {
+ ctx->ibuf = p1;
+ ctx->ibuf_off = 0;
+ ctx->ibuf_len = 0;
+ ctx->ibuf_size = ibs;
+ }
+ if (ctx->obuf != p2) {
OPENSSL_free(ctx->obuf);
- ctx->obuf=p2;
- ctx->obuf_off=0;
- ctx->obuf_len=0;
- ctx->obuf_size=obs;
- }
+ ctx->obuf = p2;
+ ctx->obuf_off = 0;
+ ctx->obuf_len = 0;
+ ctx->obuf_size = obs;
+ }
break;
case BIO_C_DO_STATE_MACHINE:
- if (b->next_bio == NULL) return(0);
+ if (b->next_bio == NULL)
+ return (0);
BIO_clear_retry_flags(b);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
BIO_copy_next_retry(b);
break;
case BIO_CTRL_FLUSH:
- if (b->next_bio == NULL) return(0);
- if (ctx->obuf_len <= 0)
- {
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ if (b->next_bio == NULL)
+ return (0);
+ if (ctx->obuf_len <= 0) {
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
- }
+ }
- for (;;)
- {
+ for (;;) {
BIO_clear_retry_flags(b);
- if (ctx->obuf_len > 0)
- {
- r=BIO_write(b->next_bio,
- &(ctx->obuf[ctx->obuf_off]),
- ctx->obuf_len);
+ if (ctx->obuf_len > 0) {
+ r = BIO_write(b->next_bio,
+ &(ctx->obuf[ctx->obuf_off]),
+ ctx->obuf_len);
#if 0
-fprintf(stderr,"FLUSH [%3d] %3d -> %3d\n",ctx->obuf_off,ctx->obuf_len,r);
+ fprintf(stderr, "FLUSH [%3d] %3d -> %3d\n", ctx->obuf_off, ctx->obuf_len, r);
#endif
BIO_copy_next_retry(b);
- if (r <= 0) return((long)r);
- ctx->obuf_off+=r;
- ctx->obuf_len-=r;
- }
- else
- {
- ctx->obuf_len=0;
- ctx->obuf_off=0;
- ret=1;
+ if (r <= 0)
+ return ((long)r);
+ ctx->obuf_off += r;
+ ctx->obuf_len -= r;
+ } else {
+ ctx->obuf_len = 0;
+ ctx->obuf_off = 0;
+ ret = 1;
break;
- }
}
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ }
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
case BIO_CTRL_DUP:
- dbio=(BIO *)ptr;
- if ( !BIO_set_read_buffer_size(dbio,ctx->ibuf_size) ||
- !BIO_set_write_buffer_size(dbio,ctx->obuf_size))
- ret=0;
+ dbio = (BIO *)ptr;
+ if (!BIO_set_read_buffer_size(dbio, ctx->ibuf_size) ||
+ !BIO_set_write_buffer_size(dbio, ctx->obuf_size))
+ ret = 0;
break;
default:
- if (b->next_bio == NULL) return(0);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
- }
- return(ret);
-malloc_error:
- BIOerr(BIO_F_BUFFER_CTRL,ERR_R_MALLOC_FAILURE);
- return(0);
}
-
-static long buffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
- {
- long ret=1;
-
- if (b->next_bio == NULL) return(0);
- switch (cmd)
- {
+ return (ret);
+malloc_error:
+ BIOerr(BIO_F_BUFFER_CTRL, ERR_R_MALLOC_FAILURE);
+ return (0);
+}
+
+static long
+buffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
+{
+ long ret = 1;
+
+ if (b->next_bio == NULL)
+ return (0);
+ switch (cmd) {
default:
- ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
+ ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
break;
- }
- return(ret);
}
+ return (ret);
+}
-static int buffer_gets(BIO *b, char *buf, int size)
- {
+static int
+buffer_gets(BIO *b, char *buf, int size)
+{
BIO_F_BUFFER_CTX *ctx;
- int num=0,i,flag;
+ int num = 0, i, flag;
char *p;
- ctx=(BIO_F_BUFFER_CTX *)b->ptr;
+ ctx = (BIO_F_BUFFER_CTX *)b->ptr;
size--; /* reserve space for a '\0' */
BIO_clear_retry_flags(b);
- for (;;)
- {
- if (ctx->ibuf_len > 0)
- {
- p= &(ctx->ibuf[ctx->ibuf_off]);
- flag=0;
- for (i=0; (i<ctx->ibuf_len) && (i<size); i++)
- {
- *(buf++)=p[i];
- if (p[i] == '\n')
- {
- flag=1;
+ for (;;) {
+ if (ctx->ibuf_len > 0) {
+ p = &(ctx->ibuf[ctx->ibuf_off]);
+ flag = 0;
+ for (i = 0; (i < ctx->ibuf_len) && (i < size); i++) {
+ *(buf++) = p[i];
+ if (p[i] == '\n') {
+ flag = 1;
i++;
break;
- }
- }
- num+=i;
- size-=i;
- ctx->ibuf_len-=i;
- ctx->ibuf_off+=i;
- if (flag || size == 0)
- {
- *buf='\0';
- return(num);
}
}
+ num += i;
+ size -= i;
+ ctx->ibuf_len -= i;
+ ctx->ibuf_off += i;
+ if (flag || size == 0) {
+ *buf = '\0';
+ return (num);
+ }
+ }
else /* read another chunk */
- {
- i=BIO_read(b->next_bio,ctx->ibuf,ctx->ibuf_size);
- if (i <= 0)
- {
+ {
+ i = BIO_read(b->next_bio, ctx->ibuf, ctx->ibuf_size);
+ if (i <= 0) {
BIO_copy_next_retry(b);
- *buf='\0';
- if (i < 0) return((num > 0)?num:i);
- if (i == 0) return(num);
- }
- ctx->ibuf_len=i;
- ctx->ibuf_off=0;
+ *buf = '\0';
+ if (i < 0)
+ return ((num > 0) ? num : i);
+ if (i == 0)
+ return (num);
}
+ ctx->ibuf_len = i;
+ ctx->ibuf_off = 0;
}
}
+}
-static int buffer_puts(BIO *b, const char *str)
- {
- return(buffer_write(b,str,strlen(str)));
- }
-
+static int
+buffer_puts(BIO *b, const char *str)
+{
+ return (buffer_write(b, str, strlen(str)));
+}
#include <openssl/bio.h>
#include <openssl/evp.h>
-static int linebuffer_write(BIO *h, const char *buf,int num);
+static int linebuffer_write(BIO *h, const char *buf, int num);
static int linebuffer_read(BIO *h, char *buf, int size);
static int linebuffer_puts(BIO *h, const char *str);
static int linebuffer_gets(BIO *h, char *str, int size);
/* #define DEBUG */
-static BIO_METHOD methods_linebuffer=
- {
+static BIO_METHOD methods_linebuffer = {
BIO_TYPE_LINEBUFFER,
"linebuffer",
linebuffer_write,
linebuffer_new,
linebuffer_free,
linebuffer_callback_ctrl,
- };
+};
-BIO_METHOD *BIO_f_linebuffer(void)
- {
- return(&methods_linebuffer);
- }
+BIO_METHOD
+*BIO_f_linebuffer(void)
+{
+ return (&methods_linebuffer);
+}
-typedef struct bio_linebuffer_ctx_struct
- {
+typedef struct bio_linebuffer_ctx_struct {
char *obuf; /* the output char array */
int obuf_size; /* how big is the output buffer */
int obuf_len; /* how many bytes are in it */
- } BIO_LINEBUFFER_CTX;
+} BIO_LINEBUFFER_CTX;
-static int linebuffer_new(BIO *bi)
- {
+static int
+linebuffer_new(BIO *bi)
+{
BIO_LINEBUFFER_CTX *ctx;
- ctx=(BIO_LINEBUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_LINEBUFFER_CTX));
- if (ctx == NULL) return(0);
- ctx->obuf=(char *)OPENSSL_malloc(DEFAULT_LINEBUFFER_SIZE);
- if (ctx->obuf == NULL) { OPENSSL_free(ctx); return(0); }
- ctx->obuf_size=DEFAULT_LINEBUFFER_SIZE;
- ctx->obuf_len=0;
-
- bi->init=1;
- bi->ptr=(char *)ctx;
- bi->flags=0;
- return(1);
+ ctx = (BIO_LINEBUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_LINEBUFFER_CTX));
+ if (ctx == NULL)
+ return (0);
+ ctx->obuf = (char *)OPENSSL_malloc(DEFAULT_LINEBUFFER_SIZE);
+ if (ctx->obuf == NULL) {
+ OPENSSL_free(ctx);
+ return (0);
}
+ ctx->obuf_size = DEFAULT_LINEBUFFER_SIZE;
+ ctx->obuf_len = 0;
+
+ bi->init = 1;
+ bi->ptr = (char *)ctx;
+ bi->flags = 0;
+ return (1);
+}
-static int linebuffer_free(BIO *a)
- {
+static int
+linebuffer_free(BIO *a)
+{
BIO_LINEBUFFER_CTX *b;
- if (a == NULL) return(0);
- b=(BIO_LINEBUFFER_CTX *)a->ptr;
- if (b->obuf != NULL) OPENSSL_free(b->obuf);
+ if (a == NULL)
+ return (0);
+ b = (BIO_LINEBUFFER_CTX *)a->ptr;
+ if (b->obuf != NULL)
+ OPENSSL_free(b->obuf);
OPENSSL_free(a->ptr);
- a->ptr=NULL;
- a->init=0;
- a->flags=0;
- return(1);
- }
-
-static int linebuffer_read(BIO *b, char *out, int outl)
- {
- int ret=0;
-
- if (out == NULL) return(0);
- if (b->next_bio == NULL) return(0);
- ret=BIO_read(b->next_bio,out,outl);
+ a->ptr = NULL;
+ a->init = 0;
+ a->flags = 0;
+ return (1);
+}
+
+static int
+linebuffer_read(BIO *b, char *out, int outl)
+{
+ int ret = 0;
+
+ if (out == NULL)
+ return (0);
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_read(b->next_bio, out, outl);
BIO_clear_retry_flags(b);
BIO_copy_next_retry(b);
- return(ret);
- }
+ return (ret);
+}
-static int linebuffer_write(BIO *b, const char *in, int inl)
- {
- int i,num=0,foundnl;
+static int
+linebuffer_write(BIO *b, const char *in, int inl)
+{
+ int i, num = 0, foundnl;
BIO_LINEBUFFER_CTX *ctx;
- if ((in == NULL) || (inl <= 0)) return(0);
- ctx=(BIO_LINEBUFFER_CTX *)b->ptr;
- if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
+ if ((in == NULL) || (inl <= 0))
+ return (0);
+ ctx = (BIO_LINEBUFFER_CTX *)b->ptr;
+ if ((ctx == NULL) || (b->next_bio == NULL))
+ return (0);
BIO_clear_retry_flags(b);
- do
- {
+ do {
const char *p;
- for(p = in; p < in + inl && *p != '\n'; p++)
+ for (p = in; p < in + inl && *p != '\n'; p++)
;
- if (*p == '\n')
- {
+ if (*p == '\n') {
p++;
foundnl = 1;
- }
- else
+ } else
foundnl = 0;
/* If a NL was found and we already have text in the save
buffer, concatenate them and write */
- while ((foundnl || p - in > ctx->obuf_size - ctx->obuf_len)
- && ctx->obuf_len > 0)
- {
+ while ((foundnl || p - in > ctx->obuf_size - ctx->obuf_len) &&
+ ctx->obuf_len > 0) {
int orig_olen = ctx->obuf_len;
-
+
i = ctx->obuf_size - ctx->obuf_len;
- if (p - in > 0)
- {
- if (i >= p - in)
- {
+ if (p - in > 0) {
+ if (i >= p - in) {
memcpy(&(ctx->obuf[ctx->obuf_len]),
- in,p - in);
+ in, p - in);
ctx->obuf_len += p - in;
inl -= p - in;
num += p - in;
in = p;
- }
- else
- {
+ } else {
memcpy(&(ctx->obuf[ctx->obuf_len]),
- in,i);
+ in, i);
ctx->obuf_len += i;
inl -= i;
in += i;
num += i;
- }
}
+ }
#if 0
-BIO_write(b->next_bio, "<*<", 3);
+ BIO_write(b->next_bio, "<*<", 3);
#endif
- i=BIO_write(b->next_bio,
- ctx->obuf, ctx->obuf_len);
- if (i <= 0)
- {
+ i = BIO_write(b->next_bio, ctx->obuf, ctx->obuf_len);
+ if (i <= 0) {
ctx->obuf_len = orig_olen;
BIO_copy_next_retry(b);
-
#if 0
-BIO_write(b->next_bio, ">*>", 3);
+ BIO_write(b->next_bio, ">*>", 3);
#endif
- if (i < 0) return((num > 0)?num:i);
- if (i == 0) return(num);
- }
+ if (i < 0)
+ return ((num > 0) ? num : i);
+ if (i == 0)
+ return (num);
+ }
#if 0
-BIO_write(b->next_bio, ">*>", 3);
+ BIO_write(b->next_bio, ">*>", 3);
#endif
if (i < ctx->obuf_len)
memmove(ctx->obuf, ctx->obuf + i,
- ctx->obuf_len - i);
- ctx->obuf_len-=i;
- }
+ ctx->obuf_len - i);
+ ctx->obuf_len -= i;
+ }
/* Now that the save buffer is emptied, let's write the input
buffer if a NL was found and there is anything to write. */
- if ((foundnl || p - in > ctx->obuf_size) && p - in > 0)
- {
+ if ((foundnl || p - in > ctx->obuf_size) && p - in > 0) {
#if 0
-BIO_write(b->next_bio, "<*<", 3);
+ BIO_write(b->next_bio, "<*<", 3);
#endif
- i=BIO_write(b->next_bio,in,p - in);
- if (i <= 0)
- {
+ i = BIO_write(b->next_bio, in, p - in);
+ if (i <= 0) {
BIO_copy_next_retry(b);
#if 0
-BIO_write(b->next_bio, ">*>", 3);
+ BIO_write(b->next_bio, ">*>", 3);
#endif
- if (i < 0) return((num > 0)?num:i);
- if (i == 0) return(num);
- }
+ if (i < 0)
+ return ((num > 0) ? num : i);
+ if (i == 0)
+ return (num);
+ }
#if 0
-BIO_write(b->next_bio, ">*>", 3);
+ BIO_write(b->next_bio, ">*>", 3);
#endif
- num+=i;
- in+=i;
- inl-=i;
- }
+ num += i;
+ in += i;
+ inl -= i;
}
- while(foundnl && inl > 0);
+ } while (foundnl && inl > 0);
/* We've written as much as we can. The rest of the input buffer, if
any, is text that doesn't and with a NL and therefore needs to be
saved for the next trip. */
- if (inl > 0)
- {
+ if (inl > 0) {
memcpy(&(ctx->obuf[ctx->obuf_len]), in, inl);
ctx->obuf_len += inl;
num += inl;
- }
- return num;
}
+ return num;
+}
-static long linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
+static long
+linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
BIO *dbio;
BIO_LINEBUFFER_CTX *ctx;
- long ret=1;
+ long ret = 1;
char *p;
int r;
int obs;
- ctx=(BIO_LINEBUFFER_CTX *)b->ptr;
+ ctx = (BIO_LINEBUFFER_CTX *)b->ptr;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_RESET:
- ctx->obuf_len=0;
- if (b->next_bio == NULL) return(0);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ ctx->obuf_len = 0;
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
case BIO_CTRL_INFO:
- ret=(long)ctx->obuf_len;
+ ret = (long)ctx->obuf_len;
break;
case BIO_CTRL_WPENDING:
- ret=(long)ctx->obuf_len;
- if (ret == 0)
- {
- if (b->next_bio == NULL) return(0);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
- }
+ ret = (long)ctx->obuf_len;
+ if (ret == 0) {
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
+ }
break;
case BIO_C_SET_BUFF_SIZE:
- obs=(int)num;
- p=ctx->obuf;
- if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size))
- {
- p=(char *)OPENSSL_malloc((int)num);
+ obs = (int)num;
+ p = ctx->obuf;
+ if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size)) {
+ p = (char *)OPENSSL_malloc((int)num);
if (p == NULL)
goto malloc_error;
- }
- if (ctx->obuf != p)
- {
- if (ctx->obuf_len > obs)
- {
+ }
+ if (ctx->obuf != p) {
+ if (ctx->obuf_len > obs) {
ctx->obuf_len = obs;
- }
+ }
memcpy(p, ctx->obuf, ctx->obuf_len);
OPENSSL_free(ctx->obuf);
- ctx->obuf=p;
- ctx->obuf_size=obs;
- }
+ ctx->obuf = p;
+ ctx->obuf_size = obs;
+ }
break;
case BIO_C_DO_STATE_MACHINE:
- if (b->next_bio == NULL) return(0);
+ if (b->next_bio == NULL)
+ return (0);
BIO_clear_retry_flags(b);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
BIO_copy_next_retry(b);
break;
case BIO_CTRL_FLUSH:
- if (b->next_bio == NULL) return(0);
- if (ctx->obuf_len <= 0)
- {
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ if (b->next_bio == NULL)
+ return (0);
+ if (ctx->obuf_len <= 0) {
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
- }
+ }
- for (;;)
- {
+ for (;;) {
BIO_clear_retry_flags(b);
- if (ctx->obuf_len > 0)
- {
- r=BIO_write(b->next_bio,
- ctx->obuf, ctx->obuf_len);
+ if (ctx->obuf_len > 0) {
+ r = BIO_write(b->next_bio,
+ ctx->obuf, ctx->obuf_len);
#if 0
-fprintf(stderr,"FLUSH %3d -> %3d\n",ctx->obuf_len,r);
+ fprintf(stderr, "FLUSH %3d -> %3d\n", ctx->obuf_len, r);
#endif
BIO_copy_next_retry(b);
- if (r <= 0) return((long)r);
+ if (r <= 0)
+ return ((long)r);
if (r < ctx->obuf_len)
memmove(ctx->obuf, ctx->obuf + r,
- ctx->obuf_len - r);
- ctx->obuf_len-=r;
- }
- else
- {
- ctx->obuf_len=0;
- ret=1;
+ ctx->obuf_len - r);
+ ctx->obuf_len -= r;
+ } else {
+ ctx->obuf_len = 0;
+ ret = 1;
break;
- }
}
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ }
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
case BIO_CTRL_DUP:
- dbio=(BIO *)ptr;
- if ( !BIO_set_write_buffer_size(dbio,ctx->obuf_size))
- ret=0;
+ dbio = (BIO *)ptr;
+ if (!BIO_set_write_buffer_size(dbio, ctx->obuf_size))
+ ret = 0;
break;
default:
- if (b->next_bio == NULL) return(0);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
- }
- return(ret);
-malloc_error:
- BIOerr(BIO_F_LINEBUFFER_CTRL,ERR_R_MALLOC_FAILURE);
- return(0);
}
+ return (ret);
+malloc_error:
+ BIOerr(BIO_F_LINEBUFFER_CTRL, ERR_R_MALLOC_FAILURE);
+ return (0);
+}
-static long linebuffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
- {
- long ret=1;
+static long
+linebuffer_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
+{
+ long ret = 1;
- if (b->next_bio == NULL) return(0);
- switch (cmd)
- {
+ if (b->next_bio == NULL)
+ return (0);
+ switch (cmd) {
default:
- ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
+ ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
break;
- }
- return(ret);
}
+ return (ret);
+}
-static int linebuffer_gets(BIO *b, char *buf, int size)
- {
- if (b->next_bio == NULL) return(0);
- return(BIO_gets(b->next_bio,buf,size));
- }
-
-static int linebuffer_puts(BIO *b, const char *str)
- {
- return(linebuffer_write(b,str,strlen(str)));
- }
+static int
+linebuffer_gets(BIO *b, char *buf, int size)
+{
+ if (b->next_bio == NULL)
+ return (0);
+ return (BIO_gets(b->next_bio, buf, size));
+}
+static int
+linebuffer_puts(BIO *b, const char *str)
+{
+ return (linebuffer_write(b, str, strlen(str)));
+}
/* BIO_put and BIO_get both add to the digest,
* BIO_gets returns the digest */
-static int nbiof_write(BIO *h,const char *buf,int num);
-static int nbiof_read(BIO *h,char *buf,int size);
-static int nbiof_puts(BIO *h,const char *str);
-static int nbiof_gets(BIO *h,char *str,int size);
-static long nbiof_ctrl(BIO *h,int cmd,long arg1,void *arg2);
+static int nbiof_write(BIO *h, const char *buf, int num);
+static int nbiof_read(BIO *h, char *buf, int size);
+static int nbiof_puts(BIO *h, const char *str);
+static int nbiof_gets(BIO *h, char *str, int size);
+static long nbiof_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int nbiof_new(BIO *h);
static int nbiof_free(BIO *data);
-static long nbiof_callback_ctrl(BIO *h,int cmd,bio_info_cb *fp);
-typedef struct nbio_test_st
- {
+static long nbiof_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
+
+typedef struct nbio_test_st {
/* only set if we sent a 'should retry' error */
int lrn;
int lwn;
- } NBIO_TEST;
+} NBIO_TEST;
-static BIO_METHOD methods_nbiof=
- {
+static BIO_METHOD methods_nbiof = {
BIO_TYPE_NBIO_TEST,
"non-blocking IO test filter",
nbiof_write,
nbiof_new,
nbiof_free,
nbiof_callback_ctrl,
- };
+};
-BIO_METHOD *BIO_f_nbio_test(void)
- {
- return(&methods_nbiof);
- }
+BIO_METHOD
+*BIO_f_nbio_test(void)
+{
+ return (&methods_nbiof);
+}
-static int nbiof_new(BIO *bi)
- {
+static int
+nbiof_new(BIO *bi)
+{
NBIO_TEST *nt;
- if (!(nt=(NBIO_TEST *)OPENSSL_malloc(sizeof(NBIO_TEST)))) return(0);
- nt->lrn= -1;
- nt->lwn= -1;
- bi->ptr=(char *)nt;
- bi->init=1;
- bi->flags=0;
- return(1);
- }
+ if (!(nt = (NBIO_TEST *)OPENSSL_malloc(sizeof(NBIO_TEST))))
+ return (0);
+ nt->lrn = -1;
+ nt->lwn = -1;
+ bi->ptr = (char *)nt;
+ bi->init = 1;
+ bi->flags = 0;
+ return (1);
+}
-static int nbiof_free(BIO *a)
- {
- if (a == NULL) return(0);
+static int
+nbiof_free(BIO *a)
+{
+ if (a == NULL)
+ return (0);
if (a->ptr != NULL)
OPENSSL_free(a->ptr);
- a->ptr=NULL;
- a->init=0;
- a->flags=0;
- return(1);
- }
-
-static int nbiof_read(BIO *b, char *out, int outl)
- {
- int ret=0;
+ a->ptr = NULL;
+ a->init = 0;
+ a->flags = 0;
+ return (1);
+}
+
+static int
+nbiof_read(BIO *b, char *out, int outl)
+{
+ int ret = 0;
#if 1
int num;
unsigned char n;
#endif
- if (out == NULL) return(0);
- if (b->next_bio == NULL) return(0);
+ if (out == NULL)
+ return (0);
+ if (b->next_bio == NULL)
+ return (0);
BIO_clear_retry_flags(b);
#if 1
- RAND_pseudo_bytes(&n,1);
- num=(n&0x07);
+ RAND_pseudo_bytes(&n, 1);
+ num = (n & 0x07);
- if (outl > num) outl=num;
+ if (outl > num)
+ outl = num;
- if (num == 0)
- {
- ret= -1;
+ if (num == 0) {
+ ret = -1;
BIO_set_retry_read(b);
- }
- else
+ } else
#endif
- {
- ret=BIO_read(b->next_bio,out,outl);
+ {
+ ret = BIO_read(b->next_bio, out, outl);
if (ret < 0)
BIO_copy_next_retry(b);
- }
- return(ret);
}
+ return (ret);
+}
-static int nbiof_write(BIO *b, const char *in, int inl)
- {
+static int
+nbiof_write(BIO *b, const char *in, int inl)
+{
NBIO_TEST *nt;
- int ret=0;
+ int ret = 0;
int num;
unsigned char n;
- if ((in == NULL) || (inl <= 0)) return(0);
- if (b->next_bio == NULL) return(0);
- nt=(NBIO_TEST *)b->ptr;
+ if ((in == NULL) || (inl <= 0))
+ return (0);
+ if (b->next_bio == NULL)
+ return (0);
+ nt = (NBIO_TEST *)b->ptr;
BIO_clear_retry_flags(b);
#if 1
- if (nt->lwn > 0)
- {
- num=nt->lwn;
- nt->lwn=0;
- }
- else
- {
- RAND_pseudo_bytes(&n,1);
- num=(n&7);
- }
+ if (nt->lwn > 0) {
+ num = nt->lwn;
+ nt->lwn = 0;
+ } else {
+ RAND_pseudo_bytes(&n, 1);
+ num = (n&7);
+ }
- if (inl > num) inl=num;
+ if (inl > num)
+ inl = num;
- if (num == 0)
- {
- ret= -1;
+ if (num == 0) {
+ ret = -1;
BIO_set_retry_write(b);
- }
- else
+ } else
#endif
- {
- ret=BIO_write(b->next_bio,in,inl);
- if (ret < 0)
- {
+ {
+ ret = BIO_write(b->next_bio, in, inl);
+ if (ret < 0) {
BIO_copy_next_retry(b);
- nt->lwn=inl;
- }
+ nt->lwn = inl;
}
- return(ret);
}
+ return (ret);
+}
-static long nbiof_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
+static long
+nbiof_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
long ret;
- if (b->next_bio == NULL) return(0);
- switch (cmd)
- {
- case BIO_C_DO_STATE_MACHINE:
+ if (b->next_bio == NULL)
+ return (0);
+ switch (cmd) {
+ case BIO_C_DO_STATE_MACHINE:
BIO_clear_retry_flags(b);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
BIO_copy_next_retry(b);
break;
case BIO_CTRL_DUP:
- ret=0L;
+ ret = 0L;
break;
default:
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
break;
- }
- return(ret);
}
+ return (ret);
+}
-static long nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
- {
- long ret=1;
+static long
+nbiof_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
+{
+ long ret = 1;
- if (b->next_bio == NULL) return(0);
- switch (cmd)
- {
+ if (b->next_bio == NULL)
+ return (0);
+ switch (cmd) {
default:
- ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
+ ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
break;
- }
- return(ret);
- }
-
-static int nbiof_gets(BIO *bp, char *buf, int size)
- {
- if (bp->next_bio == NULL) return(0);
- return(BIO_gets(bp->next_bio,buf,size));
- }
-
-
-static int nbiof_puts(BIO *bp, const char *str)
- {
- if (bp->next_bio == NULL) return(0);
- return(BIO_puts(bp->next_bio,str));
}
+ return (ret);
+}
+static int
+nbiof_gets(BIO *bp, char *buf, int size)
+{
+ if (bp->next_bio == NULL)
+ return (0);
+ return (BIO_gets(bp->next_bio, buf, size));
+}
+static int
+nbiof_puts(BIO *bp, const char *str)
+{
+ if (bp->next_bio == NULL)
+ return (0);
+ return (BIO_puts(bp->next_bio, str));
+}
static int nullf_new(BIO *h);
static int nullf_free(BIO *data);
static long nullf_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
-static BIO_METHOD methods_nullf=
- {
+
+static BIO_METHOD methods_nullf = {
BIO_TYPE_NULL_FILTER,
"NULL filter",
nullf_write,
nullf_new,
nullf_free,
nullf_callback_ctrl,
- };
-
-BIO_METHOD *BIO_f_null(void)
- {
- return(&methods_nullf);
- }
-
-static int nullf_new(BIO *bi)
- {
- bi->init=1;
- bi->ptr=NULL;
- bi->flags=0;
- return(1);
- }
-
-static int nullf_free(BIO *a)
- {
- if (a == NULL) return(0);
+};
+
+BIO_METHOD
+*BIO_f_null(void)
+{
+ return (&methods_nullf);
+}
+
+static int
+nullf_new(BIO *bi)
+{
+ bi->init = 1;
+ bi->ptr = NULL;
+ bi->flags = 0;
+ return (1);
+}
+
+static int
+nullf_free(BIO *a)
+{
+ if (a == NULL)
+ return (0);
/* a->ptr=NULL;
a->init=0;
a->flags=0;*/
- return(1);
- }
-
-static int nullf_read(BIO *b, char *out, int outl)
- {
- int ret=0;
-
- if (out == NULL) return(0);
- if (b->next_bio == NULL) return(0);
- ret=BIO_read(b->next_bio,out,outl);
+ return (1);
+}
+
+static int
+nullf_read(BIO *b, char *out, int outl)
+{
+ int ret = 0;
+
+ if (out == NULL)
+ return (0);
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_read(b->next_bio, out, outl);
BIO_clear_retry_flags(b);
BIO_copy_next_retry(b);
- return(ret);
- }
-
-static int nullf_write(BIO *b, const char *in, int inl)
- {
- int ret=0;
-
- if ((in == NULL) || (inl <= 0)) return(0);
- if (b->next_bio == NULL) return(0);
- ret=BIO_write(b->next_bio,in,inl);
+ return (ret);
+}
+
+static int
+nullf_write(BIO *b, const char *in, int inl)
+{
+ int ret = 0;
+
+ if ((in == NULL) || (inl <= 0))
+ return (0);
+ if (b->next_bio == NULL)
+ return (0);
+ ret = BIO_write(b->next_bio, in, inl);
BIO_clear_retry_flags(b);
BIO_copy_next_retry(b);
- return(ret);
- }
+ return (ret);
+}
-static long nullf_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
+static long
+nullf_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
long ret;
- if (b->next_bio == NULL) return(0);
- switch(cmd)
- {
- case BIO_C_DO_STATE_MACHINE:
+ if (b->next_bio == NULL)
+ return (0);
+ switch (cmd) {
+ case BIO_C_DO_STATE_MACHINE:
BIO_clear_retry_flags(b);
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
BIO_copy_next_retry(b);
break;
case BIO_CTRL_DUP:
- ret=0L;
+ ret = 0L;
break;
default:
- ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
- }
- return(ret);
+ ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
}
+ return (ret);
+}
-static long nullf_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
- {
- long ret=1;
+static long
+nullf_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
+{
+ long ret = 1;
- if (b->next_bio == NULL) return(0);
- switch (cmd)
- {
+ if (b->next_bio == NULL)
+ return (0);
+ switch (cmd) {
default:
- ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
+ ret = BIO_callback_ctrl(b->next_bio, cmd, fp);
break;
- }
- return(ret);
}
-
-static int nullf_gets(BIO *bp, char *buf, int size)
- {
- if (bp->next_bio == NULL) return(0);
- return(BIO_gets(bp->next_bio,buf,size));
- }
-
-
-static int nullf_puts(BIO *bp, const char *str)
- {
- if (bp->next_bio == NULL) return(0);
- return(BIO_puts(bp->next_bio,str));
- }
-
-
+ return (ret);
+}
+
+static int
+nullf_gets(BIO *bp, char *buf, int size)
+{
+ if (bp->next_bio == NULL)
+ return (0);
+ return (BIO_gets(bp->next_bio, buf, size));
+}
+
+static int
+nullf_puts(BIO *bp, const char *str)
+{
+ if (bp->next_bio == NULL)
+ return (0);
+ return (BIO_puts(bp->next_bio, str));
+}
#define BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP 37 /* flag whether the last */
#define BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP 38 /* I/O operation tiemd out */
-
+
/* #ifdef IP_MTU_DISCOVER */
#define BIO_CTRL_DGRAM_MTU_DISCOVER 39 /* set DF bit on egress packets */
/* #endif */
#define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN))
#define BIO_cb_post(a) ((a)&BIO_CB_RETURN)
-long (*BIO_get_callback(const BIO *b)) (struct bio_st *,int,const char *,int, long,long);
-void BIO_set_callback(BIO *b,
- long (*callback)(struct bio_st *,int,const char *,int, long,long));
+long (*BIO_get_callback(const BIO *b))(struct bio_st *, int, const char *,
+ int, long, long);
+void BIO_set_callback(BIO *b,
+ long (*callback)(struct bio_st *, int, const char *, int, long, long));
char *BIO_get_callback_arg(const BIO *b);
void BIO_set_callback_arg(BIO *b, char *arg);
typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long);
-typedef struct bio_method_st
- {
+typedef struct bio_method_st {
int type;
const char *name;
int (*bwrite)(BIO *, const char *, int);
long (*ctrl)(BIO *, int, long, void *);
int (*create)(BIO *);
int (*destroy)(BIO *);
- long (*callback_ctrl)(BIO *, int, bio_info_cb *);
- } BIO_METHOD;
+ long (*callback_ctrl)(BIO *, int, bio_info_cb *);
+} BIO_METHOD;
-struct bio_st
- {
+struct bio_st {
BIO_METHOD *method;
/* bio, mode, argp, argi, argl, ret */
- long (*callback)(struct bio_st *,int,const char *,int, long,long);
+ long (*callback)(struct bio_st *, int, const char *, int, long, long);
char *cb_arg; /* first argument for the callback */
int init;
unsigned long num_write;
CRYPTO_EX_DATA ex_data;
- };
+};
DECLARE_STACK_OF(BIO)
-typedef struct bio_f_buffer_ctx_struct
- {
+typedef struct bio_f_buffer_ctx_struct {
/* Buffers are setup like this:
*
* <---------------------- size ----------------------->
int ibuf_size; /* how big is the input buffer */
int obuf_size; /* how big is the output buffer */
- char *ibuf; /* the char array */
- int ibuf_len; /* how many bytes are in it */
- int ibuf_off; /* write/read offset */
+ char *ibuf; /* the char array */
+ int ibuf_len; /* how many bytes are in it */
+ int ibuf_off; /* write/read offset */
- char *obuf; /* the char array */
- int obuf_len; /* how many bytes are in it */
- int obuf_off; /* write/read offset */
- } BIO_F_BUFFER_CTX;
+ char *obuf; /* the char array */
+ int obuf_len; /* how many bytes are in it */
+ int obuf_off; /* write/read offset */
+} BIO_F_BUFFER_CTX;
/* Prefix and suffix callback in ASN1 BIO */
typedef int asn1_ps_func(BIO *b, unsigned char **pbuf, int *plen, void *parg);
#ifndef OPENSSL_NO_SCTP
/* SCTP parameter structs */
-struct bio_dgram_sctp_sndinfo
- {
+struct bio_dgram_sctp_sndinfo {
uint16_t snd_sid;
uint16_t snd_flags;
uint32_t snd_ppid;
uint32_t snd_context;
- };
+};
-struct bio_dgram_sctp_rcvinfo
- {
+struct bio_dgram_sctp_rcvinfo {
uint16_t rcv_sid;
uint16_t rcv_ssn;
uint16_t rcv_flags;
uint32_t rcv_tsn;
uint32_t rcv_cumtsn;
uint32_t rcv_context;
- };
+};
-struct bio_dgram_sctp_prinfo
- {
+struct bio_dgram_sctp_prinfo {
uint16_t pr_policy;
uint32_t pr_value;
- };
+};
#endif
/* connect BIO stuff */
/* If you are wondering why this isn't defined, its because CONST_STRICT is
* purely a compile-time kludge to allow const to be checked.
*/
-int BIO_read_filename(BIO *b,const char *name);
+int BIO_read_filename(BIO *b, const char *name);
#else
#define BIO_read_filename(b,name) BIO_ctrl(b,BIO_C_SET_FILENAME, \
BIO_CLOSE|BIO_FP_READ,(char *)name)
/* These two aren't currently implemented */
/* int BIO_get_ex_num(BIO *bio); */
/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */
-int BIO_set_ex_data(BIO *bio,int idx,void *data);
-void *BIO_get_ex_data(BIO *bio,int idx);
-int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
- CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
+int BIO_set_ex_data(BIO *bio, int idx, void *data);
+void *BIO_get_ex_data(BIO *bio, int idx);
+int
+BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
+CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
unsigned long BIO_number_read(BIO *bio);
unsigned long BIO_number_written(BIO *bio);
/* For BIO_f_asn1() */
-int BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix,
- asn1_ps_func *prefix_free);
-int BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix,
- asn1_ps_func **pprefix_free);
-int BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix,
- asn1_ps_func *suffix_free);
-int BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix,
- asn1_ps_func **psuffix_free);
+int
+BIO_asn1_set_prefix(BIO *b, asn1_ps_func *prefix,
+asn1_ps_func *prefix_free);
+int
+BIO_asn1_get_prefix(BIO *b, asn1_ps_func **pprefix,
+asn1_ps_func **pprefix_free);
+int
+BIO_asn1_set_suffix(BIO *b, asn1_ps_func *suffix,
+asn1_ps_func *suffix_free);
+int
+BIO_asn1_get_suffix(BIO *b, asn1_ps_func **psuffix,
+asn1_ps_func **psuffix_free);
# ifndef OPENSSL_NO_FP_API
BIO_METHOD *BIO_s_file(void );
# define BIO_s_file_internal BIO_s_file
# endif
BIO * BIO_new(BIO_METHOD *type);
-int BIO_set(BIO *a,BIO_METHOD *type);
+int BIO_set(BIO *a, BIO_METHOD *type);
int BIO_free(BIO *a);
void BIO_vfree(BIO *a);
int BIO_read(BIO *b, void *data, int len);
-int BIO_gets(BIO *bp,char *buf, int size);
+int BIO_gets(BIO *bp, char *buf, int size);
int BIO_write(BIO *b, const void *data, int len);
-int BIO_puts(BIO *bp,const char *buf);
-int BIO_indent(BIO *b,int indent,int max);
-long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg);
-long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long));
-char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg);
-long BIO_int_ctrl(BIO *bp,int cmd,long larg,int iarg);
-BIO * BIO_push(BIO *b,BIO *append);
+int BIO_puts(BIO *bp, const char *buf);
+int BIO_indent(BIO *b, int indent, int max);
+long BIO_ctrl(BIO *bp, int cmd, long larg, void *parg);
+long BIO_callback_ctrl(BIO *b, int cmd,
+ void (*fp)(struct bio_st *, int, const char *, int, long, long));
+char * BIO_ptr_ctrl(BIO *bp, int cmd, long larg);
+long BIO_int_ctrl(BIO *bp, int cmd, long larg, int iarg);
+BIO * BIO_push(BIO *b, BIO *append);
BIO * BIO_pop(BIO *b);
void BIO_free_all(BIO *a);
-BIO * BIO_find_type(BIO *b,int bio_type);
+BIO * BIO_find_type(BIO *b, int bio_type);
BIO * BIO_next(BIO *b);
BIO * BIO_get_retry_BIO(BIO *bio, int *reason);
int BIO_get_retry_reason(BIO *bio);
int BIO_nwrite0(BIO *bio, char **buf);
int BIO_nwrite(BIO *bio, char **buf, int num);
-long BIO_debug_callback(BIO *bio,int cmd,const char *argp,int argi,
- long argl,long ret);
+long BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi,
+ long argl, long ret);
BIO_METHOD *BIO_s_mem(void);
BIO *BIO_new_mem_buf(void *buf, int len);
int BIO_fd_should_retry(int i);
int BIO_fd_non_fatal_error(int error);
-int BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u),
- void *u, const char *s, int len);
-int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
- void *u, const char *s, int len, int indent);
-int BIO_dump(BIO *b,const char *bytes,int len);
-int BIO_dump_indent(BIO *b,const char *bytes,int len,int indent);
+int
+BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u),
+void *u, const char *s, int len);
+int
+BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
+void *u, const char *s, int len, int indent);
+int BIO_dump(BIO *b, const char *bytes, int len);
+int BIO_dump_indent(BIO *b, const char *bytes, int len, int indent);
#ifndef OPENSSL_NO_FP_API
int BIO_dump_fp(FILE *fp, const char *s, int len);
int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent);
*/
int BIO_sock_error(int sock);
int BIO_socket_ioctl(int fd, long type, void *arg);
-int BIO_socket_nbio(int fd,int mode);
+int BIO_socket_nbio(int fd, int mode);
int BIO_get_port(const char *str, unsigned short *port_ptr);
int BIO_get_host_ip(const char *str, unsigned char *ip);
-int BIO_get_accept_socket(char *host_port,int mode);
-int BIO_accept(int sock,char **ip_port);
+int BIO_get_accept_socket(char *host_port, int mode);
+int BIO_accept(int sock, char **ip_port);
int BIO_sock_init(void );
void BIO_sock_cleanup(void);
-int BIO_set_tcp_ndelay(int sock,int turn_on);
+int BIO_set_tcp_ndelay(int sock, int turn_on);
BIO *BIO_new_socket(int sock, int close_flag);
BIO *BIO_new_dgram(int fd, int close_flag);
#ifndef OPENSSL_NO_SCTP
BIO *BIO_new_dgram_sctp(int fd, int close_flag);
int BIO_dgram_is_sctp(BIO *bio);
-int BIO_dgram_sctp_notification_cb(BIO *b,
- void (*handle_notifications)(BIO *bio, void *context, void *buf),
- void *context);
+int
+BIO_dgram_sctp_notification_cb(BIO *b,
+ void (*handle_notifications)(BIO *bio, void *context, void *buf),
+void *context);
int BIO_dgram_sctp_wait_for_dry(BIO *b);
int BIO_dgram_sctp_msg_waiting(BIO *b);
#endif
BIO *BIO_new_connect(char *host_port);
BIO *BIO_new_accept(char *host_port);
-int BIO_new_bio_pair(BIO **bio1, size_t writebuf1,
- BIO **bio2, size_t writebuf2);
+int
+BIO_new_bio_pair(BIO **bio1, size_t writebuf1,
+BIO **bio2, size_t writebuf2);
/* If successful, returns 1 and in *bio1, *bio2 two BIO pair endpoints.
* Otherwise returns 0 and sets *bio1 and *bio2 to NULL.
* Size 0 uses default value.
#else
# define __bio_h__attr__(x)
#endif
-int BIO_printf(BIO *bio, const char *format, ...)
- __bio_h__attr__((__format__(__printf__,2,3)));
-int BIO_vprintf(BIO *bio, const char *format, va_list args)
- __bio_h__attr__((__format__(__printf__,2,0)));
-int BIO_snprintf(char *buf, size_t n, const char *format, ...)
- __bio_h__attr__((__format__(__printf__,3,4)));
-int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
- __bio_h__attr__((__format__(__printf__,3,0)));
+int
+BIO_printf(BIO *bio, const char *format, ...)
+__bio_h__attr__((__format__(__printf__, 2, 3)));
+int
+BIO_vprintf(BIO *bio, const char *format, va_list args)
+__bio_h__attr__((__format__(__printf__, 2, 0)));
+int
+BIO_snprintf(char *buf, size_t n, const char *format, ...)
+__bio_h__attr__((__format__(__printf__, 3, 4)));
+int
+BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
+__bio_h__attr__((__format__(__printf__, 3, 0)));
#undef __bio_h__attr__
/* BEGIN ERROR CODES */
#include <openssl/bio.h>
#include <openssl/err.h>
-long BIO_debug_callback(BIO *bio, int cmd, const char *argp,
- int argi, long argl, long ret)
- {
+long
+BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi, long argl,
+ long ret)
+{
BIO *b;
char buf[256];
char *p;
- long r=1;
+ long r = 1;
size_t p_maxlen;
if (BIO_CB_RETURN & cmd)
- r=ret;
+ r = ret;
- (void) snprintf(buf,sizeof buf,"BIO[%08lX]:",(unsigned long)bio);
- p= &(buf[14]);
+ (void) snprintf(buf, sizeof buf, "BIO[%08lX]:", (unsigned long)bio);
+ p = &(buf[14]);
p_maxlen = sizeof buf - 14;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CB_FREE:
- (void) snprintf(p,p_maxlen,"Free - %s\n",bio->method->name);
+ (void) snprintf(p, p_maxlen, "Free - %s\n", bio->method->name);
break;
case BIO_CB_READ:
if (bio->method->type & BIO_TYPE_DESCRIPTOR)
- (void) snprintf(p,p_maxlen,"read(%d,%lu) - %s fd=%d\n",
- bio->num,(unsigned long)argi,
- bio->method->name,bio->num);
+ (void) snprintf(p, p_maxlen,
+ "read(%d,%lu) - %s fd=%d\n",
+ bio->num,(unsigned long)argi,
+ bio->method->name, bio->num);
else
- (void) snprintf(p,p_maxlen,"read(%d,%lu) - %s\n",
- bio->num,(unsigned long)argi,
- bio->method->name);
+ (void) snprintf(p, p_maxlen, "read(%d,%lu) - %s\n",
+ bio->num, (unsigned long)argi, bio->method->name);
break;
case BIO_CB_WRITE:
if (bio->method->type & BIO_TYPE_DESCRIPTOR)
- (void) snprintf(p,p_maxlen,"write(%d,%lu) - %s fd=%d\n",
- bio->num,(unsigned long)argi,
- bio->method->name,bio->num);
+ (void) snprintf(p, p_maxlen,
+ "write(%d,%lu) - %s fd=%d\n",
+ bio->num, (unsigned long)argi,
+ bio->method->name, bio->num);
else
- (void) snprintf(p,p_maxlen,"write(%d,%lu) - %s\n",
- bio->num,(unsigned long)argi,
- bio->method->name);
+ (void) snprintf(p, p_maxlen, "write(%d,%lu) - %s\n",
+ bio->num, (unsigned long)argi, bio->method->name);
break;
case BIO_CB_PUTS:
- (void) snprintf(p,p_maxlen,"puts() - %s\n",bio->method->name);
+ (void) snprintf(p, p_maxlen,
+ "puts() - %s\n", bio->method->name);
break;
case BIO_CB_GETS:
- (void) snprintf(p,p_maxlen,"gets(%lu) - %s\n",(unsigned long)argi,bio->method->name);
+ (void) snprintf(p, p_maxlen, "gets(%lu) - %s\n",
+ (unsigned long)argi, bio->method->name);
break;
case BIO_CB_CTRL:
- (void) snprintf(p,p_maxlen,"ctrl(%lu) - %s\n",(unsigned long)argi,bio->method->name);
+ (void) snprintf(p, p_maxlen, "ctrl(%lu) - %s\n",
+ (unsigned long)argi, bio->method->name);
break;
case BIO_CB_RETURN|BIO_CB_READ:
- (void) snprintf(p,p_maxlen,"read return %ld\n",ret);
+ (void) snprintf(p, p_maxlen, "read return %ld\n", ret);
break;
case BIO_CB_RETURN|BIO_CB_WRITE:
- (void) snprintf(p,p_maxlen,"write return %ld\n",ret);
+ (void) snprintf(p, p_maxlen, "write return %ld\n", ret);
break;
case BIO_CB_RETURN|BIO_CB_GETS:
- (void) snprintf(p,p_maxlen,"gets return %ld\n",ret);
+ (void) snprintf(p, p_maxlen, "gets return %ld\n", ret);
break;
case BIO_CB_RETURN|BIO_CB_PUTS:
- (void) snprintf(p,p_maxlen,"puts return %ld\n",ret);
+ (void) snprintf(p, p_maxlen, "puts return %ld\n", ret);
break;
case BIO_CB_RETURN|BIO_CB_CTRL:
- (void) snprintf(p,p_maxlen,"ctrl return %ld\n",ret);
+ (void) snprintf(p, p_maxlen, "ctrl return %ld\n", ret);
break;
default:
- (void) snprintf(p,p_maxlen,"bio callback - unknown type (%d)\n",cmd);
+ (void) snprintf(p, p_maxlen,
+ "bio callback - unknown type (%d)\n", cmd);
break;
- }
+ }
- b=(BIO *)bio->cb_arg;
+ b = (BIO *)bio->cb_arg;
if (b != NULL)
- BIO_write(b,buf,strlen(buf));
+ BIO_write(b, buf, strlen(buf));
#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)
else
- fputs(buf,stderr);
+ fputs(buf, stderr);
#endif
- return(r);
- }
+ return (r);
+}
#define ERR_FUNC(func) ERR_PACK(ERR_LIB_BIO,func,0)
#define ERR_REASON(reason) ERR_PACK(ERR_LIB_BIO,0,reason)
-static ERR_STRING_DATA BIO_str_functs[]=
- {
-{ERR_FUNC(BIO_F_ACPT_STATE), "ACPT_STATE"},
-{ERR_FUNC(BIO_F_BIO_ACCEPT), "BIO_accept"},
-{ERR_FUNC(BIO_F_BIO_BER_GET_HEADER), "BIO_BER_GET_HEADER"},
-{ERR_FUNC(BIO_F_BIO_CALLBACK_CTRL), "BIO_callback_ctrl"},
-{ERR_FUNC(BIO_F_BIO_CTRL), "BIO_ctrl"},
-{ERR_FUNC(BIO_F_BIO_GETHOSTBYNAME), "BIO_gethostbyname"},
-{ERR_FUNC(BIO_F_BIO_GETS), "BIO_gets"},
-{ERR_FUNC(BIO_F_BIO_GET_ACCEPT_SOCKET), "BIO_get_accept_socket"},
-{ERR_FUNC(BIO_F_BIO_GET_HOST_IP), "BIO_get_host_ip"},
-{ERR_FUNC(BIO_F_BIO_GET_PORT), "BIO_get_port"},
-{ERR_FUNC(BIO_F_BIO_MAKE_PAIR), "BIO_MAKE_PAIR"},
-{ERR_FUNC(BIO_F_BIO_NEW), "BIO_new"},
-{ERR_FUNC(BIO_F_BIO_NEW_FILE), "BIO_new_file"},
-{ERR_FUNC(BIO_F_BIO_NEW_MEM_BUF), "BIO_new_mem_buf"},
-{ERR_FUNC(BIO_F_BIO_NREAD), "BIO_nread"},
-{ERR_FUNC(BIO_F_BIO_NREAD0), "BIO_nread0"},
-{ERR_FUNC(BIO_F_BIO_NWRITE), "BIO_nwrite"},
-{ERR_FUNC(BIO_F_BIO_NWRITE0), "BIO_nwrite0"},
-{ERR_FUNC(BIO_F_BIO_PUTS), "BIO_puts"},
-{ERR_FUNC(BIO_F_BIO_READ), "BIO_read"},
-{ERR_FUNC(BIO_F_BIO_SOCK_INIT), "BIO_sock_init"},
-{ERR_FUNC(BIO_F_BIO_WRITE), "BIO_write"},
-{ERR_FUNC(BIO_F_BUFFER_CTRL), "BUFFER_CTRL"},
-{ERR_FUNC(BIO_F_CONN_CTRL), "CONN_CTRL"},
-{ERR_FUNC(BIO_F_CONN_STATE), "CONN_STATE"},
-{ERR_FUNC(BIO_F_DGRAM_SCTP_READ), "DGRAM_SCTP_READ"},
-{ERR_FUNC(BIO_F_FILE_CTRL), "FILE_CTRL"},
-{ERR_FUNC(BIO_F_FILE_READ), "FILE_READ"},
-{ERR_FUNC(BIO_F_LINEBUFFER_CTRL), "LINEBUFFER_CTRL"},
-{ERR_FUNC(BIO_F_MEM_READ), "MEM_READ"},
-{ERR_FUNC(BIO_F_MEM_WRITE), "MEM_WRITE"},
-{ERR_FUNC(BIO_F_SSL_NEW), "SSL_new"},
-{ERR_FUNC(BIO_F_WSASTARTUP), "WSASTARTUP"},
-{0,NULL}
- };
+static ERR_STRING_DATA BIO_str_functs[]= {
+ {ERR_FUNC(BIO_F_ACPT_STATE), "ACPT_STATE"},
+ {ERR_FUNC(BIO_F_BIO_ACCEPT), "BIO_accept"},
+ {ERR_FUNC(BIO_F_BIO_BER_GET_HEADER), "BIO_BER_GET_HEADER"},
+ {ERR_FUNC(BIO_F_BIO_CALLBACK_CTRL), "BIO_callback_ctrl"},
+ {ERR_FUNC(BIO_F_BIO_CTRL), "BIO_ctrl"},
+ {ERR_FUNC(BIO_F_BIO_GETHOSTBYNAME), "BIO_gethostbyname"},
+ {ERR_FUNC(BIO_F_BIO_GETS), "BIO_gets"},
+ {ERR_FUNC(BIO_F_BIO_GET_ACCEPT_SOCKET), "BIO_get_accept_socket"},
+ {ERR_FUNC(BIO_F_BIO_GET_HOST_IP), "BIO_get_host_ip"},
+ {ERR_FUNC(BIO_F_BIO_GET_PORT), "BIO_get_port"},
+ {ERR_FUNC(BIO_F_BIO_MAKE_PAIR), "BIO_MAKE_PAIR"},
+ {ERR_FUNC(BIO_F_BIO_NEW), "BIO_new"},
+ {ERR_FUNC(BIO_F_BIO_NEW_FILE), "BIO_new_file"},
+ {ERR_FUNC(BIO_F_BIO_NEW_MEM_BUF), "BIO_new_mem_buf"},
+ {ERR_FUNC(BIO_F_BIO_NREAD), "BIO_nread"},
+ {ERR_FUNC(BIO_F_BIO_NREAD0), "BIO_nread0"},
+ {ERR_FUNC(BIO_F_BIO_NWRITE), "BIO_nwrite"},
+ {ERR_FUNC(BIO_F_BIO_NWRITE0), "BIO_nwrite0"},
+ {ERR_FUNC(BIO_F_BIO_PUTS), "BIO_puts"},
+ {ERR_FUNC(BIO_F_BIO_READ), "BIO_read"},
+ {ERR_FUNC(BIO_F_BIO_SOCK_INIT), "BIO_sock_init"},
+ {ERR_FUNC(BIO_F_BIO_WRITE), "BIO_write"},
+ {ERR_FUNC(BIO_F_BUFFER_CTRL), "BUFFER_CTRL"},
+ {ERR_FUNC(BIO_F_CONN_CTRL), "CONN_CTRL"},
+ {ERR_FUNC(BIO_F_CONN_STATE), "CONN_STATE"},
+ {ERR_FUNC(BIO_F_DGRAM_SCTP_READ), "DGRAM_SCTP_READ"},
+ {ERR_FUNC(BIO_F_FILE_CTRL), "FILE_CTRL"},
+ {ERR_FUNC(BIO_F_FILE_READ), "FILE_READ"},
+ {ERR_FUNC(BIO_F_LINEBUFFER_CTRL), "LINEBUFFER_CTRL"},
+ {ERR_FUNC(BIO_F_MEM_READ), "MEM_READ"},
+ {ERR_FUNC(BIO_F_MEM_WRITE), "MEM_WRITE"},
+ {ERR_FUNC(BIO_F_SSL_NEW), "SSL_new"},
+ {ERR_FUNC(BIO_F_WSASTARTUP), "WSASTARTUP"},
+ {0, NULL}
+};
-static ERR_STRING_DATA BIO_str_reasons[]=
- {
-{ERR_REASON(BIO_R_ACCEPT_ERROR) ,"accept error"},
-{ERR_REASON(BIO_R_BAD_FOPEN_MODE) ,"bad fopen mode"},
-{ERR_REASON(BIO_R_BAD_HOSTNAME_LOOKUP) ,"bad hostname lookup"},
-{ERR_REASON(BIO_R_BROKEN_PIPE) ,"broken pipe"},
-{ERR_REASON(BIO_R_CONNECT_ERROR) ,"connect error"},
-{ERR_REASON(BIO_R_EOF_ON_MEMORY_BIO) ,"EOF on memory BIO"},
-{ERR_REASON(BIO_R_ERROR_SETTING_NBIO) ,"error setting nbio"},
-{ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET),"error setting nbio on accepted socket"},
-{ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET),"error setting nbio on accept socket"},
-{ERR_REASON(BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET),"gethostbyname addr is not af inet"},
-{ERR_REASON(BIO_R_INVALID_ARGUMENT) ,"invalid argument"},
-{ERR_REASON(BIO_R_INVALID_IP_ADDRESS) ,"invalid ip address"},
-{ERR_REASON(BIO_R_IN_USE) ,"in use"},
-{ERR_REASON(BIO_R_KEEPALIVE) ,"keepalive"},
-{ERR_REASON(BIO_R_NBIO_CONNECT_ERROR) ,"nbio connect error"},
-{ERR_REASON(BIO_R_NO_ACCEPT_PORT_SPECIFIED),"no accept port specified"},
-{ERR_REASON(BIO_R_NO_HOSTNAME_SPECIFIED) ,"no hostname specified"},
-{ERR_REASON(BIO_R_NO_PORT_DEFINED) ,"no port defined"},
-{ERR_REASON(BIO_R_NO_PORT_SPECIFIED) ,"no port specified"},
-{ERR_REASON(BIO_R_NO_SUCH_FILE) ,"no such file"},
-{ERR_REASON(BIO_R_NULL_PARAMETER) ,"null parameter"},
-{ERR_REASON(BIO_R_TAG_MISMATCH) ,"tag mismatch"},
-{ERR_REASON(BIO_R_UNABLE_TO_BIND_SOCKET) ,"unable to bind socket"},
-{ERR_REASON(BIO_R_UNABLE_TO_CREATE_SOCKET),"unable to create socket"},
-{ERR_REASON(BIO_R_UNABLE_TO_LISTEN_SOCKET),"unable to listen socket"},
-{ERR_REASON(BIO_R_UNINITIALIZED) ,"uninitialized"},
-{ERR_REASON(BIO_R_UNSUPPORTED_METHOD) ,"unsupported method"},
-{ERR_REASON(BIO_R_WRITE_TO_READ_ONLY_BIO),"write to read only BIO"},
-{ERR_REASON(BIO_R_WSASTARTUP) ,"WSAStartup"},
-{0,NULL}
- };
+static ERR_STRING_DATA BIO_str_reasons[]= {
+ {ERR_REASON(BIO_R_ACCEPT_ERROR) , "accept error"},
+ {ERR_REASON(BIO_R_BAD_FOPEN_MODE) , "bad fopen mode"},
+ {ERR_REASON(BIO_R_BAD_HOSTNAME_LOOKUP) , "bad hostname lookup"},
+ {ERR_REASON(BIO_R_BROKEN_PIPE) , "broken pipe"},
+ {ERR_REASON(BIO_R_CONNECT_ERROR) , "connect error"},
+ {ERR_REASON(BIO_R_EOF_ON_MEMORY_BIO) , "EOF on memory BIO"},
+ {ERR_REASON(BIO_R_ERROR_SETTING_NBIO) , "error setting nbio"},
+ {ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET), "error setting nbio on accepted socket"},
+ {ERR_REASON(BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET), "error setting nbio on accept socket"},
+ {ERR_REASON(BIO_R_GETHOSTBYNAME_ADDR_IS_NOT_AF_INET), "gethostbyname addr is not af inet"},
+ {ERR_REASON(BIO_R_INVALID_ARGUMENT) , "invalid argument"},
+ {ERR_REASON(BIO_R_INVALID_IP_ADDRESS) , "invalid ip address"},
+ {ERR_REASON(BIO_R_IN_USE) , "in use"},
+ {ERR_REASON(BIO_R_KEEPALIVE) , "keepalive"},
+ {ERR_REASON(BIO_R_NBIO_CONNECT_ERROR) , "nbio connect error"},
+ {ERR_REASON(BIO_R_NO_ACCEPT_PORT_SPECIFIED), "no accept port specified"},
+ {ERR_REASON(BIO_R_NO_HOSTNAME_SPECIFIED) , "no hostname specified"},
+ {ERR_REASON(BIO_R_NO_PORT_DEFINED) , "no port defined"},
+ {ERR_REASON(BIO_R_NO_PORT_SPECIFIED) , "no port specified"},
+ {ERR_REASON(BIO_R_NO_SUCH_FILE) , "no such file"},
+ {ERR_REASON(BIO_R_NULL_PARAMETER) , "null parameter"},
+ {ERR_REASON(BIO_R_TAG_MISMATCH) , "tag mismatch"},
+ {ERR_REASON(BIO_R_UNABLE_TO_BIND_SOCKET) , "unable to bind socket"},
+ {ERR_REASON(BIO_R_UNABLE_TO_CREATE_SOCKET), "unable to create socket"},
+ {ERR_REASON(BIO_R_UNABLE_TO_LISTEN_SOCKET), "unable to listen socket"},
+ {ERR_REASON(BIO_R_UNINITIALIZED) , "uninitialized"},
+ {ERR_REASON(BIO_R_UNSUPPORTED_METHOD) , "unsupported method"},
+ {ERR_REASON(BIO_R_WRITE_TO_READ_ONLY_BIO), "write to read only BIO"},
+ {ERR_REASON(BIO_R_WSASTARTUP) , "WSAStartup"},
+ {0, NULL}
+};
#endif
-void ERR_load_BIO_strings(void)
- {
+void
+ERR_load_BIO_strings(void)
+{
#ifndef OPENSSL_NO_ERR
-
- if (ERR_func_error_string(BIO_str_functs[0].error) == NULL)
- {
- ERR_load_strings(0,BIO_str_functs);
- ERR_load_strings(0,BIO_str_reasons);
- }
-#endif
+ if (ERR_func_error_string(BIO_str_functs[0].error) == NULL) {
+ ERR_load_strings(0, BIO_str_functs);
+ ERR_load_strings(0, BIO_str_reasons);
}
+#endif
+}
#include <openssl/bio.h>
#include <openssl/stack.h>
-BIO *BIO_new(BIO_METHOD *method)
- {
- BIO *ret=NULL;
-
- ret=(BIO *)OPENSSL_malloc(sizeof(BIO));
- if (ret == NULL)
- {
- BIOerr(BIO_F_BIO_NEW,ERR_R_MALLOC_FAILURE);
- return(NULL);
- }
- if (!BIO_set(ret,method))
- {
+BIO
+*BIO_new(BIO_METHOD *method)
+{
+ BIO *ret = NULL;
+
+ ret = (BIO *)OPENSSL_malloc(sizeof(BIO));
+ if (ret == NULL) {
+ BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE);
+ return (NULL);
+ }
+ if (!BIO_set(ret, method)) {
OPENSSL_free(ret);
- ret=NULL;
- }
- return(ret);
+ ret = NULL;
}
+ return (ret);
+}
-int BIO_set(BIO *bio, BIO_METHOD *method)
- {
- bio->method=method;
- bio->callback=NULL;
- bio->cb_arg=NULL;
- bio->init=0;
- bio->shutdown=1;
- bio->flags=0;
- bio->retry_reason=0;
- bio->num=0;
- bio->ptr=NULL;
- bio->prev_bio=NULL;
- bio->next_bio=NULL;
- bio->references=1;
- bio->num_read=0L;
- bio->num_write=0L;
+int
+BIO_set(BIO *bio, BIO_METHOD *method)
+{
+ bio->method = method;
+ bio->callback = NULL;
+ bio->cb_arg = NULL;
+ bio->init = 0;
+ bio->shutdown = 1;
+ bio->flags = 0;
+ bio->retry_reason = 0;
+ bio->num = 0;
+ bio->ptr = NULL;
+ bio->prev_bio = NULL;
+ bio->next_bio = NULL;
+ bio->references = 1;
+ bio->num_read = 0L;
+ bio->num_write = 0L;
CRYPTO_new_ex_data(CRYPTO_EX_INDEX_BIO, bio, &bio->ex_data);
if (method->create != NULL)
- if (!method->create(bio))
- {
+ if (!method->create(bio)) {
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, bio,
- &bio->ex_data);
- return(0);
- }
- return(1);
- }
+ &bio->ex_data);
+ return (0);
+ }
+ return (1);
+}
-int BIO_free(BIO *a)
- {
+int
+BIO_free(BIO *a)
+{
int i;
- if (a == NULL) return(0);
+ if (a == NULL)
+ return (0);
- i=CRYPTO_add(&a->references,-1,CRYPTO_LOCK_BIO);
+ i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_BIO);
#ifdef REF_PRINT
- REF_PRINT("BIO",a);
+ REF_PRINT("BIO", a);
#endif
- if (i > 0) return(1);
+ if (i > 0)
+ return (1);
#ifdef REF_CHECK
- if (i < 0)
- {
- fprintf(stderr,"BIO_free, bad reference count\n");
+ if (i < 0) {
+ fprintf(stderr, "BIO_free, bad reference count\n");
abort();
- }
+ }
#endif
if ((a->callback != NULL) &&
- ((i=(int)a->callback(a,BIO_CB_FREE,NULL,0,0L,1L)) <= 0))
- return(i);
+ ((i = (int)a->callback(a, BIO_CB_FREE, NULL, 0, 0L, 1L)) <= 0))
+ return (i);
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_BIO, a, &a->ex_data);
- if ((a->method == NULL) || (a->method->destroy == NULL)) return(1);
+ if ((a->method == NULL) || (a->method->destroy == NULL))
+ return (1);
a->method->destroy(a);
OPENSSL_free(a);
- return(1);
- }
+ return (1);
+}
-void BIO_vfree(BIO *a)
- { BIO_free(a); }
+void
+BIO_vfree(BIO *a)
+{
+ BIO_free(a);
+}
-void BIO_clear_flags(BIO *b, int flags)
- {
+void
+BIO_clear_flags(BIO *b, int flags)
+{
b->flags &= ~flags;
- }
+}
-int BIO_test_flags(const BIO *b, int flags)
- {
+int
+BIO_test_flags(const BIO *b, int flags)
+{
return (b->flags & flags);
- }
+}
-void BIO_set_flags(BIO *b, int flags)
- {
+void
+BIO_set_flags(BIO *b, int flags)
+{
b->flags |= flags;
- }
+}
-long (*BIO_get_callback(const BIO *b))(struct bio_st *,int,const char *,int, long,long)
- {
+long
+(*BIO_get_callback(const BIO *b))(struct bio_st *, int, const char *, int,
+ long, long)
+{
return b->callback;
- }
+}
-void BIO_set_callback(BIO *b, long (*cb)(struct bio_st *,int,const char *,int, long,long))
- {
+void
+BIO_set_callback(BIO *b, long (*cb)(struct bio_st *, int, const char *, int,
+ long, long))
+{
b->callback = cb;
- }
+}
-void BIO_set_callback_arg(BIO *b, char *arg)
- {
+void
+BIO_set_callback_arg(BIO *b, char *arg)
+{
b->cb_arg = arg;
- }
+}
-char * BIO_get_callback_arg(const BIO *b)
- {
+char *
+BIO_get_callback_arg(const BIO *b)
+{
return b->cb_arg;
- }
+}
-const char * BIO_method_name(const BIO *b)
- {
+const char *
+BIO_method_name(const BIO *b)
+{
return b->method->name;
- }
+}
-int BIO_method_type(const BIO *b)
- {
+int
+BIO_method_type(const BIO *b)
+{
return b->method->type;
- }
-
+}
-int BIO_read(BIO *b, void *out, int outl)
- {
+int
+BIO_read(BIO *b, void *out, int outl)
+{
int i;
- long (*cb)(BIO *,int,const char *,int,long,long);
+ long (*cb)(BIO *, int, const char *, int, long, long);
- if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL))
- {
- BIOerr(BIO_F_BIO_READ,BIO_R_UNSUPPORTED_METHOD);
- return(-2);
- }
+ if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) {
+ BIOerr(BIO_F_BIO_READ, BIO_R_UNSUPPORTED_METHOD);
+ return (-2);
+ }
- cb=b->callback;
+ cb = b->callback;
if ((cb != NULL) &&
- ((i=(int)cb(b,BIO_CB_READ,out,outl,0L,1L)) <= 0))
- return(i);
+ ((i = (int)cb(b, BIO_CB_READ, out, outl, 0L, 1L)) <= 0))
+ return (i);
- if (!b->init)
- {
- BIOerr(BIO_F_BIO_READ,BIO_R_UNINITIALIZED);
- return(-2);
- }
+ if (!b->init) {
+ BIOerr(BIO_F_BIO_READ, BIO_R_UNINITIALIZED);
+ return (-2);
+ }
- i=b->method->bread(b,out,outl);
+ i = b->method->bread(b, out, outl);
- if (i > 0) b->num_read+=(unsigned long)i;
+ if (i > 0)
+ b->num_read += (unsigned long)i;
if (cb != NULL)
- i=(int)cb(b,BIO_CB_READ|BIO_CB_RETURN,out,outl,
- 0L,(long)i);
- return(i);
- }
+ i = (int)cb(b, BIO_CB_READ|BIO_CB_RETURN, out, outl,
+ 0L, (long)i);
+ return (i);
+}
-int BIO_write(BIO *b, const void *in, int inl)
- {
+int
+BIO_write(BIO *b, const void *in, int inl)
+{
int i;
- long (*cb)(BIO *,int,const char *,int,long,long);
+ long (*cb)(BIO *, int, const char *, int, long, long);
if (b == NULL)
- return(0);
+ return (0);
- cb=b->callback;
- if ((b->method == NULL) || (b->method->bwrite == NULL))
- {
- BIOerr(BIO_F_BIO_WRITE,BIO_R_UNSUPPORTED_METHOD);
- return(-2);
- }
+ cb = b->callback;
+ if ((b->method == NULL) || (b->method->bwrite == NULL)) {
+ BIOerr(BIO_F_BIO_WRITE, BIO_R_UNSUPPORTED_METHOD);
+ return (-2);
+ }
if ((cb != NULL) &&
- ((i=(int)cb(b,BIO_CB_WRITE,in,inl,0L,1L)) <= 0))
- return(i);
+ ((i = (int)cb(b, BIO_CB_WRITE, in, inl, 0L, 1L)) <= 0))
+ return (i);
- if (!b->init)
- {
- BIOerr(BIO_F_BIO_WRITE,BIO_R_UNINITIALIZED);
- return(-2);
- }
+ if (!b->init) {
+ BIOerr(BIO_F_BIO_WRITE, BIO_R_UNINITIALIZED);
+ return (-2);
+ }
- i=b->method->bwrite(b,in,inl);
+ i = b->method->bwrite(b, in, inl);
- if (i > 0) b->num_write+=(unsigned long)i;
+ if (i > 0)
+ b->num_write += (unsigned long)i;
if (cb != NULL)
- i=(int)cb(b,BIO_CB_WRITE|BIO_CB_RETURN,in,inl,
- 0L,(long)i);
- return(i);
- }
+ i = (int)cb(b, BIO_CB_WRITE|BIO_CB_RETURN, in, inl,
+ 0L, (long)i);
+ return (i);
+}
-int BIO_puts(BIO *b, const char *in)
- {
+int
+BIO_puts(BIO *b, const char *in)
+{
int i;
- long (*cb)(BIO *,int,const char *,int,long,long);
+ long (*cb)(BIO *, int, const char *, int, long, long);
- if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL))
- {
- BIOerr(BIO_F_BIO_PUTS,BIO_R_UNSUPPORTED_METHOD);
- return(-2);
- }
+ if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) {
+ BIOerr(BIO_F_BIO_PUTS, BIO_R_UNSUPPORTED_METHOD);
+ return (-2);
+ }
- cb=b->callback;
+ cb = b->callback;
if ((cb != NULL) &&
- ((i=(int)cb(b,BIO_CB_PUTS,in,0,0L,1L)) <= 0))
- return(i);
+ ((i = (int)cb(b, BIO_CB_PUTS, in, 0, 0L, 1L)) <= 0))
+ return (i);
- if (!b->init)
- {
- BIOerr(BIO_F_BIO_PUTS,BIO_R_UNINITIALIZED);
- return(-2);
- }
+ if (!b->init) {
+ BIOerr(BIO_F_BIO_PUTS, BIO_R_UNINITIALIZED);
+ return (-2);
+ }
- i=b->method->bputs(b,in);
+ i = b->method->bputs(b, in);
- if (i > 0) b->num_write+=(unsigned long)i;
+ if (i > 0)
+ b->num_write += (unsigned long)i;
if (cb != NULL)
- i=(int)cb(b,BIO_CB_PUTS|BIO_CB_RETURN,in,0,
- 0L,(long)i);
- return(i);
- }
+ i = (int)cb(b, BIO_CB_PUTS|BIO_CB_RETURN, in, 0, 0L, (long)i);
+ return (i);
+}
-int BIO_gets(BIO *b, char *in, int inl)
- {
+int
+BIO_gets(BIO *b, char *in, int inl)
+{
int i;
- long (*cb)(BIO *,int,const char *,int,long,long);
+ long (*cb)(BIO *, int, const char *, int, long, long);
- if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL))
- {
- BIOerr(BIO_F_BIO_GETS,BIO_R_UNSUPPORTED_METHOD);
- return(-2);
- }
+ if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL)) {
+ BIOerr(BIO_F_BIO_GETS, BIO_R_UNSUPPORTED_METHOD);
+ return (-2);
+ }
- cb=b->callback;
+ cb = b->callback;
if ((cb != NULL) &&
- ((i=(int)cb(b,BIO_CB_GETS,in,inl,0L,1L)) <= 0))
- return(i);
+ ((i = (int)cb(b, BIO_CB_GETS, in, inl, 0L, 1L)) <= 0))
+ return (i);
- if (!b->init)
- {
- BIOerr(BIO_F_BIO_GETS,BIO_R_UNINITIALIZED);
- return(-2);
- }
+ if (!b->init) {
+ BIOerr(BIO_F_BIO_GETS, BIO_R_UNINITIALIZED);
+ return (-2);
+ }
- i=b->method->bgets(b,in,inl);
+ i = b->method->bgets(b, in, inl);
if (cb != NULL)
- i=(int)cb(b,BIO_CB_GETS|BIO_CB_RETURN,in,inl,
- 0L,(long)i);
- return(i);
- }
+ i = (int)cb(b, BIO_CB_GETS|BIO_CB_RETURN, in, inl, 0L, (long)i);
+ return (i);
+}
-int BIO_indent(BIO *b,int indent,int max)
- {
- if(indent < 0)
- indent=0;
- if(indent > max)
- indent=max;
- while(indent--)
- if(BIO_puts(b," ") != 1)
- return 0;
+int
+BIO_indent(BIO *b, int indent, int max)
+{
+ if (indent < 0)
+ indent = 0;
+ if (indent > max)
+ indent = max;
+ while (indent--)
+ if (BIO_puts(b, " ") != 1)
+ return 0;
return 1;
- }
+}
-long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg)
- {
+long
+BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg)
+{
int i;
- i=iarg;
- return(BIO_ctrl(b,cmd,larg,(char *)&i));
- }
+ i = iarg;
+ return (BIO_ctrl(b, cmd, larg,(char *)&i));
+}
-char *BIO_ptr_ctrl(BIO *b, int cmd, long larg)
- {
- char *p=NULL;
+char
+*BIO_ptr_ctrl(BIO *b, int cmd, long larg)
+{
+ char *p = NULL;
- if (BIO_ctrl(b,cmd,larg,(char *)&p) <= 0)
- return(NULL);
+ if (BIO_ctrl(b, cmd, larg,(char *)&p) <= 0)
+ return (NULL);
else
- return(p);
- }
+ return (p);
+}
-long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
- {
+long
+BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
+{
long ret;
- long (*cb)(BIO *,int,const char *,int,long,long);
+ long (*cb)(BIO *, int, const char *, int, long, long);
- if (b == NULL) return(0);
+ if (b == NULL)
+ return (0);
- if ((b->method == NULL) || (b->method->ctrl == NULL))
- {
- BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD);
- return(-2);
- }
+ if ((b->method == NULL) || (b->method->ctrl == NULL)) {
+ BIOerr(BIO_F_BIO_CTRL, BIO_R_UNSUPPORTED_METHOD);
+ return (-2);
+ }
- cb=b->callback;
+ cb = b->callback;
if ((cb != NULL) &&
- ((ret=cb(b,BIO_CB_CTRL,parg,cmd,larg,1L)) <= 0))
- return(ret);
+ ((ret = cb(b, BIO_CB_CTRL, parg, cmd, larg, 1L)) <= 0))
+ return (ret);
- ret=b->method->ctrl(b,cmd,larg,parg);
+ ret = b->method->ctrl(b, cmd, larg, parg);
if (cb != NULL)
- ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,parg,cmd,
- larg,ret);
- return(ret);
- }
+ ret = cb(b, BIO_CB_CTRL|BIO_CB_RETURN, parg, cmd, larg, ret);
+ return (ret);
+}
-long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long))
- {
+long
+BIO_callback_ctrl(BIO *b, int cmd,
+ void (*fp)(struct bio_st *, int, const char *, int, long, long))
+{
long ret;
- long (*cb)(BIO *,int,const char *,int,long,long);
+ long (*cb)(BIO *, int, const char *, int, long, long);
- if (b == NULL) return(0);
+ if (b == NULL)
+ return (0);
- if ((b->method == NULL) || (b->method->callback_ctrl == NULL))
- {
- BIOerr(BIO_F_BIO_CALLBACK_CTRL,BIO_R_UNSUPPORTED_METHOD);
- return(-2);
- }
+ if ((b->method == NULL) || (b->method->callback_ctrl == NULL)) {
+ BIOerr(BIO_F_BIO_CALLBACK_CTRL, BIO_R_UNSUPPORTED_METHOD);
+ return (-2);
+ }
- cb=b->callback;
+ cb = b->callback;
if ((cb != NULL) &&
- ((ret=cb(b,BIO_CB_CTRL,(void *)&fp,cmd,0,1L)) <= 0))
- return(ret);
+ ((ret = cb(b, BIO_CB_CTRL,(void *)&fp, cmd, 0, 1L)) <= 0))
+ return (ret);
- ret=b->method->callback_ctrl(b,cmd,fp);
+ ret = b->method->callback_ctrl(b, cmd, fp);
if (cb != NULL)
- ret=cb(b,BIO_CB_CTRL|BIO_CB_RETURN,(void *)&fp,cmd,
- 0,ret);
- return(ret);
- }
+ ret = cb(b, BIO_CB_CTRL|BIO_CB_RETURN,(void *)&fp, cmd, 0, ret);
+ return (ret);
+}
/* It is unfortunate to duplicate in functions what the BIO_(w)pending macros
* do; but those macros have inappropriate return type, and for interfacing
* from other programming languages, C macros aren't much of a help anyway. */
-size_t BIO_ctrl_pending(BIO *bio)
- {
+size_t
+BIO_ctrl_pending(BIO *bio)
+{
return BIO_ctrl(bio, BIO_CTRL_PENDING, 0, NULL);
- }
+}
-size_t BIO_ctrl_wpending(BIO *bio)
- {
+size_t
+BIO_ctrl_wpending(BIO *bio)
+{
return BIO_ctrl(bio, BIO_CTRL_WPENDING, 0, NULL);
- }
+}
/* put the 'bio' on the end of b's list of operators */
-BIO *BIO_push(BIO *b, BIO *bio)
- {
+BIO
+*BIO_push(BIO *b, BIO *bio)
+{
BIO *lb;
- if (b == NULL) return(bio);
- lb=b;
+ if (b == NULL)
+ return (bio);
+ lb = b;
while (lb->next_bio != NULL)
- lb=lb->next_bio;
- lb->next_bio=bio;
+ lb = lb->next_bio;
+ lb->next_bio = bio;
if (bio != NULL)
- bio->prev_bio=lb;
+ bio->prev_bio = lb;
/* called to do internal processing */
- BIO_ctrl(b,BIO_CTRL_PUSH,0,lb);
- return(b);
- }
+ BIO_ctrl(b, BIO_CTRL_PUSH, 0, lb);
+ return (b);
+}
/* Remove the first and return the rest */
-BIO *BIO_pop(BIO *b)
- {
+BIO
+*BIO_pop(BIO *b)
+{
BIO *ret;
- if (b == NULL) return(NULL);
- ret=b->next_bio;
+ if (b == NULL)
+ return (NULL);
+ ret = b->next_bio;
- BIO_ctrl(b,BIO_CTRL_POP,0,b);
+ BIO_ctrl(b, BIO_CTRL_POP, 0, b);
if (b->prev_bio != NULL)
- b->prev_bio->next_bio=b->next_bio;
+ b->prev_bio->next_bio = b->next_bio;
if (b->next_bio != NULL)
- b->next_bio->prev_bio=b->prev_bio;
+ b->next_bio->prev_bio = b->prev_bio;
- b->next_bio=NULL;
- b->prev_bio=NULL;
- return(ret);
- }
+ b->next_bio = NULL;
+ b->prev_bio = NULL;
+ return (ret);
+}
-BIO *BIO_get_retry_BIO(BIO *bio, int *reason)
- {
- BIO *b,*last;
+BIO
+*BIO_get_retry_BIO(BIO *bio, int *reason)
+{
+ BIO *b, *last;
- b=last=bio;
- for (;;)
- {
+ b = last = bio;
+ for (;;) {
if (!BIO_should_retry(b)) break;
- last=b;
- b=b->next_bio;
- if (b == NULL) break;
- }
- if (reason != NULL) *reason=last->retry_reason;
- return(last);
- }
+ last = b;
+ b = b->next_bio;
+ if (b == NULL)
+ break;
+ }
+ if (reason != NULL)
+ *reason = last->retry_reason;
+ return (last);
+}
-int BIO_get_retry_reason(BIO *bio)
- {
- return(bio->retry_reason);
- }
+int
+BIO_get_retry_reason(BIO *bio)
+{
+ return (bio->retry_reason);
+}
-BIO *BIO_find_type(BIO *bio, int type)
- {
- int mt,mask;
-
- if(!bio) return NULL;
- mask=type&0xff;
- do {
- if (bio->method != NULL)
- {
- mt=bio->method->type;
-
- if (!mask)
- {
- if (mt & type) return(bio);
- }
- else if (mt == type)
- return(bio);
- }
- bio=bio->next_bio;
- } while (bio != NULL);
- return(NULL);
- }
+BIO
+*BIO_find_type(BIO *bio, int type)
+{
+ int mt, mask;
+
+ if (!bio)
+ return NULL;
+ mask = type & 0xff;
+ do {
+ if (bio->method != NULL) {
+ mt = bio->method->type;
+ if (!mask) {
+ if (mt & type)
+ return (bio);
+ } else if (mt == type)
+ return (bio);
+ }
+ bio = bio->next_bio;
+ } while (bio != NULL);
+ return (NULL);
+}
-BIO *BIO_next(BIO *b)
- {
- if(!b) return NULL;
+BIO
+*BIO_next(BIO *b)
+{
+ if (!b)
+ return NULL;
return b->next_bio;
- }
+}
-void BIO_free_all(BIO *bio)
- {
+void
+BIO_free_all(BIO *bio)
+{
BIO *b;
int ref;
- while (bio != NULL)
- {
- b=bio;
- ref=b->references;
- bio=bio->next_bio;
+ while (bio != NULL) {
+ b = bio;
+ ref = b->references;
+ bio = bio->next_bio;
BIO_free(b);
/* Since ref count > 1, don't free anyone else. */
- if (ref > 1) break;
- }
+ if (ref > 1)
+ break;
}
+}
-BIO *BIO_dup_chain(BIO *in)
- {
- BIO *ret=NULL,*eoc=NULL,*bio,*new_bio;
+BIO
+*BIO_dup_chain(BIO *in)
+{
+ BIO *ret = NULL, *eoc = NULL, *bio, *new_bio;
- for (bio=in; bio != NULL; bio=bio->next_bio)
- {
- if ((new_bio=BIO_new(bio->method)) == NULL) goto err;
- new_bio->callback=bio->callback;
- new_bio->cb_arg=bio->cb_arg;
- new_bio->init=bio->init;
- new_bio->shutdown=bio->shutdown;
- new_bio->flags=bio->flags;
+ for (bio = in; bio != NULL; bio = bio->next_bio) {
+ if ((new_bio = BIO_new(bio->method)) == NULL) goto err;
+ new_bio->callback = bio->callback;
+ new_bio->cb_arg = bio->cb_arg;
+ new_bio->init = bio->init;
+ new_bio->shutdown = bio->shutdown;
+ new_bio->flags = bio->flags;
/* This will let SSL_s_sock() work with stdin/stdout */
- new_bio->num=bio->num;
+ new_bio->num = bio->num;
- if (!BIO_dup_state(bio,(char *)new_bio))
- {
+ if (!BIO_dup_state(bio,(char *)new_bio)) {
BIO_free(new_bio);
goto err;
- }
+ }
/* copy app data */
- if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_BIO, &new_bio->ex_data,
- &bio->ex_data))
+ if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_BIO,
+ &new_bio->ex_data, &bio->ex_data))
goto err;
- if (ret == NULL)
- {
- eoc=new_bio;
- ret=eoc;
- }
- else
- {
- BIO_push(eoc,new_bio);
- eoc=new_bio;
- }
+ if (ret == NULL) {
+ eoc = new_bio;
+ ret = eoc;
+ } else {
+ BIO_push(eoc, new_bio);
+ eoc = new_bio;
}
- return(ret);
+ }
+ return (ret);
err:
if (ret != NULL)
BIO_free(ret);
- return(NULL);
- }
+ return (NULL);
-void BIO_copy_next_retry(BIO *b)
- {
- BIO_set_flags(b,BIO_get_retry_flags(b->next_bio));
- b->retry_reason=b->next_bio->retry_reason;
- }
+}
-int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
- CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
- {
+void
+BIO_copy_next_retry(BIO *b)
+{
+ BIO_set_flags(b, BIO_get_retry_flags(b->next_bio));
+ b->retry_reason = b->next_bio->retry_reason;
+}
+
+int
+BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
+ CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
+{
return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_BIO, argl, argp,
- new_func, dup_func, free_func);
- }
+ new_func, dup_func, free_func);
+}
-int BIO_set_ex_data(BIO *bio, int idx, void *data)
- {
- return(CRYPTO_set_ex_data(&(bio->ex_data),idx,data));
- }
+int
+BIO_set_ex_data(BIO *bio, int idx, void *data)
+{
+ return (CRYPTO_set_ex_data(&(bio->ex_data), idx, data));
+}
-void *BIO_get_ex_data(BIO *bio, int idx)
- {
- return(CRYPTO_get_ex_data(&(bio->ex_data),idx));
- }
+void
+*BIO_get_ex_data(BIO *bio, int idx)
+{
+ return (CRYPTO_get_ex_data(&(bio->ex_data), idx));
+}
-unsigned long BIO_number_read(BIO *bio)
+unsigned long
+BIO_number_read(BIO *bio)
{
- if(bio) return bio->num_read;
+ if (bio)
+ return bio->num_read;
return 0;
}
-unsigned long BIO_number_written(BIO *bio)
+unsigned long
+BIO_number_written(BIO *bio)
{
- if(bio) return bio->num_write;
+ if (bio)
+ return bio->num_write;
return 0;
}
#undef FIONBIO
#endif
-typedef struct bio_accept_st
- {
+typedef struct bio_accept_st {
int state;
char *param_addr;
* If 2, always use SO_REUSEADDR. */
int bind_mode;
BIO *bio_chain;
- } BIO_ACCEPT;
+} BIO_ACCEPT;
static int acpt_write(BIO *h, const char *buf, int num);
static int acpt_read(BIO *h, char *buf, int size);
#define ACPT_S_GET_ACCEPT_SOCKET 2
#define ACPT_S_OK 3
-static BIO_METHOD methods_acceptp=
- {
+static BIO_METHOD methods_acceptp = {
BIO_TYPE_ACCEPT,
"socket accept",
acpt_write,
acpt_new,
acpt_free,
NULL,
- };
+};
-BIO_METHOD *BIO_s_accept(void)
- {
- return(&methods_acceptp);
- }
+BIO_METHOD
+*BIO_s_accept(void)
+{
+ return (&methods_acceptp);
+}
-static int acpt_new(BIO *bi)
- {
+static int
+acpt_new(BIO *bi)
+{
BIO_ACCEPT *ba;
- bi->init=0;
- bi->num=-1;
- bi->flags=0;
- if ((ba=BIO_ACCEPT_new()) == NULL)
- return(0);
- bi->ptr=(char *)ba;
- ba->state=ACPT_S_BEFORE;
- bi->shutdown=1;
- return(1);
- }
-
-static BIO_ACCEPT *BIO_ACCEPT_new(void)
- {
+ bi->init = 0;
+ bi->num = -1;
+ bi->flags = 0;
+ if ((ba = BIO_ACCEPT_new()) == NULL)
+ return (0);
+ bi->ptr = (char *)ba;
+ ba->state = ACPT_S_BEFORE;
+ bi->shutdown = 1;
+ return (1);
+}
+
+static BIO_ACCEPT
+*BIO_ACCEPT_new(void)
+{
BIO_ACCEPT *ret;
- if ((ret=(BIO_ACCEPT *)OPENSSL_malloc(sizeof(BIO_ACCEPT))) == NULL)
- return(NULL);
-
- memset(ret,0,sizeof(BIO_ACCEPT));
- ret->accept_sock=-1;
- ret->bind_mode=BIO_BIND_NORMAL;
- return(ret);
- }
-
-static void BIO_ACCEPT_free(BIO_ACCEPT *a)
- {
- if(a == NULL)
- return;
-
- if (a->param_addr != NULL) OPENSSL_free(a->param_addr);
- if (a->addr != NULL) OPENSSL_free(a->addr);
- if (a->bio_chain != NULL) BIO_free(a->bio_chain);
+ if ((ret = (BIO_ACCEPT *)OPENSSL_malloc(sizeof(BIO_ACCEPT))) == NULL)
+ return (NULL);
+
+ memset(ret, 0, sizeof(BIO_ACCEPT));
+ ret->accept_sock = -1;
+ ret->bind_mode = BIO_BIND_NORMAL;
+ return (ret);
+}
+
+static void
+BIO_ACCEPT_free(BIO_ACCEPT *a)
+{
+ if (a == NULL)
+ return;
+
+ if (a->param_addr != NULL)
+ OPENSSL_free(a->param_addr);
+ if (a->addr != NULL)
+ OPENSSL_free(a->addr);
+ if (a->bio_chain != NULL)
+ BIO_free(a->bio_chain);
OPENSSL_free(a);
- }
+}
-static void acpt_close_socket(BIO *bio)
- {
+static void
+acpt_close_socket(BIO *bio)
+{
BIO_ACCEPT *c;
- c=(BIO_ACCEPT *)bio->ptr;
- if (c->accept_sock != -1)
- {
+ c = (BIO_ACCEPT *)bio->ptr;
+ if (c->accept_sock != -1) {
shutdown(c->accept_sock, SHUT_RDWR);
close(c->accept_sock);
- c->accept_sock=-1;
- bio->num=-1;
- }
+ c->accept_sock = -1;
+ bio->num = -1;
}
+}
-static int acpt_free(BIO *a)
- {
+static int
+acpt_free(BIO *a)
+{
BIO_ACCEPT *data;
- if (a == NULL) return(0);
- data=(BIO_ACCEPT *)a->ptr;
-
- if (a->shutdown)
- {
+ if (a == NULL)
+ return (0);
+ data = (BIO_ACCEPT *)a->ptr;
+
+ if (a->shutdown) {
acpt_close_socket(a);
BIO_ACCEPT_free(data);
- a->ptr=NULL;
- a->flags=0;
- a->init=0;
- }
- return(1);
+ a->ptr = NULL;
+ a->flags = 0;
+ a->init = 0;
}
-
-static int acpt_state(BIO *b, BIO_ACCEPT *c)
- {
- BIO *bio=NULL,*dbio;
- int s= -1;
+ return (1);
+}
+
+static int
+acpt_state(BIO *b, BIO_ACCEPT *c)
+{
+ BIO *bio = NULL, *dbio;
+ int s = -1;
int i;
again:
- switch (c->state)
- {
+ switch (c->state) {
case ACPT_S_BEFORE:
- if (c->param_addr == NULL)
- {
- BIOerr(BIO_F_ACPT_STATE,BIO_R_NO_ACCEPT_PORT_SPECIFIED);
- return(-1);
- }
- s=BIO_get_accept_socket(c->param_addr,c->bind_mode);
+ if (c->param_addr == NULL) {
+ BIOerr(BIO_F_ACPT_STATE, BIO_R_NO_ACCEPT_PORT_SPECIFIED);
+ return (-1);
+ }
+ s = BIO_get_accept_socket(c->param_addr, c->bind_mode);
if (s == -1)
- return(-1);
+ return (-1);
- if (c->accept_nbio)
- {
- if (!BIO_socket_nbio(s,1))
- {
+ if (c->accept_nbio) {
+ if (!BIO_socket_nbio(s, 1)) {
close(s);
- BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET);
- return(-1);
- }
+ BIOerr(BIO_F_ACPT_STATE, BIO_R_ERROR_SETTING_NBIO_ON_ACCEPT_SOCKET);
+ return (-1);
}
- c->accept_sock=s;
- b->num=s;
- c->state=ACPT_S_GET_ACCEPT_SOCKET;
- return(1);
+ }
+ c->accept_sock = s;
+ b->num = s;
+ c->state = ACPT_S_GET_ACCEPT_SOCKET;
+ return (1);
/* break; */
case ACPT_S_GET_ACCEPT_SOCKET:
- if (b->next_bio != NULL)
- {
- c->state=ACPT_S_OK;
+ if (b->next_bio != NULL) {
+ c->state = ACPT_S_OK;
goto again;
- }
+ }
BIO_clear_retry_flags(b);
- b->retry_reason=0;
- i=BIO_accept(c->accept_sock,&(c->addr));
+ b->retry_reason = 0;
+ i = BIO_accept(c->accept_sock, &(c->addr));
/* -2 return means we should retry */
- if(i == -2)
- {
+ if (i == -2) {
BIO_set_retry_special(b);
- b->retry_reason=BIO_RR_ACCEPT;
+ b->retry_reason = BIO_RR_ACCEPT;
return -1;
- }
+ }
- if (i < 0) return(i);
+ if (i < 0)
+ return (i);
- bio=BIO_new_socket(i,BIO_CLOSE);
- if (bio == NULL) goto err;
+ bio = BIO_new_socket(i, BIO_CLOSE);
+ if (bio == NULL)
+ goto err;
- BIO_set_callback(bio,BIO_get_callback(b));
- BIO_set_callback_arg(bio,BIO_get_callback_arg(b));
+ BIO_set_callback(bio, BIO_get_callback(b));
+ BIO_set_callback_arg(bio, BIO_get_callback_arg(b));
- if (c->nbio)
- {
- if (!BIO_socket_nbio(i,1))
- {
- BIOerr(BIO_F_ACPT_STATE,BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET);
+ if (c->nbio) {
+ if (!BIO_socket_nbio(i, 1)) {
+ BIOerr(BIO_F_ACPT_STATE, BIO_R_ERROR_SETTING_NBIO_ON_ACCEPTED_SOCKET);
goto err;
- }
}
+ }
/* If the accept BIO has an bio_chain, we dup it and
* put the new socket at the end. */
- if (c->bio_chain != NULL)
- {
- if ((dbio=BIO_dup_chain(c->bio_chain)) == NULL)
+ if (c->bio_chain != NULL) {
+ if ((dbio = BIO_dup_chain(c->bio_chain)) == NULL)
goto err;
- if (!BIO_push(dbio,bio)) goto err;
- bio=dbio;
- }
- if (BIO_push(b,bio) == NULL) goto err;
+ if (!BIO_push(dbio, bio)) goto err;
+ bio = dbio;
+ }
+ if (BIO_push(b, bio)
+ == NULL) goto err;
+
+ c->state = ACPT_S_OK;
+ return (1);
- c->state=ACPT_S_OK;
- return(1);
err:
if (bio != NULL)
BIO_free(bio);
else if (s >= 0)
close(s);
- return(0);
+ return (0);
/* break; */
case ACPT_S_OK:
- if (b->next_bio == NULL)
- {
- c->state=ACPT_S_GET_ACCEPT_SOCKET;
+ if (b->next_bio == NULL) {
+ c->state = ACPT_S_GET_ACCEPT_SOCKET;
goto again;
- }
- return(1);
+ }
+ return (1);
/* break; */
- default:
- return(0);
+ default:
+ return (0);
/* break; */
- }
-
}
+}
-static int acpt_read(BIO *b, char *out, int outl)
- {
- int ret=0;
+static int
+acpt_read(BIO *b, char *out, int outl)
+{
+ int ret = 0;
BIO_ACCEPT *data;
BIO_clear_retry_flags(b);
- data=(BIO_ACCEPT *)b->ptr;
+ data = (BIO_ACCEPT *)b->ptr;
- while (b->next_bio == NULL)
- {
- ret=acpt_state(b,data);
- if (ret <= 0) return(ret);
- }
+ while (b->next_bio == NULL) {
+ ret = acpt_state(b, data);
+ if (ret <= 0)
+ return (ret);
+ }
- ret=BIO_read(b->next_bio,out,outl);
+ ret = BIO_read(b->next_bio, out, outl);
BIO_copy_next_retry(b);
- return(ret);
- }
+ return (ret);
+}
-static int acpt_write(BIO *b, const char *in, int inl)
- {
+static int
+acpt_write(BIO *b, const char *in, int inl)
+{
int ret;
BIO_ACCEPT *data;
BIO_clear_retry_flags(b);
- data=(BIO_ACCEPT *)b->ptr;
+ data = (BIO_ACCEPT *)b->ptr;
- while (b->next_bio == NULL)
- {
- ret=acpt_state(b,data);
- if (ret <= 0) return(ret);
- }
+ while (b->next_bio == NULL) {
+ ret = acpt_state(b, data);
+ if (ret <= 0)
+ return (ret);
+ }
- ret=BIO_write(b->next_bio,in,inl);
+ ret = BIO_write(b->next_bio, in, inl);
BIO_copy_next_retry(b);
- return(ret);
- }
+ return (ret);
+}
-static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
+static long
+acpt_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
int *ip;
- long ret=1;
+ long ret = 1;
BIO_ACCEPT *data;
char **pp;
- data=(BIO_ACCEPT *)b->ptr;
+ data = (BIO_ACCEPT *)b->ptr;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_RESET:
- ret=0;
- data->state=ACPT_S_BEFORE;
+ ret = 0;
+ data->state = ACPT_S_BEFORE;
acpt_close_socket(b);
- b->flags=0;
+ b->flags = 0;
break;
case BIO_C_DO_STATE_MACHINE:
/* use this one to start the connection */
- ret=(long)acpt_state(b,data);
+ ret = (long)acpt_state(b, data);
break;
case BIO_C_SET_ACCEPT:
- if (ptr != NULL)
- {
- if (num == 0)
- {
- b->init=1;
+ if (ptr != NULL) {
+ if (num == 0) {
+ b->init = 1;
if (data->param_addr != NULL)
OPENSSL_free(data->param_addr);
- data->param_addr=BUF_strdup(ptr);
- }
- else if (num == 1)
- {
- data->accept_nbio=(ptr != NULL);
- }
- else if (num == 2)
- {
+ data->param_addr = BUF_strdup(ptr);
+ } else if (num == 1) {
+ data->accept_nbio = (ptr != NULL);
+ } else if (num == 2) {
if (data->bio_chain != NULL)
BIO_free(data->bio_chain);
- data->bio_chain=(BIO *)ptr;
- }
+ data->bio_chain = (BIO *)ptr;
}
+ }
break;
case BIO_C_SET_NBIO:
- data->nbio=(int)num;
+ data->nbio = (int)num;
break;
case BIO_C_SET_FD:
- b->init=1;
+ b->init = 1;
b->num= *((int *)ptr);
- data->accept_sock=b->num;
- data->state=ACPT_S_GET_ACCEPT_SOCKET;
- b->shutdown=(int)num;
- b->init=1;
+ data->accept_sock = b->num;
+ data->state = ACPT_S_GET_ACCEPT_SOCKET;
+ b->shutdown = (int)num;
+ b->init = 1;
break;
case BIO_C_GET_FD:
- if (b->init)
- {
- ip=(int *)ptr;
+ if (b->init) {
+ ip = (int *)ptr;
if (ip != NULL)
- *ip=data->accept_sock;
- ret=data->accept_sock;
- }
- else
- ret= -1;
+ *ip = data->accept_sock;
+ ret = data->accept_sock;
+ } else
+ ret = -1;
break;
case BIO_C_GET_ACCEPT:
- if (b->init)
- {
- if (ptr != NULL)
- {
- pp=(char **)ptr;
- *pp=data->param_addr;
- }
- else
- ret= -1;
- }
- else
- ret= -1;
+ if (b->init) {
+ if (ptr != NULL) {
+ pp = (char **)ptr;
+ *pp = data->param_addr;
+ } else
+ ret = -1;
+ } else
+ ret = -1;
break;
case BIO_CTRL_GET_CLOSE:
- ret=b->shutdown;
+ ret = b->shutdown;
break;
case BIO_CTRL_SET_CLOSE:
- b->shutdown=(int)num;
+ b->shutdown = (int)num;
break;
case BIO_CTRL_PENDING:
case BIO_CTRL_WPENDING:
- ret=0;
+ ret = 0;
break;
case BIO_CTRL_FLUSH:
break;
case BIO_C_SET_BIND_MODE:
- data->bind_mode=(int)num;
+ data->bind_mode = (int)num;
break;
case BIO_C_GET_BIND_MODE:
- ret=(long)data->bind_mode;
+ ret = (long)data->bind_mode;
break;
case BIO_CTRL_DUP:
/* dbio=(BIO *)ptr;
BIO_set_port(dbio,data->param_port);
if (data->param_hostname)
BIO_set_hostname(dbio,data->param_hostname);
- BIO_set_nbio(dbio,data->nbio); */
+ BIO_set_nbio(dbio,data->nbio);
+*/
break;
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
}
-
-static int acpt_puts(BIO *bp, const char *str)
- {
- int n,ret;
-
- n=strlen(str);
- ret=acpt_write(bp,str,n);
- return(ret);
- }
-
-BIO *BIO_new_accept(char *str)
- {
+ return (ret);
+}
+
+static int
+acpt_puts(BIO *bp, const char *str)
+{
+ int n, ret;
+
+ n = strlen(str);
+ ret = acpt_write(bp, str, n);
+ return (ret);
+}
+
+BIO
+*BIO_new_accept(char *str)
+{
BIO *ret;
- ret=BIO_new(BIO_s_accept());
- if (ret == NULL) return(NULL);
- if (BIO_set_accept_port(ret,str))
- return(ret);
- else
- {
+ ret = BIO_new(BIO_s_accept());
+ if (ret == NULL)
+ return (NULL);
+ if (BIO_set_accept_port(ret, str))
+ return (ret);
+ else {
BIO_free(ret);
- return(NULL);
- }
+ return (NULL);
}
+}
#endif
static int bio_make_pair(BIO *bio1, BIO *bio2);
static void bio_destroy_pair(BIO *bio);
-static BIO_METHOD methods_biop =
-{
+static BIO_METHOD methods_biop = {
BIO_TYPE_BIO,
"BIO pair",
bio_write,
NULL /* no bio_callback_ctrl */
};
-BIO_METHOD *BIO_s_bio(void)
- {
+BIO_METHOD
+*BIO_s_bio(void)
+{
return &methods_biop;
- }
+}
+
+struct bio_bio_st {
+ BIO *peer; /* NULL if buf == NULL.
+ * If peer != NULL, then peer->ptr is also a bio_bio_st,
+ * and its "peer" member points back to us.
+ * peer != NULL iff init != 0 in the BIO. */
-struct bio_bio_st
-{
- BIO *peer; /* NULL if buf == NULL.
- * If peer != NULL, then peer->ptr is also a bio_bio_st,
- * and its "peer" member points back to us.
- * peer != NULL iff init != 0 in the BIO. */
-
/* This is for what we write (i.e. reading uses peer's struct): */
- int closed; /* valid iff peer != NULL */
- size_t len; /* valid iff buf != NULL; 0 if peer == NULL */
- size_t offset; /* valid iff buf != NULL; 0 if len == 0 */
+ int closed; /* valid iff peer != NULL */
+ size_t len; /* valid iff buf != NULL; 0 if peer == NULL */
+ size_t offset; /* valid iff buf != NULL; 0 if len == 0 */
size_t size;
char *buf; /* "size" elements (if != NULL) */
size_t request; /* valid iff peer != NULL; 0 if len != 0,
- * otherwise set by peer to number of bytes
- * it (unsuccessfully) tried to read,
+ * otherwise set by peer to number of bytes
+ * it (unsuccessfully) tried to read,
* never more than buffer space (size-len) warrants. */
};
-static int bio_new(BIO *bio)
- {
+static int
+bio_new(BIO *bio)
+{
struct bio_bio_st *b;
-
+
b = OPENSSL_malloc(sizeof *b);
if (b == NULL)
return 0;
b->peer = NULL;
- b->size = 17*1024; /* enough for one TLS record (just a default) */
+ b->size = 17 * 1024; /* enough for one TLS record (just a default) */
b->buf = NULL;
bio->ptr = b;
return 1;
- }
+}
-
-static int bio_free(BIO *bio)
- {
+static int
+bio_free(BIO *bio)
+{
struct bio_bio_st *b;
if (bio == NULL)
if (b->peer)
bio_destroy_pair(bio);
-
- if (b->buf != NULL)
- {
+
+ if (b->buf != NULL) {
OPENSSL_free(b->buf);
- }
+ }
OPENSSL_free(b);
return 1;
- }
+}
-static int bio_read(BIO *bio, char *buf, int size_)
- {
+static int
+bio_read(BIO *bio, char *buf, int size_)
+{
size_t size = size_;
size_t rest;
struct bio_bio_st *b, *peer_b;
if (buf == NULL || size == 0)
return 0;
- if (peer_b->len == 0)
- {
+ if (peer_b->len == 0) {
if (peer_b->closed)
return 0; /* writer has closed, and no data is left */
- else
- {
+ else {
BIO_set_retry_read(bio); /* buffer is empty */
if (size <= peer_b->size)
peer_b->request = size;
* deliver in one write */
peer_b->request = peer_b->size;
return -1;
- }
}
+ }
/* we can read */
if (peer_b->len < size)
size = peer_b->len;
/* now read "size" bytes */
-
+
rest = size;
-
+
assert(rest > 0);
do /* one or two iterations */
- {
+ {
size_t chunk;
-
+
assert(rest <= peer_b->len);
if (peer_b->offset + rest <= peer_b->size)
chunk = rest;
/* wrap around ring buffer */
chunk = peer_b->size - peer_b->offset;
assert(peer_b->offset + chunk <= peer_b->size);
-
+
memcpy(buf, peer_b->buf + peer_b->offset, chunk);
-
+
peer_b->len -= chunk;
- if (peer_b->len)
- {
+ if (peer_b->len) {
peer_b->offset += chunk;
assert(peer_b->offset <= peer_b->size);
if (peer_b->offset == peer_b->size)
peer_b->offset = 0;
buf += chunk;
- }
- else
- {
+ } else {
/* buffer now empty, no need to advance "buf" */
assert(chunk == rest);
peer_b->offset = 0;
- }
- rest -= chunk;
}
- while (rest);
-
+ rest -= chunk;
+ } while (rest);
+
return size;
- }
+}
/* non-copying interface: provide pointer to available data in buffer
* bio_nread0: return number of available bytes
*/
/* WARNING: The non-copying interface is largely untested as of yet
* and may contain bugs. */
-static ossl_ssize_t bio_nread0(BIO *bio, char **buf)
- {
+static ossl_ssize_t
+bio_nread0(BIO *bio, char **buf)
+{
struct bio_bio_st *b, *peer_b;
ossl_ssize_t num;
-
+
BIO_clear_retry_flags(bio);
if (!bio->init)
return 0;
-
+
b = bio->ptr;
assert(b != NULL);
assert(b->peer != NULL);
peer_b = b->peer->ptr;
assert(peer_b != NULL);
assert(peer_b->buf != NULL);
-
+
peer_b->request = 0;
-
- if (peer_b->len == 0)
- {
+
+ if (peer_b->len == 0) {
char dummy;
-
+
/* avoid code duplication -- nothing available for reading */
return bio_read(bio, &dummy, 1); /* returns 0 or -1 */
- }
+ }
num = peer_b->len;
if (peer_b->size < peer_b->offset + num)
if (buf != NULL)
*buf = peer_b->buf + peer_b->offset;
return num;
- }
+}
-static ossl_ssize_t bio_nread(BIO *bio, char **buf, size_t num_)
- {
+static ossl_ssize_t
+bio_nread(BIO *bio, char **buf, size_t num_)
+{
struct bio_bio_st *b, *peer_b;
ossl_ssize_t num, available;
peer_b = b->peer->ptr;
peer_b->len -= num;
- if (peer_b->len)
- {
+ if (peer_b->len) {
peer_b->offset += num;
assert(peer_b->offset <= peer_b->size);
if (peer_b->offset == peer_b->size)
peer_b->offset = 0;
- }
- else
+ } else
peer_b->offset = 0;
return num;
- }
+}
-static int bio_write(BIO *bio, const char *buf, int num_)
- {
+static int
+bio_write(BIO *bio, const char *buf, int num_)
+{
size_t num = num_;
size_t rest;
struct bio_bio_st *b;
if (!bio->init || buf == NULL || num == 0)
return 0;
- b = bio->ptr;
+ b = bio->ptr;
+
assert(b != NULL);
assert(b->peer != NULL);
assert(b->buf != NULL);
b->request = 0;
- if (b->closed)
- {
+ if (b->closed) {
/* we already closed */
BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE);
return -1;
- }
+ }
assert(b->len <= b->size);
- if (b->len == b->size)
- {
+ if (b->len == b->size) {
BIO_set_retry_write(bio); /* buffer is full */
return -1;
- }
+ }
/* we can write */
if (num > b->size - b->len)
num = b->size - b->len;
-
+
/* now write "num" bytes */
rest = num;
-
+
assert(rest > 0);
do /* one or two iterations */
- {
+ {
size_t write_offset;
size_t chunk;
else
/* wrap around ring buffer */
chunk = b->size - write_offset;
-
+
memcpy(b->buf + write_offset, buf, chunk);
-
+
b->len += chunk;
assert(b->len <= b->size);
-
+
rest -= chunk;
buf += chunk;
- }
- while (rest);
+ } while (rest);
return num;
- }
+}
/* non-copying interface: provide pointer to region to write to
* bio_nwrite0: check how much space is available
* (example usage: bio_nwrite0(), write to buffer, bio_nwrite()
* or just bio_nwrite(), write to buffer)
*/
-static ossl_ssize_t bio_nwrite0(BIO *bio, char **buf)
- {
+static ossl_ssize_t
+bio_nwrite0(BIO *bio, char **buf)
+{
struct bio_bio_st *b;
size_t num;
size_t write_offset;
if (!bio->init)
return 0;
- b = bio->ptr;
+ b = bio->ptr;
+
assert(b != NULL);
assert(b->peer != NULL);
assert(b->buf != NULL);
b->request = 0;
- if (b->closed)
- {
+ if (b->closed) {
BIOerr(BIO_F_BIO_NWRITE0, BIO_R_BROKEN_PIPE);
return -1;
- }
+ }
assert(b->len <= b->size);
- if (b->len == b->size)
- {
+ if (b->len == b->size) {
BIO_set_retry_write(bio);
return -1;
- }
+ }
num = b->size - b->len;
write_offset = b->offset + b->len;
assert(write_offset + num <= b->size);
return num;
- }
+}
-static ossl_ssize_t bio_nwrite(BIO *bio, char **buf, size_t num_)
- {
+static ossl_ssize_t
+bio_nwrite(BIO *bio, char **buf, size_t num_)
+{
struct bio_bio_st *b;
ossl_ssize_t num, space;
assert(b->len <= b->size);
return num;
- }
+}
-static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
- {
+static long
+bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
+{
long ret;
struct bio_bio_st *b = bio->ptr;
-
+
assert(b != NULL);
- switch (cmd)
- {
- /* specific CTRL codes */
+ switch (cmd) {
+ /* specific CTRL codes */
case BIO_C_SET_WRITE_BUF_SIZE:
- if (b->peer)
- {
+ if (b->peer) {
BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE);
ret = 0;
- }
- else if (num == 0)
- {
+ } else if (num == 0) {
BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT);
ret = 0;
- }
- else
- {
+ } else {
size_t new_size = num;
- if (b->size != new_size)
- {
- if (b->buf)
- {
+ if (b->size != new_size) {
+ if (b->buf) {
OPENSSL_free(b->buf);
b->buf = NULL;
- }
- b->size = new_size;
}
- ret = 1;
+ b->size = new_size;
}
+ ret = 1;
+ }
break;
case BIO_C_GET_WRITE_BUF_SIZE:
case BIO_C_MAKE_BIO_PAIR:
{
- BIO *other_bio = ptr;
-
- if (bio_make_pair(bio, other_bio))
- ret = 1;
- else
- ret = 0;
+ BIO *other_bio = ptr;
+
+ if (bio_make_pair(bio, other_bio))
+ ret = 1;
+ else
+ ret = 0;
}
break;
-
+
case BIO_C_DESTROY_BIO_PAIR:
/* Affects both BIOs in the pair -- call just once!
* Or let BIO_free(bio1); BIO_free(bio2); do the job. */
/* prepare for non-copying read */
ret = (long) bio_nread0(bio, ptr);
break;
-
+
case BIO_C_NREAD:
/* non-copying read */
ret = (long) bio_nread(bio, ptr, (size_t) num);
break;
-
+
case BIO_C_NWRITE0:
/* prepare for non-copying write */
ret = (long) bio_nwrite0(bio, ptr);
/* non-copying write */
ret = (long) bio_nwrite(bio, ptr, (size_t) num);
break;
-
- /* standard CTRL codes follow */
+
+ /* standard CTRL codes follow */
case BIO_CTRL_RESET:
- if (b->buf != NULL)
- {
+ if (b->buf != NULL) {
b->len = 0;
b->offset = 0;
- }
+ }
ret = 0;
- break;
+ break;
+
case BIO_CTRL_GET_CLOSE:
ret = bio->shutdown;
break;
case BIO_CTRL_PENDING:
- if (b->peer != NULL)
- {
+ if (b->peer != NULL) {
struct bio_bio_st *peer_b = b->peer->ptr;
-
+
ret = (long) peer_b->len;
- }
- else
+ } else
ret = 0;
break;
case BIO_CTRL_DUP:
/* See BIO_dup_chain for circumstances we have to expect. */
{
- BIO *other_bio = ptr;
- struct bio_bio_st *other_b;
-
- assert(other_bio != NULL);
- other_b = other_bio->ptr;
- assert(other_b != NULL);
-
- assert(other_b->buf == NULL); /* other_bio is always fresh */
-
- other_b->size = b->size;
+ BIO *other_bio = ptr;
+ struct bio_bio_st *other_b;
+
+ assert(other_bio != NULL);
+ other_b = other_bio->ptr;
+ assert(other_b != NULL);
+
+ assert(other_b->buf == NULL); /* other_bio is always fresh */
+
+ other_b->size = b->size;
}
ret = 1;
case BIO_CTRL_EOF:
{
- BIO *other_bio = ptr;
-
- if (other_bio)
- {
- struct bio_bio_st *other_b = other_bio->ptr;
-
- assert(other_b != NULL);
- ret = other_b->len == 0 && other_b->closed;
- }
- else
- ret = 1;
+ BIO *other_bio = ptr;
+
+ if (other_bio) {
+ struct bio_bio_st *other_b = other_bio->ptr;
+
+ assert(other_b != NULL);
+ ret = other_b->len == 0 && other_b->closed;
+ } else
+ ret = 1;
}
break;
default:
ret = 0;
- }
- return ret;
}
+ return ret;
+}
-static int bio_puts(BIO *bio, const char *str)
- {
+static int
+bio_puts(BIO *bio, const char *str)
+{
return bio_write(bio, str, strlen(str));
- }
+}
-static int bio_make_pair(BIO *bio1, BIO *bio2)
- {
+static int
+bio_make_pair(BIO *bio1, BIO *bio2)
+{
struct bio_bio_st *b1, *b2;
assert(bio1 != NULL);
b1 = bio1->ptr;
b2 = bio2->ptr;
-
- if (b1->peer != NULL || b2->peer != NULL)
- {
+
+ if (b1->peer != NULL || b2->peer != NULL) {
BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE);
return 0;
- }
-
- if (b1->buf == NULL)
- {
+ }
+
+ if (b1->buf == NULL) {
b1->buf = OPENSSL_malloc(b1->size);
- if (b1->buf == NULL)
- {
+ if (b1->buf == NULL) {
BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
return 0;
- }
+ }
b1->len = 0;
b1->offset = 0;
- }
-
- if (b2->buf == NULL)
- {
+ }
+
+ if (b2->buf == NULL) {
b2->buf = OPENSSL_malloc(b2->size);
- if (b2->buf == NULL)
- {
+ if (b2->buf == NULL) {
BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
return 0;
- }
+ }
b2->len = 0;
b2->offset = 0;
- }
-
+ }
+
b1->peer = bio2;
b1->closed = 0;
b1->request = 0;
bio2->init = 1;
return 1;
- }
+}
-static void bio_destroy_pair(BIO *bio)
- {
+static void
+bio_destroy_pair(BIO *bio)
+{
struct bio_bio_st *b = bio->ptr;
- if (b != NULL)
- {
+ if (b != NULL) {
BIO *peer_bio = b->peer;
- if (peer_bio != NULL)
- {
+ if (peer_bio != NULL) {
struct bio_bio_st *peer_b = peer_bio->ptr;
assert(peer_b != NULL);
assert(peer_b->buf != NULL);
peer_b->len = 0;
peer_b->offset = 0;
-
+
b->peer = NULL;
bio->init = 0;
assert(b->buf != NULL);
b->len = 0;
b->offset = 0;
- }
}
}
-
+}
+
/* Exported convenience functions */
-int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1,
- BIO **bio2_p, size_t writebuf2)
- {
- BIO *bio1 = NULL, *bio2 = NULL;
- long r;
- int ret = 0;
-
- bio1 = BIO_new(BIO_s_bio());
- if (bio1 == NULL)
- goto err;
- bio2 = BIO_new(BIO_s_bio());
- if (bio2 == NULL)
- goto err;
-
- if (writebuf1)
- {
- r = BIO_set_write_buf_size(bio1, writebuf1);
- if (!r)
- goto err;
- }
- if (writebuf2)
- {
- r = BIO_set_write_buf_size(bio2, writebuf2);
- if (!r)
- goto err;
- }
-
- r = BIO_make_bio_pair(bio1, bio2);
- if (!r)
- goto err;
- ret = 1;
-
- err:
- if (ret == 0)
- {
- if (bio1)
- {
- BIO_free(bio1);
- bio1 = NULL;
- }
- if (bio2)
- {
- BIO_free(bio2);
- bio2 = NULL;
- }
- }
-
- *bio1_p = bio1;
- *bio2_p = bio2;
- return ret;
- }
-
-size_t BIO_ctrl_get_write_guarantee(BIO *bio)
- {
- return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL);
+int
+BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1, BIO **bio2_p, size_t writebuf2)
+{
+ BIO *bio1 = NULL, *bio2 = NULL;
+ long r;
+ int ret = 0;
+
+ bio1 = BIO_new(BIO_s_bio());
+ if (bio1 == NULL)
+ goto err;
+ bio2 = BIO_new(BIO_s_bio());
+ if (bio2 == NULL)
+ goto err;
+
+ if (writebuf1) {
+ r = BIO_set_write_buf_size(bio1, writebuf1);
+ if (!r)
+ goto err;
+ }
+ if (writebuf2) {
+ r = BIO_set_write_buf_size(bio2, writebuf2);
+ if (!r)
+ goto err;
}
-size_t BIO_ctrl_get_read_request(BIO *bio)
- {
- return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL);
+ r = BIO_make_bio_pair(bio1, bio2);
+ if (!r)
+ goto err;
+ ret = 1;
+
+ err:
+ if (ret == 0) {
+ if (bio1) {
+ BIO_free(bio1);
+ bio1 = NULL;
+ }
+ if (bio2) {
+ BIO_free(bio2);
+ bio2 = NULL;
+ }
}
-int BIO_ctrl_reset_read_request(BIO *bio)
- {
+ *bio1_p = bio1;
+ *bio2_p = bio2;
+ return ret;
+}
+
+size_t
+BIO_ctrl_get_write_guarantee(BIO *bio)
+{
+ return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL);
+}
+
+size_t
+BIO_ctrl_get_read_request(BIO *bio)
+{
+ return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL);
+}
+
+int
+BIO_ctrl_reset_read_request(BIO *bio)
+{
return (BIO_ctrl(bio, BIO_C_RESET_READ_REQUEST, 0, NULL) != 0);
- }
+}
/* BIO_nread0/nread/nwrite0/nwrite are available only for BIO pairs for now
* (conceivably some other BIOs could allow non-copying reads and writes too.)
*/
-int BIO_nread0(BIO *bio, char **buf)
- {
+int
+BIO_nread0(BIO *bio, char **buf)
+{
long ret;
- if (!bio->init)
- {
+ if (!bio->init) {
BIOerr(BIO_F_BIO_NREAD0, BIO_R_UNINITIALIZED);
return -2;
- }
+ }
ret = BIO_ctrl(bio, BIO_C_NREAD0, 0, buf);
if (ret > INT_MAX)
return INT_MAX;
else
return (int) ret;
- }
+}
-int BIO_nread(BIO *bio, char **buf, int num)
- {
+int
+BIO_nread(BIO *bio, char **buf, int num)
+{
int ret;
- if (!bio->init)
- {
+ if (!bio->init) {
BIOerr(BIO_F_BIO_NREAD, BIO_R_UNINITIALIZED);
return -2;
- }
+ }
ret = (int) BIO_ctrl(bio, BIO_C_NREAD, num, buf);
if (ret > 0)
bio->num_read += ret;
return ret;
- }
+}
-int BIO_nwrite0(BIO *bio, char **buf)
- {
+int
+BIO_nwrite0(BIO *bio, char **buf)
+{
long ret;
- if (!bio->init)
- {
+ if (!bio->init) {
BIOerr(BIO_F_BIO_NWRITE0, BIO_R_UNINITIALIZED);
return -2;
- }
+ }
ret = BIO_ctrl(bio, BIO_C_NWRITE0, 0, buf);
if (ret > INT_MAX)
return INT_MAX;
else
return (int) ret;
- }
+}
-int BIO_nwrite(BIO *bio, char **buf, int num)
- {
+int
+BIO_nwrite(BIO *bio, char **buf, int num)
+{
int ret;
- if (!bio->init)
- {
+ if (!bio->init) {
BIOerr(BIO_F_BIO_NWRITE, BIO_R_UNINITIALIZED);
return -2;
- }
+ }
ret = BIO_ctrl(bio, BIO_C_NWRITE, num, buf);
if (ret > 0)
bio->num_write += ret;
return ret;
- }
+}
#endif
-typedef struct bio_connect_st
- {
+typedef struct bio_connect_st {
int state;
char *param_hostname;
/* called when the connection is initially made
* callback(BIO,state,ret); The callback should return
* 'ret'. state is for compatibility with the ssl info_callback */
- int (*info_callback)(const BIO *bio,int state,int ret);
- } BIO_CONNECT;
+ int (*info_callback)(const BIO *bio, int state, int ret);
+} BIO_CONNECT;
static int conn_write(BIO *h, const char *buf, int num);
static int conn_read(BIO *h, char *buf, int size);
static int conn_state(BIO *b, BIO_CONNECT *c);
static void conn_close_socket(BIO *data);
-BIO_CONNECT *BIO_CONNECT_new(void );
+BIO_CONNECT *BIO_CONNECT_new(void);
void BIO_CONNECT_free(BIO_CONNECT *a);
-static BIO_METHOD methods_connectp=
- {
+static BIO_METHOD methods_connectp = {
BIO_TYPE_CONNECT,
"socket connect",
conn_write,
conn_new,
conn_free,
conn_callback_ctrl,
- };
+};
-static int conn_state(BIO *b, BIO_CONNECT *c)
- {
- int ret= -1,i;
+static int
+conn_state(BIO *b, BIO_CONNECT *c)
+{
+ int ret = -1, i;
unsigned long l;
- char *p,*q;
- int (*cb)(const BIO *,int,int)=NULL;
+ char *p, *q;
+ int (*cb)(const BIO *, int, int) = NULL;
if (c->info_callback != NULL)
- cb=c->info_callback;
+ cb = c->info_callback;
- for (;;)
- {
- switch (c->state)
- {
+ for (;;) {
+ switch (c->state) {
case BIO_CONN_S_BEFORE:
- p=c->param_hostname;
- if (p == NULL)
- {
- BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTNAME_SPECIFIED);
+ p = c->param_hostname;
+ if (p == NULL) {
+ BIOerr(BIO_F_CONN_STATE, BIO_R_NO_HOSTNAME_SPECIFIED);
goto exit_loop;
- }
- for ( ; *p != '\0'; p++)
- {
- if ((*p == ':') || (*p == '/')) break;
- }
+ }
+ for (; *p != '\0'; p++) {
+ if ((*p == ':') || (*p == '/'))
+ break;
+ }
i= *p;
- if ((i == ':') || (i == '/'))
- {
-
- *(p++)='\0';
- if (i == ':')
- {
- for (q=p; *q; q++)
- if (*q == '/')
- {
- *q='\0';
+ if ((i == ':') || (i == '/')) {
+ *(p++) = '\0';
+ if (i == ':') {
+ for (q = p; *q; q++)
+ if (*q == '/') {
+ *q = '\0';
break;
- }
+ }
if (c->param_port != NULL)
OPENSSL_free(c->param_port);
- c->param_port=BUF_strdup(p);
- }
+ c->param_port = BUF_strdup(p);
}
+ }
- if (c->param_port == NULL)
- {
- BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED);
- ERR_add_error_data(2,"host=",c->param_hostname);
+ if (c->param_port == NULL) {
+ BIOerr(BIO_F_CONN_STATE, BIO_R_NO_PORT_SPECIFIED);
+ ERR_add_error_data(2, "host=", c->param_hostname);
goto exit_loop;
- }
- c->state=BIO_CONN_S_GET_IP;
+ }
+ c->state = BIO_CONN_S_GET_IP;
break;
case BIO_CONN_S_GET_IP:
- if (BIO_get_host_ip(c->param_hostname,&(c->ip[0])) <= 0)
+ if (BIO_get_host_ip(c->param_hostname, &(c->ip[0])) <= 0)
goto exit_loop;
- c->state=BIO_CONN_S_GET_PORT;
+ c->state = BIO_CONN_S_GET_PORT;
break;
case BIO_CONN_S_GET_PORT:
- if (c->param_port == NULL)
- {
+ if (c->param_port == NULL) {
/* abort(); */
goto exit_loop;
- }
- else if (BIO_get_port(c->param_port,&c->port) <= 0)
+ } else if (BIO_get_port(c->param_port, &c->port) <= 0)
goto exit_loop;
- c->state=BIO_CONN_S_CREATE_SOCKET;
+ c->state = BIO_CONN_S_CREATE_SOCKET;
break;
case BIO_CONN_S_CREATE_SOCKET:
/* now setup address */
- memset((char *)&c->them,0,sizeof(c->them));
- c->them.sin_family=AF_INET;
- c->them.sin_port=htons((unsigned short)c->port);
- l=(unsigned long)
- ((unsigned long)c->ip[0]<<24L)|
- ((unsigned long)c->ip[1]<<16L)|
- ((unsigned long)c->ip[2]<< 8L)|
- ((unsigned long)c->ip[3]);
- c->them.sin_addr.s_addr=htonl(l);
- c->state=BIO_CONN_S_CREATE_SOCKET;
-
- ret=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL);
- if (ret == -1)
- {
- SYSerr(SYS_F_SOCKET,errno);
- ERR_add_error_data(4,"host=",c->param_hostname,
- ":",c->param_port);
- BIOerr(BIO_F_CONN_STATE,BIO_R_UNABLE_TO_CREATE_SOCKET);
+ memset((char *)&c->them, 0, sizeof(c->them));
+ c->them.sin_family = AF_INET;
+ c->them.sin_port = htons((unsigned short)c->port);
+ l = (unsigned long)
+ ((unsigned long)c->ip[0] << 24L)|
+ ((unsigned long)c->ip[1] << 16L)|
+ ((unsigned long)c->ip[2] << 8L)|
+ ((unsigned long)c->ip[3]);
+ c->them.sin_addr.s_addr = htonl(l);
+ c->state = BIO_CONN_S_CREATE_SOCKET;
+
+ ret = socket(AF_INET, SOCK_STREAM, SOCKET_PROTOCOL);
+ if (ret == -1) {
+ SYSerr(SYS_F_SOCKET, errno);
+ ERR_add_error_data(4, "host=",
+ c->param_hostname, ":", c->param_port);
+ BIOerr(BIO_F_CONN_STATE,
+ BIO_R_UNABLE_TO_CREATE_SOCKET);
goto exit_loop;
- }
- b->num=ret;
- c->state=BIO_CONN_S_NBIO;
+ }
+ b->num = ret;
+ c->state = BIO_CONN_S_NBIO;
break;
case BIO_CONN_S_NBIO:
- if (c->nbio)
- {
- if (!BIO_socket_nbio(b->num,1))
- {
- BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO);
- ERR_add_error_data(4,"host=",
- c->param_hostname,
- ":",c->param_port);
+ if (c->nbio) {
+ if (!BIO_socket_nbio(b->num, 1)) {
+ BIOerr(BIO_F_CONN_STATE,
+ BIO_R_ERROR_SETTING_NBIO);
+ ERR_add_error_data(4, "host=",
+ c->param_hostname, ":",
+ c->param_port);
goto exit_loop;
- }
}
- c->state=BIO_CONN_S_CONNECT;
+ }
+ c->state = BIO_CONN_S_CONNECT;
#if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE)
- i=1;
- i=setsockopt(b->num,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i));
- if (i < 0)
- {
- SYSerr(SYS_F_SOCKET,errno);
- ERR_add_error_data(4,"host=",c->param_hostname,
- ":",c->param_port);
- BIOerr(BIO_F_CONN_STATE,BIO_R_KEEPALIVE);
+ i = 1;
+ i = setsockopt(b->num, SOL_SOCKET, SO_KEEPALIVE,(char *)&i, sizeof(i));
+ if (i < 0) {
+ SYSerr(SYS_F_SOCKET, errno);
+ ERR_add_error_data(4, "host=",
+ c->param_hostname, ":", c->param_port);
+ BIOerr(BIO_F_CONN_STATE, BIO_R_KEEPALIVE);
goto exit_loop;
- }
+ }
#endif
break;
case BIO_CONN_S_CONNECT:
BIO_clear_retry_flags(b);
- ret=connect(b->num,
- (struct sockaddr *)&c->them,
- sizeof(c->them));
- b->retry_reason=0;
- if (ret < 0)
- {
- if (BIO_sock_should_retry(ret))
- {
+ ret = connect(b->num,
+ (struct sockaddr *)&c->them,
+ sizeof(c->them));
+ b->retry_reason = 0;
+ if (ret < 0) {
+ if (BIO_sock_should_retry(ret)) {
BIO_set_retry_special(b);
- c->state=BIO_CONN_S_BLOCKED_CONNECT;
- b->retry_reason=BIO_RR_CONNECT;
- }
- else
- {
- SYSerr(SYS_F_CONNECT,errno);
- ERR_add_error_data(4,"host=",
- c->param_hostname,
- ":",c->param_port);
- BIOerr(BIO_F_CONN_STATE,BIO_R_CONNECT_ERROR);
- }
- goto exit_loop;
+ c->state = BIO_CONN_S_BLOCKED_CONNECT;
+ b->retry_reason = BIO_RR_CONNECT;
+ } else {
+ SYSerr(SYS_F_CONNECT, errno);
+ ERR_add_error_data(4, "host=",
+ c->param_hostname, ":",
+ c->param_port);
+ BIOerr(BIO_F_CONN_STATE,
+ BIO_R_CONNECT_ERROR);
}
- else
- c->state=BIO_CONN_S_OK;
+ goto exit_loop;
+ } else
+ c->state = BIO_CONN_S_OK;
break;
case BIO_CONN_S_BLOCKED_CONNECT:
- i=BIO_sock_error(b->num);
- if (i)
- {
+ i = BIO_sock_error(b->num);
+ if (i) {
BIO_clear_retry_flags(b);
- SYSerr(SYS_F_CONNECT,i);
- ERR_add_error_data(4,"host=",
- c->param_hostname,
- ":",c->param_port);
- BIOerr(BIO_F_CONN_STATE,BIO_R_NBIO_CONNECT_ERROR);
- ret=0;
+ SYSerr(SYS_F_CONNECT, i);
+ ERR_add_error_data(4, "host=",
+ c->param_hostname, ":", c->param_port);
+ BIOerr(BIO_F_CONN_STATE,
+ BIO_R_NBIO_CONNECT_ERROR);
+ ret = 0;
goto exit_loop;
- }
- else
- c->state=BIO_CONN_S_OK;
+ } else
+ c->state = BIO_CONN_S_OK;
break;
case BIO_CONN_S_OK:
- ret=1;
+ ret = 1;
goto exit_loop;
default:
/* abort(); */
goto exit_loop;
- }
+ }
- if (cb != NULL)
- {
- if (!(ret=cb((BIO *)b,c->state,ret)))
+ if (cb != NULL) {
+ if (!(ret = cb((BIO *)b, c->state, ret)))
goto end;
- }
}
+ }
/* Loop does not exit */
exit_loop:
if (cb != NULL)
- ret=cb((BIO *)b,c->state,ret);
+ ret = cb((BIO *)b, c->state, ret);
end:
- return(ret);
- }
+ return (ret);
+}
-BIO_CONNECT *BIO_CONNECT_new(void)
- {
+BIO_CONNECT
+*BIO_CONNECT_new(void)
+{
BIO_CONNECT *ret;
- if ((ret=(BIO_CONNECT *)OPENSSL_malloc(sizeof(BIO_CONNECT))) == NULL)
- return(NULL);
- ret->state=BIO_CONN_S_BEFORE;
- ret->param_hostname=NULL;
- ret->param_port=NULL;
- ret->info_callback=NULL;
- ret->nbio=0;
- ret->ip[0]=0;
- ret->ip[1]=0;
- ret->ip[2]=0;
- ret->ip[3]=0;
- ret->port=0;
- memset((char *)&ret->them,0,sizeof(ret->them));
- return(ret);
- }
-
-void BIO_CONNECT_free(BIO_CONNECT *a)
- {
- if(a == NULL)
- return;
+ if ((ret = (BIO_CONNECT *)OPENSSL_malloc(sizeof(BIO_CONNECT))) == NULL)
+ return (NULL);
+ ret->state = BIO_CONN_S_BEFORE;
+ ret->param_hostname = NULL;
+ ret->param_port = NULL;
+ ret->info_callback = NULL;
+ ret->nbio = 0;
+ ret->ip[0] = 0;
+ ret->ip[1] = 0;
+ ret->ip[2] = 0;
+ ret->ip[3] = 0;
+ ret->port = 0;
+ memset((char *)&ret->them, 0, sizeof(ret->them));
+ return (ret);
+}
+
+void
+BIO_CONNECT_free(BIO_CONNECT *a)
+{
+ if (a == NULL)
+ return;
if (a->param_hostname != NULL)
OPENSSL_free(a->param_hostname);
if (a->param_port != NULL)
OPENSSL_free(a->param_port);
OPENSSL_free(a);
- }
-
-BIO_METHOD *BIO_s_connect(void)
- {
- return(&methods_connectp);
- }
-
-static int conn_new(BIO *bi)
- {
- bi->init=0;
- bi->num=-1;
- bi->flags=0;
- if ((bi->ptr=(char *)BIO_CONNECT_new()) == NULL)
- return(0);
+}
+
+BIO_METHOD
+*BIO_s_connect(void)
+{
+ return (&methods_connectp);
+}
+
+static int
+conn_new(BIO *bi)
+{
+ bi->init = 0;
+ bi->num = -1;
+ bi->flags = 0;
+ if ((bi->ptr = (char *)BIO_CONNECT_new()) == NULL)
+ return (0);
else
- return(1);
- }
+ return (1);
+}
-static void conn_close_socket(BIO *bio)
- {
+static void
+conn_close_socket(BIO *bio)
+{
BIO_CONNECT *c;
- c=(BIO_CONNECT *)bio->ptr;
- if (bio->num != -1)
- {
+ c = (BIO_CONNECT *)bio->ptr;
+ if (bio->num != -1) {
/* Only do a shutdown if things were established */
if (c->state == BIO_CONN_S_OK)
shutdown(bio->num, SHUT_RDWR);
close(bio->num);
- bio->num=-1;
- }
+ bio->num = -1;
}
+}
-static int conn_free(BIO *a)
- {
+static int
+conn_free(BIO *a)
+{
BIO_CONNECT *data;
- if (a == NULL) return(0);
- data=(BIO_CONNECT *)a->ptr;
-
- if (a->shutdown)
- {
+ if (a == NULL)
+ return (0);
+ data = (BIO_CONNECT *)a->ptr;
+
+ if (a->shutdown) {
conn_close_socket(a);
BIO_CONNECT_free(data);
- a->ptr=NULL;
- a->flags=0;
- a->init=0;
- }
- return(1);
+ a->ptr = NULL;
+ a->flags = 0;
+ a->init = 0;
}
-
-static int conn_read(BIO *b, char *out, int outl)
- {
- int ret=0;
+ return (1);
+}
+
+static int
+conn_read(BIO *b, char *out, int outl)
+{
+ int ret = 0;
BIO_CONNECT *data;
- data=(BIO_CONNECT *)b->ptr;
- if (data->state != BIO_CONN_S_OK)
- {
- ret=conn_state(b,data);
+ data = (BIO_CONNECT *)b->ptr;
+ if (data->state != BIO_CONN_S_OK) {
+ ret = conn_state(b, data);
if (ret <= 0)
- return(ret);
- }
+ return (ret);
+ }
- if (out != NULL)
- {
+ if (out != NULL) {
errno = 0;
- ret=read(b->num,out,outl);
+ ret = read(b->num, out, outl);
BIO_clear_retry_flags(b);
- if (ret <= 0)
- {
+ if (ret <= 0) {
if (BIO_sock_should_retry(ret))
BIO_set_retry_read(b);
- }
}
- return(ret);
}
+ return (ret);
+}
-static int conn_write(BIO *b, const char *in, int inl)
- {
+static int
+conn_write(BIO *b, const char *in, int inl)
+{
int ret;
BIO_CONNECT *data;
- data=(BIO_CONNECT *)b->ptr;
- if (data->state != BIO_CONN_S_OK)
- {
- ret=conn_state(b,data);
- if (ret <= 0) return(ret);
- }
+ data = (BIO_CONNECT *)b->ptr;
+ if (data->state != BIO_CONN_S_OK) {
+ ret = conn_state(b, data);
+ if (ret <= 0)
+ return (ret);
+ }
errno = 0;
- ret=write(b->num,in,inl);
+ ret = write(b->num, in, inl);
BIO_clear_retry_flags(b);
- if (ret <= 0)
- {
+ if (ret <= 0) {
if (BIO_sock_should_retry(ret))
BIO_set_retry_write(b);
- }
- return(ret);
}
+ return (ret);
+}
-static long conn_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
+static long
+conn_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
BIO *dbio;
int *ip;
const char **pptr;
- long ret=1;
+ long ret = 1;
BIO_CONNECT *data;
- data=(BIO_CONNECT *)b->ptr;
+ data = (BIO_CONNECT *)b->ptr;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_RESET:
- ret=0;
- data->state=BIO_CONN_S_BEFORE;
+ ret = 0;
+ data->state = BIO_CONN_S_BEFORE;
conn_close_socket(b);
- b->flags=0;
+ b->flags = 0;
break;
case BIO_C_DO_STATE_MACHINE:
/* use this one to start the connection */
if (data->state != BIO_CONN_S_OK)
- ret=(long)conn_state(b,data);
+ ret = (long)conn_state(b, data);
else
- ret=1;
+ ret = 1;
break;
case BIO_C_GET_CONNECT:
- if (ptr != NULL)
- {
- pptr=(const char **)ptr;
- if (num == 0)
- {
- *pptr=data->param_hostname;
-
- }
- else if (num == 1)
- {
- *pptr=data->param_port;
- }
- else if (num == 2)
- {
- *pptr= (char *)&(data->ip[0]);
- }
- else if (num == 3)
- {
- *((int *)ptr)=data->port;
- }
- if ((!b->init) || (ptr == NULL))
- *pptr="not initialized";
- ret=1;
+ if (ptr != NULL) {
+ pptr = (const char **)ptr;
+ if (num == 0) {
+ *pptr = data->param_hostname;
+
+ } else if (num == 1) {
+ *pptr = data->param_port;
+ } else if (num == 2) {
+ *pptr = (char *)&(data->ip[0]);
+ } else if (num == 3) {
+ *((int *)ptr) = data->port;
}
+ if ((!b->init) || (ptr == NULL))
+ *pptr = "not initialized";
+ ret = 1;
+ }
break;
case BIO_C_SET_CONNECT:
- if (ptr != NULL)
- {
- b->init=1;
- if (num == 0)
- {
+ if (ptr != NULL) {
+ b->init = 1;
+ if (num == 0) {
if (data->param_hostname != NULL)
OPENSSL_free(data->param_hostname);
- data->param_hostname=BUF_strdup(ptr);
- }
- else if (num == 1)
- {
+ data->param_hostname = BUF_strdup(ptr);
+ } else if (num == 1) {
if (data->param_port != NULL)
OPENSSL_free(data->param_port);
- data->param_port=BUF_strdup(ptr);
- }
- else if (num == 2)
- {
+ data->param_port = BUF_strdup(ptr);
+ } else if (num == 2) {
char buf[16];
unsigned char *p = ptr;
- (void) snprintf(buf,sizeof buf,"%d.%d.%d.%d",
- p[0],p[1],p[2],p[3]);
+ (void) snprintf(buf, sizeof buf, "%d.%d.%d.%d",
+ p[0], p[1], p[2], p[3]);
if (data->param_hostname != NULL)
OPENSSL_free(data->param_hostname);
- data->param_hostname=BUF_strdup(buf);
- memcpy(&(data->ip[0]),ptr,4);
- }
- else if (num == 3)
- {
- char buf[DECIMAL_SIZE(int)+1];
+ data->param_hostname = BUF_strdup(buf);
+ memcpy(&(data->ip[0]), ptr, 4);
+ } else if (num == 3) {
+ char buf[DECIMAL_SIZE(int) + 1];
- (void) snprintf(buf,sizeof buf,"%d",*(int *)ptr);
+ (void) snprintf(buf, sizeof buf, "%d",
+ *(int *)ptr);
if (data->param_port != NULL)
OPENSSL_free(data->param_port);
- data->param_port=BUF_strdup(buf);
+ data->param_port = BUF_strdup(buf);
data->port= *(int *)ptr;
- }
}
+ }
break;
case BIO_C_SET_NBIO:
- data->nbio=(int)num;
+ data->nbio = (int)num;
break;
case BIO_C_GET_FD:
- if (b->init)
- {
- ip=(int *)ptr;
+ if (b->init) {
+ ip = (int *)ptr;
if (ip != NULL)
- *ip=b->num;
- ret=b->num;
- }
- else
- ret= -1;
+ *ip = b->num;
+ ret = b->num;
+ } else
+ ret = -1;
break;
case BIO_CTRL_GET_CLOSE:
- ret=b->shutdown;
+ ret = b->shutdown;
break;
case BIO_CTRL_SET_CLOSE:
- b->shutdown=(int)num;
+ b->shutdown = (int)num;
break;
case BIO_CTRL_PENDING:
case BIO_CTRL_WPENDING:
- ret=0;
+ ret = 0;
break;
case BIO_CTRL_FLUSH:
break;
case BIO_CTRL_DUP:
{
- dbio=(BIO *)ptr;
- if (data->param_port)
- BIO_set_conn_port(dbio,data->param_port);
- if (data->param_hostname)
- BIO_set_conn_hostname(dbio,data->param_hostname);
- BIO_set_nbio(dbio,data->nbio);
- /* FIXME: the cast of the function seems unlikely to be a good idea */
- (void)BIO_set_info_callback(dbio,(bio_info_cb *)data->info_callback);
+ dbio = (BIO *)ptr;
+ if (data->param_port)
+ BIO_set_conn_port(dbio, data->param_port);
+ if (data->param_hostname)
+ BIO_set_conn_hostname(dbio,
+ data->param_hostname);
+ BIO_set_nbio(dbio, data->nbio);
+ /* FIXME: the cast of the function seems unlikely to be a good idea */
+ (void)BIO_set_info_callback(dbio,
+ (bio_info_cb *)data->info_callback);
}
break;
case BIO_CTRL_SET_CALLBACK:
{
#if 0 /* FIXME: Should this be used? -- Richard Levitte */
- BIOerr(BIO_F_CONN_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
- ret = -1;
+ BIOerr(BIO_F_CONN_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
+ ret = -1;
#else
- ret=0;
+ ret = 0;
#endif
}
break;
case BIO_CTRL_GET_CALLBACK:
{
- int (**fptr)(const BIO *bio,int state,int xret);
+ int (**fptr)(const BIO *bio, int state, int xret);
- fptr=(int (**)(const BIO *bio,int state,int xret))ptr;
- *fptr=data->info_callback;
+ fptr = (int (**)(const BIO *bio, int state, int xret))ptr;
+ *fptr = data->info_callback;
}
break;
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
}
+ return (ret);
+}
-static long conn_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
- {
- long ret=1;
+static long
+conn_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
+{
+ long ret = 1;
BIO_CONNECT *data;
- data=(BIO_CONNECT *)b->ptr;
+ data = (BIO_CONNECT *)b->ptr;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_SET_CALLBACK:
{
- data->info_callback=(int (*)(const struct bio_st *, int, int))fp;
+ data->info_callback = (int (*)(const struct bio_st *, int, int))fp;
}
break;
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
}
-
-static int conn_puts(BIO *bp, const char *str)
- {
- int n,ret;
-
- n=strlen(str);
- ret=conn_write(bp,str,n);
- return(ret);
- }
-
-BIO *BIO_new_connect(char *str)
- {
+ return (ret);
+}
+
+static int
+conn_puts(BIO *bp, const char *str)
+{
+ int n, ret;
+
+ n = strlen(str);
+ ret = conn_write(bp, str, n);
+ return (ret);
+}
+
+BIO
+*BIO_new_connect(char *str)
+{
BIO *ret;
- ret=BIO_new(BIO_s_connect());
- if (ret == NULL) return(NULL);
- if (BIO_set_conn_hostname(ret,str))
- return(ret);
- else
- {
+ ret = BIO_new(BIO_s_connect());
+ if (ret == NULL)
+ return (NULL);
+ if (BIO_set_conn_hostname(ret, str))
+ return (ret);
+ else {
BIO_free(ret);
- return(NULL);
- }
+ return (NULL);
}
+}
#endif
-
static int dgram_sctp_new(BIO *h);
static int dgram_sctp_free(BIO *data);
#ifdef SCTP_AUTHENTICATION_EVENT
-static void dgram_sctp_handle_auth_free_key_event(BIO *b, union sctp_notification *snp);
+static void dgram_sctp_handle_auth_free_key_event(BIO *b,
+ union sctp_notification *snp);
#endif
#endif
static void get_current_time(struct timeval *t);
-static BIO_METHOD methods_dgramp=
- {
+static BIO_METHOD methods_dgramp = {
BIO_TYPE_DGRAM,
"datagram socket",
dgram_write,
dgram_new,
dgram_free,
NULL,
- };
+};
#ifndef OPENSSL_NO_SCTP
-static BIO_METHOD methods_dgramp_sctp=
- {
+static BIO_METHOD methods_dgramp_sctp = {
BIO_TYPE_DGRAM_SCTP,
"datagram sctp socket",
dgram_sctp_write,
dgram_sctp_new,
dgram_sctp_free,
NULL,
- };
+};
#endif
-typedef struct bio_dgram_data_st
- {
+typedef struct bio_dgram_data_st {
union {
struct sockaddr sa;
struct sockaddr_in sa_in;
unsigned int mtu;
struct timeval next_timeout;
struct timeval socket_timeout;
- } bio_dgram_data;
+} bio_dgram_data;
#ifndef OPENSSL_NO_SCTP
-typedef struct bio_dgram_sctp_save_message_st
- {
- BIO *bio;
- char *data;
- int length;
- } bio_dgram_sctp_save_message;
+typedef struct bio_dgram_sctp_save_message_st {
+ BIO *bio;
+ char *data;
+ int length;
+} bio_dgram_sctp_save_message;
-typedef struct bio_dgram_sctp_data_st
- {
+typedef struct bio_dgram_sctp_data_st {
union {
struct sockaddr sa;
struct sockaddr_in sa_in;
int save_shutdown;
int peer_auth_tested;
bio_dgram_sctp_save_message saved_message;
- } bio_dgram_sctp_data;
+} bio_dgram_sctp_data;
#endif
-BIO_METHOD *BIO_s_datagram(void)
- {
- return(&methods_dgramp);
- }
+BIO_METHOD
+*BIO_s_datagram(void)
+{
+ return (&methods_dgramp);
+}
-BIO *BIO_new_dgram(int fd, int close_flag)
- {
+BIO
+*BIO_new_dgram(int fd, int close_flag)
+{
BIO *ret;
- ret=BIO_new(BIO_s_datagram());
- if (ret == NULL) return(NULL);
- BIO_set_fd(ret,fd,close_flag);
- return(ret);
- }
+ ret = BIO_new(BIO_s_datagram());
+ if (ret == NULL)
+ return (NULL);
+ BIO_set_fd(ret, fd, close_flag);
+ return (ret);
+}
-static int dgram_new(BIO *bi)
- {
+static int
+dgram_new(BIO *bi)
+{
bio_dgram_data *data = NULL;
- bi->init=0;
- bi->num=0;
+ bi->init = 0;
+ bi->num = 0;
data = OPENSSL_malloc(sizeof(bio_dgram_data));
if (data == NULL)
return 0;
memset(data, 0x00, sizeof(bio_dgram_data));
- bi->ptr = data;
+ bi->ptr = data;
- bi->flags=0;
- return(1);
- }
+ bi->flags = 0;
+ return (1);
+}
-static int dgram_free(BIO *a)
- {
+static int
+dgram_free(BIO *a)
+{
bio_dgram_data *data;
- if (a == NULL) return(0);
- if ( ! dgram_clear(a))
+ if (a == NULL)
+ return (0);
+ if (!dgram_clear(a))
return 0;
data = (bio_dgram_data *)a->ptr;
- if(data != NULL) OPENSSL_free(data);
+ if (data != NULL)
+ OPENSSL_free(data);
- return(1);
- }
+ return (1);
+}
-static int dgram_clear(BIO *a)
- {
- if (a == NULL) return(0);
- if (a->shutdown)
- {
- if (a->init)
- {
+static int
+dgram_clear(BIO *a)
+{
+ if (a == NULL)
+ return (0);
+ if (a->shutdown) {
+ if (a->init) {
shutdown(a->num, SHUT_RDWR);
close(a->num);
- }
- a->init=0;
- a->flags=0;
}
- return(1);
+ a->init = 0;
+ a->flags = 0;
}
+ return (1);
+}
-static void dgram_adjust_rcv_timeout(BIO *b)
- {
+static void
+dgram_adjust_rcv_timeout(BIO *b)
+{
#if defined(SO_RCVTIMEO)
bio_dgram_data *data = (bio_dgram_data *)b->ptr;
- union { size_t s; int i; } sz = {0};
+ union { size_t s;
+ int i;
+ } sz = {0};
/* Is a timer active? */
- if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0)
- {
+ if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) {
struct timeval timenow, timeleft;
/* Read current socket timeout */
sz.i = sizeof(timeout);
if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, &sz.i) < 0)
- { perror("getsockopt"); }
- else
- {
+ (void*)&timeout, &sz.i) < 0) {
+ perror("getsockopt");
+ } else {
data->socket_timeout.tv_sec = timeout / 1000;
data->socket_timeout.tv_usec = (timeout % 1000) * 1000;
- }
+ }
#else
sz.i = sizeof(data->socket_timeout);
- if ( getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- &(data->socket_timeout), (void *)&sz) < 0)
- { perror("getsockopt"); }
- else if (sizeof(sz.s)!=sizeof(sz.i) && sz.i==0)
- OPENSSL_assert(sz.s<=sizeof(data->socket_timeout));
+ if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
+ &(data->socket_timeout), (void *)&sz) < 0) {
+ perror("getsockopt");
+ } else if (sizeof(sz.s) != sizeof(sz.i) && sz.i == 0)
+ OPENSSL_assert(sz.s <= sizeof(data->socket_timeout));
#endif
/* Get current time */
memcpy(&timeleft, &(data->next_timeout), sizeof(struct timeval));
timeleft.tv_sec -= timenow.tv_sec;
timeleft.tv_usec -= timenow.tv_usec;
- if (timeleft.tv_usec < 0)
- {
+ if (timeleft.tv_usec < 0) {
timeleft.tv_sec--;
timeleft.tv_usec += 1000000;
- }
+ }
- if (timeleft.tv_sec < 0)
- {
+ if (timeleft.tv_sec < 0) {
timeleft.tv_sec = 0;
timeleft.tv_usec = 1;
- }
+ }
/* Adjust socket timeout if next handhake message timer
* will expire earlier.
*/
- if ((data->socket_timeout.tv_sec == 0 && data->socket_timeout.tv_usec == 0) ||
- (data->socket_timeout.tv_sec > timeleft.tv_sec) ||
- (data->socket_timeout.tv_sec == timeleft.tv_sec &&
- data->socket_timeout.tv_usec >= timeleft.tv_usec))
- {
+ if ((data->socket_timeout.tv_sec == 0 &&
+ data->socket_timeout.tv_usec == 0) ||
+ (data->socket_timeout.tv_sec > timeleft.tv_sec) ||
+ (data->socket_timeout.tv_sec == timeleft.tv_sec &&
+ data->socket_timeout.tv_usec >= timeleft.tv_usec)) {
#ifdef OPENSSL_SYS_WINDOWS
timeout = timeleft.tv_sec * 1000 + timeleft.tv_usec / 1000;
if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, sizeof(timeout)) < 0)
- { perror("setsockopt"); }
+ (void*)&timeout, sizeof(timeout)) < 0) {
+ perror("setsockopt");
+ }
#else
- if ( setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, &timeleft,
- sizeof(struct timeval)) < 0)
- { perror("setsockopt"); }
-#endif
+ if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
+ &timeleft, sizeof(struct timeval)) < 0) {
+ perror("setsockopt");
}
- }
#endif
+ }
}
+#endif
+}
-static void dgram_reset_rcv_timeout(BIO *b)
- {
+static void
+dgram_reset_rcv_timeout(BIO *b)
+{
#if defined(SO_RCVTIMEO)
bio_dgram_data *data = (bio_dgram_data *)b->ptr;
/* Is a timer active? */
- if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0)
- {
+ if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) {
#ifdef OPENSSL_SYS_WINDOWS
int timeout = data->socket_timeout.tv_sec * 1000 +
- data->socket_timeout.tv_usec / 1000;
+ data->socket_timeout.tv_usec / 1000;
if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, sizeof(timeout)) < 0)
- { perror("setsockopt"); }
+ (void*)&timeout, sizeof(timeout)) < 0) {
+ perror("setsockopt");
+ }
#else
- if ( setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, &(data->socket_timeout),
- sizeof(struct timeval)) < 0)
- { perror("setsockopt"); }
-#endif
+ if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
+ &(data->socket_timeout), sizeof(struct timeval)) < 0) {
+ perror("setsockopt");
}
#endif
}
+#endif
+}
-static int dgram_read(BIO *b, char *out, int outl)
- {
- int ret=0;
+static int
+dgram_read(BIO *b, char *out, int outl)
+{
+ int ret = 0;
bio_dgram_data *data = (bio_dgram_data *)b->ptr;
struct {
- /*
- * See commentary in b_sock.c. <appro>
- */
- union { size_t s; int i; } len;
- union {
- struct sockaddr sa;
- struct sockaddr_in sa_in;
+ /*
+ * See commentary in b_sock.c. <appro>
+ */
+ union {
+ size_t s;
+ int i;
+ } len;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_in sa_in;
#if OPENSSL_USE_IPV6
- struct sockaddr_in6 sa_in6;
+ struct sockaddr_in6 sa_in6;
#endif
} peer;
} sa;
- sa.len.s=0;
- sa.len.i=sizeof(sa.peer);
+ sa.len.s = 0;
+ sa.len.i = sizeof(sa.peer);
- if (out != NULL)
- {
+ if (out != NULL) {
errno = 0;
memset(&sa.peer, 0x00, sizeof(sa.peer));
dgram_adjust_rcv_timeout(b);
- ret=recvfrom(b->num,out,outl,0,&sa.peer.sa,(void *)&sa.len);
- if (sizeof(sa.len.i)!=sizeof(sa.len.s) && sa.len.i==0)
- {
- OPENSSL_assert(sa.len.s<=sizeof(sa.peer));
+ ret = recvfrom(b->num, out, outl, 0, &sa.peer.sa,(void *)&sa.len);
+ if (sizeof(sa.len.i) != sizeof(sa.len.s) && sa.len.i == 0) {
+ OPENSSL_assert(sa.len.s <= sizeof(sa.peer));
sa.len.i = (int)sa.len.s;
- }
+ }
- if ( ! data->connected && ret >= 0)
+ if (! data->connected && ret >= 0)
BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, &sa.peer);
BIO_clear_retry_flags(b);
- if (ret < 0)
- {
- if (BIO_dgram_should_retry(ret))
- {
+ if (ret < 0) {
+ if (BIO_dgram_should_retry(ret)) {
BIO_set_retry_read(b);
data->_errno = errno;
- }
}
+ }
dgram_reset_rcv_timeout(b);
- }
- return(ret);
}
+ return (ret);
+}
-static int dgram_write(BIO *b, const char *in, int inl)
- {
+static int
+dgram_write(BIO *b, const char *in, int inl)
+{
int ret;
bio_dgram_data *data = (bio_dgram_data *)b->ptr;
errno = 0;
- if ( data->connected )
- ret=write(b->num,in,inl);
- else
- {
+ if (data->connected)
+ ret = write(b->num, in, inl);
+ else {
int peerlen = sizeof(data->peer);
if (data->peer.sa.sa_family == AF_INET)
peerlen = sizeof(data->peer.sa_in6);
#endif
#if defined(NETWARE_CLIB) && defined(NETWARE_BSDSOCK)
- ret=sendto(b->num, (char *)in, inl, 0, &data->peer.sa, peerlen);
+ ret = sendto(b->num, (char *)in, inl, 0, &data->peer.sa, peerlen);
#else
- ret=sendto(b->num, in, inl, 0, &data->peer.sa, peerlen);
+ ret = sendto(b->num, in, inl, 0, &data->peer.sa, peerlen);
#endif
- }
+ }
BIO_clear_retry_flags(b);
- if (ret <= 0)
- {
- if (BIO_dgram_should_retry(ret))
- {
- BIO_set_retry_write(b);
+ if (ret <= 0) {
+ if (BIO_dgram_should_retry(ret)) {
+ BIO_set_retry_write(b);
+
data->_errno = errno;
#if 0 /* higher layers are responsible for querying MTU, if necessary */
- if ( data->_errno == EMSGSIZE)
+ if (data->_errno == EMSGSIZE)
/* retrieve the new MTU */
- BIO_ctrl(b, BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL);
+ BIO_ctrl(b, BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL);
#endif
- }
}
- return(ret);
}
+ return (ret);
+}
-static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
- long ret=1;
+static long
+dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+ long ret = 1;
int *ip;
struct sockaddr *to = NULL;
bio_dgram_data *data = NULL;
#if OPENSSL_USE_IPV6
struct sockaddr_in6 s6;
#endif
- } addr;
+ } addr;
#endif
data = (bio_dgram_data *)b->ptr;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_RESET:
- num=0;
+ num = 0;
case BIO_C_FILE_SEEK:
- ret=0;
+ ret = 0;
break;
case BIO_C_FILE_TELL:
case BIO_CTRL_INFO:
- ret=0;
+ ret = 0;
break;
case BIO_C_SET_FD:
dgram_clear(b);
b->num= *((int *)ptr);
- b->shutdown=(int)num;
- b->init=1;
+ b->shutdown = (int)num;
+ b->init = 1;
break;
case BIO_C_GET_FD:
- if (b->init)
- {
- ip=(int *)ptr;
- if (ip != NULL) *ip=b->num;
- ret=b->num;
- }
- else
- ret= -1;
+ if (b->init) {
+ ip = (int *)ptr;
+ if (ip != NULL)
+ *ip = b->num;
+ ret = b->num;
+ } else
+ ret = -1;
break;
case BIO_CTRL_GET_CLOSE:
- ret=b->shutdown;
+ ret = b->shutdown;
break;
case BIO_CTRL_SET_CLOSE:
- b->shutdown=(int)num;
+ b->shutdown = (int)num;
break;
case BIO_CTRL_PENDING:
case BIO_CTRL_WPENDING:
- ret=0;
+ ret = 0;
break;
case BIO_CTRL_DUP:
case BIO_CTRL_FLUSH:
- ret=1;
+ ret = 1;
break;
case BIO_CTRL_DGRAM_CONNECT:
to = (struct sockaddr *)ptr;
#if 0
- if (connect(b->num, to, sizeof(struct sockaddr)) < 0)
- { perror("connect"); ret = 0; }
- else
- {
+ if (connect(b->num, to, sizeof(struct sockaddr)) < 0) {
+ perror("connect");
+ ret = 0;
+ } else {
#endif
- switch (to->sa_family)
- {
- case AF_INET:
- memcpy(&data->peer,to,sizeof(data->peer.sa_in));
- break;
+ switch (to->sa_family) {
+ case AF_INET:
+ memcpy(&data->peer, to, sizeof(data->peer.sa_in));
+ break;
#if OPENSSL_USE_IPV6
- case AF_INET6:
- memcpy(&data->peer,to,sizeof(data->peer.sa_in6));
- break;
+ case AF_INET6:
+ memcpy(&data->peer, to, sizeof(data->peer.sa_in6));
+ break;
#endif
- default:
- memcpy(&data->peer,to,sizeof(data->peer.sa));
- break;
- }
-#if 0
+ default:
+ memcpy(&data->peer, to, sizeof(data->peer.sa));
+ break;
}
+#if 0
+ }
#endif
break;
/* (Linux)kernel sets DF bit on outgoing IP packets */
#if defined(OPENSSL_SYS_LINUX) && defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DO)
addr_len = (socklen_t)sizeof(addr);
memset((void *)&addr, 0, sizeof(addr));
- if (getsockname(b->num, &addr.sa, &addr_len) < 0)
- {
+ if (getsockname(b->num, &addr.sa, &addr_len) < 0) {
ret = 0;
break;
- }
- switch (addr.sa.sa_family)
- {
+ }
+ switch (addr.sa.sa_family) {
case AF_INET:
sockopt_val = IP_PMTUDISC_DO;
- if ((ret = setsockopt(b->num, IPPROTO_IP, IP_MTU_DISCOVER,
- &sockopt_val, sizeof(sockopt_val))) < 0)
+ if ((ret = setsockopt(b->num, IPPROTO_IP,
+ IP_MTU_DISCOVER, &sockopt_val,
+ sizeof(sockopt_val))) < 0)
perror("setsockopt");
break;
#if OPENSSL_USE_IPV6 && defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DO)
case AF_INET6:
sockopt_val = IPV6_PMTUDISC_DO;
- if ((ret = setsockopt(b->num, IPPROTO_IPV6, IPV6_MTU_DISCOVER,
- &sockopt_val, sizeof(sockopt_val))) < 0)
+ if ((ret = setsockopt(b->num, IPPROTO_IPV6,
+ IPV6_MTU_DISCOVER, &sockopt_val,
+ sizeof(sockopt_val))) < 0)
perror("setsockopt");
break;
#endif
default:
ret = -1;
break;
- }
+ }
ret = -1;
#else
break;
#if defined(OPENSSL_SYS_LINUX) && defined(IP_MTU)
addr_len = (socklen_t)sizeof(addr);
memset((void *)&addr, 0, sizeof(addr));
- if (getsockname(b->num, &addr.sa, &addr_len) < 0)
- {
+ if (getsockname(b->num, &addr.sa, &addr_len) < 0) {
ret = 0;
break;
- }
+ }
sockopt_len = sizeof(sockopt_val);
- switch (addr.sa.sa_family)
- {
+ switch (addr.sa.sa_family) {
case AF_INET:
- if ((ret = getsockopt(b->num, IPPROTO_IP, IP_MTU, (void *)&sockopt_val,
- &sockopt_len)) < 0 || sockopt_val < 0)
- {
+ if ((ret = getsockopt(b->num, IPPROTO_IP, IP_MTU,
+ (void *)&sockopt_val, &sockopt_len)) < 0 ||
+ sockopt_val < 0) {
ret = 0;
- }
- else
- {
+ } else {
/* we assume that the transport protocol is UDP and no
* IP options are used.
*/
data->mtu = sockopt_val - 8 - 20;
ret = data->mtu;
- }
+ }
break;
#if OPENSSL_USE_IPV6 && defined(IPV6_MTU)
case AF_INET6:
- if ((ret = getsockopt(b->num, IPPROTO_IPV6, IPV6_MTU, (void *)&sockopt_val,
- &sockopt_len)) < 0 || sockopt_val < 0)
- {
+ if ((ret = getsockopt(b->num, IPPROTO_IPV6, IPV6_MTU,
+ (void *)&sockopt_val, &sockopt_len)) < 0 ||
+ sockopt_val < 0) {
ret = 0;
- }
- else
- {
+ } else {
/* we assume that the transport protocol is UDP and no
* IPV6 options are used.
*/
data->mtu = sockopt_val - 8 - 40;
ret = data->mtu;
- }
+ }
break;
#endif
- default:
+default:
ret = 0;
break;
- }
+ }
#else
ret = 0;
#endif
break;
case BIO_CTRL_DGRAM_GET_FALLBACK_MTU:
- switch (data->peer.sa.sa_family)
- {
- case AF_INET:
- ret = 576 - 20 - 8;
- break;
+ switch (data->peer.sa.sa_family) {
+ case AF_INET:
+ ret = 576 - 20 - 8;
+ break;
#if OPENSSL_USE_IPV6
- case AF_INET6:
+ case AF_INET6:
#ifdef IN6_IS_ADDR_V4MAPPED
- if (IN6_IS_ADDR_V4MAPPED(&data->peer.sa_in6.sin6_addr))
- ret = 576 - 20 - 8;
- else
+ if (IN6_IS_ADDR_V4MAPPED(&data->peer.sa_in6.sin6_addr))
+ ret = 576 - 20 - 8;
+ else
#endif
- ret = 1280 - 40 - 8;
- break;
+ ret = 1280 - 40 - 8;
+ break;
#endif
- default:
- ret = 576 - 20 - 8;
- break;
- }
+ default:
+ ret = 576 - 20 - 8;
+ break;
+ }
break;
case BIO_CTRL_DGRAM_GET_MTU:
return data->mtu;
case BIO_CTRL_DGRAM_SET_CONNECTED:
to = (struct sockaddr *)ptr;
- if ( to != NULL)
- {
+ if (to != NULL) {
data->connected = 1;
- switch (to->sa_family)
- {
- case AF_INET:
- memcpy(&data->peer,to,sizeof(data->peer.sa_in));
- break;
-#if OPENSSL_USE_IPV6
- case AF_INET6:
- memcpy(&data->peer,to,sizeof(data->peer.sa_in6));
- break;
-#endif
- default:
- memcpy(&data->peer,to,sizeof(data->peer.sa));
- break;
- }
- }
- else
- {
- data->connected = 0;
- memset(&(data->peer), 0x00, sizeof(data->peer));
- }
- break;
- case BIO_CTRL_DGRAM_GET_PEER:
- switch (data->peer.sa.sa_family)
- {
+ switch (to->sa_family) {
case AF_INET:
- ret=sizeof(data->peer.sa_in);
+ memcpy(&data->peer, to, sizeof(data->peer.sa_in));
break;
#if OPENSSL_USE_IPV6
case AF_INET6:
- ret=sizeof(data->peer.sa_in6);
+ memcpy(&data->peer, to, sizeof(data->peer.sa_in6));
break;
#endif
default:
- ret=sizeof(data->peer.sa);
+ memcpy(&data->peer, to, sizeof(data->peer.sa));
break;
}
- if (num==0 || num>ret)
- num=ret;
- memcpy(ptr,&data->peer,(ret=num));
+ } else {
+ data->connected = 0;
+ memset(&(data->peer), 0x00, sizeof(data->peer));
+ }
+ break;
+ case BIO_CTRL_DGRAM_GET_PEER:
+ switch (data->peer.sa.sa_family) {
+ case AF_INET:
+ ret = sizeof(data->peer.sa_in);
+ break;
+#if OPENSSL_USE_IPV6
+ case AF_INET6:
+ ret = sizeof(data->peer.sa_in6);
+ break;
+#endif
+ default:
+ ret = sizeof(data->peer.sa);
+ break;
+ }
+ if (num == 0 || num > ret)
+ num = ret;
+ memcpy(ptr, &data->peer, (ret = num));
break;
case BIO_CTRL_DGRAM_SET_PEER:
to = (struct sockaddr *) ptr;
- switch (to->sa_family)
- {
- case AF_INET:
- memcpy(&data->peer,to,sizeof(data->peer.sa_in));
- break;
+ switch (to->sa_family) {
+ case AF_INET:
+ memcpy(&data->peer, to, sizeof(data->peer.sa_in));
+ break;
#if OPENSSL_USE_IPV6
- case AF_INET6:
- memcpy(&data->peer,to,sizeof(data->peer.sa_in6));
- break;
+ case AF_INET6:
+ memcpy(&data->peer, to, sizeof(data->peer.sa_in6));
+ break;
#endif
- default:
- memcpy(&data->peer,to,sizeof(data->peer.sa));
- break;
- }
+ default:
+ memcpy(&data->peer, to, sizeof(data->peer.sa));
+ break;
+ }
break;
case BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT:
memcpy(&(data->next_timeout), ptr, sizeof(struct timeval));
case BIO_CTRL_DGRAM_SET_RECV_TIMEOUT:
#ifdef OPENSSL_SYS_WINDOWS
{
- struct timeval *tv = (struct timeval *)ptr;
- int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000;
- if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, sizeof(timeout)) < 0)
- { perror("setsockopt"); ret = -1; }
+ struct timeval *tv = (struct timeval *)ptr;
+ int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000;
+ if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
+ (void*)&timeout, sizeof(timeout)) < 0) {
+ perror("setsockopt");
+ ret = -1;
+ }
}
#else
- if ( setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, ptr,
- sizeof(struct timeval)) < 0)
- { perror("setsockopt"); ret = -1; }
+ if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, ptr,
+ sizeof(struct timeval)) < 0) {
+ perror("setsockopt");
+ ret = -1;
+ }
#endif
break;
case BIO_CTRL_DGRAM_GET_RECV_TIMEOUT:
{
- union { size_t s; int i; } sz = {0};
+ union {
+ size_t s;
+ int i;
+ } sz = {0};
#ifdef OPENSSL_SYS_WINDOWS
- int timeout;
- struct timeval *tv = (struct timeval *)ptr;
-
- sz.i = sizeof(timeout);
- if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, &sz.i) < 0)
- { perror("getsockopt"); ret = -1; }
- else
- {
- tv->tv_sec = timeout / 1000;
- tv->tv_usec = (timeout % 1000) * 1000;
- ret = sizeof(*tv);
+ int timeout;
+ struct timeval *tv = (struct timeval *)ptr;
+
+ sz.i = sizeof(timeout);
+ if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
+ (void*)&timeout, &sz.i) < 0) {
+ perror("getsockopt");
+ ret = -1;
+ } else {
+ tv->tv_sec = timeout / 1000;
+ tv->tv_usec = (timeout % 1000) * 1000;
+ ret = sizeof(*tv);
}
#else
- sz.i = sizeof(struct timeval);
- if ( getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- ptr, (void *)&sz) < 0)
- { perror("getsockopt"); ret = -1; }
- else if (sizeof(sz.s)!=sizeof(sz.i) && sz.i==0)
- {
- OPENSSL_assert(sz.s<=sizeof(struct timeval));
- ret = (int)sz.s;
- }
- else
- ret = sz.i;
+ sz.i = sizeof(struct timeval);
+ if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
+ ptr, (void *)&sz) < 0) {
+ perror("getsockopt");
+ ret = -1;
+ } else if (sizeof(sz.s)!=sizeof(sz.i) && sz.i==0) {
+ OPENSSL_assert(sz.s <= sizeof(struct timeval));
+ ret = (int)sz.s;
+ } else
+ ret = sz.i;
#endif
}
break;
case BIO_CTRL_DGRAM_SET_SEND_TIMEOUT:
#ifdef OPENSSL_SYS_WINDOWS
{
- struct timeval *tv = (struct timeval *)ptr;
- int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000;
- if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
- (void*)&timeout, sizeof(timeout)) < 0)
- { perror("setsockopt"); ret = -1; }
+ struct timeval *tv = (struct timeval *)ptr;
+ int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000;
+ if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
+ (void*)&timeout, sizeof(timeout)) < 0) {
+ perror("setsockopt");
+ ret = -1;
+ }
}
#else
- if ( setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, ptr,
- sizeof(struct timeval)) < 0)
- { perror("setsockopt"); ret = -1; }
+ if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, ptr,
+ sizeof(struct timeval)) < 0) {
+ perror("setsockopt");
+ ret = -1;
+ }
#endif
break;
case BIO_CTRL_DGRAM_GET_SEND_TIMEOUT:
{
- union { size_t s; int i; } sz = {0};
+ union {
+ size_t s;
+ int i;
+ } sz = {0};
#ifdef OPENSSL_SYS_WINDOWS
- int timeout;
- struct timeval *tv = (struct timeval *)ptr;
-
- sz.i = sizeof(timeout);
- if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
- (void*)&timeout, &sz.i) < 0)
- { perror("getsockopt"); ret = -1; }
- else
- {
- tv->tv_sec = timeout / 1000;
- tv->tv_usec = (timeout % 1000) * 1000;
- ret = sizeof(*tv);
+ int timeout;
+ struct timeval *tv = (struct timeval *)ptr;
+
+ sz.i = sizeof(timeout);
+ if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
+ (void*)&timeout, &sz.i) < 0) {
+ perror("getsockopt");
+ ret = -1;
+ } else {
+ tv->tv_sec = timeout / 1000;
+ tv->tv_usec = (timeout % 1000) * 1000;
+ ret = sizeof(*tv);
}
#else
- sz.i = sizeof(struct timeval);
- if ( getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
- ptr, (void *)&sz) < 0)
- { perror("getsockopt"); ret = -1; }
- else if (sizeof(sz.s)!=sizeof(sz.i) && sz.i==0)
- {
- OPENSSL_assert(sz.s<=sizeof(struct timeval));
- ret = (int)sz.s;
- }
- else
- ret = sz.i;
+ sz.i = sizeof(struct timeval);
+ if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
+ ptr, (void *)&sz) < 0) {
+ perror("getsockopt");
+ ret = -1;
+ } else if (sizeof(sz.s) != sizeof(sz.i) && sz.i == 0) {
+ OPENSSL_assert(sz.s <= sizeof(struct timeval));
+ ret = (int)sz.s;
+ } else
+ ret = sz.i;
#endif
}
break;
/* fall-through */
case BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP:
#ifdef OPENSSL_SYS_WINDOWS
- if ( data->_errno == WSAETIMEDOUT)
+ if (data->_errno == WSAETIMEDOUT)
#else
- if ( data->_errno == EAGAIN)
+ if (data->_errno == EAGAIN)
#endif
- {
+ {
ret = 1;
data->_errno = 0;
- }
- else
+ } else
ret = 0;
break;
#ifdef EMSGSIZE
case BIO_CTRL_DGRAM_MTU_EXCEEDED:
- if ( data->_errno == EMSGSIZE)
- {
+ if (data->_errno == EMSGSIZE) {
ret = 1;
data->_errno = 0;
- }
- else
+ } else
ret = 0;
break;
#endif
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
}
+ return (ret);
+}
-static int dgram_puts(BIO *bp, const char *str)
- {
- int n,ret;
+static int
+dgram_puts(BIO *bp, const char *str)
+{
+ int n, ret;
- n=strlen(str);
- ret=dgram_write(bp,str,n);
- return(ret);
- }
+ n = strlen(str);
+ ret = dgram_write(bp, str, n);
+ return (ret);
+}
#ifndef OPENSSL_NO_SCTP
-BIO_METHOD *BIO_s_datagram_sctp(void)
- {
- return(&methods_dgramp_sctp);
- }
+BIO_METHOD
+*BIO_s_datagram_sctp(void)
+{
+ return (&methods_dgramp_sctp);
+}
-BIO *BIO_new_dgram_sctp(int fd, int close_flag)
- {
+BIO
+*BIO_new_dgram_sctp(int fd, int close_flag)
+{
BIO *bio;
int ret, optval = 20000;
int auth_data = 0, auth_forward = 0;
#endif
#endif
- bio=BIO_new(BIO_s_datagram_sctp());
- if (bio == NULL) return(NULL);
- BIO_set_fd(bio,fd,close_flag);
+ bio = BIO_new(BIO_s_datagram_sctp());
+ if (bio == NULL)
+ return (NULL);
+ BIO_set_fd(bio, fd, close_flag);
/* Activate SCTP-AUTH for DATA and FORWARD-TSN chunks */
auth.sauth_chunk = OPENSSL_SCTP_DATA_CHUNK_TYPE;
OPENSSL_assert(ret >= 0);
for (p = (unsigned char*) authchunks->gauth_chunks;
- p < (unsigned char*) authchunks + sockopt_len;
- p += sizeof(uint8_t))
- {
- if (*p == OPENSSL_SCTP_DATA_CHUNK_TYPE) auth_data = 1;
- if (*p == OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE) auth_forward = 1;
- }
-
+ p < (unsigned char*) authchunks + sockopt_len;
+ p += sizeof(uint8_t)) {
+ if (*p == OPENSSL_SCTP_DATA_CHUNK_TYPE)
+ auth_data = 1;
+ if (*p == OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE)
+ auth_forward = 1;
+ }
+
OPENSSL_free(authchunks);
OPENSSL_assert(auth_data);
ret = setsockopt(fd, IPPROTO_SCTP, SCTP_PARTIAL_DELIVERY_POINT, &optval, sizeof(optval));
OPENSSL_assert(ret >= 0);
- return(bio);
- }
+ return (bio);
+}
-int BIO_dgram_is_sctp(BIO *bio)
- {
+int
+BIO_dgram_is_sctp(BIO *bio)
+{
return (BIO_method_type(bio) == BIO_TYPE_DGRAM_SCTP);
- }
+}
-static int dgram_sctp_new(BIO *bi)
- {
+static int
+dgram_sctp_new(BIO *bi)
+{
bio_dgram_sctp_data *data = NULL;
- bi->init=0;
- bi->num=0;
+ bi->init = 0;
+ bi->num = 0;
data = OPENSSL_malloc(sizeof(bio_dgram_sctp_data));
if (data == NULL)
return 0;
#ifdef SCTP_PR_SCTP_NONE
data->prinfo.pr_policy = SCTP_PR_SCTP_NONE;
#endif
- bi->ptr = data;
+ bi->ptr = data;
- bi->flags=0;
- return(1);
- }
+ bi->flags = 0;
+ return (1);
+}
-static int dgram_sctp_free(BIO *a)
- {
+static int
+dgram_sctp_free(BIO *a)
+{
bio_dgram_sctp_data *data;
- if (a == NULL) return(0);
- if ( ! dgram_clear(a))
+ if (a == NULL)
+ return (0);
+ if (! dgram_clear(a))
return 0;
data = (bio_dgram_sctp_data *)a->ptr;
- if(data != NULL) OPENSSL_free(data);
+ if (data != NULL)
+ OPENSSL_free(data);
- return(1);
- }
+ return (1);
+}
#ifdef SCTP_AUTHENTICATION_EVENT
-void dgram_sctp_handle_auth_free_key_event(BIO *b, union sctp_notification *snp)
- {
+void
+dgram_sctp_handle_auth_free_key_event(BIO *b, union sctp_notification *snp)
+{
int ret;
struct sctp_authkey_event* authkeyevent = &snp->sn_auth_event;
- if (authkeyevent->auth_indication == SCTP_AUTH_FREE_KEY)
- {
+ if (authkeyevent->auth_indication == SCTP_AUTH_FREE_KEY) {
struct sctp_authkeyid authkeyid;
/* delete key */
authkeyid.scact_keynumber = authkeyevent->auth_keynumber;
ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DELETE_KEY,
- &authkeyid, sizeof(struct sctp_authkeyid));
- }
+ &authkeyid, sizeof(struct sctp_authkeyid));
}
+}
#endif
-static int dgram_sctp_read(BIO *b, char *out, int outl)
- {
+static int
+dgram_sctp_read(BIO *b, char *out, int outl)
+{
int ret = 0, n = 0, i, optval;
socklen_t optlen;
bio_dgram_sctp_data *data = (bio_dgram_sctp_data *)b->ptr;
struct cmsghdr *cmsg;
char cmsgbuf[512];
- if (out != NULL)
- {
+ if (out != NULL) {
errno = 0;
- do
- {
+ do {
memset(&data->rcvinfo, 0x00, sizeof(struct bio_dgram_sctp_rcvinfo));
iov.iov_base = out;
iov.iov_len = outl;
msg.msg_flags = 0;
n = recvmsg(b->num, &msg, 0);
- if (msg.msg_controllen > 0)
- {
- for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg))
- {
+ if (msg.msg_controllen > 0) {
+ for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
if (cmsg->cmsg_level != IPPROTO_SCTP)
continue;
#ifdef SCTP_RCVINFO
- if (cmsg->cmsg_type == SCTP_RCVINFO)
- {
+ if (cmsg->cmsg_type == SCTP_RCVINFO) {
struct sctp_rcvinfo *rcvinfo;
rcvinfo = (struct sctp_rcvinfo *)CMSG_DATA(cmsg);
data->rcvinfo.rcv_tsn = rcvinfo->rcv_tsn;
data->rcvinfo.rcv_cumtsn = rcvinfo->rcv_cumtsn;
data->rcvinfo.rcv_context = rcvinfo->rcv_context;
- }
+ }
#endif
#ifdef SCTP_SNDRCV
- if (cmsg->cmsg_type == SCTP_SNDRCV)
- {
+ if (cmsg->cmsg_type == SCTP_SNDRCV) {
struct sctp_sndrcvinfo *sndrcvinfo;
sndrcvinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg);
data->rcvinfo.rcv_tsn = sndrcvinfo->sinfo_tsn;
data->rcvinfo.rcv_cumtsn = sndrcvinfo->sinfo_cumtsn;
data->rcvinfo.rcv_context = sndrcvinfo->sinfo_context;
- }
-#endif
}
+#endif
}
+ }
- if (n <= 0)
- {
+ if (n <= 0) {
if (n < 0)
ret = n;
break;
- }
+ }
- if (msg.msg_flags & MSG_NOTIFICATION)
- {
+ if (msg.msg_flags & MSG_NOTIFICATION) {
snp = (union sctp_notification*) out;
- if (snp->sn_header.sn_type == SCTP_SENDER_DRY_EVENT)
- {
+ if (snp->sn_header.sn_type == SCTP_SENDER_DRY_EVENT) {
#ifdef SCTP_EVENT
struct sctp_event event;
#else
/* If a message has been delayed until the socket
* is dry, it can be sent now.
*/
- if (data->saved_message.length > 0)
- {
+ if (data->saved_message.length > 0) {
dgram_sctp_write(data->saved_message.bio, data->saved_message.data,
- data->saved_message.length);
+ data->saved_message.length);
OPENSSL_free(data->saved_message.data);
data->saved_message.length = 0;
- }
+ }
/* disable sender dry event */
#ifdef SCTP_EVENT
i = setsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(struct sctp_event_subscribe));
OPENSSL_assert(i >= 0);
#endif
- }
+ }
#ifdef SCTP_AUTHENTICATION_EVENT
if (snp->sn_header.sn_type == SCTP_AUTHENTICATION_EVENT)
data->handle_notifications(b, data->notification_context, (void*) out);
memset(out, 0, outl);
- }
- else
+ } else
ret += n;
- }
+ }
while ((msg.msg_flags & MSG_NOTIFICATION) && (msg.msg_flags & MSG_EOR) && (ret < outl));
- if (ret > 0 && !(msg.msg_flags & MSG_EOR))
- {
+ if (ret > 0 && !(msg.msg_flags & MSG_EOR)) {
/* Partial message read, this should never happen! */
/* The buffer was too small, this means the peer sent
* max record size (2^14 + 2048 + 13)
*/
optlen = (socklen_t) sizeof(int);
- ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_PARTIAL_DELIVERY_POINT,
- &optval, &optlen);
+ ret = getsockopt(b->num, IPPROTO_SCTP,
+ SCTP_PARTIAL_DELIVERY_POINT, &optval, &optlen);
OPENSSL_assert(ret >= 0);
OPENSSL_assert(optval >= 18445);
memset(out, 0, outl);
BIO_set_retry_read(b);
return -1;
- }
+ }
BIO_clear_retry_flags(b);
- if (ret < 0)
- {
- if (BIO_dgram_should_retry(ret))
- {
+ if (ret < 0) {
+ if (BIO_dgram_should_retry(ret)) {
BIO_set_retry_read(b);
data->_errno = errno;
- }
}
+ }
/* Test if peer uses SCTP-AUTH before continuing */
- if (!data->peer_auth_tested)
- {
+ if (!data->peer_auth_tested) {
int ii, auth_data = 0, auth_forward = 0;
unsigned char *p;
struct sctp_authchunks *authchunks;
OPENSSL_assert(ii >= 0);
for (p = (unsigned char*) authchunks->gauth_chunks;
- p < (unsigned char*) authchunks + optlen;
- p += sizeof(uint8_t))
- {
- if (*p == OPENSSL_SCTP_DATA_CHUNK_TYPE) auth_data = 1;
- if (*p == OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE) auth_forward = 1;
- }
+ p < (unsigned char*) authchunks + optlen;
+ p += sizeof(uint8_t)) {
+ if (*p == OPENSSL_SCTP_DATA_CHUNK_TYPE)
+ auth_data = 1;
+ if (*p == OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE)
+ auth_forward = 1;
+ }
OPENSSL_free(authchunks);
- if (!auth_data || !auth_forward)
- {
- BIOerr(BIO_F_DGRAM_SCTP_READ,BIO_R_CONNECT_ERROR);
+ if (!auth_data || !auth_forward) {
+ BIOerr(BIO_F_DGRAM_SCTP_READ, BIO_R_CONNECT_ERROR);
return -1;
- }
+ }
data->peer_auth_tested = 1;
- }
}
- return(ret);
}
+ return (ret);
+}
-static int dgram_sctp_write(BIO *b, const char *in, int inl)
- {
+static int
+dgram_sctp_write(BIO *b, const char *in, int inl)
+{
int ret;
bio_dgram_sctp_data *data = (bio_dgram_sctp_data *)b->ptr;
struct bio_dgram_sctp_sndinfo *sinfo = &(data->sndinfo);
* socket is not dry yet, we have to save it and send it
* as soon as the socket gets dry.
*/
- if (data->save_shutdown && !BIO_dgram_sctp_wait_for_dry(b))
- {
+ if (data->save_shutdown && !BIO_dgram_sctp_wait_for_dry(b)) {
data->saved_message.bio = b;
data->saved_message.length = inl;
data->saved_message.data = OPENSSL_malloc(inl);
ret = sendmsg(b->num, &msg, 0);
BIO_clear_retry_flags(b);
- if (ret <= 0)
- {
- if (BIO_dgram_should_retry(ret))
- {
- BIO_set_retry_write(b);
+ if (ret <= 0) {
+ if (BIO_dgram_should_retry(ret)) {
+ BIO_set_retry_write(b);
+
data->_errno = errno;
- }
}
- return(ret);
}
+ return (ret);
+}
-static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
- long ret=1;
+static long
+dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+ long ret = 1;
bio_dgram_sctp_data *data = NULL;
socklen_t sockopt_len = 0;
struct sctp_authkeyid authkeyid;
data = (bio_dgram_sctp_data *)b->ptr;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_DGRAM_QUERY_MTU:
/* Set to maximum (2^14)
* and ignore user input to enable transport
/* Get active key */
sockopt_len = sizeof(struct sctp_authkeyid);
ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len);
- if (ret < 0) break;
+ if (ret < 0)
+ break;
/* Add new key */
sockopt_len = sizeof(struct sctp_authkey) + 64 * sizeof(uint8_t);
memcpy(&authkey->sca_key[0], ptr, 64 * sizeof(uint8_t));
ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_KEY, authkey, sockopt_len);
- if (ret < 0) break;
+ if (ret < 0)
+ break;
/* Reset active key */
ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY,
- &authkeyid, sizeof(struct sctp_authkeyid));
- if (ret < 0) break;
+ &authkeyid, sizeof(struct sctp_authkeyid));
+ if (ret < 0)
+ break;
break;
case BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY:
/* Get active key */
sockopt_len = sizeof(struct sctp_authkeyid);
ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len);
- if (ret < 0) break;
+ if (ret < 0)
+ break;
/* Set active key */
authkeyid.scact_keynumber = authkeyid.scact_keynumber + 1;
ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY,
- &authkeyid, sizeof(struct sctp_authkeyid));
- if (ret < 0) break;
+ &authkeyid, sizeof(struct sctp_authkeyid));
+ if (ret < 0)
+ break;
/* CCS has been sent, so remember that and fall through
* to check if we need to deactivate an old key
data->ccs_rcvd = 1;
/* CSS has been both, received and sent, so deactivate an old key */
- if (data->ccs_rcvd == 1 && data->ccs_sent == 1)
- {
+ if (data->ccs_rcvd == 1 && data->ccs_sent == 1) {
/* Get active key */
sockopt_len = sizeof(struct sctp_authkeyid);
ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len);
- if (ret < 0) break;
+ if (ret < 0)
+ break;
/* Deactivate key or delete second last key if
* SCTP_AUTHENTICATION_EVENT is not available.
#ifdef SCTP_AUTH_DEACTIVATE_KEY
sockopt_len = sizeof(struct sctp_authkeyid);
ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DEACTIVATE_KEY,
- &authkeyid, sockopt_len);
- if (ret < 0) break;
+ &authkeyid, sockopt_len);
+ if (ret < 0)
+ break;
#endif
#ifndef SCTP_AUTHENTICATION_EVENT
- if (authkeyid.scact_keynumber > 0)
- {
+ if (authkeyid.scact_keynumber > 0) {
authkeyid.scact_keynumber = authkeyid.scact_keynumber - 1;
ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DELETE_KEY,
- &authkeyid, sizeof(struct sctp_authkeyid));
- if (ret < 0) break;
- }
+ &authkeyid, sizeof(struct sctp_authkeyid));
+ if (ret < 0)
+ break;
+ }
#endif
data->ccs_rcvd = 0;
data->ccs_sent = 0;
- }
+ }
break;
case BIO_CTRL_DGRAM_SCTP_GET_SNDINFO:
/* Returns the size of the copied struct. */
/* Pass to default ctrl function to
* process SCTP unspecific commands
*/
- ret=dgram_ctrl(b, cmd, num, ptr);
+ ret = dgram_ctrl(b, cmd, num, ptr);
break;
- }
- return(ret);
}
+ return (ret);
+}
-int BIO_dgram_sctp_notification_cb(BIO *b,
- void (*handle_notifications)(BIO *bio, void *context, void *buf),
- void *context)
- {
+int
+BIO_dgram_sctp_notification_cb(BIO *b,
+ void (*handle_notifications)(BIO *bio, void *context, void *buf),
+ void *context)
+{
bio_dgram_sctp_data *data = (bio_dgram_sctp_data *) b->ptr;
- if (handle_notifications != NULL)
- {
+ if (handle_notifications != NULL) {
data->handle_notifications = handle_notifications;
data->notification_context = context;
- }
- else
+ } else
return -1;
return 0;
- }
+}
-int BIO_dgram_sctp_wait_for_dry(BIO *b)
+int
+BIO_dgram_sctp_wait_for_dry(BIO *b)
{
int is_dry = 0;
int n, sockflags, ret;
ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, &eventsize);
if (ret < 0)
return -1;
-
+
event.sctp_sender_dry_event = 1;
-
+
ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(struct sctp_event_subscribe));
#endif
if (ret < 0)
msg.msg_flags = 0;
n = recvmsg(b->num, &msg, MSG_PEEK);
- if (n <= 0)
- {
+ if (n <= 0) {
if ((n < 0) && (errno != EAGAIN) && (errno != EWOULDBLOCK))
return -1;
else
return 0;
- }
+ }
/* if we find a notification, process it and try again if necessary */
- while (msg.msg_flags & MSG_NOTIFICATION)
- {
+ while (msg.msg_flags & MSG_NOTIFICATION) {
memset(&snp, 0x00, sizeof(union sctp_notification));
iov.iov_base = (char *)&snp;
iov.iov_len = sizeof(union sctp_notification);
msg.msg_flags = 0;
n = recvmsg(b->num, &msg, 0);
- if (n <= 0)
- {
+ if (n <= 0) {
if ((n < 0) && (errno != EAGAIN) && (errno != EWOULDBLOCK))
return -1;
else
return is_dry;
- }
-
- if (snp.sn_header.sn_type == SCTP_SENDER_DRY_EVENT)
- {
+ }
+
+ if (snp.sn_header.sn_type == SCTP_SENDER_DRY_EVENT) {
is_dry = 1;
/* disable sender dry event */
#endif
if (ret < 0)
return -1;
- }
+ }
#ifdef SCTP_AUTHENTICATION_EVENT
if (snp.sn_header.sn_type == SCTP_AUTHENTICATION_EVENT)
msg.msg_flags = 0;
/* if we have seen the dry already, don't wait */
- if (is_dry)
- {
+ if (is_dry) {
sockflags = fcntl(b->num, F_GETFL, 0);
fcntl(b->num, F_SETFL, O_NONBLOCK);
- }
+ }
n = recvmsg(b->num, &msg, MSG_PEEK);
- if (is_dry)
- {
+ if (is_dry) {
fcntl(b->num, F_SETFL, sockflags);
- }
+ }
- if (n <= 0)
- {
+ if (n <= 0) {
if ((n < 0) && (errno != EAGAIN) && (errno != EWOULDBLOCK))
return -1;
else
return is_dry;
- }
}
+ }
/* read anything else */
return is_dry;
}
-int BIO_dgram_sctp_msg_waiting(BIO *b)
- {
+int
+BIO_dgram_sctp_msg_waiting(BIO *b)
+{
int n, sockflags;
union sctp_notification snp;
struct msghdr msg;
/* Check if there are any messages waiting to be read */
do
- {
+ {
memset(&snp, 0x00, sizeof(union sctp_notification));
iov.iov_base = (char *)&snp;
iov.iov_len = sizeof(union sctp_notification);
fcntl(b->num, F_SETFL, sockflags);
/* if notification, process and try again */
- if (n > 0 && (msg.msg_flags & MSG_NOTIFICATION))
- {
+ if (n > 0 && (msg.msg_flags & MSG_NOTIFICATION)) {
#ifdef SCTP_AUTHENTICATION_EVENT
if (snp.sn_header.sn_type == SCTP_AUTHENTICATION_EVENT)
dgram_sctp_handle_auth_free_key_event(b, &snp);
if (data->handle_notifications != NULL)
data->handle_notifications(b, data->notification_context, (void*) &snp);
- }
+ }
- } while (n > 0 && (msg.msg_flags & MSG_NOTIFICATION));
+ } while (n > 0 && (msg.msg_flags & MSG_NOTIFICATION));
/* Return 1 if there is a message to be read, return 0 otherwise. */
if (n > 0)
return 1;
else
return 0;
- }
+}
-static int dgram_sctp_puts(BIO *bp, const char *str)
- {
- int n,ret;
+static int
+dgram_sctp_puts(BIO *bp, const char *str)
+{
+ int n, ret;
- n=strlen(str);
- ret=dgram_sctp_write(bp,str,n);
- return(ret);
- }
+ n = strlen(str);
+ ret = dgram_sctp_write(bp, str, n);
+ return (ret);
+}
#endif
-static int BIO_dgram_should_retry(int i)
- {
+static int
+BIO_dgram_should_retry(int i)
+{
int err;
- if ((i == 0) || (i == -1))
- {
- err=errno;
+ if ((i == 0) || (i == -1)) {
+ err = errno;
#if defined(OPENSSL_SYS_WINDOWS)
/* If the socket return value (i) is -1
*/
#endif
- return(BIO_dgram_non_fatal_error(err));
- }
- return(0);
+ return (BIO_dgram_non_fatal_error(err));
}
+ return (0);
+}
-int BIO_dgram_non_fatal_error(int err)
- {
- switch (err)
- {
+int
+BIO_dgram_non_fatal_error(int err)
+{
+ switch (err) {
#if defined(OPENSSL_SYS_WINDOWS)
# if defined(WSAEWOULDBLOCK)
case WSAEWOULDBLOCK:
case EALREADY:
#endif
- return(1);
+ return (1);
/* break; */
default:
break;
- }
- return(0);
}
+ return (0);
+}
-static void get_current_time(struct timeval *t)
- {
+static void
+get_current_time(struct timeval *t) {
gettimeofday(t, NULL);
- }
+}
#endif
static int fd_free(BIO *data);
int BIO_fd_should_retry(int s);
-static BIO_METHOD methods_fdp=
- {
- BIO_TYPE_FD,"file descriptor",
+static BIO_METHOD methods_fdp = {
+ BIO_TYPE_FD, "file descriptor",
fd_write,
fd_read,
fd_puts,
fd_new,
fd_free,
NULL,
- };
+};
-BIO_METHOD *BIO_s_fd(void)
- {
- return(&methods_fdp);
- }
+BIO_METHOD
+*BIO_s_fd(void)
+{
+ return (&methods_fdp);
+}
-BIO *BIO_new_fd(int fd,int close_flag)
- {
+BIO
+*BIO_new_fd(int fd, int close_flag)
+{
BIO *ret;
- ret=BIO_new(BIO_s_fd());
- if (ret == NULL) return(NULL);
- BIO_set_fd(ret,fd,close_flag);
- return(ret);
- }
+ ret = BIO_new(BIO_s_fd());
+ if (ret == NULL)
+ return (NULL);
+ BIO_set_fd(ret, fd, close_flag);
+ return (ret);
+}
-static int fd_new(BIO *bi)
- {
- bi->init=0;
- bi->num=-1;
- bi->ptr=NULL;
+static int
+fd_new(BIO *bi)
+{
+ bi->init = 0;
+ bi->num = -1;
+ bi->ptr = NULL;
bi->flags=BIO_FLAGS_UPLINK; /* essentially redundant */
- return(1);
- }
+ return (1);
+}
-static int fd_free(BIO *a)
- {
- if (a == NULL) return(0);
- if (a->shutdown)
- {
- if (a->init)
- {
+static int
+fd_free(BIO *a)
+{
+ if (a == NULL)
+ return (0);
+ if (a->shutdown) {
+ if (a->init) {
UP_close(a->num);
- }
- a->init=0;
- a->flags=BIO_FLAGS_UPLINK;
}
- return(1);
+ a->init = 0;
+ a->flags = BIO_FLAGS_UPLINK;
}
-
-static int fd_read(BIO *b, char *out,int outl)
- {
- int ret=0;
+ return (1);
+}
- if (out != NULL)
- {
+static int
+fd_read(BIO *b, char *out, int outl)
+{
+ int ret = 0;
+
+ if (out != NULL) {
errno = 0;
- ret=UP_read(b->num,out,outl);
+ ret = UP_read(b->num, out, outl);
BIO_clear_retry_flags(b);
- if (ret <= 0)
- {
+ if (ret <= 0) {
if (BIO_fd_should_retry(ret))
BIO_set_retry_read(b);
- }
}
- return(ret);
}
+ return (ret);
+}
-static int fd_write(BIO *b, const char *in, int inl)
- {
+static int
+fd_write(BIO *b, const char *in, int inl)
+{
int ret;
errno = 0;
- ret=UP_write(b->num,in,inl);
+ ret = UP_write(b->num, in, inl);
BIO_clear_retry_flags(b);
- if (ret <= 0)
- {
+ if (ret <= 0) {
if (BIO_fd_should_retry(ret))
BIO_set_retry_write(b);
- }
- return(ret);
}
+ return (ret);
+}
-static long fd_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
- long ret=1;
+static long
+fd_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+ long ret = 1;
int *ip;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_RESET:
- num=0;
+ num = 0;
case BIO_C_FILE_SEEK:
- ret=(long)UP_lseek(b->num,num,0);
+ ret = (long)UP_lseek(b->num, num, 0);
break;
case BIO_C_FILE_TELL:
case BIO_CTRL_INFO:
- ret=(long)UP_lseek(b->num,0,1);
+ ret = (long)UP_lseek(b->num, 0, 1);
break;
case BIO_C_SET_FD:
fd_free(b);
b->num= *((int *)ptr);
- b->shutdown=(int)num;
- b->init=1;
+ b->shutdown = (int)num;
+ b->init = 1;
break;
case BIO_C_GET_FD:
- if (b->init)
- {
- ip=(int *)ptr;
- if (ip != NULL) *ip=b->num;
- ret=b->num;
- }
- else
- ret= -1;
+ if (b->init) {
+ ip = (int *)ptr;
+ if (ip != NULL)
+ *ip = b->num;
+ ret = b->num;
+ } else
+ ret = -1;
break;
case BIO_CTRL_GET_CLOSE:
- ret=b->shutdown;
+ ret = b->shutdown;
break;
case BIO_CTRL_SET_CLOSE:
- b->shutdown=(int)num;
+ b->shutdown = (int)num;
break;
case BIO_CTRL_PENDING:
case BIO_CTRL_WPENDING:
- ret=0;
+ ret = 0;
break;
case BIO_CTRL_DUP:
case BIO_CTRL_FLUSH:
- ret=1;
+ ret = 1;
break;
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
}
+ return (ret);
+}
-static int fd_puts(BIO *bp, const char *str)
- {
- int n,ret;
+static int
+fd_puts(BIO *bp, const char *str)
+{
+ int n, ret;
- n=strlen(str);
- ret=fd_write(bp,str,n);
- return(ret);
- }
+ n = strlen(str);
+ ret = fd_write(bp, str, n);
+ return (ret);
+}
-static int fd_gets(BIO *bp, char *buf, int size)
- {
- int ret=0;
- char *ptr=buf;
- char *end=buf+size-1;
+static int
+fd_gets(BIO *bp, char *buf, int size)
+{
+ int ret = 0;
+ char *ptr = buf;
+ char *end = buf + size - 1;
- while ( (ptr < end) && (fd_read(bp, ptr, 1) > 0) && (ptr[0] != '\n') )
+ while ((ptr < end) && (fd_read(bp, ptr, 1) > 0) && (ptr[0] != '\n'))
ptr++;
- ptr[0]='\0';
+ ptr[0] = '\0';
if (buf[0] != '\0')
- ret=strlen(buf);
- return(ret);
- }
+ ret = strlen(buf);
+ return (ret);
+}
-int BIO_fd_should_retry(int i)
- {
+int
+BIO_fd_should_retry(int i)
+{
int err;
- if ((i == 0) || (i == -1))
- {
- err=errno;
+ if ((i == 0) || (i == -1)) {
+ err = errno;
#if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
if ((i == -1) && (err == 0))
- return(1);
+ return (1);
#endif
- return(BIO_fd_non_fatal_error(err));
- }
- return(0);
+ return (BIO_fd_non_fatal_error(err));
}
+ return (0);
+}
-int BIO_fd_non_fatal_error(int err)
- {
- switch (err)
- {
+int
+BIO_fd_non_fatal_error(int err)
+{
+ switch (err) {
#ifdef EWOULDBLOCK
# ifdef WSAEWOULDBLOCK
#ifdef EALREADY
case EALREADY:
#endif
- return(1);
+ return (1);
/* break; */
default:
break;
- }
- return(0);
}
+ return (0);
+}
#endif
static long file_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int file_new(BIO *h);
static int file_free(BIO *data);
-static BIO_METHOD methods_filep=
- {
+
+static BIO_METHOD methods_filep = {
BIO_TYPE_FILE,
"FILE pointer",
file_write,
file_new,
file_free,
NULL,
- };
+};
-BIO *BIO_new_file(const char *filename, const char *mode)
- {
+BIO
+*BIO_new_file(const char *filename, const char *mode)
+{
BIO *ret;
- FILE *file=NULL;
+ FILE *file = NULL;
#if defined(_WIN32) && defined(CP_UTF8)
- int sz, len_0 = (int)strlen(filename)+1;
+ int sz, len_0 = (int)strlen(filename) + 1;
DWORD flags;
/*
* ERROR_NO_UNICODE_TRANSLATION, in which case we fall
* back to fopen...
*/
- if ((sz=MultiByteToWideChar(CP_UTF8,(flags=MB_ERR_INVALID_CHARS),
- filename,len_0,NULL,0))>0 ||
- (GetLastError()==ERROR_INVALID_FLAGS &&
- (sz=MultiByteToWideChar(CP_UTF8,(flags=0),
- filename,len_0,NULL,0))>0)
- )
- {
+ if ((sz = MultiByteToWideChar(CP_UTF8,(flags = MB_ERR_INVALID_CHARS),
+ filename, len_0, NULL, 0)) > 0 ||
+ (GetLastError() == ERROR_INVALID_FLAGS &&
+ (sz = MultiByteToWideChar(CP_UTF8,(flags = 0),
+ filename, len_0, NULL, 0)) > 0)) {
WCHAR wmode[8];
WCHAR *wfilename = _alloca(sz*sizeof(WCHAR));
- if (MultiByteToWideChar(CP_UTF8,flags,
- filename,len_0,wfilename,sz) &&
- MultiByteToWideChar(CP_UTF8,0,mode,strlen(mode)+1,
- wmode,sizeof(wmode)/sizeof(wmode[0])) &&
- (file=_wfopen(wfilename,wmode))==NULL &&
- (errno==ENOENT || errno==EBADF)
- ) /* UTF-8 decode succeeded, but no file, filename
+ if (MultiByteToWideChar(CP_UTF8, flags, filename, len_0,
+ wfilename, sz) && MultiByteToWideChar(CP_UTF8, 0, mode,
+ strlen(mode) + 1, wmode,
+ sizeof(wmode) / sizeof(wmode[0])) &&
+ (file = _wfopen(wfilename, wmode)) == NULL &&
+ (errno == ENOENT || errno == EBADF)
+ ) /* UTF - 8 decode succeeded, but no file, filename
* could still have been locale-ized... */
- file = fopen(filename,mode);
- }
- else if (GetLastError()==ERROR_NO_UNICODE_TRANSLATION)
- {
- file = fopen(filename,mode);
- }
+ file = fopen(filename, mode);
+ } else if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION) {
+ file = fopen(filename, mode);
+ }
#else
- file=fopen(filename,mode);
+ file = fopen(filename, mode);
+
#endif
- if (file == NULL)
- {
+ if (file == NULL) {
SYSerr(SYS_F_FOPEN, errno);
- ERR_add_error_data(5,"fopen('",filename,"','",mode,"')");
+ ERR_add_error_data(5, "fopen('", filename, "', '", mode, "')");
if (errno == ENOENT)
- BIOerr(BIO_F_BIO_NEW_FILE,BIO_R_NO_SUCH_FILE);
+ BIOerr(BIO_F_BIO_NEW_FILE, BIO_R_NO_SUCH_FILE);
else
- BIOerr(BIO_F_BIO_NEW_FILE,ERR_R_SYS_LIB);
- return(NULL);
- }
- if ((ret=BIO_new(BIO_s_file())) == NULL)
- {
+ BIOerr(BIO_F_BIO_NEW_FILE, ERR_R_SYS_LIB);
+ return (NULL);
+ }
+ if ((ret = BIO_new(BIO_s_file())) == NULL) {
fclose(file);
- return(NULL);
- }
-
- BIO_clear_flags(ret,BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */
- BIO_set_fp(ret,file,BIO_CLOSE);
- return(ret);
+ return (NULL);
}
-BIO *BIO_new_fp(FILE *stream, int close_flag)
- {
- BIO *ret;
-
- if ((ret=BIO_new(BIO_s_file())) == NULL)
- return(NULL);
-
- BIO_set_flags(ret,BIO_FLAGS_UPLINK); /* redundant, left for documentation puposes */
- BIO_set_fp(ret,stream,close_flag);
- return(ret);
- }
+ BIO_clear_flags(ret, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */
+ BIO_set_fp(ret, file, BIO_CLOSE);
+ return (ret);
+}
-BIO_METHOD *BIO_s_file(void)
- {
- return(&methods_filep);
- }
+BIO
+*BIO_new_fp(FILE *stream, int close_flag)
+{
+ BIO *ret;
-static int file_new(BIO *bi)
- {
- bi->init=0;
- bi->num=0;
- bi->ptr=NULL;
+ if ((ret = BIO_new(BIO_s_file())) == NULL)
+ return (NULL);
+
+ BIO_set_flags(ret, BIO_FLAGS_UPLINK); /* redundant, left for documentation puposes */
+ BIO_set_fp(ret, stream, close_flag);
+ return (ret);
+}
+
+BIO_METHOD
+*BIO_s_file(void)
+{
+ return (&methods_filep);
+}
+
+static int
+file_new(BIO *bi)
+{
+ bi->init = 0;
+ bi->num = 0;
+ bi->ptr = NULL;
bi->flags=BIO_FLAGS_UPLINK; /* default to UPLINK */
- return(1);
- }
-
-static int file_free(BIO *a)
- {
- if (a == NULL) return(0);
- if (a->shutdown)
- {
- if ((a->init) && (a->ptr != NULL))
- {
+ return (1);
+}
+
+static int
+file_free(BIO *a)
+{
+ if (a == NULL)
+ return (0);
+ if (a->shutdown) {
+ if ((a->init) && (a->ptr != NULL)) {
if (a->flags&BIO_FLAGS_UPLINK)
UP_fclose (a->ptr);
else
fclose (a->ptr);
- a->ptr=NULL;
- a->flags=BIO_FLAGS_UPLINK;
- }
- a->init=0;
+ a->ptr = NULL;
+ a->flags = BIO_FLAGS_UPLINK;
}
- return(1);
+ a->init = 0;
}
-
-static int file_read(BIO *b, char *out, int outl)
- {
- int ret=0;
+ return (1);
+}
- if (b->init && (out != NULL))
- {
+static int
+file_read(BIO *b, char *out, int outl)
+{
+ int ret = 0;
+
+ if (b->init && (out != NULL)) {
if (b->flags&BIO_FLAGS_UPLINK)
- ret=UP_fread(out,1,(int)outl,b->ptr);
+ ret = UP_fread(out, 1,(int)outl, b->ptr);
else
- ret=fread(out,1,(int)outl,(FILE *)b->ptr);
- if(ret == 0 && (b->flags&BIO_FLAGS_UPLINK)?UP_ferror((FILE *)b->ptr):ferror((FILE *)b->ptr))
- {
+ ret = fread(out, 1,(int)outl,(FILE *)b->ptr);
+ if (ret == 0 && (b->flags & BIO_FLAGS_UPLINK) ?
+ UP_ferror((FILE *)b->ptr) : ferror((FILE *)b->ptr)) {
SYSerr(SYS_F_FREAD, errno);
- BIOerr(BIO_F_FILE_READ,ERR_R_SYS_LIB);
- ret=-1;
- }
+ BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB);
+ ret = -1;
}
- return(ret);
}
+ return (ret);
+}
-static int file_write(BIO *b, const char *in, int inl)
- {
- int ret=0;
+static int
+file_write(BIO *b, const char *in, int inl)
+{
+ int ret = 0;
- if (b->init && (in != NULL))
- {
+ if (b->init && (in != NULL)) {
if (b->flags&BIO_FLAGS_UPLINK)
- ret=UP_fwrite(in,(int)inl,1,b->ptr);
+ ret = UP_fwrite(in,(int)inl, 1, b->ptr);
else
- ret=fwrite(in,(int)inl,1,(FILE *)b->ptr);
+ ret = fwrite(in,(int)inl, 1,(FILE *)b->ptr);
if (ret)
- ret=inl;
+ ret = inl;
/* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */
/* according to Tim Hudson <tjh@cryptsoft.com>, the commented
* out version above can cause 'inl' write calls under
* some stupid stdio implementations (VMS) */
- }
- return(ret);
}
-
-static long file_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
- long ret=1;
- FILE *fp=(FILE *)b->ptr;
+ return (ret);
+}
+
+static long
+file_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+ long ret = 1;
+ FILE *fp = (FILE *)b->ptr;
FILE **fpp;
char p[4];
- switch (cmd)
- {
+ switch (cmd) {
case BIO_C_FILE_SEEK:
case BIO_CTRL_RESET:
if (b->flags&BIO_FLAGS_UPLINK)
- ret=(long)UP_fseek(b->ptr,num,0);
+ ret = (long)UP_fseek(b->ptr, num, 0);
else
- ret=(long)fseek(fp,num,0);
+ ret = (long)fseek(fp, num, 0);
break;
case BIO_CTRL_EOF:
if (b->flags&BIO_FLAGS_UPLINK)
- ret=(long)UP_feof(fp);
+ ret = (long)UP_feof(fp);
else
- ret=(long)feof(fp);
+ ret = (long)feof(fp);
break;
case BIO_C_FILE_TELL:
case BIO_CTRL_INFO:
if (b->flags&BIO_FLAGS_UPLINK)
- ret=UP_ftell(b->ptr);
+ ret = UP_ftell(b->ptr);
else
- ret=ftell(fp);
+ ret = ftell(fp);
break;
case BIO_C_SET_FILE_PTR:
file_free(b);
- b->shutdown=(int)num&BIO_CLOSE;
- b->ptr=ptr;
- b->init=1;
+ b->shutdown = (int)num&BIO_CLOSE;
+ b->ptr = ptr;
+ b->init = 1;
#if BIO_FLAGS_UPLINK!=0
#if defined(__MINGW32__) && defined(__MSVCRT__) && !defined(_IOB_ENTRIES)
#define _IOB_ENTRIES 20
#if defined(_IOB_ENTRIES)
/* Safety net to catch purely internal BIO_set_fp calls */
if ((size_t)ptr >= (size_t)stdin &&
- (size_t)ptr < (size_t)(stdin+_IOB_ENTRIES))
- BIO_clear_flags(b,BIO_FLAGS_UPLINK);
+ (size_t)ptr < (size_t)(stdin + _IOB_ENTRIES))
+ BIO_clear_flags(b, BIO_FLAGS_UPLINK);
#endif
#endif
#ifdef UP_fsetmod
#endif
{
#if defined(OPENSSL_SYS_WINDOWS)
- int fd = _fileno((FILE*)ptr);
- if (num & BIO_FP_TEXT)
- _setmode(fd,_O_TEXT);
- else
- _setmode(fd,_O_BINARY);
+ int fd = _fileno((FILE*)ptr);
+ if (num & BIO_FP_TEXT)
+ _setmode(fd, _O_TEXT);
+ else
+ _setmode(fd, _O_BINARY);
#elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB)
- int fd = fileno((FILE*)ptr);
- /* Under CLib there are differences in file modes */
- if (num & BIO_FP_TEXT)
- setmode(fd,O_TEXT);
- else
- setmode(fd,O_BINARY);
-#elif defined(OPENSSL_SYS_MSDOS)
- int fd = fileno((FILE*)ptr);
- /* Set correct text/binary mode */
- if (num & BIO_FP_TEXT)
- _setmode(fd,_O_TEXT);
- /* Dangerous to set stdin/stdout to raw (unless redirected) */
- else
- {
- if (fd == STDIN_FILENO || fd == STDOUT_FILENO)
- {
- if (isatty(fd) <= 0)
- _setmode(fd,_O_BINARY);
- }
+ int fd = fileno((FILE*)ptr);
+ /* Under CLib there are differences in file modes */
+ if (num & BIO_FP_TEXT)
+ setmode(fd, O_TEXT);
else
- _setmode(fd,_O_BINARY);
+ setmode(fd, O_BINARY);
+#elif defined(OPENSSL_SYS_MSDOS)
+ int fd = fileno((FILE*)ptr);
+ /* Set correct text/binary mode */
+ if (num & BIO_FP_TEXT)
+ _setmode(fd, _O_TEXT);
+ /* Dangerous to set stdin/stdout to raw (unless redirected) */
+ else {
+ if (fd == STDIN_FILENO || fd == STDOUT_FILENO) {
+ if (isatty(fd) <= 0)
+ _setmode(fd, _O_BINARY);
+ } else
+ _setmode(fd, _O_BINARY);
}
#elif defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN)
- int fd = fileno((FILE*)ptr);
- if (num & BIO_FP_TEXT)
- setmode(fd, O_TEXT);
- else
- setmode(fd, O_BINARY);
+ int fd = fileno((FILE*)ptr);
+ if (num & BIO_FP_TEXT)
+ setmode(fd, O_TEXT);
+ else
+ setmode(fd, O_BINARY);
#endif
}
break;
case BIO_C_SET_FILENAME:
file_free(b);
- b->shutdown=(int)num&BIO_CLOSE;
- if (num & BIO_FP_APPEND)
- {
+ b->shutdown = (int)num&BIO_CLOSE;
+ if (num & BIO_FP_APPEND) {
if (num & BIO_FP_READ)
- BUF_strlcpy(p,"a+",sizeof p);
- else BUF_strlcpy(p,"a",sizeof p);
- }
- else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE))
- BUF_strlcpy(p,"r+",sizeof p);
+ BUF_strlcpy(p, "a+", sizeof p);
+ else BUF_strlcpy(p, "a", sizeof p);
+ } else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE))
+ BUF_strlcpy(p, "r+", sizeof p);
else if (num & BIO_FP_WRITE)
- BUF_strlcpy(p,"w",sizeof p);
+ BUF_strlcpy(p, "w", sizeof p);
else if (num & BIO_FP_READ)
- BUF_strlcpy(p,"r",sizeof p);
- else
- {
- BIOerr(BIO_F_FILE_CTRL,BIO_R_BAD_FOPEN_MODE);
- ret=0;
+ BUF_strlcpy(p, "r", sizeof p);
+ else {
+ BIOerr(BIO_F_FILE_CTRL, BIO_R_BAD_FOPEN_MODE);
+ ret = 0;
break;
- }
+ }
#if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_WIN32_CYGWIN)
if (!(num & BIO_FP_TEXT))
- strcat(p,"b");
+ strcat(p, "b");
else
- strcat(p,"t");
+ strcat(p, "t");
#endif
#if defined(OPENSSL_SYS_NETWARE)
if (!(num & BIO_FP_TEXT))
- strcat(p,"b");
+ strcat(p, "b");
else
- strcat(p,"t");
+ strcat(p, "t");
#endif
- fp=fopen(ptr,p);
- if (fp == NULL)
- {
+ fp = fopen(ptr, p);
+ if (fp == NULL) {
SYSerr(SYS_F_FOPEN, errno);
- ERR_add_error_data(5,"fopen('",ptr,"','",p,"')");
- BIOerr(BIO_F_FILE_CTRL,ERR_R_SYS_LIB);
- ret=0;
+ ERR_add_error_data(5, "fopen('", ptr, "', '", p, "')");
+ BIOerr(BIO_F_FILE_CTRL, ERR_R_SYS_LIB);
+ ret = 0;
break;
- }
- b->ptr=fp;
- b->init=1;
- BIO_clear_flags(b,BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */
+ }
+ b->ptr = fp;
+ b->init = 1;
+ BIO_clear_flags(b, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */
break;
case BIO_C_GET_FILE_PTR:
/* the ptr parameter is actually a FILE ** in this case. */
- if (ptr != NULL)
- {
- fpp=(FILE **)ptr;
- *fpp=(FILE *)b->ptr;
- }
+ if (ptr != NULL) {
+ fpp = (FILE **)ptr;
+ *fpp = (FILE *)b->ptr;
+ }
break;
case BIO_CTRL_GET_CLOSE:
- ret=(long)b->shutdown;
+ ret = (long)b->shutdown;
break;
case BIO_CTRL_SET_CLOSE:
- b->shutdown=(int)num;
+ b->shutdown = (int)num;
break;
case BIO_CTRL_FLUSH:
if (b->flags&BIO_FLAGS_UPLINK)
fflush((FILE *)b->ptr);
break;
case BIO_CTRL_DUP:
- ret=1;
+ ret = 1;
break;
case BIO_CTRL_WPENDING:
case BIO_CTRL_PUSH:
case BIO_CTRL_POP:
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
}
+ return (ret);
+}
-static int file_gets(BIO *bp, char *buf, int size)
- {
- int ret=0;
+static int
+file_gets(BIO *bp, char *buf, int size)
+{
+ int ret = 0;
- buf[0]='\0';
- if (bp->flags&BIO_FLAGS_UPLINK)
- {
- if (!UP_fgets(buf,size,bp->ptr))
+ buf[0] = '\0';
+ if (bp->flags&BIO_FLAGS_UPLINK) {
+ if (!UP_fgets(buf, size, bp->ptr))
goto err;
- }
- else
- {
- if (!fgets(buf,size,(FILE *)bp->ptr))
+ } else {
+ if (!fgets(buf, size,(FILE *)bp->ptr))
goto err;
- }
- if (buf[0] != '\0')
- ret=strlen(buf);
- err:
- return(ret);
}
+ if (buf[0] != '\0')
+ ret = strlen(buf);
+err:
+ return (ret);
+}
-static int file_puts(BIO *bp, const char *str)
- {
- int n,ret;
+static int
+file_puts(BIO *bp, const char *str)
+{
+ int n, ret;
- n=strlen(str);
- ret=file_write(bp,str,n);
- return(ret);
- }
+ n = strlen(str);
+ ret = file_write(bp, str, n);
+ return (ret);
+}
#endif /* OPENSSL_NO_STDIO */
#endif /* HEADER_BSS_FILE_C */
-
-
# if __INITIAL_POINTER_SIZE == 64
# pragma pointer_size save
# pragma pointer_size 32
- void * _malloc32 (__size_t);
+void * _malloc32 (__size_t);
# pragma pointer_size restore
# endif /* __INITIAL_POINTER_SIZE == 64 */
# endif /* __INITIAL_POINTER_SIZE && defined _ANSI_C_SOURCE */
static void xsyslog(BIO* bp, int priority, const char* string);
static void xcloselog(BIO* bp);
-static BIO_METHOD methods_slg=
- {
- BIO_TYPE_MEM,"syslog",
+static BIO_METHOD methods_slg = {
+ BIO_TYPE_MEM, "syslog",
slg_write,
NULL,
slg_puts,
slg_new,
slg_free,
NULL,
- };
+};
-BIO_METHOD *BIO_s_log(void)
- {
- return(&methods_slg);
- }
+BIO_METHOD
+*BIO_s_log(void)
+{
+ return (&methods_slg);
+}
-static int slg_new(BIO *bi)
- {
- bi->init=1;
- bi->num=0;
- bi->ptr=NULL;
+static int
+slg_new(BIO *bi)
+{
+ bi->init = 1;
+ bi->num = 0;
+ bi->ptr = NULL;
xopenlog(bi, "application", LOG_DAEMON);
- return(1);
- }
+ return (1);
+}
-static int slg_free(BIO *a)
- {
- if (a == NULL) return(0);
+static int
+slg_free(BIO *a)
+{
+ if (a == NULL)
+ return (0);
xcloselog(a);
- return(1);
- }
-
-static int slg_write(BIO *b, const char *in, int inl)
- {
- int ret= inl;
+ return (1);
+}
+
+static int
+slg_write(BIO *b, const char *in, int inl)
+{
+ int ret = inl;
char* buf;
char* pp;
int priority, i;
- static const struct
- {
+ static const struct {
int strl;
char str[10];
int log_level;
- }
- mapping[] =
- {
+ }
+ mapping[] = {
{ 6, "PANIC ", LOG_EMERG },
{ 6, "EMERG ", LOG_EMERG },
{ 4, "EMR ", LOG_EMERG },
{ 6, "DEBUG ", LOG_DEBUG },
{ 4, "DBG ", LOG_DEBUG },
{ 0, "", LOG_ERR } /* The default */
- };
+ };
- if((buf= (char *)OPENSSL_malloc(inl+ 1)) == NULL){
- return(0);
+ if ((buf = (char *)OPENSSL_malloc(inl + 1)) == NULL) {
+ return (0);
}
strncpy(buf, in, inl);
- buf[inl]= '\0';
+ buf[inl] = '\0';
i = 0;
- while(strncmp(buf, mapping[i].str, mapping[i].strl) != 0) i++;
+ while (strncmp(buf, mapping[i].str, mapping[i].strl) != 0)
+ i++;
priority = mapping[i].log_level;
pp = buf + mapping[i].strl;
xsyslog(b, priority, pp);
OPENSSL_free(buf);
- return(ret);
- }
+ return (ret);
+}
-static long slg_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
- switch (cmd)
- {
+static long
+slg_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+ switch (cmd) {
case BIO_CTRL_SET:
xcloselog(b);
xopenlog(b, ptr, num);
break;
default:
break;
- }
- return(0);
}
+ return (0);
+}
-static int slg_puts(BIO *bp, const char *str)
- {
- int n,ret;
+static int
+slg_puts(BIO *bp, const char *str)
+{
+ int n, ret;
- n=strlen(str);
- ret=slg_write(bp,str,n);
- return(ret);
- }
+ n = strlen(str);
+ ret = slg_write(bp, str, n);
+ return (ret);
+}
#if defined(OPENSSL_SYS_WIN32)
-static void xopenlog(BIO* bp, char* name, int level)
+static void
+xopenlog(BIO* bp, char* name, int level)
{
if (check_winnt())
- bp->ptr = RegisterEventSourceA(NULL,name);
+ bp->ptr = RegisterEventSourceA(NULL, name);
else
bp->ptr = NULL;
}
-static void xsyslog(BIO *bp, int priority, const char *string)
+static void
+xsyslog(BIO *bp, int priority, const char *string)
{
LPCSTR lpszStrings[2];
- WORD evtype= EVENTLOG_ERROR_TYPE;
- char pidbuf[DECIMAL_SIZE(DWORD)+4];
+ WORD evtype = EVENTLOG_ERROR_TYPE;
+ char pidbuf[DECIMAL_SIZE(DWORD) + 4];
if (bp->ptr == NULL)
return;
- switch (priority)
- {
+ switch (priority) {
case LOG_EMERG:
case LOG_ALERT:
case LOG_CRIT:
as error anyway. */
evtype = EVENTLOG_ERROR_TYPE;
break;
- }
+ }
sprintf(pidbuf, "[%u] ", GetCurrentProcessId());
lpszStrings[0] = pidbuf;
lpszStrings[1] = string;
ReportEventA(bp->ptr, evtype, 0, 1024, NULL, 2, 0,
- lpszStrings, NULL);
+ lpszStrings, NULL);
}
-
-static void xcloselog(BIO* bp)
+
+static void
+xcloselog(BIO* bp)
{
- if(bp->ptr)
+ if (bp->ptr)
DeregisterEventSource((HANDLE)(bp->ptr));
- bp->ptr= NULL;
+ bp->ptr = NULL;
}
#elif defined(OPENSSL_SYS_VMS)
static int VMS_OPC_target = LOG_DAEMON;
-static void xopenlog(BIO* bp, char* name, int level)
+static void
+xopenlog(BIO* bp, char* name, int level)
{
- VMS_OPC_target = level;
+ VMS_OPC_target = level;
+
}
-static void xsyslog(BIO *bp, int priority, const char *string)
+static void
+xsyslog(BIO *bp, int priority, const char *string)
{
struct dsc$descriptor_s opc_dsc;
char buf[10240];
unsigned int len;
- struct dsc$descriptor_s buf_dsc;
+ struct dsc$descriptor_s buf_dsc;
$DESCRIPTOR(fao_cmd, "!AZ: !AZ");
char *priority_tag;
- switch (priority)
- {
- case LOG_EMERG: priority_tag = "Emergency"; break;
- case LOG_ALERT: priority_tag = "Alert"; break;
- case LOG_CRIT: priority_tag = "Critical"; break;
- case LOG_ERR: priority_tag = "Error"; break;
- case LOG_WARNING: priority_tag = "Warning"; break;
- case LOG_NOTICE: priority_tag = "Notice"; break;
- case LOG_INFO: priority_tag = "Info"; break;
- case LOG_DEBUG: priority_tag = "DEBUG"; break;
- }
+ switch (priority) {
+ case LOG_EMERG:
+ priority_tag = "Emergency"; break;
+ case LOG_ALERT:
+ priority_tag = "Alert"; break;
+ case LOG_CRIT:
+ priority_tag = "Critical"; break;
+ case LOG_ERR:
+ priority_tag = "Error"; break;
+ case LOG_WARNING:
+ priority_tag = "Warning"; break;
+ case LOG_NOTICE:
+ priority_tag = "Notice"; break;
+ case LOG_INFO:
+ priority_tag = "Info"; break;
+ case LOG_DEBUG:
+ priority_tag = "DEBUG"; break;
+ }
buf_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
buf_dsc.dsc$b_class = DSC$K_CLASS_S;
lib$sys_fao(&fao_cmd, &len, &buf_dsc, priority_tag, string);
/* We know there's an 8-byte header. That's documented. */
- opcdef_p = OPCDEF_MALLOC( 8+ len);
+ opcdef_p = OPCDEF_MALLOC( 8 + len);
opcdef_p->opc$b_ms_type = OPC$_RQ_RQST;
memcpy(opcdef_p->opc$z_ms_target_classes, &VMS_OPC_target, 3);
opcdef_p->opc$l_ms_rqstid = 0;
OPENSSL_free(opcdef_p);
}
-static void xcloselog(BIO* bp)
+static void
+xcloselog(BIO* bp)
{
}
#else /* Unix/Watt32 */
-static void xopenlog(BIO* bp, char* name, int level)
+static void
+xopenlog(BIO* bp, char* name, int level)
{
#ifdef WATT32 /* djgpp/DOS */
openlog(name, LOG_PID|LOG_CONS|LOG_NDELAY, level);
#endif
}
-static void xsyslog(BIO *bp, int priority, const char *string)
+static void
+xsyslog(BIO *bp, int priority, const char *string)
{
syslog(priority, "%s", string);
}
-static void xcloselog(BIO* bp)
+static void
+xcloselog(BIO* bp)
{
closelog();
}
static long mem_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int mem_new(BIO *h);
static int mem_free(BIO *data);
-static BIO_METHOD mem_method=
- {
+
+static BIO_METHOD mem_method = {
BIO_TYPE_MEM,
"memory buffer",
mem_write,
mem_new,
mem_free,
NULL,
- };
+};
/* bio->num is used to hold the value to return on 'empty', if it is
* 0, should_retry is not set */
-BIO_METHOD *BIO_s_mem(void)
- {
- return(&mem_method);
- }
+BIO_METHOD
+*BIO_s_mem(void)
+{
+ return (&mem_method);
+}
-BIO *BIO_new_mem_buf(void *buf, int len)
+BIO
+*BIO_new_mem_buf(void *buf, int len)
{
BIO *ret;
BUF_MEM *b;
size_t sz;
if (!buf) {
- BIOerr(BIO_F_BIO_NEW_MEM_BUF,BIO_R_NULL_PARAMETER);
+ BIOerr(BIO_F_BIO_NEW_MEM_BUF, BIO_R_NULL_PARAMETER);
return NULL;
}
- sz = (len<0) ? strlen(buf) : (size_t)len;
- if(!(ret = BIO_new(BIO_s_mem())) ) return NULL;
+ sz = (len < 0) ? strlen(buf) : (size_t)len;
+ if (!(ret = BIO_new(BIO_s_mem())))
+ return NULL;
b = (BUF_MEM *)ret->ptr;
b->data = buf;
b->length = sz;
return ret;
}
-static int mem_new(BIO *bi)
- {
+static int
+mem_new(BIO *bi)
+{
BUF_MEM *b;
- if ((b=BUF_MEM_new()) == NULL)
- return(0);
- bi->shutdown=1;
- bi->init=1;
- bi->num= -1;
- bi->ptr=(char *)b;
- return(1);
- }
+ if ((b = BUF_MEM_new()) == NULL)
+ return (0);
+ bi->shutdown = 1;
+ bi->init = 1;
+ bi->num = -1;
+ bi->ptr = (char *)b;
+ return (1);
+}
-static int mem_free(BIO *a)
- {
- if (a == NULL) return(0);
- if (a->shutdown)
- {
- if ((a->init) && (a->ptr != NULL))
- {
+static int
+mem_free(BIO *a)
+{
+ if (a == NULL)
+ return (0);
+ if (a->shutdown) {
+ if ((a->init) && (a->ptr != NULL)) {
BUF_MEM *b;
b = (BUF_MEM *)a->ptr;
- if(a->flags & BIO_FLAGS_MEM_RDONLY) b->data = NULL;
- BUF_MEM_free(b);
- a->ptr=NULL;
- }
+ if (a->flags & BIO_FLAGS_MEM_RDONLY)
+ b->data = NULL;
+ BUF_MEM_free(b);
+ a->ptr = NULL;
}
- return(1);
}
-
-static int mem_read(BIO *b, char *out, int outl)
- {
- int ret= -1;
+ return (1);
+}
+
+static int
+mem_read(BIO *b, char *out, int outl)
+{
+ int ret = -1;
BUF_MEM *bm;
- bm=(BUF_MEM *)b->ptr;
+ bm = (BUF_MEM *)b->ptr;
BIO_clear_retry_flags(b);
- ret=(outl >=0 && (size_t)outl > bm->length)?(int)bm->length:outl;
+ ret = (outl >=0 && (size_t)outl > bm->length) ? (int)bm->length : outl;
if ((out != NULL) && (ret > 0)) {
- memcpy(out,bm->data,ret);
- bm->length-=ret;
- if(b->flags & BIO_FLAGS_MEM_RDONLY) bm->data += ret;
+ memcpy(out, bm->data, ret);
+ bm->length -= ret;
+ if (b->flags & BIO_FLAGS_MEM_RDONLY)
+ bm->data += ret;
else {
- memmove(&(bm->data[0]),&(bm->data[ret]),bm->length);
+ memmove(&(bm->data[0]), &(bm->data[ret]), bm->length);
}
- } else if (bm->length == 0)
- {
+ } else if (bm->length == 0) {
ret = b->num;
if (ret != 0)
BIO_set_retry_read(b);
- }
- return(ret);
}
+ return (ret);
+}
-static int mem_write(BIO *b, const char *in, int inl)
- {
- int ret= -1;
+static int
+mem_write(BIO *b, const char *in, int inl)
+{
+ int ret = -1;
int blen;
BUF_MEM *bm;
- bm=(BUF_MEM *)b->ptr;
- if (in == NULL)
- {
- BIOerr(BIO_F_MEM_WRITE,BIO_R_NULL_PARAMETER);
+ bm = (BUF_MEM *)b->ptr;
+ if (in == NULL) {
+ BIOerr(BIO_F_MEM_WRITE, BIO_R_NULL_PARAMETER);
goto end;
- }
+ }
- if(b->flags & BIO_FLAGS_MEM_RDONLY) {
- BIOerr(BIO_F_MEM_WRITE,BIO_R_WRITE_TO_READ_ONLY_BIO);
+ if (b->flags & BIO_FLAGS_MEM_RDONLY) {
+ BIOerr(BIO_F_MEM_WRITE, BIO_R_WRITE_TO_READ_ONLY_BIO);
goto end;
}
BIO_clear_retry_flags(b);
- blen=bm->length;
- if (BUF_MEM_grow_clean(bm,blen+inl) != (blen+inl))
+ blen = bm->length;
+ if (BUF_MEM_grow_clean(bm, blen + inl) != (blen + inl))
goto end;
- memcpy(&(bm->data[blen]),in,inl);
- ret=inl;
+ memcpy(&(bm->data[blen]), in, inl);
+ ret = inl;
end:
- return(ret);
- }
+ return (ret);
+}
-static long mem_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
- long ret=1;
+static long
+mem_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+ long ret = 1;
char **pptr;
- BUF_MEM *bm=(BUF_MEM *)b->ptr;
+ BUF_MEM *bm = (BUF_MEM *)b->ptr;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_RESET:
- if (bm->data != NULL)
- {
+ if (bm->data != NULL) {
/* For read only case reset to the start again */
- if(b->flags & BIO_FLAGS_MEM_RDONLY)
- {
+ if (b->flags & BIO_FLAGS_MEM_RDONLY) {
bm->data -= bm->max - bm->length;
bm->length = bm->max;
- }
- else
- {
- memset(bm->data,0,bm->max);
- bm->length=0;
- }
+ } else {
+ memset(bm->data, 0, bm->max);
+ bm->length = 0;
}
+ }
break;
case BIO_CTRL_EOF:
- ret=(long)(bm->length == 0);
+ ret = (long)(bm->length == 0);
break;
case BIO_C_SET_BUF_MEM_EOF_RETURN:
- b->num=(int)num;
+ b->num = (int)num;
break;
case BIO_CTRL_INFO:
- ret=(long)bm->length;
- if (ptr != NULL)
- {
- pptr=(char **)ptr;
- *pptr=(char *)&(bm->data[0]);
- }
+ ret = (long)bm->length;
+ if (ptr != NULL) {
+ pptr = (char **)ptr;
+ *pptr = (char *)&(bm->data[0]);
+ }
break;
case BIO_C_SET_BUF_MEM:
mem_free(b);
- b->shutdown=(int)num;
- b->ptr=ptr;
+ b->shutdown = (int)num;
+ b->ptr = ptr;
break;
case BIO_C_GET_BUF_MEM_PTR:
- if (ptr != NULL)
- {
- pptr=(char **)ptr;
- *pptr=(char *)bm;
- }
+ if (ptr != NULL) {
+ pptr = (char **)ptr;
+ *pptr = (char *)bm;
+ }
break;
case BIO_CTRL_GET_CLOSE:
- ret=(long)b->shutdown;
+ ret = (long)b->shutdown;
break;
case BIO_CTRL_SET_CLOSE:
- b->shutdown=(int)num;
+ b->shutdown = (int)num;
break;
case BIO_CTRL_WPENDING:
- ret=0L;
+ ret = 0L;
break;
case BIO_CTRL_PENDING:
- ret=(long)bm->length;
+ ret = (long)bm->length;
break;
case BIO_CTRL_DUP:
case BIO_CTRL_FLUSH:
- ret=1;
+ ret = 1;
break;
case BIO_CTRL_PUSH:
case BIO_CTRL_POP:
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
}
+ return (ret);
+}
-static int mem_gets(BIO *bp, char *buf, int size)
- {
- int i,j;
- int ret= -1;
+static int
+mem_gets(BIO *bp, char *buf, int size)
+{
+ int i, j;
+ int ret = -1;
char *p;
- BUF_MEM *bm=(BUF_MEM *)bp->ptr;
+ BUF_MEM *bm = (BUF_MEM *)bp->ptr;
BIO_clear_retry_flags(bp);
- j=bm->length;
- if ((size-1) < j) j=size-1;
- if (j <= 0)
- {
- *buf='\0';
+ j = bm->length;
+ if ((size - 1) < j)
+ j = size - 1;
+ if (j <= 0) {
+ *buf = '\0';
return 0;
- }
- p=bm->data;
- for (i=0; i<j; i++)
- {
- if (p[i] == '\n')
- {
+ }
+ p = bm->data;
+ for (i = 0; i < j; i++) {
+ if (p[i] == '\n') {
i++;
break;
- }
}
+ }
/*
* i is now the max num of bytes to copy, either j or up to
* and including the first newline
*/
- i=mem_read(bp,buf,i);
- if (i > 0) buf[i]='\0';
- ret=i;
- return(ret);
- }
+ i = mem_read(bp, buf, i);
+ if (i > 0)
+ buf[i] = '\0';
+ ret = i;
+ return (ret);
+}
-static int mem_puts(BIO *bp, const char *str)
- {
- int n,ret;
+static int
+mem_puts(BIO *bp, const char *str)
+{
+ int n, ret;
- n=strlen(str);
- ret=mem_write(bp,str,n);
+ n = strlen(str);
+ ret = mem_write(bp, str, n);
/* memory semantics is that it will always work */
- return(ret);
- }
-
+ return (ret);
+}
static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int null_new(BIO *h);
static int null_free(BIO *data);
-static BIO_METHOD null_method=
- {
+
+static BIO_METHOD null_method = {
BIO_TYPE_NULL,
"NULL",
null_write,
null_new,
null_free,
NULL,
- };
+};
-BIO_METHOD *BIO_s_null(void)
- {
- return(&null_method);
- }
+BIO_METHOD
+*BIO_s_null(void)
+{
+ return (&null_method);
+}
-static int null_new(BIO *bi)
- {
- bi->init=1;
- bi->num=0;
- bi->ptr=(NULL);
- return(1);
- }
+static int
+null_new(BIO *bi)
+{
+ bi->init = 1;
+ bi->num = 0;
+ bi->ptr = (NULL);
+ return (1);
+}
-static int null_free(BIO *a)
- {
- if (a == NULL) return(0);
- return(1);
- }
-
-static int null_read(BIO *b, char *out, int outl)
- {
- return(0);
- }
+static int
+null_free(BIO *a)
+{
+ if (a == NULL)
+ return (0);
+ return (1);
+}
-static int null_write(BIO *b, const char *in, int inl)
- {
- return(inl);
- }
+static int
+null_read(BIO *b, char *out, int outl)
+{
+ return (0);
+}
+
+static int
+null_write(BIO *b, const char *in, int inl)
+{
+ return (inl);
+}
-static long null_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
- long ret=1;
+static long
+null_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+ long ret = 1;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_RESET:
case BIO_CTRL_EOF:
case BIO_CTRL_SET:
case BIO_CTRL_SET_CLOSE:
case BIO_CTRL_FLUSH:
case BIO_CTRL_DUP:
- ret=1;
+ ret = 1;
break;
case BIO_CTRL_GET_CLOSE:
case BIO_CTRL_INFO:
case BIO_CTRL_PENDING:
case BIO_CTRL_WPENDING:
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
}
+ return (ret);
+}
-static int null_gets(BIO *bp, char *buf, int size)
- {
- return(0);
- }
-
-static int null_puts(BIO *bp, const char *str)
- {
- if (str == NULL) return(0);
- return(strlen(str));
- }
+static int
+null_gets(BIO *bp, char *buf, int size)
+{
+ return (0);
+}
+static int
+null_puts(BIO *bp, const char *str)
+{
+ if (str == NULL)
+ return (0);
+ return (strlen(str));
+}
typedef unsigned short io_channel;
/*************************************************************************/
-struct io_status { short status, count; long flags; };
+ struct io_status { short status, count;
+ long flags;
+};
-struct rpc_msg { /* Should have member alignment inhibited */
- char channel; /* 'A'-app data. 'R'-remote client 'G'-global */
- char function; /* 'G'-get, 'P'-put, 'C'-confirm, 'X'-close */
- unsigned short int length; /* Amount of data returned or max to return */
- char data[4092]; /* variable data */
+ struct rpc_msg { /* Should have member alignment inhibited */
+ char channel; /* 'A'-app data. 'R'-remote client 'G'-global */
+ char function; /* 'G'-get, 'P'-put, 'C'-confirm, 'X'-close */
+ unsigned short int length; /* Amount of data returned or max to return */
+ char data[4092]; /* variable data */
};
#define RPC_HDR_SIZE (sizeof(struct rpc_msg) - 4092)
struct rpc_ctx {
- int filled, pos;
- struct rpc_msg msg;
+ int filled, pos;
+ struct rpc_msg msg;
};
-static int rtcp_write(BIO *h,const char *buf,int num);
-static int rtcp_read(BIO *h,char *buf,int size);
-static int rtcp_puts(BIO *h,const char *str);
-static int rtcp_gets(BIO *h,char *str,int size);
-static long rtcp_ctrl(BIO *h,int cmd,long arg1,void *arg2);
+static int rtcp_write(BIO *h, const char *buf, int num);
+static int rtcp_read(BIO *h, char *buf, int size);
+static int rtcp_puts(BIO *h, const char *str);
+static int rtcp_gets(BIO *h, char *str, int size);
+static long rtcp_ctrl(BIO *h, int cmd, long arg1, void *arg2);
static int rtcp_new(BIO *h);
static int rtcp_free(BIO *data);
-static BIO_METHOD rtcp_method=
- {
+static BIO_METHOD rtcp_method = {
BIO_TYPE_FD,
"RTCP",
rtcp_write,
rtcp_new,
rtcp_free,
NULL,
- };
+};
-BIO_METHOD *BIO_s_rtcp(void)
- {
- return(&rtcp_method);
- }
+BIO_METHOD
+*BIO_s_rtcp(void)
+{
+ return (&rtcp_method);
+}
/*****************************************************************************/
/* Decnet I/O routines.
*/
#pragma message disable DOLLARID
#endif
-static int get ( io_channel chan, char *buffer, int maxlen, int *length )
+static int get(io_channel chan, char *buffer, int maxlen, int *length)
{
- int status;
- struct io_status iosb;
- status = sys$qiow ( 0, chan, IO$_READVBLK, &iosb, 0, 0,
- buffer, maxlen, 0, 0, 0, 0 );
- if ( (status&1) == 1 ) status = iosb.status;
- if ( (status&1) == 1 ) *length = iosb.count;
- return status;
+ int status;
+ struct io_status iosb;
+ status = sys$qiow(0, chan, IO$_READVBLK, &iosb, 0, 0, buffer, maxlen,
+ 0, 0, 0, 0 );
+ if ((status & 1) == 1)
+ status = iosb.status;
+ if ((status & 1) == 1 )
+ *length = iosb.count;
+ return status;
}
-static int put ( io_channel chan, char *buffer, int length )
+static int put(io_channel chan, char *buffer, int length)
{
- int status;
- struct io_status iosb;
- status = sys$qiow ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0,
- buffer, length, 0, 0, 0, 0 );
- if ( (status&1) == 1 ) status = iosb.status;
- return status;
+ int status;
+ struct io_status iosb;
+ status = sys$qiow ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0, buffer,
+ length, 0, 0, 0, 0 );
+ if ((status & 1) == 1)
+ status = iosb.status;
+ return status;
}
#ifdef __DECC
/***************************************************************************/
-static int rtcp_new(BIO *bi)
+static int
+rtcp_new(BIO *bi)
{
- struct rpc_ctx *ctx;
- bi->init=1;
- bi->num=0;
+ struct rpc_ctx *ctx;
+ bi->init = 1;
+ bi->num = 0;
bi->flags = 0;
- bi->ptr=OPENSSL_malloc(sizeof(struct rpc_ctx));
- ctx = (struct rpc_ctx *) bi->ptr;
+ bi->ptr = OPENSSL_malloc(sizeof(struct rpc_ctx));
+ ctx = (struct rpc_ctx *)bi->ptr;
ctx->filled = 0;
ctx->pos = 0;
- return(1);
+ return (1);
}
-static int rtcp_free(BIO *a)
+static int
+rtcp_free(BIO *a)
{
- if (a == NULL) return(0);
- if ( a->ptr ) OPENSSL_free ( a->ptr );
+ if (a == NULL)
+ return (0);
+ if (a->ptr)
+ OPENSSL_free(a->ptr);
a->ptr = NULL;
- return(1);
+ return (1);
}
-
-static int rtcp_read(BIO *b, char *out, int outl)
+
+static int
+rtcp_read(BIO *b, char *out, int outl)
{
- int status, length;
- struct rpc_ctx *ctx;
- /*
- * read data, return existing.
- */
- ctx = (struct rpc_ctx *) b->ptr;
- if ( ctx->pos < ctx->filled ) {
- length = ctx->filled - ctx->pos;
- if ( length > outl ) length = outl;
- memmove ( out, &ctx->msg.data[ctx->pos], length );
- ctx->pos += length;
- return length;
- }
- /*
- * Requst more data from R channel.
- */
- ctx->msg.channel = 'R';
- ctx->msg.function = 'G';
- ctx->msg.length = sizeof(ctx->msg.data);
- status = put ( b->num, (char *) &ctx->msg, RPC_HDR_SIZE );
- if ( (status&1) == 0 ) {
- return -1;
- }
- /*
- * Read.
- */
- ctx->pos = ctx->filled = 0;
- status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length );
- if ( (status&1) == 0 ) length = -1;
- if ( ctx->msg.channel != 'R' || ctx->msg.function != 'C' ) {
- length = -1;
- }
- ctx->filled = length - RPC_HDR_SIZE;
-
- if ( ctx->pos < ctx->filled ) {
- length = ctx->filled - ctx->pos;
- if ( length > outl ) length = outl;
- memmove ( out, ctx->msg.data, length );
- ctx->pos += length;
- return length;
- }
+ int status, length;
+ struct rpc_ctx *ctx;
+ /*
+ * read data, return existing.
+ */
+ ctx = (struct rpc_ctx *)b->ptr;
+ if (ctx->pos < ctx->filled) {
+ length = ctx->filled - ctx->pos;
+ if (length > outl)
+ length = outl;
+ memmove(out, &ctx->msg.data[ctx->pos], length);
+ ctx->pos += length;
+ return length;
+ }
+ /*
+ * Requst more data from R channel.
+ */
+ ctx->msg.channel = 'R';
+ ctx->msg.function = 'G';
+ ctx->msg.length = sizeof(ctx->msg.data);
+ status = put(b->num, (char *)&ctx->msg, RPC_HDR_SIZE);
+ if ((status & 1) == 0 ) {
+ return -1;
+ }
+ /*
+ * Read.
+ */
+ ctx->pos = ctx->filled = 0;
+ status = get(b->num, (char *)&ctx->msg, sizeof(ctx->msg), &length);
+ if ((status & 1) == 0)
+ length = -1;
+ if (ctx->msg.channel != 'R' || ctx->msg.function != 'C') {
+ length = -1;
+ }
+ ctx->filled = length - RPC_HDR_SIZE;
+
+ if (ctx->pos < ctx->filled) {
+ length = ctx->filled - ctx->pos;
+ if (length > outl)
+ length = outl;
+ memmove(out, ctx->msg.data, length);
+ ctx->pos += length;
+ return length;
+ }
- return length;
+ return length;
}
-static int rtcp_write(BIO *b, const char *in, int inl)
+static int
+rtcp_write(BIO *b, const char *in, int inl)
{
- int status, i, segment, length;
- struct rpc_ctx *ctx;
- /*
- * Output data, send in chunks no larger that sizeof(ctx->msg.data).
- */
- ctx = (struct rpc_ctx *) b->ptr;
- for ( i = 0; i < inl; i += segment ) {
- segment = inl - i;
- if ( segment > sizeof(ctx->msg.data) ) segment = sizeof(ctx->msg.data);
- ctx->msg.channel = 'R';
- ctx->msg.function = 'P';
- ctx->msg.length = segment;
- memmove ( ctx->msg.data, &in[i], segment );
- status = put ( b->num, (char *) &ctx->msg, segment + RPC_HDR_SIZE );
- if ((status&1) == 0 ) { i = -1; break; }
+ int status, i, segment, length;
+ struct rpc_ctx *ctx;
+ /*
+ * Output data, send in chunks no larger that sizeof(ctx->msg.data).
+ */
+ ctx = (struct rpc_ctx *)b->ptr;
+ for (i = 0; i < inl; i += segment) {
+ segment = inl - i;
+ if (segment > sizeof(ctx->msg.data))
+ segment = sizeof(ctx->msg.data);
+ ctx->msg.channel = 'R';
+ ctx->msg.function = 'P';
+ ctx->msg.length = segment;
+ memmove(ctx->msg.data, &in[i], segment);
+ status = put(b->num, (char *) &ctx->msg,
+ segment + RPC_HDR_SIZE);
+ if ((status & 1) == 0) {
+ i = -1;
+ break;
+ }
- status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length );
- if ( ((status&1) == 0) || (length < RPC_HDR_SIZE) ) { i = -1; break; }
- if ( (ctx->msg.channel != 'R') || (ctx->msg.function != 'C') ) {
- printf("unexpected response when confirming put %c %c\n",
- ctx->msg.channel, ctx->msg.function );
+ status = get(b->num, (char *)&ctx->msg, sizeof(ctx->msg),
+ &length );
+ if (((status&1) == 0) || (length < RPC_HDR_SIZE)) {
+ i = -1;
+ break;
+ }
+ if ((ctx->msg.channel != 'R') || (ctx->msg.function != 'C')) {
+ printf("unexpected response when confirming put %c %c\n",
+ ctx->msg.channel, ctx->msg.function );
+ }
}
- }
- return(i);
+ return (i);
}
-static long rtcp_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
- long ret=1;
+static long
+rtcp_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+ long ret = 1;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_CTRL_RESET:
case BIO_CTRL_EOF:
ret = 1;
case BIO_C_SET_FD:
b->num = num;
ret = 1;
- break;
+ break;
case BIO_CTRL_SET_CLOSE:
case BIO_CTRL_FLUSH:
case BIO_CTRL_DUP:
- ret=1;
+ ret = 1;
break;
case BIO_CTRL_GET_CLOSE:
case BIO_CTRL_INFO:
case BIO_CTRL_PENDING:
case BIO_CTRL_WPENDING:
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
- }
-
-static int rtcp_gets(BIO *bp, char *buf, int size)
- {
- return(0);
}
+ return (ret);
+}
-static int rtcp_puts(BIO *bp, const char *str)
+static int
+rtcp_gets(BIO *bp, char *buf, int size)
{
- int length;
- if (str == NULL) return(0);
- length = strlen ( str );
- if ( length == 0 ) return (0);
- return rtcp_write ( bp,str, length );
+ return (0);
}
+static int
+rtcp_puts(BIO *bp, const char *str)
+{
+ int length;
+ if (str == NULL)
+ return (0);
+ length = strlen(str);
+ if (length == 0)
+ return (0);
+ return rtcp_write(bp, str, length);
+}
static int sock_free(BIO *data);
int BIO_sock_should_retry(int s);
-static BIO_METHOD methods_sockp=
- {
+static BIO_METHOD methods_sockp = {
BIO_TYPE_SOCKET,
"socket",
sock_write,
sock_new,
sock_free,
NULL,
- };
+};
-BIO_METHOD *BIO_s_socket(void)
- {
- return(&methods_sockp);
- }
+BIO_METHOD
+*BIO_s_socket(void)
+{
+ return (&methods_sockp);
+}
-BIO *BIO_new_socket(int fd, int close_flag)
- {
+BIO
+*BIO_new_socket(int fd, int close_flag)
+{
BIO *ret;
- ret=BIO_new(BIO_s_socket());
- if (ret == NULL) return(NULL);
- BIO_set_fd(ret,fd,close_flag);
- return(ret);
- }
+ ret = BIO_new(BIO_s_socket());
+ if (ret == NULL)
+ return (NULL);
+ BIO_set_fd(ret, fd, close_flag);
+ return (ret);
+}
-static int sock_new(BIO *bi)
- {
- bi->init=0;
- bi->num=0;
- bi->ptr=NULL;
- bi->flags=0;
- return(1);
- }
+static int
+sock_new(BIO *bi)
+{
+ bi->init = 0;
+ bi->num = 0;
+ bi->ptr = NULL;
+ bi->flags = 0;
+ return (1);
+}
-static int sock_free(BIO *a)
- {
- if (a == NULL) return(0);
- if (a->shutdown)
- {
- if (a->init)
- {
+static int
+sock_free(BIO *a)
+{
+ if (a == NULL)
+ return (0);
+ if (a->shutdown) {
+ if (a->init) {
shutdown(a->num, SHUT_RDWR);
close(a->num);
- }
- a->init=0;
- a->flags=0;
}
- return(1);
+ a->init = 0;
+ a->flags = 0;
}
-
-static int sock_read(BIO *b, char *out, int outl)
- {
- int ret=0;
+ return (1);
+}
- if (out != NULL)
- {
+static int
+sock_read(BIO *b, char *out, int outl)
+{
+ int ret = 0;
+
+ if (out != NULL) {
errno = 0;
- ret=read(b->num,out,outl);
+ ret = read(b->num, out, outl);
BIO_clear_retry_flags(b);
- if (ret <= 0)
- {
+ if (ret <= 0) {
if (BIO_sock_should_retry(ret))
BIO_set_retry_read(b);
- }
}
- return(ret);
}
+ return (ret);
+}
-static int sock_write(BIO *b, const char *in, int inl)
- {
+static int
+sock_write(BIO *b, const char *in, int inl)
+{
int ret;
-
+
errno = 0;
- ret=write(b->num,in,inl);
+ ret = write(b->num, in, inl);
BIO_clear_retry_flags(b);
- if (ret <= 0)
- {
+ if (ret <= 0) {
if (BIO_sock_should_retry(ret))
BIO_set_retry_write(b);
- }
- return(ret);
}
+ return (ret);
+}
-static long sock_ctrl(BIO *b, int cmd, long num, void *ptr)
- {
- long ret=1;
+static long
+sock_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+ long ret = 1;
int *ip;
- switch (cmd)
- {
+ switch (cmd) {
case BIO_C_SET_FD:
sock_free(b);
b->num= *((int *)ptr);
- b->shutdown=(int)num;
- b->init=1;
+ b->shutdown = (int)num;
+ b->init = 1;
break;
case BIO_C_GET_FD:
- if (b->init)
- {
- ip=(int *)ptr;
- if (ip != NULL) *ip=b->num;
- ret=b->num;
- }
- else
- ret= -1;
+ if (b->init) {
+ ip = (int *)ptr;
+ if (ip != NULL)
+ *ip = b->num;
+ ret = b->num;
+ } else
+ ret = -1;
break;
case BIO_CTRL_GET_CLOSE:
- ret=b->shutdown;
+ ret = b->shutdown;
break;
case BIO_CTRL_SET_CLOSE:
- b->shutdown=(int)num;
+ b->shutdown = (int)num;
break;
case BIO_CTRL_DUP:
case BIO_CTRL_FLUSH:
- ret=1;
+ ret = 1;
break;
default:
- ret=0;
+ ret = 0;
break;
- }
- return(ret);
}
+ return (ret);
+}
-static int sock_puts(BIO *bp, const char *str)
- {
- int n,ret;
+static int
+sock_puts(BIO *bp, const char *str)
+{
+ int n, ret;
- n=strlen(str);
- ret=sock_write(bp,str,n);
- return(ret);
- }
+ n = strlen(str);
+ ret = sock_write(bp, str, n);
+ return (ret);
+}
-int BIO_sock_should_retry(int i)
- {
+int
+BIO_sock_should_retry(int i)
+{
int err;
- if ((i == 0) || (i == -1))
- {
- err=errno;
+ if ((i == 0) || (i == -1)) {
+ err = errno;
#if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
if ((i == -1) && (err == 0))
- return(1);
+ return (1);
#endif
- return(BIO_sock_non_fatal_error(err));
- }
- return(0);
+ return (BIO_sock_non_fatal_error(err));
}
+ return (0);
+}
-int BIO_sock_non_fatal_error(int err)
- {
- switch (err)
- {
+int
+BIO_sock_non_fatal_error(int err)
+{
+ switch (err) {
#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_NETWARE)
# if defined(WSAEWOULDBLOCK)
case WSAEWOULDBLOCK:
#ifdef EALREADY
case EALREADY:
#endif
- return(1);
+ return (1);
/* break; */
default:
break;
- }
- return(0);
}
+ return (0);
+}
#endif /* #ifndef OPENSSL_NO_SOCK */