220 lines
5.6 KiB
C
220 lines
5.6 KiB
C
/*-
|
|
* Copyright (c) 2017-2018 Carsten Sonne Larsen <cs@innolan.net>
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*
|
|
*/
|
|
|
|
#ifndef CONFIG_H_INCLUDED
|
|
#define CONFIG_H_INCLUDED
|
|
|
|
#include <exec/io.h>
|
|
#include <exec/types.h>
|
|
#include <exec/memory.h>
|
|
#include <exec/devices.h>
|
|
#include <exec/libraries.h>
|
|
#include <resources/battclock.h>
|
|
#include <libraries/asl.h>
|
|
#include <libraries/commodities.h>
|
|
#include <dos/dos.h>
|
|
#include <dos/dostags.h>
|
|
#include <proto/dos.h>
|
|
#include <proto/asl.h>
|
|
#include <proto/exec.h>
|
|
#include <proto/icon.h>
|
|
#include <proto/timer.h>
|
|
#include <proto/locale.h>
|
|
#include <proto/utility.h>
|
|
#include <proto/gadtools.h>
|
|
#include <proto/intuition.h>
|
|
#include <proto/battclock.h>
|
|
#include <proto/commodities.h>
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <math.h>
|
|
|
|
#include "compiler.h"
|
|
|
|
//#define DEBUG_BUILD 1
|
|
|
|
#if defined(AROS) || defined(__CLIB2__)
|
|
#include <stdint.h>
|
|
#endif
|
|
|
|
#if defined(__libnix__)
|
|
typedef u_int8_t uint8_t;
|
|
typedef u_int16_t uint16_t;
|
|
typedef u_int32_t uint32_t;
|
|
typedef u_int64_t uint64_t;
|
|
typedef uint32_t uintptr_t;
|
|
#endif
|
|
|
|
#if defined(__CLIB2__)
|
|
#define __NO_NET_API
|
|
#define NO_INLINE_STDARG
|
|
#endif
|
|
|
|
#if defined(AROS) || defined(__CLIB2__)
|
|
#include <proto/socket.h>
|
|
#include <bsdsocket/socketbasetags.h>
|
|
#endif
|
|
|
|
#if defined(__libnix__)
|
|
#include <amitcp/socketbasetags.h>
|
|
#include "clib/amitcp_protos.h"
|
|
#endif
|
|
|
|
#if defined(__libnix__) || defined(__CLIB2__)
|
|
#include "netdb.h"
|
|
#include "sys/errno.h"
|
|
#include "sys/socket.h"
|
|
#include "netinet/in.h"
|
|
#else
|
|
#include <netdb.h>
|
|
#include <sys/errno.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#endif
|
|
|
|
#ifdef MAXPATHLEN
|
|
#undef MAXPATHLEN
|
|
#endif
|
|
#ifdef MAXFILELEN
|
|
#undef MAXFILELEN
|
|
#endif
|
|
#ifdef MAXFILEPATHLEN
|
|
#undef MAXFILEPATHLEN
|
|
#endif
|
|
#define MAXPATHLEN 1792
|
|
#define MAXFILELEN 256
|
|
#define MAXFILEPATHLEN MAXPATHLEN + MAXFILELEN
|
|
#define MAXDOSERRORLEN 256
|
|
#define SETTINGMESSAGELEN 128
|
|
|
|
#ifndef HAVE_POLL
|
|
#define POLLIN 0x0001
|
|
struct pollfd
|
|
{
|
|
int fd;
|
|
short events;
|
|
short revents;
|
|
};
|
|
typedef unsigned int nfds_t;
|
|
int poll(struct pollfd *, nfds_t, int);
|
|
#endif
|
|
|
|
#if AOS3
|
|
#define IPTR ULONG
|
|
#endif
|
|
#if AOS3
|
|
#define VARSIZE 0
|
|
#else
|
|
#define VARSIZE 1
|
|
#endif
|
|
|
|
#ifdef AROS
|
|
#define VSNPrintf(str, n, format, args) vsnprintf(str, n, format, args)
|
|
#define SNPrintf(str, n, format, ...) snprintf(str, n, format, __VA_ARGS__)
|
|
#endif
|
|
|
|
#define LIB_OK 0
|
|
#define COM_OK 0
|
|
#define LIB_ERROR -1
|
|
#define COM_ERROR -1
|
|
|
|
#define APP_SHORT_NAME "AmiTimeKeeper"
|
|
#define APP_LONG_NAME "Amiga Time Keeper"
|
|
#define APP_VERSION "1.05"
|
|
#define APP_DATE_VERSION "1.05 (06.08.2018)"
|
|
#define APP_ID APP_SHORT_NAME " " APP_DATE_VERSION
|
|
#define APP_TITLE APP_LONG_NAME " " APP_DATE_VERSION
|
|
#define APP_TITLE_VERSION APP_LONG_NAME " " APP_VERSION
|
|
|
|
#include "log.h"
|
|
#include "state.h"
|
|
#include "string.h"
|
|
|
|
#define KEYWORD_COUNT 9
|
|
#define KEYWORD_SERVER "SERVER"
|
|
#define KEYWORD_PORT "PORT"
|
|
#define KEYWORD_THRESHOLD "THRESHOLD"
|
|
#define KEYWORD_INTERVAL "INTERVAL"
|
|
#define KEYWORD_PRIORITY "CX_PRIORITY"
|
|
#define KEYWORD_READONLY "READONLY"
|
|
#define KEYWORD_TIMEOUT "TIMEOUT"
|
|
#define KEYWORD_VERBOSE "VERBOSE"
|
|
#define KEYWORD_LOGFILE "LOGFILE"
|
|
|
|
#define SERVER_DEF "pool.ntp.org"
|
|
#define PORT_DEF "123"
|
|
#define THRESHOLD_MIN 1000LL
|
|
#define THRESHOLD_DEF 1000000LL
|
|
#define INTERVAL_MIN 500
|
|
#define INTERVAL_DEF 17500
|
|
#define PRIORITY_MIN -128
|
|
#define PRIORITY_DEF 25
|
|
#define PRIORITY_MAX 127
|
|
#define READONLY_DEF 0
|
|
#define TIMEOUT_MIN 100
|
|
#define TIMEOUT_DEF 5000
|
|
#define TIMEOUT_MAX 30000
|
|
#define VERBOSE_MIN 0
|
|
#define VERBOSE_DEF 0
|
|
#define VERBOSE_MAX 3
|
|
#define LOGFILE_DEF NULL
|
|
|
|
#define KEYWORD_TEMPLATE_1 KEYWORD_READONLY "/S," KEYWORD_SERVER "/K," KEYWORD_PORT "/K," KEYWORD_TIMEOUT "/N/K," KEYWORD_THRESHOLD "/K,"
|
|
#define KEYWORD_TEMPLATE_2 KEYWORD_INTERVAL "/N/K," KEYWORD_VERBOSE "/N/K," KEYWORD_PRIORITY "/N/K," KEYWORD_LOGFILE "/K"
|
|
#define KEYWORD_TEMPLATE KEYWORD_TEMPLATE_1 KEYWORD_TEMPLATE_2
|
|
|
|
/* broker.c */
|
|
void StartBroker(void);
|
|
void SetBrokerPriority(int);
|
|
void ShutdownBroker(void);
|
|
|
|
/* com.c */
|
|
void StartCom(void);
|
|
void StopComAsync(void);
|
|
void RestartSntpAsync(void);
|
|
bool CheckComClosed(void);
|
|
|
|
/* win_main.c */
|
|
void ShowSettingWindow(void);
|
|
void HideSettingWindow(void);
|
|
|
|
/* libraries.c */
|
|
int OpenLibraries(void);
|
|
void CloseLibraries(void);
|
|
|
|
/* net.c */
|
|
int OpenSocketLibrary(void);
|
|
void CloseSocketLibrary(void);
|
|
const char *GetErrorText(void);
|
|
const char *GetHostErrorText(void);
|
|
int GetErrorNo(void);
|
|
int GetHostErrorNo(void);
|
|
extern struct Library *SocketBase;
|
|
|
|
#endif
|