1 /* 2 * HCLINK.H 3 * 4 * $DragonFly: src/bin/cpdup/hclink.h,v 1.1 2006/08/13 20:51:40 dillon Exp $ 5 */ 6 7 #ifndef _HCLINK_H_ 8 #define _HCLINK_H_ 9 10 struct HCHostDesc { 11 struct HCHostDesc *next; 12 int desc; 13 int type; 14 void *data; 15 }; 16 17 struct HostConf { 18 char *host; /* [user@]host */ 19 int fdin; /* pipe */ 20 int fdout; /* pipe */ 21 int error; /* permanent failure code */ 22 pid_t pid; 23 int windex; /* output buffer index */ 24 struct HCHostDesc *hostdescs; 25 char rbuf[65536]; /* output buffer */ 26 char wbuf[65536]; /* output buffer */ 27 }; 28 29 struct HCHead { 30 int32_t magic; /* magic number / byte ordering */ 31 int32_t bytes; /* size of packet */ 32 int16_t cmd; /* command code */ 33 int16_t id; /* transaction id */ 34 int32_t error; /* error code (response) */ 35 }; 36 37 #define HCMAGIC 0x48435052 /* compatible byte ordering */ 38 #define HCMAGIC_REV 0x52504348 /* reverse byte ordering */ 39 #define HCC_ALIGN(bytes) (((bytes) + 7) & ~7) 40 41 struct HCLeaf { 42 int16_t leafid; 43 int16_t reserved; /* reserved must be 0 */ 44 int32_t bytes; 45 }; 46 47 #define HCF_REPLY 0x8000 /* reply */ 48 49 #define LCF_TYPEMASK 0x0F00 50 #define LCF_INT32 0x0100 /* 4 byte integer */ 51 #define LCF_INT64 0x0200 /* 8 byte integer */ 52 #define LCF_STRING 0x0300 /* string, must be 0-terminated */ 53 #define LCF_BINARY 0x0F00 /* binary data */ 54 55 #define LCF_NESTED 0x8000 56 57 struct HCDesc { 58 int16_t cmd; 59 int (*func)(struct HostConf *, struct HCHead *); 60 }; 61 62 /* 63 * Item extraction macros 64 */ 65 #define HCC_STRING(item) ((const char *)((item) + 1)) 66 #define HCC_INT32(item) (*(int32_t *)((item) + 1)) 67 #define HCC_INT64(item) (*(int64_t *)((item) + 1)) 68 #define HCC_BINARYDATA(item) ((void *)((item) + 1)) 69 70 /* 71 * Prototypes 72 */ 73 int hcc_connect(struct HostConf *hc); 74 int hcc_slave(int fdin, int fdout, struct HCDesc *descs, int count); 75 76 void hcc_start_command(struct HostConf *hc, int16_t cmd); 77 struct HCHead *hcc_finish_command(struct HostConf *hc); 78 void hcc_leaf_string(struct HostConf *hc, int16_t leafid, const char *str); 79 void hcc_leaf_data(struct HostConf *hc, int16_t leafid, const void *ptr, int bytes); 80 void hcc_leaf_int32(struct HostConf *hc, int16_t leafid, int32_t value); 81 void hcc_leaf_int64(struct HostConf *hc, int16_t leafid, int64_t value); 82 83 int hcc_alloc_descriptor(struct HostConf *hc, void *ptr, int type); 84 void *hcc_get_descriptor(struct HostConf *hc, int desc, int type); 85 void hcc_set_descriptor(struct HostConf *hc, int desc, void *ptr, int type); 86 87 struct HCLeaf *hcc_firstitem(struct HCHead *head); 88 struct HCLeaf *hcc_nextitem(struct HCHead *head, struct HCLeaf *item); 89 90 void hcc_debug_dump(struct HCHead *head); 91 92 #endif 93 94