Beispiel #1
0
int main()
{
    struct mg_context *ctx = mg_start();
    mg_set_option(ctx, "ports", "33333");

    mg_set_uri_callback(ctx, "/",         &show_index, 0);
    mg_set_uri_callback(ctx, "/multiply", &multiply,   0);
    mg_set_uri_callback(ctx, "/result",   &get_result, 0);

    getchar();
    mg_stop(ctx);

    return 0;
}
Beispiel #2
0
void ofxWebServer::addHandler(ofxWSRequestHandler *handler, string pattern) {
	
	// make sure there's a forward slash at the beginning
	if(pattern.size()==0) {
		pattern = "/";
	} else if(pattern[0]!='/') {
		pattern = "/" + pattern;
	}
	
	mg_set_uri_callback(ctx, pattern.c_str(), webserverCallback, handler);
}
Beispiel #3
0
int
main(int argc, char *argv[])
{
	struct mg_context *ctx;

	ctx = mg_start();
	mg_set_option(ctx, "ports", "8080");
	mg_set_auth_callback(ctx, "/*", &authorize, NULL);
	mg_set_uri_callback(ctx, "/login", &login_page, NULL);

	for (;;)
		sleep(1);
}
Beispiel #4
0
int main (int argc, const char * argv[])
{
	helper_num = 0;
    helper1 = 0;
    helper2 = 0;
    helper3 = 0;
    SN1_par = 100;
    SN2_par = 100;
    SN3_par = 100;
    
	struct mg_context	*ctx; 
		
	(void) signal(SIGTERM, signal_handler);
	(void) signal(SIGINT, signal_handler);
	
	if ((ctx = mg_start()) == NULL) {
		(void) printf("%s\n", "Cannot initialize Mongoose context");
		exit(EXIT_FAILURE);
	}
	
	mg_set_option(ctx, "ports", "9909");	
	mg_set_option(ctx, "max_threads", "10");
	mg_set_option(ctx, "dir_list", "no");   // Disable directory listing
	
	mg_set_uri_callback(ctx, "/*", get, NULL);  // Setting callback handler.
	
	printf("Mongoose %s started on port(s) [%s], serving directory [%s]\n",
		   mg_version(),
		   mg_get_option(ctx, "ports"),
		   mg_get_option(ctx, "root"));
	
	fflush(stdout); 
	getchar();
	exit_flag = 9;
	
	(void) printf("Exiting on signal %d, "
				  "waiting for all threads to finish...", exit_flag);
	fflush(stdout);
	mg_stop(ctx);
	
	(void) printf("%s", " done.\n");
	
	return (EXIT_SUCCESS);	
}
Beispiel #5
0
void 
http_start(const char *web_root_, const char *doc_root_) 
{
  replace_str(&doc_root, doc_root_);
  replace_str(&web_root, web_root_);
    
  http_stop();
  ctx = mg_start();
  mg_set_option(ctx, "root", web_root);
  mg_set_option(ctx, "ports", http_port);
  mg_set_uri_callback(ctx, "/", &show_index, NULL);
  mg_set_uri_callback(ctx, "/eval", &eval_script, NULL);  
  mg_set_uri_callback(ctx, "/get_files", &get_files, NULL);
  mg_set_uri_callback(ctx, "/open_file", &open_file, NULL);
  mg_set_uri_callback(ctx, "/upload_file", &upload_file, NULL);
  mg_set_uri_callback(ctx, "/upload_script", &upload_script, NULL);
}
Beispiel #6
0
int
main_ztv_webui_init(int argc, char *argv[])
{
	if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'A') {
		if (argc != 6)
			show_usage_and_exit();
		exit(mg_edit_passwords(argv[2], argv[3], argv[4],argv[5]));
	}

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

#ifndef _WIN32
	(void) signal(SIGCHLD, signal_handler);
#endif /* _WIN32 */
	(void) signal(SIGTERM, signal_handler);
	(void) signal(SIGINT, signal_handler);

	if ((ctx = mg_start()) == NULL) {
		(void) printf("%s\n", "Cannot initialize Mongoose context");
		exit(EXIT_FAILURE);
	}

	process_command_line_arguments(ctx, argv);
	if (mg_get_option(ctx, "ports") == NULL &&
	    mg_set_option(ctx, "ports", "8080") != 1)
		exit(EXIT_FAILURE);

	printf("Mongoose %s started on port(s) [%s], serving directory [%s]\n",
	    mg_version(),
	    mg_get_option(ctx, "ports"),
	    mg_get_option(ctx, "root"));

    mg_set_uri_callback(ctx, "/login", &login_page, NULL);
    mg_set_uri_callback(ctx, "/ztv", &ztv_page, NULL);
    mg_set_uri_callback(ctx, "/share.apk", &share_pkg,NULL);
    mg_set_uri_callback(ctx, "/shs", &shs_page, NULL);
    mg_set_uri_callback(ctx, "/about", &shs_page, NULL);
    mg_set_uri_callback(ctx, "/uploadfile", &upload_page, NULL);
    mg_set_uri_callback(ctx, "/upload.html", &upload_input_page, NULL);
    mg_set_uri_callback(ctx, "/upload.htm", &upload_input_page, NULL);    
    mg_set_uri_callback(ctx, "/r.html", &rili_page, NULL);
    mg_set_uri_callback(ctx, "/r.manifest", &r_manifest_page, NULL);        
    mg_set_uri_callback(ctx, "/http302Jobs.mp4", &http302Jobs_mp4_page, NULL);  
    mg_set_uri_callback(ctx, "/bbs.html", &bbs_input_page, NULL);  
    mg_set_uri_callback(ctx, "/bbs", &bbs_page, NULL);

	fflush(stdout);
/*	while (exit_flag == 0)
		sleep(1);

	(void) printf("Exiting on signal %d, "
	    "waiting for all threads to finish...", exit_flag);
	fflush(stdout);
	mg_stop(ctx);
	(void) printf("%s", " done.\n");   */

	return (EXIT_SUCCESS);
}
Beispiel #7
0
void setup_sources(struct mg_context *ctx)
{
  mg_set_uri_callback(ctx, "/sources", &sources, NULL);
  mg_set_uri_callback(ctx, "/sources/new", &add_source, NULL);
}