OSSP CVS Repository

ossp - Check-in [2850]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 2850
Date: 2002-Nov-19 16:54:51 (local)
2002-Nov-19 15:54:51 (UTC)
User:mlelstv
Branch:
Comment: wrap BIO objects from libcrypto as an endpoint adjust test program to use sio_bio instead of sio_sa

PR: Submitted by: Reviewed by: Approved by: Obtained from:

Tickets:
Inspections:
Files:
ossp-pkg/sio/Makefile      1.1 -> 1.2     3 inserted, 2 deleted
ossp-pkg/sio/sio_bio.c      added-> 1.1
ossp-pkg/sio/sio_test.c      1.2 -> 1.3     19 inserted, 8 deleted

ossp-pkg/sio/Makefile 1.1 -> 1.2

--- Makefile     2002/11/14 09:24:54     1.1
+++ Makefile     2002/11/19 15:54:51     1.2
@@ -10,7 +10,8 @@
 
 al_test: al_test.o al.o
 
-sio_test: sio_test.o sio_buffer.o sio_hello.o sio_fd.o sio_sa.o sio.o al.o lib_sa/sa.o
+sio_test: sio_test.o sio_buffer.o sio_hello.o sio_bio.o sio.o al.o lib_sa/sa.o
+        $(CC) $(CFLAGS) -o sio_test sio_test.o sio_buffer.o sio_hello.o sio_bio.o sio.o al.o lib_sa/sa.o -lcrypto
 
 lib_sa/sa.o: lib_sa/sa.c
         $(CC) $(CFLAGS) -c -Ilib_sa -o lib_sa/sa.o lib_sa/sa.c
@@ -22,5 +23,5 @@
         $(CC) $(CFLAGS) -c -Ilib_sa sio_test.c
 
 clean:
-        rm -f sio_test sio_test.o sio_buffer.o sio_hello.o sio_fd.o sio_sa.o sio.o al.o lib_sa/sa.o
+        rm -f *.o lib_sa/sa.o
 


ossp-pkg/sio/sio_bio.c -> 1.1

*** /dev/null    Sat Nov 23 02:32:24 2024
--- -    Sat Nov 23 02:32:34 2024
***************
*** 0 ****
--- 1,163 ----
+ #include <stddef.h>
+ #include <stdlib.h>
+ #include <string.h>
+ 
+ #include "al.h"
+ #include "sio.h"
+ 
+ #include <openssl/bio.h>
+ 
+ typedef struct {
+     BIO *bio;
+     size_t inputsize;
+     al_label_t data_label;
+     al_label_t eof_label;
+     char eof;
+ } private_t;
+ 
+ /*
+  * create stage
+  *
+  * allocate private instance data
+  */
+ static
+ sio_rc_t siobio_init(sio_t *sio, void **u)
+ {
+     private_t *my;
+     
+     my = (private_t *)malloc(sizeof(private_t));
+     if (my == NULL)
+         return SIO_ERR_MEM;
+ 
+     my->bio          = NULL;
+     my->eof          = '\0';
+ 
+     sio_label(sio, SIO_LN_DATA, &my->data_label);
+     sio_label(sio, SIO_LN_EOF, &my->eof_label);
+ 
+     *u = my;
+ 
+     return SIO_OK;
+ }
+ 
+ /*
+  * configure stage
+  *
+  * pass two void pointers
+  */
+ static
+ sio_rc_t siobio_configure(sio_t *sio, void *u, void *obj, void *val)
+ {
+     private_t *my = (private_t *)u;
+     const char *name = (const char *)obj;
+ 
+     if (!strcmp(name, "bio")) {
+         my->bio       = (BIO *)val;
+     } else if (!strcmp(name, "inputsize")) {
+         my->inputsize = *(int *)val;
+     } else {
+         return SIO_ERR_ARG;
+     }
+ 
+     return SIO_OK;
+ }
+ 
+ /*
+  * destroy stage
+  */
+ static
+ sio_rc_t siobio_cleanup(sio_t *sio, void *u)
+ {
+     private_t *my = (private_t *)u;
+ 
+     free(my);
+ 
+     return SIO_OK;
+ }
+ 
+ static
+ sio_rc_t siobio_openr(sio_t *sio, al_t *al, void *u)
+ {
+     return SIO_OK;
+ }
+ 
+ static
+ sio_rc_t siobio_closer(sio_t *sio, al_t *al, void *u)
+ {
+     return SIO_OK;
+ }
+ 
+ static
+ sio_rc_t siobio_openw(sio_t *sio, al_t *al, void *u)
+ {
+     return SIO_OK;
+ }
+ 
+ static
+ sio_rc_t siobio_closew(sio_t *sio, al_t *al, void *u)
+ {
+     return SIO_OK;
+ }
+ 
+ static
+ void freebiobuf(char *p, size_t n, void *u)
+ {
+     free(p);
+ }
+ static
+ sio_rc_t siobio_input(sio_t *sio, al_t *al, void *u)
+ {
+     private_t *my = (private_t *)u;
+     char *p;
+     int n;
+ 
+     n = BIO_pending(my->bio);
+     if (n == 0 || n > my->inputsize)
+         n = my->inputsize;
+     p = malloc(n);
+     n = BIO_read(my->bio, p, n);
+ 
+     if (n == 0 && !BIO_should_read(my->bio))
+         al_append_bytes(al, &my->eof, sizeof(my->eof), my->eof_label);
+     else
+         al_attach_buffer(al, p, n, my->data_label, freebiobuf, NULL);
+ 
+     return SIO_SCHED_DOWN;
+ }
+ 
+ static
+ al_rc_t siobio_write_chunk(al_chunk_t *alc, void *u)
+ {
+     private_t *my = (private_t *)u;
+ 
+     if (al_same_label(alc, my->data_label))
+         BIO_write(my->bio, al_chunk_ptr(alc, 0), al_chunk_len(alc));
+ 
+     return AL_OK;
+ }
+ static
+ sio_rc_t siobio_output(sio_t *sio, al_t *al, void *u)
+ {
+     private_t *my = (private_t *)u;
+ 
+     al_traverse_cb(al, 0, al_bytes(al), AL_FORWARD, my->data_label,
+                    siobio_write_chunk, (void *)my);
+ 
+     al_splice(al, 0, al_bytes(al), NULL, NULL);
+ 
+     return SIO_SCHED_DOWN;
+ }
+ 
+ sio_module_t sio_module_bio = {
+     "bio",
+     siobio_init,
+     siobio_configure,
+     siobio_cleanup,
+     siobio_openr,
+     siobio_closer,
+     siobio_openw,
+     siobio_closew,
+     siobio_input,
+     siobio_output
+ };
+ 


ossp-pkg/sio/sio_test.c 1.2 -> 1.3

--- sio_test.c   2002/11/05 13:23:36     1.2
+++ sio_test.c   2002/11/19 15:54:51     1.3
@@ -4,8 +4,11 @@
 #include "sio.h"
 
 #include "sa.h"
+#include <openssl/ssl.h>
+#include <openssl/bio.h>
+extern BIO_METHOD *BIO_s_socket();
 
-extern sio_module_t sio_module_sa;
+extern sio_module_t sio_module_bio;
 extern sio_module_t sio_module_hello;
 extern sio_module_t sio_module_buffer;
 
@@ -16,13 +19,16 @@
 {
     sio_rc_t rc;
     sio_t *sio;
-    sio_stage_t *sios_sa, *sios_hello, *sios_buffer;
+    sio_stage_t *sios_bio, *sios_hello, *sios_buffer;
 
     sa_rc_t src;
     sa_addr_t *saa;
     sa_t *msa, *sa;
     char *uri;
 
+    int fd;
+    BIO *bio;
+
     char buf[] = "Hello world\n";
 
     size_t actual;
@@ -39,12 +45,12 @@
     uri = NULL;
 
     e(sio_create(&sio));
-    e(sio_create_stage(sio, &sio_module_sa, &sios_sa));
+    e(sio_create_stage(sio, &sio_module_bio, &sios_bio));
     e(sio_create_stage(sio, &sio_module_hello, &sios_hello));
     e(sio_create_stage(sio, &sio_module_buffer, &sios_buffer));
 
     buflen = 256;
-    e(sio_configure_stage(sio, sios_sa, "buflen", &buflen));
+    e(sio_configure_stage(sio, sios_bio, "inputsize", &buflen));
 
     buflen = 1000;
     e(sio_configure_stage(sio, sios_buffer, "outputsize", &buflen));
@@ -58,16 +64,21 @@
         printf("Connection from %s\n",uri);
         s(sa_addr_destroy(saa));
 
-        e(sio_configure_stage(sio, sios_sa, "sa", sa));
+
+        bio = BIO_new(BIO_s_socket());
+        sa_getfd(sa, &fd);
+        BIO_set_fd(bio, fd, 0);
+
+        e(sio_configure_stage(sio, sios_bio, "bio", bio));
 
         e(sio_attach(sio, sios_buffer, SIO_MODE_WRITE));
         e(sio_attach(sio, sios_hello, SIO_MODE_READWRITE));
-        e(sio_attach(sio, sios_sa, SIO_MODE_READWRITE));
+        e(sio_attach(sio, sios_bio, SIO_MODE_READWRITE));
 
         e(sio_write(sio, buf, sizeof(buf)-1, &actual));
         e(sio_push(sio));
 
-        e(sio_detach(sio, sios_sa));
+        e(sio_detach(sio, sios_bio));
         e(sio_detach(sio, sios_hello));
         e(sio_detach(sio, sios_buffer));
 
@@ -77,7 +88,7 @@
 
     e(sio_destroy_stage(sio, sios_buffer));
     e(sio_destroy_stage(sio, sios_hello));
-    e(sio_destroy_stage(sio, sios_sa));
+    e(sio_destroy_stage(sio, sios_bio));
 
     e(sio_destroy(sio));
 

CVSTrac 2.0.1