Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
865ac097
Commit
865ac097
authored
May 04, 2010
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
started to work on sessions
parent
b5d7c34b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
6 deletions
+21
-6
chat.c
examples/chat.c
+21
-6
No files found.
examples/chat.c
View file @
865ac097
...
...
@@ -21,6 +21,11 @@
#include "mongoose.h"
#define MAX_USER_LEN 20
#define MAX_MESSAGE_LEN 100
#define MAX_MESSAGES 5
#define MAX_SESSIONS 2
static
const
char
*
login_url
=
"/login.html"
;
static
const
char
*
authorize_url
=
"/authorize"
;
static
const
char
*
web_root
=
"./html"
;
...
...
@@ -37,13 +42,23 @@ static const char *ajax_reply_start =
// the message is then originated from the server itself.
struct
message
{
long
id
;
char
user
[
20
];
char
text
[
200
];
char
user
[
MAX_USER_LEN
];
char
text
[
MAX_MESSAGE_LEN
];
time_t
utc_timestamp
;
};
static
struct
message
messages
[
5
];
// Ringbuffer where messages are kept
// Describes web session.
struct
session
{
char
session_id
[
33
];
char
authenticated_user
[
MAX_USER_LEN
];
time_t
expiration_timestamp_utc
;
};
static
struct
message
messages
[
MAX_MESSAGES
];
// Ringbuffer for messages
static
struct
session
sessions
[
MAX_SESSIONS
];
// Current sessions
static
long
last_message_id
;
// Protects messages, sessions, last_message_id
static
pthread_rwlock_t
rwlock
=
PTHREAD_RWLOCK_INITIALIZER
;
// Get a get of messages with IDs greater than last_id and transform them
...
...
@@ -208,9 +223,9 @@ static int must_authorize(const struct mg_request_info *request_info) {
strcmp
(
request_info
->
uri
,
authorize_url
)
!=
0
);
}
static
in
t
process_request
(
struct
mg_connection
*
conn
,
static
enum
mg_error_
t
process_request
(
struct
mg_connection
*
conn
,
const
struct
mg_request_info
*
request_info
)
{
int
processed
=
1
;
enum
mg_error_t
processed
=
MG_SUCCESS
;
if
(
must_authorize
(
request_info
)
&&
!
is_authorized
(
conn
,
request_info
))
{
...
...
@@ -225,7 +240,7 @@ static int process_request(struct mg_connection *conn,
}
else
{
// No suitable handler found, mark as not processed. Mongoose will
// try to serve the request.
processed
=
0
;
processed
=
MG_ERROR
;
}
return
processed
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment