void
osip_negotiation_free (osip_negotiation_t * config)
{
  if (config == NULL)
    return;
  osip_free (config->o_username);
  osip_free (config->o_session_id);
  osip_free (config->o_session_version);
  osip_free (config->o_nettype);
  osip_free (config->o_addrtype);
  osip_free (config->o_addr);

  osip_free (config->c_nettype);
  osip_free (config->c_addrtype);
  osip_free (config->c_addr);
  osip_free (config->c_addr_multicast_ttl);
  osip_free (config->c_addr_multicast_int);

  osip_list_special_free (config->audio_codec,
			  (void *(*)(void *)) &__payload_free);
  osip_list_special_free (config->video_codec,
			  (void *(*)(void *)) &__payload_free);
  osip_list_special_free (config->other_codec,
			  (void *(*)(void *)) &__payload_free);

  /* other are pointer to func, they don't need free() calls */

  /* yes, this is done here... :) */
  osip_free (config);
}
Esempio n. 2
0
int
osip_negotiation_remove_other_payloads (osip_negotiation_t *config)
{
  osip_list_special_free (config->other_codec, (void *(*)(void *)) &__payload_free);
  config->other_codec = (osip_list_t *) osip_malloc (sizeof (osip_list_t));
  osip_list_init (config->other_codec);
  return 0;
}
Esempio n. 3
0
void
sdp_media_free (sdp_media_t * media)
{
  if (media == NULL)
    return;
  osip_free (media->m_media);
  osip_free (media->m_port);
  osip_free (media->m_number_of_port);
  osip_free (media->m_proto);
  osip_list_ofchar_free (media->m_payloads);
  osip_free (media->i_info);
  osip_list_special_free (media->c_connections,
			  (void *(*)(void *)) &sdp_connection_free);
  osip_list_special_free (media->b_bandwidths,
			  (void *(*)(void *)) &sdp_bandwidth_free);
  osip_list_special_free (media->a_attributes,
			  (void *(*)(void *)) &sdp_attribute_free);
  sdp_key_free (media->k_key);
  osip_free (media);
}
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 OSIP_BADPARAMETER;
  if (response == NULL)
    return OSIP_BADPARAMETER;

  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 i;
  }

  if (dialog->state == DIALOG_EARLY && osip_list_size (&dialog->route_set) > 0) {
    osip_list_special_free (&dialog->route_set, (void (*)(void *)) &osip_record_route_free);
    osip_list_init (&dialog->route_set);
  }

  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 i;
      osip_list_add (&dialog->route_set, rr2, 0);
      pos++;
    }
  }

  if (MSG_IS_STATUS_2XX (response))
    dialog->state = DIALOG_CONFIRMED;
  return OSIP_SUCCESS;
}
Esempio n. 5
0
void
sdp_message_free (sdp_message_t * sdp)
{
  if (sdp == NULL)
    return;
  osip_free (sdp->v_version);
  osip_free (sdp->o_username);
  osip_free (sdp->o_sess_id);
  osip_free (sdp->o_sess_version);
  osip_free (sdp->o_nettype);
  osip_free (sdp->o_addrtype);
  osip_free (sdp->o_addr);
  osip_free (sdp->s_name);
  osip_free (sdp->i_info);
  osip_free (sdp->u_uri);

  osip_list_ofchar_free (sdp->e_emails);

  osip_list_ofchar_free (sdp->p_phones);

  sdp_connection_free (sdp->c_connection);

  osip_list_special_free (sdp->b_bandwidths,
			  (void *(*)(void *)) &sdp_bandwidth_free);

  osip_list_special_free (sdp->t_descrs,
			  (void *(*)(void *)) &sdp_time_descr_free);

  osip_free (sdp->z_adjustments);
  sdp_key_free (sdp->k_key);

  osip_list_special_free (sdp->a_attributes,
			  (void *(*)(void *)) &sdp_attribute_free);

  osip_list_special_free (sdp->m_medias, (void *(*)(void *)) &sdp_media_free);

  osip_free (sdp);
}
void
osip_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->line_param);
  osip_free (dialog->remote_tag);
  osip_free (dialog->local_tag);
  osip_free (dialog->call_id);
  osip_free (dialog);
}
Esempio n. 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;
}
Esempio n. 8
0
static int
_eXosip_register_build_register (eXosip_reg_t * jr, osip_message_t ** _reg)
{
    osip_message_t *reg = NULL;
    int i;

    reg = NULL;
    *_reg = NULL;

    if (jr->r_last_tr != NULL)
    {
        if (jr->r_last_tr->state != NICT_TERMINATED
                && jr->r_last_tr->state != NICT_COMPLETED)
            return -1;
        else
        {
            osip_message_t *last_response = NULL;
            osip_transaction_t *tr;

            osip_message_clone (jr->r_last_tr->orig_request, &reg);
            if (reg == NULL)
                return -1;
            /* reg = jr->r_last_tr->orig_request; */
            if (jr->r_last_tr->last_response != NULL)
            {
                osip_message_clone (jr->r_last_tr->last_response, &last_response);
                if (last_response == NULL)
                {
                    osip_message_free (reg);
                    return -1;
                }
            }

            __eXosip_delete_jinfo (jr->r_last_tr);
            tr = jr->r_last_tr;
            jr->r_last_tr = NULL;
            osip_list_add (eXosip.j_transactions, tr, 0);

            /* modify the REGISTER request */
            {
                int osip_cseq_num = osip_atoi (reg->cseq->number);
                int length = strlen (reg->cseq->number);


                osip_list_special_free(&reg->authorizations, (void *(*)(void *)) &osip_authorization_free);
                osip_list_special_free(&reg->proxy_authorizations, (void *(*)(void *)) &osip_proxy_authorization_free);


                if (-1 == eXosip_update_top_via (reg))
                {
                    osip_message_free (reg);
                    if (last_response != NULL)
                        osip_message_free (last_response);
                    return -1;
                }

                osip_cseq_num++;
                osip_free (reg->cseq->number);
                reg->cseq->number = (char *) osip_malloc (length + 2);      /* +2 like for 9 to 10 */
                sprintf (reg->cseq->number, "%i", osip_cseq_num);

                {
                    osip_header_t *exp;

                    osip_message_header_get_byname (reg, "expires", 0, &exp);
                    if (exp!=NULL)
                    {
                        if (exp->hvalue!=NULL)
                            osip_free (exp->hvalue);
                        exp->hvalue = (char *) osip_malloc (10);
                        snprintf (exp->hvalue, 9, "%i", jr->r_reg_period);
                    }
                }

                osip_message_force_update (reg);
            }

            if (last_response != NULL)
            {
                if (last_response->status_code==401 || last_response->status_code==407)
                {
                    eXosip_add_authentication_information (reg, last_response);
                }
                else
                    eXosip_add_authentication_information (reg, NULL);
                osip_message_free (last_response);
            }
        }
    }
    if (reg == NULL)
    {
        i = generating_register (jr, &reg, eXosip.transport,
                                 jr->r_aor, jr->r_registrar, jr->r_contact,
                                 jr->r_reg_period);
        if (i != 0)
        {
            return -2;
        }
    }

    *_reg = reg;
    return 0;
}
Esempio n. 9
0
static int
_eXosip_register_build_register(eXosip_reg_t * jr, osip_message_t ** _reg)
{
	osip_message_t *reg = NULL;
	int i;

	*_reg = NULL;

	if (jr == NULL)
		return OSIP_BADPARAMETER;

	if (jr->r_last_tr != NULL) {
		if (jr->r_last_tr->state != NICT_TERMINATED
			&& jr->r_last_tr->state != NICT_COMPLETED)
			return OSIP_WRONG_STATE;
		else {
			osip_message_t *last_response = NULL;
			osip_transaction_t *tr;

			i = osip_message_clone(jr->r_last_tr->orig_request, &reg);
			if (i != 0)
				return i;
			if (jr->r_last_tr->last_response != NULL) {
				i = osip_message_clone(jr->r_last_tr->last_response,
									   &last_response);
				if (i != 0) {
					osip_message_free(reg);
					return i;
				}
			}

			__eXosip_delete_jinfo(jr->r_last_tr);
			tr = jr->r_last_tr;
			jr->r_last_tr = NULL;
			osip_list_add(&eXosip.j_transactions, tr, 0);

			/* modify the REGISTER request */
			{
				int osip_cseq_num = osip_atoi(reg->cseq->number);
				int length = strlen(reg->cseq->number);


				osip_list_special_free(&reg->authorizations, (void (*)(void *))
									   &osip_authorization_free);
				osip_list_special_free(&reg->proxy_authorizations,
									   (void (*)(void *))
									   &osip_proxy_authorization_free);


				i = eXosip_update_top_via(reg);
				if (i != 0) {
					osip_message_free(reg);
					if (last_response != NULL)
						osip_message_free(last_response);
					return i;
				}

				osip_cseq_num++;
				osip_free(reg->cseq->number);
				reg->cseq->number = (char *) osip_malloc(length + 2);	/* +2 like for 9 to 10 */
				if (reg->cseq->number == NULL) {
					osip_message_free(reg);
					if (last_response != NULL)
						osip_message_free(last_response);
					return OSIP_NOMEM;
				}
				snprintf(reg->cseq->number, length + 2, "%i", osip_cseq_num);


				if (last_response != NULL && last_response->status_code == 423) {
					/* increase expires value to "min-expires" value */
					osip_header_t *exp;
					osip_header_t *min_exp;

					osip_message_header_get_byname(reg, "expires", 0, &exp);
					osip_message_header_get_byname(last_response, "min-expires", 0,
												   &min_exp);
					if (exp != NULL && exp->hvalue != NULL && min_exp != NULL
						&& min_exp->hvalue != NULL) {
						osip_free(exp->hvalue);
						exp->hvalue = osip_strdup(min_exp->hvalue);
						jr->r_reg_period = atoi(min_exp->hvalue);
					} else {
						osip_message_free(reg);
						if (last_response != NULL)
							osip_message_free(last_response);
						OSIP_TRACE(osip_trace
								   (__FILE__, __LINE__, OSIP_ERROR, NULL,
									"eXosip: missing Min-Expires or Expires in REGISTER\n"));
						return OSIP_SYNTAXERROR;
					}
				} else {
					osip_header_t *exp;

					osip_message_header_get_byname(reg, "expires", 0, &exp);
					if (exp != NULL) {
						if (exp->hvalue != NULL)
							osip_free(exp->hvalue);
						exp->hvalue = (char *) osip_malloc(10);
						if (exp->hvalue == NULL) {
							osip_message_free(reg);
							if (last_response != NULL)
								osip_message_free(last_response);
							return OSIP_NOMEM;
						}
						snprintf(exp->hvalue, 9, "%i", jr->r_reg_period);
					}
				}

				osip_message_force_update(reg);
			}

			if (last_response != NULL) {
				if (last_response->status_code == 401
					|| last_response->status_code == 407) {
					eXosip_add_authentication_information(reg, last_response);
				} else
					eXosip_add_authentication_information(reg, NULL);
				osip_message_free(last_response);
			}
		}
	}
	if (reg == NULL) {
		i = generating_register(jr, &reg, eXosip.transport,
								jr->r_aor, jr->r_registrar, jr->r_contact,
								jr->r_reg_period);
		if (i != 0)
			return i;
	}

	*_reg = reg;
	return OSIP_SUCCESS;
}
Esempio n. 10
0
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;
}
Esempio n. 11
0
int
_eXosip_subscribe_send_request_with_credential (struct eXosip_t *excontext, eXosip_subscribe_t * js, 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;
  int i;

  if (js == NULL)
    return OSIP_BADPARAMETER;
  if (jd != NULL) {
    if (jd->d_out_trs == NULL)
      return OSIP_BADPARAMETER;
  }

  if (out_tr == NULL) {
    out_tr = _eXosip_find_last_out_subscribe (js, jd);
  }

  if (out_tr == NULL || out_tr->orig_request == NULL || out_tr->last_response == NULL)
    return OSIP_NOTFOUND;

  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;
  }

  {
    osip_generic_param_t *tag = NULL;

    osip_to_get_tag (msg->to, &tag);
    if (NULL == tag && jd != NULL && jd->d_dialog != NULL && jd->d_dialog->remote_tag != NULL) {
      osip_to_set_tag (msg->to, osip_strdup (jd->d_dialog->remote_tag));
    }
  }

  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;
  }

  /* increment cseq */
  cseq = atoi (msg->cseq->number);
  osip_free (msg->cseq->number);
  msg->cseq->number = _eXosip_strdup_printf ("%i", cseq + 1);
  if (msg->cseq->number == NULL) {
    osip_message_free (msg);
    return OSIP_NOMEM;
  }

  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;
  }

  osip_list_special_free (&msg->authorizations, (void (*)(void *)) &osip_authorization_free);
  osip_list_special_free (&msg->proxy_authorizations, (void (*)(void *)) &osip_proxy_authorization_free);

  if (out_tr->last_response->status_code == 401 || out_tr->last_response->status_code == 407) {
    _eXosip_add_authentication_information (excontext, msg, out_tr->last_response);
  }
  else
    _eXosip_add_authentication_information (excontext, msg, NULL);


  if (out_tr != NULL && out_tr->last_response != NULL && out_tr->last_response->status_code == 423) {
    /* increase expires value to "min-expires" value */
    osip_header_t *exp;
    osip_header_t *min_exp;

    osip_message_header_get_byname (msg, "expires", 0, &exp);
    osip_message_header_get_byname (out_tr->last_response, "min-expires", 0, &min_exp);
    if (exp != NULL && exp->hvalue != NULL && min_exp != NULL && min_exp->hvalue != NULL) {
      osip_free (exp->hvalue);
      exp->hvalue = osip_strdup (min_exp->hvalue);
    }
    else {
      osip_message_free (msg);
      OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: missing Min-Expires or Expires in PUBLISH\n"));
      return OSIP_SYNTAXERROR;
    }
  }


  osip_message_force_update (msg);

  i = _eXosip_transaction_init (excontext, &tr, NICT, excontext->j_osip, msg);

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

  if (out_tr == js->s_out_tr) {
    /* replace with the new tr */
    osip_list_add (&excontext->j_transactions, js->s_out_tr, 0);
    js->s_out_tr = tr;
  }
  else {
    /* add the new tr for the current dialog */
    osip_list_add (jd->d_out_trs, tr, 0);
  }

  sipevent = osip_new_outgoing_sipmessage (msg);

  osip_transaction_set_reserved5 (tr, js);
  osip_transaction_set_reserved3 (tr, jd);

  osip_transaction_add_event (tr, sipevent);

  _eXosip_update (excontext);   /* fixed? */
  _eXosip_wakeup (excontext);
  return OSIP_SUCCESS;
}
Esempio n. 12
0
void
osip_message_free (osip_message_t * sip)
{
  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);

#ifndef MINISIZE
  osip_list_special_free (&sip->accepts, (void (*)(void *)) &osip_accept_free);
#endif
  osip_list_special_free (&sip->authorizations, (void (*)(void *)) &osip_authorization_free);
  if (sip->call_id != NULL)
    osip_call_id_free (sip->call_id);
#ifndef MINISIZE
  osip_list_special_free (&sip->accept_encodings, (void (*)(void *)) &osip_accept_encoding_free);
  osip_list_special_free (&sip->accept_languages, (void (*)(void *)) &osip_accept_language_free);
  osip_list_special_free (&sip->alert_infos, (void (*)(void *)) &osip_alert_info_free);
  osip_list_special_free (&sip->allows, (void (*)(void *)) &osip_allow_free);
  osip_list_special_free (&sip->authentication_infos, (void (*)(void *)) &osip_authentication_info_free);
  osip_list_special_free (&sip->content_encodings, (void (*)(void *)) &osip_content_encoding_free);
  osip_list_special_free (&sip->error_infos, (void (*)(void *)) &osip_error_info_free);
  osip_list_special_free (&sip->proxy_authentication_infos, (void (*)(void *))
                          &osip_proxy_authentication_info_free);
#endif
  osip_list_special_free (&sip->call_infos, (void (*)(void *)) &osip_call_info_free);
  osip_list_special_free (&sip->contacts, (void (*)(void *)) &osip_contact_free);
  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);
  if (sip->from != NULL)
    osip_from_free (sip->from);
  if (sip->mime_version != NULL)
    osip_mime_version_free (sip->mime_version);
  osip_list_special_free (&sip->proxy_authenticates, (void (*)(void *)) &osip_proxy_authenticate_free);
  osip_list_special_free (&sip->proxy_authorizations, (void (*)(void *)) &osip_proxy_authorization_free);
  osip_list_special_free (&sip->record_routes, (void (*)(void *)) &osip_record_route_free);
  osip_list_special_free (&sip->routes, (void (*)(void *)) &osip_route_free);
  if (sip->to != NULL)
    osip_to_free (sip->to);
  osip_list_special_free (&sip->vias, (void (*)(void *)) &osip_via_free);
  osip_list_special_free (&sip->www_authenticates, (void (*)(void *)) &osip_www_authenticate_free);
  osip_list_special_free (&sip->headers, (void (*)(void *)) &osip_header_free);
  osip_list_special_free (&sip->bodies, (void (*)(void *)) &osip_body_free);
  osip_free (sip->message);
  osip_free (sip);
}