g_lock: Fix uninitalized variable reads
[Samba.git] / ctdb / event / event_protocol.c
blobbaa9e1ecb825ea8b7ec4168a8ad8164b5bbf29d6
1 /*
2 CTDB event daemon protocol
4 Copyright (C) Amitay Isaacs 2018
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "replace.h"
22 #include <talloc.h>
24 #include "protocol/protocol_basic.h"
26 #include "event_protocol.h"
27 #include "event_protocol_api.h"
29 static size_t ctdb_event_script_action_len(enum ctdb_event_script_action in)
31 uint32_t u32 = in;
33 return ctdb_uint32_len(&u32);
36 static void ctdb_event_script_action_push(enum ctdb_event_script_action in,
37 uint8_t *buf,
38 size_t *npush)
40 uint32_t u32 = in;
42 ctdb_uint32_push(&u32, buf, npush);
45 static int ctdb_event_script_action_pull(uint8_t *buf,
46 size_t buflen,
47 enum ctdb_event_script_action *out,
48 size_t *npull)
50 enum ctdb_event_script_action value;
51 uint32_t u32;
52 size_t np;
53 int ret;
55 ret = ctdb_uint32_pull(buf, buflen, &u32, &np);
56 if (ret != 0) {
57 return ret;
60 switch (u32) {
61 case 0:
62 value = CTDB_EVENT_SCRIPT_DISABLE;
63 break;
65 case 1:
66 value = CTDB_EVENT_SCRIPT_ENABLE;
67 break;
69 default:
70 return EINVAL;
73 *out = value;
74 *npull = np;
76 return 0;
79 static size_t ctdb_event_command_len(enum ctdb_event_command in)
81 uint32_t u32 = in;
83 return ctdb_uint32_len(&u32);
86 static void ctdb_event_command_push(enum ctdb_event_command in,
87 uint8_t *buf,
88 size_t *npush)
90 uint32_t u32 = in;
92 ctdb_uint32_push(&u32, buf, npush);
95 static int ctdb_event_command_pull(uint8_t *buf,
96 size_t buflen,
97 enum ctdb_event_command *out,
98 size_t *npull)
100 enum ctdb_event_command value;
101 uint32_t u32;
102 size_t np;
103 int ret;
105 ret = ctdb_uint32_pull(buf, buflen, &u32, &np);
106 if (ret != 0) {
107 return ret;
110 switch (u32) {
111 case 1:
112 value = CTDB_EVENT_CMD_RUN;
113 break;
115 case 2:
116 value = CTDB_EVENT_CMD_STATUS;
117 break;
119 case 3:
120 value = CTDB_EVENT_CMD_SCRIPT;
121 break;
123 default:
124 return EINVAL;
127 *out = value;
128 *npull = np;
130 return 0;
133 static size_t ctdb_event_script_len(struct ctdb_event_script *in)
135 return ctdb_stringn_len(&in->name) +
136 ctdb_timeval_len(&in->begin) +
137 ctdb_timeval_len(&in->end) +
138 ctdb_int32_len(&in->result) +
139 ctdb_stringn_len(&in->output);
142 static void ctdb_event_script_push(struct ctdb_event_script *in,
143 uint8_t *buf,
144 size_t *npush)
146 size_t offset = 0, np;
148 ctdb_stringn_push(&in->name, buf+offset, &np);
149 offset += np;
151 ctdb_timeval_push(&in->begin, buf+offset, &np);
152 offset += np;
154 ctdb_timeval_push(&in->end, buf+offset, &np);
155 offset += np;
157 ctdb_int32_push(&in->result, buf+offset, &np);
158 offset += np;
160 ctdb_stringn_push(&in->output, buf+offset, &np);
161 offset += np;
163 *npush = offset;
166 static int ctdb_event_script_pull_elems(uint8_t *buf,
167 size_t buflen,
168 TALLOC_CTX *mem_ctx,
169 struct ctdb_event_script *value,
170 size_t *npull)
172 size_t offset = 0, np;
173 int ret;
175 ret = ctdb_stringn_pull(buf+offset,
176 buflen-offset,
177 mem_ctx,
178 &value->name,
179 &np);
180 if (ret != 0) {
181 return ret;
183 offset += np;
185 ret = ctdb_timeval_pull(buf+offset,
186 buflen-offset,
187 &value->begin,
188 &np);
189 if (ret != 0) {
190 return ret;
192 offset += np;
194 ret = ctdb_timeval_pull(buf+offset,
195 buflen-offset,
196 &value->end,
197 &np);
198 if (ret != 0) {
199 return ret;
201 offset += np;
203 ret = ctdb_int32_pull(buf+offset,
204 buflen-offset,
205 &value->result,
206 &np);
207 if (ret != 0) {
208 return ret;
210 offset += np;
212 ret = ctdb_stringn_pull(buf+offset,
213 buflen-offset,
214 mem_ctx,
215 &value->output,
216 &np);
217 if (ret != 0) {
218 return ret;
220 offset += np;
222 *npull = offset;
224 return 0;
227 #ifdef EVENT_PROTOCOL_TEST
228 static int ctdb_event_script_pull(uint8_t *buf,
229 size_t buflen,
230 TALLOC_CTX *mem_ctx,
231 struct ctdb_event_script **out,
232 size_t *npull)
234 struct ctdb_event_script *value;
235 int ret;
237 value = talloc(mem_ctx, struct ctdb_event_script);
238 if (value == NULL) {
239 return ENOMEM;
242 ret = ctdb_event_script_pull_elems(buf, buflen, value, value, npull);
243 if (ret != 0) {
244 talloc_free(value);
245 return ret;
248 *out = value;
250 return 0;
252 #endif
254 static size_t ctdb_event_script_list_len(struct ctdb_event_script_list *in)
256 size_t len;
257 int i;
259 len = ctdb_int32_len(&in->num_scripts);
261 for (i=0; i<in->num_scripts; i++) {
262 len += ctdb_event_script_len(&in->script[i]);
265 return len;
268 static void ctdb_event_script_list_push(struct ctdb_event_script_list *in,
269 uint8_t *buf,
270 size_t *npush)
272 size_t offset = 0, np;
273 int i;
275 ctdb_int32_push(&in->num_scripts, buf+offset, &np);
276 offset += np;
278 for (i=0; i<in->num_scripts; i++) {
279 ctdb_event_script_push(&in->script[i], buf+offset, &np);
280 offset += np;
283 *npush = offset;
286 static int ctdb_event_script_list_pull(uint8_t *buf,
287 size_t buflen,
288 TALLOC_CTX *mem_ctx,
289 struct ctdb_event_script_list **out,
290 size_t *npull)
292 struct ctdb_event_script_list *value = NULL;
293 size_t offset = 0, np;
294 int num_scripts;
295 int ret, i;
297 ret = ctdb_int32_pull(buf+offset, buflen-offset, &num_scripts, &np);
298 if (ret != 0) {
299 return ret;
301 offset += np;
303 if (num_scripts < 0) {
304 return EINVAL;
307 value = talloc_zero(mem_ctx, struct ctdb_event_script_list);
308 if (value == NULL) {
309 return ENOMEM;
312 value->num_scripts = num_scripts;
313 if (num_scripts == 0) {
314 goto done;
317 value->script = talloc_array(value, struct ctdb_event_script,
318 num_scripts);
319 if (value->script == NULL) {
320 ret = ENOMEM;
321 goto fail;
324 for (i=0; i<num_scripts; i++) {
325 ret = ctdb_event_script_pull_elems(buf+offset,
326 buflen-offset,
327 value,
328 &value->script[i],
329 &np);
330 if (ret != 0) {
331 goto fail;
333 offset += np;
336 done:
337 *out = value;
338 *npull = offset;
340 return 0;
342 fail:
343 talloc_free(value);
344 return ret;
347 static size_t ctdb_event_request_run_len(struct ctdb_event_request_run *in)
349 return ctdb_stringn_len(&in->component) +
350 ctdb_stringn_len(&in->event) +
351 ctdb_stringn_len(&in->args) +
352 ctdb_uint32_len(&in->timeout) +
353 ctdb_uint32_len(&in->flags);
356 static void ctdb_event_request_run_push(struct ctdb_event_request_run *in,
357 uint8_t *buf,
358 size_t *npush)
360 size_t offset = 0, np;
362 ctdb_stringn_push(&in->component, buf+offset, &np);
363 offset += np;
365 ctdb_stringn_push(&in->event, buf+offset, &np);
366 offset += np;
368 ctdb_stringn_push(&in->args, buf+offset, &np);
369 offset += np;
371 ctdb_uint32_push(&in->timeout, buf+offset, &np);
372 offset += np;
374 ctdb_uint32_push(&in->flags, buf+offset, &np);
375 offset += np;
377 *npush = offset;
380 static int ctdb_event_request_run_pull(uint8_t *buf,
381 size_t buflen,
382 TALLOC_CTX *mem_ctx,
383 struct ctdb_event_request_run **out,
384 size_t *npull)
386 struct ctdb_event_request_run *value;
387 size_t offset = 0, np;
388 int ret;
390 value = talloc(mem_ctx, struct ctdb_event_request_run);
391 if (value == NULL) {
392 return ENOMEM;
395 ret = ctdb_stringn_pull(buf+offset,
396 buflen-offset,
397 value,
398 &value->component,
399 &np);
400 if (ret != 0) {
401 goto fail;
403 offset += np;
405 ret = ctdb_stringn_pull(buf+offset,
406 buflen-offset,
407 value,
408 &value->event,
409 &np);
410 if (ret != 0) {
411 goto fail;
413 offset += np;
415 ret = ctdb_stringn_pull(buf+offset,
416 buflen-offset,
417 value,
418 &value->args,
419 &np);
420 if (ret != 0) {
421 goto fail;
423 offset += np;
425 ret = ctdb_uint32_pull(buf+offset,
426 buflen-offset,
427 &value->timeout,
428 &np);
429 if (ret != 0) {
430 goto fail;
432 offset += np;
434 ret = ctdb_uint32_pull(buf+offset,
435 buflen-offset,
436 &value->flags,
437 &np);
438 if (ret != 0) {
439 goto fail;
441 offset += np;
443 *out = value;
444 *npull = offset;
446 return 0;
448 fail:
449 talloc_free(value);
450 return ret;
453 static size_t ctdb_event_request_status_len(
454 struct ctdb_event_request_status *in)
456 return ctdb_stringn_len(&in->component) +
457 ctdb_stringn_len(&in->event);
460 static void ctdb_event_request_status_push(
461 struct ctdb_event_request_status *in,
462 uint8_t *buf,
463 size_t *npush)
465 size_t offset = 0, np;
467 ctdb_stringn_push(&in->component, buf+offset, &np);
468 offset += np;
470 ctdb_stringn_push(&in->event, buf+offset, &np);
471 offset += np;
473 *npush = offset;
476 static int ctdb_event_request_status_pull(
477 uint8_t *buf,
478 size_t buflen,
479 TALLOC_CTX *mem_ctx,
480 struct ctdb_event_request_status **out,
481 size_t *npull)
483 struct ctdb_event_request_status *value;
484 size_t offset = 0, np;
485 int ret;
487 value = talloc(mem_ctx, struct ctdb_event_request_status);
488 if (value == NULL) {
489 return ENOMEM;
492 ret = ctdb_stringn_pull(buf+offset,
493 buflen-offset,
494 value,
495 &value->component,
496 &np);
497 if (ret != 0) {
498 goto fail;
500 offset += np;
502 ret = ctdb_stringn_pull(buf+offset,
503 buflen-offset,
504 value,
505 &value->event,
506 &np);
507 if (ret != 0) {
508 goto fail;
510 offset += np;
512 *out = value;
513 *npull = offset;
515 return 0;
517 fail:
518 talloc_free(value);
519 return ret;
522 static size_t ctdb_event_request_script_len(
523 struct ctdb_event_request_script *in)
525 return ctdb_stringn_len(&in->component) +
526 ctdb_stringn_len(&in->script) +
527 ctdb_event_script_action_len(in->action);
530 static void ctdb_event_request_script_push(
531 struct ctdb_event_request_script *in,
532 uint8_t *buf,
533 size_t *npush)
535 size_t offset = 0, np;
537 ctdb_stringn_push(&in->component, buf+offset, &np);
538 offset += np;
540 ctdb_stringn_push(&in->script, buf+offset, &np);
541 offset += np;
543 ctdb_event_script_action_push(in->action, buf+offset, &np);
544 offset += np;
546 *npush = offset;
549 static int ctdb_event_request_script_pull(
550 uint8_t *buf,
551 size_t buflen,
552 TALLOC_CTX *mem_ctx,
553 struct ctdb_event_request_script **out,
554 size_t *npull)
556 struct ctdb_event_request_script *value;
557 size_t offset = 0, np;
558 int ret;
560 value = talloc(mem_ctx, struct ctdb_event_request_script);
561 if (value == NULL) {
562 return ENOMEM;
565 ret = ctdb_stringn_pull(buf+offset,
566 buflen-offset,
567 value,
568 &value->component,
569 &np);
570 if (ret != 0) {
571 goto fail;
573 offset += np;
575 ret = ctdb_stringn_pull(buf+offset,
576 buflen-offset,
577 value,
578 &value->script,
579 &np);
580 if (ret != 0) {
581 goto fail;
583 offset += np;
585 ret = ctdb_event_script_action_pull(buf+offset,
586 buflen-offset,
587 &value->action,
588 &np);
589 if (ret != 0) {
590 goto fail;
592 offset += np;
594 *out = value;
595 *npull = offset;
597 return 0;
599 fail:
600 talloc_free(value);
601 return ret;
604 static size_t ctdb_event_reply_status_len(
605 struct ctdb_event_reply_status *in)
607 return ctdb_int32_len(&in->summary) +
608 ctdb_event_script_list_len(in->script_list);
611 static void ctdb_event_reply_status_push(
612 struct ctdb_event_reply_status *in,
613 uint8_t *buf,
614 size_t *npush)
616 size_t offset = 0, np;
618 ctdb_int32_push(&in->summary, buf+offset, &np);
619 offset += np;
621 ctdb_event_script_list_push(in->script_list, buf+offset, &np);
622 offset += np;
624 *npush = offset;
627 static int ctdb_event_reply_status_pull(
628 uint8_t *buf,
629 size_t buflen,
630 TALLOC_CTX *mem_ctx,
631 struct ctdb_event_reply_status **out,
632 size_t *npull)
634 struct ctdb_event_reply_status *value;
635 size_t offset = 0, np;
636 int ret;
638 value = talloc(mem_ctx, struct ctdb_event_reply_status);
639 if (value == NULL) {
640 return ENOMEM;
643 ret = ctdb_int32_pull(buf+offset, buflen-offset, &value->summary, &np);
644 if (ret != 0) {
645 goto fail;
647 offset += np;
649 ret = ctdb_event_script_list_pull(buf+offset,
650 buflen-offset,
651 value,
652 &value->script_list,
653 &np);
654 if (ret != 0) {
655 goto fail;
657 offset += np;
659 *out = value;
660 *npull = offset;
662 return 0;
664 fail:
665 talloc_free(value);
666 return ret;
669 static size_t ctdb_event_header_len(struct ctdb_event_header *in)
671 return ctdb_uint32_len(&in->length) +
672 ctdb_uint32_len(&in->version) +
673 ctdb_uint32_len(&in->reqid);
676 static void ctdb_event_header_push(struct ctdb_event_header *in,
677 uint8_t *buf,
678 size_t *npush)
680 size_t offset = 0, np;
682 ctdb_uint32_push(&in->length, buf+offset, &np);
683 offset += np;
685 ctdb_uint32_push(&in->version, buf+offset, &np);
686 offset += np;
688 ctdb_uint32_push(&in->reqid, buf+offset, &np);
689 offset += np;
691 *npush = offset;
694 static int ctdb_event_header_pull(uint8_t *buf,
695 size_t buflen,
696 struct ctdb_event_header *value,
697 size_t *npull)
699 size_t offset = 0, np;
700 int ret;
702 ret = ctdb_uint32_pull(buf+offset,
703 buflen-offset,
704 &value->length,
705 &np);
706 if (ret != 0) {
707 return ret;
709 offset += np;
711 ret = ctdb_uint32_pull(buf+offset,
712 buflen-offset,
713 &value->version,
714 &np);
715 if (ret != 0) {
716 return ret;
718 offset += np;
720 ret = ctdb_uint32_pull(buf+offset,
721 buflen-offset,
722 &value->reqid,
723 &np);
724 if (ret != 0) {
725 return ret;
727 offset += np;
729 *npull = offset;
731 return 0;
734 int ctdb_event_header_extract(uint8_t *buf,
735 size_t buflen,
736 struct ctdb_event_header *value)
738 size_t np;
740 return ctdb_event_header_pull(buf, buflen, value, &np);
743 static size_t ctdb_event_request_data_len(struct ctdb_event_request *in)
745 size_t len;
747 len = ctdb_event_command_len(in->cmd);
749 switch (in->cmd) {
750 case CTDB_EVENT_CMD_RUN:
751 len += ctdb_event_request_run_len(in->data.run);
752 break;
754 case CTDB_EVENT_CMD_STATUS:
755 len += ctdb_event_request_status_len(in->data.status);
756 break;
758 case CTDB_EVENT_CMD_SCRIPT:
759 len += ctdb_event_request_script_len(in->data.script);
760 break;
762 default:
763 break;
766 return len;
769 static void ctdb_event_request_data_push(struct ctdb_event_request *in,
770 uint8_t *buf,
771 size_t *npush)
773 size_t offset = 0, np;
775 ctdb_event_command_push(in->cmd, buf+offset, &np);
776 offset += np;
778 switch (in->cmd) {
779 case CTDB_EVENT_CMD_RUN:
780 ctdb_event_request_run_push(in->data.run, buf+offset, &np);
781 break;
783 case CTDB_EVENT_CMD_STATUS:
784 ctdb_event_request_status_push(in->data.status,
785 buf+offset,
786 &np);
787 break;
789 case CTDB_EVENT_CMD_SCRIPT:
790 ctdb_event_request_script_push(in->data.script,
791 buf+offset,
792 &np);
793 break;
794 default:
795 np = 0;
796 break;
798 offset += np;
800 *npush = offset;
803 static int ctdb_event_request_data_pull(uint8_t *buf,
804 size_t buflen,
805 TALLOC_CTX *mem_ctx,
806 struct ctdb_event_request **out,
807 size_t *npull)
809 struct ctdb_event_request *value;
810 size_t offset = 0, np;
811 int ret;
813 value = talloc(mem_ctx, struct ctdb_event_request);
814 if (value == NULL) {
815 return ENOMEM;
818 ret = ctdb_event_command_pull(buf+offset,
819 buflen-offset,
820 &value->cmd,
821 &np);
822 if (ret != 0) {
823 goto fail;
825 offset += np;
827 switch (value->cmd) {
828 case CTDB_EVENT_CMD_RUN:
829 ret = ctdb_event_request_run_pull(buf+offset,
830 buflen-offset,
831 value,
832 &value->data.run,
833 &np);
834 break;
836 case CTDB_EVENT_CMD_STATUS:
837 ret = ctdb_event_request_status_pull(buf+offset,
838 buflen-offset,
839 value,
840 &value->data.status,
841 &np);
842 break;
844 case CTDB_EVENT_CMD_SCRIPT:
845 ret = ctdb_event_request_script_pull(buf+offset,
846 buflen-offset,
847 value,
848 &value->data.script,
849 &np);
850 break;
852 default:
853 np = 0;
854 break;
857 if (ret != 0) {
858 goto fail;
860 offset += np;
862 *out = value;
863 *npull = offset;
865 return 0;
867 fail:
868 talloc_free(value);
869 return ret;
872 static size_t ctdb_event_reply_data_len(struct ctdb_event_reply *in)
874 size_t len;
876 len = ctdb_event_command_len(in->cmd) +
877 ctdb_int32_len(&in->result);
879 if (in->result != 0) {
880 goto done;
883 switch (in->cmd) {
884 case CTDB_EVENT_CMD_STATUS:
885 len += ctdb_event_reply_status_len(in->data.status);
886 break;
888 default:
889 break;
892 done:
893 return len;
896 static void ctdb_event_reply_data_push(struct ctdb_event_reply *in,
897 uint8_t *buf,
898 size_t *npush)
900 size_t offset = 0, np;
902 ctdb_event_command_push(in->cmd, buf+offset, &np);
903 offset += np;
905 ctdb_int32_push(&in->result, buf+offset, &np);
906 offset += np;
908 if (in->result != 0) {
909 goto done;
912 switch (in->cmd) {
913 case CTDB_EVENT_CMD_STATUS:
914 ctdb_event_reply_status_push(in->data.status, buf+offset, &np);
915 break;
917 default:
918 np = 0;
919 break;
921 offset += np;
923 done:
924 *npush = offset;
927 static int ctdb_event_reply_data_pull(uint8_t *buf,
928 size_t buflen,
929 TALLOC_CTX *mem_ctx,
930 struct ctdb_event_reply **out,
931 size_t *npull)
933 struct ctdb_event_reply *value;
934 size_t offset = 0, np;
935 int ret;
937 value = talloc(mem_ctx, struct ctdb_event_reply);
938 if (value == NULL) {
939 return ENOMEM;
942 ret = ctdb_event_command_pull(buf+offset,
943 buflen-offset,
944 &value->cmd,
945 &np);
946 if (ret != 0) {
947 goto fail;
949 offset += np;
951 ret = ctdb_int32_pull(buf+offset, buflen-offset, &value->result, &np);
952 if (ret != 0) {
953 goto fail;
955 offset += np;
957 if (value->result != 0) {
958 goto done;
961 switch (value->cmd) {
962 case CTDB_EVENT_CMD_STATUS:
963 ret = ctdb_event_reply_status_pull(buf+offset,
964 buflen-offset,
965 value,
966 &value->data.status,
967 &np);
968 break;
970 default:
971 np = 0;
972 break;
975 if (ret != 0) {
976 goto fail;
978 offset += np;
980 done:
981 *out = value;
982 *npull = offset;
984 return 0;
986 fail:
987 talloc_free(value);
988 return ret;
991 size_t ctdb_event_request_len(struct ctdb_event_header *h,
992 struct ctdb_event_request *in)
994 return ctdb_event_header_len(h) +
995 ctdb_event_request_data_len(in);
998 int ctdb_event_request_push(struct ctdb_event_header *h,
999 struct ctdb_event_request *in,
1000 uint8_t *buf,
1001 size_t *buflen)
1003 size_t len, offset = 0, np;
1005 len = ctdb_event_request_len(h, in);
1006 if (*buflen < len) {
1007 *buflen = len;
1008 return EMSGSIZE;
1011 h->length = *buflen;
1013 ctdb_event_header_push(h, buf+offset, &np);
1014 offset += np;
1016 ctdb_event_request_data_push(in, buf+offset, &np);
1017 offset += np;
1019 if (offset > *buflen) {
1020 return EMSGSIZE;
1023 return 0;
1026 int ctdb_event_request_pull(uint8_t *buf,
1027 size_t buflen,
1028 struct ctdb_event_header *h,
1029 TALLOC_CTX *mem_ctx,
1030 struct ctdb_event_request **out)
1032 size_t offset = 0, np;
1033 int ret;
1035 ret = ctdb_event_header_pull(buf+offset, buflen-offset, h, &np);
1036 if (ret != 0) {
1037 return ret;
1039 offset += np;
1041 ret = ctdb_event_request_data_pull(buf+offset,
1042 buflen-offset,
1043 mem_ctx,
1044 out,
1045 &np);
1046 if (ret != 0) {
1047 return ret;
1049 offset += np;
1051 if (offset > buflen) {
1052 return EMSGSIZE;
1055 return 0;
1058 size_t ctdb_event_reply_len(struct ctdb_event_header *h,
1059 struct ctdb_event_reply *in)
1061 return ctdb_event_header_len(h) +
1062 ctdb_event_reply_data_len(in);
1065 int ctdb_event_reply_push(struct ctdb_event_header *h,
1066 struct ctdb_event_reply *in,
1067 uint8_t *buf,
1068 size_t *buflen)
1070 size_t len, offset = 0, np;
1072 len = ctdb_event_reply_len(h, in);
1073 if (*buflen < len) {
1074 *buflen = len;
1075 return EMSGSIZE;
1078 h->length = *buflen;
1080 ctdb_event_header_push(h, buf+offset, &np);
1081 offset += np;
1083 ctdb_event_reply_data_push(in, buf+offset, &np);
1084 offset += np;
1086 if (offset > *buflen) {
1087 return EMSGSIZE;
1090 return 0;
1093 int ctdb_event_reply_pull(uint8_t *buf,
1094 size_t buflen,
1095 struct ctdb_event_header *h,
1096 TALLOC_CTX *mem_ctx,
1097 struct ctdb_event_reply **out)
1099 size_t offset = 0, np;
1100 int ret;
1102 ret = ctdb_event_header_pull(buf+offset, buflen-offset, h, &np);
1103 if (ret != 0) {
1104 return ret;
1106 offset += np;
1108 ret = ctdb_event_reply_data_pull(buf+offset,
1109 buflen-offset,
1110 mem_ctx,
1111 out,
1112 &np);
1113 if (ret != 0) {
1114 return ret;
1116 offset += np;
1118 if (offset > buflen) {
1119 return EMSGSIZE;
1122 return 0;