libosip  4.1.0
osip.h
Go to the documentation of this file.
1 /*
2  The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
3  Copyright (C) 2001-2012 Aymeric MOIZARD amoizard@antisip.com
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 
21 #ifndef _OSIP_H_
22 #define _OSIP_H_
23 
24 #if defined(HAVE_DICT_DICT_H)
25 #include <dict/dict.h>
26 #endif
27 
28 #include <osipparser2/osip_const.h>
29 
30 /* Time-related functions and data types */
31 #include <osip2/osip_time.h>
32 
33 #ifdef __sun
34 #include <sys/types.h>
35 #endif
36 
38 #include <osip2/osip_fifo.h>
39 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 
62  typedef enum _state_t {
63  /* STATES for invite client transaction */
64  ICT_PRE_CALLING,
65  ICT_CALLING,
66  ICT_PROCEEDING,
67  ICT_COMPLETED,
68  ICT_TERMINATED,
69 
70  /* STATES for invite server transaction */
71  IST_PRE_PROCEEDING,
72  IST_PROCEEDING,
73  IST_COMPLETED,
74  IST_CONFIRMED,
75  IST_TERMINATED,
76 
77  /* STATES for NON-invite client transaction */
78  NICT_PRE_TRYING,
79  NICT_TRYING,
80  NICT_PROCEEDING,
81  NICT_COMPLETED,
82  NICT_TERMINATED,
83 
84  /* STATES for NON-invite server transaction */
85  NIST_PRE_TRYING,
86  NIST_TRYING,
87  NIST_PROCEEDING,
88  NIST_COMPLETED,
89  NIST_TERMINATED,
90 
91 #ifndef DOXYGEN
92  DIALOG_EARLY,
93  DIALOG_CONFIRMED,
94  DIALOG_CLOSE /* ?? */
95 #endif
96  } state_t;
97 
115  typedef enum type_t {
116  /* TIMEOUT EVENTS for ICT */
121  /* TIMEOUT EVENTS for NICT */
126  /* TIMEOUT EVENTS for IST */
131  /* TIMEOUT EVENTS for NIST */
134  /* FOR INCOMING MESSAGE */
142  /* FOR OUTGOING MESSAGE */
152  } type_t;
153 
162  typedef enum osip_fsm_type_t {
163  ICT,
164  IST,
167  } osip_fsm_type_t;
168 
169 #ifndef DEFAULT_T1
170 
174 #define DEFAULT_T1 500 /* 500 ms */
175 #endif
176 #ifndef DEFAULT_T1_TCP_PROGRESS
177 
185 #define DEFAULT_T1_TCP_PROGRESS 50 /* 50ms */
186 #endif
187 #ifndef DEFAULT_T2
188 
192 #define DEFAULT_T2 4000 /* 4s */
193 #endif
194 #ifndef DEFAULT_T4
195 
199 #define DEFAULT_T4 5000 /* 5s */
200 #endif
201 
202 
207  typedef struct osip_ict osip_ict_t;
208 
213  struct osip_ict {
215  struct timeval timer_a_start;
217  struct timeval timer_b_start;
219  struct timeval timer_d_start;
220  char *destination;
221  int port;
222  };
223 
228  typedef struct osip_nict osip_nict_t;
229 
234  struct osip_nict {
236  struct timeval timer_e_start;
238  struct timeval timer_f_start;
240  struct timeval timer_k_start;
241  char *destination;
242  int port;
244  };
245 
250  typedef struct osip_ist osip_ist_t;
251 
256  struct osip_ist {
258  struct timeval timer_g_start;
260  struct timeval timer_h_start;
262  struct timeval timer_i_start;
263  };
264 
269  typedef struct osip_nist osip_nist_t;
270 
275  struct osip_nist {
277  struct timeval timer_j_start;
278  };
279 
285 
291  struct osip_srv_entry {
292  char srv[512];
293  int priority;
294  int weight;
295  int rweight;
296  int port;
297  char ipaddress[512];
298  };
299 
300 #define OSIP_SRV_STATE_UNKNOWN 0
301 #define OSIP_SRV_STATE_RETRYLATER 2
302 #define OSIP_SRV_STATE_COMPLETED 3
303 #define OSIP_SRV_STATE_NOTSUPPORTED 4
309  typedef struct osip_srv_record osip_srv_record_t;
310 
316  char name[512];
317  int srv_state;
318  char protocol[64];
319  int order;
321  int index;
323  };
324 
325 #define OSIP_NAPTR_STATE_UNKNOWN 0
326 #define OSIP_NAPTR_STATE_INPROGRESS 1
327 #define OSIP_NAPTR_STATE_NAPTRDONE 2
328 #define OSIP_NAPTR_STATE_SRVINPROGRESS 3
329 #define OSIP_NAPTR_STATE_SRVDONE 4
330 #define OSIP_NAPTR_STATE_RETRYLATER 5
331 #define OSIP_NAPTR_STATE_NOTSUPPORTED 6
337  typedef struct osip_naptr osip_naptr_t;
338 
343  struct osip_naptr {
344  char domain[512];
346  void *arg;
353  };
354 
360 
366 
383  time_t birth_time;
384  time_t completed_time;
386  int in_socket;
389  void *config;
399  void *reserved1;
400  void *reserved2;
401  void *reserved3;
402  void *reserved4;
403  void *reserved5;
404  void *reserved6;
405  };
406 
407 
480 
484  typedef enum osip_kill_callback_type {
492 
504 
509  typedef void (*osip_message_cb_t) (int type, osip_transaction_t *, osip_message_t *);
514  typedef void (*osip_kill_transaction_cb_t) (int type, osip_transaction_t *);
519  typedef void (*osip_transport_error_cb_t) (int type, osip_transaction_t *, int error);
520 
521 
522  struct osip_dialog;
523 
528  typedef struct ixt ixt_t;
529 
534  struct ixt {
535  /* any ACK received that match this context will set counter to -1 */
536  struct osip_dialog *dialog;
539  struct timeval start;
540  int interval;
541  char *dest;
542  int port;
543  int sock;
544  int counter;
545  };
546 
547 
555  typedef struct osip osip_t;
556 
561  struct osip {
562 
570  void *id_mutex;
573  /* list of transactions for ict, ist, nict, nist */
585  int (*cb_send_message) (osip_transaction_t *, osip_message_t *, char *, int, int);
587 #if defined(HAVE_DICT_DICT_H)
588  dict *osip_ict_hastable;
589  dict *osip_ist_hastable;
590  dict *osip_nict_hastable;
591  dict *osip_nist_hastable;
592 #endif
593  };
594 
602 
610 
618 
627  typedef struct osip_event osip_event_t;
628 
633  struct osip_event {
637  };
638 
639 
640 
648  int osip_transaction_init (osip_transaction_t ** transaction, osip_fsm_type_t ctx_type, osip_t * osip, osip_message_t * request);
653  int osip_transaction_free (osip_transaction_t * transaction);
661  int osip_transaction_free2 (osip_transaction_t * transaction);
662 
670  void osip_response_get_destination (osip_message_t * response, char **address, int *portnum);
680  int osip_ict_set_destination (osip_ict_t * ict, char *destination, int port);
681 
691  int osip_nict_set_destination (osip_nict_t * nict, char *destination, int port);
692 
698  int osip_transaction_add_event (osip_transaction_t * transaction, osip_event_t * evt);
707  int osip_transaction_execute (osip_transaction_t * transaction, osip_event_t * evt);
720  int osip_transaction_set_your_instance (osip_transaction_t * transaction, void *ptr);
721 
733  int osip_transaction_set_reserved1 (osip_transaction_t * transaction, void *ptr);
740  int osip_transaction_set_reserved2 (osip_transaction_t * transaction, void *ptr);
741 
748  int osip_transaction_set_reserved3 (osip_transaction_t * transaction, void *ptr);
749 
756  int osip_transaction_set_reserved4 (osip_transaction_t * transaction, void *ptr);
757 
764  int osip_transaction_set_reserved5 (osip_transaction_t * transaction, void *ptr);
765 
772  int osip_transaction_set_reserved6 (osip_transaction_t * transaction, void *ptr);
773 
779  void *osip_transaction_get_your_instance (osip_transaction_t * transaction);
780 
785  void *osip_transaction_get_reserved1 (osip_transaction_t * transaction);
786 
791  void *osip_transaction_get_reserved2 (osip_transaction_t * transaction);
792 
797  void *osip_transaction_get_reserved3 (osip_transaction_t * transaction);
798 
803  void *osip_transaction_get_reserved4 (osip_transaction_t * transaction);
804 
809  void *osip_transaction_get_reserved5 (osip_transaction_t * transaction);
810 
815  void *osip_transaction_get_reserved6 (osip_transaction_t * transaction);
816 
824  int osip_transaction_get_destination (osip_transaction_t * transaction, char **ip, int *port);
825 
826 
833  int osip_transaction_set_srv_record (osip_transaction_t * transaction, osip_srv_record_t * record);
834 
841  int osip_transaction_set_naptr_record (osip_transaction_t * transaction, osip_naptr_t * record);
842 
849  int osip_transaction_set_in_socket (osip_transaction_t * transaction, int sock);
856  int osip_transaction_set_out_socket (osip_transaction_t * transaction, int sock);
857 
858 
859 
864  int osip_init (osip_t ** osip);
869  void osip_release (osip_t * osip);
870 
877  void osip_set_application_context (osip_t * osip, void *pointer);
878 
885 
886 
892  int osip_remove_transaction (osip_t * osip, osip_transaction_t * ict);
893 
894 
899  int osip_ict_execute (osip_t * osip);
904  int osip_ist_execute (osip_t * osip);
909  int osip_nict_execute (osip_t * osip);
914  int osip_nist_execute (osip_t * osip);
915 
924  void osip_timers_gettimeout (osip_t * osip, struct timeval *lower_tv);
925 
946 
947 /* Take care of mutlithreading issuewhile using this method */
953  osip_transaction_t *osip_transaction_find (osip_list_t * transactions, osip_event_t * evt);
954 
955 
956 #ifndef DOXYGEN
957 
964 #ifdef OSIP_MONOTHREAD
965  osip_transaction_t *osip_find_transaction (osip_t * osip, osip_event_t * evt);
966 #endif
967 
968  osip_transaction_t *__osip_find_transaction (osip_t * osip, osip_event_t * evt, int consume);
969 #endif
970 
978 
984  osip_transaction_t *osip_create_transaction (osip_t * osip, osip_event_t * evt);
985 
991  osip_event_t *osip_parse (const char *buf, size_t length);
992 
993 
999 
1007  void osip_start_200ok_retransmissions (osip_t * osip, struct osip_dialog *dialog, osip_message_t * msg200ok, int sock);
1008 
1018  void osip_start_ack_retransmissions (osip_t * osip, struct osip_dialog *dialog, osip_message_t * ack, char *dest, int port, int sock);
1019 
1026 
1035 
1036 
1042 
1047  void osip_event_free (osip_event_t * event);
1048 
1054  void osip_set_cb_send_message (osip_t * cf, int (*cb) (osip_transaction_t *, osip_message_t *, char *, int, int));
1055 
1056 /* FOR INCOMING TRANSACTION */
1061 #define EVT_IS_RCV_INVITE(event) (event->type==RCV_REQINVITE)
1062 
1066 #define EVT_IS_RCV_ACK(event) (event->type==RCV_REQACK)
1067 
1071 #define EVT_IS_RCV_REQUEST(event) (event->type==RCV_REQUEST)
1072 
1076 #define EVT_IS_RCV_STATUS_1XX(event) (event->type==RCV_STATUS_1XX)
1077 
1081 #define EVT_IS_RCV_STATUS_2XX(event) (event->type==RCV_STATUS_2XX)
1082 
1086 #define EVT_IS_RCV_STATUS_3456XX(event) (event->type==RCV_STATUS_3456XX)
1087 
1088 
1089 /* FOR OUTGOING TRANSACTION */
1094 #define EVT_IS_SND_INVITE(event) (event->type==SND_REQINVITE)
1095 
1099 #define EVT_IS_SND_ACK(event) (event->type==SND_REQACK)
1100 
1104 #define EVT_IS_SND_REQUEST(event) (event->type==SND_REQUEST)
1105 
1109 #define EVT_IS_SND_STATUS_1XX(event) (event->type==SND_STATUS_1XX)
1110 
1114 #define EVT_IS_SND_STATUS_2XX(event) (event->type==SND_STATUS_2XX)
1115 
1119 #define EVT_IS_SND_STATUS_3456XX(event) (event->type==SND_STATUS_3456XX)
1120 
1124 #define EVT_IS_INCOMINGMSG(event) (event->type>=RCV_REQINVITE \
1125  &&event->type<=RCV_STATUS_3456XX)
1126 
1130 #define EVT_IS_INCOMINGREQ(event) (EVT_IS_RCV_INVITE(event) \
1131  ||EVT_IS_RCV_ACK(event) \
1132  ||EVT_IS_RCV_REQUEST(event))
1133 
1137 #define EVT_IS_INCOMINGRESP(event) (EVT_IS_RCV_STATUS_1XX(event) \
1138  ||EVT_IS_RCV_STATUS_2XX(event) \
1139  ||EVT_IS_RCV_STATUS_3456XX(event))
1140 
1144 #define EVT_IS_OUTGOINGMSG(event) (event->type>=SND_REQINVITE \
1145  &&event->type<=SND_STATUS_3456XX)
1146 
1150 #define EVT_IS_OUTGOINGREQ(event) (EVT_IS_SND_INVITE(event) \
1151  ||EVT_IS_SND_ACK(event) \
1152  ||EVT_IS_SND_REQUEST(event))
1153 
1157 #define EVT_IS_OUTGOINGRESP(event) (EVT_IS_SND_STATUS_1XX(event) \
1158  ||EVT_IS_SND_STATUS_2XX(event) \
1159  ||EVT_IS_SND_STATUS_3456XX(event))
1160 
1165 #define EVT_IS_MSG(event) (event->type>=RCV_REQINVITE \
1166  &&event->type<=SND_STATUS_3456XX)
1167 
1172 #define EVT_IS_KILL_TRANSACTION(event) (event->type==KILL_TRANSACTION)
1173 
1174 #ifdef __cplusplus
1175 }
1176 #endif
1177 
1178 #endif