Click here to Skip to main content
15,894,539 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,

I've used "snorkel API" to develop an embedded web-server which allows the client to submit some information through a "POST form", and based on this information, a QR code has been generated.
Now the problem is that I cannot display the QR code (Which is saves as .jpg image).

The Snorkel API use provides an HTTP based UI to manage the service that I'm trying to provide. (it provides an HTTP based UI as the primary end-user interface).

So, whenever I run my C++ embedded web-server (snorkel), I open the internet explorer and write http://localhost:80 to get the end-user interface.

Everything is working just fine, except for displaying the image, which i think is a programming mistake, which i cannot find.

Here is the code, if someone can help, I'd really appreciate it:

C++
#pragma hdrstop
#pragma argsused

#include <snorkel.h>
#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>

call_status_t index_htm(snorkel_obj_t http,     /*read environment from this object */
			snorkel_obj_t outstream)  /* write data to the output stream   */
  {
   
   if (snorkel_printf (outstream, "<html><body><h2><img src=<c:\users\rania\documents\snorkel> width=178 height=178"
"</h2></body></html>\r\n")== SNORKEL_ERROR)
		 return HTTP_ERROR;

   return HTTP_SUCCESS;
   }

void syntax (char *pszProg)
	{
	 fprintf (stderr, "syntax error:\n");
	 fprintf (stderr, "%s [-p <port>]\n", pszProg);
	 exit (1);
	 }

void main (int argc, char *argv[])
 {
  int i = 1;
  int port = 80;
  snorkel_obj_t http = 0;
  char szExit[10];
  for (; i < argc; i++)
  {
   if (argv[i][0] == '-' || argv[i][0] == '/')
	 {
	  char carg = argv[i][1];
	  switch (carg)
	   {
		case 'p':          /* port number */
		port = atoi (argv[i + 1]);
		i++;
		break;
		default:
		syntax (argv[0]);
		break;
		}
	  }
   }

/*
 *
 * initialize API
 *
 */
 if (snorkel_init () != SNORKEL_SUCCESS)
  {
	perror ("could not initialize snorkel\n");
	//exit (1);
   }
/*
 *
 * create a server object
 *
 */
 http = snorkel_obj_create (snorkel_obj_server, 2,     /* number of handler threads to create */
								 "/Users/rania/Documents/Snorkel PRACTICE"       /* directory containing index.html     */);

  if (!http)
   {
	 perror ("could not create http server\n");
	 //exit (1);
   }

/*
 *
 * create a listener
 *
 */
 if (snorkel_obj_set (http,    /* server object */
					  snorkel_attrib_listener, /* attribute   */
					  port,    /* port number */
					  0 /* SSL support */ )
					  != SNORKEL_SUCCESS)
	  {
	   fprintf (stderr, "could not create listener\n");
	   snorkel_obj_destroy (http);
	   //exit (1);
	  }

 /*
  *
  * overload the URL index.html
  *
  */

 if (snorkel_obj_set (http,    /* server object */
					 snorkel_attrib_uri,      /* attribute type */
					 GET,     /* method */
					 "/index.html",   /* url */
					 contenttype_binary, index_htm) != SNORKEL_SUCCESS)
		 {
		   perror ("could not overload index.html");
		   snorkel_obj_destroy (http);
		   //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);
		 }

 /*
  *
  * start the server
  *
  */
  fprintf (stderr, "\n\n[HTTP] starting embedded server\n");
  if (snorkel_obj_start (http) != SNORKEL_SUCCESS)
   {
	perror ("could not start server\n");
	snorkel_obj_destroy (http);
	//exit (1);
	}

/*
 *
 * do something while server runs
 * as a separate thread
 *
 */
  fprintf (stderr, "\n[HTTP] started.\n\n"
					 "--hit enter to terminate--\n");
  fgets (szExit, sizeof (szExit), stdin);

  fprintf (stderr, "[HTTP] bye\n");

 /*
  *
  * graceful clean up
  *
  */
  snorkel_obj_destroy (http);
  exit (0);
  }



Please, need your help.
Best Regards.
Posted
Updated 9-Apr-14 23:37pm
v2
Comments
Richard MacCutchan 10-Apr-14 5:38am    
You need to provide some clues as to where it is going wrong.
enhzflep 10-Apr-14 9:22am    
The call to snorkel_printf looks suspect to me, and for a number of reasons, I might add.

Firstly, you're not providing an actual filename, just a folder name
Secondly, you've got angled brackets in this path
Thirdly, you're providing a local folder-name, not one relative to the site's root.

What do you get when you view the page in a browser and hit "view-source"?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900