Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

osip.h

Go to the documentation of this file.
00001 /*
00002   The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-)
00003   Copyright (C) 2001,2002,2003,2004  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 #include <osipparser2/osip_const.h>
00025 
00026 /* Time-related functions and data types */
00027 #include <osip2/osip_time.h>
00028 
00029 #ifdef __sun
00030 #include <sys/types.h>
00031 #endif
00032 
00033 #include <osipparser2/osip_parser.h>
00034 #include <osip2/osip_fifo.h>
00035 
00048 #ifdef __cplusplus
00049 extern "C"
00050 {
00051 #endif
00052 
00053 
00059   typedef enum _state_t
00060   {
00061     /* STATES for invite client transaction */
00062     ICT_PRE_CALLING,
00063     ICT_CALLING,
00064     ICT_PROCEEDING,
00065     ICT_COMPLETED,
00066     ICT_TERMINATED,
00067 
00068     /* STATES for invite server transaction */
00069     IST_PRE_PROCEEDING,
00070     IST_PROCEEDING,
00071     IST_COMPLETED,
00072     IST_CONFIRMED,
00073     IST_TERMINATED,
00074 
00075     /* STATES for NON-invite client transaction */
00076     NICT_PRE_TRYING,
00077     NICT_TRYING,
00078     NICT_PROCEEDING,
00079     NICT_COMPLETED,
00080     NICT_TERMINATED,
00081 
00082     /* STATES for NON-invite server transaction */
00083     NIST_PRE_TRYING,
00084     NIST_TRYING,
00085     NIST_PROCEEDING,
00086     NIST_COMPLETED,
00087     NIST_TERMINATED,
00088 
00089 #ifndef DOXYGEN
00090     DIALOG_EARLY,
00091     DIALOG_CONFIRMED,
00092     DIALOG_CLOSE                /* ?? */
00093 #endif
00094   }
00095   state_t;
00096 
00114   typedef enum type_t
00115   {
00116     /* TIMEOUT EVENTS for ICT */
00117     TIMEOUT_A,   
00118     TIMEOUT_B,   
00119     TIMEOUT_D,   
00121     /* TIMEOUT EVENTS for NICT */
00122     TIMEOUT_E,   
00123     TIMEOUT_F,   
00124     TIMEOUT_K,   
00126     /* TIMEOUT EVENTS for IST */
00127     TIMEOUT_G,   
00128     TIMEOUT_H,   
00129     TIMEOUT_I,   
00131     /* TIMEOUT EVENTS for NIST */
00132     TIMEOUT_J,   
00134     /* FOR INCOMING MESSAGE */
00135     RCV_REQINVITE,    
00136     RCV_REQACK,       
00137     RCV_REQUEST,      
00138     RCV_STATUS_1XX,   
00139     RCV_STATUS_2XX,   
00140     RCV_STATUS_3456XX,
00142     /* FOR OUTGOING MESSAGE */
00143     SND_REQINVITE,    
00144     SND_REQACK,       
00145     SND_REQUEST,      
00146     SND_STATUS_1XX,   
00147     SND_STATUS_2XX,   
00148     SND_STATUS_3456XX,
00150     KILL_TRANSACTION, 
00151     UNKNOWN_EVT
00152   }
00153   type_t;
00154 
00163   typedef enum osip_fsm_type_t
00164   {
00165     ICT, 
00166     IST, 
00167     NICT,
00168     NIST 
00169   }
00170   osip_fsm_type_t;
00171 
00172 #ifndef DEFAULT_T1
00173 
00177 #define DEFAULT_T1 500          /* 500 ms */
00178 #endif
00179 #ifndef DEFAULT_T2
00180 
00184 #define DEFAULT_T2 4000         /* 4s */
00185 #endif
00186 #ifndef DEFAULT_T4
00187 
00191 #define DEFAULT_T4 5000         /* 5s */
00192 #endif
00193 
00194 
00199   typedef struct osip_ict osip_ict_t;
00200 
00205   struct osip_ict
00206   {
00207     int timer_a_length;           
00208     struct timeval timer_a_start; 
00209     int timer_b_length;           
00210     struct timeval timer_b_start; 
00211     int timer_d_length;           
00212     struct timeval timer_d_start; 
00213     char *destination;            
00214     int port;                     
00215   };
00216 
00221   typedef struct osip_nict osip_nict_t;
00222 
00227   struct osip_nict
00228   {
00229     int timer_e_length;           
00230     struct timeval timer_e_start; 
00231     int timer_f_length;           
00232     struct timeval timer_f_start; 
00233     int timer_k_length;           
00234     struct timeval timer_k_start; 
00235     char *destination;            
00236     int port;                     
00238   };
00239 
00244   typedef struct osip_ist osip_ist_t;
00245 
00250   struct osip_ist
00251   {
00252     int timer_g_length;      
00253     struct timeval timer_g_start; 
00254     int timer_h_length;           
00255     struct timeval timer_h_start; 
00256     int timer_i_length;           
00257     struct timeval timer_i_start; 
00258   };
00259 
00264   typedef struct osip_nist osip_nist_t;
00265 
00270   struct osip_nist
00271   {
00272     int timer_j_length;            
00273     struct timeval timer_j_start;  
00274   };
00275 
00280   typedef struct osip_transaction osip_transaction_t;
00281 
00286   struct osip_transaction
00287   {
00288 
00289     void *your_instance;        
00290     int transactionid;          
00291     osip_fifo_t *transactionff; 
00293     osip_via_t *topvia;         
00294     osip_from_t *from;          
00295     osip_to_t *to;              
00296     osip_call_id_t *callid;     
00297     osip_cseq_t *cseq;          
00299     osip_message_t *orig_request;  
00300     osip_message_t *last_response; 
00301     osip_message_t *ack;           
00303     state_t state;              
00305     time_t birth_time;          
00306     time_t completed_time;      
00308     int in_socket;              
00309     int out_socket;             
00311     void *config;               
00313     osip_fsm_type_t ctx_type;   
00314     osip_ict_t *ict_context;    
00315     osip_ist_t *ist_context;    
00316     osip_nict_t *nict_context;  
00317     osip_nist_t *nist_context;  
00318   };
00319 
00320 
00324   typedef enum osip_message_callback_type
00325   {
00326     OSIP_ICT_INVITE_SENT = 0,               
00327     OSIP_ICT_INVITE_SENT_AGAIN,             
00328     OSIP_ICT_ACK_SENT,                      
00329     OSIP_ICT_ACK_SENT_AGAIN,                
00330     OSIP_ICT_STATUS_1XX_RECEIVED,           
00331     OSIP_ICT_STATUS_2XX_RECEIVED,           
00332     OSIP_ICT_STATUS_2XX_RECEIVED_AGAIN,     
00333     OSIP_ICT_STATUS_3XX_RECEIVED,           
00334     OSIP_ICT_STATUS_4XX_RECEIVED,           
00335     OSIP_ICT_STATUS_5XX_RECEIVED,           
00336     OSIP_ICT_STATUS_6XX_RECEIVED,           
00337     OSIP_ICT_STATUS_3456XX_RECEIVED_AGAIN,  
00339     OSIP_IST_INVITE_RECEIVED,               
00340     OSIP_IST_INVITE_RECEIVED_AGAIN,         
00341     OSIP_IST_ACK_RECEIVED,                  
00342     OSIP_IST_ACK_RECEIVED_AGAIN,            
00343     OSIP_IST_STATUS_1XX_SENT,               
00344     OSIP_IST_STATUS_2XX_SENT,               
00345     OSIP_IST_STATUS_2XX_SENT_AGAIN,         
00346     OSIP_IST_STATUS_3XX_SENT,               
00347     OSIP_IST_STATUS_4XX_SENT,               
00348     OSIP_IST_STATUS_5XX_SENT,               
00349     OSIP_IST_STATUS_6XX_SENT,               
00350     OSIP_IST_STATUS_3456XX_SENT_AGAIN,      
00352     OSIP_NICT_REGISTER_SENT,                
00353     OSIP_NICT_BYE_SENT,                     
00354     OSIP_NICT_OPTIONS_SENT,                 
00355     OSIP_NICT_INFO_SENT,                    
00356     OSIP_NICT_CANCEL_SENT,                  
00357     OSIP_NICT_NOTIFY_SENT,                  
00358     OSIP_NICT_SUBSCRIBE_SENT,               
00359     OSIP_NICT_UNKNOWN_REQUEST_SENT,         
00360     OSIP_NICT_REQUEST_SENT_AGAIN,           
00361     OSIP_NICT_STATUS_1XX_RECEIVED,          
00362     OSIP_NICT_STATUS_2XX_RECEIVED,          
00363     OSIP_NICT_STATUS_2XX_RECEIVED_AGAIN,    
00364     OSIP_NICT_STATUS_3XX_RECEIVED,          
00365     OSIP_NICT_STATUS_4XX_RECEIVED,          
00366     OSIP_NICT_STATUS_5XX_RECEIVED,          
00367     OSIP_NICT_STATUS_6XX_RECEIVED,          
00368     OSIP_NICT_STATUS_3456XX_RECEIVED_AGAIN, 
00370     OSIP_NIST_REGISTER_RECEIVED,            
00371     OSIP_NIST_BYE_RECEIVED,                 
00372     OSIP_NIST_OPTIONS_RECEIVED,             
00373     OSIP_NIST_INFO_RECEIVED,                
00374     OSIP_NIST_CANCEL_RECEIVED,              
00375     OSIP_NIST_NOTIFY_RECEIVED,              
00376     OSIP_NIST_SUBSCRIBE_RECEIVED,           
00378     OSIP_NIST_UNKNOWN_REQUEST_RECEIVED,     
00379     OSIP_NIST_REQUEST_RECEIVED_AGAIN,       
00380     OSIP_NIST_STATUS_1XX_SENT,              
00381     OSIP_NIST_STATUS_2XX_SENT,              
00382     OSIP_NIST_STATUS_2XX_SENT_AGAIN,        
00383     OSIP_NIST_STATUS_3XX_SENT,              
00384     OSIP_NIST_STATUS_4XX_SENT,              
00385     OSIP_NIST_STATUS_5XX_SENT,              
00386     OSIP_NIST_STATUS_6XX_SENT,              
00387     OSIP_NIST_STATUS_3456XX_SENT_AGAIN,     
00389     OSIP_MESSAGE_CALLBACK_COUNT             
00390   } osip_message_callback_type_t;
00391 
00395   typedef enum osip_kill_callback_type
00396   {
00397     OSIP_ICT_KILL_TRANSACTION,      
00398     OSIP_IST_KILL_TRANSACTION,      
00399     OSIP_NICT_KILL_TRANSACTION,     
00400     OSIP_NIST_KILL_TRANSACTION,     
00402     OSIP_KILL_CALLBACK_COUNT        
00403   } osip_kill_callback_type_t;
00404 
00409   typedef enum osip_transport_error_callback_type
00410   {
00411     OSIP_ICT_TRANSPORT_ERROR,             
00412     OSIP_IST_TRANSPORT_ERROR,             
00413     OSIP_NICT_TRANSPORT_ERROR,            
00414     OSIP_NIST_TRANSPORT_ERROR,            
00416     OSIP_TRANSPORT_ERROR_CALLBACK_COUNT   
00417   } osip_transport_error_callback_type_t;
00418 
00423   typedef void (*osip_message_cb_t) (int type, osip_transaction_t *,
00424                                      osip_message_t *);
00429   typedef void (*osip_kill_transaction_cb_t) (int type, osip_transaction_t *);
00434   typedef void (*osip_transport_error_cb_t) (int type, osip_transaction_t *,
00435                                              int error);
00436 
00437 
00438   struct osip_dialog;
00439 
00444   typedef struct ixt_t ixt_t;
00445 
00450   struct ixt_t
00451   {
00452     /* any ACK received that match this context will set counter to -1 */
00453     struct osip_dialog *dialog; 
00454     osip_message_t *msg2xx;     
00455     osip_message_t *ack;        
00456     time_t start;               
00457     int interval;               
00458     char *dest;                 
00459     int port;                   
00460     int sock;                   
00461     int counter;                
00462   };
00463 
00464 
00472   typedef struct osip osip_t;
00473 
00478   struct osip
00479   {
00480 
00481     void *application_context;  
00483     /* list of transactions for ict, ist, nict, nist */
00484     osip_list_t *osip_ict_transactions;  
00485     osip_list_t *osip_ist_transactions;  
00486     osip_list_t *osip_nict_transactions; 
00487     osip_list_t *osip_nist_transactions; 
00489     osip_list_t *ixt_retransmissions;    
00491     osip_message_cb_t msg_callbacks[OSIP_MESSAGE_CALLBACK_COUNT];        
00492     osip_kill_transaction_cb_t kill_callbacks[OSIP_KILL_CALLBACK_COUNT]; 
00493     osip_transport_error_cb_t tp_error_callbacks[OSIP_TRANSPORT_ERROR_CALLBACK_COUNT];  
00495     int (*cb_send_message) (osip_transaction_t *, osip_message_t *, char *,
00496                             int, int);  
00497   };
00498 
00505   int osip_set_message_callback (osip_t *osip, int type, osip_message_cb_t cb);
00506 
00513   int osip_set_kill_transaction_callback (osip_t *osip, int type,
00514                                           osip_kill_transaction_cb_t cb);
00515 
00522   int osip_set_transport_error_callback (osip_t *osip, int type,
00523                                          osip_transport_error_cb_t cb);
00524 
00533   typedef struct osip_event osip_event_t;
00534 
00539   struct osip_event
00540   {
00541     type_t type;             
00542     int transactionid;       
00543     osip_message_t *sip;     
00544   };
00545 
00546 
00547 
00555   int osip_transaction_init (osip_transaction_t ** transaction,
00556                              osip_fsm_type_t ctx_type, osip_t * osip,
00557                              osip_message_t * request);
00562   int osip_transaction_free (osip_transaction_t * transaction);
00570   int osip_transaction_free2 (osip_transaction_t * transaction);
00571 
00579   void osip_response_get_destination (osip_message_t * response,
00580                                       char **address,
00581                                       int *portnum);
00591   int osip_ict_set_destination (osip_ict_t * ict, char *destination,
00592                                 int port);
00593 
00603   int osip_nict_set_destination (osip_nict_t * nict, char *destination,
00604                                  int port);
00605 
00611   int osip_transaction_add_event (osip_transaction_t * transaction,
00612                                   osip_event_t * evt);
00621   int osip_transaction_execute (osip_transaction_t * transaction,
00622                                 osip_event_t * evt);
00634   int osip_transaction_set_your_instance (osip_transaction_t * transaction,
00635                                           void *instance);
00640   void *osip_transaction_get_your_instance (osip_transaction_t * transaction);
00641 
00649   int osip_transaction_get_destination (osip_transaction_t * transaction,
00650                                         char **ip, int *port);
00651 
00652 
00659   int osip_transaction_set_in_socket (osip_transaction_t * transaction,
00660                                       int sock);
00667   int osip_transaction_set_out_socket (osip_transaction_t * transaction,
00668                                        int sock);
00669 
00670 
00671 
00676   int osip_init (osip_t ** osip);
00681   void osip_release (osip_t * osip);
00682 
00689   void osip_set_application_context (osip_t * osip, void *pointer);
00690 
00696   void *osip_get_application_context (osip_t * osip);
00697 
00698 
00704   int osip_remove_transaction (osip_t * osip, osip_transaction_t * ict);
00705 
00706 
00711   int osip_ict_execute (osip_t * osip);
00716   int osip_ist_execute (osip_t * osip);
00721   int osip_nict_execute (osip_t * osip);
00726   int osip_nist_execute (osip_t * osip);
00727 
00736   void osip_timers_gettimeout (osip_t * osip, struct timeval *lower_tv);
00737 
00742   void osip_timers_ict_execute (osip_t * osip);
00747   void osip_timers_ist_execute (osip_t * osip);
00752   void osip_timers_nict_execute (osip_t * osip);
00757   void osip_timers_nist_execute (osip_t * osip);
00758 
00759 /* Take care of mutlithreading issuewhile using this method */
00765   osip_transaction_t *osip_transaction_find (osip_list_t * transactions,
00766                                              osip_event_t * evt);
00767 
00768 
00769 #ifndef DOXYGEN
00770 
00777 #ifndef OSIP_MT
00778   osip_transaction_t *osip_find_transaction (osip_t * osip,
00779                                              osip_event_t * evt);
00780 #endif
00781 
00782   osip_transaction_t *__osip_find_transaction (osip_t * osip,
00783                                                osip_event_t * evt,
00784                                                int consume);
00785 #endif
00786 
00793   int osip_find_transaction_and_add_event (osip_t * osip, osip_event_t * evt);
00794 
00800   osip_transaction_t *osip_create_transaction (osip_t * osip,
00801                                                osip_event_t * evt);
00802 
00808   osip_event_t *osip_parse (const char *buf, size_t length);
00809 
00810 
00815   void osip_retransmissions_execute (osip_t * osip);
00816 
00824   void osip_start_200ok_retransmissions (osip_t * osip,
00825                                          struct osip_dialog *dialog,
00826                                          osip_message_t * msg200ok, int sock);
00827 
00837   void osip_start_ack_retransmissions (osip_t * osip,
00838                                        struct osip_dialog *dialog,
00839                                        osip_message_t * ack, char *dest,
00840                                        int port, int sock);
00841 
00847   struct osip_dialog *osip_stop_200ok_retransmissions (osip_t * osip, osip_message_t * ack);
00848 
00856   void osip_stop_retransmissions_from_dialog (osip_t * osip,
00857                                               struct osip_dialog *dialog);
00858 
00859 
00864   osip_event_t *osip_new_outgoing_sipmessage (osip_message_t * sip);
00865 
00870   void osip_event_free (osip_event_t * event);
00871 
00877   void osip_set_cb_send_message (osip_t * cf,
00878                                  int (*cb) (osip_transaction_t *,
00879                                             osip_message_t *, char *,
00880                                             int, int));
00881 
00882 /* FOR INCOMING TRANSACTION */
00887 #define EVT_IS_RCV_INVITE(event)       (event->type==RCV_REQINVITE)
00888 
00892 #define EVT_IS_RCV_ACK(event)          (event->type==RCV_REQACK)
00893 
00897 #define EVT_IS_RCV_REQUEST(event)      (event->type==RCV_REQUEST)
00898 
00902 #define EVT_IS_RCV_STATUS_1XX(event)   (event->type==RCV_STATUS_1XX)
00903 
00907 #define EVT_IS_RCV_STATUS_2XX(event)   (event->type==RCV_STATUS_2XX)
00908 
00912 #define EVT_IS_RCV_STATUS_3456XX(event)   (event->type==RCV_STATUS_3456XX)
00913 
00914 
00915 /* FOR OUTGOING TRANSACTION */
00920 #define EVT_IS_SND_INVITE(event)       (event->type==SND_REQINVITE)
00921 
00925 #define EVT_IS_SND_ACK(event)          (event->type==SND_REQACK)
00926 
00930 #define EVT_IS_SND_REQUEST(event)      (event->type==SND_REQUEST)
00931 
00935 #define EVT_IS_SND_STATUS_1XX(event)   (event->type==SND_STATUS_1XX)
00936 
00940 #define EVT_IS_SND_STATUS_2XX(event)   (event->type==SND_STATUS_2XX)
00941 
00945 #define EVT_IS_SND_STATUS_3456XX(event)   (event->type==SND_STATUS_3456XX)
00946 
00950 #define EVT_IS_INCOMINGMSG(event)      (event->type>=RCV_REQINVITE \
00951                                        &&event->type<=RCV_STATUS_3456XX)
00952 
00956 #define EVT_IS_INCOMINGREQ(event)      (EVT_IS_RCV_INVITE(event) \
00957                                        ||EVT_IS_RCV_ACK(event) \
00958                                        ||EVT_IS_RCV_REQUEST(event))
00959 
00963 #define EVT_IS_INCOMINGRESP(event)     (EVT_IS_RCV_STATUS_1XX(event) \
00964                                        ||EVT_IS_RCV_STATUS_2XX(event) \
00965                                        ||EVT_IS_RCV_STATUS_3456XX(event))
00966 
00970 #define EVT_IS_OUTGOINGMSG(event)      (event->type>=SND_REQINVITE \
00971                                        &&event->type<=SND_STATUS_3456XX)
00972 
00976 #define EVT_IS_OUTGOINGREQ(event)      (EVT_IS_SND_INVITE(event) \
00977                                        ||EVT_IS_SND_ACK(event) \
00978                                        ||EVT_IS_SND_REQUEST(event))
00979 
00983 #define EVT_IS_OUTGOINGRESP(event)     (EVT_IS_SND_STATUS_1XX(event) \
00984                                        ||EVT_IS_SND_STATUS_2XX(event) \
00985                                        ||EVT_IS_SND_STATUS_3456XX(event))
00986 
00991 #define EVT_IS_MSG(event)              (event->type>=RCV_REQINVITE \
00992                                        &&event->type<=SND_STATUS_3456XX)
00993 
00998 #define EVT_IS_KILL_TRANSACTION(event) (event->type==KILL_TRANSACTION)
00999 
01000 #ifdef __cplusplus
01001 }
01002 #endif
01003 
01004 
01007 #endif

Generated on Tue Feb 22 00:59:46 2005 for libosip by  doxygen 1.4.1