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.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/qarsh/qarsh_packet.c b/qarsh/qarsh_packet.c
index 929e204..cc4f082 100644
--- a/qarsh/qarsh_packet.c
+++ b/qarsh/qarsh_packet.c
@@ -16,21 +16,25 @@ int parse_qp_returncode(xmlXPathContextPtr ctxt, struct qa_packet *qp);
int parse_qp_ack(xmlXPathContextPtr ctxt, struct qa_packet *qp);
int parse_qp_runcmd(xmlXPathContextPtr ctxt, struct qa_packet *qp);
int parse_qp_cmdexit(xmlXPathContextPtr ctxt, struct qa_packet *qp);
+int parse_qp_setuser(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);
void string_qp_runcmd(xmlNodePtr node, struct qa_packet *qp);
void string_qp_ack(xmlNodePtr node, struct qa_packet *qp);
void string_qp_cmdexit(xmlNodePtr node, struct qa_packet *qp);
+void string_qp_setuser(xmlNodePtr node, struct qa_packet *qp);
void free_qp_hello(struct qa_packet *qp);
void free_qp_returncode(struct qa_packet *qp);
void free_qp_runcmd(struct qa_packet *qp);
+void free_qp_setuser(struct qa_packet *qp);
void dump_qp_ack(struct qa_packet *qp);
void dump_qp_runcmd(struct qa_packet *qp);
void dump_qp_returncode(struct qa_packet *qp);
void dump_qp_cmdexit(struct qa_packet *qp);
+void dump_qp_setuser(struct qa_packet *qp);
struct packet_internals {
@@ -76,6 +80,12 @@ struct packet_internals {
.pi_string = string_qp_cmdexit,
.pi_free = NULL,
.pi_dump = dump_qp_cmdexit
+ }, {
+ .pi_name = "setuser",
+ .pi_parse = parse_qp_setuser,
+ .pi_string = string_qp_setuser,
+ .pi_free = free_qp_setuser,
+ .pi_dump = dump_qp_setuser
}
};
@@ -177,6 +187,14 @@ parse_qp_cmdexit(xmlXPathContextPtr ctxt, struct qa_packet *qp)
free(s);
return 0;
}
+
+int
+parse_qp_setuser(xmlXPathContextPtr ctxt, struct qa_packet *qp)
+{
+ qp->qp_setuser.qp_user = get_xpath_string(ctxt, "param[@name='user']");
+ qp->qp_setuser.qp_group = get_xpath_string(ctxt, "param[@name='group']");
+ return 0;
+}
struct qa_packet *
parse_packet(xmlXPathContextPtr ctxt)
@@ -323,6 +341,14 @@ void string_qp_cmdexit(xmlNodePtr node, struct qa_packet *qp)
xmlAddChild(node, make_param("status", tmpstr));
}
+void string_qp_setuser(xmlNodePtr node, struct qa_packet *qp)
+{
+ xmlAddChild(node, make_param("user", qp->qp_setuser.qp_user));
+ if (qp->qp_setuser.qp_group) {
+ xmlAddChild(node, make_param("group", qp->qp_setuser.qp_group));
+ }
+}
+
/* Must pass in a pointer, but not a malloc'ed pointer */
char *
qptostr(struct qa_packet *qp, char **qpstr, int *qpsize)
@@ -372,6 +398,23 @@ make_qp_hello(char *greeting)
}
struct qa_packet *
+make_qp_returncode(int rc, int eno, char *strerr)
+{
+ struct qa_packet *qp;
+
+ qp = malloc(sizeof *qp);
+ assert(qp);
+ memset(qp, 0, sizeof *qp);
+
+ qp->qp_type = QP_RETURNCODE;
+ qp->qp_returncode.qp_rc = rc;
+ qp->qp_returncode.qp_errno = eno;
+ qp->qp_returncode.qp_strerror = strdup(strerr);
+
+ return qp;
+}
+
+struct qa_packet *
make_qp_ack(enum qa_packet_type t, int i)
{
struct qa_packet *qp;
@@ -418,6 +461,21 @@ make_qp_cmdexit(pid_t pid, int status)
return qp;
}
+struct qa_packet *
+make_qp_setuser(char *user, char *group)
+{
+ struct qa_packet *qp;
+ qp = malloc(sizeof *qp);
+ assert(qp);
+ memset(qp, 0, sizeof *qp);
+
+ qp->qp_type = QP_SETUSER;
+ qp->qp_setuser.qp_user = strdup(user);
+ if (group) qp->qp_setuser.qp_group = strdup(group);
+
+ return qp;
+}
+
/*
* Packet deallocation functions
*/
@@ -440,6 +498,13 @@ free_qp_runcmd(struct qa_packet *qp)
}
void
+free_qp_setuser(struct qa_packet *qp)
+{
+ condfree(qp->qp_setuser.qp_user);
+ condfree(qp->qp_setuser.qp_group);
+}
+
+void
qpfree(struct qa_packet *qp)
{
if (qp) {
@@ -488,6 +553,13 @@ dump_qp_cmdexit(struct qa_packet *qp)
}
void
+dump_qp_setuser(struct qa_packet *qp)
+{
+ printf("\tuser: %s\n", qp->qp_setuser.qp_user);
+ printf("\tgroup: %s\n", qp->qp_setuser.qp_group);
+}
+
+void
dump_qp(struct qa_packet *qp)
{
printf("%s #%d\n", QP_NAME(qp->qp_type), qp->qp_seq);