From e14bb203118a2d82c28d73a5b63b7040b5b8784a Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 4 Feb 2023 16:48:49 +0200 Subject: [PATCH 32/32] Move some definitions from packets.h and connection.h to new conn_types.h See osdn #47306 Signed-off-by: Marko Lindqvist --- common/networking/Makefile.am | 1 + common/networking/conn_types.h | 72 ++++++++++++++++++++++++++++++++++ common/networking/connection.h | 13 ++---- common/networking/packets.h | 37 +---------------- 4 files changed, 79 insertions(+), 44 deletions(-) create mode 100644 common/networking/conn_types.h diff --git a/common/networking/Makefile.am b/common/networking/Makefile.am index e9a93e0b1a..ccd88ecc7c 100644 --- a/common/networking/Makefile.am +++ b/common/networking/Makefile.am @@ -13,6 +13,7 @@ AM_CPPFLAGS = \ libfcivnetwork_la_SOURCES = \ connection.c \ connection.h \ + conn_types.h \ dataio.h \ dataio_json.c \ dataio_json.h \ diff --git a/common/networking/conn_types.h b/common/networking/conn_types.h new file mode 100644 index 0000000000..22788e4f0c --- /dev/null +++ b/common/networking/conn_types.h @@ -0,0 +1,72 @@ +/*********************************************************************** + Freeciv - Copyright (C) 2023 - The Freeciv Team + 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 2, 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. +***********************************************************************/ +#ifndef FC__CONN_TYPES_H +#define FC__CONN_TYPES_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* common/networking/ related type definitions. + * + * Like common/fc_types.h, + * this file serves to reduce the cross-inclusion of header files which + * occurs when a type which is defined in one file is needed for a function + * definition in another file. + */ + +/* Used in the network protocol. */ +#define MAX_LEN_PACKET 4096 +#define MAX_LEN_CAPSTR 512 +#define MAX_LEN_PASSWORD 512 /* Do not change this under any circumstances */ +#define MAX_LEN_CONTENT (MAX_LEN_PACKET - 20) + +#define MAX_LEN_BUFFER (MAX_LEN_PACKET * 128) + +/* Used in network protocol. */ +#define MAX_LEN_MSG 1536 +#define MAX_LEN_ROUTE 2000 /* MAX_LEN_PACKET / 2 - header */ + +/* Used in network protocol. */ +enum authentication_type { + AUTH_LOGIN_FIRST, /* Request a password for a returning user */ + AUTH_NEWUSER_FIRST, /* Request a password for a new user */ + AUTH_LOGIN_RETRY, /* Inform the client to try a different password */ + AUTH_NEWUSER_RETRY /* Inform the client to try a different [new] password */ +}; + +/* Used in network protocol. */ +enum report_type { + REPORT_WONDERS_OF_THE_WORLD, + REPORT_WONDERS_OF_THE_WORLD_LONG, + REPORT_TOP_CITIES, + REPORT_DEMOGRAPHIC, + REPORT_ACHIEVEMENTS +}; + +/* The size of opaque (void *) data sent in the network packet. To avoid + * fragmentation issues, this SHOULD NOT be larger than the standard + * ethernet or PPP 1500 byte frame size (with room for headers). + * + * Do not spend much time optimizing, you have no idea of the actual dynamic + * path characteristics between systems, such as VPNs and tunnels. + * + * Used in network protocol. + */ +#define ATTRIBUTE_CHUNK_SIZE (1400) + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* FC__CONN_TYPES_H */ diff --git a/common/networking/connection.h b/common/networking/connection.h index a970be857c..c7577c0505 100644 --- a/common/networking/connection.h +++ b/common/networking/connection.h @@ -17,7 +17,7 @@ extern "C" { #endif /* __cplusplus */ -#include /* time_t */ +#include /* time_t */ #ifdef FREECIV_HAVE_SYS_TYPES_H #include @@ -47,19 +47,14 @@ extern "C" { /* common */ #include "fc_types.h" +/* common/networking */ +#include "conn_types.h" + struct conn_pattern_list; struct genhash; struct packet_handlers; struct timer_list; -/* Used in the network protocol. */ -#define MAX_LEN_PACKET 4096 -#define MAX_LEN_CAPSTR 512 -#define MAX_LEN_PASSWORD 512 /* do not change this under any circumstances */ -#define MAX_LEN_CONTENT (MAX_LEN_PACKET - 20) - -#define MAX_LEN_BUFFER (MAX_LEN_PACKET * 128) - /**************************************************************************** Command access levels for client-side use; at present, they are only used to control access to server commands typed at the client chatline. diff --git a/common/networking/packets.h b/common/networking/packets.h index c958727871..d756701cbd 100644 --- a/common/networking/packets.h +++ b/common/networking/packets.h @@ -17,14 +17,10 @@ extern "C" { #endif /* __cplusplus */ -struct connection; -struct data_in; - /* utility */ #include "shared.h" /* MAX_LEN_ADDR */ /* common */ -#include "connection.h" /* struct connection, MAX_LEN_* */ #include "diptreaty.h" #include "effects.h" #include "events.h" @@ -38,10 +34,9 @@ struct data_in; #include "unittype.h" #include "worklist.h" +struct connection; +struct data_in; -/* Used in network protocol. */ -#define MAX_LEN_MSG 1536 -#define MAX_LEN_ROUTE 2000 /* MAX_LEN_PACKET / 2 - header */ #ifdef FREECIV_WEB #define web_send_packet(packetname, pconn, ...) \ @@ -62,31 +57,11 @@ do { \ #define web_lsend_packet(packetname, ...) #endif /* FREECIV_WEB */ -/* The size of opaque (void *) data sent in the network packet. To avoid - * fragmentation issues, this SHOULD NOT be larger than the standard - * ethernet or PPP 1500 byte frame size (with room for headers). - * - * Do not spend much time optimizing, you have no idea of the actual dynamic - * path characteristics between systems, such as VPNs and tunnels. - * - * Used in network protocol. - */ -#define ATTRIBUTE_CHUNK_SIZE (1400) - /* Indicates that the player initiated a request. * * Used in network protocol. */ #define REQEST_PLAYER_INITIATED (0) -/* Used in network protocol. */ -enum report_type { - REPORT_WONDERS_OF_THE_WORLD, - REPORT_WONDERS_OF_THE_WORLD_LONG, - REPORT_TOP_CITIES, - REPORT_DEMOGRAPHIC, - REPORT_ACHIEVEMENTS -}; - /* Used in network protocol. */ enum unit_info_use { UNIT_INFO_IDENTITY, @@ -94,14 +69,6 @@ enum unit_info_use { UNIT_INFO_CITY_PRESENT }; -/* Used in network protocol. */ -enum authentication_type { - AUTH_LOGIN_FIRST, /* request a password for a returning user */ - AUTH_NEWUSER_FIRST, /* request a password for a new user */ - AUTH_LOGIN_RETRY, /* inform the client to try a different password */ - AUTH_NEWUSER_RETRY /* inform the client to try a different [new] password */ -}; - #include "packets_gen.h" struct packet_handlers { -- 2.39.1