osip_dialog.c

来自「最新osip源代码」· C语言 代码 · 共 656 行 · 第 1/2 页

C
656
字号
  (*dialog)->your_instance = NULL;  (*dialog)->type = CALLER;  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)    goto diau_error_0;  i = osip_from_get_tag (response->from, &tag);  if (i != 0)    goto diau_error_1;  (*dialog)->local_tag = osip_strdup (tag->gvalue);  i = osip_to_get_tag (response->to, &tag);  if (i != 0)    {      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_WARNING, NULL,                   "Remote UA is not compliant: missing a tag in response!\n"));      (*dialog)->remote_tag = NULL;  } else    (*dialog)->remote_tag = osip_strdup (tag->gvalue);  (*dialog)->route_set = (osip_list_t *) osip_malloc (sizeof (osip_list_t));  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)        goto diau_error_2;#ifdef OSIP_FUTURE_FIX_2_3      osip_list_add ((*dialog)->route_set, rr2, 0);#else      osip_list_add ((*dialog)->route_set, rr2, -1);#endif      pos++;    }  (*dialog)->local_cseq = osip_atoi (response->cseq->number);  (*dialog)->remote_cseq = -1;  i = osip_to_clone (response->to, &((*dialog)->remote_uri));  if (i != 0)    goto diau_error_3;  i = osip_from_clone (response->from, &((*dialog)->local_uri));  if (i != 0)    goto diau_error_4;  {    osip_contact_t *contact;    if (!osip_list_eol (response->contacts, 0))      {        contact = osip_list_get (response->contacts, 0);        i = osip_contact_clone (contact, &((*dialog)->remote_contact_uri));        if (i != 0)          goto diau_error_5;    } else      {        (*dialog)->remote_contact_uri = NULL;        OSIP_TRACE (osip_trace                    (__FILE__, __LINE__, OSIP_WARNING, NULL,                     "Remote UA is not compliant: missing a contact in response!\n"));      }  }  (*dialog)->secure = -1;       /* non secure */  return 0;diau_error_5:  osip_from_free ((*dialog)->local_uri);diau_error_4:  osip_from_free ((*dialog)->remote_uri);diau_error_3:diau_error_2:  osip_list_special_free ((*dialog)->route_set,                          (void *(*)(void *)) &osip_record_route_free);  osip_free ((*dialog)->remote_tag);  osip_free ((*dialog)->local_tag);diau_error_1:  osip_free ((*dialog)->call_id);diau_error_0:  OSIP_TRACE (osip_trace              (__FILE__, __LINE__, OSIP_ERROR, NULL,               "Could not establish dialog!\n"));  osip_free (*dialog);  *dialog = NULL;  return -1;}#if 1                           /* SIPIT13 */intosip_dialog_init_as_uac_with_remote_request (osip_dialog_t ** dialog,                                             osip_message_t * next_request,                                             int local_cseq){  int i;  osip_generic_param_t *tag;  *dialog = NULL;  (*dialog) = (osip_dialog_t *) osip_malloc (sizeof (osip_dialog_t));  if (*dialog == NULL)    return -1;  memset (*dialog, 0, sizeof (osip_dialog_t));  (*dialog)->your_instance = NULL;  (*dialog)->type = CALLER;#if 0  (*dialog)->state = DIALOG_CONFIRMED;#endif  (*dialog)->state = DIALOG_EARLY;  i = osip_call_id_to_str (next_request->call_id, &((*dialog)->call_id));  if (i != 0)    goto diau_error_0;  i = osip_from_get_tag (next_request->to, &tag);  if (i != 0)    goto diau_error_1;  (*dialog)->local_tag = osip_strdup (tag->gvalue);  i = osip_to_get_tag (next_request->from, &tag);  if (i != 0)    {      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_WARNING, NULL,                   "Remote UA is not compliant: missing a tag in next request!\n"));      (*dialog)->remote_tag = NULL;  } else    (*dialog)->remote_tag = osip_strdup (tag->gvalue);  (*dialog)->route_set = (osip_list_t *) osip_malloc (sizeof (osip_list_t));  osip_list_init ((*dialog)->route_set);  (*dialog)->local_cseq = local_cseq;   /* -1 osip_atoi (xxx->cseq->number); */  (*dialog)->remote_cseq = osip_atoi (next_request->cseq->number);  i = osip_to_clone (next_request->from, &((*dialog)->remote_uri));  if (i != 0)    goto diau_error_3;  i = osip_from_clone (next_request->to, &((*dialog)->local_uri));  if (i != 0)    goto diau_error_4;  {    osip_contact_t *contact;    if (!osip_list_eol (next_request->contacts, 0))      {        contact = osip_list_get (next_request->contacts, 0);        i = osip_contact_clone (contact, &((*dialog)->remote_contact_uri));        if (i != 0)          goto diau_error_5;    } else      {        (*dialog)->remote_contact_uri = NULL;        OSIP_TRACE (osip_trace                    (__FILE__, __LINE__, OSIP_WARNING, NULL,                     "Remote UA is not compliant? missing a contact in response!\n"));      }  }  (*dialog)->secure = -1;       /* non secure */  return 0;diau_error_5:  osip_from_free ((*dialog)->local_uri);diau_error_4:  osip_from_free ((*dialog)->remote_uri);diau_error_3:  osip_free ((*dialog)->remote_tag);  osip_free ((*dialog)->local_tag);diau_error_1:  osip_free ((*dialog)->call_id);diau_error_0:  OSIP_TRACE (osip_trace              (__FILE__, __LINE__, OSIP_ERROR, NULL,               "Could not establish dialog!\n"));  osip_free (*dialog);  *dialog = NULL;  return -1;}#endifintosip_dialog_init_as_uas (osip_dialog_t ** dialog, osip_message_t * invite,                         osip_message_t * response){  int i;  int pos;  osip_generic_param_t *tag;  (*dialog) = (osip_dialog_t *) osip_malloc (sizeof (osip_dialog_t));  if (*dialog == NULL)    return -1;  memset (*dialog, 0, sizeof (osip_dialog_t));  (*dialog)->your_instance = NULL;  (*dialog)->type = CALLEE;  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)    goto diau_error_0;  i = osip_to_get_tag (response->to, &tag);  if (i != 0)    goto diau_error_1;  (*dialog)->local_tag = osip_strdup (tag->gvalue);  i = osip_from_get_tag (response->from, &tag);  if (i != 0)    {      OSIP_TRACE (osip_trace                  (__FILE__, __LINE__, OSIP_WARNING, NULL,                   "Remote UA is not compliant: missing a tag in response!\n"));      (*dialog)->remote_tag = NULL;  } else    (*dialog)->remote_tag = osip_strdup (tag->gvalue);  (*dialog)->route_set = (osip_list_t *) osip_malloc (sizeof (osip_list_t));  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)        goto diau_error_2;      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);  (*dialog)->remote_cseq = osip_atoi (response->cseq->number);  i = osip_from_clone (response->from, &((*dialog)->remote_uri));  if (i != 0)    goto diau_error_3;  i = osip_to_clone (response->to, &((*dialog)->local_uri));  if (i != 0)    goto diau_error_4;  {    osip_contact_t *contact;    if (!osip_list_eol (invite->contacts, 0))      {        contact = osip_list_get (invite->contacts, 0);        i = osip_contact_clone (contact, &((*dialog)->remote_contact_uri));        if (i != 0)          goto diau_error_5;    } else      {        (*dialog)->remote_contact_uri = NULL;        OSIP_TRACE (osip_trace                    (__FILE__, __LINE__, OSIP_WARNING, NULL,                     "Remote UA is not compliant: missing a contact in response!\n"));      }  }  (*dialog)->secure = -1;       /* non secure */  return 0;diau_error_5:  osip_from_free ((*dialog)->local_uri);diau_error_4:  osip_from_free ((*dialog)->remote_uri);diau_error_3:diau_error_2:  osip_list_special_free ((*dialog)->route_set,                          (void *(*)(void *)) &osip_record_route_free);  osip_free ((*dialog)->remote_tag);  osip_free ((*dialog)->local_tag);diau_error_1:  osip_free ((*dialog)->call_id);diau_error_0:  OSIP_TRACE (osip_trace              (__FILE__, __LINE__, OSIP_ERROR, NULL,               "Could not establish dialog!\n"));  osip_free (*dialog);  *dialog = NULL;  return -1;}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 + =
减小字号Ctrl + -
显示快捷键?