summaryrefslogtreecommitdiffstats
path: root/qarsh_packet.c
diff options
context:
space:
mode:
authorNathan Straz <nstraz@redhat.com>2013-08-28 14:16:30 -0400
committerNathan Straz <nstraz@redhat.com>2013-09-11 17:49:33 -0400
commitceaf5360d969f2507018f51876f64aaae767e367 (patch)
tree07d3db73a4186ce2dcad660393e9265b0ff254ca /qarsh_packet.c
parent604b053a1e710f22226fcb86c34e737df1058f92 (diff)
downloadqarsh-ceaf5360d969f2507018f51876f64aaae767e367.tar.gz
qarsh-ceaf5360d969f2507018f51876f64aaae767e367.tar.xz
qarsh-ceaf5360d969f2507018f51876f64aaae767e367.zip
Get commands running over one socket
Added a new packet to limit data sent from the other side.
Diffstat (limited to 'qarsh_packet.c')
-rw-r--r--qarsh_packet.c57
1 files changed, 47 insertions, 10 deletions
diff --git a/qarsh_packet.c b/qarsh_packet.c
index 269675f..945db6b 100644
--- a/qarsh_packet.c
+++ b/qarsh_packet.c
@@ -49,6 +49,7 @@ void parse_qp_recvfile(char *buf, int *buflen, struct qa_packet *qp);
void parse_qp_sendfile(char *buf, int *buflen, struct qa_packet *qp);
void parse_qp_rstat(char *buf, int *buflen, struct qa_packet *qp);
void parse_qp_data(char *buf, int *buflen, struct qa_packet *qp);
+void parse_qp_data_allow(char *buf, int *buflen, struct qa_packet *qp);
char *store_qp_hello(char *buf, struct qa_packet *qp);
char *store_qp_returncode(char *buf, struct qa_packet *qp);
@@ -61,6 +62,7 @@ char *store_qp_recvfile(char *buf, struct qa_packet *qp);
char *store_qp_sendfile(char *buf, struct qa_packet *qp);
char *store_qp_rstat(char *buf, struct qa_packet *qp);
char *store_qp_data(char *buf, struct qa_packet *qp);
+char *store_qp_data_allow(char *buf, struct qa_packet *qp);
void free_qp_hello(struct qa_packet *qp);
void free_qp_returncode(struct qa_packet *qp);
@@ -81,6 +83,7 @@ void dump_qp_recvfile(struct qa_packet *qp);
void dump_qp_sendfile(struct qa_packet *qp);
void dump_qp_rstat(struct qa_packet *qp);
void dump_qp_data(struct qa_packet *qp);
+void dump_qp_data_allow(struct qa_packet *qp);
struct packet_internals {
@@ -162,6 +165,12 @@ struct packet_internals {
.pi_store = store_qp_data,
.pi_free = free_qp_data,
.pi_dump = dump_qp_data
+ }, {
+ .pi_name = "dallow",
+ .pi_parse = parse_qp_data_allow,
+ .pi_store = store_qp_data_allow,
+ .pi_free = NULL,
+ .pi_dump = dump_qp_data_allow
}
};
@@ -268,9 +277,6 @@ void
parse_qp_runcmd(char *buf, int *buflen, struct qa_packet *qp)
{
buf = fetch_string(buf, buflen, &(qp->qp_runcmd.qp_cmdline));
- buf = fetch_int(buf, buflen, &(qp->qp_runcmd.qp_stdin_port));
- buf = fetch_int(buf, buflen, &(qp->qp_runcmd.qp_stdout_port));
- buf = fetch_int(buf, buflen, &(qp->qp_runcmd.qp_stderr_port));
}
void
@@ -344,6 +350,13 @@ parse_qp_data(char *buf, int *buflen, struct qa_packet *qp)
}
}
+void
+parse_qp_data_allow(char *buf, int *buflen, struct qa_packet *qp)
+{
+ buf = fetch_int(buf, buflen, (int *)&(qp->qp_dallow.qp_remfd));
+ buf = fetch_int(buf, buflen, (int *)&(qp->qp_dallow.qp_count));
+}
+
struct qa_packet *
parse_packet(char *buf, int buflen)
{
@@ -424,9 +437,6 @@ char *
store_qp_runcmd(char *buf, struct qa_packet *qp)
{
buf = store_string(buf, qp->qp_runcmd.qp_cmdline);
- buf = store_int(buf, qp->qp_runcmd.qp_stdin_port);
- buf = store_int(buf, qp->qp_runcmd.qp_stdout_port);
- buf = store_int(buf, qp->qp_runcmd.qp_stderr_port);
return buf;
}
@@ -499,6 +509,14 @@ store_qp_data(char *buf, struct qa_packet *qp)
return buf;
}
+char *
+store_qp_data_allow(char *buf, struct qa_packet *qp)
+{
+ buf = store_int(buf, qp->qp_dallow.qp_remfd);
+ buf = store_int(buf, qp->qp_dallow.qp_count);
+ return buf;
+}
+
int
qptostr(struct qa_packet *qp, char *qpstr, int maxsize)
{
@@ -568,7 +586,7 @@ 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)
+make_qp_runcmd(char *cmdline)
{
struct qa_packet *qp;
qp = malloc(sizeof *qp);
@@ -577,9 +595,6 @@ make_qp_runcmd(char *cmdline, int p_in, int p_out, int p_err)
qp->qp_type = QP_RUNCMD;
qp->qp_runcmd.qp_cmdline = strdup(cmdline);
- qp->qp_runcmd.qp_stdin_port = p_in;
- qp->qp_runcmd.qp_stdout_port = p_out;
- qp->qp_runcmd.qp_stderr_port = p_err;
return qp;
}
@@ -698,6 +713,21 @@ make_qp_data(const int remfd, const off_t offset, const int count, void *blob)
return qp;
}
+struct qa_packet *
+make_qp_data_allow(const int remfd, const int count)
+{
+ struct qa_packet *qp;
+ qp = malloc(sizeof *qp);
+ assert(qp);
+ memset(qp, 0, sizeof *qp);
+
+ qp->qp_type = QP_DALLOW;
+ qp->qp_dallow.qp_remfd = remfd;
+ qp->qp_dallow.qp_count = count;
+
+ return qp;
+}
+
/*
* Packet deallocation functions
*/
@@ -843,6 +873,13 @@ dump_qp_data(struct qa_packet *qp)
}
void
+dump_qp_data_allow(struct qa_packet *qp)
+{
+ fprintf(stderr, "remfd: %d count: %d",
+ qp->qp_dallow.qp_remfd, qp->qp_dallow.qp_count);
+}
+
+void
dump_qp(struct qa_packet *qp)
{
fprintf(stderr, "#%d %s ", qp->qp_seq, QP_NAME(qp->qp_type));