File: SimpleWebServer.h

package info (click to toggle)
gnustep-base 1.31.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,580 kB
  • sloc: objc: 239,446; ansic: 36,519; cpp: 122; sh: 112; makefile: 100; xml: 32
file content (116 lines) | stat: -rw-r--r-- 3,729 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/** -*- objc -*-
 *
 * Author: Sergei Golovin <svgdev@mail.ru>
 *
 */

#import <Foundation/Foundation.h>
#import <GNUstepBase/GSMime.h>

/**
 *  Implements a simple web server with delegate interaction which mimic of
 *  the WebServer's delegate protocol.
 *
 *  The SimpleWebServer class currently has many limitations (deficiencies).
 *  The following is a list of most important ones:
 *     - supports only one connection simultaneously.
 *     - doesn't support any transfer-content-encoding (more precisely it uses
 *       only 'identity' transfer-content-encoding that is without any modification
 *       of the content/message);
 *     - the class uses UTF8 by default. It expects a request and produces responses 
 *       in that encoding;
 *     - it expects an explicit request for closing of the connection (that is
 *       the request's header 'Connection' must be 'close') or implicitly does it
 *       if no 'Connection' has been supplied;
 *     - doesn't support pipelining of requests;
 *
 *  Use the -[setDebug: YES] to raise verbosity.
 */
@interface SimpleWebServer : NSObject
{
  /* holds the file handler of connection */
  NSFileHandle            *_fh;
  /* holds the 'near' file handler of connection...
     see "Background Inter-Process Communication Using Sockets"
     of Low-Level File Management Programming Topics
  */
  NSFileHandle            *_cfh;

  /* the delegate ... NOT RETAINED...
   * see below the protocol SimpleWebServerDelegate */
  id                  _delegate;
  /* the debug mode */
  BOOL                   _debug;
  /* the address to bind with */
  NSString            *_address;
  /* the port to listen to */
  NSString               *_port;
  /* SSL configuration and options */
  NSDictionary         *_secure;
  /* whether to use a secure TLS/SSL connection */
  BOOL                _isSecure;
  /* the collector of received bytes from a client */
  NSMutableData	      *_capture;
  /* holds the current request */
  GSMimeDocument      *_request;
  /* holds the current response */
  GSMimeDocument     *_response;
  /* the flag the server wants to operate */
  BOOL _isRunning;
  /* to close the connection after sending the response */
  BOOL _isClose;
}
- (void)dealloc;

/* getters */
/**
 *  Returns the string of the port number if the instance is accepting
 *  connections (is started). Otherwise returns nil.
 */
- (NSString *)port;
/* end of getters */

/* setters */
/**
 *  Starts the simple web server listening on the supplied address and port.
 *  The dictionary 'dict' is supplied with additional configuration parameters.
 *  connections. The dictionary's keys are:
 *     CertificateFile
 *       the path to a certificate (if the web server should wait for HTTPS)
 *     KeyFile
 *       the path to a key (if the web server should wait for HTTPS)
 */
- (BOOL)setAddress:(NSString *)address
	      port:(NSString *)port
	    secure:(NSDictionary *)dict;
/**
 *  Sets the debug mode.
 */
- (void)setDebug:(BOOL)flag;

/**
 *  Sets the delegate responding to the selector -[processRequest:response:].
 */
- (void)setDelegate:(id)delegate;
/* end of setters */

/**
 *  Commands the web server to stop listening.
 */
- (void)stop;

@end /* SimpleWebServer */

@protocol SimpleWebServerDelegate
/**
 *  An implementor gets the supplied request for processing and
 *  modifies the supplied response which the supplied SimpleWebServer
 *  server should send back to it's peer if the return value is set
 *  to YES. Otherwise SimpleWebServer sends the predetermined response
 *  (TODO).
 */
- (BOOL)processRequest:(GSMimeDocument *)request
	      response:(GSMimeDocument *)response
		   for:(SimpleWebServer *)server;

@end /* SimpleWebServerDelegate */