{"thread":{"id":"4417","subject":"[PATCH] Refactor git_tcp_connect() functions a little.","startedAt":"2006-06-07T03:58:41Z","lastAt":"2006-06-07T04:53:04Z","messageCount":2,"participants":["Jon Loeliger","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"21368","messageId":"E1FnpBp-00043u-Uc@jdl.com","threadId":"4417","inReplyTo":null,"subject":"[PATCH] Refactor git_tcp_connect() functions a little.","fromName":"Jon Loeliger","fromEmail":"jdl@jdl.com","sentAt":"2006-06-07T03:58:41Z","receivedAt":"2006-06-07T03:58:41Z","isPatch":true,"sender":{"key":"jdl@jdl.com","avatar":"https://gravatar.com/avatar/75ce9a10b151acd2c28ec4ab2136dba7b2ff1634530bd04b155981a749d08a64?d=mp&s=160"},"body":"Add client side sending of \"\\0host=%s\\0\" extended\narg for git native protocol, backwards compatibly.\n\nSigned-off-by: Jon Loeliger <jdl@jdl.com>\n---\n connect.c |   42 ++++++++++++++++++++++++++++++++----------\n 1 files changed, 32 insertions(+), 10 deletions(-)\n\nI've tested this against an \"old\" daemon, and my new daemon\nrunning on jdl.com that understands the new host=%s parameter.\nBoth appear to work still.\n\nHowever, I don't have a setup to test a proxy connection,\nand I left FIXME: down there asking the question if it is\neven needed in this case as well.  I _think_ so, but I am\njust not sure.  (It should be a straight pass-through to\nanother git: native protocol, right?)\n\nAnd if it is needed there too, do you want to refactor\nthese two packet_writes() for commonality again?\n\n\ndiff --git a/connect.c b/connect.c\nindex 54f7bf7..3fa890d 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -322,7 +322,10 @@ #define STR(s)\tSTR_(s)\n \n #ifndef NO_IPV6\n \n-static int git_tcp_connect(int fd[2], const char *prog, char *host, char *path)\n+/*\n+ * Returns a connected socket() fd, or else die()s.\n+ */\n+static int git_tcp_connect_sock(char *host)\n {\n \tint sockfd = -1;\n \tchar *colon, *end;\n@@ -356,7 +359,8 @@ static int git_tcp_connect(int fd[2], co\n \t\tdie(\"Unable to look up %s (%s)\", host, gai_strerror(gai));\n \n \tfor (ai0 = ai; ai; ai = ai->ai_next) {\n-\t\tsockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);\n+\t\tsockfd = socket(ai->ai_family,\n+\t\t\t\tai->ai_socktype, ai->ai_protocol);\n \t\tif (sockfd < 0)\n \t\t\tcontinue;\n \t\tif (connect(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) {\n@@ -372,15 +376,15 @@ static int git_tcp_connect(int fd[2], co\n \tif (sockfd < 0)\n \t\tdie(\"unable to connect a socket (%s)\", strerror(errno));\n \n-\tfd[0] = sockfd;\n-\tfd[1] = sockfd;\n-\tpacket_write(sockfd, \"%s %s\\n\", prog, path);\n-\treturn 0;\n+\treturn sockfd;\n }\n \n #else /* NO_IPV6 */\n \n-static int git_tcp_connect(int fd[2], const char *prog, char *host, char *path)\n+/*\n+ * Returns a connected socket() fd, or else die()s.\n+ */\n+static int git_tcp_connect_sock(char *host)\n {\n \tint sockfd = -1;\n \tchar *colon, *end;\n@@ -407,7 +411,6 @@ static int git_tcp_connect(int fd[2], co\n \t\tport = colon + 1;\n \t}\n \n-\n \the = gethostbyname(host);\n \tif (!he)\n \t\tdie(\"Unable to look up %s (%s)\", host, hstrerror(h_errno));\n@@ -441,13 +444,29 @@ static int git_tcp_connect(int fd[2], co\n \tif (sockfd < 0)\n \t\tdie(\"unable to connect a socket (%s)\", strerror(errno));\n \n+\treturn sockfd;\n+}\n+\n+#endif /* NO_IPV6 */\n+\n+\n+static int git_tcp_connect(int fd[2],\n+\t\t\t   const char *prog, char *host, char *path)\n+{\n+\tint sockfd = git_tcp_connect_sock(host);\n+\n \tfd[0] = sockfd;\n \tfd[1] = sockfd;\n-\tpacket_write(sockfd, \"%s %s\\n\", prog, path);\n+\n+\t/*\n+\t * Separate original protocol components prog and path\n+\t * from extended components with a NUL byte.\n+\t */\n+\tpacket_write(sockfd, \"%s %s%chost=%s%c\", prog, path, 0, host, 0);\n+\n \treturn 0;\n }\n \n-#endif /* NO_IPV6 */\n \n static char *git_proxy_command = NULL;\n static const char *rhost_name = NULL;\n@@ -551,7 +570,10 @@ static int git_proxy_connect(int fd[2], \n \tfd[1] = pipefd[1][1];\n \tclose(pipefd[0][1]);\n \tclose(pipefd[1][0]);\n+\n+\t/* FIXME: Does this need %chost=%s%c tacked on here too? */\n \tpacket_write(fd[1], \"%s %s\\n\", prog, path);\n+\n \treturn pid;\n }\n \n-- \n1.4.0.rc1.ga6a5-dirty\n"},{"id":"21369","messageId":"7vy7w9lg7j.fsf@assigned-by-dhcp.cox.net","threadId":"4417","inReplyTo":"E1FnpBp-00043u-Uc@jdl.com","subject":"Re: [PATCH] Refactor git_tcp_connect() functions a little.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-06-07T04:53:04Z","receivedAt":"2006-06-07T04:53:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jon Loeliger <jdl@jdl.com> writes:\n\n> Add client side sending of \"\\0host=%s\\0\" extended\n> arg for git native protocol, backwards compatibly.\n>\n> Signed-off-by: Jon Loeliger <jdl@jdl.com>\n> ---\n>  connect.c |   42 ++++++++++++++++++++++++++++++++----------\n>  1 files changed, 32 insertions(+), 10 deletions(-)\n>\n> I've tested this against an \"old\" daemon, and my new daemon\n> running on jdl.com that understands the new host=%s parameter.\n> Both appear to work still.\n\nThanks.\n\n> However, I don't have a setup to test a proxy connection,\n> and I left FIXME: down there asking the question if it is\n> even needed in this case as well.  I _think_ so, but I am\n> just not sure.  (It should be a straight pass-through to\n> another git: native protocol, right?)\n\nI think so.\n\n> And if it is needed there too, do you want to refactor\n> these two packet_writes() for commonality again?\n\nLet me munge that part and push it out.  I've tested it lightly\nboth with and without proxy.  My proxy was a single liner shell\nscript:\n\n\tnc -o /var/tmp/nc.log localhost 9418\n\nwhose dump started with this nice request packet:\n\n> 00000000 30 30 35 62 67 69 74 2d 75 70 6c 6f 61 64 2d 70 # 005bgit-upload-p\n> 00000010 61 63 6b 20 2f 6f 70 74 2f 70 61 63 6b 72 61 74 # ack /opt/packrat\n> 00000020 2f 70 6c 61 79 70 65 6e 2f 70 75 62 6c 69 63 2f # /playpen/public/\n> 00000030 69 6e 2d 70 6c 61 63 65 2f 67 69 74 2f 67 69 74 # in-place/git/git\n> 00000040 2e 6a 75 6e 69 6f 00 68 6f 73 74 3d 6c 6f 63 61 # .junio.host=loca\n> 00000050 6c 68 6f 73 74 3a 34 34 33 33 00                # lhost:4433.\n\nfor a request \"peek-remote git://localhost:4433/opt/.../git.junio\".\n\nI suspect that a real git proxy, if somebody ever writes one,\nwould read the first outgoing packet reads the request\n(including this host= stuff) and connect to the true destination\nintelligently after sending out a modified request packet.\n\nTakers?\n"}]}