jint Java_net_pagekite_lib_PageKiteAPI_addFrontend( JNIEnv* env, jclass unused_class , jstring jdomain , jint jport ){ if (pagekite_manager_global == NULL) return -1; const jbyte* domain = NULL; if (jdomain != NULL) domain = (*env)->GetStringUTFChars(env, jdomain, NULL); int port = jport; jint rv = pagekite_add_frontend(pagekite_manager_global, domain, port); if (jdomain != NULL) (*env)->ReleaseStringUTFChars(env, jdomain, domain); return rv; }
int main(int argc, char **argv) { pagekite_mgr m; unsigned int bail_on_errors = 0; unsigned int conn_eviction_idle_s = 0; char* proto; char* kitename; char* secret; char* lua_settings[MAX_PLUGIN_ARGS+1]; int lua_settingc = 0; int lua_no_defaults = 0; int gotargs = 0; int verbosity = 0; int use_ipv4 = 1; #ifdef HAVE_IPV6 int use_ipv6 = 1; #endif int use_current = 1; int use_ssl = 1; int use_fake_ping = 0; int use_watchdog = 0; int max_conns = 25; int spare_frontends = 0; char* fe_hostname = NULL; char* ddns_url = PAGEKITE_NET_DDNS; int ac; int pport; int lport; /* FIXME: Is this too lame? */ srand(time(0) ^ getpid()); while (-1 != (ac = getopt(argc, argv, "46c:B:CE:F:Io:Ln:qRSvWZ"))) { switch (ac) { case '4': use_ipv4 = 0; break; case '6': #ifdef HAVE_IPV6 use_ipv6 = 0; #endif break; case 'C': use_current = 0; break; case 'v': verbosity++; break; case 'q': verbosity--; break; case 'I': use_ssl = 0; break; case 'R': use_fake_ping = 1; break; case 'S': ddns_url = NULL; break; case 'W': use_watchdog = 1; break; case 'F': gotargs++; assert(fe_hostname == NULL); fe_hostname = strdup(optarg); break; case 'B': gotargs++; if (1 == sscanf(optarg, "%u", &bail_on_errors)) break; usage(EXIT_ERR_USAGE); case 'c': gotargs++; if (1 == sscanf(optarg, "%d", &max_conns)) break; usage(EXIT_ERR_USAGE); case 'E': gotargs++; if (1 == sscanf(optarg, "%u", &conn_eviction_idle_s)) break; usage(EXIT_ERR_USAGE); case 'o': if (lua_settingc >= MAX_PLUGIN_ARGS) usage(EXIT_ERR_USAGE); gotargs++; lua_settings[lua_settingc++] = strdup(optarg); break; case 'L': lua_no_defaults = 1; break; case 'n': gotargs++; if (1 == sscanf(optarg, "%d", &spare_frontends)) break; usage(EXIT_ERR_USAGE); default: usage(EXIT_ERR_USAGE); } gotargs++; } lua_settings[lua_settingc] = NULL; if ((argc-1-gotargs) < 5 || ((argc-1-gotargs) % 5) != 0) { usage(EXIT_ERR_USAGE); } #ifndef _MSC_VER signal(SIGUSR1, &raise_log_level); #endif int flags = 0; if (use_ssl) flags |= PK_WITH_SSL; if (use_ipv4) flags |= PK_WITH_IPV4; #ifdef HAVE_IPV6 if (use_ipv6) flags |= PK_WITH_IPV6; #endif if (NULL == (m = pagekite_init("pagekitec", 1 + (argc-1-gotargs)/5, /* Kites */ PAGEKITE_NET_FE_MAX, max_conns, ddns_url, flags, verbosity))) { pagekite_perror(m, argv[0]); safe_exit(EXIT_ERR_MANAGER_INIT); } /* Set all the parameters */ pagekite_want_spare_frontends(m, spare_frontends); pagekite_enable_watchdog(m, use_watchdog); pagekite_enable_fake_ping(m, use_fake_ping); pagekite_set_bail_on_errors(m, bail_on_errors); pagekite_set_conn_eviction_idle_s(m, conn_eviction_idle_s); pagekite_enable_lua_plugins(m, !lua_no_defaults, lua_settings); for (ac = gotargs; ac+5 < argc; ac += 5) { if ((1 != sscanf(argv[ac+1], "%d", &lport)) || (1 != sscanf(argv[ac+4], "%d", &pport))) { usage(EXIT_ERR_USAGE); } proto = argv[ac+2]; kitename = argv[ac+3]; secret = argv[ac+5]; if ((0 > pagekite_add_kite(m, proto, kitename, 0, secret, "localhost", lport)) || (use_current && (0 > (pagekite_add_frontend(m, kitename, pport))))) { pagekite_perror(m, argv[0]); safe_exit(EXIT_ERR_ADD_KITE); } } /* The API could do this stuff on INIT, but since we allow for manually specifying a front-end hostname, we do things by hand. */ if (fe_hostname) { if (0 > pagekite_add_frontend(m, fe_hostname, 443)) { pagekite_perror(m, argv[0]); safe_exit(EXIT_ERR_FRONTENDS); } } else if (ddns_url != NULL) { if (0 > pagekite_add_service_frontends(m, flags)) { pagekite_perror(m, argv[0]); safe_exit(EXIT_ERR_FRONTENDS); } } if (0 > pagekite_start(m)) { pagekite_perror(m, argv[0]); safe_exit(EXIT_ERR_START_THREAD); } pagekite_wait(m); pagekite_free(m); return 0; }