summaryrefslogtreecommitdiffstats
path: root/qarsh/qarsh_packet.c
diff options
context:
space:
mode:
Diffstat (limited to 'qarsh/qarsh_packet.c')
-rw-r--r--qarsh/qarsh_packet.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/qarsh/qarsh_packet.c b/qarsh/qarsh_packet.c
index f3f5559..76fadf1 100644
--- a/qarsh/qarsh_packet.c
+++ b/qarsh/qarsh_packet.c
@@ -20,6 +20,7 @@ int parse_qp_setuser(xmlXPathContextPtr ctxt, struct qa_packet *qp);
int parse_qp_kill(xmlXPathContextPtr ctxt, struct qa_packet *qp);
int parse_qp_recvfile(xmlXPathContextPtr ctxt, struct qa_packet *qp);
int parse_qp_sendfile(xmlXPathContextPtr ctxt, struct qa_packet *qp);
+int parse_qp_rstat(xmlXPathContextPtr ctxt, struct qa_packet *qp);
void string_qp_hello(xmlNodePtr node, struct qa_packet *qp);
void string_qp_returncode(xmlNodePtr node, struct qa_packet *qp);
@@ -30,6 +31,7 @@ void string_qp_setuser(xmlNodePtr node, struct qa_packet *qp);
void string_qp_kill(xmlNodePtr node, struct qa_packet *qp);
void string_qp_recvfile(xmlNodePtr node, struct qa_packet *qp);
void string_qp_sendfile(xmlNodePtr node, struct qa_packet *qp);
+void string_qp_rstat(xmlNodePtr node, struct qa_packet *qp);
void free_qp_hello(struct qa_packet *qp);
void free_qp_returncode(struct qa_packet *qp);
@@ -37,6 +39,7 @@ void free_qp_runcmd(struct qa_packet *qp);
void free_qp_setuser(struct qa_packet *qp);
void free_qp_recvfile(struct qa_packet *qp);
void free_qp_sendfile(struct qa_packet *qp);
+void free_qp_rstat(struct qa_packet *qp);
void dump_qp_ack(struct qa_packet *qp);
void dump_qp_runcmd(struct qa_packet *qp);
@@ -46,6 +49,7 @@ void dump_qp_setuser(struct qa_packet *qp);
void dump_qp_kill(struct qa_packet *qp);
void dump_qp_recvfile(struct qa_packet *qp);
void dump_qp_sendfile(struct qa_packet *qp);
+void dump_qp_rstat(struct qa_packet *qp);
struct packet_internals {
@@ -115,6 +119,12 @@ struct packet_internals {
.pi_string = string_qp_sendfile,
.pi_free = free_qp_sendfile,
.pi_dump = dump_qp_sendfile
+ }, {
+ .pi_name = "rstat",
+ .pi_parse = parse_qp_rstat,
+ .pi_string = string_qp_rstat,
+ .pi_free = free_qp_rstat,
+ .pi_dump = dump_qp_rstat
}
};
@@ -273,6 +283,32 @@ parse_qp_sendfile(xmlXPathContextPtr ctxt, struct qa_packet *qp)
return 0;
}
+int
+parse_qp_rstat(xmlXPathContextPtr ctxt, struct qa_packet *qp)
+{
+ char *s;
+
+ qp->qp_rstat.qp_path = get_xpath_string(ctxt, "param[@name='path']");
+
+ s = get_xpath_string(ctxt, "param[@name='st_mode']");
+ qp->qp_rstat.qp_st_mode = atoi(s);
+ free(s);
+
+ s = get_xpath_string(ctxt, "param[@name='st_uid']");
+ qp->qp_rstat.qp_st_uid = atoi(s);
+ free(s);
+
+ s = get_xpath_string(ctxt, "param[@name='st_gid']");
+ qp->qp_rstat.qp_st_gid = atoi(s);
+ free(s);
+
+ s = get_xpath_string(ctxt, "param[@name='st_size']");
+ qp->qp_rstat.qp_st_size = atol(s);
+ free(s);
+
+ return 0;
+}
+
struct qa_packet *
parse_packet(xmlXPathContextPtr ctxt)
@@ -462,6 +498,21 @@ void string_qp_sendfile(xmlNodePtr node, struct qa_packet *qp)
xmlAddChild(node, make_param("count", tmpstr));
}
+void string_qp_rstat(xmlNodePtr node, struct qa_packet *qp)
+{
+ char tmpstr[32];
+
+ xmlAddChild(node, make_param("path", qp->qp_rstat.qp_path));
+ snprintf(tmpstr, 32, "%d", qp->qp_rstat.qp_st_mode);
+ xmlAddChild(node, make_param("st_mode", tmpstr));
+ snprintf(tmpstr, 32, "%d", qp->qp_rstat.qp_st_uid);
+ xmlAddChild(node, make_param("st_uid", tmpstr));
+ snprintf(tmpstr, 32, "%d", qp->qp_rstat.qp_st_gid);
+ xmlAddChild(node, make_param("st_gid", tmpstr));
+ snprintf(tmpstr, 32, "%ld", qp->qp_rstat.qp_st_size);
+ xmlAddChild(node, make_param("st_size", tmpstr));
+}
+
/* Must pass in a pointer, but not a malloc'ed pointer */
char *
qptostr(struct qa_packet *qp, char **qpstr, int *qpsize)
@@ -635,6 +686,25 @@ make_qp_sendfile(const char *path, int of_port, size_t count)
return qp;
}
+struct qa_packet *
+make_qp_rstat(const char *path, const struct stat *sb)
+{
+ struct qa_packet *qp;
+ qp = malloc(sizeof *qp);
+ assert(qp);
+ memset(qp, 0, sizeof *qp);
+
+ qp->qp_type = QP_RSTAT;
+ qp->qp_rstat.qp_path = strdup(path);
+ if (sb) {
+ qp->qp_rstat.qp_st_mode = sb->st_mode;
+ qp->qp_rstat.qp_st_uid = sb->st_uid;
+ qp->qp_rstat.qp_st_gid = sb->st_gid;
+ qp->qp_rstat.qp_st_size = sb->st_size;
+ }
+ return qp;
+}
+
/*
* Packet deallocation functions
*/
@@ -675,6 +745,12 @@ free_qp_sendfile(struct qa_packet *qp)
condfree(qp->qp_sendfile.qp_path);
}
+void
+free_qp_rstat(struct qa_packet *qp)
+{
+ condfree(qp->qp_rstat.qp_path);
+}
+
void
qpfree(struct qa_packet *qp)
@@ -755,6 +831,16 @@ dump_qp_sendfile(struct qa_packet *qp)
}
void
+dump_qp_rstat(struct qa_packet *qp)
+{
+ printf("\tpath: %s\n", qp->qp_rstat.qp_path);
+ printf("\tst_mode: %o\n", qp->qp_rstat.qp_st_mode);
+ printf("\tst_uid: %d\n", qp->qp_rstat.qp_st_uid);
+ printf("\tst_gid: %d\n", qp->qp_rstat.qp_st_gid);
+ printf("\tst_size: %ld\n", qp->qp_rstat.qp_st_size);
+}
+
+void
dump_qp(struct qa_packet *qp)
{
printf("%s #%d\n", QP_NAME(qp->qp_type), qp->qp_seq);