@@ -62,6 +62,14 @@ typedef struct tport_nat_s tport_nat_t;
6262#include <errno.h>
6363#include <limits.h>
6464
65+ #if HAVE_WIN32
66+ #include <io.h>
67+ #define access (_filename , _mode ) _access(_filename, _mode)
68+ #define R_OK (04)
69+ #else
70+ #include <unistd.h>
71+ #endif
72+
6573#ifndef IPPROTO_SCTP
6674#define IPPROTO_SCTP (132)
6775#endif
@@ -71,6 +79,7 @@ typedef struct tport_nat_s tport_nat_t;
7179#include <sofia-sip/rbtree.h>
7280
7381#include "tport_internal.h"
82+ #include "tport_tls.h"
7483
7584#if HAVE_FUNC
7685#elif HAVE_FUNCTION
@@ -280,6 +289,42 @@ int tport_is_verified(tport_t const *self)
280289 return tport_has_tls (self ) && self -> tp_is_connected && self -> tp_verified ;
281290}
282291
292+ /** Reload TLS certificates on all TLS primary transports. */
293+ int tport_reload_tls (tport_t * self , char const * cert_dir )
294+ {
295+ su_home_t autohome [SU_HOME_AUTO_SIZE (1024 )];
296+ char const * cert , * cafile ;
297+ tport_t * tp ;
298+ int reloaded = 0 ;
299+
300+ if (!self || !cert_dir )
301+ return -1 ;
302+
303+ su_home_auto (autohome , sizeof autohome );
304+
305+ cert = su_sprintf (autohome , "%s/%s" , cert_dir , "agent.pem" );
306+ if (access (cert , R_OK ) != 0 )
307+ cert = su_sprintf (autohome , "%s/%s" , cert_dir , "tls.pem" );
308+
309+ cafile = su_sprintf (autohome , "%s/%s" , cert_dir , "cafile.pem" );
310+ if (access (cafile , R_OK ) != 0 )
311+ cafile = su_sprintf (autohome , "%s/%s" , cert_dir , "tls.pem" );
312+
313+ for (tp = tport_primaries (self ); tp ; tp = tport_next (tp )) {
314+ if (tport_has_tls (tp )) {
315+ tport_tls_primary_t * tlspri = (tport_tls_primary_t * )tp -> tp_pri ;
316+ if (tlspri -> tlspri_master ) {
317+ if (tls_reload_cert (tlspri -> tlspri_master , cert , cert , cafile ) == 0 )
318+ reloaded ++ ;
319+ }
320+ }
321+ }
322+
323+ su_home_deinit (autohome );
324+
325+ return reloaded ;
326+ }
327+
283328/** Return true if transport is being updated. */
284329int tport_is_updating (tport_t const * self )
285330{
0 commit comments