예제 #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
/* 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
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 -1;
  if (header->hname == NULL)
    return -1;

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

  *dest = he;
  return 0;
}
예제 #6
0
int
osip_body_set_header (osip_body_t * body, const char *hname,
		      const char *hvalue)
{
  osip_header_t *h;
  int i;

  if (body == NULL)
    return -1;
  if (hname == NULL)
    return -1;
  if (hvalue == NULL)
    return -1;

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

  h->hname = osip_strdup (hname);
  h->hvalue = osip_strdup (hvalue);

  osip_list_add (body->headers, h, -1);
  return 0;
}