Esempio n. 1
0
/**
 * Handler that adds the 'v1' and 'v2' values to the given HTML code.
 *
 * @param cls a 'const char *' with the HTML webpage to return
 * @param mime mime type to use
 * @param session session handle 
 * @param connection connection to use
 */
static int
fill_v1_v2_form (const void *cls,
		 const char *mime,
		 struct Session *session,
		 struct MHD_Connection *connection)
{
  int ret;
  const char *form = cls;
  char *reply;
  struct MHD_Response *response;

  reply = malloc (strlen (form) + strlen (session->value_1) + strlen (session->value_2) + 1);
  snprintf (reply,
	    strlen (form) + strlen (session->value_1) + strlen (session->value_2) + 1,
	    form,
	    session->value_1);
  /* return static form */
  response = MHD_create_response_from_buffer (strlen (reply),
					      (void *) reply,
					      MHD_RESPMEM_MUST_FREE);
  add_session_cookie (session, response);
  MHD_add_response_header (response,
			   MHD_HTTP_HEADER_CONTENT_ENCODING,
			   mime);
  ret = MHD_queue_response (connection, 
			    MHD_HTTP_OK, 
			    response);
  MHD_destroy_response (response);
  return ret;
}
Esempio n. 2
0
/**
 * Handler that returns a simple static HTTP page that
 * is passed in via 'cls'.
 *
 * @param cls a 'const char *' with the HTML webpage to return
 * @param mime mime type to use
 * @param session session handle
 * @param connection connection to use
 */
static int
serve_simple_form (const void *cls,
		   const char *mime,
		   struct Session *session,
		   struct MHD_Connection *connection)
{
  int ret;
  const char *form = cls;
  struct MHD_Response *response;

  /* return static form */
  response = MHD_create_response_from_buffer (strlen (form),
					      (void *) form,
					      MHD_RESPMEM_PERSISTENT);
  if (NULL == response)
    return MHD_NO;
  add_session_cookie (session, response);
  MHD_add_response_header (response,
			   MHD_HTTP_HEADER_CONTENT_ENCODING,
			   mime);
  ret = MHD_queue_response (connection,
			    MHD_HTTP_OK,
			    response);
  MHD_destroy_response (response);
  return ret;
}
Esempio n. 3
0
static int
serveSnapShotXML (const void *cls,
	      		  const char *mime,
	      		  struct Session *session,
	      		  struct MHD_Connection *connection)
{
  int ret;
  //char *reply;
  struct MHD_Response *response;

/*  
  reply = malloc(MAXTEXTFILELENGTH);
  if (NULL == reply)
    return MHD_NO;  
  if ( !ReadTextFileIntoString(reply, "data/SnapShot.xml") )
    return MHD_NO;  
  // Just a trial to check something is changing on the page
  static int Count = 1;
  char *pString = malloc(MAXTEXTFILELENGTH);
  sprintf(pString, reply, Count++);
  free(reply);
  
  const char *pValue = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "Cmd");
  printf("Cmd = %s\n", pValue);
  */
  const char *pCmd = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "Cmd");
//  printf("Cmd = %s\n", pCmd);
  
  // The XML is filled up by the CommandDispatcher using a static string object.
  // Since this is a .c file, we cannot use class objects here, so we basically
  // extract a char point from it.
  const char *pString;   
// Dispatch the command
  CommandDispatcher(&pString, pCmd);
  //strcpy(pString, MASTER_NAME);
  //sprintf(pString, reply, String);
  //free(reply);
  
  //fprintf(stdout, "%s\n", pString);
    
  /* return static form */
  response = MHD_create_response_from_buffer (strlen (pString),
					      (void *) pString,
					      MHD_RESPMEM_PERSISTENT);				  
  if (NULL == response)
    return MHD_NO;
  add_session_cookie (session, response);
  MHD_add_response_header (response,
			   MHD_HTTP_HEADER_CONTENT_ENCODING,
			   mime);
  ret = MHD_queue_response (connection,
			    MHD_HTTP_OK,
			    response);
  MHD_destroy_response (response);
  return ret;
}
Esempio n. 4
0
/**
 * Handler that adds the 'v1' value to the given HTML code.
 *
 * @param cls unused
 * @param mime mime type to use
 * @param session session handle
 * @param connection connection to use
 */
static int
ServeMainPage (const void *cls,
	      const char *mime,
	      struct Session *session,
	      struct MHD_Connection *connection)
{
  int ret;
  char *reply;
  struct MHD_Response *response;
  
  reply = malloc(MAXTEXTFILELENGTH);
  if (NULL == reply)
    return MHD_NO;  
  if ( !ReadTextFileIntoString(reply, "data/MainPage.html") )
    return MHD_NO;  

/*    
  // Open the MainPage html file
  FILE *fp = fopen("data/MainPage.html", "rb");
  if (NULL == fp)
	  return MHD_NO;
  fseek(fp, 0L, SEEK_END);
  long sz = ftell(fp);
  fseek(fp, 0L, SEEK_SET);
  reply = malloc (sz+1);
  if (NULL == reply)
    return MHD_NO;
  fread (reply, 1, sz, fp);
  fclose (fp);
 */

  /* return static form */
  response = MHD_create_response_from_buffer (strlen (reply),
					      (void *) reply,
					      MHD_RESPMEM_MUST_FREE);
  if (NULL == response)
    return MHD_NO;
  add_session_cookie (session, response);
  MHD_add_response_header (response,
			   MHD_HTTP_HEADER_CONTENT_ENCODING,
			   mime);
  ret = MHD_queue_response (connection,
			    MHD_HTTP_OK,
			    response);
  MHD_destroy_response (response);
  return ret;
}
Esempio n. 5
0
static int
serveMasterNameXML (const void *cls,
	      		  const char *mime,
	      		  struct Session *session,
	      		  struct MHD_Connection *connection)
{
  int ret;
  //char *reply;
  struct MHD_Response *response;
   
  const char *pCmd = MHD_lookup_connection_value (connection, MHD_GET_ARGUMENT_KIND, "Cmd");
  printf("Cmd = %s\n", pCmd);
  
  // The XML is filled up by the CommandDispatcher using a static string object.
  // Since this is a .c file, we cannot use class objects here, so we basically
  // extract a char point from it.
  const char *pString;   
  // Dispatch the command
  CommandDispatcher(&pString, pCmd);
  //strcpy(pString, MASTER_NAME);
  //sprintf(pString, reply, String);
  //free(reply);
  
  fprintf(stdout, "%s\n", pString);
  
  /* return static form */
  response = MHD_create_response_from_buffer (strlen (pString),
					      (void *) pString,
					      MHD_RESPMEM_PERSISTENT);				  
  if (NULL == response)
    return MHD_NO;
  add_session_cookie (session, response);
  MHD_add_response_header (response,
			   MHD_HTTP_HEADER_CONTENT_ENCODING,
			   mime);
  ret = MHD_queue_response (connection,
			    MHD_HTTP_OK,
			    response);
  MHD_destroy_response (response);
  return ret;
}