Artifact 1052b0c4dc927bd3cb5403ed3c7636242366ddb5
Ticket change
[1052b0c4dc]
- New ticket 2384764107 Make the http command working on Windows..
by
anonymous on
2009-09-17 14:08:24.
D 2009-09-17T14:08:24
J comment This\swould\smake\sit\spossible\sto\suse\sFossil\swith\sInetd\slike\sservers\son\sWindows,\sfor\sexample\s[http://www.xmailserver.org/wininetd.html].\r\n\r\nThe\sfollowing\spatch\sagainst\sFossil\sversion\s[0eb08b860c]\simplements\sthis\sfunctionality:\r\n\r\n<verbatim>\r\ndiff\s-Naur\sfossil-src/src/cgi.c\sfossil-src-mod/src/cgi.c\r\n---\sfossil-src/src/cgi.c\t2009-09-13\s09:37:48\s+0000\r\n+++\sfossil-src-mod/src/cgi.c\t2009-09-17\s11:25:47\s+0000\r\n@@\s-29,10\s+29,11\s@@\r\n\s*/\r\n\s#include\s"config.h"\r\n\s#ifdef\s__MINGW32__\r\n-#\s\sinclude\s<windows.h>\s\s\s\s\s\s\s\s\s\s\s/*\sfor\sSleep\sonce\sserver\sworks\sagain\s*/\r\n-#\s\sinclude\s<winsock2.h>\s\s\s\s\s\s\s\s\s\s/*\ssocket\soperations\s*/\r\n-#\s\sdefine\ssleep\sSleep\s\s\s\s\s\s\s\s\s\s\s\s/*\swindows\sdoes\snot\shave\ssleep,\sbut\sSleep\s*/\r\n-#\s\sinclude\s<ws2tcpip.h>\s\s\s\s\s\s\s\s\s\s\r\n+#\s\sinclude\s<windows.h>\s\s\s\s\s\s\s\s\s\s\s/*\sWindows\sspecific\sdeclarations\s*/\r\n+#\s\sinclude\s<winsock2.h>\s\s\s\s\s\s\s\s\s\s/*\sWindows\ssocket\soperations\s*/\r\n+#\s\sinclude\s<ws2tcpip.h>\s\s\s\s\s\s\s\s\s\s/*\sfor\ssocklen_t\s*/\r\n+#\s\sinclude\s<fcntl.h>\r\n+#\s\sinclude\s<io.h>\r\n\s#else\r\n\s#\s\sinclude\s<sys/socket.h>\r\n\s#\s\sinclude\s<netinet/in.h>\r\n@@\s-1076,6\s+1077,95\s@@\r\n\s\s\sreturn\szResult;\r\n\s}\r\n\s\r\n+#ifdef\s__MINGW32__\r\n+/*\r\n+**\sData\sstructure\srelated\sto\sall\svariables\sfor\sthe\swindows\ssocket\senvironment.\r\n+*/\r\n+typedef\sstruct\sWinSocketData\s{\r\n+\s\sint\s\s\s\s\sfWSAInit;\s\s\s\s\s\s\s/*\sTrue,\sif\sWindows\ssockets\sinitialized\s*/\r\n+\s\sSOCKET\s\shSocket;\s\s\s\s\s\s\s\s/*\sHandle\sto\sthe\ssocket\s*/\r\n+}\sWinSocketData;\r\n+\r\n+static\sWinSocketData\swsd;\r\n+\r\n+/*\r\n+**\sExit\shandler\sroutine.\sMake\ssure\sany\sremaining\soutput\sgets\sflushed\sto\sthe\r\n+**\soutput\sstream.\sIf\sthe\sstandard\shandles\sare\sredirected\sto\sa\ssocket\sthen\r\n+**\smake\sshure\sthe\ssocket\sgets\sclosed\sproperly\sand\sclean\sup\sthe\swindows\ssocket\r\n+**\senvironment.\r\n+*/\r\n+static\svoid\scgi_handle_http_request_exit(void)\r\n+{\r\n+\s\sfflush(g.httpOut);\r\n+\r\n+\s\sif(\swsd.hSocket\s!=\sINVALID_SOCKET\s){\r\n+\s\s\s\sshutdown(wsd.hSocket,\sSD_BOTH);\r\n+\s\s\s\sclosesocket(wsd.hSocket);\r\n+\s\s}\r\n+\s\sif\s(wsd.fWSAInit)\s{\r\n+\s\s\s\sWSACleanup();\r\n+\s\s}\r\n+\s\sreturn;\r\n+}\r\n+\r\n+/*\r\n+**\sThis\sroutine\sinitalizes\sthe\senvironment\son\swindows\sfor\sthe\r\n+**\scgi_handle_http_request\sroutine.\sIt\ssets\sthe\sstandard\sinput\sand\souput\r\n+**\shandles\sto\sbinary\smode,\sinitalizes\sthe\swindows\ssocket\senvironment\sand\stries\r\n+**\sto\sget\sthe\ssocket\shandle\sfrom\sthe\sstandard\shandles.\sIt\salso\sestablishs\sa\r\n+**\sexit\sroutine\sto\sclean\sup\son\sprogram\sexit.\r\n+*/\r\n+void\scgi_handle_http_request_init(void)\r\n+{\r\n+\s\sWSADATA\swd;\r\n+\s\sSOCKET\shSock;\r\n+\s\sint\ssocket_type;\r\n+\s\sint\ssocket_type_len\s=\ssizeof(socket_type);\r\n+\r\n+\s\s/*\r\n+\s\s**\sInitialize\sthe\swindows\ssocket\sdata\sstructure.\r\n+\s\s*/\r\n+\s\swsd.fWSAInit\s=\s0;\r\n+\s\swsd.hSocket\s=\sINVALID_SOCKET;\r\n+\r\n+\s\s/*\r\n+\s\s**\sRegister\sthe\sexit\sfunction.\r\n+\s\s*/\r\n+\s\satexit(cgi_handle_http_request_exit);\r\n+\r\n+\s\s/*\r\n+\s\s**\sSet\sthe\smode\sof\sthe\shttp\sinput\sand\soutput\sstreams\sto\sbinary.\r\n+\s\s*/\r\n+\s\s_setmode(_fileno(g.httpIn),\s\s_O_BINARY);\r\n+\s\s_setmode(_fileno(g.httpOut),\s_O_BINARY);\r\n+\r\n+\s\s/*\r\n+\s\s**\sInitialize\sthe\swindows\ssocket\sAPI.\sThis\sis\srequired\sif\swe\sneed\sto\r\n+\s\s**\scall\sany\sother\sWindows\sSocket\sfunction.\r\n+\s\s*/\r\n+\s\sif(\sWSAStartup(MAKEWORD(2,2),\s&wd)\s==\s0\s)\swsd.fWSAInit\s=\s1;\r\n+\r\n+\s\s/*\r\n+\s\s**\sWindows\sSocket\shandles\smust\sbe\shandled\sdifferently\sthan\sfile\shandles.\r\n+\s\s**\sThere\sis\sno\sfunction\sto\sdetect\sif\sa\sfile\shandle\sis\sa\ssocket\sor\snot,\sso\r\n+\s\s**\slets\scall\sa\ssocket\sfunction\swith\sthe\shandle\sfrom\sstdin,\sand\sif\sthere\sis\r\n+\s\s**\sno\serror,\sassume\sit\sis\sa\ssocket!\r\n+\s\s*/\r\n+\s\sif(\swsd.fWSAInit\s){\r\n+\s\s\s\shSock\s=\s(SOCKET)_get_osfhandle(_fileno(stdin));\r\n+\s\s\s\sif(\sgetsockopt\s(hSock,\sSOL_SOCKET,\sSO_TYPE,\r\n+\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s(char\s*)&socket_type,\s&socket_type_len)\s==\s0\s){\r\n+\s\s\s\s\s\swsd.hSocket\s=\shSock;\r\n+\s\s\s\s}\r\n+\s\s}\r\n+\s\sreturn;\r\n+}\r\n+\r\n+#\s\sdefine\sCGI_SOCKET\swsd.hSocket\r\n+#else\r\n+#\s\sdefine\sCGI_SOCKET\sfileno(g.httpIn)\r\n+#endif\s/*\s__MINGW32__\s*/\r\n+\r\n\s/*\r\n\s**\sThis\sroutine\shandles\sa\ssingle\sHTTP\srequest\swhich\sis\scoming\sin\son\r\n\s**\sstandard\sinput\sand\swhich\sreplies\son\sstandard\soutput.\r\n@@\s-1092,6\s+1182,9\s@@\r\n\s\s\ssize_t\ssize\s=\ssizeof(struct\ssockaddr_in);\r\n\s\s\schar\szLine[2000];\s\s\s\s\s/*\sA\ssingle\sline\sof\sinput.\s*/\r\n\s\r\n+#ifdef\s__MINGW32__\r\n+\s\scgi_handle_http_request_init();\r\n+#endif\r\n\s\s\sg.fullHttpReply\s=\s1;\r\n\s\s\sif(\sfgets(zLine,\ssizeof(zLine),g.httpIn)==0\s){\r\n\s\s\s\s\smalformed_request();\r\n@@\s-1116,7\s+1209,7\s@@\r\n\s\s\scgi_setenv("PATH_INFO",\szToken);\r\n\s\s\scgi_setenv("QUERY_STRING",\s&zToken[i]);\r\n\s\s\sif(\szIpAddr==0\s&&\r\n-\s\s\s\s\s\s\s\sgetpeername(fileno(g.httpIn),\s(struct\ssockaddr*)&remoteName,\s\r\n+\s\s\s\s\s\s\s\sgetpeername(CGI_SOCKET,\s(struct\ssockaddr*)&remoteName,\s\r\n\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s(socklen_t*)&size)>=0\r\n\s\s\s){\r\n\s\s\s\s\szIpAddr\s=\sinet_ntoa(remoteName.sin_addr);\r\n</verbatim>\r\n\r\n--tsbg
J foundin 0eb08b860c
J private_contact 76518fb407f147a1d053c00b5b993281a339c0e3
J severity Important
J status Open
J title Make\sthe\shttp\scommand\sworking\son\sWindows.
J type Feature_Request
K 2384764107f0d084867503e16461f18b80f72e24
U anonymous
Z 82eef6ac9138b0d099a52bc433ee7876