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