Convert v2.x webpage to v3.x

Discussion to talk about software related topics only.
Post Reply
SeeCwriter
Posts: 605
Joined: Mon May 12, 2008 10:55 am

Convert v2.x webpage to v3.x

Post by SeeCwriter »

I have a webpage that was developed in the v2.x tools for the NANO and MOD5541X. I set a new Get Handler to handle special requests from the webpage.

Code: Select all

void init()
{
    StartHttps();
    default_page = "index.htm";
    OldHttpHandler = SetNewGetHandler( MyHttpHandler );
}

int MyHttpHandler(int sock, PSTR url, PSTR rxb)
  {
  iprintf("HTTP request: [%s]\r\n", url);

  // special request?
  if (url && strlen(url)>5)
    {
    if (httpstricmp(url,"O2SETTINGS_"))       // dump settings?
      {
      SendTextHeader(sock);
      WebDumpSettings(sock);
      return 0;
      }
    else if (httpstricmp(url,"EVENTLOG_"))    // full eventlog?
      {
      SendTextHeader( sock );
      WebWriteFullEventlog(sock);
      return 0;
      }
    else if (httpstricmp(url,"CALDATA"))      // calibration block?
      {
      WriteWebCal(sock);
      return 0;
      }
    }

  return OldHttpHandler(sock, url, rxb);      // A routine status update.
  }
But v3.x doesn't have a SetNewGetHandler function. How do I accomplish the same thing in v3.x?
I'm using v3.3.4.
User avatar
TomNB
Posts: 538
Joined: Tue May 10, 2016 8:22 am

Re: Convert v2.x webpage to v3.x

Post by TomNB »

Hello,

Instead of one large function that has to parse URLs, the 3.x method is to have a callback function for each page (or group of pages by using a wildcard match filter). So instead of parsing for "if (httpstricmp(url,"O2SETTINGS_"))" , you register a callback function for the name "O2SETTINGS_" and it gets called directly. So i your code example you would create 3 callback functions, one for each page.

Here are the docs: https://www.netburner.com/NBDocs/Develo ... otoc_md183

And example: \nburn\examples\Web\HtmlServerGetRequest
SeeCwriter
Posts: 605
Joined: Mon May 12, 2008 10:55 am

Re: Convert v2.x webpage to v3.x

Post by SeeCwriter »

I had read the docs on GET callbacks, but it seemed to only apply to webpages. So there would be a single callback for each webpage, whereas "O2SETTINGS_" is actually a button click on the same webpage that causes certain data to be sent to the webpage which then creates a file on the user's PC to save the data.
I created a callback with the name "O2SETTINGS_*.txt" and it works.
Thanks.
Post Reply