res_pjproject: Add utility functions to convert between socket structures

Currently, to convert from a pj_sockaddr to an ast_sockaddr, the address
needs to be rendered to a string and then parsed into the correct
structure. This also involves a call to getaddrinfo(3). The same is true
for the inverse operation.

Instead, because we know the internal structure of both ast_sockaddr and
pj_sockaddr, we can translate directly between the two without the
need for an intermediate string.

Change-Id: If0fc4bba9643f755604c6ffbb0d7cc46020bc761
This commit is contained in:
Sean Bright
2018-08-28 09:42:13 -04:00
parent 16df182155
commit 600c5d79fd
3 changed files with 205 additions and 1 deletions

View File

@@ -22,6 +22,8 @@
#include <pj/types.h>
#include <pj/pool.h>
struct ast_sockaddr;
/*!
* \brief Retrieve a pjproject build option
*
@@ -97,4 +99,28 @@ void ast_pjproject_caching_pool_init(pj_caching_pool *cp,
*/
void ast_pjproject_caching_pool_destroy(pj_caching_pool *cp);
/*!
* \brief Fill a pj_sockaddr from an ast_sockaddr
* \since 13.24.0
*
* \param addr The source address to copy
* \param pjaddr The target address to receive the copied address
*
* \retval 0 Success
* \retval -1 Failure
*/
int ast_sockaddr_to_pj_sockaddr(const struct ast_sockaddr *addr, pj_sockaddr *pjaddr);
/*!
* \brief Fill an ast_sockaddr from a pj_sockaddr
* \since 13.24.0
*
* \param addr The target address to receive the copied address
* \param pjaddr The source address to copy
*
* \retval 0 Success
* \retval -1 Failure
*/
int ast_sockaddr_from_pj_sockaddr(struct ast_sockaddr *addr, const pj_sockaddr *pjaddr);
#endif /* _RES_PJPROJECT_H */