SIP Witch 1.9.15
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
voip.cpp
Go to the documentation of this file.
1 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
2 // Copyright (C) 2015 Cherokees of Idaho.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #include <sipwitch-config.h>
18 #include <ucommon/ucommon.h>
19 #include <ucommon/export.h>
20 #include <sipwitch/voip.h>
21 
22 namespace sipwitch {
23 
24 static int family = AF_INET;
25 
26 #ifdef EXOSIP_API4
27 
28 bool voip::publish(voip::context_t ctx, const char *uri, const char *contact, const char *event, const char *duration, const char *type, const char *body)
29 {
30  bool result = true;
31  voip::msg_t msg = NULL;
32 
33  eXosip_lock(ctx);
34  eXosip_build_publish(ctx, &msg, uri, contact, NULL, event, duration, type, body);
35  if(msg)
36  eXosip_publish(ctx, msg, uri);
37  else
38  result = false;
39  eXosip_unlock(ctx);
40  return result;
41 }
42 
43 void voip::call_reference(context_t ctx, call_t cid, void *route)
44 {
45  eXosip_lock(ctx);
46  eXosip_call_set_reference(ctx, cid, route);
47  eXosip_unlock(ctx);
48 }
49 
50 void voip::option(context_t ctx, int opt, const void *value)
51 {
52  if(ctx && value) {
53  eXosip_lock(ctx);
54  eXosip_set_option(ctx, opt, value);
55  eXosip_unlock(ctx);
56  }
57 }
58 
59 void voip::add_authentication(context_t ctx, const char *user, const char *secret, const char *realm, bool automatic)
60 {
61  eXosip_lock(ctx);
62  eXosip_add_authentication_info(ctx, user, user, secret, NULL, realm);
63  if(automatic)
65  eXosip_unlock(ctx);
66 }
67 
68 void voip::free_message_request(context_t ctx, msg_t msg)
69 {
70  if(msg)
71  osip_message_free(msg);
72  eXosip_unlock(ctx);
73 }
74 
75 bool voip::make_request_message(context_t ctx, const char *method, const char *to, const char *from, msg_t *msg, const char *route)
76 {
77  if(!msg)
78  return false;
79 
80  *msg = NULL;
81  eXosip_lock(ctx);
82  eXosip_message_build_request(ctx, msg, method, to, from, route);
83  if(!*msg) {
84  eXosip_unlock(ctx);
85  return false;
86  }
87  return true;
88 }
89 
90 bool voip::make_response_message(context_t ctx, tid_t tid, int status, msg_t *msg)
91 {
92  if(!msg)
93  return false;
94 
95  *msg = NULL;
96  eXosip_lock(ctx);
97  eXosip_message_build_answer(ctx, tid, status, msg);
98  if(!*msg) {
99  eXosip_unlock(ctx);
100  return false;
101  }
102  return true;
103 }
104 
105 void voip::send_response_message(context_t ctx, tid_t tid, int status, msg_t msg)
106 {
107  if(!msg)
108  eXosip_lock(ctx);
109  eXosip_message_send_answer(ctx, tid, status, msg);
110  eXosip_unlock(ctx);
111 }
112 
113 bool voip::make_ack_message(context_t ctx, did_t did, msg_t *msg)
114 {
115  if(!msg)
116  return false;
117 
118  *msg = NULL;
119  eXosip_lock(ctx);
120  eXosip_call_build_ack(ctx, did, msg);
121  if(!*msg) {
122  eXosip_unlock(ctx);
123  return false;
124  }
125  return true;
126 }
127 
128 void voip::send_ack_message(context_t ctx, did_t tid, msg_t msg)
129 {
130  if(!msg)
131  eXosip_lock(ctx);
132  eXosip_call_send_ack(ctx, tid, msg);
133  eXosip_unlock(ctx);
134 }
135 
136 bool voip::make_prack_message(context_t ctx, tid_t tid, msg_t *msg)
137 {
138  if(!msg)
139  return false;
140 
141  *msg = NULL;
142  eXosip_lock(ctx);
143  eXosip_call_build_prack(ctx, tid, msg);
144  if(!*msg) {
145  eXosip_unlock(ctx);
146  return false;
147  }
148  return true;
149 }
150 
151 void voip::send_prack_message(context_t ctx, tid_t tid, msg_t msg)
152 {
153  if(!msg)
154  eXosip_lock(ctx);
155  eXosip_call_send_prack(ctx, tid, msg);
156  eXosip_unlock(ctx);
157 }
158 
159 bool voip::make_options_response(context_t ctx, tid_t tid, int status, msg_t *msg)
160 {
161  if(!msg)
162  return false;
163 
164  *msg = NULL;
165  eXosip_lock(ctx);
166  eXosip_options_build_answer(ctx, tid, status, msg);
167  if(!*msg) {
168  eXosip_unlock(ctx);
169  return false;
170  }
171  return true;
172 }
173 
174 void voip::send_options_response(context_t ctx, tid_t tid, int status, msg_t msg)
175 {
176  if(!msg)
177  eXosip_lock(ctx);
178  eXosip_options_send_answer(ctx, tid, status, msg);
179  eXosip_unlock(ctx);
180 }
181 
182 bool voip::make_answer_response(context_t ctx, tid_t tid, int status, msg_t *msg)
183 {
184  if(!msg)
185  return false;
186 
187  *msg = NULL;
188  eXosip_lock(ctx);
189  eXosip_call_build_answer(ctx, tid, status, msg);
190  if(!*msg) {
191  eXosip_unlock(ctx);
192  return false;
193  }
194  return true;
195 }
196 
197 void voip::send_answer_response(context_t ctx, tid_t tid, int status, msg_t msg)
198 {
199  if(!msg)
200  eXosip_lock(ctx);
201  eXosip_call_send_answer(ctx, tid, status, msg);
202  eXosip_unlock(ctx);
203 }
204 
205 void voip::send_request_message(context_t ctx, msg_t msg)
206 {
207  if(!msg)
208  return;
209 
210  eXosip_message_send_request(ctx, msg);
211  eXosip_unlock(ctx);
212 }
213 
214 void voip::release_call(context_t ctx, call_t cid, did_t did)
215 {
216  eXosip_lock(ctx);
217  eXosip_call_terminate(ctx, cid, did);
218  eXosip_unlock(ctx);
219 }
220 
221 bool voip::make_dialog_request(context_t ctx, did_t did, const char *method, msg_t *msg)
222 {
223  if(!msg)
224  return false;
225 
226  *msg = NULL;
227  eXosip_lock(ctx);
228  eXosip_call_build_request(ctx, did, method, msg);
229  if(!*msg) {
230  eXosip_unlock(ctx);
231  return false;
232  }
233 
234  return true;
235 }
236 
237 bool voip::make_dialog_notify(context_t ctx, did_t did, int status, msg_t *msg)
238 {
239  if(!msg)
240  return false;
241 
242  *msg = NULL;
243  eXosip_lock(ctx);
244  eXosip_call_build_notify(ctx, did, status, msg);
245  if(!*msg) {
246  eXosip_unlock(ctx);
247  return false;
248  }
249 
250  return true;
251 }
252 
253 bool voip::make_dialog_update(context_t ctx, did_t did, msg_t *msg)
254 {
255  if(!msg)
256  return false;
257 
258  *msg = NULL;
259  eXosip_lock(ctx);
260  eXosip_call_build_update(ctx, did, msg);
261  if(!*msg) {
262  eXosip_unlock(ctx);
263  return false;
264  }
265 
266  return true;
267 }
268 
269 bool voip::make_dialog_refer(context_t ctx, did_t did, const char *to, msg_t *msg)
270 {
271  if(!msg)
272  return false;
273 
274  *msg = NULL;
275  eXosip_lock(ctx);
276  eXosip_call_build_refer(ctx, did, to, msg);
277  if(!*msg) {
278  eXosip_unlock(ctx);
279  return false;
280  }
281 
282  return true;
283 }
284 
285 bool voip::make_dialog_info(context_t ctx, did_t did, msg_t *msg)
286 {
287  if(!msg)
288  return false;
289 
290  *msg = NULL;
291  eXosip_lock(ctx);
292  eXosip_call_build_info(ctx, did, msg);
293  if(!*msg) {
294  eXosip_unlock(ctx);
295  return false;
296  }
297 
298  return true;
299 }
300 
301 bool voip::make_dialog_options(context_t ctx, did_t did, msg_t *msg)
302 {
303  if(!msg)
304  return false;
305 
306  *msg = NULL;
307  eXosip_lock(ctx);
308  eXosip_call_build_options(ctx, did, msg);
309  if(!*msg) {
310  eXosip_unlock(ctx);
311  return false;
312  }
313 
314  return true;
315 }
316 
317 void voip::send_dialog_message(context_t ctx, did_t did, msg_t msg)
318 {
319  if(!msg)
320  return;
321 
322  eXosip_call_send_request(ctx, did, msg);
323  eXosip_unlock(ctx);
324 }
325 
326 bool voip::make_invite_request(context_t ctx, const char *to, const char *from, const char *subject, msg_t *msg, const char *route)
327 {
328  *msg = NULL;
329  eXosip_lock(ctx);
330  eXosip_call_build_initial_invite(ctx, msg, to, from, route, subject);
331  if(!*msg) {
332  eXosip_unlock(ctx);
333  return false;
334  }
335 
336  return true;
337 }
338 
339 voip::call_t voip::send_invite_request(context_t ctx, msg_t msg)
340 {
341  if(!msg)
342  return -1;
343 
344  int rtn = eXosip_call_send_initial_invite(ctx, msg);
345  eXosip_unlock(ctx);
346  return rtn;
347 }
348 
349 voip::reg_t voip::make_registry_request(context_t ctx, const char *uri, const char *s, const char *c, unsigned exp, msg_t *msg)
350 {
351  *msg = NULL;
352  eXosip_lock(ctx);
353  reg_t rid = eXosip_register_build_initial_register(ctx, uri, s, c, exp, msg);
354  if(!*msg)
355  eXosip_unlock(ctx);
356  return rid;
357 }
358 
359 void voip::send_registry_request(context_t c, reg_t r, msg_t msg)
360 {
361  if(!msg)
362  return;
364  eXosip_unlock(c);
365 }
366 
367 bool voip::release_registry(context_t ctx, reg_t rid)
368 {
369  bool rtn = false;
370  msg_t msg = NULL;
371  eXosip_lock(ctx);
372  eXosip_register_build_register(ctx, rid, 0, &msg);
373  if(msg) {
374  eXosip_register_send_register(ctx, rid, msg);
375  rtn = true;
376  }
377  eXosip_unlock(ctx);
378  return rtn;
379 }
380 
381 void voip::default_action(context_t ctx, event_t ev)
382 {
383  eXosip_lock(ctx);
384  eXosip_default_action(ctx, ev);
385  eXosip_unlock(ctx);
386 }
387 
388 void voip::automatic_action(context_t ctx)
389 {
390  eXosip_lock(ctx);
392  eXosip_unlock(ctx);
393 }
394 
395 voip::event_t voip::get_event(context_t ctx, timeout_t timeout)
396 {
397  unsigned s = timeout / 1000l;
398  unsigned ms = timeout % 1000l;
399  return eXosip_event_wait(ctx, s, ms);
400 }
401 
402 bool voip::listen(context_t ctx, int proto, const char *addr, unsigned port, bool tls)
403 {
404  int tlsmode = 0;
405 
406  if(!ctx)
407  return false;
408 
409 #ifdef AF_INET6
410  if(family == AF_INET6 && addr && (!strcmp(addr, "::0") || !strcmp(addr, "::*")))
411  addr = NULL;
412 #endif
413  if(addr && !strcmp(addr, "*"))
414  addr = NULL;
415 
416  // port always even...
417  port = port & 0xfffe;
418  if(tls) {
419  tlsmode = 1;
420  ++port; // tls always next odd port...
421  }
422 
423  if(eXosip_listen_addr(ctx, proto, addr, port, family, tlsmode))
424  return false;
425 
426  return true;
427 }
428 
429 void voip::create(context_t *ctx, const char *agent, int f)
430 {
431  *ctx = eXosip_malloc();
432  eXosip_init(*ctx);
433 
434  if(agent)
435  eXosip_set_user_agent(*ctx, agent);
436 
437  family = f;
438 
439 #ifdef AF_INET6
440  if(family == AF_INET6)
442 #endif
443 }
444 
445 void voip::release(context_t ctx)
446 {
447  if(!ctx)
448  return;
449 
450  eXosip_quit(ctx);
451 }
452 
453 #else
454 
455 static bool active = false;
456 
457 bool voip::publish(voip::context_t ctx, const char *uri, const char *contact, const char *event, const char *duration, const char *type, const char *body)
458 {
459  bool result = true;
460  voip::msg_t msg = NULL;
461 
462  eXosip_lock();
463  eXosip_build_publish(&msg, uri, contact, NULL, event, duration, type, body);
464  if(msg)
465  eXosip_publish(msg, uri);
466  else
467  result = false;
468  eXosip_unlock();
469  return result;
470 }
471 
472 void voip::call_reference(context_t ctx, call_t cid, void *route)
473 {
474  eXosip_lock();
475  eXosip_call_set_reference(cid, route);
476  eXosip_unlock();
477 }
478 
479 void voip::option(voip::context_t ctx, int opt, const void *value)
480 {
481  if(ctx && value) {
482  eXosip_lock();
483  eXosip_set_option(opt, value);
484  eXosip_unlock();
485  }
486 }
487 
488 void voip::add_authentication(context_t ctx, const char *user, const char *secret, const char *realm, bool automatic)
489 {
490  eXosip_lock();
491  eXosip_add_authentication_info(user, user, secret, NULL, realm);
492  if(automatic)
494  eXosip_unlock();
495 }
496 
498 {
499  if(msg)
500  osip_message_free(msg);
501  eXosip_unlock();
502 }
503 
504 bool voip::make_request_message(context_t ctx, const char *method, const char *to, const char *from, msg_t *msg, const char *route)
505 {
506  if(!msg)
507  return false;
508 
509  *msg = NULL;
510  eXosip_lock();
511  eXosip_message_build_request(msg, method, to, from, route);
512  if(!*msg) {
513  eXosip_unlock();
514  return false;
515  }
516  return true;
517 }
518 
519 bool voip::make_response_message(context_t ctx, tid_t tid, int status, msg_t *msg)
520 {
521  if(!msg)
522  return false;
523 
524  *msg = NULL;
525  eXosip_lock();
526  eXosip_message_build_answer(tid, status, msg);
527  if(!*msg) {
528  eXosip_unlock();
529  return false;
530  }
531  return true;
532 }
533 
534 void voip::send_response_message(context_t ctx, tid_t tid, int status, msg_t msg)
535 {
536  if(!msg)
537  eXosip_lock();
538  eXosip_message_send_answer(tid, status, msg);
539  eXosip_unlock();
540 }
541 
542 bool voip::make_invite_request(context_t ctx, const char *to, const char *from, const char *subject, msg_t *msg, const char *route)
543 {
544  *msg = NULL;
545  eXosip_lock();
546  eXosip_call_build_initial_invite(msg, to, from, route, subject);
547  if(!*msg) {
548  eXosip_unlock();
549  return false;
550  }
551 
552  return true;
553 }
554 
556 {
557  if(!msg)
558  return -1;
559 
560  int rtn = eXosip_call_send_initial_invite(msg);
561  eXosip_unlock();
562  return rtn;
563 }
564 
565 bool voip::make_options_response(context_t ctx, tid_t tid, int status, msg_t *msg)
566 {
567  if(!msg)
568  return false;
569  *msg = NULL;
570  eXosip_lock();
571  eXosip_options_build_answer(tid, status, msg);
572  if(!*msg) {
573  eXosip_unlock();
574  return false;
575  }
576  return true;
577 }
578 
579 void voip::send_options_response(context_t ctx, tid_t tid, int status, msg_t msg)
580 {
581  if(!msg)
582  eXosip_lock();
583  eXosip_options_send_answer(tid, status, msg);
584  eXosip_unlock();
585 }
586 
587 bool voip::make_answer_response(context_t ctx, tid_t tid, int status, msg_t *msg)
588 {
589  if(!msg)
590  return false;
591  *msg = NULL;
592  eXosip_lock();
593  eXosip_call_build_answer(tid, status, msg);
594  if(!*msg) {
595  eXosip_unlock();
596  return false;
597  }
598  return true;
599 }
600 
601 void voip::send_answer_response(context_t ctx, tid_t tid, int status, msg_t msg)
602 {
603  if(!msg)
604  eXosip_lock();
605  eXosip_call_send_answer(tid, status, msg);
606  eXosip_unlock();
607 }
608 
610 {
611  if(!msg)
612  return;
613 
615  eXosip_unlock();
616 }
617 
618 voip::reg_t voip::make_registry_request(context_t ctx, const char *uri, const char *s, const char *c, unsigned exp, msg_t *msg)
619 {
620  if(!msg)
621  return -1;
622 
623  *msg = NULL;
624  eXosip_lock();
625  reg_t rid = eXosip_register_build_initial_register(uri, s, c, exp, msg);
626  if(!msg)
627  eXosip_unlock();
628  return rid;
629 }
630 
632 {
633  if(!msg)
634  return;
636  eXosip_unlock();
637 }
638 
640 {
641  bool rtn = false;
642  msg_t msg = NULL;
643  eXosip_lock();
644  eXosip_register_build_register(rid, 0, &msg);
645  if(msg) {
647  rtn = true;
648  }
649  eXosip_unlock();
650  return rtn;
651 }
652 
654 {
655  eXosip_lock();
656  eXosip_call_terminate(cid, did);
657  eXosip_unlock();
658 }
659 
661 {
662  if(!msg)
663  return false;
664 
665  *msg = NULL;
666  eXosip_lock();
667  eXosip_call_build_ack(did, msg);
668  if(!*msg) {
669  eXosip_unlock();
670  return false;
671  }
672  return true;
673 }
674 
676 {
677  if(!msg)
678  eXosip_lock();
679  eXosip_call_send_ack(tid, msg);
680  eXosip_unlock();
681 }
682 
684 {
685  if(!msg)
686  return false;
687 
688  *msg = NULL;
689  eXosip_lock();
690  eXosip_call_build_prack(tid, msg);
691  if(!*msg) {
692  eXosip_unlock();
693  return false;
694  }
695  return true;
696 }
697 
699 {
700  if(!msg)
701  eXosip_lock();
702  eXosip_call_send_prack(tid, msg);
703  eXosip_unlock();
704 }
705 
706 bool voip::make_dialog_request(context_t ctx, did_t did, const char *method, msg_t *msg)
707 {
708  if(!msg)
709  return false;
710 
711  *msg = NULL;
712  eXosip_lock();
713  eXosip_call_build_request(did, method, msg);
714  if(!*msg) {
715  eXosip_unlock();
716  return false;
717  }
718 
719  return true;
720 }
721 
722 bool voip::make_dialog_notify(context_t ctx, did_t did, int status, msg_t *msg)
723 {
724  if(!msg)
725  return false;
726 
727  *msg = NULL;
728  eXosip_lock();
729  eXosip_call_build_notify(did, status, msg);
730  if(!*msg) {
731  eXosip_unlock();
732  return false;
733  }
734 
735  return true;
736 }
737 
739 {
740  if(!msg)
741  return false;
742 
743  *msg = NULL;
744  eXosip_lock();
745  eXosip_call_build_update(did, msg);
746  if(!*msg) {
747  eXosip_unlock();
748  return false;
749  }
750 
751  return true;
752 }
753 
754 bool voip::make_dialog_refer(context_t ctx, did_t did, const char *to, msg_t *msg)
755 {
756  if(!msg)
757  return false;
758 
759  *msg = NULL;
760  eXosip_lock();
761  eXosip_call_build_refer(did, to, msg);
762  if(!*msg) {
763  eXosip_unlock();
764  return false;
765  }
766 
767  return true;
768 }
769 
771 {
772  if(!msg)
773  return false;
774 
775  *msg = NULL;
776  eXosip_lock();
777  eXosip_call_build_info(did, msg);
778  if(!*msg) {
779  eXosip_unlock();
780  return false;
781  }
782 
783  return true;
784 }
785 
787 {
788  if(!msg)
789  return false;
790 
791  *msg = NULL;
792  eXosip_lock();
793  eXosip_call_build_options(did, msg);
794  if(!*msg) {
795  eXosip_unlock();
796  return false;
797  }
798 
799  return true;
800 }
801 
803 {
804  if(!msg)
805  return;
806 
807  eXosip_call_send_request(did, msg);
808  eXosip_unlock();
809 }
810 
812 {
813  eXosip_lock();
815  eXosip_unlock();
816 }
817 
819 {
820  eXosip_lock();
822  eXosip_unlock();
823 }
824 
826 {
827  unsigned s = timeout / 1000l;
828  unsigned ms = timeout % 1000l;
829  return eXosip_event_wait(s, ms);
830 }
831 
832 bool voip::listen(context_t ctx, int proto, const char *addr, unsigned port, bool tls)
833 {
834  int tlsmode = 0;
835 
836 #ifdef AF_INET6
837  if(family == AF_INET6 && addr && (!strcmp(addr, "::0") || !strcmp(addr, "::*")))
838  addr = NULL;
839 #endif
840  if(addr && !strcmp(addr, "*"))
841  addr = NULL;
842 
843  // port always even...
844  port = port & 0xfffe;
845  if(tls) {
846  tlsmode = 1;
847  ++port; // tls always next odd port...
848  }
849 
850  if(eXosip_listen_addr(proto, addr, port, family, tlsmode))
851  return false;
852 
853  return true;
854 }
855 
856 void voip::create(context_t *ctx, const char *agent, int f)
857 {
858  if(active) {
859  *ctx = NULL;
860  return;
861  }
862  *ctx = (void *)-1;
863  eXosip_init();
864  active = true;
865 
866  if(agent)
867  eXosip_set_user_agent(agent);
868 
869  family = f;
870 
871 #ifdef AF_INET6
872  if(family == AF_INET6)
874 #endif
875 }
876 
878 {
879  if(!ctx || !active)
880  return;
881 
882  active = false;
883  eXosip_quit();
884 }
885 
886 #endif
887 
889 {
890  if(ev)
891  eXosip_event_free(ev);
892 }
893 
894 void voip::show(msg_t msg)
895 {
896  char *text = NULL;
897  size_t tlen;
898 
899  osip_message_to_str(msg, &text, &tlen);
900  if(text) {
901  text[tlen] = 0;
902  shell::printf("%s", text);
903  osip_free(text);
904  }
905 }
906 
908 {
909  osip_message_set_header(msg, ACCEPT, "application/sdp, text/plain");
910 }
911 
913 {
914  osip_message_set_header(msg, ALLOW, "INVITE,ACK,CANCEL,OPTIONS,INFO,REFER,MESSAGE,SUBSCRIBE,NOTIFY,REGISTER,PRACK");
915  osip_message_set_header(msg, ALLOW_EVENTS, "talk, hold, refer");
916 }
917 
918 void voip::server_requires(voip::msg_t msg, const char *txt)
919 {
920  osip_message_set_require(msg, txt);
921 }
922 
923 void voip::server_supports(voip::msg_t msg, const char *txt)
924 {
925  osip_message_set_supported(msg, txt);
926 }
927 
928 void voip::header(voip::msg_t msg, const char *key, const char *value)
929 {
930  osip_message_set_header(msg, key, value);
931 }
932 
933 void voip::attach(msg_t msg, const char *type, const char *body, size_t size)
934 {
935  if(body)
936  osip_message_set_body(msg, body, size);
937  if(type)
939 }
940 
941 void voip::attach(msg_t msg, const char *type, const char *body)
942 {
943  attach(msg, type, body, strlen(body));
944 }
945 
946 } // end namespace
int eXosip_options_build_answer(struct eXosip_t *excontext, int tid, int status, osip_message_t **answer)
Build answer for an OPTIONS request.
Structure for SIP Message (REQUEST and RESPONSE).
Definition: osip_message.h:55
static void automatic_action(context_t ctx)
Definition: voip.cpp:818
static void call_reference(context_t ctx, call_t cid, void *route)
Definition: voip.cpp:472
int eXosip_publish(struct eXosip_t *excontext, osip_message_t *message, const char *to)
Send an Publication Message (PUBLISH request).
int eXosip_call_build_request(struct eXosip_t *excontext, int did, const char *method, osip_message_t **request)
Build a default request within a call.
static void add_authentication(context_t ctx, const char *user, const char *secret, const char *realm, bool automatic=false)
Definition: voip.cpp:488
static void release(context_t ctx)
Definition: voip.cpp:877
void eXosip_set_user_agent(struct eXosip_t *excontext, const char *user_agent)
Set the SIP User-Agent: header string.
int eXosip_register_build_register(struct eXosip_t *excontext, int rid, int expires, osip_message_t **reg)
Build a new REGISTER request for an existing registration.
int eXosip_message_send_request(struct eXosip_t *excontext, osip_message_t *message)
Send an request.
static bool make_prack_message(context_t ctx, tid_t tid, msg_t *msg)
Definition: voip.cpp:683
int eXosip_call_send_prack(struct eXosip_t *excontext, int tid, osip_message_t *prack)
Send a PRACK for invite.
static bool make_answer_response(context_t ctx, tid_t tid, int status, msg_t *msg)
Definition: voip.cpp:587
int eXosip_lock(struct eXosip_t *excontext)
Lock the eXtented oSIP library.
static void send_ack_message(context_t ctx, did_t did, msg_t msg=NULL)
Definition: voip.cpp:675
int eXosip_call_set_reference(struct eXosip_t *excontext, int id, void *reference)
Set a new application context for an existing call.
Structure for event description.
Definition: eXosip.h:359
int eXosip_message_build_request(struct eXosip_t *excontext, osip_message_t **message, const char *method, const char *to, const char *from, const char *route)
Build a default request message.
int eXosip_call_send_request(struct eXosip_t *excontext, int did, osip_message_t *request)
send the request within call.
void eXosip_event_free(eXosip_event_t *je)
Free ressource in an eXosip event.
int eXosip_default_action(struct eXosip_t *excontext, eXosip_event_t *je)
Initiate some default actions:
unsigned long timeout_t
Definition: voip.h:73
int eXosip_build_publish(struct eXosip_t *excontext, osip_message_t **message, const char *to, const char *from, const char *route, const char *event, const char *expires, const char *ctype, const char *body)
build publication for a user.
events event_t
Definition: events.h:204
static void send_registry_request(context_t ctx, reg_t rid, msg_t msg)
Definition: voip.cpp:631
int eXosip_message_send_answer(struct eXosip_t *excontext, int tid, int status, osip_message_t *answer)
Send answer for a request.
int eXosip_init(struct eXosip_t *excontext)
Initiate the eXtented oSIP library.
int osip_message_set_content_type(osip_message_t *sip, const char *hvalue)
Set the Content-type header.
static bool make_request_message(context_t ctx, const char *method, const char *to, const char *from, msg_t *msg, const char *route=NULL)
Definition: voip.cpp:504
void eXosip_quit(struct eXosip_t *excontext)
Release ressource used by the eXtented oSIP library.
static bool publish(context_t ctx, const char *uri, const char *contact, const char *event, const char *duration, const char *type, const char *body)
Definition: voip.cpp:457
static bool make_ack_message(context_t ctx, did_t did, msg_t *msg)
Definition: voip.cpp:660
int osip_message_set_header(osip_message_t *sip, const char *hname, const char *hvalue)
Allocate and Add an "unknown" header (not defined in oSIP).
int eXosip_call_build_refer(struct eXosip_t *excontext, int did, const char *refer_to, osip_message_t **request)
Build a default REFER for a call transfer.
int eXosip_call_terminate(struct eXosip_t *excontext, int cid, int did)
Terminate a call.
static call_t send_invite_request(context_t ctx, msg_t msg)
Definition: voip.cpp:555
static void release_event(event_t ev)
Definition: voip.cpp:888
static void send_dialog_message(context_t ctx, did_t did, msg_t msg)
Definition: voip.cpp:802
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.
static bool make_dialog_info(context_t ctx, did_t did, msg_t *msg)
Definition: voip.cpp:770
int call_t
Definition: voip.h:62
int tid_t
Definition: voip.h:60
static bool make_dialog_request(context_t ctx, did_t did, const char *method, msg_t *msg)
Definition: voip.cpp:706
int eXosip_options_send_answer(struct eXosip_t *excontext, int tid, int status, osip_message_t *answer)
Send answer for an OPTIONS request.
void osip_message_free(osip_message_t *sip)
Free all resource in a osip_message_t element.
static void server_requires(voip::msg_t msg, const char *txt)
Definition: voip.cpp:918
#define osip_message_set_supported(sip, value)
Allocate and Add a new Supported header.
Definition: osip_parser.h:675
static bool make_options_response(context_t ctx, tid_t tid, int status, msg_t *msg)
Definition: voip.cpp:565
#define ACCEPT
Definition: osip_const.h:34
static void send_options_response(context_t ctx, tid_t tid, int status, msg_t msg=NULL)
Definition: voip.cpp:579
int eXosip_add_authentication_info(struct eXosip_t *excontext, const char *username, const char *userid, const char *passwd, const char *ha1, const char *realm)
Add authentication credentials.
#define ALLOW_EVENTS
Definition: voip.h:144
#define osip_free(P)
Definition: osip_port.h:105
int eXosip_call_build_prack(struct eXosip_t *excontext, int tid, osip_message_t **prack)
Build a PRACK for invite.
eXosip_event_t * event_t
Definition: voip.h:58
int eXosip_unlock(struct eXosip_t *excontext)
UnLock the eXtented oSIP library.
int eXosip_register_send_register(struct eXosip_t *excontext, int rid, osip_message_t *reg)
Send a REGISTER request for an existing registration.
int eXosip_call_build_initial_invite(struct eXosip_t *excontext, osip_message_t **invite, const char *to, const char *from, const char *route, const char *subject)
Build a default INVITE message for a new call.
int eXosip_set_option(struct eXosip_t *excontext, int opt, const void *value)
Set eXosip options.
static bool make_dialog_notify(context_t ctx, did_t did, int status, msg_t *msg)
Definition: voip.cpp:722
int eXosip_call_send_ack(struct eXosip_t *excontext, int did, osip_message_t *ack)
Send the ACK for the 200ok received.
static bool listen(context_t ctx, int proto=IPPROTO_UDP, const char *iface=NULL, unsigned port=5060, bool tls=false)
Definition: voip.cpp:832
static void attach(msg_t msg, const char *type, const char *body)
Definition: voip.cpp:941
static void server_supports(voip::msg_t msg, const char *txt)
Definition: voip.cpp:923
static bool make_dialog_options(context_t ctx, did_t did, msg_t *msg)
Definition: voip.cpp:786
static void release_call(context_t ctx, call_t cid, did_t did)
Definition: voip.cpp:653
int eXosip_call_build_ack(struct eXosip_t *excontext, int did, osip_message_t **ack)
Build a default ACK for a 200ok received.
int eXosip_call_build_notify(struct eXosip_t *excontext, int did, int subscription_status, osip_message_t **request)
Build a default NOTIFY within a call.
static void send_response_message(context_t ctx, tid_t tid, int status, msg_t msg=NULL)
Definition: voip.cpp:534
int osip_message_to_str(osip_message_t *sip, char **dest, size_t *message_length)
Get a string representation of a osip_message_t element.
int eXosip_message_build_answer(struct eXosip_t *excontext, int tid, int status, osip_message_t **answer)
Build answer for a request.
static void send_answer_response(context_t ctx, tid_t tid, int status, msg_t msg=NULL)
Definition: voip.cpp:601
char * value[96]
Definition: cgiserver.cpp:90
struct eXosip_t * eXosip_malloc(void)
Allocate an eXosip context.
static void free_message_request(context_t ctx, voip::msg_t msg)
Definition: voip.cpp:497
void * context_t
Definition: voip.h:53
eXosip_event_t * eXosip_event_wait(struct eXosip_t *excontext, int tv_s, int tv_ms)
Wait for an eXosip event.
static void default_action(context_t ctx, event_t ev)
Definition: voip.cpp:811
static void send_prack_message(context_t ctx, tid_t tid, msg_t msg)
Definition: voip.cpp:698
int did_t
Definition: voip.h:61
int eXosip_call_send_initial_invite(struct eXosip_t *excontext, osip_message_t *invite)
Initiate a call.
void eXosip_automatic_action(struct eXosip_t *excontext)
Initiate some automatic actions:
static void option(context_t ctx, int opt, const void *value)
Definition: voip.cpp:479
int reg_t
Definition: voip.h:59
static bool make_dialog_refer(context_t ctx, did_t did, const char *to, msg_t *msg)
Definition: voip.cpp:754
static void send_request_message(context_t ctx, msg_t msg)
Definition: voip.cpp:609
int eXosip_call_send_answer(struct eXosip_t *excontext, int tid, int status, osip_message_t *answer)
Send Answer for invite.
int eXosip_call_build_options(struct eXosip_t *excontext, int did, osip_message_t **request)
Build a default OPTIONS within a call.
osip_message_t * msg_t
Definition: voip.h:64
static bool make_dialog_update(context_t ctx, did_t did, msg_t *msg)
Definition: voip.cpp:738
static void server_accepts(voip::msg_t msg)
Definition: voip.cpp:907
static bool make_response_message(context_t ctx, tid_t tid, int status, msg_t *msg)
Definition: voip.cpp:519
int eXosip_call_build_info(struct eXosip_t *excontext, int did, osip_message_t **request)
Build a default INFO within a call.
#define ALLOW
Definition: osip_const.h:38
static void show(msg_t msg)
Definition: voip.cpp:894
static bool make_invite_request(context_t ctx, const char *to, const char *from, const char *subject, msg_t *msg, const char *route=NULL)
Definition: voip.cpp:542
static reg_t make_registry_request(context_t ctx, const char *uri, const char *s, const char *c, unsigned exp, msg_t *msg)
Definition: voip.cpp:618
static void server_allows(voip::msg_t msg)
Definition: voip.cpp:912
int eXosip_listen_addr(struct eXosip_t *excontext, int transport, const char *addr, int port, int family, int secure)
Listen on a specified socket.
int osip_message_set_body(osip_message_t *sip, const char *buf, size_t length)
Set the Body of the SIP message.
static void header(msg_t msg, const char *key, const char *value)
Definition: voip.cpp:928
void eXosip_enable_ipv6(int ipv6_enable)
Use IPv6 instead of IPv4.
#define osip_message_set_require(sip, value)
Allocate and Add a new Require header.
Definition: osip_parser.h:662
int eXosip_call_build_answer(struct eXosip_t *excontext, int tid, int status, osip_message_t **answer)
Build default Answer for request.
int eXosip_call_build_update(struct eXosip_t *excontext, int did, osip_message_t **request)
Build a default UPDATE within a call.
static bool release_registry(context_t ctx, reg_t rid)
Definition: voip.cpp:639
static void create(context_t *ctx, const char *agent, int family=AF_INET)
Definition: voip.cpp:856
static event_t get_event(context_t ctx, timeout_t timeout)
Definition: voip.cpp:825