modules/tm/dlg.h
cbac555e
 /*
  * $Id$
84d8e165
  * Copyright (C) 2001-2003 FhG Fokus
179e3637
  *
  * This file is part of ser, a free SIP server.
  *
  * ser is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
  * For a license to use the ser software under conditions
  * other than those described here, or to purchase support for this
  * software, please contact iptel.org by e-mail at the following addresses:
  *   info@iptel.org
  *
  * ser is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
cbac555e
  *
  * History:
  * -------
  * 2003-03-29 Created by janakj
0277f618
  * 2007-04-13 added dialog callbacks (andrei)
cbac555e
  */
 
 #ifndef DLG_H
 #define DLG_H
 
 
0ade91eb
 #include <stdio.h>
cbac555e
 #include "../../str.h"
1f8f46a3
 #include "../../ip_addr.h"
cbac555e
 #include "../../parser/parse_rr.h"
 #include "../../parser/msg_parser.h"
 
0277f618
 /*
 #define DIALOG_CALLBACKS
 */
 
 #ifdef DIALOG_CALLBACKS
 #include "t_hooks.h"
 #include "h_table.h"
 
 #define DLG_CB_UAC 30
 #define DLG_CB_UAS 31
 
 #endif /* DIALOG_CALLBACKS */
 
cbac555e
 
 /*
  * Dialog sequence
  */
 typedef struct dlg_seq {
 	unsigned int value;    /* Sequence value */
 	unsigned char is_set;  /* is_set flag */
 } dlg_seq_t;
 
 
 /*
  * Dialog state
  */
 typedef enum dlg_state {
 	DLG_NEW = 0,   /* New dialog, no reply received yet */
 	DLG_EARLY,     /* Early dialog, provisional response received */
 	DLG_CONFIRMED, /* Confirmed dialog, 2xx received */
 	DLG_DESTROYED  /* Destroyed dialog */
 } dlg_state_t;
 
 
 /*
  * Structure describing a dialog identifier
  */
 typedef struct dlg_id {
 	str call_id;    /* Call-ID */
 	str rem_tag;    /* Remote tag of the dialog */
 	str loc_tag;    /* Local tag of the dialog */
 } dlg_id_t;
 
 
 /*
84d8e165
  * It is necessary to analyze the dialog data to find out
0ade91eb
  * what URI put into the Record-Route, where the message
  * should be really sent and how to construct the route
  * set of the message. This structure stores this information
  * so we don't have to calculate each time we want to send a
  * message within dialog
  */
 typedef struct dlg_hooks {
c5867ab3
 	str ru;
 	str nh;
0ade91eb
 	str* request_uri;   /* This should be put into Request-URI */
 	str* next_hop;      /* Where the message should be really sent */
 	rr_t* first_route;  /* First route to be printed into the message */
 	str* last_route;    /* If not zero add this as the last route */
 } dlg_hooks_t;
 
 
 /*
cbac555e
  * Structure representing dialog state
  */
 typedef struct dlg {
 	dlg_id_t id;            /* Dialog identifier */
 	dlg_seq_t loc_seq;      /* Local sequence number */
 	dlg_seq_t rem_seq;      /* Remote sequence number */
 	str loc_uri;            /* Local URI */
 	str rem_uri;            /* Remote URI */
 	str rem_target;         /* Remote target URI */
04436036
 	str dst_uri;		/* Destination URI */
cbac555e
 	unsigned char secure;   /* Secure flag -- currently not used */
 	dlg_state_t state;      /* State of the dialog */
 	rr_t* route_set;        /* Route set */
0ade91eb
 	dlg_hooks_t hooks;      /* Various hooks used to store information that
 				 * can be reused when building a message (to
84d8e165
 				 * prevent repeated analyzing of the dialog data
0ade91eb
 				 */
1f8f46a3
 	struct socket_info* send_sock;
0277f618
 #ifdef DIALOG_CALLBACKS
 	struct tmcb_head_list dlg_callbacks;
 #endif
cbac555e
 } dlg_t;
 
665ec3ae
 typedef enum {
 	IS_TARGET_REFRESH,
 	IS_NOT_TARGET_REFRESH,
 	TARGET_REFRESH_UNKNOWN
 } target_refresh_t;
cbac555e
 
 /*
  * Create a new dialog
  */
 int new_dlg_uac(str* _cid, str* _ltag, unsigned int _lseq, str* _luri, str* _ruri, dlg_t** _d);
c5867ab3
 typedef int (*new_dlg_uac_f)(str* _cid, str* _ltag, unsigned int _lseq, str* _luri, str* _ruri, dlg_t** _d);
cbac555e
 
 
 /*
  * A response arrived, update dialog
  */
665ec3ae
 int dlg_response_uac(dlg_t* _d, struct sip_msg* _m, target_refresh_t is_target_refresh);
 typedef int (*dlg_response_uac_f)(dlg_t* _d, struct sip_msg* _m, target_refresh_t is_target_refresh);
cbac555e
 
 /*
  * Establishing a new dialog, UAS side
  */
c5867ab3
 int new_dlg_uas(struct sip_msg* _req, int _code, /*str* _tag,*/ dlg_t** _d);
 typedef int (*new_dlg_uas_f)(struct sip_msg* _req, int _code, dlg_t** _d);
cbac555e
 
04436036
 /*
  * UAS side - update dialog state and to tag
  */
 int update_dlg_uas(dlg_t *_d, int _code, str* _tag);
 typedef int (*update_dlg_uas_f)(dlg_t *_d, int _code, str* _tag);
cbac555e
 
 /*
  * UAS side - update a dialog from a request
  */
665ec3ae
 int dlg_request_uas(dlg_t* _d, struct sip_msg* _m, target_refresh_t is_target_request);
 typedef int (*dlg_request_uas_f)(dlg_t* _d, struct sip_msg* _m, target_refresh_t is_target_request);
cbac555e
 
 
 /*
  * Destroy a dialog state
  */
 void free_dlg(dlg_t* _d);
c5867ab3
 typedef void (*free_dlg_f)(dlg_t* _d);
cbac555e
 
 
 /*
  * Print a dialog structure, just for debugging
  */
0ade91eb
 void print_dlg(FILE* out, dlg_t* _d);
c5867ab3
 typedef void (*print_dlg_f)(FILE* out, dlg_t* _d);
0ade91eb
 
 
 /*
  * Calculate length of the route set
  */
 int calculate_routeset_length(dlg_t* _d);
 
 
 /*
  *
  * Print the route set
  */
 char* print_routeset(char* buf, dlg_t* _d);
cbac555e
 
ffd3b034
 /*
  * wrapper to calculate_hooks
  * added by dcm
  */
 int w_calculate_hooks(dlg_t* _d);
a6fc01ca
 typedef int (*calculate_hooks_f)(dlg_t* _d);
cbac555e
 
04436036
 /*
  * set dialog's request uri and destination uri (optional)
  */
 int set_dlg_target(dlg_t* _d, str* _ruri, str* _duri);
 typedef int (*set_dlg_target_f)(dlg_t* _d, str* _ruri, str* _duri);
 
0277f618
 #ifdef DIALOG_CALLBACKS
 
 /* dialog callback
  * params:  type - DLG_UAC or DLG_UAS
  *          dlg  - dialog structure
  *          msg  - message used for creating the new dialog for the new_dlg_uas
  *                 case, 0 otherwise (new_dlg_uac)
  */
 typedef void (dialog_cb) (int type, dlg_t* dlg, struct sip_msg* msg);
 
 /* callbacks for new dialogs (called each time a new dialog (uas or uac) is
  * created). Can be used for installing in-dialog callbacks
  * returns < 0 on error*/
 int register_new_dlg_cb(int types, dialog_cb f, void* param);
 /* callbacks for messages sent dialogs */
 int register_dlg_tmcb(int type, dlg_t* dlg, transaction_cb f, void* param);
 void run_trans_dlg_callbacks(dlg_t* dlg, struct cell* trans,
 								struct retr_buf* rbuf);
 /* cleanup on exit */
 void destroy_new_dlg_cbs();
1237c6d1
 
 typedef int (*register_new_dlg_cb_f)(int, dialog_cb, void*);
 typedef int (*register_dlg_tmcb_f)(int, dlg_t*, transaction_cb, void*);
0277f618
 #endif /* DIALOG_CALLBACKS */
 
 
cbac555e
 #endif /* DLG_H */