static int socket_send_request(int fd, const struct su_context *ctx) { #define write_data(fd, data, data_len) \ do { \ size_t __len = htonl(data_len); \ __len = write((fd), &__len, sizeof(__len)); \ if (__len != sizeof(__len)) { \ PLOGE("write(" #data ")"); \ return -1; \ } \ __len = write((fd), data, data_len); \ if (__len != data_len) { \ PLOGE("write(" #data ")"); \ return -1; \ } \ } while (0) #define write_string_data(fd, name, data) \ do { \ write_data(fd, name, strlen(name)); \ write_data(fd, data, strlen(data)); \ } while (0) // stringify everything. #define write_token(fd, name, data) \ do { \ char buf[16]; \ snprintf(buf, sizeof(buf), "%d", data); \ write_string_data(fd, name, buf); \ } while (0) write_token(fd, "version", PROTO_VERSION); write_token(fd, "binary.version", VERSION_CODE); write_token(fd, "pid", ctx->from.pid); write_string_data(fd, "from.name", ctx->from.name); write_string_data(fd, "to.name", ctx->to.name); write_token(fd, "from.uid", ctx->from.uid); write_token(fd, "to.uid", ctx->to.uid); write_string_data(fd, "from.bin", ctx->from.bin); // TODO: Fix issue where not using -c does not result a in a command write_string_data(fd, "command", get_command(&ctx->to)); write_token(fd, "eof", PROTO_VERSION); return 0; }
static int socket_send_request(int fd, const struct su_context *ctx) { write_token(fd, "version", PROTO_VERSION); write_token(fd, "binary.version", VERSION_CODE); write_token(fd, "pid", ctx->from.pid); write_string_data(fd, "from.name", ctx->from.name); write_string_data(fd, "to.name", ctx->to.name); write_token(fd, "from.uid", ctx->from.uid); write_token(fd, "to.uid", ctx->to.uid); write_string_data(fd, "from.bin", ctx->from.bin); write_string_data(fd, "bind.from", ctx->bind.from); write_string_data(fd, "bind.to", ctx->bind.to); write_string_data(fd, "init", ctx->init); // TODO: Fix issue where not using -c does not result a in a command write_string_data(fd, "command", get_command(&ctx->to)); write_token(fd, "eof", PROTO_VERSION); return 0; }