aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/session.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/session.h')
-rw-r--r--src/daemon/session.h154
1 files changed, 154 insertions, 0 deletions
diff --git a/src/daemon/session.h b/src/daemon/session.h
new file mode 100644
index 00000000..5e8be40c
--- /dev/null
+++ b/src/daemon/session.h
@@ -0,0 +1,154 @@
1/*
2 This file is part of libmicrohttpd
3 (C) 2007 Daniel Pittman
4
5 libmicrohttpd is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 libmicrohttpd is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with libmicrohttpd; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file session.h
23 * @brief Methods for managing sessions
24 * @author Daniel Pittman
25 * @author Christian Grothoff
26 * @version 0.1.0
27 */
28
29#ifndef SESSION_H
30#define SESSION_H
31
32
33struct MHD_Session {
34 struct MHD_Session * next;
35
36 struct MHD_Daemon * daemon;
37
38 struct MHD_HTTP_Header * headers_received;
39
40 struct MHD_Response * response;
41
42 char * requestType;
43
44 /**
45 * Buffer for reading requests.
46 */
47 void * read_buffer;
48
49 /**
50 * Buffer for writing response.
51 */
52 void * write_buffer;
53
54 /**
55 * Foreign address (of length addr_len).
56 */
57 struct sockaddr_in * addr;
58
59 /**
60 * Thread for this session (if we are using
61 * one thread per connection).
62 */
63 pthread_t pid;
64
65 size_t read_buffer_size;
66
67 size_t readLoc;
68
69 size_t write_buffer_size;
70
71 size_t writeLoc;
72
73 /**
74 * Current write position in the actual response
75 * (excluding headers, content only; should be 0
76 * while sending headers).
77 */
78 size_t messagePos;
79
80 /**
81 * Length of the foreign address.
82 */
83 socklen_t addr_len;
84
85 /**
86 * Socket for this connection. Set to -1 if
87 * this connection has died (daemon should clean
88 * up in that case).
89 */
90 int socket_fd;
91
92 /**
93 * Have we finished receiving all of the headers yet?
94 * Set to 1 once we are done processing all of the
95 * headers. Note that due to pipelining, it is
96 * possible that the NEXT request is already
97 * (partially) waiting in the read buffer.
98 */
99 int headersReceived;
100
101 /**
102 * Have we finished receiving the data from a
103 * potential file-upload?
104 */
105 int bodyReceived;
106
107 /**
108 * Have we finished sending all of the headers yet?
109 */
110 int headersSent;
111
112 /**
113 * HTTP response code. Only valid if response object
114 * is already set.
115 */
116 unsigned int responseCode;
117
118};
119
120
121/**
122 * Obtain the select sets for this session.
123 *
124 * @return MHD_YES on success
125 */
126int
127MHD_session_get_fdset(struct MHD_Session * session,
128 fd_set * read_fd_set,
129 fd_set * write_fd_set,
130 fd_set * except_fd_set,
131 int * max_fd);
132
133
134/**
135 * This function handles a particular connection when it has been
136 * determined that there is data to be read off a socket. All implementations
137 * (multithreaded, external select, internal select) call this function
138 * to handle reads.
139 */
140int
141MHD_session_handle_read(struct MHD_Session * session);
142
143
144/**
145 * This function was created to handle writes to sockets when it has been
146 * determined that the socket can be written to. If there is no data
147 * to be written, however, the function call does nothing. All implementations
148 * (multithreaded, external select, internal select) call this function
149 */
150int
151MHD_session_handle_write(struct MHD_Session * session);
152
153
154#endif