/* return ElvTrue if VIO is available. */ static int vio_test (void) { VIOMODEINFO info; USHORT rc; #if 0 { static char digits[] = "0123456789abcdef"; char buffer[32]; int i, j; for (i = 0; i < 16; i++) { for (j = 0; j < 16; j++) { buffer[j * 2] = digits[j]; buffer[j * 2 + 1] = i * 16 + j; buffer[j * 2 + 1] = 0x07; buffer[j * 2 ] = i * 16 + j; } VioWrtCellStr (buffer, 32, i, 0, 0); } vio_read (buffer, 1, 0); } #endif info.cb = sizeof (info); rc = VioGetMode (&info, 0); return rc == NO_ERROR; }
/* Emulate a blocking recv() call with vio_read(). */ static long yassl_recv(void *ptr, void *buf, size_t len) { return (long)vio_read(ptr, buf, len); }
/* Repeatedly get events (keystrokes), and call elvis' event functions */ static void vio_loop (void) { char buf[20]; int len; int timeout = 0; MAPSTATE mst = MAP_CLEAR; VWIN *scan; /* perform the -c command or -t tag */ mainfirstcmd(windefault); while (vwins) { /* reset the ttycaught bitmap */ ttycaught = 0; /* if no window is current, then make the newest current */ if (!current) { current = vwins; } /* redraw the window(s) */ { /* redraw each window; the current one last */ for (scan = vwins; scan; scan = scan->next) { if (scan != current) { scan->shape = eventdraw ((GUIWIN *)scan); } } current->shape = eventdraw ((GUIWIN *)current); movecurs (current); /* make the cursor be this window's shape */ cursorshape (current->shape); } /* choose a timeout value */ switch (mst) { case MAP_CLEAR: timeout = 0; break; case MAP_USER: timeout = o_usertime; break; case MAP_KEY: timeout = o_keytime; break; } /* read events */ do_flush (); vio_CM (c_row, c_col); len = vio_read (buf, sizeof buf, timeout); /* process keystroke data */ if (len == -2) { /* vio_read() itself did something. We don't need to * do anything except the usual screen updates. */ } else if (len == -1) { /* Maybe the screen was resized? Get new size */ vio_getsize (); /* Resize the windows to match the new screen. The * easiest way to do this is to "change" the size of the * current window to its original size and force the * other windows to compensate. If there is only one * window, then should be resized to the screen size. */ chgsize (current, vwins->next ? current->height : (int)o_ttyrows, ElvTrue); } else { mst = eventkeys ((GUIWIN *)current, toCHAR (buf), len); /* if first keystroke after running an external * program, then we need to expose every window. */ if (afterprg == 1) { /* reset the flag BEFORE exposing windows, * or else the eventexpose() won't work right. */ afterprg = 0; vio_resume (ElvTrue); for (scan = vwins; scan; scan = scan->next) { eventexpose ((GUIWIN *)scan, 0, 0, scan->height - 1, (int)(o_ttycolumns - 1)); } } else if (afterprg == 2) { /* it became 2 while processing the earlier * keystrokes. Set it to 1 now, so we'll * read one more keystroke before exposing * all the windows. */ afterprg = 1; } } } }
int main(int argc, char** argv) { char* server_key = 0, *server_cert = 0; char* client_key = 0, *client_cert = 0; char* ca_file = 0, *ca_path = 0; char* cipher=0; int child_pid,sv[2]; my_bool unused; struct st_VioSSLFd* ssl_acceptor= 0; struct st_VioSSLFd* ssl_connector= 0; Vio* client_vio=0, *server_vio=0; enum enum_ssl_init_error ssl_init_error; unsigned long ssl_error; MY_INIT(argv[0]); DBUG_PROCESS(argv[0]); DBUG_PUSH(default_dbug_option); if (argc<5) { print_usage(); return 1; } server_key = argv[1]; server_cert = argv[2]; client_key = argv[3]; client_cert = argv[4]; if (argc>5) ca_file = argv[5]; if (argc>6) ca_path = argv[6]; printf("Server key/cert : %s/%s\n", server_key, server_cert); printf("Client key/cert : %s/%s\n", client_key, client_cert); if (ca_file!=0) printf("CAfile : %s\n", ca_file); if (ca_path!=0) printf("CApath : %s\n", ca_path); if (socketpair(PF_UNIX, SOCK_STREAM, IPPROTO_IP, sv)==-1) fatal_error("socketpair"); ssl_acceptor = new_VioSSLAcceptorFd(server_key, server_cert, ca_file, ca_path, cipher); ssl_connector = new_VioSSLConnectorFd(client_key, client_cert, ca_file, ca_path, cipher, &ssl_init_error); client_vio = (struct st_vio*)my_malloc(sizeof(struct st_vio),MYF(0)); client_vio->sd = sv[0]; client_vio->vioblocking(client_vio, 0, &unused); sslconnect(ssl_connector,client_vio,60L,&ssl_error); server_vio = (struct st_vio*)my_malloc(sizeof(struct st_vio),MYF(0)); server_vio->sd = sv[1]; server_vio->vioblocking(client_vio, 0, &unused); sslaccept(ssl_acceptor,server_vio,60L, &ssl_error); printf("Socketpair: %d , %d\n", client_vio->sd, server_vio->sd); child_pid = fork(); if (child_pid==-1) { my_free(ssl_acceptor); my_free(ssl_connector); fatal_error("fork"); } if (child_pid==0) { /* child, therefore, client */ char xbuf[100]; int r = vio_read(client_vio,xbuf, sizeof(xbuf)); if (r<=0) { my_free(ssl_acceptor); my_free(ssl_connector); fatal_error("client:SSL_read"); } xbuf[r] = 0; printf("client:got %s\n", xbuf); my_free(client_vio); my_free(ssl_acceptor); my_free(ssl_connector); } else { const char* s = "Huhuhuh"; int r = vio_write(server_vio,(uchar*)s, strlen(s)); if (r<=0) { my_free(ssl_acceptor); my_free(ssl_connector); fatal_error("server:SSL_write"); } my_free(server_vio); my_free(ssl_acceptor); my_free(ssl_connector); } return 0; }