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
f1b4f0c4
Commit
f1b4f0c4
authored
Oct 28, 2016
by
Sergey Lyubka
Committed by
Cesanta Bot
Oct 28, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix SEGFAULT in MQTT server
PUBLISHED_FROM=6455082726781aab819a7f8645e81adaa7fc7669
parent
c04e3f80
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
789 additions
and
90 deletions
+789
-90
LIST_ENTRY.md
docs/c-api/mqtt_server.h/LIST_ENTRY.md
+10
-0
intro.md
docs/c-api/mqtt_server.h/intro.md
+1
-3
mg_mqtt_broker.md
docs/c-api/mqtt_server.h/mg_mqtt_broker.md
+0
-32
mg_mqtt_broker_init.md
docs/c-api/mqtt_server.h/mg_mqtt_broker_init.md
+0
-10
mg_mqtt_next.md
docs/c-api/mqtt_server.h/mg_mqtt_next.md
+0
-18
struct_mg_mqtt_broker.md
docs/c-api/mqtt_server.h/struct_mg_mqtt_broker.md
+2
-2
struct_mg_mqtt_session.md
docs/c-api/mqtt_server.h/struct_mg_mqtt_session.md
+5
-5
mongoose.c
mongoose.c
+8
-13
mongoose.h
mongoose.h
+763
-7
No files found.
docs/c-api/mqtt_server.h/LIST_ENTRY.md
0 → 100644
View file @
f1b4f0c4
---
title
:
"
LIST_ENTRY()"
decl_name
:
"
LIST_ENTRY"
symbol_kind
:
"
func"
signature
:
|
LIST_ENTRY(mg_mqtt_session);
---
Broker
docs/c-api/mqtt_server.h/intro.md
View file @
f1b4f0c4
...
...
@@ -3,9 +3,7 @@ title: "MQTT Server API reference"
symbol_kind
:
"
intro"
decl_name
:
"
mqtt_server.h"
items
:
-
{
name
:
mg_mqtt_broker.md
}
-
{
name
:
mg_mqtt_broker_init.md
}
-
{
name
:
mg_mqtt_next.md
}
-
{
name
:
LIST_ENTRY.md
}
-
{
name
:
struct_mg_mqtt_broker.md
}
-
{
name
:
struct_mg_mqtt_session.md
}
---
...
...
docs/c-api/mqtt_server.h/mg_mqtt_broker.md
deleted
100644 → 0
View file @
c04e3f80
---
title
:
"
mg_mqtt_broker()"
decl_name
:
"
mg_mqtt_broker"
symbol_kind
:
"
func"
signature
:
|
void mg_mqtt_broker(struct mg_connection *brk, int ev, void *data);
---
Processes a MQTT broker message.
The listening connection expects a pointer to an initialised
`mg_mqtt_broker`
structure in the
`user_data`
field.
Basic usage:
```
c
mg_mqtt_broker_init
(
&
brk
,
NULL
);
if
((
nc
=
mg_bind
(
&
mgr
,
address
,
mg_mqtt_broker
))
==
NULL
)
{
// fail;
}
nc
->
user_data
=
&
brk
;
```
New incoming connections will receive a
`mg_mqtt_session`
structure
in the connection
`user_data`
. The original
`user_data`
will be stored
in the
`user_data`
field of the session structure. This allows the user
handler to store user data before
`mg_mqtt_broker`
creates the session.
Since only the MG_EV_ACCEPT message is processed by the listening socket,
for most events the
`user_data`
will thus point to a
`mg_mqtt_session`
.
docs/c-api/mqtt_server.h/mg_mqtt_broker_init.md
deleted
100644 → 0
View file @
c04e3f80
---
title
:
"
mg_mqtt_broker_init()"
decl_name
:
"
mg_mqtt_broker_init"
symbol_kind
:
"
func"
signature
:
|
void mg_mqtt_broker_init(struct mg_mqtt_broker *brk, void *user_data);
---
Initialises a MQTT broker.
docs/c-api/mqtt_server.h/mg_mqtt_next.md
deleted
100644 → 0
View file @
c04e3f80
---
title
:
"
mg_mqtt_next()"
decl_name
:
"
mg_mqtt_next"
symbol_kind
:
"
func"
signature
:
|
struct mg_mqtt_session *mg_mqtt_next(struct mg_mqtt_broker *brk,
struct mg_mqtt_session *s);
---
Iterates over all MQTT session connections. Example:
```
c
struct
mg_mqtt_session
*
s
;
for
(
s
=
mg_mqtt_next
(
brk
,
NULL
);
s
!=
NULL
;
s
=
mg_mqtt_next
(
brk
,
s
))
{
// Do something
}
```
docs/c-api/mqtt_server.h/struct_mg_mqtt_broker.md
View file @
f1b4f0c4
...
...
@@ -4,8 +4,8 @@ decl_name: "struct mg_mqtt_broker"
symbol_kind
:
"
struct"
signature
:
|
struct mg_mqtt_broker {
struct mg_mqtt_session *
sessions; /* Session list */
void *user_data; /* User data */
LIST_HEAD(, mg_mqtt_session)
sessions; /* Session list */
void *user_data;
/* User data */
};
---
...
...
docs/c-api/mqtt_server.h/struct_mg_mqtt_session.md
View file @
f1b4f0c4
...
...
@@ -4,12 +4,12 @@ decl_name: "struct mg_mqtt_session"
symbol_kind
:
"
struct"
signature
:
|
struct mg_mqtt_session {
struct mg_mqtt_broker *brk; /* Broker */
struct mg_mqtt_session *next, *prev; /* mg_mqtt_broker::sessions linkage */
struct mg_connection *nc; /* Connection with the client */
size_t num_subscriptions; /* Size of `subscriptions` array */
struct mg_mqtt_broker *brk; /* Broker */
LIST_ENTRY(mg_mqtt_session) link; /* mg_mqtt_broker::sessions linkage */
struct mg_connection *nc; /* Connection with the client */
size_t num_subscriptions; /* Size of `subscriptions` array */
void *user_data; /* User data */
struct mg_mqtt_topic_expression *subscriptions;
void *user_data; /* User data */
};
---
...
...
mongoose.c
View file @
f1b4f0c4
...
...
@@ -8595,7 +8595,7 @@ void mg_mqtt_disconnect(struct mg_connection *nc) {
*/
/* Amalgamated: #include "mongoose/src/internal.h" */
/* Amalgamated: #include "mongoose/src/mqtt-
brok
er.h" */
/* Amalgamated: #include "mongoose/src/mqtt-
serv
er.h" */
#if MG_ENABLE_MQTT_BROKER
...
...
@@ -8609,16 +8609,11 @@ static void mg_mqtt_session_init(struct mg_mqtt_broker *brk,
}
static
void
mg_mqtt_add_session
(
struct
mg_mqtt_session
*
s
)
{
s
->
next
=
s
->
brk
->
sessions
;
s
->
brk
->
sessions
=
s
;
s
->
prev
=
NULL
;
if
(
s
->
next
!=
NULL
)
s
->
next
->
prev
=
s
;
LIST_INSERT_HEAD
(
&
s
->
brk
->
sessions
,
s
,
link
);
}
static
void
mg_mqtt_remove_session
(
struct
mg_mqtt_session
*
s
)
{
if
(
s
->
prev
==
NULL
)
s
->
brk
->
sessions
=
s
->
next
;
if
(
s
->
prev
)
s
->
prev
->
next
=
s
->
next
;
if
(
s
->
next
)
s
->
next
->
prev
=
s
->
prev
;
LIST_REMOVE
(
s
,
link
);
}
static
void
mg_mqtt_destroy_session
(
struct
mg_mqtt_session
*
s
)
{
...
...
@@ -8636,7 +8631,7 @@ static void mg_mqtt_close_session(struct mg_mqtt_session *s) {
}
void
mg_mqtt_broker_init
(
struct
mg_mqtt_broker
*
brk
,
void
*
user_data
)
{
brk
->
sessions
=
NULL
;
LIST_EMPTY
(
&
brk
->
sessions
)
;
brk
->
user_data
=
user_data
;
}
...
...
@@ -8662,7 +8657,6 @@ static void mg_mqtt_broker_handle_connect(struct mg_mqtt_broker *brk,
static
void
mg_mqtt_broker_handle_subscribe
(
struct
mg_connection
*
nc
,
struct
mg_mqtt_message
*
msg
)
{
struct
mg_mqtt_session
*
ss
=
(
struct
mg_mqtt_session
*
)
nc
->
user_data
;
uint8_t
qoss
[
512
];
size_t
qoss_len
=
0
;
...
...
@@ -8676,7 +8670,6 @@ static void mg_mqtt_broker_handle_subscribe(struct mg_connection *nc,
qoss
[
qoss_len
++
]
=
qos
;
}
ss
->
subscriptions
=
(
struct
mg_mqtt_topic_expression
*
)
realloc
(
ss
->
subscriptions
,
sizeof
(
*
ss
->
subscriptions
)
*
qoss_len
);
for
(
pos
=
0
;
...
...
@@ -8721,7 +8714,8 @@ static void mg_mqtt_broker_handle_publish(struct mg_mqtt_broker *brk,
if
(
mg_mqtt_match_topic_expression
(
s
->
subscriptions
[
i
].
topic
,
&
msg
->
topic
))
{
char
buf
[
100
],
*
p
=
buf
;
mg_asprintf
(
&
p
,
sizeof
(
buf
),
"%.*s"
,
(
int
)
msg
->
topic
.
len
,
msg
->
topic
.
p
);
mg_asprintf
(
&
p
,
sizeof
(
buf
),
"%.*s"
,
(
int
)
msg
->
topic
.
len
,
msg
->
topic
.
p
);
if
(
p
==
NULL
)
{
return
;
}
...
...
@@ -8748,6 +8742,7 @@ void mg_mqtt_broker(struct mg_connection *nc, int ev, void *data) {
switch
(
ev
)
{
case
MG_EV_ACCEPT
:
mg_set_protocol_mqtt
(
nc
);
nc
->
user_data
=
NULL
;
// This is NOT a listening connection
break
;
case
MG_EV_MQTT_CONNECT
:
mg_mqtt_broker_handle_connect
(
brk
,
nc
);
...
...
@@ -8768,7 +8763,7 @@ void mg_mqtt_broker(struct mg_connection *nc, int ev, void *data) {
struct
mg_mqtt_session
*
mg_mqtt_next
(
struct
mg_mqtt_broker
*
brk
,
struct
mg_mqtt_session
*
s
)
{
return
s
==
NULL
?
brk
->
sessions
:
s
->
next
;
return
s
==
NULL
?
LIST_FIRST
(
&
brk
->
sessions
)
:
LIST_NEXT
(
s
,
link
)
;
}
#endif
/* MG_ENABLE_MQTT_BROKER */
...
...
mongoose.h
View file @
f1b4f0c4
This diff is collapsed.
Click to expand it.
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