From 4e5708fbe452fc32e4dc2fca48c67a0914af4a87 Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Mon, 9 Jul 2018 09:46:10 +0800 Subject: [PATCH] make all C callback function unexported --- _gnutls.h | 8 ++++---- gnutls.c | 8 ++++---- tls.go | 24 ++++++++++++------------ 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/_gnutls.h b/_gnutls.h index acfef48..60991ad 100644 --- a/_gnutls.h +++ b/_gnutls.h @@ -14,9 +14,9 @@ struct session void *data; }; -extern int OnDataReadCallback(void *, char *, int); -extern int OnDataWriteCallback(void *, char *, int); -extern int OnDataTimeoutRead(void *, int); +extern int onDataReadCallback(void *, char *, int); +extern int onDataWriteCallback(void *, char *, int); +extern int onDataTimeoutRead(void *, int); struct session *init_gnutls_client_session(); struct session *init_gnutls_server_session(); @@ -31,7 +31,7 @@ int set_callback(struct session *sess); void session_destroy(struct session *); -int OnCertSelectCallback(void *ptr, char *hostname, int namelen, +int onCertSelectCallback(void *ptr, char *hostname, int namelen, int *pcert_length, gnutls_pcert_st **cert, gnutls_privkey_t *privke); gnutls_cipher_hd_t new_cipher(int cipher_type, char *key, int keylen, char *iv, int ivlen); diff --git a/gnutls.c b/gnutls.c index 6dffda3..8ed4047 100644 --- a/gnutls.c +++ b/gnutls.c @@ -85,24 +85,24 @@ int cert_select_callback(gnutls_session_t sess, const gnutls_datum_t *req_ca_dn, //return -1; } //printf("call go callback\n"); - ret = OnCertSelectCallback(ptr, hostname, namelen, pcert_length, pcert, pkey); + ret = onCertSelectCallback(ptr, hostname, namelen, pcert_length, pcert, pkey); //printf("after callback pcert_length %d, pcert 0x%x, pkey 0x%x\n", *pcert_length, pcert, pkey); return ret; } ssize_t pull_function(gnutls_transport_ptr_t ptr, void *data, size_t len) { - return OnDataReadCallback(ptr, data, len); + return onDataReadCallback(ptr, data, len); } int pull_timeout_function(gnutls_transport_ptr_t ptr, unsigned int ms) { - return OnDataTimeoutRead(ptr, ms); + return onDataTimeoutRead(ptr, ms); } ssize_t push_function(gnutls_transport_ptr_t ptr, const void *data, size_t len) { - return OnDataWriteCallback(ptr, (char *)data, len); + return onDataWriteCallback(ptr, (char *)data, len); } void set_data(struct session *sess, size_t data) diff --git a/tls.go b/tls.go index 037147f..f47f0de 100644 --- a/tls.go +++ b/tls.go @@ -341,10 +341,10 @@ func (c *Conn) getServerName() string { return name } -// OnDataReadCallback callback function for gnutls library want to read data from network +// onDataReadCallback callback function for gnutls library want to read data from network // -//export OnDataReadCallback -func OnDataReadCallback(d unsafe.Pointer, cbuf *C.char, bufLen C.int) C.int { +//export onDataReadCallback +func onDataReadCallback(d unsafe.Pointer, cbuf *C.char, bufLen C.int) C.int { //log.Println("read addr ", uintptr(d)) conn := (*Conn)(unsafe.Pointer((uintptr(d)))) buf := make([]byte, int(bufLen)) @@ -360,10 +360,10 @@ func OnDataReadCallback(d unsafe.Pointer, cbuf *C.char, bufLen C.int) C.int { return C.int(n) } -// OnDataWriteCallback callback function for gnutls library want to send data to network +// onDataWriteCallback callback function for gnutls library want to send data to network // -//export OnDataWriteCallback -func OnDataWriteCallback(d unsafe.Pointer, cbuf *C.char, bufLen C.int) C.int { +//export onDataWriteCallback +func onDataWriteCallback(d unsafe.Pointer, cbuf *C.char, bufLen C.int) C.int { //log.Println("write addr ", uintptr(d), int(_l)) conn := (*Conn)(unsafe.Pointer((uintptr(d)))) gobuf := C.GoBytes(unsafe.Pointer(cbuf), bufLen) @@ -375,22 +375,22 @@ func OnDataWriteCallback(d unsafe.Pointer, cbuf *C.char, bufLen C.int) C.int { return C.int(n) } -// OnDataTimeoutRead callback function for timeout read +// onDataTimeoutRead callback function for timeout read // -//export OnDataTimeoutRead -func OnDataTimeoutRead(d unsafe.Pointer, delay C.int) C.int { +//export onDataTimeoutRead +func onDataTimeoutRead(d unsafe.Pointer, delay C.int) C.int { log.Println("timeout pull function") return 0 } -// OnCertSelectCallback callback function for ceritificate select, +// onCertSelectCallback callback function for ceritificate select, // this function select certificate from Config.Certificates field, // // on server side, this function select the certificate depend on SNI what client send, // if client not send SNI, select the Config.Certificates[0] // -//export OnCertSelectCallback -func OnCertSelectCallback(ptr unsafe.Pointer, hostname *C.char, +//export onCertSelectCallback +func onCertSelectCallback(ptr unsafe.Pointer, hostname *C.char, namelen C.int, pcertLength *C.int, cert **C.gnutls_pcert_st, privkey *C.gnutls_privkey_t) C.int { servername := C.GoStringN(hostname, namelen)