예제 #1
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);
}
예제 #2
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); 
}
예제 #3
0
TInt CHttpServer::ExecuteL()
	{
		// Create and install the active scheduler
		CActiveScheduler* activeScheduler = new (ELeave) CActiveScheduler;
		CleanupStack::PushL(activeScheduler);
		CActiveScheduler::Install(activeScheduler);

		//Initialize Ruby
		RhoRubyStart();
	
		//Send open home event
		SendWindowEvent( ECmdAppHome );
		
#ifdef ENABLE_RUBY_VM_STAT		
		g_httpd_thread_loaded = 1;
#endif		
		
		while ( !iClose )
			{
			shttpd_poll(ctx, 1000);
			}

		RhoRubyStop();

		CleanupStack::PopAndDestroy(activeScheduler);
		
	 	return 0;
	}
예제 #4
0
static void* http_thread(void* arg)
{
    HTTPAccess* access = (HTTPAccess*)arg;

    while (!access->stopped)
    {
        shttpd_poll(access->ctx, 1000);
    }

    shttpd_fini(access->ctx);

    pthread_exit((void*) 0);
}
예제 #5
0
파일: example.c 프로젝트: Apercu/iphone-sms
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);
}
예제 #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);
}
예제 #8
0
파일: standalone.c 프로젝트: mmocean/shttpd
int
main(int argc, char *argv[])
{
	struct shttpd_ctx	*ctx;

	//全局变量的时间 - 暂时不知做什么用的
	current_time = time(NULL);
	if (argc > 1 && argv[argc - 2][0] != '-' && argv[argc - 1][0] != '-')
		config_file = argv[argc - 1];

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

	//配置文件读取
	ctx = init_from_argc_argv(config_file, argc, argv);

#ifndef _WIN32
	/* Switch to alternate UID, it is safe now, after shttpd_listen() */
	//默认是NULL值 暂时不管
	if (ctx->uid != NULL) {
		struct passwd	*pw;

		if ((pw = getpwnam(ctx->uid)) == NULL)
			elog(E_FATAL, 0, "main: unknown user [%s]", ctx->uid);
		else if (setgid(pw->pw_gid) == -1)
			elog(E_FATAL, NULL, "main: setgid(%s): %s",
			    ctx->uid, strerror(errno));
		else if (setuid(pw->pw_uid) == -1)
			elog(E_FATAL, NULL, "main: setuid(%s): %s",
			    ctx->uid, strerror(errno));
	}
	(void) signal(SIGCHLD, signal_handler);
	(void) signal(SIGPIPE, SIG_IGN);
#endif /* _WIN32 */

	//信号注册
	//SIGTERM 使用kill产生
	//SIGINT 使用ctrl+c产生
	(void) signal(SIGTERM, signal_handler);
	(void) signal(SIGINT, signal_handler);


	//默认>0是以demon程序启动
	if (ctx->inetd_mode) {
		(void) freopen("/dev/null", "a", stderr);
		shttpd_add_socket(ctx, fileno(stdin));
	} else {
		//控制台启动
		open_listening_ports(ctx);
	}

	elog(E_LOG, NULL, "shttpd %s started on port(s) %s, serving %s",
	    VERSION, ctx->ports, ctx->document_root);

	//捕获到信号就退出
	while (exit_flag == 0)
		shttpd_poll(ctx, 5000);

	elog(E_LOG, NULL, "%d requests %.2lf Mb in %.2lf Mb out. "
	    "Exit on signal %d", ctx->nrequests, (double) (ctx->in / 1048576),
	    (double) ctx->out / 1048576, exit_flag);

	/*释放资源 内部很多的free*/
	shttpd_fini(ctx);

	return (EXIT_SUCCESS);
}