source: branches/New_Config_Format-branch/gsdl/src/w32server/httpsrv.cpp@ 1279

Last change on this file since 1279 was 1279, checked in by sjboddie, 24 years ago

merged changes to trunk into New_Config_Format branch

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1/*
2Copyright (C) 1996
3
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation; either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18The author can be contacted via Email at [email protected]
19*/
20#include "text_t.h"
21#include <windows.h>
22#include <stdlib.h>
23#include <stdio.h>
24#include <string.h>
25#include <memory.h>
26#pragma hdrstop
27#include "netio.h"
28#include "settings.h"
29#include "httpreq.h"
30#include "httpsrv.h"
31#include "locate.h"
32
33//Private Functions
34
35/*
36Function Name: HTTP Server Answer
37Purpose: Answers messages saying that a connection is ready to start
38*/
39void HTTPServerAnswer();
40
41//Module Vars
42static SOCKET ServerSocket = INVALID_SOCKET;
43
44static HWND MsgWindow;
45
46/******************************************************************************/
47// returns 0 on success, and a WSA error otherwise
48int StartHTTPServer(HWND PassedMsgWindow) {
49
50 MsgWindow = PassedMsgWindow;
51 //Create the server socket
52 return CreateListeningSocket(gsdl_port_num, MsgWindow, HTTP_SERVER_MSG, ServerSocket);
53}
54
55/******************************************************************************/
56void EndHTTPServer()
57{
58 //Stop the listening socket
59 DestroyListeningSocket(ServerSocket, MsgWindow);
60}
61
62/******************************************************************************/
63void ProcessHTTPServerMsg(WPARAM Socket, LPARAM MsgInfo) {
64 log_message("accept message arrived\n");
65 if (Socket != ServerSocket) {
66 if (gsdl_keep_log || gsdl_show_console) log_message("Incorrect socket sent in message");
67 }
68 switch (WSAGETSELECTEVENT(MsgInfo)) {
69 case FD_ACCEPT:
70 switch (WSAGETSELECTERROR(MsgInfo)) {
71 case WSAENETDOWN:
72 LogCriticalError("1","Network Down");
73 break;
74 default: //No Error
75 HTTPServerAnswer();
76 }
77 break;
78 }
79}
80
81/******************************************************************************/
82void HTTPServerAnswer() {
83 SOCKADDR_IN ClientSockAddr;
84 SOCKET ClientSocket;
85 int AddrLen = sizeof(SOCKADDR_IN);
86 RequestThreadMessageT Parameters;
87 while (AnswerListeningSocket(ServerSocket, ClientSocket, ClientSockAddr, AddrLen) == 0) {
88 log_message("Answering socket\n");
89 //Call the thread procedure to handle the connection
90 Parameters.ClientSockAddr = ClientSockAddr;
91 Parameters.ClientSocket = ClientSocket;
92 Parameters.AddrLen = AddrLen;
93 RequestThread(&Parameters);
94 }
95}
96
Note: See TracBrowser for help on using the repository browser.