/* returns null on error. */
int
osip_content_type_to_str (const osip_content_type_t * content_type,
			  char **dest)
{
  char *buf;
  char *tmp;
  size_t len;

  *dest = NULL;
  if ((content_type == NULL) || (content_type->type == NULL)
      || (content_type->subtype == NULL))
    return -1;

  /* try to guess a long enough length */
  len = strlen (content_type->type) + strlen (content_type->subtype) + 4	/* for '/', ' ', ';' and '\0' */
    + 10 * osip_list_size (content_type->gen_params);

  buf = (char *) osip_malloc (len);
  tmp = buf;

  sprintf (tmp, "%s/%s", content_type->type, content_type->subtype);

  tmp = tmp + strlen (tmp);
  {
    int pos = 0;
    osip_generic_param_t *u_param;

    if (!osip_list_eol (content_type->gen_params, pos))
      {				/* needed for cannonical form! (authentication issue of rfc2543) */
	sprintf (tmp, " ");
	tmp++;
      }
    while (!osip_list_eol (content_type->gen_params, pos))
      {
	size_t tmp_len;

	u_param =
	  (osip_generic_param_t *) osip_list_get (content_type->gen_params,
						  pos);
	if (u_param->gvalue == NULL)
	  {
	    osip_free (buf);
	    return -1;
	  }
	tmp_len = strlen (buf) + 4 + strlen (u_param->gname)
	  + strlen (u_param->gvalue);
	if (len < tmp_len)
	  {
	    buf = osip_realloc (buf, tmp_len);
	    len = tmp_len;
	    tmp = buf + strlen (buf);
	  }
	sprintf (tmp, ";%s=%s", u_param->gname, u_param->gvalue);
	tmp = tmp + strlen (tmp);
	pos++;
      }
  }
  *dest = buf;
  return 0;
}
Пример #2
0
void
_eXosip_dialog_free (struct eXosip_t *excontext, eXosip_dialog_t * jd)
{
  while (!osip_list_eol (jd->d_inc_trs, 0)) {
    osip_transaction_t *tr;

    tr = (osip_transaction_t *) osip_list_get (jd->d_inc_trs, 0);
    osip_list_remove (jd->d_inc_trs, 0);
    _eXosip_delete_reserved (tr);
    osip_list_add (&excontext->j_transactions, tr, 0);
  }

  while (!osip_list_eol (jd->d_out_trs, 0)) {
    osip_transaction_t *tr;

    tr = (osip_transaction_t *) osip_list_get (jd->d_out_trs, 0);
    osip_list_remove (jd->d_out_trs, 0);
    _eXosip_delete_reserved (tr);
    osip_list_add (&excontext->j_transactions, tr, 0);
  }

  osip_message_free (jd->d_200Ok);
  osip_message_free (jd->d_ack);

  osip_dialog_free (jd->d_dialog);

  osip_free (jd->d_out_trs);
  osip_free (jd->d_inc_trs);
  osip_free (jd);

  _eXosip_update (excontext);
}
Пример #3
0
void
eXosip_dialog_free (eXosip_dialog_t * jd)
{
  while (!osip_list_eol (jd->d_inc_trs, 0))
    {
      osip_transaction_t *tr;

      tr = (osip_transaction_t *) osip_list_get (jd->d_inc_trs, 0);
      osip_list_remove (jd->d_inc_trs, 0);
      __eXosip_delete_jinfo (tr);
      osip_list_add (eXosip.j_transactions, tr, 0);
    }

  while (!osip_list_eol (jd->d_out_trs, 0))
    {
      osip_transaction_t *tr;

      tr = (osip_transaction_t *) osip_list_get (jd->d_out_trs, 0);
      osip_list_remove (jd->d_out_trs, 0);
      __eXosip_delete_jinfo (tr);
      osip_list_add (eXosip.j_transactions, tr, 0);
    }

  osip_message_free (jd->d_200Ok);
  osip_message_free (jd->d_ack);

  osip_dialog_free (jd->d_dialog);

  osip_free (jd->d_out_trs);
  osip_free (jd->d_inc_trs);
  osip_free (jd);

  eXosip_update ();
}
Пример #4
0
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;
}
Пример #5
0
int
_eXosip_insubscription_transaction_find (int tid, eXosip_notify_t ** jn,
        eXosip_dialog_t ** jd,
        osip_transaction_t ** tr)
{
    for (*jn = eXosip.j_notifies; *jn != NULL; *jn = (*jn)->next)
    {
        if ((*jn)->n_inc_tr != NULL && (*jn)->n_inc_tr->transactionid == tid)
        {
            *tr = (*jn)->n_inc_tr;
            *jd = (*jn)->n_dialogs;
            return 0;
        }
        if ((*jn)->n_out_tr != NULL && (*jn)->n_out_tr->transactionid == tid)
        {
            *tr = (*jn)->n_out_tr;
            *jd = (*jn)->n_dialogs;
            return 0;
        }
        for (*jd = (*jn)->n_dialogs; *jd != NULL; *jd = (*jd)->next)
        {
            osip_transaction_t *transaction;
            int pos = 0;

            while (!osip_list_eol ((*jd)->d_inc_trs, pos))
            {
                transaction =
                    (osip_transaction_t *) osip_list_get ((*jd)->d_inc_trs, pos);
                if (transaction != NULL && transaction->transactionid == tid)
                {
                    *tr = transaction;
                    return 0;
                }
                pos++;
            }

            pos = 0;
            while (!osip_list_eol ((*jd)->d_out_trs, pos))
            {
                transaction =
                    (osip_transaction_t *) osip_list_get ((*jd)->d_out_trs, pos);
                if (transaction != NULL && transaction->transactionid == tid)
                {
                    *tr = transaction;
                    return 0;
                }
                pos++;
            }
        }
    }
    *jd = NULL;
    *jn = NULL;
    return -1;
}
Пример #6
0
int
eXosip_remove_transaction_from_call (osip_transaction_t * tr, eXosip_call_t * jc)
{
  osip_transaction_t *inc_tr;
  osip_transaction_t *out_tr;
  eXosip_dialog_t *jd;
  int pos = 0;

  if (jc->c_inc_tr == tr)
    {
      jc->c_inc_tr = NULL;      /* can be NULL */
      return 0;
    }

  for (jd = jc->c_dialogs; jd != NULL; jd = jd->next)
    {
      pos = 0;
      while (!osip_list_eol (jd->d_inc_trs, pos))
        {
          inc_tr = osip_list_get (jd->d_inc_trs, pos);
          if (inc_tr == tr)
            {
              osip_list_remove (jd->d_inc_trs, pos);
              return 0;
            }
          pos++;
        }
    }

  if (jc->c_out_tr == tr)
    {
      jc->c_out_tr = NULL;      /* can be NULL */
      return 0;
    }

  for (jd = jc->c_dialogs; jd != NULL; jd = jd->next)
    {
      pos = 0;
      while (!osip_list_eol (jd->d_out_trs, pos))
        {
          out_tr = osip_list_get (jd->d_out_trs, pos);
          if (out_tr == tr)
            {
              osip_list_remove (jd->d_out_trs, pos);
              return 0;
            }
          pos++;
        }
    }

  OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL,
                          "eXosip: No information.\n"));
  return -1;
}
Пример #7
0
int
_eXosip_call_transaction_find (int tid, eXosip_call_t ** jc,
                               eXosip_dialog_t ** jd, osip_transaction_t ** tr)
{
  for (*jc = eXosip.j_calls; *jc != NULL; *jc = (*jc)->next)
    {
      if ((*jc)->c_inc_tr != NULL && (*jc)->c_inc_tr->transactionid == tid)
        {
          *tr = (*jc)->c_inc_tr;
          *jd = (*jc)->c_dialogs;
          return OSIP_SUCCESS;
        }
      if ((*jc)->c_out_tr != NULL && (*jc)->c_out_tr->transactionid == tid)
        {
          *tr = (*jc)->c_out_tr;
          *jd = (*jc)->c_dialogs;
          return OSIP_SUCCESS;
        }
      for (*jd = (*jc)->c_dialogs; *jd != NULL; *jd = (*jd)->next)
        {
          osip_transaction_t *transaction;
          int pos = 0;

          while (!osip_list_eol ((*jd)->d_inc_trs, pos))
            {
              transaction =
                (osip_transaction_t *) osip_list_get ((*jd)->d_inc_trs, pos);
              if (transaction != NULL && transaction->transactionid == tid)
                {
                  *tr = transaction;
                  return OSIP_SUCCESS;
                }
              pos++;
            }

          pos = 0;
          while (!osip_list_eol ((*jd)->d_out_trs, pos))
            {
              transaction =
                (osip_transaction_t *) osip_list_get ((*jd)->d_out_trs, pos);
              if (transaction != NULL && transaction->transactionid == tid)
                {
                  *tr = transaction;
                  return OSIP_SUCCESS;
                }
              pos++;
            }
        }
    }
  *jd = NULL;
  *jc = NULL;
  return OSIP_NOTFOUND;
}
Пример #8
0
int
_sdp_analyse_attribute (sdp_message_t * sdp, sdp_media_t * med)
{
  int pos;
  int pos_media;

  /* test media attributes */
  pos = 0;
  while (!osip_list_eol (med->a_attributes, pos))
    {
      sdp_attribute_t *at;

      at = (sdp_attribute_t *) osip_list_get (med->a_attributes, pos);
      if (at->a_att_field != NULL && 0 == strcmp (at->a_att_field, "sendonly"))
        {
          return _SENDONLY;
      } else if (at->a_att_field != NULL &&
                 0 == strcmp (at->a_att_field, "recvonly"))
        {
          return _RECVONLY;
      } else if (at->a_att_field != NULL &&
                 0 == strcmp (at->a_att_field, "sendrecv"))
        {
          return _SENDRECV;
        }
      pos++;
    }

  /* test global attributes */
  pos_media = -1;
  pos = 0;
  while (!osip_list_eol (sdp->a_attributes, pos))
    {
      sdp_attribute_t *at;

      at = (sdp_attribute_t *) osip_list_get (sdp->a_attributes, pos);
      if (at->a_att_field != NULL && 0 == strcmp (at->a_att_field, "sendonly"))
        {
          return _SENDONLY;
      } else if (at->a_att_field != NULL &&
                 0 == strcmp (at->a_att_field, "recvonly"))
        {
          return _RECVONLY;
      } else if (at->a_att_field != NULL &&
                 0 == strcmp (at->a_att_field, "sendrecv"))
        {
          return _SENDRECV;
        }
      pos++;
    }

  return _SENDRECV;
}
int
osip_dialog_update_route_set_as_uas (osip_dialog_t * dialog, osip_message_t * invite)
{
  osip_contact_t *contact;
  int i;

  if (dialog == NULL)
    return OSIP_BADPARAMETER;
  if (invite == NULL)
    return OSIP_BADPARAMETER;

  if (osip_list_eol (&invite->contacts, 0)) {
    OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_WARNING, NULL, "missing a contact in invite!\n"));
  }
  else {
    if (dialog->remote_contact_uri != NULL) {
      osip_contact_free (dialog->remote_contact_uri);
    }
    dialog->remote_contact_uri = NULL;
    contact = osip_list_get (&invite->contacts, 0);
    i = osip_contact_clone (contact, &(dialog->remote_contact_uri));
    if (i != 0)
      return i;
  }
  return OSIP_SUCCESS;
}
Пример #10
0
osip_transaction_t *
_eXosip_find_last_out_invite (eXosip_call_t * jc, eXosip_dialog_t * jd)
{
  osip_transaction_t *out_tr;
  int pos;

  out_tr = NULL;
  pos = 0;
  if (jd == NULL && jc == NULL)
    return NULL;

  if (jd != NULL) {
    while (!osip_list_eol (jd->d_out_trs, pos)) {
      out_tr = osip_list_get (jd->d_out_trs, pos);
      if (0 == strcmp (out_tr->cseq->method, "INVITE"))
        break;
      else
        out_tr = NULL;
      pos++;
    }
  }

  if (out_tr == NULL)
    return jc->c_out_tr;        /* can be NULL */

  return out_tr;
}
Пример #11
0
osip_transaction_t *
eXosip_find_last_inc_invite(eXosip_call_t *jc, eXosip_dialog_t *jd )
{
  osip_transaction_t *inc_tr;
  int pos;
  inc_tr = NULL;
  pos=0;
  if (jd!=NULL)
    {
      while (!osip_list_eol(jd->d_inc_trs, pos))
	{
	  inc_tr = osip_list_get(jd->d_inc_trs, pos);
	  if (0==strcmp(inc_tr->cseq->method, "INVITE"))
	    break;
	  else inc_tr = NULL;
	  pos++;
	}
    }
  else
    inc_tr = NULL;

  if (inc_tr==NULL)
    return jc->c_inc_tr; /* can be NULL */

  return inc_tr;
}
Пример #12
0
int
osip_uri_param_get_byname (osip_list_t * params, char *pname,
                           osip_uri_param_t ** url_param)
{
  int pos = 0;
  size_t pname_len;
  osip_uri_param_t *u_param;

  *url_param = NULL;
  if (pname == NULL)
    return -1;
  pname_len = strlen (pname);
  if (pname_len <= 0)
    return -1;
  while (!osip_list_eol (params, pos))
    {
      size_t len;

      u_param = (osip_uri_param_t *) osip_list_get (params, pos);
      len = strlen (u_param->gname);
      if (pname_len == len
          && osip_strncasecmp (u_param->gname, pname, strlen (pname)) == 0)
        {
          *url_param = u_param;
          return 0;
        }
      pos++;
    }
  return -1;
}
Пример #13
0
void
osip_uri_free (osip_uri_t * url)
{
  int pos = 0;

  if (url == NULL)
    return;
  osip_free (url->scheme);
  osip_free (url->username);
  osip_free (url->password);
  osip_free (url->host);
  osip_free (url->port);

  osip_uri_param_freelist (&url->url_params);

  {
    osip_uri_header_t *u_header;

    while (!osip_list_eol (&url->url_headers, pos))
      {
        u_header = (osip_uri_header_t *) osip_list_get (&url->url_headers, pos);
        osip_list_remove (&url->url_headers, pos);
        osip_uri_header_free (u_header);
      }
  }

  osip_free (url->string);

  osip_free (url);
}
Пример #14
0
static int
eXtl_update_local_target(osip_message_t *req)
{
  int pos = 0;

  if (dtls_firewall_ip!='\0')
    {

      while (!osip_list_eol (&req->contacts, pos))
	{
	  osip_contact_t *co;
	  
	  co = (osip_contact_t *) osip_list_get (&req->contacts, pos);
	  pos++;
	  if (co != NULL && co->url != NULL && co->url->host != NULL
	      && 0 == osip_strcasecmp (co->url->host, dtls_firewall_ip))
	    {
	      if (co->url->port == NULL &&
		  0 != osip_strcasecmp (dtls_firewall_port, "5061"))
		{
		  co->url->port = osip_strdup (dtls_firewall_port);
		}
	      else if (co->url->port != NULL &&
		       0 != osip_strcasecmp (dtls_firewall_port,
					     co->url->port))
		{
		  osip_free (co->url->port);
		  co->url->port = osip_strdup (dtls_firewall_port);
		}
	    }
	}
    }

  return 0;
}
Пример #15
0
static int
sdp_append_time_descr (char *string, int size, char *tmp,
		       sdp_time_descr_t * time_descr, char **next_tmp)
{
  int pos;

  if (time_descr->t_start_time == NULL)
    return -1;
  if (time_descr->t_stop_time == NULL)
    return -1;


  tmp = __osip_sdp_append_string (string, size, tmp, "t=");
  tmp =
    __osip_sdp_append_string (string, size, tmp, time_descr->t_start_time);
  tmp = __osip_sdp_append_string (string, size, tmp, " ");
  tmp = __osip_sdp_append_string (string, size, tmp, time_descr->t_stop_time);

  tmp = __osip_sdp_append_string (string, size, tmp, CRLF);

  pos = 0;
  while (!osip_list_eol (time_descr->r_repeats, pos))
    {
      char *str = (char *) osip_list_get (time_descr->r_repeats, pos);

      tmp = __osip_sdp_append_string (string, size, tmp, "r=");
      tmp = __osip_sdp_append_string (string, size, tmp, str);
      tmp = __osip_sdp_append_string (string, size, tmp, CRLF);
      pos++;
    }

  *next_tmp = tmp;
  return 0;
}
Пример #16
0
osip_transaction_t *
_eXosip_find_last_inc_transaction (eXosip_call_t * jc, eXosip_dialog_t * jd, const char *method)
{
  osip_transaction_t *inc_tr;
  int pos;

  inc_tr = NULL;
  pos = 0;
  if (method == NULL || method[0] == '\0')
    return NULL;
  if (jd != NULL) {
    while (!osip_list_eol (jd->d_inc_trs, pos)) {
      inc_tr = osip_list_get (jd->d_inc_trs, pos);
      if (0 == osip_strcasecmp (inc_tr->cseq->method, method))
        break;
      else
        inc_tr = NULL;
      pos++;
    }
  }
  else
    inc_tr = NULL;

  return inc_tr;
}
Пример #17
0
osip_transaction_t *
eXosip_find_last_inc_subscribe (eXosip_notify_t * jn, eXosip_dialog_t * jd)
{
  osip_transaction_t *inc_tr;
  int pos;

  inc_tr = NULL;
  pos = 0;
  if (jd != NULL)
    {
      while (!osip_list_eol (jd->d_inc_trs, pos))
        {
          inc_tr = osip_list_get (jd->d_inc_trs, pos);
          if (0 == strcmp (inc_tr->cseq->method, "SUBSCRIBE"))
            break;
          else
            inc_tr = NULL;
          pos++;
        }
  } else
    inc_tr = NULL;

  if (inc_tr == NULL)
    return jn->n_inc_tr;        /* can be NULL */

  return inc_tr;
}
Пример #18
0
osip_transaction_t *_eXosip_find_last_out_subscribe(eXosip_subscribe_t * js,
												   eXosip_dialog_t * jd)
{
	osip_transaction_t *out_tr;
	int pos;

	out_tr = NULL;
	pos = 0;
	if (jd != NULL) {
		while (!osip_list_eol(jd->d_out_trs, pos)) {
			out_tr = osip_list_get(jd->d_out_trs, pos);
			if (0 == strcmp(out_tr->cseq->method, "SUBSCRIBE"))
				break;
			else
				out_tr = NULL;
			pos++;
		}
	} else
		out_tr = NULL;

	if (out_tr == NULL)
		return js->s_out_tr;	/* can be NULL */

	return out_tr;
}
Пример #19
0
        void SIPBuilder::CameraInfoAck(osip_message_t* msg,
                char** rtmsg, size_t* rtlen)
        {
            string head_line("SIP/2.0 200 OK\r\n");

            osip_via_t *via;
            char* via_c = NULL; 
            if( !osip_list_eol (&msg->vias, 0))
            {
                via = (osip_via_t *) osip_list_get (&msg->vias, 0);
                osip_via_to_str( via, &via_c);
            }else{
                return;
            }
            string via_header(via_c);
            via_header = string("Via: ")+via_header+string("\r\n");
            
            char* from_tag_c;
            osip_from_to_str( msg->from, &from_tag_c );
            string from_header(from_tag_c);
            from_header = string("From: ")+from_header+string("\r\n");

            char* to_tag_c;
            osip_to_to_str( msg->to, &to_tag_c );
            string to_header(to_tag_c);
            string to_tag_num = _RandomNum();
            to_header = to_header + ";tag="+to_tag_num;
            to_header = string("To: ")+to_header+string("\r\n");


            string call_id_num = string(msg->call_id->number);
            string call_header = string("Call-ID: ")+call_id_num+("\r\n");

            string cseq_num = string(msg->cseq->number);
            string cseq_header = string("Cseq: ")+cseq_num+string(" MESSAGE\r\n");
            string content_type_header = "Content-Type: APPLICATION/SDP\r\n";

            string forwords = string("Max-Forwards: 70\r\n");
            string expires = string("Expires: 3000\r\n");
            string contentlenth = string("Content-Length: 0")+string("\r\n");
            string cflr = string("\r\n");

            string sip_msg_str = head_line + via_header + to_header + from_header
                + call_header + cseq_header  + content_type_header + 
                forwords + expires + contentlenth + cflr;
            
#ifdef DEBUG
            cout<<"check 200ok camerainfoack:"<<endl;
            cout<<sip_msg_str<<endl;
#endif
            size_t sip_len = sip_msg_str.length();
            char* sip_msg_c = (char*)malloc(sizeof(char)* sip_len);
            memcpy( sip_msg_c, sip_msg_str.c_str(), sip_len);
            *rtmsg = sip_msg_c;
            *rtlen = sip_len;
            /*send 200ok, wait ack*/
            return;
        }
Пример #20
0
int
_eXosip_subscribe_transaction_find (struct eXosip_t *excontext, int tid, eXosip_subscribe_t ** js, eXosip_dialog_t ** jd, osip_transaction_t ** tr)
{
  for (*js = excontext->j_subscribes; *js != NULL; *js = (*js)->next) {
    if ((*js)->s_inc_tr != NULL && (*js)->s_inc_tr->transactionid == tid) {
      *tr = (*js)->s_inc_tr;
      *jd = (*js)->s_dialogs;
      return OSIP_SUCCESS;
    }
    if ((*js)->s_out_tr != NULL && (*js)->s_out_tr->transactionid == tid) {
      *tr = (*js)->s_out_tr;
      *jd = (*js)->s_dialogs;
      return OSIP_SUCCESS;
    }
    for (*jd = (*js)->s_dialogs; *jd != NULL; *jd = (*jd)->next) {
      osip_transaction_t *transaction;
      int pos = 0;

      while (!osip_list_eol ((*jd)->d_inc_trs, pos)) {
        transaction = (osip_transaction_t *) osip_list_get ((*jd)->d_inc_trs, pos);
        if (transaction != NULL && transaction->transactionid == tid) {
          *tr = transaction;
          return OSIP_SUCCESS;
        }
        pos++;
      }

      pos = 0;
      while (!osip_list_eol ((*jd)->d_out_trs, pos)) {
        transaction = (osip_transaction_t *) osip_list_get ((*jd)->d_out_trs, pos);
        if (transaction != NULL && transaction->transactionid == tid) {
          *tr = transaction;
          return OSIP_SUCCESS;
        }
        pos++;
      }
    }
  }
  *jd = NULL;
  *js = NULL;
  return OSIP_NOTFOUND;
}
Пример #21
0
int
sdp_message_endof_media (sdp_message_t * sdp, int i)
{
  if (sdp == NULL)
    return OSIP_BADPARAMETER;
  if (i == -1)
    return OSIP_SUCCESS;
  if (!osip_list_eol (&sdp->m_medias, i))
    return OSIP_SUCCESS;        /* not end of list */
  return OSIP_UNDEFINED_ERROR;  /* end of list */
}
Пример #22
0
int
sdp_message_endof_media (sdp_message_t * sdp, int i)
{
  if (sdp == NULL)
    return -1;
  if (i == -1)
    return 0;
  if (!osip_list_eol (&sdp->m_medias, i))
    return 0;                   /* not end of list */
  return -1;                    /* end of list */
}
Пример #23
0
void
osip_uri_param_freelist (osip_list_t * params)
{
  osip_uri_param_t *u_param;

  while (!osip_list_eol (params, 0))
    {
      u_param = (osip_uri_param_t *) osip_list_get (params, 0);
      osip_list_remove (params, 0);
      osip_uri_param_free (u_param);
    }
}
Пример #24
0
/*
 * create a reply template from an given SIP request
 *
 * RETURNS a pointer to osip_message_t
 */
osip_message_t *msg_make_template_reply (sip_ticket_t *ticket, int code) {
   osip_message_t *request=ticket->sipmsg;
   osip_message_t *response;
   int pos;

   osip_message_init (&response);
   response->message=NULL;
   osip_message_set_version (response, osip_strdup ("SIP/2.0"));
   osip_message_set_status_code (response, code);
   osip_message_set_reason_phrase (response, 
                                   osip_strdup(osip_message_get_reason (code)));

   if (request->to==NULL) {
      ERROR("msg_make_template_reply: empty To in request header");
      return NULL;
   }

   if (request->from==NULL) {
      ERROR("msg_make_template_reply: empty From in request header");
      return NULL;
   }

   osip_to_clone (request->to, &response->to);
   osip_from_clone (request->from, &response->from);

   /* if 3xx, also include 1st contact header */
   if ((code==200) || ((code>=300) && (code<400))) {
      osip_contact_t *req_contact = NULL;
      osip_contact_t *res_contact = NULL;
      osip_message_get_contact(request, 0, &req_contact);
      if (req_contact) osip_contact_clone (req_contact, &res_contact);
      if (res_contact) osip_list_add(response->contacts,res_contact,0);
   }

   /* via headers */
   pos = 0;
   while (!osip_list_eol (request->vias, pos)) {
      char *tmp;
      osip_via_t *via;
      via = (osip_via_t *) osip_list_get (request->vias, pos);
      osip_via_to_str (via, &tmp);

      osip_message_set_via (response, tmp);
      osip_free (tmp);
      pos++;
   }

   osip_call_id_clone(request->call_id,&response->call_id);
   
   osip_cseq_clone(request->cseq,&response->cseq);

   return response;
}
Пример #25
0
void osip_list_ofchar_free(osip_list_t * li)
{
	int pos = 0;
	char *chain;

	if (li == NULL)
		return;
	while (!osip_list_eol(li, pos)) {
		chain = (char *) osip_list_get(li, pos);
		osip_list_remove(li, pos);
		osip_free(chain);
	}
}
Пример #26
0
void osip_list_special_free(osip_list_t * li, void (*free_func) (void *))
{
	void *element;

	if (li == NULL)
		return;
	while (!osip_list_eol(li, 0)) {
		element = (void *) osip_list_get(li, 0);
		osip_list_remove(li, 0);
		if (free_func != NULL)
			free_func(element);
	}
}
Пример #27
0
int
osip_body_clone (const osip_body_t * body, osip_body_t ** dest)
{
  int pos;
  int i;
  osip_body_t *copy;

  if (body == NULL || body->length<=0)
    return -1;

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

  
  copy->body = (char*)osip_malloc(body->length+2);
  copy->length = body->length;
  memcpy(copy->body,body->body,body->length);
  copy->body[body->length]='\0';

  if (body->content_type != NULL)
    {
      i = osip_content_type_clone (body->content_type, &(copy->content_type));
      if (i != 0)
	goto bc_error1;
    }

  {
    osip_header_t *header;
    osip_header_t *header2;

    pos = 0;
    while (!osip_list_eol (body->headers, pos))
      {
	header = (osip_header_t *) osip_list_get (body->headers, pos);
	i = osip_header_clone (header, &header2);
	if (i != 0)
	  goto bc_error1;
	osip_list_add (copy->headers, header2, -1);	/* insert as last element */
	pos++;
      }
  }

  *dest = copy;
  return 0;
bc_error1:
  osip_body_free (copy);
  return -1;
}
Пример #28
0
int
osip_via_clone (const osip_via_t * via, osip_via_t ** dest)
{
  int i;
  osip_via_t *vi;

  *dest = NULL;
  if (via == NULL)
    return -1;
  if (via->version == NULL)
    return -1;
  if (via->protocol == NULL)
    return -1;
  if (via->host == NULL)
    return -1;

  i = osip_via_init (&vi);
  if (i != 0)
    return -1;
  vi->version = osip_strdup (via->version);
  vi->protocol = osip_strdup (via->protocol);
  vi->host = osip_strdup (via->host);
  if (via->port != NULL)
    vi->port = osip_strdup (via->port);
  if (via->comment != NULL)
    vi->comment = osip_strdup (via->comment);

  {
    int pos = 0;
    osip_generic_param_t *u_param;
    osip_generic_param_t *dest_param;

    while (!osip_list_eol (via->via_params, pos))
      {
	u_param =
	  (osip_generic_param_t *) osip_list_get (via->via_params, pos);
	i = osip_generic_param_clone (u_param, &dest_param);
	if (i != 0)
	  {
	    osip_via_free (vi);
	    return -1;
	  }
	osip_list_add (vi->via_params, dest_param, -1);
	pos++;
      }
  }
  *dest = vi;
  return 0;
}
Пример #29
0
void
__nict_unload_fsm ()
{
  transition_t *transition;
  osip_statemachine_t *statemachine = __nict_get_fsm ();

  while (!osip_list_eol (statemachine->transitions, 0))
    {
      transition = (transition_t *) osip_list_get (statemachine->transitions, 0);
      osip_list_remove (statemachine->transitions, 0);
      osip_free (transition);
    }
  osip_free (statemachine->transitions);
  osip_free (statemachine);
}
Пример #30
0
int from_2char_without_params(osip_from_t *from,char **str)
{
	osip_from_t *tmpfrom=NULL;
	osip_from_clone(from,&tmpfrom);
	if (tmpfrom!=NULL){
		while(!osip_list_eol(&tmpfrom->gen_params,0)){
			osip_generic_param_t *param=(osip_generic_param_t*)osip_list_get(&tmpfrom->gen_params,0);
			osip_generic_param_free(param);
			osip_list_remove(&tmpfrom->gen_params,0);
		}
	}else return -1;
	osip_from_to_str(tmpfrom,str);
	osip_from_free(tmpfrom);
	return 0;
}