1 /* 2 * Copyright (C) 2001-2003 FhG Fokus 3 * 4 * This file is part of Kamailio, a free SIP server. 5 * 6 * Kamailio is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version 10 * 11 * Kamailio is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 * 20 */ 21 22 /*! 23 * \file 24 * \brief TM :: 25 * \ingroup tm 26 */ 27 28 29 #ifndef DLG_H 30 #define DLG_H 31 32 33 #include <stdio.h> 34 #include "../../core/str.h" 35 #include "../../core/ip_addr.h" 36 #include "../../core/parser/parse_rr.h" 37 #include "../../core/parser/msg_parser.h" 38 39 /* 40 #define DIALOG_CALLBACKS 41 */ 42 43 #ifdef DIALOG_CALLBACKS 44 #include "t_hooks.h" 45 #include "h_table.h" 46 47 #define DLG_CB_UAC 30 48 #define DLG_CB_UAS 31 49 50 #endif /* DIALOG_CALLBACKS */ 51 52 53 /* 54 * Dialog sequence 55 */ 56 typedef struct dlg_seq 57 { 58 unsigned int value; /* Sequence value */ 59 unsigned char is_set; /* is_set flag */ 60 } dlg_seq_t; 61 62 63 /* 64 * Dialog state 65 */ 66 typedef enum dlg_state { 67 DLG_NEW = 0, /* New dialog, no reply received yet */ 68 DLG_EARLY, /* Early dialog, provisional response received */ 69 DLG_CONFIRMED, /* Confirmed dialog, 2xx received */ 70 DLG_DESTROYED /* Destroyed dialog */ 71 } dlg_state_t; 72 73 74 /* 75 * Structure describing a dialog identifier 76 */ 77 typedef struct dlg_id 78 { 79 str call_id; /* Call-ID */ 80 str rem_tag; /* Remote tag of the dialog */ 81 str loc_tag; /* Local tag of the dialog */ 82 } dlg_id_t; 83 84 85 /* 86 * It is necessary to analyze the dialog data to find out 87 * what URI put into the Record-Route, where the message 88 * should be really sent and how to construct the route 89 * set of the message. This structure stores this information 90 * so we don't have to calculate each time we want to send a 91 * message within dialog 92 */ 93 typedef struct dlg_hooks 94 { 95 str ru; 96 str nh; 97 str *request_uri; /* This should be put into Request-URI */ 98 str *next_hop; /* Where the message should be really sent */ 99 rr_t *first_route; /* First route to be printed into the message */ 100 str *last_route; /* If not zero add this as the last route */ 101 } dlg_hooks_t; 102 103 104 /* 105 * Structure representing dialog state 106 */ 107 typedef struct dlg 108 { 109 dlg_id_t id; /* Dialog identifier */ 110 dlg_seq_t loc_seq; /* Local sequence number */ 111 dlg_seq_t rem_seq; /* Remote sequence number */ 112 str loc_uri; /* Local URI */ 113 str rem_uri; /* Remote URI */ 114 str rem_target; /* Remote target URI */ 115 str dst_uri; /* Destination URI */ 116 str loc_dname; /* Local Display Name */ 117 str rem_dname; /* Remote Display Name */ 118 unsigned char secure; /* Secure flag -- currently not used */ 119 dlg_state_t state; /* State of the dialog */ 120 rr_t *route_set; /* Route set */ 121 dlg_hooks_t hooks; /* Various hooks used to store information that 122 * can be reused when building a message (to 123 * prevent repeated analyzing of the dialog data 124 */ 125 struct socket_info *send_sock; 126 #ifdef DIALOG_CALLBACKS 127 struct tmcb_head_list dlg_callbacks; 128 #endif 129 } dlg_t; 130 131 typedef enum { 132 IS_TARGET_REFRESH, 133 IS_NOT_TARGET_REFRESH, 134 TARGET_REFRESH_UNKNOWN 135 } target_refresh_t; 136 137 /* 138 * Create a new dialog 139 */ 140 int new_dlg_uac(str *_cid, str *_ltag, unsigned int _lseq, str *_luri, 141 str *_ruri, dlg_t **_d); 142 typedef int (*new_dlg_uac_f)(str *_cid, str *_ltag, unsigned int _lseq, 143 str *_luri, str *_ruri, dlg_t **_d); 144 145 146 /** 147 * Function to add Display Names to an existing dialog 148 */ 149 int dlg_add_extra(dlg_t *_d, str *_ldname, str *_rdname); 150 typedef int (*dlg_add_extra_f)(dlg_t *_d, str *_ldname, str *_rdname); 151 152 153 /* 154 * A response arrived, update dialog 155 */ 156 int dlg_response_uac( 157 dlg_t *_d, struct sip_msg *_m, target_refresh_t is_target_refresh); 158 typedef int (*dlg_response_uac_f)( 159 dlg_t *_d, struct sip_msg *_m, target_refresh_t is_target_refresh); 160 161 /* 162 * Establishing a new dialog, UAS side 163 */ 164 int new_dlg_uas(struct sip_msg *_req, int _code, /*str* _tag,*/ dlg_t **_d); 165 typedef int (*new_dlg_uas_f)(struct sip_msg *_req, int _code, dlg_t **_d); 166 167 /* 168 * UAS side - update dialog state and to tag 169 */ 170 int update_dlg_uas(dlg_t *_d, int _code, str *_tag); 171 typedef int (*update_dlg_uas_f)(dlg_t *_d, int _code, str *_tag); 172 173 /* 174 * UAS side - update a dialog from a request 175 */ 176 int dlg_request_uas( 177 dlg_t *_d, struct sip_msg *_m, target_refresh_t is_target_request); 178 typedef int (*dlg_request_uas_f)( 179 dlg_t *_d, struct sip_msg *_m, target_refresh_t is_target_request); 180 181 182 /* 183 * Destroy a dialog state 184 */ 185 void free_dlg(dlg_t *_d); 186 typedef void (*free_dlg_f)(dlg_t *_d); 187 188 189 /* 190 * Print a dialog structure, just for debugging 191 */ 192 void print_dlg(FILE *out, dlg_t *_d); 193 typedef void (*print_dlg_f)(FILE *out, dlg_t *_d); 194 195 196 /* 197 * Calculate length of the route set 198 */ 199 int calculate_routeset_length(dlg_t *_d); 200 201 202 /* 203 * 204 * Print the route set 205 */ 206 char *print_routeset(char *buf, dlg_t *_d); 207 208 /* 209 * wrapper to calculate_hooks 210 * added by dcm 211 */ 212 int w_calculate_hooks(dlg_t *_d); 213 typedef int (*calculate_hooks_f)(dlg_t *_d); 214 215 /* 216 * set dialog's request uri and destination uri (optional) 217 */ 218 int set_dlg_target(dlg_t *_d, str *_ruri, str *_duri); 219 typedef int (*set_dlg_target_f)(dlg_t *_d, str *_ruri, str *_duri); 220 221 #ifdef DIALOG_CALLBACKS 222 223 /* dialog callback 224 * params: type - DLG_UAC or DLG_UAS 225 * dlg - dialog structure 226 * msg - message used for creating the new dialog for the new_dlg_uas 227 * case, 0 otherwise (new_dlg_uac) 228 */ 229 typedef void(dialog_cb)(int type, dlg_t *dlg, struct sip_msg *msg); 230 231 /* callbacks for new dialogs (called each time a new dialog (uas or uac) is 232 * created). Can be used for installing in-dialog callbacks 233 * returns < 0 on error*/ 234 int register_new_dlg_cb(int types, dialog_cb f, void *param); 235 /* callbacks for messages sent dialogs */ 236 int register_dlg_tmcb(int type, dlg_t *dlg, transaction_cb f, void *param); 237 void run_trans_dlg_callbacks( 238 dlg_t *dlg, struct cell *trans, struct retr_buf *rbuf); 239 /* cleanup on exit */ 240 void destroy_new_dlg_cbs(void); 241 242 typedef int (*register_new_dlg_cb_f)(int, dialog_cb, void *); 243 typedef int (*register_dlg_tmcb_f)(int, dlg_t *, transaction_cb, void *); 244 #endif /* DIALOG_CALLBACKS */ 245 246 247 #endif /* DLG_H */ 248