| 1092 | } |
| 1093 | |
| 1094 | static int rpc_service(struct rpc_state *rpc, struct discovery *heads, |
| 1095 | const char **client_argv, const struct strbuf *preamble, |
| 1096 | struct strbuf *rpc_result) |
| 1097 | { |
| 1098 | const char *svc = rpc->service_name; |
| 1099 | struct strbuf buf = STRBUF_INIT; |
| 1100 | struct child_process client = CHILD_PROCESS_INIT; |
| 1101 | int err = 0; |
| 1102 | |
| 1103 | client.in = -1; |
| 1104 | client.out = -1; |
| 1105 | client.git_cmd = 1; |
| 1106 | strvec_pushv(&client.args, client_argv); |
| 1107 | if (start_command(&client)) |
| 1108 | exit(1); |
| 1109 | write_or_die(client.in, preamble->buf, preamble->len); |
| 1110 | if (heads) |
| 1111 | write_or_die(client.in, heads->buf, heads->len); |
| 1112 | |
| 1113 | rpc->alloc = http_post_buffer; |
| 1114 | rpc->buf = xmalloc(rpc->alloc); |
| 1115 | rpc->in = client.in; |
| 1116 | rpc->out = client.out; |
| 1117 | |
| 1118 | strbuf_addf(&buf, "%s%s", url.buf, svc); |
| 1119 | rpc->service_url = strbuf_detach(&buf, NULL); |
| 1120 | |
| 1121 | rpc->hdr_accept_language = xstrdup_or_null(http_get_accept_language_header()); |
| 1122 | |
| 1123 | strbuf_addf(&buf, "Content-Type: application/x-%s-request", svc); |
| 1124 | rpc->hdr_content_type = strbuf_detach(&buf, NULL); |
| 1125 | |
| 1126 | strbuf_addf(&buf, "Accept: application/x-%s-result", svc); |
| 1127 | rpc->hdr_accept = strbuf_detach(&buf, NULL); |
| 1128 | |
| 1129 | if (get_protocol_http_header(heads->version, &buf)) |
| 1130 | rpc->protocol_header = strbuf_detach(&buf, NULL); |
| 1131 | else |
| 1132 | rpc->protocol_header = NULL; |
| 1133 | |
| 1134 | while (!err) { |
| 1135 | int n = packet_read(rpc->out, rpc->buf, rpc->alloc, 0); |
| 1136 | if (!n) |
| 1137 | break; |
| 1138 | rpc->pos = 0; |
| 1139 | rpc->len = n; |
| 1140 | err |= post_rpc(rpc, 0, 0); |
| 1141 | } |
| 1142 | |
| 1143 | close(client.in); |
| 1144 | client.in = -1; |
| 1145 | if (!err) { |
| 1146 | strbuf_read(rpc_result, client.out, 0); |
| 1147 | } else { |
| 1148 | char buf[4096]; |
| 1149 | for (;;) |
| 1150 | if (xread(client.out, buf, sizeof(buf)) <= 0) |
| 1151 | break; |
no test coverage detected