Commit a1237e22 authored by Jan Kadlec's avatar Jan Kadlec

Modified Makefile - removed ldns linking.

Added one function to parser-util.c - mktime_from_utc - although this has been done before (lost in merge?)
Modified zoneparser.h header
Refs #280
parent 255ca032
......@@ -35,7 +35,7 @@ CC = gcc
CFLAGS_DEBUG = -g -O0
CFLAGS_OPTIMAL = -O2 -funroll-loops -fomit-frame-pointer
CFLAGS += -Wall -std=gnu99 -D _XOPEN_SOURCE=600 -D_GNU_SOURCE
LDFLAGS += -lpthread -lurcu -lldns -lrt -lm
LDFLAGS += -lpthread -lurcu -lrt -lm
all: cutedns unittests zoneparser
ifeq ($(DEBUG),1)
......
......@@ -97,10 +97,7 @@ size_t strlcpy(char *dst, const char *src, size_t siz)
* Paul Vixie, 1996.
*/
int
inet_pton(af, src, dst)
int af;
const char *src;
void *dst;
inet_pton(int af, const char *src, void *dst)
{
switch (af) {
case AF_INET:
......@@ -921,3 +918,50 @@ strtottl(const char *nptr, const char **endptr)
return seconds;
}
/* Number of days per month (except for February in leap years). */
static const int mdays[] = {
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
static int
is_leap_year(int year)
{
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}
static int
leap_days(int y1, int y2)
{
--y1;
--y2;
return (y2/4 - y1/4) - (y2/100 - y1/100) + (y2/400 - y1/400);
}
/*
* Code adapted from Python 2.4.1 sources (Lib/calendar.py).
*/
time_t
mktime_from_utc(const struct tm *tm)
{
int year = 1900 + tm->tm_year;
time_t days = 365 * (year - 1970) + leap_days(1970, year);
time_t hours;
time_t minutes;
time_t seconds;
int i;
for (i = 0; i < tm->tm_mon; ++i) {
days += mdays[i];
}
if (tm->tm_mon > 1 && is_leap_year(year)) {
++days;
}
days += tm->tm_mday - 1;
hours = days * 24 + tm->tm_hour;
minutes = hours * 60 + tm->tm_min;
seconds = minutes * 60 + tm->tm_sec;
return seconds;
}
/*
* zonec.h -- zone compiler.
/*!
* \file zoneparser.h
*
* Copyright (c) 2001-2006, NLnet Labs. All rights reserved.
* \author modifications by Jan Kadlec <jan.kadlec@nic.cz>, most of the code
* by NLnet Labs
* Copyright (c) 2001-2006, NLnet Labs. All rights reserved.
* See LICENSE for the license.
*
* See LICENSE for the license.
* \brief Zone compiler.
*
* \addtogroup zoneparser
* @{
*/
#ifndef _ZONEC_H_
#define _ZONEC_H_
#ifndef _CUTEDNS_ZONEPARSER_H_
#define _CUTEDNS_ZONEPARSER_H_
#include <stdio.h>
......@@ -121,7 +126,8 @@ uint8_t *zparser_conv_b32(const char *b32);
uint8_t *zparser_conv_b64(const char *b64);
uint8_t *zparser_conv_rrtype(const char *rr);
uint8_t *zparser_conv_nxt(uint8_t nxtbits[]);
uint8_t *zparser_conv_nsec(uint8_t nsecbits[NSEC_WINDOW_COUNT][NSEC_WINDOW_BITS_SIZE]);
uint8_t *zparser_conv_nsec(uint8_t nsecbits[NSEC_WINDOW_COUNT]
[NSEC_WINDOW_BITS_SIZE]);
uint8_t *zparser_conv_loc(char *str);
uint8_t *zparser_conv_algorithm(const char *algstr);
uint8_t *zparser_conv_certificate_type(const char *typestr);
......@@ -149,4 +155,6 @@ void zparser_init(const char *filename, uint32_t ttl, uint16_t rclass,
void zparser_free();
#endif /* _ZONEC_H_ */
#endif /* _CUTEDNS_ZONEPARSER_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