[前][次][番号順一覧][スレッド一覧]

ruby-changes:36710

From: nobu <ko1@a...>
Date: Sat, 13 Dec 2014 06:57:54 +0900 (JST)
Subject: [ruby-changes:36710] nobu:r48790 (trunk): ossl_ssl.h: accessor macros

nobu	2014-12-13 06:57:33 +0900 (Sat, 13 Dec 2014)

  New Revision: 48790

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48790

  Log:
    ossl_ssl.h: accessor macros
    
    * ext/openssl/ossl_ssl.c (GetSSLCTX): accessor macro.
    * ext/openssl/ossl_ssl.h (GetSSL): ditto.

  Modified files:
    trunk/ext/openssl/ossl_ssl.c
    trunk/ext/openssl/ossl_ssl.h
    trunk/ext/openssl/ossl_ssl_session.c
Index: ext/openssl/ossl_ssl.c
===================================================================
--- ext/openssl/ossl_ssl.c	(revision 48789)
+++ ext/openssl/ossl_ssl.c	(revision 48790)
@@ -24,6 +24,10 @@ https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L24
 #  define TO_SOCKET(s) (s)
 #endif
 
+#define GetSSLCTX(obj, ctx) do { \
+	Data_Get_Struct((obj), SSL_CTX, (ctx)); \
+} while (0)
+
 VALUE mSSL;
 VALUE eSSLError;
 VALUE cSSLContext;
@@ -203,7 +207,7 @@ ossl_sslctx_set_ssl_version(VALUE self, https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L207
     if (!method) {
         ossl_raise(rb_eArgError, "unknown SSL method `%s'.", s);
     }
-    Data_Get_Struct(self, SSL_CTX, ctx);
+    GetSSLCTX(self, ctx);
     if (SSL_CTX_set_ssl_version(ctx, method) != 1) {
         ossl_raise(eSSLError, "SSL_CTX_set_ssl_version");
     }
@@ -244,7 +248,7 @@ ossl_call_client_cert_cb(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L248
     VALUE cb, ary, cert, key;
     SSL *ssl;
 
-    Data_Get_Struct(obj, SSL, ssl);
+    GetSSL(obj, ssl);
     cb = (VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_client_cert_cb_idx);
     if (NIL_P(cb)) return Qfalse;
     ary = rb_funcall(cb, rb_intern("call"), 1, obj);
@@ -280,7 +284,7 @@ ossl_call_tmp_dh_callback(VALUE *args) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L284
     VALUE cb, dh;
     EVP_PKEY *pkey;
 
-    Data_Get_Struct(args[0], SSL, ssl);
+    GetSSL(args[0], ssl);
     cb = (VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_tmp_dh_callback_idx);
     if (NIL_P(cb)) return Qfalse;
     dh = rb_funcall(cb, rb_intern("call"), 3, args[0], args[1], args[2]);
@@ -482,7 +486,7 @@ ossl_sslctx_add_extra_chain_cert_i(RB_BL https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L486
     X509 *x509;
     SSL_CTX *ctx;
 
-    Data_Get_Struct(arg, SSL_CTX, ctx);
+    GetSSLCTX(arg, ctx);
     x509 = DupX509CertPtr(i);
     if(!SSL_CTX_add_extra_chain_cert(ctx, x509)){
 	ossl_raise(eSSLError, NULL);
@@ -513,8 +517,8 @@ ossl_call_servername_cb(VALUE ary) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L517
         SSL_CTX *ctx2;
 
         ossl_sslctx_setup(ret_obj);
-        Data_Get_Struct(ssl_obj, SSL, ssl);
-        Data_Get_Struct(ret_obj, SSL_CTX, ctx2);
+        GetSSL(ssl_obj, ssl);
+        GetSSLCTX(ret_obj, ctx2);
         SSL_set_SSL_CTX(ssl, ctx2);
     } else if (!NIL_P(ret_obj)) {
             ossl_raise(rb_eArgError, "servername_cb must return an OpenSSL::SSL::SSLContext object or nil");
@@ -665,7 +669,7 @@ ossl_sslctx_setup(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L669
     VALUE val;
 
     if(OBJ_FROZEN(self)) return Qnil;
-    Data_Get_Struct(self, SSL_CTX, ctx);
+    GetSSLCTX(self, ctx);
 
 #if !defined(OPENSSL_NO_DH)
     if (RTEST(ossl_sslctx_get_tmp_dh_cb(self))){
@@ -841,7 +845,7 @@ ossl_sslctx_get_ciphers(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L845
     VALUE ary;
     int i, num;
 
-    Data_Get_Struct(self, SSL_CTX, ctx);
+    GetSSLCTX(self, ctx);
     if(!ctx){
         rb_warning("SSL_CTX is not initialized.");
         return Qnil;
@@ -896,7 +900,7 @@ ossl_sslctx_set_ciphers(VALUE self, VALU https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L900
         StringValue(str);
     }
 
-    Data_Get_Struct(self, SSL_CTX, ctx);
+    GetSSLCTX(self, ctx);
     if(!ctx){
         ossl_raise(eSSLError, "SSL_CTX is not initialized.");
         return Qnil;
@@ -920,7 +924,7 @@ ossl_sslctx_session_add(VALUE self, VALU https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L924
     SSL_CTX *ctx;
     SSL_SESSION *sess;
 
-    Data_Get_Struct(self, SSL_CTX, ctx);
+    GetSSLCTX(self, ctx);
     SafeGetSSLSession(arg, sess);
 
     return SSL_CTX_add_session(ctx, sess) == 1 ? Qtrue : Qfalse;
@@ -938,7 +942,7 @@ ossl_sslctx_session_remove(VALUE self, V https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L942
     SSL_CTX *ctx;
     SSL_SESSION *sess;
 
-    Data_Get_Struct(self, SSL_CTX, ctx);
+    GetSSLCTX(self, ctx);
     SafeGetSSLSession(arg, sess);
 
     return SSL_CTX_remove_session(ctx, sess) == 1 ? Qtrue : Qfalse;
@@ -955,7 +959,7 @@ ossl_sslctx_get_session_cache_mode(VALUE https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L959
 {
     SSL_CTX *ctx;
 
-    Data_Get_Struct(self, SSL_CTX, ctx);
+    GetSSLCTX(self, ctx);
 
     return LONG2NUM(SSL_CTX_get_session_cache_mode(ctx));
 }
@@ -973,7 +977,7 @@ ossl_sslctx_set_session_cache_mode(VALUE https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L977
 {
     SSL_CTX *ctx;
 
-    Data_Get_Struct(self, SSL_CTX, ctx);
+    GetSSLCTX(self, ctx);
 
     SSL_CTX_set_session_cache_mode(ctx, NUM2LONG(arg));
 
@@ -992,7 +996,7 @@ ossl_sslctx_get_session_cache_size(VALUE https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L996
 {
     SSL_CTX *ctx;
 
-    Data_Get_Struct(self, SSL_CTX, ctx);
+    GetSSLCTX(self, ctx);
 
     return LONG2NUM(SSL_CTX_sess_get_cache_size(ctx));
 }
@@ -1009,7 +1013,7 @@ ossl_sslctx_set_session_cache_size(VALUE https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L1013
 {
     SSL_CTX *ctx;
 
-    Data_Get_Struct(self, SSL_CTX, ctx);
+    GetSSLCTX(self, ctx);
 
     SSL_CTX_sess_set_cache_size(ctx, NUM2LONG(arg));
 
@@ -1044,7 +1048,7 @@ ossl_sslctx_get_session_cache_stats(VALU https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L1048
     SSL_CTX *ctx;
     VALUE hash;
 
-    Data_Get_Struct(self, SSL_CTX, ctx);
+    GetSSLCTX(self, ctx);
 
     hash = rb_hash_new();
     rb_hash_aset(hash, ID2SYM(rb_intern("cache_num")), LONG2NUM(SSL_CTX_sess_number(ctx)));
@@ -1079,7 +1083,7 @@ ossl_sslctx_flush_sessions(int argc, VAL https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L1083
 
     rb_scan_args(argc, argv, "01", &arg1);
 
-    Data_Get_Struct(self, SSL_CTX, ctx);
+    GetSSLCTX(self, ctx);
 
     if (NIL_P(arg1)) {
         tm = time(0);
@@ -1177,14 +1181,14 @@ ossl_ssl_setup(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L1181
     SSL *ssl;
     rb_io_t *fptr;
 
-    Data_Get_Struct(self, SSL, ssl);
+    GetSSL(self, ssl);
     if(!ssl){
 #ifdef HAVE_SSL_SET_TLSEXT_HOST_NAME
 	VALUE hostname = rb_iv_get(self, "@hostname");
 #endif
 
         v_ctx = ossl_ssl_get_ctx(self);
-        Data_Get_Struct(v_ctx, SSL_CTX, ctx);
+        GetSSLCTX(v_ctx, ctx);
 
         ssl = SSL_new(ctx);
         if (!ssl) {
@@ -1224,7 +1228,7 @@ ossl_ssl_setup(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L1228
 
 #define ossl_ssl_data_get_struct(v, ssl)		\
 do {							\
-    Data_Get_Struct((v), SSL, (ssl));			\
+    GetSSL((v), (ssl)); 				\
     if (!(ssl)) {					\
         rb_warning("SSL session is not started yet.");  \
         return Qnil;					\
@@ -1394,7 +1398,7 @@ ossl_ssl_read_internal(int argc, VALUE * https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L1398
     }
     if(ilen == 0) return str;
 
-    Data_Get_Struct(self, SSL, ssl);
+    GetSSL(self, ssl);
     GetOpenFile(ossl_ssl_get_io(self), fptr);
     if (ssl) {
 	if(!nonblock && SSL_pending(ssl) <= 0)
@@ -1486,7 +1490,7 @@ ossl_ssl_write_internal(VALUE self, VALU https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L1490
     rb_io_t *fptr;
 
     StringValue(str);
-    Data_Get_Struct(self, SSL, ssl);
+    GetSSL(self, ssl);
     GetOpenFile(ossl_ssl_get_io(self), fptr);
 
     if (ssl) {
@@ -1571,7 +1575,7 @@ ossl_ssl_close(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L1575
     /* ossl_ssl_data_get_struct() is not usable here because it may return
      * from this function; */
 
-    Data_Get_Struct(self, SSL, ssl);
+    GetSSL(self, ssl);
 
     io = ossl_ssl_get_io(self);
     if (!RTEST(rb_funcall(io, rb_intern("closed?"), 0))) {
Index: ext/openssl/ossl_ssl.h
===================================================================
--- ext/openssl/ossl_ssl.h	(revision 48789)
+++ ext/openssl/ossl_ssl.h	(revision 48790)
@@ -11,6 +11,10 @@ https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.h#L11
 #if !defined(_OSSL_SSL_H_)
 #define _OSSL_SSL_H_
 
+#define GetSSL(obj, ssl) do { \
+	Data_Get_Struct((obj), SSL, (ssl)); \
+} while (0)
+
 #define GetSSLSession(obj, sess) do { \
 	Data_Get_Struct((obj), SSL_SESSION, (sess)); \
 	if (!(sess)) { \
Index: ext/openssl/ossl_ssl_session.c
===================================================================
--- ext/openssl/ossl_ssl_session.c	(revision 48789)
+++ ext/openssl/ossl_ssl_session.c	(revision 48790)
@@ -43,7 +43,7 @@ static VALUE ossl_ssl_session_initialize https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl_session.c#L43
 	if (rb_obj_is_instance_of(arg1, cSSLSocket)) {
 		SSL *ssl;
 
-		Data_Get_Struct(arg1, SSL, ssl);
+		GetSSL(arg1, ssl);
 
 		if (!ssl || (ctx = SSL_get1_session(ssl)) == NULL)
 			ossl_raise(eSSLSession, "no session available");

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]