Commit a5579709 authored by Daniel Salzman's avatar Daniel Salzman

contrib: move print and tolower from internal

parent 4c743a68
......@@ -38,6 +38,11 @@ src/contrib/openbsd/strlcat.c
src/contrib/openbsd/strlcat.h
src/contrib/openbsd/strlcpy.c
src/contrib/openbsd/strlcpy.h
src/contrib/print.c
src/contrib/print.h
src/contrib/string.c
src/contrib/string.h
src/contrib/tolower.h
src/contrib/ucw/array-sort.h
src/contrib/ucw/binsearch.h
src/contrib/ucw/heap.c
......@@ -360,8 +365,6 @@ src/libknot/internal/hhash.h
src/libknot/internal/lists.c
src/libknot/internal/lists.h
src/libknot/internal/macros.h
src/libknot/internal/mem.c
src/libknot/internal/mem.h
src/libknot/internal/mempattern.c
src/libknot/internal/mempattern.h
src/libknot/internal/namedb/lmdb.h
......@@ -375,12 +378,8 @@ src/libknot/internal/namedb/namedb_trie.c
src/libknot/internal/namedb/namedb_trie.h
src/libknot/internal/net.c
src/libknot/internal/net.h
src/libknot/internal/print.c
src/libknot/internal/print.h
src/libknot/internal/sockaddr.c
src/libknot/internal/sockaddr.h
src/libknot/internal/tolower.c
src/libknot/internal/tolower.h
src/libknot/internal/trie/hat-trie.c
src/libknot/internal/trie/hat-trie.h
src/libknot/internal/trie/murmurhash3.c
......
......@@ -26,7 +26,9 @@ libcontrib_ladir = $(includedir)
nobase_libcontrib_la_HEADERS = \
contrib/endian.h \
contrib/getline.h \
contrib/print.h \
contrib/string.h \
contrib/tolower.h \
contrib/openbsd/strlcat.h \
contrib/openbsd/strlcpy.h \
contrib/ucw/array-sort.h \
......@@ -84,9 +86,7 @@ nobase_libknot_internal_la_HEADERS = \
libknot/internal/namedb/namedb_lmdb.h \
libknot/internal/namedb/namedb_trie.h \
libknot/internal/net.h \
libknot/internal/print.h \
libknot/internal/sockaddr.h \
libknot/internal/tolower.h \
libknot/internal/trie/hat-trie.h \
libknot/internal/trie/murmurhash3.h \
libknot/internal/utils.h \
......@@ -102,6 +102,7 @@ nobase_libknot_yparser_la_HEADERS = \
# dynamic: libknot sources
libcontrib_la_SOURCES = \
contrib/getline.c \
contrib/print.c \
contrib/string.c \
contrib/openbsd/strlcat.c \
contrib/openbsd/strlcpy.c \
......@@ -153,9 +154,7 @@ libknot_internal_la_SOURCES = \
libknot/internal/namedb/namedb_lmdb.c \
libknot/internal/namedb/namedb_trie.c \
libknot/internal/net.c \
libknot/internal/print.c \
libknot/internal/sockaddr.c \
libknot/internal/tolower.c \
libknot/internal/trie/hat-trie.c \
libknot/internal/trie/murmurhash3.c \
libknot/internal/utils.c \
......
......@@ -16,13 +16,13 @@
#include <stdio.h>
#include <ctype.h>
#include "libknot/internal/macros.h"
#include "libknot/internal/print.h"
#include "contrib/print.h"
typedef int (*printf_t)(const char *fmt, ...);
static void array_printf(const uint8_t *data, const unsigned length,
printf_t print_handler, const char type)
printf_t print_handler, const char type)
{
for (unsigned i = 0; i < length; i++) {
uint8_t ch = data[i];
......@@ -64,5 +64,4 @@ float time_diff(struct timeval *begin, struct timeval *end)
{
return (end->tv_sec - begin->tv_sec) * 1000 +
(end->tv_usec - begin->tv_usec) / 1000.0;
}
......@@ -14,16 +14,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
* \file print.h
*
* \author Marek Vavrusa <marek.vavrusa@nic.cz>
* \file
*
* \brief Custom printing functions.
*
* Downloaded hex_print, bit_print from http://www.digitalpeer.com/id/print
* Updated with generic printf handler.
*
* \addtogroup common_lib
* \addtogroup contrib
* @{
*/
......@@ -59,7 +54,7 @@ void short_hex_print(const uint8_t *data, unsigned length);
void txt_print(const uint8_t *data, unsigned length);
/*!
* \brief Get time diff in miliseconds.
* \brief Get time difference in miliseconds.
*
* \param begin
* \param end
......
/*!
* \file tolower.h
*
* \author Lubos Slovak <lubos.slovak@nic.cz>
*
* \brief Table for converting ASCII characters to lowercase.
*
* \addtogroup libknot
* @{
*/
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
......@@ -23,17 +13,18 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
* \file
*
* \brief Table for converting ASCII characters to lowercase.
*
* \addtogroup contrib
* @{
*/
#pragma once
#include <stdint.h>
#include <stdlib.h>
/*! \brief Size of the character conversion table. */
#define KNOT_CHAR_TABLE_SIZE (UINT8_MAX + 1)
/*! \brief Character table mapping uppercase letters to lowercase. */
extern const uint8_t knot_char_table[KNOT_CHAR_TABLE_SIZE];
/*!
* \brief Converts binary character to lowercase.
......@@ -43,28 +34,25 @@ extern const uint8_t knot_char_table[KNOT_CHAR_TABLE_SIZE];
* \return \a c converted to lowercase (or \a c if not applicable).
*/
static inline uint8_t knot_tolower(uint8_t c) {
return knot_char_table[c];
}
/*!
* \brief Convert binary data to lowercase (if lowercase equivalent exists).
*
* \param data Binary input string.
* \param size Size of the input string
*
* \return Lowercase representation of the input string.
*/
static inline uint8_t *knot_strtolower(const uint8_t *data, size_t size)
{
uint8_t *result = (uint8_t *)malloc(size);
if (!result)
return NULL;
for (size_t i = 0; i < size; ++i) {
result[i] = knot_tolower(data[i]);
}
return result;
const uint8_t *tolower_table = (uint8_t *)
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"
"\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F"
"\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F"
"\x40\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F"
"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x5B\x5C\x5D\x5E\x5F"
"\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F"
"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7A\x7B\x7C\x7D\x7E\x7F"
"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F"
"\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F"
"\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF"
"\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF"
"\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF"
"\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF"
"\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF"
"\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF";
return tolower_table[c];
}
/*! @} */
......@@ -26,7 +26,7 @@
#include "libknot/libknot.h"
#include "libknot/descriptor.h"
#include "libknot/internal/lists.h"
#include "libknot/internal/print.h"
#include "contrib/print.h"
/* AXFR context. @note aliasing the generic xfr_proc */
struct axfr_proc {
......
......@@ -26,9 +26,9 @@
#include "knot/zone/serial.h"
#include "libknot/libknot.h"
#include "libknot/descriptor.h"
#include "libknot/internal/print.h"
#include "libknot/internal/utils.h"
#include "libknot/rrtype/soa.h"
#include "contrib/print.h"
/* ------------------------ IXFR-out processing ----------------------------- */
......
......@@ -24,7 +24,6 @@
#include "knot/dnssec/zone-sign.h"
#include "knot/common/log.h"
#include "libknot/internal/macros.h"
#include "libknot/internal/print.h"
#include "knot/dnssec/zone-events.h"
#include "knot/updates/ddns.h"
#include "knot/updates/zone-update.h"
......@@ -37,6 +36,7 @@
#include "knot/server/udp-handler.h"
#include "knot/nameserver/capture.h"
#include "libknot/processing/requestor.h"
#include "contrib/print.h"
/* UPDATE-specific logging (internal, expects 'qdata' variable set). */
#define UPDATE_LOG(severity, msg, ...) \
......
......@@ -27,8 +27,8 @@
#include "libknot/packet/wire.h"
#include "libknot/internal/macros.h"
#include "libknot/internal/mempattern.h"
#include "libknot/internal/tolower.h"
#include "libknot/internal/utils.h"
#include "contrib/tolower.h"
/*----------------------------------------------------------------------------*/
......
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "libknot/internal/macros.h"
#include "libknot/internal/tolower.h"
const uint8_t knot_char_table[KNOT_CHAR_TABLE_SIZE] = {
'\x00',
'\x01',
'\x02',
'\x03',
'\x04',
'\x05',
'\x06',
'\x07',
'\x08',
'\x09',
'\x0A',
'\x0B',
'\x0C',
'\x0D',
'\x0E',
'\x0F',
'\x10',
'\x11',
'\x12',
'\x13',
'\x14',
'\x15',
'\x16',
'\x17',
'\x18',
'\x19',
'\x1A',
'\x1B',
'\x1C',
'\x1D',
'\x1E',
'\x1F',
'\x20',
'\x21', /* ! */
'\x22', /* " */
'\x23', /* # */
'\x24', /* $ */
'\x25', /* % */
'\x26', /* & */
'\x27', /* ' */
'\x28', /* ( */
'\x29', /* ) */
'\x2A', /* * */
'\x2B', /* + */
'\x2C', /* , */
'\x2D', /* - */
'\x2E', /* . */
'\x2F', /* / */
'\x30', /* 0 */
'\x31', /* 1 */
'\x32', /* 2 */
'\x33', /* 3 */
'\x34', /* 4 */
'\x35', /* 5 */
'\x36', /* 6 */
'\x37', /* 7 */
'\x38', /* 8 */
'\x39', /* 9 */
'\x3A', /* : */
'\x3B', /* ; */
'\x3C', /* < */
'\x3D', /* = */
'\x3E', /* > */
'\x3F', /* ? */
'\x40', /* @ */
'\x61', /* A */
'\x62', /* B */
'\x63', /* C */
'\x64', /* D */
'\x65', /* E */
'\x66', /* F */
'\x67', /* G */
'\x68', /* H */
'\x69', /* I */
'\x6A', /* J */
'\x6B', /* K */
'\x6C', /* L */
'\x6D', /* M */
'\x6E', /* N */
'\x6F', /* O */
'\x70', /* P */
'\x71', /* Q */
'\x72', /* R */
'\x73', /* S */
'\x74', /* T */
'\x75', /* U */
'\x76', /* V */
'\x77', /* W */
'\x78', /* X */
'\x79', /* Y */
'\x7A', /* Z */
'\x5B', /* [ */
'\x5C', /* \ */
'\x5D', /* ] */
'\x5E', /* ^ */
'\x5F', /* _ */
'\x60', /* ` */
'\x61', /* a */
'\x62', /* b */
'\x63', /* c */
'\x64', /* d */
'\x65', /* e */
'\x66', /* f */
'\x67', /* g */
'\x68', /* h */
'\x69', /* i */
'\x6A', /* j */
'\x6B', /* k */
'\x6C', /* l */
'\x6D', /* m */
'\x6E', /* n */
'\x6F', /* o */
'\x70', /* p */
'\x71', /* q */
'\x72', /* r */
'\x73', /* s */
'\x74', /* t */
'\x75', /* u */
'\x76', /* v */
'\x77', /* w */
'\x78', /* x */
'\x79', /* y */
'\x7A', /* z */
'\x7B', /* { */
'\x7C', /* | */
'\x7D', /* } */
'\x7E', /* ~ */
'\x7F',
'\x80',
'\x81',
'\x82',
'\x83',
'\x84',
'\x85',
'\x86',
'\x87',
'\x88',
'\x89',
'\x8A',
'\x8B',
'\x8C',
'\x8D',
'\x8E',
'\x8F',
'\x90',
'\x91',
'\x92',
'\x93',
'\x94',
'\x95',
'\x96',
'\x97',
'\x98',
'\x99',
'\x9A',
'\x9B',
'\x9C',
'\x9D',
'\x9E',
'\x9F',
'\xA0',
'\xA1',
'\xA2',
'\xA3',
'\xA4',
'\xA5',
'\xA6',
'\xA7',
'\xA8',
'\xA9',
'\xAA',
'\xAB',
'\xAC',
'\xAD',
'\xAE',
'\xAF',
'\xB0',
'\xB1',
'\xB2',
'\xB3',
'\xB4',
'\xB5',
'\xB6',
'\xB7',
'\xB8',
'\xB9',
'\xBA',
'\xBB',
'\xBC',
'\xBD',
'\xBE',
'\xBF',
'\xC0',
'\xC1',
'\xC2',
'\xC3',
'\xC4',
'\xC5',
'\xC6',
'\xC7',
'\xC8',
'\xC9',
'\xCA',
'\xCB',
'\xCC',
'\xCD',
'\xCE',
'\xCF',
'\xD0',
'\xD1',
'\xD2',
'\xD3',
'\xD4',
'\xD5',
'\xD6',
'\xD7',
'\xD8',
'\xD9',
'\xDA',
'\xDB',
'\xDC',
'\xDD',
'\xDE',
'\xDF',
'\xE0',
'\xE1',
'\xE2',
'\xE3',
'\xE4',
'\xE5',
'\xE6',
'\xE7',
'\xE8',
'\xE9',
'\xEA',
'\xEB',
'\xEC',
'\xED',
'\xEE',
'\xEF',
'\xF0',
'\xF1',
'\xF2',
'\xF3',
'\xF4',
'\xF5',
'\xF6',
'\xF7',
'\xF8',
'\xF9',
'\xFA',
'\xFB',
'\xFC',
'\xFD',
'\xFE',
'\xFF',
};
......@@ -20,7 +20,7 @@
#include "libknot/errcode.h"
#include "libknot/packet/pkt.h"
#include "libknot/internal/macros.h"
#include "libknot/internal/tolower.h"
#include "contrib/tolower.h"
/*! \brief Case insensitive label compare for compression. */
static bool compr_label_match(const uint8_t *n, const uint8_t *p)
......
......@@ -19,7 +19,7 @@
#include "libknot/rrtype/nsec3.h"
#include "libknot/errcode.h"
#include "libknot/internal/macros.h"
#include "libknot/internal/tolower.h"
#include "contrib/tolower.h"
_public_
void knot_nsec3_bitmap(const knot_rdataset_t *rrs, size_t pos,
......
......@@ -25,9 +25,9 @@
#include "utils/common/params.h"
#include "libknot/libknot.h"
#include "libknot/internal/lists.h"
#include "libknot/internal/print.h"
#include "libknot/internal/sockaddr.h"
#include "libknot/internal/wire_ctx.h"
#include "contrib/print.h"
#include "contrib/openbsd/strlcat.h"
static lookup_table_t rtypes[] = {
......
......@@ -26,8 +26,8 @@
#include "utils/common/sign.h"
#include "libknot/libknot.h"
#include "libknot/internal/lists.h"
#include "libknot/internal/print.h"
#include "libknot/internal/sockaddr.h"
#include "contrib/print.h"
#if USE_DNSTAP
# include "dnstap/convert.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment