7 #include "run-command.h"
10 #include "argv-array.h"
12 static struct remote
*remote
;
13 static const char *url
; /* always ends with a trailing slash */
18 unsigned progress
: 1,
23 static struct options options
;
25 static int set_option(const char *name
, const char *value
)
27 if (!strcmp(name
, "verbosity")) {
29 int v
= strtol(value
, &end
, 10);
30 if (value
== end
|| *end
)
32 options
.verbosity
= v
;
35 else if (!strcmp(name
, "progress")) {
36 if (!strcmp(value
, "true"))
38 else if (!strcmp(value
, "false"))
44 else if (!strcmp(name
, "depth")) {
46 unsigned long v
= strtoul(value
, &end
, 10);
47 if (value
== end
|| *end
)
52 else if (!strcmp(name
, "followtags")) {
53 if (!strcmp(value
, "true"))
54 options
.followtags
= 1;
55 else if (!strcmp(value
, "false"))
56 options
.followtags
= 0;
61 else if (!strcmp(name
, "dry-run")) {
62 if (!strcmp(value
, "true"))
64 else if (!strcmp(value
, "false"))
71 return 1 /* unsupported */;
81 unsigned proto_git
: 1;
83 static struct discovery
*last_discovery
;
85 static struct ref
*parse_git_refs(struct discovery
*heads
, int for_push
)
87 struct ref
*list
= NULL
;
88 get_remote_heads(-1, heads
->buf
, heads
->len
, &list
,
89 for_push
? REF_NORMAL
: 0, NULL
);
93 static struct ref
*parse_info_refs(struct discovery
*heads
)
95 char *data
, *start
, *mid
;
99 struct ref
*refs
= NULL
;
100 struct ref
*ref
= NULL
;
101 struct ref
*last_ref
= NULL
;
106 while (i
< heads
->len
) {
112 if (data
[i
] == '\n') {
113 if (mid
- start
!= 40)
114 die("%sinfo/refs not valid: is this a git repository?", url
);
117 ref
= xmalloc(sizeof(struct ref
) +
118 strlen(ref_name
) + 1);
119 memset(ref
, 0, sizeof(struct ref
));
120 strcpy(ref
->name
, ref_name
);
121 get_sha1_hex(start
, ref
->old_sha1
);
125 last_ref
->next
= ref
;
132 ref
= alloc_ref("HEAD");
133 if (!http_fetch_ref(url
, ref
) &&
134 !resolve_remote_symref(ref
, refs
)) {
144 static void free_discovery(struct discovery
*d
)
147 if (d
== last_discovery
)
148 last_discovery
= NULL
;
155 static int show_http_message(struct strbuf
*type
, struct strbuf
*msg
)
160 * We only show text/plain parts, as other types are likely
161 * to be ugly to look at on the user's terminal.
163 * TODO should handle "; charset=XXX", and re-encode into
166 if (strcasecmp(type
->buf
, "text/plain"))
175 eol
= strchrnul(p
, '\n');
176 fprintf(stderr
, "remote: %.*s\n", (int)(eol
- p
), p
);
182 static struct discovery
* discover_refs(const char *service
, int for_push
)
184 struct strbuf exp
= STRBUF_INIT
;
185 struct strbuf type
= STRBUF_INIT
;
186 struct strbuf buffer
= STRBUF_INIT
;
187 struct discovery
*last
= last_discovery
;
189 int http_ret
, maybe_smart
= 0;
191 if (last
&& !strcmp(service
, last
->service
))
193 free_discovery(last
);
195 strbuf_addf(&buffer
, "%sinfo/refs", url
);
196 if ((!prefixcmp(url
, "http://") || !prefixcmp(url
, "https://")) &&
197 git_env_bool("GIT_SMART_HTTP", 1)) {
199 if (!strchr(url
, '?'))
200 strbuf_addch(&buffer
, '?');
202 strbuf_addch(&buffer
, '&');
203 strbuf_addf(&buffer
, "service=%s", service
);
205 refs_url
= strbuf_detach(&buffer
, NULL
);
207 http_ret
= http_get_strbuf(refs_url
, &type
, &buffer
,
208 HTTP_NO_CACHE
| HTTP_KEEP_ERROR
);
212 case HTTP_MISSING_TARGET
:
213 show_http_message(&type
, &buffer
);
214 die("repository '%s' not found", url
);
216 show_http_message(&type
, &buffer
);
217 die("Authentication failed for '%s'", url
);
219 show_http_message(&type
, &buffer
);
220 die("unable to access '%s': %s", url
, curl_errorstr
);
223 last
= xcalloc(1, sizeof(*last_discovery
));
224 last
->service
= service
;
225 last
->buf_alloc
= strbuf_detach(&buffer
, &last
->len
);
226 last
->buf
= last
->buf_alloc
;
228 strbuf_addf(&exp
, "application/x-%s-advertisement", service
);
230 (5 <= last
->len
&& last
->buf
[4] == '#') &&
231 !strbuf_cmp(&exp
, &type
)) {
235 * smart HTTP response; validate that the service
236 * pkt-line matches our request.
238 line
= packet_read_line_buf(&last
->buf
, &last
->len
, NULL
);
241 strbuf_addf(&exp
, "# service=%s", service
);
242 if (strcmp(line
, exp
.buf
))
243 die("invalid server response; got '%s'", line
);
244 strbuf_release(&exp
);
246 /* The header can include additional metadata lines, up
247 * until a packet flush marker. Ignore these now, but
248 * in the future we might start to scan them.
250 while (packet_read_line_buf(&last
->buf
, &last
->len
, NULL
))
257 last
->refs
= parse_git_refs(last
, for_push
);
259 last
->refs
= parse_info_refs(last
);
262 strbuf_release(&exp
);
263 strbuf_release(&type
);
264 strbuf_release(&buffer
);
265 last_discovery
= last
;
269 static struct ref
*get_refs(int for_push
)
271 struct discovery
*heads
;
274 heads
= discover_refs("git-receive-pack", for_push
);
276 heads
= discover_refs("git-upload-pack", for_push
);
281 static void output_refs(struct ref
*refs
)
284 for (posn
= refs
; posn
; posn
= posn
->next
) {
286 printf("@%s %s\n", posn
->symref
, posn
->name
);
288 printf("%s %s\n", sha1_to_hex(posn
->old_sha1
), posn
->name
);
295 const char *service_name
;
297 struct strbuf
*stdin_preamble
;
299 char *hdr_content_type
;
307 struct strbuf result
;
308 unsigned gzip_request
: 1;
309 unsigned initial_buffer
: 1;
312 static size_t rpc_out(void *ptr
, size_t eltsize
,
313 size_t nmemb
, void *buffer_
)
315 size_t max
= eltsize
* nmemb
;
316 struct rpc_state
*rpc
= buffer_
;
317 size_t avail
= rpc
->len
- rpc
->pos
;
320 rpc
->initial_buffer
= 0;
321 avail
= packet_read(rpc
->out
, NULL
, NULL
, rpc
->buf
, rpc
->alloc
, 0);
330 memcpy(ptr
, rpc
->buf
+ rpc
->pos
, avail
);
335 #ifndef NO_CURL_IOCTL
336 static curlioerr
rpc_ioctl(CURL
*handle
, int cmd
, void *clientp
)
338 struct rpc_state
*rpc
= clientp
;
344 case CURLIOCMD_RESTARTREAD
:
345 if (rpc
->initial_buffer
) {
349 fprintf(stderr
, "Unable to rewind rpc post data - try increasing http.postBuffer\n");
350 return CURLIOE_FAILRESTART
;
353 return CURLIOE_UNKNOWNCMD
;
358 static size_t rpc_in(char *ptr
, size_t eltsize
,
359 size_t nmemb
, void *buffer_
)
361 size_t size
= eltsize
* nmemb
;
362 struct rpc_state
*rpc
= buffer_
;
363 write_or_die(rpc
->in
, ptr
, size
);
367 static int run_slot(struct active_request_slot
*slot
,
368 struct slot_results
*results
)
371 struct slot_results results_buf
;
374 results
= &results_buf
;
376 slot
->results
= results
;
377 slot
->curl_result
= curl_easy_perform(slot
->curl
);
378 finish_active_slot(slot
);
380 err
= handle_curl_result(results
);
381 if (err
!= HTTP_OK
&& err
!= HTTP_REAUTH
) {
382 error("RPC failed; result=%d, HTTP code = %ld",
383 results
->curl_result
, results
->http_code
);
389 static int probe_rpc(struct rpc_state
*rpc
, struct slot_results
*results
)
391 struct active_request_slot
*slot
;
392 struct curl_slist
*headers
= NULL
;
393 struct strbuf buf
= STRBUF_INIT
;
396 slot
= get_active_slot();
398 headers
= curl_slist_append(headers
, rpc
->hdr_content_type
);
399 headers
= curl_slist_append(headers
, rpc
->hdr_accept
);
401 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 0);
402 curl_easy_setopt(slot
->curl
, CURLOPT_POST
, 1);
403 curl_easy_setopt(slot
->curl
, CURLOPT_URL
, rpc
->service_url
);
404 curl_easy_setopt(slot
->curl
, CURLOPT_ENCODING
, NULL
);
405 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, "0000");
406 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, 4);
407 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, headers
);
408 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
, fwrite_buffer
);
409 curl_easy_setopt(slot
->curl
, CURLOPT_FILE
, &buf
);
411 err
= run_slot(slot
, results
);
413 curl_slist_free_all(headers
);
414 strbuf_release(&buf
);
418 static int post_rpc(struct rpc_state
*rpc
)
420 struct active_request_slot
*slot
;
421 struct curl_slist
*headers
= NULL
;
422 int use_gzip
= rpc
->gzip_request
;
423 char *gzip_body
= NULL
;
424 size_t gzip_size
= 0;
425 int err
, large_request
= 0;
427 /* Try to load the entire request, if we can fit it into the
428 * allocated buffer space we can use HTTP/1.0 and avoid the
429 * chunked encoding mess.
432 size_t left
= rpc
->alloc
- rpc
->len
;
433 char *buf
= rpc
->buf
+ rpc
->len
;
436 if (left
< LARGE_PACKET_MAX
) {
442 n
= packet_read(rpc
->out
, NULL
, NULL
, buf
, left
, 0);
450 err
= probe_rpc(rpc
, NULL
);
451 } while (err
== HTTP_REAUTH
);
456 headers
= curl_slist_append(headers
, rpc
->hdr_content_type
);
457 headers
= curl_slist_append(headers
, rpc
->hdr_accept
);
458 headers
= curl_slist_append(headers
, "Expect:");
461 slot
= get_active_slot();
463 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 0);
464 curl_easy_setopt(slot
->curl
, CURLOPT_POST
, 1);
465 curl_easy_setopt(slot
->curl
, CURLOPT_URL
, rpc
->service_url
);
466 curl_easy_setopt(slot
->curl
, CURLOPT_ENCODING
, "gzip");
469 /* The request body is large and the size cannot be predicted.
470 * We must use chunked encoding to send it.
472 headers
= curl_slist_append(headers
, "Transfer-Encoding: chunked");
473 rpc
->initial_buffer
= 1;
474 curl_easy_setopt(slot
->curl
, CURLOPT_READFUNCTION
, rpc_out
);
475 curl_easy_setopt(slot
->curl
, CURLOPT_INFILE
, rpc
);
476 #ifndef NO_CURL_IOCTL
477 curl_easy_setopt(slot
->curl
, CURLOPT_IOCTLFUNCTION
, rpc_ioctl
);
478 curl_easy_setopt(slot
->curl
, CURLOPT_IOCTLDATA
, rpc
);
480 if (options
.verbosity
> 1) {
481 fprintf(stderr
, "POST %s (chunked)\n", rpc
->service_name
);
485 } else if (gzip_body
) {
487 * If we are looping to retry authentication, then the previous
488 * run will have set up the headers and gzip buffer already,
489 * and we just need to send it.
491 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, gzip_body
);
492 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, gzip_size
);
494 } else if (use_gzip
&& 1024 < rpc
->len
) {
495 /* The client backend isn't giving us compressed data so
496 * we can try to deflate it ourselves, this may save on.
502 memset(&stream
, 0, sizeof(stream
));
503 git_deflate_init_gzip(&stream
, Z_BEST_COMPRESSION
);
504 gzip_size
= git_deflate_bound(&stream
, rpc
->len
);
505 gzip_body
= xmalloc(gzip_size
);
507 stream
.next_in
= (unsigned char *)rpc
->buf
;
508 stream
.avail_in
= rpc
->len
;
509 stream
.next_out
= (unsigned char *)gzip_body
;
510 stream
.avail_out
= gzip_size
;
512 ret
= git_deflate(&stream
, Z_FINISH
);
513 if (ret
!= Z_STREAM_END
)
514 die("cannot deflate request; zlib deflate error %d", ret
);
516 ret
= git_deflate_end_gently(&stream
);
518 die("cannot deflate request; zlib end error %d", ret
);
520 gzip_size
= stream
.total_out
;
522 headers
= curl_slist_append(headers
, "Content-Encoding: gzip");
523 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, gzip_body
);
524 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, gzip_size
);
526 if (options
.verbosity
> 1) {
527 fprintf(stderr
, "POST %s (gzip %lu to %lu bytes)\n",
529 (unsigned long)rpc
->len
, (unsigned long)gzip_size
);
533 /* We know the complete request size in advance, use the
534 * more normal Content-Length approach.
536 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, rpc
->buf
);
537 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, rpc
->len
);
538 if (options
.verbosity
> 1) {
539 fprintf(stderr
, "POST %s (%lu bytes)\n",
540 rpc
->service_name
, (unsigned long)rpc
->len
);
545 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, headers
);
546 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
, rpc_in
);
547 curl_easy_setopt(slot
->curl
, CURLOPT_FILE
, rpc
);
549 err
= run_slot(slot
, NULL
);
550 if (err
== HTTP_REAUTH
&& !large_request
)
555 curl_slist_free_all(headers
);
560 static int rpc_service(struct rpc_state
*rpc
, struct discovery
*heads
)
562 const char *svc
= rpc
->service_name
;
563 struct strbuf buf
= STRBUF_INIT
;
564 struct strbuf
*preamble
= rpc
->stdin_preamble
;
565 struct child_process client
;
568 memset(&client
, 0, sizeof(client
));
572 client
.argv
= rpc
->argv
;
573 if (start_command(&client
))
576 write_or_die(client
.in
, preamble
->buf
, preamble
->len
);
578 write_or_die(client
.in
, heads
->buf
, heads
->len
);
580 rpc
->alloc
= http_post_buffer
;
581 rpc
->buf
= xmalloc(rpc
->alloc
);
583 rpc
->out
= client
.out
;
584 strbuf_init(&rpc
->result
, 0);
586 strbuf_addf(&buf
, "%s%s", url
, svc
);
587 rpc
->service_url
= strbuf_detach(&buf
, NULL
);
589 strbuf_addf(&buf
, "Content-Type: application/x-%s-request", svc
);
590 rpc
->hdr_content_type
= strbuf_detach(&buf
, NULL
);
592 strbuf_addf(&buf
, "Accept: application/x-%s-result", svc
);
593 rpc
->hdr_accept
= strbuf_detach(&buf
, NULL
);
596 int n
= packet_read(rpc
->out
, NULL
, NULL
, rpc
->buf
, rpc
->alloc
, 0);
601 err
|= post_rpc(rpc
);
607 strbuf_read(&rpc
->result
, client
.out
, 0);
611 if (xread(client
.out
, buf
, sizeof(buf
)) <= 0)
618 err
|= finish_command(&client
);
619 free(rpc
->service_url
);
620 free(rpc
->hdr_content_type
);
621 free(rpc
->hdr_accept
);
623 strbuf_release(&buf
);
627 static int fetch_dumb(int nr_heads
, struct ref
**to_fetch
)
629 struct walker
*walker
;
630 char **targets
= xmalloc(nr_heads
* sizeof(char*));
634 die("dumb http transport does not support --depth");
635 for (i
= 0; i
< nr_heads
; i
++)
636 targets
[i
] = xstrdup(sha1_to_hex(to_fetch
[i
]->old_sha1
));
638 walker
= get_http_walker(url
);
640 walker
->get_tree
= 1;
641 walker
->get_history
= 1;
642 walker
->get_verbosely
= options
.verbosity
>= 3;
643 walker
->get_recover
= 0;
644 ret
= walker_fetch(walker
, nr_heads
, targets
, NULL
, NULL
);
647 for (i
= 0; i
< nr_heads
; i
++)
651 return ret
? error("Fetch failed.") : 0;
654 static int fetch_git(struct discovery
*heads
,
655 int nr_heads
, struct ref
**to_fetch
)
657 struct rpc_state rpc
;
658 struct strbuf preamble
= STRBUF_INIT
;
659 char *depth_arg
= NULL
;
660 int argc
= 0, i
, err
;
661 const char *argv
[15];
663 argv
[argc
++] = "fetch-pack";
664 argv
[argc
++] = "--stateless-rpc";
665 argv
[argc
++] = "--stdin";
666 argv
[argc
++] = "--lock-pack";
667 if (options
.followtags
)
668 argv
[argc
++] = "--include-tag";
670 argv
[argc
++] = "--thin";
671 if (options
.verbosity
>= 3) {
675 if (!options
.progress
)
676 argv
[argc
++] = "--no-progress";
678 struct strbuf buf
= STRBUF_INIT
;
679 strbuf_addf(&buf
, "--depth=%lu", options
.depth
);
680 depth_arg
= strbuf_detach(&buf
, NULL
);
681 argv
[argc
++] = depth_arg
;
686 for (i
= 0; i
< nr_heads
; i
++) {
687 struct ref
*ref
= to_fetch
[i
];
688 if (!ref
->name
|| !*ref
->name
)
689 die("cannot fetch by sha1 over smart http");
690 packet_buf_write(&preamble
, "%s\n", ref
->name
);
692 packet_buf_flush(&preamble
);
694 memset(&rpc
, 0, sizeof(rpc
));
695 rpc
.service_name
= "git-upload-pack",
697 rpc
.stdin_preamble
= &preamble
;
698 rpc
.gzip_request
= 1;
700 err
= rpc_service(&rpc
, heads
);
702 write_or_die(1, rpc
.result
.buf
, rpc
.result
.len
);
703 strbuf_release(&rpc
.result
);
704 strbuf_release(&preamble
);
709 static int fetch(int nr_heads
, struct ref
**to_fetch
)
711 struct discovery
*d
= discover_refs("git-upload-pack", 0);
713 return fetch_git(d
, nr_heads
, to_fetch
);
715 return fetch_dumb(nr_heads
, to_fetch
);
718 static void parse_fetch(struct strbuf
*buf
)
720 struct ref
**to_fetch
= NULL
;
721 struct ref
*list_head
= NULL
;
722 struct ref
**list
= &list_head
;
723 int alloc_heads
= 0, nr_heads
= 0;
726 if (!prefixcmp(buf
->buf
, "fetch ")) {
727 char *p
= buf
->buf
+ strlen("fetch ");
730 unsigned char old_sha1
[20];
732 if (strlen(p
) < 40 || get_sha1_hex(p
, old_sha1
))
733 die("protocol error: expected sha/ref, got %s'", p
);
739 die("protocol error: expected sha/ref, got %s'", p
);
741 ref
= alloc_ref(name
);
742 hashcpy(ref
->old_sha1
, old_sha1
);
747 ALLOC_GROW(to_fetch
, nr_heads
+ 1, alloc_heads
);
748 to_fetch
[nr_heads
++] = ref
;
751 die("http transport does not support %s", buf
->buf
);
754 if (strbuf_getline(buf
, stdin
, '\n') == EOF
)
760 if (fetch(nr_heads
, to_fetch
))
761 exit(128); /* error already reported */
762 free_refs(list_head
);
770 static int push_dav(int nr_spec
, char **specs
)
772 const char **argv
= xmalloc((10 + nr_spec
) * sizeof(char*));
775 argv
[argc
++] = "http-push";
776 argv
[argc
++] = "--helper-status";
778 argv
[argc
++] = "--dry-run";
779 if (options
.verbosity
> 1)
780 argv
[argc
++] = "--verbose";
782 for (i
= 0; i
< nr_spec
; i
++)
783 argv
[argc
++] = specs
[i
];
786 if (run_command_v_opt(argv
, RUN_GIT_CMD
))
787 die("git-%s failed", argv
[0]);
792 static int push_git(struct discovery
*heads
, int nr_spec
, char **specs
)
794 struct rpc_state rpc
;
796 struct argv_array args
;
798 argv_array_init(&args
);
799 argv_array_pushl(&args
, "send-pack", "--stateless-rpc", "--helper-status",
803 argv_array_push(&args
, "--thin");
805 argv_array_push(&args
, "--dry-run");
806 if (options
.verbosity
== 0)
807 argv_array_push(&args
, "--quiet");
808 else if (options
.verbosity
> 1)
809 argv_array_push(&args
, "--verbose");
810 argv_array_push(&args
, options
.progress
? "--progress" : "--no-progress");
811 argv_array_push(&args
, url
);
812 for (i
= 0; i
< nr_spec
; i
++)
813 argv_array_push(&args
, specs
[i
]);
815 memset(&rpc
, 0, sizeof(rpc
));
816 rpc
.service_name
= "git-receive-pack",
817 rpc
.argv
= args
.argv
;
819 err
= rpc_service(&rpc
, heads
);
821 write_or_die(1, rpc
.result
.buf
, rpc
.result
.len
);
822 strbuf_release(&rpc
.result
);
823 argv_array_clear(&args
);
827 static int push(int nr_spec
, char **specs
)
829 struct discovery
*heads
= discover_refs("git-receive-pack", 1);
832 if (heads
->proto_git
)
833 ret
= push_git(heads
, nr_spec
, specs
);
835 ret
= push_dav(nr_spec
, specs
);
836 free_discovery(heads
);
840 static void parse_push(struct strbuf
*buf
)
843 int alloc_spec
= 0, nr_spec
= 0, i
, ret
;
846 if (!prefixcmp(buf
->buf
, "push ")) {
847 ALLOC_GROW(specs
, nr_spec
+ 1, alloc_spec
);
848 specs
[nr_spec
++] = xstrdup(buf
->buf
+ 5);
851 die("http transport does not support %s", buf
->buf
);
854 if (strbuf_getline(buf
, stdin
, '\n') == EOF
)
860 ret
= push(nr_spec
, specs
);
865 exit(128); /* error already reported */
868 for (i
= 0; i
< nr_spec
; i
++)
873 int main(int argc
, const char **argv
)
875 struct strbuf buf
= STRBUF_INIT
;
878 git_extract_argv0_path(argv
[0]);
879 setup_git_directory_gently(&nongit
);
881 fprintf(stderr
, "Remote needed\n");
885 options
.verbosity
= 1;
886 options
.progress
= !!isatty(2);
889 remote
= remote_get(argv
[1]);
892 end_url_with_slash(&buf
, argv
[2]);
894 end_url_with_slash(&buf
, remote
->url
[0]);
897 url
= strbuf_detach(&buf
, NULL
);
899 http_init(remote
, url
, 0);
902 if (strbuf_getline(&buf
, stdin
, '\n') == EOF
) {
904 fprintf(stderr
, "Error reading command stream\n");
906 fprintf(stderr
, "Unexpected end of command stream\n");
911 if (!prefixcmp(buf
.buf
, "fetch ")) {
913 die("Fetch attempted without a local repo");
916 } else if (!strcmp(buf
.buf
, "list") || !prefixcmp(buf
.buf
, "list ")) {
917 int for_push
= !!strstr(buf
.buf
+ 4, "for-push");
918 output_refs(get_refs(for_push
));
920 } else if (!prefixcmp(buf
.buf
, "push ")) {
923 } else if (!prefixcmp(buf
.buf
, "option ")) {
924 char *name
= buf
.buf
+ strlen("option ");
925 char *value
= strchr(name
, ' ');
933 result
= set_option(name
, value
);
937 printf("error invalid value\n");
939 printf("unsupported\n");
942 } else if (!strcmp(buf
.buf
, "capabilities")) {
949 fprintf(stderr
, "Unknown command '%s'\n", buf
.buf
);