Skip to content

Commit

Permalink
Remove LUA and raw listener from public API
Browse files Browse the repository at this point in the history
  • Loading branch information
BjarniRunar committed Jul 5, 2017
1 parent 57438d8 commit ed942a4
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 170 deletions.
6 changes: 2 additions & 4 deletions bindings/java/net/pagekite/lib/PageKiteAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ public class PageKiteAPI extends Object
public static native int poll(int timeout);
public static native int tick();
public static native int setBailOnErrors(int errors);
/* FIXME: void pagekite_perror(const char*) */
/* FIXME: int pagekite_add_listener(const char* domain, int port, pagekite_callback_t* callback_func, void* callback_data) */
/* FIXME: int pagekite_enable_lua_plugins(int enable_defaults, char** settings) */
public static native int perror(String prefix);

public static boolean libLoaded;
static {
Expand All @@ -137,4 +135,4 @@ public class PageKiteAPI extends Object
libLoaded = true;
} catch (Throwable t) { }
}
}
}
16 changes: 15 additions & 1 deletion bindings/python/libpagekite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def get_libpagekite_cdll():
(c_int, "dump_state_to_log", (c_void_p,)),
(c_int, "poll", (c_void_p, c_int,)),
(c_int, "tick", (c_void_p,)),
(c_int, "set_bail_on_errors", (c_void_p, c_int,))):
(c_int, "set_bail_on_errors", (c_void_p, c_int,)),
(c_int, "perror", (c_void_p, c_char_p,))):
method = getattr(dll, "pagekite_%s" % func_name)
method.restype = restype
method.argtypes = argtypes
Expand Down Expand Up @@ -867,3 +868,16 @@ def set_bail_on_errors(self, errors):
"""
assert(self.pkm is not None)
return self.dll.pagekite_set_bail_on_errors(self.pkm, c_int(errors))

def perror(self, prefix):
"""
Log an error and reset the internal error state.
Args:
* `const char* prefix`: Prefix for the logged message
Returns:
Always returns 0.
"""
assert(self.pkm is not None)
return self.dll.pagekite_perror(self.pkm, c_char_p(prefix.encode("utf-8")))
15 changes: 1 addition & 14 deletions contrib/backends/pagekitec.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,9 @@ int main(int argc, char **argv) {
char* proto;
char* kitename;
char* secret;
char* lua_settings[MAX_PLUGIN_ARGS+1];
char* whitelabel_tld = NULL;
char* app_name = "pagekitec";
char* localhost = "localhost";
int lua_settingc = 0;
int lua_no_defaults = 0;
int gotargs = 0;
int verbosity = 0;
int use_current = 1;
Expand All @@ -133,7 +130,7 @@ int main(int argc, char **argv) {
flags |= PK_WITH_IPV6;
#endif

while (-1 != (ac = getopt(argc, argv, "46a:B:c:CE:F:P:HIo:l:LNn:qRsSvWw:Z"))) {
while (-1 != (ac = getopt(argc, argv, "46a:B:c:CE:F:P:HIl:Nn:qRsSvWw:Z"))) {
switch (ac) {
case '4':
flags &= ~PK_WITH_IPV4;
Expand Down Expand Up @@ -206,14 +203,6 @@ int main(int argc, char **argv) {
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;
Expand All @@ -223,7 +212,6 @@ int main(int argc, char **argv) {
}
gotargs++;
}
lua_settings[lua_settingc] = NULL;

if ((argc-1-gotargs) < 5 || ((argc-1-gotargs) % 5) != 0) {
usage(EXIT_ERR_USAGE);
Expand Down Expand Up @@ -271,7 +259,6 @@ int main(int argc, char **argv) {
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);

/* Move the logging to the event API, mostly for testing. */
if (0 == (flags & PK_WITH_SYSLOG)) {
Expand Down
57 changes: 3 additions & 54 deletions doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
* [`pagekite_tick `](#pgkttck)
* [`pagekite_set_bail_on_errors `](#pgktstblnrrrs)
* [`pagekite_perror `](#pgktprrr)
* Experimental
* [`pagekite_add_listener `](#pgktddlstnr)
* [`pagekite_enable_lua_plugins `](#pgktnbllplgns)
* [Constants](#constants)

## Functions
Expand Down Expand Up @@ -781,65 +778,17 @@ This function can be called at any time.

<a name="pgktprrr"><hr></a>

#### `void pagekite_perror(...)`
#### `int pagekite_perror(...)`

Log an error and reset the internal error state.

**Arguments**:

* `pagekite_mgr`: A reference to the PageKite manager object
* `const char*`: Prefix for the logged message
* `const char* prefix`: Prefix for the logged message

**Returns**: Always returns 0.

### Experimental

<a name="pgktddlstnr"><hr></a>

#### `int pagekite_add_listener(...)`

Add a listening port to the event loop.

When a connection has been accepted, the requested callback will
be invoked. The callback should take two arguments: the first
an int (the file descriptor of the accepted connection), the second
a `void*` which will contain the `callback_data`.

**Note:** This function is experimental and may change in the
future.

**Arguments**:

* `pagekite_mgr`: A reference to the PageKite manager object
* `const char* domain`: Hostname or IP to listen on, e.g. "0.0.0.0"
* `int port`: Port to listen on
* `pagekite_callback_t* callback_func`: Callback function
* `void* callback_data`: Arbitrary data to pass to callback on connect

**Returns**: The number of relay IPs configured, or -1 on failure.


<a name="pgktnbllplgns"><hr></a>

#### `int pagekite_enable_lua_plugins(...)`

Enable and configure Lua plugins.

This will configure and enable Lua plugins, either only those
specified in the `settings` list, or all default plugins if `enable_defaults`
is nonzero.

**Note:** This function is experimental and may change in the
future.

**Arguments**:

* `pagekite_mgr`: A reference to the PageKite manager object
* `int enable_defaults`: If non-zero, default plugins will be enabled
* `char** settings`: NULL-terminated list of settings, e.g. web_ui=8080.

**Returns**: The number of relay IPs configured, or -1 on failure.

<a name="constants"><hr></a>

## Constants
Expand Down Expand Up @@ -909,4 +858,4 @@ PK_EV_RESPOND_OK = 0x00000001
PK_EV_RESPOND_ACCEPT = 0x00000002
PK_EV_RESPOND_FALSE = 0x0000ff00
PK_EV_RESPOND_ABORT = 0x00000100
PK_EV_RESPOND_REJECT = 0x00000200
PK_EV_RESPOND_REJECT = 0x00000200
16 changes: 15 additions & 1 deletion doc/API_JNI.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* [`poll `](#pll)
* [`tick `](#tck)
* [`setBailOnErrors `](#stBlOnErrrs)
* [`perror `](#prrr)
* [Constants](#constants)

## Functions
Expand Down Expand Up @@ -750,6 +751,19 @@ This function can be called at any time.

**Returns**: Always returns 0.


<a name="prrr"><hr></a>

#### `int perror(...)`

Log an error and reset the internal error state.

**Arguments**:

* `String prefix`: Prefix for the logged message

**Returns**: Always returns 0.

<a name="constants"><hr></a>

## Constants
Expand Down Expand Up @@ -819,4 +833,4 @@ PageKiteAPI.PK_EV_RESPOND_OK = 0x00000001
PageKiteAPI.PK_EV_RESPOND_ACCEPT = 0x00000002
PageKiteAPI.PK_EV_RESPOND_FALSE = 0x0000ff00
PageKiteAPI.PK_EV_RESPOND_ABORT = 0x00000100
PageKiteAPI.PK_EV_RESPOND_REJECT = 0x00000200
PageKiteAPI.PK_EV_RESPOND_REJECT = 0x00000200
42 changes: 7 additions & 35 deletions include/pagekite.h
Original file line number Diff line number Diff line change
Expand Up @@ -751,55 +751,27 @@ DECLSPEC_DLL int pagekite_set_bail_on_errors(
*
* Returns: Always returns 0.
*/
DECLSPEC_DLL void pagekite_perror(
DECLSPEC_DLL int pagekite_perror(
pagekite_mgr, /* A reference to the PageKite manager object */
const char* /* Prefix for the logged message */
const char* prefix /* Prefix for the logged message */
);


/* Experimental: Add a listening port to the event loop.
*
* When a connection has been accepted, the requested callback will
* be invoked. The callback should take two arguments: the first an
* int (the file descriptor of the accepted connection), the second
* a `void*` which will contain the `callback_data`.
*
* **Note:** This function is experimental and may change in the future.
*
* Returns: The number of relay IPs configured, or -1 on failure.
*/
DECLSPEC_DLL int pagekite_add_listener(
pagekite_mgr, /* A reference to the PageKite manager object */
const char* domain, /* Hostname or IP to listen on, e.g. "0.0.0.0" */
int port, /* Port to listen on */
pagekite_callback_t* callback_func, /* Callback function */
void* callback_data /* Arbitrary data to pass to callback on connect */
);
#if WITH_PAGEKITE_RELAY


/* Experimental: Enable and configure Lua plugins.
/* Relays: Enable PageKite relaying on a given port
*
* This will configure and enable Lua plugins, either only those
* specified in the `settings` list, or all default plugins if
* `enable_defaults` is nonzero.
* This will configure and enable the PageKite relay on a given port.
*
* **Note:** This function is experimental and may change in the future.
*
* Returns: The number of relay IPs configured, or -1 on failure.
* Returns: 0 on success, a negative error code on failure.
*/
DECLSPEC_DLL int pagekite_enable_lua_plugins(
pagekite_mgr, /* A reference to the PageKite manager object */
int enable_defaults, /* If non-zero, default plugins will be enabled */
char** settings /* NULL-terminated list of settings, e.g. web_ui=8080. */
);


#if WITH_PAGEKITE_RELAY
DECLSPEC_DLL int pagekite_add_relay_listener(
pagekite_mgr, /* A reference to the PageKite manager object */
int port, /* The port to listen on */
int flags /* Flags, which features to enable */
);

#endif

#ifdef __cplusplus
Expand Down
15 changes: 12 additions & 3 deletions libpagekite/pagekite-jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,11 +557,20 @@ jint Java_net_pagekite_lib_PageKiteAPI_setBailOnErrors(
return rv;
}

/* FIXME: void pagekite_perror(pagekite_mgr, const char*) */
jint Java_net_pagekite_lib_PageKiteAPI_perror(
JNIEnv* env, jclass unused_class
, jstring jprefix
){
if (pagekite_manager_global == NULL) return -1;

/* FIXME: int pagekite_add_listener(pagekite_mgr, const char* domain, int port, pagekite_callback_t* callback_func, void* callback_data) */
const jbyte* prefix = NULL;
if (jprefix != NULL) prefix = (*env)->GetStringUTFChars(env, jprefix, NULL);

/* FIXME: int pagekite_enable_lua_plugins(pagekite_mgr, int enable_defaults, char** settings) */
jint rv = pagekite_perror(pagekite_manager_global, prefix);

if (jprefix != NULL) (*env)->ReleaseStringUTFChars(env, jprefix, prefix);
return rv;
}
#else
# warning Java not found, not building JNI.
#endif
20 changes: 0 additions & 20 deletions libpagekite/pagekite.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,15 +431,6 @@ int pagekite_set_openssl_ciphers(pagekite_mgr pkm, const char* ciphers)
return 0;
}

int pagekite_enable_lua_plugins(pagekite_mgr pkm,
int enable_defaults,
char** settings)
{
PK_MANAGER(pkm)->lua_enable_defaults = (enable_defaults != 0);
PK_MANAGER(pkm)->lua_settings = (const char**) settings;
return pkm_configure_lua(PK_MANAGER(pkm));
}

int pagekite_want_spare_frontends(pagekite_mgr pkm, int spares)
{
if (pkm == NULL) return -1;
Expand Down Expand Up @@ -486,17 +477,6 @@ int pagekite_add_frontend(pagekite_mgr pkm,
FE_STATUS_AUTO, 0);
}

int pagekite_add_listener(pagekite_mgr pkm,
const char* domain,
int port,
pagekite_callback_t* callback_func,
void* callback_data)
{
if (pkm == NULL) return -1;
return pkm_add_listener(PK_MANAGER(pkm), domain, port,
callback_func, callback_data);
}

int pagekite_enable_tick_timer(pagekite_mgr pkm, int enabled)
{
if (pkm == NULL) return -1;
Expand Down
39 changes: 1 addition & 38 deletions libpagekite/pagekite.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -757,47 +757,10 @@ DECLSPEC_DLL int pagekite_perror(
);


/* Experimental: Add a listening port to the event loop.
*
* When a connection has been accepted, the requested callback will
* be invoked. The callback should take two arguments: the first an
* int (the file descriptor of the accepted connection), the second
* a `void*` which will contain the `callback_data`.
*
* **Note:** This function is experimental and may change in the future.
*
* Returns: The number of relay IPs configured, or -1 on failure.
*/
DECLSPEC_DLL int pagekite_add_listener(
pagekite_mgr, /* A reference to the PageKite manager object */
const char* domain, /* Hostname or IP to listen on, e.g. "0.0.0.0" */
int port, /* Port to listen on */
pagekite_callback_t* callback_func, /* Callback function */
void* callback_data /* Arbitrary data to pass to callback on connect */
);


/* Experimental: Enable and configure Lua plugins.
*
* This will configure and enable Lua plugins, either only those
* specified in the `settings` list, or all default plugins if
* `enable_defaults` is nonzero.
*
* **Note:** This function is experimental and may change in the future.
*
* Returns: The number of relay IPs configured, or -1 on failure.
*/
DECLSPEC_DLL int pagekite_enable_lua_plugins(
pagekite_mgr, /* A reference to the PageKite manager object */
int enable_defaults, /* If non-zero, default plugins will be enabled */
char** settings /* NULL-terminated list of settings, e.g. web_ui=8080. */
);


#if WITH_PAGEKITE_RELAY


/* Experimental: Enable PageKite relaying on a given port
/* Relays: Enable PageKite relaying on a given port
*
* This will configure and enable the PageKite relay on a given port.
*
Expand Down

0 comments on commit ed942a4

Please sign in to comment.