コード例 #1
0
int
osip_header_clone (const osip_header_t * header, osip_header_t ** dest)
{
  int i;
  osip_header_t *he;

  *dest = NULL;
  if (header == NULL)
    return OSIP_BADPARAMETER;
  if (header->hname == NULL)
    return OSIP_BADPARAMETER;

  i = osip_header_init (&he);
  if (i != 0)
    return i;
  he->hname = osip_strdup (header->hname);

  if (he->hname==NULL)
  {
	  osip_header_free (he);
	  return OSIP_NOMEM;
  }
  if (header->hvalue != NULL)
  {
	  he->hvalue = osip_strdup (header->hvalue);
	  if (he->hvalue==NULL)
	  {
		  osip_header_free (he);
		  return OSIP_NOMEM;
	  }
  }

  *dest = he;
  return OSIP_SUCCESS;
}
コード例 #2
0
ファイル: osip_header.c プロジェクト: avis/osip
/* returns -1 on error. */
int
osip_message_set_header(osip_message_t * sip, const char *hname,
						const char *hvalue)
{
	osip_header_t *h;
	int i;

	if (sip == NULL || hname == NULL)
		return OSIP_BADPARAMETER;

	i = osip_header_init(&h);
	if (i != 0)
		return i;

	h->hname = (char *) osip_malloc(strlen(hname) + 1);

	if (h->hname == NULL) {
		osip_header_free(h);
		return OSIP_NOMEM;
	}
	osip_clrncpy(h->hname, hname, strlen(hname));

	if (hvalue != NULL) {		/* some headers can be null ("subject:") */
		h->hvalue = (char *) osip_malloc(strlen(hvalue) + 1);
		if (h->hvalue == NULL) {
			osip_header_free(h);
			return OSIP_NOMEM;
		}
		osip_clrncpy(h->hvalue, hvalue, strlen(hvalue));
	} else
		h->hvalue = NULL;
	sip->message_property = 2;
	osip_list_add(&sip->headers, h, -1);
	return OSIP_SUCCESS;		/* ok */
}
コード例 #3
0
/* returns -1 on error. */
int
osip_message_replace_header (osip_message_t * sip, const char *hname,
			     const char *hvalue)
{
  osip_header_t *h, *oldh;
  int i, oldpos = -1;

  if (sip == NULL || hname == NULL)
    return OSIP_BADPARAMETER;

  oldpos = osip_message_header_get_byname(sip, hname, 0, &oldh);

  i = osip_header_init (&h);
  if (i != 0)
    return i;

  h->hname = (char *) osip_malloc (strlen (hname) + 1);

  if (h->hname == NULL)
    {
      osip_header_free (h);
      return OSIP_NOMEM;
    }
  osip_clrncpy (h->hname, hname, strlen (hname));

  if (hvalue != NULL)
    {                           /* some headers can be null ("subject:") */
      h->hvalue = (char *) osip_malloc (strlen (hvalue) + 1);
      if (h->hvalue == NULL)
	{
	  osip_header_free (h);
	  return OSIP_NOMEM;
	}
      osip_clrncpy (h->hvalue, hvalue, strlen (hvalue));
    } else
      h->hvalue = NULL;

  if (oldpos != -1)
    {
      osip_list_remove(&sip->headers, oldpos);
      osip_header_free(oldh);
    }

  sip->message_property = 2;
  osip_list_add (&sip->headers, h, -1);
  return OSIP_SUCCESS;                     /* ok */
}
コード例 #4
0
ファイル: osip_header.c プロジェクト: Nymphetaminer/dsl-n55u
/* returns -1 on error. */
int
osip_message_set_topheader (osip_message_t * sip, const char *hname, const char *hvalue)
{
  osip_header_t *h;
  int i;

  if (hname == NULL)
    return -1;

  i = osip_header_init (&h);
  if (i != 0)
    return -1;

  h->hname = (char *) osip_malloc (strlen (hname) + 1);

  if (h->hname == NULL)
    {
      osip_header_free (h);
      return -1;
    }
  osip_strncpy (h->hname, hname, strlen (hname));
  osip_clrspace (h->hname);

  if (hvalue != NULL)
    {				/* some headers can be null ("subject:") */
      h->hvalue = (char *) osip_malloc (strlen (hvalue) + 1);
      if (h->hvalue == NULL)
	{
	  osip_header_free (h);
	  return -1;
	}
      osip_strncpy (h->hvalue, hvalue, strlen (hvalue));
      osip_clrspace (h->hvalue);
    }
  else
    h->hvalue = NULL;
#ifdef USE_TMP_BUFFER
  sip->message_property = 2;
#endif
  osip_list_add (sip->headers, h, 0);
  return 0;			/* ok */
}
コード例 #5
0
/* INPUT : osip_body_t *body | body.  */
void
osip_body_free (osip_body_t * body)
{
  if (body == NULL)
    return;
  osip_free (body->body);
  if (body->content_type != NULL)
    {
      osip_content_type_free (body->content_type);
    }

  {
    osip_header_t *header;

    while (!osip_list_eol (body->headers, 0))
      {
	header = (osip_header_t *) osip_list_get (body->headers, 0);
	osip_list_remove (body->headers, 0);
	osip_header_free (header);
      }
    osip_free (body->headers);
  }
  osip_free (body);
}
コード例 #6
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);
}