sl@0: /* crypto/bio/bss_conn.c */ sl@0: /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) sl@0: * All rights reserved. sl@0: * sl@0: * This package is an SSL implementation written sl@0: * by Eric Young (eay@cryptsoft.com). sl@0: * The implementation was written so as to conform with Netscapes SSL. sl@0: * sl@0: * This library is free for commercial and non-commercial use as long as sl@0: * the following conditions are aheared to. The following conditions sl@0: * apply to all code found in this distribution, be it the RC4, RSA, sl@0: * lhash, DES, etc., code; not just the SSL code. The SSL documentation sl@0: * included with this distribution is covered by the same copyright terms sl@0: * except that the holder is Tim Hudson (tjh@cryptsoft.com). sl@0: * sl@0: * Copyright remains Eric Young's, and as such any Copyright notices in sl@0: * the code are not to be removed. sl@0: * If this package is used in a product, Eric Young should be given attribution sl@0: * as the author of the parts of the library used. sl@0: * This can be in the form of a textual message at program startup or sl@0: * in documentation (online or textual) provided with the package. sl@0: * sl@0: * Redistribution and use in source and binary forms, with or without sl@0: * modification, are permitted provided that the following conditions sl@0: * are met: sl@0: * 1. Redistributions of source code must retain the copyright sl@0: * notice, this list of conditions and the following disclaimer. sl@0: * 2. Redistributions in binary form must reproduce the above copyright sl@0: * notice, this list of conditions and the following disclaimer in the sl@0: * documentation and/or other materials provided with the distribution. sl@0: * 3. All advertising materials mentioning features or use of this software sl@0: * must display the following acknowledgement: sl@0: * "This product includes cryptographic software written by sl@0: * Eric Young (eay@cryptsoft.com)" sl@0: * The word 'cryptographic' can be left out if the rouines from the library sl@0: * being used are not cryptographic related :-). sl@0: * 4. If you include any Windows specific code (or a derivative thereof) from sl@0: * the apps directory (application code) you must include an acknowledgement: sl@0: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" sl@0: * sl@0: * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND sl@0: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE sl@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE sl@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE sl@0: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL sl@0: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS sl@0: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) sl@0: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT sl@0: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY sl@0: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF sl@0: * SUCH DAMAGE. sl@0: * sl@0: * The licence and distribution terms for any publically available version or sl@0: * derivative of this code cannot be changed. i.e. this code cannot simply be sl@0: * copied and put under another distribution licence sl@0: * [including the GNU Public Licence.] sl@0: */ sl@0: /* sl@0: © Portions copyright (c) 2006 Nokia Corporation. All rights reserved. sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #define USE_SOCKETS sl@0: #include "cryptlib.h" sl@0: #include sl@0: #if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__))) sl@0: #include "libcrypto_wsd_macros.h" sl@0: #include "libcrypto_wsd.h" sl@0: #endif sl@0: sl@0: #ifndef OPENSSL_NO_SOCK sl@0: sl@0: #ifdef OPENSSL_SYS_WIN16 sl@0: #define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ sl@0: #else sl@0: #define SOCKET_PROTOCOL IPPROTO_TCP sl@0: #endif sl@0: sl@0: #if (defined(OPENSSL_SYS_VMS) && __VMS_VER < 70000000) sl@0: /* FIONBIO used as a switch to enable ioctl, and that isn't in VMS < 7.0 */ sl@0: #undef FIONBIO sl@0: #endif sl@0: sl@0: sl@0: typedef struct bio_connect_st sl@0: { sl@0: int state; sl@0: sl@0: char *param_hostname; sl@0: char *param_port; sl@0: int nbio; sl@0: sl@0: unsigned char ip[4]; sl@0: unsigned short port; sl@0: sl@0: struct sockaddr_in them; sl@0: sl@0: /* int socket; this will be kept in bio->num so that it is sl@0: * compatible with the bss_sock bio */ sl@0: sl@0: /* called when the connection is initially made sl@0: * callback(BIO,state,ret); The callback should return sl@0: * 'ret'. state is for compatibility with the ssl info_callback */ sl@0: int (*info_callback)(const BIO *bio,int state,int ret); sl@0: } BIO_CONNECT; sl@0: sl@0: static int conn_write(BIO *h, const char *buf, int num); sl@0: static int conn_read(BIO *h, char *buf, int size); sl@0: static int conn_puts(BIO *h, const char *str); sl@0: static long conn_ctrl(BIO *h, int cmd, long arg1, void *arg2); sl@0: static int conn_new(BIO *h); sl@0: static int conn_free(BIO *data); sl@0: static long conn_callback_ctrl(BIO *h, int cmd, bio_info_cb *); sl@0: sl@0: static int conn_state(BIO *b, BIO_CONNECT *c); sl@0: static void conn_close_socket(BIO *data); sl@0: BIO_CONNECT *BIO_CONNECT_new(void ); sl@0: void BIO_CONNECT_free(BIO_CONNECT *a); sl@0: sl@0: #ifndef EMULATOR sl@0: static BIO_METHOD methods_connectp= sl@0: { sl@0: BIO_TYPE_CONNECT, sl@0: "socket connect", sl@0: conn_write, sl@0: conn_read, sl@0: conn_puts, sl@0: NULL, /* connect_gets, */ sl@0: conn_ctrl, sl@0: conn_new, sl@0: conn_free, sl@0: conn_callback_ctrl, sl@0: }; sl@0: #else sl@0: sl@0: GET_STATIC_VAR_FROM_TLS(methods_connectp,bss_conn,BIO_METHOD) sl@0: #define methods_connectp (*GET_WSD_VAR_NAME(methods_connectp,bss_conn,s)()) sl@0: const BIO_METHOD temp_s_methods_connectp= sl@0: { sl@0: BIO_TYPE_CONNECT, sl@0: "socket connect", sl@0: conn_write, sl@0: conn_read, sl@0: conn_puts, sl@0: NULL, /* connect_gets, */ sl@0: conn_ctrl, sl@0: conn_new, sl@0: conn_free, sl@0: conn_callback_ctrl, sl@0: }; sl@0: #endif sl@0: sl@0: static int conn_state(BIO *b, BIO_CONNECT *c) sl@0: { sl@0: int ret= -1,i; sl@0: unsigned long l; sl@0: char *p,*q; sl@0: int (*cb)(const BIO *,int,int)=NULL; sl@0: sl@0: if (c->info_callback != NULL) sl@0: cb=c->info_callback; sl@0: sl@0: for (;;) sl@0: { sl@0: switch (c->state) sl@0: { sl@0: case BIO_CONN_S_BEFORE: sl@0: p=c->param_hostname; sl@0: if (p == NULL) sl@0: { sl@0: BIOerr(BIO_F_CONN_STATE,BIO_R_NO_HOSTNAME_SPECIFIED); sl@0: goto exit_loop; sl@0: } sl@0: for ( ; *p != '\0'; p++) sl@0: { sl@0: if ((*p == ':') || (*p == '/')) break; sl@0: } sl@0: sl@0: i= *p; sl@0: if ((i == ':') || (i == '/')) sl@0: { sl@0: sl@0: *(p++)='\0'; sl@0: if (i == ':') sl@0: { sl@0: for (q=p; *q; q++) sl@0: if (*q == '/') sl@0: { sl@0: *q='\0'; sl@0: break; sl@0: } sl@0: if (c->param_port != NULL) sl@0: OPENSSL_free(c->param_port); sl@0: c->param_port=BUF_strdup(p); sl@0: } sl@0: } sl@0: sl@0: if (c->param_port == NULL) sl@0: { sl@0: BIOerr(BIO_F_CONN_STATE,BIO_R_NO_PORT_SPECIFIED); sl@0: ERR_add_error_data(2,"host=",c->param_hostname); sl@0: goto exit_loop; sl@0: } sl@0: c->state=BIO_CONN_S_GET_IP; sl@0: break; sl@0: sl@0: case BIO_CONN_S_GET_IP: sl@0: if (BIO_get_host_ip(c->param_hostname,&(c->ip[0])) <= 0) sl@0: goto exit_loop; sl@0: c->state=BIO_CONN_S_GET_PORT; sl@0: break; sl@0: sl@0: case BIO_CONN_S_GET_PORT: sl@0: if (c->param_port == NULL) sl@0: { sl@0: /* abort(); */ sl@0: goto exit_loop; sl@0: } sl@0: else if (BIO_get_port(c->param_port,&c->port) <= 0) sl@0: goto exit_loop; sl@0: c->state=BIO_CONN_S_CREATE_SOCKET; sl@0: break; sl@0: sl@0: case BIO_CONN_S_CREATE_SOCKET: sl@0: /* now setup address */ sl@0: memset((char *)&c->them,0,sizeof(c->them)); sl@0: c->them.sin_family=AF_INET; sl@0: c->them.sin_port=htons((unsigned short)c->port); sl@0: l=(unsigned long) sl@0: ((unsigned long)c->ip[0]<<24L)| sl@0: ((unsigned long)c->ip[1]<<16L)| sl@0: ((unsigned long)c->ip[2]<< 8L)| sl@0: ((unsigned long)c->ip[3]); sl@0: c->them.sin_addr.s_addr=htonl(l); sl@0: c->state=BIO_CONN_S_CREATE_SOCKET; sl@0: sl@0: ret=socket(AF_INET,SOCK_STREAM,SOCKET_PROTOCOL); sl@0: if (ret == INVALID_SOCKET) sl@0: { sl@0: SYSerr(SYS_F_SOCKET,get_last_socket_error()); sl@0: ERR_add_error_data(4,"host=",c->param_hostname, sl@0: ":",c->param_port); sl@0: BIOerr(BIO_F_CONN_STATE,BIO_R_UNABLE_TO_CREATE_SOCKET); sl@0: goto exit_loop; sl@0: } sl@0: b->num=ret; sl@0: c->state=BIO_CONN_S_NBIO; sl@0: break; sl@0: sl@0: case BIO_CONN_S_NBIO: sl@0: if (c->nbio) sl@0: { sl@0: if (!BIO_socket_nbio(b->num,1)) sl@0: { sl@0: BIOerr(BIO_F_CONN_STATE,BIO_R_ERROR_SETTING_NBIO); sl@0: ERR_add_error_data(4,"host=", sl@0: c->param_hostname, sl@0: ":",c->param_port); sl@0: goto exit_loop; sl@0: } sl@0: } sl@0: c->state=BIO_CONN_S_CONNECT; sl@0: sl@0: #if defined(SO_KEEPALIVE) && !defined(OPENSSL_SYS_MPE) sl@0: i=1; sl@0: i=setsockopt(b->num,SOL_SOCKET,SO_KEEPALIVE,(char *)&i,sizeof(i)); sl@0: if (i < 0) sl@0: { sl@0: SYSerr(SYS_F_SOCKET,get_last_socket_error()); sl@0: ERR_add_error_data(4,"host=",c->param_hostname, sl@0: ":",c->param_port); sl@0: BIOerr(BIO_F_CONN_STATE,BIO_R_KEEPALIVE); sl@0: goto exit_loop; sl@0: } sl@0: #endif sl@0: break; sl@0: sl@0: case BIO_CONN_S_CONNECT: sl@0: BIO_clear_retry_flags(b); sl@0: ret=connect(b->num, sl@0: (struct sockaddr *)&c->them, sl@0: sizeof(c->them)); sl@0: b->retry_reason=0; sl@0: if (ret < 0) sl@0: { sl@0: if (BIO_sock_should_retry(ret)) sl@0: { sl@0: BIO_set_retry_special(b); sl@0: c->state=BIO_CONN_S_BLOCKED_CONNECT; sl@0: b->retry_reason=BIO_RR_CONNECT; sl@0: } sl@0: else sl@0: { sl@0: SYSerr(SYS_F_CONNECT,get_last_socket_error()); sl@0: ERR_add_error_data(4,"host=", sl@0: c->param_hostname, sl@0: ":",c->param_port); sl@0: BIOerr(BIO_F_CONN_STATE,BIO_R_CONNECT_ERROR); sl@0: } sl@0: goto exit_loop; sl@0: } sl@0: else sl@0: c->state=BIO_CONN_S_OK; sl@0: break; sl@0: sl@0: case BIO_CONN_S_BLOCKED_CONNECT: sl@0: i=BIO_sock_error(b->num); sl@0: if (i) sl@0: { sl@0: BIO_clear_retry_flags(b); sl@0: SYSerr(SYS_F_CONNECT,i); sl@0: ERR_add_error_data(4,"host=", sl@0: c->param_hostname, sl@0: ":",c->param_port); sl@0: BIOerr(BIO_F_CONN_STATE,BIO_R_NBIO_CONNECT_ERROR); sl@0: ret=0; sl@0: goto exit_loop; sl@0: } sl@0: else sl@0: c->state=BIO_CONN_S_OK; sl@0: break; sl@0: sl@0: case BIO_CONN_S_OK: sl@0: ret=1; sl@0: goto exit_loop; sl@0: default: sl@0: /* abort(); */ sl@0: goto exit_loop; sl@0: } sl@0: sl@0: if (cb != NULL) sl@0: { sl@0: if (!(ret=cb((BIO *)b,c->state,ret))) sl@0: goto end; sl@0: } sl@0: } sl@0: sl@0: /* Loop does not exit */ sl@0: exit_loop: sl@0: if (cb != NULL) sl@0: ret=cb((BIO *)b,c->state,ret); sl@0: end: sl@0: return(ret); sl@0: } sl@0: sl@0: EXPORT_C BIO_CONNECT *BIO_CONNECT_new(void) sl@0: { sl@0: BIO_CONNECT *ret; sl@0: sl@0: if ((ret=(BIO_CONNECT *)OPENSSL_malloc(sizeof(BIO_CONNECT))) == NULL) sl@0: return(NULL); sl@0: ret->state=BIO_CONN_S_BEFORE; sl@0: ret->param_hostname=NULL; sl@0: ret->param_port=NULL; sl@0: ret->info_callback=NULL; sl@0: ret->nbio=0; sl@0: ret->ip[0]=0; sl@0: ret->ip[1]=0; sl@0: ret->ip[2]=0; sl@0: ret->ip[3]=0; sl@0: ret->port=0; sl@0: memset((char *)&ret->them,0,sizeof(ret->them)); sl@0: return(ret); sl@0: } sl@0: sl@0: EXPORT_C void BIO_CONNECT_free(BIO_CONNECT *a) sl@0: { sl@0: if(a == NULL) sl@0: return; sl@0: sl@0: if (a->param_hostname != NULL) sl@0: OPENSSL_free(a->param_hostname); sl@0: if (a->param_port != NULL) sl@0: OPENSSL_free(a->param_port); sl@0: OPENSSL_free(a); sl@0: } sl@0: sl@0: EXPORT_C BIO_METHOD *BIO_s_connect(void) sl@0: { sl@0: return(&methods_connectp); sl@0: } sl@0: sl@0: static int conn_new(BIO *bi) sl@0: { sl@0: bi->init=0; sl@0: bi->num=INVALID_SOCKET; sl@0: bi->flags=0; sl@0: if ((bi->ptr=(char *)BIO_CONNECT_new()) == NULL) sl@0: return(0); sl@0: else sl@0: return(1); sl@0: } sl@0: sl@0: static void conn_close_socket(BIO *bio) sl@0: { sl@0: BIO_CONNECT *c; sl@0: sl@0: c=(BIO_CONNECT *)bio->ptr; sl@0: if (bio->num != INVALID_SOCKET) sl@0: { sl@0: /* Only do a shutdown if things were established */ sl@0: if (c->state == BIO_CONN_S_OK) sl@0: shutdown(bio->num,2); sl@0: closesocket(bio->num); sl@0: bio->num=INVALID_SOCKET; sl@0: } sl@0: } sl@0: sl@0: static int conn_free(BIO *a) sl@0: { sl@0: BIO_CONNECT *data; sl@0: sl@0: if (a == NULL) return(0); sl@0: data=(BIO_CONNECT *)a->ptr; sl@0: sl@0: if (a->shutdown) sl@0: { sl@0: conn_close_socket(a); sl@0: BIO_CONNECT_free(data); sl@0: a->ptr=NULL; sl@0: a->flags=0; sl@0: a->init=0; sl@0: } sl@0: return(1); sl@0: } sl@0: sl@0: static int conn_read(BIO *b, char *out, int outl) sl@0: { sl@0: int ret=0; sl@0: BIO_CONNECT *data; sl@0: sl@0: data=(BIO_CONNECT *)b->ptr; sl@0: if (data->state != BIO_CONN_S_OK) sl@0: { sl@0: ret=conn_state(b,data); sl@0: if (ret <= 0) sl@0: return(ret); sl@0: } sl@0: sl@0: if (out != NULL) sl@0: { sl@0: clear_socket_error(); sl@0: ret=readsocket(b->num,out,outl); sl@0: BIO_clear_retry_flags(b); sl@0: if (ret <= 0) sl@0: { sl@0: if (BIO_sock_should_retry(ret)) sl@0: BIO_set_retry_read(b); sl@0: } sl@0: } sl@0: return(ret); sl@0: } sl@0: sl@0: static int conn_write(BIO *b, const char *in, int inl) sl@0: { sl@0: int ret; sl@0: BIO_CONNECT *data; sl@0: sl@0: data=(BIO_CONNECT *)b->ptr; sl@0: if (data->state != BIO_CONN_S_OK) sl@0: { sl@0: ret=conn_state(b,data); sl@0: if (ret <= 0) return(ret); sl@0: } sl@0: sl@0: clear_socket_error(); sl@0: ret=writesocket(b->num,in,inl); sl@0: BIO_clear_retry_flags(b); sl@0: if (ret <= 0) sl@0: { sl@0: if (BIO_sock_should_retry(ret)) sl@0: BIO_set_retry_write(b); sl@0: } sl@0: return(ret); sl@0: } sl@0: sl@0: static long conn_ctrl(BIO *b, int cmd, long num, void *ptr) sl@0: { sl@0: BIO *dbio; sl@0: int *ip; sl@0: const char **pptr; sl@0: long ret=1; sl@0: BIO_CONNECT *data; sl@0: sl@0: data=(BIO_CONNECT *)b->ptr; sl@0: sl@0: switch (cmd) sl@0: { sl@0: case BIO_CTRL_RESET: sl@0: ret=0; sl@0: data->state=BIO_CONN_S_BEFORE; sl@0: conn_close_socket(b); sl@0: b->flags=0; sl@0: break; sl@0: case BIO_C_DO_STATE_MACHINE: sl@0: /* use this one to start the connection */ sl@0: if (data->state != BIO_CONN_S_OK) sl@0: ret=(long)conn_state(b,data); sl@0: else sl@0: ret=1; sl@0: break; sl@0: case BIO_C_GET_CONNECT: sl@0: if (ptr != NULL) sl@0: { sl@0: pptr=(const char **)ptr; sl@0: if (num == 0) sl@0: { sl@0: *pptr=data->param_hostname; sl@0: sl@0: } sl@0: else if (num == 1) sl@0: { sl@0: *pptr=data->param_port; sl@0: } sl@0: else if (num == 2) sl@0: { sl@0: *pptr= (char *)&(data->ip[0]); sl@0: } sl@0: else if (num == 3) sl@0: { sl@0: *((int *)ptr)=data->port; sl@0: } sl@0: if ((!b->init) || (ptr == NULL)) sl@0: *pptr="not initialized"; sl@0: ret=1; sl@0: } sl@0: break; sl@0: case BIO_C_SET_CONNECT: sl@0: if (ptr != NULL) sl@0: { sl@0: b->init=1; sl@0: if (num == 0) sl@0: { sl@0: if (data->param_hostname != NULL) sl@0: OPENSSL_free(data->param_hostname); sl@0: data->param_hostname=BUF_strdup(ptr); sl@0: } sl@0: else if (num == 1) sl@0: { sl@0: if (data->param_port != NULL) sl@0: OPENSSL_free(data->param_port); sl@0: data->param_port=BUF_strdup(ptr); sl@0: } sl@0: else if (num == 2) sl@0: { sl@0: char buf[16]; sl@0: unsigned char *p = ptr; sl@0: sl@0: BIO_snprintf(buf,sizeof buf,"%d.%d.%d.%d", sl@0: p[0],p[1],p[2],p[3]); sl@0: if (data->param_hostname != NULL) sl@0: OPENSSL_free(data->param_hostname); sl@0: data->param_hostname=BUF_strdup(buf); sl@0: memcpy(&(data->ip[0]),ptr,4); sl@0: } sl@0: else if (num == 3) sl@0: { sl@0: char buf[DECIMAL_SIZE(int)+1]; sl@0: sl@0: BIO_snprintf(buf,sizeof buf,"%d",*(int *)ptr); sl@0: if (data->param_port != NULL) sl@0: OPENSSL_free(data->param_port); sl@0: data->param_port=BUF_strdup(buf); sl@0: data->port= *(int *)ptr; sl@0: } sl@0: } sl@0: break; sl@0: case BIO_C_SET_NBIO: sl@0: data->nbio=(int)num; sl@0: break; sl@0: case BIO_C_GET_FD: sl@0: if (b->init) sl@0: { sl@0: ip=(int *)ptr; sl@0: if (ip != NULL) sl@0: *ip=b->num; sl@0: ret=b->num; sl@0: } sl@0: else sl@0: ret= -1; sl@0: break; sl@0: case BIO_CTRL_GET_CLOSE: sl@0: ret=b->shutdown; sl@0: break; sl@0: case BIO_CTRL_SET_CLOSE: sl@0: b->shutdown=(int)num; sl@0: break; sl@0: case BIO_CTRL_PENDING: sl@0: case BIO_CTRL_WPENDING: sl@0: ret=0; sl@0: break; sl@0: case BIO_CTRL_FLUSH: sl@0: break; sl@0: case BIO_CTRL_DUP: sl@0: { sl@0: dbio=(BIO *)ptr; sl@0: if (data->param_port) sl@0: BIO_set_conn_port(dbio,data->param_port); sl@0: if (data->param_hostname) sl@0: BIO_set_conn_hostname(dbio,data->param_hostname); sl@0: BIO_set_nbio(dbio,data->nbio); sl@0: /* FIXME: the cast of the function seems unlikely to be a good idea */ sl@0: (void)BIO_set_info_callback(dbio,(bio_info_cb *)data->info_callback); sl@0: } sl@0: break; sl@0: case BIO_CTRL_SET_CALLBACK: sl@0: { sl@0: #if 0 /* FIXME: Should this be used? -- Richard Levitte */ sl@0: BIOerr(BIO_F_CONN_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); sl@0: ret = -1; sl@0: #else sl@0: ret=0; sl@0: #endif sl@0: } sl@0: break; sl@0: case BIO_CTRL_GET_CALLBACK: sl@0: { sl@0: int (**fptr)(const BIO *bio,int state,int xret); sl@0: sl@0: fptr=(int (**)(const BIO *bio,int state,int xret))ptr; sl@0: *fptr=data->info_callback; sl@0: } sl@0: break; sl@0: default: sl@0: ret=0; sl@0: break; sl@0: } sl@0: return(ret); sl@0: } sl@0: sl@0: static long conn_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp) sl@0: { sl@0: long ret=1; sl@0: BIO_CONNECT *data; sl@0: sl@0: data=(BIO_CONNECT *)b->ptr; sl@0: sl@0: switch (cmd) sl@0: { sl@0: case BIO_CTRL_SET_CALLBACK: sl@0: { sl@0: data->info_callback=(int (*)(const struct bio_st *, int, int))fp; sl@0: } sl@0: break; sl@0: default: sl@0: ret=0; sl@0: break; sl@0: } sl@0: return(ret); sl@0: } sl@0: sl@0: static int conn_puts(BIO *bp, const char *str) sl@0: { sl@0: int n,ret; sl@0: sl@0: n=strlen(str); sl@0: ret=conn_write(bp,str,n); sl@0: return(ret); sl@0: } sl@0: sl@0: EXPORT_C BIO *BIO_new_connect(char *str) sl@0: { sl@0: BIO *ret; sl@0: sl@0: ret=BIO_new(BIO_s_connect()); sl@0: if (ret == NULL) return(NULL); sl@0: if (BIO_set_conn_hostname(ret,str)) sl@0: return(ret); sl@0: else sl@0: { sl@0: BIO_free(ret); sl@0: return(NULL); sl@0: } sl@0: } sl@0: sl@0: #endif sl@0: