コード例 #1
0
ファイル: osip_dialog.c プロジェクト: gabrieldelsaint/UIM
int
osip_dialog_update_route_set_as_uac (osip_dialog_t * dialog,
                                     osip_message_t * response)
{
  /* only the remote target URI is updated here... */
  osip_contact_t *contact;
  int i;

  if (dialog == NULL)
    return -1;
  if (response == NULL)
    return -1;

  if (osip_list_eol (&response->contacts, 0))
    {                           /* no contact header in response? */
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_WARNING, NULL,
                   "missing a contact in response!\n"));
  } else
    {
      /* I personally think it's a bad idea to keep the old
         value in case the new one is broken... */
      if (dialog->remote_contact_uri != NULL)
        {
          osip_contact_free (dialog->remote_contact_uri);
        }
      dialog->remote_contact_uri = NULL;
      contact = osip_list_get (&response->contacts, 0);
      i = osip_contact_clone (contact, &(dialog->remote_contact_uri));
      if (i != 0)
        return -1;
    }

  if (dialog->state == DIALOG_EARLY && osip_list_size (&dialog->route_set) == 0)
    {                           /* update the route set */
      int 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)
            return -1;
          osip_list_add (&dialog->route_set, rr2, 0);
          pos++;
        }
    }

  if (MSG_IS_STATUS_2XX (response))
    dialog->state = DIALOG_CONFIRMED;
  return 0;
}
コード例 #2
0
int
complete_answer_that_establish_a_dialog2(osip_message_t *response, osip_message_t *request, char *ctct)
{
	int pos=0;
	char contact[1000];
	/* 12.1.1:
	copy all record-route in response
	add a contact with global scope
	*/
	while (!osip_list_eol(&request->record_routes, pos))
	{
		osip_record_route_t *rr;
		osip_record_route_t *rr2;
		rr = osip_list_get(&request->record_routes, pos);
		if (osip_record_route_clone(rr, &rr2))
		{
			return -1;
		}
		osip_list_add(&response->record_routes, rr2, -1);
		pos++;
	}

	if (ctct && ctct[0])
	{
		snprintf (contact, sizeof (contact), "%s", ctct) ;
	}
	else
	{
		if
		(
			owsip_account_contact_get
			(
				owsip_account_get_from_received_request (request),
				contact,
				sizeof (contact)
			) == NULL
		)
		{
			return -1 ;
		}
	}

	osip_message_set_contact(response, contact);

	return 0;
}
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;
}
コード例 #4
0
int
complete_answer_that_establish_a_dialog (osip_message_t * response,
                                         osip_message_t * request)
{
  int i;
  int pos = 0;
  char contact[1000];
  char locip[50];
  struct eXosip_net *net;

  /* 12.1.1:
     copy all record-route in response
     add a contact with global scope
   */
  while (!osip_list_eol (request->record_routes, pos))
    {
      osip_record_route_t *rr;
      osip_record_route_t *rr2;

      rr = osip_list_get (request->record_routes, pos);
      i = osip_record_route_clone (rr, &rr2);
      if (i != 0)
        return -1;
      osip_list_add (response->record_routes, rr2, -1);
      pos++;
    }

  i = _eXosip_find_protocol (response);
  if (i == IPPROTO_UDP)
    {
      net = &eXosip.net_interfaces[0];
  } else if (i == IPPROTO_TCP)
    {
      net = &eXosip.net_interfaces[1];
  } else
    {
      net = &eXosip.net_interfaces[0];
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: unsupported protocol (default to UDP)\n"));
      return -1;
    }

#ifdef SM
  eXosip_get_localip_from_via (response, locip, 49);
#else
  eXosip_guess_ip_for_via (net->net_ip_family, locip, 49);
#endif

  if (request->to->url->username == NULL)
    snprintf (contact, 1000, "<sip:%s:%s>", locip, net->net_port);
  else
    snprintf (contact, 1000, "<sip:%s@%s:%s>", request->to->url->username,
              locip, net->net_port);

  if (eXosip.net_interfaces[0].net_firewall_ip[0] != '\0')
    {
      osip_contact_t *con =
        (osip_contact_t *) osip_list_get (request->contacts, 0);
      if (con != NULL && con->url != NULL && con->url->host != NULL)
        {
          char *c_address = con->url->host;

          struct addrinfo *addrinfo;
          struct __eXosip_sockaddr addr;

          i = eXosip_get_addrinfo (&addrinfo, con->url->host, 5060, IPPROTO_UDP);
          if (i == 0)
            {
              memcpy (&addr, addrinfo->ai_addr, addrinfo->ai_addrlen);
              freeaddrinfo (addrinfo);
              c_address = inet_ntoa (((struct sockaddr_in *) &addr)->sin_addr);
              OSIP_TRACE (osip_trace
                          (__FILE__, __LINE__, OSIP_INFO1, NULL,
                           "eXosip: here is the resolved destination host=%s\n",
                           c_address));
            }

          /* If c_address is a PUBLIC address, the request was
             coming from the PUBLIC network. */
          if (eXosip_is_public_address (c_address))
            {
              if (request->to->url->username == NULL)
                snprintf (contact, 1000, "<sip:%s:%s>",
                          eXosip.net_interfaces[0].net_firewall_ip, net->net_port);
              else
                snprintf (contact, 1000, "<sip:%s@%s:%s>",
                          request->to->url->username,
                          eXosip.net_interfaces[0].net_firewall_ip, net->net_port);
            }
        }
    }

  osip_message_set_contact (response, contact);

  return 0;
}
コード例 #5
0
ファイル: osip_dialog.c プロジェクト: smx-smx/dsl-n55u
int
osip_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;

    (*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;
}
コード例 #6
0
ファイル: jresponse.c プロジェクト: Christof0113/rtsp-tools
int
_eXosip_complete_answer_that_establish_a_dialog (struct eXosip_t *excontext, osip_message_t * response, osip_message_t * request)
{
  int i;
  int route_found = 0;
  char contact[1024];
  char scheme[10];
  osip_list_iterator_t it;
  osip_record_route_t *rr;

  snprintf(scheme, sizeof(scheme), "sip");

  /* 12.1.1:
     copy all record-route in response
     add a contact with global scope
   */
  rr = (osip_record_route_t *)osip_list_get_first(&request->record_routes, &it);
  while (rr != NULL) {
    osip_record_route_t *rr2;

    i = osip_record_route_clone (rr, &rr2);
    if (i != 0)
      return i;
    osip_list_add (&response->record_routes, rr2, -1);

    /* rfc3261: 12.1.1 UAS behavior (check sips in top most Record-Route) */
    if (it.pos==0 && rr2!=NULL && rr2->url!=NULL && rr2->url->scheme!=NULL && osip_strcasecmp(rr2->url->scheme, "sips")==0)
      snprintf(scheme, sizeof(scheme), "sips");

    rr = (osip_record_route_t *)osip_list_get_next(&it);
    route_found=1;
  }

  if (MSG_IS_BYE (request)) {
    return OSIP_SUCCESS;
  }

  if (route_found==0) {
    /* rfc3261: 12.1.1 UAS behavior (check sips in Contact if no Record-Route) */
    osip_contact_t *co = (osip_contact_t *) osip_list_get(&request->contacts, 0);
    if (co!=NULL && co->url!=NULL && co->url->scheme!=NULL && osip_strcasecmp(co->url->scheme, "sips")==0)
      snprintf(scheme, sizeof(scheme), "sips");
  }
  /* rfc3261: 12.1.1 UAS behavior (check sips in Request-URI) */
  if (request->req_uri->scheme!=NULL && osip_strcasecmp(request->req_uri->scheme, "sips")==0)
    snprintf(scheme, sizeof(scheme), "sips");

  /* special values to be replaced in transport layer (eXtl_*.c files) */
  if (request->to->url->username == NULL)
    snprintf (contact, 1000, "<%s:999.999.999.999:99999>", scheme);
  else {
    char *tmp2 = __osip_uri_escape_userinfo (request->to->url->username);

    snprintf (contact, 1000, "<%s:%[email protected]:99999>", scheme, tmp2);
    osip_free (tmp2);
  }

  {
    osip_via_t *via;

    via = (osip_via_t *) osip_list_get (&response->vias, 0);
    if (via == NULL || via->protocol == NULL)
      return OSIP_SYNTAXERROR;
    if (excontext->enable_outbound==1) {
      contact[strlen (contact) - 1] = '\0';
      strcat (contact, ";ob");
      strcat (contact, ">");
    }
    if (strlen (contact) + strlen (via->protocol) + strlen (";transport=>") < 1024 && 0 != osip_strcasecmp (via->protocol, "UDP")) {
      contact[strlen (contact) - 1] = '\0';
      strcat (contact, ";transport=");
      strcat (contact, via->protocol);
      strcat (contact, ">");
    }
    if (excontext->sip_instance[0] != 0 && strlen (contact) + 64 < 1024) {
      strcat(contact, ";+sip.instance=\"<urn:uuid:");
      strcat(contact, excontext->sip_instance);
      strcat(contact, ">\"");
    }
  }

  osip_message_set_contact (response, contact);

  if (excontext->default_contact_displayname[0]!='\0') {
    osip_contact_t *new_contact;
    osip_message_get_contact(response, 0, &new_contact);
    if (new_contact!=NULL) {
      new_contact->displayname = osip_strdup (excontext->default_contact_displayname);
    }
  }

  if (excontext->eXtl_transport._tl_update_contact!=NULL)
    excontext->eXtl_transport._tl_update_contact(excontext, response);
  return OSIP_SUCCESS;
}
コード例 #7
0
ファイル: jresponse.c プロジェクト: HunterChen/exosip
int
_eXosip_complete_answer_that_establish_a_dialog (struct eXosip_t *excontext, osip_message_t * response, osip_message_t * request)
{
  int i;
  int pos = 0;
  char contact[1024];
  char locip[65];
  char firewall_ip[65];
  char firewall_port[10];

  firewall_ip[0] = '\0';
  firewall_port[0] = '\0';
  if (excontext->eXtl->tl_get_masquerade_contact != NULL) {
    excontext->eXtl->tl_get_masquerade_contact (excontext, firewall_ip, sizeof (firewall_ip), firewall_port, sizeof (firewall_port));
  }

  /* 12.1.1:
     copy all record-route in response
     add a contact with global scope
   */
  while (!osip_list_eol (&request->record_routes, pos)) {
    osip_record_route_t *rr;
    osip_record_route_t *rr2;

    rr = osip_list_get (&request->record_routes, pos);
    i = osip_record_route_clone (rr, &rr2);
    if (i != 0)
      return i;
    osip_list_add (&response->record_routes, rr2, -1);
    pos++;
  }

  memset (locip, '\0', sizeof (locip));
  _eXosip_guess_ip_for_via (excontext, excontext->eXtl->proto_family, locip, 49);

  if (request->to->url->username == NULL)
    snprintf (contact, 1000, "<sip:%s:%s>", locip, firewall_port);
  else {
    char *tmp2 = __osip_uri_escape_userinfo (request->to->url->username);

    snprintf (contact, 1000, "<sip:%s@%s:%s>", tmp2, locip, firewall_port);
    osip_free (tmp2);
  }
  if (firewall_ip[0] != '\0') {
#ifdef USE_LOCALIP_WITH_LOCALPROXY      /* disable this code for local testing because it adds an extra DNS */
    osip_contact_t *con = (osip_contact_t *) osip_list_get (&request->contacts, 0);

    if (con != NULL && con->url != NULL && con->url->host != NULL) {
      char *c_address = con->url->host;

      struct addrinfo *addrinfo;
      struct __eXosip_sockaddr addr;

      i = _eXosip_get_addrinfo (excontext, &addrinfo, con->url->host, 5060, IPPROTO_UDP);
      if (i == 0) {
        memcpy (&addr, addrinfo->ai_addr, addrinfo->ai_addrlen);
        _eXosip_freeaddrinfo (addrinfo);
        c_address = inet_ntoa (((struct sockaddr_in *) &addr)->sin_addr);
        OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL, "eXosip: here is the resolved destination host=%s\n", c_address));
      }

      /* If c_address is a PUBLIC address, the request was
         coming from the PUBLIC network. */
      if (_eXosip_is_public_address (c_address)) {
        if (request->to->url->username == NULL)
          snprintf (contact, 1000, "<sip:%s:%s>", firewall_ip, firewall_port);
        else {
          char *tmp2 = __osip_uri_escape_userinfo (request->to->url->username);

          snprintf (contact, 1000, "<sip:%s@%s:%s>", tmp2, firewall_ip, firewall_port);
          osip_free (tmp2);
        }
      }
    }
#else
    if (request->to->url->username == NULL)
      snprintf (contact, 1000, "<sip:%s:%s>", firewall_ip, firewall_port);
    else {
      char *tmp2 = __osip_uri_escape_userinfo (request->to->url->username);

      snprintf (contact, 1000, "<sip:%s@%s:%s>", tmp2, firewall_ip, firewall_port);
      osip_free (tmp2);
    }
#endif
  }

  {
    osip_via_t *via;

    via = (osip_via_t *) osip_list_get (&response->vias, 0);
    if (via == NULL || via->protocol == NULL)
      return OSIP_SYNTAXERROR;
    if (strlen (contact) + strlen (via->protocol) + strlen (";transport=>") < 1024 && 0 != osip_strcasecmp (via->protocol, "UDP")) {
      contact[strlen (contact) - 1] = '\0';
      strcat (contact, ";transport=");
      strcat (contact, via->protocol);
      strcat (contact, ">");
    }
  }

  osip_message_set_contact (response, contact);

  return OSIP_SUCCESS;
}
コード例 #8
0
int
osip_message_clone (const osip_message_t * sip, osip_message_t ** dest)
{
    osip_message_t *copy;
    int pos = 0;
    int i;

    if (sip == NULL)
        return -1;
    *dest = NULL;

    i = osip_message_init (&copy);
    if (i != 0)
        return -1;

    copy->sip_method = osip_strdup (sip->sip_method);
    copy->sip_version = osip_strdup (sip->sip_version);
    copy->status_code = sip->status_code;
    copy->reason_phrase = osip_strdup (sip->reason_phrase);
    if (sip->req_uri != NULL)
    {
        i = osip_uri_clone (sip->req_uri, &(copy->req_uri));
        if (i != 0)
            goto mc_error1;
    }

    {
        osip_accept_t *accept;
        osip_accept_t *accept2;

        pos = 0;
        while (!osip_list_eol (&sip->accepts, pos))
        {
            accept = (osip_accept_t *) osip_list_get (&sip->accepts, pos);
            i = osip_accept_clone (accept, &accept2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->accepts, accept2, -1);     /* insert as last element */
            pos++;
        }
    }
    {
        osip_accept_encoding_t *accept_encoding;
        osip_accept_encoding_t *accept_encoding2;

        pos = 0;
        while (!osip_list_eol (&sip->accept_encodings, pos))
        {
            accept_encoding =
                (osip_accept_encoding_t *) osip_list_get (&sip->accept_encodings, pos);
            i = osip_accept_encoding_clone (accept_encoding, &accept_encoding2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->accept_encodings, accept_encoding2, -1);
            pos++;
        }
    }
    {
        osip_accept_language_t *accept_language;
        osip_accept_language_t *accept_language2;

        pos = 0;
        while (!osip_list_eol (&sip->accept_languages, pos))
        {
            accept_language =
                (osip_accept_language_t *) osip_list_get (&sip->accept_languages, pos);
            i = osip_accept_language_clone (accept_language, &accept_language2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->accept_languages, accept_language2, -1);
            pos++;
        }
    }
    {
        osip_alert_info_t *alert_info;
        osip_alert_info_t *alert_info2;

        pos = 0;
        while (!osip_list_eol (&sip->alert_infos, pos))
        {
            alert_info = (osip_alert_info_t *) osip_list_get (&sip->alert_infos, pos);
            i = osip_alert_info_clone (alert_info, &alert_info2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->alert_infos, alert_info2, -1);
            pos++;
        }
    }
    {
        osip_allow_t *allow;
        osip_allow_t *allow2;

        pos = 0;
        while (!osip_list_eol (&sip->allows, pos))
        {
            allow = (osip_allow_t *) osip_list_get (&sip->allows, pos);
            i = osip_allow_clone (allow, &allow2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->allows, allow2, -1);
            pos++;
        }
    }
    {
        osip_authentication_info_t *authentication_info;
        osip_authentication_info_t *authentication_info2;

        pos = 0;
        while (!osip_list_eol (&sip->authentication_infos, pos))
        {
            authentication_info =
                (osip_authentication_info_t *) osip_list_get (&sip->
                        authentication_infos, pos);
            i =
                osip_authentication_info_clone (authentication_info,
                                                &authentication_info2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->authentication_infos, authentication_info2, -1);
            pos++;
        }
    }
    {
        osip_authorization_t *authorization;
        osip_authorization_t *authorization2;

        pos = 0;
        while (!osip_list_eol (&sip->authorizations, pos))
        {
            authorization =
                (osip_authorization_t *) osip_list_get (&sip->authorizations, pos);
            i = osip_authorization_clone (authorization, &authorization2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->authorizations, authorization2, -1);
            pos++;
        }
    }
    if (sip->call_id != NULL)
    {
        i = osip_call_id_clone (sip->call_id, &(copy->call_id));
        if (i != 0)
            goto mc_error1;
    }
    {
        osip_call_info_t *call_info;
        osip_call_info_t *call_info2;

        pos = 0;
        while (!osip_list_eol (&sip->call_infos, pos))
        {
            call_info = (osip_call_info_t *) osip_list_get (&sip->call_infos, pos);
            i = osip_call_info_clone (call_info, &call_info2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->call_infos, call_info2, -1);
            pos++;
        }
    }
    {
        osip_contact_t *contact;
        osip_contact_t *contact2;

        pos = 0;
        while (!osip_list_eol (&sip->contacts, pos))
        {
            contact = (osip_contact_t *) osip_list_get (&sip->contacts, pos);
            i = osip_contact_clone (contact, &contact2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->contacts, contact2, -1);
            pos++;
        }
    }
    {
        osip_content_encoding_t *content_encoding;
        osip_content_encoding_t *content_encoding2;

        pos = 0;
        while (!osip_list_eol (&sip->content_encodings, pos))
        {
            content_encoding =
                (osip_content_encoding_t *) osip_list_get (&sip->content_encodings, pos);
            i = osip_content_encoding_clone (content_encoding, &content_encoding2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->content_encodings, content_encoding2, -1);
            pos++;
        }
    }
    if (sip->content_length != NULL)
    {
        i = osip_content_length_clone (sip->content_length, &(copy->content_length));
        if (i != 0)
            goto mc_error1;
    }
    if (sip->content_type != NULL)
    {
        i = osip_content_type_clone (sip->content_type, &(copy->content_type));
        if (i != 0)
            goto mc_error1;
    }
    if (sip->cseq != NULL)
    {
        i = osip_cseq_clone (sip->cseq, &(copy->cseq));
        if (i != 0)
            goto mc_error1;
    }
    {
        osip_error_info_t *error_info;
        osip_error_info_t *error_info2;

        pos = 0;
        while (!osip_list_eol (&sip->error_infos, pos))
        {
            error_info = (osip_error_info_t *) osip_list_get (&sip->error_infos, pos);
            i = osip_error_info_clone (error_info, &error_info2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->error_infos, error_info2, -1);
            pos++;
        }
    }
    if (sip->from != NULL)
    {
        i = osip_from_clone (sip->from, &(copy->from));
        if (i != 0)
            goto mc_error1;
    }
    if (sip->mime_version != NULL)
    {
        i = osip_mime_version_clone (sip->mime_version, &(copy->mime_version));
        if (i != 0)
            goto mc_error1;
    }
    {
        osip_proxy_authenticate_t *proxy_authenticate;
        osip_proxy_authenticate_t *proxy_authenticate2;

        pos = 0;
        while (!osip_list_eol (&sip->proxy_authenticates, pos))
        {
            proxy_authenticate =
                (osip_proxy_authenticate_t *) osip_list_get (&sip->
                        proxy_authenticates, pos);
            i =
                osip_proxy_authenticate_clone (proxy_authenticate, &proxy_authenticate2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->proxy_authenticates, proxy_authenticate2, -1);
            pos++;
        }
    }
    {
        osip_proxy_authentication_info_t *proxy_authentication_info;
        osip_proxy_authentication_info_t *proxy_authentication_info2;

        pos = 0;
        while (!osip_list_eol (&sip->proxy_authentication_infos, pos))
        {
            proxy_authentication_info =
                (osip_proxy_authentication_info_t *) osip_list_get (&sip->
                        proxy_authentication_infos,
                        pos);
            i =
                osip_proxy_authentication_info_clone (proxy_authentication_info,
                        &proxy_authentication_info2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->proxy_authentication_infos,
                           proxy_authentication_info2, -1);
            pos++;
        }
    }
    {
        osip_proxy_authorization_t *proxy_authorization;
        osip_proxy_authorization_t *proxy_authorization2;

        pos = 0;
        while (!osip_list_eol (&sip->proxy_authorizations, pos))
        {
            proxy_authorization =
                (osip_proxy_authorization_t *) osip_list_get (&sip->
                        proxy_authorizations, pos);
            i =
                osip_proxy_authorization_clone (proxy_authorization,
                                                &proxy_authorization2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->proxy_authorizations, proxy_authorization2, -1);
            pos++;
        }
    }
    {
        osip_record_route_t *record_route;
        osip_record_route_t *record_route2;

        pos = 0;
        while (!osip_list_eol (&sip->record_routes, pos))
        {
            record_route =
                (osip_record_route_t *) osip_list_get (&sip->record_routes, pos);
            i = osip_record_route_clone (record_route, &record_route2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->record_routes, record_route2, -1);
            pos++;
        }
    }
    {
        osip_route_t *route;
        osip_route_t *route2;

        pos = 0;
        while (!osip_list_eol (&sip->routes, pos))
        {
            route = (osip_route_t *) osip_list_get (&sip->routes, pos);
            i = osip_route_clone (route, &route2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->routes, route2, -1);
            pos++;
        }
    }
    if (sip->to != NULL)
    {
        i = osip_to_clone (sip->to, &(copy->to));
        if (i != 0)
            goto mc_error1;
    }
    {
        osip_via_t *via;
        osip_via_t *via2;

        pos = 0;
        while (!osip_list_eol (&sip->vias, pos))
        {
            via = (osip_via_t *) osip_list_get (&sip->vias, pos);
            i = osip_via_clone (via, &via2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->vias, via2, -1);
            pos++;
        }
    }
    {
        osip_www_authenticate_t *www_authenticate;
        osip_www_authenticate_t *www_authenticate2;

        pos = 0;
        while (!osip_list_eol (&sip->www_authenticates, pos))
        {
            www_authenticate =
                (osip_www_authenticate_t *) osip_list_get (&sip->www_authenticates, pos);
            i = osip_www_authenticate_clone (www_authenticate, &www_authenticate2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->www_authenticates, www_authenticate2, -1);
            pos++;
        }
    }

    {
        osip_header_t *header;
        osip_header_t *header2;

        pos = 0;
        while (!osip_list_eol (&sip->headers, pos))
        {
            header = (osip_header_t *) osip_list_get (&sip->headers, pos);
            i = osip_header_clone (header, &header2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->headers, header2, -1);
            pos++;
        }
    }

    {
        osip_body_t *body;
        osip_body_t *body2;

        pos = 0;
        while (!osip_list_eol (&sip->bodies, pos))
        {
            body = (osip_body_t *) osip_list_get (&sip->bodies, pos);
            i = osip_body_clone (body, &body2);
            if (i != 0)
                goto mc_error1;
            osip_list_add (&copy->bodies, body2, -1);
            pos++;
        }
    }

    copy->message_length = sip->message_length;
    copy->message = osip_strdup (sip->message);
    copy->message_property = sip->message_property;

    *dest = copy;
    return 0;
mc_error1:
    osip_message_free (copy);
    return -1;

}