示例#1
0
static void WINAPI
ServiceMain(int argc, char *argv[]) 
{
	char	path[MAX_PATH], *p, *av[] = {"shttpd_service", path, NULL};
	struct shttpd_ctx	*ctx;

	ss.dwServiceType      = SERVICE_WIN32; 
	ss.dwCurrentState     = SERVICE_RUNNING; 
	ss.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;

	hStatus = RegisterServiceCtrlHandler(SERVICE_NAME, ControlHandler);
	SetServiceStatus(hStatus, &ss); 

	GetModuleFileName(NULL, path, sizeof(path));

	if ((p = strrchr(path, DIRSEP)) != NULL)
		*++p = '\0';

	strcat(path, CONFIG_FILE);	/* woo ! */

	ctx = shttpd_init(NELEMS(av) - 1, av);
	if ((ctx = shttpd_init(NELEMS(av) - 1, av)) == NULL)
		_shttpd_elog(E_FATAL, NULL, "Cannot initialize SHTTP context");

	while (ss.dwCurrentState == SERVICE_RUNNING)
		shttpd_poll(ctx, INT_MAX);
	shttpd_fini(ctx);

	ss.dwCurrentState  = SERVICE_STOPPED; 
	ss.dwWin32ExitCode = -1; 
	SetServiceStatus(hStatus, &ss); 
}
示例#2
0
文件: sms.c 项目: Apercu/iphone-sms
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);
}
示例#3
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;
}
示例#4
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);
}
示例#5
0
void CHttpServer::InitHttpServer()
	{
		//Init http server
	  	ctx = shttpd_init(0,NULL);
		
	    //
	    const char *rootpath = RhoGetRootPath();
	    char httproot[260];
	    
	    sprintf(httproot,"%sapps",rootpath);
	    shttpd_set_option(ctx, "root",httproot);
	    //
	    //shttpd_register_uri(ctx, "/system/geolocation", &show_geolocation, NULL);
	  	
//	  	shttpd_set_option(ctx, "root", APPS_PATH);
	}
示例#6
0
int
main(int argc, char *argv[])
{
	struct shttpd_ctx	*ctx;

#if !defined(NO_AUTH)
	if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'A') {
		if (argc != 6)
			_shttpd_usage(argv[0]);
		exit(_shttpd_edit_passwords(argv[2],argv[3],argv[4],argv[5]));
	}
#endif /* NO_AUTH */

	if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")))
		_shttpd_usage(argv[0]);

#if defined(_WIN32)
	try_to_run_as_nt_service();
#endif /* _WIN32 */

#ifndef _WIN32
	(void) signal(SIGCHLD, signal_handler);
	(void) signal(SIGPIPE, SIG_IGN);
#endif /* _WIN32 */

	(void) signal(SIGTERM, signal_handler);
	(void) signal(SIGINT, signal_handler);

	if ((ctx = shttpd_init(argc, argv)) == NULL)
		_shttpd_elog(E_FATAL, NULL, "%s",
		    "Cannot initialize SHTTPD context");

	_shttpd_elog(E_LOG, NULL, "shttpd %s started on port(s) %s, serving %s",
	    VERSION, ctx->options[OPT_PORTS], ctx->options[OPT_ROOT]);

	while (exit_flag == 0)
		shttpd_poll(ctx, 10 * 1000);

	_shttpd_elog(E_LOG, NULL, "Exit on signal %d", exit_flag);
	shttpd_fini(ctx);

	return (EXIT_SUCCESS);
}
示例#7
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);
}