1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
|
/*
* Automatically generated from ./regress.rpc
* by event_rpcgen.py/0.1. DO NOT EDIT THIS FILE.
*/
#include <sys/types.h>
#ifdef _EVENT_HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define EVENT_NO_STRUCT
#include <event.h>
#ifdef _EVENT___func__
#define __func__ _EVENT___func__
#endif
#include "./regress.gen.h"
void event_err(int eval, const char *fmt, ...);
void event_warn(const char *fmt, ...);
void event_errx(int eval, const char *fmt, ...);
void event_warnx(const char *fmt, ...);
/*
* Implementation of msg
*/
static struct msg_access_ __msg_base = {
msg_from_name_assign,
msg_from_name_get,
msg_to_name_assign,
msg_to_name_get,
msg_attack_assign,
msg_attack_get,
msg_run_assign,
msg_run_get,
msg_run_add,
};
struct msg *
msg_new(void)
{
struct msg *tmp;
if ((tmp = malloc(sizeof(struct msg))) == NULL) {
event_warn("%s: malloc", __func__);
return (NULL);
}
tmp->base = &__msg_base;
tmp->from_name_data = NULL;
tmp->from_name_set = 0;
tmp->to_name_data = NULL;
tmp->to_name_set = 0;
tmp->attack_data = NULL;
tmp->attack_set = 0;
tmp->run_data = NULL;
tmp->run_length = 0;
tmp->run_num_allocated = 0;
tmp->run_set = 0;
return (tmp);
}
struct run *
msg_run_add(struct msg *msg)
{
if (++msg->run_length >= msg->run_num_allocated) {
int tobe_allocated = msg->run_num_allocated;
struct run ** new_data = NULL;
tobe_allocated = !tobe_allocated ? 1 : tobe_allocated << 1;
new_data = (struct run **) realloc(msg->run_data,
tobe_allocated * sizeof(struct run *));
if (new_data == NULL)
goto error;
msg->run_data = new_data;
msg->run_num_allocated = tobe_allocated;
}
msg->run_data[msg->run_length - 1] = run_new();
if (msg->run_data[msg->run_length - 1] == NULL)
goto error;
msg->run_set = 1;
return (msg->run_data[msg->run_length - 1]);
error:
--msg->run_length;
return (NULL);
}
int
msg_from_name_assign(struct msg *msg,
const char * value)
{
if (msg->from_name_data != NULL)
free(msg->from_name_data);
if ((msg->from_name_data = strdup(value)) == NULL)
return (-1);
msg->from_name_set = 1;
return (0);
}
int
msg_to_name_assign(struct msg *msg,
const char * value)
{
if (msg->to_name_data != NULL)
free(msg->to_name_data);
if ((msg->to_name_data = strdup(value)) == NULL)
return (-1);
msg->to_name_set = 1;
return (0);
}
int
msg_attack_assign(struct msg *msg,
const struct kill* value)
{
struct evbuffer *tmp = NULL;
if (msg->attack_set) {
kill_clear(msg->attack_data);
msg->attack_set = 0;
} else {
msg->attack_data = kill_new();
if (msg->attack_data == NULL) {
event_warn("%s: kill_new()", __func__);
goto error;
}
}
if ((tmp = evbuffer_new()) == NULL) {
event_warn("%s: evbuffer_new()", __func__);
goto error;
}
kill_marshal(tmp, value);
if (kill_unmarshal(msg->attack_data, tmp) == -1) {
event_warnx("%s: kill_unmarshal", __func__);
goto error;
}
msg->attack_set = 1;
evbuffer_free(tmp);
return (0);
error:
if (tmp != NULL)
evbuffer_free(tmp);
if (msg->attack_data != NULL) {
kill_free(msg->attack_data);
msg->attack_data = NULL;
}
return (-1);
}
int
msg_run_assign(struct msg *msg, int off,
const struct run * value)
{
struct evbuffer *tmp = NULL;
if (!msg->run_set || off < 0 || off >= msg->run_length)
return (-1);
run_clear(msg->run_data[off]);
if ((tmp = evbuffer_new()) == NULL) {
event_warn("%s: evbuffer_new()", __func__);
goto error;
}
run_marshal(tmp, value);
if (run_unmarshal(msg->run_data[off], tmp) == -1) {
event_warnx("%s: run_unmarshal", __func__);
goto error;
}
evbuffer_free(tmp);
return (0);
error:
if (tmp != NULL)
evbuffer_free(tmp);
run_clear(msg->run_data[off]);
return (-1);
}
int
msg_from_name_get(struct msg *msg, char * *value)
{
if (msg->from_name_set != 1)
return (-1);
*value = msg->from_name_data;
return (0);
}
int
msg_to_name_get(struct msg *msg, char * *value)
{
if (msg->to_name_set != 1)
return (-1);
*value = msg->to_name_data;
return (0);
}
int
msg_attack_get(struct msg *msg, struct kill* *value)
{
if (msg->attack_set != 1) {
msg->attack_data = kill_new();
if (msg->attack_data == NULL)
return (-1);
msg->attack_set = 1;
}
*value = msg->attack_data;
return (0);
}
int
msg_run_get(struct msg *msg, int offset,
struct run * *value)
{
if (!msg->run_set || offset < 0 || offset >= msg->run_length)
return (-1);
*value = msg->run_data[offset];
return (0);
}
void
msg_clear(struct msg *tmp)
{
if (tmp->from_name_set == 1) {
free (tmp->from_name_data);
tmp->from_name_data = NULL;
tmp->from_name_set = 0;
}
if (tmp->to_name_set == 1) {
free (tmp->to_name_data);
tmp->to_name_data = NULL;
tmp->to_name_set = 0;
}
if (tmp->attack_set == 1) {
kill_free(tmp->attack_data);
tmp->attack_data = NULL;
tmp->attack_set = 0;
}
if (tmp->run_set == 1) {
int i;
for (i = 0; i < tmp->run_length; ++i) {
run_free(tmp->run_data[i]);
}
free(tmp->run_data);
tmp->run_data = NULL;
tmp->run_set = 0;
tmp->run_length = 0;
tmp->run_num_allocated = 0;
}
}
void
msg_free(struct msg *tmp)
{
if (tmp->from_name_data != NULL)
free (tmp->from_name_data);
if (tmp->to_name_data != NULL)
free (tmp->to_name_data);
if (tmp->attack_data != NULL)
kill_free(tmp->attack_data);
if (tmp->run_data != NULL) {
int i;
for (i = 0; i < tmp->run_length; ++i) {
run_free(tmp->run_data[i]);
tmp->run_data[i] = NULL;
}
free(tmp->run_data);
tmp->run_data = NULL;
tmp->run_length = 0;
tmp->run_num_allocated = 0;
}
free(tmp);
}
void
msg_marshal(struct evbuffer *evbuf, const struct msg *tmp){
evtag_marshal_string(evbuf, MSG_FROM_NAME, tmp->from_name_data);
evtag_marshal_string(evbuf, MSG_TO_NAME, tmp->to_name_data);
if (tmp->attack_set) {
evtag_marshal_kill(evbuf, MSG_ATTACK, tmp->attack_data);
}
{
int i;
for (i = 0; i < tmp->run_length; ++i) {
evtag_marshal_run(evbuf, MSG_RUN, tmp->run_data[i]);
}
}
}
int
msg_unmarshal(struct msg *tmp, struct evbuffer *evbuf)
{
ev_uint32_t tag;
while (EVBUFFER_LENGTH(evbuf) > 0) {
if (evtag_peek(evbuf, &tag) == -1)
return (-1);
switch (tag) {
case MSG_FROM_NAME:
if (tmp->from_name_set)
return (-1);
if (evtag_unmarshal_string(evbuf, MSG_FROM_NAME, &tmp->from_name_data) == -1) {
event_warnx("%s: failed to unmarshal from_name", __func__);
return (-1);
}
tmp->from_name_set = 1;
break;
case MSG_TO_NAME:
if (tmp->to_name_set)
return (-1);
if (evtag_unmarshal_string(evbuf, MSG_TO_NAME, &tmp->to_name_data) == -1) {
event_warnx("%s: failed to unmarshal to_name", __func__);
return (-1);
}
tmp->to_name_set = 1;
break;
case MSG_ATTACK:
if (tmp->attack_set)
return (-1);
tmp->attack_data = kill_new();
if (tmp->attack_data == NULL)
return (-1);
if (evtag_unmarshal_kill(evbuf, MSG_ATTACK, tmp->attack_data) == -1) {
event_warnx("%s: failed to unmarshal attack", __func__);
return (-1);
}
tmp->attack_set = 1;
break;
case MSG_RUN:
if (msg_run_add(tmp) == NULL)
return (-1);
if (evtag_unmarshal_run(evbuf, MSG_RUN,
tmp->run_data[tmp->run_length - 1]) == -1) {
--tmp->run_length;
event_warnx("%s: failed to unmarshal run", __func__);
return (-1);
}
tmp->run_set = 1;
break;
default:
return -1;
}
}
if (msg_complete(tmp) == -1)
return (-1);
return (0);
}
int
msg_complete(struct msg *msg)
{
if (!msg->from_name_set)
return (-1);
if (!msg->to_name_set)
return (-1);
if (msg->attack_set && kill_complete(msg->attack_data) == -1)
return (-1);
{
int i;
for (i = 0; i < msg->run_length; ++i) {
if (run_complete(msg->run_data[i]) == -1)
return (-1);
}
}
return (0);
}
int
evtag_unmarshal_msg(struct evbuffer *evbuf, ev_uint32_t need_tag, struct msg *msg)
{
ev_uint32_t tag;
int res = -1;
struct evbuffer *tmp = evbuffer_new();
if (evtag_unmarshal(evbuf, &tag, tmp) == -1 || tag != need_tag)
goto error;
if (msg_unmarshal(msg, tmp) == -1)
goto error;
res = 0;
error:
evbuffer_free(tmp);
return (res);
}
void
evtag_marshal_msg(struct evbuffer *evbuf, ev_uint32_t tag, const struct msg *msg)
{
struct evbuffer *_buf = evbuffer_new();
assert(_buf != NULL);
evbuffer_drain(_buf, -1);
msg_marshal(_buf, msg);
evtag_marshal(evbuf, tag, EVBUFFER_DATA(_buf), EVBUFFER_LENGTH(_buf));
evbuffer_free(_buf);
}
/*
* Implementation of kill
*/
static struct kill_access_ __kill_base = {
kill_weapon_assign,
kill_weapon_get,
kill_action_assign,
kill_action_get,
kill_how_often_assign,
kill_how_often_get,
};
struct kill *
kill_new(void)
{
struct kill *tmp;
if ((tmp = malloc(sizeof(struct kill))) == NULL) {
event_warn("%s: malloc", __func__);
return (NULL);
}
tmp->base = &__kill_base;
tmp->weapon_data = NULL;
tmp->weapon_set = 0;
tmp->action_data = NULL;
tmp->action_set = 0;
tmp->how_often_data = 0;
tmp->how_often_set = 0;
return (tmp);
}
int
kill_weapon_assign(struct kill *msg,
const char * value)
{
if (msg->weapon_data != NULL)
free(msg->weapon_data);
if ((msg->weapon_data = strdup(value)) == NULL)
return (-1);
msg->weapon_set = 1;
return (0);
}
int
kill_action_assign(struct kill *msg,
const char * value)
{
if (msg->action_data != NULL)
free(msg->action_data);
if ((msg->action_data = strdup(value)) == NULL)
return (-1);
msg->action_set = 1;
return (0);
}
int
kill_how_often_assign(struct kill *msg, const ev_uint32_t value)
{
msg->how_often_set = 1;
msg->how_often_data = value;
return (0);
}
int
kill_weapon_get(struct kill *msg, char * *value)
{
if (msg->weapon_set != 1)
return (-1);
*value = msg->weapon_data;
return (0);
}
int
kill_action_get(struct kill *msg, char * *value)
{
if (msg->action_set != 1)
return (-1);
*value = msg->action_data;
return (0);
}
int
kill_how_often_get(struct kill *msg, ev_uint32_t *value)
{
if (msg->how_often_set != 1)
return (-1);
*value = msg->how_often_data;
return (0);
}
void
kill_clear(struct kill *tmp)
{
if (tmp->weapon_set == 1) {
free (tmp->weapon_data);
tmp->weapon_data = NULL;
tmp->weapon_set = 0;
}
if (tmp->action_set == 1) {
free (tmp->action_data);
tmp->action_data = NULL;
tmp->action_set = 0;
}
tmp->how_often_set = 0;
}
void
kill_free(struct kill *tmp)
{
if (tmp->weapon_data != NULL)
free (tmp->weapon_data);
if (tmp->action_data != NULL)
free (tmp->action_data);
free(tmp);
}
void
kill_marshal(struct evbuffer *evbuf, const struct kill *tmp){
evtag_marshal_string(evbuf, KILL_WEAPON, tmp->weapon_data);
evtag_marshal_string(evbuf, KILL_ACTION, tmp->action_data);
if (tmp->how_often_set) {
evtag_marshal_int(evbuf, KILL_HOW_OFTEN, tmp->how_often_data);
}
}
int
kill_unmarshal(struct kill *tmp, struct evbuffer *evbuf)
{
ev_uint32_t tag;
while (EVBUFFER_LENGTH(evbuf) > 0) {
if (evtag_peek(evbuf, &tag) == -1)
return (-1);
switch (tag) {
case KILL_WEAPON:
if (tmp->weapon_set)
return (-1);
if (evtag_unmarshal_string(evbuf, KILL_WEAPON, &tmp->weapon_data) == -1) {
event_warnx("%s: failed to unmarshal weapon", __func__);
return (-1);
}
tmp->weapon_set = 1;
break;
case KILL_ACTION:
if (tmp->action_set)
return (-1);
if (evtag_unmarshal_string(evbuf, KILL_ACTION, &tmp->action_data) == -1) {
event_warnx("%s: failed to unmarshal action", __func__);
return (-1);
}
tmp->action_set = 1;
break;
case KILL_HOW_OFTEN:
if (tmp->how_often_set)
return (-1);
if (evtag_unmarshal_int(evbuf, KILL_HOW_OFTEN, &tmp->how_often_data) == -1) {
event_warnx("%s: failed to unmarshal how_often", __func__);
return (-1);
}
tmp->how_often_set = 1;
break;
default:
return -1;
}
}
if (kill_complete(tmp) == -1)
return (-1);
return (0);
}
int
kill_complete(struct kill *msg)
{
if (!msg->weapon_set)
return (-1);
if (!msg->action_set)
return (-1);
return (0);
}
int
evtag_unmarshal_kill(struct evbuffer *evbuf, ev_uint32_t need_tag, struct kill *msg)
{
ev_uint32_t tag;
int res = -1;
struct evbuffer *tmp = evbuffer_new();
if (evtag_unmarshal(evbuf, &tag, tmp) == -1 || tag != need_tag)
goto error;
if (kill_unmarshal(msg, tmp) == -1)
goto error;
res = 0;
error:
evbuffer_free(tmp);
return (res);
}
void
evtag_marshal_kill(struct evbuffer *evbuf, ev_uint32_t tag, const struct kill *msg)
{
struct evbuffer *_buf = evbuffer_new();
assert(_buf != NULL);
evbuffer_drain(_buf, -1);
kill_marshal(_buf, msg);
evtag_marshal(evbuf, tag, EVBUFFER_DATA(_buf), EVBUFFER_LENGTH(_buf));
evbuffer_free(_buf);
}
/*
* Implementation of run
*/
static struct run_access_ __run_base = {
run_how_assign,
run_how_get,
run_some_bytes_assign,
run_some_bytes_get,
run_fixed_bytes_assign,
run_fixed_bytes_get,
};
struct run *
run_new(void)
{
struct run *tmp;
if ((tmp = malloc(sizeof(struct run))) == NULL) {
event_warn("%s: malloc", __func__);
return (NULL);
}
tmp->base = &__run_base;
tmp->how_data = NULL;
tmp->how_set = 0;
tmp->some_bytes_data = NULL;
tmp->some_bytes_length = 0;
tmp->some_bytes_set = 0;
memset(tmp->fixed_bytes_data, 0, sizeof(tmp->fixed_bytes_data));
tmp->fixed_bytes_set = 0;
return (tmp);
}
int
run_how_assign(struct run *msg,
const char * value)
{
if (msg->how_data != NULL)
free(msg->how_data);
if ((msg->how_data = strdup(value)) == NULL)
return (-1);
msg->how_set = 1;
return (0);
}
int
run_some_bytes_assign(struct run *msg, const ev_uint8_t * value, ev_uint32_t len)
{
if (msg->some_bytes_data != NULL)
free (msg->some_bytes_data);
msg->some_bytes_data = malloc(len);
if (msg->some_bytes_data == NULL)
return (-1);
msg->some_bytes_set = 1;
msg->some_bytes_length = len;
memcpy(msg->some_bytes_data, value, len);
return (0);
}
int
run_fixed_bytes_assign(struct run *msg, const ev_uint8_t *value)
{
msg->fixed_bytes_set = 1;
memcpy(msg->fixed_bytes_data, value, 24);
return (0);
}
int
run_how_get(struct run *msg, char * *value)
{
if (msg->how_set != 1)
return (-1);
*value = msg->how_data;
return (0);
}
int
run_some_bytes_get(struct run *msg, ev_uint8_t * *value, ev_uint32_t *plen)
{
if (msg->some_bytes_set != 1)
return (-1);
*value = msg->some_bytes_data;
*plen = msg->some_bytes_length;
return (0);
}
int
run_fixed_bytes_get(struct run *msg, ev_uint8_t **value)
{
if (msg->fixed_bytes_set != 1)
return (-1);
*value = msg->fixed_bytes_data;
return (0);
}
void
run_clear(struct run *tmp)
{
if (tmp->how_set == 1) {
free (tmp->how_data);
tmp->how_data = NULL;
tmp->how_set = 0;
}
if (tmp->some_bytes_set == 1) {
free (tmp->some_bytes_data);
tmp->some_bytes_data = NULL;
tmp->some_bytes_length = 0;
tmp->some_bytes_set = 0;
}
tmp->fixed_bytes_set = 0;
memset(tmp->fixed_bytes_data, 0, sizeof(tmp->fixed_bytes_data));
}
void
run_free(struct run *tmp)
{
if (tmp->how_data != NULL)
free (tmp->how_data);
if (tmp->some_bytes_data != NULL)
free (tmp->some_bytes_data);
free(tmp);
}
void
run_marshal(struct evbuffer *evbuf, const struct run *tmp){
evtag_marshal_string(evbuf, RUN_HOW, tmp->how_data);
if (tmp->some_bytes_set) {
evtag_marshal(evbuf, RUN_SOME_BYTES, tmp->some_bytes_data, tmp->some_bytes_length);
}
evtag_marshal(evbuf, RUN_FIXED_BYTES, tmp->fixed_bytes_data, sizeof(tmp->fixed_bytes_data));
}
int
run_unmarshal(struct run *tmp, struct evbuffer *evbuf)
{
ev_uint32_t tag;
while (EVBUFFER_LENGTH(evbuf) > 0) {
if (evtag_peek(evbuf, &tag) == -1)
return (-1);
switch (tag) {
case RUN_HOW:
if (tmp->how_set)
return (-1);
if (evtag_unmarshal_string(evbuf, RUN_HOW, &tmp->how_data) == -1) {
event_warnx("%s: failed to unmarshal how", __func__);
return (-1);
}
tmp->how_set = 1;
break;
case RUN_SOME_BYTES:
if (tmp->some_bytes_set)
return (-1);
if (evtag_payload_length(evbuf, &tmp->some_bytes_length) == -1)
return (-1);
if (tmp->some_bytes_length > EVBUFFER_LENGTH(evbuf))
return (-1);
if ((tmp->some_bytes_data = malloc(tmp->some_bytes_length)) == NULL)
return (-1);
if (evtag_unmarshal_fixed(evbuf, RUN_SOME_BYTES, tmp->some_bytes_data, tmp->some_bytes_length) == -1) {
event_warnx("%s: failed to unmarshal some_bytes", __func__);
return (-1);
}
tmp->some_bytes_set = 1;
break;
case RUN_FIXED_BYTES:
if (tmp->fixed_bytes_set)
return (-1);
if (evtag_unmarshal_fixed(evbuf, RUN_FIXED_BYTES, tmp->fixed_bytes_data, sizeof(tmp->fixed_bytes_data)) == -1) {
event_warnx("%s: failed to unmarshal fixed_bytes", __func__);
return (-1);
}
tmp->fixed_bytes_set = 1;
break;
default:
return -1;
}
}
if (run_complete(tmp) == -1)
return (-1);
return (0);
}
int
run_complete(struct run *msg)
{
if (!msg->how_set)
return (-1);
if (!msg->fixed_bytes_set)
return (-1);
return (0);
}
int
evtag_unmarshal_run(struct evbuffer *evbuf, ev_uint32_t need_tag, struct run *msg)
{
ev_uint32_t tag;
int res = -1;
struct evbuffer *tmp = evbuffer_new();
if (evtag_unmarshal(evbuf, &tag, tmp) == -1 || tag != need_tag)
goto error;
if (run_unmarshal(msg, tmp) == -1)
goto error;
res = 0;
error:
evbuffer_free(tmp);
return (res);
}
void
evtag_marshal_run(struct evbuffer *evbuf, ev_uint32_t tag, const struct run *msg)
{
struct evbuffer *_buf = evbuffer_new();
assert(_buf != NULL);
evbuffer_drain(_buf, -1);
run_marshal(_buf, msg);
evtag_marshal(evbuf, tag, EVBUFFER_DATA(_buf), EVBUFFER_LENGTH(_buf));
evbuffer_free(_buf);
}
|