Freeciv-3.3: /fast/freeciv/nightly/main/common/networking/dataio_json.c Source File

Freeciv-3.3

Loading...
Searching...
No Matches
dataio_json.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#ifdef FREECIV_JSON_CONNECTION
19
20#include "fc_prehdrs.h"
21
22#include <curl/curl.h>
23
24#include <limits.h>
25#include <math.h>
26#include <stdint.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30
31#ifdef FREECIV_HAVE_SYS_TYPES_H
32#include <sys/types.h>
33#endif
34#ifdef HAVE_SYS_SOCKET_H
35#include <sys/socket.h>
36#endif
37#ifdef HAVE_NETINET_IN_H
38#include <netinet/in.h>
39#endif
40#ifdef HAVE_ARPA_INET_H
41#include <arpa/inet.h>
42#endif
43
44/* utility */
45#include "bitvector.h"
46#include "capability.h"
47#include "log.h"
48#include "mem.h"
49#include "support.h"
50
51/* common */
52#include "events.h"
53#include "player.h"
54#include "requirements.h"
55#include "tech.h"
56#include "worklist.h"
57
58/* common/aicore */
59#include "cm.h"
60
61#include "dataio.h"
62
63static bool dio_get_bool8_json_internal(json_t *json_packet,
64 const struct plocation *location,
65 bool *dest);
66
67/**********************************************************************/
70static CURL *get_curl(void)
71{
72 static CURL *curl_easy_handle = NULL;
73
74 if (curl_easy_handle == NULL) {
75 curl_easy_handle = curl_easy_init();
76 } else {
77 /* Reuse the existing CURL easy handle */
78 curl_easy_reset(curl_easy_handle);
79 }
80
81 return curl_easy_handle;
82}
83
84static int plocation_write_data(json_t *item,
85 const struct plocation *location,
86 json_t *data);
87
88/**********************************************************************/
91static int plocation_write_field(json_t *item,
92 const struct plocation *location,
93 json_t *data)
94{
95 int e = -1;
96
97 if (location->sub_location == NULL) {
98 e = json_object_set_new(item, location->name, data);
99 } else {
100 e = plocation_write_data(json_object_get(item, location->name),
101 location->sub_location, data);
102 }
103
104 return e;
105}
106
107/**********************************************************************/
110static int plocation_write_elem(json_t *item,
111 const struct plocation *location,
112 json_t *data)
113{
114 int e = -1;
115
116 if (location->sub_location == NULL) {
117 if (location->number == -1) {
118 e = json_array_append_new(item, data);
119 } else {
120 e = json_array_set_new(item, location->number, data);
121 }
122 } else {
123 // PTZ200718 handles last element get case...
124 // better here than all around put_array-diff algo ?
125 size_t n = (location->number == -1)
126 ? (json_array_size(item) - 1)
127 : location->number;
128
129 json_t *sub_item = json_array_get(item, n);
130
131 if (json_is_array(sub_item)) {
132 e = plocation_write_data(sub_item,
133 location->sub_location, data);
134 } else {
135 log_error("ERROR:plocation_write_elem:array not found for sub location:"
136 "%s @[" SIZE_T_PRINTF "]",
137 json_dumps(item, JSON_DECODE_ANY), location->number);
138 }
139 }
140
141 return e;
142}
143
144/**********************************************************************/
148static int plocation_write_data(json_t *item,
149 const struct plocation *location,
150 json_t *data)
151{
152 int e = -1;
153
154 switch (location->kind) {
155 case PADR_FIELD:
156 e = plocation_write_field(item, location, data);
157 break;
158 case PADR_ELEMENT:
159 e = plocation_write_elem(item, location, data);
160 break;
161 default:
162 log_error("Unknown packet part location kind.");
163 break;
164 }
165
166 return e;
167}
168
169static json_t *plocation_read_data(json_t *item,
170 const struct plocation *location);
171
172/**********************************************************************/
175static json_t *plocation_read_field(json_t *item,
176 const struct plocation *location)
177{
178 if (location->sub_location == NULL) {
179 return json_object_get(item, location->name);
180 } else {
181 return plocation_read_data(json_object_get(item, location->name),
182 location->sub_location);
183 }
184}
185
186/**********************************************************************/
189static json_t *plocation_read_elem(json_t *item,
190 const struct plocation *location)
191{
192 if (location->sub_location == NULL) {
193 return json_array_get(item, location->number);
194 } else {
195 return plocation_read_data(json_array_get(item, location->number),
196 location->sub_location);
197 }
198}
199
200/**********************************************************************/
203static json_t *plocation_read_data(json_t *item,
204 const struct plocation *location)
205{
206 if (json_is_null(item)) { // PTZ200719 sanity checks stops the massacre
207 return item;
208 }
209
210 switch (location->kind) {
211 case PADR_FIELD:
212 return plocation_read_field(item, location);
213 case PADR_ELEMENT:
214 return plocation_read_elem(item, location);
215 default:
216 log_error("Unknown packet part location kind.");
217 return NULL;
218 }
219}
220
221/**********************************************************************/
224int dio_put_uint8_json(struct json_data_out *dout,
225 const struct plocation *location,
226 int value)
227{
228 int e;
229
230 if (dout->json) {
231 e = plocation_write_data(dout->json, location, json_integer(value));
232 } else {
233 e = dio_put_uint8_raw(&dout->raw, value);
234 }
235
236 return e;
237}
238
239/**********************************************************************/
242int dio_put_sint8_json(struct json_data_out *dout,
243 const struct plocation *location,
244 int value)
245{
246 int e;
247
248 if (dout->json) {
249 e = plocation_write_data(dout->json, location, json_integer(value));
250 } else {
251 e = dio_put_sint8_raw(&dout->raw, value);
252 }
253
254 return e;
255}
256
257/**********************************************************************/
260int dio_put_uint16_json(struct json_data_out *dout,
261 const struct plocation *location, int value)
262{
263 int e;
264
265 if (dout->json) {
266 e = plocation_write_data(dout->json, location, json_integer(value));
267 } else {
268 e = dio_put_uint16_raw(&dout->raw, value);
269 }
270
271 return e;
272}
273
274/**********************************************************************/
277int dio_put_sint16_json(struct json_data_out *dout,
278 const struct plocation *location, int value)
279{
280 int e;
281
282 if (dout->json) {
283 e = plocation_write_data(dout->json, location, json_integer(value));
284 } else {
285 e = dio_put_sint16_raw(&dout->raw, value);
286 }
287
288 return e;
289}
290
291/**********************************************************************/
294int dio_put_cm_parameter_json(struct json_data_out *dout,
295 struct plocation *location,
296 const struct cm_parameter *param)
297{
298 int e = 0;
299
300 if (dout->json) {
301 json_t *obj = json_object();
302 json_t *min_surplus = json_array();
303 json_t *factor = json_array();
304 int i;
305
306 for (i = 0; i < O_LAST; i++) {
307 e |= json_array_append_new(min_surplus,
308 json_integer(param->minimal_surplus[i]));
309 e |= json_array_append_new(factor,
310 json_integer(param->factor[i]));
311 }
312
313 e |= json_object_set_new(obj, "minimal_surplus", min_surplus);
314 e |= json_object_set_new(obj, "factor", factor);
315 e |= json_object_set_new(obj, "max_growth", json_boolean(param->max_growth));
316 e |= json_object_set_new(obj, "require_happy",
317 json_boolean(param->require_happy));
318 e |= json_object_set_new(obj, "allow_disorder",
319 json_boolean(param->allow_disorder));
320 e |= json_object_set_new(obj, "allow_specialists",
321 json_boolean(param->allow_specialists));
322 e |= json_object_set_new(obj, "happy_factor",
323 json_integer(param->happy_factor));
324 e |= plocation_write_data(dout->json, location, obj);
325 } else {
326 e = dio_put_cm_parameter_raw(&dout->raw, param);
327 }
328
329 return e;
330}
331
332/**********************************************************************/
335int dio_put_unit_order_json(struct json_data_out *dout,
336 struct plocation *location,
337 const struct unit_order *order)
338{
339 int e = 0;
340
341 if (dout->json) {
342 json_t *obj = json_object();
343
344 e |= json_object_set_new(obj, "order", json_integer(order->order));
345 e |= json_object_set_new(obj, "activity", json_integer(order->activity));
346 e |= json_object_set_new(obj, "target", json_integer(order->target));
347 e |= json_object_set_new(obj, "sub_target", json_integer(order->sub_target));
348 e |= json_object_set_new(obj, "action", json_integer(order->action));
349 if (order->dir == -1) {
350 /* Avoid integer underflow */
351 e |= json_object_set_new(obj, "dir", json_integer(-1));
352 } else {
353 e |= json_object_set_new(obj, "dir", json_integer(order->dir));
354 }
355 e |= plocation_write_data(dout->json, location, obj);
356 } else {
357 e = dio_put_unit_order_raw(&dout->raw, order);
358 }
359
360 return e;
361}
362
363/**********************************************************************/
366int dio_put_worklist_json(struct json_data_out *dout,
367 struct plocation *location,
368 const struct worklist *pwl)
369{
370 int e = 0;
371
372 if (dout->json) {
373 int i;
374 const int size = worklist_length(pwl);
375
376 /* Must create the array before insertion. */
377 e |= dio_put_farray_json(dout, location, size);
378
379 location->sub_location = plocation_elem_new(0);
380
381 for (i = 0; i < size; i++) {
382 const struct universal *pcp = &(pwl->entries[i]);
383 json_t *universal = json_object();
384
385 location->sub_location->number = i;
386
387 e |= json_object_set_new(universal, "kind", json_integer(pcp->kind));
388 e |= json_object_set_new(universal, "value",
389 json_integer(universal_number(pcp)));
390
391 e |= plocation_write_data(dout->json, location, universal);
392 }
393
394 FC_FREE(location->sub_location);
395 } else {
396 e = dio_put_worklist_raw(&dout->raw, pwl);
397 }
398
399 return e;
400}
401
402/**********************************************************************/
405static bool dio_get_uint8_json_internal(json_t *json_packet,
406 const struct plocation *location,
407 int *dest)
408{
409 json_t *pint = plocation_read_data(json_packet, location);
410
411 if (!pint) {
412 log_error("ERROR: Unable to get uint8 from location: %s", plocation_name(location));
413 return FALSE;
414 }
415 *dest = json_integer_value(pint);
416
417 return TRUE;
418}
419
420/**********************************************************************/
423bool dio_get_uint8_json(struct connection *pc, struct data_in *din,
424 const struct plocation *location, int *dest)
425{
426 if (pc->json_mode) {
427 return dio_get_uint8_json_internal(pc->json_packet, location, dest);
428 } else {
429 return dio_get_uint8_raw(din, dest);
430 }
431}
432
433/**********************************************************************/
436bool dio_get_uint16_json(struct connection *pc, struct data_in *din,
437 const struct plocation *location, int *dest)
438{
439 if (pc->json_mode) {
440 json_t *pint = plocation_read_data(pc->json_packet, location);
441
442 if (!pint) {
443 log_error("ERROR: Unable to get uint16 from location: %s", plocation_name(location));
444 return FALSE;
445 }
446 *dest = json_integer_value(pint);
447 } else {
448 return dio_get_uint16_raw(din, dest);
449 }
450
451 return TRUE;
452}
453
454/**********************************************************************/
457static bool dio_get_uint32_json_internal(json_t *json_packet,
458 const struct plocation *location,
459 int *dest)
460{
461 json_t *pint = plocation_read_data(json_packet, location);
462
463 if (!pint) {
464 log_error("ERROR: Unable to get uint32 from location: %s", plocation_name(location));
465 return FALSE;
466 }
467 *dest = json_integer_value(pint);
468
469 return TRUE;
470}
471
472/**********************************************************************/
475bool dio_get_uint32_json(struct connection *pc, struct data_in *din,
476 const struct plocation *location, int *dest)
477{
478 if (pc->json_mode) {
479 return dio_get_uint32_json_internal(pc->json_packet, location, dest);
480 } else {
481 return dio_get_uint32_raw(din, dest);
482 }
483}
484
485/**********************************************************************/
488bool dio_get_sint32_json(struct connection *pc, struct data_in *din,
489 const struct plocation *location, int *dest)
490{
491 if (pc->json_mode) {
492 return dio_get_uint32_json_internal(pc->json_packet, location, dest);
493 } else {
494 return dio_get_sint32_raw(din, dest);
495 }
496}
497
498/**********************************************************************/
501bool dio_get_cm_parameter_json(struct connection *pc, struct data_in *din,
502 struct plocation *location,
503 struct cm_parameter *param)
504{
505 if (pc->json_mode) {
506 int i;
507
508 cm_init_parameter(param);
509
510 location->sub_location = plocation_field_new("max_growth");
511 if (!dio_get_bool8_json(pc, din, location, &param->max_growth)) {
512 log_packet("Corrupt cm_parameter.max_growth");
513 FC_FREE(location->sub_location);
514 return FALSE;
515 }
516
517 location->sub_location->name = "require_happy";
518 if (!dio_get_bool8_json(pc, din, location, &param->require_happy)) {
519 log_packet("Corrupt cm_parameter.require_happy");
520 FC_FREE(location->sub_location);
521 return FALSE;
522 }
523
524 location->sub_location->name = "allow_disorder";
525 if (!dio_get_bool8_json(pc, din, location, &param->allow_disorder)) {
526 log_packet("Corrupt cm_parameter.allow_disorder");
527 FC_FREE(location->sub_location);
528 return FALSE;
529 }
530
531 location->sub_location->name = "allow_specialists";
532 if (!dio_get_bool8_json(pc, din, location, &param->allow_specialists)) {
533 log_packet("Corrupt cm_parameter.allow_specialists");
534 FC_FREE(location->sub_location);
535 FC_FREE(location->sub_location);
536 return FALSE;
537 }
538
539 location->sub_location->name = "happy_factor";
540 if (!dio_get_uint16_json(pc, din, location, &param->happy_factor)) {
541 log_packet("Corrupt cm_parameter.happy_factor");
542 FC_FREE(location->sub_location);
543 return FALSE;
544 }
545
546 location->sub_location->name = "factor";
547 location->sub_location->sub_location = plocation_elem_new(0);
548 for (i = 0; i < O_LAST; i++) {
549 location->sub_location->sub_location->number = i;
550 if (!dio_get_uint16_json(pc, din, location, &param->factor[i])) {
551 log_packet("Corrupt cm_parameter.factor");
552 FC_FREE(location->sub_location->sub_location);
553 FC_FREE(location->sub_location);
554 return FALSE;
555 }
556 }
557
558 location->sub_location->name = "minimal_surplus";
559 for (i = 0; i < O_LAST; i++) {
560 location->sub_location->sub_location->number = i;
561 if (!dio_get_sint16_json(pc, din, location,
562 &param->minimal_surplus[i])) {
563 log_packet("Corrupt cm_parameter.minimal_surplus");
564 FC_FREE(location->sub_location->sub_location);
565 FC_FREE(location->sub_location);
566 return FALSE;
567 }
568 }
569
570 FC_FREE(location->sub_location->sub_location);
571 FC_FREE(location->sub_location);
572 } else {
573 return dio_get_cm_parameter_raw(din, param);
574 }
575
576 return TRUE;
577}
578
579/**********************************************************************/
582bool dio_get_unit_order_json(struct connection *pc, struct data_in *din,
583 struct plocation *location,
584 struct unit_order *order)
585{
586 if (pc->json_mode) {
587 struct plocation *loc;
588 int iorder, iactivity, idir; /* These fields are enums */
589
590 /* Orders may be located in a nested field (as items in an array) */
591 loc = location;
592 while (loc->sub_location) {
593 loc = loc->sub_location;
594 }
595
596 loc->sub_location = plocation_field_new("order");
597 if (!dio_get_uint8_json(pc, din, location, &iorder)) {
598 log_packet("Corrupt order.order");
599 FC_FREE(loc->sub_location);
600 return FALSE;
601 }
602
603 loc->sub_location->name = "activity";
604 if (!dio_get_uint8_json(pc, din, location, &iactivity)) {
605 log_packet("Corrupt order.activity");
606 FC_FREE(loc->sub_location);
607 return FALSE;
608 }
609
610 loc->sub_location->name = "target";
611 if (!dio_get_sint32_json(pc, din, location, &order->target)) {
612 log_packet("Corrupt order.target");
613 FC_FREE(loc->sub_location);
614 return FALSE;
615 }
616
617 loc->sub_location->name = "sub_target";
618 if (!dio_get_sint16_json(pc, din, location, &order->sub_target)) {
619 log_packet("Corrupt order.sub_target");
620 FC_FREE(loc->sub_location);
621 return FALSE;
622 }
623
624 loc->sub_location->name = "action";
625 if (!dio_get_uint8_json(pc, din, location, &order->action)) {
626 log_packet("Corrupt order.action");
627 FC_FREE(loc->sub_location);
628 return FALSE;
629 }
630
631 loc->sub_location->name = "dir";
632 if (!dio_get_uint8_json(pc, din, location, &idir)) {
633 log_packet("Corrupt order.dir");
634 FC_FREE(loc->sub_location);
635 return FALSE;
636 }
637
638 /*
639 * FIXME: The values should be checked!
640 */
641 order->order = iorder;
642 order->activity = iactivity;
643 order->dir = idir;
644
645 FC_FREE(loc->sub_location);
646 } else {
647 return dio_get_unit_order_raw(din, order);
648 }
649
650 return TRUE;
651}
652
653/**********************************************************************/
656bool dio_get_worklist_json(struct connection *pc, struct data_in *din,
657 struct plocation *location,
658 struct worklist *pwl)
659{
660 if (pc->json_mode) {
661 int i, length;
662
663 const json_t *wlist = plocation_read_data(pc->json_packet, location);
664
665 worklist_init(pwl);
666
667 if (!json_is_array(wlist)) {
668 log_packet("Not a worklist");
669 return FALSE;
670 }
671
672 /* Safe. Checked that it was an array above. */
673 length = json_array_size(wlist);
674
675 /* A worklist is an array... */
676 location->sub_location = plocation_elem_new(0);
677
678 /* ... of universal objects. */
679 location->sub_location->sub_location = plocation_field_new("kind");
680
681 for (i = 0; i < length; i++) {
682 int value;
683 int kind;
684 struct universal univ;
685
686 location->sub_location->number = i;
687
688 location->sub_location->sub_location->name = "kind";
689 if (!dio_get_uint8_json_internal(pc->json_packet, location, &kind)) {
690 log_packet("Corrupt worklist element kind");
691 FC_FREE(location->sub_location->sub_location);
692 FC_FREE(location->sub_location);
693 return FALSE;
694 }
695
696 location->sub_location->sub_location->name = "value";
697 if (!dio_get_uint8_json_internal(pc->json_packet, location, &value)) {
698 log_packet("Corrupt worklist element value");
699 FC_FREE(location->sub_location->sub_location);
700 FC_FREE(location->sub_location);
701 return FALSE;
702 }
703
704 /*
705 * FIXME: the value returned by universal_by_number() should be checked!
706 */
707 univ = universal_by_number(kind, value);
708 worklist_append(pwl, &univ);
709 }
710
711 FC_FREE(location->sub_location->sub_location);
712 FC_FREE(location->sub_location);
713 } else {
714 return dio_get_worklist_raw(din, pwl);
715 }
716
717 return TRUE;
718}
719
720/**********************************************************************/
724bool dio_get_arraylen_json(struct connection *pc, struct data_in *din,
725 const struct plocation *location, int *dest)
726{
727 if (pc->json_mode) {
728 const json_t *arr = plocation_read_data(pc->json_packet, location);
729
730 if (!json_is_array(arr)) {
731 log_packet("Not an array");
732 return FALSE;
733 }
734
735 *dest = json_array_size(arr);
736 } else {
737 return dio_get_arraylen_raw(din, dest);
738 }
739
740 return TRUE;
741}
742
743/**********************************************************************/
746bool dio_get_uint8_vec8_json(struct connection *pc, struct data_in *din,
747 const struct plocation *location,
748 int **values, int stop_value)
749{
750 if (pc->json_mode) {
751 /* TODO: implement */
752 log_warn("Received unimplemeted data type uint8_vec8.");
753 } else {
754 return dio_get_uint8_vec8_raw(din, values, stop_value);
755 }
756
757 return TRUE;
758}
759
760/**********************************************************************/
763bool dio_get_uint16_vec8_json(struct connection *pc, struct data_in *din,
764 const struct plocation *location,
765 int **values,
766 int stop_value)
767{
768 if (pc->json_mode) {
769 /* TODO: implement */
770 log_warn("Received unimplemeted data type uint16_vec8.");
771 } else {
772 return dio_get_uint16_vec8_raw(din, values, stop_value);
773 }
774
775 return TRUE;
776}
777
778/**********************************************************************/
781bool dio_get_requirement_json(struct connection *pc, struct data_in *din,
782 const struct plocation *location,
783 struct requirement *preq)
784{
785 if (pc->json_mode) {
786 int kind, range, value;
787 bool survives, present, quiet;
788
789 struct plocation *req_field;
790
791 /* Find the requirement object. */
792 json_t *requirement = plocation_read_data(pc->json_packet, location);
793
794 if (!requirement) {
795 log_error("ERROR: Unable to get requirement from location: %s", plocation_name(location));
796 return FALSE;
797 }
798
799 /* Find the requirement object fields and translate their values. */
800 req_field = plocation_field_new("kind");
801 if (!dio_get_uint8_json_internal(requirement, req_field, &kind)) {
802 log_error("ERROR: Unable to get part of requirement from location: %s",
803 plocation_name(location));
804 return FALSE;
805 }
806
807 req_field->name = "value";
808 if (!dio_get_uint32_json_internal(requirement, req_field, &value)) {
809 log_error("ERROR: Unable to get part of requirement from location: %s",
810 plocation_name(location));
811 return FALSE;
812 }
813
814 req_field->name = "range";
815 if (!dio_get_uint8_json_internal(requirement, req_field, &range)) {
816 log_error("ERROR: Unable to get part of requirement from location: %s",
817 plocation_name(location));
818 return FALSE;
819 }
820
821 req_field->name = "survives";
822 if (!dio_get_bool8_json_internal(requirement, req_field, &survives)) {
823 log_error("ERROR: Unable to get part of requirement from location: %s",
824 plocation_name(location));
825 return FALSE;
826 }
827
828 req_field->name = "present";
829 if (!dio_get_bool8_json_internal(requirement, req_field, &present)) {
830 log_error("ERROR: Unable to get part of requirement from location: %s",
831 plocation_name(location));
832 return FALSE;
833 }
834
835 req_field->name = "quiet";
836 if (!dio_get_bool8_json_internal(requirement, req_field, &quiet)) {
837 log_error("ERROR: Unable to get part of requirement from location: %s",
838 plocation_name(location));
839 return FALSE;
840 }
841
842 FC_FREE(req_field);
843
844 /* Create a requirement with the values sent over the network. */
845 *preq = req_from_values(kind, range, survives, present, quiet, value);
846 } else {
847 return dio_get_requirement_raw(din, preq);
848 }
849
850 return TRUE;
851}
852
853/**********************************************************************/
856bool dio_get_action_probability_json(struct connection *pc, struct data_in *din,
857 const struct plocation *location,
858 struct act_prob *prob)
859{
860 if (pc->json_mode) {
861 struct plocation *ap_field;
862
863 /* Find the action probability object. */
864 json_t *action_probability = plocation_read_data(pc->json_packet, location);
865
866 if (!action_probability) {
867 log_error("ERROR: Unable to get action probability from location: %s",
868 plocation_name(location));
869 return FALSE;
870 }
871
872 /* Find the action probability object fields and translate their
873 * values. */
874 ap_field = plocation_field_new("min");
875 if (!dio_get_uint8_json_internal(action_probability, ap_field, &prob->min)) {
876 log_error("ERROR: Unable to get part of action probability "
877 "from location: %s",
878 plocation_name(location));
879 return FALSE;
880 }
881
882 ap_field->name = "max";
883 if (!dio_get_uint8_json_internal(action_probability, ap_field, &prob->max)) {
884 log_error("ERROR: Unable to get part of action probability "
885 "from location: %s",
886 plocation_name(location));
887 return FALSE;
888 }
889
890 FC_FREE(ap_field);
891 } else {
892 return dio_get_action_probability_raw(din, prob);
893 }
894
895 return TRUE;
896}
897
898/**********************************************************************/
901int dio_put_farray_json(struct json_data_out *dout,
902 const struct plocation *location, int size)
903{
904 int e = 0;
905
906 if (dout->json) {
907 int i;
908 json_t *farray = json_array();
909
910 /* Jansson's json_array_set_new() refuses to create array elements so
911 * they must be created with the array. */
912 for (i = 0; i < size; i++) {
913 e |= json_array_append_new(farray, json_null());
914 }
915
916 e |= plocation_write_data(dout->json, location, farray);
917 } else {
918 /* No caller needs this */
919 }
920
921 return e;
922}
923
924/**********************************************************************/
927int dio_put_uint32_json(struct json_data_out *dout,
928 const struct plocation *location, int value)
929{
930 int e;
931
932 if (dout->json) {
933 e = plocation_write_data(dout->json, location, json_integer(value));
934 } else {
935 e = dio_put_uint32_raw(&dout->raw, value);
936 }
937
938 return e;
939}
940
941/**********************************************************************/
944int dio_put_sint32_json(struct json_data_out *dout,
945 const struct plocation *location, int value)
946{
947 int e;
948
949 if (dout->json) {
950 e = plocation_write_data(dout->json, location, json_integer(value));
951 } else {
952 e = dio_put_sint32_raw(&dout->raw, value);
953 }
954
955 return e;
956}
957
958/**********************************************************************/
961int dio_put_bool8_json(struct json_data_out *dout,
962 const struct plocation *location, bool value)
963{
964 int e;
965
966 if (dout->json) {
967 e = plocation_write_data(dout->json, location, value ? json_true() : json_false());
968 } else {
969 e = dio_put_bool8_raw(&dout->raw, value);
970 }
971
972 return e;
973}
974
975/**********************************************************************/
978int dio_put_bool32_json(struct json_data_out *dout,
979 const struct plocation *location, bool value)
980{
981 int e;
982
983 if (dout->json) {
984 e = plocation_write_data(dout->json, location, value ? json_true() : json_false());
985 } else {
986 e = dio_put_bool32_raw(&dout->raw, value);
987 }
988
989 return e;
990}
991
992/**********************************************************************/
995int dio_put_ufloat_json(struct json_data_out *dout,
996 const struct plocation *location,
997 float value, int float_factor)
998{
999 int e;
1000
1001 if (dout->json) {
1002 e = plocation_write_data(dout->json, location, json_real(value));
1003 } else {
1004 e = dio_put_ufloat_raw(&dout->raw, value, float_factor);
1005 }
1006
1007 return e;
1008}
1009
1010/**********************************************************************/
1013int dio_put_sfloat_json(struct json_data_out *dout,
1014 const struct plocation *location,
1015 float value, int float_factor)
1016{
1017 int e;
1018
1019 if (dout->json) {
1020 e = plocation_write_data(dout->json, location, json_real(value));
1021 } else {
1022 e = dio_put_sfloat_raw(&dout->raw, value, float_factor);
1023 }
1024
1025 return e;
1026}
1027
1028/**********************************************************************/
1032int dio_put_arraylen_json(struct json_data_out *dout,
1033 const struct plocation *location, int size)
1034{
1035 int e;
1036
1037 if (dout->json) {
1038 e = dio_put_farray_json(dout, location, size);
1039 } else {
1040 e = dio_put_arraylen_raw(&dout->raw, size);
1041 }
1042
1043 return e;
1044}
1045
1046/**********************************************************************/
1049int dio_put_uint8_vec8_json(struct json_data_out *dout,
1050 const struct plocation *location,
1051 int *values, int stop_value)
1052{
1053 int e;
1054
1055 if (dout->json) {
1056 /* TODO: implement. */
1057 log_error("Tried to send unimplemeted data type uint8_vec8.");
1058 e = -1;
1059 } else {
1060 e = dio_put_uint8_vec8_raw(&dout->raw, values, stop_value);
1061 }
1062
1063 return e;
1064}
1065
1066/**********************************************************************/
1069int dio_put_uint16_vec8_json(struct json_data_out *dout,
1070 const struct plocation *location, int *values,
1071 int stop_value)
1072{
1073 int e;
1074
1075 if (dout->json) {
1076 /* TODO: implement. */
1077 log_error("Tried to send unimplemeted data type uint16_vec8.");
1078 e = -1;
1079 } else {
1080 e = dio_put_uint16_vec8_raw(&dout->raw, values, stop_value);
1081 }
1082
1083 return e;
1084}
1085
1086/**********************************************************************/
1089int dio_put_memory_json(struct json_data_out *dout,
1090 struct plocation *location,
1091 const void *value,
1092 size_t size)
1093{
1094 int e;
1095
1096 if (dout->json) {
1097 int i;
1098
1099 e = dio_put_farray_json(dout, location, size);
1100
1101 location->sub_location = plocation_elem_new(0);
1102
1103 for (i = 0; i < size; i++) {
1104 location->sub_location->number = i;
1105
1106 e |= dio_put_uint8_json(dout, location,
1107 ((unsigned char *)value)[i]);
1108 }
1109
1110 FC_FREE(location->sub_location);
1111 } else {
1112 e = dio_put_memory_raw(&dout->raw, value, size);
1113 }
1114
1115 return e;
1116}
1117
1118/**********************************************************************/
1121int dio_put_string_json(struct json_data_out *dout,
1122 const struct plocation *location,
1123 const char *value)
1124{
1125 int e;
1126
1127 if (dout->json) {
1128 e = plocation_write_data(dout->json, location, json_string(value));
1129 } else {
1130 e = dio_put_string_raw(&dout->raw, value);
1131 }
1132
1133 return e;
1134}
1135
1136/**********************************************************************/
1139int dio_put_estring_json(struct json_data_out *dout,
1140 const struct plocation *location,
1141 const char *value)
1142{
1143 int e;
1144
1145 if (dout->json) {
1146 char *escaped_value;
1147
1148 /* Let CURL find the length it self by passing 0 */
1149 escaped_value = curl_easy_escape(get_curl(), value, 0);
1150
1151 /* Handle as a regular string from now on. */
1152 e = dio_put_string_json(dout, location, escaped_value);
1153
1154 /* CURL's memory management wants to free this it self. */
1155 curl_free(escaped_value);
1156 } else {
1157 e = dio_put_estring_raw(&dout->raw, value);
1158 }
1159
1160 return e;
1161}
1162
1163/**********************************************************************/
1166int dio_put_requirement_json(struct json_data_out *dout,
1167 const struct plocation *location,
1168 const struct requirement *preq)
1169{
1170 int e = 0;
1171
1172 if (dout->json) {
1173 int kind, range, value;
1174 bool survives, present, quiet;
1175
1176 /* Create the requirement object. */
1177 json_t *requirement = json_object();
1178
1179 /* Read the requirement values. */
1180 req_get_values(preq, &kind, &range, &survives, &present, &quiet, &value);
1181
1182 /* Write the requirement values to the fields of the requirement
1183 * object. */
1184 e |= json_object_set_new(requirement, "kind", json_integer(kind));
1185 e |= json_object_set_new(requirement, "value", json_integer(value));
1186
1187 e |= json_object_set_new(requirement, "range", json_integer(range));
1188
1189 e |= json_object_set_new(requirement, "survives", json_boolean(survives));
1190 e |= json_object_set_new(requirement, "present", json_boolean(present));
1191 e |= json_object_set_new(requirement, "quiet", json_boolean(quiet));
1192
1193 /* Put the requirement object in the packet. */
1194 e |= plocation_write_data(dout->json, location, requirement);
1195 } else {
1196 e = dio_put_requirement_raw(&dout->raw, preq);
1197 }
1198
1199 return e;
1200}
1201
1202/**********************************************************************/
1205int dio_put_action_probability_json(struct json_data_out *dout,
1206 const struct plocation *location,
1207 const struct act_prob *prob)
1208{
1209 int e = 0;
1210
1211 if (dout->json) {
1212 /* Create the action probability object. */
1213 json_t *action_probability = json_object();
1214
1215 /* Write the action probability values to the fields of the action
1216 * probability object. */
1217 e |= json_object_set_new(action_probability, "min", json_integer(prob->min));
1218 e |= json_object_set_new(action_probability, "max", json_integer(prob->max));
1219
1220 /* Put the action probability object in the packet. */
1221 e |= plocation_write_data(dout->json, location, action_probability);
1222 } else {
1223 e = dio_put_action_probability_raw(&dout->raw, prob);
1224 }
1225
1226 return e;
1227}
1228
1229/**********************************************************************/
1232static bool dio_get_bool8_json_internal(json_t *json_packet,
1233 const struct plocation *location,
1234 bool *dest)
1235{
1236 json_t *pbool = plocation_read_data(json_packet, location);
1237
1238 if (!pbool) {
1239 log_error("ERROR: Unable to get bool8 from location: %s", plocation_name(location));
1240 return FALSE;
1241 }
1242 *dest = json_is_true(pbool);
1243
1244 return TRUE;
1245}
1246
1247/**********************************************************************/
1250bool dio_get_bool8_json(struct connection *pc, struct data_in *din,
1251 const struct plocation *location, bool *dest)
1252{
1253 if (pc->json_mode) {
1254 return dio_get_bool8_json_internal(pc->json_packet, location, dest);
1255 } else {
1256 return dio_get_bool8_raw(din, dest);
1257 }
1258}
1259
1260/**********************************************************************/
1263bool dio_get_bool32_json(struct connection *pc, struct data_in *din,
1264 const struct plocation *location, bool *dest)
1265{
1266 if (pc->json_mode) {
1267 json_t *pbool = plocation_read_data(pc->json_packet, location);
1268
1269 if (!pbool) {
1270 log_error("ERROR: Unable to get bool32 from location: %s", plocation_name(location));
1271 return FALSE;
1272 }
1273 *dest = json_is_true(pbool);
1274 } else {
1275 return dio_get_bool32_raw(din, dest);
1276 }
1277
1278 return TRUE;
1279}
1280
1281/**********************************************************************/
1284bool dio_get_ufloat_json(struct connection *pc, struct data_in *din,
1285 const struct plocation *location,
1286 float *dest, int float_factor)
1287{
1288 if (pc->json_mode) {
1289 json_t *preal = plocation_read_data(pc->json_packet, location);
1290
1291 if (!preal) {
1292 log_error("ERROR: Unable to get real from location: %s", plocation_name(location));
1293 return FALSE;
1294 }
1295 *dest = json_real_value(preal);
1296 } else {
1297 return dio_get_ufloat_raw(din, dest, float_factor);
1298 }
1299
1300 return TRUE;
1301}
1302
1303/**********************************************************************/
1306bool dio_get_sfloat_json(struct connection *pc, struct data_in *din,
1307 const struct plocation *location,
1308 float *dest, int float_factor)
1309{
1310 if (pc->json_mode) {
1311 json_t *preal = plocation_read_data(pc->json_packet, location);
1312
1313 if (!preal) {
1314 log_error("ERROR: Unable to get real from location: %s", plocation_name(location));
1315 return FALSE;
1316 }
1317 *dest = json_real_value(preal);
1318 } else {
1319 return dio_get_sfloat_raw(din, dest, float_factor);
1320 }
1321
1322 return TRUE;
1323}
1324
1325/**********************************************************************/
1328bool dio_get_sint8_json(struct connection *pc, struct data_in *din,
1329 const struct plocation *location, int *dest)
1330{
1331 if (pc->json_mode) {
1332 json_t *pint = plocation_read_data(pc->json_packet, location);
1333
1334 if (!pint) {
1335 log_error("ERROR: Unable to get sint8 from location: %s", plocation_name(location));
1336 return FALSE;
1337 }
1338 *dest = json_integer_value(pint);
1339 } else {
1340 return dio_get_sint8_raw(din, dest);
1341 }
1342
1343 return TRUE;
1344}
1345
1346/**********************************************************************/
1349bool dio_get_sint16_json(struct connection *pc, struct data_in *din,
1350 const struct plocation *location, int *dest)
1351{
1352 if (pc->json_mode) {
1353 json_t *pint = plocation_read_data(pc->json_packet, location);
1354
1355 if (!pint) {
1356 log_error("ERROR: Unable to get sint16 from location: %s", plocation_name(location));
1357 return FALSE;
1358 }
1359 *dest = json_integer_value(pint);
1360 } else {
1361 return dio_get_sint16_raw(din, dest);
1362 }
1363
1364 return TRUE;
1365}
1366
1367/**********************************************************************/
1370bool dio_get_memory_json(struct connection *pc, struct data_in *din,
1371 struct plocation *location,
1372 void *dest, size_t dest_size)
1373{
1374 if (pc->json_mode) {
1375 int i;
1376
1377 location->sub_location = plocation_elem_new(0);
1378
1379 for (i = 0; i < dest_size; i++) {
1380 int val;
1381
1382 location->sub_location->number = i;
1383
1384 if (!dio_get_uint8_json_internal(pc->json_packet, location, &val)) {
1385 free(location->sub_location);
1386 return FALSE;
1387 }
1388 ((unsigned char *)dest)[i] = val;
1389 }
1390
1391 FC_FREE(location->sub_location);
1392 } else {
1393 return dio_get_memory_raw(din, dest, dest_size);
1394 }
1395
1396 return TRUE;
1397}
1398
1399/**********************************************************************/
1402static bool dio_get_string_json_internal(json_t *json_packet,
1403 const struct plocation *location,
1404 char *dest, size_t max_dest_size)
1405{
1406 json_t *pstring = plocation_read_data(json_packet, location);
1407 const char *result_str;
1408
1409 if (!pstring) {
1410 log_error("ERROR: Unable to get string from location: %s", plocation_name(location));
1411 return FALSE;
1412 }
1413
1414 result_str = json_string_value(pstring);
1415
1416 if (dest
1417 && !dataio_get_conv_callback(dest, max_dest_size, result_str, strlen(result_str))) {
1418 log_error("ERROR: Unable to get string from location: %s", plocation_name(location));
1419 return FALSE;
1420 }
1421
1422 return TRUE;
1423}
1424
1425/**********************************************************************/
1428bool dio_get_string_json(struct connection *pc, struct data_in *din,
1429 const struct plocation *location,
1430 char *dest, size_t max_dest_size)
1431{
1432 if (pc->json_mode) {
1433 return dio_get_string_json_internal(pc->json_packet, location,
1434 dest, max_dest_size);
1435 } else {
1436 return dio_get_string_raw(din, dest, max_dest_size);
1437 }
1438}
1439
1440/**********************************************************************/
1445bool dio_get_estring_json(struct connection *pc, struct data_in *din,
1446 const struct plocation *location,
1447 char *dest, size_t max_dest_size)
1448{
1449 if (pc->json_mode) {
1450 char *escaped_value;
1451 char *unescaped_value;
1452
1453 /* The encoded string has the same size limit as the decoded string. */
1454 escaped_value = fc_malloc(max_dest_size);
1455
1456 if (!dio_get_string_json_internal(pc->json_packet, location,
1457 escaped_value, max_dest_size)) {
1458 /* dio_get_string_json() has logged this already. */
1459 return FALSE;
1460 }
1461
1462 /* Let CURL find the length it self by passing 0 */
1463 unescaped_value = curl_easy_unescape(get_curl(), escaped_value, 0, NULL);
1464
1465 /* Done with the escaped value. */
1466 FC_FREE(escaped_value);
1467
1468 /* Copy the unescaped value so CURL can free its own copy. */
1469 memcpy(dest, unescaped_value,
1470 /* Don't copy the memory following unescaped_value. */
1471 MIN(max_dest_size, strlen(unescaped_value) + 1));
1472
1473 /* CURL's memory management wants to free this it self. */
1474 curl_free(unescaped_value);
1475
1476 /* Make sure that the string is terminated. */
1477 dest[max_dest_size - 1] = '\0';
1478 } else {
1479 return dio_get_estring_raw(din, dest, max_dest_size);
1480 }
1481
1482 return TRUE;
1483}
1484
1485#endif /* FREECIV_JSON_CONNECTION */
n
#define n
Definition astring.c:77
bitvector.h
capability.h
cm_init_parameter
void cm_init_parameter(struct cm_parameter *dest)
Definition cm.c:2180
cm.h
incite_cost
char * incite_cost
Definition comments.c:74
dataio.h
dio_put_unit_order_json
int dio_put_unit_order_json(struct json_data_out *dout, struct plocation *location, const struct unit_order *order)
dio_get_uint8_vec8_json
bool dio_get_uint8_vec8_json(struct connection *pc, struct data_in *din, const struct plocation *location, int **values, int stop_value) fc__attribute((nonnull(4)))
dio_get_uint8_json
bool dio_get_uint8_json(struct connection *pc, struct data_in *din, const struct plocation *location, int *dest) fc__attribute((nonnull(4)))
dio_put_uint8_vec8_json
int dio_put_uint8_vec8_json(struct json_data_out *dout, const struct plocation *location, int *values, int stop_value)
dio_get_cm_parameter_json
bool dio_get_cm_parameter_json(struct connection *pc, struct data_in *din, struct plocation *location, struct cm_parameter *param) fc__attribute((nonnull(4)))
dio_get_requirement_json
bool dio_get_requirement_json(struct connection *pc, struct data_in *din, const struct plocation *location, struct requirement *preq) fc__attribute((nonnull(4)))
dio_put_worklist_json
int dio_put_worklist_json(struct json_data_out *dout, struct plocation *location, const struct worklist *pwl)
dio_put_uint32_json
int dio_put_uint32_json(struct json_data_out *dout, const struct plocation *location, int value)
dio_get_estring_json
bool dio_get_estring_json(struct connection *pc, struct data_in *din, const struct plocation *location, char *dest, size_t max_dest_size) fc__attribute((nonnull(4)))
dio_put_uint16_vec8_json
int dio_put_uint16_vec8_json(struct json_data_out *dout, const struct plocation *location, int *values, int stop_value)
dio_get_uint32_json
bool dio_get_uint32_json(struct connection *pc, struct data_in *din, const struct plocation *location, int *dest) fc__attribute((nonnull(4)))
dio_get_memory_json
bool dio_get_memory_json(struct connection *pc, struct data_in *din, struct plocation *location, void *dest, size_t dest_size) fc__attribute((nonnull(4)))
dio_get_uint16_vec8_json
bool dio_get_uint16_vec8_json(struct connection *pc, struct data_in *din, const struct plocation *location, int **values, int stop_value) fc__attribute((nonnull(4)))
dio_put_uint16_json
int dio_put_uint16_json(struct json_data_out *dout, const struct plocation *location, int value)
dio_get_sint8_json
bool dio_get_sint8_json(struct connection *pc, struct data_in *din, const struct plocation *location, int *dest) fc__attribute((nonnull(4)))
dio_put_memory_json
int dio_put_memory_json(struct json_data_out *dout, struct plocation *location, const void *value, size_t size)
dio_get_sint32_json
bool dio_get_sint32_json(struct connection *pc, struct data_in *din, const struct plocation *location, int *dest) fc__attribute((nonnull(4)))
dio_put_arraylen_json
int dio_put_arraylen_json(struct json_data_out *dout, const struct plocation *location, int size)
dio_put_uint8_json
int dio_put_uint8_json(struct json_data_out *dout, const struct plocation *location, int value)
dio_put_farray_json
int dio_put_farray_json(struct json_data_out *dout, const struct plocation *location, int size)
dio_put_bool8_json
int dio_put_bool8_json(struct json_data_out *dout, const struct plocation *location, bool value)
dio_put_sint32_json
int dio_put_sint32_json(struct json_data_out *dout, const struct plocation *location, int value)
dio_put_estring_json
int dio_put_estring_json(struct json_data_out *dout, const struct plocation *location, const char *value)
dio_put_action_probability_json
int dio_put_action_probability_json(struct json_data_out *dout, const struct plocation *location, const struct act_prob *prob)
dio_get_arraylen_json
bool dio_get_arraylen_json(struct connection *pc, struct data_in *din, const struct plocation *location, int *dest) fc__attribute((nonnull(4)))
dio_get_worklist_json
bool dio_get_worklist_json(struct connection *pc, struct data_in *din, struct plocation *location, struct worklist *pwl) fc__attribute((nonnull(4)))
dio_get_sfloat_json
bool dio_get_sfloat_json(struct connection *pc, struct data_in *din, const struct plocation *location, float *dest, int float_factor) fc__attribute((nonnull(4)))
dio_put_bool32_json
int dio_put_bool32_json(struct json_data_out *dout, const struct plocation *location, bool value)
dio_get_bool32_json
bool dio_get_bool32_json(struct connection *pc, struct data_in *din, const struct plocation *location, bool *dest) fc__attribute((nonnull(4)))
dio_get_ufloat_json
bool dio_get_ufloat_json(struct connection *pc, struct data_in *din, const struct plocation *location, float *dest, int float_factor) fc__attribute((nonnull(4)))
dio_get_bool8_json
bool dio_get_bool8_json(struct connection *pc, struct data_in *din, const struct plocation *location, bool *dest) fc__attribute((nonnull(4)))
dio_get_unit_order_json
bool dio_get_unit_order_json(struct connection *pc, struct data_in *din, struct plocation *location, struct unit_order *order) fc__attribute((nonnull(4)))
dio_put_sfloat_json
int dio_put_sfloat_json(struct json_data_out *dout, const struct plocation *location, float value, int float_factor)
dio_put_requirement_json
int dio_put_requirement_json(struct json_data_out *dout, const struct plocation *location, const struct requirement *preq)
dio_put_sint8_json
int dio_put_sint8_json(struct json_data_out *dout, const struct plocation *location, int value)
dio_put_sint16_json
int dio_put_sint16_json(struct json_data_out *dout, const struct plocation *location, int value)
dio_put_ufloat_json
int dio_put_ufloat_json(struct json_data_out *dout, const struct plocation *location, float value, int float_factor)
dio_get_sint16_json
bool dio_get_sint16_json(struct connection *pc, struct data_in *din, const struct plocation *location, int *dest) fc__attribute((nonnull(4)))
dio_put_string_json
int dio_put_string_json(struct json_data_out *dout, const struct plocation *location, const char *value)
dio_get_action_probability_json
bool dio_get_action_probability_json(struct connection *pc, struct data_in *din, const struct plocation *location, struct act_prob *prob) fc__attribute((nonnull(4)))
dio_get_uint16_json
bool dio_get_uint16_json(struct connection *pc, struct data_in *din, const struct plocation *location, int *dest) fc__attribute((nonnull(4)))
dio_put_cm_parameter_json
int dio_put_cm_parameter_json(struct json_data_out *dout, struct plocation *location, const struct cm_parameter *order)
dio_get_string_json
bool dio_get_string_json(struct connection *pc, struct data_in *din, const struct plocation *location, char *dest, size_t max_dest_size) fc__attribute((nonnull(4)))
dio_get_requirement_raw
bool dio_get_requirement_raw(struct data_in *din, struct requirement *preq)
Definition dataio_raw.c:1052
dio_get_sint8_raw
bool dio_get_sint8_raw(struct data_in *din, int *dest)
Definition dataio_raw.c:759
dio_put_uint8_vec8_raw
int dio_put_uint8_vec8_raw(struct raw_data_out *dout, int *values, int stop_value)
Definition dataio_raw.c:447
dio_put_cm_parameter_raw
int dio_put_cm_parameter_raw(struct raw_data_out *dout, const struct cm_parameter *param)
Definition dataio_raw.c:533
dio_put_action_probability_raw
int dio_put_action_probability_raw(struct raw_data_out *dout, const struct act_prob *aprob)
Definition dataio_raw.c:1038
dio_put_uint8_raw
int dio_put_uint8_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:265
plocation_field_new
struct plocation * plocation_field_new(char *name)
Definition dataio_raw.c:1100
dio_get_worklist_raw
bool dio_get_worklist_raw(struct data_in *din, struct worklist *pwl)
Definition dataio_raw.c:932
dio_get_action_probability_raw
bool dio_get_action_probability_raw(struct data_in *din, struct act_prob *aprob)
Definition dataio_raw.c:1018
dio_put_uint32_raw
int dio_put_uint32_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:309
dataio_get_conv_callback
bool dataio_get_conv_callback(char *dst, size_t ndst, const char *src, size_t nsrc)
Definition dataio_raw.c:139
dio_get_sfloat_raw
bool dio_get_sfloat_raw(struct data_in *din, float *dest, int float_factor)
Definition dataio_raw.c:744
dio_get_uint32_raw
bool dio_get_uint32_raw(struct data_in *din, int *dest)
Definition dataio_raw.c:640
dio_put_string_raw
int dio_put_string_raw(struct raw_data_out *dout, const char *value)
Definition dataio_raw.c:512
dio_get_sint16_raw
bool dio_get_sint16_raw(struct data_in *din, int *dest)
Definition dataio_raw.c:777
dio_get_unit_order_raw
bool dio_get_unit_order_raw(struct data_in *din, struct unit_order *order)
Definition dataio_raw.c:906
dio_get_sint32_raw
bool dio_get_sint32_raw(struct data_in *din, int *dest)
Definition dataio_raw.c:795
dio_put_bool8_raw
int dio_put_bool8_raw(struct raw_data_out *dout, bool value)
Definition dataio_raw.c:386
dio_get_cm_parameter_raw
bool dio_get_cm_parameter_raw(struct data_in *din, struct cm_parameter *param)
Definition dataio_raw.c:868
dio_put_sint8_raw
int dio_put_sint8_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:358
dio_put_requirement_raw
int dio_put_requirement_raw(struct raw_data_out *dout, const struct requirement *preq)
Definition dataio_raw.c:1078
dio_get_uint8_vec8_raw
bool dio_get_uint8_vec8_raw(struct data_in *din, int **values, int stop_value)
Definition dataio_raw.c:968
dio_get_uint16_raw
bool dio_get_uint16_raw(struct data_in *din, int *dest)
Definition dataio_raw.c:619
dio_put_sint32_raw
int dio_put_sint32_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:374
dio_get_memory_raw
bool dio_get_memory_raw(struct data_in *din, void *dest, size_t dest_size)
Definition dataio_raw.c:816
dio_put_memory_raw
int dio_put_memory_raw(struct raw_data_out *dout, const void *value, size_t size)
Definition dataio_raw.c:499
dio_get_bool32_raw
bool dio_get_bool32_raw(struct data_in *din, bool *dest)
Definition dataio_raw.c:707
dio_get_ufloat_raw
bool dio_get_ufloat_raw(struct data_in *din, float *dest, int float_factor)
Definition dataio_raw.c:728
dio_put_bool32_raw
int dio_put_bool32_raw(struct raw_data_out *dout, bool value)
Definition dataio_raw.c:398
dio_get_uint8_raw
bool dio_get_uint8_raw(struct data_in *din, int *dest)
Definition dataio_raw.c:598
dio_put_uint16_raw
int dio_put_uint16_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:287
dio_get_uint16_vec8_raw
bool dio_get_uint16_vec8_raw(struct data_in *din, int **values, int stop_value)
Definition dataio_raw.c:993
plocation_elem_new
struct plocation * plocation_elem_new(int number)
Definition dataio_raw.c:1114
dio_get_bool8_raw
bool dio_get_bool8_raw(struct data_in *din, bool *dest)
Definition dataio_raw.c:687
dio_put_unit_order_raw
int dio_put_unit_order_raw(struct raw_data_out *dout, const struct unit_order *order)
Definition dataio_raw.c:560
dio_put_ufloat_raw
int dio_put_ufloat_raw(struct raw_data_out *dout, float value, int float_factor)
Definition dataio_raw.c:412
dio_put_uint16_vec8_raw
int dio_put_uint16_vec8_raw(struct raw_data_out *dout, int *values, int stop_value)
Definition dataio_raw.c:474
dio_put_sfloat_raw
int dio_put_sfloat_raw(struct raw_data_out *dout, float value, int float_factor)
Definition dataio_raw.c:429
dio_put_sint16_raw
int dio_put_sint16_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:366
dio_get_string_raw
bool dio_get_string_raw(struct data_in *din, char *dest, size_t max_dest_size)
Definition dataio_raw.c:831
plocation_name
const char * plocation_name(const struct plocation *loc)
Definition dataio_raw.c:1130
dio_put_worklist_raw
int dio_put_worklist_raw(struct raw_data_out *dout, const struct worklist *pwl)
Definition dataio_raw.c:579
dio_put_arraylen_raw
#define dio_put_arraylen_raw
Definition dataio_raw.h:167
PADR_FIELD
@ PADR_FIELD
Definition dataio_raw.h:57
PADR_ELEMENT
@ PADR_ELEMENT
Definition dataio_raw.h:59
dio_get_arraylen_raw
#define dio_get_arraylen_raw
Definition dataio_raw.h:166
dio_get_estring_raw
#define dio_get_estring_raw
Definition dataio_raw.h:162
dio_put_estring_raw
#define dio_put_estring_raw
Definition dataio_raw.h:163
events.h
fc_prehdrs.h
O_LAST
@ O_LAST
Definition fc_types.h:101
loc
struct tile * loc
Definition citydlg.c:221
log.h
log_packet
#define log_packet
Definition log.h:137
log_warn
#define log_warn(message,...)
Definition log.h:105
log_error
#define log_error(message,...)
Definition log.h:103
mem.h
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
player.h
req_get_values
void req_get_values(const struct requirement *req, int *type, int *range, bool *survives, bool *present, bool *quiet, int *value)
Definition requirements.c:1441
req_from_values
struct requirement req_from_values(int type, int range, bool survives, bool present, bool quiet, int value)
Definition requirements.c:1422
universal_by_number
struct universal universal_by_number(const enum universals_n kind, const int value)
Definition requirements.c:627
universal_number
int universal_number(const struct universal *source)
Definition requirements.c:881
requirements.h
MIN
#define MIN(x, y)
Definition shared.h:55
size
size_t size
Definition specvec.h:72
act_prob
Definition fc_types.h:1250
act_prob::max
int max
Definition fc_types.h:1252
act_prob::min
int min
Definition fc_types.h:1251
cm_parameter
Definition cm.h:40
cm_parameter::allow_disorder
bool allow_disorder
Definition cm.h:44
cm_parameter::factor
int factor[O_LAST]
Definition cm.h:47
cm_parameter::max_growth
bool max_growth
Definition cm.h:42
cm_parameter::allow_specialists
bool allow_specialists
Definition cm.h:45
cm_parameter::require_happy
bool require_happy
Definition cm.h:43
cm_parameter::minimal_surplus
int minimal_surplus[O_LAST]
Definition cm.h:41
cm_parameter::happy_factor
int happy_factor
Definition cm.h:48
connection
Definition connection.h:136
data_in
Definition dataio_raw.h:30
item
Definition climisc.h:80
json_data_out
Definition dataio_json.h:34
plocation
Definition dataio_raw.h:63
plocation::kind
enum plocation_kind kind
Definition dataio_raw.h:65
plocation::number
size_t number
Definition dataio_raw.h:70
plocation::sub_location
struct plocation * sub_location
Definition dataio_raw.h:79
plocation::name
char * name
Definition dataio_raw.h:73
range
Definition unittype.c:879
requirement
Definition requirements.h:81
unit_order
Definition unit.h:93
unit_order::activity
enum unit_activity activity
Definition unit.h:95
unit_order::order
enum unit_orders order
Definition unit.h:94
unit_order::action
int action
Definition unit.h:102
unit_order::dir
enum direction8 dir
Definition unit.h:104
unit_order::target
int target
Definition unit.h:98
unit_order::sub_target
int sub_target
Definition unit.h:99
universal
Definition fc_types.h:908
universal::kind
enum universals_n kind
Definition fc_types.h:910
universal::value
universals_u value
Definition fc_types.h:909
worklist
Definition worklist.h:28
support.h
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
tech.h
worklist_init
void worklist_init(struct worklist *pwl)
Definition worklist.c:38
worklist_append
bool worklist_append(struct worklist *pwl, const struct universal *prod)
Definition worklist.c:147
worklist_length
int worklist_length(const struct worklist *pwl)
Definition worklist.c:57
worklist.h