Michael Jerris b7c6c0e483 Merge up to current sofia-sip darcs.
Thu Nov 15 08:40:38 EST 2007  Pekka.Pessi@nokia.com
  * htable2.h: fixed usize_t/size_t confusion

Fri Nov 16 06:38:51 EST 2007  Youness Alaoui <youness.alaoui@collabora.co.uk>
  * Added #include <stdio.h>

Fri Nov 16 10:27:58 EST 2007  Pekka.Pessi@nokia.com
  * auth_client.c: allow multiple challenges in auc_credentials() or auc_all_credentials()

Fri Nov 16 10:29:00 EST 2007  Pekka.Pessi@nokia.com
  * nua/test_proxy.[hc], nua/test_register.c: test support of multiple realms.

Fri Nov 16 11:17:09 EST 2007  Pekka.Pessi@nokia.com
  * sofia-sip/su_alloc.h, su_alloc.c: added su_home_lock(), su_home_trylock(), su_home_unlock()
  
  Added test in torture_su_alloc.c. Using in su_pthread_port.c.

Fri Nov 16 12:29:55 EST 2007  Pekka.Pessi@nokia.com
  * test_register.c, test_proxy.c: use realm "test-proxy" during normal tests

Fri Nov 16 12:34:00 EST 2007  Pekka.Pessi@nokia.com
  * nua_register.c: sf.net bug #1816647: Outbound contact does not make it to dialogs
  
  Now use Contact from first registration instead of Contact generated from
  transport.

Mon Nov 19 12:00:06 EST 2007  Pekka Pessi <Pekka.Pessi@nokia.com>
  * su_alloc.c: silenced warnings on Sun CC



git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6338 d0543943-73ff-0310-b7d9-9358b9ac24b2
2007-11-19 18:09:15 +00:00

158 lines
3.8 KiB
C

/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2005 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
/**@ingroup msg_parser
* @CFILE msg_auth.c
*
* Functions for handling authentication-related headers
*
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
*
* @date Created: Tue Jun 13 02:57:51 2000 ppessi
*
*/
#include "config.h"
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <assert.h>
#include <sofia-sip/msg.h>
#include <sofia-sip/msg_parser.h>
#include <sofia-sip/msg_header.h>
#include <sofia-sip/bnf.h>
#if 0
/**
* Scan and compact an authentication parameter.
*
* Scan an authentication parameter, which has syntax as follows:
* @code
* auth-item = auth-param | base64-string
* auth-param = token [ "=" (token | quoted-string)]
* @endcode
*
* Parameters:
* @param s pointer to string to scan
*
* @return Number of characters scanned, or zero upon an error.
*/
static size_t msg_auth_item_scan(char *start)
{
char *p, *s;
p = s = start;
/* XXX */
return start - s;
}
#endif
/* ====================================================================== */
/*
* auth = ("Authorization" | "Encryption" |
* "Proxy-Authenticate" | "Proxy-Authorization" |
* "Response-Key" | "WWW-Authenticate") ":"
* scheme 1*SP #auth-param
* scheme = token
* auth-param = token | token "=" token | token "=" quoted-string
*/
/** Parse security headers. */
issize_t msg_auth_d(su_home_t *home,
msg_header_t *h,
char *s,
isize_t slen)
{
msg_auth_t *au = (msg_auth_t *)h;
au->au_scheme = s;
skip_token(&s);
if (!IS_LWS(*s)) return -1;
*s++ = '\0'; /* NUL-terminate scheme */
return msg_commalist_d(home, &s, (msg_param_t **)&au->au_params,
NULL /* msg_auth_item_scan */);
}
issize_t msg_auth_e(char b[], isize_t bsiz, msg_header_t const *h, int f)
{
msg_auth_t const *au = (msg_auth_t *)h;
int compact = MSG_IS_COMPACT(f);
char *b0 = b, *end = b + bsiz;
MSG_STRING_E(b, end, au->au_scheme);
if (au->au_params) {
MSG_CHAR_E(b, end, ' ');
MSG_COMMALIST_E(b, end, au->au_params, compact);
}
MSG_TERM_E(b, end);
return b - b0;
}
/**@internal
* Extra size of a msg_auth_t object.
*
* This function calculates extra size required by a msg_auth_t object.
*
* @param a pointer to a msg_auth_t object
*
* @return
* Size of strings related to msg_auth_t object.
*/
isize_t msg_auth_dup_xtra(msg_header_t const *h, isize_t offset)
{
msg_auth_t const *au = h->sh_auth;
MSG_PARAMS_SIZE(offset, au->au_params);
offset += MSG_STRING_SIZE(au->au_scheme);
return offset;
}
/**Duplicate one msg_auth_t object. */
char *msg_auth_dup_one(msg_header_t *dst,
msg_header_t const *src,
char *b,
isize_t xtra)
{
msg_auth_t *au = dst->sh_auth;
msg_auth_t const *o = src->sh_auth;
char *end = b + xtra;
b = msg_params_dup(&au->au_params, o->au_params, b, xtra);
MSG_STRING_DUP(b, au->au_scheme, o->au_scheme);
assert(b <= end); (void)end;
return b;
}