[En-Nut-Discussion] any code in lib for parsing POST tokens in req_query?

Damian Slee damian at commtech.com.au
Wed Aug 6 06:04:23 CEST 2003


Hi,
I am finding that req->req_query is NULL in my cgi function after a form is posted.

Anyone know why?

thanks,

damian

-----Original Message-----
From: Harald Kipp [mailto:harald.kipp at egnite.de]
Sent: Tuesday, 5 August 2003 5:03 PM
To: en-nut-discussion at egnite.de
Subject: Re: [En-Nut-Discussion] any code in lib for parsing POST tokens
in req_query?


Damian,

The next release will include a form sample:

/*
  * CGI Sample: Proccessing a form.
  *
  * This routine must have been registered by NutRegisterCgi() and is
  * automatically called by NutHttpProcessRequest() when the client
  * request the URL 'cgi-bin/form.cgi'.
  *
  * Thanks to Tom Boettger, who provided this sample for ICCAVR.
  */
int ShowForm(FILE * stream, REQUEST * req)
{
     static prog_char html_head[] = "<HTML><BODY><BR><H1>Form 
Result</H1><BR><BR>";
     static prog_char html_body[] = "<BR><BR><p><a 
href=\"../index.html\">return to main</a></BODY></HTML></p>";

     NutHttpSendHeaderTop(stream, req, 200, "Ok");
     NutHttpSendHeaderBot(stream, html_mt, -1);

     /* Send HTML header. */
     fputs_P(html_head, stream);

     if (req->req_query) {
#ifdef __IMAGECRAFT__
         char *param1;
         char *param2;
         char *param3;

         /*
          * Extract the parameters. Note, that it is potentially dangerous
          * to use strtok in multithreaded applications. There's no problem
          * here, because we can be sure that there will by no thread switch
          * between the first and the last call to strtok. Otherwise we
          * must use strtok_r().
          */
         param1 = strtok(req->req_query, "=");
         param1 = strtok(NULL, "&");
         param2 = strtok(NULL, "=");
         param2 = strtok(NULL, "&");
         param3 = strtok(NULL, "=");
         param3 = strtok(NULL, "&");

         /* Send the parameters back to the client. */
         fputs("Param1=", stream);
         fputs(param1, stream);
         fputs("<BR>Param2=", stream);
         fputs(param2, stream);
         fputs("<BR>Param3=", stream);
         fputs(param3, stream);
#else
         /*
          * There's no strtok in the GCC library. So we take the chance to
          * demonstrate Peter Scandrett's strtok_r().
          */
         char *qp;
         char *c[3];
         char *p[3];
         u_char i;

         /* Extract 3 parameters. */
         qp = req->req_query;
         for(i = 0; i < 3; i++) {
             c[i] = strtok_r(&qp, "=");
             p[i] = strtok_r(&qp, "&");
         }

         /* Send the parameters back to the client. */
         for(i = 0; i < 3; i++) {
             fprintf_P(stream, PSTR("%s: %s<BR>\r\n"), c[i], p[i]);
         }
#endif
     }

     fputs_P(html_body, stream);
     fflush(stream);

     return 0;
}

_______________________________________________
En-Nut-Discussion mailing list
En-Nut-Discussion at egnite.de
http://www.egnite.de/mailman/listinfo/en-nut-discussion



More information about the En-Nut-Discussion mailing list