00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _OSIP_H_
00022 #define _OSIP_H_
00023
00024 #if defined(HAVE_DICT_DICT_H)
00025 #include <dict/dict.h>
00026 #endif
00027
00028 #include <osipparser2/osip_const.h>
00029
00030
00031 #include <osip2/osip_time.h>
00032
00033 #ifdef __sun
00034 #include <sys/types.h>
00035 #endif
00036
00037 #include <osipparser2/osip_parser.h>
00038 #include <osip2/osip_fifo.h>
00039
00052 #ifdef __cplusplus
00053 extern "C"
00054 {
00055 #endif
00056
00057
00063 typedef enum _state_t
00064 {
00065
00066 ICT_PRE_CALLING,
00067 ICT_CALLING,
00068 ICT_PROCEEDING,
00069 ICT_COMPLETED,
00070 ICT_TERMINATED,
00071
00072
00073 IST_PRE_PROCEEDING,
00074 IST_PROCEEDING,
00075 IST_COMPLETED,
00076 IST_CONFIRMED,
00077 IST_TERMINATED,
00078
00079
00080 NICT_PRE_TRYING,
00081 NICT_TRYING,
00082 NICT_PROCEEDING,
00083 NICT_COMPLETED,
00084 NICT_TERMINATED,
00085
00086
00087 NIST_PRE_TRYING,
00088 NIST_TRYING,
00089 NIST_PROCEEDING,
00090 NIST_COMPLETED,
00091 NIST_TERMINATED,
00092
00093 #ifndef DOXYGEN
00094 DIALOG_EARLY,
00095 DIALOG_CONFIRMED,
00096 DIALOG_CLOSE
00097 #endif
00098 }
00099 state_t;
00100
00118 typedef enum type_t
00119 {
00120
00121 TIMEOUT_A,
00122 TIMEOUT_B,
00123 TIMEOUT_D,
00125
00126 TIMEOUT_E,
00127 TIMEOUT_F,
00128 TIMEOUT_K,
00130
00131 TIMEOUT_G,
00132 TIMEOUT_H,
00133 TIMEOUT_I,
00135
00136 TIMEOUT_J,
00138
00139 RCV_REQINVITE,
00140 RCV_REQACK,
00141 RCV_REQUEST,
00142 RCV_STATUS_1XX,
00143 RCV_STATUS_2XX,
00144 RCV_STATUS_3456XX,
00146
00147 SND_REQINVITE,
00148 SND_REQACK,
00149 SND_REQUEST,
00150 SND_STATUS_1XX,
00151 SND_STATUS_2XX,
00152 SND_STATUS_3456XX,
00154 KILL_TRANSACTION,
00155 UNKNOWN_EVT
00156 }
00157 type_t;
00158
00167 typedef enum osip_fsm_type_t
00168 {
00169 ICT,
00170 IST,
00171 NICT,
00172 NIST
00173 }
00174 osip_fsm_type_t;
00175
00176 #ifndef DEFAULT_T1
00177
00181 #define DEFAULT_T1 500
00182 #endif
00183 #ifndef DEFAULT_T2
00184
00188 #define DEFAULT_T2 4000
00189 #endif
00190 #ifndef DEFAULT_T4
00191
00195 #define DEFAULT_T4 5000
00196 #endif
00197
00198
00203 typedef struct osip_ict osip_ict_t;
00204
00209 struct osip_ict
00210 {
00211 int timer_a_length;
00212 struct timeval timer_a_start;
00213 int timer_b_length;
00214 struct timeval timer_b_start;
00215 int timer_d_length;
00216 struct timeval timer_d_start;
00217 char *destination;
00218 int port;
00219 };
00220
00225 typedef struct osip_nict osip_nict_t;
00226
00231 struct osip_nict
00232 {
00233 int timer_e_length;
00234 struct timeval timer_e_start;
00235 int timer_f_length;
00236 struct timeval timer_f_start;
00237 int timer_k_length;
00238 struct timeval timer_k_start;
00239 char *destination;
00240 int port;
00242 };
00243
00248 typedef struct osip_ist osip_ist_t;
00249
00254 struct osip_ist
00255 {
00256 int timer_g_length;
00257 struct timeval timer_g_start;
00258 int timer_h_length;
00259 struct timeval timer_h_start;
00260 int timer_i_length;
00261 struct timeval timer_i_start;
00262 };
00263
00268 typedef struct osip_nist osip_nist_t;
00269
00274 struct osip_nist
00275 {
00276 int timer_j_length;
00277 struct timeval timer_j_start;
00278 };
00279
00284 typedef struct osip_srv_entry osip_srv_entry_t;
00285
00291 struct osip_srv_entry {
00292 char srv[512];
00293 int priority;
00294 int weight;
00295 int rweight;
00296 int port;
00297 };
00298
00303 typedef struct osip_srv_record osip_srv_record_t;
00304
00309 struct osip_srv_record {
00310 char name[512];
00311 char protocol[64];
00312 struct osip_srv_entry srventry[10];
00313 };
00314
00319 typedef struct osip_transaction osip_transaction_t;
00320
00325 struct osip_transaction
00326 {
00327
00328 void *your_instance;
00329 int transactionid;
00330 osip_fifo_t *transactionff;
00332 osip_via_t *topvia;
00333 osip_from_t *from;
00334 osip_to_t *to;
00335 osip_call_id_t *callid;
00336 osip_cseq_t *cseq;
00338 osip_message_t *orig_request;
00339 osip_message_t *last_response;
00340 osip_message_t *ack;
00342 state_t state;
00344 time_t birth_time;
00345 time_t completed_time;
00347 int in_socket;
00348 int out_socket;
00350 void *config;
00352 osip_fsm_type_t ctx_type;
00353 osip_ict_t *ict_context;
00354 osip_ist_t *ist_context;
00355 osip_nict_t *nict_context;
00356 osip_nist_t *nist_context;
00358 osip_srv_record_t record;
00359 };
00360
00361
00365 typedef enum osip_message_callback_type
00366 {
00367 OSIP_ICT_INVITE_SENT = 0,
00368 OSIP_ICT_INVITE_SENT_AGAIN,
00369 OSIP_ICT_ACK_SENT,
00370 OSIP_ICT_ACK_SENT_AGAIN,
00371 OSIP_ICT_STATUS_1XX_RECEIVED,
00372 OSIP_ICT_STATUS_2XX_RECEIVED,
00373 OSIP_ICT_STATUS_2XX_RECEIVED_AGAIN,
00374 OSIP_ICT_STATUS_3XX_RECEIVED,
00375 OSIP_ICT_STATUS_4XX_RECEIVED,
00376 OSIP_ICT_STATUS_5XX_RECEIVED,
00377 OSIP_ICT_STATUS_6XX_RECEIVED,
00378 OSIP_ICT_STATUS_3456XX_RECEIVED_AGAIN,
00380 OSIP_IST_INVITE_RECEIVED,
00381 OSIP_IST_INVITE_RECEIVED_AGAIN,
00382 OSIP_IST_ACK_RECEIVED,
00383 OSIP_IST_ACK_RECEIVED_AGAIN,
00384 OSIP_IST_STATUS_1XX_SENT,
00385 OSIP_IST_STATUS_2XX_SENT,
00386 OSIP_IST_STATUS_2XX_SENT_AGAIN,
00387 OSIP_IST_STATUS_3XX_SENT,
00388 OSIP_IST_STATUS_4XX_SENT,
00389 OSIP_IST_STATUS_5XX_SENT,
00390 OSIP_IST_STATUS_6XX_SENT,
00391 OSIP_IST_STATUS_3456XX_SENT_AGAIN,
00393 OSIP_NICT_REGISTER_SENT,
00394 OSIP_NICT_BYE_SENT,
00395 OSIP_NICT_OPTIONS_SENT,
00396 OSIP_NICT_INFO_SENT,
00397 OSIP_NICT_CANCEL_SENT,
00398 OSIP_NICT_NOTIFY_SENT,
00399 OSIP_NICT_SUBSCRIBE_SENT,
00400 OSIP_NICT_UNKNOWN_REQUEST_SENT,
00401 OSIP_NICT_REQUEST_SENT_AGAIN,
00402 OSIP_NICT_STATUS_1XX_RECEIVED,
00403 OSIP_NICT_STATUS_2XX_RECEIVED,
00404 OSIP_NICT_STATUS_2XX_RECEIVED_AGAIN,
00405 OSIP_NICT_STATUS_3XX_RECEIVED,
00406 OSIP_NICT_STATUS_4XX_RECEIVED,
00407 OSIP_NICT_STATUS_5XX_RECEIVED,
00408 OSIP_NICT_STATUS_6XX_RECEIVED,
00409 OSIP_NICT_STATUS_3456XX_RECEIVED_AGAIN,
00411 OSIP_NIST_REGISTER_RECEIVED,
00412 OSIP_NIST_BYE_RECEIVED,
00413 OSIP_NIST_OPTIONS_RECEIVED,
00414 OSIP_NIST_INFO_RECEIVED,
00415 OSIP_NIST_CANCEL_RECEIVED,
00416 OSIP_NIST_NOTIFY_RECEIVED,
00417 OSIP_NIST_SUBSCRIBE_RECEIVED,
00419 OSIP_NIST_UNKNOWN_REQUEST_RECEIVED,
00420 OSIP_NIST_REQUEST_RECEIVED_AGAIN,
00421 OSIP_NIST_STATUS_1XX_SENT,
00422 OSIP_NIST_STATUS_2XX_SENT,
00423 OSIP_NIST_STATUS_2XX_SENT_AGAIN,
00424 OSIP_NIST_STATUS_3XX_SENT,
00425 OSIP_NIST_STATUS_4XX_SENT,
00426 OSIP_NIST_STATUS_5XX_SENT,
00427 OSIP_NIST_STATUS_6XX_SENT,
00428 OSIP_NIST_STATUS_3456XX_SENT_AGAIN,
00430 OSIP_ICT_STATUS_TIMEOUT,
00431 OSIP_NICT_STATUS_TIMEOUT,
00433 OSIP_MESSAGE_CALLBACK_COUNT
00434 } osip_message_callback_type_t;
00435
00439 typedef enum osip_kill_callback_type
00440 {
00441 OSIP_ICT_KILL_TRANSACTION,
00442 OSIP_IST_KILL_TRANSACTION,
00443 OSIP_NICT_KILL_TRANSACTION,
00444 OSIP_NIST_KILL_TRANSACTION,
00446 OSIP_KILL_CALLBACK_COUNT
00447 } osip_kill_callback_type_t;
00448
00453 typedef enum osip_transport_error_callback_type
00454 {
00455 OSIP_ICT_TRANSPORT_ERROR,
00456 OSIP_IST_TRANSPORT_ERROR,
00457 OSIP_NICT_TRANSPORT_ERROR,
00458 OSIP_NIST_TRANSPORT_ERROR,
00460 OSIP_TRANSPORT_ERROR_CALLBACK_COUNT
00461 } osip_transport_error_callback_type_t;
00462
00467 typedef void (*osip_message_cb_t) (int type, osip_transaction_t *,
00468 osip_message_t *);
00473 typedef void (*osip_kill_transaction_cb_t) (int type, osip_transaction_t *);
00478 typedef void (*osip_transport_error_cb_t) (int type, osip_transaction_t *,
00479 int error);
00480
00481
00482 struct osip_dialog;
00483
00488 typedef struct ixt_t ixt_t;
00489
00494 struct ixt_t
00495 {
00496
00497 struct osip_dialog *dialog;
00498 osip_message_t *msg2xx;
00499 osip_message_t *ack;
00500 struct timeval start;
00501 int interval;
00502 char *dest;
00503 int port;
00504 int sock;
00505 int counter;
00506 };
00507
00508
00516 typedef struct osip osip_t;
00517
00522 struct osip
00523 {
00524
00525 void *application_context;
00527
00528 osip_list_t osip_ict_transactions;
00529 osip_list_t osip_ist_transactions;
00530 osip_list_t osip_nict_transactions;
00531 osip_list_t osip_nist_transactions;
00533 osip_list_t ixt_retransmissions;
00535 osip_message_cb_t msg_callbacks[OSIP_MESSAGE_CALLBACK_COUNT];
00536 osip_kill_transaction_cb_t kill_callbacks[OSIP_KILL_CALLBACK_COUNT];
00537 osip_transport_error_cb_t tp_error_callbacks[OSIP_TRANSPORT_ERROR_CALLBACK_COUNT];
00539 int (*cb_send_message) (osip_transaction_t *, osip_message_t *, char *,
00540 int, int);
00543 #if defined(HAVE_DICT_DICT_H)
00544 dict *osip_ict_hastable;
00545 dict *osip_ist_hastable;
00546 dict *osip_nict_hastable;
00547 dict *osip_nist_hastable;
00548 #endif
00549 };
00550
00557 int osip_set_message_callback (osip_t * osip, int type, osip_message_cb_t cb);
00558
00565 int osip_set_kill_transaction_callback (osip_t * osip, int type,
00566 osip_kill_transaction_cb_t cb);
00567
00574 int osip_set_transport_error_callback (osip_t * osip, int type,
00575 osip_transport_error_cb_t cb);
00576
00585 typedef struct osip_event osip_event_t;
00586
00591 struct osip_event
00592 {
00593 type_t type;
00594 int transactionid;
00595 osip_message_t *sip;
00596 };
00597
00598
00599
00607 int osip_transaction_init (osip_transaction_t ** transaction,
00608 osip_fsm_type_t ctx_type, osip_t * osip,
00609 osip_message_t * request);
00614 int osip_transaction_free (osip_transaction_t * transaction);
00622 int osip_transaction_free2 (osip_transaction_t * transaction);
00623
00631 void osip_response_get_destination (osip_message_t * response,
00632 char **address, int *portnum);
00642 int osip_ict_set_destination (osip_ict_t * ict, char *destination, int port);
00643
00653 int osip_nict_set_destination (osip_nict_t * nict, char *destination, int port);
00654
00660 int osip_transaction_add_event (osip_transaction_t * transaction,
00661 osip_event_t * evt);
00670 int osip_transaction_execute (osip_transaction_t * transaction,
00671 osip_event_t * evt);
00683 int osip_transaction_set_your_instance (osip_transaction_t * transaction,
00684 void *instance);
00689 void *osip_transaction_get_your_instance (osip_transaction_t * transaction);
00690
00698 int osip_transaction_get_destination (osip_transaction_t * transaction,
00699 char **ip, int *port);
00700
00701
00708 int osip_transaction_set_srv_record(osip_transaction_t *transaction, osip_srv_record_t *record);
00709
00716 int osip_transaction_set_in_socket (osip_transaction_t * transaction, int sock);
00723 int osip_transaction_set_out_socket (osip_transaction_t * transaction, int sock);
00724
00725
00726
00731 int osip_init (osip_t ** osip);
00736 void osip_release (osip_t * osip);
00737
00744 void osip_set_application_context (osip_t * osip, void *pointer);
00745
00751 void *osip_get_application_context (osip_t * osip);
00752
00753
00759 int osip_remove_transaction (osip_t * osip, osip_transaction_t * ict);
00760
00761
00766 int osip_ict_execute (osip_t * osip);
00771 int osip_ist_execute (osip_t * osip);
00776 int osip_nict_execute (osip_t * osip);
00781 int osip_nist_execute (osip_t * osip);
00782
00791 void osip_timers_gettimeout (osip_t * osip, struct timeval *lower_tv);
00792
00797 void osip_timers_ict_execute (osip_t * osip);
00802 void osip_timers_ist_execute (osip_t * osip);
00807 void osip_timers_nict_execute (osip_t * osip);
00812 void osip_timers_nist_execute (osip_t * osip);
00813
00814
00820 osip_transaction_t *osip_transaction_find (osip_list_t * transactions,
00821 osip_event_t * evt);
00822
00823
00824 #ifndef DOXYGEN
00825
00832 #ifndef OSIP_MT
00833 osip_transaction_t *osip_find_transaction (osip_t * osip, osip_event_t * evt);
00834 #endif
00835
00836 osip_transaction_t *__osip_find_transaction (osip_t * osip,
00837 osip_event_t * evt, int consume);
00838 #endif
00839
00846 int osip_find_transaction_and_add_event (osip_t * osip, osip_event_t * evt);
00847
00853 osip_transaction_t *osip_create_transaction (osip_t * osip, osip_event_t * evt);
00854
00860 osip_event_t *osip_parse (const char *buf, size_t length);
00861
00862
00867 void osip_retransmissions_execute (osip_t * osip);
00868
00876 void osip_start_200ok_retransmissions (osip_t * osip,
00877 struct osip_dialog *dialog,
00878 osip_message_t * msg200ok, int sock);
00879
00889 void osip_start_ack_retransmissions (osip_t * osip,
00890 struct osip_dialog *dialog,
00891 osip_message_t * ack, char *dest,
00892 int port, int sock);
00893
00899 struct osip_dialog *osip_stop_200ok_retransmissions (osip_t * osip,
00900 osip_message_t * ack);
00901
00909 void osip_stop_retransmissions_from_dialog (osip_t * osip,
00910 struct osip_dialog *dialog);
00911
00912
00917 osip_event_t *osip_new_outgoing_sipmessage (osip_message_t * sip);
00918
00923 void osip_event_free (osip_event_t * event);
00924
00930 void osip_set_cb_send_message (osip_t * cf,
00931 int (*cb) (osip_transaction_t *,
00932 osip_message_t *, char *, int, int));
00933
00934
00939 #define EVT_IS_RCV_INVITE(event) (event->type==RCV_REQINVITE)
00940
00944 #define EVT_IS_RCV_ACK(event) (event->type==RCV_REQACK)
00945
00949 #define EVT_IS_RCV_REQUEST(event) (event->type==RCV_REQUEST)
00950
00954 #define EVT_IS_RCV_STATUS_1XX(event) (event->type==RCV_STATUS_1XX)
00955
00959 #define EVT_IS_RCV_STATUS_2XX(event) (event->type==RCV_STATUS_2XX)
00960
00964 #define EVT_IS_RCV_STATUS_3456XX(event) (event->type==RCV_STATUS_3456XX)
00965
00966
00967
00972 #define EVT_IS_SND_INVITE(event) (event->type==SND_REQINVITE)
00973
00977 #define EVT_IS_SND_ACK(event) (event->type==SND_REQACK)
00978
00982 #define EVT_IS_SND_REQUEST(event) (event->type==SND_REQUEST)
00983
00987 #define EVT_IS_SND_STATUS_1XX(event) (event->type==SND_STATUS_1XX)
00988
00992 #define EVT_IS_SND_STATUS_2XX(event) (event->type==SND_STATUS_2XX)
00993
00997 #define EVT_IS_SND_STATUS_3456XX(event) (event->type==SND_STATUS_3456XX)
00998
01002 #define EVT_IS_INCOMINGMSG(event) (event->type>=RCV_REQINVITE \
01003 &&event->type<=RCV_STATUS_3456XX)
01004
01008 #define EVT_IS_INCOMINGREQ(event) (EVT_IS_RCV_INVITE(event) \
01009 ||EVT_IS_RCV_ACK(event) \
01010 ||EVT_IS_RCV_REQUEST(event))
01011
01015 #define EVT_IS_INCOMINGRESP(event) (EVT_IS_RCV_STATUS_1XX(event) \
01016 ||EVT_IS_RCV_STATUS_2XX(event) \
01017 ||EVT_IS_RCV_STATUS_3456XX(event))
01018
01022 #define EVT_IS_OUTGOINGMSG(event) (event->type>=SND_REQINVITE \
01023 &&event->type<=SND_STATUS_3456XX)
01024
01028 #define EVT_IS_OUTGOINGREQ(event) (EVT_IS_SND_INVITE(event) \
01029 ||EVT_IS_SND_ACK(event) \
01030 ||EVT_IS_SND_REQUEST(event))
01031
01035 #define EVT_IS_OUTGOINGRESP(event) (EVT_IS_SND_STATUS_1XX(event) \
01036 ||EVT_IS_SND_STATUS_2XX(event) \
01037 ||EVT_IS_SND_STATUS_3456XX(event))
01038
01043 #define EVT_IS_MSG(event) (event->type>=RCV_REQINVITE \
01044 &&event->type<=SND_STATUS_3456XX)
01045
01050 #define EVT_IS_KILL_TRANSACTION(event) (event->type==KILL_TRANSACTION)
01051
01052 #ifdef __cplusplus
01053 }
01054 #endif
01055
01056
01059 #endif