File: osip.h

package info (click to toggle)
libosip 0.9.7-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,852 kB
  • ctags: 1,812
  • sloc: ansic: 20,266; sh: 9,218; makefile: 215
file content (2015 lines) | stat: -rw-r--r-- 73,321 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
/*
  The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
  Copyright (C) 2001,2002,2003  Aymeric MOIZARD jack@atosc.org
  
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
  
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/


#ifndef _OSIP_H_
#define _OSIP_H_

#include <osip/const.h>

#include <time.h>

#ifdef __sun
#include <sys/types.h>
#endif

#include <osip/smsg.h>
#include <osip/fifo.h>

/**
 * @file osip.h
 * @brief oSIP fsm Routines
 *
 * <H2>Introduction.</H2>
 * fsm stands for 'finite state machine'. The possible STATE of the state
 * machines are defined in the enum state. In oSIP, you can actually find
 * 4 different state machines. Those state machines definitions are directly
 * related to the definitions of transactions from the SIP specifications.
 * (See section: 17.1.1,  17.1.2,  17.2.1,  17.2.2). In the 4 drawings shown
 * in those sections, you'll find the possible STATES and the possible EVENTS
 * (sipevent_t) that can occur. EVENTS can be either TIMEOUT events and
 * SIP message (incoming and outgoing) events.
 * <H2>Why 4 finite state machines.</H2>
 * <BR>SIP has two different kind of transaction: INVITE and NON-INVITE ones.
 * Also, a SIP User Agent can act as a server and as a client. This simply
 * leads to 4 transactions state machines.
 * <BR>
 * <H2>Step 1: oSIP initialisation</H2>
 * <BR>To use oSIP, a program MUST first initialise internal elements in the
 * stack. The initialisation is shown below:
 * <pre><code>
 * osip_t *osip;
 * // initialise internal element first
 * if (0!=osip_global_init())
 *   return -1;
 * // allocate a global osip element.
 * if (0!=osip_init(&osip))
 *   return -1;
 *
 * // the next step is the initialisation of the callbacks used by the
 * // oSIP stack to announce events (when a transition occurs in the fsm)
 *
 * // This callback is somewhat special and is used by oSIP to inform
 * // the application that a message has to be sent. The message is
 * // sent by your application! oSIP has no ways to send it alone.
 * // Also, the method you supply will be called with default values where
 * // you should send the SIP message. You are not mandated to send the
 * // SIP message by using those default values.
 * // the callback MUST return 0 on success, 1 on ECONNREFUSED, -1 on error.
 *  osip_setcb_send_message(osip, &application_cb_snd_message);
 *
 * // here is the long list of callback that you can register. Some
 * // of this callbacks are very useless (announcing a retransmission,
 * // or announcing that you have sent a SIP message which you may already
 * // know...).
 *
 * // those callbacks are mandatory. They are called when oSIP has decided
 * // that this transaction MUST no longer be handled by oSIP. (This is
 * // called in both successful or error cases scenario)
 *  osip_setcb_ict_kill_transaction(osip,&application_cb_ict_kill_transaction);
 *  osip_setcb_ist_kill_transaction(osip,&application_cb_ist_kill_transaction);
 *  osip_setcb_nict_kill_transaction(osip,&application_cb_nict_kill_transaction);
 *  osip_setcb_nist_kill_transaction(osip,&application_cb_nist_kill_transaction);
 *
 * // those callbacks are optional. The purpose is to announce retransmissions
 * // of SIP message decided by the oSIP stack. (They can be used for statistics?)
 *  osip_setcb_ict_2xx_received2(osip,&application_cb_rcvresp_retransmission);
 *  osip_setcb_ict_3456xx_received2(osip,&application_cb_rcvresp_retransmission);
 *  osip_setcb_ict_invite_sent2(osip,&application_cb_sndreq_retransmission);
 *  osip_setcb_ist_2xx_sent2(osip,&application_cb_sndresp_retransmission);
 *  osip_setcb_ist_3456xx_sent2(osip,&application_cb_sndresp_retransmission);
 *  osip_setcb_ist_invite_received2(osip,&application_cb_rcvreq_retransmission);
 *  osip_setcb_nict_2xx_received2(osip,&application_cb_rcvresp_retransmission);
 *  osip_setcb_nict_3456xx_received2(osip,&application_cb_rcvresp_retransmission);
 *  osip_setcb_nict_request_sent2(osip,&application_cb_sndreq_retransmission);
 *  osip_setcb_nist_2xx_sent2(osip,&application_cb_sndresp_retransmission);
 *  osip_setcb_nist_3456xx_sent2(osip,&application_cb_sndresp_retransmission);
 *  osip_setcb_nist_request_received2(osip,&application_cb_rcvreq_retransmission);
 *
 * // those callbacks are mandatory. They are used to announce network related
 * // errors (the return code of the network callback if it was not 0)
 *  osip_setcb_ict_transport_error(osip,&application_cb_transport_error);
 *  osip_setcb_ist_transport_error(osip,&application_cb_transport_error);
 *  osip_setcb_nict_transport_error(osip,&application_cb_transport_error);
 *  osip_setcb_nist_transport_error(osip,&application_cb_transport_error);
 *  
 * // those callbacks are optional. They are used to announce the initial
 * // request sent for a newly created transaction.
 *  osip_setcb_ict_invite_sent  (osip,&application_cb_sndinvite);
 *  osip_setcb_ict_ack_sent     (osip,&application_cb_sndack);
 *  osip_setcb_nict_register_sent(osip,&application_cb_sndregister);
 *  osip_setcb_nict_bye_sent     (osip,&application_cb_sndbye);
 *  osip_setcb_nict_cancel_sent  (osip,&application_cb_sndcancel);
 *  osip_setcb_nict_info_sent    (osip,&application_cb_sndinfo);
 *  osip_setcb_nict_options_sent (osip,&application_cb_sndoptions);
 *  osip_setcb_nict_subscribe_sent (osip,&application_cb_sndoptions);
 *  osip_setcb_nict_notify_sent (osip,&application_cb_sndoptions);
 *  osip_setcb_nict_unknown_sent(osip,&application_cb_sndunkrequest);
 *
 * // those callbacks are mandatory. They are used to announce the initial
 * // response received for a transaction. (for SIP response between 100 and 199,
 * // all responses are announced because this is not a retransmission case)
 *  osip_setcb_ict_1xx_received(osip,&application_cb_rcv1xx);
 *  osip_setcb_ict_2xx_received(osip,&application_cb_rcv2xx);
 *  osip_setcb_ict_3xx_received(osip,&application_cb_rcv3xx);
 *  osip_setcb_ict_4xx_received(osip,&application_cb_rcv4xx);
 *  osip_setcb_ict_5xx_received(osip,&application_cb_rcv5xx);
 *  osip_setcb_ict_6xx_received(osip,&application_cb_rcv6xx);
 *  
 * // those callbacks are optional. They are used to announce the initial
 * // response sent for a transaction. (for SIP response between 100 and 199,
 * // all responses are announced because this is not a retransmission case)
 *  osip_setcb_ist_1xx_sent(osip,&application_cb_snd1xx);
 *  osip_setcb_ist_2xx_sent(osip,&application_cb_snd2xx);
 *  osip_setcb_ist_3xx_sent(osip,&application_cb_snd3xx);
 *  osip_setcb_ist_4xx_sent(osip,&application_cb_snd4xx);
 *  osip_setcb_ist_5xx_sent(osip,&application_cb_snd5xx);
 *  osip_setcb_ist_6xx_sent(osip,&application_cb_snd6xx);
 *
 * // those callbacks are mandatory. They are used to announce the initial
 * // response received for a transaction. (for SIP response between 100 and 199,
 * // all responses are announced because this is not a retransmission case)
 *  osip_setcb_nict_1xx_received(osip,&application_cb_rcv1xx);
 *  osip_setcb_nict_2xx_received(osip,&application_cb_rcv2xx);
 *  osip_setcb_nict_3xx_received(osip,&application_cb_rcv3xx);
 *  osip_setcb_nict_4xx_received(osip,&application_cb_rcv4xx);
 *  osip_setcb_nict_5xx_received(osip,&application_cb_rcv5xx);
 *  osip_setcb_nict_6xx_received(osip,&application_cb_rcv6xx);
 *
 * // those callbacks are optional. They are used to announce the initial
 * // response sent for a transaction. (for SIP response between 100 and 199,
 * // all responses are announced because this is not a retransmission case)
 *  osip_setcb_nist_1xx_sent(osip,&application_cb_snd1xx);
 *  osip_setcb_nist_2xx_sent(osip,&application_cb_snd2xx);
 *  osip_setcb_nist_3xx_sent(osip,&application_cb_snd3xx);
 *  osip_setcb_nist_4xx_sent(osip,&application_cb_snd4xx);
 *  osip_setcb_nist_5xx_sent(osip,&application_cb_snd5xx);
 *  osip_setcb_nist_6xx_sent(osip,&application_cb_snd6xx);
 *
 * // those callbacks are mandatory. They are used to announce the initial
 * // request received for a transaction. It is not useless to notice that
 * // a special behaviour exist for the 200 OK and the ACK in the case of
 * // a successful INVITE transaction. This will be discussed later.
 *  osip_setcb_ist_invite_received   (osip,&application_cb_rcvinvite);
 *  osip_setcb_ist_ack_received      (osip,&application_cb_rcvack);
 * // this callback is optional
 *  osip_setcb_ist_ack_received2     (osip,&application_cb_rcvack2);
 *  osip_setcb_nist_register_received(osip,&application_cb_rcvregister);
 *  osip_setcb_nist_bye_received     (osip,&application_cb_rcvbye);
 *  osip_setcb_nist_cancel_received  (osip,&application_cb_rcvcancel);
 *  osip_setcb_nist_info_received    (osip,&application_cb_rcvinfo);
 *  osip_setcb_nist_options_received (osip,&application_cb_rcvoptions);
 *  osip_setcb_nist_subscribe_received(osip,&application_cb_rcvoptions);
 *  osip_setcb_nist_notify_received  (osip,&application_cb_rcvoptions);
 *  osip_setcb_nist_unknown_received (osip,&application_cb_rcvunkrequest);
 *
 * </code></pre>
 * <P>
 * <H2>Step 2: Initialising a new transaction.</H2>
 * <BR>Let's assume you want to implement a User Agent and you want to
 * start a REGISTER transaction. Using the parser library, you will first
 * have to build a SIP compliant message. (oSIP, as a low layer library
 * provides an interface to build SIP messages, but it's up to you to
 * correctly fill all the required fields.)
 * As soon as you have build the SIP message, you are ready to start a new
 * transaction. Here is the code:
 * <BR><pre><code>
 * osip_t *osip = your_global_osip_context;
 * transaction_t *transaction;
 * sip_t         *sip_register_message;
 * sipevent_t *sipevent;
 *
 * application_build_register(&sip_register_message);
 * transaction_init(&transaction,
 *		   NICT,          //a REGISTER is a Non-Invite-Client-Transaction
 *		   osip,
 *		   sip_register_message);
 *
 * // If you have a special context that you want to associate to that
 * // transaction, you can use a special method that associate your context
 * // to the transaction context.
 *
 * transaction_set_your_instance(transaction, my_context);
 *
 * // at this point, the transaction context exists in oSIP but you still have
 * // to give the SIP message to the finite state machine.   
 * sipevent = osip_new_outgoing_sipmessage(msg);
 * sipevent->transactionid =  transaction->transactionid;
 * transaction_add_event(transaction, sipevent);
 * // at this point, the event will be handled by oSIP. (The memory resource will
 * // also be handled by oSIP). Note that no action is taken there. 
 * </pre></code>
 * <P>Adding new events in the fsm is made with similar code.
 * <P>
 * <H2>Step 3: Consuming events.</H2>
 * <BR>The previous step show how to create a transaction and one possible way
 * to add a new event. (Note, that some events -the TIMEOUT_* ones- will be
 * added by oSIP not by the application). In this step, we describe how the
 * oSIP stack will consume events. In fact, this is very simple, but you
 * should be aware that it's not always allowed to consume an event at any time!
 * The fsm MUST consume events sequentially within a transaction. This means
 * that when your are calling transaction_execute(), it is forbidden to call
 * this method again with the same transaction context until the first call
 * has returned. In a multi threaded application, if one thread handles one
 * transaction, the code will be the following:
 * <BR><pre><code>
 *   while (1)
 *     {
 *       se = (sipevent_t *)fifo_get(transaction->transactionff);
 *       if (se==NULL)
 * 	  sthread_exit();
 *       if (transaction_execute(transaction,se)<1)  // deletion asked
 * 	  sthread_exit();
 *   }
 * </pre></code>
 * <P>
 * <H2>Step 4: How the stack will announce the events</H2>
 * Looking at the case of a usual outgoing REGISTER transaction, this behaviour
 * is expected.
 * <BR>When an event is seen as useful for the fsm, it means that a transition
 * from one state to another has to be done on the transaction context. If the
 * event is SND_REQUEST (this is the case for an outgoing REGISTER), the
 * callback previously registered to announce this action will be called. This
 * callback is useless for the application as no action has to be taken at this
 * step. A more interesting announcement will be made when consuming the
 * first final response received. If the callbacks associated to 2xx message
 * is called, then the transaction has succeeded. Inside this callback, you
 * will probably inform the user of the success of the registration if you want
 * to do so...
 * If the final response is not a 2xx, or the network callback is called, you'll
 * probably want to take some actions. For example, if you receive a 302, you'll
 * probably want to retry a registration at the new location. All that decision
 * is up to you.
 */

/**
 * @defgroup oSIP_FSM oSIP fsm Handling
 * @ingroup oSIP
 * @{
 */

#ifdef __cplusplus
extern "C"
{
#endif


/**
 * Enumeration for transaction state.
 * <BR>
 * <BR>Here is the list of possible values for transactions:
 * <BR>   ICT_PRE_CALLING,
 * <BR>   ICT_CALLING,
 * <BR>   ICT_PROCEEDING,
 * <BR>   ICT_COMPLETED,
 * <BR>   ICT_TERMINATED,
 * <BR>
 * <BR>   IST_PRE_PROCEEDING,
 * <BR>   IST_PROCEEDING,
 * <BR>   IST_COMPLETED,
 * <BR>   IST_CONFIRMED,
 * <BR>   IST_TERMINATED,
 *<BR>
 * <BR>   NICT_PRE_TRYING,
 * <BR>   NICT_TRYING,
 * <BR>   NICT_PROCEEDING,
 * <BR>   NICT_COMPLETED,
 * <BR>   NICT_TERMINATED,
 *<BR>
 * <BR>   NIST_PRE_TRYING,
 * <BR>   NIST_TRYING,
 * <BR>   NIST_PROCEEDING,
 * <BR>   NIST_COMPLETED,
 * <BR>   NIST_TERMINATED,
 *
 */
  typedef enum _state_t
  {
    /* STATES for invite client transaction */
    ICT_PRE_CALLING,
    ICT_CALLING,
    ICT_PROCEEDING,
    ICT_COMPLETED,
    ICT_TERMINATED,

    /* STATES for invite server transaction */
    IST_PRE_PROCEEDING,		/* this is used to only announce once the INVITE */
    IST_PROCEEDING,
    IST_COMPLETED,
    IST_CONFIRMED,
    IST_TERMINATED,

    /* STATES for NON-invite client transaction */
    NICT_PRE_TRYING,
    NICT_TRYING,
    NICT_PROCEEDING,
    NICT_COMPLETED,
    NICT_TERMINATED,

    /* STATES for NON-invite server transaction */
    NIST_PRE_TRYING,
    NIST_TRYING,
    NIST_PROCEEDING,
    NIST_COMPLETED,
    NIST_TERMINATED,

#ifndef DOXYGEN
    DIALOG_EARLY,
    DIALOG_CONFIRMED,
    DIALOG_CLOSE		/* ?? */
#endif
  }
  state_t;

/**
 * Enumeration for event type.
 * <BR>The list of values that you need to know is reduced to this:
 * <BR> RCV_REQINVITE,
 * <BR> RCV_REQACK,
 * <BR> RCV_REQUEST,
 * <BR> RCV_STATUS_1XX,
 * <BR> RCV_STATUS_2XX,
 * <BR> RCV_STATUS_3456XX,
 *<BR>
 * <BR> SND_REQINVITE,
 * <BR> SND_REQACK,
 * <BR> SND_REQUEST,
 * <BR> SND_STATUS_1XX,
 * <BR> SND_STATUS_2XX,
 * <BR> SND_STATUS_3456XX,
 */
  typedef enum type_t
  {
    /* TIMEOUT EVENTS for ICT */
    TIMEOUT_A,	 /**< Timer A */
    TIMEOUT_B,	 /**< Timer B */
    TIMEOUT_D,	 /**< Timer D */

    /* TIMEOUT EVENTS for NICT */
    TIMEOUT_E,	 /**< Timer E */
    TIMEOUT_F,	 /**< Timer F */
    TIMEOUT_K,	 /**< Timer K */

    /* TIMEOUT EVENTS for IST */
    TIMEOUT_G,	 /**< Timer G */
    TIMEOUT_H,	 /**< Timer H */
    TIMEOUT_I,	 /**< Timer I */

    /* TIMEOUT EVENTS for NIST */
    TIMEOUT_J,	 /**< Timer J */

    /* FOR INCOMING MESSAGE */
    RCV_REQINVITE,    /**< Event is an incoming INVITE request */
    RCV_REQACK,	      /**< Event is an incoming ACK request */
    RCV_REQUEST,      /**< Event is an incoming NON-INVITE and NON-ACK request */
    RCV_STATUS_1XX,   /**< Event is an incoming informational response */
    RCV_STATUS_2XX,   /**< Event is an incoming 2XX response */
    RCV_STATUS_3456XX,/**< Event is an incoming final response (not 2XX) */

    /* FOR OUTGOING MESSAGE */
    SND_REQINVITE,    /**< Event is an outgoing INVITE request */
    SND_REQACK,	      /**< Event is an outgoing ACK request */
    SND_REQUEST,      /**< Event is an outgoing NON-INVITE and NON-ACK request */
    SND_STATUS_1XX,   /**< Event is an outgoing informational response */
    SND_STATUS_2XX,   /**< Event is an outgoing 2XX response */
    SND_STATUS_3456XX,/**< Event is an outgoing final response (not 2XX) */

    KILL_TRANSACTION, /**< Event to 'kill' the transaction before termination */
    UNKNOWN_EVT
  }
  type_t;

#ifndef DOXYGEN
  typedef struct statemachine_t statemachine_t;

  struct statemachine_t
  {
    list_t *transitions;
  };
#endif

/**
 * Enumeration for transaction type.
 * A transaction can be either of:
 *  ICT,
 *  IST,
 *  NICT,
 *  NIST,
 */
  typedef enum context_type_t
  {
    ICT, /**< Invite Client (outgoing) Transaction */
    IST, /**< Invite Server (incoming) Transaction */
    NICT,/**< Non-Invite Client (outgoing) Transaction */
    NIST /**< Non-Invite Server (incoming) Transaction */
  }
  context_type_t;

#ifndef DEFAULT_T1
/**
 * You can re-define the default value for T1. (T1 is defined in rfcxxxx)
 * The default value is 500ms.
 */
#define DEFAULT_T1 500		/* 500 ms */
#endif
#ifndef DEFAULT_T2
/**
 * You can re-define the default value for T2. (T2 is defined in rfcxxxx)
 * The default value is 4000ms.
 */
#define DEFAULT_T2 4000		/* 4s */
#endif
#ifndef DEFAULT_T4
/**
 * You can re-define the default value for T4. (T1 is defined in rfcxxxx)
 * The default value is 5000ms.
 */
#define DEFAULT_T4 5000		/* 5s */
#endif


/**
 * Structure for INVITE CLIENT TRANSACTION (outgoing INVITE transaction).
 * @defvar ict_t
 */
  typedef struct ict_t ict_t;

  struct ict_t
  {
    /* state machine is implied... */

    int timer_a_length;		/* A=T1, A=2xT1... (unreliable transport only)  */
    time_t timer_a_start;
    int timer_b_length;		/* B = 64* T1                                   */
    time_t timer_b_start;	/* fire when transaction timeouts               */
    int timer_d_length;		/* D >= 32s for unreliable transport (else = 0) */
    time_t timer_d_start;	/* should be equal to timer H */

    char *destination;		/* url used to send requests         */
    int port;			/* port of next hop                  */

  };

/**
 * Structure for NON-INVITE CLIENT TRANSACTION (outgoing NON-INVITE transaction).
 * @defvar nict_t
 */
  typedef struct nict_t nict_t;

  struct nict_t
  {
    /* state machine is implied... */

    int timer_e_length;		/* A=T1, A=2xT1... (unreliable transport only)  */
    time_t timer_e_start;	/*  (else = -1) not active                      */
    int timer_f_length;		/* B = 64* T1                                   */
    time_t timer_f_start;	/* fire when transaction timeouts               */
    int timer_k_length;		/* K = T4 (else = 0)                            */
    time_t timer_k_start;

    char *destination;		/* url used to send requests         */
    int port;			/* port of next hop                  */

  };

/**
 * Structure for INVITE SERVER TRANSACTION (incoming INVITE transaction).
 * @defvar ist_t
 */
  typedef struct ist_t ist_t;

  struct ist_t
  {

    int timer_g_length;		/* G=MIN(T1*2,T2) for unreliable transport (else=0) */
    time_t timer_g_start;	/* else = 0 when reliable transport is used!       */
    int timer_h_length;		/* H = 64* T1                                      */
    time_t timer_h_start;	/* fire when if no ACK is received                 */
    int timer_i_length;		/* I = T4 for unreliable transport (else = 0)      */
    time_t timer_i_start;	/* absorb all ACK                                  */

    int auto_send_100;		/* set to 0 for automatic 100 replies (0 is default) */

  };

/**
 * Structure for NON-INVITE SERVER TRANSACTION (incoming SERVER transaction).
 * @defvar nist_t
 */
  typedef struct nist_t nist_t;

  struct nist_t
  {

    int timer_j_length;		/* J = 64*T1 (else 0) */
    time_t timer_j_start;

  };

/**
 * Structure for transaction handling.
 * @defvar transaction_t
 */
  typedef struct transaction_t transaction_t;

  struct transaction_t
  {

    void *your_instance;	/* add whatever you want here.       */
    int transactionid;		/* simple id used to identify the tr. */
    fifo_t *transactionff;	/* events must be added in this fifo */

    via_t *topvia;		/* CALL-LEG definition */
    from_t *from;		/* CALL-LEG definition */
    to_t *to;
    call_id_t *callid;
    cseq_t *cseq;

    sip_t *orig_request;	/* last request sent                 */
    sip_t *last_response;	/* last response received            */
    sip_t *ack;			/* ack request sent                  */

    state_t state;		/* state of transaction              */

    time_t birth_time;		/* birth_date of transaction         */
    time_t completed_time;	/* end   date of transaction         */

    /* RESPONSE are received on this socket */
    int in_socket;
    /* REQUESTS are sent on this socket */
    int out_socket;

    void *config;		/* transaction is managed by config  */

    context_type_t ctx_type;
    ict_t *ict_context;
    ist_t *ist_context;
    nict_t *nict_context;
    nist_t *nist_context;
  };

/**
 * Structure for osip handling.
 * In order to use osip, you have to manage at least one global instance
 * of an osip_t element. Then, you'll register a set of required callbacks
 * and a set of optional ones.
 * @defvar osip_t
 */
  typedef struct osip_t osip_t;

  struct osip_t
  {

    void *application_context;	/* a pointer for your personnal usage */

    /* list of transactions for ict, ist, nict, nist */
    list_t *ict_transactions;
    list_t *ist_transactions;
    list_t *nict_transactions;
    list_t *nist_transactions;

    /* callbacks for sending messages */
    int (*cb_send_message) (transaction_t *, sip_t *, char *, int, int);

    /* callbacks for ict */
    void (*cb_ict_kill_transaction) (transaction_t *);
    void (*cb_ict_invite_sent) (transaction_t *, sip_t *);
    void (*cb_ict_invite_sent2) (transaction_t *, sip_t *);
    void (*cb_ict_ack_sent) (transaction_t *, sip_t *);
    void (*cb_ict_ack_sent2) (transaction_t *, sip_t *);
    void (*cb_ict_1xx_received) (transaction_t *, sip_t *);
    void (*cb_ict_2xx_received) (transaction_t *, sip_t *);
    void (*cb_ict_2xx_received2) (transaction_t *, sip_t *);
    void (*cb_ict_3xx_received) (transaction_t *, sip_t *);
    void (*cb_ict_4xx_received) (transaction_t *, sip_t *);
    void (*cb_ict_5xx_received) (transaction_t *, sip_t *);
    void (*cb_ict_6xx_received) (transaction_t *, sip_t *);
    void (*cb_ict_3456xx_received2) (transaction_t *, sip_t *);

    void (*cb_ict_transport_error) (transaction_t *, int error);

    /* callbacks for ist */
    void (*cb_ist_kill_transaction) (transaction_t *);
    void (*cb_ist_invite_received) (transaction_t *, sip_t *);
    void (*cb_ist_invite_received2) (transaction_t *, sip_t *);
    void (*cb_ist_ack_received) (transaction_t *, sip_t *);
    void (*cb_ist_ack_received2) (transaction_t *, sip_t *);
    void (*cb_ist_1xx_sent) (transaction_t *, sip_t *);
    void (*cb_ist_2xx_sent) (transaction_t *, sip_t *);
    void (*cb_ist_2xx_sent2) (transaction_t *, sip_t *);
    void (*cb_ist_3xx_sent) (transaction_t *, sip_t *);
    void (*cb_ist_4xx_sent) (transaction_t *, sip_t *);
    void (*cb_ist_5xx_sent) (transaction_t *, sip_t *);
    void (*cb_ist_6xx_sent) (transaction_t *, sip_t *);
    void (*cb_ist_3456xx_sent2) (transaction_t *, sip_t *);

    void (*cb_ist_transport_error) (transaction_t *, int error);


    /* callbacks for nict */
    void (*cb_nict_kill_transaction) (transaction_t *);
    void (*cb_nict_register_sent) (transaction_t *, sip_t *);
    void (*cb_nict_bye_sent) (transaction_t *, sip_t *);
    void (*cb_nict_options_sent) (transaction_t *, sip_t *);
    void (*cb_nict_info_sent) (transaction_t *, sip_t *);
    void (*cb_nict_cancel_sent) (transaction_t *, sip_t *);
    void (*cb_nict_notify_sent) (transaction_t *, sip_t *);
    void (*cb_nict_subscribe_sent) (transaction_t *, sip_t *);
    void (*cb_nict_unknown_sent) (transaction_t *, sip_t *);
    void (*cb_nict_request_sent2) (transaction_t *, sip_t *);
    void (*cb_nict_1xx_received) (transaction_t *, sip_t *);
    void (*cb_nict_2xx_received) (transaction_t *, sip_t *);
    void (*cb_nict_2xx_received2) (transaction_t *, sip_t *);
    void (*cb_nict_3xx_received) (transaction_t *, sip_t *);
    void (*cb_nict_4xx_received) (transaction_t *, sip_t *);
    void (*cb_nict_5xx_received) (transaction_t *, sip_t *);
    void (*cb_nict_6xx_received) (transaction_t *, sip_t *);
    void (*cb_nict_3456xx_received2) (transaction_t *, sip_t *);
    void (*cb_nict_transport_error) (transaction_t *, int error);

    /* callbacks for nist */
    void (*cb_nist_kill_transaction) (transaction_t *);
    void (*cb_nist_register_received) (transaction_t *, sip_t *);
    void (*cb_nist_bye_received) (transaction_t *, sip_t *);
    void (*cb_nist_options_received) (transaction_t *, sip_t *);
    void (*cb_nist_info_received) (transaction_t *, sip_t *);
    void (*cb_nist_cancel_received) (transaction_t *, sip_t *);
    void (*cb_nist_notify_received) (transaction_t *, sip_t *);
    void (*cb_nist_subscribe_received) (transaction_t *, sip_t *);
    /* ... TO BE ADDED: All known and used method extensions */
    void (*cb_nist_unknown_received) (transaction_t *, sip_t *);
    void (*cb_nist_request_received2) (transaction_t *, sip_t *);
    void (*cb_nist_1xx_sent) (transaction_t *, sip_t *);
    void (*cb_nist_2xx_sent) (transaction_t *, sip_t *);
    void (*cb_nist_2xx_sent2) (transaction_t *, sip_t *);
    void (*cb_nist_3xx_sent) (transaction_t *, sip_t *);
    void (*cb_nist_4xx_sent) (transaction_t *, sip_t *);
    void (*cb_nist_5xx_sent) (transaction_t *, sip_t *);
    void (*cb_nist_6xx_sent) (transaction_t *, sip_t *);
    void (*cb_nist_3456xx_sent2) (transaction_t *, sip_t *);
    void (*cb_nist_transport_error) (transaction_t *, int error);

  };


/**
 * Structure for sipevent handling.
 * A sipevent_t element will have a type and will be related
 * to a transaction. In the general case, it is used by the
 * application layer to give SIP messages to the oSIP finite
 * state machine.
 * @defvar sipevent_t
 */
  typedef struct sipevent_t sipevent_t;

  struct sipevent_t
  {
    type_t type;
    int transactionid;
    sip_t *sip;
  };

#ifndef DOXYGEN

/**
 * Allocate an ict_t element. (for outgoing INVITE transaction)
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param ict The element to allocate.
 * @param osip The global instance of oSIP.
 * @param invite The SIP request that initiate the transaction.
 */
  int ict_init (ict_t ** ict, osip_t * osip, sip_t * invite);
/**
 * Free all resource in a ict_t element.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param ict The element to free.
 */
  int ict_free (ict_t * ict);

#endif

/**
 * Set the host and port destination used for sending the SIP message.
 * This can be useful for an application with 'DIRECT ROOTING MODE'
 * NOTE: Instead, you should use the 'Route' header facility which
 * leads to the same behaviour.
 * @param ict The element to work on.
 * @param destination The destination host.
 * @param port The destination port.
 */
  int ict_set_destination (ict_t * ict, char *destination, int port);

#ifndef DOXYGEN
/**
 * Check if this transaction needs a TIMEOUT_A event 
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param ict The element to work on.
 * @param state The actual state of the transaction.
 * @param transactionid The transaction id.
 */
  sipevent_t *ict_need_timer_a_event (ict_t * ict, state_t state,
				      int transactionid);
/**
 * Check if this transaction needs a TIMEOUT_B event 
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param ict The element to work on.
 * @param state The actual state of the transaction.
 * @param transactionid The transaction id.
 */
  sipevent_t *ict_need_timer_b_event (ict_t * ict, state_t state,
				      int transactionid);
/**
 * Check if this transaction needs a TIMEOUT_D event 
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param ict The element to work on.
 * @param state The actual state of the transaction.
 * @param transactionid The transaction id.
 */
  sipevent_t *ict_need_timer_d_event (ict_t * ict, state_t state,
				      int transactionid);

/**
 * Allocate an nict_t element. (for outgoing NON-INVITE transaction)
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param nict The element to allocate.
 * @param osip The global instance of oSIP.
 * @param request The SIP request that initiate the transaction.
 */
  int nict_init (nict_t ** nict, osip_t * osip, sip_t * request);
/**
 * Free all resource in an nict_t element.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param nict The element to free.
 */
  int nict_free (nict_t * nict);

#endif

/**
 * Set the host and port destination used for sending the SIP message.
 * This can be useful for an application with 'DIRECT ROOTING MODE'
 * NOTE: Instead, you should use the 'Route' header facility which
 * leads to the same behaviour.
 * @param nict The element to work on.
 * @param destination The destination host.
 * @param port The destination port.
 */
  int nict_set_destination (nict_t * nict, char *destination, int port);

#ifndef DOXYGEN

/**
 * Check if this transaction needs a TIMEOUT_E event 
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param nict The element to work on.
 * @param state The actual state of the transaction.
 * @param transactionid The transaction id.
 */
  sipevent_t *nict_need_timer_e_event (nict_t * nict, state_t state,
				       int transactionid);
/**
 * Check if this transaction needs a TIMEOUT_F event 
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param nict The element to work on.
 * @param state The actual state of the transaction.
 * @param transactionid The transaction id.
 */
  sipevent_t *nict_need_timer_f_event (nict_t * nict, state_t state,
				       int transactionid);
/**
 * Check if this transaction needs a TIMEOUT_K event 
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param nict The element to work on.
 * @param state The actual state of the transaction.
 * @param transactionid The transaction id.
 */
  sipevent_t *nict_need_timer_k_event (nict_t * nict, state_t state,
				       int transactionid);

/**
 * Allocate an ist_t element. (for incoming INVITE transaction)
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param ist The element to allocate.
 * @param osip The global instance of oSIP.
 * @param invite The SIP invite that initiate the transaction.
 */
  int ist_init (ist_t ** ist, osip_t * osip, sip_t * invite);
/**
 * Free all resource in a ist_t element.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param ist The element to free.
 */
  int ist_free (ist_t * ist);
  int ist_set_auto_send_100 (ist_t * ist, int abool);
/**
 * Check if this transaction needs a TIMEOUT_G event 
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param ist The element to work on.
 * @param state The actual state of the transaction.
 * @param transactionid The transaction id.
 */
  sipevent_t *ist_need_timer_g_event (ist_t * ist, state_t state,
				      int transactionid);
/**
 * Check if this transaction needs a TIMEOUT_H event 
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param ist The element to work on.
 * @param state The actual state of the transaction.
 * @param transactionid The transaction id.
 */
  sipevent_t *ist_need_timer_h_event (ist_t * ist, state_t state,
				      int transactionid);
/**
 * Check if this transaction needs a TIMEOUT_I event 
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param ist The element to work on.
 * @param state The actual state of the transaction.
 * @param transactionid The transaction id.
 */
  sipevent_t *ist_need_timer_i_event (ist_t * ist, state_t state,
				      int transactionid);

/**
 * Allocate an nist_t element. (for incoming NON-INVITE transaction)
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param nist The element to allocate.
 * @param osip The global instance of oSIP.
 * @param request The SIP request that initiate the transaction.
 */
  int nist_init (nist_t ** nist, osip_t * osip, sip_t * request);
/**
 * Free all resource in a nist_t element.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param nist The element to free.
 */
  int nist_free (nist_t * nist);

#endif

/**
 * Check if this transaction needs a TIMEOUT_J event 
 * @param nist The element to work on.
 * @param state The actual state of the transaction.
 * @param transactionid The transaction id.
 */
  sipevent_t *nist_need_timer_j_event (nist_t * nist, state_t state,
				       int transactionid);

/**
 * Allocate an transaction_t element.
 * @param transaction The element to allocate.
 * @param ctx_type The type of transaction. (ICT, IST, NICT, NIST)
 * @param osip The global instance of oSIP.
 * @param request The SIP request that initiate the transaction.
 */
  int transaction_init (transaction_t ** transaction, context_type_t ctx_type,
			osip_t * osip, sip_t * request);
/**
 * Free all resource in a transaction_t element.
 * @param transaction The element to free.
 */
  int transaction_free (transaction_t * transaction);
/**
 * Free all resource in a transaction_t element.
 * This method does the same than transaction_free() but it assumes
 * that the transaction is already removed from the list of transaction
 * in the osip stack. (to remove it use osip_xixt_remove(osip, transaction);
 * @param transaction The element to free.
 */
/*  */
  int transaction_free2 (transaction_t * transaction);

/**
 * Add a SIP event in the fifo of a transaction_t element.
 * @param transaction The element to work on.
 * @param evt The event to add.
 */
  int transaction_add_event (transaction_t * transaction, sipevent_t * evt);
/**
 * Consume one sipevent_t element previously added in the fifo.
 * NOTE: This method MUST NEVER be called within another call
 * of this method. (For example, you can't call transaction_execute()
 * in a callback registered in the osip_t element.)
 * @param transaction The element to free.
 * @param evt The element to consume.
 */
  int transaction_execute (transaction_t * transaction, sipevent_t * evt);
/**
 * Set a pointer to your personal context associated with this transaction.
 * NOTE: this is a very useful method that allow you to avoid searching
 * for your personal context inside the registered callbacks.
 * You can initialise this pointer to your context right after
 * the creation of the transaction_t element. Then, you'll be
 * able to get the address of your context by calling
 * transaction_get_your_instance().
 * @param transaction The element to work on.
 * @param instance The address of your context.
 */
  int transaction_set_your_instance (transaction_t * transaction,
				     void *instance);
/**
 * Get a pointer to your personal context associated with this transaction.
 * @param transaction The element to work on.
 */
  void *transaction_get_your_instance (transaction_t * transaction);

/**
 * Get target ip and port for this request.
 * (automaticly set by transaction_init() for ict and nict)
 * @param transaction The element to work on.
 * @param The host where to send initial request.
 * @param The port where to send initial request.
 */
  int transaction_get_destination(transaction_t * transaction, char **ip, int *port);

#ifndef DOXYGEN

/**
 * Set the Top Via value associated to this transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param transaction The element to work on.
 * @param topvia The topvia header.
 */
  int transaction_set_topvia (transaction_t * transaction, via_t * topvia);
/**
 * Set the from value associated to this transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param transaction The element to work on.
 * @param from The from header.
 */
  int transaction_set_from (transaction_t * transaction, from_t * from);
/**
 * Set the to value associated to this transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param transaction The element to work on.
 * @param to The to header.
 */
  int transaction_set_to (transaction_t * transaction, to_t * to);
/**
 * Set the Call-Id value associated to this transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param transaction The element to work on.
 * @param call_id The Call-Id header.
 */
  int transaction_set_call_id (transaction_t * transaction,
			       call_id_t * call_id);
/**
 * Set the cseq value associated to this transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param transaction The element to work on.
 * @param cseq The cseq header.
 */
  int transaction_set_cseq (transaction_t * transaction, cseq_t * cseq);
/**
 * Set the initial request associated to this transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param transaction The element to work on.
 * @param request The initial request.
 */
  int transaction_set_orig_request (transaction_t * transaction,
				    sip_t * request);
/**
 * Set the last RESPONSE associated to this transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param transaction The element to work on.
 * @param last_response The last RESPONSE.
 */
  int transaction_set_last_response (transaction_t * transaction,
				     sip_t * last_response);
/**
 * Set the ACK message associated to this transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param transaction The element to work on.
 * @param ack The ACK MESSAGE.
 */
  int transaction_set_ack (transaction_t * transaction, sip_t * ack);
/**
 * Set the state of the transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param transaction The element to work on.
 * @param state The new state.
 */
  int transaction_set_state (transaction_t * transaction, state_t state);
/**
 * Set the socket for incoming message.
 * NOTE: THIS HAS NEVER TESTED! Please send feedback.
 * @param transaction The element to work on.
 * @param sock The socket for incoming message.
 */
  int transaction_set_in_socket (transaction_t * transaction, int sock);
/**
 * Set the from value associated to this transaction.
 * NOTE: THIS HAS NEVER TESTED! Please send feedback.
 * @param transaction The element to work on.
 * @param sock The socket for outgoing message.
 */
  int transaction_set_out_socket (transaction_t * transaction, int sock);
/**
 * Set the from value associated to this transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param transaction The element to work on.
 * @param osip The osip_t element.
 */
  int transaction_set_config (transaction_t * transaction, osip_t * osip);

/**
 * Check if the response match a server transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param tr The transaction.
 * @param resp The SIP response received.
 */
  int transaction_matching_response_to_xict_17_1_3 (transaction_t * tr,
						    sip_t * resp);
/**
 * Check if the request match a client transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param tr The transaction.
 * @param request The SIP request received.
 */
  int transaction_matching_request_to_xist_17_2_3 (transaction_t * tr,
						   sip_t * request);
/**
 * Check if the tags in the From headers match.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param from1 The first From header.
 * @param from2 The second From header.
 */
  int from_tag_match (from_t * from1, from_t * from2);
/**
 * Check if the tags in the To headers match.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param to1 The first To header.
 * @param to2 The second To header.
 */
  int to_tag_match (to_t * to1, to_t * to2);
/**
 * Check if the Via headers match.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param via1 The first Via header.
 * @param via2 The second Via header.
 */
  int via_match (via_t * via1, via_t * via2);
/**
 * Check if the first 2 parameters match the other ones.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param to1 The initial to header.
 * @param from1 The initial from header.
 * @param to2 The new to header.
 * @param from2 The new from header.
 */
  int callleg_match (to_t * to1, from_t * from1, to_t * to2, from_t * from2);
/**
 * Check if the Call-Id headers match.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param callid1 The initial Call-Id header.
 * @param callid2 The new Call-Id header.
 */
  int call_id_match (call_id_t * callid1, call_id_t * callid2);
/**
 * Check if the CSeq headers match.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param cseq1 The initial CSeq header.
 * @param cseq2 The new CSeq header.
 */
  int cseq_match (cseq_t * cseq1, cseq_t * cseq2);

#endif				/* endif DOXYGEN */

/**
 * Initialise the global oSIP stack elements.
 * This method initialise the parser and load the fsm.
 * This method MUST be called before any call to oSIP is made.
 */
  int osip_global_init ();
/**
 * Free all global resource hold by the oSIP stack.
 * This can only be called after all osip_t element has been "stopped".
 */
  void osip_global_free ();
/** 
 * Allocate an osip_t element.
 * @param osip the element to allocate.
 */
  int osip_init (osip_t ** osip);
/**
 * Free all resource in a osip_t element.
 * @param osip The element to free.
 */
/**
 * Free all resource in a osip_t element.
 * @param osip The element to free.
 */
  void osip_free (osip_t * osip);

/**
 * Set a pointer in a osip_t element.
 * This help to find your application layer in callbacks.
 * @param osip The element to free.
 */
  void osip_set_application_context (osip_t * osip, void *pointer);

/**
 * Get a pointer in a osip_t element.
 * This help to find your application layer in callbacks.
 * @param osip The element to free.
 */
  void *osip_get_application_context (osip_t * osip);

#ifndef DOXYGEN

/**
 * Lock access to the list of ict transactions.
 * @param osip The element to work on.
 */
  int osip_ict_lock (osip_t * osip);
/**
 * Unlock access to the list of ict transactions.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param osip The element to work on.
 */
  int osip_ict_unlock (osip_t * osip);
/**
 * Lock access to the list of ist transactions.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param osip The element to work on.
 */
  int osip_ist_lock (osip_t * osip);
/**
 * Unlock access to the list of ist transactions.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param osip The element to work on.
 */
  int osip_ist_unlock (osip_t * osip);
/**
 * Lock access to the list of nict transactions.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param osip The element to work on.
 */
  int osip_nict_lock (osip_t * osip);
/**
 * Unlock access to the list of nict transactions.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param osip The element to work on.
 */
  int osip_nict_unlock (osip_t * osip);
/**
 * Lock access to the list of nist transactions.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param osip The element to work on.
 */
  int osip_nist_lock (osip_t * osip);
/**
 * Unlock access to the list of nist transactions.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param osip The element to work on.
 */
  int osip_nist_unlock (osip_t * osip);
/**
 * Add a ict transaction in the ict list of transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param osip The element to work on.
 * @param ict The transaction to add.
 */
  int osip_add_ict (osip_t * osip, transaction_t * ict);
/**
 * Add a ist transaction in the ist list of transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param osip The element to work on.
 * @param ist The transaction to add.
 */
  int osip_add_ist (osip_t * osip, transaction_t * ist);
/**
 * Add a nict transaction in the nict list of transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param osip The element to work on.
 * @param nict The transaction to add.
 */
  int osip_add_nict (osip_t * osip, transaction_t * nict);
/**
 * Add a nist transaction in the nist list of transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param osip The element to work on.
 * @param nist The transaction to add.
 */
  int osip_add_nist (osip_t * osip, transaction_t * nist);
/**
 * Remove a ict transaction from the ict list of transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param osip The element to work on.
 * @param ict The transaction to add.
 */
  int osip_remove_ict (osip_t * osip, transaction_t * ict);
/**
 * Remove a ist transaction from the ist list of transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param osip The element to work on.
 * @param ist The transaction to add.
 */
  int osip_remove_ist (osip_t * osip, transaction_t * ist);
/**
 * Remove a nict transaction from the nict list of transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param osip The element to work on.
 * @param nict The transaction to add.
 */
  int osip_remove_nict (osip_t * osip, transaction_t * nict);
/**
 * Remove a nist transaction from the nist list of transaction.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param osip The element to work on.
 * @param nist The transaction to add.
 */
  int osip_remove_nist (osip_t * osip, transaction_t * nist);

#endif

/**
 * Consume ALL pending sipevent_t previously added in the fifos of ict transactions.
 * @param osip The element to work on.
 */
  int osip_ict_execute (osip_t * osip);
/**
 * Consume ALL pending sipevent_t previously added in the fifos of ist transactions.
 * @param osip The element to work on.
 */
  int osip_ist_execute (osip_t * osip);
/**
 * Consume ALL pending sipevent_t previously added in the fifos of nict transactions.
 * @param osip The element to work on.
 */
  int osip_nict_execute (osip_t * osip);
/**
 * Consume ALL pending sipevent_t previously added in the fifos of nist transactions.
 * @param osip The element to work on.
 */
  int osip_nist_execute (osip_t * osip);

/**
 * Check if an ict transactions needs a timer event.
 * @param osip The element to work on.
 */
  void osip_timers_ict_execute (osip_t * osip);
/**
 * Check if an ist transactions needs a timer event.
 * @param osip The element to work on.
 */
  void osip_timers_ist_execute (osip_t * osip);
/**
 * Check if a nict transactions needs a timer event.
 * @param osip The element to work on.
 */
  void osip_timers_nict_execute (osip_t * osip);
/**
 * Check if a nist transactions needs a timer event.
 * @param osip The element to work on.
 */
  void osip_timers_nist_execute (osip_t * osip);

/* obsolete in 0.8.4: see comments in fsm/osip.c */
/* transaction_t *osip_distribute_event(osip_t *osip,sipevent_t* sipevent); */

/* obsolete: use osip_find_transaction + osip_create_transaction */
/**
 * Search for a transaction that match this event (MUST be a MESSAGE event).
 * @param transactions The list of transactions to work on.
 * @param evt The element representing the SIP MESSAGE.
 */
  transaction_t *osip_transaction_find (list_t * transactions,
					sipevent_t * evt);

/*
  BUG!!!
  BUG!!! there is a possible race conditions with this new method!!!
  BUG!!!
*/

/**
 * OBSOLETE!! -> some race conditions can happen in multi threaded applications.
 * <BR>Search for a transaction that match this event (MUST be a MESSAGE event).
 * @param osip The element to work on.
 * @param evt The element representing the SIP MESSAGE.
 */
#ifndef OSIP_MT
  transaction_t *osip_find_transaction (osip_t * osip, sipevent_t * evt);
#endif

  transaction_t *__osip_find_transaction (osip_t * osip, sipevent_t * evt,
					  int consume);

/**
 * Search for a transaction that match this event (MUST be a MESSAGE event)
 * and add this event if a transaction is found..
 * @param osip The element to work on.
 * @param evt The element representing the SIP MESSAGE.
 */
  int osip_find_transaction_and_add_event (osip_t * osip, sipevent_t * evt);

/**
 * Create a transaction for this event (MUST be a SIP REQUEST event).
 * @param osip The element to work on.
 * @param evt The element representing the new SIP REQUEST.
 */
  transaction_t *osip_create_transaction (osip_t * osip, sipevent_t * evt);

/**
 * Create a sipevent from a SIP message string.
 * @param buf The SIP message as a string.
 */
  sipevent_t *osip_parse (char *buf);

#ifndef DOXYGEN

/**
 * Allocate a sipevent.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param type The type of the event.
 * @param transactionid The transaction id for this event.
 */
  sipevent_t *osip_new_event (type_t type, int transactionid);
/**
 * Allocate a sipevent (we know this message is an INCOMING SIP message).
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param type The type of the event.
 * @param transactionid The transaction id for this event.
 */
  sipevent_t *osip_new_incoming_sipmessage (sip_t * sip);

#endif

/**
 * Allocate a sipevent (we know this message is an OUTGOING SIP message).
 * @param sip The SIP message we want to send.
 */
  sipevent_t *osip_new_outgoing_sipmessage (sip_t * sip);


/**
 * Register the callback used to send SIP message.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_send_message (osip_t * cf,
				int (*cb) (transaction_t *, sip_t *, char *,
					   int, int));
/* callbacks for ict */
/**
 * Register the callback called when the transaction is deleted.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ict_kill_transaction (osip_t * cf,
					void (*cb) (transaction_t *));
/**
 * Register the callback called when an INVITE is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ict_invite_sent (osip_t * cf,
				   void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when an INVITE is retransmitted.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ict_invite_sent2 (osip_t * cf,
				    void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when an ACK is sent.
 * NOTE: This method is only called if the final response was not a 2xx
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ict_ack_sent (osip_t * cf,
				void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when an ACK is retransmitted.
 * NOTE: This method is only called if the final response was not a 2xx
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ict_ack_sent2 (osip_t * cf,
				 void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 1xx SIP message is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ict_1xx_received (osip_t * cf,
				    void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 2xx SIP message is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ict_2xx_received (osip_t * cf,
				    void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 2xx SIP message is received again.
 * NOTE: obsolete... THIS IS NEVER CALLED! as the transaction is destroyed
 * when the first 200 is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ict_2xx_received2 (osip_t * cf,
				     void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 3xx SIP message is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ict_3xx_received (osip_t * cf,
				    void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 4xx SIP message is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ict_4xx_received (osip_t * cf,
				    void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 5xx SIP message is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ict_5xx_received (osip_t * cf,
				    void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 6xx SIP message is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ict_6xx_received (osip_t * cf,
				    void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a retransmission of a final response is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ict_3456xx_received2 (osip_t * cf,
					void (*cb) (transaction_t *,
						    sip_t *));
/**
 * Register the callback called when a transport error happens.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ict_transport_error (osip_t * cf,
				       void (*cb) (transaction_t *,
						   int error));

/* callbacks for ist */
/**
 * Register the callback called when the transaction is deleted.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ist_kill_transaction (osip_t * cf,
					void (*cb) (transaction_t *));
/**
 * Register the callback called when an INVITE is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ist_invite_received (osip_t * cf,
				       void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when an INVITE is received again.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ist_invite_received2 (osip_t * cf,
					void (*cb) (transaction_t *,
						    sip_t *));
/**
 * Register the callback called when an ACK is received.
 * NOTE: This method is only called if the final response was not a 2xx
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ist_ack_received (osip_t * cf,
				    void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when an ACK is received again.
 * NOTE: This method is only called if the final response was not a 2xx
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ist_ack_received2 (osip_t * cf,
				     void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 1xx SIP message is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ist_1xx_sent (osip_t * cf,
				void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 1xx SIP message is sent again.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ist_1xx_sent2 (osip_t * cf,
				 void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 2xx SIP message is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ist_2xx_sent (osip_t * cf,
				void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 2xx SIP message is sent again.
 * NOTE: This method is never called because the transaction is destroyed
 * right after the first 200 OK is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ist_2xx_sent2 (osip_t * cf,
				 void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 3xx SIP message is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ist_3xx_sent (osip_t * cf,
				void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 4xx SIP message is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ist_4xx_sent (osip_t * cf,
				void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 5xx SIP message is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ist_5xx_sent (osip_t * cf,
				void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 6xx SIP message is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ist_6xx_sent (osip_t * cf,
				void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a final response (not 200) is sent again.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ist_3456xx_sent2 (osip_t * cf,
				    void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a transport error happens.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_ist_transport_error (osip_t * cf,
				       void (*cb) (transaction_t *,
						   int error));


/* callbacks for nict */
/**
 * Register the callback called when the transaction is deleted.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nict_kill_transaction (osip_t * cf,
					 void (*cb) (transaction_t *));
/**
 * Register the callback called when an REGISTER is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nict_register_sent (osip_t * cf,
				      void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when an BYE is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nict_bye_sent (osip_t * cf,
				 void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when an OPTIONS is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nict_options_sent (osip_t * cf,
				     void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when an INFO is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nict_info_sent (osip_t * cf,
				  void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when an CANCEL is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nict_cancel_sent (osip_t * cf,
				    void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when an NOTIFY is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nict_notify_sent (osip_t * cf,
				    void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when an SUBSCRIBE is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nict_subscribe_sent (osip_t * cf,
				       void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when an UNKNOWN REQUEST is sent.
 * NOTE: All SIP request that do not have specific callback
 * will use this one.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nict_unknown_sent (osip_t * cf,
				     void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when an REQUEST is sent again.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nict_request_sent2 (osip_t * cf,
				      void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 1xx SIP message is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nict_1xx_received (osip_t * cf,
				     void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 2xx SIP message is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nict_2xx_received (osip_t * cf,
				     void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 2xx SIP message is received again.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nict_2xx_received2 (osip_t * cf,
				      void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 3xx SIP message is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nict_3xx_received (osip_t * cf,
				     void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 4xx SIP message is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nict_4xx_received (osip_t * cf,
				     void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 5xx SIP message is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nict_5xx_received (osip_t * cf,
				     void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 6xx SIP message is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nict_6xx_received (osip_t * cf,
				     void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a final response (not 200) is received again.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nict_3456xx_received2 (osip_t * cf,
					 void (*cb) (transaction_t *,
						     sip_t *));
/**
 * Register the callback called when a transport error happens.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nict_transport_error (osip_t * cf,
					void (*cb) (transaction_t *,
						    int error));

  /* callbacks for nist */
/**
 * Register the callback called when the transaction is deleted.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nist_kill_transaction (osip_t * cf,
					 void (*cb) (transaction_t *));
/**
 * Register the callback called when an REGISTER is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nist_register_received (osip_t * cf,
					  void (*cb) (transaction_t *,
						      sip_t *));
/**
 * Register the callback called when an BYE is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nist_bye_received (osip_t * cf,
				     void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when an OPTIONS is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nist_options_received (osip_t * cf,
					 void (*cb) (transaction_t *,
						     sip_t *));
/**
 * Register the callback called when an INFO is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nist_info_received (osip_t * cf,
				      void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when an CANCEL is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nist_cancel_received (osip_t * cf,
					void (*cb) (transaction_t *,
						    sip_t *));
/**
 * Register the callback called when an NOTIFY is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nist_notify_received (osip_t * cf,
					void (*cb) (transaction_t *,
						    sip_t *));
/**
 * Register the callback called when an SUBSCRIBE is received.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nist_subscribe_received (osip_t * cf,
					   void (*cb) (transaction_t *,
						       sip_t *));
/**
 * Register the callback called when an unknown REQUEST is received.
 * NOTE: When the message does not have a specific callback, this
 * callback is used instead.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nist_unknown_received (osip_t * cf,
					 void (*cb) (transaction_t *,
						     sip_t *));
  /* ... TO BE ADDED: All known and used method extensions */
/**
 * Register the callback called when a REQUEST is received again.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nist_request_received2 (osip_t * cf,
					  void (*cb) (transaction_t *,
						      sip_t *));
/**
 * Register the callback called when a 1xx SIP message is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nist_1xx_sent (osip_t * cf,
				 void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 2xx SIP message is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nist_2xx_sent (osip_t * cf,
				 void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 2xx SIP message is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nist_2xx_sent2 (osip_t * cf,
				  void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 3xx SIP message is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nist_3xx_sent (osip_t * cf,
				 void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 4xx SIP message is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nist_4xx_sent (osip_t * cf,
				 void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 5xx SIP message is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nist_5xx_sent (osip_t * cf,
				 void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a 6xx SIP message is sent.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nist_6xx_sent (osip_t * cf,
				 void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a final response is sent again.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nist_3456xx_sent2 (osip_t * cf,
				     void (*cb) (transaction_t *, sip_t *));
/**
 * Register the callback called when a transport error happens.
 * @param cf The osip element attached to the transaction.
 * @param cb The method we want to register.
 */
  void osip_setcb_nist_transport_error (osip_t * cf,
					void (*cb) (transaction_t *,
						    int error));


/* FOR INCOMING TRANSACTION */
/**
 * Check if the sipevent is of type RCV_REQINVITE.
 * @param event the event to check.
 */
#define EVT_IS_RCV_INVITE(event)       (event->type==RCV_REQINVITE)
/**
 * Check if the sipevent is of type RCV_REQACK.
 * @param event the event to check.
 */
#define EVT_IS_RCV_ACK(event)          (event->type==RCV_REQACK)
/**
 * Check if the sipevent is of type RCV_REQUEST.
 * @param event the event to check.
 */
#define EVT_IS_RCV_REQUEST(event)      (event->type==RCV_REQUEST)
/**
 * Check if the sipevent is of type RCV_STATUS_1XX.
 * @param event the event to check.
 */
#define EVT_IS_RCV_STATUS_1XX(event)   (event->type==RCV_STATUS_1XX)
/**
 * Check if the sipevent is of type RCV_STATUS_2XX.
 * @param event the event to check.
 */
#define EVT_IS_RCV_STATUS_2XX(event)   (event->type==RCV_STATUS_2XX)
/**
 * Check if the sipevent is of type RCV_STATUS_3456XX.
 * @param event the event to check.
 */
#define EVT_IS_RCV_STATUS_3456XX(event)   (event->type==RCV_STATUS_3456XX)


/* FOR OUTGOING TRANSACTION */
/**
 * Check if the sipevent is of type SND_REQINVITE.
 * @param event the event to check.
 */
#define EVT_IS_SND_INVITE(event)       (event->type==SND_REQINVITE)
/**
 * Check if the sipevent is of type SND_REQACK.
 * @param event the event to check.
 */
#define EVT_IS_SND_ACK(event)          (event->type==SND_REQACK)
/**
 * Check if the sipevent is of type SND_REQUEST.
 * @param event the event to check.
 */
#define EVT_IS_SND_REQUEST(event)      (event->type==SND_REQUEST)
/**
 * Check if the sipevent is of type SND_STATUS_1XX.
 * @param event the event to check.
 */
#define EVT_IS_SND_STATUS_1XX(event)   (event->type==SND_STATUS_1XX)
/**
 * Check if the sipevent is of type SND_STATUS_2XX.
 * @param event the event to check.
 */
#define EVT_IS_SND_STATUS_2XX(event)   (event->type==SND_STATUS_2XX)
/**
 * Check if the sipevent is of type SND_STATUS_3456XX.
 * @param event the event to check.
 */
#define EVT_IS_SND_STATUS_3456XX(event)   (event->type==SND_STATUS_3456XX)
/**
 * Check if the sipevent is of an incoming SIP MESSAGE.
 * @param event the event to check.
 */
#define EVT_IS_INCOMINGMSG(event)      (event->type>=RCV_REQINVITE \
                	               &&event->type<=RCV_STATUS_3456XX)
/**
 * Check if the sipevent is of an incoming SIP REQUEST.
 * @param event the event to check.
 */
#define EVT_IS_INCOMINGREQ(event)      (EVT_IS_RCV_INVITE(event) \
                                       ||EVT_IS_RCV_ACK(event) \
                                       ||EVT_IS_RCV_REQUEST(event))
/**
 * Check if the sipevent is of an incoming SIP RESPONSE.
 * @param event the event to check.
 */
#define EVT_IS_INCOMINGRESP(event)     (EVT_IS_RCV_STATUS_1XX(event) \
                                       ||EVT_IS_RCV_STATUS_2XX(event) \
				       ||EVT_IS_RCV_STATUS_3456XX(event))
/**
 * Check if the sipevent is of an outgoing SIP MESSAGE.
 * @param event the event to check.
 */
#define EVT_IS_OUTGOINGMSG(event)      (event->type>=SND_REQINVITE \
                	               &&event->type<=SND_STATUS_3456XX)
/**
 * Check if the sipevent is of an outgoing SIP REQUEST.
 * @param event the event to check.
 */
#define EVT_IS_OUTGOINGREQ(event)      (EVT_IS_SND_INVITE(event) \
                                       ||EVT_IS_SND_ACK(event) \
                                       ||EVT_IS_SND_REQUEST(event))
/**
 * Check if the sipevent is of an outgoing SIP RESPONSE.
 * @param event the event to check.
 */
#define EVT_IS_OUTGOINGRESP(event)     (EVT_IS_SND_STATUS_1XX(event) \
                                       ||EVT_IS_SND_STATUS_2XX(event) \
				       ||EVT_IS_SND_STATUS_3456XX(event))

/**
 * Check if the sipevent is a SIP MESSAGE.
 * @param event the event to check.
 */
#define EVT_IS_MSG(event)              (event->type>=RCV_REQINVITE \
                	               &&event->type<=SND_STATUS_3456XX)
/**
 * Check if the sipevent is of type KILL_TRANSACTION.
 * NOTE: THIS IS AN INTERNAL METHOD ONLY
 * @param event the event to check.
 */
#define EVT_IS_KILL_TRANSACTION(event) (event->type==KILL_TRANSACTION)

/*
 * Check if the sipevent is of type UNKNOWN_EVT.
 * NOTE: obsolete! This never happen.
 * @param event the event to check.
 */
/* #define EVT_IS_UNKNOWN_EVT(event)      (event->type==UNKNOWN_EVT) */
/*
 * Check if the sipevent is of type UNKNOWN_EVT.
 * NOTE: obsolete!
 * @param event the event to check.
 */
/* #define EVT_IS_TIMEOUT(event)          (event->type==TIMEOUT) */


#ifdef __cplusplus
}
#endif


/** @} */

#endif