Esempio n. 1
0
int
main (int argc, char *argv[])
{
  int sock, data = 1234567;
  struct shttpd_ctx *ctx;
  const char	*config_file;	/* Configuration file */

#ifndef _WIN32
  signal (SIGPIPE, SIG_IGN);
#endif /* !_WIN32 */

  ctx = shttpd_init (NULL, "document_root", "/usr/local/isms", "aliases", "/=/iPhone", "global_htpasswd", "/usr/local/etc/htpasswd","ssl_certificate", "/usr/local/etc/shttpd.pem", NULL);
  
  current_time = time(NULL);
  config_file = CONFIG;
  if (argc > 1 && argv[argc - 2][0] != '-' && argv[argc - 1][0] != '-')
    config_file = argv[argc - 1];
  ctx = do_init(config_file, argc, argv);

  if(fork_background)
  {
    int i = fork();
    if (i<0) exit(1); /* fork error */
    if (i>0) exit(0); /* parent exits */
  }
  /*
   * Initialize SHTTPD context.
   * Attach folder c:\ to the URL /my_c  (for windows), and
   * /etc/ to URL /my_etc (for UNIX). These are Apache-like aliases.
   * Set WWW root to current directory.
   */
//    if(gsm_modem < 0)
//   {
//	gsm_modem = InitConn(115200);
//	SetPDUMode(gsm_modem);
//    }

  /* Let pass 'data' variable to callback, user can change it */
  shttpd_register_url (ctx, "/", &index_html, (void *) &data);
  shttpd_register_url (ctx, "/simpb.html", &simpb_html,NULL);
  shttpd_register_url (ctx, "/credit.html", &credit_html, NULL);
  shttpd_register_url (ctx, "/api.html", &api_html, NULL);
  shttpd_register_url (ctx, "/sqlite.html", &sqlite_html, NULL);
  shttpd_register_url (ctx, "/sms.html", &sms_html, NULL);
  shttpd_register_url (ctx, "/sms_sim.html", &sms_sim_html, NULL);
  shttpd_register_url (ctx, "/setting.html", &setting_html, NULL);
  /* Open listening socket */
  sock = shttpd_open_port (443);
  shttpd_listen (ctx, sock);

  /* Serve connections infinitely until someone kills us */
  for (;;)
    shttpd_poll (ctx, 1000);

  /* Probably unreached, because we will be killed by signal */
  shttpd_fini (ctx);
  if(gsm_modem > 0)
	close(gsm_modem);
  return (EXIT_SUCCESS);
}
Esempio n. 2
0
int hac_create_http_access(MediaPlayer* player, int port, HTTPAccess** access)
{
    HTTPAccess* newAccess;

    CALLOC_ORET(newAccess, HTTPAccess, 1);

    CHK_OFAIL(har_create_resources(&newAccess->resources));

    newAccess->control = ply_get_media_control(player);
    if (newAccess->control == NULL)
    {
        fprintf(stderr, "Media player has no control\n");
        goto fail;
    }

    newAccess->playerListener.data = newAccess;
    newAccess->playerListener.frame_displayed_event = hac_frame_displayed_event;
    newAccess->playerListener.frame_dropped_event = hac_frame_dropped_event;
    newAccess->playerListener.state_change_event = hac_state_change_event;
    newAccess->playerListener.end_of_source_event = hac_end_of_source_event;
    newAccess->playerListener.start_of_source_event = hac_start_of_source_event;
    newAccess->playerListener.player_closed = hac_player_closed;

    if (!ply_register_player_listener(player, &newAccess->playerListener))
    {
        fprintf(stderr, "Failed to register http access as player listener\n");
        goto fail;
    }

    CHK_OFAIL((newAccess->ctx = shttpd_init(NULL, "document_root", "/dev/null", NULL)) != NULL);
    shttpd_register_uri(newAccess->ctx, "/", &http_player_page, newAccess);
    shttpd_register_uri(newAccess->ctx, "/player.html", &http_player_page, newAccess);
    shttpd_register_uri(newAccess->ctx, "/index.html", &http_player_page, newAccess);
    shttpd_register_uri(newAccess->ctx, "/resources/*", &http_static_content, newAccess);
    shttpd_register_uri(newAccess->ctx, "/player/state.xml", &http_player_state_xml, newAccess);
    shttpd_register_uri(newAccess->ctx, "/player/state.txt", &http_player_state_txt, newAccess);
    shttpd_register_uri(newAccess->ctx, "/player/control/*", &http_player_control, newAccess);
    CHK_OFAIL(shttpd_listen(newAccess->ctx, port, 0));


    CHK_OFAIL(init_mutex(&newAccess->playerStateMutex));
    CHK_OFAIL(create_joinable_thread(&newAccess->httpThreadId, http_thread, newAccess));


    *access = newAccess;
    return 1;

fail:
    hac_free_http_access(&newAccess);
    return 0;
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
	int			sock, data = 1234567;
	struct shttpd_ctx	*ctx;
	
	/* Get rid of warnings */
	argc = argc;
	argv = argv;

#ifndef _WIN32
	signal(SIGPIPE, SIG_IGN);
#endif /* !_WIN32 */

	/*
	 * Initialize SHTTPD context.
	 * Attach folder c:\ to the URL /my_c  (for windows), and
	 * /etc/ to URL /my_etc (for UNIX). These are Apache-like aliases.
	 * Set WWW root to current directory.
	 */
	ctx = shttpd_init(NULL,
		"aliases", "c:\\/->/my_c,/etc/->/my_etc",
		"document_root", ".", 
		"ssl_certificate", "shttpd.pem", NULL);

	/* Let pass 'data' variable to callback, user can change it */
	shttpd_register_url(ctx, "/", &index_html, (void *) &data);
	shttpd_register_url(ctx, "/abc.html", &index_html, (void *) &data);

	/* Show how to use password protection */
	shttpd_register_url(ctx, "/secret", &secret_html, (void *) &data);
	shttpd_protect_url(ctx, "/secret", "passfile");

	/* Show how to use stateful big data transfer */
	shttpd_register_url(ctx, "/huge", &huge_html, NULL);

	/* Open listening socket */
	sock = shttpd_open_port(9000);
	shttpd_listen(ctx, sock);

	/* Serve connections infinitely until someone kills us */
	for (;;)
		shttpd_poll(ctx, 1000);

	/* Probably unreached, because we will be killed by signal */
	shttpd_fini(ctx);

	return (EXIT_SUCCESS);
}
Esempio n. 4
0
void CNTService::Run()
{
    int sock;
    struct  shttpd_ctx	*ctx;

    /* Initialize and setup URLs we gonna serve */
    ctx = shttpd_init(NULL,
        "aliases", "c:\\/->/my_c,/etc/->/my_etc",
	"document_root", ".", NULL);
    /* Let pass 'data' variable to callback, user can change it */
    shttpd_register_url(ctx,"/", &index_html, NULL); //*********** changed ML 
	
    /* Open listening socket */
    sock = shttpd_open_port(9000);//*********** changed ML
    shttpd_listen(ctx, sock);	  //*********** changed ML

    /* Serve connections until SERVICE_CONTROL_STOP received */
    while (m_bIsRunning)
        shttpd_poll(ctx,200); //********* changed ML 

    /* Clean up */
   shttpd_fini(ctx);
}