Ejemplo n.º 1
0
int
eXosip_call_get_referto (int did, char *refer_to, size_t refer_to_len)
{
  eXosip_dialog_t *jd = NULL;
  eXosip_call_t *jc = NULL;
  osip_transaction_t *tr = NULL;
  osip_uri_t *referto_uri;
  char atmp[256];
  char *referto_tmp = NULL;
  int i;

  if (did <= 0)
    return OSIP_BADPARAMETER;

  eXosip_call_dialog_find (did, &jc, &jd);
  if (jc == NULL || jd == NULL || jd->d_dialog == NULL)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: No call here?\n"));
      return OSIP_NOTFOUND;
    }

  tr = eXosip_find_last_invite (jc, jd);

  if (tr == NULL || tr->orig_request == NULL)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: No transaction for call?\n"));
      return OSIP_NOTFOUND;
    }

  i = osip_uri_clone (jd->d_dialog->remote_uri->url, &referto_uri);
  if (i != 0)
    return i;

  snprintf (atmp, sizeof (atmp), "%s;to-tag=%s;from-tag=%s",
            jd->d_dialog->call_id,
            jd->d_dialog->remote_tag, jd->d_dialog->local_tag);

  osip_uri_uheader_add (referto_uri, osip_strdup ("Replaces"), osip_strdup (atmp));
  i = osip_uri_to_str (referto_uri, &referto_tmp);
  if (i != 0)
    {
      osip_uri_free (referto_uri);
      return i;
    }

  snprintf (refer_to, refer_to_len, "%s", referto_tmp);
  osip_uri_free (referto_uri);

  return OSIP_SUCCESS;
}
Ejemplo n.º 2
0
int
osip_uri_parse_headers (osip_uri_t * url, const char *headers)
{
  char *and;
  char *equal;

  /* find '=' wich is the separator for one header */
  /* find ';' wich is the separator for multiple headers */

  equal = strchr (headers, '=');
  and = strchr (headers + 1, '&');

  if (equal == NULL)            /* each header MUST have a value */
    return -1;

  do
    {
      char *hname;
      char *hvalue;

      hname = (char *) osip_malloc (equal - headers);
      if (hname == NULL)
        return -1;
      osip_strncpy (hname, headers + 1, equal - headers - 1);
      __osip_uri_unescape (hname);

      if (and != NULL)
        {
          if (and - equal < 2)
            {
              osip_free (hname);
              return -1;
            }
          hvalue = (char *) osip_malloc (and - equal);
          if (hvalue == NULL)
            {
              osip_free (hname);
              return -1;
            }
          osip_strncpy (hvalue, equal + 1, and - equal - 1);
          __osip_uri_unescape (hvalue);
      } else
        {                       /* this is for the last header (no and...) */
          if (headers + strlen (headers) - equal + 1 < 2)
            {
              osip_free (hname);
              return -1;
            }
          hvalue = (char *) osip_malloc (headers + strlen (headers) - equal + 1);
          if (hvalue == NULL)
            {
              osip_free (hname);
              return -1;
            }
          osip_strncpy (hvalue, equal + 1, headers + strlen (headers) - equal);
          __osip_uri_unescape (hvalue);
        }

      osip_uri_uheader_add (url, hname, hvalue);

      if (and == NULL)          /* we just set the last header */
        equal = NULL;
      else                      /* continue on next header */
        {
          headers = and;
          equal = strchr (headers, '=');
          and = strchr (headers + 1, '&');
          if (equal == NULL)    /* each header MUST have a value */
            return -1;
        }
    }
  while (equal != NULL);
  return 0;
}