aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2016-02-01 15:42:09 +1000
committerSteve Bennett <steveb@workware.net.au>2016-02-01 15:52:10 +1000
commit2d39166b9970cd0954238ee80e8ab63a8d0bb47d (patch)
treebb045da71fdaa7eae928cefca94c24d70ee86def
parent54697b4bebf26e80d60e7a10d42fc5f4f00b9fdd (diff)
downloadjimtcl-2d39166b9970cd0954238ee80e8ab63a8d0bb47d.zip
jimtcl-2d39166b9970cd0954238ee80e8ab63a8d0bb47d.tar.gz
jimtcl-2d39166b9970cd0954238ee80e8ab63a8d0bb47d.tar.bz2
aio: fix aio ssl support
The following changes were not merged: - commit examples/{certificate,key}.pem - return AioFile from JimMakeChannel to allow ssl-specific settings to be set - improve examples/ssl.{client,server} so they work out-of-the-box Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--examples/certificate.pem14
-rw-r--r--examples/key.pem9
-rw-r--r--examples/ssl.client6
-rw-r--r--examples/ssl.server3
-rw-r--r--jim-aio.c24
5 files changed, 44 insertions, 12 deletions
diff --git a/examples/certificate.pem b/examples/certificate.pem
new file mode 100644
index 0000000..9d7ac23
--- /dev/null
+++ b/examples/certificate.pem
@@ -0,0 +1,14 @@
+-----BEGIN CERTIFICATE-----
+MIICLDCCAdYCAQAwDQYJKoZIhvcNAQEEBQAwgaAxCzAJBgNVBAYTAlBUMRMwEQYD
+VQQIEwpRdWVlbnNsYW5kMQ8wDQYDVQQHEwZMaXNib2ExFzAVBgNVBAoTDk5ldXJv
+bmlvLCBMZGEuMRgwFgYDVQQLEw9EZXNlbnZvbHZpbWVudG8xGzAZBgNVBAMTEmJy
+dXR1cy5uZXVyb25pby5wdDEbMBkGCSqGSIb3DQEJARYMc2FtcG9AaWtpLmZpMB4X
+DTk2MDkwNTAzNDI0M1oXDTk2MTAwNTAzNDI0M1owgaAxCzAJBgNVBAYTAlBUMRMw
+EQYDVQQIEwpRdWVlbnNsYW5kMQ8wDQYDVQQHEwZMaXNib2ExFzAVBgNVBAoTDk5l
+dXJvbmlvLCBMZGEuMRgwFgYDVQQLEw9EZXNlbnZvbHZpbWVudG8xGzAZBgNVBAMT
+EmJydXR1cy5uZXVyb25pby5wdDEbMBkGCSqGSIb3DQEJARYMc2FtcG9AaWtpLmZp
+MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAL7+aty3S1iBA/+yxjxv4q1MUTd1kjNw
+L4lYKbpzzlmC5beaQXeQ2RmGMTXU+mDvuqItjVHOK3DvPK7lTcSGftUCAwEAATAN
+BgkqhkiG9w0BAQQFAANBAFqPEKFjk6T6CKTHvaQeEAsX0/8YHPHqH/9AnhSjrwuX
+9EBc0n6bVGhN7XaXd6sJ7dym9sbsWxb+pJdurnkxjx4=
+-----END CERTIFICATE-----
diff --git a/examples/key.pem b/examples/key.pem
new file mode 100644
index 0000000..239ad66
--- /dev/null
+++ b/examples/key.pem
@@ -0,0 +1,9 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIBPAIBAAJBAL7+aty3S1iBA/+yxjxv4q1MUTd1kjNwL4lYKbpzzlmC5beaQXeQ
+2RmGMTXU+mDvuqItjVHOK3DvPK7lTcSGftUCAwEAAQJBALjkK+jc2+iihI98riEF
+oudmkNziSRTYjnwjx8mCoAjPWviB3c742eO3FG4/soi1jD9A5alihEOXfUzloenr
+8IECIQD3B5+0l+68BA/6d76iUNqAAV8djGTzvxnCxycnxPQydQIhAMXt4trUI3nc
+a+U8YL2HPFA3gmhBsSICbq2OptOCnM7hAiEA6Xi3JIQECob8YwkRj29DU3/4WYD7
+WLPgsQpwo1GuSpECICGsnWH5oaeD9t9jbFoSfhJvv0IZmxdcLpRcpslpeWBBAiEA
+6/5B8J0GHdJq89FHwEG/H2eVVUYu5y/aD6sgcm+0Avg=
+-----END RSA PRIVATE KEY-----
diff --git a/examples/ssl.client b/examples/ssl.client
index f0699b4..58be7b3 100644
--- a/examples/ssl.client
+++ b/examples/ssl.client
@@ -2,7 +2,11 @@
load_ssl_certs /etc/ssl/certs
set s [[socket stream 127.0.0.1:20000] ssl]
-$s verify
+try {
+ $s verify
+} on error msg {
+ stderr puts $msg
+}
foreach i [range 1 20] {
$s puts "1 << $i"
diff --git a/examples/ssl.server b/examples/ssl.server
index cc162a2..7ccb101 100644
--- a/examples/ssl.server
+++ b/examples/ssl.server
@@ -18,6 +18,9 @@ $s readable {
# Get the request (max 80 chars) - need the source address
while {[$sock gets buf] >= 0} {
+ if {$buf eq ""} {
+ break
+ }
set buf [string trim $buf]
puts -nonewline "read '$buf'"
diff --git a/jim-aio.c b/jim-aio.c
index 9463bda..87834a7 100644
--- a/jim-aio.c
+++ b/jim-aio.c
@@ -273,7 +273,7 @@ static const JimAioFopsType ssl_fops = {
#endif
static int JimAioSubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
-static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filename,
+static AioFile *JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filename,
const char *hdlfmt, int family, const char *mode);
#if !defined(JIM_ANSIC) && !defined(JIM_BOOTSTRAP)
@@ -803,7 +803,7 @@ static int aio_cmd_accept(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
/* Create the file command */
return JimMakeChannel(interp, NULL, sock, Jim_NewStringObj(interp, "accept", -1),
- "aio.sockstream%ld", af->addr_family, "r+");
+ "aio.sockstream%ld", af->addr_family, "r+") ? JIM_OK : JIM_ERR;
}
static int aio_cmd_listen(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
@@ -1118,7 +1118,8 @@ static int aio_cmd_ssl(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
}
}
- if (JimMakeChannel(interp, NULL, fd, NULL, "aio.sslstream%ld", af->addr_family, "r+") != JIM_OK) {
+ af = JimMakeChannel(interp, NULL, fd, NULL, "aio.sslstream%ld", af->addr_family, "r+");
+ if (af == NULL) {
goto out;
}
@@ -1153,7 +1154,6 @@ static int aio_cmd_verify(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
Jim_SetResultString(interp, "failed to verify the connection authenticity", -1);
}
}
-
return ret;
}
#endif
@@ -1368,7 +1368,7 @@ static int JimAioOpenCommand(Jim_Interp *interp, int argc,
}
}
#endif
- return JimMakeChannel(interp, NULL, -1, argv[1], "aio.handle%ld", 0, mode);
+ return JimMakeChannel(interp, NULL, -1, argv[1], "aio.handle%ld", 0, mode) ? JIM_OK : JIM_ERR;
}
#if defined(JIM_SSL)
@@ -1407,8 +1407,9 @@ static SSL_CTX *JimAioSslCtx(Jim_Interp *interp)
* mode is used for open or fdopen.
*
* Creates the command and sets the name as the current result.
+ * Returns the AioFile pointer on sucess or NULL on failure.
*/
-static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filename,
+static AioFile *JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filename,
const char *hdlfmt, int family, const char *mode)
{
AioFile *af;
@@ -1445,7 +1446,7 @@ static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filenam
}
#endif
Jim_DecrRefCount(interp, filename);
- return JIM_ERR;
+ return NULL;
}
}
@@ -1463,6 +1464,7 @@ static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filenam
af->openFlags = openFlags;
af->addr_family = family;
af->fops = &stdio_fops;
+ af->ssl = NULL;
Jim_CreateCommand(interp, buf, JimAioSubCmdProc, af, JimAioDelProc);
@@ -1471,7 +1473,7 @@ static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filenam
*/
Jim_SetResult(interp, Jim_MakeGlobalNamespaceName(interp, Jim_NewStringObj(interp, buf, -1)));
- return JIM_OK;
+ return af;
}
#if defined(HAVE_PIPE) || (defined(HAVE_SOCKETPAIR) && defined(HAVE_SYS_UN_H))
@@ -1481,11 +1483,11 @@ static int JimMakeChannel(Jim_Interp *interp, FILE *fh, int fd, Jim_Obj *filenam
static int JimMakeChannelPair(Jim_Interp *interp, int p[2], Jim_Obj *filename,
const char *hdlfmt, int family, const char *mode[2])
{
- if (JimMakeChannel(interp, NULL, p[0], filename, hdlfmt, family, mode[0]) == JIM_OK) {
+ if (JimMakeChannel(interp, NULL, p[0], filename, hdlfmt, family, mode[0])) {
Jim_Obj *objPtr = Jim_NewListObj(interp, NULL, 0);
Jim_ListAppendElement(interp, objPtr, Jim_GetResult(interp));
- if (JimMakeChannel(interp, NULL, p[1], filename, hdlfmt, family, mode[1]) == JIM_OK) {
+ if (JimMakeChannel(interp, NULL, p[1], filename, hdlfmt, family, mode[1])) {
Jim_ListAppendElement(interp, objPtr, Jim_GetResult(interp));
Jim_SetResult(interp, objPtr);
return JIM_OK;
@@ -1765,7 +1767,7 @@ static int JimAioSockCommand(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
return JIM_ERR;
}
- return JimMakeChannel(interp, NULL, sock, argv[1], hdlfmt, family, mode);
+ return JimMakeChannel(interp, NULL, sock, argv[1], hdlfmt, family, mode) ? JIM_OK : JIM_ERR;
}
#endif /* JIM_BOOTSTRAP */