2 The oSIP library implements the Session Initiation Protocol (SIP -rfc2543-)
3 Copyright (C) 2001 Aymeric MOIZARD jack@atosc.org
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <osip2/osip.h>
27 * @brief oSIP dialog Routines
29 * Dialog management is a powerful facility given by oSIP. This feature is
30 * needed by SIP end point who has the capability to answer calls. (i.e.
31 * answering 200 OK to an INVITE).
33 * A Dialog is a context for a call establishment in oSIP. It's not useless
34 * to say that ONE invite request can lead to several call establishment.
35 * This can happen if your call has been forked by a proxy and several
36 * user agent was contacted and replied at the same time. It is true that
37 * this case won't probably happen several times a month...
39 * There is two ways of creating a dialog. In one case, you are the CALLER
40 * and in the other case, you will be the CALLEE.
42 * <LI>Creating a dialog as a CALLER
43 * <BR>In this case, you have to create a dialog each time you receive
44 * an answer with a code between 101 and 299. The best place in oSIP to
45 * actually create a dialog is of course in the callback that announce
46 * such SIP messages. Of course, each time you receive a response, you have
47 * to check for an existing dialog associated to this INVITE that can have
48 * been created by earlier SIP answer coming from the same User Agent. The
49 * code in the callback will look like the following:
50 * <BR> void cb_rcv1xx(osip_transaction_t *tr,osip_message_t *sip)
52 * <BR> osip_dialog_t *dialog;
53 * <BR> if (MSG_IS_RESPONSEFOR(sip, "INVITE")&&!MSG_TEST_CODE(sip, 100)) {
54 * <BR> dialog = my_application_search_existing_dialog(sip);
55 * <BR> if (dialog==NULL) //NO EXISTING DIALOG
57 * <BR> i = osip_dialog_init_as_uac(&dialog, sip);
58 * <BR> my_application_add_existing_dialog(dialog);
61 * <BR> // no dialog establishment for other REQUEST
64 * <LI>Creating a dialog as a CALLEE
65 * <BR>In this case, you will have to create a dialog upon receiving the first
66 * transmission of the INVITE request. The correct place to do that is inside
67 * the callback previously registered to announce new INVITE. First, you will
68 * build a SIP answer like 180 or 200 and you'll be able to create a dialog
69 * by calling the following code:
70 * <BR>osip_dialog_t *dialog;
71 * <BR>osip_dialog_init_as_uas(&dialog, original_invite, response_that_you_build);
72 * <BR>To make things working, you MUST create a VALID response: do not
73 * forget to create a new tag and put it in the 'To' header. The dialog
74 * management heavily depends on this tag.
77 * <P>The dialog management is compliant with the latest SIP draft
78 * (rfc2543bis-09). It should handle successfully most cases where
79 * a remote UA is not compliant (no tag in the To of a final response!)
80 * But for example, if you receive 2 answers from 2 uncompliant
81 * UA, they will be detected as being related to the same dialog...
82 * Do not change any code in oSIP or in your application... instead, you
83 * should boycott such implementation. :-
87 * @defgroup oSIP_DIALOG oSIP dialog Handling
99 typedef enum _osip_dialog_type_t
109 * Structure for referencing a dialog.
112 typedef struct osip_dialog osip_dialog_t;
116 * Structure for referencing a dialog.
120 /* char *dialog_id; ***implied*** *//* call-id:local_tag:remote-tag */
124 osip_list_t *route_set;
127 osip_to_t *remote_uri;
128 osip_from_t *local_uri;
129 osip_contact_t *remote_contact_uri;
132 /* type of dialog (CALLEE or CALLER) */
133 osip_dialog_type_t type;
134 state_t state; /* DIALOG_EARLY || DIALOG_CONFIRMED || DIALOG_CLOSED */
138 * Allocate a osip_dialog_t element as a UAC.
139 * <UL><LI>NOTE1: Only INVITE transactions can create a dialog.</LI>
140 * <LI>NOTE2: The dialog should be created when the first response is received.
141 * (except for a 100 Trying)</LI>
142 * <LI>NOTE3: Remote UA should be compliant! If not (not tag in the to header?)
143 * the old mechanism is used to match the request but if 2 uncompliant
144 * UA both answer 200 OK for the same transaction, they won't be detected.
145 * This is a major BUG in the old rfc.</LI></UL>
146 * @param dialog The element to allocate.
147 * @param response The response containing the informations.
149 int osip_dialog_init_as_uac (osip_dialog_t ** dialog,
150 osip_message_t * response);
152 * Allocate a osip_dialog_t element as a UAC.
153 * <UL><LI>This could be used to initiate dialog with a NOTIFY coming
154 * before the answer for a subscribe has reached us.</LI>
155 * @param dialog The element to allocate.
156 * @param next_request The response containing the informations.
157 * @param local_cseq The local cseq
159 int osip_dialog_init_as_uac_with_remote_request (osip_dialog_t ** dialog,
165 * Allocate a osip_dialog_t element as a UAS.
166 * NOTE1: Only INVITE transactions can create a dialog.
167 * NOTE2: The dialog should be created when the first response is sent.
168 * (except for a 100 Trying)
169 * @param dialog The element to allocate.
170 * @param invite The INVITE request containing some informations.
171 * @param response The response containing other informations.
173 int osip_dialog_init_as_uas (osip_dialog_t ** dialog,
174 osip_message_t * invite,
175 osip_message_t * response);
177 * Free all resource in a osip_dialog_t element.
178 * @param dialog The element to free.
180 void osip_dialog_free (osip_dialog_t * dialog);
182 * Set the state of the dialog.
183 * This is useful to keep information on who is the initiator of the call.
184 * @param dialog The element to work on.
185 * @param type The type of dialog (CALLEE or CALLER).
187 void osip_dialog_set_state (osip_dialog_t * dialog, state_t type);
189 * Update the Route-Set as UAS of a dialog.
190 * NOTE: bis-09 says that only INVITE transactions can update the route-set.
191 * NOTE: bis-09 says that updating the route-set means: update the contact
192 * field only (AND NOT THE ROUTE-SET). This method follow this behaviour.
193 * NOTE: This method should be called for each request (except 100 Trying)
194 * received for a dialog.
195 * @param dialog The element to work on.
196 * @param invite The invite received.
198 int osip_dialog_update_route_set_as_uas (osip_dialog_t * dialog,
199 osip_message_t * invite);
201 * Update the CSeq (remote cseq) during a UAS transaction of a dialog.
202 * NOTE: All INCOMING transactions MUST update the remote CSeq.
203 * @param dialog The element to work on.
204 * @param request The request received.
206 int osip_dialog_update_osip_cseq_as_uas (osip_dialog_t * dialog,
207 osip_message_t * request);
210 * Match a response received with a dialog.
211 * @param dialog The element to work on.
212 * @param response The response received.
214 int osip_dialog_match_as_uac (osip_dialog_t * dialog,
215 osip_message_t * response);
217 * Update the tag as UAC of a dialog?. (this could be needed if the 180
218 * does not contains any tag, but the 200 contains one.
219 * @param dialog The element to work on.
220 * @param response The response received.
222 int osip_dialog_update_tag_as_uac (osip_dialog_t * dialog,
223 osip_message_t * response);
225 * Update the Route-Set as UAC of a dialog.
226 * NOTE: bis-09 says that only INVITE transactions can update the route-set.
227 * NOTE: bis-09 says that updating the route-set means: update the contact
228 * field only (AND NOT THE ROUTE-SET). This method follow this behaviour.
229 * NOTE: This method should be called for each request (except 100 Trying)
230 * received for a dialog.
231 * @param dialog The element to work on.
232 * @param response The response received.
234 int osip_dialog_update_route_set_as_uac (osip_dialog_t * dialog,
235 osip_message_t * response);
238 * Match a request (response sent??) received with a dialog.
239 * @param dialog The element to work on.
240 * @param request The request received.
242 int osip_dialog_match_as_uas (osip_dialog_t * dialog,
243 osip_message_t * request);
246 int osip_dialog_is_originator (osip_dialog_t * dialog);
247 int osip_dialog_is_callee (osip_dialog_t * dialog);