Freeciv-3.2
Loading...
Searching...
No Matches
Macros | Functions
packets_json.h File Reference
#include <jansson.h>

Go to the source code of this file.

Macros

#define log_packet_json   log_debug
 
#define SEND_PACKET_START(packet_type)
 
#define SEND_PACKET_END(packet_type)
 
#define SEND_PACKET_DISCARD()
 
#define RECEIVE_PACKET_START(packet_type, result)
 
#define RECEIVE_PACKET_END(result)
 
#define RECEIVE_PACKET_FIELD_ERROR(field, ...)
 
#define PACKET_STRVEC_SEPARATOR   '\3'
 
#define PACKET_STRVEC_COMPUTE(str, strvec)
 
#define PACKET_STRVEC_EXTRACT(strvec, str)
 

Functions

voidget_packet_from_connection_json (struct connection *pc, enum packet_type *ptype)
 

Macro Definition Documentation

◆ log_packet_json

#define log_packet_json   log_debug

Definition at line 22 of file packets_json.h.

◆ PACKET_STRVEC_COMPUTE

#define PACKET_STRVEC_COMPUTE (   str,
  strvec 
)
Value:
if (NULL != strvec) { \
} else { \
str[0] = '\0'; \
}
#define str
Definition astring.c:76
char * incite_cost
Definition comments.c:75
#define PACKET_STRVEC_SEPARATOR

Definition at line 116 of file packets_json.h.

◆ PACKET_STRVEC_EXTRACT

#define PACKET_STRVEC_EXTRACT (   strvec,
  str 
)
Value:
if ('\0' != str[0]) { \
} else { \
strvec = NULL; \
}
struct strvec * strvec_new(void)

Definition at line 122 of file packets_json.h.

◆ PACKET_STRVEC_SEPARATOR

#define PACKET_STRVEC_SEPARATOR   '\3'

Definition at line 115 of file packets_json.h.

◆ RECEIVE_PACKET_END

#define RECEIVE_PACKET_END (   result)
Value:
if (pc->json_mode) { \
json_decref(pc->json_packet); \
result = fc_malloc(sizeof(*result)); \
*result = packet_buf; \
return result; \
} else { \
return NULL; \
} \
result = fc_malloc(sizeof(*result)); \
*result = packet_buf; \
return result; \
}
#define fc_malloc(sz)
Definition mem.h:34
bool packet_check(struct data_in *din, struct connection *pc)
Definition packets.c:665

Definition at line 94 of file packets_json.h.

◆ RECEIVE_PACKET_FIELD_ERROR

#define RECEIVE_PACKET_FIELD_ERROR (   field,
  ... 
)
Value:
log_packet("Error on field '" #field "'" __VA_ARGS__); \
return NULL;
#define log_packet
Definition log.h:137

Definition at line 110 of file packets_json.h.

◆ RECEIVE_PACKET_START

#define RECEIVE_PACKET_START (   packet_type,
  result 
)
Value:
struct packet_type packet_buf, *result = &packet_buf; \
struct data_in din; \
if (!pc->json_mode) { \
dio_input_init(&din, pc->buffer->data, \
data_type_size(pc->packet_header.length)); \
{ \
int size; \
dio_get_type_raw(&din, pc->packet_header.length, &size); \
dio_input_init(&din, pc->buffer->data, MIN(size, pc->buffer->ndata)); \
} \
dio_input_skip(&din, (data_type_size(pc->packet_header.length) \
+ data_type_size(pc->packet_header.type))); \
}
size_t data_type_size(enum data_type type)
Definition dataio_raw.c:229
packet_type
#define MIN(x, y)
Definition shared.h:55
size_t size
Definition specvec.h:72

Definition at line 78 of file packets_json.h.

◆ SEND_PACKET_DISCARD

#define SEND_PACKET_DISCARD ( )
Value:
{ \
if (pc->json_mode) { \
} \
return 0; \
}

Definition at line 70 of file packets_json.h.

◆ SEND_PACKET_END

#define SEND_PACKET_END (   packet_type)
Value:
{ \
size_t size; \
if (pc->json_mode) { \
log_packet_json("Json out: %s", json_buffer); \
} \
} else { \
dio_put_type_raw(&dout.raw, pc->packet_header.length, size); \
} \
fc_assert(!dout.raw.too_short); \
return send_packet_data(pc, buffer, size, packet_type); \
}
size_t dio_output_used(struct raw_data_out *dout)
Definition dataio_raw.c:184
int send_packet_data(struct connection *pc, unsigned char *data, int len, enum packet_type packet_type)
Definition packets.c:213

Definition at line 45 of file packets_json.h.

◆ SEND_PACKET_START

#define SEND_PACKET_START (   packet_type)
Value:
unsigned char buffer[MAX_LEN_PACKET * 5]; \
struct plocation *pid_addr; \
char *json_buffer = NULL; \
dio_output_init(&(dout.raw), buffer, sizeof(buffer)); \
if (pc->json_mode) { \
dout.json = json_object(); \
} else { \
dout.json = NULL; \
dio_put_type_raw(&dout.raw, pc->packet_header.length, 0); \
dio_put_type_raw(&dout.raw, pc->packet_header.type, packet_type); \
}
#define MAX_LEN_PACKET
Definition conn_types.h:29
struct plocation * plocation_field_new(char *name)

Definition at line 27 of file packets_json.h.

Function Documentation

◆ get_packet_from_connection_json()

void * get_packet_from_connection_json ( struct connection pc,
enum packet_type ptype 
)