Author: cazfi Date: Wed Jan 27 18:13:26 2016 New Revision: 31638 URL: http://svn.gna.org/viewcvs/freeciv?rev=31638&view=rev Log: Fixed get_conv callback use when json protocol is in use.
See bug #24345 Modified: trunk/common/dataio.c trunk/common/dataio.h trunk/common/dataio_json.c trunk/common/dataio_json.h Modified: trunk/common/dataio.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/dataio.c?rev=31638&r1=31637&r2=31638&view=diff ============================================================================== --- trunk/common/dataio.c (original) +++ trunk/common/dataio.c Wed Jan 27 18:13:26 2016 @@ -131,6 +131,15 @@ void dio_set_get_conv_callback(DIO_GET_CONV_FUN fun) { get_conv_callback = fun; +} + +/************************************************************************** + Call the get_conv callback. +**************************************************************************/ +bool dataio_get_conv_callback(char *dst, size_t ndst, const char *src, + size_t nsrc) +{ + return get_conv_callback(dst, ndst, src, nsrc); } /************************************************************************** Modified: trunk/common/dataio.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/dataio.h?rev=31638&r1=31637&r2=31638&view=diff ============================================================================== --- trunk/common/dataio.h (original) +++ trunk/common/dataio.h Wed Jan 27 18:13:26 2016 @@ -89,6 +89,9 @@ const char *src, size_t nsrc); void dio_set_get_conv_callback(DIO_GET_CONV_FUN fun); +bool dataio_get_conv_callback(char *dst, size_t ndst, const char *src, + size_t nsrc); + /* General functions */ void dio_output_init(struct raw_data_out *dout, void *destination, size_t dest_size); Modified: trunk/common/dataio_json.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/dataio_json.c?rev=31638&r1=31637&r2=31638&view=diff ============================================================================== --- trunk/common/dataio_json.c (original) +++ trunk/common/dataio_json.c Wed Jan 27 18:13:26 2016 @@ -70,11 +70,6 @@ #include "dataio.h" -static bool get_conv(char *dst, size_t ndst, const char *src, - size_t nsrc); - -static DIO_GET_CONV_FUN get_conv_callback = get_conv; - /************************************************************************** Returns a CURL easy handle for name encoding and decoding **************************************************************************/ @@ -90,27 +85,6 @@ } return curl_easy_handle; -} - -/************************************************************************** - Returns FALSE if the destination isn't large enough or the source was - bad. This is default get_conv_callback. -**************************************************************************/ -static bool get_conv(char *dst, size_t ndst, const char *src, - size_t nsrc) -{ - size_t len = nsrc; /* length to copy, not including null */ - bool ret = TRUE; - - if (ndst > 0 && len >= ndst) { - ret = FALSE; - len = ndst - 1; - } - - memcpy(dst, src, len); - dst[len] = '\0'; - - return ret; } static void plocation_write_data(json_t *item, @@ -809,14 +783,17 @@ char *dest, size_t max_dest_size) { json_t *pstring = plocation_read_data(json_packet, location); + const char *result_str; if (!pstring) { log_error("ERROR: Unable to get string with key: %s", key); return FALSE; } - const char *result_str = json_string_value(pstring); - - if (dest && !(*get_conv_callback) (dest, max_dest_size, result_str, strlen(result_str))) { + + result_str = json_string_value(pstring); + + if (dest + && !dataio_get_conv_callback(dest, max_dest_size, result_str, strlen(result_str))) { log_error("ERROR: Unable to get string with key: %s", key); return FALSE; } Modified: trunk/common/dataio_json.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/common/dataio_json.h?rev=31638&r1=31637&r2=31638&view=diff ============================================================================== --- trunk/common/dataio_json.h (original) +++ trunk/common/dataio_json.h Wed Jan 27 18:13:26 2016 @@ -29,19 +29,6 @@ struct raw_data_out raw; json_t *json; }; - -/* network string conversion */ -typedef char *(*DIO_PUT_CONV_FUN) (const char *src, size_t *length); -void dio_set_put_conv_callback(DIO_PUT_CONV_FUN fun); - -typedef bool(*DIO_GET_CONV_FUN) (char *dst, size_t ndst, - const char *src, size_t nsrc); -void dio_set_get_conv_callback(DIO_GET_CONV_FUN fun); - -/* General functions */ -void dio_input_rewind(struct data_in *din); - -size_t data_type_size(enum data_type type); /* gets */ bool dio_get_type_json(struct data_in *din, enum data_type type, int *dest) _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits