2
eXosip - This is the eXtended osip library.
3
Copyright (C) 2002, 2003 Aymeric MOIZARD - jack@atosc.org
5
eXosip is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
eXosip 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
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
#include <eXosip_cfg.h>
28
extern eXosip_t eXosip;
30
/* Private functions */
31
static char *generating_no_sdp_answer(eXosip_call_t *jc, eXosip_dialog_t *jd,
32
osip_message_t *orig_request, char *local_sdp_port);
35
eXosip_build_response_default(int jid, int status)
41
_eXosip_build_response_default(osip_message_t **dest, osip_dialog_t *dialog,
42
int status, osip_message_t *request)
44
osip_generic_param_t *tag;
45
osip_message_t *response;
49
if (request==NULL) return -1;
51
i = osip_message_init(&response);
54
/* initialise osip_message_t structure */
57
response->sip_version = (char *)osip_malloc(8*sizeof(char));
58
sprintf(response->sip_version,"SIP/2.0");
59
osip_message_set_status_code(response, status);
61
/* handle some internal reason definitions. */
62
if (MSG_IS_NOTIFY(request) && status==481)
64
response->reason_phrase = osip_strdup("Subcription Does Not Exist");
66
else if (MSG_IS_SUBSCRIBE(request) && status==202)
68
response->reason_phrase = osip_strdup("Accepted subscription");
72
response->reason_phrase = osip_strdup(osip_message_get_reason(status));
73
if (response->reason_phrase==NULL)
75
if (response->status_code == 101)
76
response->reason_phrase = osip_strdup("Dialog Establishement");
78
response->reason_phrase = osip_strdup("Unknown code");
80
response->req_uri = NULL;
81
response->sip_method = NULL;
84
i = osip_to_clone(request->to, &(response->to));
85
if (i!=0) goto grd_error_1;
87
i = osip_to_get_tag(response->to,&tag);
89
{ /* we only add a tag if it does not already contains one! */
90
if ((dialog!=NULL) && (dialog->local_tag!=NULL))
91
/* it should contain the local TAG we created */
92
{ osip_to_set_tag(response->to, osip_strdup(dialog->local_tag)); }
96
osip_to_set_tag(response->to, osip_to_tag_new_random());
100
i = osip_from_clone(request->from, &(response->from));
101
if (i!=0) goto grd_error_1;
104
while (!osip_list_eol(request->vias,pos))
108
via = (osip_via_t *)osip_list_get(request->vias,pos);
109
i = osip_via_clone(via, &via2);
110
if (i!=-0) goto grd_error_1;
111
osip_list_add(response->vias, via2, -1);
115
i = osip_call_id_clone(request->call_id, &(response->call_id));
116
if (i!=0) goto grd_error_1;
117
i = osip_cseq_clone(request->cseq, &(response->cseq));
118
if (i!=0) goto grd_error_1;
120
if (MSG_IS_SUBSCRIBE(request))
123
osip_message_set_header(response, "Event", "presence");
124
i = osip_message_get_expires(request, 0, &exp);
128
i = osip_header_clone(exp, &cp);
130
osip_list_add(response->headers, cp, 0);
134
osip_message_set_allow(response, "INVITE");
135
osip_message_set_allow(response, "ACK");
136
osip_message_set_allow(response, "OPTIONS");
137
osip_message_set_allow(response, "CANCEL");
138
osip_message_set_allow(response, "BYE");
139
osip_message_set_allow(response, "SUBSCRIBE");
140
osip_message_set_allow(response, "NOTIFY");
141
osip_message_set_allow(response, "MESSAGE");
142
osip_message_set_allow(response, "INFO");
148
osip_message_free(response);
153
complete_answer_that_establish_a_dialog(osip_message_t *response, osip_message_t *request)
164
copy all record-route in response
165
add a contact with global scope
167
while (!osip_list_eol(request->record_routes, pos))
169
osip_record_route_t *rr;
170
osip_record_route_t *rr2;
171
rr = osip_list_get(request->record_routes, pos);
172
i = osip_record_route_clone(rr, &rr2);
174
osip_list_add(response->record_routes, rr2, -1);
179
eXosip_get_localip_from_via(response,&locip);
181
eXosip_guess_ip_for_via(eXosip.ip_family, locip, 49);
184
if (eXosip.answer_contact[0])
185
snprintf(contact,1000, "%s", eXosip.answer_contact);
186
else if (request->to->url->username==NULL)
187
snprintf(contact,1000, "<sip:%s:%s>", locip, eXosip.localport);
189
snprintf(contact,1000, "<sip:%s@%s:%s>", request->to->url->username,
190
locip, eXosip.localport);
192
if (eXosip.j_firewall_ip[0]!='\0')
194
osip_contact_t *con = (osip_contact_t *) osip_list_get (request->contacts, 0);
195
if (con!=NULL && con->url!=NULL && con->url->host!=NULL)
197
char *c_address = con->url->host;
199
struct addrinfo *addrinfo;
200
struct __eXosip_sockaddr addr;
201
i = eXosip_get_addrinfo(&addrinfo, con->url->host, 5060);
204
memcpy (&addr, addrinfo->ai_addr, addrinfo->ai_addrlen);
205
freeaddrinfo (addrinfo);
206
c_address = inet_ntoa (((struct sockaddr_in *) &addr)->sin_addr);
207
OSIP_TRACE (osip_trace
208
(__FILE__, __LINE__, OSIP_INFO1, NULL,
209
"eXosip: here is the resolved destination host=%s\n", c_address));
212
/* If c_address is a PUBLIC address, the request was
213
coming from the PUBLIC network. */
214
if (eXosip_is_public_address(c_address))
216
if (request->to->url->username==NULL)
217
snprintf(contact,1000, "<sip:%s:%s>", eXosip.j_firewall_ip,
220
snprintf(contact,1000, "<sip:%s@%s:%s>", request->to->url->username,
221
eXosip.j_firewall_ip, eXosip.localport);
230
osip_message_set_contact(response, contact);
236
generating_no_sdp_answer(eXosip_call_t *jc, eXosip_dialog_t *jd,
237
osip_message_t *orig_request, char *local_sdp_port)
239
sdp_message_t *local_sdp = NULL;
240
char *local_body = NULL;
245
if(osip_negotiation_sdp_build_offer(eXosip.osip_negotiation, NULL, &local_sdp, local_sdp_port, NULL) != 0)
251
while (!sdp_message_endof_media (local_sdp, pos))
254
char *tmp = sdp_message_m_media_get (local_sdp, pos);
255
if (0 == strncmp (tmp, "audio", 5))
257
char *payload = NULL;
259
payload = sdp_message_m_payload_get (local_sdp, pos, k);
263
else if (0==strcmp("110",payload))
265
sdp_message_a_attribute_add (local_sdp,
268
osip_strdup ("110 20"));
270
else if (0==strcmp("111",payload))
272
sdp_message_a_attribute_add (local_sdp,
275
osip_strdup ("111 20"));
278
} while (payload != NULL);
284
i = sdp_message_to_str(local_sdp, &local_body);
286
if (local_body!=NULL)
288
size= (char *)osip_malloc(7*sizeof(char));
290
sprintf(size,"%li",strlen(local_body));
292
sprintf(size,"%i",strlen(local_body));
294
osip_message_set_content_length(orig_request, size);
297
osip_message_set_body(orig_request, local_body, strlen(local_body));
298
osip_message_set_content_type(orig_request, "application/sdp");
301
osip_message_set_content_length(orig_request, "0");
303
osip_negotiation_ctx_set_local_sdp(jc->c_ctx, local_sdp);
305
OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO3,NULL,"200 OK w/ SDP (RESPONSE TO INVITE w/ NO SDP)=\n%s\n", local_body));
311
generating_sdp_answer(osip_message_t *request, osip_negotiation_ctx_t *context)
313
sdp_message_t *remote_sdp;
314
sdp_message_t *local_sdp = NULL;
321
if (MSG_IS_INVITE(request)||MSG_IS_OPTIONS(request)||MSG_IS_RESPONSE_FOR(request, "INVITE"))
324
body = (osip_body_t *)osip_list_get(request->bodies,0);
328
/* remote_sdp = (sdp_message_t *) osip_malloc(sizeof(sdp_message_t)); */
329
i = sdp_message_init(&remote_sdp);
330
if (i!=0) return NULL;
332
/* WE ASSUME IT IS A SDP BODY AND THAT */
333
/* IT IS THE ONLY ONE, OF COURSE, THIS IS */
335
i = sdp_message_parse(remote_sdp,body->body);
336
if (i!=0) return NULL;
338
i = osip_negotiation_ctx_set_remote_sdp(context, remote_sdp);
340
i = osip_negotiation_ctx_execute_negotiation(eXosip.osip_negotiation, context);
343
local_sdp = osip_negotiation_ctx_get_local_sdp(context);
345
if (eXosip.j_firewall_ip[0]!='\0')
347
char *c_address = NULL;
349
/* If remote message contains a Public IP, we have to replace the SDP
350
connection address */
351
c_address = sdp_message_c_addr_get(remote_sdp, -1, 0);
352
while (c_address==NULL)
354
c_address = sdp_message_c_addr_get(remote_sdp, pos, 0);
359
if (c_address!=NULL) /* found a connection address: check if it is public */
362
struct addrinfo *addrinfo;
363
struct __eXosip_sockaddr addr;
364
i = eXosip_get_addrinfo(&addrinfo, c_address, 5060);
367
memcpy (&addr, addrinfo->ai_addr, addrinfo->ai_addrlen);
368
freeaddrinfo (addrinfo);
369
c_address = inet_ntoa (((struct sockaddr_in *) &addr)->sin_addr);
370
OSIP_TRACE (osip_trace
371
(__FILE__, __LINE__, OSIP_INFO1, NULL,
372
"eXosip: here is the resolved destination host=%s\n", c_address));
375
if (eXosip_is_public_address(c_address))
377
/* replace the IP with our firewall ip */
378
sdp_connection_t *conn;
380
conn = sdp_message_connection_get(local_sdp, pos, 0);
383
if (conn->c_addr!=NULL )
385
osip_free(conn->c_addr);
386
conn->c_addr = osip_strdup(eXosip.j_firewall_ip);
389
conn = sdp_message_connection_get(local_sdp, pos, 0);
395
i = sdp_message_to_str(local_sdp, &local_body);
397
remote_sdp = osip_negotiation_ctx_get_remote_sdp(context);
398
sdp_message_free(remote_sdp);
399
osip_negotiation_ctx_set_remote_sdp(context, NULL);
402
OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_ERROR,NULL,"ERROR: Could not parse local SDP answer %i\n",i));
409
OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL,"WARNING: Unsupported media %i\n",i));
413
OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_ERROR,NULL,"ERROR: while building answer to SDP (%i)\n",i));
415
remote_sdp = osip_negotiation_ctx_get_remote_sdp(context);
416
sdp_message_free(remote_sdp);
417
osip_negotiation_ctx_set_remote_sdp(context, NULL);
423
eXosip_answer_options_1xx(eXosip_call_t *jc, eXosip_dialog_t *jd, int code)
425
osip_event_t *evt_answer;
426
osip_transaction_t *tr;
427
osip_message_t *response;
430
tr = eXosip_find_last_inc_options(jc, jd);
433
OSIP_TRACE (osip_trace
434
(__FILE__, __LINE__, OSIP_ERROR, NULL,
435
"eXosip: cannot find transaction to answer"));
441
i = _eXosip_build_response_default(&response, jd->d_dialog, code, tr->orig_request);
445
i = _eXosip_build_response_default(&response, NULL, code, tr->orig_request);
450
OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_ERROR,NULL,"ERROR: Could not create response for OPTIONS\n"));
454
evt_answer = osip_new_outgoing_sipmessage(response);
455
evt_answer->transactionid = tr->transactionid;
457
osip_transaction_add_event(tr, evt_answer);
463
eXosip_answer_options_2xx(eXosip_call_t *jc, eXosip_dialog_t *jd, int code)
465
osip_event_t *evt_answer;
466
osip_transaction_t *tr;
467
osip_message_t *response;
473
tr = eXosip_find_last_inc_options(jc, jd);
476
OSIP_TRACE (osip_trace
477
(__FILE__, __LINE__, OSIP_ERROR, NULL,
478
"eXosip: cannot find transaction to answer"));
481
osip_negotiation_sdp_build_offer(eXosip.osip_negotiation, NULL, &sdp, "10400", NULL);
488
i = _eXosip_build_response_default(&response, jd->d_dialog, code, tr->orig_request);
492
i = _eXosip_build_response_default(&response, NULL, code, tr->orig_request);
496
OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL,"ERROR: Could not create response for options\n"));
497
sdp_message_free(sdp); /* not used */
500
i = sdp_message_to_str(sdp, &body);
501
sdp_message_free(sdp);
503
osip_message_free(response);
506
i = osip_message_set_body(response, body, strlen(body));
508
osip_message_free(response);
512
snprintf(size, 9,"%li",strlen(body));
514
snprintf(size, 9,"%i",strlen(body));
516
i = osip_message_set_content_length(response, size);
519
osip_message_free(response);
523
i = osip_message_set_content_type(response, "application/sdp");
525
osip_message_free(response);
529
evt_answer = osip_new_outgoing_sipmessage(response);
530
evt_answer->transactionid = tr->transactionid;
532
osip_transaction_add_event(tr, evt_answer);
538
eXosip_answer_options_3456xx(eXosip_call_t *jc, eXosip_dialog_t *jd, int code)
540
osip_event_t *evt_answer;
541
osip_transaction_t *tr;
542
osip_message_t *response;
544
tr = eXosip_find_last_inc_options(jc, jd);
547
OSIP_TRACE (osip_trace
548
(__FILE__, __LINE__, OSIP_ERROR, NULL,
549
"eXosip: cannot find transaction to answer"));
555
i = _eXosip_build_response_default(&response, jd->d_dialog, code, tr->orig_request);
559
i = _eXosip_build_response_default(&response, NULL, code, tr->orig_request);
563
OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL,"ERROR: Could not create response for options\n"));
569
/* Should add contact fields */
571
osip_message_set_contact(response, jc->c_redirection);
574
osip_message_set_content_length(response, "0");
575
/* send message to transaction layer */
577
evt_answer = osip_new_outgoing_sipmessage(response);
578
evt_answer->transactionid = tr->transactionid;
580
osip_transaction_add_event(tr, evt_answer);
587
_eXosip2_answer_invite_1xx(eXosip_call_t *jc, eXosip_dialog_t *jd, int code, osip_message_t **answer)
590
osip_transaction_t *tr;
591
tr = eXosip_find_last_inc_invite(jc, jd);
594
OSIP_TRACE (osip_trace
595
(__FILE__, __LINE__, OSIP_ERROR, NULL,
596
"eXosip: cannot find transaction to answer"));
599
/* is the transaction already answered? */
600
if (tr->state==IST_COMPLETED
601
|| tr->state==IST_CONFIRMED
602
|| tr->state==IST_TERMINATED)
604
OSIP_TRACE (osip_trace
605
(__FILE__, __LINE__, OSIP_ERROR, NULL,
606
"eXosip: transaction already answered\n"));
611
i = _eXosip_build_response_default(answer, NULL, code, tr->orig_request);
613
i = _eXosip_build_response_default(answer, jd->d_dialog, code, tr->orig_request);
617
OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_ERROR,NULL,"ERROR: Could not create response for invite\n"));
621
osip_message_set_content_length(*answer, "0");
622
/* send message to transaction layer */
626
i = complete_answer_that_establish_a_dialog(*answer, tr->orig_request);
633
_eXosip2_answer_invite_2xx(eXosip_call_t *jc, eXosip_dialog_t *jd, int code, osip_message_t **answer)
636
osip_transaction_t *tr;
637
tr = eXosip_find_last_inc_invite(jc, jd);
639
if (tr==NULL || tr->orig_request==NULL)
641
OSIP_TRACE (osip_trace
642
(__FILE__, __LINE__, OSIP_ERROR, NULL,
643
"eXosip: cannot find transaction to answer\n"));
647
if (jd!=NULL && jd->d_dialog==NULL)
648
{ /* element previously removed */
649
OSIP_TRACE (osip_trace
650
(__FILE__, __LINE__, OSIP_ERROR, NULL,
651
"eXosip: cannot answer this closed transaction\n"));
655
/* is the transaction already answered? */
656
if (tr->state==IST_COMPLETED
657
|| tr->state==IST_CONFIRMED
658
|| tr->state==IST_TERMINATED)
660
OSIP_TRACE (osip_trace
661
(__FILE__, __LINE__, OSIP_ERROR, NULL,
662
"eXosip: transaction already answered\n"));
667
i = _eXosip_build_response_default(answer, NULL, code, tr->orig_request);
669
i = _eXosip_build_response_default(answer, jd->d_dialog, code, tr->orig_request);
673
OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL,"ERROR: Could not create response for invite\n"));
677
/* request that estabish a dialog: */
678
/* 12.1.1 UAS Behavior */
680
i = complete_answer_that_establish_a_dialog(*answer, tr->orig_request);
681
if (i!=0) goto g2atii_error_1;; /* ?? */
687
osip_message_free(*answer);
692
_eXosip2_answer_invite_3456xx(eXosip_call_t *jc, eXosip_dialog_t *jd, int code, osip_message_t **answer)
695
osip_transaction_t *tr;
696
tr = eXosip_find_last_inc_invite(jc, jd);
699
OSIP_TRACE (osip_trace
700
(__FILE__, __LINE__, OSIP_ERROR, NULL,
701
"eXosip: cannot find transaction to answer"));
704
/* is the transaction already answered? */
705
if (tr->state==IST_COMPLETED
706
|| tr->state==IST_CONFIRMED
707
|| tr->state==IST_TERMINATED)
709
OSIP_TRACE (osip_trace
710
(__FILE__, __LINE__, OSIP_ERROR, NULL,
711
"eXosip: transaction already answered\n"));
715
i = _eXosip_build_response_default(answer, jd->d_dialog, code, tr->orig_request);
718
OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL,"ERROR: Could not create response for invite\n"));
724
/* Should add contact fields */
728
osip_message_set_content_length(*answer, "0");
729
/* send message to transaction layer */
735
eXosip_answer_invite_1xx(eXosip_call_t *jc, eXosip_dialog_t *jd, int code)
737
osip_event_t *evt_answer;
738
osip_message_t *response;
740
osip_transaction_t *tr;
741
tr = eXosip_find_last_inc_invite(jc, jd);
744
OSIP_TRACE (osip_trace
745
(__FILE__, __LINE__, OSIP_ERROR, NULL,
746
"eXosip: cannot find transaction to answer"));
749
/* is the transaction already answered? */
750
if (tr->state==IST_COMPLETED
751
|| tr->state==IST_CONFIRMED
752
|| tr->state==IST_TERMINATED)
754
OSIP_TRACE (osip_trace
755
(__FILE__, __LINE__, OSIP_ERROR, NULL,
756
"eXosip: transaction already answered\n"));
761
i = _eXosip_build_response_default(&response, NULL, code, tr->orig_request);
763
i = _eXosip_build_response_default(&response, jd->d_dialog, code, tr->orig_request);
767
OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_ERROR,NULL,"ERROR: Could not create response for invite\n"));
771
osip_message_set_content_length(response, "0");
772
/* send message to transaction layer */
776
/* request that estabish a dialog: */
777
/* 12.1.1 UAS Behavior */
778
i = complete_answer_that_establish_a_dialog(response, tr->orig_request);
782
i = eXosip_dialog_init_as_uas(&jd, tr->orig_request, response);
785
OSIP_TRACE (osip_trace
786
(__FILE__, __LINE__, OSIP_ERROR, NULL,
787
"eXosip: cannot create dialog!\n"));
789
ADD_ELEMENT(jc->c_dialogs, jd);
793
evt_answer = osip_new_outgoing_sipmessage(response);
794
evt_answer->transactionid = tr->transactionid;
796
osip_transaction_add_event(tr, evt_answer);
803
eXosip_answer_invite_2xx_with_body(eXosip_call_t *jc, eXosip_dialog_t *jd, int code,const char*bodytype, const char*body)
805
osip_event_t *evt_answer;
806
osip_message_t *response;
809
osip_transaction_t *tr;
810
tr = eXosip_find_last_inc_invite(jc, jd);
812
if (tr==NULL || tr->orig_request==NULL)
814
OSIP_TRACE (osip_trace
815
(__FILE__, __LINE__, OSIP_ERROR, NULL,
816
"eXosip: cannot find transaction to answer\n"));
820
if (jd!=NULL && jd->d_dialog==NULL)
821
{ /* element previously removed */
822
OSIP_TRACE (osip_trace
823
(__FILE__, __LINE__, OSIP_ERROR, NULL,
824
"eXosip: cannot answer this closed transaction\n"));
828
/* is the transaction already answered? */
829
if (tr->state==IST_COMPLETED
830
|| tr->state==IST_CONFIRMED
831
|| tr->state==IST_TERMINATED)
833
OSIP_TRACE (osip_trace
834
(__FILE__, __LINE__, OSIP_ERROR, NULL,
835
"eXosip: transaction already answered\n"));
840
i = _eXosip_build_response_default(&response, NULL, code, tr->orig_request);
842
i = _eXosip_build_response_default(&response, jd->d_dialog, code, tr->orig_request);
846
OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL,"ERROR: Could not create response for invite\n"));
847
code = 500; /* ? which code to use? */
853
osip_message_set_content_length(response, "0");
854
/* TODO: send message to transaction layer */
855
evt_answer = osip_new_outgoing_sipmessage(response);
856
evt_answer->transactionid = tr->transactionid;
857
osip_transaction_add_event(tr, evt_answer);
862
i = osip_message_set_body(response, body, strlen(body));
866
size = (char *) osip_malloc(6*sizeof(char));
867
sprintf(size,"%i",strlen(body));
868
i = osip_message_set_content_length(response, size);
870
if (i!=0) goto g2atii_error_1;
871
i = osip_message_set_content_type(response, bodytype);
872
if (i!=0) goto g2atii_error_1;
874
/* request that estabish a dialog: */
875
/* 12.1.1 UAS Behavior */
877
i = complete_answer_that_establish_a_dialog(response, tr->orig_request);
878
if (i!=0) goto g2atii_error_1;; /* ?? */
880
/* THIS RESPONSE MUST BE SENT RELIABILY until the final ACK is received !! */
881
/* this response must be stored at the upper layer!!! (it will be destroyed*/
882
/* right after being sent! */
886
i = eXosip_dialog_init_as_uas(&jd, tr->orig_request, response);
889
OSIP_TRACE (osip_trace
890
(__FILE__, __LINE__, OSIP_ERROR, NULL,
891
"eXosip: cannot create dialog!\n"));
894
ADD_ELEMENT(jc->c_dialogs, jd);
897
eXosip_dialog_set_200ok(jd, response);
898
evt_answer = osip_new_outgoing_sipmessage(response);
899
evt_answer->transactionid = tr->transactionid;
901
osip_transaction_add_event(tr, evt_answer);
903
osip_dialog_set_state(jd->d_dialog, DIALOG_CONFIRMED);
908
osip_message_free(response);
913
eXosip_answer_invite_2xx(eXosip_call_t *jc, eXosip_dialog_t *jd, int code, char *local_sdp_port)
915
osip_event_t *evt_answer;
916
osip_message_t *response;
920
osip_transaction_t *tr;
921
tr = eXosip_find_last_inc_invite(jc, jd);
923
if (tr==NULL || tr->orig_request==NULL)
925
OSIP_TRACE (osip_trace
926
(__FILE__, __LINE__, OSIP_ERROR, NULL,
927
"eXosip: cannot find transaction to answer\n"));
931
if (jd!=NULL && jd->d_dialog==NULL)
932
{ /* element previously removed */
933
OSIP_TRACE (osip_trace
934
(__FILE__, __LINE__, OSIP_ERROR, NULL,
935
"eXosip: cannot answer this closed transaction\n"));
939
/* is the transaction already answered? */
940
if (tr->state==IST_COMPLETED
941
|| tr->state==IST_CONFIRMED
942
|| tr->state==IST_TERMINATED)
944
OSIP_TRACE (osip_trace
945
(__FILE__, __LINE__, OSIP_ERROR, NULL,
946
"eXosip: transaction already answered\n"));
950
/* WE SHOULD LOOK FOR A SDP PACKET!! */
951
if(NULL != osip_list_get(tr->orig_request->bodies,0))
953
body = generating_sdp_answer(tr->orig_request, jc->c_ctx);
955
code = 488; /* bad sdp */
959
if(local_sdp_port==NULL)
960
code = 488; /* session description in the request is not acceptable. */
962
/* body is NULL (contains no SDP), generate a response to INVITE w/ no SDP */
963
body = generating_no_sdp_answer(jc, jd, tr->orig_request, local_sdp_port);
967
i = _eXosip_build_response_default(&response, NULL, code, tr->orig_request);
969
i = _eXosip_build_response_default(&response, jd->d_dialog, code, tr->orig_request);
973
OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL,"ERROR: Could not create response for invite\n"));
974
code = 500; /* ? which code to use? */
975
osip_free(body); /* not used */
981
osip_message_set_content_length(response, "0");
982
/* TODO: send message to transaction layer */
984
evt_answer = osip_new_outgoing_sipmessage(response);
985
evt_answer->transactionid = tr->transactionid;
986
osip_transaction_add_event(tr, evt_answer);
991
i = osip_message_set_body(response, body, strlen(body));
995
size = (char *) osip_malloc(6*sizeof(char));
997
sprintf(size,"%li",strlen(body));
999
sprintf(size,"%i",strlen(body));
1001
i = osip_message_set_content_length(response, size);
1003
if (i!=0) goto g2atii_error_1;
1004
i = osip_message_set_content_type(response, "application/sdp");
1005
if (i!=0) goto g2atii_error_1;
1007
/* request that estabish a dialog: */
1008
/* 12.1.1 UAS Behavior */
1010
i = complete_answer_that_establish_a_dialog(response, tr->orig_request);
1011
if (i!=0) goto g2atii_error_1;; /* ?? */
1015
/* THIS RESPONSE MUST BE SENT RELIABILY until the final ACK is received !! */
1016
/* this response must be stored at the upper layer!!! (it will be destroyed*/
1017
/* right after being sent! */
1021
i = eXosip_dialog_init_as_uas(&jd, tr->orig_request, response);
1024
OSIP_TRACE (osip_trace
1025
(__FILE__, __LINE__, OSIP_ERROR, NULL,
1026
"eXosip: cannot create dialog!\n"));
1029
ADD_ELEMENT(jc->c_dialogs, jd);
1032
eXosip_dialog_set_200ok(jd, response);
1033
evt_answer = osip_new_outgoing_sipmessage(response);
1034
evt_answer->transactionid = tr->transactionid;
1036
osip_transaction_add_event(tr, evt_answer);
1038
osip_dialog_set_state(jd->d_dialog, DIALOG_CONFIRMED);
1044
osip_message_free(response);
1049
eXosip_answer_invite_3456xx(eXosip_call_t *jc, eXosip_dialog_t *jd, int code)
1051
osip_event_t *evt_answer;
1052
osip_message_t *response;
1054
osip_transaction_t *tr;
1055
tr = eXosip_find_last_inc_invite(jc, jd);
1058
OSIP_TRACE (osip_trace
1059
(__FILE__, __LINE__, OSIP_ERROR, NULL,
1060
"eXosip: cannot find transaction to answer"));
1063
/* is the transaction already answered? */
1064
if (tr->state==IST_COMPLETED
1065
|| tr->state==IST_CONFIRMED
1066
|| tr->state==IST_TERMINATED)
1068
OSIP_TRACE (osip_trace
1069
(__FILE__, __LINE__, OSIP_ERROR, NULL,
1070
"eXosip: transaction already answered\n"));
1074
i = _eXosip_build_response_default(&response, jd->d_dialog, code, tr->orig_request);
1077
OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL,"ERROR: Could not create response for invite\n"));
1083
/* Should add contact fields */
1085
osip_message_set_contact(response, jc->c_redirection);
1088
osip_message_set_content_length(response, "0");
1089
/* send message to transaction layer */
1091
evt_answer = osip_new_outgoing_sipmessage(response);
1092
evt_answer->transactionid = tr->transactionid;
1094
osip_transaction_add_event(tr, evt_answer);
1101
eXosip_notify_answer_subscribe_1xx(eXosip_notify_t *jn, eXosip_dialog_t *jd, int code)
1103
osip_event_t *evt_answer;
1104
osip_message_t *response;
1106
osip_transaction_t *tr;
1107
tr = eXosip_find_last_inc_subscribe(jn, jd);
1110
OSIP_TRACE (osip_trace
1111
(__FILE__, __LINE__, OSIP_ERROR, NULL,
1112
"eXosip: cannot find transaction to answer"));
1117
i = _eXosip_build_response_default(&response, NULL, code, tr->orig_request);
1119
i = _eXosip_build_response_default(&response, jd->d_dialog, code, tr->orig_request);
1123
OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_ERROR,NULL,"ERROR: Could not create response for subscribe\n"));
1129
/* request that estabish a dialog: */
1130
/* 12.1.1 UAS Behavior */
1131
i = complete_answer_that_establish_a_dialog(response, tr->orig_request);
1135
i = eXosip_dialog_init_as_uas(&jd, tr->orig_request, response);
1138
OSIP_TRACE (osip_trace
1139
(__FILE__, __LINE__, OSIP_ERROR, NULL,
1140
"eXosip: cannot create dialog!\n"));
1142
ADD_ELEMENT(jn->n_dialogs, jd);
1146
evt_answer = osip_new_outgoing_sipmessage(response);
1147
evt_answer->transactionid = tr->transactionid;
1149
osip_transaction_add_event(tr, evt_answer);
1155
eXosip_notify_answer_subscribe_2xx(eXosip_notify_t *jn, eXosip_dialog_t *jd, int code)
1157
osip_event_t *evt_answer;
1158
osip_message_t *response;
1160
osip_transaction_t *tr;
1161
tr = eXosip_find_last_inc_subscribe(jn, jd);
1163
if (tr==NULL || tr->orig_request==NULL)
1165
OSIP_TRACE (osip_trace
1166
(__FILE__, __LINE__, OSIP_ERROR, NULL,
1167
"eXosip: cannot find transaction to answer\n"));
1171
if (jd!=NULL && jd->d_dialog==NULL)
1172
{ /* element previously removed, this is a no hop! */
1173
OSIP_TRACE (osip_trace
1174
(__FILE__, __LINE__, OSIP_ERROR, NULL,
1175
"eXosip: cannot answer this closed transaction\n"));
1180
i = _eXosip_build_response_default(&response, NULL, code, tr->orig_request);
1182
i = _eXosip_build_response_default(&response, jd->d_dialog, code, tr->orig_request);
1186
OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL,"ERROR: Could not create response for subscribe\n"));
1187
code = 500; /* ? which code to use? */
1191
/* request that estabish a dialog: */
1192
/* 12.1.1 UAS Behavior */
1194
i = complete_answer_that_establish_a_dialog(response, tr->orig_request);
1195
if (i!=0) goto g2atii_error_1;; /* ?? */
1198
/* THIS RESPONSE MUST BE SENT RELIABILY until the final ACK is received !! */
1199
/* this response must be stored at the upper layer!!! (it will be destroyed*/
1200
/* right after being sent! */
1204
i = eXosip_dialog_init_as_uas(&jd, tr->orig_request, response);
1207
OSIP_TRACE (osip_trace
1208
(__FILE__, __LINE__, OSIP_ERROR, NULL,
1209
"eXosip: cannot create dialog!\n"));
1212
ADD_ELEMENT(jn->n_dialogs, jd);
1215
eXosip_dialog_set_200ok(jd, response);
1216
evt_answer = osip_new_outgoing_sipmessage(response);
1217
evt_answer->transactionid = tr->transactionid;
1219
osip_transaction_add_event(tr, evt_answer);
1222
osip_dialog_set_state(jd->d_dialog, DIALOG_CONFIRMED);
1226
osip_message_free(response);
1231
eXosip_notify_answer_subscribe_3456xx(eXosip_notify_t *jn, eXosip_dialog_t *jd, int code)
1233
osip_event_t *evt_answer;
1234
osip_message_t *response;
1236
osip_transaction_t *tr;
1237
tr = eXosip_find_last_inc_subscribe(jn, jd);
1240
OSIP_TRACE (osip_trace
1241
(__FILE__, __LINE__, OSIP_ERROR, NULL,
1242
"eXosip: cannot find transaction to answer"));
1245
i = _eXosip_build_response_default(&response, jd->d_dialog, code, tr->orig_request);
1248
OSIP_TRACE(osip_trace(__FILE__,__LINE__,OSIP_INFO1,NULL,"ERROR: Could not create response for subscribe\n"));
1254
/* Should add contact fields */
1258
evt_answer = osip_new_outgoing_sipmessage(response);
1259
evt_answer->transactionid = tr->transactionid;
1261
osip_transaction_add_event(tr, evt_answer);