2002-08-02 23:57:46 +04:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2002-05-30 20:13:16 +04:00
|
|
|
#ifndef CHTTPSERVER_H
|
|
|
|
#define CHTTPSERVER_H
|
|
|
|
|
|
|
|
#include "CString.h"
|
2002-06-11 02:06:45 +04:00
|
|
|
#include "BasicTypes.h"
|
2002-06-01 23:26:11 +04:00
|
|
|
#include "stdvector.h"
|
2002-05-30 20:13:16 +04:00
|
|
|
|
|
|
|
class CServer;
|
2002-05-31 18:43:23 +04:00
|
|
|
class CConfig;
|
2002-05-30 20:13:16 +04:00
|
|
|
class CHTTPRequest;
|
|
|
|
class CHTTPReply;
|
2002-06-17 16:02:26 +04:00
|
|
|
class IDataSocket;
|
2002-05-30 20:13:16 +04:00
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//! Simple HTTP server
|
|
|
|
/*!
|
|
|
|
This class implements a simple HTTP server for interacting with the
|
|
|
|
synergy server.
|
|
|
|
*/
|
2002-05-30 20:13:16 +04:00
|
|
|
class CHTTPServer {
|
|
|
|
public:
|
|
|
|
CHTTPServer(CServer*);
|
|
|
|
virtual ~CHTTPServer();
|
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//! @name manipulators
|
|
|
|
//@{
|
2002-05-30 20:13:16 +04:00
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//! Process HTTP request
|
|
|
|
/*!
|
|
|
|
Synchronously processes an HTTP request on the given socket.
|
|
|
|
*/
|
2002-06-17 16:02:26 +04:00
|
|
|
void processRequest(IDataSocket*);
|
2002-05-30 20:13:16 +04:00
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//@}
|
2002-05-30 20:13:16 +04:00
|
|
|
|
|
|
|
protected:
|
2002-07-30 18:59:36 +04:00
|
|
|
//! Process HTTP request
|
|
|
|
/*!
|
|
|
|
Processes a successfully read HTTP request. The reply is partially
|
|
|
|
filled in (version, method, status (200) and reason (OK)). This
|
|
|
|
method checks the URI and handles the request, filling in the rest
|
|
|
|
of the reply. If the request cannot be satisfied it throws an
|
|
|
|
appropriate XHTTP exception.
|
|
|
|
*/
|
2002-05-30 20:13:16 +04:00
|
|
|
virtual void doProcessRequest(CHTTPRequest&, CHTTPReply&);
|
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//! Process request for map
|
2002-05-30 20:13:16 +04:00
|
|
|
virtual void doProcessGetEditMap(CHTTPRequest&, CHTTPReply&);
|
2002-07-30 18:59:36 +04:00
|
|
|
|
|
|
|
//! Process request for changing map
|
2002-05-30 20:13:16 +04:00
|
|
|
virtual void doProcessPostEditMap(CHTTPRequest&, CHTTPReply&);
|
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//! Parse coordinate string
|
2002-05-30 20:13:16 +04:00
|
|
|
static bool parseXY(const CString&, SInt32& x, SInt32& y);
|
|
|
|
|
2002-07-30 18:59:36 +04:00
|
|
|
//! Screen map helper
|
|
|
|
/*!
|
|
|
|
This class represents the screen map as a resizable array. It's
|
|
|
|
used to handle map requests.
|
|
|
|
*/
|
2002-05-30 20:13:16 +04:00
|
|
|
class CScreenArray {
|
|
|
|
public:
|
|
|
|
CScreenArray();
|
|
|
|
~CScreenArray();
|
|
|
|
|
|
|
|
// resize the array. this also clears all the elements.
|
|
|
|
void resize(SInt32 w, SInt32 h);
|
|
|
|
|
|
|
|
// insert/remove a row/column. all elements in a new row/column
|
|
|
|
// are unset.
|
|
|
|
void insertRow(SInt32 insertedBeforeRow);
|
|
|
|
void insertColumn(SInt32 insertedBeforeColumn);
|
|
|
|
void eraseRow(SInt32 row);
|
|
|
|
void eraseColumn(SInt32 column);
|
|
|
|
|
|
|
|
// rotate rows or columns
|
|
|
|
void rotateRows(SInt32 rowsDown);
|
|
|
|
void rotateColumns(SInt32 columnsDown);
|
|
|
|
|
|
|
|
// remove/set a screen name. setting an empty name is the
|
|
|
|
// same as removing a name. names are not checked for
|
|
|
|
// validity.
|
|
|
|
void remove(SInt32 x, SInt32 y);
|
|
|
|
void set(SInt32 x, SInt32 y, const CString&);
|
|
|
|
|
2002-05-31 18:43:23 +04:00
|
|
|
// convert a CConfig to a CScreenArray. returns true iff
|
2002-05-30 20:13:16 +04:00
|
|
|
// all connections are symmetric and therefore exactly
|
|
|
|
// representable by a CScreenArray.
|
2002-05-31 18:43:23 +04:00
|
|
|
bool convertFrom(const CConfig&);
|
2002-05-30 20:13:16 +04:00
|
|
|
|
|
|
|
// accessors
|
|
|
|
|
|
|
|
// get the array size
|
|
|
|
SInt32 getWidth() const { return m_w; }
|
|
|
|
SInt32 getHeight() const { return m_h; }
|
|
|
|
|
|
|
|
// returns true iff the cell has a 4-connected neighbor
|
|
|
|
bool isAllowed(SInt32 x, SInt32 y) const;
|
|
|
|
|
|
|
|
// returns true iff the cell has a (non-empty) name
|
|
|
|
bool isSet(SInt32 x, SInt32 y) const;
|
|
|
|
|
|
|
|
// get a screen name
|
|
|
|
CString get(SInt32 x, SInt32 y) const;
|
|
|
|
|
|
|
|
// find a screen by name. returns true iff found.
|
|
|
|
bool find(const CString&, SInt32& x, SInt32& y) const;
|
|
|
|
|
|
|
|
// return true iff the overall array is valid. that means
|
|
|
|
// just zero or one screen or all screens are 4-connected
|
|
|
|
// to other screens.
|
|
|
|
bool isValid() const;
|
|
|
|
|
2002-05-31 18:43:23 +04:00
|
|
|
// convert this to a CConfig
|
|
|
|
void convertTo(CConfig&) const;
|
2002-05-30 20:13:16 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
typedef std::vector<CString> CNames;
|
|
|
|
|
|
|
|
SInt32 m_w, m_h;
|
|
|
|
CNames m_screens;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
CServer* m_server;
|
2002-06-02 17:34:35 +04:00
|
|
|
static const UInt32 s_maxRequestSize;
|
2002-05-30 20:13:16 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|