Пример #1
0
/* returns -1 on error. */
int
osip_message_set_route (osip_message_t * sip, const char *hvalue)
{
  osip_route_t *route;
  int i;

  if (hvalue == NULL || hvalue[0] == '\0')
    return 0;

#ifdef __VXWORKS_OS__
  i = osip_route_init2 (&route);
#else
  i = osip_route_init (&route);
#endif
  if (i != 0)
    return -1;
  i = osip_route_parse (route, hvalue);
  if (i != 0)
    {
      osip_route_free (route);
      return -1;
    }
  sip->message_property = 2;
  osip_list_add (&sip->routes, route, -1);
  return 0;
}
Пример #2
0
void linphone_proxy_config_set_route(LinphoneProxyConfig *obj, const char *route)
{
	int err;
	osip_uri_param_t *lr_param=NULL;
	osip_route_t *rt=NULL;
	char *tmproute=NULL;
	if (route!=NULL && strlen(route)>0){
		osip_route_init(&rt);
		err=osip_route_parse(rt,route);
		if (err<0){
			ms_warning("Could not parse %s",route);
			osip_route_free(rt);
			return ;
		}
		if (obj->reg_route!=NULL) {
			ms_free(obj->reg_route);
			obj->reg_route=NULL;
		}
			
		/* check if the lr parameter is set , if not add it */
		osip_uri_uparam_get_byname(rt->url, "lr", &lr_param);
	  	if (lr_param==NULL){
			osip_uri_uparam_add(rt->url,osip_strdup("lr"),NULL);
			osip_route_to_str(rt,&tmproute);
			obj->reg_route=ms_strdup(tmproute);
			osip_free(tmproute);
		}else obj->reg_route=ms_strdup(route);
	}else{
		if (obj->reg_route!=NULL) ms_free(obj->reg_route);
		obj->reg_route=NULL;
	}
}
Пример #3
0
int
main (int argc, char **argv)
{
  FILE *routes_file;


  osip_route_t *route;
  char *a_route;
  char *dest;
  char *res;

  routes_file = fopen (argv[1], "r");
  if (routes_file == NULL)
    {
      fprintf (stdout, "Failed to open %s file.\nUsage: troute routes.txt\n",
               argv[1]);
      exit (0);
    }

  a_route = (char *) osip_malloc (200);
  res = fgets (a_route, 200, routes_file);      /* lines are under 200 */
  while (res != NULL)
    {

      int errcode;

      /* remove the last '\n' before parsing */
      strncpy (a_route + strlen (a_route) - 1, "\0", 1);

      if (0 != strncmp (a_route, "#", 1))
        {
          /* allocate & init route */
          osip_route_init (&route);
          printf ("=================================================\n");
          printf ("ROUTE TO PARSE: |%s|\n", a_route);
          errcode = osip_route_parse (route, a_route);
          if (errcode != -1)
            {
              if (osip_route_to_str (route, &dest) != -1)
                {
                  printf ("result:         |%s|\n", dest);
                  osip_free (dest);
                }
          } else
            printf ("Bad route format: %s\n", a_route);
          osip_route_free (route);
          printf ("=================================================\n");
        }
      res = fgets (a_route, 200, routes_file);  /* lines are under 200 */
    }
  osip_free (a_route);
  return 0;
}
Пример #4
0
/* Set loose route if not set in route url */
char* uas_check_route(const char *url)
{
	int err;
	osip_uri_param_t *lr_param=NULL;
	osip_route_t *rt=NULL;
	char *route=NULL;
   
	if (url!=NULL && strlen(url)>0)
   {
		osip_route_init(&rt);
		err=osip_route_parse(rt,url);
		if (err<0)
      {
			osip_route_free(rt);



			return NULL;
		}

      /* check if the lr parameter is set , if not add it */
		osip_uri_uparam_get_byname(rt->url, "lr", &lr_param);
	  	if (lr_param==NULL)
      {
			osip_uri_uparam_add(rt->url,osip_strdup("lr"),NULL);

			osip_route_to_str(rt,&route);
         
         return route;
		}

      return xstr_clone(url);
	}

   return NULL;
}
Пример #5
0
static int
dialog_fill_route_set (osip_dialog_t * dialog, osip_message_t * request)
{
  /* if the pre-existing route set contains a "lr" (compliance
     with bis-08) then the req_uri should contains the remote target
     URI */
  int i;
  int pos = 0;
  osip_uri_param_t *lr_param;
  osip_route_t *route;
  char *last_route;

  /* AMD bug: fixed 17/06/2002 */

  route = (osip_route_t *) osip_list_get (&dialog->route_set, 0);

  osip_uri_uparam_get_byname (route->url, "lr", &lr_param);
  if (lr_param != NULL)         /* the remote target URI is the req_uri! */
    {
      i = osip_uri_clone (dialog->remote_contact_uri->url, &(request->req_uri));
      if (i != 0)
        return i;
      /* "[request] MUST includes a Route header field containing
         the route set values in order." */
      /* AMD bug: fixed 17/06/2002 */
      pos = 0;                  /* first element is at index 0 */
      while (!osip_list_eol (&dialog->route_set, pos))
        {
          osip_route_t *route2;

          route = osip_list_get (&dialog->route_set, pos);
          i = osip_route_clone (route, &route2);
          if (i != 0)
            return i;
          osip_list_add (&request->routes, route2, -1);
          pos++;
        }
      return OSIP_SUCCESS;
    }

  /* if the first URI of route set does not contain "lr", the req_uri
     is set to the first uri of route set */


  i = osip_uri_clone (route->url, &(request->req_uri));
  if (i != 0)
    return i;
  /* add the route set */
  /* "The UAC MUST add a route header field containing
     the remainder of the route set values in order. */
  pos = 0;                      /* yes it is */

  while (!osip_list_eol (&dialog->route_set, pos))      /* not the first one in the list */
    {
      osip_route_t *route2;

      route = osip_list_get (&dialog->route_set, pos);
      i = osip_route_clone (route, &route2);
      if (i != 0)
        return i;
      if (!osip_list_eol (&dialog->route_set, pos + 1))
        osip_list_add (&request->routes, route2, -1);
      else
        osip_route_free (route2);
      pos++;
    }

  /* The UAC MUST then place the remote target URI into
     the route header field as the last value */
  i = osip_uri_to_str (dialog->remote_contact_uri->url, &last_route);
  if (i != 0)
    return i;
  i = osip_message_set_route (request, last_route);
  osip_free (last_route);
  if (i != 0)
    {
      return i;
    }

  /* route header and req_uri set */
  return OSIP_SUCCESS;
}
Пример #6
0
/* 
   method is the type of request. ("INVITE", "REGISTER"...)
   to is the remote target URI
   transport is either "TCP" or "UDP" (by now, only UDP is implemented!)
*/
int
generating_request_out_of_dialog (osip_message_t ** dest, const char *method,
                                  const char *to, const char *transport,
                                  const char *from, const char *proxy)
{
  /* Section 8.1:
     A valid request contains at a minimum "To, From, Call-iD, Cseq,
     Max-Forwards and Via
   */
  int i;
  osip_message_t *request;
  char locip[65];
  int doing_register;
  char *register_callid_number = NULL;

  *dest = NULL;

  if (eXosip.eXtl == NULL)
    return OSIP_NO_NETWORK;

  /*guess the local ip since req uri is known */
  memset (locip, '\0', sizeof (locip));
  eXosip_guess_ip_for_via (eXosip.eXtl->proto_family, locip, 49);
  if (locip[0] == '\0')
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: no default interface defined\n"));
      return OSIP_NO_NETWORK;
    }

  i = osip_message_init (&request);
  if (i != 0)
    return i;

  /* prepare the request-line */
  osip_message_set_method (request, osip_strdup (method));
  osip_message_set_version (request, osip_strdup ("SIP/2.0"));
  osip_message_set_status_code (request, 0);
  osip_message_set_reason_phrase (request, NULL);

  doing_register = 0 == strcmp ("REGISTER", method);

  if (doing_register)
    {
      osip_uri_init (&(request->req_uri));
      i = osip_uri_parse (request->req_uri, proxy);
      if (i != 0)
        {
          osip_message_free (request);
          return i;
        }
      i = osip_message_set_to (request, from);
      if (i != 0 || request->to == NULL)
        {
          if (i >= 0)
            i = OSIP_SYNTAXERROR;
          osip_message_free (request);
          return i;
        }
  } else
    {
      /* in any cases except REGISTER: */
      i = osip_message_set_to (request, to);
      if (i != 0 || request->to == NULL)
        {
          if (i >= 0)
            i = OSIP_SYNTAXERROR;
          OSIP_TRACE (osip_trace
                      (__FILE__, __LINE__, OSIP_ERROR, NULL,
                       "ERROR: callee address does not seems to be a sipurl: %s\n",
                       to));
          osip_message_free (request);
          return i;
        }

      /* REMOVE ALL URL PARAMETERS from to->url headers and add them as headers */
      if (request->to != NULL && request->to->url != NULL)
        {
          osip_uri_t *url = request->to->url;
          while (osip_list_size (&url->url_headers) > 0)
            {
              osip_uri_header_t *u_header;
              u_header = (osip_uri_param_t *) osip_list_get (&url->url_headers, 0);
              if (u_header == NULL)
                break;

              if (osip_strcasecmp (u_header->gname, "from") == 0)
                {
              } else if (osip_strcasecmp (u_header->gname, "to") == 0)
                {
              } else if (osip_strcasecmp (u_header->gname, "call-id") == 0)
                {
              } else if (osip_strcasecmp (u_header->gname, "cseq") == 0)
                {
              } else if (osip_strcasecmp (u_header->gname, "via") == 0)
                {
              } else if (osip_strcasecmp (u_header->gname, "contact") == 0)
                {
              } else
                osip_message_set_header (request, u_header->gname,
                                         u_header->gvalue);
              osip_list_remove (&url->url_headers, 0);
              osip_uri_param_free (u_header);
            }
        }

      if (proxy != NULL && proxy[0] != 0)
        {                       /* equal to a pre-existing route set */
          /* if the pre-existing route set contains a "lr" (compliance
             with bis-08) then the req_uri should contains the remote target
             URI */
          osip_uri_param_t *lr_param;
          osip_route_t *o_proxy;

          osip_route_init (&o_proxy);
          i = osip_route_parse (o_proxy, proxy);
          if (i != 0)
            {
              osip_route_free (o_proxy);
              osip_message_free (request);
              return i;
            }

          osip_uri_uparam_get_byname (o_proxy->url, "lr", &lr_param);
          if (lr_param != NULL) /* to is the remote target URI in this case! */
            {
              osip_uri_clone (request->to->url, &(request->req_uri));
              /* "[request] MUST includes a Route header field containing
                 the route set values in order." */
              osip_list_add (&request->routes, o_proxy, 0);
          } else
            /* if the first URI of route set does not contain "lr", the req_uri
               is set to the first uri of route set */
            {
              request->req_uri = o_proxy->url;
              o_proxy->url = NULL;
              osip_route_free (o_proxy);
              /* add the route set */
              /* "The UAC MUST add a route header field containing
                 the remainder of the route set values in order.
                 The UAC MUST then place the remote target URI into
                 the route header field as the last value
               */
              osip_message_set_route (request, to);
            }
      } else                    /* No route set (outbound proxy) is used */
        {
          /* The UAC must put the remote target URI (to field) in the req_uri */
          i = osip_uri_clone (request->to->url, &(request->req_uri));
          if (i != 0)
            {
              osip_message_free (request);
              return i;
            }
        }
    }

  /* set To and From */
  i = osip_message_set_from (request, from);
  if (i != 0 || request->from == NULL)
    {
      if (i >= 0)
        i = OSIP_SYNTAXERROR;
      osip_message_free (request);
      return i;
    }

  /* add a tag */
  osip_from_set_tag (request->from, osip_from_tag_new_random ());

  /* set the cseq and call_id header */
  {
    osip_call_id_t *callid;
    osip_cseq_t *cseq;
    char *num;
    char *cidrand;

    /* call-id is always the same for REGISTRATIONS */
    i = osip_call_id_init (&callid);
    if (i != 0)
      {
        osip_message_free (request);
        return i;
      }
    cidrand = osip_call_id_new_random ();
    osip_call_id_set_number (callid, cidrand);
    if (doing_register)
      register_callid_number = cidrand;

    request->call_id = callid;

    i = osip_cseq_init (&cseq);
    if (i != 0)
      {
        osip_message_free (request);
        return i;
      }
    num = osip_strdup (doing_register ? "1" : "20");
    osip_cseq_set_number (cseq, num);
    osip_cseq_set_method (cseq, osip_strdup (method));
    request->cseq = cseq;

    if (cseq->method == NULL || cseq->number == NULL)
      {
        osip_message_free (request);
        return OSIP_NOMEM;
      }
  }

  i = _eXosip_request_add_via (request, transport, locip);
  if (i != 0)
    {
      osip_message_free (request);
      return i;
    }

  /* always add the Max-Forward header */
  osip_message_set_max_forwards (request, "70");        /* a UA should start a request with 70 */

  if (0 == strcmp ("REGISTER", method))
    {
  } else if (0 == strcmp ("INFO", method))
    {
  } else if (0 == strcmp ("OPTIONS", method))
    {
      osip_message_set_accept (request, "application/sdp");
    }

  osip_message_set_user_agent (request, eXosip.user_agent);
  /*  else if ... */
  *dest = request;
  return OSIP_SUCCESS;
}
Пример #7
0
int
_eXosip_call_retry_request (eXosip_call_t * jc,
                            eXosip_dialog_t * jd, osip_transaction_t * out_tr)
{
  osip_transaction_t *tr = NULL;
  osip_message_t *msg = NULL;
  osip_event_t *sipevent;

  int cseq;
  osip_via_t *via;
  osip_contact_t *co;
  int pos;
  int i;
  int protocol = IPPROTO_UDP;

  if (jc == NULL)
    return OSIP_BADPARAMETER;
  if (jd != NULL)
    {
      if (jd->d_out_trs == NULL)
        return OSIP_BADPARAMETER;
    }
  if (out_tr == NULL
      || out_tr->orig_request == NULL || out_tr->last_response == NULL)
    return OSIP_BADPARAMETER;

  i = osip_message_clone (out_tr->orig_request, &msg);
  if (i != 0)
    {
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: could not clone msg for authentication\n"));
      return i;
    }

  via = (osip_via_t *) osip_list_get (&msg->vias, 0);
  if (via == NULL || msg->cseq == NULL || msg->cseq->number == NULL)
    {
      osip_message_free (msg);
      OSIP_TRACE (osip_trace
                  (__FILE__, __LINE__, OSIP_ERROR, NULL,
                   "eXosip: missing via or cseq header\n"));
      return OSIP_SYNTAXERROR;
    }

  if (MSG_IS_STATUS_3XX (out_tr->last_response))
    {
      co = NULL;
      pos = 0;
      while (!osip_list_eol (&out_tr->last_response->contacts, pos))
        {
          co =
            (osip_contact_t *) osip_list_get (&out_tr->last_response->contacts,
                                              pos);
          if (co != NULL && co->url != NULL)
            {
              /* check tranport? Only allow UDP, right now */
              osip_uri_param_t *u_param;
              int pos2;

              u_param = NULL;
              pos2 = 0;
              while (!osip_list_eol (&co->url->url_params, pos2))
                {
                  u_param =
                    (osip_uri_param_t *) osip_list_get (&co->url->url_params,
                                                        pos2);
                  if (u_param == NULL || u_param->gname == NULL
                      || u_param->gvalue == NULL)
                    {
                      u_param = NULL;
                      /* skip */
                  } else if (0 == osip_strcasecmp (u_param->gname, "transport"))
                    {
                      if (0 == osip_strcasecmp (u_param->gvalue, "udp"))
                        {
                          u_param = NULL;
                          protocol = IPPROTO_UDP;
                          break;        /* ok */
                      } else if (0 == osip_strcasecmp (u_param->gvalue, "tcp"))
                        {
                          protocol = IPPROTO_TCP;
                          u_param = NULL;
                        }
                      break;
                    }
                  pos2++;
                }

              if (u_param == NULL || u_param->gname == NULL
                  || u_param->gvalue == NULL)
                {
                  break;        /* default is udp! */
                }
            }
          pos++;
          co = NULL;
        }

      if (co == NULL || co->url == NULL)
        {
          osip_message_free (msg);
          OSIP_TRACE (osip_trace
                      (__FILE__, __LINE__, OSIP_ERROR, NULL,
                       "eXosip: contact header\n"));
          return OSIP_SYNTAXERROR;
        }

      /* TODO:
         remove extra parameter from new request-uri
         check usual parameter like "transport"
       */

      if (msg->req_uri != NULL && msg->req_uri->host != NULL
          && co->url->host != NULL
          && 0 == osip_strcasecmp (co->url->host, msg->req_uri->host))
        {
          osip_uri_param_t *maddr_param = NULL;
          osip_uri_uparam_get_byname (co->url, "maddr", &maddr_param);
          if (maddr_param != NULL && maddr_param->gvalue != NULL)
            {
              /* This is a redirect server, the route should probably be removed? */
              osip_route_t *route = NULL;
              osip_generic_param_t *tag = NULL;
              osip_message_get_route (msg, 0, &route);
              if (route != NULL)
                {
                  osip_to_get_tag (msg->to, &tag);
                  if (tag == NULL && route != NULL && route->url != NULL)
                    {
                      osip_list_remove (&msg->routes, 0);
                      osip_route_free (route);
                    }
                }
            }
        }

      /* replace request-uri with NEW contact address */
      osip_uri_free (msg->req_uri);
      msg->req_uri = NULL;
      osip_uri_clone (co->url, &msg->req_uri);

      /* support for diversions headers/draft! */
      {
        int count = 0;
        pos = 0;
        while (!osip_list_eol (&out_tr->last_response->headers, pos))
          {
            osip_header_t *copy = NULL;
            osip_header_t *head =
              osip_list_get (&out_tr->last_response->headers, pos);
            if (head != NULL && 0 == osip_strcasecmp (head->hname, "diversion"))
              {
                i = osip_header_clone (head, &copy);
                if (i == 0)
                  {
                    osip_list_add (&msg->headers, copy, count);
                    count++;
                  }
              }
            pos++;
          }
      }

    }
  /* remove all previous authentication headers */
  osip_list_special_free (&msg->authorizations,
                          (void *(*)(void *)) &osip_authorization_free);
  osip_list_special_free (&msg->proxy_authorizations,
                          (void *(*)(void *)) &osip_proxy_authorization_free);

  /* increment cseq */
  cseq = atoi (msg->cseq->number);
  osip_free (msg->cseq->number);
  msg->cseq->number = strdup_printf ("%i", cseq + 1);
  if (jd != NULL && jd->d_dialog != NULL)
    {
      jd->d_dialog->local_cseq++;
    }

  i = eXosip_update_top_via (msg);
  if (i != 0)
    {
      osip_message_free (msg);
      return i;
    }

  if (out_tr->last_response->status_code == 401
      || out_tr->last_response->status_code == 407)
    eXosip_add_authentication_information (msg, out_tr->last_response);
  else
    eXosip_add_authentication_information (msg, NULL);
  osip_message_force_update (msg);

  if (0 != osip_strcasecmp (msg->sip_method, "INVITE"))
    {
      i = _eXosip_transaction_init (&tr, NICT, eXosip.j_osip, msg);
  } else
    {
      i = _eXosip_transaction_init (&tr, ICT, eXosip.j_osip, msg);
    }

  if (i != 0)
    {
      osip_message_free (msg);
      return i;
    }

  if (out_tr == jc->c_out_tr)
    {
      /* replace with the new tr */
      osip_list_add (&eXosip.j_transactions, jc->c_out_tr, 0);
      jc->c_out_tr = tr;

      /* fix dialog issue */
      if (jd != NULL)
        {
          REMOVE_ELEMENT (jc->c_dialogs, jd);
          eXosip_dialog_free (jd);
          jd = NULL;
        }
  } else
    {
      /* add the new tr for the current dialog */
      osip_list_add (jd->d_out_trs, tr, 0);
    }

  sipevent = osip_new_outgoing_sipmessage (msg);

#ifndef MINISIZE
  osip_transaction_set_your_instance (tr, __eXosip_new_jinfo (jc, jd, NULL, NULL));
#else
  osip_transaction_set_your_instance (tr, __eXosip_new_jinfo (jc, jd));
#endif
  osip_transaction_add_event (tr, sipevent);

  eXosip_update ();             /* fixed? */
  __eXosip_wakeup ();
  return OSIP_SUCCESS;
}
Пример #8
0
void
osip_message_free (osip_message_t * sip)
{
    int pos = 0;

    if (sip == NULL)
        return;

    osip_free (sip->sip_method);
    osip_free (sip->sip_version);
    if (sip->req_uri != NULL)
    {
        osip_uri_free (sip->req_uri);
    }
    osip_free (sip->reason_phrase);

    {
        osip_accept_t *accept;

        while (!osip_list_eol (&sip->accepts, pos))
        {
            accept = (osip_accept_t *) osip_list_get (&sip->accepts, pos);
            osip_list_remove (&sip->accepts, pos);
            osip_accept_free (accept);
        }
    }
    {
        osip_accept_encoding_t *accept_encoding;

        while (!osip_list_eol (&sip->accept_encodings, pos))
        {
            accept_encoding =
                (osip_accept_encoding_t *) osip_list_get (&sip->accept_encodings, pos);
            osip_list_remove (&sip->accept_encodings, pos);
            osip_accept_encoding_free (accept_encoding);
        }
    }
    {
        osip_accept_language_t *accept_language;

        while (!osip_list_eol (&sip->accept_languages, pos))
        {
            accept_language =
                (osip_accept_language_t *) osip_list_get (&sip->accept_languages, pos);
            osip_list_remove (&sip->accept_languages, pos);
            osip_accept_language_free (accept_language);
        }
    }
    {
        osip_alert_info_t *alert_info;

        while (!osip_list_eol (&sip->alert_infos, pos))
        {
            alert_info = (osip_alert_info_t *) osip_list_get (&sip->alert_infos, pos);
            osip_list_remove (&sip->alert_infos, pos);
            osip_alert_info_free (alert_info);
        }
    }
    {
        osip_allow_t *al;

        while (!osip_list_eol (&sip->allows, pos))
        {
            al = (osip_allow_t *) osip_list_get (&sip->allows, pos);
            osip_list_remove (&sip->allows, pos);
            osip_allow_free (al);
        }
    }
    {
        osip_authentication_info_t *al;

        while (!osip_list_eol (&sip->authentication_infos, pos))
        {
            al =
                (osip_authentication_info_t *) osip_list_get (&sip->
                        authentication_infos, pos);
            osip_list_remove (&sip->authentication_infos, pos);
            osip_authentication_info_free (al);
        }
    }
    {
        osip_authorization_t *al;

        while (!osip_list_eol (&sip->authorizations, pos))
        {
            al = (osip_authorization_t *) osip_list_get (&sip->authorizations, pos);
            osip_list_remove (&sip->authorizations, pos);
            osip_authorization_free (al);
        }
    }
    if (sip->call_id != NULL)
    {
        osip_call_id_free (sip->call_id);
    }
    {
        osip_call_info_t *call_info;

        while (!osip_list_eol (&sip->call_infos, pos))
        {
            call_info = (osip_call_info_t *) osip_list_get (&sip->call_infos, pos);
            osip_list_remove (&sip->call_infos, pos);
            osip_call_info_free (call_info);
        }
    }
    {
        osip_contact_t *contact;

        while (!osip_list_eol (&sip->contacts, pos))
        {
            contact = (osip_contact_t *) osip_list_get (&sip->contacts, pos);
            osip_list_remove (&sip->contacts, pos);
            osip_contact_free (contact);
        }
    }
    {
        osip_content_encoding_t *ce;

        while (!osip_list_eol (&sip->content_encodings, pos))
        {
            ce =
                (osip_content_encoding_t *) osip_list_get (&sip->content_encodings, pos);
            osip_list_remove (&sip->content_encodings, pos);
            osip_content_encoding_free (ce);
        }
    }
    if (sip->content_length != NULL)
    {
        osip_content_length_free (sip->content_length);
    }
    if (sip->content_type != NULL)
    {
        osip_content_type_free (sip->content_type);
    }
    if (sip->cseq != NULL)
    {
        osip_cseq_free (sip->cseq);
    }
    {
        osip_error_info_t *error_info;

        while (!osip_list_eol (&sip->error_infos, pos))
        {
            error_info = (osip_error_info_t *) osip_list_get (&sip->error_infos, pos);
            osip_list_remove (&sip->error_infos, pos);
            osip_error_info_free (error_info);
        }
    }
    if (sip->from != NULL)
    {
        osip_from_free (sip->from);
    }
    if (sip->mime_version != NULL)
    {
        osip_mime_version_free (sip->mime_version);
    }
    {
        osip_proxy_authenticate_t *al;

        while (!osip_list_eol (&sip->proxy_authenticates, pos))
        {
            al =
                (osip_proxy_authenticate_t *) osip_list_get (&sip->
                        proxy_authenticates, pos);
            osip_list_remove (&sip->proxy_authenticates, pos);
            osip_proxy_authenticate_free (al);
        }
    }
    {
        osip_proxy_authentication_info_t *al;

        while (!osip_list_eol (&sip->proxy_authentication_infos, pos))
        {
            al =
                (osip_proxy_authentication_info_t *) osip_list_get (&sip->
                        proxy_authentication_infos,
                        pos);
            osip_list_remove (&sip->proxy_authentication_infos, pos);
            osip_proxy_authentication_info_free (al);
        }
    }
    {
        osip_proxy_authorization_t *proxy_authorization;

        while (!osip_list_eol (&sip->proxy_authorizations, pos))
        {
            proxy_authorization =
                (osip_proxy_authorization_t *) osip_list_get (&sip->
                        proxy_authorizations, pos);
            osip_list_remove (&sip->proxy_authorizations, pos);
            osip_proxy_authorization_free (proxy_authorization);
        }
    }
    {
        osip_record_route_t *record_route;

        while (!osip_list_eol (&sip->record_routes, pos))
        {
            record_route =
                (osip_record_route_t *) osip_list_get (&sip->record_routes, pos);
            osip_list_remove (&sip->record_routes, pos);
            osip_record_route_free (record_route);
        }
    }
    {
        osip_route_t *route;

        while (!osip_list_eol (&sip->routes, pos))
        {
            route = (osip_route_t *) osip_list_get (&sip->routes, pos);
            osip_list_remove (&sip->routes, pos);
            osip_route_free (route);
        }
    }
    if (sip->to != NULL)
    {
        osip_to_free (sip->to);
    }
    {
        osip_via_t *via;

        while (!osip_list_eol (&sip->vias, pos))
        {
            via = (osip_via_t *) osip_list_get (&sip->vias, pos);
            osip_list_remove (&sip->vias, pos);
            osip_via_free (via);
        }
    }
    {
        osip_www_authenticate_t *al;

        while (!osip_list_eol (&sip->www_authenticates, pos))
        {
            al =
                (osip_www_authenticate_t *) osip_list_get (&sip->www_authenticates, pos);
            osip_list_remove (&sip->www_authenticates, pos);
            osip_www_authenticate_free (al);
        }
    }

    {
        osip_header_t *header;

        while (!osip_list_eol (&sip->headers, pos))
        {
            header = (osip_header_t *) osip_list_get (&sip->headers, pos);
            osip_list_remove (&sip->headers, pos);
            osip_header_free (header);
        }
    }

    {
        osip_body_t *body;

        while (!osip_list_eol (&sip->bodies, pos))
        {
            body = (osip_body_t *) osip_list_get (&sip->bodies, pos);
            osip_list_remove (&sip->bodies, pos);
            osip_body_free (body);
        }
    }
    osip_free (sip->message);
    osip_free (sip);
}