19 #include <sipwitch-config.h>
21 #include <ucommon/ucommon.h>
23 static int verbose = 0;
25 static int family = AF_INET;
26 static int protocol = IPPROTO_UDP;
27 static const char *server = NULL;
28 static const char *forwarded = NULL;
29 static const char *proxy = NULL;
30 static const char *binding = NULL;
31 static unsigned timeout = 1000;
34 #if defined(EXOSIP_OPT_BASE_OPTION) && !defined(EXOSIP_OPT_DONT_SEND_101)
39 #define EXOSIP_CONTEXT context
40 #define OPTION_CONTEXT context,
41 #define EXOSIP_LOCK eXosip_lock(context);
42 #define EXOSIP_UNLOCK eXosip_unlock(context);
43 static struct eXosip_t *context = NULL;
45 #define EXOSIP_LOCK eXosip_lock();
46 #define EXOSIP_UNLOCK eXosip_unlock();
47 #define EXOSIP_CONTEXT
48 #define OPTION_CONTEXT
51 using namespace ucommon;
53 #if defined(_MSWINDOWS_) && defined(__GNUC__)
56 static Socket::address localhost(
"127.0.0.1");
63 const char *cp, *user;
73 cp = getenv(
"SIP_PROXY");
77 cp = getenv(
"SIP_SERVER");
82 while(NULL != *(++argv)) {
83 if(!strcmp(*argv,
"--")) {
88 if(!strncmp(*argv,
"--", 2))
91 if(!strcmp(*argv,
"-q") || !strcmp(*argv,
"-quiet")) {
96 if(!strcmp(*argv,
"-version")) {
97 printf(
"sipquery 0.1\n"
98 "Copyright (C) 2008 David Sugar, Tycho Softworks\n"
99 "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n"
100 "This is free software: you are free to change and redistribute it.\n"
101 "There is NO WARRANTY, to the extent permitted by law.\n");
105 if(!strcmp(*argv,
"-v") || !strcmp(*argv,
"-verbose")) {
111 if(!strcmp(*argv,
"-t") || !strcmp(*argv,
"-timeout")) {
112 if(NULL == *(++argv))
113 shell::errexit(3,
"*** sipuser: timeout option missing timeout\n");
114 timeout = atoi(*argv) * 1000;
116 shell::errexit(3,
"*** sipuser: timeout option invalid\n");
121 if(!strncmp(*argv,
"-timeout=", 9)) {
122 timeout = atoi(*argv + 9) * 1000;
124 shell::errexit(3,
"*** sipuser: timeout option invalid\n");
129 if(!strcmp(*argv,
"-p") || !strcmp(*argv,
"-port")) {
130 if(NULL == *(++argv))
131 shell::errexit(3,
"*** sipuser: port option missing port\n");
135 shell::errexit(3,
"*** sipuser: port option invalid number\n");
140 if(!strncmp(*argv,
"-port=", 6)) {
141 port = atoi(*argv + 6);
143 shell::errexit(3,
"*** sipuser: port option invalid number\n");
148 if(!strcmp(*argv,
"-proxy")) {
151 shell::errexit(3,
"*** sipuser: proxy option missing proxy\n");
155 if(!strncmp(*argv,
"-proxy=", 7)) {
160 if(!strcmp(*argv,
"-server")) {
163 shell::errexit(3,
"*** sipuser: server option missing proxy\n");
167 if(!strncmp(*argv,
"-server=", 8)) {
172 if(!strcmp(*argv,
"-forward")) {
173 forwarded = *(++argv);
175 shell::errexit(3,
"*** sipuser: forwarding option missing interface\n");
179 if(!strncmp(*argv,
"-forward=", 9)) {
180 forwarded = *argv + 8;
184 if(!strcmp(*argv,
"-?") || !strcmp(*argv,
"-h") || !strcmp(*argv,
"-help")) {
185 fprintf(stderr,
"usage: sipuser [options] userid\n"
187 " -proxy sip:proxyhost[:port]\n"
188 " -server sip:server[:port]\n"
189 " -forward ip-address\n"
190 " -port port-numer\n"
191 " -timeout seconds\n"
193 "Report bugs to sipwitch-devel@gnu.org\n");
198 shell::errexit(3,
"*** sipuser: %s: unknown option\n", *argv);
205 shell::errexit(3,
"use: sipuser [options] userid\n");
212 #if defined(WIN32) || defined(_WIn32)
217 port = 5060 + getuid();
225 shell::errexit(3,
"*** sipuser: failed exosip init\n");
228 if(family == AF_INET6) {
237 if(!binding && family == AF_INET6)
242 shell::errexit(3,
"*** sipuser: failed to listen %s:%d\n", binding, port);
250 if(!strncmp(user,
"sip:", 4)) {
254 else if(!strncmp(user,
"sips:", 5)) {
259 if(!server && strchr(user,
'@')) {
260 server = strchr(user,
'@');
264 if(server && !strncmp(server,
"sip:", 4))
266 else if(server && !strncmp(server,
"sips:", 5))
270 if(family == AF_INET6 && server == NULL)
274 server =
"127.0.0.1";
279 if(strncmp(proxy,
"sip:", 4) && strncmp(proxy,
"sips:", 5)) {
281 snprintf(pbuffer,
sizeof(pbuffer),
"sips:%s", proxy);
283 snprintf(pbuffer,
sizeof(pbuffer),
"sip:%s", proxy);
287 if(tls && !strchr(user,
'@'))
288 snprintf(buffer,
sizeof(buffer),
"sips:%s@%s", user, server);
289 else if(!strchr(user,
'@'))
290 snprintf(buffer,
sizeof(buffer),
"sip:%s@%s", user, server);
292 snprintf(buffer,
sizeof(buffer),
"sips:%s", user);
294 snprintf(buffer,
sizeof(buffer),
"sip:%s", user);
301 shell::errexit(3,
"*** sipuser: cannot create query for %s\n", user);
303 snprintf(tbuffer,
sizeof(tbuffer),
"<%s>", buffer);
312 shell::errexit(2,
"*** sipuser: timed out\n");
323 if(contact && contact->
url)
324 printf(
"%s:%s@%s:%s\n",
Structure for SIP Message (REQUEST and RESPONSE).
user is successfully registred.
osip_list_t contacts
Contacts headers.
void eXosip_set_user_agent(struct eXosip_t *excontext, const char *user_agent)
Set the SIP User-Agent: header string.
void * osip_list_get(const osip_list_t *li, int pos)
Get an element from a list.
Structure for event description.
void eXosip_event_free(eXosip_event_t *je)
Free ressource in an eXosip event.
int eXosip_init(struct eXosip_t *excontext)
Initiate the eXtented oSIP library.
void eXosip_quit(struct eXosip_t *excontext)
Release ressource used by the eXtented oSIP library.
int eXosip_register_build_initial_register(struct eXosip_t *excontext, const char *from, const char *proxy, const char *contact, int expires, osip_message_t **reg)
Build initial REGISTER request.
int eXosip_register_remove(struct eXosip_t *excontext, int rid)
Remove existing registration without sending REGISTER.
int osip_message_set_to(osip_message_t *sip, const char *hvalue)
Set the To header.
int eXosip_register_send_register(struct eXosip_t *excontext, int rid, osip_message_t *reg)
Send a REGISTER request for an existing registration.
int osip_list_eol(const osip_list_t *li, int pos)
Check if the end of list is detected .
Definition of the From header.
struct eXosip_t * eXosip_malloc(void)
Allocate an eXosip context.
eXosip_event_t * eXosip_event_wait(struct eXosip_t *excontext, int tv_s, int tv_ms)
Wait for an eXosip event.
void eXosip_masquerade_contact(struct eXosip_t *excontext, const char *public_address, int port)
This method is used to replace contact address with the public address of your NAT.
char * scheme
Uri Scheme (sip or sips)
void osip_list_ofchar_free(osip_list_t *li)
Free a list of element where elements are pointer to 'char'.
osip_message_t * response
last response within current transaction
eXosip_event_type_t type
type of the event
int eXosip_listen_addr(struct eXosip_t *excontext, int transport, const char *addr, int port, int family, int secure)
Listen on a specified socket.
void eXosip_enable_ipv6(int ipv6_enable)
Use IPv6 instead of IPv4.