Hello
I'm using snorkel embedded web-server, in which the client (browser) submits a mobile-number into the form in order to be processed within the server, and to generate a QR code, which will finally be displayed on the client-side (browser).
Of course, I've used the GET and POST methods to get the mobile-number from the client, and to post it to the server, respectively.
my question are:
1- how can I display the generated QR code within the same server on the client-side? (I've already created a function called dispQR that display the QR code image file)
2- can I use a POST method again within the same server?
<pre lang="xml">#pragma hdrstop
#pragma argsused
#include <tchar.h>
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include "snorkel.h"
#include <string.h>
#include <windows.h>
#include <tchar.h>
#include <math.h>
#include<string>
#include<sstream>
using namespace std;
char szmobilenumber[80];
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"
};
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);
return HTTP_SUCCESS;
}
call_status_t
dispQR (snorkel_obj_t outstream)
{
snorkel_printf (outstream,
"<html><body><img src=file:///webcontent/QR4.jpg>"
"</img></body></html>\r\n");
}
void syntax (char *pszProg)
{
fprintf (stderr, "syntax error:\n");
fprintf (stderr, "%s [-p <port>] [-l <log>]\n", pszProg);
exit (1);
}
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;
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);
}
if (snorkel_obj_set (http,snorkel_attrib_listener,port, 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_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);
}
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);
if(szmobilenumber[0] == '\0')
{
cout<<"No Number was entered";
getch();
exit(0);
}
else
{
cout<<"\nNumber Submitted by the Client: "<<szmobilenumber<<"\n\n";
cout<<"Generate QR code Process...";
}
snorkel_obj_destroy (http);
if (logobj)
snorkel_obj_destroy (logobj);
getch();
}
Any help is really appreciated.
Regards.