Prechádzať zdrojové kódy

Merge branch 'cvs-head' of git://git.sip-router.org/ser_modules into ser_modules

* 'cvs-head' of git://git.sip-router.org/ser_modules:
  tls: don't start if tcp is in async mode
  tls: fixed missing TCP_BUF_SIZE
Andrei Pelinescu-Onciul 16 rokov pred
rodič
commit
35ce8821dd
2 zmenil súbory, kde vykonal 63 pridanie a 1 odobranie
  1. 6 0
      modules_s/tls/tls_mod.c
  2. 57 1
      modules_s/tls/tls_server.c

+ 6 - 0
modules_s/tls/tls_mod.c

@@ -301,6 +301,12 @@ static int mod_init(void)
 				"(set enable_tls=1 in the config to enable it)\n");
 		return 0;
 	}
+
+	if (cfg_get(tcp, tcp_cfg, async) && !tls_force_run){
+		ERR("tls does not support tcp in async mode, please use"
+				" tcp_async=no in the config file\n");
+		return -1;
+	}
 	     /* Convert tls_method parameter to integer */
 	method = tls_parse_method(&tls_method);
 	if (method < 0) {

+ 57 - 1
modules_s/tls/tls_server.c

@@ -799,6 +799,62 @@ again:
 }
 
 
+
+/* nonblocking version */
+int tls_h_nonblocking_write(struct tcp_connection *c, int fd, const char *buf,
+			  unsigned int len)
+{
+	int err, n;
+	
+	n = 0;
+	if (tls_update_fd(c, fd) < 0) goto error;
+again:
+	err = 0;
+	if (c->state == S_CONN_CONNECT) {
+		if (tls_connect(c, &err) < 0) goto error;
+	} else if (c->state == S_CONN_ACCEPT) {
+		if (tls_accept(c, &err) < 0) goto error;
+	}
+	if (c->state!=S_CONN_CONNECT && c->state!=S_CONN_ACCEPT){
+		n = tls_write(c, buf, len, &err);
+		if (n < 0) {
+			DBG("tls_write error %d (ssl %d)\n", n, err);
+			goto error;
+		} else if (n==len){
+			goto end;
+		}else{
+			DBG("%ld bytes still need to be written\n", 
+				(long)(len - n));
+		}
+	}else
+		n=0; /* no bytes written */
+
+		switch(err){
+			/* TODO: set some flag: WANT_READ, WANT_WRITE */
+			case 0:
+			case SSL_ERROR_WANT_WRITE:
+				break;
+			case SSL_ERROR_WANT_READ:
+				break;
+#if OPENSSL_VERSION_NUMBER >= 0x00907000L /*0.9.7*/
+			case SSL_ERROR_WANT_ACCEPT:
+#endif
+			case SSL_ERROR_WANT_CONNECT:
+				DBG("re-trying accept/connect\n");
+				break;
+			default:
+				BUG("Unhandled SSL error %d\n", err);
+				goto error;
+		}
+	
+error:
+	return -1;
+end:
+	return n;
+}
+
+
+
 /*
  * called only when a connection is in S_CONN_OK, we do not have to care
  * about accepting or connecting here, each modification of ssl data
@@ -813,7 +869,7 @@ int tls_h_read(struct tcp_connection * c)
 	SSL* ssl;
 
 	r = &c->req;
-	bytes_free = TCP_BUF_SIZE - (int)(r->pos - r->buf);
+	bytes_free = c->req.b_size - (int)(r->pos - r->buf);
 	
 	if (bytes_free == 0) {
 		ERR("Buffer overrun, dropping\n");