-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Add MQTT protocol handler #3514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
lib/mqtt.c
Outdated
| break; | ||
| } | ||
| if(result) | ||
| infof(conn->data, "=== %s result: %d\n", __func__, result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this is leftover debug code. Will be removed.
|
Nits on travis: and and in the tidy build: |
|
Any ideas or thoughts on how we can add tests for this? |
|
This is very nice :-) But why are your subscribe and publish examples beginning with http://? |
Haha. Because old habits die hard? 😁 Edited. |
|
When you say no support for username and password, does that mean it's not setting the username and password flags or just can't pass values at the moment? The vast majority of MQTT servers are authenticated. Many systems use JWTs or x.509 certificates passed in the username or password field for auth, it may be valuable to support inclusion of a file for these fields. |
|
@conduit242 The limitations are not meant to be permanent, quite the contrary. I listed things that I think might be interesting to add in the future but which this first patch does not contain. |
lib/mqtt.c
Outdated
|
|
||
| /* reallocate a bigger buffer if necessary */ | ||
| if(pktlen > 128) { | ||
| pkt = realloc(pkt, pktlen + 2); /* one extra for payload termination */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
realloc() without a temporary returnvalue will overwrite the original pointer on allocation error, better to use Curl_saferealloc() here instead.
lib/mqtt.c
Outdated
| static CURLcode mqtt_connect(struct connectdata *conn) | ||
| { | ||
| CURLcode result = CURLE_OK; | ||
| const char clientid[] = "curl1234abcd"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two users will not be able to use curl concurrently if static client id is used. According to spec, client id must be unique so existing client will be disconnected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable is actually only used to find out the length of the client id string (rather than using a magic number). The real client id sent is random and written into the packet a few lines below:
msnprintf(packet + client_id_offset, sizeof(packet), "curl%08x", rand());
But this code isn't terribly elegant, and your misunderstanding shows me I should rewrite it to be more clear. Thanks for reviewing!
|
scan-build found something (appveyor looks like a false positive) |
|
@zagor this now has a merge conflict. Do you have any updates on this work? What can we do to help out? |
|
I got stuck on trying to figure out if I should implement a new mqtt broker and client in python for the tests or if I should add dependencies on external modules. |
|
If I would do it, I would probably write a new MQTT test server in C based on one of the existing TCP servers. (Possibly the sockd server that I introduced most recently.) Reasons for this choice:
|
|
Okay how about this approach to get this moving forward:
|
👍 |
|
Thank you for your patience, sorry about my slowness. I'll get on with this today or tomorrow. |
1f29073 to
cad9f2d
Compare
|
The appveyor 1013 test case failure seems to be related to the mqtt thing in |
|
I don't understand how curl and curl-config can differ. Aren't they built from the same configure run? |
|
Enter: build complexity. The appveyor runs are all on Windows. Most of those builds are done with cmake, not configure. But yes, curl and curl-config are made by the same build process so they should match, which is what test 1013 verifies... |
|
I suppose the simplest "fix" is to just not add any MQTT knowledge to the cmake build... I don't know how to do it the proper way, cmake is not my friend. |
|
@zagor, since I proposed doing plain C server to drive MQTT tests, I created a "skeleton" for it based on what I did with socksd.c not too long ago to show off what I had in mind. It is basically a template source code that creates a TCP server, accepts a connection and can read/write to the client. It is designed to read commands from a config file at client connect so that the test script can pass in test specific instructions per test case. I personally don't know much about the MQTT protocol yet so I didn't venture into doing any actual protocol things. No pressure, it's just an idea! |
|
@bagder Thanks, that is exactly what I needed! |
This patch adds support for MQTT using the mqtt://host/topic URL scheme. A plain GET subscribes to the topic and prints all published messages. Doing a POST publishes the post data to the topic and exits. Example subscribe: curl http://host/home/bedroom/temp Example publish: curl -d 80 http://host/home/bedroom/dimmer Limitations: - No username support - Only QoS level 0 is implemented for publish - No way to set retain flag for publish - No username/password support - No TLS (mqtts) support - Naive EAGAIN handling won't handle split messages
Also, Use Curl_rand_hex() instead of sprintf(rand()).
Enable it with --enable-mqtt. Marked as experimental.
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This patch adds support for MQTT using the mqtt://broker/topic URL scheme.
A plain GET subscribes to the topic and prints all published messages.
Doing a POST publishes the post data to the topic and exits.
Example subscribe: curl mqtt://home/bedroom/temp
Example publish: curl -d 80 mqtt://home/bedroom/dimmer
Limitations: