柏杨丑陋的中国人:Top urgent

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/29 22:03:44
Who can do me a favor?Please offer the source of SSL of the example for MySQL via C!!!

Remark:please don't translate aboves to chinese stupidly.the reply would be good,you should get the bonus extra.Thank you for your browsing.

00001 /* Copyright (C) 2000 MySQL AB
00002
00003 This program is free software; you can redistribute it and/or modify
00004 it under the terms of the GNU General Public License as published by
00005 the Free Software Foundation; either version 2 of the License, or
00006 (at your option) any later version.
00007
00008 This program is distributed in the hope that it will be useful,
00009 but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00011 GNU General Public License for more details.
00012
00013 You should have received a copy of the GNU General Public License
00014 along with this program; if not, write to the Free Software
00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
00016
00017 #include <my_global.h>
00018 #if defined(HAVE_OPENSSL) && !defined(__NETWARE__)
00019 #include <my_sys.h>
00020 #include <m_string.h>
00021 #include <m_ctype.h>
00022 #include "mysql.h"
00023 #include "errmsg.h"
00024 #include <my_dir.h>
00025 #include <my_getopt.h>
00026 #include <signal.h>
00027 #include <violite.h>
00028
00029 const char *VER="0.2";
00030
00031
00032 #ifndef DBUG_OFF
00033 const char *default_dbug_option="d:t:O,-";
00034 #endif
00035
00036 void
00037 fatal_error( const char* r)
00038 {
00039 perror(r);
00040 exit(0);
00041 }
00042
00043 void
00044 print_usage()
00045 {
00046 printf("viossl-test: testing SSL virtual IO. Usage:\n");
00047 printf("viossl-test server-key server-cert client-key client-cert [CAfile] [CApath]\n");
00048 }
00049
00050
00051 int
00052 main(int argc, char** argv)
00053 {
00054 char* server_key = 0, *server_cert = 0;
00055 char* client_key = 0, *client_cert = 0;
00056 char* ca_file = 0, *ca_path = 0;
00057 char* cipher=0;
00058 int child_pid,sv[2];
00059 my_bool unused;
00060 struct st_VioSSLAcceptorFd* ssl_acceptor=0;
00061 struct st_VioSSLConnectorFd* ssl_connector=0;
00062 Vio* client_vio=0, *server_vio=0;
00063 MY_INIT(argv[0]);
00064 DBUG_PROCESS(argv[0]);
00065 DBUG_PUSH(default_dbug_option);
00066
00067 if (argc<5)
00068 {
00069 print_usage();
00070 return 1;
00071 }
00072
00073 server_key = argv[1];
00074 server_cert = argv[2];
00075 client_key = argv[3];
00076 client_cert = argv[4];
00077 if (argc>5)
00078 ca_file = argv[5];
00079 if (argc>6)
00080 ca_path = argv[6];
00081 printf("Server key/cert : %s/%s\n", server_key, server_cert);
00082 printf("Client key/cert : %s/%s\n", client_key, client_cert);
00083 if (ca_file!=0)
00084 printf("CAfile : %s\n", ca_file);
00085 if (ca_path!=0)
00086 printf("CApath : %s\n", ca_path);
00087
00088
00089 if (socketpair(PF_UNIX, SOCK_STREAM, IPPROTO_IP, sv)==-1)
00090 fatal_error("socketpair");
00091
00092 ssl_acceptor = new_VioSSLAcceptorFd(server_key, server_cert, ca_file,
00093 ca_path, cipher);
00094 ssl_connector = new_VioSSLConnectorFd(client_key, client_cert, ca_file,
00095 ca_path, cipher);
00096
00097 client_vio = (struct st_vio*)my_malloc(sizeof(struct st_vio),MYF(0));
00098 client_vio->sd = sv[0];
00099 client_vio->vioblocking(client_vio, 0, &unused);
00100 sslconnect(ssl_connector,client_vio,60L);
00101 server_vio = (struct st_vio*)my_malloc(sizeof(struct st_vio),MYF(0));
00102 server_vio->sd = sv[1];
00103 server_vio->vioblocking(client_vio, 0, &unused);
00104 sslaccept(ssl_acceptor,server_vio,60L);
00105
00106 printf("Socketpair: %d , %d\n", client_vio->sd, server_vio->sd);
00107
00108 child_pid = fork();
00109 if (child_pid==-1) {
00110 my_free((gptr)ssl_acceptor,MYF(0));
00111 my_free((gptr)ssl_connector,MYF(0));
00112 fatal_error("fork");
00113 }
00114 if (child_pid==0)
00115 {
00116 /* child, therefore, client */
00117 char xbuf[100];
00118 int r = vio_read(client_vio,xbuf, sizeof(xbuf));
00119 if (r<=0) {
00120 my_free((gptr)ssl_acceptor,MYF(0));
00121 my_free((gptr)ssl_connector,MYF(0));
00122 fatal_error("client:SSL_read");
00123 }
00124 xbuf[r] = 0;
00125 printf("client:got %s\n", xbuf);
00126 my_free((gptr)client_vio,MYF(0));
00127 my_free((gptr)ssl_acceptor,MYF(0));
00128 my_free((gptr)ssl_connector,MYF(0));
00129 }
00130 else
00131 {
00132 const char* s = "Huhuhuh";
00133 int r = vio_write(server_vio,(gptr)s, strlen(s));
00134 if (r<=0) {
00135 my_free((gptr)ssl_acceptor,MYF(0));
00136 my_free((gptr)ssl_connector,MYF(0));
00137 fatal_error("server:SSL_write");
00138 }
00139 my_free((gptr)server_vio,MYF(0));
00140 my_free((gptr)ssl_acceptor,MYF(0));
00141 my_free((gptr)ssl_connector,MYF(0));
00142 }
00143 return 0;
00144 }
00145 #else /* HAVE_OPENSSL */
00146
00147 int main() {
00148 return 0;
00149 }
00150 #endif /* HAVE_OPENSSL */

are you so crazy ?go and buy any computer