int _eXosip_dialog_init_as_uac (eXosip_dialog_t ** _jd, osip_message_t * _200Ok) { int i; eXosip_dialog_t *jd; *_jd = NULL; jd = (eXosip_dialog_t *) osip_malloc (sizeof (eXosip_dialog_t)); if (jd == NULL) return OSIP_NOMEM; memset (jd, 0, sizeof (eXosip_dialog_t)); jd->d_id = -1; /* not yet available to user */ if (MSG_IS_REQUEST (_200Ok)) { i = osip_dialog_init_as_uac_with_remote_request (&(jd->d_dialog), _200Ok, -1); } else { /* normal usage with response */ i = osip_dialog_init_as_uac (&(jd->d_dialog), _200Ok); } if (i != 0) { osip_free (jd); return i; } jd->d_count = 0; jd->d_session_timer_start = 0; jd->d_session_timer_length = 0; jd->d_refresher = -1; /* 0 -> me / 1 -> remote */ jd->d_timer = osip_getsystemtime (NULL); jd->d_200Ok = NULL; jd->d_ack = NULL; jd->next = NULL; jd->parent = NULL; jd->d_out_trs = (osip_list_t *) osip_malloc (sizeof (osip_list_t)); if (jd->d_out_trs == NULL) { osip_dialog_free (jd->d_dialog); osip_free (jd); return OSIP_NOMEM; } osip_list_init (jd->d_out_trs); jd->d_inc_trs = (osip_list_t *) osip_malloc (sizeof (osip_list_t)); if (jd->d_inc_trs == NULL) { osip_dialog_free (jd->d_dialog); osip_free (jd->d_out_trs); osip_free (jd); return OSIP_NOMEM; } osip_list_init (jd->d_inc_trs); *_jd = jd; return OSIP_SUCCESS; }
int _eXosip_dialog_init_as_uas (eXosip_dialog_t ** _jd, osip_message_t * _invite, osip_message_t * _200Ok) { int i; eXosip_dialog_t *jd; *_jd = NULL; jd = (eXosip_dialog_t *) osip_malloc (sizeof (eXosip_dialog_t)); if (jd == NULL) return OSIP_NOMEM; memset (jd, 0, sizeof (eXosip_dialog_t)); jd->d_id = -1; /* not yet available to user */ i = osip_dialog_init_as_uas (&(jd->d_dialog), _invite, _200Ok); if (i != 0) { osip_free (jd); return i; } jd->d_count = 0; jd->d_session_timer_start = 0; jd->d_session_timer_length = 0; jd->d_session_timer_use_update = -1; jd->d_refresher = -1; /* 0 -> me / 1 -> remote */ jd->d_timer = osip_getsystemtime (NULL); jd->d_200Ok = NULL; jd->d_ack = NULL; jd->next = NULL; jd->parent = NULL; jd->d_out_trs = (osip_list_t *) osip_malloc (sizeof (osip_list_t)); if (jd->d_out_trs == NULL) { osip_dialog_free (jd->d_dialog); osip_free (jd); return OSIP_NOMEM; } osip_list_init (jd->d_out_trs); jd->d_inc_trs = (osip_list_t *) osip_malloc (sizeof (osip_list_t)); if (jd->d_inc_trs == NULL) { osip_dialog_free (jd->d_dialog); osip_free (jd->d_out_trs); osip_free (jd); return OSIP_NOMEM; } osip_list_init (jd->d_inc_trs); jd->d_dialog->local_cseq = 1; *_jd = jd; return OSIP_SUCCESS; }
void eXosip_dialog_free (eXosip_dialog_t * jd) { while (!osip_list_eol (jd->d_inc_trs, 0)) { osip_transaction_t *tr; tr = (osip_transaction_t *) osip_list_get (jd->d_inc_trs, 0); osip_list_remove (jd->d_inc_trs, 0); __eXosip_delete_jinfo (tr); osip_list_add (eXosip.j_transactions, tr, 0); } while (!osip_list_eol (jd->d_out_trs, 0)) { osip_transaction_t *tr; tr = (osip_transaction_t *) osip_list_get (jd->d_out_trs, 0); osip_list_remove (jd->d_out_trs, 0); __eXosip_delete_jinfo (tr); osip_list_add (eXosip.j_transactions, tr, 0); } osip_message_free (jd->d_200Ok); osip_message_free (jd->d_ack); osip_dialog_free (jd->d_dialog); osip_free (jd->d_out_trs); osip_free (jd->d_inc_trs); osip_free (jd); eXosip_update (); }
void _eXosip_dialog_free (struct eXosip_t *excontext, eXosip_dialog_t * jd) { while (!osip_list_eol (jd->d_inc_trs, 0)) { osip_transaction_t *tr; tr = (osip_transaction_t *) osip_list_get (jd->d_inc_trs, 0); osip_list_remove (jd->d_inc_trs, 0); _eXosip_delete_reserved (tr); osip_list_add (&excontext->j_transactions, tr, 0); } while (!osip_list_eol (jd->d_out_trs, 0)) { osip_transaction_t *tr; tr = (osip_transaction_t *) osip_list_get (jd->d_out_trs, 0); osip_list_remove (jd->d_out_trs, 0); _eXosip_delete_reserved (tr); osip_list_add (&excontext->j_transactions, tr, 0); } osip_message_free (jd->d_200Ok); osip_message_free (jd->d_ack); osip_dialog_free (jd->d_dialog); osip_free (jd->d_out_trs); osip_free (jd->d_inc_trs); osip_free (jd); _eXosip_update (excontext); }
static int __osip_dialog_init (osip_dialog_t ** dialog, osip_message_t * invite, osip_message_t * response, osip_from_t * local, osip_to_t * remote, osip_message_t * remote_msg) { int i; int pos; osip_generic_param_t *tag; *dialog = NULL; if (response == NULL) return OSIP_BADPARAMETER; if (response->cseq == NULL || local == NULL || remote == NULL) return OSIP_SYNTAXERROR; (*dialog) = (osip_dialog_t *) osip_malloc (sizeof (osip_dialog_t)); if (*dialog == NULL) return OSIP_NOMEM; memset (*dialog, 0, sizeof (osip_dialog_t)); (*dialog)->your_instance = NULL; if (MSG_IS_STATUS_2XX (response)) (*dialog)->state = DIALOG_CONFIRMED; else /* 1XX */ (*dialog)->state = DIALOG_EARLY; i = osip_call_id_to_str (response->call_id, &((*dialog)->call_id)); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not establish dialog!\n")); osip_dialog_free (*dialog); *dialog = NULL; return i; } i = osip_to_get_tag (local, &tag); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not establish dialog!\n")); osip_dialog_free (*dialog); *dialog = NULL; return i; } (*dialog)->local_tag = osip_strdup (tag->gvalue); i = osip_from_get_tag (remote, &tag); if (i == 0) (*dialog)->remote_tag = osip_strdup (tag->gvalue); /* VR-2785: remember line value */ if (invite) { osip_uri_param_t *line_param; i = osip_uri_param_get_byname (&invite->req_uri->url_params, "line", &line_param); if (i == 0 && line_param != NULL && line_param->gvalue != NULL) (*dialog)->line_param = osip_strdup (line_param->gvalue); } osip_list_init (&(*dialog)->route_set); pos = 0; while (!osip_list_eol (&response->record_routes, pos)) { osip_record_route_t *rr; osip_record_route_t *rr2; rr = (osip_record_route_t *) osip_list_get (&response->record_routes, pos); i = osip_record_route_clone (rr, &rr2); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not establish dialog!\n")); osip_dialog_free (*dialog); *dialog = NULL; return i; } if (invite == NULL) osip_list_add (&(*dialog)->route_set, rr2, 0); else osip_list_add (&(*dialog)->route_set, rr2, -1); pos++; } /* local_cseq is set to response->cseq->number for better handling of bad UA */ (*dialog)->local_cseq = osip_atoi (response->cseq->number); i = osip_from_clone (remote, &((*dialog)->remote_uri)); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not establish dialog!\n")); osip_dialog_free (*dialog); *dialog = NULL; return i; } i = osip_to_clone (local, &((*dialog)->local_uri)); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not establish dialog!\n")); osip_dialog_free (*dialog); *dialog = NULL; return i; } { osip_contact_t *contact; if (!osip_list_eol (&remote_msg->contacts, 0)) { contact = osip_list_get (&remote_msg->contacts, 0); i = osip_contact_clone (contact, &((*dialog)->remote_contact_uri)); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "Could not establish dialog!\n")); osip_dialog_free (*dialog); *dialog = NULL; return i; } } else { (*dialog)->remote_contact_uri = NULL; OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "Remote UA is not compliant: missing a contact in remote message!\n")); } } (*dialog)->secure = -1; /* non secure */ return OSIP_SUCCESS; }
int eXosip_call_terminate (int cid, int did) { int i; osip_transaction_t *tr; osip_message_t *request = NULL; eXosip_dialog_t *jd = NULL; eXosip_call_t *jc = NULL; if (did <= 0 && cid <= 0) return OSIP_BADPARAMETER; if (did > 0) { eXosip_call_dialog_find (did, &jc, &jd); if (jd == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: No call here?\n")); return OSIP_NOTFOUND; } } else { eXosip_call_find (cid, &jc); } if (jc == NULL) { return OSIP_NOTFOUND; } tr = eXosip_find_last_out_invite (jc, jd); if (jd != NULL && jd->d_dialog != NULL && jd->d_dialog->state == DIALOG_CONFIRMED) { /* don't send CANCEL on re-INVITE: send BYE instead */ } else if (tr != NULL && tr->last_response != NULL && MSG_IS_STATUS_1XX (tr->last_response)) { i = generating_cancel (&request, tr->orig_request); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot terminate this call!\n")); return i; } i = eXosip_create_cancel_transaction (jc, jd, request); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot initiate SIP transaction!\n")); return i; } if (jd != NULL) { osip_dialog_free (jd->d_dialog); jd->d_dialog = NULL; eXosip_update (); /* AMD 30/09/05 */ } return OSIP_SUCCESS; } if (jd == NULL || jd->d_dialog == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: No established dialog!\n")); return OSIP_WRONG_STATE; } if (tr == NULL) { /*this may not be enough if it's a re-INVITE! */ tr = eXosip_find_last_inc_invite (jc, jd); if (tr != NULL && tr->last_response != NULL && MSG_IS_STATUS_1XX (tr->last_response)) { /* answer with 603 */ osip_generic_param_t *to_tag; osip_from_param_get_byname (tr->orig_request->to, "tag", &to_tag); i = eXosip_call_send_answer (tr->transactionid, 603, NULL); if (to_tag == NULL) return i; } } if (jd->d_dialog == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot terminate this call!\n")); return OSIP_WRONG_STATE; } i = generating_bye (&request, jd->d_dialog, eXosip.transport); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot terminate this call!\n")); return i; } eXosip_add_authentication_information (request, NULL); i = eXosip_create_transaction (jc, jd, request); if (i != 0) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: cannot initiate SIP transaction!\n")); return i; } osip_dialog_free (jd->d_dialog); jd->d_dialog = NULL; eXosip_update (); /* AMD 30/09/05 */ return OSIP_SUCCESS; }