#ifndef _QARSH_PACKET_H # define _QARSH_PACKET_H 1 #include #define QARSH_MAX_PACKET_SIZE 32*1024 enum qa_packet_type { QP_INVALID = 0, QP_HELLO = 1, QP_RETURNCODE = 2, QP_RUNCMD = 3, QP_ACK = 4, QP_CMDEXIT = 5 }; struct qp_hello_pkt { char *qp_greeting; }; struct qp_returncode_pkt { int qp_rc; int qp_errno; char *qp_strerror; }; struct qp_runcmd_pkt { char *qp_cmdline; int qp_stdin_port; int qp_stdout_port; int qp_stderr_port; }; /* General packet for acknowledging a command worked */ struct qp_ack_pkt { enum qa_packet_type qp_ack_type; int qp_ack_seq; }; struct qp_cmdexit_pkt { pid_t qp_pid; int qp_status; }; #define QP_VERSION 1 struct qa_packet { enum qa_packet_type qp_type; int qp_seq; /* Sequence number for this packet */ union { struct qp_hello_pkt hello; struct qp_returncode_pkt returncode; struct qp_runcmd_pkt runcmd; struct qp_ack_pkt ack; struct qp_cmdexit_pkt cmdexit; } qp_u; }; #define qp_hello qp_u.hello #define qp_returncode qp_u.returncode #define qp_runcmd qp_u.runcmd #define qp_ack qp_u.ack #define qp_cmdexit qp_u.cmdexit /* Prototypes */ char *qp_packet_type(enum qa_packet_type t); struct qa_packet *parse_packets(char *buf, int n); struct qa_packet *make_qp_hello(char *greeting); struct qa_packet *make_qp_ack(enum qa_packet_type t, int i); struct qa_packet *make_qp_runcmd(char *cmdline, int p_in, int p_out, int p_err); struct qa_packet *make_qp_cmdexit(pid_t pid, int status); char *qptostr(struct qa_packet *qp, char **qpstr, int *qpsize); void qpfree(struct qa_packet *qp); void dump_qp(struct qa_packet *qp); #endif /* !_QARSH_PACKET_H */