📄 osip_dialog.c
字号:
From: remote_uri;remote_tag */ if (dlg->local_tag == NULL) /* NOT POSSIBLE BECAUSE I MANAGE REMOTE_TAG AND I ALWAYS ADD IT! */ return OSIP_SYNTAXERROR; i = osip_from_get_tag (request->from, &tag_param_remote); if (i != 0 && dlg->remote_tag != NULL) /* no tag in request but tag in dialog */ return OSIP_SYNTAXERROR; /* impossible... */ if (i != 0 && dlg->remote_tag == NULL) /* no tag in request AND no tag in dialog */ { if (0 == osip_from_compare ((osip_from_t *) dlg->remote_uri, (osip_from_t *) request->from) && 0 == osip_from_compare (dlg->local_uri, request->to)) return OSIP_SUCCESS; return OSIP_UNDEFINED_ERROR; } if (dlg->remote_tag == NULL) /* tag in response BUT no tag in dialog */ { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "Remote UA is not compliant: missing a tag in To feilds!\n")); if (0 == osip_from_compare ((osip_from_t *) dlg->remote_uri, (osip_from_t *) request->from) && 0 == osip_from_compare (dlg->local_uri, request->to)) return OSIP_SUCCESS; return OSIP_UNDEFINED_ERROR; } /* we don't have to compare remote_uri with from && local_uri with to. ----> we have both tag recognized, it's enough.. */ if (0 == strcmp (tag_param_remote->gvalue, dlg->remote_tag)) return OSIP_SUCCESS; return OSIP_UNDEFINED_ERROR;}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); 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;}intosip_dialog_init_as_uac (osip_dialog_t ** dialog, osip_message_t * response){ int i; i = __osip_dialog_init (dialog, NULL, response, response->from, response->to, response); if (i!=0) { *dialog = NULL; return i; } (*dialog)->type = CALLER; (*dialog)->remote_cseq = -1; return OSIP_SUCCESS;}/* SIPIT13 */intosip_dialog_init_as_uac_with_remote_request (osip_dialog_t ** dialog, osip_message_t * next_request, int local_cseq){ int i; *dialog = NULL; if (next_request->cseq==NULL) return OSIP_BADPARAMETER; i = __osip_dialog_init (dialog, next_request, next_request, next_request->to, next_request->from, next_request); if (i!=0) { *dialog = NULL; return i; } (*dialog)->type = CALLER; (*dialog)->state = DIALOG_CONFIRMED; (*dialog)->local_cseq = local_cseq; /* -1 osip_atoi (xxx->cseq->number); */ (*dialog)->remote_cseq = osip_atoi (next_request->cseq->number); return OSIP_SUCCESS;}intosip_dialog_init_as_uas (osip_dialog_t ** dialog, osip_message_t * invite, osip_message_t * response){ int i; *dialog = NULL; if (response->cseq==NULL) return OSIP_SYNTAXERROR; i = __osip_dialog_init (dialog, invite, response, response->to, response->from, invite); if (i!=0) { *dialog = NULL; return i; } (*dialog)->type = CALLEE; (*dialog)->remote_cseq = osip_atoi (response->cseq->number); return OSIP_SUCCESS;}voidosip_dialog_free (osip_dialog_t * dialog){ if (dialog == NULL) return; osip_contact_free (dialog->remote_contact_uri); osip_from_free (dialog->local_uri); osip_to_free (dialog->remote_uri); osip_list_special_free (&dialog->route_set, (void *(*)(void *)) &osip_record_route_free); osip_free (dialog->remote_tag); osip_free (dialog->local_tag); osip_free (dialog->call_id); osip_free (dialog);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -