예제 #1
0
/* returns -1 on error. */
int
osip_message_set_authorization (osip_message_t * sip, const char *hvalue)
{
  osip_authorization_t *authorization;
  int i;

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

  if (sip == NULL)
    return OSIP_BADPARAMETER;
  i = osip_authorization_init (&authorization);
  if (i != 0)
    return i;
  i = osip_authorization_parse (authorization, hvalue);
  if (i != 0) {
    osip_authorization_free (authorization);
    return i;
  }
  sip->message_property = 2;
  osip_list_add (&sip->authorizations, authorization, -1);
  return OSIP_SUCCESS;
}
int
osip_authorization_clone (const osip_authorization_t * auth,
                          osip_authorization_t ** dest)
{
  int i;
  osip_authorization_t *au;

  *dest = NULL;
  if (auth == NULL)
    return OSIP_BADPARAMETER;
  /* to be removed?
     if (auth->auth_type==NULL) return -1;
     if (auth->username==NULL) return -1;
     if (auth->realm==NULL) return -1;
     if (auth->nonce==NULL) return -1;
     if (auth->uri==NULL) return -1;
     if (auth->response==NULL) return -1;
     if (auth->opaque==NULL) return -1;
   */

  i = osip_authorization_init (&au);
  if (i == -1)                  /* allocation failed */
    return i;
  if (auth->auth_type != NULL)
    {
      au->auth_type = osip_strdup (auth->auth_type);
      if (au->auth_type == NULL)
	  {
		  osip_authorization_free (au);
		  return OSIP_NOMEM;
	  }
    }
  if (auth->username != NULL)
    {
      au->username = osip_strdup (auth->username);
      if (au->username == NULL)
	  {
		  osip_authorization_free (au);
		  return OSIP_NOMEM;
	  }
    }
  if (auth->realm != NULL)
    {
      au->realm = osip_strdup (auth->realm);
      if (auth->realm == NULL)
	  {
		  osip_authorization_free (au);
		  return OSIP_NOMEM;
	  }
    }
  if (auth->nonce != NULL)
    {
      au->nonce = osip_strdup (auth->nonce);
      if (auth->nonce == NULL)
	  {
		  osip_authorization_free (au);
		  return OSIP_NOMEM;
	  }
    }
  if (auth->uri != NULL)
    {
      au->uri = osip_strdup (auth->uri);
      if (au->uri == NULL)
	  {
		  osip_authorization_free (au);
		  return OSIP_NOMEM;
	  }
    }
  if (auth->response != NULL)
    {
      au->response = osip_strdup (auth->response);
      if (auth->response == NULL)
	  {
		  osip_authorization_free (au);
		  return OSIP_NOMEM;
	  }
    }
  if (auth->digest != NULL)
    {
      au->digest = osip_strdup (auth->digest);
      if (au->digest == NULL)
	  {
		  osip_authorization_free (au);
		  return OSIP_NOMEM;
	  }
    }
  if (auth->algorithm != NULL)
    {
      au->algorithm = osip_strdup (auth->algorithm);
      if (auth->algorithm == NULL)
	  {
		  osip_authorization_free (au);
		  return OSIP_NOMEM;
	  }
    }
  if (auth->cnonce != NULL)
    {
      au->cnonce = osip_strdup (auth->cnonce);
      if (au->cnonce == NULL)
	  {
		  osip_authorization_free (au);
		  return OSIP_NOMEM;
	  }
    }
  if (auth->opaque != NULL)
    {
      au->opaque = osip_strdup (auth->opaque);
      if (auth->opaque == NULL)
	  {
		  osip_authorization_free (au);
		  return OSIP_NOMEM;
	  }
    }
  if (auth->message_qop != NULL)
    {
      au->message_qop = osip_strdup (auth->message_qop);
      if (auth->message_qop == NULL)
	  {
		  osip_authorization_free (au);
		  return OSIP_NOMEM;
	  }
    }
  if (auth->nonce_count != NULL)
    {
      au->nonce_count = osip_strdup (auth->nonce_count);
      if (auth->nonce_count == NULL)
	  {
		  osip_authorization_free (au);
		  return OSIP_NOMEM;
	  }
    }

  *dest = au;
  return OSIP_SUCCESS;
}