How to parse uri queries with GET in SMCP

7 views
Skip to first unread message

Shantanoo Desai

unread,
Jan 18, 2017, 11:41:17 AM1/18/17
to SMCP Developers
Hi,

I have been looking around and wanted to know are there implementations for parsing URI queries using GET in SMCP.

in a nutshell, something like:

   
smcpctl get coap://localhost:5683/hash?param=file



this is a just a dumb example where I wish to use a simple md5 hash check on the above mentioned `file` parameter. A rough logic is if the `file` exists do a simple md5 hash and return it using GET.

I think if smcp-variable_handler.h and .c are the files one should be working with? and is there any example in the repo?


thanks,

shan

Paulo Leonardo

unread,
Jan 19, 2017, 4:20:34 PM1/19/17
to Shantanoo Desai, SMCP Developers
Shantanoo,

do you mean parsing the URI on "server" endpoint?

I have put this gist: https://gist.github.com/paulobrizolara/e6a190d9310635260f31947753867d3f
with part of a code i was working on.
It shows how to load a Url using smcp.
Note: the code uses c++11.
Note2: i did not tested this code isolated, but i hope it is working. :)

Also, it does not handle the query part (i.e.: "?param=file").
But since coap stores it as an option (see here in the RFC), then it should be easy to adapt the code.

Check for the 'COAP_OPTION_URI_QUERY' option in 'smcp/coap.h'



Paulo


 

Robert Quattlebaum

unread,
Feb 8, 2017, 2:08:06 PM2/8/17
to Shantanoo Desai, SMCP Developers Group
Yes, queries on URIs should be parsed and passed along with the GET request (as in, this is already implemented), but I'm a little confused by your question.

smcp-variable_handler is used for easily implementing simple variable-like resources that you can get and set. (like "light-state", "temperature", etc)

But I'm not sure what that has to do with URI query parsing.

-- RQ

Robert Quattlebaum

unread,
Feb 8, 2017, 2:12:37 PM2/8/17
to Paulo Leonardo, Shantanoo Desai, SMCP Developers Group

Note that there is a an already-implemented similar mechanism in smcp:

//! Get a string representation of the destination path in the inbound packet.
SMCP_API_EXTERN char* smcp_inbound_get_path(char* where, uint8_t flags);

Where the flags are:

#define SMCP_GET_PATH_REMAINING (1<<0)
#define SMCP_GET_PATH_LEADING_SLASH (1<<1)
#define SMCP_GET_PATH_INCLUDE_QUERY (1<<2)

So you could easily use this to reconstruct the part of the URI after the host.

-- RQ
Reply all
Reply to author
Forward
0 new messages