Sunday, July 30, 2006

Some things I learned this weekend

First, while I have known it for a while, it just doesn't get prettier on closer examination—OpenSSL is one convoluted library. I was attempting to roll my own OpenSSL interface using SBCL's sb-alien ffi hooks. While I was making progress, I suddenly came to the part where I needed to deal with x509_store_st structures, and decided there had to be an easier way. I originally looked at CL+SSL but abandonded it on initial inspection because I thought it would be too difficult to get it working with our epoll code. Once I hit the wall that was x509_store_st (for good reading check out "Secure Programming Cookbook for C and C++" Section 10.5) I decided to take a closer look at the CL+SSL code. It turns out that you can get at the underlying socket, even though it is wrapped under many stream classes. I should be able to use this socket to connect the CL+SSL streams into the epoll event notification structure I have set up.

Second, while the time spent on the OpenSSL stuff was a bust, I did learn more about how to declare complex structures in sb-alien. Things that might be obvious to others, but weren't to me:

void is ony valid as a return type for a function. The function "void foo(void*)" as a function pointer in a structure becomes:

(define-alien-type nil
(struct foo
(bar (* (function void (* t))))))

The first void is retained as it is the return void. The void in the arg list gets turned into a t.

Along the function definition line, it also doesn't work to include the names of the function's paramenters

(foo (* (function int (bar int) (baz int)))) ; does not work
(foo (* (function int int int)))

This may have been mentioned, but I couldn't seem to get scructures to nest without declaring the entire inside structure in-place. What was

(define-alien-type nil
(struct baz
(some int)
(other int)))

(define-alien-type nil
(struct foo
(bar (struct baz))))

Will not work with a complaint about unable to determine storage space needed for baz, In this case, the only recourse is to put baz into bar lock-stock-and-barrel:

(define-alien-type nil
(struct foo
(bar (struct baz
(some int)
(other int)))

0 Comments:

Post a Comment

<< Home