mirror of
https://github.com/strophe/libstrophe.git
synced 2026-07-18 03:46:21 +00:00
It has been pointed out that the wording of the license of this library is not entirely clear. The term "dual licensing" usually refers to a licence choice of two licenses "LICENSE1 _or_ LICENSE2. Instead the license of this library claimed "LICENSE1 _and_ LICENSE2". After an internal discussion with @metajack and @pasis it was made clear that the initial idea was to dual license the library in the usual way. This was also made clear by jack on the ML in the past [0]. As of jack, these licensing terms originated from jquery, which also used the 'and' version in the past and has since been corrected [1]. This patch changes the license terms to 'MIT or GPLv3' and also adds SPDX headers [2]. [0] https://groups.google.com/g/libstrophe/c/JkFgr601JQc [1] https://stackoverflow.com/q/2758409 [2] https://spdx.org Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
56 lines
1.3 KiB
C
56 lines
1.3 KiB
C
/* SPDX-License-Identifier: MIT OR GPL-3.0-only */
|
|
/* test.c
|
|
* strophe XMPP client library -- common routines for tests
|
|
*
|
|
* Copyright (C) 2014 Dmitry Podgorny <pasis.ua@gmail.com>
|
|
*
|
|
* This software is provided AS-IS with no warranty, either express
|
|
* or implied.
|
|
*
|
|
* This program is dual licensed under the MIT or GPLv3 licenses.
|
|
*/
|
|
|
|
#include <assert.h>
|
|
#include <string.h>
|
|
|
|
#include "test.h"
|
|
|
|
static uint8_t char_to_bin(char c)
|
|
{
|
|
return c <= '9' ? (uint8_t)(c - '0')
|
|
: c <= 'Z' ? (uint8_t)(c - 'A' + 10)
|
|
: (uint8_t)(c - 'a' + 10);
|
|
}
|
|
|
|
void test_hex_to_bin(const char *hex, uint8_t *bin, size_t *bin_len)
|
|
{
|
|
size_t len = strlen(hex);
|
|
size_t i;
|
|
|
|
assert(len % 2 == 0);
|
|
|
|
for (i = 0; i < len / 2; ++i) {
|
|
bin[i] = char_to_bin(hex[i * 2]) * 16 + char_to_bin(hex[i * 2 + 1]);
|
|
}
|
|
*bin_len = len / 2;
|
|
}
|
|
|
|
const char *test_bin_to_hex(const uint8_t *bin, size_t len)
|
|
{
|
|
static char buf[2048];
|
|
size_t i;
|
|
|
|
static const char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7',
|
|
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
|
|
|
assert(ARRAY_SIZE(buf) > len * 2);
|
|
|
|
for (i = 0; i < len; ++i) {
|
|
buf[i * 2] = hex[(bin[i] >> 4) & 0x0f];
|
|
buf[i * 2 + 1] = hex[bin[i] & 0x0f];
|
|
}
|
|
buf[len * 2] = '\0';
|
|
|
|
return buf;
|
|
}
|