Example #1
0
int
osip_dialog_match_as_uac (osip_dialog_t * dlg, osip_message_t * answer)
{
    osip_generic_param_t *tag_param_local;
    osip_generic_param_t *tag_param_remote;
    char *tmp;
    int i;

    osip_call_id_to_str (answer->call_id, &tmp);
    if (0 != strcmp (dlg->call_id, tmp))
    {
        osip_free (tmp);
        return -1;
    }
    osip_free (tmp);

    /* for INCOMING RESPONSE:
       To: remote_uri;remote_tag
       From: local_uri;local_tag           <- LOCAL TAG ALWAYS EXIST
     */
    i = osip_from_get_tag (answer->from, &tag_param_local);
    if (i != 0)
        return -1;
    if (dlg->local_tag == NULL)
        /* NOT POSSIBLE BECAUSE I MANAGE REMOTE_TAG AND I ALWAYS ADD IT! */
        return -1;
    if (0 != strcmp (tag_param_local->gvalue, dlg->local_tag))
        return -1;

    i = osip_to_get_tag (answer->to, &tag_param_remote);
    if (i != 0 && dlg->remote_tag != NULL)	/* no tag in response but tag in dialog */
        return -1;			/* impossible... */
    if (i != 0 && dlg->remote_tag == NULL)	/* no tag in response AND no tag in dialog */
    {
        if (0 ==
                osip_from_compare ((osip_from_t *) dlg->local_uri, (osip_from_t *) answer->from)
                && 0 == osip_from_compare (dlg->remote_uri, answer->to))
            return 0;
        return -1;
    }

    /* 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 0;
    return -1;
}
int
osip_dialog_match_as_uas (osip_dialog_t * dlg, osip_message_t * request)
{
  osip_generic_param_t *tag_param_remote;
  int i;
  char *tmp;

  if (dlg == NULL || dlg->call_id == NULL)
    return OSIP_BADPARAMETER;
  if (request == NULL || request->call_id == NULL || request->from == NULL || request->to == NULL)
    return OSIP_BADPARAMETER;

  osip_call_id_to_str (request->call_id, &tmp);
  if (0 != strcmp (dlg->call_id, tmp)) {
    osip_free (tmp);
    return OSIP_UNDEFINED_ERROR;
  }
  osip_free (tmp);

  /* for INCOMING REQUEST:
     To: local_uri;local_tag           <- LOCAL TAG ALWAYS EXIST
     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;

#if 0
  /* VR-2785: use line param to distinguish between two registrations by the same user */
  if (dlg->line_param) {
    osip_uri_param_t *line_param;

    i = osip_uri_param_get_byname (&request->req_uri->url_params, "line", &line_param);
    if (i == 0 && strcmp (dlg->line_param, line_param->gvalue))
      return OSIP_UNDEFINED_ERROR;      /* both dlg and req_uri have line params and they do not match */
  }
#endif

  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;
}
int
osip_dialog_match_as_uac (osip_dialog_t * dlg, osip_message_t * answer)
{
  osip_generic_param_t *tag_param_local;
  osip_generic_param_t *tag_param_remote;
  char *tmp;
  int i;

  if (dlg == NULL || dlg->call_id == NULL)
    return OSIP_BADPARAMETER;
  if (answer == NULL || answer->call_id == NULL || answer->from == NULL || answer->to == NULL)
    return OSIP_BADPARAMETER;

  OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "Using this method is discouraged. See source code explanations!\n"));
  /*
     When starting a new transaction and when receiving several answers,
     you must be prepared to receive several answers from different sources.
     (because of forking).

     Because some UAs are not compliant (a to tag is missing!), this method
     may match the wrong dialog when a dialog has been created with an empty
     tag in the To header.

     Personnaly, I would recommend to discard 1xx>=101 answers without To tags!
     Just my own feelings.
   */
  osip_call_id_to_str (answer->call_id, &tmp);
  if (0 != strcmp (dlg->call_id, tmp)) {
    osip_free (tmp);
    return OSIP_UNDEFINED_ERROR;
  }
  osip_free (tmp);

  /* for INCOMING RESPONSE:
     To: remote_uri;remote_tag
     From: local_uri;local_tag           <- LOCAL TAG ALWAYS EXIST
   */
  i = osip_from_get_tag (answer->from, &tag_param_local);
  if (i != 0)
    return OSIP_SYNTAXERROR;
  if (dlg->local_tag == NULL)
    /* NOT POSSIBLE BECAUSE I MANAGE REMOTE_TAG AND I ALWAYS ADD IT! */
    return OSIP_SYNTAXERROR;
  if (0 != strcmp (tag_param_local->gvalue, dlg->local_tag))
    return OSIP_UNDEFINED_ERROR;

  i = osip_to_get_tag (answer->to, &tag_param_remote);
  if (i != 0 && dlg->remote_tag != NULL)        /* no tag in response but tag in dialog */
    return OSIP_SYNTAXERROR;    /* impossible... */
  if (i != 0 && dlg->remote_tag == NULL) {      /* no tag in response AND no tag in dialog */
    if (0 == osip_from_compare ((osip_from_t *) dlg->local_uri, (osip_from_t *) answer->from)
        && 0 == osip_from_compare (dlg->remote_uri, answer->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 fields!\n"));
    if (0 == osip_from_compare ((osip_from_t *) dlg->local_uri, (osip_from_t *) answer->from)
        && 0 == osip_from_compare (dlg->remote_uri, answer->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;
}
Example #4
0
int
osip_dialog_match_as_uas (osip_dialog_t * dlg, osip_message_t * request)
{
  osip_generic_param_t *tag_param_remote;
  int i;
  char *tmp;

  if (dlg == NULL)
    return -1;
  if (request == NULL || request->call_id == NULL ||
      request->from == NULL || request->to == NULL)
    return -1;

  osip_call_id_to_str (request->call_id, &tmp);
  if (0 != strcmp (dlg->call_id, tmp))
    {
      osip_free (tmp);
      return -1;
    }
  osip_free (tmp);

  /* for INCOMING REQUEST:
     To: local_uri;local_tag           <- LOCAL TAG ALWAYS EXIST
     From: remote_uri;remote_tag
   */

  if (dlg->local_tag == NULL)
    /* NOT POSSIBLE BECAUSE I MANAGE REMOTE_TAG AND I ALWAYS ADD IT! */
    return -1;

  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 -1;                  /* 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 0;
      return -1;
    }

  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 0;
      return -1;
    }
  /* 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 0;

  return -1;
}