forked from Mirrors/freeswitch
b7c6c0e483
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
104 lines
2.4 KiB
C
104 lines
2.4 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
|
|
*
|
|
*/
|
|
|
|
/**@internal @file token64.c
|
|
*
|
|
* Token encoding.
|
|
*
|
|
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
|
|
*
|
|
* @date Created: Wed Apr 3 10:45:47 2002 ppessi
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdio.h>
|
|
#include <stddef.h>
|
|
#include <assert.h>
|
|
|
|
#include "sofia-sip/token64.h"
|
|
|
|
static const char code[65] =
|
|
"0123456789-abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
|
/** Encode data as a SIP/HTTP token.
|
|
*
|
|
* @note
|
|
* A token is case-independent, so this is really not a good idea.
|
|
* Use msg_random_token() instead.
|
|
*/
|
|
isize_t token64_e(char b[], isize_t bsiz, void const *data, isize_t dlen)
|
|
{
|
|
size_t i, n, slack;
|
|
unsigned char const *h = data;
|
|
char *s = b, *end = b + bsiz;
|
|
long w;
|
|
|
|
if (dlen <= 0) {
|
|
if (bsiz && b) *b = '\0';
|
|
return 0;
|
|
}
|
|
|
|
n = (8 * dlen + 5) / 6;
|
|
if (bsiz == 0 || b == NULL)
|
|
return n;
|
|
|
|
if (b + n >= end)
|
|
dlen = 6 * bsiz / 8;
|
|
else
|
|
end = b + n + 1;
|
|
|
|
slack = dlen % 3;
|
|
dlen -= slack;
|
|
|
|
for (i = 0; i < dlen; i += 3, s += 4) {
|
|
unsigned char h0 = h[i], h1 = h[i + 1], h2 = h[i + 2];
|
|
|
|
s[0] = code[h0 >> 2];
|
|
s[1] = code[((h0 << 4)|(h1 >> 4)) & 63];
|
|
s[2] = code[((h1 << 4)|(h2 >> 6)) & 63];
|
|
s[3] = code[(h2) & 63];
|
|
}
|
|
|
|
if (slack) {
|
|
if (slack == 2)
|
|
w = (h[i] << 16) | (h[i+1] << 8);
|
|
else
|
|
w = (h[i] << 16);
|
|
|
|
if (s < end) *s++ = code[(w >> 18) & 63];
|
|
if (s < end) *s++ = code[(w >> 12) & 63];
|
|
if (s < end && slack == 2) *s++ = code[(w >> 6) & 63];
|
|
}
|
|
|
|
if (s < end)
|
|
*s++ = '\0';
|
|
else
|
|
end[-1] = '\0';
|
|
|
|
assert(end == s);
|
|
|
|
return n;
|
|
}
|