WICED Studio - Server application using wildcard character (*) in web page data base

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Creating a server application with all dynamic pages.Using the WICED macro START_OF_HTTP_PAGE_DATABASE to define all the possible web pages and page callbacks. In our app can treat the pages generically so only a single callback needed for all our pages - relying on the fact that WICED will provide the specific filename and/or data to the callback function.

Since we will have many pages (more than shown below) I would prefer to use wildcard syntax in the web page data base, see below. There appears to be a WICED problem related to this.

If a POST request, we parse the data (part of the parameter http_data in the callback) for some keywords specific to our application. Then we read the file passed as parameter url_path from our embedded file system and serve that via the WICED api  wiced_http_response_stream_write. The problem is sometimes a POST request is divided over 2 packets. In the first packet the file name is correct, but no data is attached, http_data->message_data_length = 0. The subsequent packet will have the data but now the filename is incorrect, it is as specified in the web page data base, "*.html". If I do not use wildcard characters in the data base and populate it explicitly with all the possible files everything works as expected. Moving forward we may have hundreds of possible pages so the use of wildcard in the web page data base is needed.

// signature of our page callback.....

static int32_t pageCallback(const char* url_path, const char* url_parameters, wiced_http_response_stream_t* stream, void* arg, wiced_http_message_body_t * http_data )

// example of a portion of web page data based when all files explicitly defined

START_OF_HTTP_PAGE_DATABASE(ap_web_pages)

    ROOT_HTTP_PAGE_REDIRECT("/indexhme.htm"),

    { "/upload_a.htm", "text/html", WICED_DYNAMIC_URL_CONTENT, .url_content.dynamic_data   = { pageCallback,PostUpload}, },

    { "/buftmp.htm", "text/html", WICED_DYNAMIC_URL_CONTENT, .url_content.dynamic_data   = { pageCallback,PostUpload}, },

    { "/buftmp1.htm", "text/html", WICED_DYNAMIC_URL_CONTENT, .url_content.dynamic_data   = { pageCallback,PostUpload}, },

    { "/buftmp2.htm", "text/html", WICED_DYNAMIC_URL_CONTENT, .url_content.dynamic_data   = { pageCallback,PostUpdate}, },

    { "/buftmp3.htm", "text/html", WICED_DYNAMIC_URL_CONTENT, .url_content.dynamic_data   = { pageCallback,PostUpload}, },

    { "/filepost.htm", "text/html", WICED_DYNAMIC_URL_CONTENT, .url_content.dynamic_data   = { pageCallback,PostUpload}, },

// example of a portion of our web page database using wildcard

START_OF_HTTP_PAGE_DATABASE(ap_web_pages)

    ROOT_HTTP_PAGE_REDIRECT("/indexhme.htm"), // real home

    { "/*.htm", "text/html", WICED_DYNAMIC_URL_CONTENT, .url_content.dynamic_data   = { pageCallback,PostUpload}, }, // DAT file

0 Likes
1 Solution
PriyaM_16
Moderator
Moderator
Moderator
250 replies posted 100 replies posted 50 replies posted

Hello,

Can you share any example project that can help me to recreate your use case?

On my part, I tried to tweak the demo.appliance application. I added the code to ask for First name/Last name in the html page (43xxx_Wi-Fi\resources\apps\appliance\top_web_page_top.html)

        First name: <input type="text" name="fname"><br>

        Last name: <input type="text" name="lname"><br>

        <input type="submit" value="Submit">

pastedImage_1.png

And modified the general_ajax_script to send POST messages when the client submits the data.

req.open("POST", ajax_url, true);

Depending on the way the HTML page and corresponding general_ajax_script.js is written, the URI and the content-Length are being sent in my application.

You may check the UART log:

process_button_handler: URL_PATH: /button_handler

process_button_handler: url_parameters: (null)

process_button_handler: http_message_body->message_data_length: 20

process_button_handler: http_message_body->request_type: 1(POST)

and the corresponding Wireshark log:

pastedImage_1.png

View solution in original post

0 Likes
4 Replies
PriyaM_16
Moderator
Moderator
Moderator
250 replies posted 100 replies posted 50 replies posted

Hello,

I have few questions based on your implementation

1. The first post request has content-length as Zero but all the other fields are as expected i.e., content-type?

2. Is your implementation asking for credentials from users like username/password?

3. Can the file name be cached from the POST request with content-length=0 and used in subsequent POST requests?

0 Likes
Anonymous
Not applicable

Thanks. to answer your questions:

1. Yes all other fields seem correct

2. Yes, username/password is required.

3. Sure,can come up with a scheme that does what you suggest, logic to cache the name. If there is an underlying WICED bug would be preferable to get that fixed, or at least acknowledged along with any caveats. By the way this is WICED studio 6.2.

0 Likes
PriyaM_16
Moderator
Moderator
Moderator
250 replies posted 100 replies posted 50 replies posted

Hello,

Can you share any example project that can help me to recreate your use case?

On my part, I tried to tweak the demo.appliance application. I added the code to ask for First name/Last name in the html page (43xxx_Wi-Fi\resources\apps\appliance\top_web_page_top.html)

        First name: <input type="text" name="fname"><br>

        Last name: <input type="text" name="lname"><br>

        <input type="submit" value="Submit">

pastedImage_1.png

And modified the general_ajax_script to send POST messages when the client submits the data.

req.open("POST", ajax_url, true);

Depending on the way the HTML page and corresponding general_ajax_script.js is written, the URI and the content-Length are being sent in my application.

You may check the UART log:

process_button_handler: URL_PATH: /button_handler

process_button_handler: url_parameters: (null)

process_button_handler: http_message_body->message_data_length: 20

process_button_handler: http_message_body->request_type: 1(POST)

and the corresponding Wireshark log:

pastedImage_1.png

0 Likes
Anonymous
Not applicable

Thanks. I can not share source code  or project as is as it is proprietary. Not sure if I can create some stripped down version. In the mean time I am testing your suggestion of caching the file name to see if that is a reliable work around.

0 Likes