5353#include "rtpp_tnotify_set.h"
5454#include "rtpp_tnotify_tgt.h"
5555#include "rtpp_mallocs.h"
56+ #include "rtpp_util.h"
5657
5758#define RTPP_TNOTIFY_TARGETS_MAX 64
5859#define RTPP_TNOTIFY_WILDCARDS_MAX 2
6162
6263struct rtpp_tnotify_wildcard {
6364 char * socket_name ;
64- int socket_type ;
65+ enum rtpp_tnotify_stype socket_type ;
6566 int port ;
6667};
6768
@@ -177,18 +178,28 @@ parse_timeout_sock(const char *sock_name, union rtpp_tnotify_entry *rtep,
177178 sprefix = NULL ;
178179 if (strncmp ("unix:" , sock_name , 5 ) == 0 ) {
179180 usock_name = sock_name + 5 ;
180- rtep -> rtt .socket_type = AF_LOCAL ;
181+ rtep -> rtt .socket_type = RTPP_TNS_LOCAL ;
181182 } else if (strncmp ("tcp:" , sock_name , 4 ) == 0 ) {
182183 if (parse_hostport (sock_name + 4 , host , sizeof (host ), port , sizeof (port ), 0 , e ) != 0 ) {
183184 return (-1 );
184185 }
185- rtep -> rtt .socket_type = AF_INET ;
186+ rtep -> rtt .socket_type = RTPP_TNS_INET ;
187+ #if defined(LIBRTPPROXY )
188+ } else if (strncmp ("fd:" , sock_name , 3 ) == 0 ) {
189+ int fd ;
190+ if (atoi_safe (sock_name + 3 , & fd ) != ATOI_OK || fd < 0 ) {
191+ return (-1 );
192+ }
193+ rtep -> rtt .socket_type = RTPP_TNS_FD ;
194+ rtep -> rtt .fd = fd ;
195+ #endif
186196 } else {
187197 sprefix = "unix:" ;
188198 usock_name = sock_name ;
189- rtep -> rtt .socket_type = AF_LOCAL ;
199+ rtep -> rtt .socket_type = RTPP_TNS_LOCAL ;
190200 }
191- if (rtep -> rtt .socket_type == AF_UNIX ) {
201+ switch (rtep -> rtt .socket_type ) {
202+ case RTPP_TNS_LOCAL :
192203 if (strlen (usock_name ) == 0 ) {
193204 * e = "Timeout notification socket name too short" ;
194205 return (-1 );
@@ -200,19 +211,26 @@ parse_timeout_sock(const char *sock_name, union rtpp_tnotify_entry *rtep,
200211 ifsun -> sun_len = strlen (ifsun -> sun_path );
201212#endif
202213 rtep -> rtt .remote_len = sizeof (struct sockaddr_un );
203- } else if (rtep -> rtt .socket_type == AF_INET && strcmp (host , CC_SELF_STR ) == 0 ) {
204- rtep -> rtw .socket_type = AF_INET ;
205- rtep -> rtw .port = atoi (port );
206- snp = & rtep -> rtt .socket_name ;
207- rval = 1 ;
208- } else {
214+ break ;
215+
216+ case RTPP_TNS_INET :
217+ if (strcmp (host , CC_SELF_STR ) == 0 ) {
218+ rtep -> rtw .socket_type = RTPP_TNS_INET ;
219+ rtep -> rtw .port = atoi (port );
220+ snp = & rtep -> rtt .socket_name ;
221+ rval = 1 ;
222+ break ;
223+ }
209224 ifsa = sstosa (& rtep -> rtt .remote );
210225 n = resolve (ifsa , AF_INET , host , port , 0 );
211226 if (n != 0 ) {
212227 * e = gai_strerror (n );
213228 return (-1 );
214229 }
215230 rtep -> rtt .remote_len = SA_LEN (ifsa );
231+ break ;
232+ default :
233+ break ;
216234 }
217235 int snlen = (sprefix == NULL ) ? strlen (sock_name ) :
218236 strlen (sprefix ) + strlen (usock_name );
@@ -261,8 +279,12 @@ rtpp_tnotify_set_append(struct rtpp_tnotify_set *pub,
261279 goto e1 ;
262280 }
263281 memcpy (tntp , & rte .rtt , sizeof (struct rtpp_tnotify_target ));
264- tntp -> connected = 0 ;
265- tntp -> fd = -1 ;
282+ if (tntp -> socket_type != RTPP_TNS_FD ) {
283+ tntp -> connected = 0 ;
284+ tntp -> fd = -1 ;
285+ } else {
286+ tntp -> connected = 1 ;
287+ }
266288 pvt -> tp [pvt -> tp_len ] = tntp ;
267289 pvt -> tp_len += 1 ;
268290 } else {
@@ -321,6 +343,7 @@ get_tp4wp(struct rtpp_tnotify_set_priv *pvt, struct rtpp_tnotify_wildcard *wp,
321343 continue ;
322344 return (tp );
323345 }
346+ assert (wp -> socket_type != RTPP_TNS_FD );
324347 /* Nothing found, crank up a new entry */
325348 if (pvt -> tp_len == RTPP_TNOTIFY_TARGETS_MAX ) {
326349 return (NULL );
@@ -375,19 +398,22 @@ rtpp_tnotify_set_lookup(struct rtpp_tnotify_set *pub, const char *socket_name,
375398 for (i = 0 ; i < pvt -> tp_len ; i ++ ) {
376399 if (pvt -> tp [i ]-> socket_name == NULL )
377400 continue ;
378- if (pvt -> tp [i ]-> socket_type != AF_LOCAL ||
401+ if (pvt -> tp [i ]-> socket_type != RTPP_TNS_LOCAL ||
379402 strcmp (pvt -> tp [i ]-> socket_name + 5 , socket_name ) != 0 )
380403 continue ;
381404 return (pvt -> tp [i ]);
382405 }
383406 return (NULL );
407+ } else if (sep - socket_name == 2 && memcmp (socket_name , "fd" , 2 ) == 0 ) {
408+ /* RTPP_TNS_FD can only match directly */
409+ return (NULL );
384410 }
385411 /* Handle wildcards */
386412 for (i = 0 ; i < pvt -> wp_len ; i ++ ) {
387413 wp = pvt -> wp [i ];
388414 if (strcmp (wp -> socket_name , socket_name ) != 0 )
389415 continue ;
390- if (ccaddr != NULL && wp -> socket_type != ccaddr -> sa_family )
416+ if (ccaddr != NULL && RTPP_TNT_STYPE ( wp ) != ccaddr -> sa_family )
391417 continue ;
392418 return (get_tp4wp (pvt , wp , ccaddr , laddr ));
393419 }
0 commit comments