1/* Do not edit: automatically built by gen_msg.awk. */
2
3#include "db_config.h"
4
5#include "db_int.h"
6#include "dbinc/db_page.h"
7#include "dbinc/db_am.h"
8#include "dbinc/log.h"
9#include "dbinc/mp.h"
10#include "dbinc/txn.h"
11
12/*
13 * PUBLIC: int __rep_bulk_marshal __P((ENV *, __rep_bulk_args *,
14 * PUBLIC:	 u_int8_t *, size_t, size_t *));
15 */
16int
17__rep_bulk_marshal(env, argp, bp, max, lenp)
18	ENV *env;
19	__rep_bulk_args *argp;
20	u_int8_t *bp;
21	size_t *lenp, max;
22{
23	u_int8_t *start;
24
25	if (max < __REP_BULK_SIZE
26	    + (size_t)argp->bulkdata.size)
27		return (ENOMEM);
28	start = bp;
29
30	DB_HTONL_COPYOUT(env, bp, argp->len);
31	DB_HTONL_COPYOUT(env, bp, argp->lsn.file);
32	DB_HTONL_COPYOUT(env, bp, argp->lsn.offset);
33	DB_HTONL_COPYOUT(env, bp, argp->bulkdata.size);
34	if (argp->bulkdata.size > 0) {
35		memcpy(bp, argp->bulkdata.data, argp->bulkdata.size);
36		bp += argp->bulkdata.size;
37	}
38
39	*lenp = (size_t)(bp - start);
40	return (0);
41}
42
43/*
44 * PUBLIC: int __rep_bulk_unmarshal __P((ENV *, __rep_bulk_args *,
45 * PUBLIC:	 u_int8_t *, size_t, u_int8_t **));
46 */
47int
48__rep_bulk_unmarshal(env, argp, bp, max, nextp)
49	ENV *env;
50	__rep_bulk_args *argp;
51	u_int8_t *bp;
52	size_t max;
53	u_int8_t **nextp;
54{
55	size_t needed;
56
57	needed = __REP_BULK_SIZE;
58	if (max < needed)
59		goto too_few;
60	DB_NTOHL_COPYIN(env, argp->len, bp);
61	DB_NTOHL_COPYIN(env, argp->lsn.file, bp);
62	DB_NTOHL_COPYIN(env, argp->lsn.offset, bp);
63	DB_NTOHL_COPYIN(env, argp->bulkdata.size, bp);
64	argp->bulkdata.data = bp;
65	needed += (size_t)argp->bulkdata.size;
66	if (max < needed)
67		goto too_few;
68	bp += argp->bulkdata.size;
69
70	if (nextp != NULL)
71		*nextp = bp;
72	return (0);
73
74too_few:
75	__db_errx(env,
76	    "Not enough input bytes to fill a __rep_bulk message");
77	return (EINVAL);
78}
79
80/*
81 * PUBLIC: int __rep_control_marshal __P((ENV *, __rep_control_args *,
82 * PUBLIC:	 u_int8_t *, size_t, size_t *));
83 */
84int
85__rep_control_marshal(env, argp, bp, max, lenp)
86	ENV *env;
87	__rep_control_args *argp;
88	u_int8_t *bp;
89	size_t *lenp, max;
90{
91	u_int8_t *start;
92
93	if (max < __REP_CONTROL_SIZE)
94		return (ENOMEM);
95	start = bp;
96
97	DB_HTONL_COPYOUT(env, bp, argp->rep_version);
98	DB_HTONL_COPYOUT(env, bp, argp->log_version);
99	DB_HTONL_COPYOUT(env, bp, argp->lsn.file);
100	DB_HTONL_COPYOUT(env, bp, argp->lsn.offset);
101	DB_HTONL_COPYOUT(env, bp, argp->rectype);
102	DB_HTONL_COPYOUT(env, bp, argp->gen);
103	DB_HTONL_COPYOUT(env, bp, argp->msg_sec);
104	DB_HTONL_COPYOUT(env, bp, argp->msg_nsec);
105	DB_HTONL_COPYOUT(env, bp, argp->flags);
106
107	*lenp = (size_t)(bp - start);
108	return (0);
109}
110
111/*
112 * PUBLIC: int __rep_control_unmarshal __P((ENV *,
113 * PUBLIC:	 __rep_control_args *, u_int8_t *, size_t, u_int8_t **));
114 */
115int
116__rep_control_unmarshal(env, argp, bp, max, nextp)
117	ENV *env;
118	__rep_control_args *argp;
119	u_int8_t *bp;
120	size_t max;
121	u_int8_t **nextp;
122{
123	if (max < __REP_CONTROL_SIZE)
124		goto too_few;
125	DB_NTOHL_COPYIN(env, argp->rep_version, bp);
126	DB_NTOHL_COPYIN(env, argp->log_version, bp);
127	DB_NTOHL_COPYIN(env, argp->lsn.file, bp);
128	DB_NTOHL_COPYIN(env, argp->lsn.offset, bp);
129	DB_NTOHL_COPYIN(env, argp->rectype, bp);
130	DB_NTOHL_COPYIN(env, argp->gen, bp);
131	DB_NTOHL_COPYIN(env, argp->msg_sec, bp);
132	DB_NTOHL_COPYIN(env, argp->msg_nsec, bp);
133	DB_NTOHL_COPYIN(env, argp->flags, bp);
134
135	if (nextp != NULL)
136		*nextp = bp;
137	return (0);
138
139too_few:
140	__db_errx(env,
141	    "Not enough input bytes to fill a __rep_control message");
142	return (EINVAL);
143}
144
145/*
146 * PUBLIC: int __rep_egen_marshal __P((ENV *, __rep_egen_args *,
147 * PUBLIC:	 u_int8_t *, size_t, size_t *));
148 */
149int
150__rep_egen_marshal(env, argp, bp, max, lenp)
151	ENV *env;
152	__rep_egen_args *argp;
153	u_int8_t *bp;
154	size_t *lenp, max;
155{
156	u_int8_t *start;
157
158	if (max < __REP_EGEN_SIZE)
159		return (ENOMEM);
160	start = bp;
161
162	DB_HTONL_COPYOUT(env, bp, argp->egen);
163
164	*lenp = (size_t)(bp - start);
165	return (0);
166}
167
168/*
169 * PUBLIC: int __rep_egen_unmarshal __P((ENV *, __rep_egen_args *,
170 * PUBLIC:	 u_int8_t *, size_t, u_int8_t **));
171 */
172int
173__rep_egen_unmarshal(env, argp, bp, max, nextp)
174	ENV *env;
175	__rep_egen_args *argp;
176	u_int8_t *bp;
177	size_t max;
178	u_int8_t **nextp;
179{
180	if (max < __REP_EGEN_SIZE)
181		goto too_few;
182	DB_NTOHL_COPYIN(env, argp->egen, bp);
183
184	if (nextp != NULL)
185		*nextp = bp;
186	return (0);
187
188too_few:
189	__db_errx(env,
190	    "Not enough input bytes to fill a __rep_egen message");
191	return (EINVAL);
192}
193
194/*
195 * PUBLIC: int __rep_fileinfo_marshal __P((ENV *, u_int32_t,
196 * PUBLIC:	 __rep_fileinfo_args *, u_int8_t *, size_t, size_t *));
197 */
198int
199__rep_fileinfo_marshal(env, version, argp, bp, max, lenp)
200	ENV *env;
201	u_int32_t version;
202	__rep_fileinfo_args *argp;
203	u_int8_t *bp;
204	size_t *lenp, max;
205{
206	int copy_only;
207	u_int8_t *start;
208
209	if (max < __REP_FILEINFO_SIZE
210	    + (size_t)argp->uid.size
211	    + (size_t)argp->info.size)
212		return (ENOMEM);
213	start = bp;
214
215	copy_only = 0;
216	if (version < DB_REPVERSION_47)
217		copy_only = 1;
218	if (copy_only) {
219		memcpy(bp, &argp->pgsize, sizeof(u_int32_t));
220		bp += sizeof(u_int32_t);
221	} else
222		DB_HTONL_COPYOUT(env, bp, argp->pgsize);
223	if (copy_only) {
224		memcpy(bp, &argp->pgno, sizeof(u_int32_t));
225		bp += sizeof(u_int32_t);
226	} else
227		DB_HTONL_COPYOUT(env, bp, argp->pgno);
228	if (copy_only) {
229		memcpy(bp, &argp->max_pgno, sizeof(u_int32_t));
230		bp += sizeof(u_int32_t);
231	} else
232		DB_HTONL_COPYOUT(env, bp, argp->max_pgno);
233	if (copy_only) {
234		memcpy(bp, &argp->filenum, sizeof(u_int32_t));
235		bp += sizeof(u_int32_t);
236	} else
237		DB_HTONL_COPYOUT(env, bp, argp->filenum);
238	if (copy_only) {
239		memcpy(bp, &argp->finfo_flags, sizeof(u_int32_t));
240		bp += sizeof(u_int32_t);
241	} else
242		DB_HTONL_COPYOUT(env, bp, argp->finfo_flags);
243	if (copy_only) {
244		memcpy(bp, &argp->type, sizeof(u_int32_t));
245		bp += sizeof(u_int32_t);
246	} else
247		DB_HTONL_COPYOUT(env, bp, argp->type);
248	if (copy_only) {
249		memcpy(bp, &argp->db_flags, sizeof(u_int32_t));
250		bp += sizeof(u_int32_t);
251	} else
252		DB_HTONL_COPYOUT(env, bp, argp->db_flags);
253	if (copy_only) {
254		memcpy(bp, &argp->uid.size, sizeof(u_int32_t));
255		bp += sizeof(u_int32_t);
256	} else
257		DB_HTONL_COPYOUT(env, bp, argp->uid.size);
258	if (argp->uid.size > 0) {
259		memcpy(bp, argp->uid.data, argp->uid.size);
260		bp += argp->uid.size;
261	}
262	if (copy_only) {
263		memcpy(bp, &argp->info.size, sizeof(u_int32_t));
264		bp += sizeof(u_int32_t);
265	} else
266		DB_HTONL_COPYOUT(env, bp, argp->info.size);
267	if (argp->info.size > 0) {
268		memcpy(bp, argp->info.data, argp->info.size);
269		bp += argp->info.size;
270	}
271
272	*lenp = (size_t)(bp - start);
273	return (0);
274}
275
276/*
277 * PUBLIC: int __rep_fileinfo_unmarshal __P((ENV *, u_int32_t,
278 * PUBLIC:	 __rep_fileinfo_args **, u_int8_t *, size_t, u_int8_t **));
279 */
280int
281__rep_fileinfo_unmarshal(env, version, argpp, bp, max, nextp)
282	ENV *env;
283	u_int32_t version;
284	__rep_fileinfo_args **argpp;
285	u_int8_t *bp;
286	size_t max;
287	u_int8_t **nextp;
288{
289	size_t needed;
290	__rep_fileinfo_args *argp;
291	int ret;
292	int copy_only;
293
294	needed = __REP_FILEINFO_SIZE;
295	if (max < needed)
296		goto too_few;
297	if ((ret = __os_malloc(env, sizeof(*argp), &argp)) != 0)
298		return (ret);
299
300	copy_only = 0;
301	if (version < DB_REPVERSION_47)
302		copy_only = 1;
303	if (copy_only) {
304		memcpy(&argp->pgsize, bp, sizeof(u_int32_t));
305		bp += sizeof(u_int32_t);
306	} else
307		DB_NTOHL_COPYIN(env, argp->pgsize, bp);
308	if (copy_only) {
309		memcpy(&argp->pgno, bp, sizeof(u_int32_t));
310		bp += sizeof(u_int32_t);
311	} else
312		DB_NTOHL_COPYIN(env, argp->pgno, bp);
313	if (copy_only) {
314		memcpy(&argp->max_pgno, bp, sizeof(u_int32_t));
315		bp += sizeof(u_int32_t);
316	} else
317		DB_NTOHL_COPYIN(env, argp->max_pgno, bp);
318	if (copy_only) {
319		memcpy(&argp->filenum, bp, sizeof(u_int32_t));
320		bp += sizeof(u_int32_t);
321	} else
322		DB_NTOHL_COPYIN(env, argp->filenum, bp);
323	if (copy_only) {
324		memcpy(&argp->finfo_flags, bp, sizeof(u_int32_t));
325		bp += sizeof(u_int32_t);
326	} else
327		DB_NTOHL_COPYIN(env, argp->finfo_flags, bp);
328	if (copy_only) {
329		memcpy(&argp->type, bp, sizeof(u_int32_t));
330		bp += sizeof(u_int32_t);
331	} else
332		DB_NTOHL_COPYIN(env, argp->type, bp);
333	if (copy_only) {
334		memcpy(&argp->db_flags, bp, sizeof(u_int32_t));
335		bp += sizeof(u_int32_t);
336	} else
337		DB_NTOHL_COPYIN(env, argp->db_flags, bp);
338	if (copy_only) {
339		memcpy(&argp->uid.size, bp, sizeof(u_int32_t));
340		bp += sizeof(u_int32_t);
341	} else
342		DB_NTOHL_COPYIN(env, argp->uid.size, bp);
343	argp->uid.data = bp;
344	needed += (size_t)argp->uid.size;
345	if (max < needed)
346		goto too_few;
347	bp += argp->uid.size;
348	if (copy_only) {
349		memcpy(&argp->info.size, bp, sizeof(u_int32_t));
350		bp += sizeof(u_int32_t);
351	} else
352		DB_NTOHL_COPYIN(env, argp->info.size, bp);
353	argp->info.data = bp;
354	needed += (size_t)argp->info.size;
355	if (max < needed)
356		goto too_few;
357	bp += argp->info.size;
358
359	if (nextp != NULL)
360		*nextp = bp;
361	*argpp = argp;
362	return (0);
363
364too_few:
365	__db_errx(env,
366	    "Not enough input bytes to fill a __rep_fileinfo message");
367	return (EINVAL);
368}
369
370/*
371 * PUBLIC: int __rep_grant_info_marshal __P((ENV *,
372 * PUBLIC:	 __rep_grant_info_args *, u_int8_t *, size_t, size_t *));
373 */
374int
375__rep_grant_info_marshal(env, argp, bp, max, lenp)
376	ENV *env;
377	__rep_grant_info_args *argp;
378	u_int8_t *bp;
379	size_t *lenp, max;
380{
381	u_int8_t *start;
382
383	if (max < __REP_GRANT_INFO_SIZE)
384		return (ENOMEM);
385	start = bp;
386
387	DB_HTONL_COPYOUT(env, bp, argp->msg_sec);
388	DB_HTONL_COPYOUT(env, bp, argp->msg_nsec);
389
390	*lenp = (size_t)(bp - start);
391	return (0);
392}
393
394/*
395 * PUBLIC: int __rep_grant_info_unmarshal __P((ENV *,
396 * PUBLIC:	 __rep_grant_info_args *, u_int8_t *, size_t, u_int8_t **));
397 */
398int
399__rep_grant_info_unmarshal(env, argp, bp, max, nextp)
400	ENV *env;
401	__rep_grant_info_args *argp;
402	u_int8_t *bp;
403	size_t max;
404	u_int8_t **nextp;
405{
406	if (max < __REP_GRANT_INFO_SIZE)
407		goto too_few;
408	DB_NTOHL_COPYIN(env, argp->msg_sec, bp);
409	DB_NTOHL_COPYIN(env, argp->msg_nsec, bp);
410
411	if (nextp != NULL)
412		*nextp = bp;
413	return (0);
414
415too_few:
416	__db_errx(env,
417	    "Not enough input bytes to fill a __rep_grant_info message");
418	return (EINVAL);
419}
420
421/*
422 * PUBLIC: int __rep_logreq_marshal __P((ENV *, __rep_logreq_args *,
423 * PUBLIC:	 u_int8_t *, size_t, size_t *));
424 */
425int
426__rep_logreq_marshal(env, argp, bp, max, lenp)
427	ENV *env;
428	__rep_logreq_args *argp;
429	u_int8_t *bp;
430	size_t *lenp, max;
431{
432	u_int8_t *start;
433
434	if (max < __REP_LOGREQ_SIZE)
435		return (ENOMEM);
436	start = bp;
437
438	DB_HTONL_COPYOUT(env, bp, argp->endlsn.file);
439	DB_HTONL_COPYOUT(env, bp, argp->endlsn.offset);
440
441	*lenp = (size_t)(bp - start);
442	return (0);
443}
444
445/*
446 * PUBLIC: int __rep_logreq_unmarshal __P((ENV *, __rep_logreq_args *,
447 * PUBLIC:	 u_int8_t *, size_t, u_int8_t **));
448 */
449int
450__rep_logreq_unmarshal(env, argp, bp, max, nextp)
451	ENV *env;
452	__rep_logreq_args *argp;
453	u_int8_t *bp;
454	size_t max;
455	u_int8_t **nextp;
456{
457	if (max < __REP_LOGREQ_SIZE)
458		goto too_few;
459	DB_NTOHL_COPYIN(env, argp->endlsn.file, bp);
460	DB_NTOHL_COPYIN(env, argp->endlsn.offset, bp);
461
462	if (nextp != NULL)
463		*nextp = bp;
464	return (0);
465
466too_few:
467	__db_errx(env,
468	    "Not enough input bytes to fill a __rep_logreq message");
469	return (EINVAL);
470}
471
472/*
473 * PUBLIC: int __rep_newfile_marshal __P((ENV *, __rep_newfile_args *,
474 * PUBLIC:	 u_int8_t *, size_t, size_t *));
475 */
476int
477__rep_newfile_marshal(env, argp, bp, max, lenp)
478	ENV *env;
479	__rep_newfile_args *argp;
480	u_int8_t *bp;
481	size_t *lenp, max;
482{
483	u_int8_t *start;
484
485	if (max < __REP_NEWFILE_SIZE)
486		return (ENOMEM);
487	start = bp;
488
489	DB_HTONL_COPYOUT(env, bp, argp->version);
490
491	*lenp = (size_t)(bp - start);
492	return (0);
493}
494
495/*
496 * PUBLIC: int __rep_newfile_unmarshal __P((ENV *,
497 * PUBLIC:	 __rep_newfile_args *, u_int8_t *, size_t, u_int8_t **));
498 */
499int
500__rep_newfile_unmarshal(env, argp, bp, max, nextp)
501	ENV *env;
502	__rep_newfile_args *argp;
503	u_int8_t *bp;
504	size_t max;
505	u_int8_t **nextp;
506{
507	if (max < __REP_NEWFILE_SIZE)
508		goto too_few;
509	DB_NTOHL_COPYIN(env, argp->version, bp);
510
511	if (nextp != NULL)
512		*nextp = bp;
513	return (0);
514
515too_few:
516	__db_errx(env,
517	    "Not enough input bytes to fill a __rep_newfile message");
518	return (EINVAL);
519}
520
521/*
522 * PUBLIC: int __rep_update_marshal __P((ENV *, u_int32_t,
523 * PUBLIC:	 __rep_update_args *, u_int8_t *, size_t, size_t *));
524 */
525int
526__rep_update_marshal(env, version, argp, bp, max, lenp)
527	ENV *env;
528	u_int32_t version;
529	__rep_update_args *argp;
530	u_int8_t *bp;
531	size_t *lenp, max;
532{
533	int copy_only;
534	u_int8_t *start;
535
536	if (max < __REP_UPDATE_SIZE)
537		return (ENOMEM);
538	start = bp;
539
540	copy_only = 0;
541	if (version < DB_REPVERSION_47)
542		copy_only = 1;
543	if (copy_only) {
544		memcpy(bp, &argp->first_lsn.file, sizeof(u_int32_t));
545		bp += sizeof(u_int32_t);
546		memcpy(bp, &argp->first_lsn.offset, sizeof(u_int32_t));
547		bp += sizeof(u_int32_t);
548	} else {
549		DB_HTONL_COPYOUT(env, bp, argp->first_lsn.file);
550		DB_HTONL_COPYOUT(env, bp, argp->first_lsn.offset);
551	}
552	if (copy_only) {
553		memcpy(bp, &argp->first_vers, sizeof(u_int32_t));
554		bp += sizeof(u_int32_t);
555	} else
556		DB_HTONL_COPYOUT(env, bp, argp->first_vers);
557	if (copy_only) {
558		memcpy(bp, &argp->num_files, sizeof(u_int32_t));
559		bp += sizeof(u_int32_t);
560	} else
561		DB_HTONL_COPYOUT(env, bp, argp->num_files);
562
563	*lenp = (size_t)(bp - start);
564	return (0);
565}
566
567/*
568 * PUBLIC: int __rep_update_unmarshal __P((ENV *, u_int32_t,
569 * PUBLIC:	 __rep_update_args **, u_int8_t *, size_t, u_int8_t **));
570 */
571int
572__rep_update_unmarshal(env, version, argpp, bp, max, nextp)
573	ENV *env;
574	u_int32_t version;
575	__rep_update_args **argpp;
576	u_int8_t *bp;
577	size_t max;
578	u_int8_t **nextp;
579{
580	__rep_update_args *argp;
581	int ret;
582	int copy_only;
583
584	if (max < __REP_UPDATE_SIZE)
585		goto too_few;
586	if ((ret = __os_malloc(env, sizeof(*argp), &argp)) != 0)
587		return (ret);
588
589	copy_only = 0;
590	if (version < DB_REPVERSION_47)
591		copy_only = 1;
592	if (copy_only) {
593		memcpy(&argp->first_lsn.file, bp, sizeof(u_int32_t));
594		bp += sizeof(u_int32_t);
595		memcpy(&argp->first_lsn.offset, bp, sizeof(u_int32_t));
596		bp += sizeof(u_int32_t);
597	} else {
598		DB_NTOHL_COPYIN(env, argp->first_lsn.file, bp);
599		DB_NTOHL_COPYIN(env, argp->first_lsn.offset, bp);
600	}
601	if (copy_only) {
602		memcpy(&argp->first_vers, bp, sizeof(u_int32_t));
603		bp += sizeof(u_int32_t);
604	} else
605		DB_NTOHL_COPYIN(env, argp->first_vers, bp);
606	if (copy_only) {
607		memcpy(&argp->num_files, bp, sizeof(u_int32_t));
608		bp += sizeof(u_int32_t);
609	} else
610		DB_NTOHL_COPYIN(env, argp->num_files, bp);
611
612	if (nextp != NULL)
613		*nextp = bp;
614	*argpp = argp;
615	return (0);
616
617too_few:
618	__db_errx(env,
619	    "Not enough input bytes to fill a __rep_update message");
620	return (EINVAL);
621}
622
623/*
624 * PUBLIC: int __rep_vote_info_marshal __P((ENV *,
625 * PUBLIC:	 __rep_vote_info_args *, u_int8_t *, size_t, size_t *));
626 */
627int
628__rep_vote_info_marshal(env, argp, bp, max, lenp)
629	ENV *env;
630	__rep_vote_info_args *argp;
631	u_int8_t *bp;
632	size_t *lenp, max;
633{
634	u_int8_t *start;
635
636	if (max < __REP_VOTE_INFO_SIZE)
637		return (ENOMEM);
638	start = bp;
639
640	DB_HTONL_COPYOUT(env, bp, argp->egen);
641	DB_HTONL_COPYOUT(env, bp, argp->nsites);
642	DB_HTONL_COPYOUT(env, bp, argp->nvotes);
643	DB_HTONL_COPYOUT(env, bp, argp->priority);
644	DB_HTONL_COPYOUT(env, bp, argp->tiebreaker);
645
646	*lenp = (size_t)(bp - start);
647	return (0);
648}
649
650/*
651 * PUBLIC: int __rep_vote_info_unmarshal __P((ENV *,
652 * PUBLIC:	 __rep_vote_info_args *, u_int8_t *, size_t, u_int8_t **));
653 */
654int
655__rep_vote_info_unmarshal(env, argp, bp, max, nextp)
656	ENV *env;
657	__rep_vote_info_args *argp;
658	u_int8_t *bp;
659	size_t max;
660	u_int8_t **nextp;
661{
662	if (max < __REP_VOTE_INFO_SIZE)
663		goto too_few;
664	DB_NTOHL_COPYIN(env, argp->egen, bp);
665	DB_NTOHL_COPYIN(env, argp->nsites, bp);
666	DB_NTOHL_COPYIN(env, argp->nvotes, bp);
667	DB_NTOHL_COPYIN(env, argp->priority, bp);
668	DB_NTOHL_COPYIN(env, argp->tiebreaker, bp);
669
670	if (nextp != NULL)
671		*nextp = bp;
672	return (0);
673
674too_few:
675	__db_errx(env,
676	    "Not enough input bytes to fill a __rep_vote_info message");
677	return (EINVAL);
678}
679
680