dlg.h

Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  * Copyright (C) 2001-2003 FhG Fokus
00004  *
00005  * This file is part of SIP-router, a free SIP server.
00006  *
00007  * SIP-router is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version
00011  *
00012  * SIP-router is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  * History:
00022  * -------
00023  * 2003-03-29 Created by janakj
00024  * 2007-04-13 added dialog callbacks (andrei)
00025  */
00026 
00034 #ifndef DLG_H
00035 #define DLG_H
00036 
00037 
00038 #include <stdio.h>
00039 #include "../../str.h"
00040 #include "../../ip_addr.h"
00041 #include "../../parser/parse_rr.h"
00042 #include "../../parser/msg_parser.h"
00043 
00044 /*
00045 #define DIALOG_CALLBACKS
00046 */
00047 
00048 #ifdef DIALOG_CALLBACKS
00049 #include "t_hooks.h"
00050 #include "h_table.h"
00051 
00052 #define DLG_CB_UAC 30
00053 #define DLG_CB_UAS 31
00054 
00055 #endif /* DIALOG_CALLBACKS */
00056 
00057 
00058 /*
00059  * Dialog sequence
00060  */
00061 typedef struct dlg_seq {
00062         unsigned int value;    /* Sequence value */
00063         unsigned char is_set;  /* is_set flag */
00064 } dlg_seq_t;
00065 
00066 
00067 /*
00068  * Dialog state
00069  */
00070 typedef enum dlg_state {
00071         DLG_NEW = 0,   /* New dialog, no reply received yet */
00072         DLG_EARLY,     /* Early dialog, provisional response received */
00073         DLG_CONFIRMED, /* Confirmed dialog, 2xx received */
00074         DLG_DESTROYED  /* Destroyed dialog */
00075 } dlg_state_t;
00076 
00077 
00078 /*
00079  * Structure describing a dialog identifier
00080  */
00081 typedef struct dlg_id {
00082         str call_id;    /* Call-ID */
00083         str rem_tag;    /* Remote tag of the dialog */
00084         str loc_tag;    /* Local tag of the dialog */
00085 } dlg_id_t;
00086 
00087 
00088 /*
00089  * It is necessary to analyze the dialog data to find out
00090  * what URI put into the Record-Route, where the message
00091  * should be really sent and how to construct the route
00092  * set of the message. This structure stores this information
00093  * so we don't have to calculate each time we want to send a
00094  * message within dialog
00095  */
00096 typedef struct dlg_hooks {
00097         str ru;
00098         str nh;
00099         str* request_uri;   /* This should be put into Request-URI */
00100         str* next_hop;      /* Where the message should be really sent */
00101         rr_t* first_route;  /* First route to be printed into the message */
00102         str* last_route;    /* If not zero add this as the last route */
00103 } dlg_hooks_t;
00104 
00105 
00106 /*
00107  * Structure representing dialog state
00108  */
00109 typedef struct dlg {
00110         dlg_id_t id;            /* Dialog identifier */
00111         dlg_seq_t loc_seq;      /* Local sequence number */
00112         dlg_seq_t rem_seq;      /* Remote sequence number */
00113         str loc_uri;            /* Local URI */
00114         str rem_uri;            /* Remote URI */
00115         str rem_target;         /* Remote target URI */
00116         str dst_uri;            /* Destination URI */
00117         str loc_dname;          /* Local Display Name */
00118         str rem_dname;          /* Remote Display Name */
00119         unsigned char secure;   /* Secure flag -- currently not used */
00120         dlg_state_t state;      /* State of the dialog */
00121         rr_t* route_set;        /* Route set */
00122         dlg_hooks_t hooks;      /* Various hooks used to store information that
00123                                  * can be reused when building a message (to
00124                                  * prevent repeated analyzing of the dialog data
00125                                  */
00126         struct socket_info* send_sock;
00127 #ifdef DIALOG_CALLBACKS
00128         struct tmcb_head_list dlg_callbacks;
00129 #endif
00130 } dlg_t;
00131 
00132 typedef enum {
00133         IS_TARGET_REFRESH,
00134         IS_NOT_TARGET_REFRESH,
00135         TARGET_REFRESH_UNKNOWN
00136 } target_refresh_t;
00137 
00138 /*
00139  * Create a new dialog
00140  */
00141 int new_dlg_uac(str* _cid, str* _ltag, unsigned int _lseq, str* _luri, str* _ruri, dlg_t** _d);
00142 typedef int (*new_dlg_uac_f)(str* _cid, str* _ltag, unsigned int _lseq, str* _luri, str* _ruri, dlg_t** _d);
00143 
00144 
00148 int dlg_add_extra(dlg_t* _d, str* _ldname, str* _rdname);
00149 typedef int (*dlg_add_extra_f)(dlg_t* _d, str* _ldname, str* _rdname);
00150 
00151 
00152 /*
00153  * A response arrived, update dialog
00154  */
00155 int dlg_response_uac(dlg_t* _d, struct sip_msg* _m, target_refresh_t is_target_refresh);
00156 typedef int (*dlg_response_uac_f)(dlg_t* _d, struct sip_msg* _m, target_refresh_t is_target_refresh);
00157 
00158 /*
00159  * Establishing a new dialog, UAS side
00160  */
00161 int new_dlg_uas(struct sip_msg* _req, int _code, /*str* _tag,*/ dlg_t** _d);
00162 typedef int (*new_dlg_uas_f)(struct sip_msg* _req, int _code, dlg_t** _d);
00163 
00164 /*
00165  * UAS side - update dialog state and to tag
00166  */
00167 int update_dlg_uas(dlg_t *_d, int _code, str* _tag);
00168 typedef int (*update_dlg_uas_f)(dlg_t *_d, int _code, str* _tag);
00169 
00170 /*
00171  * UAS side - update a dialog from a request
00172  */
00173 int dlg_request_uas(dlg_t* _d, struct sip_msg* _m, target_refresh_t is_target_request);
00174 typedef int (*dlg_request_uas_f)(dlg_t* _d, struct sip_msg* _m, target_refresh_t is_target_request);
00175 
00176 
00177 /*
00178  * Destroy a dialog state
00179  */
00180 void free_dlg(dlg_t* _d);
00181 typedef void (*free_dlg_f)(dlg_t* _d);
00182 
00183 
00184 /*
00185  * Print a dialog structure, just for debugging
00186  */
00187 void print_dlg(FILE* out, dlg_t* _d);
00188 typedef void (*print_dlg_f)(FILE* out, dlg_t* _d);
00189 
00190 
00191 /*
00192  * Calculate length of the route set
00193  */
00194 int calculate_routeset_length(dlg_t* _d);
00195 
00196 
00197 /*
00198  *
00199  * Print the route set
00200  */
00201 char* print_routeset(char* buf, dlg_t* _d);
00202 
00203 /*
00204  * wrapper to calculate_hooks
00205  * added by dcm
00206  */
00207 int w_calculate_hooks(dlg_t* _d);
00208 typedef int (*calculate_hooks_f)(dlg_t* _d);
00209 
00210 /*
00211  * set dialog's request uri and destination uri (optional)
00212  */
00213 int set_dlg_target(dlg_t* _d, str* _ruri, str* _duri);
00214 typedef int (*set_dlg_target_f)(dlg_t* _d, str* _ruri, str* _duri);
00215 
00216 #ifdef DIALOG_CALLBACKS
00217 
00218 /* dialog callback
00219  * params:  type - DLG_UAC or DLG_UAS
00220  *          dlg  - dialog structure
00221  *          msg  - message used for creating the new dialog for the new_dlg_uas
00222  *                 case, 0 otherwise (new_dlg_uac)
00223  */
00224 typedef void (dialog_cb) (int type, dlg_t* dlg, struct sip_msg* msg);
00225 
00226 /* callbacks for new dialogs (called each time a new dialog (uas or uac) is
00227  * created). Can be used for installing in-dialog callbacks
00228  * returns < 0 on error*/
00229 int register_new_dlg_cb(int types, dialog_cb f, void* param);
00230 /* callbacks for messages sent dialogs */
00231 int register_dlg_tmcb(int type, dlg_t* dlg, transaction_cb f, void* param);
00232 void run_trans_dlg_callbacks(dlg_t* dlg, struct cell* trans,
00233                                                                 struct retr_buf* rbuf);
00234 /* cleanup on exit */
00235 void destroy_new_dlg_cbs(void);
00236 
00237 typedef int (*register_new_dlg_cb_f)(int, dialog_cb, void*);
00238 typedef int (*register_dlg_tmcb_f)(int, dlg_t*, transaction_cb, void*);
00239 #endif /* DIALOG_CALLBACKS */
00240 
00241 
00242 #endif /* DLG_H */