lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] httpd: how to implement AJAX


From: Giuseppe Modugno
Subject: Re: [lwip-users] httpd: how to implement AJAX
Date: Tue, 14 Nov 2017 13:42:05 +0100
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0

Il 13/11/2017 18:04, Noam Weissman ha scritto:
Yes SSID is a session ID that had been added to my own server code.
So are you using a completely different HTTP server from the httpd that is in apps folder of lwip main source?

When a user askes for a page and there is no ssid the server will redirect (send a 303)

And load a login page instead. After the user writes user+password the data is sent to

The server.

How do you send user+password to the server? PUT? Do you encode these sensible values?

The server call’s external code to check for validity of user+pass… if OK it

Request a new ssid from a separate task.

 

After that the web server sends the previously request page + ssid… every operation

at the browser side must add that ssid value.

Is it a cookie, right?

Every time the web server gets a request

with the correct ssid it clears the related timeout. If the ssid timeouts and the user asks

for some data it will again redirect to the login page.

Do you call a specific function from main at regular intervals to clear all SSID that expire?

Regarding AJAX:

 

How do you handle SSI ?... I am doing it differently ? I have something like this in my code:

 

const SSI_t SSI_Table[] =

{

  {"mem_rout", mem_routing},

  {"IOSel", IO_Selection},

   {"get_users", get_users},

   {"ajax_reply", AjaxReply},

 

   {NULL, NULL} // last tag must always be NULL to close the list

};

 

 

mem_routing, IO_Selection,  get_users,  and   AjaxReply  are call-back function that are called by the web

server as a result of encountering the proper tag… for mem_routing it is   <!--#mem_rout-->

I think LWIP_HTTPD_CUSTOM_FILES is simpler to use when you have a file that is completely dynamic. Your "single tag trick" works, but IMHO is too complex for what you have to do.

 

my AjaxReply parses the GET params and after that does something like that:

How AjaxReply() function could access GET params if they aren't accessible from the SSI handler? Most probably the answer is in the file state (LWIP_HTTPD_FILE_STATE) that is filled by httpd_cgi_handler() callback (as explained by goldsimon).

 

// get action param

Char *Action = "">

 

 

If(strcmp(Action, “do_something_1”) == 0)

{

 

}

elses If(strcmp(Action, “do_something_2”) == 0)

{

 

}

 

 

else

{

  // print a debug error :  action unknown

}

 

 

 

Hope that helped,

Noam.

 

 

 

 

 

 

From: lwip-users [mailto:address@hidden] On Behalf Of Giuseppe Modugno
Sent: Monday, November 13, 2017 6:09 PM
To: address@hidden
Subject: Re: [lwip-users] httpd: how to implement AJAX

 

Il 13/11/2017 14:34, Noam Weissman ha scritto:

Hi,
 
I am using the following technic for AJAX.
 
Create an empty file named ajax.shtml or ajax.html and add it to your file list.
 
Inside the file you only write one tag without anything else. For example <!--#AjaxCall-->
 
Do not add  CR or LF just the tag !!.
 
Now when you issue an AJAX call the WEB server opens the file, reads it and send its data.
Because the file has only the tag it will parse it, call your handler for that tag and send back 
To the browser just your data !!

Ok, so you use SSI to create dynamic data. I tried with custom files, because *all the content* is dynamic (and not only some parts, defined by specific tags).


If you use Juery it will look something like this... actually a function used as an event handler in 
my own code:
 
function resetIO()
      {
        //Remove the dialog
        returnToPage();
        
        $.ajax({
          url: "ajax.shtml",
          dataType : "text",
          type : "GET",
          cache : false,
          data : ({
            ssid: ssid,
            a: 'opReset',
            type: 2
          }),
          error : function()
          {
            showMessage("Network Error: Sorry, there was a problem connecting to the server.");
          },    
          success : function(result) 
          {
            window.location.href = "">
          }
        });
      }
 
In the above data you have the a:  variable,  this is your AJAX action !. 

If I understood well, data is translated in query string, in your example:

    GET ajax.shtml?ssid=<ssid>&a=opReset&type=2

Of course, <ssid> is the value of ssid _javascript_ variable.


In your own SSI/CGI code you have a table with tags + callbacks... one of the callback function
Is your AJAX handler. Inside it you create an if <> else layout and handle the different actions.

The prototype for SSI callbacks is:

typedef u16_t (*tSSIHandler)(
#if LWIP_HTTPD_SSI_RAW
                             const char* ssi_tag_name,
#else /* LWIP_HTTPD_SSI_RAW */
                             int iIndex,
#endif /* LWIP_HTTPD_SSI_RAW */
                             char *pcInsert, int iInsertLen
#if LWIP_HTTPD_SSI_MULTIPART
                             , u16_t current_tag_part, u16_t *next_tag_part
#endif /* LWIP_HTTPD_SSI_MULTIPART */
#if defined(LWIP_HTTPD_FILE_STATE) && LWIP_HTTPD_FILE_STATE
                             , void *connection_state
#endif /* LWIP_HTTPD_FILE_STATE */
                             );

I don't see any reference to query string parameters. So how to select the right action?


The HTTP server will read your ajax.shtml file and because it has nothing BUT your tag it will 
only send back the dynamic data you process in your ajax handling function.

As said before, it works if the dynamic content depends only from the name of the file (ajax.shtml in your example) and not from the action in the query string (a=opReset).

Where is my error?

Another question. I saw ssid in your _javascript_ example. Is it related to a "session identifier"? If so, did you implement a session mechanism over httpd?



_______________________________________________
lwip-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users


reply via email to

[Prev in Thread] Current Thread [Next in Thread]