HI,
I've developed en embedded web-server using Snorkel API, where the server displays a form requesting the mobile number from the client using the GET and POST method via index.html.
The problem is after posting the mobile number, I need another form requesting the client to submit a One-Time-Password by also using the GET and POST, but its not working.
HERE, ARE THE TWO REQUIRED FORMS:
char szForm[] =
{ "<html>\r\n<body>\r\n"
"<form method=\"post\" action=\"postform.html\">\r\n"
"Mobile Number:\r\n"
"<input type=\"text\" name=\"mobilenumber\">\r\n"
"<br>\r\n"
"<input type=\"submit\" value=\"submit\">\r\n"
"</form>\r\n" "</body>\r\n</html>\r\n"
};
char otpForm[] =
{ "<html>\r\n<body>\r\n"
"<form method=\"post\" action=\"postform.html\">\r\n"
"One Time Password:\r\n"
"<input type=\"text\" name=\"otp\">\r\n"
"<br>\r\n"
"<input type=\"submit\" value=\"submit\">\r\n"
"</form>\r\n" "</body>\r\n</html>\r\n"
};
HERE, IS THE POSTFORM FUNCTION:
<pre>call_status_t
postform (snorkel_obj_t http, snorkel_obj_t outstream)
{
if (snorkel_obj_get(http, snorkel_attrib_post, "mobilenumber", szmobilenumber,sizeof (szmobilenumber)) != SNORKEL_SUCCESS)
return HTTP_ERROR;
snorkel_printf (outstream,"<html><body>YOUR MOBILE NUMBER IS %s </body></html>", szmobilenumber);
}
void main (int argc, char *argv[])
{
int i = 1;
int port = 8080;
char *pszIndex = 0;
char *pszLog = 0;
char szExit[10];
snorkel_obj_t logobj = 0;
snorkel_obj_t http = 0;
snorkel_obj_t outstream;
int has_ssl=0;
for (; i < argc; i++)
{
if (argv[i][0] == '-' || argv[i][0] == '/')
{
char carg = argv[i][1];
switch (carg)
{
case 'p':
port = atoi (argv[i + 1]);
i++;
break;
case 'l':
pszLog = argv[i + 1];
i++;
break;
default:
syntax (argv[0]);
break;
}
}
}
if (pszLog)
{
logobj = snorkel_obj_create (snorkel_obj_log, pszLog);
if (!logobj)
{
perror ("could not create log file\n");
exit (1);
}
snorkel_debug (1);
}
if (snorkel_init () != SNORKEL_SUCCESS)
{
perror ("could not initialize snorkel\n");
exit (1);
}
http = snorkel_obj_create (snorkel_obj_server, 4, NULL);
if (!http)
{
perror ("could not create http server\n");
exit (1);
}
has_ssl=0;
if (snorkel_obj_set (http,snorkel_attrib_listener,port, has_ssl) != SNORKEL_SUCCESS)
{
perror ("could not establish listener\n");
snorkel_obj_destroy (http);
if (logobj)
snorkel_obj_destroy (logobj);
exit (1);
}
if (snorkel_obj_set(http, snorkel_attrib_ipvers, IPVERS_IPV4,SOCK_SET) != SNORKEL_SUCCESS)
{
fprintf (stderr, "error could not set ip version\n");
exit (1);
}
if (snorkel_obj_set (http,snorkel_attrib_listener,7021, 0) != SNORKEL_SUCCESS)
{
perror ("could not establish listener\n");
snorkel_obj_destroy (http);
if (logobj)
snorkel_obj_destroy (logobj);
exit (1);
}
if (snorkel_obj_set (http, snorkel_attrib_uri_content, GET,
"/index.html",
szForm,
SNORKEL_STORE_AS_REF
) != SNORKEL_SUCCESS)
{
perror ("could not overload index.html");
snorkel_obj_destroy (http);
if (logobj)
snorkel_obj_destroy (logobj);
exit (1);
}
if (snorkel_obj_set (http,snorkel_attrib_uri, POST,"/postform.html",contenttype_text,postform) != SNORKEL_SUCCESS)
{
perror ("could not overload postform.html");
snorkel_obj_destroy (http);
if (logobj)
snorkel_obj_destroy (logobj);
exit (1);
}
<pre lang="c++">if (snorkel_obj_set (http, snorkel_attrib_uri_content, GET,
"/index.html",
otpForm,
SNORKEL_STORE_AS_REF
) != SNORKEL_SUCCESS)
{
perror ("could not overload index.html");
snorkel_obj_destroy (http);
if (logobj)
snorkel_obj_destroy (logobj);
exit (1);
}
fprintf (stderr,"\n\n[HTTP] starting on port %d....", port);
if (pszLog)
{
fprintf (stderr,"\n[HTTP] logging messages to %s\n", pszLog);
}
if (snorkel_obj_start (http) != SNORKEL_SUCCESS)
{
perror ("could not start server\n");
snorkel_obj_destroy (http);
if (logobj)
snorkel_obj_destroy (logobj);
exit (1);
}
fprintf (stderr, "\n[HTTP] started.\n\n"
"--hit enter to terminate--\n");
fgets (szExit, sizeof (szExit), stdin);
my question is: how can I display the first form szForm (the form requesting the mobile number), and after submitting the mobile number, I get the second form otpForm (the form that request the OTP)!!
Another question:
can we perform the second GET method on the same index.html, which I've used with my first GET method?
Need help please.
Best Regards.