17 #include <sipwitch-config.h>
18 #include <ucommon/ucommon.h>
19 #include <ucommon/export.h>
27 const char *cp = strchr(addr,
'@');
29 String::set(buf, size, ++cp);
33 if(String::equal(addr,
"sip:", 4))
35 else if(String::equal(addr,
"sips:", 5))
38 String::set(buf, size, addr);
53 if(!strnicmp(addr,
"sip:", 4))
55 else if(!strnicmp(addr,
"sips:", 5))
58 cp = strchr(addr,
'@');
62 String::set(buf, size, addr);
64 ep = strchr(buf,
']');
66 ep = strrchr(buf,
':');
84 if(!strnicmp(addr,
"sip:", 4))
86 else if(!strnicmp(addr,
"sips:", 5))
89 if(!strchr(addr,
'@'))
92 String::set(buf, size, addr);
93 ep = strchr(buf,
'@');
101 const char *pp = NULL;
102 const char *fp = NULL;
104 if(eq(uri,
"sips:", 5))
106 else if(eq(uri,
"sip:", 4)) {
111 pp = strchr(uri,
']');
113 pp = strchr(pp,
':');
116 pp = strrchr(uri,
':');
117 fp = strchr(uri,
':');
131 assert(user == NULL || *user != 0);
134 const char *schema =
"sip";
137 if(String::equal(uri,
"sip:", 4)) {
141 else if(String::equal(uri,
"sips:", 5)) {
146 cp = strchr(uri,
'@');
147 if(cp && user != NULL)
151 snprintf(buf, size,
"%s:%s@%s", schema, user, uri);
153 snprintf(buf, size,
"%s:%s", schema, uri);
159 const char *schema=
"sip:";
162 if(eq(uri,
"sips:", 5)) {
167 else if(!strncmp(uri,
"sip:", 4))
169 else if(!strncmp(uri,
"tcp:", 4)) {
173 else if(!strncmp(uri,
"udp:", 4)) {
178 const char *sp = strchr(uri,
'@');
182 snprintf(buf, size,
"%s%s", schema, uri);
188 assert(addr != NULL);
196 if(!Socket::query(addr, host,
sizeof(host)))
200 if(addr->sa_family == AF_INET6)
201 snprintf(buf, size,
"sip:[%s]:%u", host, (
unsigned)ntohs(((
struct sockaddr_in6 *)(addr))->sin6_port) & 0xffff);
204 snprintf(buf, size,
"sip:%s:%u", host, (
unsigned)ntohs(((
struct sockaddr_in *)(addr))->sin_port) & 0xffff);
208 void uri::identity(
const struct sockaddr *addr,
char *buf,
const char *user,
size_t size)
210 assert(addr != NULL);
212 assert(user == NULL || *user != 0);
219 String::add(buf, size, user);
220 String::add(buf, size,
"@");
224 Socket::query(addr, buf + len, size - len);
Some convenience methods for manipulating SIP uri's.
static void identity(const struct sockaddr *address, char *buffer, const char *user, size_t size)
static bool userid(const char *sipuri, char *buffer, size_t size)
static voip::context_t udp_context
static voip::context_t tls_context
Manipulate address strings.
static void serviceid(const char *sipuri, char *buffer, size_t size)
static voip::context_t route(const char *uri, char *buf, size_t size)
static voip::context_t tcp_context
static bool server(struct sockaddr *address, char *buffer, size_t size)
Service configuration and component callbacks.
static voip::context_t out_context
static bool hostid(const char *sipuri, char *buffer, size_t size)
static void publish(const char *uri, char *buffer, const char *user, size_t size)
static unsigned short portid(const char *sipuri)