|
libosip 3.6.0
|
00001 /* 00002 The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 00003 Copyright (C) 2001,2002,2003,2004,2005,2006,2007 Aymeric MOIZARD jack@atosc.org 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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 /* Time-related functions and data types */ 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 #endif 00055 00056 00062 typedef enum _state_t { 00063 /* STATES for invite client transaction */ 00064 ICT_PRE_CALLING, 00065 ICT_CALLING, 00066 ICT_PROCEEDING, 00067 ICT_COMPLETED, 00068 ICT_TERMINATED, 00069 00070 /* STATES for invite server transaction */ 00071 IST_PRE_PROCEEDING, 00072 IST_PROCEEDING, 00073 IST_COMPLETED, 00074 IST_CONFIRMED, 00075 IST_TERMINATED, 00076 00077 /* STATES for NON-invite client transaction */ 00078 NICT_PRE_TRYING, 00079 NICT_TRYING, 00080 NICT_PROCEEDING, 00081 NICT_COMPLETED, 00082 NICT_TERMINATED, 00083 00084 /* STATES for NON-invite server transaction */ 00085 NIST_PRE_TRYING, 00086 NIST_TRYING, 00087 NIST_PROCEEDING, 00088 NIST_COMPLETED, 00089 NIST_TERMINATED, 00090 00091 #ifndef DOXYGEN 00092 DIALOG_EARLY, 00093 DIALOG_CONFIRMED, 00094 DIALOG_CLOSE /* ?? */ 00095 #endif 00096 } state_t; 00097 00115 typedef enum type_t { 00116 /* TIMEOUT EVENTS for ICT */ 00117 TIMEOUT_A, 00119 TIMEOUT_B, 00121 TIMEOUT_D, 00124 /* TIMEOUT EVENTS for NICT */ 00125 TIMEOUT_E, 00127 TIMEOUT_F, 00129 TIMEOUT_K, 00132 /* TIMEOUT EVENTS for IST */ 00133 TIMEOUT_G, 00135 TIMEOUT_H, 00137 TIMEOUT_I, 00140 /* TIMEOUT EVENTS for NIST */ 00141 TIMEOUT_J, 00144 /* FOR INCOMING MESSAGE */ 00145 RCV_REQINVITE, 00146 RCV_REQACK, 00147 RCV_REQUEST, 00148 RCV_STATUS_1XX, 00150 RCV_STATUS_2XX, 00152 RCV_STATUS_3456XX, 00155 /* FOR OUTGOING MESSAGE */ 00156 SND_REQINVITE, 00157 SND_REQACK, 00158 SND_REQUEST, 00159 SND_STATUS_1XX, 00161 SND_STATUS_2XX, 00163 SND_STATUS_3456XX, 00166 KILL_TRANSACTION, 00168 UNKNOWN_EVT 00169 } type_t; 00170 00179 typedef enum osip_fsm_type_t { 00180 ICT, 00182 IST, 00184 NICT, 00186 NIST 00188 } osip_fsm_type_t; 00189 00190 #ifndef DEFAULT_T1 00191 00195 #define DEFAULT_T1 500 /* 500 ms */ 00196 #endif 00197 #ifndef DEFAULT_T2 00198 00202 #define DEFAULT_T2 4000 /* 4s */ 00203 #endif 00204 #ifndef DEFAULT_T4 00205 00209 #define DEFAULT_T4 5000 /* 5s */ 00210 #endif 00211 00212 00217 typedef struct osip_ict osip_ict_t; 00218 00223 struct osip_ict { 00224 int timer_a_length; 00225 struct timeval timer_a_start; 00227 int timer_b_length; 00228 struct timeval timer_b_start; 00230 int timer_d_length; 00231 struct timeval timer_d_start; 00233 char *destination; 00234 int port; 00235 }; 00236 00241 typedef struct osip_nict osip_nict_t; 00242 00247 struct osip_nict { 00248 int timer_e_length; 00249 struct timeval timer_e_start; 00251 int timer_f_length; 00252 struct timeval timer_f_start; 00254 int timer_k_length; 00255 struct timeval timer_k_start; 00257 char *destination; 00258 int port; 00260 }; 00261 00266 typedef struct osip_ist osip_ist_t; 00267 00272 struct osip_ist { 00273 int timer_g_length; 00274 struct timeval timer_g_start; 00276 int timer_h_length; 00277 struct timeval timer_h_start; 00279 int timer_i_length; 00280 struct timeval timer_i_start; 00282 }; 00283 00288 typedef struct osip_nist osip_nist_t; 00289 00294 struct osip_nist { 00295 int timer_j_length; 00296 struct timeval timer_j_start; 00298 }; 00299 00304 typedef struct osip_srv_entry osip_srv_entry_t; 00305 00311 struct osip_srv_entry { 00312 char srv[512]; 00313 int priority; 00314 int weight; 00315 int rweight; 00316 int port; 00317 char ipaddress[512]; 00318 }; 00319 00320 #define OSIP_SRV_STATE_UNKNOWN 0 00321 /* #define OSIP_SRV_STATE_INPROGRESS 1 */ 00322 #define OSIP_SRV_STATE_RETRYLATER 2 00323 #define OSIP_SRV_STATE_COMPLETED 3 00324 #define OSIP_SRV_STATE_NOTSUPPORTED 4 00325 00330 typedef struct osip_srv_record osip_srv_record_t; 00331 00336 struct osip_srv_record { 00337 char name[512]; 00338 int srv_state; 00339 char protocol[64]; 00340 int order; 00341 int preference; 00342 int index; 00343 osip_srv_entry_t srventry[10]; 00344 }; 00345 00346 #define OSIP_NAPTR_STATE_UNKNOWN 0 00347 #define OSIP_NAPTR_STATE_INPROGRESS 1 00348 #define OSIP_NAPTR_STATE_NAPTRDONE 2 00349 #define OSIP_NAPTR_STATE_SRVINPROGRESS 3 00350 #define OSIP_NAPTR_STATE_SRVDONE 4 00351 #define OSIP_NAPTR_STATE_RETRYLATER 5 00352 #define OSIP_NAPTR_STATE_NOTSUPPORTED 6 00353 00358 typedef struct osip_naptr osip_naptr_t; 00359 00364 struct osip_naptr { 00365 char domain[512]; 00366 int naptr_state; 00367 void *arg; 00368 int keep_in_cache; 00369 struct osip_srv_record sipudp_record; 00370 struct osip_srv_record siptcp_record; 00371 struct osip_srv_record siptls_record; 00372 struct osip_srv_record sipdtls_record; 00373 struct osip_srv_record sipsctp_record; 00374 }; 00375 00380 typedef struct osip_transaction osip_transaction_t; 00381 00386 struct osip_transaction { 00387 00388 void *your_instance; 00389 int transactionid; 00390 osip_fifo_t *transactionff; 00393 osip_via_t *topvia; 00394 osip_from_t *from; 00395 osip_to_t *to; 00396 osip_call_id_t *callid; 00397 osip_cseq_t *cseq; 00399 osip_message_t *orig_request; 00401 osip_message_t *last_response; 00403 osip_message_t *ack; 00405 state_t state; 00407 time_t birth_time; 00408 time_t completed_time; 00410 int in_socket; 00411 int out_socket; 00413 void *config; 00415 osip_fsm_type_t ctx_type; 00417 osip_ict_t *ict_context; 00418 osip_ist_t *ist_context; 00419 osip_nict_t *nict_context; 00421 osip_nist_t *nist_context; 00424 osip_srv_record_t record; 00425 osip_naptr_t *naptr_record; 00427 }; 00428 00429 00433 typedef enum osip_message_callback_type { 00434 OSIP_ICT_INVITE_SENT = 0, 00435 OSIP_ICT_INVITE_SENT_AGAIN, 00436 OSIP_ICT_ACK_SENT, 00437 OSIP_ICT_ACK_SENT_AGAIN, 00438 OSIP_ICT_STATUS_1XX_RECEIVED, 00439 OSIP_ICT_STATUS_2XX_RECEIVED, 00440 OSIP_ICT_STATUS_2XX_RECEIVED_AGAIN, 00441 OSIP_ICT_STATUS_3XX_RECEIVED, 00442 OSIP_ICT_STATUS_4XX_RECEIVED, 00443 OSIP_ICT_STATUS_5XX_RECEIVED, 00444 OSIP_ICT_STATUS_6XX_RECEIVED, 00445 OSIP_ICT_STATUS_3456XX_RECEIVED_AGAIN, 00448 OSIP_IST_INVITE_RECEIVED, 00449 OSIP_IST_INVITE_RECEIVED_AGAIN, 00450 OSIP_IST_ACK_RECEIVED, 00451 OSIP_IST_ACK_RECEIVED_AGAIN, 00452 OSIP_IST_STATUS_1XX_SENT, 00453 OSIP_IST_STATUS_2XX_SENT, 00454 OSIP_IST_STATUS_2XX_SENT_AGAIN, 00455 OSIP_IST_STATUS_3XX_SENT, 00456 OSIP_IST_STATUS_4XX_SENT, 00457 OSIP_IST_STATUS_5XX_SENT, 00458 OSIP_IST_STATUS_6XX_SENT, 00459 OSIP_IST_STATUS_3456XX_SENT_AGAIN, 00461 OSIP_NICT_REGISTER_SENT, 00462 OSIP_NICT_BYE_SENT, 00463 OSIP_NICT_OPTIONS_SENT, 00464 OSIP_NICT_INFO_SENT, 00465 OSIP_NICT_CANCEL_SENT, 00466 OSIP_NICT_NOTIFY_SENT, 00467 OSIP_NICT_SUBSCRIBE_SENT, 00468 OSIP_NICT_UNKNOWN_REQUEST_SENT, 00469 OSIP_NICT_REQUEST_SENT_AGAIN, 00470 OSIP_NICT_STATUS_1XX_RECEIVED, 00471 OSIP_NICT_STATUS_2XX_RECEIVED, 00472 OSIP_NICT_STATUS_2XX_RECEIVED_AGAIN, 00473 OSIP_NICT_STATUS_3XX_RECEIVED, 00474 OSIP_NICT_STATUS_4XX_RECEIVED, 00475 OSIP_NICT_STATUS_5XX_RECEIVED, 00476 OSIP_NICT_STATUS_6XX_RECEIVED, 00477 OSIP_NICT_STATUS_3456XX_RECEIVED_AGAIN, 00480 OSIP_NIST_REGISTER_RECEIVED, 00481 OSIP_NIST_BYE_RECEIVED, 00482 OSIP_NIST_OPTIONS_RECEIVED, 00483 OSIP_NIST_INFO_RECEIVED, 00484 OSIP_NIST_CANCEL_RECEIVED, 00485 OSIP_NIST_NOTIFY_RECEIVED, 00486 OSIP_NIST_SUBSCRIBE_RECEIVED, 00488 OSIP_NIST_UNKNOWN_REQUEST_RECEIVED, 00489 OSIP_NIST_REQUEST_RECEIVED_AGAIN, 00490 OSIP_NIST_STATUS_1XX_SENT, 00491 OSIP_NIST_STATUS_2XX_SENT, 00492 OSIP_NIST_STATUS_2XX_SENT_AGAIN, 00493 OSIP_NIST_STATUS_3XX_SENT, 00494 OSIP_NIST_STATUS_4XX_SENT, 00495 OSIP_NIST_STATUS_5XX_SENT, 00496 OSIP_NIST_STATUS_6XX_SENT, 00497 OSIP_NIST_STATUS_3456XX_SENT_AGAIN, 00499 OSIP_ICT_STATUS_TIMEOUT, 00500 OSIP_NICT_STATUS_TIMEOUT, 00502 OSIP_MESSAGE_CALLBACK_COUNT 00503 } osip_message_callback_type_t; 00504 00508 typedef enum osip_kill_callback_type { 00509 OSIP_ICT_KILL_TRANSACTION, 00510 OSIP_IST_KILL_TRANSACTION, 00511 OSIP_NICT_KILL_TRANSACTION, 00512 OSIP_NIST_KILL_TRANSACTION, 00514 OSIP_KILL_CALLBACK_COUNT 00515 } osip_kill_callback_type_t; 00516 00521 typedef enum osip_transport_error_callback_type { 00522 OSIP_ICT_TRANSPORT_ERROR, 00523 OSIP_IST_TRANSPORT_ERROR, 00524 OSIP_NICT_TRANSPORT_ERROR, 00525 OSIP_NIST_TRANSPORT_ERROR, 00527 OSIP_TRANSPORT_ERROR_CALLBACK_COUNT 00529 } osip_transport_error_callback_type_t; 00530 00535 typedef void (*osip_message_cb_t) (int type, osip_transaction_t *, 00536 osip_message_t *); 00541 typedef void (*osip_kill_transaction_cb_t) (int type, osip_transaction_t *); 00546 typedef void (*osip_transport_error_cb_t) (int type, osip_transaction_t *, 00547 int error); 00548 00549 00550 struct osip_dialog; 00551 00556 typedef struct ixt_t ixt_t; 00557 00562 struct ixt_t { 00563 /* any ACK received that match this context will set counter to -1 */ 00564 struct osip_dialog *dialog; 00566 osip_message_t *msg2xx; 00567 osip_message_t *ack; 00568 struct timeval start; 00569 int interval; 00570 char *dest; 00571 int port; 00572 int sock; 00573 int counter; 00574 }; 00575 00576 00584 typedef struct osip osip_t; 00585 00590 struct osip { 00591 00592 void *application_context; 00595 /* list of transactions for ict, ist, nict, nist */ 00596 osip_list_t osip_ict_transactions; 00598 osip_list_t osip_ist_transactions; 00600 osip_list_t osip_nict_transactions; 00602 osip_list_t osip_nist_transactions; 00605 osip_list_t ixt_retransmissions; 00607 osip_message_cb_t msg_callbacks[OSIP_MESSAGE_CALLBACK_COUNT]; 00608 osip_kill_transaction_cb_t kill_callbacks[OSIP_KILL_CALLBACK_COUNT]; 00610 osip_transport_error_cb_t 00611 tp_error_callbacks[OSIP_TRANSPORT_ERROR_CALLBACK_COUNT]; 00614 int (*cb_send_message) (osip_transaction_t *, osip_message_t *, char *, 00615 int, int); 00618 #if defined(HAVE_DICT_DICT_H) 00619 dict *osip_ict_hastable; 00620 dict *osip_ist_hastable; 00621 dict *osip_nict_hastable; 00622 dict *osip_nist_hastable; 00623 #endif 00624 }; 00625 00632 int osip_set_message_callback(osip_t * osip, int type, osip_message_cb_t cb); 00633 00640 int osip_set_kill_transaction_callback(osip_t * osip, int type, 00641 osip_kill_transaction_cb_t cb); 00642 00649 int osip_set_transport_error_callback(osip_t * osip, int type, 00650 osip_transport_error_cb_t cb); 00651 00660 typedef struct osip_event osip_event_t; 00661 00666 struct osip_event { 00667 type_t type; 00668 int transactionid; 00669 osip_message_t *sip; 00670 }; 00671 00672 00673 00681 int osip_transaction_init(osip_transaction_t ** transaction, 00682 osip_fsm_type_t ctx_type, osip_t * osip, 00683 osip_message_t * request); 00688 int osip_transaction_free(osip_transaction_t * transaction); 00696 int osip_transaction_free2(osip_transaction_t * transaction); 00697 00705 void osip_response_get_destination(osip_message_t * response, 00706 char **address, int *portnum); 00716 int osip_ict_set_destination(osip_ict_t * ict, char *destination, int port); 00717 00727 int osip_nict_set_destination(osip_nict_t * nict, char *destination, int port); 00728 00734 int osip_transaction_add_event(osip_transaction_t * transaction, 00735 osip_event_t * evt); 00744 int osip_transaction_execute(osip_transaction_t * transaction, 00745 osip_event_t * evt); 00757 int osip_transaction_set_your_instance(osip_transaction_t * transaction, 00758 void *instance); 00763 void *osip_transaction_get_your_instance(osip_transaction_t * transaction); 00764 00772 int osip_transaction_get_destination(osip_transaction_t * transaction, 00773 char **ip, int *port); 00774 00775 00782 int osip_transaction_set_srv_record(osip_transaction_t * transaction, 00783 osip_srv_record_t * record); 00784 00791 int osip_transaction_set_naptr_record(osip_transaction_t * transaction, 00792 osip_naptr_t * record); 00793 00800 int osip_transaction_set_in_socket(osip_transaction_t * transaction, int sock); 00807 int osip_transaction_set_out_socket(osip_transaction_t * transaction, 00808 int sock); 00809 00810 00811 00816 int osip_init(osip_t ** osip); 00821 void osip_release(osip_t * osip); 00822 00829 void osip_set_application_context(osip_t * osip, void *pointer); 00830 00836 void *osip_get_application_context(osip_t * osip); 00837 00838 00844 int osip_remove_transaction(osip_t * osip, osip_transaction_t * ict); 00845 00846 00851 int osip_ict_execute(osip_t * osip); 00856 int osip_ist_execute(osip_t * osip); 00861 int osip_nict_execute(osip_t * osip); 00866 int osip_nist_execute(osip_t * osip); 00867 00876 void osip_timers_gettimeout(osip_t * osip, struct timeval *lower_tv); 00877 00882 void osip_timers_ict_execute(osip_t * osip); 00887 void osip_timers_ist_execute(osip_t * osip); 00892 void osip_timers_nict_execute(osip_t * osip); 00897 void osip_timers_nist_execute(osip_t * osip); 00898 00899 /* Take care of mutlithreading issuewhile using this method */ 00905 osip_transaction_t *osip_transaction_find(osip_list_t * transactions, 00906 osip_event_t * evt); 00907 00908 00909 #ifndef DOXYGEN 00910 00917 #ifndef OSIP_MT 00918 osip_transaction_t *osip_find_transaction(osip_t * osip, osip_event_t * evt); 00919 #endif 00920 00921 osip_transaction_t *__osip_find_transaction(osip_t * osip, 00922 osip_event_t * evt, int consume); 00923 #endif 00924 00931 int osip_find_transaction_and_add_event(osip_t * osip, osip_event_t * evt); 00932 00938 osip_transaction_t *osip_create_transaction(osip_t * osip, osip_event_t * evt); 00939 00945 osip_event_t *osip_parse(const char *buf, size_t length); 00946 00947 00952 void osip_retransmissions_execute(osip_t * osip); 00953 00961 void osip_start_200ok_retransmissions(osip_t * osip, 00962 struct osip_dialog *dialog, 00963 osip_message_t * msg200ok, int sock); 00964 00974 void osip_start_ack_retransmissions(osip_t * osip, 00975 struct osip_dialog *dialog, 00976 osip_message_t * ack, char *dest, 00977 int port, int sock); 00978 00984 struct osip_dialog *osip_stop_200ok_retransmissions(osip_t * osip, 00985 osip_message_t * ack); 00986 00994 void osip_stop_retransmissions_from_dialog(osip_t * osip, 00995 struct osip_dialog *dialog); 00996 00997 01002 osip_event_t *osip_new_outgoing_sipmessage(osip_message_t * sip); 01003 01008 void osip_event_free(osip_event_t * event); 01009 01015 void osip_set_cb_send_message(osip_t * cf, 01016 int (*cb) (osip_transaction_t *, 01017 osip_message_t *, char *, int, int)); 01018 01019 /* FOR INCOMING TRANSACTION */ 01024 #define EVT_IS_RCV_INVITE(event) (event->type==RCV_REQINVITE) 01025 01029 #define EVT_IS_RCV_ACK(event) (event->type==RCV_REQACK) 01030 01034 #define EVT_IS_RCV_REQUEST(event) (event->type==RCV_REQUEST) 01035 01039 #define EVT_IS_RCV_STATUS_1XX(event) (event->type==RCV_STATUS_1XX) 01040 01044 #define EVT_IS_RCV_STATUS_2XX(event) (event->type==RCV_STATUS_2XX) 01045 01049 #define EVT_IS_RCV_STATUS_3456XX(event) (event->type==RCV_STATUS_3456XX) 01050 01051 01052 /* FOR OUTGOING TRANSACTION */ 01057 #define EVT_IS_SND_INVITE(event) (event->type==SND_REQINVITE) 01058 01062 #define EVT_IS_SND_ACK(event) (event->type==SND_REQACK) 01063 01067 #define EVT_IS_SND_REQUEST(event) (event->type==SND_REQUEST) 01068 01072 #define EVT_IS_SND_STATUS_1XX(event) (event->type==SND_STATUS_1XX) 01073 01077 #define EVT_IS_SND_STATUS_2XX(event) (event->type==SND_STATUS_2XX) 01078 01082 #define EVT_IS_SND_STATUS_3456XX(event) (event->type==SND_STATUS_3456XX) 01083 01087 #define EVT_IS_INCOMINGMSG(event) (event->type>=RCV_REQINVITE \ 01088 &&event->type<=RCV_STATUS_3456XX) 01089 01093 #define EVT_IS_INCOMINGREQ(event) (EVT_IS_RCV_INVITE(event) \ 01094 ||EVT_IS_RCV_ACK(event) \ 01095 ||EVT_IS_RCV_REQUEST(event)) 01096 01100 #define EVT_IS_INCOMINGRESP(event) (EVT_IS_RCV_STATUS_1XX(event) \ 01101 ||EVT_IS_RCV_STATUS_2XX(event) \ 01102 ||EVT_IS_RCV_STATUS_3456XX(event)) 01103 01107 #define EVT_IS_OUTGOINGMSG(event) (event->type>=SND_REQINVITE \ 01108 &&event->type<=SND_STATUS_3456XX) 01109 01113 #define EVT_IS_OUTGOINGREQ(event) (EVT_IS_SND_INVITE(event) \ 01114 ||EVT_IS_SND_ACK(event) \ 01115 ||EVT_IS_SND_REQUEST(event)) 01116 01120 #define EVT_IS_OUTGOINGRESP(event) (EVT_IS_SND_STATUS_1XX(event) \ 01121 ||EVT_IS_SND_STATUS_2XX(event) \ 01122 ||EVT_IS_SND_STATUS_3456XX(event)) 01123 01128 #define EVT_IS_MSG(event) (event->type>=RCV_REQINVITE \ 01129 &&event->type<=SND_STATUS_3456XX) 01130 01135 #define EVT_IS_KILL_TRANSACTION(event) (event->type==KILL_TRANSACTION) 01136 01137 #ifdef __cplusplus 01138 } 01139 #endif 01140 01141 #endif
1.7.3