nta_internal.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of the Sofia-SIP package
00003  *
00004  * Copyright (C) 2005 Nokia Corporation.
00005  *
00006  * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation; either version 2.1 of
00011  * the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00021  * 02110-1301 USA
00022  *
00023  */
00024 
00025 #ifndef NTA_INTERNAL_H
00026 
00027 #define NTA_INTERNAL_H 
00028 
00037 /* Resolver context type */
00038 #define SRES_CONTEXT_T    nta_outgoing_t
00039 
00040 /* We are customer of tport_t */
00041 #define TP_AGENT_T        nta_agent_t
00042 #define TP_MAGIC_T        sip_via_t 
00043 #define TP_CLIENT_T       nta_outgoing_t
00044 
00045 #include <sofia-sip/nta.h>
00046 #include <sofia-sip/nta_tport.h>
00047 #include <sofia-sip/tport.h>
00048 
00049 #if HAVE_SOFIA_SRESOLV
00050 #include <sofia-sip/sresolv.h>
00051 #endif
00052 
00053 #include <sofia-sip/htable.h>
00054 
00055 #if HAVE_SMIME
00056 #include "smimec.h"
00057 #endif
00058 
00059 SOFIA_BEGIN_DECLS
00060 
00062 #define NTA_INTERNAL_MSG (1<<15)
00063 
00065 enum nta_res_order_e
00066 {
00067   nta_res_ip6_ip4,
00068   nta_res_ip4_ip6,
00069   nta_res_ip6_only,
00070   nta_res_ip4_only
00071 };
00072 
00073 HTABLE_DECLARE_WITH(leg_htable, lht, nta_leg_t, size_t, hash_value_t);
00074 HTABLE_DECLARE_WITH(outgoing_htable, oht, nta_outgoing_t, size_t, hash_value_t);
00075 HTABLE_DECLARE_WITH(incoming_htable, iht, nta_incoming_t, size_t, hash_value_t);
00076 
00077 typedef struct outgoing_queue_t {
00078   nta_outgoing_t **q_tail;
00079   nta_outgoing_t  *q_head;
00080   size_t           q_length;
00081   unsigned         q_timeout;
00082 } outgoing_queue_t;
00083 
00084 typedef struct incoming_queue_t {
00085   nta_incoming_t **q_tail;
00086   nta_incoming_t  *q_head;
00087   size_t           q_length;
00088   unsigned         q_timeout;
00089 } incoming_queue_t;
00090 
00091 typedef struct nta_compressor nta_compressor_t;
00092 
00093 struct nta_agent_s
00094 {
00095   su_home_t             sa_home[1];
00096   su_root_t            *sa_root;
00097   su_timer_t           *sa_timer;
00098   nta_agent_magic_t    *sa_magic;
00099   nta_message_f        *sa_callback;     
00100 
00101   nta_update_magic_t   *sa_update_magic;
00102   nta_update_tport_f   *sa_update_tport;
00103 
00104   su_duration_t         sa_next; 
00105   su_time_t             sa_now;  
00106   uint32_t              sa_millisec; 
00108   uint32_t              sa_nw_updates; /* Shall we enable network detector? */
00109 
00110   uint32_t              sa_flags;       
00111   msg_mclass_t const   *sa_mclass;
00112 
00113   sip_contact_t        *sa_contact;
00114   sip_via_t            *sa_vias;   
00115   sip_via_t            *sa_public_vias;   
00116   sip_contact_t        *sa_aliases;
00118   uint64_t              sa_branch; 
00119   uint64_t              sa_tags;   
00121   char const           *sa_2543_tag; 
00123 #if HAVE_SOFIA_SRESOLV
00124   sres_resolver_t      *sa_resolver; 
00125 #endif
00126 
00127   tport_t              *sa_tports;
00128   
00129   /* Default outbound proxy */
00130   url_t                *sa_default_proxy;
00131 
00132 #if HAVE_SMIME
00133   sm_object_t          *sa_smime;
00134 #else
00135   void                 *sa_smime;
00136 #endif
00137 
00138 
00140   unsigned              sa_bad_req_mask;
00142   unsigned              sa_bad_resp_mask;
00143 
00145   size_t                sa_maxsize;
00146   
00148   size_t                sa_udp_mtu;
00149 
00151   unsigned              sa_t1;
00153   unsigned              sa_t2;
00155   unsigned              sa_t4;
00156 
00158   unsigned              sa_t1x64;
00159 
00161   unsigned              sa_progress;
00162 
00164   unsigned              sa_blacklist;
00165 
00167   unsigned              sa_drop_prob : 10;
00169   unsigned              sa_is_a_uas : 1;
00171   unsigned              sa_is_stateless : 1;
00173   unsigned              sa_user_via:1;
00175   unsigned              sa_extra_100:1;
00177   unsigned              sa_pass_100:1;
00180   unsigned              sa_timeout_408:1;
00182   unsigned              sa_pass_408:1;
00184   unsigned              sa_merge_482 : 1;
00186   unsigned              sa_cancel_2543 : 1;
00188   unsigned              sa_cancel_487 : 1;
00190   unsigned              sa_tag_3261 : 1;
00192   unsigned              sa_invite_100rel : 1;
00194   unsigned              sa_timestamp : 1;
00195 
00197   unsigned              sa_tport_ip4 : 1;
00199   unsigned              sa_tport_ip6 : 1;
00201   unsigned              sa_tport_udp : 1;
00203   unsigned              sa_tport_tcp : 1;
00205   unsigned              sa_tport_sctp : 1;
00207   unsigned              sa_tport_tls : 1;
00208 
00210   unsigned              sa_use_naptr : 1;
00212   unsigned              sa_use_srv : 1;
00213 
00215   unsigned              sa_tport_threadpool : 1;
00216 
00218   unsigned              sa_rport:1;
00220   unsigned              sa_server_rport:1;
00222   unsigned              sa_tcp_rport:1;
00223 
00225   unsigned              sa_auto_comp:1;
00226 
00228   unsigned              sa_in_timer:1;
00229 
00230   unsigned              :0;
00231 
00233   unsigned              sa_preload;
00234 
00236   char const           *sa_algorithm;
00238   char const           *sa_sigcomp_options;
00239   char const* const    *sa_sigcomp_option_list;
00240   char const           *sa_sigcomp_option_free;
00241 
00242   nta_compressor_t     *sa_compressor;
00243 
00245   enum nta_res_order_e  sa_res_order;
00246 
00249   sip_max_forwards_t    sa_max_forwards[1];
00250 
00251   /* Statistics */
00252   struct {
00253     uint32_t            as_recv_msg;
00254     uint32_t            as_recv_request;
00255     uint32_t            as_recv_response;
00256     uint32_t            as_bad_message;
00257     uint32_t            as_bad_request;
00258     uint32_t            as_bad_response;
00259     uint32_t            as_drop_request;
00260     uint32_t            as_drop_response;
00261     uint32_t            as_client_tr;
00262     uint32_t            as_server_tr;
00263     uint32_t            as_dialog_tr;
00264     uint32_t            as_acked_tr;
00265     uint32_t            as_canceled_tr;
00266     uint32_t            as_trless_request;
00267     uint32_t            as_trless_to_tr;
00268     uint32_t            as_trless_response;
00269     uint32_t            as_trless_200;
00270     uint32_t            as_merged_request;
00271     uint32_t            as_sent_msg;
00272     uint32_t            as_sent_request;
00273     uint32_t            as_sent_response;
00274     uint32_t            as_retry_request;
00275     uint32_t            as_retry_response;
00276     uint32_t            as_recv_retry;
00277     uint32_t            as_tout_request;
00278     uint32_t            as_tout_response;
00279   }                  sa_stats[1];
00280 
00282   leg_htable_t          sa_dialogs[1];
00284   nta_leg_t            *sa_default_leg;
00286   leg_htable_t          sa_defaults[1];
00288   outgoing_htable_t     sa_outgoing[1];
00289   nta_outgoing_t       *sa_default_outgoing;
00291   incoming_htable_t     sa_incoming[1]; 
00292   nta_incoming_t       *sa_default_incoming;
00293 
00294   /* Queues (states) for outgoing client transactions */
00295   struct {
00297     nta_outgoing_t   *re_list;
00298     nta_outgoing_t  **re_t1;            
00299     size_t            re_length;        
00301     outgoing_queue_t  delayed[1]; 
00302     outgoing_queue_t  resolving[1]; 
00303 
00304     outgoing_queue_t  trying[1];        /* Timer F/E */
00305     outgoing_queue_t  completed[1];     /* Timer K */
00306     outgoing_queue_t  terminated[1];
00307 
00308     /* Special queues (states) for outgoing INVITE transactions */
00309     outgoing_queue_t  inv_calling[1];   /* Timer B/A */
00310     outgoing_queue_t  inv_proceeding[1];
00311     outgoing_queue_t  inv_completed[1]; /* Timer D */
00312 
00313     /* Temporary queue for transactions waiting to be freed */
00314     outgoing_queue_t *free;
00315   } sa_out;
00316 
00317   /* Queues (states) for incoming server transactions */
00318   struct {
00320     nta_incoming_t   *re_list;
00321     nta_incoming_t  **re_t1;            
00322     size_t            re_length;
00323 
00324     incoming_queue_t  proceeding[1];    
00325     incoming_queue_t  preliminary[1];   
00326     incoming_queue_t  completed[1];     
00327     incoming_queue_t  inv_completed[1]; 
00328     incoming_queue_t  inv_confirmed[1]; 
00329     incoming_queue_t  terminated[1];    
00330     incoming_queue_t  final_failed[1];   
00331   } sa_in;
00332 
00333   /* Special task for freeing memory */
00334   su_clone_r          sa_terminator;
00335 };
00336 
00337 struct nta_leg_s
00338 {
00339   su_home_t         leg_home[1];
00340   hash_value_t      leg_hash;
00341   unsigned          leg_dialog : 1;
00342   unsigned          leg_stateless : 1;   
00343 #ifdef NTA_STRICT_ROUTING
00344   unsigned          leg_contact_set : 1;
00345 #else
00346   unsigned          leg_loose_route : 1; 
00347 #endif
00348   unsigned          leg_local_is_to : 1; 
00349   unsigned          leg_tagged : 1; 
00354   unsigned:0;
00355   nta_request_f    *leg_callback;
00356   nta_leg_magic_t  *leg_magic;
00357   nta_agent_t      *leg_agent;
00362   url_t const      *leg_url;
00363   char const       *leg_method; 
00365   uint32_t          leg_seq;    
00366   uint32_t          leg_rseq;   
00367   sip_call_id_t    *leg_id;     
00368   sip_from_t       *leg_remote; 
00369   sip_to_t         *leg_local;  
00371   sip_route_t      *leg_route;  
00372   sip_contact_t    *leg_target; 
00373 };
00374 
00375 #define leg_has_id(leg) ((leg)->leg_id != NULL)
00376 
00377 struct nta_incoming_s
00378 {
00379   su_home_t            *irq_home;
00380   hash_value_t          irq_hash;
00381   nta_agent_t          *irq_agent;
00382   nta_ack_cancel_f     *irq_callback;
00383   nta_incoming_magic_t *irq_magic;
00384 
00385   /* Timeout/state queue */
00386   nta_incoming_t      **irq_prev;
00387   nta_incoming_t       *irq_next;
00388   incoming_queue_t     *irq_queue;
00389   
00390   /* Retry queue */
00391   nta_incoming_t      **irq_rprev;
00392   nta_incoming_t       *irq_rnext;
00393 
00394   sip_method_t          irq_method;
00395   sip_request_t        *irq_rq;
00396   sip_from_t           *irq_from;
00397   sip_to_t             *irq_to;
00398   char const           *irq_tag;
00399   sip_cseq_t           *irq_cseq;
00400   sip_call_id_t        *irq_call_id;
00401   sip_via_t            *irq_via;
00402   sip_record_route_t   *irq_record_route;
00403   char const           *irq_branch;
00404 
00405   uint32_t              irq_rseq;
00406 
00407   sip_timestamp_t      *irq_timestamp;
00408   su_time_t             irq_received;
00409 
00410   su_duration_t         irq_timeout;    
00411   su_duration_t         irq_retry;      
00412   unsigned short        irq_interval;   
00414   short                 irq_status;
00415 
00416   unsigned              irq_retries : 8;
00417   unsigned              irq_default : 1;    
00418   unsigned              irq_canceled : 1;   
00419   unsigned              irq_completed : 1;  
00420   unsigned              irq_confirmed : 1;  
00421   unsigned              irq_terminated :1;  
00422   unsigned              irq_final_failed:1; 
00423   unsigned              irq_destroyed :1;   
00424   unsigned              irq_in_callback:1;  
00425   unsigned              irq_reliable_tp:1;  
00426   unsigned              irq_sigcomp_zap:1;  
00427   unsigned              irq_must_100rel:1;  
00428   unsigned              irq_tag_set:1;      
00429   unsigned              :0;
00430 
00431   tp_name_t             irq_tpn[1];
00432   tport_t              *irq_tport;
00433   struct sigcomp_compartment *irq_cc;
00434   msg_t                *irq_request;
00435   msg_t                *irq_request2;       
00436   msg_t                *irq_response;
00437 
00438   nta_reliable_t       *irq_reliable;       
00439 };
00440 
00441 struct nta_reliable_s
00442 {
00443   nta_reliable_t       *rel_next;
00444   nta_incoming_t       *rel_irq;
00445   nta_prack_f          *rel_callback;
00446   nta_reliable_magic_t *rel_magic;
00447   uint32_t              rel_rseq;
00448   unsigned short        rel_status;
00449   unsigned              rel_pracked : 1;
00450   unsigned              rel_precious : 1;
00451   msg_t                *rel_response;
00452   msg_t                *rel_unsent;
00453 };
00454 
00455 typedef struct sipdns_resolver sipdns_resolver_t;
00456 
00457 struct nta_outgoing_s
00458 {
00459   hash_value_t          orq_hash;    
00460   nta_agent_t          *orq_agent;
00461   nta_response_f       *orq_callback;
00462   nta_outgoing_magic_t *orq_magic;
00463 
00464   /* Timeout/state queue */
00465   nta_outgoing_t      **orq_prev;
00466   nta_outgoing_t       *orq_next;
00467   outgoing_queue_t     *orq_queue;
00468   
00469   /* Retry queue */
00470   nta_outgoing_t      **orq_rprev;
00471   nta_outgoing_t       *orq_rnext;
00472 
00473   sip_method_t          orq_method;
00474   char const           *orq_method_name;
00475   url_t const          *orq_url;        
00477   sip_from_t const     *orq_from;
00478   sip_to_t const       *orq_to;
00479   char const           *orq_tag;        
00481   sip_cseq_t const     *orq_cseq;
00482   sip_call_id_t const  *orq_call_id;
00483 
00484   msg_t                *orq_request;
00485   msg_t                *orq_response;
00486 
00487   su_time_t             orq_sent;       
00488   unsigned              orq_delay;      
00490   su_duration_t         orq_retry;      
00491   su_duration_t         orq_timeout;    
00493   unsigned short        orq_interval;   
00495   unsigned short        orq_status;
00496   unsigned char         orq_retries;    
00497   unsigned orq_default : 1;             
00498   unsigned orq_inserted : 1;
00499   unsigned orq_resolved : 1;
00500   unsigned orq_prepared : 1; 
00501   unsigned orq_canceled : 1;
00502   unsigned orq_terminated : 1;
00503   unsigned orq_destroyed : 1;
00504   unsigned orq_completed : 1;
00505   unsigned orq_delayed : 1;
00506   unsigned orq_stripped_uri : 1;
00507   unsigned orq_try_tcp_instead : 1;
00508   unsigned orq_try_udp_instead : 1;
00509   unsigned orq_reliable : 1; 
00510   unsigned orq_ack_error : 1; 
00511   /* Attributes */
00512   unsigned orq_user_via : 1;
00513   unsigned orq_stateless : 1;
00514   unsigned orq_pass_100 : 1;
00515   unsigned orq_sigcomp_new:1;   
00516   unsigned orq_sigcomp_zap:1;   
00517   unsigned orq_must_100rel : 1;
00518   unsigned orq_timestamp : 1;   
00519   unsigned : 0; /* pad */
00520 
00521 #if HAVE_SOFIA_SRESOLV
00522   sipdns_resolver_t    *orq_resolver;
00523 #endif
00524   enum nta_res_order_e  orq_res_order;  
00526   url_t                *orq_route;      
00527   tp_name_t             orq_tpn[1];     
00528   char const           *orq_scheme;     
00530   tport_t              *orq_tport;
00531   struct sigcomp_compartment *orq_cc;
00532   tagi_t               *orq_tags;       
00533   int                   orq_pending;    
00535   char const           *orq_branch;     
00536   char const           *orq_via_branch; 
00538   nta_outgoing_t       *orq_cancel;     
00540   uint32_t              orq_rseq;       
00541 };
00542 
00543 /* Virtual function table for plugging in SigComp */
00544 typedef struct
00545 {
00546   int ncv_size;
00547   char const *ncv_name;
00548 
00549   nta_compressor_t *(*ncv_init_agent)(nta_agent_t *sa, 
00550                                      char const * const *options);
00551 
00552   void (*ncv_deinit_agent)(nta_agent_t *sa, nta_compressor_t *);
00553 
00554   struct sigcomp_compartment *(*ncv_compartment)(nta_agent_t *sa,
00555                                                  tport_t *tport, 
00556                                                  nta_compressor_t *msc,
00557                                                  tp_name_t const *tpn,
00558                                                  char const * const *options,
00559                                                  int new_if_needed);
00560 
00561   int (*ncv_accept_compressed)(nta_agent_t *sa,
00562                                nta_compressor_t *msc,
00563                                tport_compressor_t *sc,
00564                                msg_t *msg,
00565                                struct sigcomp_compartment *cc);
00566 
00567   int (*ncv_close_compressor)(nta_agent_t *sa,
00568                               struct sigcomp_compartment *cc);
00569   int (*ncv_zap_compressor)(nta_agent_t *sa,
00570                             struct sigcomp_compartment *cc);
00571 
00572   struct sigcomp_compartment *(*ncv_compartment_ref)
00573     (struct sigcomp_compartment *);
00574 
00575   void (*ncv_compartment_unref)(struct sigcomp_compartment *);
00576  
00577 } nta_compressor_vtable_t;
00578 
00579 extern nta_compressor_vtable_t *nta_compressor_vtable;
00580 
00581 SOFIAPUBFUN nta_compressor_t *nta_agent_init_sigcomp(nta_agent_t *sa);
00582 SOFIAPUBFUN void nta_agent_deinit_sigcomp(nta_agent_t *sa);
00583 
00584 /* ====================================================================== */
00585 /* Debug log settings */
00586 
00587 #define SU_LOG   nta_log
00588 
00589 #ifdef SU_DEBUG_H
00590 #error <su_debug.h> included directly.
00591 #endif
00592 #include <sofia-sip/su_debug.h>
00593 SOFIAPUBVAR su_log_t nta_log[];
00594 
00595 SOFIA_END_DECLS
00596 
00597 #endif /* NTA_INTERNAL_H */

Sofia-SIP 1.12.6 - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.