source: main/trunk/greenstone2/runtime-src/src/w32server/httpsrv.cpp@ 30565

Last change on this file since 30565 was 2286, checked in by sjboddie, 23 years ago

Had a bit of a tidy up in the fnord webserver code. The main change of note
was the removal of our reliance on the MAX_URL_SIZE constant. URLs and post
data of any length should now work.

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