18#ifdef FREECIV_JSON_CONNECTION
27#ifdef HAVE_ARPA_INET_H
30#ifdef HAVE_NETINET_IN_H
31#include <netinet/in.h>
56#define PACKET_SIZE_STATISTICS 0
60#define SPECHASH_TAG packet_handler
61#define SPECHASH_ASTR_KEY_TYPE
62#define SPECHASH_IDATA_TYPE struct packet_handlers *
63#define SPECHASH_IDATA_FREE (packet_handler_hash_data_free_fn_t) free
110 log_verbose(
"The packet stream is corrupt. The connection "
111 "will be closed now.");
122 if (
is_server() &&
pc->server.last_request_id_seen == 0) {
128 pc->json_mode = (
pc->json_packet !=
NULL);
137 if (!
pc->json_packet) {
138 log_error(
"ERROR: Unable to parse packet: %s",
pc->buffer->data + 2);
149 if (!
pc->json_packet) {
156 log_error(
"ERROR: Unable to get packet type.");
163 utype.type = utype.itype;
167 || (receive_handler =
pc->phs.handlers->receive[utype.type]) ==
NULL) {
168 log_verbose(
"Received unsupported packet type %d (%s). The connection "
169 "will be closed now.",
176 log_packet(
"got packet type=(%s) len=%d from %s",
182 if (
pc->incoming_packet_notify) {
186#if PACKET_SIZE_STATISTICS
219 log_test(
" [%-25.25s %3d]: %6d packets; %8d bytes total; "
220 "%5d bytes/packet average",
226 log_test(
"received %d bytes in %d packets;average size "
227 "per packet %d bytes",
233 data = receive_handler(
pc);
void connection_close(struct connection *pconn, const char *reason)
bool dio_get_uint16_raw(struct data_in *din, int *dest)
bool dio_get_type_raw(struct data_in *din, enum data_type type, int *dest)
size_t data_type_size(enum data_type type)
void dio_input_init(struct data_in *din, const void *src, size_t src_size)
static bool is_server(void)
#define log_verbose(message,...)
#define log_error(message,...)
const char *const packet_functional_capability
const char * packet_name(enum packet_type type)
void * get_packet_from_connection_json(struct connection *pc, enum packet_type *ptype)